Browse Source

Reorganize tests in CodegenHLSL for better clarity and coverage (#2456)

All unit tests are now executed using FileCheck and have been moved to a separate folder HLSLFileCheck. The organization of HLSLFileCheck closely mirrors the HLSL language features. This should help us identify current gaps in our test coverage and should also allow us to add new tests under appropriate category, thus avoiding fragmentation.
Move out hlsl files used in ValidationTest.cpp into a separate folder DXILValidation.
CodegenHLSL now only contains files referenced by tests implemented in CompilerTest.cpp.
All crash tests are moved out to a separate folder called HLSLDisabled.
Vishal Sharma 6 years ago
parent
commit
4e5440e1ee
100 changed files with 1894 additions and 53 deletions
  1. 1 0
      tools/clang/test/CodeGenHLSL/Readme.md
  2. 0 53
      tools/clang/test/CodeGenHLSL/batch/misc/signature_packing_by_width.hlsl
  3. 14 0
      tools/clang/test/CodeGenHLSL/filecheck_multiple_run_lines.hlsl
  4. 19 0
      tools/clang/test/CodeGenHLSL/lib_select_res_codegenhlsl_copy.hlsl
  5. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine1.hlsl
  6. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine10.hlsl
  7. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine11.hlsl
  8. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine2.hlsl
  9. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine3.hlsl
  10. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine4.hlsl
  11. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine5.hlsl
  12. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine6.hlsl
  13. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine7.hlsl
  14. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine8.hlsl
  15. 0 0
      tools/clang/test/CodeGenHLSL/rootSigDefine9.hlsl
  16. 0 0
      tools/clang/test/CodeGenHLSL/rootSigEntry.hlsl
  17. 0 0
      tools/clang/test/CodeGenHLSL/rootSigProfile3.hlsl
  18. 0 0
      tools/clang/test/CodeGenHLSL/rootSigProfile4.hlsl
  19. 0 0
      tools/clang/test/CodeGenHLSL/structInBuffer.hlsl
  20. 9 0
      tools/clang/test/DXILValidation/AddUint64Odd.hlsl
  21. 20 0
      tools/clang/test/DXILValidation/BigStructInBuffer.hlsl
  22. 13 0
      tools/clang/test/DXILValidation/EmptyStructInBuffer.hlsl
  23. 14 0
      tools/clang/test/DXILValidation/GetDimCalcLOD.hlsl
  24. 22 0
      tools/clang/test/DXILValidation/Include.hlsl
  25. 19 0
      tools/clang/test/DXILValidation/InnerCoverage.hlsl
  26. 17 0
      tools/clang/test/DXILValidation/InnerCoverage2.hlsl
  27. 8 0
      tools/clang/test/DXILValidation/IntegerDepth.hlsl
  28. 8 0
      tools/clang/test/DXILValidation/IntegerDepth2.hlsl
  29. 15 0
      tools/clang/test/DXILValidation/RaceCond.hlsl
  30. 1 0
      tools/clang/test/DXILValidation/Readme.md
  31. 73 0
      tools/clang/test/DXILValidation/SamplerKind.hlsl
  32. 0 0
      tools/clang/test/DXILValidation/SimpleDs1.hlsl
  33. 0 0
      tools/clang/test/DXILValidation/SimpleGS1.hlsl
  34. 23 0
      tools/clang/test/DXILValidation/SimpleGS10.hlsl
  35. 23 0
      tools/clang/test/DXILValidation/SimpleGS8.hlsl
  36. 23 0
      tools/clang/test/DXILValidation/SimpleGS9.hlsl
  37. 0 0
      tools/clang/test/DXILValidation/SimpleHs1.hlsl
  38. 0 0
      tools/clang/test/DXILValidation/SimpleHs3.hlsl
  39. 0 0
      tools/clang/test/DXILValidation/SimpleHs4.hlsl
  40. 9 0
      tools/clang/test/DXILValidation/UndefValue.hlsl
  41. 9 0
      tools/clang/test/DXILValidation/UndefValue2.hlsl
  42. 0 0
      tools/clang/test/DXILValidation/abs1.hlsl
  43. 0 0
      tools/clang/test/DXILValidation/abs2.hlsl
  44. 26 0
      tools/clang/test/DXILValidation/attributes-gs-no-inout-main.hlsl
  45. 26 0
      tools/clang/test/DXILValidation/attributes-gs-no-inout-other.hlsl
  46. 25 0
      tools/clang/test/DXILValidation/attributes-gs-no-maxvertexcount.hlsl
  47. 38 0
      tools/clang/test/DXILValidation/attributes-hs-no-pcf.hlsl
  48. 83 0
      tools/clang/test/DXILValidation/barrier.hlsl
  49. 0 0
      tools/clang/test/DXILValidation/binary1.hlsl
  50. 0 0
      tools/clang/test/DXILValidation/cbuffer1.50.hlsl
  51. 12 0
      tools/clang/test/DXILValidation/cbufferOffset.hlsl
  52. 10 0
      tools/clang/test/DXILValidation/cbuffer_unused2.hlsl
  53. 10 0
      tools/clang/test/DXILValidation/check_nowarning.hlsl
  54. 10 0
      tools/clang/test/DXILValidation/check_warning.hlsl
  55. 0 0
      tools/clang/test/DXILValidation/clip_planes.hlsl
  56. 16 0
      tools/clang/test/DXILValidation/deadloop - Copy.hlsl
  57. 16 0
      tools/clang/test/DXILValidation/deadloop.hlsl
  58. 0 0
      tools/clang/test/DXILValidation/eval.hlsl
  59. 14 0
      tools/clang/test/DXILValidation/filecheck_multiple_run_lines.hlsl
  60. 7 0
      tools/clang/test/DXILValidation/fpexcept.hlsl
  61. 17 0
      tools/clang/test/DXILValidation/globallycoherent2.hlsl
  62. 16 0
      tools/clang/test/DXILValidation/globallycoherent3.hlsl
  63. 116 0
      tools/clang/test/DXILValidation/hsAttribute.hlsl
  64. 0 0
      tools/clang/test/DXILValidation/if1.hlsl
  65. 9 0
      tools/clang/test/DXILValidation/interpChange.hlsl
  66. 9 0
      tools/clang/test/DXILValidation/interpOnInt.hlsl
  67. 9 0
      tools/clang/test/DXILValidation/interpOnInt2.hlsl
  68. 18 0
      tools/clang/test/DXILValidation/intrinsic_val_imm.hlsl
  69. 34 0
      tools/clang/test/DXILValidation/lib_cs_entry.hlsl
  70. 13 0
      tools/clang/test/DXILValidation/lib_cs_entry2.hlsl
  71. 25 0
      tools/clang/test/DXILValidation/lib_cs_entry3.hlsl
  72. 191 0
      tools/clang/test/DXILValidation/lib_entries.hlsl
  73. 191 0
      tools/clang/test/DXILValidation/lib_entries2.hlsl
  74. 24 0
      tools/clang/test/DXILValidation/lib_global.hlsl
  75. 18 0
      tools/clang/test/DXILValidation/lib_global2.hlsl
  76. 13 0
      tools/clang/test/DXILValidation/lib_global3.hlsl
  77. 13 0
      tools/clang/test/DXILValidation/lib_global4.hlsl
  78. 16 0
      tools/clang/test/DXILValidation/lib_no_alias.hlsl
  79. 9 0
      tools/clang/test/DXILValidation/lib_no_alloca.h
  80. 10 0
      tools/clang/test/DXILValidation/lib_no_alloca.hlsl
  81. 15 0
      tools/clang/test/DXILValidation/lib_resource.hlsl
  82. 41 0
      tools/clang/test/DXILValidation/lib_resource2.hlsl
  83. 19 0
      tools/clang/test/DXILValidation/lib_select_res.hlsl
  84. 19 0
      tools/clang/test/DXILValidation/lib_select_res_codegenhlsl_copy.hlsl
  85. 8 0
      tools/clang/test/DXILValidation/lib_select_res_entry.hlsl
  86. 30 0
      tools/clang/test/DXILValidation/lib_unused_func.hlsl
  87. 15 0
      tools/clang/test/DXILValidation/local_resource2.hlsl
  88. 25 0
      tools/clang/test/DXILValidation/local_resource3.hlsl
  89. 18 0
      tools/clang/test/DXILValidation/local_resource5.hlsl
  90. 18 0
      tools/clang/test/DXILValidation/local_resource5_dbg.hlsl
  91. 22 0
      tools/clang/test/DXILValidation/local_resource6.hlsl
  92. 22 0
      tools/clang/test/DXILValidation/local_resource6_dbg.hlsl
  93. 0 0
      tools/clang/test/DXILValidation/loop1.hlsl
  94. 0 0
      tools/clang/test/DXILValidation/loop2.hlsl
  95. 0 0
      tools/clang/test/DXILValidation/multiStreamGS.hlsl
  96. 7 0
      tools/clang/test/DXILValidation/neg1.hlsl
  97. 17 0
      tools/clang/test/DXILValidation/optForNoOpt3.hlsl
  98. 17 0
      tools/clang/test/DXILValidation/optForNoOpt4.hlsl
  99. 12 0
      tools/clang/test/DXILValidation/phiTGSM.hlsl
  100. 205 0
      tools/clang/test/DXILValidation/recursive.ll

+ 1 - 0
tools/clang/test/CodeGenHLSL/Readme.md

@@ -0,0 +1 @@
+Files in this directory are used by tests implemented in CompilerTest.cpp

+ 0 - 53
tools/clang/test/CodeGenHLSL/batch/misc/signature_packing_by_width.hlsl

@@ -1,53 +0,0 @@
-// RUN: %dxilver 1.2 | %dxc -E main -T ps_6_2 -enable-16bit-types -HV 2018 %s | FileCheck %s
-
-// TODO: Update this file when we introduce i8
-
-// Checking if signature elements are packed by interpolation mode and data width with up to 4 elements.
-
-// CHECK: ; Name                 Index   Mask Register SysValue  Format   Used
-// CHECK: ; -------------------- ----- ------ -------- -------- ------- ------
-// CHECK: ; A                        0   xy          0     NONE    fp16
-// CHECK: ; F                        0     zw        0     NONE    fp16
-// CHECK: ; B                        0   xy          1     NONE   float
-// CHECK: ; D                        0     zw        1     NONE   float
-// CHECK: ; C                        0   xyz         2     NONE    fp16
-// CHECK: ; G                        0      w        2     NONE    fp16
-// CHECK: ; SV_PrimitiveID           0   x           3   PRIMID    uint
-// CHECK: ; E                        0   x           4     NONE     int
-// CHECK: ; I                        0    y          4     NONE     int
-// CHECK: ; H                        0   x           5     NONE   int16
-// CHECK: ; J                        0    yzw        5     NONE    fp16
-// CHECK: ; K                        0   xy          6     NONE   int16
-// CHECK: ; N                        0     z         6     NONE    fp16
-// CHECK: ; O                        0      w        6     NONE  uint16
-// CHECK: ; L                        0   xy          7     NONE    fp16
-// CHECK: ; Q                        0     z         7     NONE    fp16
-// CHECK: ; P                        0   xy          8     NONE  uint16
-// CHECK: ; SV_SampleIndex           0    N/A  special   SAMPLE    uint     NO
-
-// CHECK: !{i32 0, !"A", i8 8, i8 0, !{{[0-9]+}}, i8 2, i32 1, i8 2, i32 0, i8 0, null}
-// CHECK: !{i32 1, !"B", i8 9, i8 0, !{{[0-9]+}}, i8 2, i32 1, i8 2, i32 1, i8 0, null}
-// CHECK: !{i32 2, !"C", i8 8, i8 0, !{{[0-9]+}}, i8 2, i32 1, i8 3, i32 2, i8 0, null}
-// CHECK: !{i32 3, !"SV_PrimitiveID", i8 5, i8 10, !{{[0-9]+}}, i8 1, i32 1, i8 1, i32 3, i8 0, null}
-// CHECK: !{i32 4, !"D", i8 9, i8 0, !{{[0-9]+}}, i8 2, i32 1, i8 2, i32 1, i8 2, null}
-// CHECK: !{i32 5, !"E", i8 4, i8 0, !{{[0-9]+}}, i8 1, i32 1, i8 1, i32 4, i8 0, null}
-// CHECK: !{i32 6, !"F", i8 8, i8 0, !{{[0-9]+}}, i8 2, i32 1, i8 2, i32 0, i8 2, null}
-// CHECK: !{i32 7, !"G", i8 8, i8 0, !{{[0-9]+}}, i8 2, i32 1, i8 1, i32 2, i8 3, null}
-// CHECK: !{i32 8, !"H", i8 2, i8 0, !{{[0-9]+}}, i8 1, i32 1, i8 1, i32 5, i8 0, null}
-// CHECK: !{i32 9, !"I", i8 4, i8 0, !{{[0-9]+}}, i8 1, i32 1, i8 1, i32 4, i8 1, null}
-// CHECK: !{i32 10, !"J", i8 8, i8 0, !{{[0-9]+}}, i8 1, i32 1, i8 3, i32 5, i8 1, null}
-// CHECK: !{i32 11, !"K", i8 2, i8 0, !{{[0-9]+}}, i8 1, i32 1, i8 2, i32 6, i8 0, null}
-// CHECK: !{i32 12, !"L", i8 8, i8 0, !{{[0-9]+}}, i8 2, i32 1, i8 2, i32 7, i8 0, null}
-// CHECK: !{i32 13, !"N", i8 8, i8 0, !{{[0-9]+}}, i8 1, i32 1, i8 1, i32 6, i8 2, null}
-// CHECK: !{i32 14, !"SV_SampleIndex", i8 5, i8 12, !{{[0-9]+}}, i8 1, i32 1, i8 1, i32 -1, i8 -1, null}
-// CHECK: !{i32 15, !"O", i8 3, i8 0, !{{[0-9]+}}, i8 1, i32 1, i8 1, i32 6, i8 3, null}
-// CHECK: !{i32 16, !"P", i8 3, i8 0, !{{[0-9]+}}, i8 1, i32 1, i8 2, i32 8, i8 0, null}
-// CHECK: !{i32 17, !"Q", i8 8, i8 0, !{{[0-9]+}}, i8 2, i32 1, i8 1, i32 7, i8 2, null}
-
-float4 main(min16float2 a : A, float2 b : B, half3 c : C, uint id : SV_PrimitiveID,
-            float2 d : D, int e : E, half2 f : F, half g : G,
-            min16int h : H, int i : I, nointerpolation min16float3 j : J,
-            min16int2 k : K, half2 l : L, nointerpolation half n : N, uint sample_idx : SV_SampleIndex, uint16_t o : O,
-            vector<uint16_t,2> p : P, half q : Q) : SV_Target {
-  return 1;
-}

+ 14 - 0
tools/clang/test/CodeGenHLSL/filecheck_multiple_run_lines.hlsl

@@ -0,0 +1,14 @@
+// RUN: %dxc -E main -T vs_6_0 %s | FileCheck %s -check-prefixes=CHK1,CHK3
+// RUN: %dxc -E main -T vs_6_2 -enable-16bit-types %s | FileCheck %s -check-prefix=CHK2
+
+// CHK1: main 
+// CHK3: call float @dx.op.loadInput.f32 
+// CHK3-NEXT: call float @dx.op.loadInput.f32
+
+// CHK2: call half @dx.op.loadInput.f16
+// CHK2-NEXT: call half @dx.op.loadInput.f16
+
+half main(half a : IN0, half b : IN1) : OUT
+{ 
+	return a + b;
+}

+ 19 - 0
tools/clang/test/CodeGenHLSL/lib_select_res_codegenhlsl_copy.hlsl

@@ -0,0 +1,19 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// Make sure load resource rangeID when select resource.
+// CHECK:load i32, i32* @ReadBuffer1_rangeID
+// CHECK:load i32, i32* @ReadBuffer_rangeID
+
+RWByteAddressBuffer outputBuffer : register(u0);
+ByteAddressBuffer ReadBuffer : register(t0);
+ByteAddressBuffer ReadBuffer1 : register(t1);
+
+void test( uint cond)
+{
+	ByteAddressBuffer buffer = ReadBuffer;
+        if (cond > 2)
+           buffer = ReadBuffer1;
+
+	uint v= buffer.Load(0);
+    outputBuffer.Store(0, v);
+}

+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine1.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine1.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine10.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine10.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine11.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine11.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine2.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine2.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine3.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine3.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine4.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine4.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine5.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine5.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine6.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine6.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine7.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine7.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine8.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine8.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigDefine9.hlsl → tools/clang/test/CodeGenHLSL/rootSigDefine9.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigEntry.hlsl → tools/clang/test/CodeGenHLSL/rootSigEntry.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigProfile3.hlsl → tools/clang/test/CodeGenHLSL/rootSigProfile3.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/rootSigProfile4.hlsl → tools/clang/test/CodeGenHLSL/rootSigProfile4.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/structInBuffer.hlsl → tools/clang/test/CodeGenHLSL/structInBuffer.hlsl


+ 9 - 0
tools/clang/test/DXILValidation/AddUint64Odd.hlsl

@@ -0,0 +1,9 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: AddUint64 can only be applied to uint2 and uint4 operands
+
+float4 main(uint4 a : A, uint4 b :B) : SV_TARGET {
+  uint c = AddUint64(a.x, b.x);
+  uint3 c3 = AddUint64(a.xyz, b.xyz);
+  return c + c3.xyzz;
+}

+ 20 - 0
tools/clang/test/DXILValidation/BigStructInBuffer.hlsl

@@ -0,0 +1,20 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: elements of typed buffers and textures must fit in four 32-bit quantities
+
+struct Foo {
+  float2 a;
+  float b;
+  float c;
+  float d[2];
+};
+
+Buffer<Foo> inputs : register(t1);
+
+RWBuffer< int > g_Intensities : register(u1);
+
+[ numthreads( 64, 2, 2 ) ]
+void main( uint GI : SV_GroupIndex)
+{
+	g_Intensities = inputs[GI].d[0];
+}

+ 13 - 0
tools/clang/test/DXILValidation/EmptyStructInBuffer.hlsl

@@ -0,0 +1,13 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: object's templated type must have at least one element
+
+struct Empty {};
+Buffer<Empty> eb;
+
+
+[ numthreads( 64, 2, 2 ) ]
+void main( uint GI : SV_GroupIndex)
+{
+        eb[GI];
+}

+ 14 - 0
tools/clang/test/DXILValidation/GetDimCalcLOD.hlsl

@@ -0,0 +1,14 @@
+TextureCube<float4> cube;
+
+SamplerState    g_sam;
+
+float4 main(float2 uv : UV) : SV_TARGET
+{
+    uint w;
+    uint h;
+
+    cube.GetDimensions(w,h);
+    float lod = cube.CalculateLevelOfDetail(g_sam, float3(uv,1));
+    return float4(w, h, lod, 1.0);
+}
+

+ 22 - 0
tools/clang/test/DXILValidation/Include.hlsl

@@ -0,0 +1,22 @@
+// RUN: %dxc -E main -T ps_6_0 -Vi -I inc %s | FileCheck -input=stderr %s
+
+
+
+// CHECK: Opening file [
+// CHECK: /inc/header.hlsli], stack top [0]
+
+#include "inc/header.hlsli"
+
+//--------------------------------------------------------------------------------------
+// Pixel Shader
+//--------------------------------------------------------------------------------------
+float4 main( PS_INPUT Input) : SV_TARGET
+{
+	float4 vDiffuse = g_txDiffuse.Sample( g_samLinear, Input.vTexcoord );
+	
+	float fLighting = saturate( dot( g_vLightDir, Input.vNormal ) );
+	fLighting = max( fLighting, g_fAmbient );
+	
+	return vDiffuse * fLighting;
+}
+

+ 19 - 0
tools/clang/test/DXILValidation/InnerCoverage.hlsl

@@ -0,0 +1,19 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// note: define GENLL in order to generate the basis for InnerCoverage.ll
+
+// CHECK: error: Parameter with semantic SV_InnerCoverage has overlapping semantic index at 0
+// CHECK: error: Pixel shader inputs SV_Coverage and SV_InnerCoverage are mutually exclusive
+
+void main(snorm float b : B, uint c:C, 
+#ifndef GENLL
+	in uint inner : SV_InnerCoverage, in uint inner2 : SV_InnerCoverage,
+#endif
+	inout uint cover: SV_Coverage)
+{
+#ifndef GENLL
+  cover = cover & c;
+#else
+  cover = cover & inner;
+#endif
+}

+ 17 - 0
tools/clang/test/DXILValidation/InnerCoverage2.hlsl

@@ -0,0 +1,17 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// note: define GENLL in order to generate the basis for InnerCoverage.ll
+
+// CHECK: error: Parameter with semantic SV_InnerCoverage has overlapping semantic index at 0
+// CHECK: error: Pixel shader inputs SV_Coverage and SV_InnerCoverage are mutually exclusive
+
+void main(snorm float b : B, uint c:C,
+	in uint inner : InnerCoverage,
+	inout uint cover: SV_Coverage)
+{
+#ifndef GENLL
+  cover = cover & c;
+#else
+  cover = cover & inner;
+#endif
+}

+ 8 - 0
tools/clang/test/DXILValidation/IntegerDepth.hlsl

@@ -0,0 +1,8 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: @main
+
+int main(snorm float b : B, float c:C) : SV_DEPTH
+{
+  return b;
+}

+ 8 - 0
tools/clang/test/DXILValidation/IntegerDepth2.hlsl

@@ -0,0 +1,8 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: @main
+
+float main(snorm float b : B, float c:C) : SV_DEPTH
+{
+  return b;
+}

+ 15 - 0
tools/clang/test/DXILValidation/RaceCond.hlsl

@@ -0,0 +1,15 @@
+// RUN: %dxc -E main  -T cs_6_0 %s | FileCheck %s
+
+// CHECK: Race condition writing to shared memory detected, consider making this write conditional
+
+RWBuffer< int > g_Intensities : register(u1);
+
+groupshared int sharedData;
+
+[ numthreads( 64, 2, 2 ) ]
+void main( uint GI : SV_GroupIndex)
+{
+sharedData = GI;
+InterlockedAdd(sharedData, g_Intensities[GI]);
+g_Intensities[GI] = sharedData;
+}

+ 1 - 0
tools/clang/test/DXILValidation/Readme.md

@@ -0,0 +1 @@
+Files in this directory are used by tests implemented ValidationTest.cpp

+ 73 - 0
tools/clang/test/DXILValidation/SamplerKind.hlsl

@@ -0,0 +1,73 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: DepthOutput=0
+// CHECK: SampleFrequency=1
+
+// CHECK: NORMAL                   0                 sample
+// CHECK: TEXCOORD                 0          noperspective
+
+// CHECK: g_txDiffuse_texture_2d
+// CHECK: g_samLinear_sampler
+
+//--------------------------------------------------------------------------------------
+// File: BasicHLSL11_PS.hlsl
+//
+// The pixel shader file for the BasicHLSL11 sample.  
+// 
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//--------------------------------------------------------------------------------------
+
+//--------------------------------------------------------------------------------------
+// Globals
+//--------------------------------------------------------------------------------------
+cbuffer cbPerObject : register( b0 )
+{
+    float4    g_vObjectColor    : packoffset( c0 );
+};
+
+cbuffer cbPerFrame : register( b1 )
+{
+    float3    g_vLightDir    : packoffset( c0 );
+    float    g_fAmbient    : packoffset( c0.w );
+};
+
+//--------------------------------------------------------------------------------------
+// Textures and Samplers
+//--------------------------------------------------------------------------------------
+Texture2D    g_txDiffuse : register( t0 );
+SamplerState    g_samLinear : register( s0 );
+SamplerComparisonState     g_samLinearC : register( s1 );
+RWTexture2D<float4>    uav1 : register( u3 );
+
+//--------------------------------------------------------------------------------------
+// Input / Output structures
+//--------------------------------------------------------------------------------------
+struct PS_INPUT
+{
+  sample          float3 vNormal    : NORMAL;
+  noperspective   float2 vTexcoord  : TEXCOORD0;
+};
+
+float cmpVal;
+
+//--------------------------------------------------------------------------------------
+// Pixel Shader
+//--------------------------------------------------------------------------------------
+float4 main( PS_INPUT Input) : SV_TARGET
+{
+    float4 vDiffuse = g_txDiffuse.Sample( g_samLinear, Input.vTexcoord );
+
+    vDiffuse  += g_txDiffuse.CalculateLevelOfDetail(g_samLinear, Input.vTexcoord);
+
+    vDiffuse  += g_txDiffuse.Gather(g_samLinear, Input.vTexcoord);
+
+    vDiffuse  += g_txDiffuse.SampleCmp(g_samLinearC, Input.vTexcoord, cmpVal);
+
+    vDiffuse  += g_txDiffuse.GatherCmp(g_samLinearC, Input.vTexcoord, cmpVal);
+
+    float fLighting = saturate( dot( g_vLightDir, Input.vNormal ) );
+    fLighting = max( fLighting, g_fAmbient );
+    
+    return vDiffuse * fLighting * uav1.Load(int2(0,0));
+}
+

+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/SimpleDs1.hlsl → tools/clang/test/DXILValidation/SimpleDs1.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/SimpleGS1.hlsl → tools/clang/test/DXILValidation/SimpleGS1.hlsl


+ 23 - 0
tools/clang/test/DXILValidation/SimpleGS10.hlsl

@@ -0,0 +1,23 @@
+// RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
+
+// CHECK: input types for geometry shader must be constant size arrays
+
+
+struct Out
+{
+  float4 pos : SV_Position;
+  float4 a[2] : A;
+};
+
+struct Empty{};
+int i;
+
+[maxvertexcount(3)]
+void main(line Empty e, inout PointStream<Out> OutputStream0)
+{
+  Out output = (Out)0;
+  output.a[i] = 3;
+
+  OutputStream0.Append(output);
+  OutputStream0.RestartStrip();
+}

+ 23 - 0
tools/clang/test/DXILValidation/SimpleGS8.hlsl

@@ -0,0 +1,23 @@
+// RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
+
+// CHECK: array dimension for line must be 2
+
+
+struct Out
+{
+  float4 pos : SV_Position;
+  float4 a[2] : A;
+};
+
+struct Empty{};
+int i;
+
+[maxvertexcount(3)]
+void main(line Empty e[4], inout PointStream<Out> OutputStream0)
+{
+  Out output = (Out)0;
+  output.a[i] = 3;
+
+  OutputStream0.Append(output);
+  OutputStream0.RestartStrip();
+}

+ 23 - 0
tools/clang/test/DXILValidation/SimpleGS9.hlsl

@@ -0,0 +1,23 @@
+// RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
+
+// CHECK: input parameter conflicts with geometry specifier of previous input parameters
+
+
+struct Out
+{
+  float4 pos : SV_Position;
+  float4 a[2] : A;
+};
+
+struct Empty{};
+int i;
+
+[maxvertexcount(3)]
+void main(line Empty e[2], lineadj Empty e2[4], inout PointStream<Out> OutputStream0)
+{
+  Out output = (Out)0;
+  output.a[i] = 3;
+
+  OutputStream0.Append(output);
+  OutputStream0.RestartStrip();
+}

+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/SimpleHs1.hlsl → tools/clang/test/DXILValidation/SimpleHs1.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/SimpleHs3.hlsl → tools/clang/test/DXILValidation/SimpleHs3.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/SimpleHs4.hlsl → tools/clang/test/DXILValidation/SimpleHs4.hlsl


+ 9 - 0
tools/clang/test/DXILValidation/UndefValue.hlsl

@@ -0,0 +1,9 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: Instructions should not read uninitialized value
+
+float main(snorm float b : B) : SV_DEPTH
+{
+  float a;
+  return b + a;
+}

+ 9 - 0
tools/clang/test/DXILValidation/UndefValue2.hlsl

@@ -0,0 +1,9 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: @main
+
+float a;
+float main(snorm float b : B) : SV_DEPTH
+{
+  return b + a;
+}

+ 0 - 0
tools/clang/test/CodeGenHLSL/validation/abs1.hlsl → tools/clang/test/DXILValidation/abs1.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/expressions/intrinsics/misc/abs2.hlsl → tools/clang/test/DXILValidation/abs2.hlsl


+ 26 - 0
tools/clang/test/DXILValidation/attributes-gs-no-inout-main.hlsl

@@ -0,0 +1,26 @@
+// RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
+
+// CHECK: 18:11: error: stream-output object must be an inout parameter
+
+struct GsOut {
+    float4 pos : SV_Position;
+};
+
+void foo(inout LineStream<GsOut> param) {
+    GsOut vertex;
+    vertex = (GsOut)0;
+    param.Append(vertex);
+}
+
+// Missing inout on outData
+[maxvertexcount(3)]
+void main(in triangle float4 pos[3] : SV_Position,
+          LineStream<GsOut> outData) {
+    GsOut vertex;
+    vertex.pos = pos[0];
+    outData.Append(vertex);
+
+    foo(outData);
+
+    outData.RestartStrip();
+}

+ 26 - 0
tools/clang/test/DXILValidation/attributes-gs-no-inout-other.hlsl

@@ -0,0 +1,26 @@
+// RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
+
+// CHECK: 10:10: error: stream-output object must be an inout parameter
+
+struct GsOut {
+    float4 pos : SV_Position;
+};
+
+// Missing inout on param
+void foo(LineStream<GsOut> param) {
+    GsOut vertex;
+    vertex = (GsOut)0;
+    param.Append(vertex);
+}
+
+[maxvertexcount(3)]
+void main(in triangle float4 pos[3] : SV_Position,
+          inout LineStream<GsOut> outData) {
+    GsOut vertex;
+    vertex.pos = pos[0];
+    outData.Append(vertex);
+
+    foo(outData);
+
+    outData.RestartStrip();
+}

+ 25 - 0
tools/clang/test/DXILValidation/attributes-gs-no-maxvertexcount.hlsl

@@ -0,0 +1,25 @@
+// RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
+
+// CHECK: :16:6: error: GS entry point must have the maxvertexcount attribute
+
+struct GsOut {
+    float4 pos : SV_Position;
+};
+
+void foo(inout LineStream<GsOut> param) {
+    GsOut vertex;
+    vertex = (GsOut)0;
+    param.Append(vertex);
+}
+
+// Missing maxvertexcount attribute
+void main(in triangle float4 pos[3] : SV_Position,
+          inout LineStream<GsOut> outData) {
+    GsOut vertex;
+    vertex.pos = pos[0];
+    outData.Append(vertex);
+
+    foo(outData);
+
+    outData.RestartStrip();
+}

+ 38 - 0
tools/clang/test/DXILValidation/attributes-hs-no-pcf.hlsl

@@ -0,0 +1,38 @@
+// RUN: %dxc -E main -T hs_6_0 %s | FileCheck %s
+
+// CHECK: :32:9: error: HS entry point must have the patchconstantfunc attribute
+
+#define NumOutPoints 2
+
+struct HsCpIn {
+    float4 pos : SV_Position;
+};
+
+struct HsCpOut {
+    float4 pos : SV_Position;
+};
+
+struct HsPcfOut
+{
+  float tessOuter[4] : SV_TessFactor;
+  float tessInner[2] : SV_InsideTessFactor;
+};
+
+HsPcfOut pcf(InputPatch<HsCpIn, NumOutPoints> patch, uint patchId : SV_PrimitiveID) {
+  HsPcfOut output;
+  output = (HsPcfOut)0;
+  return output;
+}
+
+// Missing patchconstantfunc attribute
+[domain("quad")]
+[partitioning("fractional_odd")]
+[outputtopology("triangle_ccw")]
+[outputcontrolpoints(NumOutPoints)]
+HsCpOut main(InputPatch<HsCpIn, NumOutPoints> patch,
+             uint cpId : SV_OutputControlPointID,
+             uint patchId : SV_PrimitiveID) {
+    HsCpOut output;
+    output = (HsCpOut)0;
+    return output;
+}

+ 83 - 0
tools/clang/test/DXILValidation/barrier.hlsl

@@ -0,0 +1,83 @@
+// RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
+
+// CHECK: ; Buffer Definitions:
+
+// CHECK: ; Resource bind info for mats
+// CHECK: ; {
+
+// CHECK: ;   struct dx.alignment.legacy.struct.mat
+// CHECK: ;   {
+
+// CHECK: ;       row_major float2x2 f2x2;                      ; Offset:    0
+
+// CHECK: ;   } $Element;                                       ; Offset:    0 Size:    16
+
+// CHECK: ; }
+
+// CHECK: ; Resource bind info for mats2
+// CHECK: ; {
+
+// CHECK: ;   column_major float2x2 $Element;                                ; Offset:    0 Size:    16
+
+// CHECK: ; }
+
+// CHECK: ; Resource bind info for fA
+// CHECK: ; {
+
+// CHECK: ;   column_major float2x2 $Element;                                ; Offset:    0 Size:    16
+
+// CHECK: ; }
+
+// CHECK: ; Resource Bindings:
+
+// CHECK: ; Name                                 Type  Format         Dim      ID      HLSL Bind  Count
+// CHECK: ; ------------------------------ ---------- ------- ----------- ------- -------------- ------
+// CHECK: ; mats                              texture  struct         r/o      T0             t0     1
+// CHECK: ; mats2                             texture  struct         r/o      T1             t1     1
+// CHECK: ; fA                                    UAV  struct         r/w      U0             u0     1
+
+// CHECK: threadId
+// CHECK: groupId
+// CHECK: threadIdInGroup
+// CHECK: flattenedThreadIdInGroup
+// CHECK: addrspace(3)
+// CHECK: barrier
+// CHECK: i32 8
+// CHECK: barrier
+// CHECK: i32 9
+// CHECK: barrier
+// CHECK: i32 10
+// CHECK: barrier
+// CHECK: i32 11
+// CHECK: barrier
+// CHECK: i32 2
+// CHECK: barrier
+// CHECK: i32 4
+// CHECK: noduplicate
+
+groupshared column_major float2x2 dataC[8*8];
+
+RWStructuredBuffer<float2x2> fA;
+
+struct mat {
+  row_major float2x2 f2x2;
+};
+
+StructuredBuffer<mat> mats;
+StructuredBuffer<float2x2> mats2;
+
+[numthreads(8,8,1)]
+void main( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+    dataC[tid.x%(8*8)] = mats.Load(gid.x).f2x2 + mats2.Load(gtid.y);
+	GroupMemoryBarrier();
+    GroupMemoryBarrierWithGroupSync();
+    float2x2 f2x2 = dataC[8*8-1-tid.y%(8*8)];
+  AllMemoryBarrier();
+       fA[gidx+2] = f2x2;
+  AllMemoryBarrierWithGroupSync();
+      fA[gidx+1] = f2x2;
+  DeviceMemoryBarrier();
+  DeviceMemoryBarrierWithGroupSync();
+    fA[gidx] = f2x2;
+}

+ 0 - 0
tools/clang/test/CodeGenHLSL/validation/binary1.hlsl → tools/clang/test/DXILValidation/binary1.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/cbuffer1.50.hlsl → tools/clang/test/DXILValidation/cbuffer1.50.hlsl


+ 12 - 0
tools/clang/test/DXILValidation/cbufferOffset.hlsl

@@ -0,0 +1,12 @@
+// RUN: %dxc -E main -T ps_6_0 %s
+
+cbuffer Foo1 : register(b5)
+{
+  float4 g1 : packoffset(c1);
+  float4 g2 : packoffset(c0);
+}
+
+float4 main() : SV_TARGET
+{
+  return g2+g1;
+}

+ 10 - 0
tools/clang/test/DXILValidation/cbuffer_unused2.hlsl

@@ -0,0 +1,10 @@
+// RUN: %dxc -E main -T ps_6_0 %s
+
+// Check used flag in reflection.
+
+int a;
+int b;
+
+float4 main() : SV_Target {
+  return b;
+}

+ 10 - 0
tools/clang/test/DXILValidation/check_nowarning.hlsl

@@ -0,0 +1,10 @@
+// RUN: %dxc -E main -no-warnings -T ps_6_0 %s | FileCheck %s
+// CHECK-NOT: warning: attribute 'branch' can only be applied to 'if' and 'switch' statements
+
+[branch] // this should generate a warning that is used for testing
+float4 main() : SV_TARGET
+{
+    // no return stmt should cause error which is needed to direct errors
+	// and warnings to stdin instead of dxil output.
+    // return float4(1, 0, 0, 1);
+}

+ 10 - 0
tools/clang/test/DXILValidation/check_warning.hlsl

@@ -0,0 +1,10 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+// CHECK: warning: attribute 'branch' can only be applied to 'if' and 'switch' statements
+
+[branch] // this should generate a warning that is used for testing
+float4 main() : SV_TARGET
+{
+    // no return stmt should cause error which is needed to direct errors
+	// and warnings to stdin instead of dxil output.
+    // return float4(1, 0, 0, 1);
+}

+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/clip_planes.hlsl → tools/clang/test/DXILValidation/clip_planes.hlsl


+ 16 - 0
tools/clang/test/DXILValidation/deadloop - Copy.hlsl

@@ -0,0 +1,16 @@
+// RUN: %dxc -E main -T ps_6_0 %s  | FileCheck %s
+
+// CHECK: !"llvm.loop.unroll.disable"
+
+int i;
+
+float main(float2 a : A, int3 b : B) : SV_Target
+{
+  float s = 0;
+  
+  while(i < b.x) {
+    s += a.x;
+  }
+
+  return s;
+}

+ 16 - 0
tools/clang/test/DXILValidation/deadloop.hlsl

@@ -0,0 +1,16 @@
+// RUN: %dxc -E main -T ps_6_0 %s  | FileCheck %s
+
+// CHECK: !"llvm.loop.unroll.disable"
+
+int i;
+
+float main(float2 a : A, int3 b : B) : SV_Target
+{
+  float s = 0;
+  
+  while(i < b.x) {
+    s += a.x;
+  }
+
+  return s;
+}

+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/eval.hlsl → tools/clang/test/DXILValidation/eval.hlsl


+ 14 - 0
tools/clang/test/DXILValidation/filecheck_multiple_run_lines.hlsl

@@ -0,0 +1,14 @@
+// RUN: %dxc -E main -T vs_6_0 %s | FileCheck %s -check-prefixes=CHK1,CHK3
+// RUN: %dxc -E main -T vs_6_2 -enable-16bit-types %s | FileCheck %s -check-prefix=CHK2
+
+// CHK1: main 
+// CHK3: call float @dx.op.loadInput.f32 
+// CHK3-NEXT: call float @dx.op.loadInput.f32
+
+// CHK2: call half @dx.op.loadInput.f16
+// CHK2-NEXT: call half @dx.op.loadInput.f16
+
+half main(half a : IN0, half b : IN1) : OUT
+{ 
+	return a + b;
+}

+ 7 - 0
tools/clang/test/DXILValidation/fpexcept.hlsl

@@ -0,0 +1,7 @@
+// RUN: %dxc -E main -T ps_6_0 %s
+
+float3 main() : SV_Target
+{
+    // Some calls known to cause floating point exceptions when evaluated
+    return float3(pow(0.0f, 0.0f), pow(-1.0f, 0.5f), pow(0.0f, -1.0f));
+}

+ 17 - 0
tools/clang/test/DXILValidation/globallycoherent2.hlsl

@@ -0,0 +1,17 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: globallycoherent can only be used with Unordered Access View buffers
+
+globallycoherent RWTexture1D<float4> uav1 : register(u3);
+RWBuffer<float4> uav2;
+globallycoherent Buffer<float4> srv;
+
+ float4 main(uint2 a : A, uint2 b : B) : SV_Target
+{
+  globallycoherent  RWTexture1D<float4> uav3 = uav1;
+  float x = 3;
+  uav3[0] = srv[0];
+  uav1[0] = 2;
+  uav2[1] = 3;
+  return 0;
+}

+ 16 - 0
tools/clang/test/DXILValidation/globallycoherent3.hlsl

@@ -0,0 +1,16 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: 'globallycoherent' is not a valid modifier for a non-UAV type
+
+globallycoherent RWTexture1D<float4> uav1 : register(u3);
+RWBuffer<float4> uav2;
+globallycoherent float m;
+float4 main(uint2 a : A, uint2 b : B) : SV_Target
+{
+  globallycoherent  RWTexture1D<float4> uav3 = uav1;
+  globallycoherent float x = 3;
+  uav3[0] = 0;
+  uav1[0] = 2;
+  uav2[1] = 3;
+  return 0;
+}

+ 116 - 0
tools/clang/test/DXILValidation/hsAttribute.hlsl

@@ -0,0 +1,116 @@
+// RUN: %dxc -E main -T hs_6_0 %s | FileCheck %s
+
+// CHECK: InputControlPointCount=3
+// CHECK: OutputControlPointCount=3
+// CHECK: Domain=tri
+// CHECK: OutputPrimitive=triangle_cw
+
+// CHECK: storePatchConstant
+// CHECK: outputControlPointID
+
+//--------------------------------------------------------------------------------------
+// SimpleTessellation.hlsl
+//
+// Advanced Technology Group (ATG)
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//--------------------------------------------------------------------------------------
+
+struct VSSceneIn
+{
+    float3 pos    : POSITION;            
+    float3 norm   : NORMAL;            
+    float2 tex    : TEXCOORD0;            
+};
+
+struct PSSceneIn
+{
+    float4 pos  : SV_Position;
+    float2 tex  : TEXCOORD0;
+    float3 norm : NORMAL;
+};
+
+cbuffer cb0
+{
+    float4x4    g_mWorldViewProj;
+};
+
+Texture2D        g_txDiffuse : register( t0 );
+
+SamplerState    g_sampler : register( s0 );
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// Regular VS/PS rendering
+
+PSSceneIn VSSceneMain( VSSceneIn input )
+{
+    PSSceneIn output;
+    
+    output.pos = mul( float4( input.pos, 1.0 ), g_mWorldViewProj );
+    output.tex = input.tex;
+    output.norm = input.norm;
+    
+    return output;
+}
+
+float4 PSSceneMain( PSSceneIn input ) : SV_Target
+{    
+    return g_txDiffuse.Sample( g_sampler, input.tex );
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// Simple forwarding Tessellation shaders
+
+struct HSPerVertexData
+{
+    // This is just the original vertex verbatim. In many real life cases this would be a
+    // control point instead
+    PSSceneIn v;
+};
+
+struct HSPerPatchData
+{
+    // We at least have to specify tess factors per patch
+    // As we're tesselating triangles, there will be 4 tess factors
+    // In real life case this might contain face normal, for example
+	float	edges[ 3 ]	: SV_TessFactor;
+	float	inside		: SV_InsideTessFactor;
+};
+
+float4 HSPerPatchFunc()
+{
+    return 1.8;
+}
+
+HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points )
+{
+    HSPerPatchData d;
+
+    d.edges[ 0 ] = 1;
+    d.edges[ 1 ] = 1;
+    d.edges[ 2 ] = 1;
+    d.inside = 1;
+
+    return d;
+}
+
+// hull per-control point shader
+[domain("tri")]
+[partitioning("fractional_odd")]
+[outputtopology("triangle_cw")]
+[patchconstantfunc("HSPerPatchFunc")]
+[outputcontrolpoints(3)]
+HSPerVertexData main( const uint id : SV_OutputControlPointID,
+                               const InputPatch< PSSceneIn, 3 > points )
+{
+    HSPerVertexData v;
+
+    // Just forward the vertex
+    v.v = points[ id ];
+
+	return v;
+}
+
+

+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/if1.hlsl → tools/clang/test/DXILValidation/if1.hlsl


+ 9 - 0
tools/clang/test/DXILValidation/interpChange.hlsl

@@ -0,0 +1,9 @@
+// RUN: %dxc -E main -T ps_6_0 -fcgl %s | FileCheck %s
+
+// CHECK: main
+// After lowering, these would turn into multiple abs calls rather than a 4 x float
+// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 62,
+
+float4 main(float2 a : A, centroid float2 b : A1) : SV_TARGET {
+  return float4(a,b);
+}

+ 9 - 0
tools/clang/test/DXILValidation/interpOnInt.hlsl

@@ -0,0 +1,9 @@
+// RUN: %dxc -E main -T ps_6_0 -fcgl %s | FileCheck %s
+
+// CHECK: main
+// After lowering, these would turn into multiple abs calls rather than a 4 x float
+// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 62,
+
+float4 main(float4 a : A, centroid uint4 b : A1) : SV_TARGET {
+  return abs(a*b.yxxx);
+}

+ 9 - 0
tools/clang/test/DXILValidation/interpOnInt2.hlsl

@@ -0,0 +1,9 @@
+// RUN: %dxc -E main -T ps_6_0 -fcgl %s | FileCheck %s
+
+// CHECK: main
+// After lowering, these would turn into multiple abs calls rather than a 4 x float
+// CHECK: call <4 x float> @"dx.hl.op..<4 x float> (i32, <4 x float>)"(i32 62,
+
+float4 main(float4 a : A, uint4 b : A1) : SV_TARGET {
+  return abs(a*b.yxxx);
+}

+ 18 - 0
tools/clang/test/DXILValidation/intrinsic_val_imm.hlsl

@@ -0,0 +1,18 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: Shader extensions for 11.1
+
+
+// CHECK: Asin
+// CHECK: Acos
+
+float v;
+uint2 s;
+int2  i;
+
+float4 main(float4 arg : A) : SV_TARGET {
+  float t = asin(v) + acos(v) + s.x/s.y + i.x/i.y + log(v);
+  t +=  ddx(v) + ddy(s.x);
+  t +=  ddx_fine(v) + ddy_fine(s.x);
+  return t;
+}

+ 34 - 0
tools/clang/test/DXILValidation/lib_cs_entry.hlsl

@@ -0,0 +1,34 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// Make sure entry function exist.
+// CHECK: @entry(
+
+// Make sure function decl exist.
+// CHECK: LoadInputMat
+// CHECK: RotateMat
+// CHECK: StoreOutputMat
+
+// Make sure function props exist.
+// CHECK: !dx.entryPoints = !{{{.*}}, {{.*}}}
+
+// Make sure function props is correct for [numthreads(8,8,1)].
+// CHECK: @entry,
+// CHECK: !{i32 8, i32 8, i32 1}
+
+cbuffer A {
+  float a;
+}
+
+void StoreOutputMat(float2x2  m, uint gidx);
+float2x2 LoadInputMat(uint x, uint y);
+float2x2 RotateMat(float2x2 m, uint x, uint y);
+
+[numthreads(8,8,1)]
+void entry( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+    float2x2 f2x2 = LoadInputMat(gid.x, gid.y);
+
+    f2x2 = RotateMat(f2x2, tid.x, tid.y) + a;
+
+    StoreOutputMat(f2x2, gidx);
+}

+ 13 - 0
tools/clang/test/DXILValidation/lib_cs_entry2.hlsl

@@ -0,0 +1,13 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// CHECK: redefinition of entry
+
+[numthreads(8,8,1)]
+void entry( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+}
+
+[numthreads(8,8,1)]
+void entry( uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+}

+ 25 - 0
tools/clang/test/DXILValidation/lib_cs_entry3.hlsl

@@ -0,0 +1,25 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// Make sure entry function exist.
+// CHECK: @entry(
+// CHECK: @entry2(
+
+// Make sure function props exist.
+// CHECK: !dx.entryPoints = !{{{.*}}, {{.*}}, {{.*}}}
+
+// Make sure function props is correct for [numthreads(8,8,1)].
+// CHECK: @entry, !"entry", null, null, [[PROPS:![0-9]+]]}
+// CHECK: [[PROPS]] = !{i32 8, i32 5, i32 4, [[CS:![0-9]+]],
+// CHECK: [[CS]] = !{i32 8, i32 8, i32 1}
+// CHECK: @entry2, !"entry2", null, null, [[PROPS]]
+
+
+[numthreads(8,8,1)]
+void entry( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+}
+
+[numthreads(8,8,1)]
+void entry2( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+}

+ 191 - 0
tools/clang/test/DXILValidation/lib_entries.hlsl

@@ -0,0 +1,191 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+
+// Make sure entry function exist.
+// CHECK: @cs_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.threadId
+// CHECK: dx.op.groupId
+
+// Make sure entry function exist.
+// CHECK: @gs_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+// CHECK: dx.op.emitStream
+// CHECK: dx.op.cutStream
+
+// Make sure entry function exist.
+// CHECK: @ds_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.loadPatchConstant
+// CHECK: dx.op.domainLocation
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+
+// Make sure patch constant function exist.
+// CHECK: HSPerPatchFunc
+// Make sure signatures are lowered.
+// CHECK: dx.op.storePatchConstant
+
+// Make sure entry function exist.
+// CHECK: @hs_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.outputControlPointID
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+
+// Make sure entry function exist.
+// CHECK: @vs_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.loadInput
+// Dot4 for clipplane
+// CHECK: dx.op.dot4
+// CHECK: dx.op.storeOutput
+
+// Make sure entry function exist.
+// CHECK: @ps_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+// Finish ps_main
+// CHECK: ret void
+
+
+// Make sure function entrys exist.
+// CHECK: !dx.entryPoints = !{{{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}}
+// Make sure cs doesn't have signature.
+// CHECK: !"cs_main", null
+
+void StoreCSOutput(uint2 tid, uint2 gid);
+
+[numthreads(8,8,1)]
+void cs_main( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+    StoreCSOutput(tid, gid);
+}
+
+// GS
+
+struct GSOut {
+  float2 uv : TEXCOORD0;
+  float4 pos : SV_Position;
+};
+
+// geometry shader that outputs 3 vertices from a point
+[maxvertexcount(3)]
+[instance(24)]
+void gs_main(InputPatch<GSOut, 2>points, inout PointStream<GSOut> stream) {
+
+  stream.Append(points[0]);
+
+  stream.RestartStrip();
+}
+
+// DS
+struct PSSceneIn {
+  float4 pos : SV_Position;
+  float2 tex : TEXCOORD0;
+  float3 norm : NORMAL;
+
+uint   RTIndex      : SV_RenderTargetArrayIndex;
+};
+
+struct HSPerVertexData {
+  // This is just the original vertex verbatim. In many real life cases this would be a
+  // control point instead
+  PSSceneIn v;
+};
+
+struct HSPerPatchData {
+  // We at least have to specify tess factors per patch
+  // As we're tesselating triangles, there will be 4 tess factors
+  // In real life case this might contain face normal, for example
+  float edges[3] : SV_TessFactor;
+  float inside : SV_InsideTessFactor;
+};
+
+// domain shader that actually outputs the triangle vertices
+[domain("tri")] PSSceneIn ds_main(const float3 bary
+                               : SV_DomainLocation,
+                                 const OutputPatch<HSPerVertexData, 3> patch,
+                                 const HSPerPatchData perPatchData) {
+  PSSceneIn v;
+
+  // Compute interpolated coordinates
+  v.pos = patch[0].v.pos * bary.x + patch[1].v.pos * bary.y + patch[2].v.pos * bary.z + perPatchData.edges[1];
+  v.tex = patch[0].v.tex * bary.x + patch[1].v.tex * bary.y + patch[2].v.tex * bary.z + perPatchData.edges[0];
+  v.norm = patch[0].v.norm * bary.x + patch[1].v.norm * bary.y + patch[2].v.norm * bary.z + perPatchData.inside;
+  v.RTIndex = 0;
+  return v;
+}
+
+// HS
+
+HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, OutputPatch<HSPerVertexData, 3> outp)
+{
+    HSPerPatchData d;
+
+    d.edges[ 0 ] = 1;
+    d.edges[ 1 ] = 1;
+    d.edges[ 2 ] = 1;
+    d.inside = 1;
+
+    return d;
+}
+
+// hull per-control point shader
+[domain("tri")]
+[partitioning("fractional_odd")]
+[outputtopology("triangle_cw")]
+[patchconstantfunc("HSPerPatchFunc")]
+[outputcontrolpoints(3)]
+HSPerVertexData hs_main( const uint id : SV_OutputControlPointID,
+                               const InputPatch< PSSceneIn, 3 > points)
+{
+    HSPerVertexData v;
+
+    // Just forward the vertex
+    v.v = points[ id ];
+
+	return v;
+}
+
+// VS
+
+struct VS_INPUT
+{
+	float3 vPosition	: POSITION;
+	float3 vNormal		: NORMAL;
+	float2 vTexcoord	: TEXCOORD0;
+};
+
+struct VS_OUTPUT
+{
+	float3 vNormal		: NORMAL;
+	float2 vTexcoord	: TEXCOORD0;
+	float4 vPosition	: SV_POSITION;
+};
+
+cbuffer VSCB {
+float4 plane;
+}
+
+[clipplanes(plane)]
+VS_OUTPUT vs_main(VS_INPUT Input)
+{
+	VS_OUTPUT Output;
+
+	Output.vPosition = float4( Input.vPosition, 1.0 );
+	Output.vNormal = Input.vNormal;
+	Output.vTexcoord = Input.vTexcoord;
+
+       return Output;
+}
+
+// PS
+[earlydepthstencil]
+float4 ps_main(float4 a : A) : SV_TARGET
+{
+  return a;
+}

