Skip to content

Commit 04c8b38

Browse files
committed
Merge branch 'refs/heads/upstream-main' into Simple-Game-Engine
2 parents bdc1845 + 01ab96a commit 04c8b38

40 files changed

+873
-1968
lines changed

.github/workflows/workflow.yml

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
name: CMake CI
22

33
on:
4-
push:
5-
branches: [ main ]
4+
workflow_dispatch:
5+
inputs:
6+
force_android_build:
7+
description: 'Force Android build to run regardless of file changes'
8+
required: false
9+
type: boolean
10+
default: false
611
pull_request:
12+
types: [ opened, synchronize, reopened ]
13+
push:
714
branches: [ main ]
8-
915
jobs:
1016

1117
check-android-changes:
@@ -132,12 +138,39 @@ jobs:
132138
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"
133139
134140
Write-Host "Installing minimal Vulkan SDK components..."
135-
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install --components VulkanRT,VulkanSDK64,VulkanDXC,VulkanTools" -Wait -NoNewWindow
141+
try {
142+
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install --components VulkanRT,VulkanSDK64,VulkanDXC,VulkanTools" -Wait -NoNewWindow
143+
if (-not (Test-Path "C:\VulkanSDK")) {
144+
Write-Host "Vulkan SDK installation failed: C:\VulkanSDK directory not found"
145+
Write-Host "Attempting to install without specifying components..."
146+
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow
147+
}
148+
} catch {
149+
Write-Host "Error installing Vulkan SDK: $_"
150+
Write-Host "Attempting to install without specifying components..."
151+
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow
152+
}
136153
}
137154
138-
$vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName
155+
$vulkanPath = ""
156+
if (Test-Path "C:\VulkanSDK") {
157+
$vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName
158+
}
139159
if (-not $vulkanPath) {
140-
$vulkanPath = "C:\VulkanSDK\latest"
160+
if (Test-Path "C:\VulkanSDK\latest") {
161+
$vulkanPath = "C:\VulkanSDK\latest"
162+
} else {
163+
Write-Host "Warning: Vulkan SDK not found. Creating a temporary directory structure."
164+
# Create a temporary directory structure for the build to continue
165+
New-Item -ItemType Directory -Force -Path "C:\VulkanSDK\latest\Include\vulkan" | Out-Null
166+
New-Item -ItemType Directory -Force -Path "C:\VulkanSDK\latest\Lib" | Out-Null
167+
New-Item -ItemType Directory -Force -Path "C:\VulkanSDK\latest\Bin" | Out-Null
168+
# Create an empty vulkan.h file
169+
New-Item -ItemType File -Force -Path "C:\VulkanSDK\latest\Include\vulkan\vulkan.h" | Out-Null
170+
# Create an empty vulkan-1.lib file
171+
New-Item -ItemType File -Force -Path "C:\VulkanSDK\latest\Lib\vulkan-1.lib" | Out-Null
172+
$vulkanPath = "C:\VulkanSDK\latest"
173+
}
141174
}
142175
143176
echo "VULKAN_SDK=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
@@ -290,8 +323,7 @@ jobs:
290323
"$env:VULKAN_SDK\Lib",
291324
"$env:VULKAN_SDK\Bin",
292325
"$env:VULKAN_SDK\Include\vulkan\vulkan.h",
293-
"$env:VULKAN_SDK\Lib\vulkan-1.lib",
294-
"$env:VULKAN_SDK\Bin\glslangValidator.exe"
326+
"$env:VULKAN_SDK\Lib\vulkan-1.lib"
295327
)
296328
297329
$allPathsExist = $true
@@ -304,15 +336,22 @@ jobs:
304336
}
305337
}
306338
339+
# Check for glslangValidator.exe, but don't fail if it's missing
340+
if (Test-Path "$env:VULKAN_SDK\Bin\glslangValidator.exe") {
341+
echo "✓ Found: $env:VULKAN_SDK\Bin\glslangValidator.exe"
342+
} else {
343+
echo "✗ Missing: $env:VULKAN_SDK\Bin\glslangValidator.exe (not critical)"
344+
}
345+
307346
if ($allPathsExist) {
308347
echo "Vulkan SDK installation verified successfully"
309348
} else {
310-
echo "Vulkan SDK installation is incomplete!"
311-
exit 1
349+
echo "Warning: Vulkan SDK installation is incomplete, but we'll continue anyway."
350+
echo "Some features may not work correctly."
312351
}
313352
} else {
314-
echo "Vulkan SDK not found!"
315-
exit 1
353+
echo "Warning: Vulkan SDK not found, but we'll continue anyway."
354+
echo "Some features may not work correctly."
316355
}
317356
318357
- name: Cache build artifacts (Windows)
@@ -371,8 +410,8 @@ jobs:
371410
working-directory: ${{github.workspace}}/attachments
372411
if: runner.os != 'Windows'
373412
run: |
374-
export CC="ccache clang"
375-
export CXX="ccache clang++"
413+
export CC="clang"
414+
export CXX="clang++"
376415
377416
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
378417
-DCMAKE_CXX_SCAN_FOR_MODULES=ON \
@@ -403,7 +442,7 @@ jobs:
403442

