Skip to content

Constant register declarations have diverging behavior between FXC and DXC #7640

Open

Description

@Maraneshi

Description
Constant register declarations are legacy syntax, but still accepted by DXC and packed into the implicit $Globals constant buffer. However, the packing behavior differs to FXC.

Steps to Reproduce

uint u1 : register(b2);
uint u2 : register(c2);
uint u3 : register(i2);

If the above declarations are compiled with DXC, it interprets all three register declarations as packoffsets within the $Globals constant buffer, thus overlapping all three variables at offset 32. The reflection output is:

cbuffer $Globals
{
  struct $Globals
  {
      uint u1;                                      ; Offset:   32
      uint u2;                                      ; Offset:   32
      uint u3;                                      ; Offset:   32
  } $Globals;                                       ; Offset:    0 Size:    36
}

https://hlsl.godbolt.org/z/9fbE5svEx

FXC with shader models >= 4.0 instead ignores the first and third register declaration and only interprets the second one as a packoffset equivalent, leading to the following layout:

cbuffer $Globals
{
  uint u2;                           // Offset:   32 Size:     4
  uint u1;                           // Offset:   36 Size:     4
  uint u3;                           // Offset:   40 Size:     4
}

https://shader-playground.timjones.io/536347a8d3b1b75f6ec00229afd283cf

Interestingly enough, clang seems to agree with FXC when the errors about the syntax are downgraded to warnings (see first link, it doesn't output the struct reflection, but the actual loads/extractvalues in DXIL confirm the layout).

This is all very much legacy (and I'm not even technically using it fully correctly for SM3 or older), but still accepted syntax and maybe someone still wants to port really old shaders and will run into weird issues.
Possible courses of action include aligning the behavior and/or deprecating those declarations altogether. In any case there should be at least warnings, since it either breaks potential existing shaders using that syntax with DXC (if its behavior will be aligned to FXC) or breaks shaders being ported from FXC to DXC (if its packing behavior will not be changed). Clang made b# and i# declarations on globals errors by default, see also the HLSL Register Types and Diagnostics Proposal.

Environment

  • DXC version: 1.6+
  • Host Operating System: All

Activity

  1. added
    bug
    needs-triage
    on Jul 11, 2025
  2. added
    fxc-disagrees
    and removed
    needs-triage
    on Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfxc-disagrees

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions