From 91ef1f3cfd307b1b48ef692b5ab44520563a22c4 Mon Sep 17 00:00:00 2001 From: Amirali Abdolrashidi Date: Fri, 8 Sep 2023 16:39:53 -0700 Subject: [PATCH] Move buffer suballocation callers to ContextVk * Moved the following functions from BufferHelper to ContextVk. * initBufferForBufferCopy() * initBufferForImageCopy() * initBufferForVertexConversion() Bug: b/280304441 Change-Id: I890f4396b00b0c20feb44f0ad113c55924ce1014 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4854760 Commit-Queue: Amirali Abdolrashidi Reviewed-by: Shahbaz Youssefi Reviewed-by: Charlie Lao --- src/libANGLE/renderer/vulkan/BufferVk.cpp | 2 +- src/libANGLE/renderer/vulkan/ContextVk.cpp | 75 +++++++++ src/libANGLE/renderer/vulkan/ContextVk.h | 17 ++ src/libANGLE/renderer/vulkan/TextureVk.cpp | 4 +- .../renderer/vulkan/VertexArrayVk.cpp | 27 ++-- src/libANGLE/renderer/vulkan/vk_helpers.cpp | 152 +++++------------- src/libANGLE/renderer/vulkan/vk_helpers.h | 19 +-- 7 files changed, 148 insertions(+), 148 deletions(-) diff --git a/src/libANGLE/renderer/vulkan/BufferVk.cpp b/src/libANGLE/renderer/vulkan/BufferVk.cpp index 627ce8a67..eff306f46 100644 --- a/src/libANGLE/renderer/vulkan/BufferVk.cpp +++ b/src/libANGLE/renderer/vulkan/BufferVk.cpp @@ -511,7 +511,7 @@ angle::Result BufferVk::allocStagingBuffer(ContextVk *contextVk, } ANGLE_TRY( - mStagingBuffer.allocateForCopyBuffer(contextVk, static_cast(size), coherency)); + contextVk->initBufferForBufferCopy(&mStagingBuffer, static_cast(size), coherency)); *mapPtr = mStagingBuffer.getMappedMemory(); mIsStagingBufferMapped = true; diff --git a/src/libANGLE/renderer/vulkan/ContextVk.cpp b/src/libANGLE/renderer/vulkan/ContextVk.cpp index d80f111e7..1dc0aa13f 100644 --- a/src/libANGLE/renderer/vulkan/ContextVk.cpp +++ b/src/libANGLE/renderer/vulkan/ContextVk.cpp @@ -7136,6 +7136,81 @@ angle::Result ContextVk::initImageAllocation(vk::ImageHelper *imageHelper, return angle::Result::Continue; } +angle::Result ContextVk::initBufferForBufferCopy(vk::BufferHelper *bufferHelper, + size_t size, + vk::MemoryCoherency coherency) +{ + uint32_t memoryTypeIndex = mRenderer->getStagingBufferMemoryTypeIndex(coherency); + size_t alignment = mRenderer->getStagingBufferAlignment(); + return initBufferAllocation(bufferHelper, memoryTypeIndex, size, alignment, + BufferUsageType::Dynamic); +} + +angle::Result ContextVk::initBufferForImageCopy(vk::BufferHelper *bufferHelper, + size_t size, + vk::MemoryCoherency coherency, + angle::FormatID formatId, + VkDeviceSize *offset, + uint8_t **dataPtr) +{ + // When a buffer is used in copyImage, the offset must be multiple of pixel bytes. This may + // result in non-power of two alignment. VMA's virtual allocator can not handle non-power of two + // alignment. We have to adjust offset manually. + uint32_t memoryTypeIndex = mRenderer->getStagingBufferMemoryTypeIndex(coherency); + size_t imageCopyAlignment = vk::GetImageCopyBufferAlignment(formatId); + + // Add extra padding for potential offset alignment + size_t allocationSize = size + imageCopyAlignment; + allocationSize = roundUp(allocationSize, imageCopyAlignment); + size_t stagingAlignment = static_cast(mRenderer->getStagingBufferAlignment()); + + ANGLE_TRY(initBufferAllocation(bufferHelper, memoryTypeIndex, allocationSize, stagingAlignment, + BufferUsageType::Static)); + + *offset = roundUp(bufferHelper->getOffset(), static_cast(imageCopyAlignment)); + *dataPtr = bufferHelper->getMappedMemory() + (*offset) - bufferHelper->getOffset(); + + return angle::Result::Continue; +} + +angle::Result ContextVk::initBufferForVertexConversion(vk::BufferHelper *bufferHelper, + size_t size, + vk::MemoryHostVisibility hostVisibility) +{ + if (bufferHelper->valid()) + { + // If size is big enough and it is idle, then just reuse the existing buffer. + if (size <= bufferHelper->getSize() && + (hostVisibility == vk::MemoryHostVisibility::Visible) == bufferHelper->isHostVisible()) + { + if (mRenderer->hasResourceUseFinished(bufferHelper->getResourceUse())) + { + bufferHelper->initializeBarrierTracker(this); + return angle::Result::Continue; + } + else if (hostVisibility == vk::MemoryHostVisibility::NonVisible) + { + // For device local buffer, we can reuse the buffer even if it is still GPU busy. + // The memory barrier should take care of this. + return angle::Result::Continue; + } + } + + bufferHelper->release(mRenderer); + } + + uint32_t memoryTypeIndex = mRenderer->getVertexConversionBufferMemoryTypeIndex(hostVisibility); + size_t alignment = static_cast(mRenderer->getVertexConversionBufferAlignment()); + + // The size is retrieved and used in descriptor set. The descriptor set wants aligned size, + // otherwise there are test failures. Note that underline VMA allocation always allocate aligned + // size anyway. + size_t sizeToAllocate = roundUp(size, alignment); + + return initBufferAllocation(bufferHelper, memoryTypeIndex, sizeToAllocate, alignment, + BufferUsageType::Static); +} + angle::Result ContextVk::updateActiveTextures(const gl::Context *context, gl::Command command) { const gl::ProgramExecutable *executable = mState.getProgramExecutable(); diff --git a/src/libANGLE/renderer/vulkan/ContextVk.h b/src/libANGLE/renderer/vulkan/ContextVk.h index 5e276a8a7..87fbe49a7 100644 --- a/src/libANGLE/renderer/vulkan/ContextVk.h +++ b/src/libANGLE/renderer/vulkan/ContextVk.h @@ -822,6 +822,23 @@ class ContextVk : public ContextImpl, public vk::Context, public MultisampleText VkMemoryPropertyFlags flags, vk::MemoryAllocationType allocationType); + // Helper functions to initialize a buffer for a specific usage + // Suballocate a host visible buffer with alignment good for copyBuffer. + angle::Result initBufferForBufferCopy(vk::BufferHelper *bufferHelper, + size_t size, + vk::MemoryCoherency coherency); + // Suballocate a host visible buffer with alignment good for copyImage. + angle::Result initBufferForImageCopy(vk::BufferHelper *bufferHelper, + size_t size, + vk::MemoryCoherency coherency, + angle::FormatID formatId, + VkDeviceSize *offset, + uint8_t **dataPtr); + // Suballocate a buffer with alignment good for shader storage or copyBuffer. + angle::Result initBufferForVertexConversion(vk::BufferHelper *bufferHelper, + size_t size, + vk::MemoryHostVisibility hostVisibility); + // In the event of collecting too much garbage, we should flush the garbage so it can be freed. void addToPendingImageGarbage(vk::ResourceUse use, VkDeviceSize size); diff --git a/src/libANGLE/renderer/vulkan/TextureVk.cpp b/src/libANGLE/renderer/vulkan/TextureVk.cpp index 98825926a..ebcf68f36 100644 --- a/src/libANGLE/renderer/vulkan/TextureVk.cpp +++ b/src/libANGLE/renderer/vulkan/TextureVk.cpp @@ -3048,8 +3048,8 @@ angle::Result TextureVk::convertBufferToRGBA(ContextVk *contextVk, size_t &conve vk::BufferHelper *conversionBufferHelper = conversion->data.get(); if (!conversionBufferHelper->valid()) { - ANGLE_TRY(conversionBufferHelper->allocateForVertexConversion( - contextVk, conversionBufferSize, vk::MemoryHostVisibility::NonVisible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion( + conversionBufferHelper, conversionBufferSize, vk::MemoryHostVisibility::NonVisible)); } if (conversion->dirty) diff --git a/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp b/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp index 9ecfbf2fe..256113539 100644 --- a/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp +++ b/src/libANGLE/renderer/vulkan/VertexArrayVk.cpp @@ -219,8 +219,9 @@ angle::Result VertexArrayVk::convertIndexBufferGPU(ContextVk *contextVk, size_t srcDataSize = static_cast(bufferVk->getSize()) - offsetIntoSrcData; // Allocate buffer for results - ANGLE_TRY(mTranslatedByteIndexData.allocateForVertexConversion( - contextVk, sizeof(GLushort) * srcDataSize, vk::MemoryHostVisibility::NonVisible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mTranslatedByteIndexData, + sizeof(GLushort) * srcDataSize, + vk::MemoryHostVisibility::NonVisible)); mCurrentElementArrayBuffer = &mTranslatedByteIndexData; vk::BufferHelper *dst = &mTranslatedByteIndexData; @@ -248,12 +249,14 @@ angle::Result VertexArrayVk::convertIndexBufferIndirectGPU(ContextVk *contextVk, vk::BufferHelper *srcIndexBuf = mCurrentElementArrayBuffer; // Allocate buffer for results - ANGLE_TRY(mTranslatedByteIndexData.allocateForVertexConversion( - contextVk, sizeof(GLushort) * srcDataSize, vk::MemoryHostVisibility::NonVisible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mTranslatedByteIndexData, + sizeof(GLushort) * srcDataSize, + vk::MemoryHostVisibility::NonVisible)); vk::BufferHelper *dstIndexBuf = &mTranslatedByteIndexData; - ANGLE_TRY(mTranslatedByteIndirectData.allocateForVertexConversion( - contextVk, sizeof(VkDrawIndexedIndirectCommand), vk::MemoryHostVisibility::NonVisible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mTranslatedByteIndirectData, + sizeof(VkDrawIndexedIndirectCommand), + vk::MemoryHostVisibility::NonVisible)); vk::BufferHelper *dstIndirectBuf = &mTranslatedByteIndirectData; // Save new element array buffer @@ -371,8 +374,8 @@ angle::Result VertexArrayVk::convertIndexBufferCPU(ContextVk *contextVk, } } - ANGLE_TRY(mStreamedIndexData.allocateForVertexConversion(contextVk, amount, - vk::MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mStreamedIndexData, amount, + vk::MemoryHostVisibility::Visible)); GLubyte *dst = mStreamedIndexData.getMappedMemory(); *bindingDirty = BufferBindingDirty::Yes; @@ -450,8 +453,8 @@ angle::Result VertexArrayVk::convertVertexBufferGPU(ContextVk *contextVk, // Allocate buffer for results vk::BufferHelper *dstBuffer = conversion->data.get(); - ANGLE_TRY(dstBuffer->allocateForVertexConversion(contextVk, numVertices * dstFormatSize, - vk::MemoryHostVisibility::NonVisible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(dstBuffer, numVertices * dstFormatSize, + vk::MemoryHostVisibility::NonVisible)); ASSERT(conversion->dirty); conversion->dirty = false; @@ -500,8 +503,8 @@ angle::Result VertexArrayVk::convertVertexBufferCPU(ContextVk *contextVk, vk::BufferHelper *dstBufferHelper = conversion->data.get(); // Allocate buffer for results - ANGLE_TRY(dstBufferHelper->allocateForVertexConversion(contextVk, numVertices * dstFormatSize, - vk::MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(dstBufferHelper, numVertices * dstFormatSize, + vk::MemoryHostVisibility::Visible)); ANGLE_TRY(StreamVertexData(contextVk, dstBufferHelper, srcBytes, numVertices * dstFormatSize, 0, numVertices, binding.getStride(), diff --git a/src/libANGLE/renderer/vulkan/vk_helpers.cpp b/src/libANGLE/renderer/vulkan/vk_helpers.cpp index 936be0085..0f59f9006 100644 --- a/src/libANGLE/renderer/vulkan/vk_helpers.cpp +++ b/src/libANGLE/renderer/vulkan/vk_helpers.cpp @@ -4457,8 +4457,8 @@ angle::Result LineLoopHelper::getIndexBufferForDrawArrays(ContextVk *contextVk, BufferHelper **bufferOut) { size_t allocateBytes = sizeof(uint32_t) * (static_cast(clampedVertexCount) + 1); - ANGLE_TRY(mDynamicIndexBuffer.allocateForVertexConversion(contextVk, allocateBytes, - MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mDynamicIndexBuffer, allocateBytes, + MemoryHostVisibility::Visible)); uint32_t *indices = reinterpret_cast(mDynamicIndexBuffer.getMappedMemory()); // Note: there could be an overflow in this addition. @@ -4507,8 +4507,8 @@ angle::Result LineLoopHelper::getIndexBufferForElementArrayBuffer(ContextVk *con size_t unitSize = contextVk->getVkIndexTypeSize(glIndexType); size_t allocateBytes = unitSize * (indexCount + 1) + 1; - ANGLE_TRY(mDynamicIndexBuffer.allocateForVertexConversion(contextVk, allocateBytes, - MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mDynamicIndexBuffer, allocateBytes, + MemoryHostVisibility::Visible)); BufferHelper *sourceBuffer = &elementArrayBufferVk->getBuffer(); VkDeviceSize sourceOffset = @@ -4552,8 +4552,8 @@ angle::Result LineLoopHelper::streamIndices(ContextVk *contextVk, } *indexCountOut = numOutIndices; - ANGLE_TRY(mDynamicIndexBuffer.allocateForVertexConversion(contextVk, unitSize * numOutIndices, - MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion( + &mDynamicIndexBuffer, unitSize * numOutIndices, MemoryHostVisibility::Visible)); uint8_t *indices = mDynamicIndexBuffer.getMappedMemory(); if (contextVk->getState().isPrimitiveRestartEnabled()) @@ -4615,10 +4615,11 @@ angle::Result LineLoopHelper::streamIndicesIndirect(ContextVk *contextVk, } // Allocate buffer for results - ANGLE_TRY(mDynamicIndexBuffer.allocateForVertexConversion(contextVk, allocateBytes, - MemoryHostVisibility::Visible)); - ANGLE_TRY(mDynamicIndirectBuffer.allocateForVertexConversion( - contextVk, sizeof(VkDrawIndexedIndirectCommand), MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mDynamicIndexBuffer, allocateBytes, + MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mDynamicIndirectBuffer, + sizeof(VkDrawIndexedIndirectCommand), + MemoryHostVisibility::Visible)); *indexBufferOut = &mDynamicIndexBuffer; *indirectBufferOut = &mDynamicIndirectBuffer; @@ -4649,10 +4650,11 @@ angle::Result LineLoopHelper::streamArrayIndirect(ContextVk *contextVk, auto unitSize = sizeof(uint32_t); size_t allocateBytes = static_cast((vertexCount + 1) * unitSize); - ANGLE_TRY(mDynamicIndexBuffer.allocateForVertexConversion(contextVk, allocateBytes, - MemoryHostVisibility::Visible)); - ANGLE_TRY(mDynamicIndirectBuffer.allocateForVertexConversion( - contextVk, sizeof(VkDrawIndexedIndirectCommand), MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mDynamicIndexBuffer, allocateBytes, + MemoryHostVisibility::Visible)); + ANGLE_TRY(contextVk->initBufferForVertexConversion(&mDynamicIndirectBuffer, + sizeof(VkDrawIndexedIndirectCommand), + MemoryHostVisibility::Visible)); *indexBufferOut = &mDynamicIndexBuffer; *indexIndirectBufferOut = &mDynamicIndirectBuffer; @@ -4886,87 +4888,7 @@ VkResult BufferHelper::initSuballocation(ContextVk *contextVk, return VK_SUCCESS; } -angle::Result BufferHelper::allocateForCopyBuffer(ContextVk *contextVk, - size_t size, - MemoryCoherency coherency) -{ - RendererVk *renderer = contextVk->getRenderer(); - uint32_t memoryTypeIndex = renderer->getStagingBufferMemoryTypeIndex(coherency); - size_t alignment = renderer->getStagingBufferAlignment(); - return contextVk->initBufferAllocation(this, memoryTypeIndex, size, alignment, - BufferUsageType::Dynamic); -} - -angle::Result BufferHelper::allocateForVertexConversion(ContextVk *contextVk, - size_t size, - MemoryHostVisibility hostVisibility) -{ - RendererVk *renderer = contextVk->getRenderer(); - - if (valid()) - { - // If size is big enough and it is idle, then just reuse the existing buffer. - if (size <= getSize() && - (hostVisibility == MemoryHostVisibility::Visible) == isHostVisible()) - { - if (renderer->hasResourceUseFinished(getResourceUse())) - { - initializeBarrierTracker(contextVk); - return angle::Result::Continue; - } - else if (hostVisibility == MemoryHostVisibility::NonVisible) - { - // For device local buffer, we can reuse the buffer even if it is still GPU busy. - // The memory barrier should take care of this. - return angle::Result::Continue; - } - } - - release(renderer); - } - - uint32_t memoryTypeIndex = renderer->getVertexConversionBufferMemoryTypeIndex(hostVisibility); - size_t alignment = static_cast(renderer->getVertexConversionBufferAlignment()); - - // The size is retrieved and used in descriptor set. The descriptor set wants aligned size, - // otherwise there are test failures. Note that underline VMA allocation always allocate aligned - // size anyway. - size_t sizeToAllocate = roundUp(size, alignment); - - return contextVk->initBufferAllocation(this, memoryTypeIndex, sizeToAllocate, alignment, - BufferUsageType::Static); -} - -angle::Result BufferHelper::allocateForCopyImage(ContextVk *contextVk, - size_t size, - MemoryCoherency coherency, - angle::FormatID formatId, - VkDeviceSize *offset, - uint8_t **dataPtr) -{ - RendererVk *renderer = contextVk->getRenderer(); - - // When a buffer is used in copyImage, the offset must be multiple of pixel bytes. This may - // result in non-power of two alignment. VMA's virtual allocator can not handle non-power of two - // alignment. We have to adjust offset manually. - uint32_t memoryTypeIndex = renderer->getStagingBufferMemoryTypeIndex(coherency); - size_t imageCopyAlignment = GetImageCopyBufferAlignment(formatId); - - // Add extra padding for potential offset alignment - size_t allocationSize = size + imageCopyAlignment; - allocationSize = roundUp(allocationSize, imageCopyAlignment); - size_t stagingAlignment = static_cast(renderer->getStagingBufferAlignment()); - - ANGLE_TRY(contextVk->initBufferAllocation(this, memoryTypeIndex, allocationSize, - stagingAlignment, BufferUsageType::Static)); - - *offset = roundUp(getOffset(), static_cast(imageCopyAlignment)); - *dataPtr = getMappedMemory() + (*offset) - getOffset(); - - return angle::Result::Continue; -} - -ANGLE_INLINE void BufferHelper::initializeBarrierTracker(Context *context) +void BufferHelper::initializeBarrierTracker(Context *context) { RendererVk *renderer = context->getRenderer(); mCurrentQueueFamilyIndex = renderer->getQueueFamilyIndex(); @@ -7506,9 +7428,9 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk, uint8_t *stagingPointer; VkDeviceSize stagingOffset; - ANGLE_TRY(currentBuffer->allocateForCopyImage(contextVk, allocationSize, - MemoryCoherency::NonCoherent, storageFormat.id, - &stagingOffset, &stagingPointer)); + ANGLE_TRY(contextVk->initBufferForImageCopy(currentBuffer, allocationSize, + MemoryCoherency::NonCoherent, storageFormat.id, + &stagingOffset, &stagingPointer)); loadFunctionInfo.loadFunction( contextVk->getImageLoadContext(), glExtents.width, glExtents.height, glExtents.depth, @@ -7783,9 +7705,9 @@ angle::Result ImageHelper::reformatStagedBufferUpdates(ContextVk *contextVk, uint8_t *dstData; VkDeviceSize dstBufferOffset; size_t dstBufferSize = dstDataDepthPitch * copy.imageExtent.depth; - ANGLE_TRY(dstBuffer->allocateForCopyImage(contextVk, dstBufferSize, - MemoryCoherency::NonCoherent, dstFormatID, - &dstBufferOffset, &dstData)); + ANGLE_TRY(contextVk->initBufferForImageCopy( + dstBuffer, dstBufferSize, MemoryCoherency::NonCoherent, dstFormatID, + &dstBufferOffset, &dstData)); rx::PixelReadFunction pixelReadFunction = srcFormat.pixelReadFunction; rx::PixelWriteFunction pixelWriteFunction = dstFormat.pixelWriteFunction; @@ -8125,9 +8047,9 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk BufferHelper *currentBuffer = &stagingBuffer->get(); VkDeviceSize stagingOffset; - ANGLE_TRY(currentBuffer->allocateForCopyImage(contextVk, allocationSize, - MemoryCoherency::NonCoherent, formatID, - &stagingOffset, dstData)); + ANGLE_TRY(contextVk->initBufferForImageCopy(currentBuffer, allocationSize, + MemoryCoherency::NonCoherent, formatID, + &stagingOffset, dstData)); gl::LevelIndex updateLevelGL(imageIndex.getLevelIndex()); @@ -8199,9 +8121,9 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer( // The destination is only one layer deep. size_t allocationSize = outputDepthPitch; - ANGLE_TRY(currentBuffer->allocateForCopyImage(contextVk, allocationSize, - MemoryCoherency::NonCoherent, storageFormat.id, - &stagingOffset, &stagingPointer)); + ANGLE_TRY(contextVk->initBufferForImageCopy(currentBuffer, allocationSize, + MemoryCoherency::NonCoherent, storageFormat.id, + &stagingOffset, &stagingPointer)); const angle::Format ©Format = GetFormatFromFormatType(formatInfo.internalFormat, formatInfo.type); @@ -8369,9 +8291,9 @@ angle::Result ImageHelper::stageResourceClearWithFormat(ContextVk *contextVk, uint8_t *stagingPointer; VkDeviceSize stagingOffset; - ANGLE_TRY(currentBuffer->allocateForCopyImage(contextVk, totalSize, - MemoryCoherency::NonCoherent, imageFormat.id, - &stagingOffset, &stagingPointer)); + ANGLE_TRY(contextVk->initBufferForImageCopy(currentBuffer, totalSize, + MemoryCoherency::NonCoherent, imageFormat.id, + &stagingOffset, &stagingPointer)); memset(stagingPointer, 0, totalSize); VkBufferImageCopy copyRegion = {}; @@ -9299,8 +9221,8 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk, // Allocate coherent staging buffer ASSERT(dstBuffer != nullptr && !dstBuffer->valid()); VkDeviceSize dstOffset; - ANGLE_TRY(dstBuffer->allocateForCopyImage(contextVk, bufferSize, MemoryCoherency::Coherent, - imageFormat.id, &dstOffset, outDataPtr)); + ANGLE_TRY(contextVk->initBufferForImageCopy(dstBuffer, bufferSize, MemoryCoherency::Coherent, + imageFormat.id, &dstOffset, outDataPtr)); VkBuffer bufferHandle = dstBuffer->getBuffer().getHandle(); LevelIndex sourceLevelVk = toVkLevel(sourceLevelGL); @@ -9901,9 +9823,9 @@ angle::Result ImageHelper::readPixelsImpl(ContextVk *contextVk, VkDeviceSize stagingOffset = 0; size_t allocationSize = readFormat->pixelBytes * area.width * area.height; - ANGLE_TRY(stagingBuffer->allocateForCopyImage(contextVk, allocationSize, - MemoryCoherency::Coherent, mActualFormatID, - &stagingOffset, &readPixelBuffer)); + ANGLE_TRY(contextVk->initBufferForImageCopy(stagingBuffer, allocationSize, + MemoryCoherency::Coherent, mActualFormatID, + &stagingOffset, &readPixelBuffer)); VkBuffer bufferHandle = stagingBuffer->getBuffer().getHandle(); VkBufferImageCopy region = {}; diff --git a/src/libANGLE/renderer/vulkan/vk_helpers.h b/src/libANGLE/renderer/vulkan/vk_helpers.h index 83d84c1ca..38bc96e36 100644 --- a/src/libANGLE/renderer/vulkan/vk_helpers.h +++ b/src/libANGLE/renderer/vulkan/vk_helpers.h @@ -759,23 +759,6 @@ class BufferHelper : public ReadWriteResource size_t alignment, BufferUsageType usageType); - // Helper functions to initialize a buffer for a specific usage - // Suballocate a buffer with alignment good for shader storage or copyBuffer . - angle::Result allocateForVertexConversion(ContextVk *contextVk, - size_t size, - MemoryHostVisibility hostVisibility); - // Suballocate a host visible buffer with alignment good for copyBuffer . - angle::Result allocateForCopyBuffer(ContextVk *contextVk, - size_t size, - MemoryCoherency coherency); - // Suballocate a host visible buffer with alignment good for copyImage . - angle::Result allocateForCopyImage(ContextVk *contextVk, - size_t size, - MemoryCoherency coherency, - angle::FormatID formatId, - VkDeviceSize *offset, - uint8_t **dataPtr); - void destroy(RendererVk *renderer); void release(RendererVk *renderer); void releaseBufferAndDescriptorSetCache(RendererVk *renderer); @@ -873,9 +856,9 @@ class BufferHelper : public ReadWriteResource // size. Thus when user size changes, we must clear and recreate this mBufferWithUserSize. void onBufferUserSizeChange(RendererVk *renderer); - private: void initializeBarrierTracker(Context *context); + private: // Only called by DynamicBuffer. friend class DynamicBuffer; void setSuballocationOffsetAndSize(VkDeviceSize offset, VkDeviceSize size)