-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPIR-V] Add hlsl_private address space for HLSL/SPIR-V #122103
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = { | |
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_uptr | ||
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64 | ||
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared | ||
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_private | ||
}; | ||
|
||
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = { | ||
|
@@ -83,6 +84,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = { | |
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_uptr | ||
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64 | ||
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared | ||
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_private | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what hlsl_private means but using flat here is almost certainly wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This address space will be used for:
Would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it acts like thread local storage, we don't have an implementation of that right now. So it would be none of these. PRIVATE_ADDRESS globals will just fail and nothing else has thread-local like behavior There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HLSL documentation for those is currently this: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-variable-syntax FXC/DXC implementation of a If this is not available in AMDGPU yet, what value shall be picked? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should use PRIVATE_ADDRESS. It will at least fail in a way that makes it somewhat obvious what the issue is |
||
|
||
}; | ||
} // namespace targets | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5362,6 +5362,23 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) { | |
if (OpenMPRuntime->hasAllocateAttributeForGlobalVar(D, AS)) | ||
return AS; | ||
} | ||
|
||
if (LangOpts.HLSL) { | ||
if (D == nullptr) | ||
return LangAS::hlsl_private; | ||
|
||
// Except resources (Uniform, UniformConstant) & instanglble (handles) | ||
if (D->getType()->isHLSLResourceType() || | ||
D->getType()->isHLSLIntangibleType()) | ||
return D->getType().getAddressSpace(); | ||
|
||
if (D->getStorageClass() != SC_Static) | ||
return D->getType().getAddressSpace(); | ||
|
||
LangAS AS = D->getType().getAddressSpace(); | ||
return AS == LangAS::Default ? LangAS::hlsl_private : AS; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered applying the FYI, I am currently looking into adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe this is the best place to do it since it is unspellable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recall having tried this method first, but for some reasons moved it to Codegen, but I don't recall the full context. I just tried moving it in sema again, and seems there is a slight issue with |
||
return getTargetCodeGenInfo().getGlobalVarAddressSpace(*this, D); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -o - -disable-llvm-passes %s | FileCheck %s --check-prefixes=CHECK | ||
// RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-compute -std=hlsl202x -emit-llvm -o - -disable-llvm-passes %s | FileCheck %s --check-prefixes=CHECK | ||
|
||
struct S { | ||
static int Value; | ||
}; | ||
|
||
int S::Value = 1; | ||
// CHECK: @_ZN1S5ValueE = global i32 1, align 4 | ||
|
||
[shader("compute")] | ||
[numthreads(1,1,1)] | ||
void main() { | ||
S s; | ||
int value1, value2; | ||
// CHECK: %s = alloca %struct.S, align 1 | ||
// CHECK: %value1 = alloca i32, align 4 | ||
// CHECK: %value2 = alloca i32, align 4 | ||
|
||
// CHECK: [[tmp:%.*]] = load i32, ptr @_ZN1S5ValueE, align 4 | ||
// CHECK: store i32 [[tmp]], ptr %value1, align 4 | ||
value1 = S::Value; | ||
|
||
// CHECK: [[tmp:%.*]] = load i32, ptr @_ZN1S5ValueE, align 4 | ||
// CHECK: store i32 [[tmp]], ptr %value2, align 4 | ||
value2 = s.Value; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title and description only talks about SPIRV, but this is a purely language concept you're adding here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct, slightly reworded the description.
The thing is, only SPIR-V will be using this for now (same as the few others we'll add line hlsl_input, hlsl_output).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not really how languages work. It's a property of the language and exists independently of what any codegen is doing with it. As it is it sounds like you're jamming some knob you want for codegen through here that isn't part of the language.
This needs reference to some HLSL spec describing the address space without any mention of SPIRV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This being a small stepping stone for the larger change bringing hlsl_input/hlsl_output, I haven't wrote a specific HLSL spec part, only relied on current MSDN & HLSL implementations (I agree, not great).
For the
hlsl_input
/hlsl_output
address spaces, here is the wg-hlsl proposal:llvm/wg-hlsl#97
But you are right, maybe that's something we should now write properly in the hlsl-spec repo