Skip to content

Commit

Permalink
[WebGPU] Create one big shader module for Kong
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Oct 5, 2023
1 parent 3cdf439 commit f5b9f65
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@

extern WGPUDevice device;

#ifdef KINC_KONG
static WGPUShaderModule shader_module;

void kinc_g5_internal_webgpu_create_shader_module(const void *source, size_t length) {
WGPUShaderModuleWGSLDescriptor wgsl_desc = {0};
wgsl_desc.code = (const char *)source;
wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;

WGPUShaderModuleDescriptor desc = {0};
desc.nextInChain = (WGPUChainedStruct *)(&wgsl_desc);

shader_module = wgpuDeviceCreateShaderModule(device, &desc);
}

void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t length, kinc_g5_shader_type_t type) {
strcpy(&shader->impl.entry_name[0], source);
}
#else
void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t length, kinc_g5_shader_type_t type) {
WGPUShaderModuleSPIRVDescriptor smSpirvDesc;
memset(&smSpirvDesc, 0, sizeof(smSpirvDesc));
Expand All @@ -15,5 +33,6 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t le
smDesc.nextInChain = &smSpirvDesc;
shader->impl.module = wgpuDeviceCreateShaderModule(device, &smDesc);
}
#endif

void kinc_g5_shader_destroy(kinc_g5_shader_t *shader) {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ extern "C" {
struct WGPUShaderModuleImpl;

typedef struct {
#ifdef KINC_KONG
char entry_name[256];
#else
WGPUShaderModule module;
#endif
} Shader5Impl;

#ifdef __cplusplus
Expand Down

0 comments on commit f5b9f65

Please sign in to comment.