diff options
author | Kaiyi Li <kaiyili@google.com> | 2022-09-29 17:32:30 -0700 |
---|---|---|
committer | Kaiyi Li <kaiyili@google.com> | 2022-09-29 17:35:40 -0700 |
commit | 66a62760f6b5305df0e6db1a9d06bc5306c03242 (patch) | |
tree | fd686036d1f7e77d0154a863c6157aa88535b649 | |
parent | 1cae44fb2129705860dd0194fe615eef98a99478 (diff) | |
download | goldfish-opengl-66a62760f6b5305df0e6db1a9d06bc5306c03242.tar.gz |
vulkan: use thread local VkEncoder to destroy CoherentMemory
Bug: b/249548026
Change-Id: I81ff9838340b37689c8fcf5585503a1507c83a1c
-rw-r--r-- | system/vulkan_enc/HostVisibleMemoryVirtualization.cpp | 36 | ||||
-rw-r--r-- | system/vulkan_enc/HostVisibleMemoryVirtualization.h | 19 | ||||
-rw-r--r-- | system/vulkan_enc/ResourceTracker.cpp | 7 |
3 files changed, 24 insertions, 38 deletions
diff --git a/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp b/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp index 458c8136..939c306f 100644 --- a/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp +++ b/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp @@ -14,17 +14,16 @@ // limitations under the License. #include "HostVisibleMemoryVirtualization.h" -#include "android/base/AndroidSubAllocator.h" - -#include "Resources.h" -#include "VkEncoder.h" - -#include "../OpenglSystemCommon/EmulatorFeatureInfo.h" - #include <log/log.h> #include <set> +#include "../OpenglSystemCommon/EmulatorFeatureInfo.h" +#include "ResourceTracker.h" +#include "Resources.h" +#include "VkEncoder.h" +#include "android/base/AndroidSubAllocator.h" + using android::base::guest::SubAllocator; namespace goldfish_vk { @@ -33,26 +32,16 @@ bool isHostVisible(const VkPhysicalDeviceMemoryProperties* memoryProps, uint32_t return memoryProps->memoryTypes[index].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; } -CoherentMemory::CoherentMemory(VirtGpuBlobMappingPtr blobMapping, uint64_t size, VkEncoder *enc, - VkDevice device, VkDeviceMemory memory) - : mSize(size), - mBlobMapping(blobMapping), - mEnc(enc), - mDevice(device), - mMemory(memory) -{ +CoherentMemory::CoherentMemory(VirtGpuBlobMappingPtr blobMapping, uint64_t size, VkDevice device, + VkDeviceMemory memory) + : mSize(size), mBlobMapping(blobMapping), mDevice(device), mMemory(memory) { mAllocator = std::make_unique<android::base::guest::SubAllocator>(blobMapping->asRawPtr(), mSize, 4096); } CoherentMemory::CoherentMemory(GoldfishAddressSpaceBlockPtr block, uint64_t gpuAddr, uint64_t size, - VkEncoder *enc, VkDevice device, VkDeviceMemory memory) - : mSize(size), - mBlock(block), - mEnc(enc), - mDevice(device), - mMemory(memory) -{ + VkDevice device, VkDeviceMemory memory) + : mSize(size), mBlock(block), mDevice(device), mMemory(memory) { void* address = block->mmap(gpuAddr); mAllocator = std::make_unique<android::base::guest::SubAllocator>(address, mSize, kLargestPageSize); @@ -60,7 +49,8 @@ CoherentMemory::CoherentMemory(GoldfishAddressSpaceBlockPtr block, uint64_t gpuA CoherentMemory::~CoherentMemory() { - mEnc->vkFreeMemorySyncGOOGLE(mDevice, mMemory, nullptr, false); + ResourceTracker::getThreadLocalEncoder()->vkFreeMemorySyncGOOGLE(mDevice, mMemory, nullptr, + false); } VkDeviceMemory CoherentMemory::getDeviceMemory() const diff --git a/system/vulkan_enc/HostVisibleMemoryVirtualization.h b/system/vulkan_enc/HostVisibleMemoryVirtualization.h index 00809cc7..383ea81a 100644 --- a/system/vulkan_enc/HostVisibleMemoryVirtualization.h +++ b/system/vulkan_enc/HostVisibleMemoryVirtualization.h @@ -32,8 +32,6 @@ constexpr uint64_t kHostVisibleHeapSize = 512 * kMegaBtye; // 512 mb namespace goldfish_vk { -class VkEncoder; - bool isHostVisible(const VkPhysicalDeviceMemoryProperties *memoryProps, uint32_t index); using GoldfishAddressSpaceBlockPtr = std::shared_ptr<GoldfishAddressSpaceBlock>; @@ -41,16 +39,16 @@ using SubAllocatorPtr = std::unique_ptr<android::base::guest::SubAllocator>; class CoherentMemory { public: - CoherentMemory(VirtGpuBlobMappingPtr blobMapping, uint64_t size, VkEncoder *enc, - VkDevice device, VkDeviceMemory memory); - CoherentMemory(GoldfishAddressSpaceBlockPtr block, uint64_t gpuAddr, uint64_t size, - VkEncoder *enc, VkDevice device, VkDeviceMemory memory); - ~CoherentMemory(); + CoherentMemory(VirtGpuBlobMappingPtr blobMapping, uint64_t size, VkDevice device, + VkDeviceMemory memory); + CoherentMemory(GoldfishAddressSpaceBlockPtr block, uint64_t gpuAddr, uint64_t size, + VkDevice device, VkDeviceMemory memory); + ~CoherentMemory(); - VkDeviceMemory getDeviceMemory() const; + VkDeviceMemory getDeviceMemory() const; - bool subAllocate(uint64_t size, uint8_t **ptr, uint64_t& offset); - bool release(uint8_t *ptr); + bool subAllocate(uint64_t size, uint8_t** ptr, uint64_t& offset); + bool release(uint8_t* ptr); private: CoherentMemory(CoherentMemory const&); @@ -59,7 +57,6 @@ class CoherentMemory { uint64_t mSize; VirtGpuBlobMappingPtr mBlobMapping = nullptr; GoldfishAddressSpaceBlockPtr mBlock = nullptr; - VkEncoder *mEnc; VkDevice mDevice; VkDeviceMemory mMemory; SubAllocatorPtr mAllocator; diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp index 11ceb7da..657a31f7 100644 --- a/system/vulkan_enc/ResourceTracker.cpp +++ b/system/vulkan_enc/ResourceTracker.cpp @@ -2952,9 +2952,8 @@ public: block = info.goldfishBlock; info.goldfishBlock = nullptr; - coherentMemory = - std::make_shared<CoherentMemory>(block, gpuAddr, hostAllocationInfo.allocationSize, - enc, device, mem); + coherentMemory = std::make_shared<CoherentMemory>( + block, gpuAddr, hostAllocationInfo.allocationSize, device, mem); } else if (mFeatureInfo->hasVirtioGpuNext) { struct VirtGpuCreateBlob createBlob = { 0 }; uint64_t hvaSizeId[3]; @@ -2981,7 +2980,7 @@ public: } coherentMemory = - std::make_shared<CoherentMemory>(mapping, createBlob.size, enc, device, mem); + std::make_shared<CoherentMemory>(mapping, createBlob.size, device, mem); } coherentMemory->subAllocate(pAllocateInfo->allocationSize, &ptr, offset); |