summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
diff options
context:
space:
mode:
authorJoshua Batista <jbatista@microsoft.com>2025-11-21 10:11:38 -0800
committerGitHub <noreply@github.com>2025-11-21 10:11:38 -0800
commitfea070b610e0dc08447be60db7f13c150b2892d5 (patch)
tree079ed6e67f87ee9cef12ba83d0add01f9ce5696d /llvm/lib/Target/DirectX/DXILShaderFlags.cpp
parent00fb67af95635009f1539c88e8706665f4a2d017 (diff)
[HLSL] Add Load overload with status (#166449)
This PR adds a Load method for resources, which takes an additional parameter by reference, status. It fills the status parameter with a 1 or 0, depending on whether or not the resource access was mapped. CheckAccessFullyMapped is also added as an intrinsic, and called in the production of this status bit. Only addresses DXIL for the below issue: https://github.com/llvm/llvm-project/issues/138910 Also only addresses the DXIL variant for the below issue: https://github.com/llvm/llvm-project/issues/99204
Diffstat (limited to 'llvm/lib/Target/DirectX/DXILShaderFlags.cpp')
-rw-r--r--llvm/lib/Target/DirectX/DXILShaderFlags.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
index ce6e8121b9d9..e0049dc75c0d 100644
--- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
+++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
@@ -100,6 +100,26 @@ static bool checkWaveOps(Intrinsic::ID IID) {
}
}
+// Checks to see if the status bit from a load with status
+// instruction is ever extracted. If it is, the module needs
+// to have the TiledResources shader flag set.
+bool checkIfStatusIsExtracted(const IntrinsicInst &II) {
+ [[maybe_unused]] Intrinsic::ID IID = II.getIntrinsicID();
+ assert(IID == Intrinsic::dx_resource_load_typedbuffer ||
+ IID == Intrinsic::dx_resource_load_rawbuffer &&
+ "unexpected intrinsic ID");
+ for (const User *U : II.users()) {
+ if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(U)) {
+ // Resource load operations return a {result, status} pair.
+ // Check if we extract the status
+ if (EVI->getNumIndices() == 1 && EVI->getIndices()[0] == 1)
+ return true;
+ }
+ }
+
+ return false;
+}
+
/// Update the shader flags mask based on the given instruction.
/// \param CSF Shader flags mask to update.
/// \param I Instruction to check.
@@ -164,7 +184,7 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
}
}
- if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
+ if (const auto *II = dyn_cast<IntrinsicInst>(&I)) {
switch (II->getIntrinsicID()) {
default:
break;
@@ -192,6 +212,13 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
DRTM[cast<TargetExtType>(II->getArgOperand(0)->getType())];
if (RTI.isTyped())
CSF.TypedUAVLoadAdditionalFormats |= RTI.getTyped().ElementCount > 1;
+ if (!CSF.TiledResources && checkIfStatusIsExtracted(*II))
+ CSF.TiledResources = true;
+ break;
+ }
+ case Intrinsic::dx_resource_load_rawbuffer: {
+ if (!CSF.TiledResources && checkIfStatusIsExtracted(*II))
+ CSF.TiledResources = true;
break;
}
}