@@ -5,7 +5,11 @@ Tests render results with different depth bias values like 'positive', 'negative
5
5
6
6
import { makeTestGroup } from '../../../../common/framework/test_group.js' ;
7
7
import { 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' ;
9
13
import { GPUTest } from '../../../gpu_test.js' ;
10
14
import { kValue } from '../../../util/constants.js' ;
11
15
import { TexelView } from '../../../util/texture/texel_view.js' ;
@@ -28,23 +32,25 @@ enum QuadAngle {
28
32
const kPointTwoFiveBiasForPointTwoFiveZOnFloat = 8388608 ;
29
33
30
34
class DepthBiasTest extends GPUTest {
31
- runDepthBiasTest (
32
- depthFormat : EncodableTextureFormat & DepthStencilFormat ,
35
+ runDepthBiasTestInternal (
36
+ depthFormat : DepthStencilFormat ,
33
37
{
34
38
quadAngle,
35
39
bias,
36
40
biasSlopeScale,
37
41
biasClamp,
38
- expectedDepth ,
42
+ initialDepth ,
39
43
} : {
40
44
quadAngle : QuadAngle ;
41
45
bias : number ;
42
46
biasSlopeScale : number ;
43
47
biasClamp : number ;
44
- expectedDepth : number ;
48
+ initialDepth : number ;
45
49
}
46
- ) {
50
+ ) : { renderTarget : GPUTexture ; depthTexture : GPUTexture } {
47
51
const renderTargetFormat = 'rgba8unorm' ;
52
+ const depthFormatInfo = kTextureFormatInfo [ depthFormat ] ;
53
+
48
54
let vertexShaderCode : string ;
49
55
switch ( quadAngle ) {
50
56
case QuadAngle . Flat :
@@ -99,10 +105,11 @@ class DepthBiasTest extends GPUTest {
99
105
100
106
const depthStencilAttachment : GPURenderPassDepthStencilAttachment = {
101
107
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 ,
106
113
} ;
107
114
108
115
const encoder = this . device . createCommandEncoder ( ) ;
@@ -138,6 +145,33 @@ class DepthBiasTest extends GPUTest {
138
145
pass . end ( ) ;
139
146
this . device . queue . submit ( [ encoder . finish ( ) ] ) ;
140
147
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
+
141
175
const expColor = { Depth : expectedDepth } ;
142
176
const expTexelView = TexelView . fromTexelsAsColors ( depthFormat , coords => expColor ) ;
143
177
@@ -150,6 +184,52 @@ class DepthBiasTest extends GPUTest {
150
184
) ;
151
185
this . eventualExpectOK ( result ) ;
152
186
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 ) ;
153
233
}
154
234
155
235
createRenderPipelineForTest (
@@ -186,8 +266,6 @@ g.test('depth_bias')
186
266
`
187
267
Tests that a square with different depth bias values like 'positive', 'negative', 'infinity',
188
268
'slope', 'clamp', etc. is drawn as expected.
189
-
190
- TODO: Need to test 'depth24plus-stencil8' format?
191
269
`
192
270
)
193
271
. params ( u =>
@@ -261,3 +339,46 @@ g.test('depth_bias')
261
339
. fn ( async t => {
262
340
t . runDepthBiasTest ( 'depth32float' , t . params ) ;
263
341
} ) ;
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