diff --git a/flake.nix b/flake.nix index d2ad8c9..8cd7599 100644 --- a/flake.nix +++ b/flake.nix @@ -126,7 +126,7 @@ vulkanDir = "${mesa.drivers}/share/vulkan/icd.d"; vulkanFiles = builtins.filter (file: builtins.match ".*\\.json$" file != null) (builtins.attrNames (builtins.readDir vulkanDir)); vulkanPaths = lib.concatStringsSep ":" (map (file: "${vulkanDir}/${file}") vulkanFiles); - in "${linuxPackages_latest.nvidia_x11}/share/vulkan/icd.d/nvidia_icd.x86_64.json:${vulkanPaths}"; + in "${linuxPackages_latest.nvidia_x11_vulkan_beta}/share/vulkan/icd.d/nvidia_icd.x86_64.json:${vulkanPaths}"; shellHook = '' export PATH="${llvmPackages_18.clang-tools.override {enableLibcxx = true;}}/bin:$PATH" diff --git a/src/main.cpp b/src/main.cpp index 08d7e08..212db98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -604,55 +604,57 @@ class VulkanApp { } fn drawFrame() -> void { - vk::Result result = - mDevice->waitForFences(mInFlightFences[mCurrentFrame].get(), vk::Bool32(vk::True), UINT64_MAX); - - if (result != vk::Result::eSuccess) - throw std::runtime_error("Failed to wait for fences!"); - - vk::Result imageIndexResult = vk::Result::eSuccess; - u32 imageIndexValue = 0; - - std::tie(imageIndexResult, imageIndexValue) = mDevice->acquireNextImageKHR( - mSwapChain.get(), UINT64_MAX, mImageAvailableSemaphores[mCurrentFrame].get(), nullptr - ); - - if (imageIndexResult == vk::Result::eErrorOutOfDateKHR) { - recreateSwapChain(); - return; - } - - if (imageIndexResult != vk::Result::eSuccess && imageIndexResult != vk::Result::eSuboptimalKHR) - throw std::runtime_error("Failed to acquire swap chain image!"); - - mDevice->resetFences(mInFlightFences[mCurrentFrame].get()); - - mCommandBuffers[mCurrentFrame]->reset(vk::CommandBufferResetFlagBits::eReleaseResources); - recordCommandBuffer(mCommandBuffers[mCurrentFrame].get(), imageIndexValue); - - std::array waitStages = { vk::PipelineStageFlagBits::eColorAttachmentOutput }; - - vk::SubmitInfo submitInfo { - .waitSemaphoreCount = 1, - .pWaitSemaphores = &mImageAvailableSemaphores[mCurrentFrame].get(), - .pWaitDstStageMask = waitStages.data(), - .commandBufferCount = 1, - .pCommandBuffers = &mCommandBuffers[mCurrentFrame].get(), - .signalSemaphoreCount = 1, - .pSignalSemaphores = &mRenderFinishedSemaphores[mCurrentFrame].get(), - }; - - mGraphicsQueue.submit(submitInfo, mInFlightFences[mCurrentFrame].get()); - - vk::PresentInfoKHR presentInfo { - .waitSemaphoreCount = 1, - .pWaitSemaphores = &mRenderFinishedSemaphores[mCurrentFrame].get(), - .swapchainCount = 1, - .pSwapchains = &mSwapChain.get(), - .pImageIndices = &imageIndexValue, - }; - try { + vk::Result result = + mDevice->waitForFences(mInFlightFences[mCurrentFrame].get(), vk::Bool32(vk::True), UINT64_MAX); + + if (result != vk::Result::eSuccess) + throw std::runtime_error("Failed to wait for fences!"); + + vk::Result imageIndexResult = vk::Result::eSuccess; + u32 imageIndexValue = 0; + + std::tie(imageIndexResult, imageIndexValue) = mDevice->acquireNextImageKHR( + mSwapChain.get(), UINT64_MAX, mImageAvailableSemaphores[mCurrentFrame].get(), nullptr + ); + + if (imageIndexResult == vk::Result::eErrorOutOfDateKHR) { + recreateSwapChain(); + return; + } + + if (imageIndexResult != vk::Result::eSuccess && imageIndexResult != vk::Result::eSuboptimalKHR) + throw std::runtime_error("Failed to acquire swap chain image!"); + + mDevice->resetFences(mInFlightFences[mCurrentFrame].get()); + + mCommandBuffers[mCurrentFrame]->reset(vk::CommandBufferResetFlagBits::eReleaseResources); + recordCommandBuffer(mCommandBuffers[mCurrentFrame].get(), imageIndexValue); + + std::array waitStages = { + vk::PipelineStageFlagBits::eColorAttachmentOutput + }; + + vk::SubmitInfo submitInfo { + .waitSemaphoreCount = 1, + .pWaitSemaphores = &mImageAvailableSemaphores[mCurrentFrame].get(), + .pWaitDstStageMask = waitStages.data(), + .commandBufferCount = 1, + .pCommandBuffers = &mCommandBuffers[mCurrentFrame].get(), + .signalSemaphoreCount = 1, + .pSignalSemaphores = &mRenderFinishedSemaphores[mCurrentFrame].get(), + }; + + mGraphicsQueue.submit(submitInfo, mInFlightFences[mCurrentFrame].get()); + + vk::PresentInfoKHR presentInfo { + .waitSemaphoreCount = 1, + .pWaitSemaphores = &mRenderFinishedSemaphores[mCurrentFrame].get(), + .swapchainCount = 1, + .pSwapchains = &mSwapChain.get(), + .pImageIndices = &imageIndexValue, + }; + vk::Result presentResult = mPresentQueue.presentKHR(presentInfo); fmt::println("Present result: {}", vk::to_string(presentResult)); @@ -667,7 +669,6 @@ class VulkanApp { mCurrentFrame = (mCurrentFrame + 1) % MAX_FRAMES_IN_FLIGHT; } catch (vk::OutOfDateKHRError& err) { - fmt::println("Caught OutOfDateKHRError: {}", err.what()); mFramebufferResized = false; recreateSwapChain(); return;