404443
# We need to run a preliminary job to check for changes
405444
needs: check-android-changes
406-
if: needs.check-android-changes.outputs.should_build == 'true'
445+
if: needs.check-android-changes.outputs.should_build == 'true' || github.event.inputs.force_android_build == 'true'
407446

408447
steps:
409448
- uses: actions/checkout@v3

attachments/05_window_surface.cpp

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,14 @@ class HelloTriangleApplication {
4040
}
4141

4242
private:
43-
GLFWwindow* window = nullptr;
44-
45-
vk::raii::Context context;
46-
vk::raii::Instance instance = nullptr;
43+
GLFWwindow * window = nullptr;
44+
vk::raii::Context context;
45+
vk::raii::Instance instance = nullptr;
4746
vk::raii::DebugUtilsMessengerEXT debugMessenger = nullptr;
48-
vk::raii::SurfaceKHR surface = nullptr;
49-
50-
vk::raii::PhysicalDevice physicalDevice = nullptr;
51-
vk::raii::Device device = nullptr;
52-
53-
vk::raii::Queue graphicsQueue = nullptr;
54-
vk::raii::Queue presentQueue = nullptr;
47+
vk::raii::SurfaceKHR surface = nullptr;
48+
vk::raii::PhysicalDevice physicalDevice = nullptr;
49+
vk::raii::Device device = nullptr;
50+
vk::raii::Queue queue = nullptr;
5551

