summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2021-08-28 00:30:05 -0500
committeriwubcode <iwubcode@users.noreply.github.com>2021-08-30 13:47:48 -0500
commit1f2f5053735b4e94dac29237e9482befd9a2687b (patch)
treedfe18ba017a6cda4a79c01c10431c7c37e8f74a3 /Source/Core/VideoBackends/Vulkan
parent9b83cf3e7fdf6fc4d15b78193461fd1081d61008 (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')
-rw-r--r--Source/Core/VideoBackends/Vulkan/StateTracker.cpp2
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKRenderer.cpp16
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKRenderer.h11
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKShader.cpp44
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKShader.h11
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKTexture.cpp22
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKTexture.h7
-rw-r--r--Source/Core/VideoBackends/Vulkan/VulkanContext.cpp1
-rw-r--r--Source/Core/VideoBackends/Vulkan/VulkanEntryPoints.inl2
9 files changed, 80 insertions, 36 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
index cde48e1965..db59b16398 100644
--- a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
+++ b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
@@ -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(),
diff --git a/Source/Core/VideoBackends/Vulkan/VKRenderer.cpp b/Source/Core/VideoBackends/Vulkan/VKRenderer.cpp
index df10b3d2d7..4623094776 100644
--- a/Source/Core/VideoBackends/Vulkan/VKRenderer.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKRenderer.cpp
@@ -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>
diff --git a/Source/Core/VideoBackends/Vulkan/VKRenderer.h b/Source/Core/VideoBackends/Vulkan/VKRenderer.h
index fc447c77b4..d44776a0eb 100644
--- a/Source/Core/VideoBackends/Vulkan/VKRenderer.h
+++ b/Source/Core/VideoBackends/Vulkan/VKRenderer.h
@@ -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,
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
diff --git a/Source/Core/VideoBackends/Vulkan/VKShader.h b/Source/Core/VideoBackends/Vulkan/VKShader.h
index 0efb2e6ccd..8414983aaa 100644
--- a/Source/Core/VideoBackends/Vulkan/VKShader.h
+++ b/Source/Core/VideoBackends/Vulkan/VKShader.h
@@ -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
diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
index 2d826c0ca6..f744eb2e79 100644
--- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
@@ -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;
diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.h b/Source/Core/VideoBackends/Vulkan/VKTexture.h
index 283e8169df..ce25fec74f 100644
--- a/Source/Core/VideoBackends/Vulkan/VKTexture.h
+++ b/Source/Core/VideoBackends/Vulkan/VKTexture.h
@@ -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
diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp
index b0941ae856..63ad23e7ed 100644
--- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp
@@ -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;
}
diff --git a/Source/Core/VideoBackends/Vulkan/VulkanEntryPoints.inl b/Source/Core/VideoBackends/Vulkan/VulkanEntryPoints.inl
index 9006baf91a..6233ceb9f6 100644
--- a/Source/Core/VideoBackends/Vulkan/VulkanEntryPoints.inl
+++ b/Source/Core/VideoBackends/Vulkan/VulkanEntryPoints.inl
@@ -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