vulkan creation and destruction of shader modules
This commit is contained in:
@@ -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);
|
||||
}
|
@@ -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;
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user