16 changes: 11 additions & 5 deletions Source/Core/VideoBackends/D3D12/DX12Texture.cpp
Expand Up @@ -4,6 +4,7 @@
#include "VideoBackends/D3D12/DX12Texture.h"
#include "Common/Align.h"
#include "Common/Assert.h"
#include "Common/StringUtil.h"
#include "VideoBackends/D3D12/Common.h"
#include "VideoBackends/D3D12/D3D12Renderer.h"
#include "VideoBackends/D3D12/D3D12StreamBuffer.h"
Expand Down Expand Up @@ -41,9 +42,13 @@ static ComPtr<ID3D12Resource> CreateTextureUploadBuffer(u32 buffer_size)
}

DXTexture::DXTexture(const TextureConfig& config, ID3D12Resource* resource,
D3D12_RESOURCE_STATES state)
: AbstractTexture(config), m_resource(resource), m_state(state)
D3D12_RESOURCE_STATES state, std::string_view name)
: AbstractTexture(config), m_resource(resource), m_state(state), m_name(UTF8ToWString(name))
{
if (!m_name.empty())
{
resource->SetName(m_name.c_str());
}
}

DXTexture::~DXTexture()
Expand All @@ -63,7 +68,7 @@ DXTexture::~DXTexture()
g_dx_context->DeferResourceDestruction(m_resource.Get());
}

std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config)
std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config, std::string_view name)
{
constexpr D3D12_HEAP_PROPERTIES heap_properties = {D3D12_HEAP_TYPE_DEFAULT};
D3D12_RESOURCE_STATES resource_state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
Expand Down Expand Up @@ -113,7 +118,8 @@ std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config)
if (FAILED(hr))
return nullptr;

auto tex = std::unique_ptr<DXTexture>(new DXTexture(config, resource.Get(), resource_state));
auto tex =
std::unique_ptr<DXTexture>(new DXTexture(config, resource.Get(), resource_state, name));
if (!tex->CreateSRVDescriptor() || (config.IsComputeImage() && !tex->CreateUAVDescriptor()))
return nullptr;

Expand Down Expand Up @@ -142,7 +148,7 @@ std::unique_ptr<DXTexture> DXTexture::CreateAdopted(ID3D12Resource* resource)
config.flags |= AbstractTextureFlag_ComputeImage;

auto tex =
std::unique_ptr<DXTexture>(new DXTexture(config, resource, D3D12_RESOURCE_STATE_COMMON));
std::unique_ptr<DXTexture>(new DXTexture(config, resource, D3D12_RESOURCE_STATE_COMMON, ""));
if (!tex->CreateSRVDescriptor())
return nullptr;

Expand Down
9 changes: 7 additions & 2 deletions Source/Core/VideoBackends/D3D12/DX12Texture.h
Expand Up @@ -4,6 +4,8 @@
#pragma once

#include <memory>
#include <string>
#include <string_view>
#include "Common/CommonTypes.h"
#include "VideoBackends/D3D12/Common.h"
#include "VideoBackends/D3D12/DescriptorHeapManager.h"
Expand All @@ -18,7 +20,7 @@ class DXTexture final : public AbstractTexture
public:
~DXTexture();

static std::unique_ptr<DXTexture> Create(const TextureConfig& config);
static std::unique_ptr<DXTexture> Create(const TextureConfig& config, std::string_view name);
static std::unique_ptr<DXTexture> CreateAdopted(ID3D12Resource* resource);

void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer,
Expand All @@ -43,7 +45,8 @@ class DXTexture final : public AbstractTexture
void DestroyResource();

private:
DXTexture(const TextureConfig& config, ID3D12Resource* resource, D3D12_RESOURCE_STATES state);
DXTexture(const TextureConfig& config, ID3D12Resource* resource, D3D12_RESOURCE_STATES state,
std::string_view name);

bool CreateSRVDescriptor();
bool CreateUAVDescriptor();
Expand All @@ -52,6 +55,8 @@ class DXTexture final : public AbstractTexture
DescriptorHandle m_srv_descriptor = {};
DescriptorHandle m_uav_descriptor = {};

std::wstring m_name;

mutable D3D12_RESOURCE_STATES m_state;
};

Expand Down
11 changes: 7 additions & 4 deletions Source/Core/VideoBackends/Null/NullRender.cpp
Expand Up @@ -28,7 +28,8 @@ bool Renderer::IsHeadless() const
return true;
}

std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<NullTexture>(config);
}
Expand All @@ -46,13 +47,15 @@ class NullShader final : public AbstractShader
};

std::unique_ptr<AbstractShader>
Renderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source)
Renderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<NullShader>(stage);
}

std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
const void* data, size_t length)
std::unique_ptr<AbstractShader>
Renderer::CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<NullShader>(stage);
}
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/VideoBackends/Null/NullRender.h
Expand Up @@ -15,16 +15,18 @@ class Renderer final : public ::Renderer

bool IsHeadless() const 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,
Expand Down
16 changes: 9 additions & 7 deletions Source/Core/VideoBackends/OGL/OGLRender.cpp
Expand Up @@ -807,9 +807,10 @@ void Renderer::Shutdown()
glDeleteFramebuffers(1, &m_shared_read_framebuffer);
}

std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config,
std::string_view name)
{
return std::make_unique<OGLTexture>(config);
return std::make_unique<OGLTexture>(config, name);
}

std::unique_ptr<AbstractStagingTexture> Renderer::CreateStagingTexture(StagingTextureType type,
Expand All @@ -825,14 +826,15 @@ std::unique_ptr<AbstractFramebuffer> Renderer::CreateFramebuffer(AbstractTexture
static_cast<OGLTexture*>(depth_attachment));
}

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 OGLShader::CreateFromSource(stage, source);
return OGLShader::CreateFromSource(stage, source, name);
}

std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
const void* data, size_t length)
std::unique_ptr<AbstractShader>
Renderer::CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length,
[[maybe_unused]] std::string_view name)
{
return nullptr;
}
Expand Down
11 changes: 7 additions & 4 deletions Source/Core/VideoBackends/OGL/OGLRender.h
Expand Up @@ -5,6 +5,7 @@

#include <array>
#include <string>
#include <string_view>

#include "Common/GL/GLContext.h"
#include "Common/GL/GLExtensions/GLExtensions.h"
Expand Down Expand Up @@ -91,13 +92,15 @@ class Renderer : public ::Renderer
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<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,
Expand Down
26 changes: 19 additions & 7 deletions Source/Core/VideoBackends/OGL/OGLShader.cpp
Expand Up @@ -23,17 +23,26 @@ static GLenum GetGLShaderTypeForStage(ShaderStage stage)
}
}

OGLShader::OGLShader(ShaderStage stage, GLenum gl_type, GLuint gl_id, std::string source)
OGLShader::OGLShader(ShaderStage stage, GLenum gl_type, GLuint gl_id, std::string source,
std::string name)
: AbstractShader(stage), m_id(ProgramShaderCache::GenerateShaderID()), m_type(gl_type),
m_gl_id(gl_id), m_source(std::move(source))
m_gl_id(gl_id), m_source(std::move(source)), m_name(std::move(name))
{
if (!m_name.empty())
{
glObjectLabel(GetGLShaderTypeForStage(stage), m_gl_id, -1, m_name.c_str());
}
}

OGLShader::OGLShader(GLuint gl_compute_program_id, std::string source)
OGLShader::OGLShader(GLuint gl_compute_program_id, std::string source, std::string name)
: AbstractShader(ShaderStage::Compute), m_id(ProgramShaderCache::GenerateShaderID()),
m_type(GL_COMPUTE_SHADER), m_gl_compute_program_id(gl_compute_program_id),
m_source(std::move(source))
m_source(std::move(source)), m_name(std::move(name))
{
if (!m_name.empty())
{
glObjectLabel(GL_COMPUTE_SHADER, m_gl_compute_program_id, -1, m_name.c_str());
}
}

OGLShader::~OGLShader()
Expand All @@ -44,24 +53,27 @@ OGLShader::~OGLShader()
glDeleteProgram(m_gl_compute_program_id);
}

std::unique_ptr<OGLShader> OGLShader::CreateFromSource(ShaderStage stage, std::string_view source)
std::unique_ptr<OGLShader> OGLShader::CreateFromSource(ShaderStage stage, std::string_view source,
std::string_view name)
{
std::string source_str(source);
std::string name_str(name);
if (stage != ShaderStage::Compute)
{
GLenum shader_type = GetGLShaderTypeForStage(stage);
GLuint shader_id = ProgramShaderCache::CompileSingleShader(shader_type, source_str);
if (!shader_id)
return nullptr;

return std::make_unique<OGLShader>(stage, shader_type, shader_id, std::move(source_str));
return std::make_unique<OGLShader>(stage, shader_type, shader_id, std::move(source_str),
std::move(name_str));
}

// Compute shaders.
SHADER prog;
if (!ProgramShaderCache::CompileComputeShader(prog, source_str))
return nullptr;
return std::make_unique<OGLShader>(prog.glprogid, std::move(source_str));
return std::make_unique<OGLShader>(prog.glprogid, std::move(source_str), std::move(name_str));
}

} // namespace OGL
10 changes: 7 additions & 3 deletions Source/Core/VideoBackends/OGL/OGLShader.h
Expand Up @@ -5,6 +5,7 @@

#include <cstddef>
#include <memory>
#include <string>
#include <string_view>

#include "Common/CommonTypes.h"
Expand All @@ -16,8 +17,9 @@ namespace OGL
class OGLShader final : public AbstractShader
{
public:
explicit OGLShader(ShaderStage stage, GLenum gl_type, GLuint gl_id, std::string source);
explicit OGLShader(GLuint gl_compute_program_id, std::string source);
explicit OGLShader(ShaderStage stage, GLenum gl_type, GLuint gl_id, std::string source,
std::string name);
explicit OGLShader(GLuint gl_compute_program_id, std::string source, std::string name);
~OGLShader() override;

u64 GetID() const { return m_id; }
Expand All @@ -26,14 +28,16 @@ class OGLShader final : public AbstractShader
GLuint GetGLComputeProgramID() const { return m_gl_compute_program_id; }
const std::string& GetSource() const { return m_source; }

static std::unique_ptr<OGLShader> CreateFromSource(ShaderStage stage, std::string_view source);
static std::unique_ptr<OGLShader> CreateFromSource(ShaderStage stage, std::string_view source,
std::string_view name);

private:
u64 m_id;
GLenum m_type;
GLuint m_gl_id = 0;
GLuint m_gl_compute_program_id = 0;
std::string m_source;
std::string m_name;
};

} // namespace OGL
8 changes: 7 additions & 1 deletion Source/Core/VideoBackends/OGL/OGLTexture.cpp
Expand Up @@ -104,7 +104,8 @@ bool UsePersistentStagingBuffers()
}
} // Anonymous namespace

OGLTexture::OGLTexture(const TextureConfig& tex_config) : AbstractTexture(tex_config)
OGLTexture::OGLTexture(const TextureConfig& tex_config, std::string_view name)
: AbstractTexture(tex_config), m_name(name)
{
DEBUG_ASSERT_MSG(VIDEO, !tex_config.IsMultisampled() || tex_config.levels == 1,
"OpenGL does not support multisampled textures with mip levels");
Expand All @@ -114,6 +115,11 @@ OGLTexture::OGLTexture(const TextureConfig& tex_config) : AbstractTexture(tex_co
glActiveTexture(GL_MUTABLE_TEXTURE_INDEX);
glBindTexture(target, m_texId);

if (!m_name.empty())
{
glObjectLabel(GL_TEXTURE, m_texId, -1, m_name.c_str());
}

glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, m_config.levels - 1);

GLenum gl_internal_format = GetGLInternalFormatForTextureFormat(m_config.format, true);
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/VideoBackends/OGL/OGLTexture.h
Expand Up @@ -4,6 +4,8 @@
#pragma once

#include <memory>
#include <string>
#include <string_view>
#include <vector>

#include "Common/GL/GLUtil.h"
Expand All @@ -17,7 +19,7 @@ namespace OGL
class OGLTexture final : public AbstractTexture
{
public:
explicit OGLTexture(const TextureConfig& tex_config);
explicit OGLTexture(const TextureConfig& tex_config, std::string_view name);
~OGLTexture();

void CopyRectangleFromTexture(const AbstractTexture* src,
Expand All @@ -42,6 +44,7 @@ class OGLTexture final : public AbstractTexture
u32 dst_layer, u32 dst_level);

GLuint m_texId;
std::string m_name;
};

class OGLStagingTexture final : public AbstractStagingTexture
Expand Down
11 changes: 7 additions & 4 deletions Source/Core/VideoBackends/Software/SWRenderer.cpp
Expand Up @@ -38,7 +38,8 @@ bool SWRenderer::IsHeadless() const
return m_window->IsHeadless();
}

std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config)
std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<SWTexture>(config);
}
Expand Down Expand Up @@ -78,13 +79,15 @@ class SWShader final : public AbstractShader
};

