Skip to content

DXC ignores namespace in constant buffers #7322

Open

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

Activity

  1. added
    bug
    needs-triage
    on Apr 8, 2025
  2. damyanp commented on Oct 7, 2025

    @damyanp
    Member

    Helena Kotas (@hekota) - do we need to do something with this? Do we have offload-test-suite tests verifying the behavior here?

  3. hekota commented on Oct 7, 2025

    @hekota
    MemberAuthor

    @hekota - do we need to do something with this? Do we have offload-test-suite tests verifying the behavior here?

    We should fix this. Constants in cbuffer that is declared in a namespace should always be referenced by the fully qualified name ns::a when outside the namespace scope.

  4. damyanp commented on Oct 8, 2025

    @damyanp
    Member

    Motivation for this is to allow people to discover in their code won't work in clang.

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

    bug

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions