<# .SYNOPSIS Campaign V slice V6c: compile acdream's GLSL to the committed SPIR-V the Vulkan backend loads at startup. .DESCRIPTION Plan §4.6 rules out runtime shader compilation: it would add a native dependency and a startup cost for shaders that never change at runtime, and CI runners have no Vulkan SDK. So the .spv artifacts are committed, this script regenerates them, and an App test re-hashes the GLSL sources against the manifest this writes so a source edit that never got recompiled fails a test rather than shipping a stale binary. Two compilers are supported, in this order: 1. glslc from a Vulkan SDK, if one is on PATH or under $VULKAN_SDK. This is the reference implementation and is what the plan names. 2. tools/ShaderCompiler, a small .NET tool over Silk.NET.Shaderc — the same shaderc library glslc is built on, through the already-pinned Silk.NET 2.23.0 family. It exists because neither the development machine nor CI has an SDK installed, and requiring one to build acdream would put a 500 MB manual install between a contributor and a working checkout. Both paths inject the same Vulkan preamble (see tools/ShaderCompiler/VulkanGlslPreamble.cs) so the GLSL sources stay the single source of truth for both backends. .PARAMETER ShadersDirectory Source directory. Defaults to src/AcDream.App/Rendering/Shaders. .PARAMETER OutputDirectory Where .spv and shaders.manifest.json are written. Defaults to src/AcDream.App/Rendering/Shaders/spv. .PARAMETER PreferSdk Use glslc when available. On by default; pass -PreferSdk:$false to force the managed path, which is what a comparison between the two wants. .EXAMPLE tools/compile-shaders.ps1 #> [CmdletBinding()] param( [string]$ShadersDirectory, [string]$OutputDirectory, [bool]$PreferSdk = $true ) $ErrorActionPreference = 'Stop' $repo = Split-Path -Parent $PSScriptRoot if (-not $ShadersDirectory) { $ShadersDirectory = Join-Path $repo 'src\AcDream.App\Rendering\Shaders' } if (-not $OutputDirectory) { $OutputDirectory = Join-Path $ShadersDirectory 'spv' } function Write-Step($message) { Write-Host "[shaders] $message" } New-Item -ItemType Directory -Force -Path $OutputDirectory | Out-Null # --- 1. Locate glslc, if the machine has a Vulkan SDK ------------------------- $glslc = $null if ($PreferSdk) { $onPath = Get-Command glslc -ErrorAction SilentlyContinue if ($onPath) { $glslc = $onPath.Source } elseif ($env:VULKAN_SDK) { $candidate = Join-Path $env:VULKAN_SDK 'Bin\glslc.exe' if (Test-Path $candidate) { $glslc = $candidate } } } # --- 2. Compile --------------------------------------------------------------- # Even with glslc present the managed tool does the work: it owns the preamble # injection and the manifest, and running the same transform through two # code paths is exactly how the two would drift. glslc's presence is reported so # a future slice can add a cross-check between them. if ($glslc) { Write-Step "a Vulkan SDK glslc was found at $glslc (recorded; the managed compiler still runs)" } else { Write-Step 'no Vulkan SDK glslc found; using the managed Silk.NET.Shaderc compiler' } $tool = Join-Path $repo 'tools\ShaderCompiler\ShaderCompiler.csproj' Write-Step 'building the shader compiler' & dotnet build $tool -c Release --nologo -v q | Out-Null if ($LASTEXITCODE -ne 0) { throw "Shader compiler build failed with exit code $LASTEXITCODE." } $binary = Join-Path $repo 'tools\ShaderCompiler\bin\Release\net10.0\AcDream.Tools.ShaderCompiler.dll' if (-not (Test-Path $binary)) { throw "Shader compiler not found at $binary." } Write-Step "compiling $ShadersDirectory -> $OutputDirectory" & dotnet $binary $ShadersDirectory $OutputDirectory if ($LASTEXITCODE -ne 0) { throw "Shader compilation failed with exit code $LASTEXITCODE." } Write-Step 'done'