VideoBackends / VideoCommon: allow the ability to set debug names for shaders / textures. These names are visible in applications like RenderDoc

This commit is contained in:
iwubcode
2021-08-28 00:30:05 -05:00
parent 9b83cf3e7f
commit 1f2f505373
32 changed files with 276 additions and 133 deletions

View File

@ -58,7 +58,7 @@ bool StateTracker::Initialize()
{
// Create a dummy texture which can be used in place of a real binding.
m_dummy_texture =
VKTexture::Create(TextureConfig(1, 1, 1, 1, 1, AbstractTextureFormat::RGBA8, 0));
VKTexture::Create(TextureConfig(1, 1, 1, 1, 1, AbstractTextureFormat::RGBA8, 0), "");
if (!m_dummy_texture)
return false;
m_dummy_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentInitCommandBuffer(),

View File

@ -82,9 +82,10 @@ void Renderer::Shutdown()
m_swap_chain.reset();
}
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config,
std::string_view name)
{
return VKTexture::Create(config);
return VKTexture::Create(config, name);
}
std::unique_ptr<AbstractStagingTexture> Renderer::CreateStagingTexture(StagingTextureType type,
@ -93,16 +94,17 @@ std::unique_ptr<AbstractStagingTexture> Renderer::CreateStagingTexture(StagingTe
return VKStagingTexture::Create(type, config);
}
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromSource(ShaderStage stage,
std::string_view source)
std::unique_ptr<AbstractShader>
Renderer::CreateShaderFromSource(ShaderStage stage, std::string_view source, std::string_view name)
{
return VKShader::CreateFromSource(stage, source);
return VKShader::CreateFromSource(stage, source, name);
}
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
const void* data, size_t length)
const void* data, size_t length,
std::string_view name)
{
return VKShader::CreateFromBinary(stage, data, length);
return VKShader::CreateFromBinary(stage, data, length, name);
}
std::unique_ptr<NativeVertexFormat>

View File

@ -6,6 +6,7 @@
#include <array>
#include <cstddef>
#include <memory>
#include <string_view>
#include "Common/CommonTypes.h"
#include "VideoBackends/Vulkan/Constants.h"
@ -35,16 +36,18 @@ public:
bool Initialize() override;
void Shutdown() override;
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config,
std::string_view name) override;
std::unique_ptr<AbstractStagingTexture>
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
std::unique_ptr<AbstractFramebuffer>
CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override;
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage,
std::string_view source) override;
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, std::string_view source,
std::string_view name) override;
std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
size_t length) override;
size_t length,
std::string_view name) override;
std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,

View File

