Added debug names and markers to vulkan

This commit is contained in:
antopilo
2025-04-26 23:07:41 -04:00
parent 60819fe1d3
commit 958287f6b1
13 changed files with 195 additions and 16 deletions

View File

@@ -20,10 +20,42 @@ namespace Nuake
Cmd(VkCommandBuffer cmdBuffer) : CmdBuffer(cmdBuffer) {} Cmd(VkCommandBuffer cmdBuffer) : CmdBuffer(cmdBuffer) {}
VkCommandBuffer GetCmdBuffer() { return CmdBuffer; } VkCommandBuffer GetCmdBuffer() { return CmdBuffer; }
class DebugMarkerScope
{
private:
VkCommandBuffer cmd;
public:
DebugMarkerScope(VkCommandBuffer inCmd, const std::string& name, Color color = Color(1, 0, 0, 1)) :
cmd(inCmd)
{
VkDebugUtilsLabelEXT labelInfo{};
labelInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
labelInfo.pLabelName = name.c_str();
labelInfo.color[0] = color.r; // Red
labelInfo.color[1] = color.g;
labelInfo.color[2] = color.b;
labelInfo.color[3] = color.a; // Alpha
vkCmdBeginDebugUtilsLabelEXT(cmd, &labelInfo);
}
~DebugMarkerScope()
{
vkCmdEndDebugUtilsLabelEXT(cmd);
}
};
public: public:
void BeginRendering(VkRenderingInfo renderInfo); void BeginRendering(VkRenderingInfo renderInfo);
void EndRendering(); void EndRendering();
DebugMarkerScope DebugScope(const std::string& name, Color color = Color(1, 0, 0, 1))
{
return DebugMarkerScope(CmdBuffer, name, color);
}
void DebugMarker(const std::string& name, Color color = Color(1, 0, 0, 1));
void BindPipeline(VkPipeline pipeline) const; void BindPipeline(VkPipeline pipeline) const;
void SetViewport(const Vector2& size) const; void SetViewport(const Vector2& size) const;
void SetScissor(const Vector2& size) const; void SetScissor(const Vector2& size) const;

View File

@@ -70,6 +70,8 @@ void RenderPass::Execute(PassRenderContext& ctx, PassAttachments& inputs)
void RenderPass::ClearAttachments(PassRenderContext& ctx, PassAttachments& inputs) void RenderPass::ClearAttachments(PassRenderContext& ctx, PassAttachments& inputs)
{ {
auto marker = ctx.commandBuffer.DebugScope("Clear Attachments");
// Clear all color attachments // Clear all color attachments
int attachmentIndex = 0; int attachmentIndex = 0;
for (int i = 0; i < std::size(inputs); i++) for (int i = 0; i < std::size(inputs); i++)
@@ -96,6 +98,7 @@ void RenderPass::ClearAttachments(PassRenderContext& ctx, PassAttachments& input
void RenderPass::TransitionAttachments(PassRenderContext& ctx, PassAttachments& inputs) void RenderPass::TransitionAttachments(PassRenderContext& ctx, PassAttachments& inputs)
{ {
auto marker = ctx.commandBuffer.DebugScope("Transition Attachments");
// Transition all color attachments // Transition all color attachments
for (auto& attachment : inputs) for (auto& attachment : inputs)
{ {
@@ -108,6 +111,8 @@ void RenderPass::TransitionAttachments(PassRenderContext& ctx, PassAttachments&
void RenderPass::UntransitionAttachments(PassRenderContext& ctx, PassAttachments& inputs) void RenderPass::UntransitionAttachments(PassRenderContext& ctx, PassAttachments& inputs)
{ {
auto marker = ctx.commandBuffer.DebugScope("Detransition Attachments");
for (auto& attachment : inputs) for (auto& attachment : inputs)
{ {
// Transform from color attachment to transfer src for next pass // Transform from color attachment to transfer src for next pass
@@ -122,6 +127,7 @@ void RenderPass::Render(PassRenderContext& ctx, PassAttachments& inputs)
if (PreRender) if (PreRender)
{ {
auto marker = ctx.commandBuffer.DebugScope("Pre Render");
PreRender(ctx); PreRender(ctx);
} }
@@ -162,6 +168,7 @@ void RenderPass::Render(PassRenderContext& ctx, PassAttachments& inputs)
if (RenderCb) if (RenderCb)
{ {
auto marker = ctx.commandBuffer.DebugScope("Render");
RenderCb(ctx); RenderCb(ctx);
} }
} }
@@ -169,6 +176,7 @@ void RenderPass::Render(PassRenderContext& ctx, PassAttachments& inputs)
if (PostRender) if (PostRender)
{ {
auto marker = ctx.commandBuffer.DebugScope("Post Render");
PostRender(ctx); PostRender(ctx);
} }
} }
@@ -278,6 +286,7 @@ void RenderPass::Build()
VK_CALL(vkCreatePipelineLayout(VkRenderer::Get().GetDevice(), &pipeline_layout_info, nullptr, &PipelineLayout)); VK_CALL(vkCreatePipelineLayout(VkRenderer::Get().GetDevice(), &pipeline_layout_info, nullptr, &PipelineLayout));
VulkanUtil::SetDebugName(PipelineLayout, Name + "PipelineLayout");
// Create pipeline // Create pipeline
const size_t attachmentCount = Attachments.size(); const size_t attachmentCount = Attachments.size();
@@ -314,7 +323,7 @@ void RenderPass::Build()
} }
Pipeline = pipelineBuilder.BuildPipeline(VkRenderer::Get().GetDevice()); Pipeline = pipelineBuilder.BuildPipeline(VkRenderer::Get().GetDevice());
VulkanUtil::SetDebugName(Pipeline, Name + "Pipeline");
IsBuilt = true; IsBuilt = true;
} }
@@ -381,6 +390,7 @@ void RenderPipeline::Execute(PassRenderContext& ctx, PipelineAttachments& inputs
int passIndex = 0; int passIndex = 0;
for (auto& pass : RenderPasses) for (auto& pass : RenderPasses)
{ {
auto marker = ctx.commandBuffer.DebugScope(pass.GetName() + " Execute");
pass.Execute(ctx, inputs[passIndex]); pass.Execute(ctx, inputs[passIndex]);
passIndex++; passIndex++;

View File

@@ -145,6 +145,8 @@ SceneRenderPipeline::SceneRenderPipeline()
memcpy(mappedData, ssaoKernelSamples.data(), buffer->GetSize()); memcpy(mappedData, ssaoKernelSamples.data(), buffer->GetSize());
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
{ {
auto command = Cmd(cmd);
command.DebugScope("SSAO Kernel CopyBuffer");
VkBufferCopy copy{ 0 }; VkBufferCopy copy{ 0 };
copy.dstOffset = 0; copy.dstOffset = 0;
copy.srcOffset = 0; copy.srcOffset = 0;
@@ -316,7 +318,10 @@ void SceneRenderPipeline::Render(PassRenderContext& ctx)
{ LineCombineOutput }, { LineCombineOutput },
}; };
GBufferPipeline.Execute(ctx, pipelineInputs); {
auto marker = ctx.commandBuffer.DebugScope("GBufferPipeline Execute");
GBufferPipeline.Execute(ctx, pipelineInputs);
}
// Mouse Picking requests // Mouse Picking requests
if (!mousePickingRequests.empty()) if (!mousePickingRequests.empty())
@@ -334,6 +339,7 @@ void SceneRenderPipeline::Render(PassRenderContext& ctx)
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
{ {
Cmd command(cmd); Cmd command(cmd);
command.DebugScope("Mouse picking GPU to CPU copy");
command.TransitionImageLayout(GBufferEntityID, VkImageLayout::VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); command.TransitionImageLayout(GBufferEntityID, VkImageLayout::VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
command.CopyImageToBuffer(GBufferEntityID, stagingBuffer, request.mousePosition); command.CopyImageToBuffer(GBufferEntityID, stagingBuffer, request.mousePosition);
command.TransitionImageLayout(GBufferEntityID, VkImageLayout::VK_IMAGE_LAYOUT_GENERAL); command.TransitionImageLayout(GBufferEntityID, VkImageLayout::VK_IMAGE_LAYOUT_GENERAL);

View File

@@ -29,18 +29,18 @@ bool Viewport::Resize()
viewportSize = queuedResize; viewportSize = queuedResize;
auto newRenderTarget = CreateRef<VulkanImage>(ImageFormat::RGBA16F, viewportSize); auto newRenderTarget = CreateRef<VulkanImage>(ImageFormat::RGBA16F, viewportSize);
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) VkRenderer::Get().ImmediateSubmit([&, newRenderTarget](VkCommandBuffer cmd)
{ {
Cmd command(cmd); Cmd command(cmd);
command.DebugScope("Viewport Resize GPGPU copy");
command.TransitionImageLayout(renderTarget, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); command.TransitionImageLayout(renderTarget, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
command.TransitionImageLayout(newRenderTarget, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); command.TransitionImageLayout(newRenderTarget, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
command.CopyImageToImage(renderTarget, newRenderTarget); command.CopyImageToImage(renderTarget, newRenderTarget);
command.TransitionImageLayout(renderTarget, VK_IMAGE_LAYOUT_GENERAL); command.TransitionImageLayout(renderTarget, VK_IMAGE_LAYOUT_GENERAL);
command.TransitionImageLayout(newRenderTarget, VK_IMAGE_LAYOUT_GENERAL); command.TransitionImageLayout(newRenderTarget, VK_IMAGE_LAYOUT_GENERAL);
renderTarget = newRenderTarget;
}); });
renderTarget = newRenderTarget;
return true; return true;
} }

View File

@@ -14,6 +14,7 @@ namespace Nuake
class Viewport class Viewport
{ {
private: private:
std::string Name;
bool Active; bool Active;
UUID id; UUID id;
Vector2 queuedResize; Vector2 queuedResize;
@@ -33,6 +34,8 @@ namespace Nuake
void SetActive(bool isActive) { Active = isActive; } void SetActive(bool isActive) { Active = isActive; }
bool IsActive() const { return Active; } bool IsActive() const { return Active; }
void SetDebugName(const std::string& name) { Name = name; }
const std::string& GetDebugName() const { return Name; }
UUID GetID() const { return id; } UUID GetID() const { return id; }
UUID GetViewID() const { return viewId; } UUID GetViewID() const { return viewId; }
void SetViewID(UUID inViewID) { this->viewId = inViewID; } void SetViewID(UUID inViewID) { this->viewId = inViewID; }

View File

@@ -3,6 +3,7 @@
#include "VulkanRenderer.h" #include "VulkanRenderer.h"
#include "VulkanAllocator.h" #include "VulkanAllocator.h"
#include "VulkanInit.h"
using namespace Nuake; using namespace Nuake;
@@ -36,6 +37,8 @@ void VkMesh::UploadToGPU(const std::vector<Vertex>& vertices, const std::vector<
memcpy((char*)mappedData + VertexBuffer->GetSize(), indices.data(), IndexBuffer->GetSize()); memcpy((char*)mappedData + VertexBuffer->GetSize(), indices.data(), IndexBuffer->GetSize());
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) { VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) {
auto command = Cmd(cmd);
command.DebugScope("VkMesh UploadToGPU");
VkBufferCopy vertexCopy{ 0 }; VkBufferCopy vertexCopy{ 0 };
vertexCopy.dstOffset = 0; vertexCopy.dstOffset = 0;
vertexCopy.srcOffset = 0; vertexCopy.srcOffset = 0;
@@ -65,6 +68,9 @@ void VkMesh::CreateDescriptorSet()
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
DescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); DescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
DescriptorSet = vk.GetDescriptorAllocator().Allocate(device, DescriptorLayout); DescriptorSet = vk.GetDescriptorAllocator().Allocate(device, DescriptorLayout);
VulkanUtil::SetDebugName(DescriptorLayout, "VkMesh " + std::to_string(ID) + " DescriptorLayout");
VulkanUtil::SetDebugName(DescriptorSet, "VkMesh " + std::to_string(ID) + " DescriptorSet");
} }
VkDescriptorBufferInfo bufferInfo{}; VkDescriptorBufferInfo bufferInfo{};

View File

@@ -91,7 +91,7 @@ namespace Nuake
constexpr uint32_t MAX_MODEL_MATRIX = 3000; constexpr uint32_t MAX_MODEL_MATRIX = 3000;
constexpr uint32_t MAX_MATERIAL = 3000; constexpr uint32_t MAX_MATERIAL = 3000;
constexpr uint32_t MAX_TEXTURES = 1000; constexpr uint32_t MAX_TEXTURES = 3000;
constexpr uint32_t MAX_CAMERAS = 1000; constexpr uint32_t MAX_CAMERAS = 1000;
constexpr uint32_t MAX_LIGHTS = 100; constexpr uint32_t MAX_LIGHTS = 100;

View File

@@ -5,6 +5,7 @@
#include "VulkanRenderer.h" #include "VulkanRenderer.h"
#include "vk_mem_alloc.h" #include "vk_mem_alloc.h"
#include "VulkanInit.h"
#include "VkResources.h" #include "VkResources.h"
using namespace Nuake; using namespace Nuake;
@@ -33,6 +34,8 @@ AllocatedBuffer::AllocatedBuffer(const std::string& name, size_t inSize, BufferU
AllocatedBuffer::AllocatedBuffer(inSize, inFlags, inUsage) AllocatedBuffer::AllocatedBuffer(inSize, inFlags, inUsage)
{ {
Name = name.empty() ? std::to_string(ID) : name; // Default name is just ID Name = name.empty() ? std::to_string(ID) : name; // Default name is just ID
VulkanUtil::SetDebugName(Buffer, "Name");
} }
AllocatedBuffer::~AllocatedBuffer() AllocatedBuffer::~AllocatedBuffer()

View File

@@ -62,13 +62,19 @@ VulkanImage::VulkanImage(const std::string & path) :
vmaCreateImage(VulkanAllocator::Get().GetAllocator(), &imgCreateInfo, &imgAllocInfo, &Image, &Allocation, nullptr); vmaCreateImage(VulkanAllocator::Get().GetAllocator(), &imgCreateInfo, &imgAllocInfo, &Image, &Allocation, nullptr);
VulkanUtil::SetDebugName(Image, path + "Image");
VkImageViewCreateInfo imageViewCreateInfo = VulkanInit::ImageviewCreateInfo(static_cast<VkFormat>(Format), Image, VK_IMAGE_ASPECT_COLOR_BIT); VkImageViewCreateInfo imageViewCreateInfo = VulkanInit::ImageviewCreateInfo(static_cast<VkFormat>(Format), Image, VK_IMAGE_ASPECT_COLOR_BIT);
VK_CALL(vkCreateImageView(VkRenderer::Get().GetDevice(), &imageViewCreateInfo, nullptr, &ImageView)); VK_CALL(vkCreateImageView(VkRenderer::Get().GetDevice(), &imageViewCreateInfo, nullptr, &ImageView));
VulkanUtil::SetDebugName(ImageView, path + "ImageView");
// Transition image and copy data to GPU // Transition image and copy data to GPU
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
{ {
Cmd command(cmd);
command.DebugScope("Image CPU to GPU Copy");
TransitionLayout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); TransitionLayout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
//VulkanUtil::TransitionImage(cmd, Image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); //VulkanUtil::TransitionImage(cmd, Image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
@@ -225,6 +231,7 @@ VulkanImage::VulkanImage(void* inData, ImageFormat inFormat, Vector2 inSize) : V
Layout = VK_IMAGE_LAYOUT_UNDEFINED; Layout = VK_IMAGE_LAYOUT_UNDEFINED;
VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd)
{ {
TransitionLayout(cmd, VK_IMAGE_LAYOUT_GENERAL); TransitionLayout(cmd, VK_IMAGE_LAYOUT_GENERAL);
TransitionLayout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); TransitionLayout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
VkBufferImageCopy copyRegion = {}; VkBufferImageCopy copyRegion = {};
@@ -296,7 +303,6 @@ VulkanImage::VulkanImage(void* inData, size_t inSize) :
vmaCreateImage(VulkanAllocator::Get().GetAllocator(), &imgCreateInfo, &imgAllocInfo, &Image, &Allocation, nullptr); vmaCreateImage(VulkanAllocator::Get().GetAllocator(), &imgCreateInfo, &imgAllocInfo, &Image, &Allocation, nullptr);
VkImageViewCreateInfo imageViewCreateInfo = VulkanInit::ImageviewCreateInfo(static_cast<VkFormat>(Format), Image, VK_IMAGE_ASPECT_COLOR_BIT); VkImageViewCreateInfo imageViewCreateInfo = VulkanInit::ImageviewCreateInfo(static_cast<VkFormat>(Format), Image, VK_IMAGE_ASPECT_COLOR_BIT);
VK_CALL(vkCreateImageView(VkRenderer::Get().GetDevice(), &imageViewCreateInfo, nullptr, &ImageView)); VK_CALL(vkCreateImageView(VkRenderer::Get().GetDevice(), &imageViewCreateInfo, nullptr, &ImageView));
@@ -336,7 +342,8 @@ VulkanImage::~VulkanImage()
void VulkanImage::SetDebugName(const std::string& name) void VulkanImage::SetDebugName(const std::string& name)
{ {
GPUManaged::SetDebugName(name); GPUManaged::SetDebugName(name);
VulkanUtil::SetDebugName(Image, name);
VulkanUtil::SetDebugName(ImageView, name);
vmaSetAllocationName(VulkanAllocator::Get().GetAllocator(), Allocation, GetDebugName().data()); vmaSetAllocationName(VulkanAllocator::Get().GetAllocator(), Allocation, GetDebugName().data());
} }
@@ -401,6 +408,7 @@ VkDescriptorSet& VulkanImage::GetImGuiDescriptorSet()
ImGuiDescriptorSetGenerated = true; ImGuiDescriptorSetGenerated = true;
struct cleanUpData struct cleanUpData
{ {
VkDescriptorSet descriptorSet; VkDescriptorSet descriptorSet;
@@ -413,6 +421,8 @@ VkDescriptorSet& VulkanImage::GetImGuiDescriptorSet()
Sampler Sampler
}; };
AddGPUCleanUpFunc([=]() { AddGPUCleanUpFunc([=]() {
cleanUpData data = dataToCleanUp; cleanUpData data = dataToCleanUp;
ImGui_ImplVulkan_RemoveTexture(data.descriptorSet); ImGui_ImplVulkan_RemoveTexture(data.descriptorSet);

View File

@@ -2,7 +2,9 @@
#include <volk/volk.h> #include <volk/volk.h>
#include "Nuake/Core/Maths.h" #include "Nuake/Core/Maths.h"
#include "Nuake/Rendering/Vulkan/VulkanRenderer.h"
#include <string>
#include <vector> #include <vector>
namespace Nuake namespace Nuake
@@ -46,5 +48,80 @@ namespace Nuake
static void TransitionImage(VkCommandBuffer cmd, VkImage image, VkImageLayout currentLayout, VkImageLayout newLayout, bool isDepth = false); static void TransitionImage(VkCommandBuffer cmd, VkImage image, VkImageLayout currentLayout, VkImageLayout newLayout, bool isDepth = false);
static void CopyImageToImage(VkCommandBuffer cmd, VkImage source, VkImage destination, Vector2 srcSize, Vector2 dstSize); static void CopyImageToImage(VkCommandBuffer cmd, VkImage source, VkImage destination, Vector2 srcSize, Vector2 dstSize);
template<typename VulkanHandleType>
static constexpr VkObjectType GetVkObjectType()
{
if constexpr (std::is_same_v<VulkanHandleType, VkBuffer>) {
return VK_OBJECT_TYPE_BUFFER;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkImage>) {
return VK_OBJECT_TYPE_IMAGE;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkShaderModule>) {
return VK_OBJECT_TYPE_SHADER_MODULE;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkPipeline>) {
return VK_OBJECT_TYPE_PIPELINE;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkDescriptorSet>) {
return VK_OBJECT_TYPE_DESCRIPTOR_SET;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkPipelineLayout>) {
return VK_OBJECT_TYPE_PIPELINE_LAYOUT;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkRenderPass>) {
return VK_OBJECT_TYPE_RENDER_PASS;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkFramebuffer>) {
return VK_OBJECT_TYPE_FRAMEBUFFER;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkDescriptorSetLayout>) {
return VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkBufferView>) {
return VK_OBJECT_TYPE_BUFFER_VIEW;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkImageView>) {
return VK_OBJECT_TYPE_IMAGE_VIEW;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkSampler>) {
return VK_OBJECT_TYPE_SAMPLER;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkSamplerYcbcrConversion>) {
return VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkPipelineCache>) {
return VK_OBJECT_TYPE_PIPELINE_CACHE;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkQueryPool>) {
return VK_OBJECT_TYPE_QUERY_POOL;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkEvent>) {
return VK_OBJECT_TYPE_EVENT;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkFence>) {
return VK_OBJECT_TYPE_FENCE;
}
else if constexpr (std::is_same_v<VulkanHandleType, VkSemaphore>) {
return VK_OBJECT_TYPE_SEMAPHORE;
}
else {
static_assert(false, "Unknown Vulkan object type.");
return VK_OBJECT_TYPE_UNKNOWN;
}
}
template<typename VulkanHandleType>
static void SetDebugName(VulkanHandleType object, const std::string& name)
{
VkDebugUtilsObjectNameInfoEXT info{};
info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
info.objectType = GetVkObjectType<VulkanHandleType>();
info.objectHandle = reinterpret_cast<uint64_t>(object);
info.pObjectName = name.c_str();
vkSetDebugUtilsObjectNameEXT(VkRenderer::Get().GetDevice(), &info);
}
}; };
} }

View File

@@ -179,6 +179,7 @@ void VkRenderer::GetInstance()
//make the vulkan instance, with basic debug features //make the vulkan instance, with basic debug features
auto instRet = builder.set_app_name("Nuake Engine") auto instRet = builder.set_app_name("Nuake Engine")
.request_validation_layers(NKUseValidationLayer) .request_validation_layers(NKUseValidationLayer)
.enable_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)
.use_default_debug_messenger() .use_default_debug_messenger()
.require_api_version(1, 3, 0) .require_api_version(1, 3, 0)
.build(); .build();
@@ -209,7 +210,7 @@ void VkRenderer::SelectGPU()
{ {
VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
VK_KHR_LINE_RASTERIZATION_EXTENSION_NAME, VK_KHR_LINE_RASTERIZATION_EXTENSION_NAME,
VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME,
}; };
auto systemInfoRet = vkb::SystemInfo::get_system_info(); auto systemInfoRet = vkb::SystemInfo::get_system_info();
@@ -219,9 +220,9 @@ void VkRenderer::SelectGPU()
{ {
if (!systemInfo.is_extension_available(extension)) if (!systemInfo.is_extension_available(extension))
{ {
std::string errMessage = "No GPU found who supports the required Vulkan extension: " + std::string(extension); //std::string errMessage = "No GPU found who supports the required Vulkan extension: " + std::string(extension);
errMessage += "\nConsider updating drivers."; //errMessage += "\nConsider updating drivers.";
Logger::Log(errMessage, "vulkan", CRITICAL); //Logger::Log(errMessage, "vulkan", CRITICAL);
//OS::ShowMessageBox("Vulkan Error", errMessage); //OS::ShowMessageBox("Vulkan Error", errMessage);
} }
} }
@@ -233,7 +234,7 @@ void VkRenderer::SelectGPU()
.set_required_features_12(features12) .set_required_features_12(features12)
.set_required_features(VkPhysicalDeviceFeatures{ .set_required_features(VkPhysicalDeviceFeatures{
.fillModeNonSolid = VK_TRUE, .fillModeNonSolid = VK_TRUE,
.wideLines = VK_TRUE .wideLines = VK_TRUE,
}) })
.set_surface(Surface) .set_surface(Surface)
.add_required_extensions(requiredExtensions) .add_required_extensions(requiredExtensions)
@@ -451,6 +452,11 @@ void VkRenderer::DrawScenes()
ctx.SelectedEntityID = viewport->GetSelectedEntityID(); ctx.SelectedEntityID = viewport->GetSelectedEntityID();
SceneRenderers[view]->DrawSceneView(ctx); SceneRenderers[view]->DrawSceneView(ctx);
Stats.ViewRenderers++;
}
else
{
Stats.ViewRenderSkipped++;
} }
} }
} }
@@ -737,6 +743,8 @@ void VkRenderer::BeginScene(const UUID& camera)
bool VkRenderer::Draw() bool VkRenderer::Draw()
{ {
Stats = {};
VK_CALL(vkWaitForFences(Device, 1, &GetCurrentFrame().RenderFence, true, 1000000000)); VK_CALL(vkWaitForFences(Device, 1, &GetCurrentFrame().RenderFence, true, 1000000000));
if (SurfaceSize != Window::Get()->GetSize()) if (SurfaceSize != Window::Get()->GetSize())
@@ -798,7 +806,6 @@ bool VkRenderer::Draw()
std::mutex queueMutex; std::mutex queueMutex;
void VkRenderer::EndDraw() void VkRenderer::EndDraw()
{ {
std::lock_guard<std::mutex> lock(queueMutex); std::lock_guard<std::mutex> lock(queueMutex);
if (FrameSkipped) if (FrameSkipped)
{ {
@@ -894,7 +901,9 @@ void VkRenderer::ImmediateSubmit(std::function<void(VkCommandBuffer cmd)>&& func
VK_CALL(vkResetCommandBuffer(ImguiCommandBuffer, 0)); VK_CALL(vkResetCommandBuffer(ImguiCommandBuffer, 0));
VkCommandBuffer cmd = ImguiCommandBuffer; VkCommandBuffer cmd = ImguiCommandBuffer;
Cmd command(cmd);
command.DebugScope("Immediate Submit", Color(1, 1, 0, 1));
VkCommandBufferBeginInfo cmdBeginInfo = VulkanInit::CommandBufferBeginInfo(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT); VkCommandBufferBeginInfo cmdBeginInfo = VulkanInit::CommandBufferBeginInfo(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
VK_CALL(vkBeginCommandBuffer(cmd, &cmdBeginInfo)); VK_CALL(vkBeginCommandBuffer(cmd, &cmdBeginInfo));
@@ -927,8 +936,6 @@ void DescriptorAllocator::InitPool(VkDevice device, uint32_t maxSets, std::span<
); );
} }
VkDescriptorPoolCreateInfo pool_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO }; VkDescriptorPoolCreateInfo pool_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO };
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
pool_info.maxSets = maxSets; pool_info.maxSets = maxSets;

View File

@@ -134,6 +134,13 @@ namespace Nuake
class Viewport; class Viewport;
struct RendererStats
{
int ViewRenderers = 0;
int ViewRenderSkipped = 0;
int DrawCalls = 0;
};
class VkRenderer class VkRenderer
{ {
private: private:
@@ -165,6 +172,7 @@ namespace Nuake
DescriptorAllocator GlobalDescriptorAllocator; DescriptorAllocator GlobalDescriptorAllocator;
public: public:
RendererStats Stats;
uint32_t FrameNumber = 0; uint32_t FrameNumber = 0;
VkDescriptorSet DrawImageDescriptors; VkDescriptorSet DrawImageDescriptors;
VkDescriptorSetLayout DrawImageDescriptorLayout; VkDescriptorSetLayout DrawImageDescriptorLayout;

View File

@@ -3,6 +3,7 @@
#include "VulkanAllocator.h" #include "VulkanAllocator.h"
#include "GPUManaged.h" #include "GPUManaged.h"
#include "VulkanInit.h"
using namespace Nuake; using namespace Nuake;
@@ -228,6 +229,7 @@ void GPUResources::CreateBindlessLayout()
DescriptorLayoutBuilder builder; DescriptorLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
ModelDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); ModelDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
VulkanUtil::SetDebugName(ModelDescriptorLayout, "ModelDescriptorLayout");
} }
// Triangles // Triangles
@@ -235,6 +237,7 @@ void GPUResources::CreateBindlessLayout()
DescriptorLayoutBuilder builder; DescriptorLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
TriangleBufferDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); TriangleBufferDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
VulkanUtil::SetDebugName(TriangleBufferDescriptorLayout, "TriangleBufferDescriptorLayout");
} }
// SSAO kernel // SSAO kernel
@@ -242,6 +245,7 @@ void GPUResources::CreateBindlessLayout()
DescriptorLayoutBuilder builder; DescriptorLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
SSAOKernelDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); SSAOKernelDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
VulkanUtil::SetDebugName(SSAOKernelDescriptorLayout, "SSAOKernelDescriptorLayout");
} }
// Samplers // Samplers
@@ -249,6 +253,7 @@ void GPUResources::CreateBindlessLayout()
DescriptorLayoutBuilder builder; DescriptorLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_SAMPLER, 2); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_SAMPLER, 2);
SamplerDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); SamplerDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
VulkanUtil::SetDebugName(SamplerDescriptorLayout, "SamplerDescriptorLayout");
} }
// Material // Material
@@ -256,6 +261,7 @@ void GPUResources::CreateBindlessLayout()
DescriptorLayoutBuilder builder; DescriptorLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
MaterialDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); MaterialDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
VulkanUtil::SetDebugName(MaterialDescriptorLayout, "MaterialDescriptorLayout");
} }
// Textures // Textures
@@ -263,6 +269,7 @@ void GPUResources::CreateBindlessLayout()
DescriptorLayoutBuilder builder; DescriptorLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MAX_TEXTURES); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MAX_TEXTURES);
TexturesDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); TexturesDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
VulkanUtil::SetDebugName(TexturesDescriptorLayout, "TexturesDescriptorLayout");
} }
// bindless lights // bindless lights
@@ -270,6 +277,7 @@ void GPUResources::CreateBindlessLayout()
DescriptorLayoutBuilder builder; DescriptorLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
LightsDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); LightsDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
VulkanUtil::SetDebugName(LightsDescriptorLayout, "LightsDescriptorLayout");
} }
// bindless cameras // bindless cameras
@@ -277,6 +285,7 @@ void GPUResources::CreateBindlessLayout()
DescriptorLayoutBuilder builder; DescriptorLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
CamerasDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); CamerasDescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
VulkanUtil::SetDebugName(CamerasDescriptorLayout, "CamerasDescriptorLayout");
} }
auto allocator = vk.GetDescriptorAllocator(); auto allocator = vk.GetDescriptorAllocator();
@@ -289,6 +298,14 @@ void GPUResources::CreateBindlessLayout()
MaterialDescriptor = allocator.Allocate(device, MaterialDescriptorLayout); MaterialDescriptor = allocator.Allocate(device, MaterialDescriptorLayout);
SSAOKernelDescriptor = allocator.Allocate(device, SSAOKernelDescriptorLayout); SSAOKernelDescriptor = allocator.Allocate(device, SSAOKernelDescriptorLayout);
VulkanUtil::SetDebugName(TexturesDescriptor, "TextureDescriptor");
VulkanUtil::SetDebugName(CamerasDescriptor, "CamerasDescriptor");
VulkanUtil::SetDebugName(TriangleBufferDescriptor, "TriangleBufferDescriptor");
VulkanUtil::SetDebugName(ModelDescriptor, "ModelDescriptor");
VulkanUtil::SetDebugName(LightsDescriptor, "LightsDescriptor");
VulkanUtil::SetDebugName(MaterialDescriptor, "MaterialDescriptor");
VulkanUtil::SetDebugName(SSAOKernelDescriptor, "SSAOKernelDescriptor");
// Samplers // Samplers
VkPhysicalDeviceProperties properties{}; VkPhysicalDeviceProperties properties{};
vkGetPhysicalDeviceProperties(VkRenderer::Get().GetPhysicalDevice(), &properties); vkGetPhysicalDeviceProperties(VkRenderer::Get().GetPhysicalDevice(), &properties);