About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/kosmickrisp/vulkan/kk_query_table.h
blob: a7d0be2cb5a0db5e6ef16c443b1a402770507455 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright © 2022 Collabora Ltd. and Red Hat Inc.
 * Copyright 2025 LunarG, Inc.
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: MIT
 */

#ifndef KK_QUERY_TABLE_H
#define KK_QUERY_TABLE_H 1

#include "kk_private.h"

#include "kk_bo.h"

#include "util/bitset.h"
#include "util/simple_mtx.h"

struct kk_device;

struct kk_query_table {
   simple_mtx_t mutex;

   uint32_t max_alloc;  /**< Maximum possible number of queries */
   uint32_t next_query; /**< Next unallocated query */
   uint32_t free_count; /**< Size of free_table */

   struct kk_bo *bo; /**< Memoery where queries are stored */

   /* Bitset of all queries currently in use.  This is the single source
    * of truth for what is and isn't free.  The free_table and next_query are
    * simply hints to make finding a free descrptor fast.  Every free
    * query will either be above next_query or in free_table but not
    * everything which satisfies those two criteria is actually free.
    */
   BITSET_WORD *in_use;

   /* Stack for free query elements */
   uint32_t *free_table;
};

VkResult kk_query_table_init(struct kk_device *dev,
                             struct kk_query_table *table,
                             uint32_t query_count);

void kk_query_table_finish(struct kk_device *dev, struct kk_query_table *table);

VkResult kk_query_table_add(struct kk_device *dev, struct kk_query_table *table,
                            uint64_t value, uint32_t *index_out);

VkResult kk_query_table_insert(struct kk_device *dev,
                               struct kk_query_table *table, uint32_t index,
                               uint64_t value);

void kk_query_table_remove(struct kk_device *dev, struct kk_query_table *table,
                           uint32_t index);

#endif /* KK_QUERY_TABLE_H */