aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorNathan Gauër <brioche@google.com>2025-06-04 13:22:37 +0200
committerGitHub <noreply@github.com>2025-06-04 13:22:37 +0200
commit20d70196c9a4da344d0944f3c78447c3bd7079c7 (patch)
tree2644223d4591f05c1b8d9efda4a7a17fff976fca /clang/lib/CodeGen/CodeGenModule.cpp
parentd7c7c461f5216c2aa1e8f0d884464daf9bcb9ecb (diff)
downloadllvm-20d70196c9a4da344d0944f3c78447c3bd7079c7.zip
llvm-20d70196c9a4da344d0944f3c78447c3bd7079c7.tar.gz
llvm-20d70196c9a4da344d0944f3c78447c3bd7079c7.tar.bz2
[HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (#138530)
This variable attribute is used in HLSL to add Vulkan specific builtins in a shader. The attribute is documented here: https://github.com/microsoft/hlsl-specs/blob/17727e88fd1cb09013cb3a144110826af05f4dd5/proposals/0011-inline-spirv.md Those variable, even if marked as `static` are externally initialized by the pipeline/driver/GPU. This is handled by moving them to a specific address space `hlsl_input`, also added by this commit. The design for input variables in Clang can be found here: https://github.com/llvm/wg-hlsl/blob/355771361ef69259fef39a65caef8bff9cb4046d/proposals/0019-spirv-input-builtin.md Co-authored-by: Justin Bogner <mail@justinbogner.com>
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 9383c57..468fc6e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5763,7 +5763,17 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
getCUDARuntime().handleVarRegistration(D, *GV);
}
- GV->setInitializer(Init);
+ if (LangOpts.HLSL && GetGlobalVarAddressSpace(D) == LangAS::hlsl_input) {
+ // HLSL Input variables are considered to be set by the driver/pipeline, but
+ // only visible to a single thread/wave.
+ GV->setExternallyInitialized(true);
+ } else {
+ GV->setInitializer(Init);
+ }
+
+ if (LangOpts.HLSL)
+ getHLSLRuntime().handleGlobalVarDefinition(D, GV);
+
if (emitter)
emitter->finalize(GV);
@@ -5806,6 +5816,12 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
!D->hasAttr<ConstInitAttr>())
Linkage = llvm::GlobalValue::InternalLinkage;
+ // HLSL variables in the input address space maps like memory-mapped
+ // variables. Even if they are 'static', they are externally initialized and
+ // read/write by the hardware/driver/pipeline.
+ if (LangOpts.HLSL && GetGlobalVarAddressSpace(D) == LangAS::hlsl_input)
+ Linkage = llvm::GlobalValue::ExternalLinkage;
+
GV->setLinkage(Linkage);
if (D->hasAttr<DLLImportAttr>())
GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);