Skip to content

Commit

Permalink
WGSL textureSample/Bias/Grad tests (#3981)
Browse files Browse the repository at this point in the history
Add all the textureSample, textureSampleBias, and textureSampleGrad
tests. cube and cube-array tests with derivatives are currently skipped
or filtered out as the software rasterizer can't handle this case
correctly or at least doesn't match too many GPUs. Rather than increase
the tolerances.

The big change is the doTextureCalls function now draws a triangle
to a 1x1 size texture, per call using isntance drawing. This allows us
to control the derivatives on a per call basis. Derviatives are based
on a variable called `derivativeBase`. It just the (fragment position - 0.5)
so (0,0) for our 1x1 pixel. It is then divided by the size of the texture
which means its implicit derivatives will choose mip level 0. This
allows us to multiply it to choose any mip level we want to test.

This means we can move the textureSample derivative tests into the main
textureSample tests. That also means we no longer need to software
renderer.

The textureSampleBias tests fail in lots of places. The issue appears
to be that the WGSL spec requires the bias is clamped to [-16, 15.99]
but many GPUs are not doing this.

NOTE: Adding textureSampleBias is what made all of this click. The
original textureSample tests separated out derivatives but you can
not separate them out with textureSampleBais since you can not
write an effective tests without mip level for the bias to affect
which levels are sampled. Further, you must control the derivatives
in order to be able to have the result be something you can test.

Implementing textureSampleGrad was also a step to getting this all
to work as you can consider textureSample as being built on
textureSampleGrad.

    textureSample(tex, smp, coord) ->
           textureSampleBias(tex, smp, coord, 0)

    textureSampleBias(tex, smp, coord, bias) ->
           textureSampleGrad(tex, smp, dpdx(coord), dpdy(coord)) // plus bias

    textureSampleGrad(tex, smp, ddx, ddy) ->
           textureSampleLevel(tex, smp, computeMipLevel(ddx, ddy))
  • Loading branch information
greggman authored Oct 7, 2024
1 parent 27f834b commit c2db0ad
Show file tree
Hide file tree
Showing 5 changed files with 2,020 additions and 586 deletions.
1 change: 0 additions & 1 deletion src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,6 @@
"webgpu:shader,execution,expression,call,builtin,textureSample:depth_array_2d_coords:*": { "subcaseMS": 92.601 },
"webgpu:shader,execution,expression,call,builtin,textureSample:depth_array_3d_coords:*": { "subcaseMS": 20.301 },
"webgpu:shader,execution,expression,call,builtin,textureSample:sampled_1d_coords:*": { "subcaseMS": 1.200 },
"webgpu:shader,execution,expression,call,builtin,textureSample:sampled_2d_coords,derivatives:*": { "subcaseMS": 0.091 },
"webgpu:shader,execution,expression,call,builtin,textureSample:sampled_2d_coords:*": { "subcaseMS": 12.500 },
"webgpu:shader,execution,expression,call,builtin,textureSample:sampled_3d_coords:*": { "subcaseMS": 36.002 },
"webgpu:shader,execution,expression,call,builtin,textureSample:sampled_array_2d_coords:*": { "subcaseMS": 92.500 },
Expand Down
Loading

0 comments on commit c2db0ad

Please sign in to comment.