Skip to content

Commit d71d127

Browse files
committed
fix depth texture using compatibility-mode
1 parent 468f47a commit d71d127

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

src/renderers/webgpu/nodes/WGSLNodeBuilder.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -534,20 +534,30 @@ class WGSLNodeBuilder extends NodeBuilder {
534534
*/
535535
generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, levelSnippet = '0u' ) {
536536

537+
let snippet;
538+
537539
if ( texture.isVideoTexture === true || texture.isStorageTexture === true ) {
538540

539-
return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`;
541+
snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`;
540542

541543
} else if ( depthSnippet ) {
542544

543-
return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
545+
snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
544546

545547
} else {
546548

547-
return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, u32( ${ levelSnippet } ) )`;
549+
snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, u32( ${ levelSnippet } ) )`;
550+
551+
if ( this.renderer.backend.compatibilityMode && texture.isDepthTexture ) {
552+
553+
snippet += '.x';
554+
555+
}
548556

549557
}
550558

559+
return snippet;
560+
551561
}
552562

553563
/**
@@ -1661,7 +1671,15 @@ ${ flowData.code }
16611671

16621672
} else if ( texture.isDepthTexture === true ) {
16631673

1664-
textureType = `texture_depth${ multisampled }_2d${ texture.isDepthArrayTexture === true ? '_array' : '' }`;
1674+
if ( this.renderer.backend.compatibilityMode && texture.compareFunction === null ) {
1675+
1676+
textureType = `texture${ multisampled }_2d<f32>`;
1677+
1678+
} else {
1679+
1680+
textureType = `texture_depth${ multisampled }_2d${ texture.isDepthArrayTexture === true ? '_array' : '' }`;
1681+
1682+
}
16651683

16661684
} else if ( texture.isVideoTexture === true ) {
16671685

src/renderers/webgpu/utils/WebGPUBindingUtils.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
2-
GPUTextureAspect, GPUTextureViewDimension, GPUTextureSampleType, GPUBufferBindingType, GPUStorageTextureAccess
2+
GPUTextureAspect, GPUTextureViewDimension, GPUTextureSampleType, GPUBufferBindingType, GPUStorageTextureAccess,
3+
GPUSamplerBindingType
34
} from './WebGPUConstants.js';
45

56
import { FloatType, IntType, UnsignedIntType } from '../../../constants.js';
@@ -100,7 +101,11 @@ class WebGPUBindingUtils {
100101

101102
if ( binding.texture.compareFunction !== null ) {
102103

103-
sampler.type = 'comparison';
104+
sampler.type = GPUSamplerBindingType.Comparison;
105+
106+
} else if ( backend.compatibilityMode ) {
107+
108+
sampler.type = GPUSamplerBindingType.NonFiltering;
104109

105110
}
106111

@@ -155,7 +160,15 @@ class WebGPUBindingUtils {
155160

156161
if ( binding.texture.isDepthTexture ) {
157162

158-
texture.sampleType = GPUTextureSampleType.Depth;
163+
if ( backend.compatibilityMode && binding.texture.compareFunction === null ) {
164+
165+
texture.sampleType = GPUTextureSampleType.UnfilterableFloat;
166+
167+
} else {
168+
169+
texture.sampleType = GPUTextureSampleType.Depth;
170+
171+
}
159172

160173
} else if ( binding.texture.isDataTexture || binding.texture.isDataArrayTexture || binding.texture.isData3DTexture ) {
161174

0 commit comments

Comments
 (0)