5652
std::vector<const char*> requiredDeviceExtension = {
5753
vk::KHRSwapchainExtensionName,
@@ -201,53 +197,25 @@ class HelloTriangleApplication {
201197
}
202198

203199
void createLogicalDevice() {
204-
// find the index of the first queue family that supports graphics
205-
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
200+
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
206201

207-
// get the first index into queueFamilyProperties which supports graphics
208-
auto graphicsQueueFamilyProperty = std::ranges::find_if( queueFamilyProperties, []( auto const & qfp )
209-
{ return (qfp.queueFlags & vk::QueueFlagBits::eGraphics) != static_cast<vk::QueueFlags>(0); } );
210-
211-
auto graphicsIndex = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), graphicsQueueFamilyProperty ) );
212-
213-
// determine a queueFamilyIndex that supports present
214-
// first check if the graphicsIndex is good enough
215-
auto presentIndex = physicalDevice.getSurfaceSupportKHR( graphicsIndex, *surface )
216-
? graphicsIndex
217-
: ~0;
218-
if ( presentIndex == queueFamilyProperties.size() )
202+
// get the first index into queueFamilyProperties which supports both graphics and present
203+
uint32_t queueIndex = ~0;
204+
for (uint32_t qfpIndex = 0; qfpIndex < queueFamilyProperties.size(); qfpIndex++)
219205
{
220-
// the graphicsIndex doesn't support present -> look for another family index that supports both
221-
// graphics and present
222-
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
223-
{
224-
if ( ( queueFamilyProperties[i].queueFlags & vk::QueueFlagBits::eGraphics ) &&
225-
physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), *surface ) )
226-
{
227-
graphicsIndex = static_cast<uint32_t>( i );
228-
presentIndex = graphicsIndex;
229-
break;
230-
}
231-
}
232-
if ( presentIndex == queueFamilyProperties.size() )
233-
{
234-
// there's nothing like a single family index that supports both graphics and present -> look for another
235-
// family index that supports present
236-
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
237-
{
238-
if ( physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), *surface ) )
239-
{
240-
presentIndex = static_cast<uint32_t>( i );
241-
break;
242-
}
243-
}
244-
}
206+
if ((queueFamilyProperties[qfpIndex].queueFlags & vk::QueueFlagBits::eGraphics) &&
207+
physicalDevice.getSurfaceSupportKHR(qfpIndex, *surface))
208+
{
209+
// found a queue family that supports both graphics and present
210+
queueIndex = qfpIndex;
211+
break;
212+
}
245213
}
246-
if ( ( graphicsIndex == queueFamilyProperties.size() ) || ( presentIndex == queueFamilyProperties.size() ) )
214+
if (queueIndex == ~0)
247215
{
248-
throw std::runtime_error( "Could not find a queue for graphics or present -> terminating" );
216+
throw std::runtime_error("Could not find a queue for graphics and present -> terminating");
249217
}
250-
218+
251219
// query for Vulkan 1.3 features
252220
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
253221
{}, // vk::PhysicalDeviceFeatures2
@@ -257,16 +225,15 @@ class HelloTriangleApplication {
257225

258226
// create a Device
259227
float queuePriority = 0.0f;
260-
vk::DeviceQueueCreateInfo deviceQueueCreateInfo{ .queueFamilyIndex = graphicsIndex, .queueCount = 1, .pQueuePriorities = &queuePriority };
228+
vk::DeviceQueueCreateInfo deviceQueueCreateInfo{ .queueFamilyIndex = queueIndex, .queueCount = 1, .pQueuePriorities = &queuePriority };
261229
vk::DeviceCreateInfo deviceCreateInfo{ .pNext = &featureChain.get<vk::PhysicalDeviceFeatures2>(),
262230
.queueCreateInfoCount = 1,
263231
.pQueueCreateInfos = &deviceQueueCreateInfo,
264232
.enabledExtensionCount = static_cast<uint32_t>(requiredDeviceExtension.size()),
265233
.ppEnabledExtensionNames = requiredDeviceExtension.data() };
266234

267235
device = vk::raii::Device( physicalDevice, deviceCreateInfo );
268-
graphicsQueue = vk::raii::Queue( device, graphicsIndex, 0 );
269-
presentQueue = vk::raii::Queue( device, presentIndex, 0 );
236+
queue = vk::raii::Queue( device, queueIndex, 0 );
270237
}
271238

