Browse Source

[spirv] Add LValue/RValue tests for templated buffer load. (#2332)

Ehsan 6 years ago
parent
commit
51f8b41866

+ 1 - 1
tools/clang/lib/SPIRV/SpirvEmitter.cpp

@@ -4602,7 +4602,7 @@ SpirvEmitter::doExtMatrixElementExpr(const ExtMatrixElementExpr *expr) {
     if (colCount > 1)
       indices.push_back(col);
 
-    if (baseExpr->isGLValue()) {
+    if (!baseInfo->isRValue()) {
       llvm::SmallVector<SpirvInstruction *, 2> indexInstructions(indices.size(),
                                                                  nullptr);
       for (uint32_t i = 0; i < indices.size(); ++i)

+ 29 - 2
tools/clang/test/CodeGenSPIRV/method.byte-address-buffer.templated-load.matrix.hlsl

@@ -1,5 +1,7 @@
 // Run: %dxc -T cs_6_2 -E main -enable-16bit-types
 
+void foo(float16_t2x3 param[3]) {}
+
 ByteAddressBuffer buf;
 
 [numthreads(64, 1, 1)]
@@ -36,7 +38,6 @@ void main(uint3 tid : SV_DispatchThreadId)
 // CHECK:                          OpStore %u16 [[matrix]]
   uint16_t2x3 u16 = buf.Load<uint16_t2x3>(tid.x);
 
-
 // ********* 32-bit matrix ********************
 
 // CHECK:    [[ptr:%\d+]] = OpAccessChain %_ptr_Uniform_uint %buf %uint_0 [[index_0:%\d+]]
@@ -151,5 +152,31 @@ void main(uint3 tid : SV_DispatchThreadId)
 // CHECK:        [[matrix_array:%\d+]] = OpCompositeConstruct %_arr_mat2v3half_uint_3 [[matrix_1]] [[matrix_2]] [[matrix_3]]
 // CHECK:                                OpStore %matVec [[matrix_array]]
   float16_t2x3 matVec[3] = buf.Load<float16_t2x3[3]>(tid.x);
-}
 
+//
+// Chceck that the rvalue resulting from the templated load is accessed correctly
+// A temporary LValue has to be constructed and accessed in order to do this.
+//
+// CHECK: OpCompositeConstruct %_arr_mat2v3half_uint_3
+// CHECK: OpStore %temp_var_
+// CHECK: OpAccessChain %_ptr_Function_mat2v3half %temp_var_ %int_0
+// CHECK: OpLoad %mat2v3half
+// CHECK: OpCompositeExtract %half {{%\d+}} 0 1
+// CHECK: OpCompositeExtract %half {{%\d+}} 0 2
+// CHECK: OpCompositeConstruct %v2half
+// CHECK: OpStore %customMatrix {{%\d+}}
+  float16_t2 customMatrix = (buf.Load<float16_t2x3[3]>(tid.x))[0]._m01_m02;
+
+// CHECK: OpCompositeConstruct %_arr_mat2v3half_uint_3
+// CHECK: OpStore %temp_var_vector
+// CHECK: OpAccessChain %_ptr_Function_half %temp_var_vector %int_1 %uint_0 %uint_1
+// CHECK: OpLoad %half
+// CHECK: OpCompositeConstruct %_arr_half_uint_3
+// CHECK: OpStore %a {{%\d+}}
+  half a[3] = {1, (buf.Load<float16_t2x3[3]>(tid.x))[1][0][1], 0};
+
+// CHECK: OpCompositeConstruct %_arr_mat2v3half_uint_3
+// CHECK: OpStore %param_var_param {{%\d+}}
+// CHECK: OpFunctionCall %void %foo %param_var_param
+  foo(buf.Load<float16_t2x3[3]>(tid.x));
+}