[clang] [HLSL] Implement RWBuffer::operator[] via __builtin_hlsl_resource_getpointer (PR #117017)

Steven Perron via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 26 10:22:15 PST 2024


================
@@ -6,14 +6,17 @@ RasterizerOrderedStructuredBuffer<int> Out2;
 
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {
+  // CHECK: define void @main()
+
+  // CHECK: %[[INPTR:.*]] = call noundef nonnull align 4 dereferenceable(4) ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_i32_0_0t(target("dx.RawBuffer", i32, 0, 0) %{{.*}}, i32 %{{.*}})
+  // CHECK: %[[LOAD:.*]] = load i32, ptr %[[INPTR]]
+  // CHECK: %[[OUT1PTR:.*]] = call noundef nonnull align 4 dereferenceable(4) ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_i32_1_0t(target("dx.RawBuffer", i32, 1, 0) %{{.*}}, i32 %{{.*}})
+  // CHECK: store i32 %[[LOAD]], ptr %[[OUT1PTR]]
   Out1[GI] = In[GI];
+
+  // CHECK: %[[INPTR:.*]] = call noundef nonnull align 4 dereferenceable(4) ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_i32_0_0t(target("dx.RawBuffer", i32, 0, 0) %{{.*}}, i32 %{{.*}})
+  // CHECK: %[[LOAD:.*]] = load i32, ptr %[[INPTR]]
+  // CHECK: %[[OUT2PTR:.*]] = call noundef nonnull align 4 dereferenceable(4) ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_i32_1_1t(target("dx.RawBuffer", i32, 1, 1) %{{.*}}, i32 %{{.*}})
+  // CHECK: store i32 %[[LOAD]], ptr %[[OUT2PTR]]
----------------
s-perron wrote:

I put this in https://github.com/llvm/wg-hlsl/pull/94/files#r1856923861, as well. I think it is relevant here too.

Consider this example: https://godbolt.org/z/f45r7vEoG. The resources can have different layouts, but they are considered the same type. Somewhere, we will have to convert one to another. At one point, I was thinking of doing that in the backend when I thought the loads and store were going to be calls to intrinsics. I could assume a particular layout, and convert while expanding the instrinsic if the layout of the parameter does not match the layout of the global variable. That will not work anymore.

How will this work for DXIL?

https://github.com/llvm/llvm-project/pull/117017


More information about the cfe-commits mailing list