You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpDecorate with Block/BufferBlock isn't working properly #261
I'm working on a basic compiler for converting Rust functions to SPIR-V using proc macros and rspirv (to achieve similar functionality as CUDA)
Error
When compiling buffers to parameters I'm having an issue where the correlating OpTypeStruct (this: %_struct_5 = OpTypeStruct %_runtimearr_float) doesn't actually get decorated with Block despite marking aforementioned type with Block using rspirv.
Code Snippet
This is from withing a struct that uses a handful of hashmaps to store and access variable ids and type ids:
// get word of the type of the elements in the runtime arrlet base_word = self.types.get(arr_ty).ok_or(anyhow!("failed to retrieve base type of runtime arr: {:?}",
arr_ty
))?;// create runtime arr type (pretty simple)let runtime_ty = self.spirv_builder.type_runtime_array(*base_word);// create a struct typelet struct_ty = self.spirv_builder.type_struct(vec![runtime_ty]);self.spirv_builder.decorate(
struct_ty,
rspirv::spirv::Decoration::Block,vec![],);let lit_0 = self.literals.get(&MimirLit::Int32(0)).ok_or(anyhow!("Failed to find literal 0 for struct decoration"))?;self.spirv_builder.member_decorate(
struct_ty,*lit_0,
rspirv::spirv::Decoration::Offset,vec![rspirv::dr::Operand::LiteralBit32(0)]);
SPIR-V
Outputted SPIR-V for my compiler: saxpy.spirv.txt
Because the SPIR-V contains %_runtimearr_float = OpTypeRuntimeArray %float and %_struct_5 = OpTypeStruct %_runtimearr_float the code for generating buffers is being called but the types are not being decorated properly.
which version you are using? Unfortunately I'm unable to open the file, reports an error when trying to download. I put together a small program with rspirv:0.12.0 which outputs the decoration just fine:
use rspirv::binary::{Assemble,Disassemble};use rspirv::spirv;fnmain(){letmut b = rspirv::dr::Builder::new();
b.set_version(1,0);
b.capability(spirv::Capability::Shader);
b.memory_model(spirv::AddressingModel::Logical, spirv::MemoryModel::GLSL450);let ty_f32 = b.type_float(32);let runtime_ty = b.type_runtime_array(ty_f32);let struct_ty = b.type_struct(vec![runtime_ty]);
b.decorate(struct_ty, rspirv::spirv::Decoration::Block,vec![]);
b.member_decorate(
struct_ty,0,// note: this should be an immediate value not an id
rspirv::spirv::Decoration::Offset,vec![rspirv::dr::Operand::LiteralBit32(0)],);let module = b.module();let code = module.assemble();letmut loader = rspirv::dr::Loader::new();
rspirv::binary::parse_words(&code,&mut loader).unwrap();let module = loader.module();println!("{}", module.disassemble());}
I'm using rspirv: 0.12.0 as well, the outputted SPIR-V is as below, I'm unsure what could be causing this. I might have to line by line debug my compiler once I'm out of school.
Activity
msiglreith commentedon Apr 25, 2025
Hi,
which version you are using? Unfortunately I'm unable to open the file, reports an error when trying to download. I put together a small program with
rspirv:0.12.0which outputs the decoration just fine:ccleavinger commentedon Apr 28, 2025
I'm using rspirv: 0.12.0 as well, the outputted SPIR-V is as below, I'm unsure what could be causing this. I might have to line by line debug my compiler once I'm out of school.
Outputted SPIR_V: