Cleaned up the code but had to add -Wno-sign-conversion to get glm to shut up.

This commit is contained in:
Zed A. Shaw 2025-11-25 10:56:18 -05:00
parent 8a7ef61c78
commit 55e38788b4
4 changed files with 30 additions and 21 deletions

View file

@ -10,7 +10,7 @@ project('hellovulk', 'cpp',
cmake = import('cmake')
# use this for common options only for our executables
cpp_args=[]
cpp_args=['-Wno-sign-conversion']
link_args=[]
# these are passed as override_defaults
exe_defaults = [ 'warning_level=2' ]
@ -56,16 +56,24 @@ elif build_machine.system() == 'darwin'
endif
vma = subproject('vulkan-memory-allocator').get_variable('vma_allocator_dep')
glm = subproject('glm').get_variable('glm_dep')
imgui = subproject('imgui').get_variable('imgui_dep')
sdl2 = subproject('sdl2').get_variable('sdl2_dep')
opts = cmake.subproject_options()
opts.add_cmake_defines({
glm_opts = cmake.subproject_options()
glm_opts.add_cmake_defines({
'GLM_ENABLE_CXX_20': true,
})
glm_proj = cmake.subproject('glm', options: glm_opts)
glm = glm_proj.get_variable('glm_dep')
vk_opts = cmake.subproject_options()
vk_opts.add_cmake_defines({
'VK_BOOTSTRAP_TEST': false,
'VK_BOOTSTRAP_INSTALL': false,
})
vkbootstrap_proj = cmake.subproject('vk-bootstrap', options: opts)
vkbootstrap_proj = cmake.subproject('vk-bootstrap', options: vk_opts)
vkbootstrap = vkbootstrap_proj.get_variable('vk_bootstrap_dep')
dependencies += [

View file

@ -1,8 +1,4 @@
/*
* Stopped at https://vkguide.dev/docs/new_chapter_1/vulkan_mainloop_code/
*/
#include "vk_engine.h"
#include "vk_engine.h"
#include "vk_images.h"
#include <print>
@ -56,7 +52,7 @@ void VulkanEngine::cleanup()
if (_isInitialized) {
vkDeviceWaitIdle(_device);
for(int i = 0; i < FRAME_OVERLAP; i++) {
for(size_t i = 0; i < FRAME_OVERLAP; i++) {
vkDestroyCommandPool(_device, _frames[i]._commandPool, nullptr);
//destroy sync objects
@ -96,7 +92,7 @@ void VulkanEngine::draw()
vkutil::transition_image(cmd, _swapchainImages[swapchainImageIndex], VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
VkClearColorValue clearValue;
float flash = std::abs(std::sin(_frameNumber / 120.0f));
float flash = std::abs(std::sin(float(_frameNumber) / 120.0f));
clearValue = { { 0.0f, 0.0f, flash, 1.0f} };
VkImageSubresourceRange clearRange = vkinit::image_subresource_range(VK_IMAGE_ASPECT_COLOR_BIT);
@ -199,12 +195,15 @@ void VulkanEngine::init_vulkan() {
SDL_Vulkan_CreateSurface(_window, _instance, &_surface);
//vulkan 1.3 features
VkPhysicalDeviceVulkan13Features features{ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES };
VkPhysicalDeviceVulkan13Features features{};
features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
features.dynamicRendering = true;
features.synchronization2 = true;
//vulkan 1.2 features
VkPhysicalDeviceVulkan12Features features12{ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES };
VkPhysicalDeviceVulkan12Features features12{};
features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
features12.bufferDeviceAddress = true;
features12.descriptorIndexing = true;
@ -231,12 +230,14 @@ void VulkanEngine::init_vulkan() {
void VulkanEngine::create_swapchain(uint32_t width, uint32_t height) {
vkb::SwapchainBuilder swapchainBuilder{ _chosenGPU, _device, _surface};
_swapchainImageFormat = VK_FORMAT_B8G8R8A8_UNORM;
VkSurfaceFormatKHR surfaceFormat{};
surfaceFormat.format=_swapchainImageFormat;
vkb::Swapchain vkbSwapchain = swapchainBuilder
//.use_default_format_selection()
.set_desired_format(VkSurfaceFormatKHR{.format=_swapchainImageFormat})
.set_desired_format(surfaceFormat)
// use vsync present mode
.set_desired_present_mode(VK_PRESENT_MODE_FIFO_KHR)
.set_desired_extent(width, height)
@ -267,7 +268,7 @@ void VulkanEngine::init_commands() {
//we also want the pool to allow for resetting of individual command buffers
VkCommandPoolCreateInfo commandPoolInfo = vkinit::command_pool_create_info(_graphicsQueueFamily, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
for (int i = 0; i < FRAME_OVERLAP; i++) {
for (size_t i = 0; i < FRAME_OVERLAP; i++) {
VK_CHECK(vkCreateCommandPool(_device, &commandPoolInfo, nullptr, &_frames[i]._commandPool));
@ -282,7 +283,7 @@ void VulkanEngine::init_sync_structures() {
VkFenceCreateInfo fenceCreateInfo = vkinit::fence_create_info(VK_FENCE_CREATE_SIGNALED_BIT);
VkSemaphoreCreateInfo semaphoreCreateInfo = vkinit::semaphore_create_info();
for (int i = 0; i < FRAME_OVERLAP; i++) {
for (size_t i = 0; i < FRAME_OVERLAP; i++) {
VK_CHECK(vkCreateFence(_device, &fenceCreateInfo, nullptr, &_frames[i]._renderFence));
VK_CHECK(vkCreateSemaphore(_device, &semaphoreCreateInfo, nullptr, &_frames[i]._swapchainSemaphore));

View file

@ -33,7 +33,7 @@ public:
VkExtent2D _swapchainExtent;
// frames/command buffer
int _frameNumber {0};
unsigned int _frameNumber = 0;
FrameData _frames[FRAME_OVERLAP];
FrameData& get_current_frame() {

View file

@ -3,7 +3,8 @@
void vkutil::transition_image(VkCommandBuffer cmd, VkImage image, VkImageLayout currentLayout, VkImageLayout newLayout)
{
VkImageMemoryBarrier2 imageBarrier {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2};
VkImageMemoryBarrier2 imageBarrier{};
imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
imageBarrier.pNext = nullptr;
imageBarrier.srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
@ -22,7 +23,6 @@ void vkutil::transition_image(VkCommandBuffer cmd, VkImage image, VkImageLayout
VkDependencyInfo depInfo{};
depInfo.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
depInfo.pNext = nullptr;
depInfo.imageMemoryBarrierCount = 1;
depInfo.pImageMemoryBarriers = &imageBarrier;