-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile_shaders.ps1
92 lines (83 loc) · 3.73 KB
/
compile_shaders.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
$srcfolder = "src\shaders"
$dstfolder = "shaders_spv"
$shaders = @(Get-ChildItem $srcfolder\* -Exclude *.glsl)
$libs = @(Get-ChildItem $srcfolder\*.glsl)
$libsdate = [datetime](Get-Date -Date "01/01/1970") # Unix epoch as minimum, please don't go too far back in time
# Get date of last modification of a "library file" (.glsl) to force recompilation of all shaders in this case (I don't want to manage a dependency tree :))
Foreach($lib in $libs)
{
$d = [datetime](Get-ItemProperty -Path $lib -Name LastWriteTime).lastwritetime
If($d -gt $libsdate) {
$libsdate = $d
}
}
function Show-Notification {
[cmdletbinding()]
Param (
[string]
$ToastTitle,
[string]
[parameter(ValueFromPipeline)]
$ToastText
)
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
$RawXml = [xml] $Template.GetXml()
($RawXml.toast.visual.binding.text|where {$_.id -eq "1"}).AppendChild($RawXml.CreateTextNode($ToastTitle)) > $null
($RawXml.toast.visual.binding.text|where {$_.id -eq "2"}).AppendChild($RawXml.CreateTextNode($ToastText)) > $null
$SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument
$SerializedXml.LoadXml($RawXml.OuterXml)
$Toast = [Windows.UI.Notifications.ToastNotification]::new($SerializedXml)
$Toast.Tag = "PowerShell"
$Toast.Group = "PowerShell"
$Toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1)
$Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PowerShell")
$Notifier.Show($Toast);
}
$errored = $false
Foreach($shader in $shaders)
{
$name = [System.IO.Path]::GetFileNameWithoutExtension($shader)
$filename = [System.IO.Path]::GetFileName($shader)
$exists = Test-Path -Path $dstfolder\$filename.spv -PathType Leaf
$d = [datetime](Get-ItemProperty -Path $shader -Name LastWriteTime).lastwritetime
If($exists) {
$d2 = [datetime](Get-ItemProperty -Path $dstfolder\$filename.spv -Name LastWriteTime).lastwritetime
}
$baseColor = $host.UI.RawUI.ForegroundColor
If(-not $exists -or $d -gt $d2 -or $libsdate -gt $d2)
{
$start = [datetime](Get-Date)
#Write-Host "[$time] " -ForegroundColor DarkGray -NoNewLine
#Write-Output "Compiling $filename to $dstfolder\$filename.spv"
$host.UI.RawUI.ForegroundColor = 'Red'
glslc.exe -O -g --target-env=vulkan1.3 -I$srcfolder $shader -o $dstfolder\$filename.spv
$dnew = [datetime](Get-ItemProperty -Path $dstfolder\$filename.spv -Name LastWriteTime).lastwritetime
$exists = Test-Path -Path $dstfolder\$filename.spv -PathType Leaf
$host.UI.RawUI.ForegroundColor = $baseColor
If(-not $exists -or $dnew -lt $start) {
$now = Get-Date -Format "HH:mm:ss"
Write-Host "[$now] " -ForegroundColor DarkGray -NoNewLine
Write-Host "Error: " -ForegroundColor Red -NoNewLine
Write-Host "Compilation of '" -NoNewLine
Write-Host "$filename'" -ForegroundColor Cyan -NoNewLine
Write-Host "' failed ('" -NoNewLine
Write-Host "$filename.spv" -ForegroundColor Cyan -NoNewLine
Write-Host "' was not created/updated)."
$errored = $true
} Else {
$now = Get-Date -Format "HH:mm:ss"
Write-Host "[$now] " -ForegroundColor DarkGray -NoNewLine
Write-Host "Success: '" -ForegroundColor Green -NoNewLine
Write-Host "$filename" -ForegroundColor Cyan -NoNewLine
Write-Host "' compiled to '" -NoNewLine
Write-Host "$filename.spv" -ForegroundColor Cyan -NoNewLine
Write-Host "'."
}
} Else {
#Write-Output "Skiping $filename ($d < $d2)"
}
}
If($errored) {
Show-Notification -ToastTitle "Shader Compilation Error" -ToastText "At least one shader compilation failed."
}