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

@ -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