From d920e5d62020d751ccaa3491cc66275ade749011 Mon Sep 17 00:00:00 2001 From: quou Date: Fri, 27 Dec 2024 18:52:48 +1100 Subject: building and running on windows with visual studio --- video.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'video.cpp') diff --git a/video.cpp b/video.cpp index e5a42dc..6677bbc 100644 --- a/video.cpp +++ b/video.cpp @@ -24,10 +24,15 @@ extern "C" { #include #include -#define VK_USE_PLATFORM_XLIB_KHR -#define GLAD_VULKAN_IMPLEMENTATION #include "glad_vk.h" +#ifdef min /* use std::min and max instead */ +#undef min +#endif +#ifdef max +#undef max +#endif + const char* device_exts[] = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME @@ -211,7 +216,7 @@ VkImageLayout state_to_image_layout(Resource_State s) { return VK_IMAGE_LAYOUT_UNDEFINED; } -static void* vk_alloc( +static void* __stdcall vk_alloc( void* uptr, size_t size, size_t alignment, @@ -233,15 +238,16 @@ static void* vk_alloc( return r; } -static void vk_free( +static void __stdcall vk_free( void* uptr, void* ptr ) { Device* d = (Device*)uptr; + if (!ptr) return; heap_free(d->heap, ptr); } -static void* vk_realloc( +static void* __stdcall vk_realloc( void* uptr, void* old, size_t size, @@ -342,6 +348,7 @@ struct Swapchain { VkSurfaceFormatKHR format; VkExtent2D size; VkPresentModeKHR mode; + VkSemaphore image_avail; int image_count; void init(const App& app, Device_Vk* dev); @@ -1527,6 +1534,16 @@ void Swapchain::initr(const App& app, Device_Vk* dev) { pbreak(r); } } + { + VkResult r; + VkSemaphoreCreateInfo si{}; + si.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + r = vkCreateSemaphore(dev->dev, &si, &dev->ac, &image_avail); + if (r != VK_SUCCESS) { + print_err("Failed to create a semaphore.\n"); + pbreak(r); + } + } get_images(dev); } @@ -1595,6 +1612,7 @@ void Swapchain::destroy(Device_Vk* dev) { int i; for (i = 0; i < image_count; i++) dev->destroy_texture(textures[i]); + vkDestroySemaphore(dev->dev, image_avail, &dev->ac); vkDestroySwapchainKHR(dev->dev, swapchain, &dev->ac); heap_free(dev->heap, textures); textures = 0; @@ -1636,7 +1654,7 @@ void Device::begin_frame() { dev->dev, dev->swapchain.swapchain, UINT64_MAX, - dev->current_ctx->semaphore, + dev->swapchain.image_avail, VK_NULL_HANDLE, &dev->backbuffer_index ); @@ -1675,7 +1693,7 @@ void Device::present() { ); si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; si.waitSemaphoreCount = 1; - si.pWaitSemaphores = &ctx->semaphore; + si.pWaitSemaphores = &dev->swapchain.image_avail; si.pWaitDstStageMask = &stage; si.signalSemaphoreCount = 1; si.pSignalSemaphores = &ctx->semaphore; -- cgit v1.2.3-54-g00ecf