diff options
| author | iwubcode <iwubcode@users.noreply.github.com> | 2021-08-28 00:30:05 -0500 |
|---|---|---|
| committer | iwubcode <iwubcode@users.noreply.github.com> | 2021-08-30 13:47:48 -0500 |
| commit | 1f2f5053735b4e94dac29237e9482befd9a2687b (patch) | |
| tree | dfe18ba017a6cda4a79c01c10431c7c37e8f74a3 /Source/Core/VideoBackends/Vulkan/VKShader.cpp | |
| parent | 9b83cf3e7fdf6fc4d15b78193461fd1081d61008 (diff) | |
VideoBackends / VideoCommon: allow the ability to set debug names for shaders / textures. These names are visible in applications like RenderDoc
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/VKShader.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/Vulkan/VKShader.cpp | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/VKShader.cpp b/Source/Core/VideoBackends/Vulkan/VKShader.cpp index e17c2c6569..cd910b898a 100644 --- a/Source/Core/VideoBackends/Vulkan/VKShader.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKShader.cpp @@ -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 |
