-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make include_spirv!
actually work statically
#8250
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
Conversation
|
||
assert_eq!( | ||
words[0], MAGIC_NUMBER, | ||
"wrong magic word {:x}. Make sure you are using a binary SPIRV file.", |
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.
Unfortunately, we lose the ability to output the magic number here, since formatting doesn't work in constants. While there are workarounds that work with the current MSRV like the const_panic
crate, I decided that this isn't a massive loss and it was better to not add more dependencies.
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.
Looking great, thanks for adding all those tests!
Albeit, see comment, to keep in line with the rest I think we should arrange this differently
The latest commit removes the test binary and splits the tests across the |
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.
nice!
Description
Right now,
include_spirv!
cannot be used to directly define astatic
variable with the shader due to thewgpu::util::make_spirv_raw
function not being const. This updates the macro to use an alternative implementation compatible with the current MSRV policy.Note that the
make_spirv_raw
function is still not const because it accepts arbitrary input which may not be aligned, and thus allocates a new buffer for unaligned input. Instead, we use a separate function for the macros which can guarantee the alignment of the bytes being included.Testing
Previously, this macro was not tested at all, and actually,
include_spirv_raw
had broken due to a change in the definition ofShaderModuleDescriptorPassthrough
. Now, bothinclude_spirv
andinclude_spirv_raw
are tested with a tiny "shader" file (it just contains the magic number + 0x11223344) to verify that the macros actually include a valid struct, and a proper test for the functionality is added to awgpu-include-spirv
test crate.Squash or rebase? Squash.
Checklist
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.