+ 191 - 0
tools/clang/test/DXILValidation/lib_entries2.hlsl

@@ -0,0 +1,191 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// Make sure entry function exist.
+// CHECK: @cs_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.threadId
+// CHECK: dx.op.groupId
+
+// Make sure entry function exist.
+// CHECK: @gs_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+// CHECK: dx.op.emitStream
+// CHECK: dx.op.cutStream
+
+// Make sure entry function exist.
+// CHECK: @ds_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.loadPatchConstant
+// CHECK: dx.op.domainLocation
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+
+// Make sure patch constant function exist.
+// CHECK: HSPerPatchFunc
+// Make sure signatures are lowered.
+// CHECK: dx.op.storePatchConstant
+
+// Make sure entry function exist.
+// CHECK: @hs_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.outputControlPointID
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+
+// Make sure entry function exist.
+// CHECK: @vs_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+
+// Make sure entry function exist.
+// CHECK: @ps_main()
+// Make sure signatures are lowered.
+// CHECK: dx.op.loadInput
+// CHECK: dx.op.storeOutput
+// Finish ps_main
+// CHECK: ret void
+
+
+
+
+// Make sure function entrys exist.
+// CHECK: !dx.entryPoints = !{{{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}}
+// Make sure cs don't have signature.
+// CHECK: !"cs_main", null
+
+void StoreCSOutput(uint2 tid, uint2 gid);
+
+[shader("compute")]
+[numthreads(8,8,1)]
+void cs_main( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+    StoreCSOutput(tid, gid);
+}
+
+// GS
+
+struct GSOut {
+  float2 uv : TEXCOORD0;
+  float4 pos : SV_Position;
+};
+
+// geometry shader that outputs 3 vertices from a point
+[shader("geometry")]
+[maxvertexcount(3)]
+[instance(24)]
+void gs_main(InputPatch<GSOut, 2>points, inout PointStream<GSOut> stream) {
+
+  stream.Append(points[0]);
+
+  stream.RestartStrip();
+}
+
+// DS
+struct PSSceneIn {
+  float4 pos : SV_Position;
+  float2 tex : TEXCOORD0;
+  float3 norm : NORMAL;
+
+uint   RTIndex      : SV_RenderTargetArrayIndex;
+};
+
+struct HSPerVertexData {
+  // This is just the original vertex verbatim. In many real life cases this would be a
+  // control point instead
+  PSSceneIn v;
+};
+
+struct HSPerPatchData {
+  // We at least have to specify tess factors per patch
+  // As we're tesselating triangles, there will be 4 tess factors
+  // In real life case this might contain face normal, for example
+  float edges[3] : SV_TessFactor;
+  float inside : SV_InsideTessFactor;
+};
+
+// domain shader that actually outputs the triangle vertices
+[shader("domain")]
+[domain("tri")] PSSceneIn ds_main(const float3 bary
+                               : SV_DomainLocation,
+                                 const OutputPatch<HSPerVertexData, 3> patch,
+                                 const HSPerPatchData perPatchData) {
+  PSSceneIn v;
+
+  // Compute interpolated coordinates
+  v.pos = patch[0].v.pos * bary.x + patch[1].v.pos * bary.y + patch[2].v.pos * bary.z + perPatchData.edges[1];
+  v.tex = patch[0].v.tex * bary.x + patch[1].v.tex * bary.y + patch[2].v.tex * bary.z + perPatchData.edges[0];
+  v.norm = patch[0].v.norm * bary.x + patch[1].v.norm * bary.y + patch[2].v.norm * bary.z + perPatchData.inside;
+  v.RTIndex = 0;
+  return v;
+}
+
+// HS
+
+HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, OutputPatch<HSPerVertexData, 3> outp)
+{
+    HSPerPatchData d;
+
+    d.edges[ 0 ] = 1;
+    d.edges[ 1 ] = 1;
+    d.edges[ 2 ] = 1;
+    d.inside = 1;
+
+    return d;
+}
+
+// hull per-control point shader
+[shader("hull")]
+[domain("tri")]
+[partitioning("fractional_odd")]
+[outputtopology("triangle_cw")]
+[patchconstantfunc("HSPerPatchFunc")]
+[outputcontrolpoints(3)]
+HSPerVertexData hs_main( const uint id : SV_OutputControlPointID,
+                               const InputPatch< PSSceneIn, 3 > points)
+{
+    HSPerVertexData v;
+
+    // Just forward the vertex
+    v.v = points[ id ];
+
+	return v;
+}
+
+// VS
+
+struct VS_INPUT
+{
+	float3 vPosition	: POSITION;
+	float3 vNormal		: NORMAL;
+	float2 vTexcoord	: TEXCOORD0;
+};
+
+struct VS_OUTPUT
+{
+	float3 vNormal		: NORMAL;
+	float2 vTexcoord	: TEXCOORD0;
+	float4 vPosition	: SV_POSITION;
+};
+
+
+[shader("vertex")]
+VS_OUTPUT vs_main(VS_INPUT Input)
+{
+	VS_OUTPUT Output;
+
+	Output.vPosition = float4( Input.vPosition, 1.0 );
+	Output.vNormal = Input.vNormal;
+	Output.vTexcoord = Input.vTexcoord;
+
+       return Output;
+}
+
+// PS
+[shader("pixel")]
+float4 ps_main(float4 a : A) : SV_TARGET
+{
+  return a;
+}

