Skip to content

Conflicting Output Location Assignment #481

Description

@marstaik

Expected Behaviour

I've used multiple vertex -> fragment outputs before with simpler data structures, but my attempt to pass two &mut Struct seem to be failing with conflicting output locations.

Example & Steps To Reproduce

Relevant source code:

pub struct BlinnPhongMaterialData {
	pub albedo:            Vec4,
	pub specular_color:    Vec4,
	pub shininess:         f32,
	pub specular_strength: f32,
}

pub struct BlinnPhongVertexData {
	pub position: Vec4,
	pub normal:   Vec4,
	pub view_dir: Vec4,
}

#[spirv(vertex)]
#[scene_descriptors]
pub fn blinn_phong_material_vert(
	#[camera] cameras: &[Camera],
	#[instance_data] instance_data: &[InstanceData],
	#[material_data] material_data: &[BlinnPhongMaterialData],
	#[spirv(instance_index)] instance_index: usize,
	// vert
	vertex: PositionNormal,
	// outputs
	out_vertex: &mut BlinnPhongVertexData,
	out_material: &mut BlinnPhongMaterialData,
	#[spirv(position)] out_pos: &mut Vec4,
) {
	// Irrelevant body, occurs even when fully commented out
}

#[spirv(fragment)]
#[scene_descriptors]
pub fn blinn_phong_material_frag(
	#[framebuffer_info] framebuffer_info: &FramebufferInfo,
	#[ambient_lights] ambient_lights: &[AmbientLight],
	#[directional_lights] directional_lights: &[DirectionalLight],
	#[point_lights] point_lights: &[PointLight],
	#[spot_lights] spot_lights: &[SpotLight],
	// outputs
	vertex: BlinnPhongVertexData,
	#[spirv(flat)] material: BlinnPhongMaterialData,
	// frag
	frag_color: &mut Vec4,
) {
	// Irrelevant
}

System Info

  • RustGpu - main e97524f6b4816056b3edaa70c3e0e0c656392c05
  • Rust: rustc 1.90.0-nightly (35f603652 2025-06-29)
  • OS: fedora
  • GPU: NVIDIA RTX 4090
  • SPIR-V: SPIRV-Tools v2025.4 v2025.4-0-g7f2d9ee9

Backtrace

error: failed to run custom build command for `rtd_scene v0.1.0 (/home/marios/proj/rtd/packages/rtd_scene)`

Caused by:
  process didn't exit successfully: `/home/marios/proj/rtd/target/debug/build/rtd_scene-c5f6f38c7d3a83ba/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RUSTGPU_CODEGEN_ARGS
  cargo:rerun-if-env-changed=RUSTGPU_RUSTFLAGS
  cargo:rerun-if-env-changed=RUSTGPU_CARGOFLAGS

  --- stderr
     Compiling rtd_scene_shaders v0.1.0 (/home/marios/proj/rtd/packages/rtd_scene_shaders)
  error: [VUID-StandaloneSpirv-OpEntryPoint-08722] Entry-point has conflicting output location assignment at location 1, component 0
    |
    = note: module `/home/marios/proj/rtd/target/spirv-builder/spirv-unknown-vulkan1.2/release/deps/rtd_scene_shaders.spv`

  warning: an unknown error occurred
    |
    = note: spirv-opt failed, leaving as unoptimized
    = note: module `/home/marios/proj/rtd/target/spirv-builder/spirv-unknown-vulkan1.2/release/deps/rtd_scene_shaders.spv`

  error: error:0:0 - [VUID-StandaloneSpirv-OpEntryPoint-08722] Entry-point has conflicting output location assignment at location 1, component 0
           OpEntryPoint Vertex %2 "materials::blinn_phong_material::blinn_phong_material_vert" %cameras %instance_data %material_data %instance_index %vertex %out_material %out_vertex %out_pos
    |
    = note: spirv-val failed
    = note: module `/home/marios/proj/rtd/target/spirv-builder/spirv-unknown-vulkan1.2/release/deps/rtd_scene_shaders.spv`

  warning: `rtd_scene_shaders` (lib) generated 1 warning
  error: could not compile `rtd_scene_shaders` (lib) due to 2 previous errors; 1 warning emitted
  Error: BuildFailed

Activity

  1. Firestar99 commented on Dec 7, 2025

    @Firestar99
    Member

    I'm aware that this is an issue for a while, but haven't gotten around to fixing it. Basically, we're assigning a new output location for each output parameter, regardless of it's size, even though for every Vec4 you output it should increase by one. Also you can''t manually overwrite output locations, so there's no way currently to emit two structs that are larger than Vec4. You can only decompose one of the structs into Vec4 and recompose it in the fragment shader.
    I'm also unsure how easy it is to fix, since the entry point interface code needs refactoring anyway, so if possible, I may delay fixing this until it is rewritten.

  2. marstaik commented on Dec 7, 2025

    @marstaik
    Author

    So, I realize an option here is to combine the two outputs into a parent structure here, but the issue is I cant seem to slap #[spirv(flat)] or other attributes inside the output struct - e.g.

    pub struct CombinedOut {
     #[spirv(flat)] // Cant figure out how to do this
      material: BlinnPhongMaterialData;
      vertex: BlinnPhongVertexData;
    }

    I could unblock a bit if I could figure it out, but nothing I've tried so far helps in this case

  3. Firestar99 commented on Dec 7, 2025

    @Firestar99
    Member

    You also can't use #[spirv(flat)] within a struct, needs to be used directly on an entry point param. Ran into this exact issue myself previously, though could get away with a single flat u32. I'll have a look tomorrow, maybe this is more trivial to fix than I think it is, the current entry point code is just a bit of a mess.

    Yea... the current situation isn't great, we really need a rethink on the entry point interface. Arguably even more important is a proper a model on what things can and cannot be read / written to a buffer, passed to a fragment shader, or pushed through subgroup intrinsics. So far we're only solved the latter.

  4. Firestar99 commented on Dec 8, 2025

    @Firestar99
    Member

    This was a surprisingly trivial fix, please try this branch: #482

    spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", branch = "location-assignment" }
    spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", branch = "location-assignment" }
    

    (or if you're using cargo-gpu, ignore the spirv-builder dep)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions