From f5b9f654246e8f7c8303f74f8fdf6b13b889a9ba Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Thu, 5 Oct 2023 18:42:46 +0200 Subject: [PATCH] [WebGPU] Create one big shader module for Kong --- .../Sources/kinc/backend/graphics5/shader.c | 19 +++++++++++++++++++ .../Sources/kinc/backend/graphics5/shader.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c index 4b769e518..ad86f6cf9 100644 --- a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c +++ b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c @@ -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)); @@ -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) {} diff --git a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h index 8a7036e59..125e8ebe9 100644 --- a/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h +++ b/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h @@ -9,7 +9,11 @@ extern "C" { struct WGPUShaderModuleImpl; typedef struct { +#ifdef KINC_KONG + char entry_name[256]; +#else WGPUShaderModule module; +#endif } Shader5Impl; #ifdef __cplusplus