Add multithreaded upload to dynamic texture on Vulkan [Core feature] (#4028)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Adrian Cojocaru <adrian.cojocaru92@yahoo.com>
This commit is contained in:
Alex Cristici
2026-01-20 17:04:34 +02:00
committed by GitHub
parent 0de907f91a
commit 6a77854632
28 changed files with 556 additions and 82 deletions

View File

@@ -158,7 +158,7 @@ void Context::destroyResources() {
clipping.vertexBuffer.reset();
}
void Context::enqueueDeletion(std::function<void(Context&)>&& function) {
void Context::enqueueDeletion(DeletionTask&& function) {
if (frameResources.empty()) {
function(*this);
return;
@@ -167,11 +167,19 @@ void Context::enqueueDeletion(std::function<void(Context&)>&& function) {
frameResources[frameResourceIndex].deletionQueue.push_back(std::move(function));
}
void Context::submitOneTimeCommand(const std::function<void(const vk::UniqueCommandBuffer&)>& function) const {
void Context::submitOneTimeCommand(const std::function<void(const vk::UniqueCommandBuffer&)>& function) {
submitOneTimeCommand({}, function);
}
void Context::submitOneTimeCommand(const vk::UniqueCommandPool& commandPool,
const std::function<void(const vk::UniqueCommandBuffer&)>& function) {
MLN_TRACE_FUNC();
#if DYNAMIC_TEXTURE_VULKAN_MULTITHREADED_UPLOAD
std::scoped_lock lock(graphicsQueueSubmitMutex);
#endif
const vk::CommandBufferAllocateInfo allocateInfo(
backend.getCommandPool().get(), vk::CommandBufferLevel::ePrimary, 1);
commandPool ? commandPool.get() : backend.getCommandPool().get(), vk::CommandBufferLevel::ePrimary, 1);
const auto& device = backend.getDevice();
const auto& dispatcher = backend.getDispatcher();
@@ -315,6 +323,10 @@ void Context::endFrame() {}
void Context::submitFrame() {
MLN_TRACE_FUNC();
#if DYNAMIC_TEXTURE_VULKAN_MULTITHREADED_UPLOAD
std::scoped_lock lock(graphicsQueueSubmitMutex);
#endif
const auto& dispatcher = backend.getDispatcher();
const auto& frame = frameResources[frameResourceIndex];
frame.commandBuffer->end(dispatcher);
@@ -433,6 +445,10 @@ gfx::Texture2DPtr Context::createTexture2D() {
return std::make_shared<Texture2D>(*this);
}
gfx::DynamicTexturePtr Context::createDynamicTexture(Size size, gfx::TexturePixelType pixelType) {
return std::make_shared<DynamicTexture>(*this, size, pixelType);
}
RenderTargetPtr Context::createRenderTarget(const Size size, const gfx::TextureChannelDataType type) {
return std::make_shared<RenderTarget>(*this, size, type);
}
@@ -738,7 +754,9 @@ const vk::UniquePipelineLayout& Context::getPushConstantPipelineLayout() {
void Context::FrameResources::runDeletionQueue(Context& context) {
MLN_TRACE_FUNC();
for (const auto& function : deletionQueue) function(context);
for (const auto& function : deletionQueue) {
function(context);
}
deletionQueue.clear();
}