Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

SampledImages in closest hit shaders doesn't compile #754

@expenses

Description

@expenses

Hey. I'm loving how rust-gpu is coming along and I've been managed to most of my ray-tracing shaders compiling, apart from the closest hit one.

Expected Behaviour

Using SampledImages in fragment shaders works fine, but doing the same thing but in a closest hit shader (the only difference being the use of #[spirv(incoming_ray_payload)]) results in a validation error:

error: error:0:0 - OpEntryPoint Entry Point <id> '1[%1]'s callgraph contains function
 <id> 9[%_spirv_std__image__SampledImage_spirv_std__image__Image_f32___spirv_types__i
mage_params__Dimensionality__TwoD____spirv_types__image_params__ImageDepth__Unknown__
__spirv_types__image_params__Arrayed__False____spirv_types__image_params__Multisample
d__False____spirv_types__image_params__Sampled__Yes____spirv_types__image_params__Ima
geFormat__Unknown____core__option__Option___spirv_types__image_params__AccessQualifie
r___None______sample___f32__glam__vec4__Vec4__glam__vec2__Vec2_], which cannot be use
d with the current execution model:
  |
  = note: spirv-val failed

Example & Steps To Reproduce

Shader code that produced the error:

#![cfg_attr(
    target_arch = "spirv",
    feature(register_attr),
    register_attr(spirv),
    no_std
)]
#![feature(asm)]

// This needs to be here to provide `#[panic_handler]`.
extern crate spirv_std;

#[cfg(not(target_arch = "spirv"))]
use spirv_std::macros::spirv;

use spirv_std::glam::{Vec2, Vec4};

use spirv_std::{
    image::SampledImage,
    Image,
};

#[spirv(closest_hit)]
pub fn xyz(
    #[spirv(descriptor_set = 0, binding = 0)] texture: &SampledImage<
        Image!(2D, type=f32, sampled=true),
    >,
    #[spirv(incoming_ray_payload)] output: &mut Vec4,
) {
    let uv = Vec2::splat(0.0);
    *output = unsafe { texture.sample(uv) };
}

Which was compiled with the following spirv-builder setup:

SpirvBuilder::new("shaders/testshader", "spirv-unknown-spv1.4")
        .print_metadata(MetadataPrintout::None)
        .extension("SPV_KHR_ray_tracing")
        .capability(spirv_builder::Capability::RayTracingKHR)
        .capability(spirv_builder::Capability::Int8)
        .capability(spirv_builder::Capability::Int64)
        .multimodule(false)
        .build()
        .unwrap()

Alternatively,

  1. Checkout https://github.com/expenses/ray-tracing-gallery/commit/77f7155fe5bb24a03161bde5580a95aa6e42085e.
  2. Uncomment these lines: https://github.com/expenses/ray-tracing-gallery/blob/77f7155fe5bb24a03161bde5580a95aa6e42085e/shaders/ray-tracing/src/lib.rs#L154-L159
  3. Run ./compile_shaders.bat or, on linux, copy rust-toolchain into the repo and run cargo run -p compile-shaders --release.

System Info

spirv-std/spirv-builder commit: 35172f7.

Rust version: nightly-2021-08-27-x86_64-pc-windows-msvc.

spirv-val --version
SPIRV-Tools v2021.3 v2021.3
Targets:
  SPIR-V 1.0
  SPIR-V 1.1
  SPIR-V 1.2
  SPIR-V 1.3
  SPIR-V 1.4
  SPIR-V 1.5
  SPIR-V 1.2 (under OpenCL 2.2 Full Profile semantics)
  SPIR-V 1.0 (under Vulkan 1.0 semantics)
  SPIR-V 1.3 (under Vulkan 1.1 semantics)
  SPIR-V 1.4 (under Vulkan 1.1 semantics)
  • Rust: nightly-2021-08-27-x86_64-pc-windows-msvc
  • OS: Windows 10.0.19042 Build 19042

Metadata

Metadata

Assignees

No one assigned

    Labels

    t: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions