-
Notifications
You must be signed in to change notification settings - Fork 246
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
Dynamic indexing into a StorageBuffer's contents won't compile #270
Comments
There is this section in rustc_codegen_spirv/codegen_cx/constant.rs:
The comment seems to indicate that constant pointers cause an issue, but suggests it applies to kernel mode. Perhaps this can be fixed, at least amended to allow this in "shader" mode? I tested it without the zombie and all the tests passed, but I don't know if that's valid. |
I do not believe it is valid to create a OpTypeRuntimeArray via OpConstantComposite - further, I don't believe there is any way to create an OpTypeRuntimeArray in user code, all values of the type must come externally. If I'm mistaken, great, but I believe that removing that zombie is incorrect. Also, kernel mode is generally far more permissive than shader mode, so if something doesn't work in kernel mode, it's highly unlikely to work in shader mode. |
I was a bit unsure if I should create this issue because one fairly likely explanation is that I was just doing something that's impossible. @khyperia I'm not quite sure if that's what you're saying or not. I think part of what confused me about this error message though was it wasn't obvious to me why a |
No, filing the issue was the right thing, thanks for filing it! I was more responding to @charles-r-earp than the original issue. And yeah, same, I'm not sure why a |
I did some more looking into this. I think then diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
index ae6f9773a..4b6a72f08 100644
--- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
+++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
@@ -263,6 +263,11 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> {
other.debug(ty, self)
)),
};
+ let pointee_type = self.lookup_type(pointee);
+ if let SpirvType::RuntimeArray{ element } = pointee_type {
+ let element_type = self.lookup_type(element);
+ println!("constant pointer to RuntimeArray<{:?}>", element_type);
+ }
let init = self.create_const_alloc(alloc, pointee);
let value = self.static_addr_of(init, alloc.align, None);
(value, AddressSpace::DATA)
@@ -394,11 +399,13 @@ impl<'tcx> CodegenCx<'tcx> {
size,
field_types,
field_offsets,
+ name,
..
} => {
let base = *offset;
let mut values = Vec::with_capacity(field_types.len());
let mut occupied_spaces = Vec::with_capacity(field_types.len());
+ println!("constant adt {}", name);
for (&ty, &field_offset) in field_types.iter().zip(field_offsets.iter()) {
let total_offset_start = base + field_offset;
let mut total_offset_end = total_offset_start;
diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs
index 92856ab7f..0d5c96a43 100644
--- a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs
+++ b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs
@@ -157,6 +157,7 @@ impl<'tcx> CodegenCx<'tcx> {
if self.is_system_crate() {
self.zombie_values.borrow_mut().insert(word, reason);
} else {
+ println!("non system zombie {}", reason);
self.tcx.sess.err(reason);
}
} This was after adding a backtrace to I got, well a bunch of things, but the last 4 lines were
|
I sort of wonder if this might be what's going on with #211 too, but with basically no evidence |
I traced down at least one of the |
Right, then this is a partial dupe of #186 (comment), strings and therefore panics aren't supported yet. (I'm guessing the panic is happening from generating out-of-bounds-index error path) |
I think this is resolved as of #305 though copying the entire buffer into the shader before indexing into it cause other issues which I ended up resolving by adding a custom
|
Come to think of it I'm not sure that I tested just doing |
Expected Behaviour
The shader to compile with dynamic indexing into a
StorageBuffer
's contentsExample & Steps To Reproduce
Source
I've tried lots of variations of this, but I think this is the clearest. It produces 3 errors and gives up, but none of the errors seem to make sense for this code:
I know this is probably a known limitation, but I didn't find reference to it so I thought I'd mention it.
System Info
Backtrace
Backtrace
The text was updated successfully, but these errors were encountered: