Add support for renaming GPU resources (development builds only)
This commit is contained in:
@@ -184,8 +184,9 @@ GPUResource::GPUResource(const SpawnParams& params)
|
|||||||
|
|
||||||
GPUResource::~GPUResource()
|
GPUResource::~GPUResource()
|
||||||
{
|
{
|
||||||
#if !BUILD_RELEASE
|
#if !BUILD_RELEASE && GPU_ENABLE_RESOURCE_NAMING
|
||||||
ASSERT(_memoryUsage == 0);
|
if (_memoryUsage != 0)
|
||||||
|
LOG(Error, "{0} '{1}' has not been disposed before destruction", ScriptingObject::ToString(), _name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +204,12 @@ uint64 GPUResource::GetMemoryUsage() const
|
|||||||
|
|
||||||
String GPUResource::GetName() const
|
String GPUResource::GetName() const
|
||||||
{
|
{
|
||||||
return String::Empty;
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUResource::SetName(const StringView& name)
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -231,10 +237,10 @@ void GPUResource::OnReleaseGPU()
|
|||||||
String GPUResource::ToString() const
|
String GPUResource::ToString() const
|
||||||
{
|
{
|
||||||
#if GPU_ENABLE_RESOURCE_NAMING
|
#if GPU_ENABLE_RESOURCE_NAMING
|
||||||
return GetName();
|
if (_name.HasChars())
|
||||||
#else
|
return _name;
|
||||||
return TEXT("GPU Resource");
|
|
||||||
#endif
|
#endif
|
||||||
|
return ScriptingObject::ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPUResource::OnDeleteObject()
|
void GPUResource::OnDeleteObject()
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint64 _memoryUsage = 0;
|
uint64 _memoryUsage = 0;
|
||||||
|
#if GPU_ENABLE_RESOURCE_NAMING
|
||||||
|
String _name;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NON_COPYABLE(GPUResource);
|
NON_COPYABLE(GPUResource);
|
||||||
@@ -77,12 +80,15 @@ public:
|
|||||||
API_PROPERTY() uint64 GetMemoryUsage() const;
|
API_PROPERTY() uint64 GetMemoryUsage() const;
|
||||||
|
|
||||||
#if GPU_ENABLE_RESOURCE_NAMING
|
#if GPU_ENABLE_RESOURCE_NAMING
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the resource name.
|
/// Gets the resource name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual String GetName() const;
|
API_PROPERTY() String GetName() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the resource name.
|
||||||
|
/// </summary>
|
||||||
|
API_PROPERTY() void SetName(const StringView& name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -119,11 +125,6 @@ class GPUResourceBase : public BaseType
|
|||||||
protected:
|
protected:
|
||||||
DeviceType* _device;
|
DeviceType* _device;
|
||||||
|
|
||||||
private:
|
|
||||||
#if GPU_ENABLE_RESOURCE_NAMING
|
|
||||||
String _name;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="GPUResourceBase"/> class.
|
/// Initializes a new instance of the <see cref="GPUResourceBase"/> class.
|
||||||
@@ -132,10 +133,10 @@ public:
|
|||||||
/// <param name="name">The resource name.</param>
|
/// <param name="name">The resource name.</param>
|
||||||
GPUResourceBase(DeviceType* device, const StringView& name) noexcept
|
GPUResourceBase(DeviceType* device, const StringView& name) noexcept
|
||||||
: _device(device)
|
: _device(device)
|
||||||
#if GPU_ENABLE_RESOURCE_NAMING
|
|
||||||
, _name(name.Get(), name.Length())
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
|
#if GPU_ENABLE_RESOURCE_NAMING
|
||||||
|
GPUResource::_name = name;
|
||||||
|
#endif
|
||||||
device->Resources.Add(this);
|
device->Resources.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,12 +160,6 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// [GPUResource]
|
// [GPUResource]
|
||||||
#if GPU_ENABLE_RESOURCE_NAMING
|
|
||||||
String GetName() const override
|
|
||||||
{
|
|
||||||
return _name;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
void OnDeviceDispose() override
|
void OnDeviceDispose() override
|
||||||
{
|
{
|
||||||
GPUResource::OnDeviceDispose();
|
GPUResource::OnDeviceDispose();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Task* GPUSwapChain::DownloadDataAsync(TextureData& result)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto texture = GPUDevice::Instance->CreateTexture(String::Empty);
|
auto texture = GPUDevice::Instance->CreateTexture();
|
||||||
if (texture->Init(GPUTextureDescription::New2D(GetWidth(), GetHeight(), GetFormat(), GPUTextureFlags::None, 1).ToStagingReadback()))
|
if (texture->Init(GPUTextureDescription::New2D(GetWidth(), GetHeight(), GetFormat(), GPUTextureFlags::None, 1).ToStagingReadback()))
|
||||||
{
|
{
|
||||||
LOG(Warning, "Failed to create staging texture for the window swapchain backuffer download.");
|
LOG(Warning, "Failed to create staging texture for the window swapchain backuffer download.");
|
||||||
@@ -84,3 +84,17 @@ void GPUSwapChain::Present(bool vsync)
|
|||||||
// Count amount of present calls
|
// Count amount of present calls
|
||||||
_presentCount++;
|
_presentCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String GPUSwapChain::ToString() const
|
||||||
|
{
|
||||||
|
#if GPU_ENABLE_RESOURCE_NAMING
|
||||||
|
return String::Format(TEXT("SwapChain {0}x{1}, {2}"), GetWidth(), GetHeight(), GetName());
|
||||||
|
#else
|
||||||
|
return TEXT("SwapChain");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
GPUResource::ResourceType GPUSwapChain::GetResourceType() const
|
||||||
|
{
|
||||||
|
return ResourceType::Texture;
|
||||||
|
}
|
||||||
|
|||||||
@@ -159,14 +159,6 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// [GPUResource]
|
// [GPUResource]
|
||||||
ResourceType GetResourceType() const final override
|
String ToString() const override;
|
||||||
{
|
ResourceType GetResourceType() const final override;
|
||||||
return ResourceType::Texture;
|
|
||||||
}
|
|
||||||
#if GPU_ENABLE_RESOURCE_NAMING
|
|
||||||
String GetName() const override
|
|
||||||
{
|
|
||||||
return String::Format(TEXT("RenderOutput {0}x{1}"), GetWidth(), GetHeight());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -211,12 +211,12 @@ uint32 GetHash(const GPUTextureDescription& key)
|
|||||||
|
|
||||||
GPUTexture* GPUTexture::Spawn(const SpawnParams& params)
|
GPUTexture* GPUTexture::Spawn(const SpawnParams& params)
|
||||||
{
|
{
|
||||||
return GPUDevice::Instance->CreateTexture(String::Empty);
|
return GPUDevice::Instance->CreateTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUTexture* GPUTexture::New()
|
GPUTexture* GPUTexture::New()
|
||||||
{
|
{
|
||||||
return GPUDevice::Instance->CreateTexture(String::Empty);
|
return GPUDevice::Instance->CreateTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUTexture::GPUTexture()
|
GPUTexture::GPUTexture()
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ Task* StreamingTexture::UpdateAllocation(int32 residency)
|
|||||||
#if GPU_ENABLE_RESOURCE_NAMING
|
#if GPU_ENABLE_RESOURCE_NAMING
|
||||||
texture = GPUDevice::Instance->CreateTexture(_texture->GetName());
|
texture = GPUDevice::Instance->CreateTexture(_texture->GetName());
|
||||||
#else
|
#else
|
||||||
texture = GPUDevice::Instance->CreateTexture(String::Empty);
|
texture = GPUDevice::Instance->CreateTexture();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -213,18 +213,19 @@ namespace RenderToolsDX
|
|||||||
{
|
{
|
||||||
HRESULT reason = S_OK;
|
HRESULT reason = S_OK;
|
||||||
const RendererType rendererType = GPUDevice::Instance ? GPUDevice::Instance->GetRendererType() : RendererType::Unknown;
|
const RendererType rendererType = GPUDevice::Instance ? GPUDevice::Instance->GetRendererType() : RendererType::Unknown;
|
||||||
|
void* nativePtr = GPUDevice::Instance ? GPUDevice::Instance->GetNativePtr() : nullptr;
|
||||||
#if GRAPHICS_API_DIRECTX12
|
#if GRAPHICS_API_DIRECTX12
|
||||||
if (rendererType == RendererType::DirectX12)
|
if (rendererType == RendererType::DirectX12 && nativePtr)
|
||||||
{
|
{
|
||||||
reason = ((ID3D12Device*)GPUDevice::Instance->GetNativePtr())->GetDeviceRemovedReason();
|
reason = ((ID3D12Device*)nativePtr)->GetDeviceRemovedReason();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if GRAPHICS_API_DIRECTX11
|
#if GRAPHICS_API_DIRECTX11
|
||||||
if (rendererType == RendererType::DirectX11 ||
|
if ((rendererType == RendererType::DirectX11 ||
|
||||||
rendererType == RendererType::DirectX10_1 ||
|
rendererType == RendererType::DirectX10_1 ||
|
||||||
rendererType == RendererType::DirectX10)
|
rendererType == RendererType::DirectX10) && nativePtr)
|
||||||
{
|
{
|
||||||
reason = ((ID3D11Device*)GPUDevice::Instance->GetNativePtr())->GetDeviceRemovedReason();
|
reason = ((ID3D11Device*)nativePtr)->GetDeviceRemovedReason();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
const Char* reasonStr = nullptr;
|
const Char* reasonStr = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user