Skip to content
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

SampledImages in closest hit shaders doesn't compile #754

Closed
expenses opened this issue Sep 23, 2021 · 3 comments
Closed

SampledImages in closest hit shaders doesn't compile #754

expenses opened this issue Sep 23, 2021 · 3 comments
Labels
t: bug Something isn't working

Comments

@expenses
Copy link
Contributor

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:/expenses/ray-tracing-gallery/commit/77f7155fe5bb24a03161bde5580a95aa6e42085e.
  2. Uncomment these lines: https:/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
@expenses expenses added the t: bug Something isn't working label Sep 23, 2021
@msiglreith
Copy link
Contributor

this is correctly flagged by spirv-val as sample operations with implicit lod calculations are only valid in a fragment shader context. you need to use a sample function which specifies the lod explicitly.

@expenses
Copy link
Contributor Author

@msiglreith Ah, I see! I was wondering why my glsl shader worked fine without setting the lod, but it turns out that glslc outputs OpImageSampleExplicitLod if sample is used in a closest hit shader. SampledImage has no sample_by_lod function, so I'll go make a PR for that.

@expenses
Copy link
Contributor Author

expenses commented Oct 8, 2021

We can close this now as #755 has been merged. The error message that you get when trying to sample with an implicit LOD is still unclear though. Perhaps we should create an issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants