[llvm] [DirectX] NonUniformResourceIndex lowering (PR #159608)
Tex Riddell via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 11:09:05 PDT 2025
================
@@ -0,0 +1,44 @@
+; RUN: opt -S -passes=dxil-op-lower %s | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.0-compute"
+
+ at A.str = internal unnamed_addr constant [2 x i8] c"A\00", align 1
+
+declare i32 @some_val();
+
+define void @test_buffers_with_nuri() {
+
+ %val = call i32 @some_val()
+
+ ; RWBuffer<float> A[10];
+ ;
+ ; A[NonUniformResourceIndex(val)];
+
+ %nuri1 = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %val)
+ %res1 = call target("dx.TypedBuffer", float, 1, 0, 0)
+ @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 %nuri1, ptr @A.str)
+ ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 %val, i1 true) #[[ATTR:.*]]
+ ; CHECK-NOT: @llvm.dx.cast.handle
+ ; CHECK-NOT: @llvm.dx.resource.nonuniformindex
+
+ ; A[NonUniformResourceIndex(val + 1) % 10];
+ %add1 = add i32 %val, 1
+ %nuri2 = tail call noundef i32 @llvm.dx.resource.nonuniformindex(i32 %add1)
+ %rem1 = urem i32 %nuri2, 10
+ %res2 = call target("dx.TypedBuffer", float, 1, 0, 0)
+ @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 %rem1, ptr @A.str)
+ ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 %rem1, i1 true) #[[ATTR]]
+
+ ; A[10 + 3 * NonUniformResourceIndex(GI)];
----------------
tex3d wrote:
It's difficult to say where to draw the line here. DXC requires it to be on the index, but it's possible that's applied after SSA (so store & load chain may be collapsed).
FXC was a bit more flexible, leading to code which would work for FXC, but not for DXC. However, there wasn't a hard rule you could follow to guarantee it would work still.
If we have the rule that it must be on the index used directly in the operation, which is what we've said for DXC, it's easiest to make sure that works. Some HLSL authors have complained a bit about this strictness though.
If we could find another objective rule we could apply and guarantee works which gives more flexibility, we could use that, but we might never implement that for DXC.
https://github.com/llvm/llvm-project/pull/159608
More information about the llvm-commits
mailing list