core: Fix Vulkan dynamic texture threading (#4102)
This commit is contained in:
@@ -47,6 +47,7 @@ public:
|
||||
BufferResource& operator=(BufferResource&&) noexcept;
|
||||
|
||||
BufferResource clone() const;
|
||||
void destroy(bool deferred = true);
|
||||
|
||||
void update(const void* data, std::size_t size, std::size_t offset) noexcept;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <mbgl/vulkan/renderer_backend.hpp>
|
||||
#include <mbgl/vulkan/pipeline.hpp>
|
||||
#include <mbgl/vulkan/descriptor_set.hpp>
|
||||
#include <mbgl/util/util.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -150,7 +151,8 @@ public:
|
||||
uint8_t getCurrentFrameResourceIndex() const { return frameResourceIndex; }
|
||||
void enqueueDeletion(DeletionTask&& function);
|
||||
void submitOneTimeCommand(const std::function<void(const vk::UniqueCommandBuffer&)>& function);
|
||||
void submitOneTimeCommand(const vk::UniqueCommandPool& commandPool,
|
||||
void submitOneTimeCommand(const vk::UniqueCommandBuffer& buffer);
|
||||
void submitOneTimeCommand(const vk::UniqueCommandPool& pool,
|
||||
const std::function<void(const vk::UniqueCommandBuffer&)>& function);
|
||||
|
||||
void requestSurfaceUpdate(bool useDelay = true);
|
||||
@@ -212,6 +214,8 @@ private:
|
||||
#if DYNAMIC_TEXTURE_VULKAN_MULTITHREADED_UPLOAD
|
||||
std::mutex graphicsQueueSubmitMutex;
|
||||
#endif
|
||||
|
||||
MBGL_STORE_THREAD(tid);
|
||||
};
|
||||
|
||||
} // namespace vulkan
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <mbgl/gfx/dynamic_texture.hpp>
|
||||
#include <mbgl/vulkan/texture2d.hpp>
|
||||
|
||||
#define DYNAMIC_TEXTURE_VULKAN_MULTITHREADED_UPLOAD 1
|
||||
#define DYNAMIC_TEXTURE_VULKAN_MULTITHREADED_UPLOAD 0
|
||||
|
||||
namespace mbgl {
|
||||
namespace vulkan {
|
||||
@@ -15,20 +15,22 @@ using UniqueBufferAllocation = std::unique_ptr<BufferAllocation>;
|
||||
class DynamicTexture : public gfx::DynamicTexture {
|
||||
public:
|
||||
DynamicTexture(Context& context, Size size, gfx::TexturePixelType pixelType);
|
||||
~DynamicTexture() override;
|
||||
|
||||
void uploadImage(const uint8_t* pixelData, gfx::TextureHandle& texHandle) override;
|
||||
void uploadDeferredImages() override;
|
||||
bool removeTexture(const gfx::TextureHandle& texHandle) override;
|
||||
|
||||
#if DYNAMIC_TEXTURE_VULKAN_MULTITHREADED_UPLOAD
|
||||
using TexturesToBlit = std::unordered_map<gfx::TextureHandle, gfx::Texture2DPtr, gfx::TextureHandle::Hasher>;
|
||||
using TexturesToBlit =
|
||||
std::unordered_map<gfx::TextureHandle, std::shared_ptr<vulkan::Texture2D>, gfx::TextureHandle::Hasher>;
|
||||
#else
|
||||
using TextureBuffersToUpload =
|
||||
std::unordered_map<gfx::TextureHandle, UniqueBufferAllocation, gfx::TextureHandle::Hasher>;
|
||||
#endif
|
||||
|
||||
private:
|
||||
Context& context;
|
||||
vulkan::Context& context;
|
||||
|
||||
#if DYNAMIC_TEXTURE_VULKAN_MULTITHREADED_UPLOAD
|
||||
TexturesToBlit texturesToBlit;
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
bool isModifiedAfter(const std::chrono::duration<double>& t) const { return t < lastModified; }
|
||||
|
||||
void create() noexcept override;
|
||||
void destroy(bool deferred = true) noexcept;
|
||||
|
||||
void upload() noexcept override;
|
||||
void upload(const void* pixelData, const Size& size_) noexcept override;
|
||||
@@ -74,7 +75,7 @@ public:
|
||||
uint16_t xOffset,
|
||||
uint16_t yOffset,
|
||||
const vk::UniqueCommandBuffer& buffer,
|
||||
std::vector<std::function<void(Context&)>>* deletionQueue = nullptr) noexcept;
|
||||
bool submit) noexcept;
|
||||
|
||||
bool needsUpload() const noexcept override { return !!imageData; };
|
||||
|
||||
@@ -96,8 +97,8 @@ private:
|
||||
void createTexture();
|
||||
void createSampler();
|
||||
|
||||
void destroyTexture();
|
||||
void destroySampler();
|
||||
void destroyTexture(bool deferred = true);
|
||||
void destroySampler(bool deferred = true);
|
||||
|
||||
void transitionToTransferWriteLayout(const vk::UniqueCommandBuffer&);
|
||||
void transitionToTransferReadLayout(const vk::UniqueCommandBuffer&);
|
||||
|
||||
Reference in New Issue
Block a user