-
Notifications
You must be signed in to change notification settings - Fork 923
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
Conversation
This comment was marked as duplicate.
This comment was marked as duplicate.
naga/src/back/spv/writer.rs
Outdated
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) | ||
} | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
Line 751 in 43cb730
ValuePointer { |
There was a problem hiding this comment.
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.
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
a869bd5
to
a12a9ba
Compare
naga/src/back/spv/block.rs
Outdated
TypeResolution::Handle(handle) => handle, | ||
TypeResolution::Value(_) => { | ||
return Err(Error::Validation( | ||
"Array types should always be in the arena", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Array types should always be in the arena", | |
"Matrix types should always be in the arena", |
I don't think this is always true:
wgpu/naga/src/proc/typifier.rs
Line 98 in 43cb730
/// - TypeInner::Matrix (generated by matrix multiplication) |
There was a problem hiding this comment.
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>
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Closing, since #6390 has landed. |
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
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.