Skip to content

Commit

Permalink
WebGPU: Make GPUProgrammableStage.entryPoint optional (emscripten-cor…
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois authored Nov 27, 2023
1 parent cfc68d8 commit 1efebf3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
25 changes: 14 additions & 11 deletions src/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions system/include/webgpu/webgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions system/include/webgpu/webgpu_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions test/webgpu_basic_rendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ void init() {

wgpu::FragmentState fragmentState{};
fragmentState.module = shaderModule;
fragmentState.entryPoint = "main_f";
fragmentState.targetCount = 1;
fragmentState.targets = &colorTargetState;

Expand All @@ -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;
Expand Down

0 comments on commit 1efebf3

Please sign in to comment.