Add a toggle to disallow_spirv.

This toggle will be used by Chromium to disallow the unsecured SPIR-V
path such that a renderer process can only use WGSL.

This new toggle will be covered by a test in Chromium that ensures that
in the default configuration SPIR-V is disallowed.

Bug: chromium:1214923

Change-Id: Ia67e0c7466044e1086399d995dc841426fe604c9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/52781
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp
index 4bff6d6..b2a2a1f 100644
--- a/src/dawn_native/ShaderModule.cpp
+++ b/src/dawn_native/ShaderModule.cpp
@@ -1083,6 +1083,10 @@
         FindInChain(chainedDescriptor, &wgslDesc);
 
         if (spirvDesc) {
+            if (device->IsToggleEnabled(Toggle::DisallowSpirv)) {
+                return DAWN_VALIDATION_ERROR("SPIR-V is disallowed.");
+            }
+
             std::vector<uint32_t> spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize);
             if (device->IsToggleEnabled(Toggle::UseTintGenerator)) {
                 tint::Program program;
diff --git a/src/dawn_native/Toggles.cpp b/src/dawn_native/Toggles.cpp
index d773de1..efc1540 100644
--- a/src/dawn_native/Toggles.cpp
+++ b/src/dawn_native/Toggles.cpp
@@ -182,7 +182,13 @@
               "Sets the D3DCOMPILE_SKIP_OPTIMIZATION and D3DCOMPILE_DEBUG compilation flags when "
               "compiling HLSL code. Enables better shader debugging with external graphics "
               "debugging tools.",
-              "https://crbug.com/dawn/776"}}
+              "https://crbug.com/dawn/776"}},
+            {Toggle::DisallowSpirv,
+             {"disallow_spirv",
+              "Disallow usage of SPIR-V completely so that only WGSL is used for shader modules."
+              "This is useful to prevent a Chromium renderer process from successfully sending"
+              "SPIR-V code to be compiled in the GPU process.",
+              "https://crbug.com/1214923"}},
             // Dummy comment to separate the }} so it is clearer what to copy-paste to add a toggle.
         }};
     }  // anonymous namespace
diff --git a/src/dawn_native/Toggles.h b/src/dawn_native/Toggles.h
index f3f0d32..f9dc6c0 100644
--- a/src/dawn_native/Toggles.h
+++ b/src/dawn_native/Toggles.h
@@ -52,6 +52,7 @@
         FlushBeforeClientWaitSync,
         UseTempBufferInSmallFormatTextureToTextureCopyFromGreaterToLessMipLevel,
         EmitHLSLDebugSymbols,
+        DisallowSpirv,
 
         EnumCount,
         InvalidEnum = EnumCount,