CultLib/packages/cultmath/tools/compile-hlsl.ps1
Meta Vens 4250dd28d5 cultmath: compile-hlsl.ps1 fails on warnings and on a missing shader without its path; compile-glsl.ps1 passes struct arguments
dxc runs with -WX; a ShaderPath that is not a file throws naming the parameter and entry index,
never the path; the GLSL wrapper builds a struct parameter from its declaration's field zeros.
design.md and README state the struct-argument twin rule, the span twins and the missing shader identity.
No C# change; the compiles run on Starfire after the last commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 03:02:13 +02:00

42 lines
1.8 KiB
PowerShell

param(
# The HLSL files to compile, each as a lib_6_3 library with its own directory as the include path.
# Default: both copies of CultMath.hlsl (the canonical one and the Unity package's byte copy).
# tools\compile-hlsl.ps1 -ShaderPath <a file holding 'float f( { return 0; }'> is the negative control.
[string[]]$ShaderPath = @(),
# The dxc to run. Default: the x64 install get-dxc.ps1 makes; it is never searched for, so a dxc
# that cannot launch (one built for another architecture) is an error, not a skipped check.
[string]$DxcPath = ""
)
$ErrorActionPreference = "Stop"
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
if (-not $DxcPath) {
$DxcPath = Join-Path $repoRoot ".tools\dxc\current\bin\x64\dxc.exe"
}
if (-not $ShaderPath) {
$ShaderPath = @(
(Join-Path $repoRoot "shaders\CultMath.hlsl"),
(Join-Path $repoRoot "unity\org.gamecult.cultmath\Shaders\CultMath.hlsl"))
}
if (-not (Test-Path -LiteralPath $DxcPath)) {
throw "dxc not found (parameter DxcPath). Run tools\get-dxc.ps1 first or pass -DxcPath."
}
$outputDirectory = Join-Path $repoRoot ".tools\hlsl"
New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null
$index = 0
foreach ($shader in $ShaderPath) {
$index++
if (-not (Test-Path -LiteralPath $shader -PathType Leaf)) {
throw "shader not found (parameter ShaderPath, entry $index)."
}
$shaderFile = Get-Item -LiteralPath $shader
$output = Join-Path $outputDirectory "$index-$($shaderFile.BaseName).dxil"
& $DxcPath -T lib_6_3 -HV 2021 -WX -I $shaderFile.DirectoryName $shaderFile.FullName -Fo $output
if ($LASTEXITCODE -ne 0) {
throw "dxc failed with exit code $LASTEXITCODE (parameter ShaderPath, entry $index)."
}
Write-Host "compiled shader $index of $(@($ShaderPath).Count) (lib_6_3, -HV 2021, -WX)"
}