Use correct Initialize call to spvc for Metal backend

BUG=dawn:292

Change-Id: I91d315d2f071cb8a25acb0d5379944ac8049deea
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14340
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn_native/metal/ShaderModuleMTL.mm b/src/dawn_native/metal/ShaderModuleMTL.mm
index c01621d..79a9db5 100644
--- a/src/dawn_native/metal/ShaderModuleMTL.mm
+++ b/src/dawn_native/metal/ShaderModuleMTL.mm
@@ -38,6 +38,25 @@
                     UNREACHABLE();
             }
         }
+
+        shaderc_spvc::CompileOptions GetMSLCompileOptions() {
+            // If these options are changed, the values in DawnSPIRVCrossGLSLFastFuzzer.cpp need to
+            // be updated.
+            shaderc_spvc::CompileOptions options;
+
+            // Disable PointSize builtin for https://bugs.chromium.org/p/dawn/issues/detail?id=146
+            // Because Metal will reject PointSize builtin if the shader is compiled into a render
+            // pipeline that uses a non-point topology.
+            // TODO (hao.x.li@intel.com): Remove this once WebGPU requires there is no
+            // gl_PointSize builtin (https://github.com/gpuweb/gpuweb/issues/332).
+            options.SetMSLEnablePointSizeBuiltIn(false);
+
+            // Always use vertex buffer 30 (the last one in the vertex buffer table) to contain
+            // the shader storage buffer lengths.
+            options.SetMSLBufferSizeBufferIndex(kBufferLengthBufferSlot);
+
+            return options;
+        }
     }  // namespace
 
     // static
@@ -57,9 +76,8 @@
     MaybeError ShaderModule::Initialize(const ShaderModuleDescriptor* descriptor) {
         mSpirv.assign(descriptor->code, descriptor->code + descriptor->codeSize);
         if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
-            shaderc_spvc::CompileOptions options;
-            shaderc_spvc_status status =
-                mSpvcContext.InitializeForGlsl(descriptor->code, descriptor->codeSize, options);
+            shaderc_spvc_status status = mSpvcContext.InitializeForMsl(
+                descriptor->code, descriptor->codeSize, GetMSLCompileOptions());
             if (status != shaderc_spvc_status_success) {
                 return DAWN_VALIDATION_ERROR("Unable to initialize instance of spvc");
             }
@@ -80,21 +98,9 @@
         std::unique_ptr<spirv_cross::CompilerMSL> compiler_impl;
         spirv_cross::CompilerMSL* compiler;
         if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
-            // If these options are changed, the values in DawnSPIRVCrossGLSLFastFuzzer.cpp need to
-            // be updated.
-            shaderc_spvc::CompileOptions options;
-
-            // Disable PointSize builtin for https://bugs.chromium.org/p/dawn/issues/detail?id=146
-            // Because Metal will reject PointSize builtin if the shader is compiled into a render
-            // pipeline that uses a non-point topology.
-            // TODO (hao.x.li@intel.com): Remove this once WebGPU requires there is no
-            // gl_PointSize builtin (https://github.com/gpuweb/gpuweb/issues/332).
-            options.SetMSLEnablePointSizeBuiltIn(false);
-
-            // Always use vertex buffer 30 (the last one in the vertex buffer table) to contain
-            // the shader storage buffer lengths.
-            options.SetMSLBufferSizeBufferIndex(kBufferLengthBufferSlot);
-            mSpvcContext.InitializeForMsl(mSpirv.data(), mSpirv.size(), options);
+            // Initializing the compiler is needed every call, because this method uses reflection
+            // to mutate the compiler's IR.
+            mSpvcContext.InitializeForMsl(mSpirv.data(), mSpirv.size(), GetMSLCompileOptions());
             // TODO(rharrison): Handle initialize failing
 
             compiler = reinterpret_cast<spirv_cross::CompilerMSL*>(mSpvcContext.GetCompiler());