From e2d9450d0df1921f7cc780c604759f2d3f03a58b Mon Sep 17 00:00:00 2001 From: Vladislav Belov Date: Wed, 17 Sep 2025 12:32:08 +0200 Subject: [PATCH] Revert "Font: make atlas uploads queue-aware on Vulkan" This reverts commit 256dff7fd456850c023f6d0122b92c54bf4bb372. --- source/graphics/Font.cpp | 9 ++++-- source/graphics/Font.h | 1 + source/renderer/backend/IDevice.h | 4 +-- source/renderer/backend/ITexture.h | 4 +-- source/renderer/backend/dummy/Device.cpp | 6 ++-- source/renderer/backend/dummy/Device.h | 4 +-- source/renderer/backend/dummy/Texture.h | 5 +-- source/renderer/backend/gl/Device.cpp | 6 ++-- source/renderer/backend/gl/Device.h | 6 ++-- source/renderer/backend/gl/Texture.h | 4 +-- source/renderer/backend/vulkan/Device.cpp | 31 +++---------------- source/renderer/backend/vulkan/Device.h | 10 ++---- .../backend/vulkan/RingCommandContext.cpp | 2 -- .../renderer/backend/vulkan/SubmitScheduler.h | 1 - source/renderer/backend/vulkan/Texture.cpp | 16 ++-------- source/renderer/backend/vulkan/Texture.h | 15 ++------- 16 files changed, 34 insertions(+), 90 deletions(-) diff --git a/source/graphics/Font.cpp b/source/graphics/Font.cpp index c9315f8794..65b69ed557 100644 --- a/source/graphics/Font.cpp +++ b/source/graphics/Font.cpp @@ -289,7 +289,7 @@ bool CFont::ConstructTextureAtlas() Renderer::Backend::ITexture::Usage::TRANSFER_DST | Renderer::Backend::ITexture::Usage::SAMPLED, m_TextureFormat, - textureSize, textureSize, defaultSamplerDesc, 1, 1, true + textureSize, textureSize, defaultSamplerDesc )); if (!m_Texture) @@ -298,6 +298,8 @@ bool CFont::ConstructTextureAtlas() return false; } + m_IsLoadingTextureToGPU = true; + // Initialise texture with transparency, for the areas we don't // overwrite with uploading later. m_TexData = std::make_unique(m_AtlasSize); @@ -492,7 +494,10 @@ std::optional CFont::GenerateGlyphBitmap(FT_Glyph& glyph, u16 codepoi void CFont::UploadTextureAtlasToGPU() { - if (m_Texture->GetBackendTexture()->IsPendingQueueSubmit() || !m_IsDirty) + if (std::exchange(m_IsLoadingTextureToGPU, false)) + return; + + if (!m_IsDirty) return; Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); diff --git a/source/graphics/Font.h b/source/graphics/Font.h index f4b3b8d791..cc8c865449 100644 --- a/source/graphics/Font.h +++ b/source/graphics/Font.h @@ -162,6 +162,7 @@ private: int m_AtlasPadding; bool m_IsDirty{false}; + bool m_IsLoadingTextureToGPU{false}; float m_StrokeWidth{0.0f}; float m_Scale{1.0f}; diff --git a/source/renderer/backend/IDevice.h b/source/renderer/backend/IDevice.h index 5862920d1c..54427ed886 100644 --- a/source/renderer/backend/IDevice.h +++ b/source/renderer/backend/IDevice.h @@ -114,12 +114,12 @@ public: virtual std::unique_ptr CreateTexture( const char* name, const ITexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware = false) = 0; + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) = 0; virtual std::unique_ptr CreateTexture2D( const char* name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1, const bool queueSubmitAware = false) = 0; + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) = 0; /** * @see IFramebuffer diff --git a/source/renderer/backend/ITexture.h b/source/renderer/backend/ITexture.h index 820ceeae9d..b2083d6346 100644 --- a/source/renderer/backend/ITexture.h +++ b/source/renderer/backend/ITexture.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2024 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -58,8 +58,6 @@ public: virtual uint32_t GetWidth() const = 0; virtual uint32_t GetHeight() const = 0; virtual uint32_t GetMIPLevelCount() const = 0; - - virtual bool IsPendingQueueSubmit() const = 0; }; } // namespace Backend diff --git a/source/renderer/backend/dummy/Device.cpp b/source/renderer/backend/dummy/Device.cpp index ba19c2fccd..43c48b0d3c 100644 --- a/source/renderer/backend/dummy/Device.cpp +++ b/source/renderer/backend/dummy/Device.cpp @@ -98,7 +98,7 @@ std::unique_ptr CDevice::CreateTexture( const char* /*name*/, const CTexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc& /*defaultSamplerDesc*/, const uint32_t MIPLevelCount, - const uint32_t /*sampleCount*/, const bool /*queueSubmitAware*/) + const uint32_t /*sampleCount*/) { return CTexture::Create(this, type, usage, format, width, height, MIPLevelCount); } @@ -106,10 +106,10 @@ std::unique_ptr CDevice::CreateTexture( std::unique_ptr CDevice::CreateTexture2D( const char* name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware) + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) { return CreateTexture(name, ITexture::Type::TEXTURE_2D, usage, - format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount, queueSubmitAware); + format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); } std::unique_ptr CDevice::CreateFramebuffer( diff --git a/source/renderer/backend/dummy/Device.h b/source/renderer/backend/dummy/Device.h index a46acd706f..dd9046cde0 100644 --- a/source/renderer/backend/dummy/Device.h +++ b/source/renderer/backend/dummy/Device.h @@ -71,12 +71,12 @@ public: std::unique_ptr CreateTexture( const char* name, const ITexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware = false) override; + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; std::unique_ptr CreateTexture2D( const char* name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1, const bool queueSubmitAware = false) override; + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; std::unique_ptr CreateFramebuffer( const char* name, SColorAttachment* colorAttachment, diff --git a/source/renderer/backend/dummy/Texture.h b/source/renderer/backend/dummy/Texture.h index 6aece1a36b..91ee199552 100644 --- a/source/renderer/backend/dummy/Texture.h +++ b/source/renderer/backend/dummy/Texture.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -51,9 +51,6 @@ public: uint32_t GetHeight() const override { return m_Height; } uint32_t GetMIPLevelCount() const override { return m_MIPLevelCount; } - // Dummy backend does not support queue submission. - bool IsPendingQueueSubmit() const override { return false; } - private: friend class CDevice; diff --git a/source/renderer/backend/gl/Device.cpp b/source/renderer/backend/gl/Device.cpp index 8389a0bc0a..73b165ebae 100644 --- a/source/renderer/backend/gl/Device.cpp +++ b/source/renderer/backend/gl/Device.cpp @@ -926,7 +926,7 @@ std::unique_ptr CDevice::CreateVertexInputLayout( std::unique_ptr CDevice::CreateTexture( const char* name, const ITexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool /*queueSubmitAware*/) + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) { return CTexture::Create(this, name, type, usage, format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); @@ -935,10 +935,10 @@ std::unique_ptr CDevice::CreateTexture( std::unique_ptr CDevice::CreateTexture2D( const char* name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware) + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) { return CreateTexture(name, CTexture::Type::TEXTURE_2D, usage, - format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount, queueSubmitAware); + format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); } std::unique_ptr CDevice::CreateFramebuffer( diff --git a/source/renderer/backend/gl/Device.h b/source/renderer/backend/gl/Device.h index 01e1c03dc8..9d5299fc6f 100644 --- a/source/renderer/backend/gl/Device.h +++ b/source/renderer/backend/gl/Device.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2024 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -87,12 +87,12 @@ public: std::unique_ptr CreateTexture( const char* name, const ITexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware) override; + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; std::unique_ptr CreateTexture2D( const char* name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1, const bool queueSubmitAware = false) override; + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; std::unique_ptr CreateFramebuffer( const char* name, SColorAttachment* colorAttachment, diff --git a/source/renderer/backend/gl/Texture.h b/source/renderer/backend/gl/Texture.h index b1929691ff..c7e0d986aa 100644 --- a/source/renderer/backend/gl/Texture.h +++ b/source/renderer/backend/gl/Texture.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -58,8 +58,6 @@ public: GLuint GetHandle() const { return m_Handle; } - // GL doesn's support queue submmit, so we don't need to track pending. - bool IsPendingQueueSubmit() const override { return false; } private: friend class CDevice; diff --git a/source/renderer/backend/vulkan/Device.cpp b/source/renderer/backend/vulkan/Device.cpp index 759dd07f37..3d144f2663 100644 --- a/source/renderer/backend/vulkan/Device.cpp +++ b/source/renderer/backend/vulkan/Device.cpp @@ -681,7 +681,6 @@ CDevice::~CDevice() if (m_QueryPool) vkDestroyQueryPool(GetVkDevice(), m_QueryPool, nullptr); - ProcessTextureUploadWatchQueue(true); ProcessDeviceObjectToDestroyQueue(true); m_RenderPassManager.reset(); @@ -754,21 +753,21 @@ std::unique_ptr CDevice::CreateVertexInputLayout( std::unique_ptr CDevice::CreateTexture( const char* name, const ITexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware) + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) { return CTexture::Create( this, name, type, usage, format, width, height, - defaultSamplerDesc, MIPLevelCount, sampleCount, queueSubmitAware); + defaultSamplerDesc, MIPLevelCount, sampleCount); } std::unique_ptr CDevice::CreateTexture2D( const char* name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware) + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) { return CreateTexture( name, ITexture::Type::TEXTURE_2D, usage, format, - width, height, defaultSamplerDesc, MIPLevelCount, sampleCount, queueSubmitAware); + width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); } std::unique_ptr CDevice::CreateFramebuffer( @@ -837,7 +836,6 @@ void CDevice::Present() m_SubmitScheduler->Present(*m_SwapChain); - ProcessTextureUploadWatchQueue(); ProcessObjectToDestroyQueue(); ProcessDeviceObjectToDestroyQueue(); @@ -1018,10 +1016,6 @@ void CDevice::ScheduleBufferToDestroy(const DeviceObjectUID uid) { m_BufferToDestroyQueue.push({m_FrameID, uid}); } -void CDevice::ScheduleTextureUploadWatch(CTexture* texture) -{ - m_TextureUploadWatcherQueue.push({ m_FrameID, texture }); -} void CDevice::SetObjectName(VkObjectType type, const uint64_t handle, const char* name) { @@ -1125,18 +1119,6 @@ void CDevice::ProcessDeviceObjectToDestroyQueue(const bool ignoreFrameID) } } -void CDevice::ProcessTextureUploadWatchQueue(const bool ignoreFrameID) -{ - while (!m_TextureUploadWatcherQueue.empty() && - (ignoreFrameID || m_TextureUploadWatcherQueue.front().first + NUMBER_OF_FRAMES_IN_FLIGHT < m_FrameID)) - { - CTexture* texture = m_TextureUploadWatcherQueue.front().second; - if (texture) - texture->SetPendingQueueSubmit(false); - m_TextureUploadWatcherQueue.pop(); - } -} - CTexture* CDevice::GetCurrentBackbufferTexture() { return IsSwapChainValid() ? m_SwapChain->GetCurrentBackbufferTexture() : nullptr; @@ -1169,11 +1151,6 @@ std::unique_ptr CreateDevice(SDL_Window* window) return Vulkan::CDevice::Create(window); } -uint32_t CDevice::GetCurrentSchedulerHandle() const -{ - return m_SubmitScheduler ? m_SubmitScheduler->GetCurrentHandle() : CSubmitScheduler::INVALID_SUBMIT_HANDLE; -} - } // namespace Vulkan } // namespace Backend diff --git a/source/renderer/backend/vulkan/Device.h b/source/renderer/backend/vulkan/Device.h index 0f43d2f228..4867db9e89 100644 --- a/source/renderer/backend/vulkan/Device.h +++ b/source/renderer/backend/vulkan/Device.h @@ -96,12 +96,12 @@ public: std::unique_ptr CreateTexture( const char* name, const ITexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware = false) override; + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; std::unique_ptr CreateTexture2D( const char* name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1, const bool queueSubmitAware = false) override; + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; std::unique_ptr CreateFramebuffer( const char* name, SColorAttachment* colorAttachment, @@ -165,8 +165,6 @@ public: void ScheduleBufferToDestroy(const DeviceObjectUID uid); - void ScheduleTextureUploadWatch(CTexture* texture); - void SetObjectName(VkObjectType type, const void* handle, const char* name) { SetObjectName(type, reinterpret_cast(handle), name); @@ -190,8 +188,6 @@ public: DeviceObjectUID GenerateNextDeviceObjectUID(); - uint32_t GetCurrentSchedulerHandle() const; - private: CDevice(); @@ -199,7 +195,6 @@ private: bool IsSwapChainValid(); void ProcessObjectToDestroyQueue(const bool ignoreFrameID = false); void ProcessDeviceObjectToDestroyQueue(const bool ignoreFrameID = false); - void ProcessTextureUploadWatchQueue(const bool ignoreFrameID = false); bool IsFormatSupportedForUsage(const Format format, const uint32_t usage) const; @@ -250,7 +245,6 @@ private: }; std::queue m_ObjectToDestroyQueue; std::queue> m_TextureToDestroyQueue; - std::queue> m_TextureUploadWatcherQueue; std::queue> m_BufferToDestroyQueue; std::unique_ptr m_RenderPassManager; diff --git a/source/renderer/backend/vulkan/RingCommandContext.cpp b/source/renderer/backend/vulkan/RingCommandContext.cpp index 9c3606dd03..3dec15b729 100644 --- a/source/renderer/backend/vulkan/RingCommandContext.cpp +++ b/source/renderer/backend/vulkan/RingCommandContext.cpp @@ -172,7 +172,6 @@ void CRingCommandContext::ScheduleUpload( const uint32_t level, const uint32_t layer) { ENSURE(texture->GetType() != ITexture::Type::TEXTURE_2D_MULTISAMPLE); - const Format format = texture->GetFormat(); if (texture->GetType() != ITexture::Type::TEXTURE_CUBE) ENSURE(layer == 0); @@ -232,7 +231,6 @@ void CRingCommandContext::ScheduleUpload( VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_PIPELINE_STAGE_TRANSFER_BIT, dstStageMask); texture->SetInitialized(); - texture->SetPendingQueueSubmit(true); } void CRingCommandContext::ScheduleUpload( diff --git a/source/renderer/backend/vulkan/SubmitScheduler.h b/source/renderer/backend/vulkan/SubmitScheduler.h index a5d07432ff..592b9ace06 100644 --- a/source/renderer/backend/vulkan/SubmitScheduler.h +++ b/source/renderer/backend/vulkan/SubmitScheduler.h @@ -65,7 +65,6 @@ public: void Flush(); - SubmitHandle GetCurrentHandle() const { return m_CurrentHandle; }; private: CSubmitScheduler(CDevice* device, VkQueue queue); diff --git a/source/renderer/backend/vulkan/Texture.cpp b/source/renderer/backend/vulkan/Texture.cpp index 5e346aa539..cc06862bf5 100644 --- a/source/renderer/backend/vulkan/Texture.cpp +++ b/source/renderer/backend/vulkan/Texture.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2024 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -28,8 +28,6 @@ #include "renderer/backend/vulkan/SamplerManager.h" #include "renderer/backend/vulkan/Utilities.h" -#include - namespace Renderer { @@ -44,7 +42,7 @@ std::unique_ptr CTexture::Create( CDevice* device, const char* name, const Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc& defaultSamplerDesc, - const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware) + const uint32_t MIPLevelCount, const uint32_t sampleCount) { std::unique_ptr texture(new CTexture(device)); @@ -56,7 +54,6 @@ std::unique_ptr CTexture::Create( texture->m_MIPLevelCount = MIPLevelCount; texture->m_SampleCount = sampleCount; texture->m_LayerCount = type == ITexture::Type::TEXTURE_CUBE ? 6 : 1; - texture->m_QueueSubmitAware = queueSubmitAware; if (type == Type::TEXTURE_2D_MULTISAMPLE) ENSURE(sampleCount > 1); @@ -383,15 +380,6 @@ CTexture::~CTexture() m_Device->ScheduleTextureToDestroy(m_UID); } -void CTexture::SetPendingQueueSubmit(bool pending) -{ - if (!m_QueueSubmitAware) - return; - - if (!std::exchange(m_PendingQueueSubmit, pending) && pending) - m_Device->ScheduleTextureUploadWatch(this); -} - IDevice* CTexture::GetDevice() { return m_Device; diff --git a/source/renderer/backend/vulkan/Texture.h b/source/renderer/backend/vulkan/Texture.h index f038ad55a3..63eb0bad47 100644 --- a/source/renderer/backend/vulkan/Texture.h +++ b/source/renderer/backend/vulkan/Texture.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -56,9 +56,6 @@ public: uint32_t GetSampleCount() const { return m_SampleCount; } uint32_t GetLayerCount() const { return m_LayerCount; } - bool IsPendingQueueSubmit() const override { return m_PendingQueueSubmit; } - void SetPendingQueueSubmit(bool pending); - VkImage GetImage() { return m_Image; } VkImageView GetAttachmentImageView() { return m_AttachmentImageView; } VkImageView GetSamplerImageView() { return m_SamplerImageView; } @@ -91,7 +88,7 @@ private: CDevice* device, const char* name, const Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc& defaultSamplerDesc, - const uint32_t MIPLevelCount, const uint32_t sampleCount, const bool queueSubmitAware = false); + const uint32_t MIPLevelCount, const uint32_t sampleCount); static std::unique_ptr WrapBackbufferImage( CDevice* device, const char* name, const VkImage image, const VkFormat format, @@ -133,14 +130,6 @@ private: // It's safe to store the current state while we use a single device command // context. bool m_Initialized = false; - - // We store a flag to indicate that the texture is in Queue submit. - bool m_PendingQueueSubmit = false; - - // If true, the texture is aware of queue submission useful for - // for dynamic textures that are updated frequently and needs to wait for - // the queue submission to finish before overwriting the texture data. - bool m_QueueSubmitAware = false; }; } // namespace Vulkan