|
|
@@ -1,19 +1,18 @@
|
|
|
-#include "core/VulkanWrapper.hpp"
|
|
|
+module;
|
|
|
|
|
|
-#include <cstring>
|
|
|
+#include <cstddef>
|
|
|
|
|
|
-#include "GLFW.hpp"
|
|
|
-#include "core/VulkanBase.hpp"
|
|
|
-#include "core/WindowManager.hpp"
|
|
|
+module Core.VulkanWrapper;
|
|
|
|
|
|
import Core.File;
|
|
|
import Core.UniquePointer;
|
|
|
-import Core.List;
|
|
|
import Core.Logger;
|
|
|
-import Core.Types;
|
|
|
import Core.Math;
|
|
|
import Core.Array;
|
|
|
import Core.Vector;
|
|
|
+import Core.VulkanUtility;
|
|
|
+import Core.WindowManager;
|
|
|
+import Core.Std;
|
|
|
|
|
|
namespace Vulkan = Core::Vulkan;
|
|
|
using Core::List;
|
|
|
@@ -57,7 +56,9 @@ bool ImageView::init(VkDevice d, VkImage image, VkFormat format) {
|
|
|
.levelCount = 1,
|
|
|
.baseArrayLayer = 0,
|
|
|
.layerCount = 1}};
|
|
|
- VK_CHECK_TRUE(vkCreateImageView(d, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateImageView(d, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = d;
|
|
|
return false;
|
|
|
}
|
|
|
@@ -73,7 +74,9 @@ bool Framebuffer::init(
|
|
|
.width = width,
|
|
|
.height = height,
|
|
|
.layers = 1};
|
|
|
- VK_CHECK_TRUE(vkCreateFramebuffer(iv.device, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateFramebuffer(iv.device, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = iv.device;
|
|
|
return false;
|
|
|
}
|
|
|
@@ -82,7 +85,9 @@ bool Semaphore::init(VkDevice d) {
|
|
|
Semaphore::~Semaphore();
|
|
|
VkSemaphoreCreateInfo info = {
|
|
|
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
|
|
|
- VK_CHECK_TRUE(vkCreateSemaphore(d, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateSemaphore(d, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = d;
|
|
|
return false;
|
|
|
}
|
|
|
@@ -92,17 +97,19 @@ bool Fence::init(VkDevice d) {
|
|
|
VkFenceCreateInfo info = {
|
|
|
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
|
|
.flags = VK_FENCE_CREATE_SIGNALED_BIT};
|
|
|
- VK_CHECK_TRUE(vkCreateFence(d, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateFence(d, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = d;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
void Fence::reset() {
|
|
|
- VK_CHECK_VOID(vkResetFences(device, 1, &handle));
|
|
|
+ check(vkResetFences(device, 1, &handle));
|
|
|
}
|
|
|
|
|
|
void Fence::waitFor(u64 timeout) {
|
|
|
- VK_CHECK_VOID(vkWaitForFences(device, 1, &handle, true, timeout));
|
|
|
+ check(vkWaitForFences(device, 1, &handle, true, timeout));
|
|
|
}
|
|
|
|
|
|
static u32 getSwapImageCount(const VkSurfaceCapabilitiesKHR* caps) {
|
|
|
@@ -138,7 +145,9 @@ bool Swapchain::init(Data& d) {
|
|
|
.presentMode = d.presentMode,
|
|
|
.clipped = VK_TRUE,
|
|
|
.oldSwapchain = VK_NULL_HANDLE};
|
|
|
- VK_CHECK_TRUE(vkCreateSwapchainKHR(d.base, &ci, nullptr, &handle));
|
|
|
+ if(check(vkCreateSwapchainKHR(d.base, &ci, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = d.base;
|
|
|
return false;
|
|
|
}
|
|
|
@@ -151,8 +160,9 @@ SwapchainResult Swapchain::nextImage(
|
|
|
return SwapchainResult::RECREATE;
|
|
|
} else if(r == VK_ERROR_OUT_OF_DATE_KHR) {
|
|
|
return SwapchainResult::ERROR_RECREATE;
|
|
|
+ } else if(r != VK_SUCCESS) {
|
|
|
+ return SwapchainResult::ERROR;
|
|
|
}
|
|
|
- VK_CHECK(SwapchainResult::ERROR, r);
|
|
|
return SwapchainResult::SUCCESS;
|
|
|
}
|
|
|
|
|
|
@@ -164,14 +174,16 @@ bool ShaderModule::init(VkDevice d, const char* path) {
|
|
|
}
|
|
|
size_t l = f.getLength() - 1;
|
|
|
if((l % 4) != 0) {
|
|
|
- VK_REPORT_ERROR("Shader size is not a multiple of 4");
|
|
|
+ Core::report(LogLevel::ERROR, "Shader size is not a multiple of 4");
|
|
|
return true;
|
|
|
}
|
|
|
VkShaderModuleCreateInfo info = {
|
|
|
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
|
|
.codeSize = l,
|
|
|
.pCode = reinterpret_cast<u32*>(static_cast<void*>(&f[0]))};
|
|
|
- VK_CHECK_TRUE(vkCreateShaderModule(d, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateShaderModule(d, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = d;
|
|
|
return false;
|
|
|
}
|
|
|
@@ -180,18 +192,24 @@ bool PipelineLayout::init(VkDevice d) {
|
|
|
PipelineLayout::~PipelineLayout();
|
|
|
VkPipelineLayoutCreateInfo info = {
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
|
|
|
- VK_CHECK_TRUE(vkCreatePipelineLayout(d, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreatePipelineLayout(d, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = d;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
bool SwapchainImages::init(const Swapchain& s, VkFormat format) {
|
|
|
u32 c = 0;
|
|
|
- VK_CHECK_TRUE(vkGetSwapchainImagesKHR(s.device, s.handle, &c, nullptr));
|
|
|
+ if(check(vkGetSwapchainImagesKHR(s.device, s.handle, &c, nullptr))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
images.resize(c);
|
|
|
imageViews.resize(c);
|
|
|
renderFinishedSemaphore.resize(c);
|
|
|
- VK_CHECK_TRUE(vkGetSwapchainImagesKHR(s.device, s.handle, &c, &images[0]));
|
|
|
+ if(check(vkGetSwapchainImagesKHR(s.device, s.handle, &c, &images[0]))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
for(u32 x = 0; x < c; x++) {
|
|
|
if(imageViews[x].init(s.device, images[x], format)) {
|
|
|
return true;
|
|
|
@@ -235,7 +253,9 @@ bool RenderPass::init(VkDevice d, VkFormat format) {
|
|
|
.pSubpasses = &subpass,
|
|
|
.dependencyCount = 1,
|
|
|
.pDependencies = &dependency};
|
|
|
- VK_CHECK_TRUE(vkCreateRenderPass(d, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateRenderPass(d, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = d;
|
|
|
return false;
|
|
|
}
|
|
|
@@ -358,8 +378,10 @@ bool Pipeline::init(
|
|
|
.basePipelineHandle = VK_NULL_HANDLE,
|
|
|
.basePipelineIndex = -1};
|
|
|
|
|
|
- VK_CHECK_TRUE(vkCreateGraphicsPipelines(
|
|
|
- pl.device, VK_NULL_HANDLE, 1, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateGraphicsPipelines(
|
|
|
+ pl.device, VK_NULL_HANDLE, 1, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = pl.device;
|
|
|
return false;
|
|
|
}
|
|
|
@@ -370,7 +392,9 @@ bool CommandPool::init(VkDevice d, u32 queueFamily) {
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
|
|
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
|
|
|
.queueFamilyIndex = queueFamily};
|
|
|
- VK_CHECK_TRUE(vkCreateCommandPool(d, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateCommandPool(d, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = d;
|
|
|
return false;
|
|
|
}
|
|
|
@@ -382,23 +406,25 @@ bool CommandBuffer::init(CommandPool& cp) {
|
|
|
.commandPool = cp,
|
|
|
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
|
|
.commandBufferCount = 1};
|
|
|
- VK_CHECK_TRUE(vkAllocateCommandBuffers(cp.device, &info, &handle));
|
|
|
+ if(check(vkAllocateCommandBuffers(cp.device, &info, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = cp.device;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
void CommandBuffer::reset() {
|
|
|
- VK_CHECK_VOID(vkResetCommandBuffer(handle, 0));
|
|
|
+ check(vkResetCommandBuffer(handle, 0));
|
|
|
}
|
|
|
|
|
|
void CommandBuffer::begin() {
|
|
|
VkCommandBufferBeginInfo info = {
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
|
|
|
- VK_CHECK_VOID(vkBeginCommandBuffer(handle, &info));
|
|
|
+ check(vkBeginCommandBuffer(handle, &info));
|
|
|
}
|
|
|
|
|
|
void CommandBuffer::end() {
|
|
|
- VK_CHECK_VOID(vkEndCommandBuffer(handle));
|
|
|
+ check(vkEndCommandBuffer(handle));
|
|
|
}
|
|
|
|
|
|
void CommandBuffer::beginRenderPass(
|
|
|
@@ -445,7 +471,7 @@ void Queue::submit(
|
|
|
.pCommandBuffers = cb,
|
|
|
.signalSemaphoreCount = 1,
|
|
|
.pSignalSemaphores = signal};
|
|
|
- VK_CHECK_VOID(vkQueueSubmit(handle, 1, &info, f));
|
|
|
+ check(vkQueueSubmit(handle, 1, &info, f));
|
|
|
}
|
|
|
|
|
|
SwapchainResult Queue::present(Semaphore& signal, Swapchain& s, u32 index) {
|
|
|
@@ -461,8 +487,9 @@ SwapchainResult Queue::present(Semaphore& signal, Swapchain& s, u32 index) {
|
|
|
return SwapchainResult::RECREATE;
|
|
|
} else if(r == VK_ERROR_OUT_OF_DATE_KHR) {
|
|
|
return SwapchainResult::ERROR_RECREATE;
|
|
|
+ } else if(r != VK_SUCCESS) {
|
|
|
+ return SwapchainResult::ERROR;
|
|
|
}
|
|
|
- VK_CHECK(SwapchainResult::ERROR, r);
|
|
|
return SwapchainResult::SUCCESS;
|
|
|
}
|
|
|
|
|
|
@@ -484,7 +511,9 @@ bool VertexBuffer::init(Base& b, size_t size, const void* data) {
|
|
|
.size = size,
|
|
|
.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE};
|
|
|
- VK_CHECK_TRUE(vkCreateBuffer(b, &info, nullptr, &handle));
|
|
|
+ if(check(vkCreateBuffer(b, &info, nullptr, &handle))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
device = b;
|
|
|
|
|
|
VkMemoryRequirements m;
|
|
|
@@ -495,11 +524,14 @@ bool VertexBuffer::init(Base& b, size_t size, const void* data) {
|
|
|
.memoryTypeIndex = b.findMemoryType(
|
|
|
m.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)};
|
|
|
- VK_CHECK_TRUE(vkAllocateMemory(device, &aInfo, nullptr, &memory));
|
|
|
- VK_CHECK_TRUE(vkBindBufferMemory(device, handle, memory, 0));
|
|
|
-
|
|
|
+ if(check(vkAllocateMemory(device, &aInfo, nullptr, &memory)) ||
|
|
|
+ check(vkBindBufferMemory(device, handle, memory, 0))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
void* destination = nullptr;
|
|
|
- VK_CHECK_TRUE(vkMapMemory(device, memory, 0, size, 0, &destination));
|
|
|
+ if(check(vkMapMemory(device, memory, 0, size, 0, &destination))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
memcpy(destination, data, size);
|
|
|
vkUnmapMemory(device, memory);
|
|
|
return false;
|