Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10065 from iwubcode/graphics-debug-details
VideoBackends / VideoCommon: expose ability to view shader/texture debug names
  • Loading branch information
leoetlino committed Aug 30, 2021
2 parents 9b83cf3 + 1f2f505 commit d94aa91
Show file tree
Hide file tree
Showing 32 changed files with 276 additions and 133 deletions.
16 changes: 9 additions & 7 deletions Source/Core/VideoBackends/D3D/D3DRender.cpp
Expand Up @@ -52,9 +52,10 @@ bool Renderer::IsHeadless() const
return !m_swap_chain;
}

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,
Expand All @@ -70,20 +71,21 @@ 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)
{
auto bytecode = DXShader::CompileShader(D3D::feature_level, stage, source);
if (!bytecode)
return nullptr;

return DXShader::CreateFromBytecode(stage, std::move(*bytecode));
return DXShader::CreateFromBytecode(stage, std::move(*bytecode), 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<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config,
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/VideoBackends/D3D/D3DRender.h
Expand Up @@ -24,13 +24,15 @@ class Renderer : 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<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
21 changes: 14 additions & 7 deletions Source/Core/VideoBackends/D3D/DXShader.cpp
Expand Up @@ -7,9 +7,15 @@

namespace DX11
{
DXShader::DXShader(ShaderStage stage, BinaryData bytecode, ID3D11DeviceChild* shader)
: D3DCommon::Shader(stage, std::move(bytecode)), m_shader(shader)
DXShader::DXShader(ShaderStage stage, BinaryData bytecode, ID3D11DeviceChild* shader,
std::string_view name)
: D3DCommon::Shader(stage, std::move(bytecode)), m_shader(shader), m_name(name)
{
if (!m_name.empty())
{
m_shader->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(m_name.size()),
m_name.data());
}
}

DXShader::~DXShader() = default;
Expand Down Expand Up @@ -38,7 +44,8 @@ ID3D11ComputeShader* DXShader::GetD3DComputeShader() const
return static_cast<ID3D11ComputeShader*>(m_shader.Get());
}

std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, BinaryData bytecode)
std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, BinaryData bytecode,
std::string_view name)
{
switch (stage)
{
Expand All @@ -50,7 +57,7 @@ std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, Binary
if (FAILED(hr))
return nullptr;

return std::make_unique<DXShader>(ShaderStage::Vertex, std::move(bytecode), vs.Get());
return std::make_unique<DXShader>(ShaderStage::Vertex, std::move(bytecode), vs.Get(), name);
}

case ShaderStage::Geometry:
Expand All @@ -61,7 +68,7 @@ std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, Binary
if (FAILED(hr))
return nullptr;

return std::make_unique<DXShader>(ShaderStage::Geometry, std::move(bytecode), gs.Get());
return std::make_unique<DXShader>(ShaderStage::Geometry, std::move(bytecode), gs.Get(), name);
}
break;

Expand All @@ -73,7 +80,7 @@ std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, Binary
if (FAILED(hr))
return nullptr;

return std::make_unique<DXShader>(ShaderStage::Pixel, std::move(bytecode), ps.Get());
return std::make_unique<DXShader>(ShaderStage::Pixel, std::move(bytecode), ps.Get(), name);
}
break;

Expand All @@ -85,7 +92,7 @@ std::unique_ptr<DXShader> DXShader::CreateFromBytecode(ShaderStage stage, Binary
if (FAILED(hr))
return nullptr;

return std::make_unique<DXShader>(ShaderStage::Compute, std::move(bytecode), cs.Get());
return std::make_unique<DXShader>(ShaderStage::Compute, std::move(bytecode), cs.Get(), name);
}
break;

Expand Down
10 changes: 8 additions & 2 deletions Source/Core/VideoBackends/D3D/DXShader.h
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

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

#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3DCommon/Shader.h"
Expand All @@ -12,18 +15,21 @@ namespace DX11
class DXShader final : public D3DCommon::Shader
{
public:
DXShader(ShaderStage stage, BinaryData bytecode, ID3D11DeviceChild* shader);
DXShader(ShaderStage stage, BinaryData bytecode, ID3D11DeviceChild* shader,
std::string_view name);
~DXShader() override;

ID3D11VertexShader* GetD3DVertexShader() const;
ID3D11GeometryShader* GetD3DGeometryShader() const;
ID3D11PixelShader* GetD3DPixelShader() const;
ID3D11ComputeShader* GetD3DComputeShader() const;

static std::unique_ptr<DXShader> CreateFromBytecode(ShaderStage stage, BinaryData bytecode);
static std::unique_ptr<DXShader> CreateFromBytecode(ShaderStage stage, BinaryData bytecode,
std::string_view name);

private:
ComPtr<ID3D11DeviceChild> m_shader;
std::string m_name;
};

} // namespace DX11
16 changes: 11 additions & 5 deletions Source/Core/VideoBackends/D3D/DXTexture.cpp
Expand Up @@ -15,9 +15,15 @@

