This repository has been archived on 2026-10-29. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
CultMath/tools/compile-hlsl-spirv.ps1
2026-06-10 21:30:49 +01:00

58 lines
1.3 KiB
PowerShell

param(
[Parameter(Mandatory = $true)]
[string]$ShaderPath,
[Parameter(Mandatory = $true)]
[string]$OutputPath,
[string]$EntryPoint = "main",
[string]$Profile = "cs_6_0",
[string[]]$IncludePath = @(),
[string]$TargetEnv = "",
[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 (Test-Path $DxcPath)) {
throw "DXC not found at '$DxcPath'. Run tools\get-dxc.ps1 first or pass -DxcPath."
}
$resolvedShader = Resolve-Path $ShaderPath
$resolvedIncludes = @((Join-Path $repoRoot "shaders"))
foreach ($path in $IncludePath) {
$resolvedIncludes += (Resolve-Path $path)
}
$outputDirectory = Split-Path -Parent $OutputPath
if ($outputDirectory) {
New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null
}
$arguments = @(
"-T", $Profile,
"-E", $EntryPoint,
"-spirv"
)
if ($TargetEnv) {
$arguments += "-fspv-target-env=$TargetEnv"
}
foreach ($include in $resolvedIncludes) {
$arguments += @("-I", $include)
}
$arguments += @($resolvedShader, "-Fo", $OutputPath)
& $DxcPath @arguments
if ($LASTEXITCODE -ne 0) {
throw "dxc.exe failed with exit code $LASTEXITCODE."
}
Get-Item -LiteralPath $OutputPath