-
Notifications
You must be signed in to change notification settings - Fork 937
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
[spv-in] Add support for structs that contain pointers #6623
Comments
This is because naga doesn't allow structs to contain pointers. |
Type [34] '' is invalid
, mysterious SPIRV validation error
Thank you. Do you think a good first step would just be to improve the error? Just out of curiosity, this does validate, even though the Rust code has a pointer in a struct: #![cfg_attr(target_arch = "spirv", no_std)]
use spirv_std::{glam::Vec2, spirv};
pub struct Cell<'world> {
pub positions: &'world mut [Vec2],
}
impl Cell<'_> {
pub fn physics_for_cell(&mut self) {
self.positions[0] = Vec2::new(0.1, 0.1);
}
}
#[spirv(compute(threads(1)))]
pub fn main(#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] positions: &mut [Vec2]) {
let mut cell = Cell { positions };
cell.physics_for_cell();
} But I suspect that's because Rust compiles down to SPIR-V without a pointer in a struct? ; SPIR-V
; Version: 1.3
; Generator: Google rspirv; 0
; Bound: 28
; Schema: 0
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint GLCompute %1 "main"
OpExecutionMode %1 LocalSize 1 1 1
OpDecorate %_runtimearr_v2float ArrayStride 8
OpDecorate %_struct_6 Block
OpMemberDecorate %_struct_6 0 Offset 0
OpDecorate %4 Binding 0
OpDecorate %4 DescriptorSet 0
%void = OpTypeVoid
%8 = OpTypeFunction %void
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%_runtimearr_v2float = OpTypeRuntimeArray %v2float
%_struct_6 = OpTypeStruct %_runtimearr_v2float
%_ptr_StorageBuffer__struct_6 = OpTypePointer StorageBuffer %_struct_6
%4 = OpVariable %_ptr_StorageBuffer__struct_6 StorageBuffer
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%float_0_100000001 = OpConstant %float 0.100000001
%bool = OpTypeBool
%_ptr_StorageBuffer_v2float = OpTypePointer StorageBuffer %v2float
%27 = OpConstantComposite %v2float %float_0_100000001 %float_0_100000001
%1 = OpFunction %void None %8
%18 = OpLabel
%20 = OpArrayLength %uint %4 0
%22 = OpULessThan %bool %uint_0 %20
OpSelectionMerge %23 None
OpBranchConditional %22 %24 %25
%24 = OpLabel
%26 = OpAccessChain %_ptr_StorageBuffer_v2float %4 %uint_0 %uint_0
OpStore %26 %27
OpBranch %23
%25 = OpLabel
OpBranch %23
%23 = OpLabel
OpReturn
OpFunctionEnd So I suspect it's not enough to just not use pointers in structs in |
For sure, some of the validator errors are lacking.
In that case the codegen is different, which avoids the issue.
Maybe, but not using pointers in structs is a lot more likely to work (with naga). |
I'm writing a physics compute shader with
rust-gpu
. Recently I tried adding Workgroup support, but I ran into this issue withnaga
validation:I'm using Bevy 0.14.1 that depends on
naga
0.20.0. But I can reproduce the error withnaga-cli
on trunk.I've managed to get a minimal reproducible
rust-gpu
shader that cross-compiles to a small GLSL shader:And so the validation error now is:
How do I dump the Naga representation? Would that be an internal WGSL version? Here's the GLSL version from
spirv-cross
(I don't know if the variable/type numbers match up with Naga's?). Anyway, looking at this version, type 7 could be the workgroup type:shared vec2 _7[1];
. But for some reason my hunch is that the problem is the struct in struct in type 6, therefore:struct _6 { _5 _m0 ...
GLSL:
And here's the SPIR-V:
I originally posted this as a discussion at #6361
The text was updated successfully, but these errors were encountered: