Forráskód Böngészése

Take care case dynamic indexing on vector start with offset. (#3558) (#3560)

* Take care case dynamic indexing on vector start with offset.
Xiang Li 4 éve
szülő
commit
917ab093bc

+ 1 - 1
lib/HLSL/HLOperationLower.cpp

@@ -6657,7 +6657,7 @@ void TranslateCBGepLegacy(GetElementPtrInst *GEP, Value *handle,
 
         // Load the whole register.
         Value *newLd = GenerateCBLoadLegacy(handle, legacyIndex,
-                                     /*channelOffset*/ 0, EltTy,
+                                     /*channelOffset*/ channel, EltTy,
                                      /*vecSize*/ vecSize, hlslOP, Builder);
         // Copy to array.
         IRBuilder<> AllocaBuilder(GEP->getParent()->getParent()->getEntryBlock().getFirstInsertionPt());

+ 23 - 0
tools/clang/test/HLSLFileCheck/hlsl/objects/CbufferLegacy/vec_indexing_with_offset.hlsl

@@ -0,0 +1,23 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// Make sure store yzw to float3.
+// CHECK:%[[X:.*]] = extractvalue %dx.types.CBufRet.f32 %{{.*}}, 1
+// CHECK:%[[Y:.*]] = extractvalue %dx.types.CBufRet.f32 %{{.*}}, 2
+// CHECK:%[[Z:.*]] = extractvalue %dx.types.CBufRet.f32 %{{.*}}, 3
+// CHECK:%[[PX:.*]] = getelementptr inbounds [3 x float], [3 x float]* %{{.*}}, i32 0, i32 0
+// CHECK:store float %[[X]], float* %[[PX]], align 4
+// CHECK:%[[PY:.*]] = getelementptr inbounds [3 x float], [3 x float]* %{{.*}}, i32 0, i32 1
+// CHECK:store float %[[Y]], float* %[[PY]], align 4
+// CHECK:%[[PZ:.*]] = getelementptr inbounds [3 x float], [3 x float]* %{{.*}}, i32 0, i32 2
+// CHECK:store float %[[Z]], float* %[[PZ]], align 4
+
+cbuffer cb
+{
+    uint i;
+    float3 v;
+};
+
+float4 main() : SV_TARGET
+{
+    return v[i];
+}

+ 26 - 0
tools/clang/test/HLSLFileCheck/hlsl/objects/CbufferLegacy/vec_indexing_with_offset_16bit.hlsl

@@ -0,0 +1,26 @@
+// RUN: %dxc -E main -T ps_6_6 -enable-16bit-types -HV 2018 %s | FileCheck %s
+
+// Make sure store .1234 to half4.
+// CHECK:%[[X:.*]] = extractvalue %dx.types.CBufRet.f16.8 %{{.*}}, 1
+// CHECK:%[[Y:.*]] = extractvalue %dx.types.CBufRet.f16.8 %{{.*}}, 2
+// CHECK:%[[Z:.*]] = extractvalue %dx.types.CBufRet.f16.8 %{{.*}}, 3
+// CHECK:%[[W:.*]] = extractvalue %dx.types.CBufRet.f16.8 %{{.*}}, 4
+// CHECK:%[[PX:.*]] = getelementptr inbounds [4 x half], [4 x half]* %{{.*}}, i32 0, i32 0
+// CHECK:store half %[[X]], half* %[[PX]], align 2
+// CHECK:%[[PY:.*]] = getelementptr inbounds [4 x half], [4 x half]* %{{.*}}, i32 0, i32 1
+// CHECK:store half %[[Y]], half* %[[PY]], align 2
+// CHECK:%[[PZ:.*]] = getelementptr inbounds [4 x half], [4 x half]* %{{.*}}, i32 0, i32 2
+// CHECK:store half %[[Z]], half* %[[PZ]], align 2
+// CHECK:%[[PW:.*]] = getelementptr inbounds [4 x half], [4 x half]* %{{.*}}, i32 0, i32 3
+// CHECK:store half %[[W]], half* %[[PW]], align 2
+
+cbuffer cb
+{
+    int16_t i;
+    half4 v;
+};
+
+float4 main() : SV_TARGET
+{
+    return v[i];
+}