namespace DX11
{
DXTexture::DXTexture(const TextureConfig& config, ComPtr<ID3D11Texture2D> texture)
: AbstractTexture(config), m_texture(std::move(texture))
DXTexture::DXTexture(const TextureConfig& config, ComPtr<ID3D11Texture2D> texture,
std::string_view name)
: AbstractTexture(config), m_texture(std::move(texture)), m_name(name)
{
if (!m_name.empty())
{
m_texture->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast<UINT>(m_name.size()),
m_name.c_str());
}
}

DXTexture::~DXTexture()
Expand All @@ -26,7 +32,7 @@ DXTexture::~DXTexture()
D3D::stateman->ApplyTextures();
}

std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config)
std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config, std::string_view name)
{
// Use typeless to create the texture when it's a render target, so we can alias it with an
// integer format (for EFB).
Expand All @@ -49,7 +55,7 @@ std::unique_ptr<DXTexture> DXTexture::Create(const TextureConfig& config)
return nullptr;
}

std::unique_ptr<DXTexture> tex(new DXTexture(config, std::move(d3d_texture)));
std::unique_ptr<DXTexture> tex(new DXTexture(config, std::move(d3d_texture), name));
if (!tex->CreateSRV() || (config.IsComputeImage() && !tex->CreateUAV()))
return nullptr;

Expand All @@ -70,7 +76,7 @@ std::unique_ptr<DXTexture> DXTexture::CreateAdopted(ComPtr<ID3D11Texture2D> text
if (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS)
config.flags |= AbstractTextureFlag_ComputeImage;

std::unique_ptr<DXTexture> tex(new DXTexture(config, std::move(texture)));
std::unique_ptr<DXTexture> tex(new DXTexture(config, std::move(texture), ""));
if (desc.BindFlags & D3D11_BIND_SHADER_RESOURCE && !tex->CreateSRV())
return nullptr;
if (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS && !tex->CreateUAV())
Expand Down
7 changes: 5 additions & 2 deletions Source/Core/VideoBackends/D3D/DXTexture.h
Expand Up @@ -5,6 +5,8 @@

#include <d3d11.h>
#include <memory>
#include <string>
#include <string_view>
#include "Common/CommonTypes.h"

#include "VideoCommon/AbstractFramebuffer.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(ComPtr<ID3D11Texture2D> texture);

void CopyRectangleFromTexture(const AbstractTexture* src,
Expand All @@ -35,14 +37,15 @@ class DXTexture final : public AbstractTexture
ID3D11UnorderedAccessView* GetD3DUAV() const { return m_uav.Get(); }

private:
DXTexture(const TextureConfig& config, ComPtr<ID3D11Texture2D> texture);
DXTexture(const TextureConfig& config, ComPtr<ID3D11Texture2D> texture, std::string_view name);

bool CreateSRV();
bool CreateUAV();

ComPtr<ID3D11Texture2D> m_texture;
ComPtr<ID3D11ShaderResourceView> m_srv;
ComPtr<ID3D11UnorderedAccessView> m_uav;
std::string m_name;
};

class DXStagingTexture final : public AbstractStagingTexture
Expand Down
16 changes: 9 additions & 7 deletions Source/Core/VideoBackends/D3D12/D3D12Renderer.cpp
Expand Up @@ -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,
Expand All @@ -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>
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/VideoBackends/D3D12/D3D12Renderer.h
Expand Up @@ -30,16 +30,18 @@ class Renderer final : 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
21 changes: 15 additions & 6 deletions Source/Core/VideoBackends/D3D12/DX12Shader.cpp
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions Source/Core/VideoBackends/D3D12/DX12Shader.h
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <memory>
#include <string>
#include <string_view>
#include "VideoBackends/D3D12/Common.h"
#include "VideoBackends/D3DCommon/Shader.h"
Expand All @@ -18,15 +19,19 @@ class DXShader final : public D3DCommon::Shader
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

0 comments on commit d94aa91

Please sign in to comment.