testing stuff
This commit is contained in:
parent
1eade711ba
commit
7762cb4712
205
src/main.cpp
205
src/main.cpp
|
@ -41,40 +41,40 @@ class VulkanApp {
|
||||||
initWindow();
|
initWindow();
|
||||||
initVulkan();
|
initVulkan();
|
||||||
mainLoop();
|
mainLoop();
|
||||||
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vkfw::UniqueInstance mGLFWInstance;
|
vkfw::Window mWindow;
|
||||||
vkfw::UniqueWindow mWindow;
|
|
||||||
|
|
||||||
vk::UniqueInstance mInstance;
|
vk::Instance mInstance;
|
||||||
|
|
||||||
vk::UniqueDebugUtilsMessengerEXT mDebugMessenger;
|
vk::DebugUtilsMessengerEXT mDebugMessenger;
|
||||||
vk::UniqueSurfaceKHR mSurface;
|
vk::SurfaceKHR mSurface;
|
||||||
|
|
||||||
vk::PhysicalDevice mPhysicalDevice;
|
vk::PhysicalDevice mPhysicalDevice;
|
||||||
vk::UniqueDevice mDevice;
|
vk::Device mDevice;
|
||||||
|
|
||||||
vk::Queue mGraphicsQueue;
|
vk::Queue mGraphicsQueue;
|
||||||
vk::Queue mPresentQueue;
|
vk::Queue mPresentQueue;
|
||||||
|
|
||||||
vk::UniqueSwapchainKHR mSwapChain;
|
vk::SwapchainKHR mSwapChain;
|
||||||
std::vector<vk::Image> mSwapChainImages;
|
std::vector<vk::Image> mSwapChainImages;
|
||||||
vk::Format mSwapChainImageFormat;
|
vk::Format mSwapChainImageFormat;
|
||||||
vk::Extent2D mSwapChainExtent;
|
vk::Extent2D mSwapChainExtent;
|
||||||
std::vector<vk::UniqueImageView> mSwapChainImageViews;
|
std::vector<vk::ImageView> mSwapChainImageViews;
|
||||||
std::vector<vk::UniqueFramebuffer> mSwapChainFramebuffers;
|
std::vector<vk::Framebuffer> mSwapChainFramebuffers;
|
||||||
|
|
||||||
vk::UniqueRenderPass mRenderPass;
|
vk::RenderPass mRenderPass;
|
||||||
vk::UniquePipelineLayout mPipelineLayout;
|
vk::PipelineLayout mPipelineLayout;
|
||||||
vk::UniquePipeline mGraphicsPipeline;
|
vk::Pipeline mGraphicsPipeline;
|
||||||
|
|
||||||
vk::UniqueCommandPool mCommandPool;
|
vk::CommandPool mCommandPool;
|
||||||
std::vector<vk::UniqueCommandBuffer> mCommandBuffers;
|
std::vector<vk::CommandBuffer> mCommandBuffers;
|
||||||
|
|
||||||
std::vector<vk::UniqueSemaphore> mImageAvailableSemaphores;
|
std::vector<vk::Semaphore> mImageAvailableSemaphores;
|
||||||
std::vector<vk::UniqueSemaphore> mRenderFinishedSemaphores;
|
std::vector<vk::Semaphore> mRenderFinishedSemaphores;
|
||||||
std::vector<vk::UniqueFence> mInFlightFences;
|
std::vector<vk::Fence> mInFlightFences;
|
||||||
|
|
||||||
bool mFramebufferResized = false;
|
bool mFramebufferResized = false;
|
||||||
u32 mCurrentFrame = 0;
|
u32 mCurrentFrame = 0;
|
||||||
|
@ -110,16 +110,16 @@ class VulkanApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initWindow() -> void {
|
fn initWindow() -> void {
|
||||||
mGLFWInstance = vkfw::initUnique();
|
vkfw::init();
|
||||||
|
|
||||||
vkfw::WindowHints hints;
|
vkfw::WindowHints hints;
|
||||||
|
|
||||||
hints.clientAPI = vkfw::ClientAPI::eNone;
|
hints.clientAPI = vkfw::ClientAPI::eNone;
|
||||||
// hints.resizable = false;
|
// hints.resizable = false;
|
||||||
|
|
||||||
mWindow = vkfw::createWindowUnique(WIDTH, HEIGHT, "Vulkan", hints);
|
mWindow = vkfw::createWindow(WIDTH, HEIGHT, "Vulkan", hints);
|
||||||
mWindow->setUserPointer(this);
|
mWindow.setUserPointer(this);
|
||||||
mWindow->setFramebufferSizeCallback(framebufferResizeCallback);
|
mWindow.setFramebufferSizeCallback(framebufferResizeCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fn framebufferResizeCallback(GLFWwindow* window, int /*width*/, int /*height*/) -> void {
|
static fn framebufferResizeCallback(GLFWwindow* window, int /*width*/, int /*height*/) -> void {
|
||||||
|
@ -145,33 +145,67 @@ class VulkanApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mainLoop() -> void {
|
fn mainLoop() -> void {
|
||||||
while (!mWindow->shouldClose()) {
|
while (!mWindow.shouldClose()) {
|
||||||
vkfw::waitEvents();
|
vkfw::waitEvents();
|
||||||
drawFrame();
|
drawFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
mDevice->waitIdle();
|
mDevice.waitIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanupSwapChain() -> void {
|
fn cleanupSwapChain() -> void {
|
||||||
for (vk::UniqueFramebuffer& mSwapChainFramebuffer : mSwapChainFramebuffers) {
|
for (vk::Framebuffer& mSwapChainFramebuffer : mSwapChainFramebuffers) {
|
||||||
mSwapChainFramebuffer.reset();
|
mDevice.destroyFramebuffer(mSwapChainFramebuffer);
|
||||||
|
}
|
||||||
|
for (vk::ImageView& mSwapChainImageView : mSwapChainImageViews) {
|
||||||
|
mDevice.destroyImageView(mSwapChainImageView);
|
||||||
}
|
}
|
||||||
for (vk::UniqueImageView& mSwapChainImageView : mSwapChainImageViews) { mSwapChainImageView.reset(); }
|
|
||||||
|
|
||||||
mSwapChain.reset();
|
mDevice.destroySwapchainKHR(mSwapChain);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup() -> void {
|
||||||
|
cleanupSwapChain();
|
||||||
|
|
||||||
|
mDevice.destroyPipeline(mGraphicsPipeline);
|
||||||
|
mDevice.destroyPipelineLayout(mPipelineLayout);
|
||||||
|
|
||||||
|
mDevice.destroyRenderPass(mRenderPass);
|
||||||
|
|
||||||
|
for (vk::Semaphore& mRenderFinishedSemaphore : mRenderFinishedSemaphores)
|
||||||
|
mDevice.destroySemaphore(mRenderFinishedSemaphore);
|
||||||
|
|
||||||
|
for (vk::Semaphore& mImageAvailableSemaphore : mImageAvailableSemaphores)
|
||||||
|
mDevice.destroySemaphore(mImageAvailableSemaphore);
|
||||||
|
|
||||||
|
for (vk::Fence& mInFlightFence : mInFlightFences) mDevice.destroyFence(mInFlightFence);
|
||||||
|
|
||||||
|
mDevice.destroyCommandPool(mCommandPool);
|
||||||
|
|
||||||
|
mDevice.destroy();
|
||||||
|
|
||||||
|
if (enableValidationLayers)
|
||||||
|
mInstance.destroyDebugUtilsMessengerEXT(mDebugMessenger, nullptr);
|
||||||
|
|
||||||
|
mInstance.destroySurfaceKHR(mSurface);
|
||||||
|
|
||||||
|
vkDestroyInstance(mInstance, nullptr);
|
||||||
|
|
||||||
|
mWindow.destroy();
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recreateSwapChain() -> void {
|
fn recreateSwapChain() -> void {
|
||||||
u32 width = 0, height = 0;
|
u32 width = 0, height = 0;
|
||||||
std::tie(width, height) = mWindow->getFramebufferSize();
|
std::tie(width, height) = mWindow.getFramebufferSize();
|
||||||
|
|
||||||
while (width == 0 || height == 0) {
|
while (width == 0 || height == 0) {
|
||||||
std::tie(width, height) = mWindow->getFramebufferSize();
|
std::tie(width, height) = mWindow.getFramebufferSize();
|
||||||
vkfw::waitEvents();
|
vkfw::waitEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
mDevice->waitIdle();
|
mDevice.waitIdle();
|
||||||
|
|
||||||
cleanupSwapChain();
|
cleanupSwapChain();
|
||||||
|
|
||||||
|
@ -219,9 +253,9 @@ class VulkanApp {
|
||||||
for (const char* extension : extensions) fmt::println("\t{}", extension);
|
for (const char* extension : extensions) fmt::println("\t{}", extension);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mInstance = vk::createInstanceUnique(createInfo);
|
mInstance = vk::createInstance(createInfo);
|
||||||
|
|
||||||
VULKAN_HPP_DEFAULT_DISPATCHER.init(mInstance.get());
|
VULKAN_HPP_DEFAULT_DISPATCHER.init(mInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setupDebugMessenger() -> void {
|
fn setupDebugMessenger() -> void {
|
||||||
|
@ -238,13 +272,13 @@ class VulkanApp {
|
||||||
.pfnUserCallback = debugCallback,
|
.pfnUserCallback = debugCallback,
|
||||||
};
|
};
|
||||||
|
|
||||||
mDebugMessenger = mInstance->createDebugUtilsMessengerEXTUnique(messengerCreateInfo, nullptr);
|
mDebugMessenger = mInstance.createDebugUtilsMessengerEXT(messengerCreateInfo, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createSurface() -> void { mSurface = vkfw::createWindowSurfaceUnique(mInstance.get(), mWindow.get()); }
|
fn createSurface() -> void { mSurface = vkfw::createWindowSurface(mInstance, mWindow); }
|
||||||
|
|
||||||
fn pickPhysicalDevice() -> void {
|
fn pickPhysicalDevice() -> void {
|
||||||
std::vector<vk::PhysicalDevice> devices = mInstance->enumeratePhysicalDevices();
|
std::vector<vk::PhysicalDevice> devices = mInstance.enumeratePhysicalDevices();
|
||||||
|
|
||||||
if (devices.empty())
|
if (devices.empty())
|
||||||
throw std::runtime_error("Failed to find GPUs with Vulkan support!");
|
throw std::runtime_error("Failed to find GPUs with Vulkan support!");
|
||||||
|
@ -293,9 +327,9 @@ class VulkanApp {
|
||||||
.ppEnabledExtensionNames = deviceExtensions.data(),
|
.ppEnabledExtensionNames = deviceExtensions.data(),
|
||||||
.pEnabledFeatures = &deviceFeatures };
|
.pEnabledFeatures = &deviceFeatures };
|
||||||
|
|
||||||
mDevice = mPhysicalDevice.createDeviceUnique(createInfo);
|
mDevice = mPhysicalDevice.createDevice(createInfo);
|
||||||
mGraphicsQueue = mDevice->getQueue(indices.graphics_family.value(), 0);
|
mGraphicsQueue = mDevice.getQueue(indices.graphics_family.value(), 0);
|
||||||
mPresentQueue = mDevice->getQueue(indices.present_family.value(), 0);
|
mPresentQueue = mDevice.getQueue(indices.present_family.value(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createSwapChain() -> void {
|
fn createSwapChain() -> void {
|
||||||
|
@ -316,7 +350,7 @@ class VulkanApp {
|
||||||
indices.present_family.value() };
|
indices.present_family.value() };
|
||||||
|
|
||||||
vk::SwapchainCreateInfoKHR createInfo {
|
vk::SwapchainCreateInfoKHR createInfo {
|
||||||
.surface = mSurface.get(),
|
.surface = mSurface,
|
||||||
.minImageCount = imageCount,
|
.minImageCount = imageCount,
|
||||||
.imageFormat = surfaceFormat.format,
|
.imageFormat = surfaceFormat.format,
|
||||||
.imageColorSpace = surfaceFormat.colorSpace,
|
.imageColorSpace = surfaceFormat.colorSpace,
|
||||||
|
@ -335,9 +369,9 @@ class VulkanApp {
|
||||||
.oldSwapchain = nullptr,
|
.oldSwapchain = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
mSwapChain = mDevice->createSwapchainKHRUnique(createInfo);
|
mSwapChain = mDevice.createSwapchainKHR(createInfo);
|
||||||
|
|
||||||
mSwapChainImages = mDevice->getSwapchainImagesKHR(mSwapChain.get());
|
mSwapChainImages = mDevice.getSwapchainImagesKHR(mSwapChain);
|
||||||
mSwapChainImageFormat = surfaceFormat.format;
|
mSwapChainImageFormat = surfaceFormat.format;
|
||||||
mSwapChainExtent = extent;
|
mSwapChainExtent = extent;
|
||||||
}
|
}
|
||||||
|
@ -363,7 +397,7 @@ class VulkanApp {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
mSwapChainImageViews[i] = mDevice->createImageViewUnique(createInfo);
|
mSwapChainImageViews[i] = mDevice.createImageView(createInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,25 +431,25 @@ class VulkanApp {
|
||||||
.pSubpasses = &subpass,
|
.pSubpasses = &subpass,
|
||||||
};
|
};
|
||||||
|
|
||||||
mRenderPass = mDevice->createRenderPassUnique(renderPassInfo);
|
mRenderPass = mDevice.createRenderPass(renderPassInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createGraphicsPipeline() -> void {
|
fn createGraphicsPipeline() -> void {
|
||||||
std::vector<char> vertShaderCode = readFile("src/shaders/vert.spv");
|
std::vector<char> vertShaderCode = readFile("src/shaders/vert.spv");
|
||||||
std::vector<char> fragShaderCode = readFile("src/shaders/frag.spv");
|
std::vector<char> fragShaderCode = readFile("src/shaders/frag.spv");
|
||||||
|
|
||||||
vk::UniqueShaderModule vertShaderModule = createShaderModule(vertShaderCode);
|
vk::ShaderModule vertShaderModule = createShaderModule(vertShaderCode);
|
||||||
vk::UniqueShaderModule fragShaderModule = createShaderModule(fragShaderCode);
|
vk::ShaderModule fragShaderModule = createShaderModule(fragShaderCode);
|
||||||
|
|
||||||
vk::PipelineShaderStageCreateInfo vertShaderStageInfo {
|
vk::PipelineShaderStageCreateInfo vertShaderStageInfo {
|
||||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||||
.module = vertShaderModule.get(),
|
.module = vertShaderModule,
|
||||||
.pName = "main",
|
.pName = "main",
|
||||||
};
|
};
|
||||||
|
|
||||||
vk::PipelineShaderStageCreateInfo fragShaderStageInfo {
|
vk::PipelineShaderStageCreateInfo fragShaderStageInfo {
|
||||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||||
.module = fragShaderModule.get(),
|
.module = fragShaderModule,
|
||||||
.pName = "main",
|
.pName = "main",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -479,7 +513,7 @@ class VulkanApp {
|
||||||
.pushConstantRangeCount = 0,
|
.pushConstantRangeCount = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
mPipelineLayout = mDevice->createPipelineLayoutUnique(pipelineLayoutInfo);
|
mPipelineLayout = mDevice.createPipelineLayout(pipelineLayoutInfo);
|
||||||
|
|
||||||
vk::GraphicsPipelineCreateInfo pipelineInfo {
|
vk::GraphicsPipelineCreateInfo pipelineInfo {
|
||||||
.stageCount = static_cast<u32>(shaderStages.size()),
|
.stageCount = static_cast<u32>(shaderStages.size()),
|
||||||
|
@ -491,21 +525,24 @@ class VulkanApp {
|
||||||
.pMultisampleState = &multisampling,
|
.pMultisampleState = &multisampling,
|
||||||
.pColorBlendState = &colorBlending,
|
.pColorBlendState = &colorBlending,
|
||||||
.pDynamicState = &dynamicState,
|
.pDynamicState = &dynamicState,
|
||||||
.layout = mPipelineLayout.get(),
|
.layout = mPipelineLayout,
|
||||||
.renderPass = mRenderPass.get(),
|
.renderPass = mRenderPass,
|
||||||
.subpass = 0,
|
.subpass = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
vk::Result graphicsPipelineResult = vk::Result::eSuccess;
|
vk::Result graphicsPipelineResult = vk::Result::eSuccess;
|
||||||
vk::UniquePipeline graphicsPipelineValue;
|
vk::Pipeline graphicsPipelineValue;
|
||||||
|
|
||||||
std::tie(graphicsPipelineResult, graphicsPipelineValue) =
|
std::tie(graphicsPipelineResult, graphicsPipelineValue) =
|
||||||
mDevice->createGraphicsPipelineUnique(nullptr, pipelineInfo).asTuple();
|
mDevice.createGraphicsPipeline(nullptr, pipelineInfo);
|
||||||
|
|
||||||
if (graphicsPipelineResult != vk::Result::eSuccess)
|
if (graphicsPipelineResult != vk::Result::eSuccess)
|
||||||
throw std::runtime_error("Failed to create graphics pipeline!");
|
throw std::runtime_error("Failed to create graphics pipeline!");
|
||||||
|
|
||||||
mGraphicsPipeline = std::move(graphicsPipelineValue);
|
mGraphicsPipeline = graphicsPipelineValue;
|
||||||
|
|
||||||
|
mDevice.destroyShaderModule(vertShaderModule);
|
||||||
|
mDevice.destroyShaderModule(fragShaderModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createFramebuffers() -> void {
|
fn createFramebuffers() -> void {
|
||||||
|
@ -513,15 +550,15 @@ class VulkanApp {
|
||||||
|
|
||||||
for (usize i = 0; i < mSwapChainImageViews.size(); i++) {
|
for (usize i = 0; i < mSwapChainImageViews.size(); i++) {
|
||||||
vk::FramebufferCreateInfo framebufferInfo {
|
vk::FramebufferCreateInfo framebufferInfo {
|
||||||
.renderPass = mRenderPass.get(),
|
.renderPass = mRenderPass,
|
||||||
.attachmentCount = 1,
|
.attachmentCount = 1,
|
||||||
.pAttachments = &mSwapChainImageViews[i].get(),
|
.pAttachments = &mSwapChainImageViews[i],
|
||||||
.width = mSwapChainExtent.width,
|
.width = mSwapChainExtent.width,
|
||||||
.height = mSwapChainExtent.height,
|
.height = mSwapChainExtent.height,
|
||||||
.layers = 1,
|
.layers = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
mSwapChainFramebuffers[i] = mDevice->createFramebufferUnique(framebufferInfo);
|
mSwapChainFramebuffers[i] = mDevice.createFramebuffer(framebufferInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,18 +570,18 @@ class VulkanApp {
|
||||||
.queueFamilyIndex = queueFamilyIndices.graphics_family.value(),
|
.queueFamilyIndex = queueFamilyIndices.graphics_family.value(),
|
||||||
};
|
};
|
||||||
|
|
||||||
mCommandPool = mDevice->createCommandPoolUnique(poolInfo);
|
mCommandPool = mDevice.createCommandPool(poolInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createCommandBuffers() -> void {
|
fn createCommandBuffers() -> void {
|
||||||
mCommandBuffers.resize(MAX_FRAMES_IN_FLIGHT);
|
mCommandBuffers.resize(MAX_FRAMES_IN_FLIGHT);
|
||||||
|
|
||||||
vk::CommandBufferAllocateInfo allocInfo { .commandPool = mCommandPool.get(),
|
vk::CommandBufferAllocateInfo allocInfo { .commandPool = mCommandPool,
|
||||||
.level = vk::CommandBufferLevel::ePrimary,
|
.level = vk::CommandBufferLevel::ePrimary,
|
||||||
.commandBufferCount =
|
.commandBufferCount =
|
||||||
static_cast<u32>(mCommandBuffers.size()) };
|
static_cast<u32>(mCommandBuffers.size()) };
|
||||||
|
|
||||||
mCommandBuffers = mDevice->allocateCommandBuffersUnique(allocInfo);
|
mCommandBuffers = mDevice.allocateCommandBuffers(allocInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recordCommandBuffer(vk::CommandBuffer commandBuffer, u32 imageIndex) -> void {
|
fn recordCommandBuffer(vk::CommandBuffer commandBuffer, u32 imageIndex) -> void {
|
||||||
|
@ -555,15 +592,15 @@ class VulkanApp {
|
||||||
vk::ClearValue clearColor { .color = { .float32 = std::array<float, 4> { 0.0F, 0.0F, 0.0F, 1.0F } } };
|
vk::ClearValue clearColor { .color = { .float32 = std::array<float, 4> { 0.0F, 0.0F, 0.0F, 1.0F } } };
|
||||||
|
|
||||||
vk::RenderPassBeginInfo renderPassInfo {
|
vk::RenderPassBeginInfo renderPassInfo {
|
||||||
.renderPass = mRenderPass.get(),
|
.renderPass = mRenderPass,
|
||||||
.framebuffer = mSwapChainFramebuffers[imageIndex].get(),
|
.framebuffer = mSwapChainFramebuffers[imageIndex],
|
||||||
.renderArea = { .offset = { .x = 0, .y = 0 }, .extent = mSwapChainExtent },
|
.renderArea = { .offset = { .x = 0, .y = 0 }, .extent = mSwapChainExtent },
|
||||||
.clearValueCount = 1,
|
.clearValueCount = 1,
|
||||||
.pClearValues = &clearColor,
|
.pClearValues = &clearColor,
|
||||||
};
|
};
|
||||||
|
|
||||||
commandBuffer.beginRenderPass(renderPassInfo, vk::SubpassContents::eInline);
|
commandBuffer.beginRenderPass(renderPassInfo, vk::SubpassContents::eInline);
|
||||||
commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, mGraphicsPipeline.get());
|
commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, mGraphicsPipeline);
|
||||||
|
|
||||||
vk::Viewport viewport {
|
vk::Viewport viewport {
|
||||||
.x = 0.0F,
|
.x = 0.0F,
|
||||||
|
@ -597,16 +634,16 @@ class VulkanApp {
|
||||||
vk::FenceCreateInfo fenceInfo { .flags = vk::FenceCreateFlagBits::eSignaled };
|
vk::FenceCreateInfo fenceInfo { .flags = vk::FenceCreateFlagBits::eSignaled };
|
||||||
|
|
||||||
for (usize idx = 0; idx < MAX_FRAMES_IN_FLIGHT; idx++) {
|
for (usize idx = 0; idx < MAX_FRAMES_IN_FLIGHT; idx++) {
|
||||||
mImageAvailableSemaphores[idx] = mDevice->createSemaphoreUnique(semaphoreInfo);
|
mImageAvailableSemaphores[idx] = mDevice.createSemaphore(semaphoreInfo);
|
||||||
mRenderFinishedSemaphores[idx] = mDevice->createSemaphoreUnique(semaphoreInfo);
|
mRenderFinishedSemaphores[idx] = mDevice.createSemaphore(semaphoreInfo);
|
||||||
mInFlightFences[idx] = mDevice->createFenceUnique(fenceInfo);
|
mInFlightFences[idx] = mDevice.createFence(fenceInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drawFrame() -> void {
|
fn drawFrame() -> void {
|
||||||
try {
|
try {
|
||||||
vk::Result result =
|
vk::Result result =
|
||||||
mDevice->waitForFences(mInFlightFences[mCurrentFrame].get(), vk::Bool32(vk::True), UINT64_MAX);
|
mDevice.waitForFences(mInFlightFences[mCurrentFrame], vk::Bool32(vk::True), UINT64_MAX);
|
||||||
|
|
||||||
if (result != vk::Result::eSuccess)
|
if (result != vk::Result::eSuccess)
|
||||||
throw std::runtime_error("Failed to wait for fences!");
|
throw std::runtime_error("Failed to wait for fences!");
|
||||||
|
@ -614,8 +651,8 @@ class VulkanApp {
|
||||||
vk::Result imageIndexResult = vk::Result::eSuccess;
|
vk::Result imageIndexResult = vk::Result::eSuccess;
|
||||||
u32 imageIndexValue = 0;
|
u32 imageIndexValue = 0;
|
||||||
|
|
||||||
std::tie(imageIndexResult, imageIndexValue) = mDevice->acquireNextImageKHR(
|
std::tie(imageIndexResult, imageIndexValue) = mDevice.acquireNextImageKHR(
|
||||||
mSwapChain.get(), UINT64_MAX, mImageAvailableSemaphores[mCurrentFrame].get(), nullptr
|
mSwapChain, UINT64_MAX, mImageAvailableSemaphores[mCurrentFrame], nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
if (imageIndexResult == vk::Result::eErrorOutOfDateKHR) {
|
if (imageIndexResult == vk::Result::eErrorOutOfDateKHR) {
|
||||||
|
@ -626,10 +663,10 @@ class VulkanApp {
|
||||||
if (imageIndexResult != vk::Result::eSuccess && imageIndexResult != vk::Result::eSuboptimalKHR)
|
if (imageIndexResult != vk::Result::eSuccess && imageIndexResult != vk::Result::eSuboptimalKHR)
|
||||||
throw std::runtime_error("Failed to acquire swap chain image!");
|
throw std::runtime_error("Failed to acquire swap chain image!");
|
||||||
|
|
||||||
mDevice->resetFences(mInFlightFences[mCurrentFrame].get());
|
mDevice.resetFences(mInFlightFences[mCurrentFrame]);
|
||||||
|
|
||||||
mCommandBuffers[mCurrentFrame]->reset(vk::CommandBufferResetFlagBits::eReleaseResources);
|
mCommandBuffers[mCurrentFrame].reset(vk::CommandBufferResetFlagBits::eReleaseResources);
|
||||||
recordCommandBuffer(mCommandBuffers[mCurrentFrame].get(), imageIndexValue);
|
recordCommandBuffer(mCommandBuffers[mCurrentFrame], imageIndexValue);
|
||||||
|
|
||||||
std::array<vk::PipelineStageFlags, 1> waitStages = {
|
std::array<vk::PipelineStageFlags, 1> waitStages = {
|
||||||
vk::PipelineStageFlagBits::eColorAttachmentOutput
|
vk::PipelineStageFlagBits::eColorAttachmentOutput
|
||||||
|
@ -637,21 +674,21 @@ class VulkanApp {
|
||||||
|
|
||||||
vk::SubmitInfo submitInfo {
|
vk::SubmitInfo submitInfo {
|
||||||
.waitSemaphoreCount = 1,
|
.waitSemaphoreCount = 1,
|
||||||
.pWaitSemaphores = &mImageAvailableSemaphores[mCurrentFrame].get(),
|
.pWaitSemaphores = &mImageAvailableSemaphores[mCurrentFrame],
|
||||||
.pWaitDstStageMask = waitStages.data(),
|
.pWaitDstStageMask = waitStages.data(),
|
||||||
.commandBufferCount = 1,
|
.commandBufferCount = 1,
|
||||||
.pCommandBuffers = &mCommandBuffers[mCurrentFrame].get(),
|
.pCommandBuffers = &mCommandBuffers[mCurrentFrame],
|
||||||
.signalSemaphoreCount = 1,
|
.signalSemaphoreCount = 1,
|
||||||
.pSignalSemaphores = &mRenderFinishedSemaphores[mCurrentFrame].get(),
|
.pSignalSemaphores = &mRenderFinishedSemaphores[mCurrentFrame],
|
||||||
};
|
};
|
||||||
|
|
||||||
mGraphicsQueue.submit(submitInfo, mInFlightFences[mCurrentFrame].get());
|
mGraphicsQueue.submit(submitInfo, mInFlightFences[mCurrentFrame]);
|
||||||
|
|
||||||
vk::PresentInfoKHR presentInfo {
|
vk::PresentInfoKHR presentInfo {
|
||||||
.waitSemaphoreCount = 1,
|
.waitSemaphoreCount = 1,
|
||||||
.pWaitSemaphores = &mRenderFinishedSemaphores[mCurrentFrame].get(),
|
.pWaitSemaphores = &mRenderFinishedSemaphores[mCurrentFrame],
|
||||||
.swapchainCount = 1,
|
.swapchainCount = 1,
|
||||||
.pSwapchains = &mSwapChain.get(),
|
.pSwapchains = &mSwapChain,
|
||||||
.pImageIndices = &imageIndexValue,
|
.pImageIndices = &imageIndexValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -674,11 +711,11 @@ class VulkanApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createShaderModule(const std::vector<char>& code) -> vk::UniqueShaderModule {
|
fn createShaderModule(const std::vector<char>& code) -> vk::ShaderModule {
|
||||||
vk::ShaderModuleCreateInfo createInfo { .codeSize = code.size(),
|
vk::ShaderModuleCreateInfo createInfo { .codeSize = code.size(),
|
||||||
.pCode = std::bit_cast<const u32*>(code.data()) };
|
.pCode = std::bit_cast<const u32*>(code.data()) };
|
||||||
|
|
||||||
return mDevice->createShaderModuleUnique(createInfo);
|
return mDevice.createShaderModule(createInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fn chooseSwapSurfaceFormat(const std::vector<vk::SurfaceFormatKHR>& availableFormats
|
static fn chooseSwapSurfaceFormat(const std::vector<vk::SurfaceFormatKHR>& availableFormats
|
||||||
|
@ -705,7 +742,7 @@ class VulkanApp {
|
||||||
return capabilities.currentExtent;
|
return capabilities.currentExtent;
|
||||||
|
|
||||||
u32 width = 0, height = 0;
|
u32 width = 0, height = 0;
|
||||||
std::tie(width, height) = mWindow->getFramebufferSize();
|
std::tie(width, height) = mWindow.getFramebufferSize();
|
||||||
|
|
||||||
vk::Extent2D actualExtent = { width, height };
|
vk::Extent2D actualExtent = { width, height };
|
||||||
|
|
||||||
|
@ -720,9 +757,9 @@ class VulkanApp {
|
||||||
fn querySwapChainSupport(vk::PhysicalDevice device) -> SwapChainSupportDetails {
|
fn querySwapChainSupport(vk::PhysicalDevice device) -> SwapChainSupportDetails {
|
||||||
SwapChainSupportDetails details;
|
SwapChainSupportDetails details;
|
||||||
|
|
||||||
details.capabilities = device.getSurfaceCapabilitiesKHR(mSurface.get());
|
details.capabilities = device.getSurfaceCapabilitiesKHR(mSurface);
|
||||||
details.formats = device.getSurfaceFormatsKHR(mSurface.get());
|
details.formats = device.getSurfaceFormatsKHR(mSurface);
|
||||||
details.present_modes = device.getSurfacePresentModesKHR(mSurface.get());
|
details.present_modes = device.getSurfacePresentModesKHR(mSurface);
|
||||||
|
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
@ -762,7 +799,7 @@ class VulkanApp {
|
||||||
if (queueFamilies[i].queueFlags & vk::QueueFlagBits::eGraphics)
|
if (queueFamilies[i].queueFlags & vk::QueueFlagBits::eGraphics)
|
||||||
indices.graphics_family = i;
|
indices.graphics_family = i;
|
||||||
|
|
||||||
vk::Bool32 queuePresentSupport = device.getSurfaceSupportKHR(i, mSurface.get());
|
vk::Bool32 queuePresentSupport = device.getSurfaceSupportKHR(i, mSurface);
|
||||||
|
|
||||||
if (queuePresentSupport)
|
if (queuePresentSupport)
|
||||||
indices.present_family = i;
|
indices.present_family = i;
|
||||||
|
|
Loading…
Reference in a new issue