- 
                Notifications
    
You must be signed in to change notification settings  - Fork 246
 
Implement OpTypeMatrix #738
Changes from all 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,12 @@ | ||
| // Tests that matrix type inference fails correctly, for empty struct | ||
| // build-fail | ||
| 
     | 
||
| use spirv_std as _; | ||
| 
     | 
||
| #[spirv(matrix)] | ||
| pub struct _EmptyStruct {} | ||
| 
     | 
||
| #[spirv(fragment)] | ||
| pub fn _entry() { | ||
| let _empty_struct = _EmptyStruct {}; | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| error: #[spirv(matrix)] type must have at least two fields | ||
| --> $DIR/invalid-matrix-type-empty.rs:7:1 | ||
| | | ||
| 7 | pub struct _EmptyStruct {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 
     | 
||
| error: aborting due to previous error | ||
| 
     | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Tests that matrix type inference fails correctly | ||
| // build-fail | ||
| 
     | 
||
| use spirv_std as _; | ||
| 
     | 
||
| #[spirv(matrix)] | ||
| pub struct _FewerFields { | ||
| _v: glam::Vec3, | ||
| } | ||
| 
     | 
||
| #[spirv(matrix)] | ||
| pub struct _NotVectorField { | ||
| _x: f32, | ||
| _y: f32, | ||
| _z: f32, | ||
| } | ||
| 
     | 
||
| #[spirv(matrix)] | ||
| pub struct _DifferentType { | ||
| _x: glam::Vec3, | ||
| _y: glam::Vec2, | ||
| } | ||
| 
     | 
||
| #[spirv(fragment)] | ||
| pub fn _entry(_arg1: _FewerFields, _arg2: _NotVectorField, _arg3: _DifferentType) {} | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| error: #[spirv(matrix)] type must have at least two fields | ||
| --> $DIR/invalid-matrix-type.rs:7:1 | ||
| | | ||
| 7 | / pub struct _FewerFields { | ||
| 8 | | _v: glam::Vec3, | ||
| 9 | | } | ||
| | |_^ | ||
| 
     | 
||
| error: #[spirv(matrix)] type fields must all be vectors | ||
| --> $DIR/invalid-matrix-type.rs:12:1 | ||
| | | ||
| 12 | / pub struct _NotVectorField { | ||
| 13 | | _x: f32, | ||
| 14 | | _y: f32, | ||
| 15 | | _z: f32, | ||
| 16 | | } | ||
| | |_^ | ||
| | | ||
| = note: field type is f32 | ||
| 
     | 
||
| error: #[spirv(matrix)] type fields must all be the same type | ||
| --> $DIR/invalid-matrix-type.rs:19:1 | ||
| | | ||
| 19 | / pub struct _DifferentType { | ||
| 20 | | _x: glam::Vec3, | ||
| 21 | | _y: glam::Vec2, | ||
| 22 | | } | ||
| | |_^ | ||
| 
     | 
||
| error: aborting due to 3 previous errors | ||
| 
     | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // 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_attrs( | ||
| #[spirv(object_to_world)] _object_to_world: Affine3, | ||
| #[spirv(world_to_object)] _world_to_object: Affine3, | ||
| ) { | ||
| } | ||
| 
         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. 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  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 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   | 
||
| 
     | 
||
| #[spirv(fragment)] | ||
| pub fn main_default(out: &mut Affine3) { | ||
| *out = Affine3::default(); | ||
| } | ||
| 
     | 
||
| #[spirv(fragment)] | ||
| pub fn main_add(affine3: Affine3, out: &mut glam::Vec3) { | ||
| *out = affine3.x + affine3.y + affine3.z + affine3.w; | ||
| } | ||
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