mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
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:
@ -62,9 +62,10 @@ void Renderer::Shutdown()
|
||||
::Renderer::Shutdown();
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
|
||||
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config,
|
||||
std::string_view name)
|
||||
{
|
||||
return DXTexture::Create(config);
|
||||
return DXTexture::Create(config, name);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractStagingTexture> Renderer::CreateStagingTexture(StagingTextureType type,
|
||||
@ -80,16 +81,17 @@ std::unique_ptr<AbstractFramebuffer> Renderer::CreateFramebuffer(AbstractTexture
|
||||
static_cast<DXTexture*>(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 DXShader::CreateFromSource(stage, source);
|
||||
return DXShader::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 DXShader::CreateFromBytecode(stage, DXShader::CreateByteCode(data, length));
|
||||
return DXShader::CreateFromBytecode(stage, DXShader::CreateByteCode(data, length), name);
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
|
@ -30,16 +30,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,
|
||||
|
@ -2,34 +2,43 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "VideoBackends/D3D12/DX12Shader.h"
|
||||
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "VideoBackends/D3D12/Common.h"
|
||||
#include "VideoBackends/D3D12/DX12Context.h"
|
||||
|
||||
namespace DX12
|
||||
{
|
||||
DXShader::DXShader(ShaderStage stage, BinaryData bytecode)
|
||||
: D3DCommon::Shader(stage, std::move(bytecode))
|
||||
DXShader::DXShader(ShaderStage stage, BinaryData bytecode, std::string_view name)
|
||||
: D3DCommon::Shader(stage, std::move(bytecode)), m_name(UTF8ToWString(name))
|
||||
{
|
||||
if (!m_name.empty())
|
||||
{
|
||||
m_compute_pipeline->SetName(m_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
DXShader::~DXShader() = default;
|
||||
|
||||
std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, BinaryData bytecode)
|
||||
std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, BinaryData bytecode,
|
||||
std::string_view name)
|
||||
{
|
||||
std::unique_ptr<DXShader> shader(new DXShader(stage, std::move(bytecode)));
|
||||
std::unique_ptr<DXShader> shader(new DXShader(stage, std::move(bytecode), name));
|
||||
if (stage == ShaderStage::Compute && !shader->CreateComputePipeline())
|
||||
return nullptr;
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
std::unique_ptr<DXShader> DXShader::CreateFromSource(ShaderStage stage, std::string_view source)
|
||||
std::unique_ptr<DXShader> DXShader::CreateFromSource(ShaderStage stage, std::string_view source,
|
||||
std::string_view name)
|
||||
{
|
||||
auto bytecode = CompileShader(g_dx_context->GetFeatureLevel(), stage, source);
|
||||
if (!bytecode)
|
||||
return nullptr;
|
||||
|
||||
return CreateFromBytecode(stage, std::move(*bytecode));
|
||||
return CreateFromBytecode(stage, std::move(*bytecode), name);
|
||||
}
|
||||
|
||||
D3D12_SHADER_BYTECODE DXShader::GetD3DByteCode() const
|
||||
|
@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include "VideoBackends/D3D12/Common.h"
|
||||
#include "VideoBackends/D3DCommon/Shader.h"
|
||||
@ -18,15 +19,19 @@ public:
|
||||
ID3D12PipelineState* GetComputePipeline() const { return m_compute_pipeline.Get(); }
|
||||
D3D12_SHADER_BYTECODE GetD3DByteCode() const;
|
||||
|
||||
static std::unique_ptr<DXShader> CreateFromBytecode(ShaderStage stage, BinaryData bytecode);
|
||||
static std::unique_ptr<DXShader> CreateFromSource(ShaderStage stage, std::string_view source);
|
||||
static std::unique_ptr<DXShader> CreateFromBytecode(ShaderStage stage, BinaryData bytecode,
|
||||
std::string_view name);
|
||||
static std::unique_ptr<DXShader> CreateFromSource(ShaderStage stage, std::string_view source,
|
||||
std::string_view name);
|
||||
|
||||
private:
|
||||
DXShader(ShaderStage stage, BinaryData bytecode);
|
||||
DXShader(ShaderStage stage, BinaryData bytecode, std::string_view name);
|
||||
|
||||
bool CreateComputePipeline();
|
||||
|
||||
ComPtr<ID3D12PipelineState> m_compute_pipeline;
|
||||
|
||||
std::wstring m_name;
|
||||
};
|
||||
|
||||
} // namespace DX12
|
||||
|
@ -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"
|
||||
@ -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()
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
@ -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,
|
||||
@ -43,7 +45,8 @@ public:
|
||||
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();
|
||||
@ -52,6 +55,8 @@ private:
|
||||
DescriptorHandle m_srv_descriptor = {};
|
||||
DescriptorHandle m_uav_descriptor = {};
|
||||
|
||||
std::wstring m_name;
|
||||
|
||||
mutable D3D12_RESOURCE_STATES m_state;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user