From b756c1601815af1dd8e0c719dc13f1f2e54b63d6 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 23 Mar 2026 18:37:18 +0100 Subject: [PATCH] Add renaming underlying GPU resource (eg. for pooled render targets) --- Source/Engine/Graphics/GPUDevice.cpp | 5 +++++ Source/Engine/Graphics/GPUResource.h | 4 ++++ .../GraphicsDevice/DirectX/DX11/GPUTextureDX11.cpp | 12 ++++++++++++ .../GraphicsDevice/DirectX/DX11/GPUTextureDX11.h | 3 +++ .../GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp | 12 ++++++++++++ .../GraphicsDevice/DirectX/DX12/GPUTextureDX12.h | 4 +++- .../GraphicsDevice/Vulkan/GPUTextureVulkan.cpp | 12 ++++++++++++ .../Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h | 3 +++ .../GraphicsDevice/WebGPU/GPUTextureWebGPU.cpp | 13 +++++++++++++ .../Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.h | 3 +++ 10 files changed, 70 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Graphics/GPUDevice.cpp b/Source/Engine/Graphics/GPUDevice.cpp index b16ed7c74..6aaee8d01 100644 --- a/Source/Engine/Graphics/GPUDevice.cpp +++ b/Source/Engine/Graphics/GPUDevice.cpp @@ -278,6 +278,11 @@ void GPUResource::SetName(const StringView& name) Platform::MemoryCopy(_namePtr, name.Get(), _nameSize * sizeof(Char)); _namePtr[_nameSize] = 0; } + OnRenamed(); +} + +void GPUResource::OnRenamed() +{ } #elif !BUILD_RELEASE diff --git a/Source/Engine/Graphics/GPUResource.h b/Source/Engine/Graphics/GPUResource.h index 1b6178036..1660a9486 100644 --- a/Source/Engine/Graphics/GPUResource.h +++ b/Source/Engine/Graphics/GPUResource.h @@ -120,6 +120,10 @@ protected: /// virtual void OnReleaseGPU(); +#if !BUILD_RELEASE + virtual void OnRenamed(); +#endif + public: // [ScriptingObject] String ToString() const override; diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUTextureDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUTextureDX11.cpp index bce8271db..2bf2e5f78 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUTextureDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUTextureDX11.cpp @@ -157,6 +157,18 @@ void GPUTextureDX11::OnReleaseGPU() GPUTexture::OnReleaseGPU(); } +#if GPU_ENABLE_RESOURCE_NAMING + +void GPUTextureDX11::OnRenamed() +{ + if (_resource) + { + DX_SET_DEBUG_NAME(_resource, GetName()); + } +} + +#endif + #define CLEAR_VIEWS() rtView = nullptr; srView = nullptr; dsView = nullptr; uaView = nullptr void GPUTextureDX11::initHandles() diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUTextureDX11.h b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUTextureDX11.h index 35101e79b..44dc40b63 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUTextureDX11.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUTextureDX11.h @@ -248,6 +248,9 @@ protected: bool OnInit() override; void OnResidentMipsChanged() override; void OnReleaseGPU() override; +#if GPU_ENABLE_RESOURCE_NAMING + void OnRenamed() override; +#endif }; #endif diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp index eada546e3..c14e34e7e 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp @@ -241,6 +241,18 @@ void GPUTextureDX12::OnReleaseGPU() GPUTexture::OnReleaseGPU(); } +#if GPU_ENABLE_RESOURCE_NAMING + +void GPUTextureDX12::OnRenamed() +{ + if (_resource) + { + DX_SET_DEBUG_NAME(_resource, GetName()); + } +} + +#endif + void GPUTextureViewDX12::Release() { _rtv.Release(); diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.h index b513b5b4f..d54c7fff9 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.h @@ -202,11 +202,13 @@ public: } protected: - // [GPUTexture] bool OnInit() override; void OnResidentMipsChanged() override; void OnReleaseGPU() override; +#if GPU_ENABLE_RESOURCE_NAMING + void OnRenamed() override; +#endif }; #endif diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.cpp index 36d0f905a..311ac9220 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.cpp @@ -522,4 +522,16 @@ void GPUTextureVulkan::OnReleaseGPU() GPUTexture::OnReleaseGPU(); } +#if GPU_ENABLE_RESOURCE_NAMING + +void GPUTextureVulkan::OnRenamed() +{ + if (_image) + { + VK_SET_DEBUG_NAME(_device, _image, VK_OBJECT_TYPE_IMAGE, GetName()); + } +} + +#endif + #endif diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h index 178938b82..06e9dbaea 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h @@ -166,6 +166,9 @@ protected: bool OnInit() override; void OnResidentMipsChanged() override; void OnReleaseGPU() override; +#if GPU_ENABLE_RESOURCE_NAMING + void OnRenamed() override; +#endif }; #endif diff --git a/Source/Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.cpp b/Source/Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.cpp index 14affdef7..513dcaf17 100644 --- a/Source/Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.cpp +++ b/Source/Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.cpp @@ -242,6 +242,19 @@ void GPUTextureWebGPU::OnReleaseGPU() GPUTexture::OnReleaseGPU(); } +#if GPU_ENABLE_RESOURCE_NAMING + +void GPUTextureWebGPU::OnRenamed() +{ + if (Texture) + { + _name.Set(_namePtr, _nameSize); + wgpuTextureSetLabel(Texture, { _name.Get(), (size_t)_name.Length() }); + } +} + +#endif + void GPUTextureWebGPU::InitHandles() { WGPUTextureViewDescriptor viewDesc = WGPU_TEXTURE_VIEW_DESCRIPTOR_INIT; diff --git a/Source/Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.h b/Source/Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.h index 2f9a3b329..2eeab53eb 100644 --- a/Source/Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.h +++ b/Source/Engine/GraphicsDevice/WebGPU/GPUTextureWebGPU.h @@ -147,6 +147,9 @@ protected: bool OnInit() override; void OnResidentMipsChanged() override; void OnReleaseGPU() override; +#if GPU_ENABLE_RESOURCE_NAMING + void OnRenamed() override; +#endif private: void InitHandles();