• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2022 Collabora Ltd. and Red Hat Inc.
3  * SPDX-License-Identifier: MIT
4  */
5 #ifndef NVK_HEAP_H
6 #define NVK_HEAP_H 1
7 
8 #include "nvk_private.h"
9 
10 #include "nouveau_bo.h"
11 #include "util/simple_mtx.h"
12 #include "util/vma.h"
13 
14 struct nvk_device;
15 
16 #define NVK_HEAP_MIN_SIZE_LOG2 16
17 #define NVK_HEAP_MAX_SIZE_LOG2 32
18 #define NVK_HEAP_MIN_SIZE (1ull << NVK_HEAP_MIN_SIZE_LOG2)
19 #define NVK_HEAP_MAX_SIZE (1ull << NVK_HEAP_MAX_SIZE_LOG2)
20 #define NVK_HEAP_MAX_BO_COUNT (NVK_HEAP_MAX_SIZE_LOG2 - \
21                                NVK_HEAP_MIN_SIZE_LOG2 + 1)
22 
23 struct nvk_heap_bo {
24    struct nouveau_ws_bo *bo;
25    void *map;
26    uint64_t addr;
27 };
28 
29 struct nvk_heap {
30    enum nouveau_ws_bo_flags bo_flags;
31    enum nouveau_ws_bo_map_flags map_flags;
32    uint32_t overalloc;
33 
34    simple_mtx_t mutex;
35    struct util_vma_heap heap;
36 
37    /* Base address for contiguous heaps, 0 otherwise */
38    uint64_t base_addr;
39 
40    uint64_t total_size;
41 
42    uint32_t bo_count;
43    struct nvk_heap_bo bos[NVK_HEAP_MAX_BO_COUNT];
44 };
45 
46 VkResult nvk_heap_init(struct nvk_device *dev, struct nvk_heap *heap,
47                        enum nouveau_ws_bo_flags bo_flags,
48                        enum nouveau_ws_bo_map_flags map_flags,
49                        uint32_t overalloc, bool contiguous);
50 
51 void nvk_heap_finish(struct nvk_device *dev, struct nvk_heap *heap);
52 
53 VkResult nvk_heap_alloc(struct nvk_device *dev, struct nvk_heap *heap,
54                         uint64_t size, uint32_t alignment,
55                         uint64_t *addr_out, void **map_out);
56 
57 VkResult nvk_heap_upload(struct nvk_device *dev, struct nvk_heap *heap,
58                          const void *data, size_t size, uint32_t alignment,
59                          uint64_t *addr_out);
60 
61 void nvk_heap_free(struct nvk_device *dev, struct nvk_heap *heap,
62                    uint64_t addr, uint64_t size);
63 
64 static inline uint64_t
nvk_heap_contiguous_base_address(struct nvk_heap * heap)65 nvk_heap_contiguous_base_address(struct nvk_heap *heap)
66 {
67    assert(heap->base_addr != 0);
68    return heap->base_addr;
69 }
70 
71 #endif /* define NVK_HEAP_H */
72