From 2b9870ccfac3b41e411ad9fa93495fba468297b8 Mon Sep 17 00:00:00 2001 From: Filip Lundgren Date: Thu, 1 Feb 2024 22:51:56 -0500 Subject: [PATCH] Support WGPUPrimitiveDepthClipControl / unclippedDepth (#21231) Co-authored-by: Kai Ninomiya --- src/library_webgpu.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/library_webgpu.js b/src/library_webgpu.js index be43a09e22f95..7cd4884c77dff 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -1256,7 +1256,15 @@ var LibraryWebGPU = { {{{ gpu.makeCheckDescriptor('descriptor') }}} function makePrimitiveState(rsPtr) { if (!rsPtr) return undefined; - {{{ gpu.makeCheckDescriptor('rsPtr') }}} + {{{ gpu.makeCheck('rsPtr') }}} + + // TODO: This small hack assumes that there's only one type that can be in the chain of + // WGPUPrimitiveState. The correct thing would be to traverse the chain, but unclippedDepth + // is going to move into the core object soon, so we'll just do this for now. See: + // https://github.com/webgpu-native/webgpu-headers/issues/212#issuecomment-1682801259 + var nextInChainPtr = {{{ makeGetValue('rsPtr', C_STRUCTS.WGPUPrimitiveState.nextInChain, '*') }}}; + var sType = nextInChainPtr ? {{{ gpu.makeGetU32('nextInChainPtr', C_STRUCTS.WGPUChainedStruct.sType) }}} : 0; + return { "topology": WebGPU.PrimitiveTopology[ {{{ gpu.makeGetU32('rsPtr', C_STRUCTS.WGPUPrimitiveState.topology) }}}], @@ -1266,6 +1274,7 @@ var LibraryWebGPU = { {{{ gpu.makeGetU32('rsPtr', C_STRUCTS.WGPUPrimitiveState.frontFace) }}}], "cullMode": WebGPU.CullMode[ {{{ gpu.makeGetU32('rsPtr', C_STRUCTS.WGPUPrimitiveState.cullMode) }}}], + "unclippedDepth": sType === {{{ gpu.SType.PrimitiveDepthClipControl }}} && {{{ gpu.makeGetBool('nextInChainPtr', C_STRUCTS.WGPUPrimitiveDepthClipControl.unclippedDepth) }}}, }; }