| 1 | #pragma once |
| 2 | |
| 3 | #include <nvn/nvn.h> |
| 4 | #include <container/seadPtrArray.h> |
| 5 | #include <heap/seadDisposer.h> |
| 6 | #include <hostio/seadHostIONode.h> |
| 7 | #include <math/seadMathCalcCommon.h> |
| 8 | #include <prim/seadBitFlag.h> |
| 9 | #include <prim/seadTypedBitFlag.h> |
| 10 | #include <thread/seadCriticalSection.h> |
| 11 | #include "common/aglGPUCommon.hpp" |
| 12 | |
| 13 | namespace agl::detail { |
| 14 | |
| 15 | using MemoryPoolDriverBitFlag = sead::BitFlag32; |
| 16 | |
| 17 | constexpr s32 VALID_POOL_TYPE_VALUE = -1; |
| 18 | constexpr s32 cGPUAccessMask = 0xF0000000; |
| 19 | constexpr u64 cGPUPhysicalMemorySizeAlignment = 0x1000; |
| 20 | |
| 21 | class MemoryPoolType : MemoryPoolDriverBitFlag { |
| 22 | public: |
| 23 | MemoryPoolType() : MemoryPoolDriverBitFlag() {} |
| 24 | MemoryPoolType(s32 p_value) : MemoryPoolDriverBitFlag(p_value) {} |
| 25 | |
| 26 | MemoryPoolType convert(MemoryAttribute attribute); |
| 27 | |
| 28 | bool IsValid() const { return (*this & cValidPoolType) == cValidPoolType; } |
| 29 | |
| 30 | void MarkValid() { *this = *this | cValidPoolType; } |
| 31 | |
| 32 | private: |
| 33 | static const MemoryPoolType cInvalidPoolType; |
| 34 | static const MemoryPoolType cValidPoolType; |
| 35 | }; |
| 36 | |
| 37 | class MemoryPool { |
| 38 | public: |
| 39 | MemoryPool(); |
| 40 | |
| 41 | void initialize(void* storage_1, u64 storage_2, const MemoryPoolType& flags); |
| 42 | void initialize(void* map_virtual_1, u64 storage, const MemoryPoolType& flags, |
| 43 | const MemoryPool& map_virtual_2, s32 map_virtual_3); |
| 44 | |
| 45 | void finalize(); |
| 46 | |
| 47 | private: |
| 48 | NVNmemoryPool mDriverPool; |
| 49 | MemoryPoolType mMemoryType; |
| 50 | uint32_t idk; |
| 51 | }; |
| 52 | static_assert(sizeof(MemoryPool) == 0x108); |
| 53 | |
| 54 | class GPUMemBlockMgrHeapEx : public sead::hostio::Node, public sead::IDisposer { |
| 55 | public: |
| 56 | GPUMemBlockMgrHeapEx(sead::Heap* p_heap); |
| 57 | ~GPUMemBlockMgrHeapEx() override; |
| 58 | |
| 59 | void finalize(); |
| 60 | |
| 61 | private: |
| 62 | s32 mAllowSharing; |
| 63 | void* m08; |
| 64 | void* m10; |
| 65 | sead::CriticalSection mCS; |
| 66 | }; |
| 67 | static_assert(sizeof(GPUMemBlockMgrHeapEx) == 0x80); |
| 68 | |
| 69 | enum class GPUMemBlockMgrFlags : u8 { |
| 70 | MemoryPoolRelated = 1 << 0, |
| 71 | EnablePoolSharing = 1 << 1, |
| 72 | Debug = 1 << 2 |
| 73 | }; |
| 74 | |
| 75 | class GPUMemBlockMgr : public sead::hostio::Node { |
| 76 | SEAD_SINGLETON_DISPOSER(GPUMemBlockMgr) |
| 77 | public: |
| 78 | GPUMemBlockMgr(); |
| 79 | virtual ~GPUMemBlockMgr(); |
| 80 | |
| 81 | void initialize(sead::Heap* heap1, sead::Heap* heap2); |
| 82 | void enableSharedMemoryPool(bool enabled); |
| 83 | static u64 calcGPUMemorySize(u64 userSize); |
| 84 | static s32 calcGPUMemoryAlignment(s32 userAlignment); |
| 85 | |
| 86 | #ifdef SEAD_DEBUG |
| 87 | void listenPropertyEvent(const sead::hostio::PropertyEvent* event) override; |
| 88 | void genMessage(sead::hostio::Context* context) override; |
| 89 | #endif |
| 90 | |
| 91 | private: |
| 92 | GPUMemBlockMgrHeapEx* findGPUMemBlockMgrHeapEx_(sead::Heap* p_heap, int* p_outIndex); |
| 93 | |
| 94 | sead::CriticalSection mCS; |
| 95 | sead::PtrArray<GPUMemBlockMgrHeapEx> mMngrHeaps; |
| 96 | size_t mMinBlockSize; |
| 97 | sead::TypedBitFlag<GPUMemBlockMgrFlags> mFlags; |
| 98 | }; |
| 99 | static_assert(sizeof(GPUMemBlockMgr) == 0x88); |
| 100 | |
| 101 | } // namespace agl::detail |
| 102 | |