microsoft / microsoft/DirectXShaderCompiler
DXC ignores namespace in constant buffers
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the two HLSL reproductions in the issue and compare DXC's behavior with Clang using the linked Compiler Explorer examples. Trace how namespace-scoped cbuffer declarations and their elements are represented, then verify that qualified references work without changing the demonstrated valid behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100