Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

fix(build): strip only the GLES3 variants of the three URP utility shaders (fix round 1, M1)

eyalgolan89559f445310
diff --git a/unity/Assets/Editor/WebShaderStripping.cs b/unity/Assets/Editor/WebShaderStripping.cs
index 466411a6e..5702bf330 100644
--- a/unity/Assets/Editor/WebShaderStripping.cs
+++ b/unity/Assets/Editor/WebShaderStripping.cs
@@ -1,7 +1,6 @@
#nullable enable
using System;
using System.Collections.Generic;
-using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;
@@ -9,8 +8,9 @@ using UnityEngine.Rendering;
namespace Statecraft.Game.EditorTools
{
- /// <summary>Strips, from WebGL builds only, three hidden URP utility shaders that need shader target 4.5 (WebGL 2 is
- /// ES 3.0) and that this build never draws with. Without them the browser console no longer reports them as "not
+ /// <summary>Strips the GLES3 (WebGL 2) variants of three hidden URP utility shaders that need shader target 4.5 (WebGL 2
+ /// is ES 3.0) and that this build never draws with; scoped by graphics API, not build target, so a WebGPU WebGL build
+ /// would keep them (fix round 1, M1). Without them the browser console no longer reports them as "not
/// supported on this GPU" (playtest 1, item 12). Why each is unused on WebGL (URP 17.3 / Core RP 17.3 sources):
/// - Hidden/CoreSRP/CoreCopy: Blitter.Initialize creates its material unconditionally, but the render-graph copy
/// pass that draws with it needs framebuffer-fetch emulation, which RenderGraphUtils reports unsupported on WebGL
@@ -31,13 +31,20 @@ namespace Statecraft.Game.EditorTools
public int callbackOrder => 0;
- /// <summary>True when every variant of <paramref name="shaderName"/> is dropped for <paramref name="target"/>.</summary>
- public static bool Strips(BuildTarget target, string shaderName) =>
- target == BuildTarget.WebGL && Array.IndexOf(Unused, shaderName) >= 0;
-
- public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
+ /// <summary>Removes the GLES3 (WebGL 2) variants of the <see cref="Unused"/> shaders from <paramref name="data"/>, in
+ /// place, and returns how many it removed. Only the API whose limit this works around: other graphics APIs (WebGPU,
+ /// Metal, D3D) keep every variant, and every other shader is untouched. Generic over the variant type so tests can
+ /// run it over plain platforms.</summary>
+ public static int Filter<T>(string shaderName, IList<T> data, Func<T, ShaderCompilerPlatform> platform)
{
- if (Strips(EditorUserBuildSettings.activeBuildTarget, shader.name)) data.Clear();
+ if (Array.IndexOf(Unused, shaderName) < 0) return 0;
+ int removed = 0;
+ for (int i = data.Count - 1; i >= 0; i--)
+ if (platform(data[i]) == ShaderCompilerPlatform.GLES3x) { data.RemoveAt(i); removed++; }
+ return removed;
}
+
+ public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data) =>
+ Filter(shader.name, data, d => d.shaderCompilerPlatform);
}
}
diff --git a/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs b/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs
index 3be745307..0bf11a05e 100644
--- a/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs
+++ b/unity/Assets/Tests/EditMode/WebShaderStrippingTests.cs
@@ -1,13 +1,15 @@
#nullable enable
-using NUnit.Framework;
using System;
+using System.Collections.Generic;
using System.Reflection;
+using NUnit.Framework;
using UnityEditor.Build;
-using UnityEditor;
+using UnityEditor.Rendering;
using UnityEngine;
-/// <summary>Playtest 1, item 12: the three hidden URP utility shaders that WebGL 2 cannot run, and that this build never
-/// draws with, are stripped from WebGL builds only; every other shader and every other platform is left alone.</summary>
+/// <summary>Playtest 1, item 12 (fix round 1, M1): the three hidden URP utility shaders that GLES3 (WebGL 2) cannot run,
+/// and that this build never draws with, lose their GLES3 variants only; other graphics APIs (WebGPU, Metal) and every
+/// other shader keep theirs.</summary>
public class WebShaderStrippingTests
{
// Editor code lives in Assembly-CSharp-Editor, which a test assembly cannot reference (as in PortraitImportTests).
@@ -21,8 +23,15 @@ public class WebShaderStrippingTests
}
}
- static bool Strips(BuildTarget target, string name) =>
- (bool)Stripper.GetMethod("Strips", BindingFlags.Public | BindingFlags.Static)!.Invoke(null, new object[] { target, name })!;
+ /// <summary>Runs the stripper's own filter (the method OnProcessShader calls) over variants given by platform.</summary>
+ static List<ShaderCompilerPlatform> Filter(string shader, params ShaderCompilerPlatform[] variants)
+ {
+ var data = new List<ShaderCompilerPlatform>(variants);
+ var filter = Stripper.GetMethod("Filter", BindingFlags.Public | BindingFlags.Static)!.MakeGenericMethod(typeof(ShaderCompilerPlatform));
+ Func<ShaderCompilerPlatform, ShaderCompilerPlatform> platform = p => p;
+ filter.Invoke(null, new object[] { shader, data, platform });
+ return data;
+ }
[Test]
public void ItIsAShaderPreprocessor() => Assert.IsTrue(typeof(IPreprocessShaders).IsAssignableFrom(Stripper));
@@ -30,16 +39,20 @@ public class WebShaderStrippingTests
[TestCase("Hidden/CoreSRP/CoreCopy")]
[TestCase("Hidden/Universal Render Pipeline/StencilDitherMaskSeed")]
[TestCase("Hidden/Universal/HDRDebugView")]
- public void TheUnsupportedUtilityShadersAreStrippedForWebGLOnly(string name)
+ public void OnlyTheGles3VariantsOfTheUnsupportedShadersAreStripped(string name)
{
Assert.IsNotNull(Shader.Find(name), name + " exists (URP renamed it?)");
- Assert.IsTrue(Strips(BuildTarget.WebGL, name));
- Assert.IsFalse(Strips(BuildTarget.StandaloneOSX, name));
+ var left = Filter(name, ShaderCompilerPlatform.GLES3x, ShaderCompilerPlatform.WebGPU, ShaderCompilerPlatform.GLES3x, ShaderCompilerPlatform.Metal);
+ CollectionAssert.AreEqual(new[] { ShaderCompilerPlatform.WebGPU, ShaderCompilerPlatform.Metal }, left);
}
[TestCase("Hidden/Universal Render Pipeline/Blit")]
[TestCase("Hidden/Universal/CoreBlit")]
[TestCase("Universal Render Pipeline/Unlit")]
[TestCase("Universal Render Pipeline/Terrain/Lit")]
- public void EveryOtherShaderIsKept(string name) => Assert.IsFalse(Strips(BuildTarget.WebGL, name));
+ public void EveryOtherShaderIsKept(string name)
+ {
+ var all = new[] { ShaderCompilerPlatform.GLES3x, ShaderCompilerPlatform.WebGPU, ShaderCompilerPlatform.Metal };
+ CollectionAssert.AreEqual(all, Filter(name, all));
+ }
}