shader+graphics pipeline handles

This commit is contained in:
Greg Wells
2025-06-04 09:57:14 -04:00
parent f20d701353
commit 9faa96d5f5
8 changed files with 44 additions and 38 deletions

View File

@@ -51,10 +51,10 @@ gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPip
} }
for (int i = 0; i < info.shaderModuleCount; i++) { for (int i = 0; i < info.shaderModuleCount; i++) {
if (info.shaderModules[i].info.stage == GN_VERTEX_SHADER_MODULE) { if (info.shaderModules[i]->info.stage == GN_VERTEX_SHADER_MODULE) {
[descriptor setVertexFunction:info.shaderModules[i].shaderModule->function]; [descriptor setVertexFunction:info.shaderModules[i]->shaderModule->function];
} else if (info.shaderModules[i].info.stage == GN_FRAGMENT_SHADER_MODULE) { } else if (info.shaderModules[i]->info.stage == GN_FRAGMENT_SHADER_MODULE) {
[descriptor setFragmentFunction:info.shaderModules[i].shaderModule->function]; [descriptor setFragmentFunction:info.shaderModules[i]->shaderModule->function];
} else { } else {
return GN_UNSUPPORTED_SHADER_MODULE; return GN_UNSUPPORTED_SHADER_MODULE;
} }

View File

@@ -173,7 +173,7 @@ gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPip
VkPipelineShaderStageCreateInfo* modules = malloc(sizeof(VkPipelineShaderStageCreateInfo) * info.shaderModuleCount); VkPipelineShaderStageCreateInfo* modules = malloc(sizeof(VkPipelineShaderStageCreateInfo) * info.shaderModuleCount);
for (int i = 0; i < info.shaderModuleCount; i++) { for (int i = 0; i < info.shaderModuleCount; i++) {
modules[i] = info.shaderModules[i].shaderModule->shaderStageInfo; modules[i] = info.shaderModules[i]->shaderModule->shaderStageInfo;
} }
VkGraphicsPipelineCreateInfo pipelineInfo = { VkGraphicsPipelineCreateInfo pipelineInfo = {

View File

@@ -11,3 +11,5 @@ GN_HANDLE(gnPresentationQueue);
GN_HANDLE(gnTexture); GN_HANDLE(gnTexture);
GN_HANDLE(gnRenderPassDescriptor); GN_HANDLE(gnRenderPassDescriptor);
GN_HANDLE(gnOutputDevice); GN_HANDLE(gnOutputDevice);
GN_HANDLE(gnShaderModule);
GN_HANDLE(gnGraphicsPipeline);

View File

@@ -63,14 +63,14 @@ typedef struct gnDeviceFunctions_t {
gnReturnCode (*_gnPresentationQueueGetImage)(gnPresentationQueueHandle presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex); gnReturnCode (*_gnPresentationQueueGetImage)(gnPresentationQueueHandle presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex);
void (*_gnDestroyPresentationQueue)(gnPresentationQueueHandle presentationQueue); void (*_gnDestroyPresentationQueue)(gnPresentationQueueHandle presentationQueue);
gnReturnCode (*_gnCreateShaderModule)(struct gnShaderModule_t* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo); gnReturnCode (*_gnCreateShaderModule)(gnShaderModuleHandle module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo);
void (*_gnDestroyShaderModule)(struct gnShaderModule_t* module); void (*_gnDestroyShaderModule)(gnShaderModuleHandle module);
gnReturnCode (*_gnCreateRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass, gnOutputDeviceHandle device, struct gnRenderPassDescriptorInfo_t info); gnReturnCode (*_gnCreateRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass, gnOutputDeviceHandle device, struct gnRenderPassDescriptorInfo_t info);
void (*_gnDestroyRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass); void (*_gnDestroyRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass);
gnReturnCode (*_gnCreateGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline, gnOutputDeviceHandle device, struct gnGraphicsPipelineInfo_t pipelineInfo); gnReturnCode (*_gnCreateGraphicsPipeline)(gnGraphicsPipelineHandle pipeline, gnOutputDeviceHandle device, struct gnGraphicsPipelineInfo_t pipelineInfo);
void (*_gnDestroyGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline); void (*_gnDestroyGraphicsPipeline)(gnGraphicsPipelineHandle pipeline);
gnReturnCode (*_gnCreateFramebuffer)(struct gnFramebuffer_t* framebuffer, gnOutputDeviceHandle device, struct gnFramebufferInfo_t framebufferInfo); gnReturnCode (*_gnCreateFramebuffer)(struct gnFramebuffer_t* framebuffer, gnOutputDeviceHandle device, struct gnFramebufferInfo_t framebufferInfo);
void (*_gnDestroyFramebuffer)(struct gnFramebuffer_t* framebuffer); void (*_gnDestroyFramebuffer)(struct gnFramebuffer_t* framebuffer);

View File

@@ -1,12 +1,13 @@
#include "gryphn_graphics_pipeline.h" #include "gryphn_graphics_pipeline.h"
#include "core/gryphn_platform_functions.h" #include "core/gryphn_platform_functions.h"
gnReturnCode gnCreateGraphicsPipeline(struct gnGraphicsPipeline_t* graphicsPipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t info) { gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t info) {
graphicsPipeline->device = device; *graphicsPipeline = malloc(sizeof(struct gnGraphicsPipeline_t));
graphicsPipeline->info = info; (*graphicsPipeline)->device = device;
return graphicsPipeline->device->deviceFunctions->_gnCreateGraphicsPipeline(graphicsPipeline, device, info); (*graphicsPipeline)->info = info;
return device->deviceFunctions->_gnCreateGraphicsPipeline(*graphicsPipeline, device, info);
} }
void gnDestroyGraphicsPipeline(struct gnGraphicsPipeline_t* graphicsPipeline) { void gnDestroyGraphicsPipeline(gnGraphicsPipelineHandle graphicsPipeline) {
graphicsPipeline->device->deviceFunctions->_gnDestroyGraphicsPipeline(graphicsPipeline); graphicsPipeline->device->deviceFunctions->_gnDestroyGraphicsPipeline(graphicsPipeline);
} }

View File

@@ -4,6 +4,7 @@
#include <core/renderpass/gryphn_render_pass_descriptor.h> #include <core/renderpass/gryphn_render_pass_descriptor.h>
#include <core/shader_module/gryphn_shader_module.h> #include <core/shader_module/gryphn_shader_module.h>
#include "utils/math/gryphn_vec2.h" #include "utils/math/gryphn_vec2.h"
#include "core/gryphn_handles.h"
typedef enum gnDynamicState_e { typedef enum gnDynamicState_e {
GN_DYNAMIC_VIEWPORT, GN_DYNAMIC_VIEWPORT,
@@ -84,19 +85,19 @@ typedef struct gnGraphicsPipelineInfo_t {
struct gnUniformLayout_t* uniformLayout; struct gnUniformLayout_t* uniformLayout;
uint32_t subpassIndex; uint32_t subpassIndex;
struct gnRenderPassDescriptor_t* renderPassDescriptor; gnRenderPassDescriptorHandle renderPassDescriptor;
uint32_t shaderModuleCount; uint32_t shaderModuleCount;
struct gnShaderModule_t* shaderModules; gnShaderModuleHandle* shaderModules;
} gnGraphicsPipelineInfo; } gnGraphicsPipelineInfo;
struct gnPlatformGraphicsPipeline_t; #ifdef GN_REVEAL_IMPL
struct gnGraphicsPipeline_t {
typedef struct gnGraphicsPipeline_t {
struct gnPlatformGraphicsPipeline_t* graphicsPipeline; struct gnPlatformGraphicsPipeline_t* graphicsPipeline;
struct gnOutputDevice_t* device; gnOutputDeviceHandle device;
struct gnGraphicsPipelineInfo_t info; gnGraphicsPipelineInfo info;
} gnGraphicsPipeline; };
#endif
gnReturnCode gnCreateGraphicsPipeline(struct gnGraphicsPipeline_t* graphicsPipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t info); gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, gnOutputDeviceHandle device, struct gnGraphicsPipelineInfo_t info);
void gnDestroyGraphicsPipeline(struct gnGraphicsPipeline_t* graphicsPipeline); void gnDestroyGraphicsPipeline(gnGraphicsPipelineHandle graphicsPipeline);

View File

@@ -1,12 +1,13 @@
#include <core/gryphn_platform_functions.h> #include <core/gryphn_platform_functions.h>
#include "gryphn_shader_module.h" #include "gryphn_shader_module.h"
gnReturnCode gnCreateShaderModule(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo) { gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo) {
module->device = device; *module = malloc(sizeof(struct gnShaderModule_t));
module->info = shaderModuleInfo; (*module)->device = device;
return device->deviceFunctions->_gnCreateShaderModule(module, device, shaderModuleInfo); (*module)->info = shaderModuleInfo;
return device->deviceFunctions->_gnCreateShaderModule(*module, device, shaderModuleInfo);
} }
void gnDestroyShaderModule(struct gnShaderModule_t* module) { void gnDestroyShaderModule(gnShaderModuleHandle module) {
module->device->deviceFunctions->_gnDestroyShaderModule(module); module->device->deviceFunctions->_gnDestroyShaderModule(module);
} }

View File

@@ -1,7 +1,8 @@
#pragma once #pragma once
#include "stdint.h" #include "stdint.h"
#include "utils/strings/gryphn_string.h" #include "utils/strings/gryphn_string.h"
#include "core/output_device/gryphn_output_device.h" #include "utils/gryphn_error_code.h"
#include "core/gryphn_handles.h"
typedef enum gnShaderModuleStage_e { typedef enum gnShaderModuleStage_e {
GN_VERTEX_SHADER_MODULE, GN_FRAGMENT_SHADER_MODULE GN_VERTEX_SHADER_MODULE, GN_FRAGMENT_SHADER_MODULE
@@ -14,13 +15,13 @@ typedef struct gnShaderModuleInfo_t {
gnString entryPoint; gnString entryPoint;
} gnShaderModuleInfo; } gnShaderModuleInfo;
struct gnPlatformShaderModule_t; #ifdef GN_REVEAL_IMPL
struct gnShaderModule_t {
typedef struct gnShaderModule_t {
struct gnPlatformShaderModule_t* shaderModule; struct gnPlatformShaderModule_t* shaderModule;
struct gnShaderModuleInfo_t info; gnShaderModuleInfo info;
struct gnOutputDevice_t* device; gnOutputDeviceHandle device;
} gnShaderModule; };
#endif
gnReturnCode gnCreateShaderModule(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo); gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo);
void gnDestroyShaderModule(struct gnShaderModule_t* module); void gnDestroyShaderModule(gnShaderModuleHandle module);