Skip to content

DXC ignores namespace in constant buffers #7322

@hekota

Description

@hekota

Description
cbuffer declarations can occur inside a namespace scope. DXC ignores it and the constant buffer elements must be referenced their local name without the namespace qualifier.

Steps to Reproduce

namespace ns {
  cbuffer CB {
    float a;
  }
}

export float foo() {
  // fails to compile:
  // return ns::a; 
  return a;
}

The float value must be referenced as a in DXC instead of ns::a. Works correcty in Clang.
https://godbolt.org/z/GMzzMnh6s

BUT - if there are any other declarations inside the namespace, the ns::a reference is recognized, and so is just a!

namespace ns {
  cbuffer CB {
    float a;
  }
  float b; // added decl
}

export float foo() {
  return ns::a + a; // no error
}

https://godbolt.org/z/xvx6zcb5q

Correct Behavior
DXC should recognize cbuffer declared within a namespace and it should create the constants with a qualified name. The constants cannot be referenced by unqualified names.

Environment

  • DXC version: main as of 4/7/2025

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crash

    Type

    No type

    Projects

    Status

    Triaged

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions