mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07: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:
@@ -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,
|
||||
@@ -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,
|
||||
|
||||
@@ -24,13 +24,15 @@ public:
|
||||
|
||||
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,
|
||||
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
{
|
||||
@@ -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:
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -12,7 +15,8 @@ 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;
|
||||
@@ -20,10 +24,12 @@ public:
|
||||
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
|
||||
|
||||
@@ -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()
|
||||
@@ -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).
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
#include "VideoCommon/AbstractFramebuffer.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(ComPtr<ID3D11Texture2D> texture);
|
||||
|
||||
void CopyRectangleFromTexture(const AbstractTexture* src,
|
||||
@@ -35,7 +37,7 @@ public:
|
||||
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();
|
||||
@@ -43,6 +45,7 @@ private:
|
||||
ComPtr<ID3D11Texture2D> m_texture;
|
||||
ComPtr<ID3D11ShaderResourceView> m_srv;
|
||||
ComPtr<ID3D11UnorderedAccessView> m_uav;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
class DXStagingTexture final : public AbstractStagingTexture
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -46,13 +47,15 @@ public:
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -15,16 +15,18 @@ public:
|
||||
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "Common/GL/GLContext.h"
|
||||
#include "Common/GL/GLExtensions/GLExtensions.h"
|
||||
@@ -91,13 +92,15 @@ 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<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,
|
||||
|
||||
@@ -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()
|
||||
@@ -44,9 +53,11 @@ 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);
|
||||
@@ -54,14 +65,15 @@ std::unique_ptr<OGLShader> OGLShader::CreateFromSource(ShaderStage stage, std::s
|
||||
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
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@@ -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; }
|
||||
@@ -26,7 +28,8 @@ public:
|
||||
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;
|
||||
@@ -34,6 +37,7 @@ private:
|
||||
GLuint m_gl_id = 0;
|
||||
GLuint m_gl_compute_program_id = 0;
|
||||
std::string m_source;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
} // namespace OGL
|
||||
|
||||
@@ -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");
|
||||
@@ -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);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/GL/GLUtil.h"
|
||||
@@ -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,
|
||||
@@ -42,6 +44,7 @@ private:
|
||||
u32 dst_layer, u32 dst_level);
|
||||
|
||||
GLuint m_texId;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
class OGLStagingTexture final : public AbstractStagingTexture
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user