Add toggles: disable_workgroup_init, disable_symbol_renaming

--disable_workgroup_init will disable the workgroup memory zero initiailization. Useful for benchmarking.

--disable_symbol_renaming will disable tint's symbol renamer. Useful for debugging output.

Bug: tint:1003
Fixed: dawn:1016
Change-Id: I92486ef88a2c1112d9ccb40f7920947bd2011c70
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/58861
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/Toggles.cpp b/src/dawn_native/Toggles.cpp
index 195aa75..efd6519 100644
--- a/src/dawn_native/Toggles.cpp
+++ b/src/dawn_native/Toggles.cpp
@@ -204,6 +204,14 @@
               "testing Tint's SPIRV->WGSL translation on real content to be sure that it will "
               "work when the same translation runs in a WASM module in the page.",
               "https://crbug.com/dawn/960"}},
+            {Toggle::DisableWorkgroupInit,
+             {"disable_workgroup_init",
+              "Disables the workgroup memory zero-initialization for compute shaders.",
+              "https://crbug.com/tint/1003"}},
+            {Toggle::DisableSymbolRenaming,
+             {"disable_symbol_renaming",
+              "Disables the WGSL symbol renaming so that names are preserved.",
+              "https://crbug.com/dawn/1016"}},
             // 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 ade8e7a..9c11400 100644
--- a/src/dawn_native/Toggles.h
+++ b/src/dawn_native/Toggles.h
@@ -56,6 +56,8 @@
         DumpShaders,
         DEPRECATED_DumpTranslatedShaders,  // Use DumpShaders
         ForceWGSLStep,
+        DisableWorkgroupInit,
+        DisableSymbolRenaming,
 
         EnumCount,
         InvalidEnum = EnumCount,
diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp
index 2c1236b..d2f0ed5 100644
--- a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp
+++ b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp
@@ -260,6 +260,12 @@
         transformManager.Add<tint::transform::BindingRemapper>();
         transformManager.Add<tint::transform::Renamer>();
 
+        if (GetDevice()->IsToggleEnabled(Toggle::DisableSymbolRenaming)) {
+            // We still need to rename HLSL reserved keywords
+            transformInputs.Add<tint::transform::Renamer::Config>(
+                tint::transform::Renamer::Target::kHlslKeywords);
+        }
+
         // D3D12 registers like `t3` and `c3` have the same bindingOffset number in the
         // remapping but should not be considered a collision because they have different types.
         const bool mayCollide = true;
@@ -284,15 +290,21 @@
 
         if (auto* data = transformOutputs.Get<tint::transform::Renamer::Data>()) {
             auto it = data->remappings.find(entryPointName);
-            if (it == data->remappings.end()) {
-                return DAWN_VALIDATION_ERROR("Could not find remapped name for entry point.");
+            if (it != data->remappings.end()) {
+                *remappedEntryPointName = it->second;
+            } else {
+                if (GetDevice()->IsToggleEnabled(Toggle::DisableSymbolRenaming)) {
+                    *remappedEntryPointName = entryPointName;
+                } else {
+                    return DAWN_VALIDATION_ERROR("Could not find remapped name for entry point.");
+                }
             }
-            *remappedEntryPointName = it->second;
         } else {
             return DAWN_VALIDATION_ERROR("Transform output missing renamer data.");
         }
 
         tint::writer::hlsl::Options options;
+        options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
         auto result = tint::writer::hlsl::Generate(&program, options);
         if (!result.success) {
             errorStream << "Generator: " << result.error << std::endl;
diff --git a/src/dawn_native/metal/ShaderModuleMTL.mm b/src/dawn_native/metal/ShaderModuleMTL.mm
index d9a9d44..d6510e1 100644
--- a/src/dawn_native/metal/ShaderModuleMTL.mm
+++ b/src/dawn_native/metal/ShaderModuleMTL.mm
@@ -125,6 +125,13 @@
         transformManager.Add<tint::transform::BindingRemapper>();
         transformManager.Add<tint::transform::Renamer>();
 
+        if (GetDevice()->IsToggleEnabled(Toggle::DisableSymbolRenaming)) {
+            // We still need to rename MSL reserved keywords
+            transformInputs.Add<tint::transform::Renamer::Config>(
+                tint::transform::Renamer::Target::kMslKeywords);
+        }
+
+
         transformInputs.Add<BindingRemapper::Remappings>(std::move(bindingPoints),
                                                          std::move(accessControls),
                                                          /* mayCollide */ true);
@@ -136,10 +143,15 @@
 
         if (auto* data = transformOutputs.Get<tint::transform::Renamer::Data>()) {
             auto it = data->remappings.find(entryPointName);
-            if (it == data->remappings.end()) {
-                return DAWN_VALIDATION_ERROR("Could not find remapped name for entry point.");
+            if (it != data->remappings.end()) {
+                *remappedEntryPointName = it->second;
+            } else {
+                if (GetDevice()->IsToggleEnabled(Toggle::DisableSymbolRenaming)) {
+                    *remappedEntryPointName = entryPointName;
+                } else {
+                    return DAWN_VALIDATION_ERROR("Could not find remapped name for entry point.");
+                }
             }
-            *remappedEntryPointName = it->second;
         } else {
             return DAWN_VALIDATION_ERROR("Transform output missing renamer data.");
         }
@@ -147,6 +159,7 @@
         tint::writer::msl::Options options;
         options.buffer_size_ubo_index = kBufferLengthBufferSlot;
         options.fixed_sample_mask = sampleMask;
+        options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
         auto result = tint::writer::msl::Generate(&program, options);
         if (!result.success) {
             errorStream << "Generator: " << result.error << std::endl;
diff --git a/src/dawn_native/opengl/ShaderModuleGL.cpp b/src/dawn_native/opengl/ShaderModuleGL.cpp
index de8d986..a5bbcb9 100644
--- a/src/dawn_native/opengl/ShaderModuleGL.cpp
+++ b/src/dawn_native/opengl/ShaderModuleGL.cpp
@@ -85,6 +85,8 @@
         // generate SPIRV and SPIRV-Cross reflection data to be used in this backend.
         if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
             tint::writer::spirv::Options options;
+            options.disable_workgroup_init =
+                GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
             auto result = tint::writer::spirv::Generate(GetTintProgram(), options);
             if (!result.success) {
                 std::ostringstream errorStream;
diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp
index 82bb0de..525dbb1 100644
--- a/src/dawn_native/vulkan/ShaderModuleVk.cpp
+++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp
@@ -108,6 +108,8 @@
 
             tint::writer::spirv::Options options;
             options.emit_vertex_point_size = true;
+            options.disable_workgroup_init =
+                GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
             auto result = tint::writer::spirv::Generate(&program, options);
             if (!result.success) {
                 errorStream << "Generator: " << result.error << std::endl;
@@ -213,6 +215,7 @@
 
         tint::writer::spirv::Options options;
         options.emit_vertex_point_size = true;
+        options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
         auto result = tint::writer::spirv::Generate(&program, options);
         if (!result.success) {
             errorStream << "Generator: " << result.error << std::endl;