这是indexloc提供的服务,不要输入任何密码
Skip to content

Compile time NaN support (Not a Number) #5316

@JD31

Description

@JD31

WGSL does not provide a NaN constant.
However, many behaviours around NaN are defined by the specification and one developer might want to use them on purpose.
In particular, it is defined behaviour to set a position to NaN from the vertex shader -> that results in the primitive culling.
My concern is that if I want to provoke this behaviour I would write something like:

const NaN: f32 = 0. / 0.;    // or bitcast<f32>(0x7fc00000u)

fn vs_main(in: VertexInput, @builtin(vertex_index) vertexIndex : u32) -> VertexOutput {
    var out: VertexOutput;

    if (...my cull condition...) {
        out.position.x = NaN;
        return out;
    }

    ... normal behaviour ...
}

That does not compile because it is not legal to create a NaN at compile time.
Of course I can make it runtime but it is a waste of performance...

Can a NaN constant be introduced ? or what workround can I use to create it ?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestA request for a new GPU feature exposed in the APIwgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions