Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions FlingEngine/Graphics/src/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ namespace Fling
vkCmdBeginRenderPass(GetHandle(), &begin_info, VK_SUBPASS_CONTENTS_INLINE);
}

void CommandBuffer::BeginLabel(const char* t_Name)
{
if (vkCmdBeginDebugUtilsLabelEXT == nullptr)
{
return;
}
VkDebugUtilsLabelEXT Label = {};
Label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
Label.pLabelName = t_Name;
vkCmdBeginDebugUtilsLabelEXT(GetHandle(), &Label);
}

void CommandBuffer::EndLabel()
{
if (vkCmdEndDebugUtilsLabelEXT != nullptr)
{
vkCmdEndDebugUtilsLabelEXT(GetHandle());
}
}

void CommandBuffer::NextSubpass()
{
// track pipeline state ?
Expand Down
9 changes: 9 additions & 0 deletions FlingEngine/Graphics/src/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ namespace Fling
/** Stop recording commands to the command buffer */
void End();

/**
* Open a named group of commands, shown by a graphics debugger (RenderDoc, Nsight).
* Does nothing when VK_EXT_debug_utils is off. Close it with EndLabel.
*/
void BeginLabel(const char* t_Name);

/** Close the group opened by the last BeginLabel. */
void EndLabel();

inline bool IsRecording() const { return m_State == State::Recording; }

private:
Expand Down
2 changes: 2 additions & 0 deletions FlingEngine/Graphics/src/DebugSubpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace Fling

void PrepareAttachments() override;

const char* DebugName() const override { return "Debug draw"; }

void CreateGraphicsPipeline() override;

void CleanUp() override;
Expand Down
2 changes: 2 additions & 0 deletions FlingEngine/Graphics/src/GeometrySubpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ namespace Fling
/**
* @param t_FrameBuffer The swap chain frame buffer
*/
const char* DebugName() const override { return "Lighting"; }

void CreateGraphicsPipeline() override;

virtual void OnSwapchainResized() override final;
Expand Down
2 changes: 2 additions & 0 deletions FlingEngine/Graphics/src/ImGuiSubpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace Fling

void PrepareAttachments() override;

const char* DebugName() const override { return "UI"; }

void CreateGraphicsPipeline() override;

void CleanUp() override;
Expand Down
29 changes: 26 additions & 3 deletions FlingEngine/Graphics/src/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ namespace Fling
return true;
}

bool Instance::IsInstanceExtensionSupported(const char* t_Name)
{
uint32 Count = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &Count, nullptr);
std::vector<VkExtensionProperties> Properties(Count);
vkEnumerateInstanceExtensionProperties(nullptr, &Count, Properties.data());
for (const VkExtensionProperties& Property : Properties)
{
if (strcmp(Property.extensionName, t_Name) == 0)
{
return true;
}
}
return false;
}

std::vector<const char*> Instance::GetRequiredExtensions()
{
std::vector<const char*> extensions;
Expand All @@ -140,11 +156,18 @@ namespace Fling
}
}

if (m_EnableValidationLayers)
{
// Pass labels need VK_EXT_debug_utils, and a Release capture needs them most. Turn the
// extension on when the driver has it, in every build but Shipping.
bool bWantDebugUtils = false;
#if FLING_DEBUG
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
bWantDebugUtils = m_EnableValidationLayers;
#endif
#ifndef FLING_SHIPPING
bWantDebugUtils = bWantDebugUtils || IsInstanceExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
#endif
if (bWantDebugUtils)
{
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}

return extensions;
Expand Down
3 changes: 3 additions & 0 deletions FlingEngine/Graphics/src/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ namespace Fling
*/
void CreateInstance();

/** True if the Vulkan loader lists this instance extension. */
static bool IsInstanceExtensionSupported(const char* t_Name);

std::vector<const char*> GetRequiredExtensions();

bool CheckValidationLayerSupport();
Expand Down
2 changes: 2 additions & 0 deletions FlingEngine/Graphics/src/OffscreenSubpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ namespace Fling
/** offsetY */ 0);

t_CmdBuf.Begin();
t_CmdBuf.BeginLabel(DebugName());
t_CmdBuf.BeginRenderPass(*m_OffscreenFrameBuf, m_ClearValues);

t_CmdBuf.SetViewport(0, {viewport});
Expand Down Expand Up @@ -337,6 +338,7 @@ namespace Fling
}

t_CmdBuf.EndRenderPass();
t_CmdBuf.EndLabel();

t_CmdBuf.End();
}
Expand Down
2 changes: 2 additions & 0 deletions FlingEngine/Graphics/src/OffscreenSubpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace Fling

void PrepareAttachments() override final;

const char* DebugName() const override { return "G-buffer"; }

void CreateGraphicsPipeline() override final;

void GatherPresentDependencies(std::vector<CommandBuffer*>& t_CmdBuffs,
Expand Down
3 changes: 3 additions & 0 deletions FlingEngine/Graphics/src/RenderPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ namespace Fling
for (size_t i = 0; i < m_Subpasses.size(); ++i)
{
// Build the subpasses for the active frame in flight
// The label groups this pass's commands in a capture
t_CmdBuf.BeginLabel(m_Subpasses[i]->DebugName());
m_Subpasses[i]->Draw(t_CmdBuf, t_ActiveFrameInFlight, t_Snapshot, DeltaTime);
t_CmdBuf.EndLabel();
}
}

Expand Down
2 changes: 2 additions & 0 deletions FlingEngine/Graphics/src/SkyboxSubpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace Fling

void CreateDescriptorSets(VkDescriptorPool t_Pool) override;

const char* DebugName() const override { return "Sky"; }

void CreateGraphicsPipeline() override;

void OnSwapchainResized() override;
Expand Down
3 changes: 3 additions & 0 deletions FlingEngine/Graphics/src/Subpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ namespace Fling

virtual void CreateGraphicsPipeline() = 0;

/** The name a graphics debugger shows for this pass's commands. */
virtual const char* DebugName() const { return "Subpass"; }

/**
* Record this pass for one frame. A pass reads only the snapshot, never the
* world, so the world can change while the frame is drawn.
Expand Down
4 changes: 4 additions & 0 deletions FlingEngine/Graphics/src/VulkanFunctions.inl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ FLING_VK_INSTANCE(vkGetPhysicalDeviceQueueFamilyProperties)
FLING_VK_INSTANCE_OPTIONAL(vkCreateDebugUtilsMessengerEXT)
FLING_VK_INSTANCE_OPTIONAL(vkDestroyDebugUtilsMessengerEXT)

// Pass labels for a graphics debugger (RenderDoc, Nsight). Null when VK_EXT_debug_utils is off.
FLING_VK_INSTANCE_OPTIONAL(vkCmdBeginDebugUtilsLabelEXT)
FLING_VK_INSTANCE_OPTIONAL(vkCmdEndDebugUtilsLabelEXT)

// VK_KHR_surface: an offscreen renderer (--offscreen) does not enable it.
// VulkanLoader::MissingPresentCommand checks them when there is a window.
FLING_VK_INSTANCE_OPTIONAL(vkDestroySurfaceKHR)
Expand Down