GPUDevice: Put debug messages/scopes behind conditions

And completely compile them out in Release builds.

Gets Devel close to Release in terms of performance.
This commit is contained in:
Stenzek 2024-12-01 23:01:33 +10:00
parent 0faa9cf650
commit 9df59713da
No known key found for this signature in database
35 changed files with 357 additions and 73 deletions

View File

@ -32,7 +32,7 @@ static constexpr GPUTexture::Format s_swap_chain_format = GPUTexture::Format::RG
void SetD3DDebugObjectName(ID3D11DeviceChild* obj, std::string_view name)
{
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
// WKPDID_D3DDebugObjectName
static constexpr GUID guid = {0x429b8c22, 0x9188, 0x4b0c, {0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00}};
@ -115,7 +115,7 @@ bool D3D11Device::CreateDeviceAndMainSwapChain(std::string_view adapter, Feature
}
}
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
if (m_debug_device)
m_context.As(&m_annotation);
#endif
@ -832,36 +832,34 @@ float D3D11Device::GetAndResetAccumulatedGPUTime()
return value;
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D11Device::PushDebugGroup(const char* name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!m_annotation)
return;
m_annotation->BeginEvent(StringUtil::UTF8StringToWideString(name).c_str());
#endif
}
void D3D11Device::PopDebugGroup()
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!m_annotation)
return;
m_annotation->EndEvent();
#endif
}
void D3D11Device::InsertDebugMessage(const char* msg)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!m_annotation)
return;
m_annotation->SetMarker(StringUtil::UTF8StringToWideString(msg).c_str());
#endif
}
#endif
void D3D11Device::MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space,
u32* map_base_vertex)
{

View File

@ -80,9 +80,11 @@ public:
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override;
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void PushDebugGroup(const char* name) override;
void PopDebugGroup() override;
void InsertDebugMessage(const char* msg) override;
#endif
void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space,
u32* map_base_vertex) override;

View File

@ -47,11 +47,15 @@ ID3D11ComputeShader* D3D11Shader::GetComputeShader() const
return static_cast<ID3D11ComputeShader*>(m_shader.Get());
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D11Shader::SetDebugName(std::string_view name)
{
SetD3DDebugObjectName(m_shader.Get(), name);
}
#endif
std::unique_ptr<GPUShader> D3D11Device::CreateShaderFromBinary(GPUShaderStage stage, std::span<const u8> data,
Error* error)
{
@ -135,11 +139,15 @@ D3D11Pipeline::~D3D11Pipeline()
D3D11Device::GetInstance().UnbindPipeline(this);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D11Pipeline::SetDebugName(std::string_view name)
{
// can't label this directly
}
#endif
D3D11Device::ComPtr<ID3D11RasterizerState> D3D11Device::GetRasterizationState(const GPUPipeline::RasterizationState& rs,
Error* error)
{

View File

@ -30,7 +30,9 @@ public:
ALWAYS_INLINE const std::vector<u8>& GetBytecode() const { return m_bytecode; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D11Shader(GPUShaderStage stage, Microsoft::WRL::ComPtr<ID3D11DeviceChild> shader, std::vector<u8> bytecode);
@ -49,7 +51,9 @@ class D3D11Pipeline final : public GPUPipeline
public:
~D3D11Pipeline() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
ALWAYS_INLINE bool IsComputePipeline() const { return !m_vs; }
ALWAYS_INLINE ID3D11RasterizerState* GetRasterizerState() const { return m_rs.Get(); }

View File

@ -42,11 +42,15 @@ D3D11Sampler::D3D11Sampler(ComPtr<ID3D11SamplerState> ss) : m_ss(std::move(ss))
D3D11Sampler::~D3D11Sampler() = default;
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D11Sampler::SetDebugName(std::string_view name)
{
SetD3DDebugObjectName(m_ss.Get(), name);
}
#endif
std::unique_ptr<GPUSampler> D3D11Device::CreateSampler(const GPUSampler::Config& config, Error* error)
{
static constexpr std::array<D3D11_TEXTURE_ADDRESS_MODE, static_cast<u8>(GPUSampler::AddressMode::MaxCount)> ta = {{
@ -200,8 +204,7 @@ bool D3D11Texture::Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32
if (IsCompressedFormat(m_format))
{
*map = static_cast<u8*>(sr.pData) + ((y / GetBlockSize()) * sr.RowPitch) +
((x / GetBlockSize()) * GetPixelSize());
*map = static_cast<u8*>(sr.pData) + ((y / GetBlockSize()) * sr.RowPitch) + ((x / GetBlockSize()) * GetPixelSize());
}
else
{
@ -225,11 +228,15 @@ void D3D11Texture::GenerateMipmaps()
D3D11Device::GetD3DContext()->GenerateMips(m_srv.Get());
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D11Texture::SetDebugName(std::string_view name)
{
SetD3DDebugObjectName(m_texture.Get(), name);
}
#endif
DXGI_FORMAT D3D11Texture::GetDXGIFormat() const
{
return D3DCommon::GetFormatMapping(m_format).resource_format;
@ -419,11 +426,15 @@ void D3D11TextureBuffer::Unmap(u32 used_elements)
m_buffer.Unmap(D3D11Device::GetD3DContext(), size);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D11TextureBuffer::SetDebugName(std::string_view name)
{
SetD3DDebugObjectName(m_buffer.GetD3DBuffer(), name);
}
#endif
std::unique_ptr<GPUTextureBuffer> D3D11Device::CreateTextureBuffer(GPUTextureBuffer::Format format,
u32 size_in_elements, Error* error /* = nullptr */)
{
@ -543,6 +554,8 @@ void D3D11DownloadTexture::Flush()
// Handled when mapped.
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D11DownloadTexture::SetDebugName(std::string_view name)
{
if (name.empty())
@ -551,6 +564,8 @@ void D3D11DownloadTexture::SetDebugName(std::string_view name)
SetD3DDebugObjectName(m_texture.Get(), name);
}
#endif
std::unique_ptr<GPUDownloadTexture> D3D11Device::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format,
Error* error /* = nullptr */)
{

View File

@ -26,7 +26,9 @@ public:
ALWAYS_INLINE ID3D11SamplerState* GetSamplerState() const { return m_ss.Get(); }
ALWAYS_INLINE ID3D11SamplerState* const* GetSamplerStateArray() const { return m_ss.GetAddressOf(); }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D11Sampler(ComPtr<ID3D11SamplerState> ss);
@ -88,7 +90,9 @@ public:
void Unmap() override;
void GenerateMipmaps() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D11Texture(u32 width, u32 height, u32 layers, u32 levels, u32 samples, Type type, Format format, Flags flags,
@ -118,7 +122,9 @@ public:
void* Map(u32 required_elements) override;
void Unmap(u32 used_elements) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D11StreamBuffer m_buffer;
@ -140,7 +146,9 @@ public:
void Flush() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D11DownloadTexture(Microsoft::WRL::ComPtr<ID3D11Texture2D> tex, u32 width, u32 height, GPUTexture::Format format);

View File

@ -310,7 +310,7 @@ u32 D3D12::RootSignatureBuilder::AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE
return index;
}
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D12::SetObjectName(ID3D12Object* object, std::string_view name)
{

View File

@ -6,6 +6,8 @@
#include "common/types.h"
#include "common/windows_headers.h"
#include "gpu_device.h"
#include <array>
#include <d3d12.h>
#include <string_view>
@ -122,7 +124,7 @@ private:
D3D12_COMPUTE_PIPELINE_STATE_DESC m_desc;
};
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetObjectName(ID3D12Object* object, std::string_view name);
#else
static inline void SetObjectName(ID3D12Object* object, std::string_view name)

View File

@ -59,7 +59,7 @@ static constexpr GPUTexture::Format s_swap_chain_format = GPUTexture::Format::RG
// We just need to keep this alive, never reference it.
static DynamicHeapArray<u8> s_pipeline_cache_data;
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
#include "WinPixEventRuntime/pix3.h"
static u32 s_debug_scope_depth = 0;
#endif
@ -117,7 +117,7 @@ D3D12Device::D3D12Device()
{
m_render_api = RenderAPI::D3D12;
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
s_debug_scope_depth = 0;
#endif
}
@ -1273,7 +1273,8 @@ void D3D12Device::SubmitPresent(GPUSwapChain* swap_chain)
SC->GetSwapChain()->Present(sync_interval, flags);
}
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
static UINT64 Palette(float phase, const std::array<float, 3>& a, const std::array<float, 3>& b,
const std::array<float, 3>& c, const std::array<float, 3>& d)
{
@ -1286,41 +1287,36 @@ static UINT64 Palette(float phase, const std::array<float, 3>& a, const std::arr
static_cast<BYTE>(std::clamp(result[1] * 255.0f, 0.0f, 255.0f)),
static_cast<BYTE>(std::clamp(result[2] * 255.0f, 0.0f, 255.0f)));
}
#endif
void D3D12Device::PushDebugGroup(const char* name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!m_debug_device)
return;
const UINT64 color = Palette(static_cast<float>(++s_debug_scope_depth), {0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, 0.5f},
{1.0f, 1.0f, 0.5f}, {0.8f, 0.90f, 0.30f});
PIXBeginEvent(GetCommandList(), color, "%s", name);
#endif
}
void D3D12Device::PopDebugGroup()
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!m_debug_device)
return;
s_debug_scope_depth = (s_debug_scope_depth == 0) ? 0 : (s_debug_scope_depth - 1u);
PIXEndEvent(GetCommandList());
#endif
}
void D3D12Device::InsertDebugMessage(const char* msg)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!m_debug_device)
return;
PIXSetMarker(GetCommandList(), PIX_COLOR(0, 0, 0), "%s", msg);
#endif
}
#endif
void D3D12Device::SetFeatures(D3D_FEATURE_LEVEL feature_level, FeatureMask disabled_features)
{
m_render_api_version = D3DCommon::GetRenderAPIVersionForFeatureLevel(feature_level);

View File

@ -101,9 +101,11 @@ public:
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override;
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void PushDebugGroup(const char* name) override;
void PopDebugGroup() override;
void InsertDebugMessage(const char* msg) override;
#endif
void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space,
u32* map_base_vertex) override;

View File

@ -22,10 +22,14 @@ D3D12Shader::D3D12Shader(GPUShaderStage stage, Bytecode bytecode) : GPUShader(st
D3D12Shader::~D3D12Shader() = default;
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D12Shader::SetDebugName(std::string_view name)
{
}
#endif
std::unique_ptr<GPUShader> D3D12Device::CreateShaderFromBinary(GPUShaderStage stage, std::span<const u8> data,
Error* error)
{
@ -72,11 +76,15 @@ D3D12Pipeline::~D3D12Pipeline()
D3D12Device::GetInstance().DeferObjectDestruction(std::move(m_pipeline));
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D12Pipeline::SetDebugName(std::string_view name)
{
D3D12::SetObjectName(m_pipeline.Get(), name);
}
#endif
std::string D3D12Pipeline::GetPipelineName(const GraphicsConfig& config)
{
SHA1Digest hash;

View File

@ -25,7 +25,9 @@ public:
ALWAYS_INLINE const u8* GetBytecodeData() const { return m_bytecode.data(); }
ALWAYS_INLINE u32 GetBytecodeSize() const { return static_cast<u32>(m_bytecode.size()); }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D12Shader(GPUShaderStage stage, Bytecode bytecode);
@ -48,7 +50,9 @@ public:
ALWAYS_INLINE const std::array<float, 4>& GetBlendConstantsF() const { return m_blend_constants_f; }
ALWAYS_INLINE bool HasVertexStride() const { return (m_vertex_stride > 0); }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
static std::string GetPipelineName(const GraphicsConfig& config);
static std::string GetPipelineName(const ComputeConfig& config);

View File

@ -616,11 +616,15 @@ void D3D12Texture::ActuallyCommitClear(ID3D12GraphicsCommandList* cmdlist)
SetState(State::Dirty);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D12Texture::SetDebugName(std::string_view name)
{
D3D12::SetObjectName(m_resource.Get(), name);
}
#endif
u32 D3D12Texture::CalculateSubresource(u32 layer, u32 level, u32 num_levels)
{
// D3D11CalcSubresource
@ -698,10 +702,14 @@ D3D12Sampler::~D3D12Sampler()
// Cleaned up by main class.
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D12Sampler::SetDebugName(std::string_view name)
{
}
#endif
D3D12DescriptorHandle D3D12Device::GetSampler(const GPUSampler::Config& config, Error* error)
{
const auto it = m_sampler_map.find(config.key);
@ -843,11 +851,15 @@ void D3D12TextureBuffer::Unmap(u32 used_elements)
m_buffer.CommitMemory(size);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D12TextureBuffer::SetDebugName(std::string_view name)
{
D3D12::SetObjectName(m_buffer.GetBuffer(), name);
}
#endif
std::unique_ptr<GPUTextureBuffer> D3D12Device::CreateTextureBuffer(GPUTextureBuffer::Format format,
u32 size_in_elements, Error* error /* = nullptr */)
{
@ -1026,6 +1038,8 @@ void D3D12DownloadTexture::Flush()
}
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void D3D12DownloadTexture::SetDebugName(std::string_view name)
{
if (name.empty())
@ -1034,6 +1048,8 @@ void D3D12DownloadTexture::SetDebugName(std::string_view name)
D3D12::SetObjectName(m_buffer.Get(), name);
}
#endif
std::unique_ptr<GPUDownloadTexture> D3D12Device::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format,
Error* error /* = nullptr */)
{

View File

@ -43,7 +43,9 @@ public:
void GenerateMipmaps() override;
void MakeReadyForSampling() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
void TransitionToState(D3D12_RESOURCE_STATES state);
void CommitClear();
@ -115,7 +117,9 @@ public:
ALWAYS_INLINE const D3D12DescriptorHandle& GetDescriptor() const { return m_descriptor; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D12Sampler(D3D12DescriptorHandle descriptor);
@ -140,7 +144,9 @@ public:
void* Map(u32 required_elements) override;
void Unmap(u32 used_elements) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D12StreamBuffer m_buffer;
@ -165,7 +171,9 @@ public:
void Flush() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
D3D12DownloadTexture(u32 width, u32 height, GPUTexture::Format format, ComPtr<D3D12MA::Allocation> allocation,

View File

@ -13,6 +13,8 @@
#include "common/small_string.h"
#include "common/types.h"
#include "fmt/base.h"
#include <cstring>
#include <deque>
#include <memory>
@ -26,6 +28,11 @@
class Error;
class Image;
// Enables debug event generation and object names for graphics debuggers.
#if defined(_DEBUG) || defined(_DEVEL)
#define ENABLE_GPU_OBJECT_NAMES
#endif
enum class RenderAPI : u8
{
None,
@ -97,7 +104,14 @@ public:
GPUSampler();
virtual ~GPUSampler();
#ifdef ENABLE_GPU_OBJECT_NAMES
virtual void SetDebugName(std::string_view name) = 0;
template<typename... T>
void SetDebugName(fmt::format_string<T...> fmt, T&&... args)
{
SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...)));
}
#endif
static Config GetNearestConfig();
static Config GetLinearConfig();
@ -135,7 +149,14 @@ public:
ALWAYS_INLINE GPUShaderStage GetStage() const { return m_stage; }
#ifdef ENABLE_GPU_OBJECT_NAMES
virtual void SetDebugName(std::string_view name) = 0;
template<typename... T>
void SetDebugName(fmt::format_string<T...> fmt, T&&... args)
{
SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...)));
}
#endif
protected:
GPUShaderStage m_stage;
@ -429,7 +450,14 @@ public:
GPUPipeline();
virtual ~GPUPipeline();
#ifdef ENABLE_GPU_OBJECT_NAMES
virtual void SetDebugName(std::string_view name) = 0;
template<typename... T>
void SetDebugName(fmt::format_string<T...> fmt, T&&... args)
{
SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...)));
}
#endif
};
class GPUTextureBuffer
@ -455,7 +483,14 @@ public:
virtual void* Map(u32 required_elements) = 0;
virtual void Unmap(u32 used_elements) = 0;
#ifdef ENABLE_GPU_OBJECT_NAMES
virtual void SetDebugName(std::string_view name) = 0;
template<typename... T>
void SetDebugName(fmt::format_string<T...> fmt, T&&... args)
{
SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...)));
}
#endif
protected:
Format m_format;
@ -739,11 +774,25 @@ public:
virtual std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::ComputeConfig& config,
Error* error = nullptr) = 0;
#ifdef ENABLE_GPU_OBJECT_NAMES
/// Debug messaging.
virtual void PushDebugGroup(const char* name) = 0;
virtual void PopDebugGroup() = 0;
virtual void InsertDebugMessage(const char* msg) = 0;
/// Formatted debug variants.
template<typename... T>
void PushDebugGroup(fmt::format_string<T...> fmt, T&&... args)
{
PushDebugGroup(TinyString::from_vformat(fmt, fmt::make_format_args(args...)));
}
template<typename... T>
void InsertDebugMessage(fmt::format_string<T...> fmt, T&&... args)
{
InsertDebugMessage(TinyString::from_vformat(fmt, fmt::make_format_args(args...)));
}
#endif
/// Vertex/index buffer abstraction.
virtual void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space,
u32* map_base_vertex) = 0;
@ -929,24 +978,74 @@ ALWAYS_INLINE void GPUDevice::PooledTextureDeleter::operator()(GPUTexture* const
}
// Macros for debug messages.
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
struct GLAutoPop
{
GLAutoPop(int dummy) {}
~GLAutoPop() { g_gpu_device->PopDebugGroup(); }
GLAutoPop(const char* name)
{
if (g_gpu_device->IsDebugDevice()) [[unlikely]]
g_gpu_device->PushDebugGroup(name);
}
template<typename... T>
GLAutoPop(fmt::format_string<T...> fmt, T&&... args)
{
if (g_gpu_device->IsDebugDevice()) [[unlikely]]
g_gpu_device->PushDebugGroup(SmallString::from_vformat(fmt, fmt::make_format_args(args...)));
}
~GLAutoPop()
{
if (g_gpu_device->IsDebugDevice()) [[unlikely]]
g_gpu_device->PopDebugGroup();
}
};
#define GL_SCOPE(name) GLAutoPop gl_auto_pop((g_gpu_device->PushDebugGroup(name), 0))
#define GL_PUSH(name) g_gpu_device->PushDebugGroup(name)
#define GL_POP() g_gpu_device->PopDebugGroup()
#define GL_INS(msg) g_gpu_device->InsertDebugMessage(msg)
#define GL_OBJECT_NAME(obj, name) (obj)->SetDebugName(name)
#define GL_SCOPE(name) GLAutoPop gl_auto_pop(name)
#define GL_PUSH(name) \
do \
{ \
if (g_gpu_device->IsDebugDevice()) [[unlikely]] \
g_gpu_device->PushDebugGroup(name); \
} while (0)
#define GL_POP() \
do \
{ \
if (g_gpu_device->IsDebugDevice()) [[unlikely]] \
g_gpu_device->PopDebugGroup(); \
} while (0)
#define GL_INS(msg) \
do \
{ \
if (g_gpu_device->IsDebugDevice()) [[unlikely]] \
g_gpu_device->InsertDebugMessage(msg); \
} while (0)
#define GL_OBJECT_NAME(obj, name) \
do \
{ \
if (g_gpu_device->IsDebugDevice()) [[unlikely]] \
(obj)->SetDebugName(name); \
} while (0)
#define GL_SCOPE_FMT(...) \
GLAutoPop gl_auto_pop((g_gpu_device->PushDebugGroup(SmallString::from_format(__VA_ARGS__)), 0))
#define GL_PUSH_FMT(...) g_gpu_device->PushDebugGroup(SmallString::from_format(__VA_ARGS__))
#define GL_INS_FMT(...) g_gpu_device->InsertDebugMessage(SmallString::from_format(__VA_ARGS__))
#define GL_OBJECT_NAME_FMT(obj, ...) (obj)->SetDebugName(SmallString::from_format(__VA_ARGS__))
#define GL_SCOPE_FMT(...) GLAutoPop gl_auto_pop(__VA_ARGS__)
#define GL_PUSH_FMT(...) \
do \
{ \
if (g_gpu_device->IsDebugDevice()) [[unlikely]] \
g_gpu_device->PushDebugGroup(__VA_ARGS__); \
} while (0)
#define GL_INS_FMT(...) \
do \
{ \
if (g_gpu_device->IsDebugDevice()) [[unlikely]] \
g_gpu_device->InsertDebugMessage(__VA_ARGS__); \
} while (0)
#define GL_OBJECT_NAME_FMT(obj, ...) \
do \
{ \
if (g_gpu_device->IsDebugDevice()) [[unlikely]] \
(obj)->SetDebugName(__VA_ARGS__); \
} while (0)
#else
#define GL_SCOPE(name) (void)0
#define GL_PUSH(name) (void)0

View File

@ -4,8 +4,11 @@
#pragma once
#include "common/gsvector.h"
#include "common/small_string.h"
#include "common/types.h"
#include "fmt/format.h"
#include <algorithm>
#include <array>
#include <string_view>
@ -184,7 +187,14 @@ public:
// Instructs the backend that we're finished rendering to this texture. It may transition it to a new layout.
virtual void MakeReadyForSampling();
#if defined(_DEBUG) || defined(_DEVEL)
virtual void SetDebugName(std::string_view name) = 0;
template<typename... T>
void SetDebugName(fmt::format_string<T...> fmt, T&&... args)
{
SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...)));
}
#endif
protected:
GPUTexture(u16 width, u16 height, u8 layers, u8 levels, u8 samples, Type type, Format format, Flags flags);
@ -252,8 +262,15 @@ public:
/// call to CopyFromTexture() and the Flush() call.
virtual void Flush() = 0;
#if defined(_DEBUG) || defined(_DEVEL)
/// Sets object name that will be displayed in graphics debuggers.
virtual void SetDebugName(std::string_view name) = 0;
template<typename... T>
void SetDebugName(fmt::format_string<T...> fmt, T&&... args)
{
SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...)));
}
#endif
/// Reads the specified rectangle from the staging texture to out_ptr, with the specified stride
/// (length in bytes of each row). CopyFromTexture() must be called first. The contents of any

View File

@ -285,9 +285,7 @@ bool MediaCaptureBase::DeliverVideoFrame(GPUTexture* stex)
return false;
}
#if defined(_DEBUG) || defined(_DEVEL)
GL_OBJECT_NAME_FMT(pf.tex, "MediaCapture {}x{} Download Texture", stex->GetWidth(), stex->GetHeight());
#endif
}
pf.tex->CopyFromTexture(0, 0, stex, 0, 0, m_video_width, m_video_height, 0, 0);

View File

@ -44,7 +44,9 @@ public:
ALWAYS_INLINE id<MTLSamplerState> GetSamplerState() const { return m_ss; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
MetalSampler(id<MTLSamplerState> ss);
@ -62,7 +64,9 @@ public:
ALWAYS_INLINE id<MTLLibrary> GetLibrary() const { return m_library; }
ALWAYS_INLINE id<MTLFunction> GetFunction() const { return m_function; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
MetalShader(GPUShaderStage stage, id<MTLLibrary> library, id<MTLFunction> function);
@ -92,7 +96,9 @@ public:
ALWAYS_INLINE MTLCullMode GetCullMode() const { return m_cull_mode; }
ALWAYS_INLINE MTLPrimitiveType GetPrimitive() const { return m_primitive; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
MetalPipeline(id pipeline, id<MTLDepthStencilState> depth, MTLCullMode cull_mode, MTLPrimitiveType primitive);
@ -122,7 +128,9 @@ public:
void MakeReadyForSampling() override;
void GenerateMipmaps() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
// Call when the texture is bound to the pipeline, or read from in a copy.
ALWAYS_INLINE void SetUseFenceCounter(u64 counter) { m_use_fence_counter = counter; }
@ -161,7 +169,9 @@ public:
void Flush() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
MetalDownloadTexture(u32 width, u32 height, GPUTexture::Format format, u8* import_buffer, size_t buffer_offset,
@ -187,7 +197,9 @@ public:
void* Map(u32 required_elements) override;
void Unmap(u32 used_elements) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
MetalStreamBuffer m_buffer;
@ -265,9 +277,11 @@ public:
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override;
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void PushDebugGroup(const char* name) override;
void PopDebugGroup() override;
void InsertDebugMessage(const char* msg) override;
#endif
void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space,
u32* map_base_vertex) override;

View File

@ -643,6 +643,8 @@ MetalShader::~MetalShader()
MetalDevice::DeferRelease(m_library);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void MetalShader::SetDebugName(std::string_view name)
{
@autoreleasepool
@ -651,6 +653,8 @@ void MetalShader::SetDebugName(std::string_view name)
}
}
#endif
std::unique_ptr<GPUShader> MetalDevice::CreateShaderFromMSL(GPUShaderStage stage, std::string_view source,
std::string_view entry_point, Error* error)
{
@ -747,11 +751,15 @@ MetalPipeline::~MetalPipeline()
MetalDevice::DeferRelease(m_pipeline);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void MetalPipeline::SetDebugName(std::string_view name)
{
// readonly property :/
}
#endif
id<MTLDepthStencilState> MetalDevice::GetDepthState(const GPUPipeline::DepthState& ds)
{
const auto it = m_depth_states.find(ds.key);
@ -1157,6 +1165,8 @@ void MetalTexture::GenerateMipmaps()
[encoder generateMipmapsForTexture:m_texture];
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void MetalTexture::SetDebugName(std::string_view name)
{
@autoreleasepool
@ -1165,6 +1175,8 @@ void MetalTexture::SetDebugName(std::string_view name)
}
}
#endif
std::unique_ptr<GPUTexture> MetalDevice::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Type type, GPUTexture::Format format,
GPUTexture::Flags flags, const void* data, u32 data_stride,
@ -1381,6 +1393,8 @@ void MetalDownloadTexture::Flush()
dev.WaitForFenceCounter(m_copy_fence_counter);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void MetalDownloadTexture::SetDebugName(std::string_view name)
{
@autoreleasepool
@ -1389,6 +1403,8 @@ void MetalDownloadTexture::SetDebugName(std::string_view name)
}
}
#endif
std::unique_ptr<GPUDownloadTexture> MetalDevice::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format,
Error* error)
{
@ -1408,11 +1424,15 @@ MetalSampler::MetalSampler(id<MTLSamplerState> ss) : m_ss(ss)
MetalSampler::~MetalSampler() = default;
#ifdef ENABLE_GPU_OBJECT_NAMES
void MetalSampler::SetDebugName(std::string_view name)
{
// lame.. have to put it on the descriptor :/
}
#endif
std::unique_ptr<GPUSampler> MetalDevice::CreateSampler(const GPUSampler::Config& config, Error* error)
{
@autoreleasepool
@ -1822,6 +1842,8 @@ void MetalTextureBuffer::Unmap(u32 used_elements)
m_buffer.CommitMemory(size);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void MetalTextureBuffer::SetDebugName(std::string_view name)
{
@autoreleasepool
@ -1830,6 +1852,8 @@ void MetalTextureBuffer::SetDebugName(std::string_view name)
}
}
#endif
std::unique_ptr<GPUTextureBuffer> MetalDevice::CreateTextureBuffer(GPUTextureBuffer::Format format,
u32 size_in_elements, Error* error)
{
@ -1840,6 +1864,8 @@ std::unique_ptr<GPUTextureBuffer> MetalDevice::CreateTextureBuffer(GPUTextureBuf
return tb;
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void MetalDevice::PushDebugGroup(const char* name)
{
}
@ -1852,6 +1878,8 @@ void MetalDevice::InsertDebugMessage(const char* msg)
{
}
#endif
void MetalDevice::MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space,
u32* map_base_vertex)
{

View File

@ -214,29 +214,26 @@ std::unique_ptr<GPUPipeline> OpenGLDevice::CreatePipeline(const GPUPipeline::Com
return {};
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void OpenGLDevice::PushDebugGroup(const char* name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!glPushDebugGroup)
return;
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, static_cast<GLsizei>(std::strlen(name)), name);
#endif
}
void OpenGLDevice::PopDebugGroup()
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!glPopDebugGroup)
return;
glPopDebugGroup();
#endif
}
void OpenGLDevice::InsertDebugMessage(const char* msg)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!glDebugMessageInsert)
return;
@ -245,9 +242,10 @@ void OpenGLDevice::InsertDebugMessage(const char* msg)
glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION,
static_cast<GLsizei>(std::strlen(msg)), msg);
}
#endif
}
#endif
static void GLAD_API_PTR GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
const GLchar* message, const void* userParam)
{

View File

@ -82,9 +82,11 @@ public:
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override;
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void PushDebugGroup(const char* name) override;
void PopDebugGroup() override;
void InsertDebugMessage(const char* msg) override;
#endif
void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space,
u32* map_base_vertex) override;

View File

@ -78,9 +78,10 @@ OpenGLShader::~OpenGLShader()
glDeleteShader(m_id.value());
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void OpenGLShader::SetDebugName(std::string_view name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (glObjectLabel)
{
if (m_id.has_value())
@ -94,9 +95,10 @@ void OpenGLShader::SetDebugName(std::string_view name)
m_debug_name = name;
}
}
#endif
}
#endif
bool OpenGLShader::Compile(Error* error)
{
if (m_compile_tried)
@ -155,7 +157,7 @@ bool OpenGLShader::Compile(Error* error)
m_id = shader;
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
if (glObjectLabel && !m_debug_name.empty())
{
glObjectLabel(GL_SHADER, shader, static_cast<GLsizei>(m_debug_name.length()),
@ -584,14 +586,16 @@ OpenGLPipeline::~OpenGLPipeline()
dev.UnrefVAO(m_key.va_key);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void OpenGLPipeline::SetDebugName(std::string_view name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (glObjectLabel)
glObjectLabel(GL_PROGRAM, m_program, static_cast<u32>(name.length()), name.data());
#endif
}
#endif
std::unique_ptr<GPUPipeline> OpenGLDevice::CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error)
{
const OpenGLPipeline::ProgramCacheKey pkey = OpenGLPipeline::GetProgramCacheKey(config);

View File

@ -16,7 +16,9 @@ class OpenGLShader final : public GPUShader
public:
~OpenGLShader() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
bool Compile(Error* error);
@ -32,7 +34,7 @@ private:
std::optional<GLuint> m_id;
bool m_compile_tried = false;
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
std::string m_debug_name;
#endif
};
@ -104,7 +106,9 @@ public:
ALWAYS_INLINE const BlendState& GetBlendState() const { return m_blend_state; }
ALWAYS_INLINE GLenum GetTopology() const { return m_topology; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
OpenGLPipeline(const ProgramCacheKey& key, GLuint program, VertexArrayCache::const_iterator vao,

View File

@ -29,17 +29,19 @@ void OpenGLStreamBuffer::Unbind()
glBindBuffer(m_target, 0);
}
#if defined(_DEBUG) || defined(_DEVEL)
void OpenGLStreamBuffer::SetDebugName(std::string_view name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (glObjectLabel)
{
glObjectLabel(GL_BUFFER, GetGLBufferId(), static_cast<GLsizei>(name.length()),
static_cast<const GLchar*>(name.data()));
}
#endif
}
#endif
namespace {
// Uses glBufferSubData() to update. Preferred for drivers which don't support {ARB,EXT}_buffer_storage.

View File

@ -26,7 +26,9 @@ public:
void Bind();
void Unbind();
#if defined(_DEBUG) || defined(_DEVEL)
void SetDebugName(std::string_view name);
#endif
struct MappingResult
{

View File

@ -485,18 +485,14 @@ void OpenGLTexture::GenerateMipmaps()
glBindTexture(target, 0);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void OpenGLTexture::SetDebugName(std::string_view name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (glObjectLabel)
glObjectLabel(GL_TEXTURE, m_id, static_cast<GLsizei>(name.length()), static_cast<const GLchar*>(name.data()));
#endif
}
#if 0
// If we don't have border clamp.. too bad, just hope for the best.
if (!m_gl_context->IsGLES() || GLAD_GL_ES_VERSION_3_2 || GLAD_GL_NV_texture_border_clamp ||
GLAD_GL_EXT_texture_border_clamp || GLAD_GL_OES_texture_border_clamp)
#endif
//////////////////////////////////////////////////////////////////////////
@ -510,14 +506,16 @@ OpenGLSampler::~OpenGLSampler()
OpenGLDevice::GetInstance().UnbindSampler(m_id);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void OpenGLSampler::SetDebugName(std::string_view name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (glObjectLabel)
glObjectLabel(GL_SAMPLER, m_id, static_cast<GLsizei>(name.length()), static_cast<const GLchar*>(name.data()));
#endif
}
#endif
std::unique_ptr<GPUSampler> OpenGLDevice::CreateSampler(const GPUSampler::Config& config, Error* error /* = nullptr */)
{
static constexpr std::array<GLenum, static_cast<u8>(GPUSampler::AddressMode::MaxCount)> ta = {{
@ -798,17 +796,19 @@ void OpenGLTextureBuffer::Unmap(u32 used_elements)
m_buffer->Unmap(size);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void OpenGLTextureBuffer::SetDebugName(std::string_view name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (glObjectLabel)
{
glObjectLabel(GL_TEXTURE, m_buffer->GetGLBufferId(), static_cast<GLsizei>(name.length()),
static_cast<const GLchar*>(name.data()));
}
#endif
}
#endif
std::unique_ptr<GPUTextureBuffer> OpenGLDevice::CreateTextureBuffer(GPUTextureBuffer::Format format,
u32 size_in_elements, Error* error)
{
@ -1037,6 +1037,8 @@ void OpenGLDownloadTexture::Flush()
m_sync = {};
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void OpenGLDownloadTexture::SetDebugName(std::string_view name)
{
if (name.empty())
@ -1046,6 +1048,8 @@ void OpenGLDownloadTexture::SetDebugName(std::string_view name)
glObjectLabel(GL_BUFFER, m_buffer_id, static_cast<GLsizei>(name.length()), name.data());
}
#endif
std::unique_ptr<GPUDownloadTexture>
OpenGLDevice::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format, Error* error /* = nullptr */)
{

View File

@ -30,7 +30,9 @@ public:
void Unmap() override;
void GenerateMipmaps() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
static std::unique_ptr<OpenGLTexture> Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, Type type,
Format format, Flags flags, const void* data, u32 data_pitch,
@ -78,7 +80,9 @@ public:
void* Map(u32 required_elements) override;
void Unmap(u32 used_elements) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
OpenGLTextureBuffer(Format format, u32 size_in_elements, std::unique_ptr<OpenGLStreamBuffer> buffer,
@ -97,7 +101,9 @@ public:
ALWAYS_INLINE GLuint GetID() const { return m_id; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
OpenGLSampler(GLuint id);
@ -121,7 +127,9 @@ public:
void Flush() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
OpenGLDownloadTexture(u32 width, u32 height, GPUTexture::Format format, bool imported, GLuint buffer_id,

View File

@ -1265,7 +1265,7 @@ bool PostProcessing::ReShadeFXShader::CreatePasses(GPUTexture::Format backbuffer
pass.samplers.push_back(std::move(sampler));
}
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
pass.name = std::move(pi.name);
#endif
m_passes.push_back(std::move(pass));

View File

@ -132,7 +132,7 @@ private:
llvm::SmallVector<Sampler, GPUDevice::MAX_TEXTURE_SAMPLERS> samplers;
u32 num_vertices;
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
std::string name;
#endif
};

View File

@ -105,7 +105,7 @@ const std::array<VkFormat, static_cast<u32>(GPUTexture::Format::MaxCount)> Vulka
// Handles are always 64-bit, even on 32-bit platforms.
static const VkRenderPass DYNAMIC_RENDERING_RENDER_PASS = ((VkRenderPass) static_cast<s64>(-1LL));
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
static u32 s_debug_scope_depth = 0;
#endif
@ -116,7 +116,7 @@ VulkanDevice::VulkanDevice()
{
m_render_api = RenderAPI::Vulkan;
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
s_debug_scope_depth = 0;
#endif
}
@ -2327,7 +2327,7 @@ void VulkanDevice::SubmitPresent(GPUSwapChain* swap_chain)
QueuePresent(static_cast<VulkanSwapChain*>(swap_chain));
}
#if defined(_DEBUG) || defined(_DEVEL)
#ifdef ENABLE_GPU_OBJECT_NAMES
static std::array<float, 3> Palette(float phase, const std::array<float, 3>& a, const std::array<float, 3>& b,
const std::array<float, 3>& c, const std::array<float, 3>& d)
{
@ -2337,11 +2337,9 @@ static std::array<float, 3> Palette(float phase, const std::array<float, 3>& a,
result[2] = a[2] + b[2] * std::cos(6.28318f * (c[2] * phase + d[2]));
return result;
}
#endif
void VulkanDevice::PushDebugGroup(const char* name)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!vkCmdBeginDebugUtilsLabelEXT || !m_debug_device)
return;
@ -2355,32 +2353,29 @@ void VulkanDevice::PushDebugGroup(const char* name)
{color[0], color[1], color[2], 1.0f},
};
vkCmdBeginDebugUtilsLabelEXT(GetCurrentCommandBuffer(), &label);
#endif
}
void VulkanDevice::PopDebugGroup()
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!vkCmdEndDebugUtilsLabelEXT || !m_debug_device)
return;
s_debug_scope_depth = (s_debug_scope_depth == 0) ? 0 : (s_debug_scope_depth - 1u);
vkCmdEndDebugUtilsLabelEXT(GetCurrentCommandBuffer());
#endif
}
void VulkanDevice::InsertDebugMessage(const char* msg)
{
#if defined(_DEBUG) || defined(_DEVEL)
if (!vkCmdInsertDebugUtilsLabelEXT || !m_debug_device)
return;
const VkDebugUtilsLabelEXT label = {VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, nullptr, msg, {0.0f, 0.0f, 0.0f, 1.0f}};
vkCmdInsertDebugUtilsLabelEXT(GetCurrentCommandBuffer(), &label);
#endif
}
#endif
u32 VulkanDevice::GetMaxMultisamples(VkPhysicalDevice physical_device, const VkPhysicalDeviceProperties& properties)
{
VkImageFormatProperties color_properties = {};

View File

@ -118,9 +118,11 @@ public:
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override;
std::unique_ptr<GPUPipeline> CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void PushDebugGroup(const char* name) override;
void PopDebugGroup() override;
void InsertDebugMessage(const char* msg) override;
#endif
void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space,
u32* map_base_vertex) override;

View File

@ -22,11 +22,15 @@ VulkanShader::~VulkanShader()
vkDestroyShaderModule(VulkanDevice::GetInstance().GetVulkanDevice(), m_module, nullptr);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void VulkanShader::SetDebugName(std::string_view name)
{
Vulkan::SetObjectName(VulkanDevice::GetInstance().GetVulkanDevice(), m_module, name);
}
#endif
std::unique_ptr<GPUShader> VulkanDevice::CreateShaderFromBinary(GPUShaderStage stage, std::span<const u8> data,
Error* error)
{
@ -107,11 +111,15 @@ VulkanPipeline::~VulkanPipeline()
VulkanDevice::GetInstance().DeferPipelineDestruction(m_pipeline);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void VulkanPipeline::SetDebugName(std::string_view name)
{
Vulkan::SetObjectName(VulkanDevice::GetInstance().GetVulkanDevice(), m_pipeline, name);
}
#endif
std::unique_ptr<GPUPipeline> VulkanDevice::CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error)
{
static constexpr std::array<std::pair<VkPrimitiveTopology, u32>, static_cast<u32>(GPUPipeline::Primitive::MaxCount)>

View File

@ -15,7 +15,9 @@ public:
ALWAYS_INLINE VkShaderModule GetModule() const { return m_module; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
VulkanShader(GPUShaderStage stage, VkShaderModule mod);
@ -34,7 +36,9 @@ public:
ALWAYS_INLINE Layout GetLayout() const { return m_layout; }
ALWAYS_INLINE u8 GetVerticesPerPrimitive() const { return m_vertices_per_primitive; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
VulkanPipeline(VkPipeline pipeline, Layout layout, u8 vertices_per_primitive, RenderPassFlag render_pass_flags);

View File

@ -459,6 +459,8 @@ void VulkanTexture::OverrideImageLayout(Layout new_layout)
m_layout = new_layout;
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void VulkanTexture::SetDebugName(std::string_view name)
{
VulkanDevice& dev = VulkanDevice::GetInstance();
@ -466,6 +468,8 @@ void VulkanTexture::SetDebugName(std::string_view name)
Vulkan::SetObjectName(dev.GetVulkanDevice(), m_view, name);
}
#endif
void VulkanTexture::TransitionToLayout(Layout layout)
{
TransitionToLayout(VulkanDevice::GetInstance().GetCurrentCommandBuffer(), layout);
@ -775,11 +779,15 @@ VulkanSampler::~VulkanSampler()
// Cleaned up by main class.
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void VulkanSampler::SetDebugName(std::string_view name)
{
Vulkan::SetObjectName(VulkanDevice::GetInstance().GetVulkanDevice(), m_sampler, name);
}
#endif
VkSampler VulkanDevice::GetSampler(const GPUSampler::Config& config, Error* error)
{
const auto it = m_sampler_map.find(config.key);
@ -942,6 +950,8 @@ void VulkanTextureBuffer::Unmap(u32 used_elements)
m_buffer.CommitMemory(size);
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void VulkanTextureBuffer::SetDebugName(std::string_view name)
{
VulkanDevice& dev = VulkanDevice::GetInstance();
@ -950,6 +960,8 @@ void VulkanTextureBuffer::SetDebugName(std::string_view name)
Vulkan::SetObjectName(dev.GetVulkanDevice(), m_buffer_view, name);
}
#endif
std::unique_ptr<GPUTextureBuffer> VulkanDevice::CreateTextureBuffer(GPUTextureBuffer::Format format,
u32 size_in_elements, Error* error)
{
@ -1195,6 +1207,8 @@ void VulkanDownloadTexture::Flush()
}
}
#ifdef ENABLE_GPU_OBJECT_NAMES
void VulkanDownloadTexture::SetDebugName(std::string_view name)
{
if (name.empty())
@ -1203,6 +1217,8 @@ void VulkanDownloadTexture::SetDebugName(std::string_view name)
Vulkan::SetObjectName(VulkanDevice::GetInstance().GetVulkanDevice(), m_buffer, name);
}
#endif
std::unique_ptr<GPUDownloadTexture>
VulkanDevice::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format, Error* error /* = nullptr */)
{

View File

@ -56,7 +56,9 @@ public:
void MakeReadyForSampling() override;
void GenerateMipmaps() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
void TransitionToLayout(Layout layout);
void CommitClear();
@ -120,7 +122,9 @@ public:
ALWAYS_INLINE VkSampler GetSampler() const { return m_sampler; }
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
VulkanSampler(VkSampler sampler);
@ -146,7 +150,9 @@ public:
void* Map(u32 required_elements) override;
void Unmap(u32 used_elements) override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
VulkanStreamBuffer m_buffer;
@ -170,7 +176,9 @@ public:
void Flush() override;
#ifdef ENABLE_GPU_OBJECT_NAMES
void SetDebugName(std::string_view name) override;
#endif
private:
VulkanDownloadTexture(u32 width, u32 height, GPUTexture::Format format, VmaAllocation allocation,