diff options
Diffstat (limited to 'src/libANGLE/renderer/vulkan/vk_helpers.cpp')
-rw-r--r-- | src/libANGLE/renderer/vulkan/vk_helpers.cpp | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/src/libANGLE/renderer/vulkan/vk_helpers.cpp b/src/libANGLE/renderer/vulkan/vk_helpers.cpp index 419800416e..b95d41386f 100644 --- a/src/libANGLE/renderer/vulkan/vk_helpers.cpp +++ b/src/libANGLE/renderer/vulkan/vk_helpers.cpp @@ -4789,10 +4789,15 @@ BufferHelper::BufferHelper() mCurrentReadAccess(0), mCurrentWriteStages(0), mCurrentReadStages(0), - mSerial() + mSerial(), + mClientBuffer(nullptr) {} -BufferHelper::~BufferHelper() = default; +BufferHelper::~BufferHelper() +{ + // We must have released external buffer properly + ASSERT(mClientBuffer == nullptr); +} BufferHelper::BufferHelper(BufferHelper &&other) { @@ -4812,6 +4817,7 @@ BufferHelper &BufferHelper::operator=(BufferHelper &&other) mCurrentWriteStages = other.mCurrentWriteStages; mCurrentReadStages = other.mCurrentReadStages; mSerial = other.mSerial; + mClientBuffer = std::move(other.mClientBuffer); return *this; } @@ -4916,6 +4922,7 @@ angle::Result BufferHelper::initExternal(ContextVk *contextVk, ANGLE_TRY(InitAndroidExternalMemory(contextVk, clientBuffer, memoryProperties, &buffer.get(), &memoryPropertyFlagsOut, &memoryTypeIndex, &deviceMemory.get(), &allocatedSize)); + mClientBuffer = clientBuffer; mSuballocation.initWithEntireBuffer( contextVk, buffer.get(), MemoryAllocationType::BufferExternal, memoryTypeIndex, @@ -4925,7 +4932,6 @@ angle::Result BufferHelper::initExternal(ContextVk *contextVk, uint8_t *ptrOut; ANGLE_TRY(map(contextVk, &ptrOut)); } - return angle::Result::Continue; } @@ -5090,6 +5096,11 @@ void BufferHelper::destroy(RendererVk *renderer) unmap(renderer); mBufferWithUserSize.destroy(renderer->getDevice()); mSuballocation.destroy(renderer); + if (mClientBuffer != nullptr) + { + ReleaseAndroidExternalMemory(renderer, mClientBuffer); + mClientBuffer = nullptr; + } } void BufferHelper::release(RendererVk *renderer) @@ -5111,6 +5122,12 @@ void BufferHelper::release(RendererVk *renderer) mUse.reset(); mWriteUse.reset(); ASSERT(!mBufferWithUserSize.valid()); + + if (mClientBuffer != nullptr) + { + ReleaseAndroidExternalMemory(renderer, mClientBuffer); + mClientBuffer = nullptr; + } } void BufferHelper::releaseBufferAndDescriptorSetCache(RendererVk *renderer) @@ -7526,8 +7543,8 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk, uint8_t *stagingPointer; VkDeviceSize stagingOffset; ANGLE_TRY(contextVk->initBufferForImageCopy(currentBuffer, allocationSize, - MemoryCoherency::NonCoherent, storageFormat.id, - &stagingOffset, &stagingPointer)); + MemoryCoherency::CachedNonCoherent, + storageFormat.id, &stagingOffset, &stagingPointer)); loadFunctionInfo.loadFunction( contextVk->getImageLoadContext(), glExtents.width, glExtents.height, glExtents.depth, @@ -7847,7 +7864,7 @@ angle::Result ImageHelper::reformatStagedBufferUpdates(ContextVk *contextVk, VkDeviceSize dstBufferOffset; size_t dstBufferSize = dstDataDepthPitch * copy.imageExtent.depth; ANGLE_TRY(contextVk->initBufferForImageCopy( - dstBuffer, dstBufferSize, MemoryCoherency::NonCoherent, dstFormatID, + dstBuffer, dstBufferSize, MemoryCoherency::CachedNonCoherent, dstFormatID, &dstBufferOffset, &dstData)); rx::PixelReadFunction pixelReadFunction = srcFormat.pixelReadFunction; @@ -8189,7 +8206,7 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk VkDeviceSize stagingOffset; ANGLE_TRY(contextVk->initBufferForImageCopy(currentBuffer, allocationSize, - MemoryCoherency::NonCoherent, formatID, + MemoryCoherency::CachedNonCoherent, formatID, &stagingOffset, dstData)); gl::LevelIndex updateLevelGL(imageIndex.getLevelIndex()); @@ -8263,8 +8280,8 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer( // The destination is only one layer deep. size_t allocationSize = outputDepthPitch; ANGLE_TRY(contextVk->initBufferForImageCopy(currentBuffer, allocationSize, - MemoryCoherency::NonCoherent, storageFormat.id, - &stagingOffset, &stagingPointer)); + MemoryCoherency::CachedNonCoherent, + storageFormat.id, &stagingOffset, &stagingPointer)); const angle::Format ©Format = GetFormatFromFormatType(formatInfo.internalFormat, formatInfo.type); @@ -8432,9 +8449,9 @@ angle::Result ImageHelper::stageResourceClearWithFormat(ContextVk *contextVk, uint8_t *stagingPointer; VkDeviceSize stagingOffset; - ANGLE_TRY(contextVk->initBufferForImageCopy(currentBuffer, totalSize, - MemoryCoherency::NonCoherent, imageFormat.id, - &stagingOffset, &stagingPointer)); + ANGLE_TRY(contextVk->initBufferForImageCopy( + currentBuffer, totalSize, MemoryCoherency::CachedNonCoherent, imageFormat.id, + &stagingOffset, &stagingPointer)); memset(stagingPointer, 0, totalSize); VkBufferImageCopy copyRegion = {}; @@ -9381,8 +9398,9 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk, // Allocate coherent staging buffer ASSERT(dstBuffer != nullptr && !dstBuffer->valid()); VkDeviceSize dstOffset; - ANGLE_TRY(contextVk->initBufferForImageCopy(dstBuffer, bufferSize, MemoryCoherency::Coherent, - imageFormat.id, &dstOffset, outDataPtr)); + ANGLE_TRY(contextVk->initBufferForImageCopy(dstBuffer, bufferSize, + MemoryCoherency::CachedCoherent, imageFormat.id, + &dstOffset, outDataPtr)); VkBuffer bufferHandle = dstBuffer->getBuffer().getHandle(); LevelIndex sourceLevelVk = toVkLevel(sourceLevelGL); @@ -10050,7 +10068,7 @@ angle::Result ImageHelper::readPixelsImpl(ContextVk *contextVk, size_t allocationSize = readFormat->pixelBytes * area.width * area.height; ANGLE_TRY(contextVk->initBufferForImageCopy(stagingBuffer, allocationSize, - MemoryCoherency::Coherent, readFormat->id, + MemoryCoherency::CachedCoherent, readFormat->id, &stagingOffset, &readPixelBuffer)); VkBuffer bufferHandle = stagingBuffer->getBuffer().getHandle(); |