diff --git a/src/util/d3d12_builders.cpp b/src/util/d3d12_builders.cpp index 4e5a7329e..e57f72eb6 100644 --- a/src/util/d3d12_builders.cpp +++ b/src/util/d3d12_builders.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "d3d12_builders.h" @@ -341,12 +341,4 @@ void D3D12::SetObjectName(ID3D12Object* object, std::string_view name) object->SetName(StringUtil::UTF8StringToWideString(name).c_str()); } -void D3D12::SetObjectNameFormatted(ID3D12Object* object, const char* format, ...) -{ - std::va_list ap; - va_start(ap, format); - SetObjectName(object, StringUtil::StdStringFromFormatV(format, ap).c_str()); - va_end(ap); -} - #endif diff --git a/src/util/d3d12_builders.h b/src/util/d3d12_builders.h index 82bb776bb..37c378774 100644 --- a/src/util/d3d12_builders.h +++ b/src/util/d3d12_builders.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -127,13 +127,9 @@ private: #ifdef _DEBUG void SetObjectName(ID3D12Object* object, std::string_view name); -void SetObjectNameFormatted(ID3D12Object* object, const char* format, ...); #else static inline void SetObjectName(ID3D12Object* object, std::string_view name) { } -static inline void SetObjectNameFormatted(ID3D12Object* object, const char* format, ...) -{ -} #endif } // namespace D3D12 diff --git a/src/util/d3d12_device.cpp b/src/util/d3d12_device.cpp index 093f014a4..59ace80e5 100644 --- a/src/util/d3d12_device.cpp +++ b/src/util/d3d12_device.cpp @@ -585,24 +585,19 @@ void D3D12Device::SubmitCommandList(bool wait_for_completion) WaitForFence(res.fence_counter); } -void D3D12Device::SubmitCommandList(bool wait_for_completion, const char* reason, ...) +void D3D12Device::SubmitCommandList(bool wait_for_completion, const std::string_view reason) { - std::va_list ap; - va_start(ap, reason); - const std::string reason_str(StringUtil::StdStringFromFormatV(reason, ap)); - va_end(ap); - - WARNING_LOG("Executing command buffer due to '{}'", reason_str); + WARNING_LOG("Executing command buffer due to '{}'", reason); SubmitCommandList(wait_for_completion); } -void D3D12Device::SubmitCommandListAndRestartRenderPass(const char* reason) +void D3D12Device::SubmitCommandListAndRestartRenderPass(const std::string_view reason) { if (InRenderPass()) EndRenderPass(); D3D12Pipeline* pl = m_current_pipeline; - SubmitCommandList(false, "%s", reason); + SubmitCommandList(false, reason); SetPipeline(pl); BeginRenderPass(); @@ -895,7 +890,7 @@ bool D3D12Device::CreateSwapChainRTV() return false; } - D3D12::SetObjectNameFormatted(backbuffer.Get(), "Swap Chain Buffer #%u", i); + D3D12::SetObjectName(backbuffer.Get(), TinyString::from_format("Swap Chain Buffer #{}", i)); D3D12DescriptorHandle rtv; if (!m_rtv_heap_manager.Allocate(&rtv)) diff --git a/src/util/d3d12_device.h b/src/util/d3d12_device.h index 24596d904..3f833d631 100644 --- a/src/util/d3d12_device.h +++ b/src/util/d3d12_device.h @@ -176,8 +176,8 @@ public: /// Ends any render pass, executes the command buffer, and invalidates cached state. void SubmitCommandList(bool wait_for_completion); - void SubmitCommandList(bool wait_for_completion, const char* reason, ...); - void SubmitCommandListAndRestartRenderPass(const char* reason); + void SubmitCommandList(bool wait_for_completion, const std::string_view reason); + void SubmitCommandListAndRestartRenderPass(const std::string_view reason); void UnbindPipeline(D3D12Pipeline* pl); void UnbindTexture(D3D12Texture* tex); diff --git a/src/util/d3d12_texture.cpp b/src/util/d3d12_texture.cpp index 28f661015..5679d1427 100644 --- a/src/util/d3d12_texture.cpp +++ b/src/util/d3d12_texture.cpp @@ -415,10 +415,10 @@ bool D3D12Texture::Update(u32 x, u32 y, u32 width, u32 height, const void* data, } else { - if (!sbuffer.ReserveMemory(required_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT)) + if (!sbuffer.ReserveMemory(required_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT)) [[unlikely]] { - D3D12Device::GetInstance().SubmitCommandList(false, "While waiting for %u bytes in texture upload buffer", - required_size); + D3D12Device::GetInstance().SubmitCommandList( + false, TinyString::from_format("Needs {} bytes in texture upload buffer", required_size)); if (!sbuffer.ReserveMemory(required_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT)) [[unlikely]] { ERROR_LOG("Failed to reserve texture upload memory ({} bytes).", required_size); @@ -485,10 +485,10 @@ bool D3D12Texture::Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 if (req_size >= (buffer.GetSize() / 2)) return false; - if (!buffer.ReserveMemory(req_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT)) + if (!buffer.ReserveMemory(req_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT)) [[unlikely]] { - dev.SubmitCommandList(false, "While waiting for %u bytes in texture upload buffer", req_size); - if (!buffer.ReserveMemory(req_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT)) + dev.SubmitCommandList(false, TinyString::from_format("Needs {} bytes in texture upload buffer", req_size)); + if (!buffer.ReserveMemory(req_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT)) [[unlikely]] Panic("Failed to reserve texture upload memory"); } diff --git a/src/util/vulkan_builders.h b/src/util/vulkan_builders.h index 4bb17c4de..eddcad4c3 100644 --- a/src/util/vulkan_builders.h +++ b/src/util/vulkan_builders.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -6,10 +6,10 @@ #include "gpu_device.h" #include "vulkan_loader.h" +#include "common/small_string.h" #include "common/string_util.h" #include -#include #include #if defined(_DEBUG) && !defined(CPU_ARCH_ARM32) && !defined(CPU_ARCH_X86) @@ -390,39 +390,19 @@ struct VkObjectTypeMap; #endif -static inline void SetFormattedObjectName(VkDevice device, void* object_handle, VkObjectType object_type, - const char* format, va_list ap) +template +static inline void SetObjectName(VkDevice device, T object_handle, const std::string_view name) { #ifdef ENABLE_VULKAN_DEBUG_OBJECTS if (!vkSetDebugUtilsObjectNameEXT) - { return; - } - const std::string str(StringUtil::StdStringFromFormatV(format, ap)); - const VkDebugUtilsObjectNameInfoEXT nameInfo{VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, nullptr, object_type, - reinterpret_cast(object_handle), str.c_str()}; - vkSetDebugUtilsObjectNameEXT(device, &nameInfo); -#endif -} - -template -static inline void SetFormattedObjectName(VkDevice device, T object_handle, const char* format, ...) -{ -#ifdef ENABLE_VULKAN_DEBUG_OBJECTS - std::va_list ap; - va_start(ap, format); - SetFormattedObjectName(device, reinterpret_cast((typename VkObjectTypeMap::type)object_handle), - VkObjectTypeMap::value, format, ap); - va_end(ap); -#endif -} - -template -static inline void SetObjectName(VkDevice device, T object_handle, std::string_view sv) -{ -#ifdef ENABLE_VULKAN_DEBUG_OBJECTS - SetFormattedObjectName(device, object_handle, "%.*s", static_cast(sv.length()), sv.data()); + const SmallString terminated_name(name); + const VkDebugUtilsObjectNameInfoEXT name_info{ + VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, nullptr, VkObjectTypeMap::value, + static_cast(reinterpret_cast(static_cast::type>(object_handle))), + terminated_name.c_str()}; + vkSetDebugUtilsObjectNameEXT(device, &name_info); #endif } } // namespace Vulkan diff --git a/src/util/vulkan_device.cpp b/src/util/vulkan_device.cpp index a9792d2b7..2a24533f0 100644 --- a/src/util/vulkan_device.cpp +++ b/src/util/vulkan_device.cpp @@ -1567,24 +1567,19 @@ void VulkanDevice::SubmitCommandBuffer(bool wait_for_completion) InvalidateCachedState(); } -void VulkanDevice::SubmitCommandBuffer(bool wait_for_completion, const char* reason, ...) +void VulkanDevice::SubmitCommandBuffer(bool wait_for_completion, const std::string_view reason) { - std::va_list ap; - va_start(ap, reason); - const std::string reason_str(StringUtil::StdStringFromFormatV(reason, ap)); - va_end(ap); - - WARNING_LOG("Executing command buffer due to '{}'", reason_str); + WARNING_LOG("Executing command buffer due to '{}'", reason); SubmitCommandBuffer(wait_for_completion); } -void VulkanDevice::SubmitCommandBufferAndRestartRenderPass(const char* reason) +void VulkanDevice::SubmitCommandBufferAndRestartRenderPass(const std::string_view reason) { if (InRenderPass()) EndRenderPass(); VulkanPipeline* pl = m_current_pipeline; - SubmitCommandBuffer(false, "%s", reason); + SubmitCommandBuffer(false, reason); SetPipeline(pl); BeginRenderPass(); diff --git a/src/util/vulkan_device.h b/src/util/vulkan_device.h index 76518afe0..b997dddf6 100644 --- a/src/util/vulkan_device.h +++ b/src/util/vulkan_device.h @@ -219,8 +219,8 @@ public: /// Ends any render pass, executes the command buffer, and invalidates cached state. void SubmitCommandBuffer(bool wait_for_completion); - void SubmitCommandBuffer(bool wait_for_completion, const char* reason, ...); - void SubmitCommandBufferAndRestartRenderPass(const char* reason); + void SubmitCommandBuffer(bool wait_for_completion, const std::string_view reason); + void SubmitCommandBufferAndRestartRenderPass(const std::string_view reason); void UnbindFramebuffer(VulkanTexture* tex); void UnbindPipeline(VulkanPipeline* pl); diff --git a/src/util/vulkan_texture.cpp b/src/util/vulkan_texture.cpp index 8b77edcdf..2a2e9b8b8 100644 --- a/src/util/vulkan_texture.cpp +++ b/src/util/vulkan_texture.cpp @@ -329,10 +329,10 @@ bool VulkanTexture::Update(u32 x, u32 y, u32 width, u32 height, const void* data } else { - if (!sbuffer.ReserveMemory(required_size, dev.GetBufferCopyOffsetAlignment())) + if (!sbuffer.ReserveMemory(required_size, dev.GetBufferCopyOffsetAlignment())) [[unlikely]] { - dev.SubmitCommandBuffer(false, "While waiting for %u bytes in texture upload buffer", required_size); - if (!sbuffer.ReserveMemory(required_size, dev.GetBufferCopyOffsetAlignment())) + dev.SubmitCommandBuffer(false, TinyString::from_format("Needs {} bytes in texture upload buffer", required_size)); + if (!sbuffer.ReserveMemory(required_size, dev.GetBufferCopyOffsetAlignment())) [[unlikely]] { ERROR_LOG("Failed to reserve texture upload memory ({} bytes).", required_size); return false; @@ -387,10 +387,10 @@ bool VulkanTexture::Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u3 if (req_size >= (buffer.GetCurrentSize() / 2)) return false; - if (!buffer.ReserveMemory(req_size, dev.GetBufferCopyOffsetAlignment())) + if (!buffer.ReserveMemory(req_size, dev.GetBufferCopyOffsetAlignment())) [[unlikely]] { - dev.SubmitCommandBuffer(false, "While waiting for %u bytes in texture upload buffer", req_size); - if (!buffer.ReserveMemory(req_size, dev.GetBufferCopyOffsetAlignment())) + dev.SubmitCommandBuffer(false, TinyString::from_format("Needs {} bytes in texture upload buffer", req_size)); + if (!buffer.ReserveMemory(req_size, dev.GetBufferCopyOffsetAlignment())) [[unlikely]] Panic("Failed to reserve texture upload memory"); }