Kokoro: run e2e tests with FXC validation

* Fixed DXC installation so that we download the latest release, and
patch it with the latest artifact build. This ensures that the correct
dxil.dll is next to dxc.exe, rather than having dxc.exe pick up whatever
dxil.dll is in PATH.

* To run tests with FXC requires the correct d3dcompiler_47.dll. To do
this, I modified the script to download the Windows SDK, and install
only the feature that contains the DLL.

* To avoid issues with DXC and FXC finding exes/dlls in PATH, modified
the script to temporarily set PATH as needed.

Bug: tint:940
Change-Id: Ic83b0b97f72ccc1f37b4b495eae6a6ab3421a95a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/72560
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/kokoro/windows/build.bat b/kokoro/windows/build.bat
index 1dfb553..a7d28ce 100644
--- a/kokoro/windows/build.bat
+++ b/kokoro/windows/build.bat
@@ -60,16 +60,28 @@
 )

 mkdir %TEMP_DIR% || goto :error

 

-call :status "Fetching DXC"

+call :status "Fetching and installing DXC"

 @echo on

-set DXC_LATEST_ARTIFACT="https://ci.appveyor.com/api/projects/dnovillo/directxshadercompiler/artifacts/build%%2FRelease%%2Fdxc-artifacts.zip?branch=master&pr=false&job=image%%3A%%20Visual%%20Studio%%202019"

-curl -L %DXC_LATEST_ARTIFACT% --output "%TEMP_DIR%\dxc.zip" || goto :error

+set DXC_RELEASE="https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.6.2112/dxc_2021_12_08.zip"

+curl -L %DXC_RELEASE% --output "%TEMP_DIR%\dxc_release.zip" || goto :error

+powershell.exe -Command "Expand-Archive -LiteralPath '%TEMP_DIR%\dxc_release.zip' -DestinationPath '%TEMP_DIR%\dxc'" || goto :error

+set DXC_PATH=%TEMP_DIR%\dxc\bin\x64

+

+rem Patch with artifact build that contains fixes not present in the release build

+set DXC_ARTIFACT="https://ci.appveyor.com/api/projects/dnovillo/directxshadercompiler/artifacts/build%%2FRelease%%2Fdxc-artifacts.zip?branch=master&pr=false&job=image%%3A%%20Visual%%20Studio%%202019"

+curl -L %DXC_ARTIFACT% --output "%TEMP_DIR%\dxc_artifact.zip" || goto :error

+powershell.exe -Command "Expand-Archive -Force -LiteralPath '%TEMP_DIR%\dxc_artifact.zip' -DestinationPath '%TEMP_DIR%\dxc_artifact'" || goto :error

+move /Y %TEMP_DIR%\dxc_artifact\bin\* %DXC_PATH%

 @echo off

 

-call :status "Unpacking DXC"

+call :status "Fetching and installing Windows SDK for d3dcompiler DLL"

 @echo on

-powershell.exe -Command "Expand-Archive -LiteralPath '%TEMP_DIR%\dxc.zip' -DestinationPath '%TEMP_DIR%\dxc'" || goto :error

-set PATH=%TEMP_DIR%\dxc\bin;%PATH%

+set WINSDK_DLL_INSTALLER=https://go.microsoft.com/fwlink/?linkid=2164145

+set WINSDK_VERSION=10.0.20348.0

+curl -L %WINSDK_DLL_INSTALLER% --output "%TEMP_DIR%\winsdksetup.exe" || goto :error

+start "download" /wait "%TEMP_DIR%\winsdksetup.exe" /quiet /norestart /ceip off /features OptionId.DesktopCPPx64 /layout "%TEMP_DIR%\winsdkinstall" || goto :error

+start "install" /wait "%TEMP_DIR%\winsdkinstall\Installers\Windows SDK for Windows Store Apps Tools-x86_en-us.msi" || goto :error

+set D3DCOMPILER_PATH=C:\Program Files (x86)\Windows Kits\10\bin\%WINSDK_VERSION%\x64

 @echo off

 

 call :status "Installing depot_tools"

@@ -130,9 +142,21 @@
 call :status "Testing test/test-all.sh"

 @echo on

 cd /d %SRC_DIR% || goto :error

