Skip to content

[SPIR-V] Invalid SPIR-V operand with isnan() #6712

Closed

Description

@shobomaru

Description
DXC generates an invalid SPIR-V

Steps to Reproduce

dxc -T cs_6_0 -spirv path/to/file.hlsl

HLSL code:

RWStructuredBuffer<float> Out;
[numthreads(1, 1, 1)]
void main(uint id : SV_DispatchThreadID)
{
        bool bar = isnan(Out[id]);
        Out[id] = (float)bar;
}

If we change the code as follows, the issue is not occurred.

        float baz = Out[id];
        Out[id] = (float)isnan(baz);

Actual Behavior

fatal error: generated SPIR-V is invalid: Expected bool scalar or vector type as Result Type: IsNan
%23 = OpIsNan %uint %22
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Environment

  • DXC version: libdxcompiler.dylib: 1.8(dev;4640-45018c75)
  • Host Operating System: Windows 11 23H2 and macOS 14.5

Activity

  1. added
    bug
    needs-triage
    spirv
    on Jun 20, 2024
  2. devshgraphicsprogramming commented on Jun 21, 2024

    @devshgraphicsprogramming

    If you're interested in a quick fix, you can use inline SPIR-V to use OpIsNan directly

  3. shobomaru commented on Jun 21, 2024

    @shobomaru
    Author

    Indeed, by defining a new function as follows, we can pass the validation.

    [[vk::ext_instruction(156)]]
    bool alt_isnan(float v1);
    
  4. gorrila007 commented on Jun 22, 2024

    @gorrila007

    RWStructuredBuffer Out;
    [numthreads(1, 1, 1)]
    void main(uint id : SV_DispatchThreadID)
    {
    float value = Out[id];
    bool bar = isnan(value); // Check if 'value' is NaN
    Out[id] = bar ? 1.0f : 0.0f; // Store 1.0f if 'value' is NaN, otherwise 0.0f
    }

  5. added a commit that references this issue on Jul 9, 2024
    535e7c9
  6. Keenuts commented on Jul 9, 2024

    @Keenuts
    Collaborator

    Thanks for the issue! Sent a PR 😊 Most of the team being OOO, there might be some delays, but it's on its way.

  7. moved this from For Google to Triaged in HLSL Triageon Jul 9, 2024
  8. added a commit that references this issue on Jul 19, 2024
    1028410
  9. added a commit that references this issue on Jul 24, 2025
    d89b222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugspirv

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions