-
Notifications
You must be signed in to change notification settings - Fork 901
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] Allow dynamic indexing of array #6188
base: trunk
Are you sure you want to change the base?
Conversation
895c756
to
f7cbb7c
Compare
Servo's CTS run: https://github.com/sagudev/servo/actions/runs/10656885185/job/29537501039 (click view raw log, then find string
|
First CTS failures is from https://github.com/gpuweb/cts/blob/9b30f7a02d172ce36d138c02614d0a5a1edbfa72/src/webgpu/shader/execution/expression/call/builtin/texture_utils.ts#L3318, because servo does not support GPUExternalTexture, second is just timeout because tests would need to be spillted more (or servo should be faster). TL;DR all ok |
f7cbb7c
to
bdcd77b
Compare
bdcd77b
to
fc694a8
Compare
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.
LGTM; let's see what @teoxoy has to say now. 😀
Note that this PR must be squashed when merged. |
Signed-off-by: sagudev <[email protected]>
gfx-rs/naga#723 back from dead Co-authored-by: Dzmitry Malyshau <[email protected]> Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
fc694a8
to
6c78051
Compare
naga/src/back/spv/block.rs
Outdated
self.function.internal_variables.push(variable); | ||
id | ||
} | ||
// TODO: support `crate::TypeInner::Matrix` |
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.
Please don't add TODO comments. Issues are easier to track, prioritize, and assign. Adding a comment that mentions an issue number is fine, if you like. (I know there are lots of other extant TODOs; the confusion is our fault.)
I'll fix this one myself.
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.
Overall, this looks really reasonable. Not approving yet because:
- I have some more tweaks I want to push
- I haven't actually looked over the test changes yet.
I should be able to finish those tomorrow morning.
naga/src/back/spv/writer.rs
Outdated
let pointer_type_id = self.id_gen.next(); | ||
Instruction::type_pointer( | ||
pointer_type_id, | ||
spirv::StorageClass::Function, | ||
container_type_id, | ||
) | ||
.to_words(&mut self.logical_layout.declarations); |
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.
It turns out that, if the thing being indexed is a TypeInner::Array
, that will never be a TypeResolution::Local
, there will always be a Handle
. So if we change this to expect a Handle<Type>
instead of container_resolution
, we can use get_pointer_id
here as well.
I have a change that does this (and documents TypeResolution::Local
a bit better) which I'll push to the branch tomorrow.
block.body.push(Instruction::load( | ||
result_type_id, | ||
id, | ||
element_pointer_id, | ||
None, | ||
)); |
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 doing things this way means that, if we have something like:
fn (aaa: array<array<array<f32, 3>, 3> 3>, i: i32, j: i32, k: i32) -> f32 {
return aaa[i][j][k];
}
then we'll end up spilling each intermediate array into its own SPIR-V variable, even though we could handle the access normally once we've spilled the outermost thing.
I don't have the wits at the moment to fix this. It's probably fine to address it in a follow-up PR.
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.
+1 for iterating! 😀
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.
Indeed.
Connections
For arrays, at least, this fixes #4337, second commit is just gfx-rs/naga#723 ported to trunk.
Description
See commits and linked PR.
Testing
There are some new tests and I did CTS run in servo.
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.