| 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 |
constexpr uint64_t kDefaultHostMemBlockSize = 16 * kMegaByte; // 16 mb |
| 22 |
|
| 23 |
namespace gfxstream { |
| 24 |
namespace vk { |
| 25 |
|
| 26 |
using GoldfishAddressSpaceBlockPtr = std::shared_ptr<GoldfishAddressSpaceBlock>; |
| 27 |
|
| 28 |
class CoherentMemory { |
| 29 |
public: |
| 30 |
CoherentMemory(VirtGpuResourceMappingPtr blobMapping, uint64_t size, VkDevice device, |
| 31 |
VkDeviceMemory memory); |
| 32 |
|
| 33 |
#if DETECT_OS_ANDROID |
| 34 |
CoherentMemory(GoldfishAddressSpaceBlockPtr block, uint64_t gpuAddr, uint64_t size, |
| 35 |
VkDevice device, VkDeviceMemory memory); |
| 36 |
#endif // DETECT_OS_ANDROID |
| 37 |
|
| 38 |
~CoherentMemory(); |
| 39 |
|
| 40 |
VkDeviceMemory getDeviceMemory() const; |
| 41 |
|
| 42 |
bool subAllocate(uint64_t size, uint8_t** ptr, uint64_t& offset); |
| 43 |
bool release(uint64_t offset); |
| 44 |
|
| 45 |
private: |
| 46 |
CoherentMemory(CoherentMemory const&); |
| 47 |
void operator=(CoherentMemory const&); |
| 48 |
|
| 49 |
uint64_t mSize; |
| 50 |
VirtGpuResourceMappingPtr mBlobMapping; |
| 51 |
GoldfishAddressSpaceBlockPtr mBlock; |
| 52 |
VkDevice mDevice; |
| 53 |
VkDeviceMemory mMemory; |
| 54 |
|
| 55 |
uint8_t* mBaseAddr = nullptr; |
| 56 |
struct mem_block* mHeap = nullptr; |
| 57 |
}; |
| 58 |
|
| 59 |
using CoherentMemoryPtr = std::shared_ptr<CoherentMemory>; |
| 60 |
|
| 61 |
} // namespace vk |
| 62 |
} // namespace gfxstream |