rust-gpu icon indicating copy to clipboard operation
rust-gpu copied to clipboard

Ray tracing position fetch support

Open atynagano opened this issue 1 year ago • 2 comments

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/HitTriangleVertexPositionsKHR.html

Is it planned, or is there any way to use such a extension?

atynagano avatar Sep 12 '23 05:09 atynagano

    use core::arch::asm;
    use spirv_std::glam::Vec3;

    #[spirv_std::macros::gpu_only]
    pub fn get_positions() -> [Vec3; 3] {
        unsafe {
            let mut result: [Vec3; 3] = Default::default();
            asm! {
                "%f32 = OpTypeFloat 32",
                "%f32x3 = OpTypeVector %f32 3",
                // OpTypeArray in asm! is not supported yet
                // "%f32x3x3 = OpTypeArray %f32x3 3",
                "%f32x3x3 = OpTypeMatrix %f32x3 3",
                "%ptr_f32x3x3 = OpTypePointer Generic %f32x3x3",
                "%positions = OpVariable %ptr_f32x3x3 Input",
                "OpDecorate %positions BuiltIn HitTriangleVertexPositionsKHR",
                "%result = OpLoad %f32x3x3 %positions",
                "OpStore {result} %result",
                result = in(reg) &mut result,
            }
            result
        }
    }

I tried the above code and got the error message error: unknown BuiltIn HitTriangleVertexPositionsKHR. So I think rspirv needs to support it first. (I am not familiar with spirv so this code may be wrong to begin with.)

atynagano avatar Sep 23 '23 15:09 atynagano

Seems supported in version 0.12.

atynagano avatar Apr 05 '24 12:04 atynagano