Skip to content

Commit 447f32b

Browse files
committed
Integrate ray-query shadows with Vulkan Ray Query, update linked chapters, and enhance CI with caching and toolchain improvements.
1 parent 6f6aaae commit 447f32b

File tree

5 files changed

+364
-38
lines changed

5 files changed

+364
-38
lines changed

.github/workflows/simple_engine_ci.yml

Lines changed: 151 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ jobs:
2828
- name: Checkout
2929
uses: actions/checkout@v4
3030

31-
- name: Install Clang + Ninja (Linux)
31+
- name: Install Clang + Ninja + ccache (Linux)
3232
if: runner.os == 'Linux'
3333
shell: bash
3434
run: |
3535
set -euo pipefail
3636
sudo apt-get update
37-
sudo apt-get install -y clang ninja-build
37+
sudo apt-get install -y clang ninja-build ccache
3838
3939
- name: Select Clang toolchain (Linux)
4040
if: runner.os == 'Linux'
@@ -48,12 +48,39 @@ jobs:
4848
if: runner.os == 'Windows'
4949
uses: ilammy/msvc-dev-cmd@v1
5050

51-
- name: Set up Ninja
51+
- name: Set up Ninja + sccache
5252
if: runner.os == 'Windows'
53-
uses: seanmiddleditch/gha-setup-ninja@v5
53+
shell: pwsh
54+
run: |
55+
choco install -y ninja sccache
56+
"SCCACHE_DIR=$env:LOCALAPPDATA\Mozilla\sccache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
5457
55-
- name: Install Vulkan SDK (Windows)
58+
- name: ccache (Linux)
59+
if: runner.os == 'Linux'
60+
uses: actions/cache@v4
61+
with:
62+
path: ~/.cache/ccache
63+
key: ${{ runner.os }}-ccache-${{ github.sha }}
64+
restore-keys: ${{ runner.os }}-ccache-
65+
66+
- name: sccache (Windows)
5667
if: runner.os == 'Windows'
68+
uses: actions/cache@v4
69+
with:
70+
path: ${{ env.SCCACHE_DIR }}
71+
key: ${{ runner.os }}-sccache-${{ github.sha }}
72+
restore-keys: ${{ runner.os }}-sccache-
73+
74+
- name: Cache Vulkan SDK (Windows)
75+
if: runner.os == 'Windows'
76+
id: cache-vulkan-windows
77+
uses: actions/cache@v4
78+
with:
79+
path: C:\VulkanSDK
80+
key: ${{ runner.os }}-vulkan-sdk
81+
82+
- name: Install Vulkan SDK (Windows)
83+
if: runner.os == 'Windows' && steps.cache-vulkan-windows.outputs.cache-hit != 'true'
5784
shell: pwsh
5885
run: |
5986
$ErrorActionPreference = 'Stop'
@@ -90,6 +117,14 @@ jobs:
90117
"Vulkan_INCLUDE_DIR=$vulkanPath\Include" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
91118
"Vulkan_LIBRARY=$vulkanPath\Lib\vulkan-1.lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
92119
120+
- name: Cache Vulkan SDK (Linux)
121+
if: runner.os == 'Linux'
122+
id: cache-vulkan-linux
123+
uses: actions/cache@v4
124+
with:
125+
path: ${{ runner.temp }}/VulkanSDK
126+
key: ${{ runner.os }}-vulkan-sdk
127+
93128
- name: Install Vulkan SDK (Linux)
94129
if: runner.os == 'Linux'
95130
shell: bash
@@ -100,32 +135,37 @@ jobs:
100135
# Prefer the SDK-provided tools when present, but install a system fallback to make CI robust.
101136
sudo apt-get install -y curl ca-certificates xz-utils spirv-tools
102137
103-
echo "Downloading Vulkan SDK from LunarG..."
104-
# Use the official LunarG download endpoint (latest Linux tarball).
105-
SDK_TGZ="${RUNNER_TEMP}/vulkansdk-linux.tar.xz"
106-
107-
download_ok=0
108-
for url in \
109-
"https://sdk.lunarg.com/sdk/download/latest/linux/vulkan-sdk.tar.xz" \
110-
"https://sdk.lunarg.com/sdk/download/latest/linux/vulkansdk-linux-x86_64.tar.xz" \
111-
"https://sdk.lunarg.com/sdk/download/latest/linux/vulkan-sdk.tar.xz?Human=true" \
112-
"https://sdk.lunarg.com/sdk/download/latest/linux/vulkansdk-linux-x86_64.tar.xz?Human=true"
113-
do
114-
echo "Attempting: $url"
115-
if curl -L --fail -o "$SDK_TGZ" "$url"; then
116-
download_ok=1
117-
break
138+
SDK_DIR="${RUNNER_TEMP}/VulkanSDK"
139+
140+
if [ "${{ steps.cache-vulkan-linux.outputs.cache-hit }}" != "true" ]; then
141+
echo "Downloading Vulkan SDK from LunarG..."
142+
# Use the official LunarG download endpoint (latest Linux tarball).
143+
SDK_TGZ="${RUNNER_TEMP}/vulkansdk-linux.tar.xz"
144+
145+
download_ok=0
146+
for url in \
147+
"https://sdk.lunarg.com/sdk/download/latest/linux/vulkan-sdk.tar.xz" \
148+
"https://sdk.lunarg.com/sdk/download/latest/linux/vulkansdk-linux-x86_64.tar.xz" \
149+
"https://sdk.lunarg.com/sdk/download/latest/linux/vulkan-sdk.tar.xz?Human=true" \
150+
"https://sdk.lunarg.com/sdk/download/latest/linux/vulkansdk-linux-x86_64.tar.xz?Human=true"
151+
do
152+
echo "Attempting: $url"
153+
if curl -L --fail -o "$SDK_TGZ" "$url"; then
154+
download_ok=1
155+
break
156+
fi
157+
done
158+
if [ "$download_ok" -ne 1 ]; then
159+
echo "Failed to download Vulkan SDK from LunarG (all endpoints returned non-200)." >&2
160+
exit 1
118161
fi
119-
done
120-
if [ "$download_ok" -ne 1 ]; then
121-
echo "Failed to download Vulkan SDK from LunarG (all endpoints returned non-200)." >&2
122-
exit 1
123-
fi
124162
125-
SDK_DIR="${RUNNER_TEMP}/VulkanSDK"
126-
rm -rf "$SDK_DIR"
127-
mkdir -p "$SDK_DIR"
128-
tar -xJf "$SDK_TGZ" -C "$SDK_DIR"
163+
rm -rf "$SDK_DIR"
164+
mkdir -p "$SDK_DIR"
165+
tar -xJf "$SDK_TGZ" -C "$SDK_DIR"
166+
else
167+
echo "Using cached Vulkan SDK from $SDK_DIR"
168+
fi
129169
130170
# The tarball extracts into a versioned subdirectory.
131171
VULKAN_SDK_PATH="$(find "$SDK_DIR" -maxdepth 1 -type d -name '1.*' | sort -r | head -n 1)"
@@ -214,8 +254,18 @@ jobs:
214254
fi
215255
216256
# Use the engine's dependency install scripts instead of calling vcpkg directly in CI.
217-
- name: Bootstrap vcpkg (Windows)
257+
- name: Cache vcpkg (Windows)
218258
if: runner.os == 'Windows'
259+
id: cache-vcpkg-windows
260+
uses: actions/cache@v4
261+
with:
262+
path: |
263+
${{ runner.temp }}/vcpkg
264+
${{ runner.temp }}/vcpkg-cache
265+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('attachments/simple_engine/vcpkg.json') }}
266+
267+
- name: Bootstrap vcpkg (Windows)
268+
if: runner.os == 'Windows' && steps.cache-vcpkg-windows.outputs.cache-hit != 'true'
219269
shell: pwsh
220270
run: |
221271
$ErrorActionPreference = 'Stop'
@@ -232,18 +282,72 @@ jobs:
232282
"$vcpkgRoot" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
233283
"CMAKE_TOOLCHAIN_FILE=$vcpkgRoot\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
234284
285+
- name: Set vcpkg env (Windows)
286+
if: runner.os == 'Windows'
287+
shell: pwsh
288+
run: |
289+
$vcpkgRoot = Join-Path $env:RUNNER_TEMP "vcpkg"
290+
"VCPKG_INSTALLATION_ROOT=$vcpkgRoot" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
291+
"$vcpkgRoot" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
292+
"CMAKE_TOOLCHAIN_FILE=$vcpkgRoot\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
293+
"VCPKG_DEFAULT_BINARY_CACHE=$env:RUNNER_TEMP\vcpkg-cache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
294+
235295
- name: Install dependencies (Windows)
236296
if: runner.os == 'Windows'
237297
shell: cmd
238298
run: |
239299
call install_dependencies_windows.bat
240300
301+
- name: Cache dependencies (Linux)
302+
if: runner.os == 'Linux'
303+
id: cache-deps-linux
304+
uses: actions/cache@v4
305+
with:
306+
path: |
307+
/home/runner/.cache/simple_engine_deps
308+
/home/runner/.local
309+
key: ${{ runner.os }}-deps-v1
310+
241311
- name: Install dependencies (Linux)
242312
if: runner.os == 'Linux'
243313
shell: bash
244314
run: |
245-
chmod +x ./install_dependencies_linux.sh
246-
./install_dependencies_linux.sh
315+
set -euo pipefail
316+
sudo apt-get update
317+
sudo apt-get install -y \
318+
build-essential cmake git ninja-build pkg-config \
319+
ca-certificates curl zip unzip tar \
320+
libglfw3-dev libglm-dev libopenal-dev \
321+
nlohmann-json3-dev libx11-dev libxrandr-dev \
322+
libxinerama-dev libxcursor-dev libxi-dev \
323+
zlib1g-dev libpng-dev libzstd-dev
324+
325+
WORK_ROOT="/home/runner/.cache/simple_engine_deps"
326+
LOCAL_INSTALL="/home/runner/.local"
327+
mkdir -p "${WORK_ROOT}"
328+
329+
# build tinygltf
330+
if [ ! -f "${LOCAL_INSTALL}/lib/cmake/tinygltf/tinygltfConfig.cmake" ]; then
331+
git clone --depth 1 https://github.com/syoyo/tinygltf.git "${WORK_ROOT}/tinygltf"
332+
cmake -S "${WORK_ROOT}/tinygltf" -B "${WORK_ROOT}/tinygltf-build" -G Ninja \
333+
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
334+
-DTINYGLTF_BUILD_LOADER_EXAMPLE=OFF -DTINYGLTF_BUILD_GL_EXAMPLES=OFF \
335+
-DTINYGLTF_BUILD_STB_IMAGE=ON -DCMAKE_INSTALL_PREFIX="${LOCAL_INSTALL}"
336+
cmake --build "${WORK_ROOT}/tinygltf-build" --parallel
337+
cmake --install "${WORK_ROOT}/tinygltf-build"
338+
fi
339+
340+
# build ktx
341+
if [ ! -f "${LOCAL_INSTALL}/lib/cmake/KTX/KTXConfig.cmake" ]; then
342+
git clone --depth 1 --branch v4.3.2 https://github.com/KhronosGroup/KTX-Software.git "${WORK_ROOT}/KTX-Software"
343+
cmake -S "${WORK_ROOT}/KTX-Software" -B "${WORK_ROOT}/KTX-Software-build" -G Ninja \
344+
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
345+
-DKTX_FEATURE_TESTS=OFF -DKTX_FEATURE_TOOLS=OFF \
346+
-DKTX_FEATURE_VULKAN=ON -DCMAKE_INSTALL_PREFIX="${LOCAL_INSTALL}" \
347+
-DVulkan_INCLUDE_DIR="${Vulkan_INCLUDE_DIR}"
348+
cmake --build "${WORK_ROOT}/KTX-Software-build" --parallel
349+
cmake --install "${WORK_ROOT}/KTX-Software-build"
350+
fi
247351
248352
- name: Configure (Windows)
249353
if: runner.os == 'Windows'
@@ -252,6 +356,8 @@ jobs:
252356
cmake -S . -B build -G Ninja
253357
-DCMAKE_BUILD_TYPE=Release
254358
-DCMAKE_TOOLCHAIN_FILE="$env:CMAKE_TOOLCHAIN_FILE"
359+
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
360+
-DCMAKE_C_COMPILER_LAUNCHER=sccache
255361
256362
- name: Configure (Linux)
257363
if: runner.os == 'Linux'
@@ -273,10 +379,23 @@ jobs:
273379
-DCMAKE_BUILD_TYPE=Release \
274380
-DCMAKE_C_COMPILER=clang \
275381
-DCMAKE_CXX_COMPILER=clang++ \
382+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
383+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
384+
-DCMAKE_PREFIX_PATH="/home/runner/.local;${VULKAN_SDK_SYSROOT}" \
276385
"${extra_args[@]}"
277386
278387
- name: Build
279388
run: cmake --build build --target SimpleEngine --parallel 4
280389

