1 /* 2 * Copyright 2018 Google 3 * SPDX-License-Identifier: MIT 4 */ 5 #pragma once 6 7 #include <vulkan/vulkan.h> 8 9 #include "VirtGpu.h" 10 #include "goldfish_address_space.h" 11 #include "util/u_mm.h" 12 #include "util/detect_os.h" 13 14 constexpr uint64_t kMegaByte = 1048576; 15 16 // This needs to be a power of 2 that is at least the min alignment needed 17 // in HostVisibleMemoryVirtualization.cpp. 18 // Some Windows drivers require a 64KB alignment for suballocated memory (b:152769369) for YUV 19 // images. 20 constexpr uint64_t kLargestPageSize = 65536; 21 22 constexpr uint64_t kDefaultHostMemBlockSize = 16 * kMegaByte; // 16 mb 23 constexpr uint64_t kHostVisibleHeapSize = 512 * kMegaByte; // 512 mb 24 25 namespace gfxstream { 26 namespace vk { 27 28 using GoldfishAddressSpaceBlockPtr = std::shared_ptr<GoldfishAddressSpaceBlock>; 29 30 class CoherentMemory { 31 public: 32 CoherentMemory(VirtGpuResourceMappingPtr blobMapping, uint64_t size, VkDevice device, 33 VkDeviceMemory memory); 34 35 #if DETECT_OS_ANDROID 36 CoherentMemory(GoldfishAddressSpaceBlockPtr block, uint64_t gpuAddr, uint64_t size, 37 VkDevice device, VkDeviceMemory memory); 38 #endif // DETECT_OS_ANDROID 39 40 ~CoherentMemory(); 41 42 VkDeviceMemory getDeviceMemory() const; 43 44 bool subAllocate(uint64_t size, uint8_t** ptr, uint64_t& offset); 45 bool release(uint8_t* ptr); 46 47 private: 48 CoherentMemory(CoherentMemory const&); 49 void operator=(CoherentMemory const&); 50 51 uint64_t mSize; 52 VirtGpuResourceMappingPtr mBlobMapping; 53 GoldfishAddressSpaceBlockPtr mBlock; 54 VkDevice mDevice; 55 VkDeviceMemory mMemory; 56 57 uint8_t* mBaseAddr = nullptr; 58 struct mem_block* mHeap = nullptr; 59 }; 60 61 using CoherentMemoryPtr = std::shared_ptr<CoherentMemory>; 62 63 } // namespace vk 64 } // namespace gfxstream 65