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

[spv-in] sampling from depth textures returns a scalar and is splatted #6384

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

schell
Copy link
Contributor

@schell schell commented Oct 8, 2024

This wraps the image expression in a splat expression when the texture being sampled/loaded is a depth texture.

Connections
This fixes #4551.

Description
Sampling from a depth texture fails because SPIR-V expects the result of sampling to be a vector, whereas WGSL expects it to be a scalar.

Testing
I ran this on some input shaders.

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@schell schell requested a review from a team as a code owner October 8, 2024 20:47
@schell schell marked this pull request as draft October 8, 2024 22:20
@schell schell marked this pull request as ready for review October 8, 2024 22:59
@schell schell force-pushed the fix/spv-in-sampling-result-for-depth-texture-is-scalar branch from 38bf9b1 to 3711eed Compare October 8, 2024 23:34
@schell
Copy link
Contributor Author

schell commented Oct 9, 2024

@jimblandy @cwfitzgerald @teoxoy @Wumpf - I just want to put this on your radar :)

naga/src/front/spv/image.rs Outdated Show resolved Hide resolved
@teoxoy
Copy link
Member

teoxoy commented Oct 10, 2024

Besides the comment I left the changes look correct but could you also add a snapshot test for this?

@schell schell requested a review from teoxoy October 10, 2024 20:15
naga/src/front/spv/image.rs Show resolved Hide resolved
let handle = if is_depth && depth_ref.is_none() {
let result_ty = self.lookup_type.lookup(result_type_id)?;
match ctx.type_arena[result_ty.handle].inner {
crate::TypeInner::Vector { size, .. } => {
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to check this here too? I thought all sampling functions return vec4s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure, so I decided to do the safe thing.

Copy link
Member

Choose a reason for hiding this comment

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

I guess it doesn't hurt but might be misleading. I checked yesterday that all of SPIR-V's sampling functions that we handle all return vec4s, could you revert this?

Co-authored-by: Teodor Tanasoaia <[email protected]>
@schell schell requested a review from teoxoy October 11, 2024 08:36
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.

[spv-in] Sampling results for depth textures need to be changed to scalar floats
2 participants