Skip to content

Commit e9a8b53

Browse files
mvaligurskyMartin Valigursky
andauthored
{Fix] DepthBias is only supported for triangles on WebGPU (#7715)
Co-authored-by: Martin Valigursky <[email protected]>
1 parent 917a3fa commit e9a8b53

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/platform/graphics/webgpu/webgpu-render-pipeline.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,11 @@ class WebgpuRenderPipeline extends WebgpuPipeline {
256256
* @param {boolean} stencilEnabled - Whether stencil is enabled.
257257
* @param {StencilParameters} stencilFront - The stencil state for front faces.
258258
* @param {StencilParameters} stencilBack - The stencil state for back faces.
259+
* @param {string} primitiveTopology - The primitive topology.
259260
* @returns {object} Returns the depth stencil state.
260261
* @private
261262
*/
262-
getDepthStencil(depthState, renderTarget, stencilEnabled, stencilFront, stencilBack) {
263+
getDepthStencil(depthState, renderTarget, stencilEnabled, stencilFront, stencilBack, primitiveTopology) {
263264

264265
/** @type {GPUDepthStencilState} */
265266
let depthStencil;
@@ -275,8 +276,10 @@ class WebgpuRenderPipeline extends WebgpuPipeline {
275276
if (depth) {
276277
depthStencil.depthWriteEnabled = depthState.write;
277278
depthStencil.depthCompare = _compareFunction[depthState.func];
278-
depthStencil.depthBias = depthState.depthBias;
279-
depthStencil.depthBiasSlopeScale = depthState.depthBiasSlope;
279+
280+
const biasAllowed = primitiveTopology === 'triangle-list' || primitiveTopology === 'triangle-strip';
281+
depthStencil.depthBias = biasAllowed ? depthState.depthBias : 0;
282+
depthStencil.depthBiasSlopeScale = biasAllowed ? depthState.depthBiasSlope : 0;
280283
} else {
281284
// if render target does not have depth buffer
282285
depthStencil.depthWriteEnabled = false;
@@ -331,7 +334,7 @@ class WebgpuRenderPipeline extends WebgpuPipeline {
331334
cullMode: _cullModes[cullMode]
332335
},
333336

334-
depthStencil: this.getDepthStencil(depthState, renderTarget, stencilEnabled, stencilFront, stencilBack),
337+
depthStencil: this.getDepthStencil(depthState, renderTarget, stencilEnabled, stencilFront, stencilBack, primitiveTopology),
335338

336339
multisample: {
337340
count: renderTarget.samples

0 commit comments

Comments
 (0)