+ 24 - 0
tools/clang/test/DXILValidation/lib_global.hlsl

@@ -0,0 +1,24 @@
+// Make constructor for static global variable is called.
+
+Texture2D    g_txDiffuse;
+SamplerState    g_samLinear;
+
+cbuffer X {
+  // Use min-precision type to force conversion of constant buffer type for legacy.
+  // This has to happen at link time at the moment, so this will break unless type
+  // annotations are retained for library.
+  min16float f;
+}
+
+static float g[2] = { 1, f };
+
+[shader("pixel")]
+float4 test(float2 c : C) : SV_TARGET
+{
+  float4 x = g_txDiffuse.Sample( g_samLinear, c );
+  return x + g[1];
+}
+
+void update() {
+  g[1]++;
+}

+ 18 - 0
tools/clang/test/DXILValidation/lib_global2.hlsl

@@ -0,0 +1,18 @@
+// Check redefine global and resource with lib_global3.hlsl, lib_global4.hlsl.
+
+float2x2 RotateMat(float2x2 m, uint x, uint y);
+float2x2 MatRotate(float2x2 m, uint x, uint y);
+
+RWStructuredBuffer<float2x2> fA;
+
+[numthreads(8,8,1)]
+void entry( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
+{
+    float2x2 f2x2 = fA[tid.x];
+
+    f2x2 = RotateMat(f2x2, tid.x, tid.y);
+
+    f2x2 = MatRotate(f2x2, tid.x, tid.y);
+
+    fA[tid.y] = f2x2;
+}

+ 13 - 0
tools/clang/test/DXILValidation/lib_global3.hlsl

@@ -0,0 +1,13 @@
+// Check redefine global and resource with lib_global2.hlsl, lib_global4.hlsl.
+
+RWBuffer<float> buf0;
+
+groupshared column_major float2x2 dataC[8*8];
+
+float2x2 MatRotate(float2x2 m, uint x, uint y) {
+    buf0[x] = y;
+    dataC[x%(8*8)] = m;
+    GroupMemoryBarrierWithGroupSync();
+    float2x2 f2x2 = dataC[8*8-1-y%(8*8)];
+    return f2x2;
+}

+ 13 - 0
tools/clang/test/DXILValidation/lib_global4.hlsl

@@ -0,0 +1,13 @@
+// Check redefine global and resource with lib_global2.hlsl, lib_global3.hlsl.
+
+RWTexture1D<float> buf0;
+
+groupshared column_major float2x2 dataC[8*8];
+
+float2x2 RotateMat(float2x2 m, uint x, uint y) {
+    buf0[x] = y;
+    dataC[x%(8*8)] = m;
+    GroupMemoryBarrierWithGroupSync();
+    float2x2 f2x2 = dataC[8*8-1-y%(8*8)];
+    return f2x2;
+}

+ 16 - 0
tools/clang/test/DXILValidation/lib_no_alias.hlsl

@@ -0,0 +1,16 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
+
+// Make sure out param has no-alias.
+// CHECK: float @"\01?test@@YAMMUT@@AIAV?$matrix@M$01$01@@M@Z"(float %a, %struct.T* noalias nocapture %t, %class.matrix.float.2.2* noalias nocapture dereferenceable(16) %m, float %b)
+
+struct T {
+  float a;
+  int b;
+};
+
+float test(float a, out T t, out float2x2 m, float b) {
+  t.a = 1;
+  t.b = 6;
+  m = 3;
+  return a + t.a - t.b - b;
+}

+ 9 - 0
tools/clang/test/DXILValidation/lib_no_alloca.h

@@ -0,0 +1,9 @@
+
+float2 test(float2 a) {
+  float2 b = a;
+  b.y = sin(a.y);
+  return b;
+}
+
+
+

+ 10 - 0
tools/clang/test/DXILValidation/lib_no_alloca.hlsl

@@ -0,0 +1,10 @@
+// Make sure no alloca for linked dxil module.
+
+float2 test(float2 a);
+
+[shader("pixel")]
+float4 ps_main(float2 a : A) : SV_TARGET
+{
+  return test(a).y;
+}
+

+ 15 - 0
tools/clang/test/DXILValidation/lib_resource.hlsl

@@ -0,0 +1,15 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
+
+// Make sure globals for resource exist.
+// CHECK: @"\01?g_txDiffuse@@3V?$Texture2D@V?$vector@M$03@@@@A" = external constant %"class.Texture2D<vector<float, 4> >", align 4
+// CHECK: @"\01?g_samLinear@@3USamplerState@@A" = external constant %struct.SamplerState, align 4
+
+Texture2D    g_txDiffuse;
+SamplerState    g_samLinear;
+
+float4 test(float2 c : C) : SV_TARGET
+{
+  float4 x = g_txDiffuse.Sample( g_samLinear, c );
+  return x;
+}
+

+ 41 - 0
tools/clang/test/DXILValidation/lib_resource2.hlsl

@@ -0,0 +1,41 @@
+// Check resource link with lib_cs_entry.hlsl
+
+RWStructuredBuffer<float2x2> unusedBuf;
+
+void UsedResFn(float2x2  m, uint gidx) {
+  unusedBuf[gidx] = m;
+}
+
+RWStructuredBuffer<float2x2> fA;
+
+void StoreOutputMat(float2x2  m, uint gidx) {
+  fA[gidx] = m;
+}
+
+void StoreCSOutput(uint2 tid, uint2 gid) {
+  fA[gid.x][gid.y] = tid;
+}
+
+struct mat {
+  row_major float2x2 f2x2;
+};
+
+StructuredBuffer<mat> mats;
+StructuredBuffer<row_major float2x2> mats2;
+
+float2x2 LoadInputMat(uint x, uint y) {
+  return mats.Load(x).f2x2 + mats2.Load(y);
+}
+
+cbuffer B {
+  float b;
+}
+
+groupshared column_major float2x2 dataC[8*8];
+
+float2x2 RotateMat(float2x2 m, uint x, uint y) {
+    dataC[x%(8*8)] = m;
+    GroupMemoryBarrierWithGroupSync();
+    float2x2 f2x2 = dataC[8*8-1-y%(8*8)];
+    return f2x2 + b;
+}

+ 19 - 0
tools/clang/test/DXILValidation/lib_select_res.hlsl

@@ -0,0 +1,19 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// Make sure load resource rangeID when select resource.
+// CHECK:load i32, i32* @ReadBuffer1_rangeID
+// CHECK:load i32, i32* @ReadBuffer_rangeID
+
+RWByteAddressBuffer outputBuffer : register(u0);
+ByteAddressBuffer ReadBuffer : register(t0);
+ByteAddressBuffer ReadBuffer1 : register(t1);
+
+void test( uint cond)
+{
+	ByteAddressBuffer buffer = ReadBuffer;
+        if (cond > 2)
+           buffer = ReadBuffer1;
+
+	uint v= buffer.Load(0);
+    outputBuffer.Store(0, v);
+}

+ 19 - 0
tools/clang/test/DXILValidation/lib_select_res_codegenhlsl_copy.hlsl

@@ -0,0 +1,19 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
+
+// Make sure load resource rangeID when select resource.
+// CHECK:load i32, i32* @ReadBuffer1_rangeID
+// CHECK:load i32, i32* @ReadBuffer_rangeID
+
+RWByteAddressBuffer outputBuffer : register(u0);
+ByteAddressBuffer ReadBuffer : register(t0);
+ByteAddressBuffer ReadBuffer1 : register(t1);
+
+void test( uint cond)
+{
+	ByteAddressBuffer buffer = ReadBuffer;
+        if (cond > 2)
+           buffer = ReadBuffer1;
+
+	uint v= buffer.Load(0);
+    outputBuffer.Store(0, v);
+}

+ 8 - 0
tools/clang/test/DXILValidation/lib_select_res_entry.hlsl

@@ -0,0 +1,8 @@
+
+void test( uint cond);
+
+[shader("pixel")]
+float main(uint c : C) : SV_Target {
+   test(c);
+   return 1;
+}

+ 30 - 0
tools/clang/test/DXILValidation/lib_unused_func.hlsl

@@ -0,0 +1,30 @@
+// RUN: %dxc -T lib_6_3 -auto-binding-space 11 -default-linkage external %s | FileCheck %s
+
+// Make sure all function still exist.
+// CHECK: unused
+// CHECK: test_out
+// CHECK: test_inout
+// CHECK: test
+
+float unused() {
+  return 3;
+}
+
+void test_out(out float4 m, float4 a)
+{
+    m = abs(a*a.yxxx);
+}
+
+export void test_inout(inout float4 m, float4 a)
+{
+    m = abs(m+a*a.yxxx);
+}
+
+export float4 test(float4 a : A, float4 b:B) : SV_TARGET
+{
+  float4 x = b;
+  test_inout(x, a);
+  test_out(x, b);
+  return x;
+}
+

+ 15 - 0
tools/clang/test/DXILValidation/local_resource2.hlsl

@@ -0,0 +1,15 @@
+// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s
+
+// CHECK: local resource not guaranteed to map to unique global resource
+
+float4 Tex2D(Texture2D<float4> t,
+  SamplerState s, float2 c) {
+  return t.Sample(s, c);
+}
+
+SamplerState g_ss;
+
+float4 main(float2 c: T) : SV_Target {
+Texture2D<float4> g_texture;
+  return Tex2D(g_texture, g_ss, c);
+}

+ 25 - 0
tools/clang/test/DXILValidation/local_resource3.hlsl

@@ -0,0 +1,25 @@
+// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s
+
+// CHECK: local resource not guaranteed to map to unique global resource
+
+float4 Tex2D(Texture2D<float4> t,
+  SamplerState s, float2 c) {
+  return t.Sample(s, c);
+}
+
+float4 test(Texture2D<float4> t,
+SamplerState s, float2 c) {
+  float4 r = Tex2D(t, s, c);
+  r += Tex2D(t, s, c+1);
+  r += Tex2D(t, s, c+2);
+  r += Tex2D(t, s, c+3);
+  r += Tex2D(t, s, c+4);
+  return r;
+}
+
+static Texture2D<float4> g_texture;
+SamplerState g_ss;
+
+float4 main(float2 c: T) : SV_Target {
+  return test(g_texture, g_ss, c);
+}

+ 18 - 0
tools/clang/test/DXILValidation/local_resource5.hlsl

@@ -0,0 +1,18 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: local resource not guaranteed to map to unique global resource
+
+float4 Tex2D(Texture2D<float4> t,
+  SamplerState s, float2 c) {
+  return t.Sample(s, c);
+}
+
+SamplerState g_ss;
+Texture2D<float4> g_texture;
+
+float4 main(float2 c: T) : SV_Target {
+Texture2D<float4> texture;
+  if (c.x>0)
+    texture = g_texture;
+  return Tex2D(texture, g_ss, c);
+}

+ 18 - 0
tools/clang/test/DXILValidation/local_resource5_dbg.hlsl

@@ -0,0 +1,18 @@
+// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s
+
+// CHECK: local resource not guaranteed to map to unique global resource
+
+float4 Tex2D(Texture2D<float4> t,
+  SamplerState s, float2 c) {
+  return t.Sample(s, c);
+}
+
+SamplerState g_ss;
+Texture2D<float4> g_texture;
+
+float4 main(float2 c: T) : SV_Target {
+Texture2D<float4> texture;
+  if (c.x>0)
+    texture = g_texture;
+  return Tex2D(texture, g_ss, c);
+}

+ 22 - 0
tools/clang/test/DXILValidation/local_resource6.hlsl

@@ -0,0 +1,22 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: local resource not guaranteed to map to unique global resource
+
+float4 Tex2D(Texture2D<float4> t,
+  SamplerState s, float2 c) {
+  return t.Sample(s, c);
+}
+
+SamplerState g_ss;
+Texture2D<float4> g_texture;
+Texture2D<float4> g_texture2;
+
+float4 main(float2 c: T) : SV_Target {
+Texture2D<float4> l_texture;
+  if (c.x>0)
+    l_texture = g_texture;
+  else
+    l_texture = g_texture2;
+
+  return Tex2D(l_texture, g_ss, c);
+}

+ 22 - 0
tools/clang/test/DXILValidation/local_resource6_dbg.hlsl

@@ -0,0 +1,22 @@
+// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s
+
+// CHECK: local resource not guaranteed to map to unique global resource
+
+float4 Tex2D(Texture2D<float4> t,
+  SamplerState s, float2 c) {
+  return t.Sample(s, c);
+}
+
+SamplerState g_ss;
+Texture2D<float4> g_texture;
+Texture2D<float4> g_texture2;
+
+float4 main(float2 c: T) : SV_Target {
+Texture2D<float4> l_texture;
+  if (c.x>0)
+    l_texture = g_texture;
+  else
+    l_texture = g_texture2;
+
+  return Tex2D(l_texture, g_ss, c);
+}

+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/loop1.hlsl → tools/clang/test/DXILValidation/loop1.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/loop2.hlsl → tools/clang/test/DXILValidation/loop2.hlsl


+ 0 - 0
tools/clang/test/CodeGenHLSL/batch/misc/multiStreamGS.hlsl → tools/clang/test/DXILValidation/multiStreamGS.hlsl


+ 7 - 0
tools/clang/test/DXILValidation/neg1.hlsl

@@ -0,0 +1,7 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// CHECK: @main
+float4 main(float4 a : A) : SV_TARGET
+{
+  return -a.yxxx;
+}

+ 17 - 0
tools/clang/test/DXILValidation/optForNoOpt3.hlsl

@@ -0,0 +1,17 @@
+// RUN: %dxc -E main -T ps_6_0 -Od %s | FileCheck %s
+
+// CHECK: Offsets for Sample* must be immediated value
+
+SamplerState samp1 : register(s5);
+Texture2D<float4> text1 : register(t3);
+
+
+int x;
+int y;
+
+float4 main(float2 a : A) : SV_Target {
+  float4 r = 0;
+  r = text1.Sample(samp1, a, int2(x+y,x-y));
+
+  return r;
+}

+ 17 - 0
tools/clang/test/DXILValidation/optForNoOpt4.hlsl

@@ -0,0 +1,17 @@
+// RUN: %dxc -E main -T ps_6_0 -Od %s | FileCheck %s
+
+// CHECK: Offsets for Sample* must be immediated value
+
+SamplerState samp1 : register(s5);
+Texture2D<float4> text1 : register(t3);
+
+int i;
+
+float4 main(float2 a : A) : SV_Target {
+  float4 r = 0;
+  for (uint x=0; x<i;x++)
+  for (uint y=0; y<2;y++) {
+    r += text1.Sample(samp1, a, int2(x+y,x-y));
+  }
+  return r;
+}

+ 12 - 0
tools/clang/test/DXILValidation/phiTGSM.hlsl

@@ -0,0 +1,12 @@
+groupshared uint g_Data[32];
+groupshared uint g_Data2[32];
+
+float t;
+[numthreads(64, 1, 1)]
+void main(uint idx : SV_DispatchThreadId) {
+  uint orig;
+  if (t > 1)
+  InterlockedAdd(g_Data[idx], 1, orig);
+  else
+  InterlockedAdd(g_Data2[idx], 1, orig);
+}

+ 205 - 0
tools/clang/test/DXILValidation/recursive.ll

@@ -0,0 +1,205 @@
+; RUN: %dxv %s | FileCheck %s
+
+; CHECK: Recursion is not permitted
+
+; This test originally covered two validator error messages:
+; 1. recursion not allowed
+; 2. functions with parameters are not allowed
+;
+; The recursion error is now handled earlier in the pipeline, and so there
+; is no coverage for error #2. But we do need the validator to check for this
+; in case someone decides to remove this. So instead, we validate the assembly
+; we would have had, which we can generate with this command:
+;
+; dxc -Vd -T ps_6_0 recursive.hlsl
+;
+
+; void test_inout(inout float4 m, float4 a) {
+;    if (a.x > 1)
+;     test_inout(m, a-1);
+;   m = abs(m+a*a.yxxx);
+; }
+;
+; float4 main(float4 a : A, float4 b:B) : SV_TARGET {
+;  float4 x = b;
+;  test_inout(x, a);
+;  return x;
+; }
+
+;
+; Input signature:
+;
+; Name                 Index   Mask Register SysValue  Format   Used
+; -------------------- ----- ------ -------- -------- ------- ------
+; A                        0   xyzw        0     NONE   float
+; B                        0   xyzw        1     NONE   float
+;
+;
+; Output signature:
+;
+; Name                 Index   Mask Register SysValue  Format   Used
+; -------------------- ----- ------ -------- -------- ------- ------
+; SV_Target                0   xyzw        0   TARGET   float   xyzw
+;
+;
+; Pipeline Runtime Information:
+;
+; Pixel Shader
+; DepthOutput=0
+; SampleFrequency=0
+;
+;
+; Input signature:
+;
+; Name                 Index             InterpMode
+; -------------------- ----- ----------------------
+; A                        0                 linear
+; B                        0                 linear
+;
+; Output signature:
+;
+; Name                 Index             InterpMode
+; -------------------- ----- ----------------------
+; SV_Target                0
+;
+; Buffer Definitions:
+;
+;
+; Resource Bindings:
+;
+; Name                                 Type  Format         Dim      ID      HLSL Bind  Count
+; ------------------------------ ---------- ------- ----------- ------- -------------- ------
+;
+target datalayout = "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "dxil-ms-dx"
+
+; Function Attrs: alwaysinline nounwind
+define internal fastcc void @"\01?test_inout@@YAXAAV?$vector@M$03@@V1@@Z"(<4 x float>* nocapture dereferenceable(16) %m, <4 x float> %a) #0 {
+entry:
+  %a.i0 = extractelement <4 x float> %a, i32 0
+  %a.i1 = extractelement <4 x float> %a, i32 1
+  %a.i2 = extractelement <4 x float> %a, i32 2
+  %a.i3 = extractelement <4 x float> %a, i32 3
+  %0 = load <4 x float>, <4 x float>* %m, align 4
+  %.i05 = extractelement <4 x float> %0, i32 0
+  %.i16 = extractelement <4 x float> %0, i32 1
+  %.i27 = extractelement <4 x float> %0, i32 2
+  %.i38 = extractelement <4 x float> %0, i32 3
+  %1 = alloca <4 x float>, align 4
+  %cmp = fcmp ogt float %a.i0, 1.000000e+00
+  br i1 %cmp, label %if.then, label %if.end
+
+if.then:                                          ; preds = %entry
+  store <4 x float> %0, <4 x float>* %1, align 4
+  %sub.i0 = fadd float %a.i0, -1.000000e+00
+  %sub.i1 = fadd float %a.i1, -1.000000e+00
+  %sub.i2 = fadd float %a.i2, -1.000000e+00
+  %sub.i3 = fadd float %a.i3, -1.000000e+00
+  %sub.upto0 = insertelement <4 x float> undef, float %sub.i0, i32 0
+  %sub.upto1 = insertelement <4 x float> %sub.upto0, float %sub.i1, i32 1
+  %sub.upto2 = insertelement <4 x float> %sub.upto1, float %sub.i2, i32 2
+  %sub = insertelement <4 x float> %sub.upto2, float %sub.i3, i32 3
+  call fastcc void @"\01?test_inout@@YAXAAV?$vector@M$03@@V1@@Z"(<4 x float>* nonnull dereferenceable(16) %1, <4 x float> %sub)
+  %2 = load <4 x float>, <4 x float>* %1, align 4
+  %.i0 = extractelement <4 x float> %2, i32 0
+  %.i1 = extractelement <4 x float> %2, i32 1
+  %.i2 = extractelement <4 x float> %2, i32 2
+  %.i3 = extractelement <4 x float> %2, i32 3
+  br label %if.end
+
+if.end:                                           ; preds = %if.then, %entry
+  %.0.i0 = phi float [ %.i0, %if.then ], [ %.i05, %entry ]
+  %.0.i1 = phi float [ %.i1, %if.then ], [ %.i16, %entry ]
+  %.0.i2 = phi float [ %.i2, %if.then ], [ %.i27, %entry ]
+  %.0.i3 = phi float [ %.i3, %if.then ], [ %.i38, %entry ]
+  %mul.i0 = fmul float %a.i0, %a.i1
+  %mul.i2 = fmul float %a.i2, %a.i0
+  %mul.i3 = fmul float %a.i3, %a.i0
+  %add.i0 = fadd float %mul.i0, %.0.i0
+  %add.i1 = fadd float %mul.i0, %.0.i1
+  %add.i2 = fadd float %mul.i2, %.0.i2
+  %add.i3 = fadd float %mul.i3, %.0.i3
+  %FAbs = call float @dx.op.unary.f32(i32 6, float %add.i0)  ; FAbs(value)
+  %3 = insertelement <4 x float> undef, float %FAbs, i64 0
+  %FAbs2 = call float @dx.op.unary.f32(i32 6, float %add.i1)  ; FAbs(value)
+  %4 = insertelement <4 x float> %3, float %FAbs2, i64 1
+  %FAbs3 = call float @dx.op.unary.f32(i32 6, float %add.i2)  ; FAbs(value)
+  %5 = insertelement <4 x float> %4, float %FAbs3, i64 2
+  %FAbs4 = call float @dx.op.unary.f32(i32 6, float %add.i3)  ; FAbs(value)
+  %6 = insertelement <4 x float> %5, float %FAbs4, i64 3
+  store <4 x float> %6, <4 x float>* %m, align 4
+  ret void
+}
+
+define void @main() {
+entry:
+  %0 = call float @dx.op.loadInput.f32(i32 4, i32 1, i32 0, i8 0, i32 undef)  ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
+  %1 = insertelement <4 x float> undef, float %0, i64 0
+  %2 = call float @dx.op.loadInput.f32(i32 4, i32 1, i32 0, i8 1, i32 undef)  ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
+  %3 = insertelement <4 x float> %1, float %2, i64 1
+  %4 = call float @dx.op.loadInput.f32(i32 4, i32 1, i32 0, i8 2, i32 undef)  ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
+  %5 = insertelement <4 x float> %3, float %4, i64 2
+  %6 = call float @dx.op.loadInput.f32(i32 4, i32 1, i32 0, i8 3, i32 undef)  ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
+  %7 = insertelement <4 x float> %5, float %6, i64 3
+  %8 = call float @dx.op.loadInput.f32(i32 4, i32 0, i32 0, i8 0, i32 undef)  ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
+  %9 = insertelement <4 x float> undef, float %8, i64 0
+  %10 = call float @dx.op.loadInput.f32(i32 4, i32 0, i32 0, i8 1, i32 undef)  ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
+  %11 = insertelement <4 x float> %9, float %10, i64 1
+  %12 = call float @dx.op.loadInput.f32(i32 4, i32 0, i32 0, i8 2, i32 undef)  ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
+  %13 = insertelement <4 x float> %11, float %12, i64 2
+  %14 = call float @dx.op.loadInput.f32(i32 4, i32 0, i32 0, i8 3, i32 undef)  ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
+  %15 = insertelement <4 x float> %13, float %14, i64 3
+  %16 = alloca <4 x float>, align 4
+  store <4 x float> %7, <4 x float>* %16, align 4
+  call fastcc void @"\01?test_inout@@YAXAAV?$vector@M$03@@V1@@Z"(<4 x float>* nonnull dereferenceable(16) %16, <4 x float> %15)
+  %17 = load <4 x float>, <4 x float>* %16, align 4
+  %18 = extractelement <4 x float> %17, i64 0
+  call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 0, float %18)  ; StoreOutput(outputSigId,rowIndex,colIndex,value)
+  %19 = extractelement <4 x float> %17, i64 1
+  call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 1, float %19)  ; StoreOutput(outputSigId,rowIndex,colIndex,value)
+  %20 = extractelement <4 x float> %17, i64 2
+  call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 2, float %20)  ; StoreOutput(outputSigId,rowIndex,colIndex,value)
+  %21 = extractelement <4 x float> %17, i64 3
+  call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 3, float %21)  ; StoreOutput(outputSigId,rowIndex,colIndex,value)
+  ret void
+}
+
+; Function Attrs: nounwind readnone
+declare float @dx.op.loadInput.f32(i32, i32, i32, i8, i32) #1
+
+; Function Attrs: nounwind
+declare void @dx.op.storeOutput.f32(i32, i32, i32, i8, float) #2
+
+; Function Attrs: nounwind readnone
+declare float @dx.op.unary.f32(i32, float) #1
+
+attributes #0 = { alwaysinline nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="0" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+attributes #2 = { nounwind }
+
+!llvm.ident = !{!0}
+!dx.version = !{!1}
+!dx.shaderModel = !{!2}
+!dx.typeAnnotations = !{!3}
+!dx.entryPoints = !{!12}
+
+!0 = !{!"clang version 3.7 (tags/RELEASE_370/final)"}
+!1 = !{i32 1, i32 0}
+!2 = !{!"ps", i32 6, i32 0}
+!3 = !{i32 1, void (<4 x float>*, <4 x float>)* @"\01?test_inout@@YAXAAV?$vector@M$03@@V1@@Z", !4, void ()* @main, !10}
+!4 = !{!5, !7, !9}
+!5 = !{i32 1, !6, !6}
+!6 = !{}
+!7 = !{i32 2, !8, !6}
+!8 = !{i32 7, i32 9}
+!9 = !{i32 0, !8, !6}
+!10 = !{!11}
+!11 = !{i32 0, !6, !6}
+!12 = !{void ()* @main, !"main", !13, null, null}
+!13 = !{!14, !18, null}
+!14 = !{!15, !17}
+!15 = !{i32 0, !"A", i8 9, i8 0, !16, i8 2, i32 1, i8 4, i32 0, i8 0, null}
+!16 = !{i32 0}
+!17 = !{i32 1, !"B", i8 9, i8 0, !16, i8 2, i32 1, i8 4, i32 1, i8 0, null}
+!18 = !{!19}
+!19 = !{i32 0, !"SV_Target", i8 9, i8 16, !16, i8 0, i32 1, i8 4, i32 0, i8 0, null}

Some files were not shown because too many files changed in this diff