Skip to content

Commit cb16fd1

Browse files
committed
Refactor entity resource loops to remove use of std::views, replacing with explicit iteration for improved clarity and maintainability. Enhance CI workflows with caching for Vulkan SDK, dependencies, and build artifacts on both Windows and Ubuntu. Add ccache and sccache integration to improve build performance.
1 parent e1c31d7 commit cb16fd1

File tree

6 files changed

+208
-27
lines changed

6 files changed

+208
-27
lines changed

.github/workflows/simple_engine.yml

Lines changed: 192 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,74 @@ jobs:
3535
fetch-depth: 0
3636
submodules: recursive
3737

38+
# Cache Vulkan SDK on Windows like in workflow.yml
39+
- name: Cache Vulkan SDK (Windows)
40+
if: runner.os == 'Windows'
41+
uses: actions/cache@v3
42+
with:
43+
path: C:\VulkanSDK
44+
key: ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt', '**/*.cpp', '**/*.h') }}
45+
restore-keys: |
46+
${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-
47+
${{ runner.os }}-vulkan-sdk-
48+
49+
# Cache vcpkg packages (Windows) like in workflow.yml
50+
- name: Cache vcpkg packages (Windows)
51+
if: runner.os == 'Windows'
52+
uses: actions/cache@v3
53+
with:
54+
path: |
55+
${{ env.VCPKG_INSTALLATION_ROOT }}/installed
56+
${{ env.VCPKG_INSTALLATION_ROOT }}/packages
57+
${{ env.VCPKG_INSTALLATION_ROOT }}/buildtrees
58+
${{ env.VCPKG_INSTALLATION_ROOT }}/downloads
59+
${{ runner.temp }}/vcpkg-cache
60+
key: ${{ runner.os }}-vcpkg-${{ hashFiles('scripts/install_dependencies_windows.bat', '**/CMakeLists.txt') }}
61+
restore-keys: |
62+
${{ runner.os }}-vcpkg-${{ hashFiles('scripts/install_dependencies_windows.bat') }}-
63+
${{ runner.os }}-vcpkg-
64+
65+
# Cache apt packages (Ubuntu)
66+
- name: Cache apt packages (Ubuntu)
67+
if: runner.os == 'Linux'
68+
uses: actions/cache@v3
69+
with:
70+
path: /var/cache/apt/archives
71+
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/simple_engine.yml') }}
72+
restore-keys: |
73+
${{ runner.os }}-apt-
74+
75+
# Cache ccache (Ubuntu)
76+
- name: Cache ccache files (Ubuntu)
77+
if: runner.os == 'Linux'
78+
uses: actions/cache@v3
79+
with:
80+
path: |
81+
~/.ccache
82+
key: ${{ runner.os }}-ccache-${{ hashFiles('attachments/simple_engine/**', '**/CMakeLists.txt') }}
83+
restore-keys: |
84+
${{ runner.os }}-ccache-
85+
86+
# Cache Vulkan SDK directory (Ubuntu)
87+
- name: Cache Vulkan SDK (Ubuntu)
88+
if: runner.os == 'Linux'
89+
uses: actions/cache@v3
90+
with:
91+
path: ${{ github.workspace }}/vulkan-sdk
92+
key: ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('attachments/simple_engine/**') }}
93+
restore-keys: |
94+
${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-
95+
${{ runner.os }}-vulkan-sdk-
96+
97+
# Cache sccache binary (Windows)
98+
- name: Cache sccache binary (Windows)
99+
if: runner.os == 'Windows'
100+
id: cache-sccache
101+
uses: actions/cache@v3
102+
with:
103+
path: ${{ runner.temp }}/sccache
104+
key: ${{ runner.os }}-sccache-0.5.4
105+
38106
# -----------------------
39107
# Linux: set up Vulkan SDK similar to workflow.yml
40108
# -----------------------
@@ -70,6 +138,15 @@ jobs:
70138
libxi-dev \
71139
libopenal-dev
72140
141+
- name: Install and configure ccache (Ubuntu)
142+
if: matrix.os == 'ubuntu-latest'
143+
run: |
144+
sudo apt-get install -y ccache
145+
ccache --max-size=2G
146+
ccache -z
147+
echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
148+
echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
149+
73150
- name: Install project deps via script (Ubuntu)
74151
if: matrix.os == 'ubuntu-latest'
75152
working-directory: attachments/simple_engine
@@ -85,32 +162,95 @@ jobs:
85162
if: matrix.os == 'windows-latest'
86163
shell: pwsh
87164
run: |
88-
git clone https://github.com/microsoft/vcpkg.git $env:USERPROFILE\vcpkg
89-
& $env:USERPROFILE\vcpkg\bootstrap-vcpkg.bat
165+
$vcpkgRoot = $env:VCPKG_INSTALLATION_ROOT
166+
if (-not $vcpkgRoot) { $vcpkgRoot = "C:\vcpkg" }
167+
if (-not (Test-Path $vcpkgRoot)) {
168+
git clone https://github.com/microsoft/vcpkg.git $vcpkgRoot
169+
& "$vcpkgRoot\bootstrap-vcpkg.bat"
170+
}
90171
$triplet = 'x64-windows'
91172
# Use manifest mode; vcpkg.json at repo root defines dependencies
92-
& $env:USERPROFILE\vcpkg\vcpkg.exe install --triplet $triplet
93-
echo "CMAKE_TOOLCHAIN_FILE=$env:USERPROFILE\vcpkg\scripts\buildsystems\vcpkg.cmake" >> $env:GITHUB_ENV
173+
& "$vcpkgRoot\vcpkg.exe" install --triplet $triplet
174+
echo "VCPKG_INSTALLATION_ROOT=$vcpkgRoot" >> $env:GITHUB_ENV
175+
echo "CMAKE_TOOLCHAIN_FILE=$vcpkgRoot\scripts\buildsystems\vcpkg.cmake" >> $env:GITHUB_ENV
94176
echo "VCPKG_TARGET_TRIPLET=$triplet" >> $env:GITHUB_ENV
95177
178+
- name: Install sccache (Windows)
179+
if: matrix.os == 'windows-latest'
180+
shell: pwsh
181+
run: |
182+
if (Test-Path "$env:RUNNER_TEMP\sccache\sccache.exe") {
183+
Write-Host "Using cached sccache binary"
184+
$sccachePath = "$env:RUNNER_TEMP\sccache"
185+
} else {
186+
Write-Host "Downloading and installing sccache..."
187+
New-Item -ItemType Directory -Force -Path "$env:RUNNER_TEMP\sccache" | Out-Null
188+
choco install -y aria2 --no-progress
189+
aria2c --split=8 --max-connection-per-server=8 --min-split-size=1M --dir="$env:RUNNER_TEMP" --out="sccache.tar.gz" "https://github.com/mozilla/sccache/releases/download/v0.5.4/sccache-v0.5.4-x86_64-pc-windows-msvc.tar.gz"
190+
tar -xzf "$env:RUNNER_TEMP\sccache.tar.gz" --strip-components=1 -C "$env:RUNNER_TEMP\sccache" "sccache-v0.5.4-x86_64-pc-windows-msvc/sccache.exe"
191+
$sccachePath = "$env:RUNNER_TEMP\sccache"
192+
}
193+
echo "$sccachePath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
194+
echo "SCCACHE_DIR=$HOME/.cache/sccache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
195+
echo "SCCACHE_CACHE_SIZE=4G" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
196+
echo "SCCACHE_ERROR_LOG=$HOME/.cache/sccache/sccache.log" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
197+
echo "SCCACHE_LOG=info" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
198+
echo "RUST_LOG=sccache=info" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
199+
New-Item -ItemType Directory -Force -Path "$HOME/.cache/sccache" | Out-Null
200+
& "$sccachePath\sccache.exe" --version
201+
96202
- name: Install project deps via script (Windows)
97203
if: matrix.os == 'windows-latest'
98204
shell: cmd
99205
working-directory: attachments/simple_engine
100206
run: |
101207
if exist install_dependencies_windows.bat call install_dependencies_windows.bat || exit /b 0
102208
103-
# Install LunarG Vulkan SDK on Windows and export environment variables for our FindVulkan.cmake
209+
# Install LunarG Vulkan SDK on Windows and export environment variables (mirror workflow.yml)
104210
- name: Install Vulkan SDK (Windows)
105211
if: matrix.os == 'windows-latest'
106212
shell: pwsh
107213
run: |
108-
choco install vulkan-sdk -y --no-progress
109-
$sdkDir = Get-ChildItem -Path 'C:\VulkanSDK' -ErrorAction SilentlyContinue | Sort-Object Name -Descending | Select-Object -First 1
110-
if (-not $sdkDir) { throw "Vulkan SDK was not installed to C:\VulkanSDK" }
111-
echo "Using Vulkan SDK: $($sdkDir.FullName)"
112-
echo "VULKAN_SDK=$($sdkDir.FullName)" >> $env:GITHUB_ENV
113-
echo "PATH=$($sdkDir.FullName)\Bin;$env:PATH" >> $env:GITHUB_ENV
214+
if (Test-Path "C:\VulkanSDK") {
215+
Write-Host "Using cached Vulkan SDK"
216+
} else {
217+
Write-Host "Downloading Vulkan SDK installer from LunarG..."
218+
choco install -y aria2 --no-progress
219+
aria2c --split=16 --max-connection-per-server=16 --min-split-size=1M --dir="$env:TEMP" --out="vulkan-sdk.exe" "https://sdk.lunarg.com/sdk/download/latest/windows/vulkan-sdk.exe"
220+
221+
Write-Host "Installing Vulkan SDK silently..."
222+
try {
223+
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install --components VulkanRT,VulkanSDK64,VulkanDXC,VulkanTools" -Wait -NoNewWindow
224+
if (-not (Test-Path "C:\VulkanSDK")) {
225+
Write-Host "Vulkan SDK installation with components failed; retrying full install..."
226+
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow
227+
}
228+
} catch {
229+
Write-Host "Error installing Vulkan SDK: $_"
230+
Write-Host "Retrying full install without component selection..."
231+
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow
232+
}
233+
}
234+
235+
# Resolve installed Vulkan SDK path (latest)
236+
$vulkanPath = ""
237+
if (Test-Path "C:\VulkanSDK") {
238+
$vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName
239+
}
240+
if (-not $vulkanPath) {
241+
if (Test-Path "C:\VulkanSDK\latest") {
242+
$vulkanPath = "C:\VulkanSDK\latest"
243+
} else {
244+
throw "Vulkan SDK not found after installation."
245+
}
246+
}
247+
248+
Write-Host "Using Vulkan SDK: $vulkanPath"
249+
echo "VULKAN_SDK=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
250+
echo "$vulkanPath\Bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
251+
echo "CMAKE_PREFIX_PATH=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
252+
echo "Vulkan_INCLUDE_DIR=$vulkanPath\Include" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
253+
echo "Vulkan_LIBRARY=$vulkanPath\Lib\vulkan-1.lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
114254
115255
# -----------------------
116256
# Configure & Build
@@ -122,7 +262,9 @@ jobs:
122262
cmake -S attachments/simple_engine \
123263
-B build-simple_engine-${{ matrix.os }}-${{ matrix.build_type }}-m${{ matrix.enable_module }} \
124264
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
125-
-DENABLE_CPP20_MODULE=${{ matrix.enable_module }}
265+
-DENABLE_CPP20_MODULE=${{ matrix.enable_module }} \
266+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
267+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
126268
127269
# Configure on Ubuntu with modules enabled: use Clang + Ninja (required for C++ modules)
128270
- name: "Configure (Ubuntu • module: Clang + Ninja)"
@@ -134,7 +276,9 @@ jobs:
134276
-DCMAKE_C_COMPILER=clang \
135277
-DCMAKE_CXX_COMPILER=clang++ \
136278
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
137-
-DENABLE_CPP20_MODULE=${{ matrix.enable_module }}
279+
-DENABLE_CPP20_MODULE=${{ matrix.enable_module }} \
280+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
281+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
138282
139283
- name: Configure (Windows)
140284
if: matrix.os == 'windows-latest'
@@ -145,13 +289,43 @@ jobs:
145289
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} `
146290
-DENABLE_CPP20_MODULE=${{ matrix.enable_module }} `
147291
-DCMAKE_TOOLCHAIN_FILE="$env:CMAKE_TOOLCHAIN_FILE" `
148-
-DVCPKG_TARGET_TRIPLET="$env:VCPKG_TARGET_TRIPLET"
292+
-DVCPKG_TARGET_TRIPLET="$env:VCPKG_TARGET_TRIPLET" `
293+
-DCMAKE_C_COMPILER_LAUNCHER=sccache `
294+
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
295+
296+
# Cache build artifacts (Windows)
297+
- name: Cache build artifacts (Windows)
298+
if: runner.os == 'Windows'
299+
uses: actions/cache@v3
300+
with:
301+
path: |
302+
build-simple_engine-windows-latest-*
303+
key: ${{ runner.os }}-build-msvc-${{ hashFiles('attachments/simple_engine/**', '**/CMakeLists.txt') }}-${{ matrix.build_type }}-m${{ matrix.enable_module }}
304+
restore-keys: |
305+
${{ runner.os }}-build-msvc-${{ hashFiles('attachments/simple_engine/**') }}-
306+
${{ runner.os }}-build-msvc-
307+
308+
# Cache build artifacts (Ubuntu)
309+
- name: Cache build artifacts (Ubuntu)
310+
if: runner.os == 'Linux'
311+
uses: actions/cache@v3
312+
with:
313+
path: |
314+
build-simple_engine-ubuntu-latest-*
315+
key: ${{ runner.os }}-build-${{ hashFiles('attachments/simple_engine/**', '**/CMakeLists.txt') }}-${{ matrix.build_type }}-m${{ matrix.enable_module }}
316+
restore-keys: |
317+
${{ runner.os }}-build-${{ hashFiles('attachments/simple_engine/**') }}-
318+
${{ runner.os }}-build-
149319
150320
- name: Build
151321
run: |
152322
cmake --build build-simple_engine-${{ matrix.os }}-${{ matrix.build_type }}-m${{ matrix.enable_module }} --config ${{ matrix.build_type }}
153323
154-
- name: Package (Release only)
155-
if: matrix.build_type == 'Release'
156-
run: |
157-
cmake --build build-simple_engine-${{ matrix.os }}-${{ matrix.build_type }}-m${{ matrix.enable_module }} --target package --config ${{ matrix.build_type }}
324+
- name: ccache statistics
325+
if: runner.os == 'Linux'
326+
run: ccache -s
327+
328+
- name: sccache statistics
329+
if: runner.os == 'Windows'
330+
shell: pwsh
331+
run: sccache -s

attachments/simple_engine/model_loader.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,8 @@ bool ModelLoader::ParseGLTF(const std::string& filename, Model* model) {
680680
// Heuristic pass: fill missing baseColor (albedo) by deriving from normal map filenames
681681
// Many Bistro materials have no baseColorTexture index. When that happens, try inferring
682682
// the base color from the normal map by replacing common suffixes like _ddna -> _d/_c/_diffuse/_basecolor/_albedo.
683-
for (auto& material : materials | std::views::values) {
683+
for (auto& kv : materials) {
684+
auto& material = kv.second;
684685
Material* mat = material.get();
685686
if (!mat) continue;
686687
if (!mat->albedoTexturePath.empty()) continue; // already set
@@ -1136,8 +1137,8 @@ if (materialMesh.vertices.empty()) {
11361137

11371138
// Convert geometry-based material mesh map to vector
11381139
std::vector<MaterialMesh> modelMaterialMeshes;
1139-
for (auto& val : geometryMaterialMeshMap | std::views::values) {
1140-
modelMaterialMeshes.push_back(val);
1140+
for (auto& kv : geometryMaterialMeshMap) {
1141+
modelMaterialMeshes.push_back(kv.second);
11411142
}
11421143

11431144
// Process texture loading for each MaterialMesh

attachments/simple_engine/renderer_core.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ void Renderer::Cleanup() {
235235

236236
// Wait for the device to be idle before cleaning up
237237
device.waitIdle();
238-
for (auto& resources : entityResources | std::views::values) {
238+
for (auto& kv : entityResources) {
239+
auto& resources = kv.second;
239240
// Memory pool handles unmapping automatically, no need to manually unmap
240241
resources.basicDescriptorSets.clear();
241242
resources.pbrDescriptorSets.clear();

attachments/simple_engine/renderer_rendering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ void Renderer::recreateSwapChain() {
316316
}
317317

318318
// Clear all entity descriptor sets since they're now invalid (allocated from the old pool)
319-
for (auto& resources : entityResources | std::views::values) {
319+
for (auto& kv : entityResources) {
320+
auto& resources = kv.second;
320321
resources.basicDescriptorSets.clear();
321322
resources.pbrDescriptorSets.clear();
322323
}
@@ -331,7 +332,8 @@ void Renderer::recreateSwapChain() {
331332
currentFrame = 0;
332333

333334
// Recreate descriptor sets for all entities after swapchain/pipeline rebuild
334-
for (const auto& entity : entityResources | std::views::keys) {
335+
for (const auto& kv : entityResources) {
336+
const auto& entity = kv.first;
335337
if (!entity) continue;
336338
auto meshComponent = entity->GetComponent<MeshComponent>();
337339
if (!meshComponent) continue;

attachments/simple_engine/renderer_resources.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,8 @@ bool Renderer::createOrResizeLightStorageBuffers(size_t lightCount) {
18931893
void Renderer::updateAllDescriptorSetsWithNewLightBuffers() {
18941894
try {
18951895
// Iterate through all entity resources and update their PBR descriptor sets
1896-
for (auto& resources : entityResources | std::views::values) {
1896+
for (auto& kv : entityResources) {
1897+
auto& resources = kv.second;
18971898
// Only update PBR descriptor sets (they have light buffer bindings)
18981899
if (!resources.pbrDescriptorSets.empty()) {
18991900
for (size_t i = 0; i < resources.pbrDescriptorSets.size() && i < lightStorageBuffers.size(); ++i) {

attachments/simple_engine/resource_manager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ void Resource::Unload() {
1818
}
1919

2020
void ResourceManager::UnloadAllResources() {
21-
for (auto& val : resources | std::views::values) {
22-
for (auto& loadedResource : val | std::views::values) {
21+
for (auto& kv : resources) {
22+
auto& val = kv.second;
23+
for (auto& innerKv : val) {
24+
auto& loadedResource = innerKv.second;
2325
loadedResource->Unload();
2426
}
2527
val.clear();

0 commit comments

Comments
 (0)