std::unique_ptr<AbstractShader>
SWRenderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source)
SWRenderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<SWShader>(stage);
}

std::unique_ptr<AbstractShader> SWRenderer::CreateShaderFromBinary(ShaderStage stage,
const void* data, size_t length)
std::unique_ptr<AbstractShader>
SWRenderer::CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length,
[[maybe_unused]] std::string_view name)
{
return std::make_unique<SWShader>(stage);
}
Expand Down
11 changes: 7 additions & 4 deletions Source/Core/VideoBackends/Software/SWRenderer.h
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <memory>
#include <string_view>

#include "Common/CommonTypes.h"

Expand All @@ -20,18 +21,20 @@ class SWRenderer final : public Renderer

bool IsHeadless() const 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;

void BindBackbuffer(const ClearColor& clear_color = {}) 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,
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Vulkan/StateTracker.cpp
Expand Up @@ -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(),
Expand Down
16 changes: 9 additions & 7 deletions Source/Core/VideoBackends/Vulkan/VKRenderer.cpp
Expand Up @@ -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,
Expand All @@ -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>
Expand Down
11 changes: 7 additions & 4 deletions Source/Core/VideoBackends/Vulkan/VKRenderer.h
Expand Up @@ -6,6 +6,7 @@
#include <array>
#include <cstddef>
#include <memory>
#include <string_view>

#include "Common/CommonTypes.h"
#include "VideoBackends/Vulkan/Constants.h"
Expand Down Expand Up @@ -35,16 +36,18 @@ class Renderer : public ::Renderer
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,
Expand Down
44 changes: 32 additions & 12 deletions Source/Core/VideoBackends/Vulkan/VKShader.cpp
Expand Up @@ -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()
Expand All @@ -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;
Expand All @@ -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 = {
Expand All @@ -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)
Expand All @@ -109,19 +129,19 @@ 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);
ShaderCompiler::SPIRVCodeVector spv(size_in_words);
if (length > 0)
std::memcpy(spv.data(), data, length);

return CreateShaderObject(stage, std::move(spv));
return CreateShaderObject(stage, std::move(spv), name);
}

} // namespace Vulkan
11 changes: 7 additions & 4 deletions Source/Core/VideoBackends/Vulkan/VKShader.h
Expand Up @@ -5,6 +5,7 @@

#include <cstddef>
#include <memory>
#include <string>
#include <string_view>
#include <vector>

Expand All @@ -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
22 changes: 16 additions & 6 deletions Source/Core/VideoBackends/Vulkan/VKTexture.cpp
Expand Up @@ -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()
Expand All @@ -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 |
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions Source/Core/VideoBackends/Vulkan/VKTexture.h
Expand Up @@ -4,6 +4,8 @@
#pragma once

#include <memory>
#include <string>
#include <string_view>

#include "VideoBackends/Vulkan/VulkanLoader.h"
#include "VideoCommon/AbstractFramebuffer.h"
Expand All @@ -29,7 +31,7 @@ class VKTexture final : public AbstractTexture

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();

Expand All @@ -55,7 +57,7 @@ class VKTexture final : public AbstractTexture
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,
Expand All @@ -77,6 +79,7 @@ class VKTexture final : public AbstractTexture
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
Expand Down
1 change: 1 addition & 0 deletions Source/Core/VideoBackends/Vulkan/VulkanContext.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/VideoBackends/Vulkan/VulkanEntryPoints.inl
Expand Up @@ -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
11 changes: 7 additions & 4 deletions Source/Core/VideoCommon/RenderBase.h
Expand Up @@ -93,7 +93,8 @@ class Renderer
virtual bool IsFullscreen() const { return false; }
virtual void BeginUtilityDrawing();
virtual void EndUtilityDrawing();
virtual std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) = 0;
virtual std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config,
std::string_view name = "") = 0;
virtual std::unique_ptr<AbstractStagingTexture>
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) = 0;
virtual std::unique_ptr<AbstractFramebuffer>
Expand Down Expand Up @@ -125,9 +126,11 @@ class Renderer

// Shader modules/objects.
virtual std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage,
std::string_view source) = 0;
virtual std::unique_ptr<AbstractShader>
CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) = 0;
std::string_view source,
std::string_view name = "") = 0;
virtual std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage,
const void* data, size_t length,
std::string_view name = "") = 0;
virtual std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0;
virtual std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
Expand Down