Make HLSL validation run with same flags as Dawn

FXC is buggy, and I recently landed changes in Dawn to run with "/O0"
rather than /"O2" because of these bugs. Let's make sure Tint end-to-end
tests do the same. Also do the same when running against DXC.

Bug: dawn:1203
Change-Id: I1a30f16dee8306bd645d87b3ccb0cc87691c5972
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/71800
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/val/hlsl.cc b/src/val/hlsl.cc
index 0a2d672..696230b 100644
--- a/src/val/hlsl.cc
+++ b/src/val/hlsl.cc
@@ -63,7 +63,14 @@
         break;
     }
 
-    auto res = dxc(profile, "-E " + ep.first, file.Path());
+    // Match Dawn's compile flags
+    // See dawn\src\dawn_native\d3d12\RenderPipelineD3D12.cpp
+    // and dawn_native\d3d12\ShaderModuleD3D12.cpp (GetDXCArguments)
+    const char* compileFlags =
+        "/Zpr "  // D3DCOMPILE_PACK_MATRIX_ROW_MAJOR
+        "/Gis";  // D3DCOMPILE_IEEE_STRICTNESS
+
+    auto res = dxc(profile, "-E " + ep.first, compileFlags, file.Path());
     if (!res.out.empty()) {
       if (!result.output.empty()) {
         result.output += "\n";
@@ -129,11 +136,26 @@
         break;
     }
 
+    // Match Dawn's compile flags
+    // See dawn\src\dawn_native\d3d12\RenderPipelineD3D12.cpp
+    UINT compileFlags = D3DCOMPILE_OPTIMIZATION_LEVEL0 |
+                        D3DCOMPILE_PACK_MATRIX_ROW_MAJOR |
+                        D3DCOMPILE_IEEE_STRICTNESS;
+
     ComPtr<ID3DBlob> compiledShader;
     ComPtr<ID3DBlob> errors;
-    if (FAILED(d3dCompile(source.c_str(), source.length(), nullptr, nullptr,
-                          nullptr, ep.first.c_str(), profile, 0, 0,
-                          &compiledShader, &errors))) {
+    HRESULT cr = d3dCompile(source.c_str(),    // pSrcData
+                            source.length(),   // SrcDataSize
+                            nullptr,           // pSourceName
+                            nullptr,           // pDefines
+                            nullptr,           // pInclude
+                            ep.first.c_str(),  // pEntrypoint
+                            profile,           // pTarget
+                            compileFlags,      // Flags1
+                            0,                 // Flags2
+                            &compiledShader,   // ppCode
+                            &errors);          // ppErrorMsgs
+    if (FAILED(cr)) {
       result.output = static_cast<char*>(errors->GetBufferPointer());
       result.failed = true;
       return result;