+rem Run tests with DXC and Metal validation

+set OLD_PATH=%PATH%

 set PATH=C:\Program Files\Metal Developer Tools\macos\bin;%PATH%

 where metal.exe

-git bash -- ./test/test-all.sh ../tint-build/tint.exe --verbose

+set PATH=%DXC_PATH%;%OLD_PATH%

+where dxc.exe dxil.dll

+call git bash -- ./test/test-all.sh ../tint-build/tint.exe --verbose || goto :error

+@echo on

+set PATH=%OLD_PATH%

+rem Run again to test with FXC validation

+set PATH=%D3DCOMPILER_PATH%;%OLD_PATH%

+where d3dcompiler_47.dll

+call git bash -- ./test/test-all.sh ../tint-build/tint.exe --verbose --format hlsl --fxc || goto :error

+@echo on

+set PATH=%OLD_PATH%

 @echo off

 

 call :status "Done"

diff --git a/test/vk-gl-cts/graphicsfuzz/cov-multiple-one-iteration-loops-global-counter-write-matrices/0-opt.spvasm.expected.hlsl b/test/vk-gl-cts/graphicsfuzz/cov-multiple-one-iteration-loops-global-counter-write-matrices/0-opt.spvasm.expected.hlsl
new file mode 100644
index 0000000..abefd0c
--- /dev/null
+++ b/test/vk-gl-cts/graphicsfuzz/cov-multiple-one-iteration-loops-global-counter-write-matrices/0-opt.spvasm.expected.hlsl
@@ -0,0 +1,435 @@
+SKIP: flaky test with FXC, often times out
+
+void set_scalar_float2x3(inout float2x3 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[1];
+      break;
+  }
+}
+
+void set_scalar_float2x4(inout float2x4 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[1];
+      break;
+  }
+}
+
+void set_scalar_float3x2(inout float3x2 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xx == int2(0, 1)) ? val.xx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xx == int2(0, 1)) ? val.xx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xx == int2(0, 1)) ? val.xx : mat[2];
+      break;
+  }
+}
+
+void set_scalar_float3x3(inout float3x3 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[2];
+      break;
+  }
+}
+
+void set_scalar_float3x4(inout float3x4 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[2];
+      break;
+  }
+}
+
+void set_scalar_float4x2(inout float4x2 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xx == int2(0, 1)) ? val.xx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xx == int2(0, 1)) ? val.xx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xx == int2(0, 1)) ? val.xx : mat[2];
+      break;
+    case 3:
+      mat[3] = (row.xx == int2(0, 1)) ? val.xx : mat[3];
+      break;
+  }
+}
+
+void set_scalar_float4x3(inout float4x3 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[2];
+      break;
+    case 3:
+      mat[3] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[3];
+      break;
+  }
+}
+
+void set_scalar_float4x4(inout float4x4 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[2];
+      break;
+    case 3:
+      mat[3] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[3];
+      break;
+  }
+}
+
+static int x_GLF_global_loop_count = 0;
+static float4 x_GLF_color = float4(0.0f, 0.0f, 0.0f, 0.0f);
+
+void main_1() {
+  float2x3 m23 = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float2x4 m24 = float2x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float3x2 m32 = float3x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float3x3 m33 = float3x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float3x4 m34 = float3x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float4x2 m42 = float4x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float4x3 m43 = float4x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float4x4 m44 = float4x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  int i = 0;
+  int i_1 = 0;
+  int i_2 = 0;
+  int i_3 = 0;
+  int i_4 = 0;
+  int i_5 = 0;
+  int i_6 = 0;
+  int i_7 = 0;
+  int i_8 = 0;
+  int i_9 = 0;
+  int i_10 = 0;
+  int i_11 = 0;
+  int i_12 = 0;
+  int i_13 = 0;
+  int i_14 = 0;
+  int i_15 = 0;
+  int i_16 = 0;
+  int i_17 = 0;
+  int i_18 = 0;
+  int i_19 = 0;
+  int i_20 = 0;
+  int i_21 = 0;
+  int i_22 = 0;
+  int i_23 = 0;
+  int i_24 = 0;
+  int i_25 = 0;
+  int i_26 = 0;
+  int i_27 = 0;
+  int i_28 = 0;
+  int i_29 = 0;
+  int i_30 = 0;
+  int i_31 = 0;
+  int i_32 = 0;
+  int i_33 = 0;
+  int i_34 = 0;
+  int i_35 = 0;
+  int i_36 = 0;
+  int i_37 = 0;
+  float sum = 0.0f;
+  int r = 0;
+  x_GLF_global_loop_count = 0;
+  m23 = float2x3(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
+  m24 = float2x4(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
+  m32 = float3x2(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
+  m33 = float3x3(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
+  m34 = float3x4(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
+  m42 = float4x2(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
+  m43 = float4x3(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
+  m44 = float4x4(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
+  i = 0;
+  {
+    [loop] for(; (i < 1); i = (i + 1)) {
+      i_1 = 0;
+      {
+        [loop] for(; (i_1 < 1); i_1 = (i_1 + 1)) {
+          i_2 = 0;
+          {
+            [loop] for(; (i_2 < 1); i_2 = (i_2 + 1)) {
+              i_3 = 0;
+              {
+                [loop] for(; (i_3 < 1); i_3 = (i_3 + 1)) {
+                  i_4 = 0;
+                  {
+                    [loop] for(; (i_4 < 1); i_4 = (i_4 + 1)) {
+                      i_5 = 0;
+                      {
+                        [loop] for(; (i_5 < 1); i_5 = (i_5 + 1)) {
+                          i_6 = 0;
+                          {
+                            [loop] for(; (i_6 < 1); i_6 = (i_6 + 1)) {
+                              i_7 = 0;
+                              {
+                                [loop] for(; (i_7 < 1); i_7 = (i_7 + 1)) {
+                                  i_8 = 0;
+                                  {
+                                    [loop] for(; (i_8 < 1); i_8 = (i_8 + 1)) {
+                                      i_9 = 0;
+                                      {
+                                        [loop] for(; (i_9 < 1); i_9 = (i_9 + 1)) {
+                                          i_10 = 0;
+                                          {
+                                            [loop] for(; (i_10 < 1); i_10 = (i_10 + 1)) {
+                                              i_11 = 0;
+                                              {
+                                                [loop] for(; (i_11 < 1); i_11 = (i_11 + 1)) {
+                                                  i_12 = 0;
+                                                  {
+                                                    [loop] for(; (i_12 < 1); i_12 = (i_12 + 1)) {
+                                                      i_13 = 0;
+                                                      {
+                                                        [loop] for(; (i_13 < 1); i_13 = (i_13 + 1)) {
+                                                          i_14 = 0;
+                                                          {
+                                                            [loop] for(; (i_14 < 1); i_14 = (i_14 + 1)) {
+                                                              i_15 = 0;
+                                                              {
+                                                                [loop] for(; (i_15 < 1); i_15 = (i_15 + 1)) {
+                                                                  i_16 = 0;
+                                                                  {
+                                                                    [loop] for(; (i_16 < 1); i_16 = (i_16 + 1)) {
+                                                                      i_17 = 0;
+                                                                      {
+                                                                        [loop] for(; (i_17 < 1); i_17 = (i_17 + 1)) {
+                                                                          i_18 = 0;
+                                                                          {
+                                                                            [loop] for(; (i_18 < 1); i_18 = (i_18 + 1)) {
+                                                                              i_19 = 0;
+                                                                              {
+                                                                                [loop] for(; (i_19 < 1); i_19 = (i_19 + 1)) {
+                                                                                  i_20 = 0;
+                                                                                  {
+                                                                                    [loop] for(; (i_20 < 1); i_20 = (i_20 + 1)) {
+                                                                                      i_21 = 0;
+                                                                                      {
+                                                                                        [loop] for(; (i_21 < 1); i_21 = (i_21 + 1)) {
+                                                                                          i_22 = 0;
+                                                                                          {
+                                                                                            [loop] for(; (i_22 < 1); i_22 = (i_22 + 1)) {
+                                                                                              i_23 = 0;
+                                                                                              {
+                                                                                                [loop] for(; (i_23 < 1); i_23 = (i_23 + 1)) {
+                                                                                                  i_24 = 0;
+                                                                                                  {
+                                                                                                    [loop] for(; (i_24 < 1); i_24 = (i_24 + 1)) {
+                                                                                                      i_25 = 0;
+                                                                                                      {
+                                                                                                        [loop] for(; (i_25 < 1); i_25 = (i_25 + 1)) {
+                                                                                                          i_26 = 0;
+                                                                                                          {
+                                                                                                            [loop] for(; (i_26 < 1); i_26 = (i_26 + 1)) {
+                                                                                                              i_27 = 0;
+                                                                                                              {
+                                                                                                                [loop] for(; (i_27 < 1); i_27 = (i_27 + 1)) {
+                                                                                                                  i_28 = 0;
+                                                                                                                  {
+                                                                                                                    [loop] for(; (i_28 < 1); i_28 = (i_28 + 1)) {
+                                                                                                                      i_29 = 0;
+                                                                                                                      {
+                                                                                                                        [loop] for(; (i_29 < 1); i_29 = (i_29 + 1)) {
+                                                                                                                          i_30 = 0;
+                                                                                                                          {
+                                                                                                                            [loop] for(; (i_30 < 1); i_30 = (i_30 + 1)) {
+                                                                                                                              i_31 = 0;
+                                                                                                                              {
+                                                                                                                                [loop] for(; (i_31 < 1); i_31 = (i_31 + 1)) {
+                                                                                                                                  i_32 = 0;
+                                                                                                                                  {
+                                                                                                                                    [loop] for(; (i_32 < 1); i_32 = (i_32 + 1)) {
+                                                                                                                                      i_33 = 0;
+                                                                                                                                      {
+                                                                                                                                        [loop] for(; (i_33 < 1); i_33 = (i_33 + 1)) {
+                                                                                                                                          i_34 = 0;
+                                                                                                                                          {
+                                                                                                                                            [loop] for(; (i_34 < 1); i_34 = (i_34 + 1)) {
+                                                                                                                                              i_35 = 0;
+                                                                                                                                              {
+                                                                                                                                                [loop] for(; (i_35 < 1); i_35 = (i_35 + 1)) {
+                                                                                                                                                  i_36 = 0;
+                                                                                                                                                  {
+                                                                                                                                                    [loop] for(; (i_36 < 1); i_36 = (i_36 + 1)) {
+                                                                                                                                                      i_37 = 0;
+                                                                                                                                                      {
+                                                                                                                                                        [loop] for(; (i_37 < 1); i_37 = (i_37 + 1)) {
+                                                                                                                                                          [loop] while (true) {
+                                                                                                                                                            x_GLF_global_loop_count = (x_GLF_global_loop_count + 1);
+                                                                                                                                                            {
+                                                                                                                                                              if ((x_GLF_global_loop_count < 98)) {
+                                                                                                                                                              } else {
+                                                                                                                                                                break;
+                                                                                                                                                              }
+                                                                                                                                                            }
+                                                                                                                                                          }
+                                                                                                                                                          set_scalar_float2x3(m23, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float2x4(m24, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float3x2(m32, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float3x3(m33, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float3x4(m34, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float4x2(m42, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float4x3(m43, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float4x4(m44, i_37, i_37, 1.0f);
+                                                                                                                                                        }
+                                                                                                                                                      }
+                                                                                                                                                    }
+                                                                                                                                                  }
+                                                                                                                                                }
+                                                                                                                                              }
+                                                                                                                                            }
+                                                                                                                                          }
+                                                                                                                                        }
+                                                                                                                                      }
+                                                                                                                                    }
+                                                                                                                                  }
+                                                                                                                                }
+                                                                                                                              }
+                                                                                                                            }
+                                                                                                                          }
+                                                                                                                        }
+                                                                                                                      }
+                                                                                                                    }
+                                                                                                                  }
+                                                                                                                }
+                                                                                                              }
+                                                                                                            }
+                                                                                                          }
+                                                                                                        }
+                                                                                                      }
+                                                                                                    }
+                                                                                                  }
+                                                                                                }
+                                                                                              }
+                                                                                            }
+                                                                                          }
+                                                                                        }
+                                                                                      }
+                                                                                    }
+                                                                                  }
+                                                                                }
+                                                                              }
+                                                                            }
+                                                                          }
+                                                                        }
+                                                                      }
+                                                                    }
+                                                                  }
+                                                                }
+                                                              }
+                                                            }
+                                                          }
+                                                        }
+                                                      }
+                                                    }
+                                                  }
+                                                }
+                                              }
+                                            }
+                                          }
+                                        }
+                                      }
+                                    }
+                                  }
+                                }
+                              }
+                            }
+                          }
+                        }
+                      }
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  sum = 0.0f;
+  r = 0;
+  {
+    [loop] for(; (x_GLF_global_loop_count < 100); r = (r + 1)) {
+      x_GLF_global_loop_count = (x_GLF_global_loop_count + 1);
+      const float x_486 = m23[0][r];
+      sum = (sum + x_486);
+      const float x_491 = m24[0][r];
+      sum = (sum + x_491);
+      const float x_496 = m32[0][r];
+      sum = (sum + x_496);
+      const float x_501 = m33[0][r];
+      sum = (sum + x_501);
+      const float x_506 = m34[0][r];
+      sum = (sum + x_506);
+      const float x_511 = m42[0][r];
+      sum = (sum + x_511);
+      const float x_516 = m43[0][r];
+      sum = (sum + x_516);
+      const float x_521 = m44[0][r];
+      sum = (sum + x_521);
+    }
+  }
+  if ((sum == 8.0f)) {
+    x_GLF_color = float4(1.0f, 0.0f, 0.0f, 1.0f);
+  } else {
+    x_GLF_color = float4(0.0f, 0.0f, 0.0f, 0.0f);
+  }
+  return;
+}
+
+struct main_out {
+  float4 x_GLF_color_1;
+};
+struct tint_symbol {
+  float4 x_GLF_color_1 : SV_Target0;
+};
+
+main_out main_inner() {
+  main_1();
+  const main_out tint_symbol_1 = {x_GLF_color};
+  return tint_symbol_1;
+}
+
+tint_symbol main() {
+  const main_out inner_result = main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.x_GLF_color_1 = inner_result.x_GLF_color_1;
+  return wrapper_result;
+}
diff --git a/test/vk-gl-cts/graphicsfuzz/cov-multiple-one-iteration-loops-global-counter-write-matrices/0-opt.wgsl.expected.hlsl b/test/vk-gl-cts/graphicsfuzz/cov-multiple-one-iteration-loops-global-counter-write-matrices/0-opt.wgsl.expected.hlsl
new file mode 100644
index 0000000..abefd0c
--- /dev/null
+++ b/test/vk-gl-cts/graphicsfuzz/cov-multiple-one-iteration-loops-global-counter-write-matrices/0-opt.wgsl.expected.hlsl
@@ -0,0 +1,435 @@
+SKIP: flaky test with FXC, often times out
+
+void set_scalar_float2x3(inout float2x3 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[1];
+      break;
+  }
+}
+
+void set_scalar_float2x4(inout float2x4 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[1];
+      break;
+  }
+}
+
+void set_scalar_float3x2(inout float3x2 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xx == int2(0, 1)) ? val.xx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xx == int2(0, 1)) ? val.xx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xx == int2(0, 1)) ? val.xx : mat[2];
+      break;
+  }
+}
+
+void set_scalar_float3x3(inout float3x3 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[2];
+      break;
+  }
+}
+
+void set_scalar_float3x4(inout float3x4 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[2];
+      break;
+  }
+}
+
+void set_scalar_float4x2(inout float4x2 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xx == int2(0, 1)) ? val.xx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xx == int2(0, 1)) ? val.xx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xx == int2(0, 1)) ? val.xx : mat[2];
+      break;
+    case 3:
+      mat[3] = (row.xx == int2(0, 1)) ? val.xx : mat[3];
+      break;
+  }
+}
+
+void set_scalar_float4x3(inout float4x3 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[2];
+      break;
+    case 3:
+      mat[3] = (row.xxx == int3(0, 1, 2)) ? val.xxx : mat[3];
+      break;
+  }
+}
+
+void set_scalar_float4x4(inout float4x4 mat, int col, int row, float val) {
+  switch (col) {
+    case 0:
+      mat[0] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[0];
+      break;
+    case 1:
+      mat[1] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[1];
+      break;
+    case 2:
+      mat[2] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[2];
+      break;
+    case 3:
+      mat[3] = (row.xxxx == int4(0, 1, 2, 3)) ? val.xxxx : mat[3];
+      break;
+  }
+}
+
+static int x_GLF_global_loop_count = 0;
+static float4 x_GLF_color = float4(0.0f, 0.0f, 0.0f, 0.0f);
+
+void main_1() {
+  float2x3 m23 = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float2x4 m24 = float2x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float3x2 m32 = float3x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float3x3 m33 = float3x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float3x4 m34 = float3x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float4x2 m42 = float4x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float4x3 m43 = float4x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  float4x4 m44 = float4x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+  int i = 0;
+  int i_1 = 0;
+  int i_2 = 0;
+  int i_3 = 0;
+  int i_4 = 0;
+  int i_5 = 0;
+  int i_6 = 0;
+  int i_7 = 0;
+  int i_8 = 0;
+  int i_9 = 0;
+  int i_10 = 0;
+  int i_11 = 0;
+  int i_12 = 0;
+  int i_13 = 0;
+  int i_14 = 0;
+  int i_15 = 0;
+  int i_16 = 0;
+  int i_17 = 0;
+  int i_18 = 0;
+  int i_19 = 0;
+  int i_20 = 0;
+  int i_21 = 0;
+  int i_22 = 0;
+  int i_23 = 0;
+  int i_24 = 0;
+  int i_25 = 0;
+  int i_26 = 0;
+  int i_27 = 0;
+  int i_28 = 0;
+  int i_29 = 0;
+  int i_30 = 0;
+  int i_31 = 0;
+  int i_32 = 0;
+  int i_33 = 0;
+  int i_34 = 0;
+  int i_35 = 0;
+  int i_36 = 0;
+  int i_37 = 0;
+  float sum = 0.0f;
+  int r = 0;
+  x_GLF_global_loop_count = 0;
+  m23 = float2x3(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
+  m24 = float2x4(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
+  m32 = float3x2(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
+  m33 = float3x3(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
+  m34 = float3x4(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
+  m42 = float4x2(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f));
+  m43 = float4x3(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f));
+  m44 = float4x4(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f));
+  i = 0;
+  {
+    [loop] for(; (i < 1); i = (i + 1)) {
+      i_1 = 0;
+      {
+        [loop] for(; (i_1 < 1); i_1 = (i_1 + 1)) {
+          i_2 = 0;
+          {
+            [loop] for(; (i_2 < 1); i_2 = (i_2 + 1)) {
+              i_3 = 0;
+              {
+                [loop] for(; (i_3 < 1); i_3 = (i_3 + 1)) {
+                  i_4 = 0;
+                  {
+                    [loop] for(; (i_4 < 1); i_4 = (i_4 + 1)) {
+                      i_5 = 0;
+                      {
+                        [loop] for(; (i_5 < 1); i_5 = (i_5 + 1)) {
+                          i_6 = 0;
+                          {
+                            [loop] for(; (i_6 < 1); i_6 = (i_6 + 1)) {
+                              i_7 = 0;
+                              {
+                                [loop] for(; (i_7 < 1); i_7 = (i_7 + 1)) {
+                                  i_8 = 0;
+                                  {
+                                    [loop] for(; (i_8 < 1); i_8 = (i_8 + 1)) {
+                                      i_9 = 0;
+                                      {
+                                        [loop] for(; (i_9 < 1); i_9 = (i_9 + 1)) {
+                                          i_10 = 0;
+                                          {
+                                            [loop] for(; (i_10 < 1); i_10 = (i_10 + 1)) {
+                                              i_11 = 0;
+                                              {
+                                                [loop] for(; (i_11 < 1); i_11 = (i_11 + 1)) {
+                                                  i_12 = 0;
+                                                  {
+                                                    [loop] for(; (i_12 < 1); i_12 = (i_12 + 1)) {
+                                                      i_13 = 0;
+                                                      {
+                                                        [loop] for(; (i_13 < 1); i_13 = (i_13 + 1)) {
+                                                          i_14 = 0;
+                                                          {
+                                                            [loop] for(; (i_14 < 1); i_14 = (i_14 + 1)) {
+                                                              i_15 = 0;
+                                                              {
+                                                                [loop] for(; (i_15 < 1); i_15 = (i_15 + 1)) {
+                                                                  i_16 = 0;
+                                                                  {
+                                                                    [loop] for(; (i_16 < 1); i_16 = (i_16 + 1)) {
+                                                                      i_17 = 0;
+                                                                      {
+                                                                        [loop] for(; (i_17 < 1); i_17 = (i_17 + 1)) {
+                                                                          i_18 = 0;
+                                                                          {
+                                                                            [loop] for(; (i_18 < 1); i_18 = (i_18 + 1)) {
+                                                                              i_19 = 0;
+                                                                              {
+                                                                                [loop] for(; (i_19 < 1); i_19 = (i_19 + 1)) {
+                                                                                  i_20 = 0;
+                                                                                  {
+                                                                                    [loop] for(; (i_20 < 1); i_20 = (i_20 + 1)) {
+                                                                                      i_21 = 0;
+                                                                                      {
+                                                                                        [loop] for(; (i_21 < 1); i_21 = (i_21 + 1)) {
+                                                                                          i_22 = 0;
+                                                                                          {
+                                                                                            [loop] for(; (i_22 < 1); i_22 = (i_22 + 1)) {
+                                                                                              i_23 = 0;
+                                                                                              {
+                                                                                                [loop] for(; (i_23 < 1); i_23 = (i_23 + 1)) {
+                                                                                                  i_24 = 0;
+                                                                                                  {
+                                                                                                    [loop] for(; (i_24 < 1); i_24 = (i_24 + 1)) {
+                                                                                                      i_25 = 0;
+                                                                                                      {
+                                                                                                        [loop] for(; (i_25 < 1); i_25 = (i_25 + 1)) {
+                                                                                                          i_26 = 0;
+                                                                                                          {
+                                                                                                            [loop] for(; (i_26 < 1); i_26 = (i_26 + 1)) {
+                                                                                                              i_27 = 0;
+                                                                                                              {
+                                                                                                                [loop] for(; (i_27 < 1); i_27 = (i_27 + 1)) {
+                                                                                                                  i_28 = 0;
+                                                                                                                  {
+                                                                                                                    [loop] for(; (i_28 < 1); i_28 = (i_28 + 1)) {
+                                                                                                                      i_29 = 0;
+                                                                                                                      {
+                                                                                                                        [loop] for(; (i_29 < 1); i_29 = (i_29 + 1)) {
+                                                                                                                          i_30 = 0;
+                                                                                                                          {
+                                                                                                                            [loop] for(; (i_30 < 1); i_30 = (i_30 + 1)) {
+                                                                                                                              i_31 = 0;
+                                                                                                                              {
+                                                                                                                                [loop] for(; (i_31 < 1); i_31 = (i_31 + 1)) {
+                                                                                                                                  i_32 = 0;
+                                                                                                                                  {
+                                                                                                                                    [loop] for(; (i_32 < 1); i_32 = (i_32 + 1)) {
+                                                                                                                                      i_33 = 0;
+                                                                                                                                      {
+                                                                                                                                        [loop] for(; (i_33 < 1); i_33 = (i_33 + 1)) {
+                                                                                                                                          i_34 = 0;
+                                                                                                                                          {
+                                                                                                                                            [loop] for(; (i_34 < 1); i_34 = (i_34 + 1)) {
+                                                                                                                                              i_35 = 0;
+                                                                                                                                              {
+                                                                                                                                                [loop] for(; (i_35 < 1); i_35 = (i_35 + 1)) {
+                                                                                                                                                  i_36 = 0;
+                                                                                                                                                  {
+                                                                                                                                                    [loop] for(; (i_36 < 1); i_36 = (i_36 + 1)) {
+                                                                                                                                                      i_37 = 0;
+                                                                                                                                                      {
+                                                                                                                                                        [loop] for(; (i_37 < 1); i_37 = (i_37 + 1)) {
+                                                                                                                                                          [loop] while (true) {
+                                                                                                                                                            x_GLF_global_loop_count = (x_GLF_global_loop_count + 1);
+                                                                                                                                                            {
+                                                                                                                                                              if ((x_GLF_global_loop_count < 98)) {
+                                                                                                                                                              } else {
+                                                                                                                                                                break;
+                                                                                                                                                              }
+                                                                                                                                                            }
+                                                                                                                                                          }
+                                                                                                                                                          set_scalar_float2x3(m23, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float2x4(m24, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float3x2(m32, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float3x3(m33, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float3x4(m34, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float4x2(m42, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float4x3(m43, i_37, i_37, 1.0f);
+                                                                                                                                                          set_scalar_float4x4(m44, i_37, i_37, 1.0f);
+                                                                                                                                                        }
+                                                                                                                                                      }
+                                                                                                                                                    }
+                                                                                                                                                  }
+                                                                                                                                                }
+                                                                                                                                              }
+                                                                                                                                            }
+                                                                                                                                          }
+                                                                                                                                        }
+                                                                                                                                      }
+                                                                                                                                    }
+                                                                                                                                  }
+                                                                                                                                }
+                                                                                                                              }
+                                                                                                                            }
+                                                                                                                          }
+                                                                                                                        }
+                                                                                                                      }
+                                                                                                                    }
+                                                                                                                  }
+                                                                                                                }
+                                                                                                              }
+                                                                                                            }
+                                                                                                          }
+                                                                                                        }
+                                                                                                      }
+                                                                                                    }
+                                                                                                  }
+                                                                                                }
+                                                                                              }
+                                                                                            }
+                                                                                          }
+                                                                                        }
+                                                                                      }
+                                                                                    }
+                                                                                  }
+                                                                                }
+                                                                              }
+                                                                            }
+                                                                          }
+                                                                        }
+                                                                      }
+                                                                    }
+                                                                  }
+                                                                }
+                                                              }
+                                                            }
+                                                          }
+                                                        }
+                                                      }
+                                                    }
+                                                  }
+                                                }
+                                              }
+                                            }
+                                          }
+                                        }
+                                      }
+                                    }
+                                  }
+                                }
+                              }
+                            }
+                          }
+                        }
+                      }
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  sum = 0.0f;
+  r = 0;
+  {
+    [loop] for(; (x_GLF_global_loop_count < 100); r = (r + 1)) {
+      x_GLF_global_loop_count = (x_GLF_global_loop_count + 1);
+      const float x_486 = m23[0][r];
+      sum = (sum + x_486);
+      const float x_491 = m24[0][r];
+      sum = (sum + x_491);
+      const float x_496 = m32[0][r];
+      sum = (sum + x_496);
+      const float x_501 = m33[0][r];
+      sum = (sum + x_501);
+      const float x_506 = m34[0][r];
+      sum = (sum + x_506);
+      const float x_511 = m42[0][r];
+      sum = (sum + x_511);
+      const float x_516 = m43[0][r];
+      sum = (sum + x_516);
+      const float x_521 = m44[0][r];
+      sum = (sum + x_521);
+    }
+  }
+  if ((sum == 8.0f)) {
+    x_GLF_color = float4(1.0f, 0.0f, 0.0f, 1.0f);
+  } else {
+    x_GLF_color = float4(0.0f, 0.0f, 0.0f, 0.0f);
+  }
+  return;
+}
+
+struct main_out {
+  float4 x_GLF_color_1;
+};
+struct tint_symbol {
+  float4 x_GLF_color_1 : SV_Target0;
+};
+
+main_out main_inner() {
+  main_1();
+  const main_out tint_symbol_1 = {x_GLF_color};
+  return tint_symbol_1;
+}
+
+tint_symbol main() {
+  const main_out inner_result = main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.x_GLF_color_1 = inner_result.x_GLF_color_1;
+  return wrapper_result;
+}