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

[naga] Support dynamic indexing of by-value matrices #6362

Closed
wants to merge 3 commits into from

Conversation

sagudev
Copy link
Contributor

@sagudev sagudev commented Oct 3, 2024

Connections
Fix #4337

Description
Add support for dynamic indexing of by-value matrices, by introducing get_local_pointer_id and then follow #6188.

Testing
New tests added and because there was no expectation changes in servo's CTS run I wrote new test: gpuweb/cts#3982 (which passes with this PR).

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.

@sagudev

This comment was marked as duplicate.

Comment on lines 172 to 179
let element_pointer_type_id = match element_ty {
LookupType::Handle(handle) => {
self.get_pointer_id(ir_types, handle, spirv::StorageClass::Function)?
}
LookupType::Local(local_type) => {
self.get_local_pointer_id(local_type, spirv::StorageClass::Function)
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we pack this in one single get_pointer_id method?

BTW get_pointer_id never returns Err.

Copy link
Member

@teoxoy teoxoy Oct 8, 2024

Choose a reason for hiding this comment

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

I think we should update get_pointer_id and address the TODO that's currently in get_local_pointer_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

address the TODO that's currently in get_local_pointer_id

This is hard as we cannot pack LookupType in pointer (due to infinite struct size), except if we box it. Another alternative is to simply put u32 for local type, but this could get pretty chaotic.

I think boxing solution is the most nice one. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

What I hand in mind is adding a new ValuePointer variant. Similar to:

ValuePointer {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LocalType has pointers encoded in LocalType::Value field.

@sagudev sagudev marked this pull request as ready for review October 5, 2024 17:37
@sagudev sagudev requested a review from a team as a code owner October 5, 2024 17:37
@sagudev sagudev changed the title [naga] support dyn indexing of matrix [naga] Support dynamic indexing of by-value matrices Oct 5, 2024
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
TypeResolution::Handle(handle) => handle,
TypeResolution::Value(_) => {
return Err(Error::Validation(
"Array types should always be in the arena",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Array types should always be in the arena",
"Matrix types should always be in the arena",

I don't think this is always true:

/// - TypeInner::Matrix (generated by matrix multiplication)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was copy&paste from array, I will check and fix.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
@jimblandy
Copy link
Member

I think actually just fixing #6358 for both matrices and arrays might be simpler than the combination of this and #6188. I'm taking a shot at it now, but if it's hard, then we'll take this PR instead.

@sagudev
Copy link
Contributor Author

sagudev commented Oct 8, 2024

I think actually just fixing #6358 for both matrices and arrays might be simpler than the combination of this and #6188. I'm taking a shot at it now, but if it's hard, then we'll take this PR instead.

Sounds good. Ping me on PR, so I will see it (and test it with servo against CTS).

jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

Permit dynamic indexing of matrices in validation.

Handle matrices and arrays consistently; remove special cases for
arrays.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessIndex` for the entire
thing.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

Permit dynamic indexing of matrices in validation.

Handle matrices and arrays consistently; remove special cases for
arrays.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessIndex` for the entire
thing.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessIndex` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessIndex` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Fixes gfx-rs#4337.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Fixes gfx-rs#4337.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Fixes gfx-rs#4337.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 10, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Fixes gfx-rs#4337.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 11, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Fixes gfx-rs#4337.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 11, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Fixes gfx-rs#4337.
Alternative to gfx-rs#6362.
jimblandy added a commit to jimblandy/wgpu that referenced this pull request Oct 11, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes gfx-rs#6358.
Fixes gfx-rs#4337.
Alternative to gfx-rs#6362.
jimblandy added a commit that referenced this pull request Oct 11, 2024
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes #6358.
Fixes #4337.
Alternative to #6362.
@jimblandy
Copy link
Member

Closing, since #6390 has landed.

@jimblandy jimblandy closed this Oct 11, 2024
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.

Support dynamic indexing of by-value matrices and arrays, per WGSL
3 participants