Skip to content

Commit

Permalink
Fix window creation issue #13
Browse files Browse the repository at this point in the history
  • Loading branch information
nyorain committed Mar 19, 2024
1 parent f7ca613 commit ee29058
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,17 +1079,14 @@ VkResult doCreateDevice(
// init command hook
dev.commandHook = std::make_unique<CommandHook>(dev);

// == window stuff ==
#ifdef VIL_WITH_SWA
if(window) {
dlg_assert(window->presentQueue); // should have been set in queue querying
dlg_assert(window->presentQueue);
dev.window = std::move(window);

if(standaloneMode) {
dev.window->dev = &dev;
dev.window->doInitSwapchain();
} else {
dev.window->initDevice(dev);
}
}
#endif // VIL_WITH_SWA
Expand Down Expand Up @@ -1311,6 +1308,19 @@ VkFormat findDepthFormat(const Device& dev) {
return findSupported(dev, fmts, img, features);
}

// This delayed initialization is needed because we cannot
// call vulkan functions (such as CreateSwapchain) inside window
// creation, where we'd ideally initialize the window.
// https://github.com/KhronosGroup/Vulkan-Loader/pull/1049 broke
// this. We now have to make sure to make it later on.
void checkInitWindow(Device& dev) {
#ifdef VIL_WITH_SWA
if(dev.window && !dev.window->dev) {
dev.window->initDevice(dev);
}
#endif // VIL_WITH_SWA
}

// NOTE: doesn't really belong here
thread_local ThreadContext ThreadContext::instance;

Expand Down
3 changes: 3 additions & 0 deletions src/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ struct Device {
void notifyApiHandleDestroyedLocked(Device& dev, Handle& handle, VkObjectType type);
void notifyMemoryResourceInvalidatedLocked(Device& dev, MemoryResource& res);

// Lazily initializes the window, if needed.
void checkInitWindow(Device& dev);

// Util for naming internal handles.
// Mainly useful to get better validation layer output for stuff
// we do inside the layer. Should never be used on any non-internal
Expand Down
2 changes: 2 additions & 0 deletions src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(
VkDeviceMemory* pMemory) {
auto& dev = getDevice(device);

checkInitWindow(dev);

ThreadMemScope memScope;
auto chainCopy = copyChainLocal(memScope, pAllocateInfo->pNext);
auto allocInfo = *pAllocateInfo;
Expand Down
3 changes: 2 additions & 1 deletion src/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <buffer.hpp>
#include <image.hpp>
#include <submit.hpp>
#include <deque>
#include <gui/gui.hpp>
#include <commandHook/submission.hpp>
#include <util/util.hpp>
Expand Down Expand Up @@ -163,6 +162,8 @@ VkResult doSubmit(Queue& queue, span<const VkSubmitInfo2> submits,
ZoneScoped;
auto& dev = *queue.dev;

checkInitWindow(dev);

QueueSubmitter submitter {};
init(submitter, queue, SubmissionType::command, fence);

Expand Down

0 comments on commit ee29058

Please sign in to comment.