-
Notifications
You must be signed in to change notification settings - Fork 246
Implement OpTypeMatrix #738
Changes from 6 commits
114b2ed
458ddb4
36282ca
47b9f92
9dda749
8ec4f2d
cb88ec2
fa0f62a
f564761
75af54f
051b3a3
572d93e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // build-pass | ||
| // compile-flags: -Ctarget-feature=+RayTracingKHR,+ext:SPV_KHR_ray_tracing | ||
|
|
||
| use spirv_std as _; | ||
|
|
||
| #[derive(Clone, Copy)] | ||
| #[spirv(matrix)] | ||
| pub struct Affine3 { | ||
| pub x: glam::Vec3, | ||
| pub y: glam::Vec3, | ||
| pub z: glam::Vec3, | ||
| pub w: glam::Vec3, | ||
| } | ||
|
|
||
| impl Affine3 { | ||
| pub const ZERO: Self = Self { | ||
| x: glam::Vec3::ZERO, | ||
| y: glam::Vec3::ZERO, | ||
| z: glam::Vec3::ZERO, | ||
| w: glam::Vec3::ZERO, | ||
| }; | ||
|
|
||
| pub const IDENTITY: Self = Self { | ||
| x: glam::Vec3::X, | ||
| y: glam::Vec3::Y, | ||
| z: glam::Vec3::Z, | ||
| w: glam::Vec3::ZERO, | ||
| }; | ||
| } | ||
|
|
||
| impl Default for Affine3 { | ||
| #[inline] | ||
| fn default() -> Self { | ||
| Self::IDENTITY | ||
| } | ||
| } | ||
|
|
||
| #[spirv(closest_hit)] | ||
| pub fn main( | ||
| #[spirv(object_to_world)] _object_to_world: Affine3, | ||
| #[spirv(world_to_object)] _world_to_object: Affine3, | ||
| ) { | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this isn't actually testing much due to the majority of it being dead code. (Also, nit, the name I would like to see field accesses/etc. tested as well, I'm nervous about just crossing our fingers and hoping that matricies behave exactly like structs in all ways and no instructions need to be modified to handle matricies specially.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I chose I feel adding more tests for field operations in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! whoops, misread it as 4 Vec4s, not 4 Vec3s, 4 Vec3s definitely is an affine transform, haha, sorry Yeah, not totally sure about where to put tests, anywhere is probably fine
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added tests |
||
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.
You don't have to (and shouldn't) do this digging into field types for this, and should use the standard type translation tools on the fields instead. Also, this is missing quite a bit of validation (e.g. if fields are different types, or there are no fields - IIRC your code ICEs if there's no fields) - there should be tests for each of the three kinds of error. Something like this should work instead:
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.
Thanks.
I updated the code and change Matrix length validation since
OpTypeMatrixrequires a length of at least 2.https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#OpTypeMatrix