summaryrefslogtreecommitdiff
path: root/video.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-27 18:52:48 +1100
committerquou <quou@disroot.org>2024-12-27 18:52:48 +1100
commitd920e5d62020d751ccaa3491cc66275ade749011 (patch)
treee806a95c598e255f9883de98cc350a3b9279d0ce /video.cpp
parente8c93463b2ae5114f0c88e768e5625abac9d5a50 (diff)
building and running on windows with visual studio
Diffstat (limited to 'video.cpp')
-rw-r--r--video.cpp32
1 files changed, 25 insertions, 7 deletions
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 <tuple>
#include <unordered_map>
-#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;