Repository navigation
Expand file tree
/
Copy pathupdate_baseline.bat
More file actions
170 lines (147 loc) · 5.3 KB
/
Copy pathupdate_baseline.bat
File metadata and controls
170 lines (147 loc) · 5.3 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
@echo off
setlocal enabledelayedexpansion
cd /d "%~dp0"
:: Usage:
:: update_baseline.bat [<BACKEND>] [--skip-images]
::
:: BACKEND (order-insensitive with --skip-images):
:: USE_D3D12 D3D12 (real GPU)
:: USE_D3D12_WARP D3D12 (WARP software adapter, used in CI)
:: USE_OPENGL OpenGL
:: USE_OPENGL_SWIFTSHADER OpenGL (SwiftShader)
:: USE_VULKAN Vulkan (real GPU)
:: USE_VULKAN_SWIFTSHADER Vulkan (SwiftShader)
::
:: Options:
:: --skip-images Skip writing baseline `_base.webp` images. The cache
:: (md5.json + version.json) is still refreshed, which is
:: all the CI pipeline needs. Local runs omit this to also
:: produce baseline-out\ images for visual inspection.
:: Parse arguments: separate the backend keyword from the --skip-images flag so callers may
:: pass them in any order (e.g. `update_baseline.bat --skip-images USE_D3D12`).
set "BACKEND_ARG="
set "SKIP_IMAGES=0"
:parse_args
if "%~1"=="" goto :done_args
if /I "%~1"=="--skip-images" (
set "SKIP_IMAGES=1"
) else (
set "BACKEND_ARG=%~1"
)
shift
goto :parse_args
:done_args
:: Determine cmake args and backend name
set "CMAKE_BACKEND_ARGS="
set "BACKEND_NAME=opengl"
set "TARGET_SUFFIX=OpenGL"
if /I "!BACKEND_ARG!"=="USE_OPENGL_SWIFTSHADER" (
set "CMAKE_BACKEND_ARGS=-DTGFX_USE_SWIFTSHADER=ON"
set "BACKEND_NAME=opengl-swiftshader"
set "TARGET_SUFFIX=OpenGL"
)
if /I "!BACKEND_ARG!"=="USE_VULKAN_SWIFTSHADER" (
set "CMAKE_BACKEND_ARGS=-DTGFX_USE_VULKAN=ON -DTGFX_USE_SWIFTSHADER=ON"
set "BACKEND_NAME=vulkan-swiftshader"
set "TARGET_SUFFIX=Vulkan"
)
if /I "!BACKEND_ARG!"=="USE_VULKAN" (
set "CMAKE_BACKEND_ARGS=-DTGFX_USE_VULKAN=ON"
set "BACKEND_NAME=vulkan"
set "TARGET_SUFFIX=Vulkan"
)
if /I "!BACKEND_ARG!"=="USE_OPENGL" (
set "CMAKE_BACKEND_ARGS="
set "BACKEND_NAME=opengl"
set "TARGET_SUFFIX=OpenGL"
)
if /I "!BACKEND_ARG!"=="USE_D3D12" (
set "CMAKE_BACKEND_ARGS=-DTGFX_USE_D3D12=ON"
set "BACKEND_NAME=d3d12"
set "TARGET_SUFFIX=D3D12"
)
if /I "!BACKEND_ARG!"=="USE_D3D12_WARP" (
set "CMAKE_BACKEND_ARGS=-DTGFX_USE_D3D12=ON -DTGFX_D3D12_USE_WARP=ON"
set "BACKEND_NAME=d3d12-warp"
set "TARGET_SUFFIX=D3D12"
)
:: Check if cache is up to date
set "CACHE_VERSION_FILE=test\baseline\.cache\%BACKEND_NAME%\version.json"
if not exist "%CACHE_VERSION_FILE%" goto :do_update
:: Compare cache version with origin/main version
git show origin/main:test/baseline/version.json > "%TEMP%\tgfx_main_version.json" 2>nul
if %errorlevel% neq 0 goto :do_update
fc /b "%TEMP%\tgfx_main_version.json" "%CACHE_VERSION_FILE%" >nul 2>&1
if %errorlevel% equ 0 (
echo Cache for %BACKEND_NAME% is up to date.
exit /b 0
)
:do_update
echo ~~~~~~~~~~~~~~~~~~~Update Baseline ^(%BACKEND_NAME%^) Start~~~~~~~~~~~~~~~~~~~~~
:: Save current state
for /f "delims=" %%i in ('git rev-parse --abbrev-ref HEAD') do set "CURRENT_BRANCH=%%i"
for /f "delims=" %%i in ('git rev-parse HEAD') do set "CURRENT_COMMIT=%%i"
for /f "delims=" %%i in ('git stash list') do set "STASH_BEFORE=%%i"
git stash push --include-untracked --quiet
set "STASH_AFTER="
for /f "delims=" %%i in ('git stash list') do set "STASH_AFTER=%%i"
:: Switch to main
git switch main --quiet
:: Install dependencies
for /f "delims=" %%i in ('npm prefix -g') do set "PATH=%%i;!PATH!"
call npm install depsync -g >nul
call depsync
:: Build UpdateBaseline
set "BUILD_DIR=build-update-baseline"
if exist %BUILD_DIR% rd /s /q %BUILD_DIR%
mkdir %BUILD_DIR%
cd %BUILD_DIR%
:: Windows Debug builds compile far slower than macOS, so this script (which is also driven by
:: CI) builds the baseline generator in Release across all Windows backends to keep the refresh
:: turnaround acceptable. macOS update_baseline.sh keeps Debug for better diagnostics.
set "SKIP_IMAGES_FLAG="
if "!SKIP_IMAGES!"=="1" set "SKIP_IMAGES_FLAG=-DTGFX_SKIP_GENERATE_BASELINE_IMAGES=ON"
cmake -G Ninja %CMAKE_BACKEND_ARGS% %SKIP_IMAGES_FLAG% -DTGFX_BUILD_TESTS=ON -DTGFX_SKIP_BASELINE_CHECK=ON -DCMAKE_BUILD_TYPE=Release ../
if %errorlevel% neq 0 (
echo CMake configuration failed
set "BASELINE_FAILED=true"
cd ..
goto :restore
)
cmake --build . --target UpdateBaseline_%TARGET_SUFFIX%
if !errorlevel! neq 0 (
echo Build failed
set "BASELINE_FAILED=true"
cd ..
goto :restore
)
:: Set up SwiftShader Vulkan library so volk can load it at runtime.
if /I "!BACKEND_ARG!"=="USE_VULKAN_SWIFTSHADER" copy /y "%~dp0vendor\swiftshader\win\x64\vk_swiftshader.dll" "%CD%\vulkan-1.dll" >nul 2>&1
UpdateBaseline_%TARGET_SUFFIX%.exe
if !errorlevel! equ 0 (
echo ~~~~~~~~~~~~~~~~~~~Update Baseline ^(%BACKEND_NAME%^) Success~~~~~~~~~~~~~~~~~~~~~
) else (
echo ~~~~~~~~~~~~~~~~~~~Update Baseline ^(%BACKEND_NAME%^) Failed~~~~~~~~~~~~~~~~~~
set "BASELINE_FAILED=true"
)
cd ..
:restore
:: Restore previous state
if "%CURRENT_BRANCH%"=="HEAD" (
git checkout %CURRENT_COMMIT% --quiet
) else (
git switch %CURRENT_BRANCH% --quiet
)
if not "!STASH_BEFORE!"=="!STASH_AFTER!" (
git stash pop --index --quiet
)
call depsync
:: Cleanup
if exist %BUILD_DIR% rd /s /q %BUILD_DIR%
del "%TEMP%\tgfx_main_version.json" >nul 2>&1
if "!BASELINE_FAILED!"=="true" (
if not exist result mkdir result
xcopy /s /e /i /q test\out result\out >nul 2>&1
exit /b 1
)
exit /b 0