Repository navigation
Expand file tree
/
Copy pathbuild.ps1
More file actions
1733 lines (1585 loc) · 73.7 KB
/
Copy pathbuild.ps1
File metadata and controls
1733 lines (1585 loc) · 73.7 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Requires -Version 5.1
[CmdletBinding()]
param (
[switch]$ForceRebuild,
[switch]$EnableTQ,
[switch]$EnableAvm,
[switch]$EnableVvenc,
[switch]$EnableX265,
[switch]$EnableX264,
[string]$Backend = "cuda",
[int]$SvtVariantId = 1,
[int]$ArchChoiceId = 1,
[switch]$NoPrompt
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$COMMON_FLAGS = "-flto -O3 -DNDEBUG -march=native"
$CudaReleases = @{
'12.9' = @{
Version = '12.9.1'
Url = 'https://developer.download.nvidia.com/compute/cuda/12.9.1/network_installers/cuda_12.9.1_windows_network.exe'
Sha256 = 'DE45C336AB4E9825018B546357DC9DE5DED9F89C4F5200EF52B8EEAC3B1B4072'
Components = @('nvcc_12.9', 'cudart_12.9')
}
'13.3' = @{
Version = '13.3.1'
Url = 'https://developer.download.nvidia.com/compute/cuda/13.3.1/network_installers/cuda_13.3.1_windows_network.exe'
Sha256 = '0A4964DB02D01A80F897605B0CB2C18FDDAF277C44940A0F3436301A577B3C57'
Components = @('nvcc_13.3', 'cudart_13.3', 'crt_13.3', 'nvvm_13.3')
}
}
function Install-CudaMinimal {
param([string]$Version, [string]$Url, [string]$Sha256, [string[]]$Components)
$mm = ($Version -split '\.')[0..1] -join '.'
$installer = "$env:TEMP\cuda_${Version}_network.exe"
$logPath = "$env:TEMP\cuda_${Version}_install.log"
Write-Host "[INFO] Downloading CUDA Toolkit $Version network installer (minimal stub, ~16 MB)..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $Url -OutFile $installer -UseBasicParsing
Write-Host "[INFO] Verifying installer checksum..." -ForegroundColor Cyan
$actual = (Get-FileHash $installer -Algorithm SHA256).Hash
if ($actual -ne $Sha256) {
Write-Host "[ERROR] CUDA installer checksum mismatch. Expected $Sha256, got $actual." -ForegroundColor Red
exit 1
}
Write-Host "[INFO] Installing CUDA $Version ($($Components -join ', '), no driver)..." -ForegroundColor Cyan
$proc = Start-Process -FilePath $installer -ArgumentList "-s $($Components -join ' ') -n -log:`"$logPath`"" -Wait -PassThru
if ($proc.ExitCode -ne 0) {
Write-Host "[ERROR] CUDA $Version installer failed (exit code $($proc.ExitCode)). Log: $logPath" -ForegroundColor Red
exit 1
}
Update-SessionEnvironment
if (-not $env:CUDA_PATH) {
$default = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v$mm"
if (Test-Path "$default\bin\nvcc.exe") { $env:CUDA_PATH = $default }
}
Write-Host "[INFO] CUDA Toolkit $Version (minimal) installed successfully." -ForegroundColor Green
Remove-Item -Path $installer -Force -ErrorAction SilentlyContinue
}
function Invoke-Step {
param([string]$Label, [scriptblock]$Action)
Write-Host "[INFO] $Label..." -ForegroundColor Cyan
& $Action
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host "[ERROR] $Label failed (exit code $LASTEXITCODE)." -ForegroundColor Red
exit 1
}
}
# Refresh PATH and SDK env vars from registry so newly installed tools are usable immediately.
function Update-SessionEnvironment {
$machinePath = [System.Environment]::GetEnvironmentVariable('PATH', 'Machine')
$userPath = [System.Environment]::GetEnvironmentVariable('PATH', 'User')
$newPath = "$machinePath;$userPath"
$commonPaths = @(
"$env:ProgramFiles\LLVM\bin",
"$env:ProgramFiles\NASM",
"$env:LOCALAPPDATA\bin\NASM",
"$env:ProgramFiles\Meson",
"$env:USERPROFILE\.cargo\bin"
)
foreach ($p in $commonPaths) {
if ((Test-Path $p) -and ($newPath -notlike "*$p*")) {
$newPath = "$p;$newPath"
}
}
$env:PATH = $newPath
foreach ($var in @('CUDA_PATH', 'HIP_PATH')) {
$val = [System.Environment]::GetEnvironmentVariable($var, 'Machine')
if (-not $val) { $val = [System.Environment]::GetEnvironmentVariable($var, 'User') }
if ($val) { Set-Item "env:$var" $val }
}
}
function Assert-Command {
param([string]$Cmd)
return [bool](Get-Command $Cmd -ErrorAction SilentlyContinue)
}
function Test-CpuFlag {
param([string]$MsysExe, [string]$Flag)
try {
& $MsysExe -lc "grep '^flags' /proc/cpuinfo | grep -q -w '$Flag'" 2>$null
return ($LASTEXITCODE -eq 0)
}
catch {
return $false
}
}
function Confirm-Install {
param([string]$AppName, [string]$WingetId)
Write-Host ""
Write-Host "[PROMPT] $AppName is missing." -ForegroundColor Yellow
$choice = Read-Host "Do you want to install it using winget? (Y/N) [Default: Y]"
if ($choice -ieq 'N') {
Write-Host "[ERROR] $AppName is required. Exiting." -ForegroundColor Red
exit 1
}
Write-Host "[INFO] Installing $AppName..." -ForegroundColor Cyan
winget install -e --id $WingetId --accept-source-agreements --accept-package-agreements | Out-Host
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Failed to install $AppName." -ForegroundColor Red
exit 1
}
Update-SessionEnvironment
Write-Host "[INFO] $AppName installed successfully." -ForegroundColor Green
}
function Find-Msys2Root {
# Well-known default path
$candidates = @('C:\msys64')
# Scoop (per-user and global)
$candidates += "$env:USERPROFILE\scoop\apps\msys2\current"
$candidates += "$env:ProgramData\scoop\apps\msys2\current"
$found = $candidates | Where-Object { Test-Path "$_\usr\bin\bash.exe" } | Select-Object -First 1
if ($found) { return $found }
# Registry uninstall entries (covers custom install paths)
$regRoots = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall',
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
)
foreach ($root in $regRoots) {
if (-not (Test-Path $root)) { continue }
$entry = Get-ChildItem $root -ErrorAction SilentlyContinue |
Get-ItemProperty -ErrorAction SilentlyContinue |
Where-Object { $_.PSObject.Properties['DisplayName'] -and $_.DisplayName -match 'MSYS2' } |
Select-Object -First 1
if ($entry -and $entry.InstallLocation -and (Test-Path "$($entry.InstallLocation)\usr\bin\bash.exe")) {
return $entry.InstallLocation
}
}
return $null
}
function Install-Msys2 {
$msysRoot = Find-Msys2Root
if (-not $msysRoot) {
Confirm-Install "MSYS2" "MSYS2.MSYS2"
$msysRoot = Find-Msys2Root
if (-not $msysRoot) {
Write-Host "[ERROR] MSYS2 not found after install. Please re-run the script or set the path manually." -ForegroundColor Red
exit 1
}
}
Write-Host "[INFO] Found MSYS2 at $msysRoot" -ForegroundColor Cyan
$msysExe = "$msysRoot\usr\bin\bash.exe"
Invoke-Step "Installing MSYS2 base dependencies" {
& $msysExe -lc "pacman --noconfirm -S --needed autoconf automake libtool base-devel pkg-config" | Out-Host
}
return $msysExe
}
function Install-VsBuildTools {
param([bool]$VsIncludeV143)
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$hasCppTools = (Test-Path $vswhere) -and
(& $vswhere -latest -products * -requires 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64' -property installationPath 2>$null)
if (-not $hasCppTools) {
Write-Host ""
Write-Host "[PROMPT] Visual Studio Build Tools with C++ workload is missing." -ForegroundColor Yellow
$choice = Read-Host "Do you want to install it? (Y/N) [Default: Y]"
if ($choice -ieq 'N') {
Write-Host "[ERROR] Visual Studio Build Tools are required. Exiting." -ForegroundColor Red
exit 1
}
Write-Host "[INFO] Installing Visual Studio Build Tools with Desktop C++ workload (this may take a while)..." -ForegroundColor Cyan
$vsWorkloadComponents = "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.26100"
if ($VsIncludeV143) {
$vsWorkloadComponents += " --add Microsoft.VisualStudio.ComponentGroup.VC.Tools.143.x86.x64"
}
$vsWingetArgs = "--quiet --wait --norestart $vsWorkloadComponents"
$vsModifyArgs = "--quiet --norestart $vsWorkloadComponents"
winget install -e --id 'Microsoft.VisualStudio.BuildTools' --source winget `
--accept-source-agreements --accept-package-agreements `
--override $vsWingetArgs | Out-Host
if ($LASTEXITCODE -ne 0) {
$existingInstallPath = & $vswhere -latest -products * -property installationPath 2>$null
if (-not $existingInstallPath) {
Write-Host "[ERROR] winget failed to install Visual Studio Build Tools (exit code $LASTEXITCODE) and no existing installation was found." -ForegroundColor Red
exit 1
}
Write-Host "[INFO] VS Build Tools already installed, but there is no C++ workload." -ForegroundColor Cyan
Write-Host "[INFO] Installing C++ workload..." -ForegroundColor Cyan
$vsInstallerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vs_installer.exe"
if (-not (Test-Path $vsInstallerPath)) {
Write-Host "[ERROR] Could not find vs_installer.exe. Please open Visual Studio Installer manually and add the 'Desktop development with C++' workload." -ForegroundColor Red
exit 1
}
Start-Process -FilePath $vsInstallerPath `
-ArgumentList "modify --installPath `"$existingInstallPath`" $vsModifyArgs" `
-Verb RunAs -Wait
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Failed to modify Visual Studio Build Tools. Please open Visual Studio Installer manually and add the 'Desktop development with C++' workload." -ForegroundColor Red
exit 1
}
}
Update-SessionEnvironment
Write-Host "[INFO] Visual Studio Build Tools with C++ workload installed successfully." -ForegroundColor Green
}
$vsPathResult = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if (-not $vsPathResult) {
Write-Host "[ERROR] Visual Studio with C++ tools not found." -ForegroundColor Red
exit 1
}
return $vsPathResult
}
function Import-Vcvars {
param([string]$VsPath, [bool]$VsIncludeV143)
$devShell = Join-Path $VsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
if (-not (Test-Path $devShell)) {
Write-Host "[ERROR] VsDevShell not found at $devShell" -ForegroundColor Red
exit 1
}
$devArgs = '-arch=x64'
if ($VsIncludeV143) { $devArgs += ' -vcvars_ver=14.4' }
Import-Module $devShell
Enter-VsDevShell -VsInstallPath $VsPath -SkipAutomaticLocation -DevCmdArguments $devArgs
}
function Install-GpuSdk {
param([string]$VshipBackend, [bool]$VsIncludeV143)
if ($VshipBackend -eq 'cuda' -and -not $env:CUDA_PATH) {
$mm = if ($VsIncludeV143) { '12.9' } else { '13.3' }
$rel = $CudaReleases[$mm]
Write-Host ""
Write-Host "[PROMPT] NVIDIA CUDA Toolkit $mm is missing." -ForegroundColor Yellow
$choice = Read-Host "Do you want to install it (minimal: $($rel.Components -join ', '))? (Y/N) [Default: Y]"
if ($choice -ieq 'N') { Write-Host "[ERROR] CUDA Toolkit is required. Exiting." -ForegroundColor Red; exit 1 }
Install-CudaMinimal -Version $rel.Version -Url $rel.Url -Sha256 $rel.Sha256 -Components $rel.Components
if (-not $env:CUDA_PATH) {
Write-Host "[ERROR] CUDA_PATH still not set after install. Try restarting your terminal, or set CUDA_PATH manually." -ForegroundColor Red
exit 1
}
}
if ($VshipBackend -eq 'hip' -and -not $env:HIP_PATH) {
Write-Host ""
Write-Host "[PROMPT] AMD HIP SDK is missing." -ForegroundColor Yellow
$choice = Read-Host "Do you want to install it? (Y/N) [Default: Y]"
if ($choice -ieq 'N') { Write-Host "[ERROR] AMD HIP SDK is required. Exiting." -ForegroundColor Red; exit 1 }
Write-Host "[INFO] Downloading AMD HIP SDK..." -ForegroundColor Cyan
$hipInstaller = "$env:TEMP\AMD-HIP-Setup.exe"
Invoke-WebRequest -Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-26.Q1-Win11-For-HIP.exe" -OutFile $hipInstaller -UseBasicParsing
Write-Host "[INFO] Installing AMD HIP SDK (this may take a while)..." -ForegroundColor Cyan
Start-Process -FilePath $hipInstaller -ArgumentList '-install' -Wait
Update-SessionEnvironment
if (-not $env:HIP_PATH) {
Write-Host "[ERROR] HIP_PATH still not set after install. Try restarting your terminal, or set HIP_PATH manually." -ForegroundColor Red
exit 1
}
Remove-Item -Path $hipInstaller -Force -ErrorAction SilentlyContinue
}
}
function Install-Dependencies {
param([string]$VshipBackend, [bool]$VsIncludeV143)
$basicTools = [ordered]@{
'git' = 'Git.Git'
'cmake' = 'Kitware.CMake'
'ninja' = 'Ninja-build.Ninja'
'cargo' = 'Rustlang.Rustup'
}
foreach ($cmd in $basicTools.Keys) {
if (-not (Assert-Command $cmd)) {
Confirm-Install $cmd $basicTools[$cmd]
}
}
$llvmBin = "$env:ProgramFiles\LLVM\bin"
if (-not (Assert-Command 'clang++')) {
if (-not (Test-Path "$llvmBin\clang++.exe")) { Confirm-Install "LLVM" "LLVM.LLVM" }
}
$nasmPaths = @("$env:ProgramFiles\NASM", "$env:LOCALAPPDATA\bin\NASM")
if (-not (Assert-Command 'nasm')) {
$nasmFound = $nasmPaths | Where-Object { Test-Path "$_\nasm.exe" } | Select-Object -First 1
if (-not $nasmFound) { Confirm-Install "NASM" "NASM.NASM" }
}
Update-SessionEnvironment
if (-not (Assert-Command 'clang')) { Write-Host "[ERROR] clang not found after LLVM setup." -ForegroundColor Red; exit 1 }
if (-not (Assert-Command 'clang++')) { Write-Host "[ERROR] clang++ not found after LLVM setup." -ForegroundColor Red; exit 1 }
if (-not (Assert-Command 'llvm-ar')) { Write-Host "[ERROR] llvm-ar not found after LLVM setup." -ForegroundColor Red; exit 1 }
if (-not (Assert-Command 'llvm-lib')) { Write-Host "[ERROR] llvm-lib not found after LLVM setup." -ForegroundColor Red; exit 1 }
if (-not (Assert-Command 'llvm-nm')) { Write-Host "[ERROR] llvm-nm not found after LLVM setup." -ForegroundColor Red; exit 1 }
if (-not (Assert-Command 'llvm-ranlib')) { Write-Host "[ERROR] llvm-ranlib not found after LLVM setup." -ForegroundColor Red; exit 1 }
if (-not (Assert-Command 'llvm-strip')) { Write-Host "[ERROR] llvm-strip not found after LLVM setup." -ForegroundColor Red; exit 1 }
if (-not (Assert-Command 'lld-link')) { Write-Host "[ERROR] lld-link not found after LLVM setup." -ForegroundColor Red; exit 1 }
if (-not (Assert-Command 'nasm')) { Write-Host "[ERROR] nasm not found after NASM setup." -ForegroundColor Red; exit 1 }
Write-Host "[INFO] Setting Rust toolchain to nightly..." -ForegroundColor Cyan
rustup default nightly | Out-Host
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Failed to set Rust toolchain to nightly." -ForegroundColor Red; exit 1
}
Write-Host "[INFO] Ensuring rust-src component (required for build-std)..." -ForegroundColor Cyan
rustup component add rust-src --toolchain nightly | Out-Host
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Failed to add rust-src component." -ForegroundColor Red; exit 1
}
Install-GpuSdk -VshipBackend $VshipBackend -VsIncludeV143 $VsIncludeV143
$msysExe = Install-Msys2
$vsPathResult = Install-VsBuildTools -VsIncludeV143 $VsIncludeV143
return @{
MsysExe = $msysExe
VsPath = $vsPathResult
}
}
function Build-Vship {
param([string]$Backend, [bool]$VsIncludeV143, [string]$VsPath)
if (Test-Path 'lib\libvship.lib') {
Write-Host "[INFO] Vship already compiled. Skipping..." -ForegroundColor Cyan
}
else {
if (Test-Path 'Vship') {
Push-Location Vship
git pull
Pop-Location
}
else {
git clone --depth 1 https://codeberg.org/Line-fr/Vship.git
}
Push-Location Vship
switch ($Backend) {
'cuda' {
$msvcBin = Split-Path (Get-Command cl.exe -ErrorAction SilentlyContinue).Definition
if (-not $msvcBin) {
Write-Host "[WARNING] cl.exe not found in PATH. nvcc may fail." -ForegroundColor Yellow
$ccbinArg = @()
}
else {
Write-Host "[INFO] Using MSVC host compiler for nvcc: $msvcBin" -ForegroundColor Cyan
$ccbinArg = @('-ccbin', $msvcBin)
}
Invoke-Step "Compiling Vship (CUDA)" {
& "$env:CUDA_PATH\bin\nvcc.exe" @ccbinArg -x cu src/VshipLib.cpp -std=c++17 -I include -arch=native -Xcompiler /MT --lib -o libvship.lib
}
}
'hip' {
Invoke-Step "Compiling Vship (HIP)" {
& "$env:HIP_PATH\bin\hipcc" -c src/VshipLib.cpp -std=c++17 -I include `
--offload-arch=native `
-Wno-unused-result -Wno-ignored-attributes -o libvship.o
}
if (Test-Path 'libvship.lib') { Remove-Item 'libvship.lib' }
Invoke-Step "Archiving Vship (HIP)" { llvm-ar rcs libvship.lib libvship.o }
}
'vulkan' {
Invoke-Step "Compiling shaderEmbedder" {
clang++ src/Vulkan/spvFileToCppHeader.cpp -std=c++17 -O2 -o shaderEmbedder.exe
}
Invoke-Step "Embedding shaders" {
.\shaderEmbedder.exe libvshipSpvShaders include/libvshipSpvShaders.hpp
}
Invoke-Step "Compiling Vship (Vulkan)" {
clang++ -c src/VshipLib.cpp -DVULKANBUILD -DNDEBUG -std=c++17 -O2 -Wall `
-Wno-ignored-attributes -Wno-unused-variable -Wno-nullability-completeness `
-Wno-unused-private-field -I include -I ..\install\include -o libvship.o
}
if (Test-Path 'libvship.lib') { Remove-Item 'libvship.lib' }
Invoke-Step "Archiving Vship (Vulkan)" { llvm-ar rcs libvship.lib libvship.o }
}
}
Copy-Item libvship.lib ..\lib\ -Force
Pop-Location
}
}
function Patch-SvtAv1 {
param([string]$Variant, [string]$MsysExe)
# should be fixed in mainline/tritium
$apply8MbStackPatch = $Variant -notin @('svt-av1-tritium', 'svt-av1-skibidi', 'mainline')
$applySharedRtcdPatch = $Variant -ne '5fish'
$patchScript = @'
#!/bin/sh
set -e
sed -i 's/\r//g' CMakeLists.txt Source/Lib/Globals/enc_handle.c Source/Lib/Codec/aom_dsp_rtcd.c Source/Lib/Codec/common_dsp_rtcd.c Source/Lib/Codec/enc_inter_prediction.c
sed -i 's/set(CMAKE_POSITION_INDEPENDENT_CODE ON)/set(CMAKE_POSITION_INDEPENDENT_CODE OFF)/' CMakeLists.txt
sed -i 's/set(CMAKE_C_STANDARD 99)/set(CMAKE_C_STANDARD 23)/' CMakeLists.txt
sed -i 's/set(CMAKE_CXX_STANDARD 11)/set(CMAKE_CXX_STANDARD 23)/' CMakeLists.txt
sed -i '/relro/s/^/#/' CMakeLists.txt
sed -i '/mno-avx/s/^/#/' CMakeLists.txt
sed -i '/fstack-protector-strong/s/^/#/' CMakeLists.txt
sed -i '/FORTIFY_SOURCE/s/^/#/' CMakeLists.txt
sed -i '/gdwarf/s/^/#/' CMakeLists.txt
sed -i '/gnull/s/^/#/' CMakeLists.txt
sed -i 's|^ return_error = svt_av1_set_default_params(config_ptr);$| return_error = config_ptr ? svt_av1_set_default_params(config_ptr) : EB_ErrorNone;|' Source/Lib/Globals/enc_handle.c
sed -i 's|^ if (svt_aom_copy_metadata_buffer(dst, src->metadata) != EB_ErrorNone)$| if (1)|' Source/Lib/Globals/enc_handle.c
sed -i 's/void NOINLINE svt_aom_enc_make_inter_predictor(/void svt_aom_enc_make_inter_predictor(/' Source/Lib/Codec/enc_inter_prediction.c
'@
if ($applySharedRtcdPatch) {
$patchScript += @'
sed -i '/^ svt_aom_setup_common_rtcd_internal(scs->static_config.use_cpu_flags);$/,/^ svt_aom_build_blk_geom(scs->svt_aom_geom_idx, scs->blk_geom_mds);$/c\
return_error = svt_shared_setup(scs);\
if (return_error != EB_ErrorNone)\
return return_error;' Source/Lib/Globals/enc_handle.c
grep -q init_shared_rtcd Source/Lib/Globals/enc_handle.c || sed -i '/^DEFINE_ONCE(global_tables_once);$/a\
\
static uint64_t shared_cpu_flags;\
static uint32_t shared_geom_idx;\
static uint16_t shared_geom_cnt;\
static struct BlockGeom *shared_blk_geom;\
static uint32_t shared_blk_geom_idx;\
\
static ONCE_ROUTINE(init_shared_rtcd) {\
svt_aom_setup_common_rtcd_internal(shared_cpu_flags);\
svt_aom_setup_rtcd_internal(shared_cpu_flags);\
ONCE_ROUTINE_EPILOG;\
}\
DEFINE_ONCE(shared_rtcd_once);\
\
static ONCE_ROUTINE(init_shared_blk_geom) {\
shared_blk_geom_idx = shared_geom_idx;\
EB_MALLOC_ARRAY_NO_CHECK(shared_blk_geom, shared_geom_cnt);\
if (shared_blk_geom)\
svt_aom_build_blk_geom(shared_blk_geom_idx, shared_blk_geom);\
ONCE_ROUTINE_EPILOG;\
}\
DEFINE_ONCE(shared_blk_geom_once);\
\
static EbErrorType svt_shared_setup(SequenceControlSet *scs) {\
shared_cpu_flags = scs->static_config.use_cpu_flags;\
svt_run_once(\&shared_rtcd_once, init_shared_rtcd);\
svt_run_once(\&global_tables_once, init_global_tables);\
shared_geom_idx = scs->svt_aom_geom_idx;\
shared_geom_cnt = scs->max_block_cnt;\
svt_run_once(\&shared_blk_geom_once, init_shared_blk_geom);\
if (shared_blk_geom \&\& shared_blk_geom_idx == scs->svt_aom_geom_idx) {\
scs->blk_geom_mds = shared_blk_geom;\
return EB_ErrorNone;\
}\
EB_MALLOC_ARRAY(scs->blk_geom_mds, scs->max_block_cnt);\
svt_aom_build_blk_geom(scs->svt_aom_geom_idx, scs->blk_geom_mds);\
return EB_ErrorNone;\
}' Source/Lib/Globals/enc_handle.c
sed -i 's|handle->scs_instance->scs->blk_geom_mds != NULL) {|handle->scs_instance->scs->blk_geom_mds != NULL \&\& handle->scs_instance->scs->blk_geom_mds != shared_blk_geom) {|' Source/Lib/Globals/enc_handle.c
sed -i 's|^ SET_FUNCTIONS_X86(ptr, neon, neon_dotprod, neon_i8mm, sve, sve2) *\\$| SET_FUNCTIONS_X86(ptr, mmx, sse, sse2, sse3, ssse3, sse4_1, sse4_2, avx, avx2, avx512) \\|' Source/Lib/Codec/aom_dsp_rtcd.c Source/Lib/Codec/common_dsp_rtcd.c
sed -i 's|^ if (scs->static_config.encoder_bit_depth == EB_EIGHT_BIT) {$| if (0) {|' Source/Lib/Globals/enc_handle.c
sed -i 's|^ if (validate_on_the_fly_settings(p_buffer,scs, enc_handle_ptr->scs_instance->config_mutex)) {$| if (0) {|' Source/Lib/Globals/enc_handle.c
sed -i 's|^ EbErrorType return_error = svt_av1_verify_settings(scs);$| EbErrorType return_error = EB_ErrorNone;|' Source/Lib/Globals/enc_handle.c
'@
}
else {
$patchScript += @'
grep -q svt5fish_cpuinfo Source/Lib/Globals/enc_handle.c || {
find third_party/cpuinfo -type f \( -name '*.c' -o -name '*.h' \) -exec sed -i 's/cpuinfo_/svt5fish_cpuinfo_/g' {} +
sed -i 's/cpuinfo_/svt5fish_cpuinfo_/g' Source/Lib/Codec/common_dsp_rtcd.c Source/Lib/Globals/enc_handle.c
}
sed -i 's|^ if(validate_on_the_fly_settings(| if(0 \&\& validate_on_the_fly_settings(|' Source/Lib/Globals/enc_handle.c
sed -i '/^ EbErrorType return_error = svt_av1_verify_settings($/,+1c\
EbErrorType return_error = EB_ErrorNone;' Source/Lib/Globals/enc_handle.c
'@
}
if ($apply8MbStackPatch) {
$patchScript += @'
sed -i 's/\r//g' Source/Lib/Codec/svt_threads.c
sed -i 's/1 MiB/8 MiB/g' Source/Lib/Codec/svt_threads.c
sed -i 's|0, // default stack size|8 * 1024 * 1024, // default stack size|' Source/Lib/Codec/svt_threads.c
sed -i 's|0, // thread active when created|STACK_SIZE_PARAM_IS_A_RESERVATION, // thread active when created|' Source/Lib/Codec/svt_threads.c
sed -i 's|const size_t min_stack_size = 1024 \* 1024;|const size_t min_stack_size = 8 * 1024 * 1024;|' Source/Lib/Codec/svt_threads.c
'@
}
if (Test-CpuFlag -MsysExe $MsysExe -Flag 'avx2') {
$patchScript += @'
if [ -f Source/API/EbConfigMacros.h ]; then
sed -i 's/\r//g' Source/API/EbConfigMacros.h
sed -i '/^#ifndef CONFIG_X86_AVX2_IS_GUARANTEED$/,/^#endif$/s/ 0$/ 1/' Source/API/EbConfigMacros.h
fi
'@
}
Set-Content -Path 'patch_svt.sh' -Value ($patchScript.Replace("`r`n", "`n") + "`n") -Encoding Ascii -NoNewline
$unixPath = $PWD.Path -replace '\\', '/'
Invoke-Step "Patching SVT-AV1 (sed)" {
& $MsysExe -lc "cd `"$unixPath`" && sh ./patch_svt.sh"
}
Remove-Item 'patch_svt.sh' -Force -ErrorAction SilentlyContinue
}
function Build-SvtAv1 {
param([string]$Variant, [string]$Dir, [string]$Branch, [string]$Repo, [string]$ExtraCFlags, [string]$ArchFlags, [bool]$NoPrompt, [string]$MsysExe)
if (Test-Path 'lib\SvtAv1Enc.lib') {
if ($NoPrompt) {
$choice = if ($ForceRebuild) { 'Y' } else { 'N' }
}
else {
Write-Host ""
Write-Host "[PROMPT] $Variant is already compiled." -ForegroundColor Yellow
$choice = Read-Host "Do you want to update and recompile ${Variant}? (Y/N) [Default: N]"
}
if ($choice -notmatch '^[Yy]') {
Write-Host "[INFO] Skipping $Variant compilation..." -ForegroundColor Cyan
return
}
}
$avx512Supported = Test-CpuFlag -MsysExe $MsysExe -Flag 'avx512f'
$svtAvx512Flag = if ($avx512Supported) { 'ON' } else { 'OFF' }
Write-Host "[INFO] Detected AVX512 support: $avx512Supported. SVT-AV1 will be built with -DENABLE_AVX512=$svtAvx512Flag." -ForegroundColor Cyan
if (Test-Path $Dir) { Remove-Item -Recurse -Force $Dir }
if ($Branch) {
# depth 300 to get the git tag
git clone --depth 300 --branch $Branch $Repo $Dir
}
else {
git clone --depth 300 $Repo $Dir
}
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Failed to clone $Repo into $Dir." -ForegroundColor Red
exit 1
}
Push-Location $Dir
Patch-SvtAv1 -Variant $Variant -MsysExe $MsysExe
$pgoDir = "$PWD/svt_pgo_data"
if (Test-Path $pgoDir) { Remove-Item -Recurse -Force $pgoDir }
New-Item -ItemType Directory $pgoDir | Out-Null
if (Test-Path svt_build_gen) { Remove-Item -Recurse -Force svt_build_gen }
Invoke-Step "Configuring $Variant (PGO Gen)" {
cmake -B svt_build_gen -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF `
-DSVT_AV1_LTO=OFF -DLIBDOVI_FOUND=0 -DLIBHDR10PLUS_RS_FOUND=0 -DENABLE_AVX512=$svtAvx512Flag `
-DCMAKE_CXX_FLAGS_RELEASE="-flto -DNDEBUG -O2 $ArchFlags $ExtraCFlags -fprofile-generate=$pgoDir" `
-DCMAKE_C_FLAGS_RELEASE="-flto -DNDEBUG -O2 $ArchFlags $ExtraCFlags -fprofile-generate=$pgoDir" `
-DLOG_QUIET=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_OUTPUT_DIRECTORY=svt_build_gen
}
Invoke-Step "Building $Variant (PGO Gen)" { ninja -C svt_build_gen }
$clipFile = @("y4m", "mkv", "mp4", "webm") |
ForEach-Object { "..\pgo_clip.$_" } |
Where-Object { Test-Path $_ } |
Select-Object -First 1
if ($clipFile) {
Write-Host "[INFO] $clipFile found. Using it for PGO." -ForegroundColor Cyan
}
else {
$clipUrl = "https://media.xiph.org/video/derf/webm/Netflix_FoodMarket2_4096x2160_60fps_10bit_420.webm"
$clipHash = "F625E9460AA7964855D00C4CAD535D910EC4EEC7594B4CCEB5611CB00CC5F75B"
$clipFile = "Netflix_FoodMarket2_4096x2160_60fps_10bit_420.webm"
if (-not (Test-Path "..\$clipFile")) {
Write-Host "[INFO] Downloading PGO clip..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $clipUrl -OutFile "..\$clipFile" -UseBasicParsing
}
$actualHash = (Get-FileHash "..\$clipFile" -Algorithm SHA256).Hash
if ($actualHash -ne $clipHash) {
Write-Host "[ERROR] PGO clip hash mismatch. Expected $clipHash, got $actualHash." -ForegroundColor Red
exit 1
}
if (-not (Test-Path "..\Netflix_FoodMarket2_1920x1080_60fps_10bit_420_96f.y4m")) {
& "..\FFmpeg\ffmpeg.exe" -hide_banner -v error -stats -y -nostdin -i "..\$clipFile" -frames:v 96 -vf "scale=1920:1080:flags=lanczos+accurate_rnd+full_chroma_int:param0=4" -pix_fmt yuv420p10le -strict -1 -f yuv4mpegpipe "..\Netflix_FoodMarket2_1920x1080_60fps_10bit_420_96f.y4m"
}
$clipFile = "..\Netflix_FoodMarket2_1920x1080_60fps_10bit_420_96f.y4m"
}
Invoke-Step "PGO Run for $Variant" {
if ($clipFile -notlike '*.y4m') {
& "..\FFmpeg\ffmpeg.exe" -i "$clipFile" -f yuv4mpegpipe -pix_fmt yuv420p10le -strict -1 - | & ".\svt_build_gen\SvtAv1EncApp.exe" -i - -b NUL --preset 3 | Out-Host
}
else {
& ".\svt_build_gen\SvtAv1EncApp.exe" -i "$clipFile" -b NUL --preset 3 | Out-Host
}
}
$profdata = "$pgoDir/default.profdata"
Invoke-Step "Merging PGO data" {
& "llvm-profdata" merge --sparse=true -o $profdata $pgoDir | Out-Host
}
if (Test-Path svt_build_use) { Remove-Item -Recurse -Force svt_build_use }
Invoke-Step "Configuring $Variant (PGO Use)" {
cmake -B svt_build_use -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF `
-DSVT_AV1_LTO=OFF -DLIBDOVI_FOUND=0 -DLIBHDR10PLUS_RS_FOUND=0 -DENABLE_AVX512=$svtAvx512Flag `
-DCMAKE_CXX_FLAGS_RELEASE="-flto -DNDEBUG -O2 $ArchFlags $ExtraCFlags -fprofile-use=$profdata" `
-DCMAKE_C_FLAGS_RELEASE="-flto -DNDEBUG -O2 $ArchFlags $ExtraCFlags -fprofile-use=$profdata" `
-DLOG_QUIET=ON -DBUILD_APPS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_OUTPUT_DIRECTORY=svt_build_use
}
Invoke-Step "Building $Variant (PGO Use)" { ninja -C svt_build_use }
Pop-Location
Copy-Item "$Dir\svt_build_use\SvtAv1Enc.lib" lib\ -Force
}
function Build-Opus {
if (Test-Path 'lib\opus.lib') {
Write-Host "[INFO] Opus already compiled. Skipping..." -ForegroundColor Cyan
}
else {
if (Test-Path 'opus') { Push-Location opus; git pull; Pop-Location }
else { git clone --depth 1 https://gitlab.xiph.org/xiph/opus.git }
Push-Location opus
Invoke-Step "Configuring Opus" {
cmake -B build -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_C_FLAGS_RELEASE="$COMMON_FLAGS" `
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
}
Invoke-Step "Building Opus" { ninja -C build }
Pop-Location
Copy-Item opus\build\opus.lib lib\ -Force
}
}
function Build-Vulkan {
param([string]$VsPath)
if ((Test-Path 'lib\vulkan-1.lib') -and (Test-Path 'install\include\spirv\unified1\spirv.h')) {
Write-Host "[INFO] Vulkan and SPIRV-Headers already compiled/installed. Skipping..." -ForegroundColor Cyan
}
else {
if (-not (Test-Path 'vulkan')) { New-Item -ItemType Directory 'vulkan' | Out-Null }
Push-Location vulkan
if (Test-Path 'Vulkan-Headers') { Push-Location 'Vulkan-Headers'; git pull; Pop-Location }
else { git clone --depth 1 https://github.com/KhronosGroup/Vulkan-Headers.git }
Invoke-Step "Configuring Vulkan Headers" {
cmake -S Vulkan-Headers -B Vulkan-Headers/build -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_INSTALL_PREFIX="$PWD/../install" `
-DCMAKE_C_FLAGS_RELEASE="$COMMON_FLAGS" `
-DCMAKE_CXX_FLAGS_RELEASE="$COMMON_FLAGS"
}
Invoke-Step "Installing Vulkan Headers" {
ninja -C Vulkan-Headers/build install
}
if (Test-Path 'SPIRV-Headers') { Push-Location 'SPIRV-Headers'; git pull; Pop-Location }
else { git clone --depth 1 https://github.com/KhronosGroup/SPIRV-Headers.git }
Invoke-Step "Configuring SPIRV-Headers" {
cmake -S SPIRV-Headers -B SPIRV-Headers/build -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_INSTALL_PREFIX="$PWD/../install"
}
Invoke-Step "Installing SPIRV-Headers" {
ninja -C SPIRV-Headers/build install
}
if (Test-Path 'Vulkan-Loader') { Push-Location 'Vulkan-Loader'; git pull; Pop-Location }
else { git clone --depth 1 https://github.com/KhronosGroup/Vulkan-Loader.git }
Invoke-Step "Building Vulkan Loader" {
cmake -S Vulkan-Loader -B Vulkan-Loader/build -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_INSTALL_PREFIX="$PWD/../install" `
-DBUILD_SHARED_LIBS=ON `
-DCMAKE_ASM_MASM_COMPILER="ml64.exe" `
-DVULKAN_HEADERS_INSTALL_DIR="$PWD/../install" `
-DCMAKE_C_FLAGS_RELEASE="$COMMON_FLAGS"
ninja -C Vulkan-Loader/build
ninja -C Vulkan-Loader/build install
}
Pop-Location
Copy-Item 'install\lib\vulkan-1.lib' 'lib\vulkan-1.lib' -Force
}
}
function Build-NvHeaders {
param([string]$MsysExe)
if (Test-Path 'nv-codec-headers\install\lib\pkgconfig\ffnvcodec.pc') {
Write-Host "[INFO] nv-codec-headers already installed. Skipping..." -ForegroundColor Cyan
}
else {
if (Test-Path 'nv-codec-headers') {
Push-Location nv-codec-headers
git pull
Pop-Location
}
else {
git clone --depth 1 https://github.com/FFmpeg/nv-codec-headers.git
}
Push-Location nv-codec-headers
$unixPwd = $PWD.Path -replace '\\', '/'
Invoke-Step "Installing nv-codec-headers" {
& $MsysExe -lc "cd `"$unixPwd`" && make install PREFIX=`"$unixPwd/install`""
}
Pop-Location
}
}
# dav1d
function Build-Dav1d {
if (Test-Path 'lib\dav1d.lib') {
Write-Host "[INFO] dav1d already compiled. Skipping..." -ForegroundColor Cyan
}
else {
if (Test-Path 'dav1d') { Push-Location dav1d; git pull; Pop-Location }
else { git clone --depth 1 https://code.videolan.org/videolan/dav1d.git }
Push-Location dav1d
if (-not (Assert-Command 'meson')) {
$mesonVersion = '1.12.0'
$mesonUrl = "https://github.com/mesonbuild/meson/releases/download/$mesonVersion/meson-$mesonVersion-64.msi"
$mesonHash = 'c35383106327e20795a3c4010d40db0bfe952baf5490584c2535f70899833dce'
$mesonMsi = "$env:TEMP\meson-$mesonVersion-64.msi"
$mesonExe = "$env:ProgramFiles\Meson\meson.exe"
Write-Host ""
Write-Host "[PROMPT] Meson is missing." -ForegroundColor Yellow
$choice = Read-Host "Do you want to install Meson $($mesonVersion)? (Y/N) [Default: Y]"
if ($choice -ieq 'N') {
Write-Host "[ERROR] Meson is required to build dav1d. Exiting." -ForegroundColor Red
exit 1
}
Write-Host "[INFO] Downloading Meson $mesonVersion..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $mesonUrl -OutFile $mesonMsi -UseBasicParsing
$actual = (Get-FileHash $mesonMsi -Algorithm SHA256).Hash
if ($actual -ne $mesonHash.ToUpper()) {
Write-Host "[ERROR] Meson installer checksum mismatch. Expected $mesonHash, got $actual." -ForegroundColor Red
exit 1
}
Write-Host "[INFO] Installing Meson $mesonVersion silently..." -ForegroundColor Cyan
$proc = Start-Process -FilePath 'msiexec.exe' -ArgumentList "/i `"$mesonMsi`" /quiet /qn ALLUSERS=1" -Wait -PassThru -Verb RunAs
if ($proc.ExitCode -ne 0) {
Write-Host "[ERROR] Meson installer failed (exit code $($proc.ExitCode))." -ForegroundColor Red
exit 1
}
if (Test-Path $mesonExe) {
$mesonBin = Split-Path $mesonExe
if ($env:PATH -notlike "*$mesonBin*") {
$env:PATH = "$mesonBin;$env:PATH"
}
}
else {
Write-Host "[ERROR] meson.exe not found at $mesonExe after install." -ForegroundColor Red
exit 1
}
Write-Host "[INFO] Meson $mesonVersion installed successfully." -ForegroundColor Green
}
Invoke-Step "Building dav1d" {
meson setup --reconfigure build --prefix="$PWD/../install" --default-library=static --buildtype=release -Db_vscrt=mt -Db_lto=true -Doptimization=3 -Denable_tools=false -Denable_examples=false -Dc_args="-DNDEBUG -march=native" -Dc_link_args="-fuse-ld=lld"
ninja -C build
meson install -C build
}
Pop-Location
Copy-Item dav1d\build\src\libdav1d.a lib\dav1d.lib -Force
}
}
function Patch-FFmpeg {
param([string]$MsysExe)
$patchScript = @'
#!/bin/sh
set -e
grep -q '^disable inline_asm_nonlocal_labels$' configure || sed -i '/^check_optflags -fno-signed-zeros$/a\
disable inline_asm_nonlocal_labels\
disable inline_asm_direct_symbol_refs' configure
'@
Set-Content -Path 'patch_ffmpeg.sh' -Value ($patchScript.Replace("`r`n", "`n") + "`n") -Encoding Ascii -NoNewline
$unixPath = $PWD.Path -replace '\\', '/'
Invoke-Step "Patching FFmpeg (sed)" {
& $MsysExe -lc "cd `"$unixPath`" && sh ./patch_ffmpeg.sh"
}
Remove-Item 'patch_ffmpeg.sh' -Force -ErrorAction SilentlyContinue
}
function Build-FFmpeg {
param([string]$VsPath, [string]$MsysExe, [string]$Backend)
$env:INCLUDE = "$PWD\dav1d\include;$PWD\dav1d\build\include;$PWD\install\include;$env:INCLUDE"
if ($Backend -eq 'cuda') {
$env:INCLUDE = "$env:CUDA_PATH\include;$env:INCLUDE"
$env:LIB = "$env:CUDA_PATH\lib\x64;$PWD\lib;$PWD\install\lib;$env:LIB"
}
else {
$env:LIB = "$PWD\lib;$PWD\install\lib;$env:LIB"
}
if (Test-Path 'lib\avcodec.lib') {
Write-Host "[INFO] FFmpeg already compiled. Skipping..." -ForegroundColor Cyan
}
else {
if (Test-Path 'FFmpeg') {
Push-Location FFmpeg
git reset --hard
git pull
Pop-Location
}
else { git clone --depth 1 https://github.com/FFmpeg/FFmpeg.git }
Push-Location FFmpeg
Patch-FFmpeg -MsysExe $MsysExe
Invoke-Step "Building FFmpeg" {
$llvmBinWin = "C:\Program Files\LLVM\bin"
if ($Backend -eq 'cuda') {
$hwArgs = @'
--enable-ffnvcodec \
--enable-nvdec \
--enable-cuvid \
--enable-decoder=h264_cuvid \
--enable-decoder=hevc_cuvid \
--enable-decoder=av1_cuvid \
--enable-decoder=vp9_cuvid \
--enable-decoder=vc1_cuvid \
'@
$hwPkgConfig = 'export PKG_CONFIG_PATH="$(pwd)/../nv-codec-headers/install/lib/pkgconfig:$PKG_CONFIG_PATH"'
}
else {
$hwArgs = @'
--enable-vulkan \
--enable-hwaccel=h264_vulkan \
--enable-hwaccel=hevc_vulkan \
--enable-hwaccel=av1_vulkan \
--enable-hwaccel=vp9_vulkan \
'@
$hwPkgConfig = ""
}
$bashScript = @"
#!/bin/sh
set -e
export PATH="`$(cygpath -u '$llvmBinWin'):`$PATH"
"@ + "`n" + @'
export PKG_CONFIG_PATH="$(pwd)/../install/lib/pkgconfig"
./configure \
--disable-all \
--disable-everything \
--cc="clang-cl" \
--cxx="clang-cl" \
--ld="lld-link" \
--ar="llvm-ar" \
--nm="llvm-nm" \
--ranlib="llvm-ranlib" \
--strip="llvm-strip" \
--toolchain="msvc" \
--extra-cflags="-flto /clang:-O3 -DNDEBUG -march=native" \
--extra-cxxflags="-flto /clang:-O3 -DNDEBUG -march=native" \
--disable-shared \
--enable-static \
--pkg-config-flags="--static" \
--disable-programs \
--disable-doc \
--disable-network \
--disable-autodetect \
--disable-debug \
--enable-ffmpeg \
--disable-ffprobe \
--disable-ffplay \
--enable-avcodec \
--enable-avformat \
--enable-avutil \
--enable-avfilter \
--enable-swscale \
--enable-swresample \
--enable-protocol=file \
--enable-protocol=pipe \
--enable-demuxer=matroska \
--enable-demuxer=mov \
--enable-demuxer=mpegts \
--enable-demuxer=mpegps \
--enable-demuxer=flv \
--enable-demuxer=avi \
--enable-demuxer=ivf \
--enable-demuxer=yuv4mpegpipe \
--enable-muxer=yuv4mpegpipe \
--enable-demuxer=h264 \
--enable-demuxer=hevc \
--enable-demuxer=vvc \
--enable-decoder=ffv1 \
--enable-decoder=rawvideo \
--enable-encoder=wrapped_avframe \
--enable-decoder=h264 \
--enable-decoder=hevc \
--enable-decoder=mpeg2video \
--enable-decoder=mpeg1video \
--enable-decoder=mpeg4 \
--enable-decoder=av1 \
--enable-decoder=libdav1d \
--enable-decoder=vp9 \
--enable-decoder=vc1 \
--enable-decoder=vvc \
--enable-decoder=utvideo \
--enable-decoder=aac \
--enable-decoder=aac_latm \
--enable-decoder=ac3 \
--enable-decoder=eac3 \
--enable-decoder=dca \
--enable-decoder=truehd \
--enable-decoder=mlp \
--enable-decoder=mp1 \
--enable-decoder=mp1float \
--enable-decoder=mp2 \
--enable-decoder=mp2float \
--enable-decoder=mp3 \
--enable-decoder=mp3float \
--enable-decoder=opus \
--enable-decoder=vorbis \
--enable-decoder=flac \
--enable-decoder=alac \
--enable-decoder=ape \
--enable-decoder=tak \
--enable-decoder=tta \
--enable-decoder=wavpack \
--enable-decoder=wmalossless \
--enable-decoder=wmapro \
--enable-decoder=wmav1 \
--enable-decoder=wmav2 \
--enable-decoder=mpc7 \
--enable-decoder=mpc8 \
--enable-decoder=dsd_lsbf \
--enable-decoder=dsd_lsbf_planar \
--enable-decoder=dsd_msbf \
--enable-decoder=dsd_msbf_planar \
--enable-decoder=pcm_s16le \
--enable-decoder=pcm_s16be \
--enable-decoder=pcm_s24le \
--enable-decoder=pcm_s24be \
--enable-decoder=pcm_s32le \
--enable-decoder=pcm_s32be \
--enable-decoder=pcm_f32le \
--enable-decoder=pcm_f32be \
--enable-decoder=pcm_f64le \
--enable-decoder=pcm_f64be \
--enable-decoder=pcm_bluray \
--enable-decoder=pcm_dvd \
--enable-libdav1d \
--enable-parser=h264 \
--enable-parser=hevc \
--enable-parser=mpeg4video \
--enable-parser=mpegvideo \
--enable-parser=av1 \