Skip to content

[Migrated] NonUniform decoration support #120

Open
@rust-gpu-bot

Description

@rust-gpu-bot

Issue automatically imported from old repo: EmbarkStudios/rust-gpu#756
Old labels: t: enhancement,s: qptr may fix
Originally creatd by expenses on 2021-09-25T11:44:25Z


Occasionally, a shader variable requires the NonUniform decoration. One example of this is when doing a texture lookup in a ray-tracing shader, where the texture index might not be uniform with the neighbouring rays. See: https://github.com/expenses/ray-tracing-gallery/blob/cb0cb06cc60a5632150e606261a02ba26862ac09/shaders/closesthit.glsl#L136-L138.

I've attempted to do this with asm!:

#[spirv(descriptor_set = 0, binding = 1)] textures: &RuntimeArray<SampledImage<
    Image!(2D, type=f32, sampled=true),
>>,
...

unsafe {
    asm! {
        "OpDecorate {} NonUniform",
        in(reg) &texture_index
    }
};

let uv = Vec2::splat(0.0);
let texture = unsafe {
    textures.index(texture_index as usize)
};
let colour: Vec4 = unsafe { texture.sample_by_lod(uv, 0.0) };

but the decoration wasn't included in the final SPIR-V module. Perhaps it was optimized out? The u32 -> usize conversion that is needed for accessing indexing RuntimeArrays could be a problem as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions