stage/columns/device_heap.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstdint> | ||
| 5 | #include <map> | ||
| 6 | #include <string> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "chrono_batch_render/device/buffer.h" | ||
| 10 | #include "chrono_batch_render/device/device.h" | ||
| 11 | #include "chrono_batch_render/device/ref.h" | ||
| 12 | |||
| 13 | namespace chrono::batch_render { | ||
| 14 | |||
| 15 | struct HeapBlock { | ||
| 16 | device::Buffer* buffer = nullptr; | ||
| 17 | uint64_t offset = 0; | ||
| 18 | uint64_t bytes = 0; | ||
| 19 | |||
| 20 | 346 | explicit operator bool() const { | |
| 21 | 346 | return buffer != nullptr; | |
| 22 | } | ||
| 23 | |||
| 24 | 43961 | uint64_t Address() const { | |
| 25 | 40917 | return buffer->Address() + offset; | |
| 26 | } | ||
| 27 | |||
| 28 | 127568 | device::BufferRange Range() const { | |
| 29 | 127568 | return buffer->Slice(offset, bytes); | |
| 30 | } | ||
| 31 | }; | ||
| 32 | |||
| 33 | class DeviceHeap { | ||
| 34 | public: | ||
| 35 | DeviceHeap(device::Device& device, std::string label); | ||
| 36 | |||
| 37 | 15313089 | device::Device& GetDevice() const { | |
| 38 | 15313089 | return m_device; | |
| 39 | } | ||
| 40 | |||
| 41 | uint64_t Bytes() const; | ||
| 42 | HeapBlock Allocate(uint64_t bytes, uint64_t alignment); | ||
| 43 | void Free(const HeapBlock& block); | ||
| 44 | |||
| 45 | private: | ||
| 46 | 2098 | struct Chunk { | |
| 47 | Ref<device::Buffer> buffer; | ||
| 48 | uint64_t used = 0; | ||
| 49 | }; | ||
| 50 | |||
| 51 | device::Device& m_device; | ||
| 52 | std::string m_label; | ||
| 53 | std::vector<Chunk> m_chunks; | ||
| 54 | std::map<uint64_t, std::vector<HeapBlock>> m_free; | ||
| 55 | uint64_t m_nextChunk; | ||
| 56 | }; | ||
| 57 | |||
| 58 | } | ||
| 59 |