Skip to content

Commit 1efebf3

Browse files
WebGPU: Make GPUProgrammableStage.entryPoint optional (#20773)
1 parent cfc68d8 commit 1efebf3

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

src/library_webgpu.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,16 @@ var LibraryWebGPU = {
311311
makeProgrammableStageDescriptor: (ptr) => {
312312
if (!ptr) return undefined;
313313
{{{ gpu.makeCheckDescriptor('ptr') }}}
314-
return {
314+
var desc = {
315315
"module": WebGPU.mgrShaderModule.get(
316316
{{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.module, '*') }}}),
317-
"entryPoint": UTF8ToString(
318-
{{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.entryPoint, '*') }}}),
319317
"constants": WebGPU.makePipelineConstants(
320318
{{{ gpu.makeGetU32('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.constantCount) }}},
321319
{{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.constants, '*') }}}),
322320
};
321+
var entryPointPtr = {{{ makeGetValue('ptr', C_STRUCTS.WGPUProgrammableStageDescriptor.entryPoint, '*') }}};
322+
if (entryPointPtr) desc["entryPoint"] = UTF8ToString(entryPointPtr);
323+
return desc;
323324
},
324325

325326
// Map from enum string back to enum number, for callbacks.
@@ -1323,18 +1324,19 @@ var LibraryWebGPU = {
13231324
function makeVertexState(viPtr) {
13241325
if (!viPtr) return undefined;
13251326
{{{ gpu.makeCheckDescriptor('viPtr') }}}
1326-
return {
1327+
var desc = {
13271328
"module": WebGPU.mgrShaderModule.get(
13281329
{{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.module, '*') }}}),
1329-
"entryPoint": UTF8ToString(
1330-
{{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.entryPoint, '*') }}}),
13311330
"constants": WebGPU.makePipelineConstants(
13321331
{{{ gpu.makeGetU32('viPtr', C_STRUCTS.WGPUVertexState.constantCount) }}},
13331332
{{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.constants, '*') }}}),
13341333
"buffers": makeVertexBuffers(
13351334
{{{ gpu.makeGetU32('viPtr', C_STRUCTS.WGPUVertexState.bufferCount) }}},
13361335
{{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.buffers, '*') }}}),
1337-
};
1336+
};
1337+
var entryPointPtr = {{{ makeGetValue('viPtr', C_STRUCTS.WGPUVertexState.entryPoint, '*') }}};
1338+
if (entryPointPtr) desc["entryPoint"] = UTF8ToString(entryPointPtr);
1339+
return desc;
13381340
}
13391341

13401342
function makeMultisampleState(msPtr) {
@@ -1350,18 +1352,19 @@ var LibraryWebGPU = {
13501352
function makeFragmentState(fsPtr) {
13511353
if (!fsPtr) return undefined;
13521354
{{{ gpu.makeCheckDescriptor('fsPtr') }}}
1353-
return {
1355+
var desc = {
13541356
"module": WebGPU.mgrShaderModule.get(
13551357
{{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.module, '*') }}}),
1356-
"entryPoint": UTF8ToString(
1357-
{{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.entryPoint, '*') }}}),
13581358
"constants": WebGPU.makePipelineConstants(
13591359
{{{ gpu.makeGetU32('fsPtr', C_STRUCTS.WGPUFragmentState.constantCount) }}},
13601360
{{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.constants, '*') }}}),
13611361
"targets": makeColorStates(
13621362
{{{ gpu.makeGetU32('fsPtr', C_STRUCTS.WGPUFragmentState.targetCount) }}},
13631363
{{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.targets, '*') }}}),
1364-
};
1364+
};
1365+
var entryPointPtr = {{{ makeGetValue('fsPtr', C_STRUCTS.WGPUFragmentState.entryPoint, '*') }}};
1366+
if (entryPointPtr) desc["entryPoint"] = UTF8ToString(entryPointPtr);
1367+
return desc;
13651368
}
13661369

13671370
var desc = {

system/include/webgpu/webgpu.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ typedef struct WGPUImageCopyTexture {
11101110
typedef struct WGPUProgrammableStageDescriptor {
11111111
WGPUChainedStruct const * nextInChain;
11121112
WGPUShaderModule module;
1113-
char const * entryPoint;
1113+
WGPU_NULLABLE char const * entryPoint;
11141114
size_t constantCount;
11151115
WGPUConstantEntry const * constants;
11161116
} WGPUProgrammableStageDescriptor WGPU_STRUCTURE_ATTRIBUTE;
@@ -1199,7 +1199,7 @@ typedef struct WGPURenderPassDescriptor {
11991199
typedef struct WGPUVertexState {
12001200
WGPUChainedStruct const * nextInChain;
12011201
WGPUShaderModule module;
1202-
char const * entryPoint;
1202+
WGPU_NULLABLE char const * entryPoint;
12031203
size_t constantCount;
12041204
WGPUConstantEntry const * constants;
12051205
size_t bufferCount;
@@ -1209,7 +1209,7 @@ typedef struct WGPUVertexState {
12091209
typedef struct WGPUFragmentState {
12101210
WGPUChainedStruct const * nextInChain;
12111211
WGPUShaderModule module;
1212-
char const * entryPoint;
1212+
WGPU_NULLABLE char const * entryPoint;
12131213
size_t constantCount;
12141214
WGPUConstantEntry const * constants;
12151215
size_t targetCount;

system/include/webgpu/webgpu_cpp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ namespace wgpu {
16371637
struct ProgrammableStageDescriptor {
16381638
ChainedStruct const * nextInChain = nullptr;
16391639
ShaderModule module;
1640-
char const * entryPoint;
1640+
char const * entryPoint = nullptr;
16411641
size_t constantCount = 0;
16421642
ConstantEntry const * constants;
16431643
};
@@ -1726,7 +1726,7 @@ namespace wgpu {
17261726
struct VertexState {
17271727
ChainedStruct const * nextInChain = nullptr;
17281728
ShaderModule module;
1729-
char const * entryPoint;
1729+
char const * entryPoint = nullptr;
17301730
size_t constantCount = 0;
17311731
ConstantEntry const * constants;
17321732
size_t bufferCount = 0;
@@ -1736,7 +1736,7 @@ namespace wgpu {
17361736
struct FragmentState {
17371737
ChainedStruct const * nextInChain = nullptr;
17381738
ShaderModule module;
1739-
char const * entryPoint;
1739+
char const * entryPoint = nullptr;
17401740
size_t constantCount = 0;
17411741
ConstantEntry const * constants;
17421742
size_t targetCount;

test/webgpu_basic_rendering.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ void init() {
110110

111111
wgpu::FragmentState fragmentState{};
112112
fragmentState.module = shaderModule;
113-
fragmentState.entryPoint = "main_f";
114113
fragmentState.targetCount = 1;
115114
fragmentState.targets = &colorTargetState;
116115

@@ -121,7 +120,6 @@ void init() {
121120
wgpu::RenderPipelineDescriptor descriptor{};
122121
descriptor.layout = device.CreatePipelineLayout(&pl);
123122
descriptor.vertex.module = shaderModule;
124-
descriptor.vertex.entryPoint = "main_v";
125123
descriptor.fragment = &fragmentState;
126124
descriptor.primitive.topology = wgpu::PrimitiveTopology::TriangleList;
127125
descriptor.depthStencil = &depthStencilState;

0 commit comments

Comments
 (0)