@ -11,16 +11,35 @@
namespace Vulkan
{
VKShader::VKShader(ShaderStage stage, std::vector<u32> spv, VkShaderModule mod)
VKShader::VKShader(ShaderStage stage, std::vector<u32> spv, VkShaderModule mod,
std::string_view name)
: AbstractShader(stage), m_spv(std::move(spv)), m_module(mod),
m_compute_pipeline(VK_NULL_HANDLE)
m_compute_pipeline(VK_NULL_HANDLE), m_name(name)
{
if (!m_name.empty())
{
VkDebugUtilsObjectNameInfoEXT name_info = {};
name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
name_info.objectType = VK_OBJECT_TYPE_SHADER_MODULE;
name_info.objectHandle = reinterpret_cast<uint64_t>(m_module);
name_info.pObjectName = m_name.data();
vkSetDebugUtilsObjectNameEXT(g_vulkan_context->GetDevice(), &name_info);
}
}
VKShader::VKShader(std::vector<u32> spv, VkPipeline compute_pipeline)
VKShader::VKShader(std::vector<u32> spv, VkPipeline compute_pipeline, std::string_view name)
: AbstractShader(ShaderStage::Compute), m_spv(std::move(spv)), m_module(VK_NULL_HANDLE),
m_compute_pipeline(compute_pipeline)
m_compute_pipeline(compute_pipeline), m_name(name)
{
if (!m_name.empty())
{
VkDebugUtilsObjectNameInfoEXT name_info = {};
name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
name_info.objectType = VK_OBJECT_TYPE_PIPELINE;
name_info.objectHandle = reinterpret_cast<uint64_t>(m_compute_pipeline);
name_info.pObjectName = m_name.data();
vkSetDebugUtilsObjectNameEXT(g_vulkan_context->GetDevice(), &name_info);
}
}
VKShader::~VKShader()
@ -38,8 +57,8 @@ AbstractShader::BinaryData VKShader::GetBinary() const
return ret;
}
static std::unique_ptr<VKShader> CreateShaderObject(ShaderStage stage,
ShaderCompiler::SPIRVCodeVector spv)
static std::unique_ptr<VKShader>
CreateShaderObject(ShaderStage stage, ShaderCompiler::SPIRVCodeVector spv, std::string_view name)
{
VkShaderModuleCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
@ -56,7 +75,7 @@ static std::unique_ptr<VKShader> CreateShaderObject(ShaderStage stage,
// If it's a graphics shader, we defer pipeline creation.
if (stage != ShaderStage::Compute)
return std::make_unique<VKShader>(stage, std::move(spv), mod);
return std::make_unique<VKShader>(stage, std::move(spv), mod, name);
// If it's a compute shader, we create the pipeline straight away.
const VkComputePipelineCreateInfo pipeline_info = {
@ -82,10 +101,11 @@ static std::unique_ptr<VKShader> CreateShaderObject(ShaderStage stage,
return nullptr;
}
return std::make_unique<VKShader>(std::move(spv), pipeline);
return std::make_unique<VKShader>(std::move(spv), pipeline, name);
}
std::unique_ptr<VKShader> VKShader::CreateFromSource(ShaderStage stage, std::string_view source)
std::unique_ptr<VKShader> VKShader::CreateFromSource(ShaderStage stage, std::string_view source,
std::string_view name)
{
std::optional<ShaderCompiler::SPIRVCodeVector> spv;
switch (stage)
@ -109,11 +129,11 @@ std::unique_ptr<VKShader> VKShader::CreateFromSource(ShaderStage stage, std::str
if (!spv)
return nullptr;
return CreateShaderObject(stage, std::move(*spv));
return CreateShaderObject(stage, std::move(*spv), name);
}
std::unique_ptr<VKShader> VKShader::CreateFromBinary(ShaderStage stage, const void* data,
size_t length)
size_t length, std::string_view name)
{
const size_t size_in_words = Common::AlignUp(length, sizeof(ShaderCompiler::SPIRVCodeType)) /
sizeof(ShaderCompiler::SPIRVCodeType);
@ -121,7 +141,7 @@ std::unique_ptr<VKShader> VKShader::CreateFromBinary(ShaderStage stage, const vo
if (length > 0)
std::memcpy(spv.data(), data, length);
return CreateShaderObject(stage, std::move(spv));
return CreateShaderObject(stage, std::move(spv), name);
}
} // namespace Vulkan

View File

@ -5,6 +5,7 @@
#include <cstddef>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
@ -17,22 +18,24 @@ namespace Vulkan
class VKShader final : public AbstractShader
{
public:
VKShader(ShaderStage stage, std::vector<u32> spv, VkShaderModule mod);
VKShader(std::vector<u32> spv, VkPipeline compute_pipeline);
VKShader(ShaderStage stage, std::vector<u32> spv, VkShaderModule mod, std::string_view name);
VKShader(std::vector<u32> spv, VkPipeline compute_pipeline, std::string_view name);
~VKShader() override;
VkShaderModule GetShaderModule() const { return m_module; }
VkPipeline GetComputePipeline() const { return m_compute_pipeline; }
BinaryData GetBinary() const override;
static std::unique_ptr<VKShader> CreateFromSource(ShaderStage stage, std::string_view source);
static std::unique_ptr<VKShader> CreateFromSource(ShaderStage stage, std::string_view source,
std::string_view name);
static std::unique_ptr<VKShader> CreateFromBinary(ShaderStage stage, const void* data,
size_t length);
size_t length, std::string_view name);
private:
std::vector<u32> m_spv;
VkShaderModule m_module;
VkPipeline m_compute_pipeline;
std::string m_name;
};
} // namespace Vulkan

View File

