瀏覽代碼

Check row and col on resultTy after CombineDimensions. (#1086)

Xiang Li 7 年之前
父節點
當前提交
4156aaf280

+ 3 - 4
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -8251,10 +8251,6 @@ clang::QualType HLSLExternalSource::CheckVectorConditional(
       rightObjectKind == AR_TOBJ_BASIC || rightObjectKind == AR_TOBJ_VECTOR ||
       rightObjectKind == AR_TOBJ_MATRIX;
 
-  
-  UINT rowCount, colCount;
-  GetRowsAndColsForAny(ResultTy, rowCount, colCount);
-
   if (!leftIsSimple || !rightIsSimple) {
     if (leftObjectKind == AR_TOBJ_OBJECT && leftObjectKind == AR_TOBJ_OBJECT) {
       if (leftType == rightType) {
@@ -8285,6 +8281,9 @@ clang::QualType HLSLExternalSource::CheckVectorConditional(
     return QualType();
   }
 
+  UINT rowCount, colCount;
+  GetRowsAndColsForAny(ResultTy, rowCount, colCount);
+
   // If result is scalar, use condition dimensions.
   // Otherwise, condition must either match or is scalar, then use result dimensions
   if (rowCount * colCount == 1) {

+ 16 - 0
tools/clang/test/CodeGenHLSL/quick-test/vecCombineSel.hlsl

@@ -0,0 +1,16 @@
+// RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
+
+
+
+// Make sure both channel is used.
+
+// CHECK: extractvalue %dx.types.CBufRet.i32 {{.*}}, 0
+// CHECK: extractvalue %dx.types.CBufRet.i32 {{.*}}, 1
+
+RWBuffer<uint2> output;
+uint2 a;
+[numthreads(4, 4, 4)]
+void main(uint3 iv : SV_GroupThreadID)
+{
+	output[0] = iv.x == 0 ? 0 : a;
+}

+ 1 - 1
tools/clang/test/HLSL/vector-conditional.hlsl

@@ -146,7 +146,7 @@ float4 main(float4 v0 : TEXCOORD) : SV_Target
   acc += b4 ? v0.xy : 1.0F;                                 /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3017: cannot implicitly convert from 'float2' to 'float4'}} */
   acc += b4 ? v0.xy : (v0 + 1.0F);                          /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3017: cannot implicitly convert from 'float2' to 'const float4'}} */
   acc += b4.xy ? v0 : (v0 + 1.0F);                          /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3020: dimension of conditional does not match value}} */
-  acc += b4.xy ? v0 : (v0.xy + 1.0F);                       /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3017: cannot implicitly convert from 'const float2' to 'float4'}} fxc-warning {{X3206: implicit truncation of vector type}} */
+  acc += b4.xy ? v0 : (v0.xy + 1.0F);                       /* expected-error {{cannot convert from 'vector<float, 2>' to 'float4'}} fxc-error {{X3017: cannot implicitly convert from 'const float2' to 'float4'}} fxc-warning {{X3206: implicit truncation of vector type}} */
 
   // lit float/int
   acc += b4 ? v0 : 1.1;