Trying to fix weird sync issue

This commit is contained in:
Dynamitos
2024-01-26 23:19:18 +01:00
parent 09790c4cbd
commit 1bf08f696b
12 changed files with 54 additions and 31 deletions
-2
View File
@@ -8,8 +8,6 @@ namespace Component
struct Mesh
{
PMeshAsset asset;
Mesh() {}
Mesh(PMeshAsset asset) : asset(asset) {}
};
} // namespace Component
} // namespace Seele
+2 -2
View File
@@ -72,8 +72,8 @@ void BasePass::render()
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
depthAttachment->getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
depthAttachment->getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
@@ -9,6 +9,8 @@
#include "Math/Vector.h"
#include "RenderGraph.h"
#include "Graphics/Command.h"
#include <vulkan/vulkan.h>
#include "Graphics/Vulkan/Graphics.h"
using namespace Seele;
@@ -130,6 +132,7 @@ void DepthPrepass::render()
}
graphics->executeCommands(commands);
graphics->endRenderPass();
//vkDeviceWaitIdle(((Vulkan::Graphics*)graphics.getHandle())->getDevice());
}
void DepthPrepass::endFrame()
@@ -34,6 +34,10 @@ void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
skyboxDataSet->updateBuffer(0, skyboxBuffer);
skyboxDataSet->writeChanges();
skyboxBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT
);
textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(0, skybox.day);
textureSet->updateTexture(1, skybox.night);
@@ -43,6 +47,14 @@ void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
void SkyboxRenderPass::render()
{
colorAttachment->getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Gfx::SE_ACCESS_COLOR_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
);
depthAttachment->getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
);
graphics->beginRenderPass(renderPass);
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("SkyboxRender");
renderCommand->setViewport(viewport);
@@ -74,12 +86,12 @@ void SkyboxRenderPass::publishOutputs()
void SkyboxRenderPass::createRenderPass()
{
baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
colorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
.colorAttachments = { baseColorAttachment },
.colorAttachments = { colorAttachment },
.depthAttachment = depthAttachment
};
renderPass = graphics->createRenderPass(std::move(layout), viewport);
@@ -18,8 +18,8 @@ public:
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
Gfx::PRenderTargetAttachment baseColorAttachment;
Gfx::OVertexBuffer cubeBuffer;
Gfx::PRenderTargetAttachment colorAttachment;
Gfx::PRenderTargetAttachment depthAttachment;
Gfx::ODescriptorLayout skyboxDataLayout;
Gfx::PDescriptorSet skyboxDataSet;
Gfx::ODescriptorLayout textureLayout;
+1 -1
View File
@@ -459,7 +459,7 @@ CommandPool::CommandPool(PGraphics graphics, PQueue queue)
.queueFamilyIndex = queue->getFamilyIndex(),
};
VK_CHECK(vkCreateCommandPool(graphics->getDevice(), &info, nullptr, &commandPool));
// TODO: dont reset individual commands, reset pool instead
allocatedBuffers.add(new Command(graphics, commandPool, this));
command = allocatedBuffers.back();
+10 -6
View File
@@ -3,15 +3,19 @@
using namespace Seele::Vulkan;
VkBool32 Seele::Vulkan::debugCallback(VkDebugReportFlagsEXT, VkDebugReportObjectTypeEXT, uint64_t, size_t, int32_t, const char *layerPrefix, const char *msg, void *)
VkBool32 Seele::Vulkan::debugCallback(
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
void* pUserData)
{
std::cerr << layerPrefix << ": " << msg << std::endl;
std::cerr << pCallbackData->pMessage << std::endl;
return VK_FALSE;
}
VkResult Seele::Vulkan::CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback)
VkResult Seele::Vulkan::CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pCallback)
{
auto func = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT");
auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
if (func != nullptr)
{
return func(instance, pCreateInfo, pAllocator, pCallback);
@@ -22,9 +26,9 @@ VkResult Seele::Vulkan::CreateDebugReportCallbackEXT(VkInstance instance, const
}
}
void Seele::Vulkan::DestroyDebugReportCallbackEXT(VkInstance instance, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT pCallback)
void Seele::Vulkan::DestroyDebugUtilsMessengerEXT(VkInstance instance, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT pCallback)
{
auto func = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT");
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
if (func != nullptr)
{
func(instance, pCallback, pAllocator);
+7 -3
View File
@@ -6,9 +6,13 @@ namespace Seele
{
namespace Vulkan
{
VkBool32 debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char *layerPrefix, const char *msg, void *userData);
VkBool32 debugCallback(
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
void* pUserData);
VkResult CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback);
void DestroyDebugReportCallbackEXT(VkInstance instance, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT pCallback);
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pCallback);
void DestroyDebugUtilsMessengerEXT(VkInstance instance, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT pCallback);
} // namespace Vulkan
} // namespace Seele
+10 -9
View File
@@ -42,7 +42,7 @@ Graphics::~Graphics()
shaderCompiler = nullptr;
pools.clear();
vkDestroyDevice(handle, nullptr);
DestroyDebugReportCallbackEXT(instance, nullptr, callback);
DestroyDebugUtilsMessengerEXT(instance, nullptr, callback);
vkDestroyInstance(instance, nullptr);
}
@@ -367,7 +367,7 @@ Array<const char *> Graphics::getRequiredExtensions()
extensions.add(glfwExtensions[i]);
}
#if ENABLE_VALIDATION
extensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
extensions.add(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
#endif // ENABLE_VALIDATION
return extensions;
}
@@ -381,7 +381,7 @@ void Graphics::initInstance(GraphicsInitializer initInfo)
.applicationVersion = VK_MAKE_VERSION(0, 0, 1),
.pEngineName = initInfo.engineName,
.engineVersion = VK_MAKE_VERSION(0, 0, 1),
.apiVersion = VK_API_VERSION_1_3,
.apiVersion = VK_API_VERSION_1_2,
};
@@ -411,15 +411,16 @@ void Graphics::initInstance(GraphicsInitializer initInfo)
}
void Graphics::setupDebugCallback()
{
VkDebugReportCallbackCreateInfoEXT createInfo = {
.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
VkDebugUtilsMessengerCreateInfoEXT createInfo = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
.pNext = nullptr,
.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT,
.pfnCallback = &debugCallback,
.flags = 0,
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT,
.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT,
.pfnUserCallback = &debugCallback,
.pUserData = nullptr,
};
VK_CHECK(CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &callback));
VK_CHECK(CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &callback));
}
void Graphics::pickPhysicalDevice()
+1 -1
View File
@@ -98,7 +98,7 @@ protected:
VkPhysicalDeviceFeatures2 features;
VkPhysicalDeviceVulkan11Features features11;
VkPhysicalDeviceVulkan12Features features12;
VkDebugReportCallbackEXT callback;
VkDebugUtilsMessengerEXT callback;
Map<uint32, OFramebuffer> allocatedFramebuffers;
VmaAllocator allocator;
OPipelineCache pipelineCache;
@@ -16,6 +16,7 @@ public:
private:
Map<uint32, OGraphicsPipeline> graphicsPipelines;
Map<uint32, OComputePipeline> computePipelines;
std::mutex cacheLock;
VkPipelineCache cache;
PGraphics graphics;
std::string cacheFile;
+1 -1
View File
@@ -111,8 +111,8 @@ void Window::beginFrame()
imageAvailableFences[currentSemaphoreIndex]->wait(100000);
imageAvailableFences[currentSemaphoreIndex]->reset();
vkAcquireNextImageKHR(graphics->getDevice(), swapchain, std::numeric_limits<uint64>::max(), imageAvailableSemaphores[currentSemaphoreIndex]->getHandle(), imageAvailableFences[currentSemaphoreIndex]->getHandle(), &currentImageIndex);
swapChainTextures[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
graphics->getGraphicsCommands()->getCommands()->waitForSemaphore(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, imageAvailableSemaphores[currentSemaphoreIndex]);
swapChainTextures[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
}
void Window::endFrame()