@ -23,11 +23,20 @@
namespace Vulkan
{
VKTexture::VKTexture(const TextureConfig& tex_config, VkDeviceMemory device_memory, VkImage image,
VkImageLayout layout /* = VK_IMAGE_LAYOUT_UNDEFINED */,
std::string_view name, VkImageLayout layout /* = VK_IMAGE_LAYOUT_UNDEFINED */,
ComputeImageLayout compute_layout /* = ComputeImageLayout::Undefined */)
: AbstractTexture(tex_config), m_device_memory(device_memory), m_image(image), m_layout(layout),
m_compute_layout(compute_layout)
m_compute_layout(compute_layout), m_name(name)
{
if (!m_name.empty())
{
VkDebugUtilsObjectNameInfoEXT name_info = {};
name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
name_info.objectType = VK_OBJECT_TYPE_IMAGE;
name_info.objectHandle = reinterpret_cast<uint64_t>(image);
name_info.pObjectName = m_name.c_str();
vkSetDebugUtilsObjectNameEXT(g_vulkan_context->GetDevice(), &name_info);
}
}
VKTexture::~VKTexture()
@ -43,7 +52,7 @@ VKTexture::~VKTexture()
}
}
std::unique_ptr<VKTexture> VKTexture::Create(const TextureConfig& tex_config)
std::unique_ptr<VKTexture> VKTexture::Create(const TextureConfig& tex_config, std::string_view name)
{
// Determine image usage, we need to flag as an attachment if it can be used as a rendertarget.
VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
@ -109,8 +118,9 @@ std::unique_ptr<VKTexture> VKTexture::Create(const TextureConfig& tex_config)
return nullptr;
}
std::unique_ptr<VKTexture> texture = std::make_unique<VKTexture>(
tex_config, device_memory, image, VK_IMAGE_LAYOUT_UNDEFINED, ComputeImageLayout::Undefined);
std::unique_ptr<VKTexture> texture =
std::make_unique<VKTexture>(tex_config, device_memory, image, name, VK_IMAGE_LAYOUT_UNDEFINED,
ComputeImageLayout::Undefined);
if (!texture->CreateView(VK_IMAGE_VIEW_TYPE_2D_ARRAY))
return nullptr;
@ -121,7 +131,7 @@ std::unique_ptr<VKTexture> VKTexture::CreateAdopted(const TextureConfig& tex_con
VkImageViewType view_type, VkImageLayout layout)
{
std::unique_ptr<VKTexture> texture = std::make_unique<VKTexture>(
tex_config, VkDeviceMemory(VK_NULL_HANDLE), image, layout, ComputeImageLayout::Undefined);
tex_config, VkDeviceMemory(VK_NULL_HANDLE), image, "", layout, ComputeImageLayout::Undefined);
if (!texture->CreateView(view_type))
return nullptr;

View File

@ -4,6 +4,8 @@
#pragma once
#include <memory>
#include <string>
#include <string_view>
#include "VideoBackends/Vulkan/VulkanLoader.h"
#include "VideoCommon/AbstractFramebuffer.h"
@ -29,7 +31,7 @@ public:
VKTexture() = delete;
VKTexture(const TextureConfig& tex_config, VkDeviceMemory device_memory, VkImage image,
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED,
std::string_view name, VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED,
ComputeImageLayout compute_layout = ComputeImageLayout::Undefined);
~VKTexture();
@ -55,7 +57,7 @@ public:
VkFormat GetVkFormat() const { return GetVkFormatForHostTextureFormat(m_config.format); }
bool IsAdopted() const { return m_device_memory != VkDeviceMemory(VK_NULL_HANDLE); }
static std::unique_ptr<VKTexture> Create(const TextureConfig& tex_config);
static std::unique_ptr<VKTexture> Create(const TextureConfig& tex_config, std::string_view name);
static std::unique_ptr<VKTexture>
CreateAdopted(const TextureConfig& tex_config, VkImage image,
VkImageViewType view_type = VK_IMAGE_VIEW_TYPE_2D_ARRAY,
@ -77,6 +79,7 @@ private:
VkImageView m_view = VK_NULL_HANDLE;
mutable VkImageLayout m_layout = VK_IMAGE_LAYOUT_UNDEFINED;
mutable ComputeImageLayout m_compute_layout = ComputeImageLayout::Undefined;
std::string m_name;
};
class VKStagingTexture final : public AbstractStagingTexture

View File

@ -223,6 +223,7 @@ bool VulkanContext::SelectInstanceExtensions(std::vector<const char*>* extension
AddExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, false);
AddExtension(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, false);
AddExtension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, false);
return true;
}

View File

@ -197,4 +197,6 @@ VULKAN_DEVICE_ENTRY_POINT(vkAcquireFullScreenExclusiveModeEXT, false)
VULKAN_DEVICE_ENTRY_POINT(vkReleaseFullScreenExclusiveModeEXT, false)
#endif
VULKAN_DEVICE_ENTRY_POINT(vkSetDebugUtilsObjectNameEXT, false)
#endif // VULKAN_DEVICE_ENTRY_POINT