vulkan creation and destruction of shader modules

This commit is contained in:
Greg Wells
2025-05-27 14:06:26 -04:00
parent df977592df
commit 4709450e94
6 changed files with 48 additions and 5 deletions

View File

@@ -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);
}

View File

@@ -0,0 +1,8 @@
#pragma once
#include <core/shader_module/gryphn_shader_module.h>
#include <vulkan/vulkan.h>
typedef struct gnPlatformShaderModule_t {
VkShaderModule shaderModule;
VkPipelineShaderStageCreateInfo shaderStageInfo;
} gnPlatformShaderModule;

View File

@@ -53,5 +53,5 @@ typedef struct gnDeviceFunctions_t {
void (*_gnDestroyPresentationQueue)(gnPresentationQueue *presentationQueue); void (*_gnDestroyPresentationQueue)(gnPresentationQueue *presentationQueue);
gnReturnCode (*_gnCreateShaderModule)(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo); 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; } gnDeviceFunctions;

View File

@@ -5,3 +5,7 @@ gnReturnCode gnCreateShaderModule(struct gnShaderModule_t* module, struct gnOutp
module->device = device; module->device = device;
return device->deviceFunctions->_gnCreateShaderModule(module, device, shaderModuleInfo); return device->deviceFunctions->_gnCreateShaderModule(module, device, shaderModuleInfo);
} }
void gnDestroyShaderModule(struct gnShaderModule_t* module) {
module->device->deviceFunctions->_gnDestroyShaderModule(module);
}

View File

@@ -9,7 +9,7 @@ typedef enum gnShaderModuleStage_e {
typedef struct gnShaderModuleInfo_t { typedef struct gnShaderModuleInfo_t {
enum gnShaderModuleStage_e stage; enum gnShaderModuleStage_e stage;
unsigned char* code; uint32_t* code;
uint32_t size; uint32_t size;
gnString entryPoint; gnString entryPoint;
} gnShaderModuleInfo; } gnShaderModuleInfo;
@@ -22,3 +22,4 @@ typedef struct gnShaderModule_t {
} gnShaderModule; } gnShaderModule;
gnReturnCode gnCreateShaderModule(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo); gnReturnCode gnCreateShaderModule(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo);
void gnDestroyShaderModule(struct gnShaderModule_t* module);

View File

@@ -16,12 +16,11 @@ typedef enum gnReturnCode_t {
GN_UNKNOWN_IMAGE_FORMAT, GN_UNKNOWN_IMAGE_FORMAT,
GN_FAILED_TO_CREATE_PRESENTATION_QUEUE, GN_FAILED_TO_CREATE_PRESENTATION_QUEUE,
GN_UNSUPPORTED_IMAGE_COUNT, 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_FRAMEBUFFER_ATTACHMENT,
// GN_UNKNOWN_SHADER_MODULE,
// GN_UNKNOWN_FUNCTION, // GN_UNKNOWN_FUNCTION,
// GN_SHADER_FAILED_TO_COMPILE,
// GN_UNKNOWN_COLOR_FORMAT, // GN_UNKNOWN_COLOR_FORMAT,
// GN_FAILED_CREATE_GRAPHICS_PIPELINE, // GN_FAILED_CREATE_GRAPHICS_PIPELINE,
// GN_FAILED_TO_CREATE_FRAMEBUFFER, // 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_FAILED_TO_CREATE_PRESENTATION_QUEUE: return "GN_FAILED_TO_CREATE_PRESENTATION_QUEUE";
case GN_UNSUPPORTED_IMAGE_COUNT: return "GN_UNSUPPORTED_IMAGE_COUNT"; 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_IMAGE_VIEW: return "GN_FAILED_TO_CREATE_IMAGE_VIEW";
case GN_FAILED_TO_CREATE_SHADER_MODULE: return "GN_FAILED_TO_CREATE_SHADER_MODULE";
} }
} }