microsoft / microsoft/DirectXShaderCompiler

Clarification on WaveActiveBit{And,Or,Xor} for signed integer types

Open
#6,850 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
The HLSL syntax documentation for WaveActiveBitAnd (as well as Or and Xor) is:

<int_type> WaveActiveBitAnd(
   <int_type> expr
);

https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/waveallbitand

This would seem to imply that they accept both signed and unsigned integer overloads, but some signed types result in failures. Is this a bug or intended behavior?

Steps to Reproduce
dxc -T cs_6_6

RWByteAddressBuffer prevent_dce : register(u0);

[numthreads(1, 1, 1)]
void main() {
  int arg = -12345;
  //prevent_dce.Store3(0u, WaveActiveBitAnd(-12345)); // !!! PASSES
  prevent_dce.Store3(0u, WaveActiveBitAnd(arg)); // !!! FAILS
  return;
}

https://godbolt.org/z/3h7szz631

Expected Behavior

Compilation succeeds. WaveActiveBitAnd, Or and Xor accept both unsigned and signed integer scalar and vector types.

Actual Behavior

Compilation fails with:

<source>:7:26: error: no matching function for call to 'WaveActiveBitAnd'
  prevent_dce.Store3(0u, WaveActiveBitAnd(arg)); // !!! FAILS
                         ^~~~~~~~~~~~~~~~
<source>:7:26: note: candidate function not viable: no known conversion from 'int' to 'unsigned int' for 1st argument
  prevent_dce.Store3(0u, WaveActiveBitAnd(arg)); // !!! FAILS
                         ^                ~~~

Compiler returned: 5

WaveActiveBitAnd, Or and Xor accept signed integer scalar literals, but not variables or vectors.

Environment

  • DXC version: libdxcompiler.so: 1.8(dev;4705-99f2d498)
  • Host Operating System: Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by running the supplied dxc -T cs_6_6 reproducer and compare literal, variable, and vector calls for WaveActiveBitAnd, WaveActiveBitOr, and WaveActiveBitXor. Done means the compiler behavior is reconciled with the documented signed and unsigned scalar/vector overloads, or the documentation clearly records the intended restriction.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.