390+
- name: Cache stats
391+
shell: bash
392+
run: |
393+
if command -v ccache >/dev/null 2>&1; then
394+
ccache -s
395+
fi
396+
if command -v sccache >/dev/null 2>&1; then
397+
sccache -s
398+
fi
399+
281400
- name: Test
282401
run: ctest --test-dir build --output-on-failure

en/Building_a_Simple_Engine/Lighting_Materials/05_vulkan_integration.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,6 @@ In this section, we've integrated our PBR implementation with the rest of the Vu
216216

217217
This approach provides a solid foundation for rendering physically accurate materials, which we'll apply in the Loading_Models chapter when we load and render glTF models. It also gives us the flexibility to modify and extend the material properties as needed for our specific rendering requirements.
218218

219-
In the next section, we'll wrap up this chapter with a conclusion and discuss potential improvements and extensions to our lighting system.
219+
In the next section, we'll explore how to add high-quality shadows using Vulkan Ray Query.
220220

221-
link:04_lighting_implementation.adoc[Previous: Lighting Implementation] | link:06_conclusion.adoc[Next: Conclusion]
221+
link:04_lighting_implementation.adoc[Previous: Lighting Implementation] | link:07_shadows.adoc[Next: Shadows]

en/Building_a_Simple_Engine/Lighting_Materials/06_conclusion.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
= Conclusion
22

