From 1efebf3abcec07fbd81c2f3e110f69fee68b01b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Mon, 27 Nov 2023 23:18:17 +0100 Subject: [PATCH] WebGPU: Make GPUProgrammableStage.entryPoint optional (#20773) --- src/library_webgpu.js | 25 ++++++++++++++----------- system/include/webgpu/webgpu.h | 6 +++--- system/include/webgpu/webgpu_cpp.h | 6 +++--- test/webgpu_basic_rendering.cpp | 2 -- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/library_webgpu.js b/src/library_webgpu.js index 40dda13d13cf..4c1e8418a985 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -311,15 +311,16 @@ var LibraryWebGPU = { makeProgrammableStageDescriptor: (ptr) => { if (!ptr) return undefined; {{{ gpu.makeCheckDescriptor('ptr') }}} - return { + var desc = { "module": WebGPU.mgrShaderModule.get( {{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.module, '*') }}}), - "entryPoint": UTF8ToString( - {{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.entryPoint, '*') }}}), "constants": WebGPU.makePipelineConstants( {{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.constantCount) }}}, {{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.constants, '*') }}}), }; + var entryPointPtr = {{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.entryPoint, '*') }}}; + if (entryPointPtr) desc["entryPoint"] = UTF8ToString(entryPointPtr); + return desc; }, // Map from enum string back to enum number, for callbacks. @@ -1323,18 +1324,19 @@ var LibraryWebGPU = { function makeVertexState(viPtr) { if (!viPtr) return undefined; {{{ gpu.makeCheckDescriptor('viPtr') }}} - return { + var desc = { "module": WebGPU.mgrShaderModule.get( {{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.module, '*') }}}), - "entryPoint": UTF8ToString( - {{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.entryPoint, '*') }}}), "constants": WebGPU.makePipelineConstants( {{{ gpu.makeGetU32('viPtr', C_STRUCTS.WGPUVertexState.constantCount) }}}, {{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.constants, '*') }}}), "buffers": makeVertexBuffers( {{{ gpu.makeGetU32('viPtr', C_STRUCTS.WGPUVertexState.bufferCount) }}}, {{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.buffers, '*') }}}), - }; + }; + var entryPointPtr = {{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.entryPoint, '*') }}}; + if (entryPointPtr) desc["entryPoint"] = UTF8ToString(entryPointPtr); + return desc; } function makeMultisampleState(msPtr) { @@ -1350,18 +1352,19 @@ var LibraryWebGPU = { function makeFragmentState(fsPtr) { if (!fsPtr) return undefined; {{{ gpu.makeCheckDescriptor('fsPtr') }}} - return { + var desc = { "module": WebGPU.mgrShaderModule.get( {{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.module, '*') }}}), - "entryPoint": UTF8ToString( - {{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.entryPoint, '*') }}}), "constants": WebGPU.makePipelineConstants( {{{ gpu.makeGetU32('fsPtr', C_STRUCTS.WGPUFragmentState.constantCount) }}}, {{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.constants, '*') }}}), "targets": makeColorStates( {{{ gpu.makeGetU32('fsPtr', C_STRUCTS.WGPUFragmentState.targetCount) }}}, {{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.targets, '*') }}}), - }; + }; + var entryPointPtr = {{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.entryPoint, '*') }}}; + if (entryPointPtr) desc["entryPoint"] = UTF8ToString(entryPointPtr); + return desc; } var desc = { diff --git a/system/include/webgpu/webgpu.h b/system/include/webgpu/webgpu.h index 7d730009b8ff..1a71b0d73b56 100644 --- a/system/include/webgpu/webgpu.h +++ b/system/include/webgpu/webgpu.h @@ -1110,7 +1110,7 @@ typedef struct WGPUImageCopyTexture { typedef struct WGPUProgrammableStageDescriptor { WGPUChainedStruct const * nextInChain; WGPUShaderModule module; - char const * entryPoint; + WGPU_NULLABLE char const * entryPoint; size_t constantCount; WGPUConstantEntry const * constants; } WGPUProgrammableStageDescriptor WGPU_STRUCTURE_ATTRIBUTE; @@ -1199,7 +1199,7 @@ typedef struct WGPURenderPassDescriptor { typedef struct WGPUVertexState { WGPUChainedStruct const * nextInChain; WGPUShaderModule module; - char const * entryPoint; + WGPU_NULLABLE char const * entryPoint; size_t constantCount; WGPUConstantEntry const * constants; size_t bufferCount; @@ -1209,7 +1209,7 @@ typedef struct WGPUVertexState { typedef struct WGPUFragmentState { WGPUChainedStruct const * nextInChain; WGPUShaderModule module; - char const * entryPoint; + WGPU_NULLABLE char const * entryPoint; size_t constantCount; WGPUConstantEntry const * constants; size_t targetCount; diff --git a/system/include/webgpu/webgpu_cpp.h b/system/include/webgpu/webgpu_cpp.h index b9076db9e29f..f81c48783f56 100644 --- a/system/include/webgpu/webgpu_cpp.h +++ b/system/include/webgpu/webgpu_cpp.h @@ -1637,7 +1637,7 @@ namespace wgpu { struct ProgrammableStageDescriptor { ChainedStruct const * nextInChain = nullptr; ShaderModule module; - char const * entryPoint; + char const * entryPoint = nullptr; size_t constantCount = 0; ConstantEntry const * constants; }; @@ -1726,7 +1726,7 @@ namespace wgpu { struct VertexState { ChainedStruct const * nextInChain = nullptr; ShaderModule module; - char const * entryPoint; + char const * entryPoint = nullptr; size_t constantCount = 0; ConstantEntry const * constants; size_t bufferCount = 0; @@ -1736,7 +1736,7 @@ namespace wgpu { struct FragmentState { ChainedStruct const * nextInChain = nullptr; ShaderModule module; - char const * entryPoint; + char const * entryPoint = nullptr; size_t constantCount = 0; ConstantEntry const * constants; size_t targetCount; diff --git a/test/webgpu_basic_rendering.cpp b/test/webgpu_basic_rendering.cpp index 7a415eaf7d2b..d652d37b3336 100644 --- a/test/webgpu_basic_rendering.cpp +++ b/test/webgpu_basic_rendering.cpp @@ -110,7 +110,6 @@ void init() { wgpu::FragmentState fragmentState{}; fragmentState.module = shaderModule; - fragmentState.entryPoint = "main_f"; fragmentState.targetCount = 1; fragmentState.targets = &colorTargetState; @@ -121,7 +120,6 @@ void init() { wgpu::RenderPipelineDescriptor descriptor{}; descriptor.layout = device.CreatePipelineLayout(&pl); descriptor.vertex.module = shaderModule; - descriptor.vertex.entryPoint = "main_v"; descriptor.fragment = &fragmentState; descriptor.primitive.topology = wgpu::PrimitiveTopology::TriangleList; descriptor.depthStencil = &depthStencilState;