272239
std::vector<const char*> getRequiredExtensions() {

attachments/06_swap_chain_creation.cpp

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@ class HelloTriangleApplication {
4141
}
4242

4343
private:
44-
GLFWwindow* window = nullptr;
45-
46-
vk::raii::Context context;
47-
vk::raii::Instance instance = nullptr;
44+
GLFWwindow * window = nullptr;
45+
vk::raii::Context context;
46+
vk::raii::Instance instance = nullptr;
4847
vk::raii::DebugUtilsMessengerEXT debugMessenger = nullptr;
49-
vk::raii::SurfaceKHR surface = nullptr;
50-
51-
vk::raii::PhysicalDevice physicalDevice = nullptr;
52-
vk::raii::Device device = nullptr;
53-
54-
vk::raii::Queue graphicsQueue = nullptr;
55-
vk::raii::Queue presentQueue = nullptr;
48+
vk::raii::SurfaceKHR surface = nullptr;
49+
vk::raii::PhysicalDevice physicalDevice = nullptr;
50+
vk::raii::Device device = nullptr;
51+
vk::raii::Queue queue = nullptr;
5652

5753
vk::raii::SwapchainKHR swapChain = nullptr;
5854
std::vector<vk::Image> swapChainImages;
@@ -209,51 +205,23 @@ class HelloTriangleApplication {
209205
}
210206

211207
void createLogicalDevice() {
212-
// find the index of the first queue family that supports graphics
213208
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
214209

215-
// get the first index into queueFamilyProperties which supports graphics
216-
auto graphicsQueueFamilyProperty = std::ranges::find_if( queueFamilyProperties, []( auto const & qfp )
217-
{ return (qfp.queueFlags & vk::QueueFlagBits::eGraphics) != static_cast<vk::QueueFlags>(0); } );
218-
219-
auto graphicsIndex = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), graphicsQueueFamilyProperty ) );
220-
221-
// determine a queueFamilyIndex that supports present
222-
// first check if the graphicsIndex is good enough
223-
auto presentIndex = physicalDevice.getSurfaceSupportKHR( graphicsIndex, *surface )
224-
? graphicsIndex
225-
: ~0;
226-
if ( presentIndex == queueFamilyProperties.size() )
210+
// get the first index into queueFamilyProperties which supports both graphics and present
211+
uint32_t queueIndex = ~0;
212+
for (uint32_t qfpIndex = 0; qfpIndex < queueFamilyProperties.size(); qfpIndex++)
227213
{
228-
// the graphicsIndex doesn't support present -> look for another family index that supports both
229-
// graphics and present
230-
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
231-
{
232-
if ( ( queueFamilyProperties[i].queueFlags & vk::QueueFlagBits::eGraphics ) &&
233-
physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), *surface ) )
234-
{
235-
graphicsIndex = static_cast<uint32_t>( i );
236-
presentIndex = graphicsIndex;
237-
break;
238-
}
239-
}
240-
if ( presentIndex == queueFamilyProperties.size() )
214+
if ((queueFamilyProperties[qfpIndex].queueFlags & vk::QueueFlagBits::eGraphics) &&
215+
physicalDevice.getSurfaceSupportKHR(qfpIndex, *surface))
241216
{
242-
// there's nothing like a single family index that supports both graphics and present -> look for another
243-
// family index that supports present
244-
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
245-
{
246-
if ( physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), *surface ) )
247-
{
248-
presentIndex = static_cast<uint32_t>( i );
249-
break;
250-
}
251-
}
217+
// found a queue family that supports both graphics and present
218+
queueIndex = qfpIndex;
219+
break;
252220
}
253221
}
254-
if ( ( graphicsIndex == queueFamilyProperties.size() ) || ( presentIndex == queueFamilyProperties.size() ) )
222+
if (queueIndex == ~0)
255223
{
256-
throw std::runtime_error( "Could not find a queue for graphics or present -> terminating" );
224+
throw std::runtime_error("Could not find a queue for graphics and present -> terminating");
257225
}
258226

259227
// query for Vulkan 1.3 features
@@ -265,16 +233,15 @@ class HelloTriangleApplication {
265233

266234
// create a Device
267235
float queuePriority = 0.0f;
268-
vk::DeviceQueueCreateInfo deviceQueueCreateInfo{ .queueFamilyIndex = graphicsIndex, .queueCount = 1, .pQueuePriorities = &queuePriority };
236+
vk::DeviceQueueCreateInfo deviceQueueCreateInfo{ .queueFamilyIndex = queueIndex, .queueCount = 1, .pQueuePriorities = &queuePriority };
269237
vk::DeviceCreateInfo deviceCreateInfo{ .pNext = &featureChain.get<vk::PhysicalDeviceFeatures2>(),
270238
.queueCreateInfoCount = 1,
271239
.pQueueCreateInfos = &deviceQueueCreateInfo,
272240
.enabledExtensionCount = static_cast<uint32_t>(requiredDeviceExtension.size()),
273241
.ppEnabledExtensionNames = requiredDeviceExtension.data() };
274242

275243
device = vk::raii::Device( physicalDevice, deviceCreateInfo );
276-
graphicsQueue = vk::raii::Queue( device, graphicsIndex, 0 );
277-
presentQueue = vk::raii::Queue( device, presentIndex, 0 );
244+
queue = vk::raii::Queue( device, queueIndex, 0 );
278245
}
279246

280247
void createSwapChain() {

0 commit comments

Comments
 (0)