3-
In this chapter, we've explored the fundamentals of lighting and materials in 3D rendering and introduced Physically Based Rendering (PBR) using the metallic-roughness workflow. We've covered the theory behind PBR and implemented a shader that can be used with glTF models. We've also learned how to use push constants to efficiently pass material properties to our shaders.
3+
In this chapter, we've explored the fundamentals of lighting and materials in 3D rendering and introduced Physically Based Rendering (PBR) using the metallic-roughness workflow. We've covered the theory behind PBR, implemented a shader that can be used with glTF models, and added high-quality shadows using Vulkan Ray Query. We've also learned how to use push constants to efficiently pass material properties to our shaders.
44

55
== What We've Learned
66

7-
This chapter has taken you through the essential concepts needed to implement physically-based rendering in a Vulkan engine. We introduced the metallic‑roughness PBR workflow, mapped glTF material properties to shader inputs, and used push constants to drive per‑draw material parameters without descriptor churn. You saw how the BRDF pieces cooperate to conserve energy and produce plausible lighting, and how to plug the shader into a vk::raii‑based pipeline so models render correctly end‑to‑end.
7+
This chapter has taken you through the essential concepts needed to implement physically-based rendering in a Vulkan engine. We introduced the metallic‑roughness PBR workflow, mapped glTF material properties to shader inputs, and used push constants to drive per‑draw material parameters without descriptor churn. You saw how the BRDF pieces cooperate to conserve energy and produce plausible lighting, and how to plug the shader into a vk::raii‑based pipeline so models render correctly end‑to‑end. Finally, we integrated hardware-accelerated ray-traced shadows for improved realism.
88

