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

Bitfields dependant on templates don't realize they're supposed to be one field #7131

Open
devshgraphicsprogramming opened this issue Feb 7, 2025 · 1 comment
Labels
bug Bug, regression, crash hlsl2021 Pertaining to HLSL2021 features
Milestone

Comments

@devshgraphicsprogramming

Description

The following struct

template<typename T, uint32_t OutputBits>
struct result_t
{
    static result_t invalid()
    {
        result_t retval;
        retval.exclusivePrefixSum = retval.outputIndex = ~0u;
        return retval;
    }

    T outputIndex : OutputBits;
    T exclusivePrefixSum : (sizeof(T)*8-OutputBits);
};

Steps to Reproduce

SPIR-V
https://godbolt.org/z/GTc3do6od

Its not a BDA only issue, for interpolants it also gets confused
https://godbolt.org/z/KK1G8czqq

I think the DXIL codegen is also wrong
https://godbolt.org/z/cPohsxvYa

Actual Behavior

The codegen results in

%result_t = OpTypeStruct %uint %uint

for the function definition, and

OpCompositeExtract %uint %20 1

for the access on exclusivePrefixSum.

The codegen treats the two bitfields as separate values.

The DXIL is also wrong

  %1 = call i32 @dx.op.loadInput.i32(i32 4, i32 1, i32 0, i8 0, i32 undef), !dbg !58
  %2 = call i32 @dx.op.loadInput.i32(i32 4, i32 0, i32 0, i8 0, i32 undef), !dbg !58

Declaring the struct as

    T outputIndex : 7;
    T exclusivePrefixSum : (32-7);

doesn't introduce this issue.

Environment

  • DXC version
  • Host Operating System <!--- Host operating system and version --->
@devshgraphicsprogramming devshgraphicsprogramming added bug Bug, regression, crash needs-triage Awaiting triage spirv Work related to SPIR-V labels Feb 7, 2025
@devshgraphicsprogramming
Copy link
Author

SpIR-V tag should be removed

@damyanp damyanp added hlsl2021 Pertaining to HLSL2021 features and removed spirv Work related to SPIR-V needs-triage Awaiting triage labels Feb 11, 2025
@damyanp damyanp moved this to Triaged in HLSL Triage Feb 11, 2025
@damyanp damyanp added this to the Dormant milestone Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash hlsl2021 Pertaining to HLSL2021 features
Projects
Status: Triaged
Development

No branches or pull requests

2 participants