This commit is contained in:
Mars 2024-10-06 18:34:42 -04:00
parent 61a2e9367b
commit 79fdc8c38a
Signed by untrusted user: pupbrained
GPG key ID: 0FF5B8826803F895
2 changed files with 51 additions and 50 deletions

View file

@ -126,7 +126,7 @@
vulkanDir = "${mesa.drivers}/share/vulkan/icd.d"; vulkanDir = "${mesa.drivers}/share/vulkan/icd.d";
vulkanFiles = builtins.filter (file: builtins.match ".*\\.json$" file != null) (builtins.attrNames (builtins.readDir vulkanDir)); vulkanFiles = builtins.filter (file: builtins.match ".*\\.json$" file != null) (builtins.attrNames (builtins.readDir vulkanDir));
vulkanPaths = lib.concatStringsSep ":" (map (file: "${vulkanDir}/${file}") vulkanFiles); 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 = '' shellHook = ''
export PATH="${llvmPackages_18.clang-tools.override {enableLibcxx = true;}}/bin:$PATH" export PATH="${llvmPackages_18.clang-tools.override {enableLibcxx = true;}}/bin:$PATH"

View file

@ -604,55 +604,57 @@ class VulkanApp {
} }
fn drawFrame() -> void { 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<vk::PipelineStageFlags, 1> 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 { 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<vk::PipelineStageFlags, 1> 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); vk::Result presentResult = mPresentQueue.presentKHR(presentInfo);
fmt::println("Present result: {}", vk::to_string(presentResult)); fmt::println("Present result: {}", vk::to_string(presentResult));
@ -667,7 +669,6 @@ class VulkanApp {
mCurrentFrame = (mCurrentFrame + 1) % MAX_FRAMES_IN_FLIGHT; mCurrentFrame = (mCurrentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
} catch (vk::OutOfDateKHRError& err) { } catch (vk::OutOfDateKHRError& err) {
fmt::println("Caught OutOfDateKHRError: {}", err.what());
mFramebufferResized = false; mFramebufferResized = false;
recreateSwapChain(); recreateSwapChain();
return; return;