Skip to content

Commit 28d577e

Browse files
authored
[DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers
This implements the DXILResourceAnalysis pass for `dx.TypedBuffer` and `dx.RawBuffer` types. This should be sufficient to lower `dx.handle.fromBinding` for this set of types, but it leaves a number of TODOs around for other resource types. This also includes a straightforward `print` method in `ResourceInfo` to make the analysis testable. This is deliberately different than the printer in `lib/Target/DirectX/DXILResource.cpp`, which attempts to print bindings in a format compatible with the comments `dxc` prints. We will eventually want to make that functionality driven by this analysis pass, but it isn't sufficient for testing so we need both. Pull Request: #100699
1 parent 1ca9fe6 commit 28d577e

File tree

4 files changed

+521
-8
lines changed

4 files changed

+521
-8
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
namespace llvm {
1919
class CallInst;
2020
class MDTuple;
21+
class TargetExtType;
2122

2223
namespace dxil {
2324

2425
class ResourceInfo {
2526
struct ResourceBinding {
26-
uint32_t UniqueID;
27+
uint32_t RecordID;
2728
uint32_t Space;
2829
uint32_t LowerBound;
2930
uint32_t Size;
3031

3132
bool operator==(const ResourceBinding &RHS) const {
32-
return std::tie(UniqueID, Space, LowerBound, Size) ==
33-
std::tie(RHS.UniqueID, RHS.Space, RHS.LowerBound, RHS.Size);
33+
return std::tie(RecordID, Space, LowerBound, Size) ==
34+
std::tie(RHS.RecordID, RHS.Space, RHS.LowerBound, RHS.Size);
3435
}
3536
bool operator!=(const ResourceBinding &RHS) const {
3637
return !(*this == RHS);
@@ -128,9 +129,9 @@ class ResourceInfo {
128129
bool isFeedback() const;
129130
bool isMultiSample() const;
130131

131-
void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
132+
void bind(uint32_t RecordID, uint32_t Space, uint32_t LowerBound,
132133
uint32_t Size) {
133-
Binding.UniqueID = UniqueID;
134+
Binding.RecordID = RecordID;
134135
Binding.Space = Space;
135136
Binding.LowerBound = LowerBound;
136137
Binding.Size = Size;
@@ -215,6 +216,8 @@ class ResourceInfo {
215216

216217
ResourceBinding getBinding() const { return Binding; }
217218
std::pair<uint32_t, uint32_t> getAnnotateProps() const;
219+
220+
void print(raw_ostream &OS) const;
218221
};
219222

220223
} // namespace dxil

llvm/include/llvm/IR/IntrinsicsDirectX.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ def int_dx_flattened_thread_id_in_group : Intrinsic<[llvm_i32_ty], [], [IntrNoMe
2020
def int_dx_create_handle : ClangBuiltin<"__builtin_hlsl_create_handle">,
2121
Intrinsic<[ llvm_ptr_ty ], [llvm_i8_ty], [IntrWillReturn]>;
2222

23+
// Create resource handle given binding information. Returns a `target("dx.")`
24+
// type appropriate for the kind of resource given a register space ID, lower
25+
// bound and range size of the binding, as well as an index and an indicator
26+
// whether that index may be non-uniform.
27+
def int_dx_handle_fromBinding
28+
: DefaultAttrsIntrinsic<
29+
[llvm_any_ty],
30+
[llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty],
31+
[IntrNoMem]>;
32+
2333
def int_dx_all : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty]>;
2434
def int_dx_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty]>;
2535
def int_dx_clamp : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>]>;

0 commit comments

Comments
 (0)