@@ -5,7 +5,11 @@ Tests render results with different depth bias values like 'positive', 'negative
55
66import { makeTestGroup } from '../../../../common/framework/test_group.js' ;
77import { unreachable } from '../../../../common/util/util.js' ;
8- import { DepthStencilFormat , EncodableTextureFormat } from '../../../capability_info.js' ;
8+ import {
9+ DepthStencilFormat ,
10+ EncodableTextureFormat ,
11+ kTextureFormatInfo ,
12+ } from '../../../capability_info.js' ;
913import { GPUTest } from '../../../gpu_test.js' ;
1014import { kValue } from '../../../util/constants.js' ;
1115import { TexelView } from '../../../util/texture/texel_view.js' ;
@@ -28,23 +32,25 @@ enum QuadAngle {
2832const kPointTwoFiveBiasForPointTwoFiveZOnFloat = 8388608 ;
2933
3034class DepthBiasTest extends GPUTest {
31- runDepthBiasTest (
32- depthFormat : EncodableTextureFormat & DepthStencilFormat ,
35+ runDepthBiasTestInternal (
36+ depthFormat : DepthStencilFormat ,
3337 {
3438 quadAngle,
3539 bias,
3640 biasSlopeScale,
3741 biasClamp,
38- expectedDepth ,
42+ initialDepth ,
3943 } : {
4044 quadAngle : QuadAngle ;
4145 bias : number ;
4246 biasSlopeScale : number ;
4347 biasClamp : number ;
44- expectedDepth : number ;
48+ initialDepth : number ;
4549 }
46- ) {
50+ ) : { renderTarget : GPUTexture ; depthTexture : GPUTexture } {
4751 const renderTargetFormat = 'rgba8unorm' ;
52+ const depthFormatInfo = kTextureFormatInfo [ depthFormat ] ;
53+
4854 let vertexShaderCode : string ;
4955 switch ( quadAngle ) {
5056 case QuadAngle . Flat :
@@ -99,10 +105,11 @@ class DepthBiasTest extends GPUTest {
99105
100106 const depthStencilAttachment : GPURenderPassDepthStencilAttachment = {
101107 view : depthTexture . createView ( ) ,
102- depthLoadOp : 'load' ,
103- depthStoreOp : 'store' ,
104- stencilLoadOp : 'load' ,
105- stencilStoreOp : 'store' ,
108+ depthLoadOp : depthFormatInfo . depth ? 'clear' : undefined ,
109+ depthStoreOp : depthFormatInfo . depth ? 'store' : undefined ,
110+ stencilLoadOp : depthFormatInfo . stencil ? 'clear' : undefined ,
111+ stencilStoreOp : depthFormatInfo . stencil ? 'store' : undefined ,
112+ depthClearValue : initialDepth ,
106113 } ;
107114
108115 const encoder = this . device . createCommandEncoder ( ) ;
@@ -138,6 +145,33 @@ class DepthBiasTest extends GPUTest {
138145 pass . end ( ) ;
139146 this . device . queue . submit ( [ encoder . finish ( ) ] ) ;
140147
148+ return { renderTarget, depthTexture } ;
149+ }
150+
151+ runDepthBiasTest (
152+ depthFormat : EncodableTextureFormat & DepthStencilFormat ,
153+ {
154+ quadAngle,
155+ bias,
156+ biasSlopeScale,
157+ biasClamp,
158+ expectedDepth,
159+ } : {
160+ quadAngle : QuadAngle ;
161+ bias : number ;
162+ biasSlopeScale : number ;
163+ biasClamp : number ;
164+ expectedDepth : number ;
165+ }
166+ ) {
167+ const { renderTarget, depthTexture } = this . runDepthBiasTestInternal ( depthFormat , {
168+ quadAngle,
169+ bias,
170+ biasSlopeScale,
171+ biasClamp,
172+ initialDepth : 0 ,
173+ } ) ;
174+
141175 const expColor = { Depth : expectedDepth } ;
142176 const expTexelView = TexelView . fromTexelsAsColors ( depthFormat , coords => expColor ) ;
143177
@@ -150,6 +184,52 @@ class DepthBiasTest extends GPUTest {
150184 ) ;
151185 this . eventualExpectOK ( result ) ;
152186 this . trackForCleanup ( renderTarget ) ;
187+ this . trackForCleanup ( depthTexture ) ;
188+ }
189+
190+ runDepthBiasTestFor24BitFormat (
191+ depthFormat : DepthStencilFormat ,
192+ {
193+ quadAngle,
194+ bias,
195+ biasSlopeScale,
196+ biasClamp,
197+ expectedColor,
198+ } : {
199+ quadAngle : QuadAngle ;
200+ bias : number ;
201+ biasSlopeScale : number ;
202+ biasClamp : number ;
203+ expectedColor : Float32Array ;
204+ }
205+ ) {
206+ const { renderTarget, depthTexture } = this . runDepthBiasTestInternal ( depthFormat , {
207+ quadAngle,
208+ bias,
209+ biasSlopeScale,
210+ biasClamp,
211+ initialDepth : 0.4 ,
212+ } ) ;
213+
214+ const renderTargetFormat = 'rgba8unorm' ;
215+ const expColor = {
216+ R : expectedColor [ 0 ] ,
217+ G : expectedColor [ 1 ] ,
218+ B : expectedColor [ 2 ] ,
219+ A : expectedColor [ 3 ] ,
220+ } ;
221+ const expTexelView = TexelView . fromTexelsAsColors ( renderTargetFormat , coords => expColor ) ;
222+
223+ const result = textureContentIsOKByT2B (
224+ this ,
225+ { texture : renderTarget } ,
226+ [ 1 , 1 ] ,
227+ { expTexelView } ,
228+ { maxDiffULPsForNormFormat : 1 }
229+ ) ;
230+ this . eventualExpectOK ( result ) ;
231+ this . trackForCleanup ( renderTarget ) ;
232+ this . trackForCleanup ( depthTexture ) ;
153233 }
154234
155235 createRenderPipelineForTest (
@@ -186,8 +266,6 @@ g.test('depth_bias')
186266 `
187267 Tests that a square with different depth bias values like 'positive', 'negative', 'infinity',
188268 'slope', 'clamp', etc. is drawn as expected.
189-
190- TODO: Need to test 'depth24plus-stencil8' format?
191269 `
192270 )
193271 . params ( u =>
@@ -261,3 +339,46 @@ g.test('depth_bias')
261339 . fn ( async t => {
262340 t . runDepthBiasTest ( 'depth32float' , t . params ) ;
263341 } ) ;
342+
343+ g . test ( 'depth_bias_24bit_format' )
344+ . desc (
345+ `
346+ Tests that a square with different depth bias values like 'positive', 'negative',
347+ 'slope', 'clamp', etc. is drawn as expected with 24 bit depth format.
348+
349+ TODO: Enhance these tests by reading back the depth (emulating the copy using texture sampling)
350+ and checking the result directly, like the non-24-bit depth tests, instead of just relying on
351+ whether the depth test passes or fails.
352+ `
353+ )
354+ . params ( u =>
355+ u //
356+ . combine ( 'format' , [ 'depth24plus' , 'depth24plus-stencil8' ] as const )
357+ . combineWithParams ( [
358+ {
359+ quadAngle : QuadAngle . Flat ,
360+ bias : 0.25 * ( 1 << 25 ) ,
361+ biasSlopeScale : 0 ,
362+ biasClamp : 0 ,
363+ expectedColor : new Float32Array ( [ 1.0 , 0.0 , 0.0 , 1.0 ] ) ,
364+ } ,
365+ {
366+ quadAngle : QuadAngle . TiltedX ,
367+ bias : 0.25 * ( 1 << 25 ) ,
368+ biasSlopeScale : 1 ,
369+ biasClamp : 0 ,
370+ expectedColor : new Float32Array ( [ 1.0 , 0.0 , 0.0 , 1.0 ] ) ,
371+ } ,
372+ {
373+ quadAngle : QuadAngle . Flat ,
374+ bias : 0.25 * ( 1 << 25 ) ,
375+ biasSlopeScale : 0 ,
376+ biasClamp : 0.1 ,
377+ expectedColor : new Float32Array ( [ 0.0 , 0.0 , 0.0 , 0.0 ] ) ,
378+ } ,
379+ ] as const )
380+ )
381+ . fn ( async t => {
382+ const { format } = t . params ;
383+ t . runDepthBiasTestFor24BitFormat ( format , t . params ) ;
384+ } ) ;
0 commit comments