-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SPIR-V] Add support for HLSL SV_GroupIndex #130670
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -341,6 +341,9 @@ class SPIRVInstructionSelector : public InstructionSelector { | |||||||||||||||||
bool loadVec3BuiltinInputID(SPIRV::BuiltIn::BuiltIn BuiltInValue, | ||||||||||||||||||
Register ResVReg, const SPIRVType *ResType, | ||||||||||||||||||
MachineInstr &I) const; | ||||||||||||||||||
bool loadBuiltinInputID(SPIRV::BuiltIn::BuiltIn BuiltInValue, | ||||||||||||||||||
Register ResVReg, const SPIRVType *ResType, | ||||||||||||||||||
MachineInstr &I) const; | ||||||||||||||||||
bool loadHandleBeforePosition(Register &HandleReg, const SPIRVType *ResType, | ||||||||||||||||||
GIntrinsic &HandleDef, MachineInstr &Pos) const; | ||||||||||||||||||
}; | ||||||||||||||||||
|
@@ -3059,6 +3062,15 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg, | |||||||||||||||||
// builtin variable | ||||||||||||||||||
return loadVec3BuiltinInputID(SPIRV::BuiltIn::WorkgroupId, ResVReg, ResType, | ||||||||||||||||||
I); | ||||||||||||||||||
case Intrinsic::spv_flattened_thread_id_in_group: | ||||||||||||||||||
// The HLSL SV_GroupIndex semantic is lowered to | ||||||||||||||||||
// llvm.spv.flattened.thread.id.in.group() intrinsic in LLVM IR for SPIR-V | ||||||||||||||||||
// backend. | ||||||||||||||||||
// | ||||||||||||||||||
// In SPIR-V backend, llvm.spv.flattened.thread.id.in.group is translated to | ||||||||||||||||||
// a `LocalInvocationIndex` builtin variable | ||||||||||||||||||
return loadBuiltinInputID(SPIRV::BuiltIn::LocalInvocationIndex, ResVReg, | ||||||||||||||||||
ResType, I); | ||||||||||||||||||
case Intrinsic::spv_fdot: | ||||||||||||||||||
return selectFloatDot(ResVReg, ResType, I); | ||||||||||||||||||
case Intrinsic::spv_udot: | ||||||||||||||||||
|
@@ -4005,6 +4017,40 @@ bool SPIRVInstructionSelector::loadVec3BuiltinInputID( | |||||||||||||||||
return Result && MIB.constrainAllUses(TII, TRI, RBI); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// Generate the instructions to load 32-bit integer builtin input IDs/Indices. | ||||||||||||||||||
// Like LocalInvocationIndex | ||||||||||||||||||
bool SPIRVInstructionSelector::loadBuiltinInputID( | ||||||||||||||||||
SPIRV::BuiltIn::BuiltIn BuiltInValue, Register ResVReg, | ||||||||||||||||||
const SPIRVType *ResType, MachineInstr &I) const { | ||||||||||||||||||
MachineIRBuilder MIRBuilder(I); | ||||||||||||||||||
const SPIRVType *PtrType = GR.getOrCreateSPIRVPointerType( | ||||||||||||||||||
ResType, MIRBuilder, SPIRV::StorageClass::Input); | ||||||||||||||||||
|
||||||||||||||||||
// Create new register for the input ID builtin variable. | ||||||||||||||||||
Register NewRegister = | ||||||||||||||||||
MIRBuilder.getMRI()->createVirtualRegister(GR.getRegClass(PtrType)); | ||||||||||||||||||
MIRBuilder.getMRI()->setType( | ||||||||||||||||||
NewRegister, | ||||||||||||||||||
LLT::pointer(storageClassToAddressSpace(SPIRV::StorageClass::Input), | ||||||||||||||||||
GR.getPointerSize())); | ||||||||||||||||||
GR.assignSPIRVTypeToVReg(PtrType, NewRegister, MIRBuilder.getMF()); | ||||||||||||||||||
|
||||||||||||||||||
// Build global variable with the necessary decorations for the input ID | ||||||||||||||||||
// builtin variable. | ||||||||||||||||||
Register Variable = GR.buildGlobalVariable( | ||||||||||||||||||
NewRegister, PtrType, getLinkStringForBuiltIn(BuiltInValue), nullptr, | ||||||||||||||||||
SPIRV::StorageClass::Input, nullptr, true, true, | ||||||||||||||||||
SPIRV::LinkageType::Import, MIRBuilder, false); | ||||||||||||||||||
Comment on lines
+4040
to
+4043
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. Changing this to false will build a variable without any linkage attribute.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
// Load uint value from the global variable. | ||||||||||||||||||
auto MIB = BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(SPIRV::OpLoad)) | ||||||||||||||||||
.addDef(ResVReg) | ||||||||||||||||||
.addUse(GR.getSPIRVTypeID(ResType)) | ||||||||||||||||||
.addUse(Variable); | ||||||||||||||||||
|
||||||||||||||||||
return MIB.constrainAllUses(TII, TRI, RBI); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
SPIRVType *SPIRVInstructionSelector::widenTypeToVec4(const SPIRVType *Type, | ||||||||||||||||||
MachineInstr &I) const { | ||||||||||||||||||
MachineIRBuilder MIRBuilder(I); | ||||||||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | FileCheck %s | ||
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %} | ||
|
||
; CHECK-DAG: %[[#int:]] = OpTypeInt 32 0 | ||
; CHECK-DAG: %[[#ptr_Input_int:]] = OpTypePointer Input %[[#int]] | ||
; CHECK-DAG: %[[#LocalInvocationIndex:]] = OpVariable %[[#ptr_Input_int]] Input | ||
|
||
; CHECK-DAG: OpEntryPoint GLCompute {{.*}} %[[#LocalInvocationIndex]] | ||
; CHECK-DAG: OpName %[[#LocalInvocationIndex]] "__spirv_BuiltInLocalInvocationIndex" | ||
; CHECK-DAG: OpDecorate %[[#LocalInvocationIndex]] BuiltIn LocalInvocationIndex | ||
|
||
target triple = "spirv-unknown-vulkan-library" | ||
|
||
declare void @local_index_user(i32) | ||
|
||
; Function Attrs: convergent noinline norecurse | ||
define void @main() #1 { | ||
entry: | ||
|
||
; CHECK: %[[#load:]] = OpLoad %[[#int]] %[[#LocalInvocationIndex]] | ||
%1 = call i32 @llvm.spv.flattened.thread.id.in.group() | ||
|
||
call spir_func void @local_index_user(i32 %1) | ||
ret void | ||
} | ||
|
||
; Function Attrs: nounwind willreturn memory(none) | ||
declare i32 @llvm.spv.flattened.thread.id.in.group() #3 | ||
|
||
attributes #1 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #3 = { nounwind willreturn memory(none) } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.