Skip to content

Commit 799ae23

Browse files
ci(audience): force StandaloneLinux64 player to OpenGLCore only at build time
Adds GraphicsApisLinuxOverride, an editor build hook gated on the AUDIENCE_LINUX_GLCORE_ONLY env var. When the env is set and the build target is StandaloneLinux64, it pins PlayerSettings graphics APIs to OpenGLCore only, dropping Vulkan from the active list. The Linux container has no GPU and the player runs on Mesa llvmpipe via -force-glcore. Vulkan was active in the build only because Unity's default Standalone API list includes it; the shader compiler emitted both glcore and vulkan variants for every shader. On the Unity 6 cell this was 213 of 413 compiles wasted on a code path the player never hit. Wires the env var through the playmode-linux job's docker run so the override fires on Linux PlayMode CI builds. Local builds and other targets see no change because the env var is unset and the hook short circuits on non-Linux build targets.
1 parent aaf44cb commit 799ae23

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

.github/workflows/test-audience-sample-app.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ jobs:
467467
AUDIENCE_TEST_PUBLISHABLE_KEY: ${{ secrets.AUDIENCE_TEST_PUBLISHABLE_KEY }}
468468
AUDIENCE_SCRIPTING_BACKEND: ${{ matrix.backend }}
469469
UNITY_VERSION: ${{ matrix.unity }}
470+
AUDIENCE_LINUX_GLCORE_ONLY: "1"
470471
run: |
471472
set -uo pipefail
472473
mkdir -p artifacts
@@ -482,6 +483,7 @@ jobs:
482483
--env UNITY_EMAIL --env UNITY_PASSWORD --env UNITY_SERIAL \
483484
--env AUDIENCE_TEST_PUBLISHABLE_KEY --env AUDIENCE_SCRIPTING_BACKEND \
484485
--env AUDIENCE_TEST_RUN_ID --env AUDIENCE_TEST_CELL_ID \
486+
--env AUDIENCE_LINUX_GLCORE_ONLY \
485487
--volume "$PWD":/github/workspace:z \
486488
--cpus=8 --memory=30487m \
487489
"$image" \
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#nullable enable
2+
3+
using System;
4+
using UnityEditor;
5+
using UnityEditor.Build;
6+
using UnityEditor.Build.Reporting;
7+
using UnityEngine;
8+
using UnityEngine.Rendering;
9+
10+
namespace Immutable.Audience.Samples.SampleApp.Editor
11+
{
12+
// Build pre-process hook that restricts the StandaloneLinux64 player to
13+
// OpenGLCore when AUDIENCE_LINUX_GLCORE_ONLY is set.
14+
//
15+
// Why: the unityci/editor Linux container has no GPU. Unity falls back
16+
// to Mesa software OpenGL via llvmpipe. The runtime -force-glcore flag
17+
// picks OpenGL when the player launches, but the build still ships
18+
// every active graphics API's shader variants. With Vulkan also active
19+
// by default, the shader compiler emits both glcore and vulkan
20+
// variants. Roughly half of the 413 shader compiles measured on Unity
21+
// 6 Linux were wasted on Vulkan variants the player never used.
22+
//
23+
// The hook runs only when the env flag is set, only for the
24+
// StandaloneLinux64 build target, and only modifies in-memory
25+
// PlayerSettings during the build. Other Standalone targets (Win, Mac)
26+
// and other CI workflows are unaffected. Local builds without the env
27+
// var see no change.
28+
//
29+
// Usage:
30+
// AUDIENCE_LINUX_GLCORE_ONLY=1 Unity -batchmode -buildTarget StandaloneLinux64 -runTests ...
31+
internal sealed class GraphicsApisLinuxOverride : IPreprocessBuildWithReport
32+
{
33+
private const string EnvVar = "AUDIENCE_LINUX_GLCORE_ONLY";
34+
35+
public int callbackOrder => 1;
36+
37+
public void OnPreprocessBuild(BuildReport report)
38+
{
39+
if (report.summary.platform != BuildTarget.StandaloneLinux64) return;
40+
41+
var requested = Environment.GetEnvironmentVariable(EnvVar);
42+
if (string.IsNullOrEmpty(requested)) return;
43+
44+
var current = PlayerSettings.GetGraphicsAPIs(BuildTarget.StandaloneLinux64);
45+
if (current.Length == 1 && current[0] == GraphicsDeviceType.OpenGLCore)
46+
{
47+
Debug.Log($"[{nameof(GraphicsApisLinuxOverride)}] StandaloneLinux64 already at OpenGLCore only.");
48+
return;
49+
}
50+
51+
PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.StandaloneLinux64, false);
52+
PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneLinux64, new[] { GraphicsDeviceType.OpenGLCore });
53+
Debug.Log($"[{nameof(GraphicsApisLinuxOverride)}] StandaloneLinux64 graphics APIs forced to OpenGLCore. Vulkan shader variants will be skipped.");
54+
}
55+
}
56+
}

examples/audience/Assets/Editor/GraphicsApisLinuxOverride.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)