From 776cddacb1ab8fd92bcb3aa42f9c0b348d8aa2ba Mon Sep 17 00:00:00 2001 From: Helena Kotas Date: Thu, 20 Feb 2025 17:27:53 -0800 Subject: [HLSL] Implement default constant buffer `$Globals` (#125807) All variable declarations in the global scope that are not resources, static or empty are implicitly added to implicit constant buffer `$Globals`. They are created in `hlsl_constant` address space and collected in an implicit `HLSLBufferDecl` node that is added to the AST at the end of the translation unit. Codegen is the same as for explicit constant buffers. Fixes #123801 --- clang/lib/CodeGen/CodeGenModule.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 7924c32..1b7d0ac 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5513,6 +5513,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, if (getLangOpts().OpenCL && ASTTy->isSamplerT()) return; + // HLSL default buffer constants will be emitted during HLSLBufferDecl codegen + if (getLangOpts().HLSL && + D->getType().getAddressSpace() == LangAS::hlsl_constant) + return; + // If this is OpenMP device, check if it is legal to emit this global // normally. if (LangOpts.OpenMPIsTargetDevice && OpenMPRuntime && -- cgit v1.1