diff --git a/rendering_api/vulkan/src/shader_module/vulkan_shader_module.c b/rendering_api/vulkan/src/shader_module/vulkan_shader_module.c new file mode 100644 index 0000000..4cca412 --- /dev/null +++ b/rendering_api/vulkan/src/shader_module/vulkan_shader_module.c @@ -0,0 +1,30 @@ +#include "vulkan_shader_module.h" +#include "output_device/vulkan_output_devices.h" + +gnReturnCode gnCreateShaderModuleFn(struct gnShaderModule_t *module, struct gnOutputDevice_t *device, struct gnShaderModuleInfo_t shaderModuleInfo) { + module->shaderModule = malloc(sizeof(struct gnPlatformShaderModule_t)); + + VkShaderModuleCreateInfo createInfo = {}; + createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + createInfo.codeSize = shaderModuleInfo.size; + createInfo.pCode = shaderModuleInfo.code; + + if (vkCreateShaderModule(device->outputDevice->device, &createInfo, NULL, &module->shaderModule->shaderModule) != VK_SUCCESS) { + return GN_FAILED_TO_CREATE_SHADER_MODULE; + } + + module->shaderModule->shaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + if (shaderModuleInfo.stage == GN_VERTEX_SHADER_MODULE) + module->shaderModule->shaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; + else if (shaderModuleInfo.stage == GN_FRAGMENT_SHADER_MODULE) + module->shaderModule->shaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; + + module->shaderModule->shaderStageInfo.module = module->shaderModule->shaderModule; + module->shaderModule->shaderStageInfo.pName = shaderModuleInfo.entryPoint.value; + + return GN_SUCCESS; +} + +void gnDestroyShaderModuleFn(struct gnShaderModule_t* module) { + vkDestroyShaderModule(module->device->outputDevice->device, module->shaderModule->shaderModule, NULL); +} diff --git a/rendering_api/vulkan/src/shader_module/vulkan_shader_module.h b/rendering_api/vulkan/src/shader_module/vulkan_shader_module.h new file mode 100644 index 0000000..423784f --- /dev/null +++ b/rendering_api/vulkan/src/shader_module/vulkan_shader_module.h @@ -0,0 +1,8 @@ +#pragma once +#include +#include + +typedef struct gnPlatformShaderModule_t { + VkShaderModule shaderModule; + VkPipelineShaderStageCreateInfo shaderStageInfo; +} gnPlatformShaderModule; diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h index 57406c2..94a099b 100644 --- a/src/core/gryphn_platform_functions.h +++ b/src/core/gryphn_platform_functions.h @@ -53,5 +53,5 @@ typedef struct gnDeviceFunctions_t { void (*_gnDestroyPresentationQueue)(gnPresentationQueue *presentationQueue); gnReturnCode (*_gnCreateShaderModule)(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo); - void (*_gnDestroyShaderModule)(struct gnShaderModuleInfo_t* module); + void (*_gnDestroyShaderModule)(struct gnShaderModule_t* module); } gnDeviceFunctions; diff --git a/src/core/shader_module/gryphn_shader_module.c b/src/core/shader_module/gryphn_shader_module.c index 65a28f4..3b7aa90 100644 --- a/src/core/shader_module/gryphn_shader_module.c +++ b/src/core/shader_module/gryphn_shader_module.c @@ -5,3 +5,7 @@ gnReturnCode gnCreateShaderModule(struct gnShaderModule_t* module, struct gnOutp module->device = device; return device->deviceFunctions->_gnCreateShaderModule(module, device, shaderModuleInfo); } + +void gnDestroyShaderModule(struct gnShaderModule_t* module) { + module->device->deviceFunctions->_gnDestroyShaderModule(module); +} diff --git a/src/core/shader_module/gryphn_shader_module.h b/src/core/shader_module/gryphn_shader_module.h index a5d92c8..254b717 100644 --- a/src/core/shader_module/gryphn_shader_module.h +++ b/src/core/shader_module/gryphn_shader_module.h @@ -9,7 +9,7 @@ typedef enum gnShaderModuleStage_e { typedef struct gnShaderModuleInfo_t { enum gnShaderModuleStage_e stage; - unsigned char* code; + uint32_t* code; uint32_t size; gnString entryPoint; } gnShaderModuleInfo; @@ -22,3 +22,4 @@ typedef struct gnShaderModule_t { } gnShaderModule; gnReturnCode gnCreateShaderModule(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo); +void gnDestroyShaderModule(struct gnShaderModule_t* module); diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index 85d36da..88b8f0d 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -16,12 +16,11 @@ typedef enum gnReturnCode_t { GN_UNKNOWN_IMAGE_FORMAT, GN_FAILED_TO_CREATE_PRESENTATION_QUEUE, GN_UNSUPPORTED_IMAGE_COUNT, - GN_FAILED_TO_CREATE_IMAGE_VIEW + GN_FAILED_TO_CREATE_IMAGE_VIEW, + GN_FAILED_TO_CREATE_SHADER_MODULE // GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, - // GN_UNKNOWN_SHADER_MODULE, // GN_UNKNOWN_FUNCTION, - // GN_SHADER_FAILED_TO_COMPILE, // GN_UNKNOWN_COLOR_FORMAT, // GN_FAILED_CREATE_GRAPHICS_PIPELINE, // GN_FAILED_TO_CREATE_FRAMEBUFFER, @@ -48,5 +47,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) { case GN_FAILED_TO_CREATE_PRESENTATION_QUEUE: return "GN_FAILED_TO_CREATE_PRESENTATION_QUEUE"; case GN_UNSUPPORTED_IMAGE_COUNT: return "GN_UNSUPPORTED_IMAGE_COUNT"; case GN_FAILED_TO_CREATE_IMAGE_VIEW: return "GN_FAILED_TO_CREATE_IMAGE_VIEW"; + case GN_FAILED_TO_CREATE_SHADER_MODULE: return "GN_FAILED_TO_CREATE_SHADER_MODULE"; } }