[llvm-branch-commits] [clang] [HLSL] Implement Texture2D::Load methods and builtin (PR #185708)
Helena Kotas via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Mar 10 19:24:02 PDT 2026
================
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -emit-llvm -disable-llvm-passes -finclude-default-header -o - %s | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,DXIL
+// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -finclude-default-header -o - %s | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,SPIRV
+
+Texture2D<float4> t;
+
+// CHECK: define hidden {{.*}} <4 x float> @test_load(int vector[2])
+// CHECK: %[[COORD:.*]] = insertelement <3 x i32> {{.*}}, i32 0, i32 2
+// CHECK: %[[CALL:.*]] = call {{.*}} <4 x float> @hlsl::Texture2D<float vector[4]>::Load(int vector[3])(ptr {{.*}} @t, <3 x i32> noundef %[[COORD]])
+// CHECK: ret <4 x float> %[[CALL]]
+
+float4 test_load(int2 loc : LOC) : SV_Target {
+ return t.Load(int3(loc, 0));
+}
+
+// CHECK: define linkonce_odr hidden {{.*}} <4 x float> @hlsl::Texture2D<float vector[4]>::Load(int vector[3])(ptr {{.*}} %[[THIS:.*]], <3 x i32> {{.*}} %[[LOCATION:.*]])
+// CHECK: %[[THIS_ADDR:.*]] = alloca ptr
+// CHECK: %[[LOCATION_ADDR:.*]] = alloca <3 x i32>
+// CHECK: store ptr %[[THIS]], ptr %[[THIS_ADDR]]
+// CHECK: store <3 x i32> %[[LOCATION]], ptr %[[LOCATION_ADDR]]
+// CHECK: %[[THIS_VAL:.*]] = load ptr, ptr %[[THIS_ADDR]]
+// CHECK: %[[HANDLE_GEP:.*]] = getelementptr inbounds nuw %"class.hlsl::Texture2D", ptr %[[THIS_VAL]], i32 0, i32 0
+// CHECK: %[[HANDLE:.*]] = load target("{{(dx.Texture|spirv.Image)}}", {{.*}}), ptr %[[HANDLE_GEP]]
+// CHECK: %[[LOCATION_VAL:.*]] = load <3 x i32>, ptr %[[LOCATION_ADDR]]
+// CHECK: %[[COORD_X:.*]] = shufflevector <3 x i32> %[[LOCATION_VAL]], <3 x i32> poison, <2 x i32> <i32 0, i32 1>
----------------
hekota wrote:
The `X` in the `COORD_X` confused me :) Because it does not have just the X coordinate, it has all of them.
https://github.com/llvm/llvm-project/pull/185708
More information about the llvm-branch-commits
mailing list