99
== Making it click: a mental model of this PBR pipeline
1010

@@ -31,7 +31,7 @@ This mental model helps you predict how a change to any input will echo through
3131

3232
== Potential Improvements
3333

34-
Our PBR pass is a solid baseline. The most impactful upgrades are image‑based lighting (environment maps for ambient/indirect), shadowing, and a few material extensions (e.g., clear coat or anisotropy). On the performance side, consider clustered forward or a deferred path when light counts grow. If you build an HDR chain, bloom and a more filmic tone mapper (ACES/Hable) round out the presentation.
34+
Our PBR pass is a solid baseline. The most impactful upgrades are image‑based lighting (environment maps for ambient/indirect) and a few material extensions (e.g., clear coat or anisotropy). On the performance side, consider clustered forward or a deferred path when light counts grow. If you build an HDR chain, bloom and a more filmic tone mapper (ACES/Hable) round out the presentation.
3535

3636
== Next Steps
3737

@@ -41,4 +41,4 @@ Remember that lighting is a complex topic with many approaches and techniques. T
4141

4242
In the next chapter, we'll explore GUI implementation, which will allow us to create interactive user interfaces for our applications.
4343

44-
link:05_vulkan_integration.adoc[Previous: Vulkan Integration] | link:../GUI/01_introduction.adoc[Next: GUI - Introduction]
44+
link:07_shadows.adoc[Previous: Shadows] | link:../GUI/01_introduction.adoc[Next: GUI - Introduction]

0 commit comments

Comments
 (0)