-
Notifications
You must be signed in to change notification settings - Fork 73
Erase explicit layout decorations (Offset
/ArrayStride
) when disallowed by Vulkan.
#379
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
base: main
Are you sure you want to change the base?
Erase explicit layout decorations (Offset
/ArrayStride
) when disallowed by Vulkan.
#379
Conversation
0fd77cb
to
707bdcc
Compare
53cf51d
to
8d01e85
Compare
8d01e85
to
84ed68f
Compare
I just want to note that you're upgrading CI's Vulkan SDK to 1.4.321.0, but |
@Firestar99 I 100% agree, that's why I still have the above quoted bit in the PR description, and it's why this PR was in draft state even before rebasing it on top of #400 (I know it'd be slower but it'd be nice to test EDIT: fixed the |
84ed68f
to
5a77372
Compare
As the I was able to get 10 failures in diff --git a/Cargo.toml b/Cargo.toml
index 7cf09984100..9da910407c9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -49,3 +49,3 @@ spirv-std-types = { path = "./crates/spirv-std/shared", version = "=0.9.0" }
spirv-std-macros = { path = "./crates/spirv-std/macros", version = "=0.9.0" }
-spirv-tools = { version = "0.12.1", default-features = false }
+spirv-tools = { version = "0.12.1", git = "https://github.com/Rust-GPU/spirv-tools-rs", default-features = false }
rustc_codegen_spirv = { path = "./crates/rustc_codegen_spirv", version = "=0.9.0", default-features = false }
diff --git a/crates/rustc_codegen_spirv/src/linker/mod.rs b/crates/rustc_codegen_spirv/src/linker/mod.rs
index d289c8e5fce..89c46e11f03 100644
--- a/crates/rustc_codegen_spirv/src/linker/mod.rs
+++ b/crates/rustc_codegen_spirv/src/linker/mod.rs
@@ -564,3 +564,3 @@ pub fn link(
- {
+ if false {
let timer = before_pass("spirt_passes::explicit_layout::erase_when_invalid"); Re-enabling the pass (removing So we should be able to land this once we release another version of |
Should I release spirv-tools for you? |
Yes, that would be great, thanks! |
(welp and I completely missed your message) Anyway, I thought I'd give spirv-tools some love before we release: Afterwards, a release should just be a trivial |
5a77372
to
9b425ac
Compare
This is very confusing. It doesn't seem to actually ignore the cache if it's the wrong version. Not sure why only Linux seems to be affected. Will purge GHA caches for old version and see what happens. |
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 feel like I can't really comment too much on the code, as I'm totally unfamiliar with spirt. I should probably start reading into the library a bit at some point, since I assume most of our current passes will eventually end up in spirt anyway.
let wk = self.wk; | ||
|
||
// FIXME(eddyb) this might need to include `Workgroup`, specifically when | ||
// `WorkgroupMemoryExplicitLayoutKHR` is being relied upon. |
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.
Shouldn't Workgroup be in this list, as #266 shows the declarations need to be removed? I'd be fine not supporting WorkgroupMemoryExplicitLayoutKHR
for the moment, haven't heard of the extension myself nor anyone using it. If somebody wants support, we can always add it later.
- VK extension: https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#VK_KHR_workgroup_memory_explicit_layout
- Coverage 25.68% 74.32% is quite good
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.
The list is for the storage classes that allow and/or require the "explicit layout" (Offset
/ArrayStride
) decorations.
So everything missing here (like Function
, Private
, Workgroup
, or weird storage classes used only within raytracing pipelines etc.) will have the decorations removed.
Maybe it's a bit confusing that the calls to this method look like:
!self.addr_space_allows_explicit_layout(...)
But it's fundamentally a small set of storage classes for which the decoderations are allowed:
This chapter describes valid uses for a set of SPIR-V decorations. Any other use of one of these decorations is invalid,
(from https://docs.vulkan.org/spec/latest/chapters/interfaces.html - Ctrl+F ArrayStride
on that page to find all the instances where they explicitly allow - or rather, require - explicit layout)
} | ||
} | ||
|
||
fn in_place_transform_global_var_decl(&mut self, gv_decl: &mut GlobalVarDecl) { |
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.
spirt question: I don't fully understand why some visitor functions are *_in_place
and others are not and returned Transformed<T>
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.
It's a combination of 2-3 things:
- wanting
Transformed
's distinction of whether a chance is actually needed, to bypass work
(but that requires by-value returns to avoid misuse) - anything interned (
AttrSet
/Const
/Type
) can't do in-place mutation
(so they use&FooDef -> Transformed<FooDef>
+ only re-interning when changed) - module-owned entities (
GlobalVar
/Func
and intra-func regions/nodes) can do in-place mutation
(and cloning the whole definition to return it viaTransformed
would be prohibitively expensive)
assert_eq!(sc_kind, wk.StorageClass); | ||
!self.addr_space_allows_explicit_layout(AddrSpace::SpvStorageClass(sc)) | ||
} | ||
_ => unreachable!(), |
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.
spirt question: I also have no idea if this unreachable is actually unreachable, or how exactly imms
and type_and_const_inputs
works, since they're unfortunately not documented.
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.
A SPIR-V "immediate" (in the spirt::spv::Imm
sense) is similar to rspirv::dr::Operand
w/o the Id
variants (as SPIR-V IDs always correspond to some Type
/Const
/GlobalVar
/Func
/etc. interned/owned entity in SPIR-T - in the case of types, type_and_const_inputs
lets them refer to other Type
s and/or Const
s, through SPIR-V IDs, but nothing else).
So hitting this unreachable!()
would require interning a type with a spirt::TypeKind::SpvInst
that:
- couldn't naturally be produced by SPIR-V -> SPIR-T (
spirt::spv::lower
) - would fail SPIR-T -> SPIR-V (
spirt::spv::lift
) - might error/panic in other parts of SPIR-T (that e.g. decode a
spv::Inst
'sspv::Imm
s according to the SPIR-V "grammar")
let is_explicit_layout_decoration = match attr { | ||
Attr::SpvAnnotation(attr_spv_inst) | ||
if (attr_spv_inst.opcode == wk.OpDecorate | ||
&& [wk.ArrayStride, wk.MatrixStride] |
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.
Oh, phew, I was worried this only mentioned ArrayStride
, but I did include MatrixStride
just in case (I guess the one instance of non-explicit-layout matrices would have to bein the context of raytracing pipelines - e.g. Ctrl+F "matrix" on https://github.khronos.org/SPIRV-Registry/extensions/KHR/SPV_KHR_ray_tracing.html - though an even simpler example is just a local variable containing a matrix).
More recent Vulkan SDK versions have started complaining about types having explicit memory layout, when used with memory that doesn't inherently require explicit layouts (only push constants and buffers really do), e.g.:
The solution used here is simpler and more specialized (a pass that erases the explicit layout decorations from types behind pointers in storage classes that don't support them, combined with updating affected loads/stores) than what I originally described in #266 (comment), so we can hopefully use this for now and not worry about
spirt::{mem,qptr}
for the next release.(not actually tested with MoltenVK, we should make sure it actually works now)