Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WGSL textureSample tests #3940

Closed
wants to merge 2 commits into from
Closed

Conversation

greggman
Copy link
Contributor

@greggman greggman commented Sep 9, 2024

Add all the textureSample 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 I'm hoping to find something I can measure, like the mapping between derivative and mix-weight, that will give us some way to test per GPU.

There's a big change to the soft rasterizer to compute derivatives by setting up 2x2 pixels and computing the derivatives by the differences between the directions.


Requirements for PR author:

  • All missing test coverage is tracked with "TODO" or .unimplemented().
  • New helpers are /** documented */ and new helper files are found in helper_index.txt.
  • Test behaves as expected in a WebGPU implementation. (If not passing, explain above.)
  • Test have be tested with compatibility mode validation enabled and behave as expected. (If not passing, explain above.)

Requirements for reviewer sign-off:

  • Tests are properly located in the test tree.
  • Test descriptions allow a reader to "read only the test plans and evaluate coverage completeness", and accurately reflect the test code.
  • Tests provide complete coverage (including validation control cases). Missing coverage MUST be covered by TODOs.
  • Helpers and types promote readability and maintainability.

When landing this PR, be sure to make any necessary issue status updates.

Copy link
Contributor

@shrekshao shrekshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

(I don't really do the % / math for calculating coords. If they pass local test I assume they are good -_-)

Add all the textureSample 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 I'm
hoping to find something I can measure, like the mapping between
derivative and mix-weight, that will give us some way to test
per GPU.

There's a big change to the soft rasterizer to compute derivatives
by setting up 2x2 pixels and computing the derivatives by the
differences between the directions.
@greggman
Copy link
Contributor Author

Hey @shrekshao, could you please re-review this. I changed it to use your min/max suggestion.

The first pass I tried maxFractionalDiff = 0. This doesn't work with nearest filtering because only 1 sample is checked and it needs to be an exact match. I tried +/- 1 / 255 and +/- 2 / 255 and it still failed a few places so it's using the same maxFractionalDiff values as the existing tests which is 0 for sint/uint textures and otherwise, various values.

Anyway, the tests seem to pass except for legit failures (see run)

Legit failures are (1) OpenGL on Linux (compat), reading depth textures returns 0 always (2) Linux Vulkan Intel seems completely broken. Otherwise, lots of stuff that was failing is no longer failing.

Also, I added some more weight queries which was an attempt to figure out what the GPU is doing and applying those to the software renderer. That code path is used by the non-derivative tests. I didn't change the non-derviative tests to use the min/max path as they are already passing.

Anyway, with such a big change it seemed best to ask for a new review. Thanks!

Copy link
Contributor

@shrekshao shrekshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I understand shaders in queryMipGradientValuesForDevice. I had some comments. Please take a look

let g = mix(0.5, 1.0, mipLevel);

let ndx = v.ndx * ${kNumWeightTypes};
result[ndx + 0] = textureSampleLevel(tex, smp, vec2f(0.5), mipLevel).r;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does mipLevel need to be mipLevelNum (f32(v.ndx))?

@fragment fn fs(v: VSOutput) -> @location(0) vec4f {
let mipLevel = f32(v.ndx) / ${kMipGradientSteps};
let size = textureDimensions(tex);
let d = mix(0.125, 0.25, mipLevel) * 4.;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: d seems unused

result[u32(pos.x)] = textureSampleLevel(tex, smp, vec2f(0.5), mipLevel).r;

@fragment fn fs(v: VSOutput) -> @location(0) vec4f {
let mipLevel = f32(v.ndx) / ${kMipGradientSteps};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused here.

say we have

let mipLevelNum = f32(v.ndx);
let mipLevel = mipLevelNum / ${kMipGradientSteps};  // maybe rename to mipLevelMix?

let mipLevel = f32(v.ndx) / ${kMipGradientSteps};
let size = textureDimensions(tex);
let d = mix(0.125, 0.25, mipLevel) * 4.;
let u = f32(v.pos.x) * pow(2.0, mipLevel) / f32(size.x);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does mipLevel need to be mipLevelNum ((f32(v.ndx))?

@shrekshao shrekshao self-requested a review September 21, 2024 00:43
@shrekshao
Copy link
Contributor

Am I understanding the queryMipGradientValuesForDevice shader correctly (based on my questions)?
Do you still have changes to make, or should I review the current files?

@greggman
Copy link
Contributor Author

Your understanding is correct but, given it's been a few days since I asked for this review I've made so new many changes that I guess we should close this and start a new one with the latest.

@greggman greggman closed this Sep 24, 2024
@greggman greggman deleted the texSamp3D-derivatives branch November 1, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants