• 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_DESCRIPTOR_TABLE_H
6 #define NVK_DESCRIPTOR_TABLE_H 1
7 
8 #include "nvk_private.h"
9 
10 #include "nouveau_bo.h"
11 #include "util/simple_mtx.h"
12 
13 struct nvk_device;
14 
15 struct nvk_descriptor_table {
16    simple_mtx_t mutex;
17 
18    uint32_t desc_size; /**< Size of a descriptor */
19    uint32_t alloc; /**< Number of descriptors allocated */
20    uint32_t max_alloc; /**< Maximum possible number of descriptors */
21    uint32_t next_desc; /**< Next unallocated descriptor */
22    uint32_t free_count; /**< Size of free_table */
23 
24    struct nouveau_ws_bo *bo;
25    void *map;
26 
27    /* Stack for free descriptor elements */
28    uint32_t *free_table;
29 };
30 
31 VkResult nvk_descriptor_table_init(struct nvk_device *dev,
32                                    struct nvk_descriptor_table *table,
33                                    uint32_t descriptor_size,
34                                    uint32_t min_descriptor_count,
35                                    uint32_t max_descriptor_count);
36 
37 void nvk_descriptor_table_finish(struct nvk_device *dev,
38                                  struct nvk_descriptor_table *table);
39 
40 VkResult nvk_descriptor_table_add(struct nvk_device *dev,
41                                   struct nvk_descriptor_table *table,
42                                   const void *desc_data, size_t desc_size,
43                                   uint32_t *index_out);
44 
45 void nvk_descriptor_table_remove(struct nvk_device *dev,
46                                  struct nvk_descriptor_table *table,
47                                  uint32_t index);
48 
49 static inline struct nouveau_ws_bo *
nvk_descriptor_table_get_bo_ref(struct nvk_descriptor_table * table,uint32_t * alloc_count_out)50 nvk_descriptor_table_get_bo_ref(struct nvk_descriptor_table *table,
51                                 uint32_t *alloc_count_out)
52 {
53    simple_mtx_lock(&table->mutex);
54    struct nouveau_ws_bo *bo = table->bo;
55    if (bo)
56       nouveau_ws_bo_ref(bo);
57    *alloc_count_out = table->alloc;
58    simple_mtx_unlock(&table->mutex);
59 
60    return bo;
61 }
62 
63 #endif
64