xref: /aosp_15_r20/external/mesa3d/src/nouveau/vulkan/nvk_descriptor_types.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2024 Collabora Ltd. and Red Hat Inc.
3  * SPDX-License-Identifier: MIT
4  */
5 #ifndef NVK_DESCRIPTOR_TYPES
6 #define NVK_DESCRIPTOR_TYPES 1
7 
8 #include "nvk_private.h"
9 
10 #include "nvk_physical_device.h"
11 
12 #define NVK_IMAGE_DESCRIPTOR_IMAGE_INDEX_MASK   0x000fffff
13 #define NVK_IMAGE_DESCRIPTOR_SAMPLER_INDEX_MASK 0xfff00000
14 
15 PRAGMA_DIAGNOSTIC_PUSH
16 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
17 struct nvk_sampled_image_descriptor {
18    unsigned image_index:20;
19    unsigned sampler_index:12;
20 };
21 PRAGMA_DIAGNOSTIC_POP
22 static_assert(sizeof(struct nvk_sampled_image_descriptor) == 4,
23               "nvk_sampled_image_descriptor has no holes");
24 
25 PRAGMA_DIAGNOSTIC_PUSH
26 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
27 struct nvk_storage_image_descriptor {
28    unsigned image_index:20;
29    unsigned sw_log2:2;
30    unsigned sh_log2:2;
31    unsigned pad:8;
32 };
33 PRAGMA_DIAGNOSTIC_POP
34 static_assert(sizeof(struct nvk_storage_image_descriptor) == 4,
35               "nvk_storage_image_descriptor has no holes");
36 
37 PRAGMA_DIAGNOSTIC_PUSH
38 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
39 struct nvk_buffer_view_descriptor {
40    unsigned image_index:20;
41    unsigned pad:12;
42 };
43 PRAGMA_DIAGNOSTIC_POP
44 static_assert(sizeof(struct nvk_buffer_view_descriptor) == 4,
45               "nvk_buffer_view_descriptor has no holes");
46 
47 PRAGMA_DIAGNOSTIC_PUSH
48 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
49 /** See also nvk_edb_bview_cache */
50 struct nvk_edb_buffer_view_descriptor {
51    /** Index of the HW descriptor in the texture/image table */
52    uint32_t index;
53    /** Offset into the HW descriptor in surface elements */
54    uint32_t offset_el;
55    /** Size of the virtual descriptor in surface elements */
56    uint32_t size_el;
57    /** Value returned in the alpha channel for OOB buffer access */
58    uint32_t oob_alpha;
59 };
60 PRAGMA_DIAGNOSTIC_POP
61 static_assert(sizeof(struct nvk_edb_buffer_view_descriptor) == 16,
62               "nvk_edb_buffer_view_descriptor has no holes");
63 
64 PRAGMA_DIAGNOSTIC_PUSH
65 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
66 struct nvk_bindless_cbuf {
67    uint64_t base_addr_shift_4:45;
68    uint64_t size_shift_4:19;
69 };
70 PRAGMA_DIAGNOSTIC_POP
71 static_assert(sizeof(struct nvk_bindless_cbuf) == 8,
72               "nvk_bindless_cbuf has no holes");
73 
74 /* This has to match nir_address_format_64bit_bounded_global */
75 PRAGMA_DIAGNOSTIC_PUSH
76 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
77 struct nvk_buffer_address {
78    uint64_t base_addr;
79    uint32_t size;
80    uint32_t zero; /* Must be zero! */
81 };
82 PRAGMA_DIAGNOSTIC_POP
83 static_assert(sizeof(struct nvk_buffer_address) == 16,
84               "nvk_buffer_address has no holes");
85 
86 #define NVK_BUFFER_ADDRESS_NULL ((struct nvk_buffer_address) { .size = 0 })
87 
88 union nvk_buffer_descriptor {
89    struct nvk_buffer_address addr;
90    struct nvk_bindless_cbuf cbuf;
91 };
92 
93 static inline bool
nvk_use_bindless_cbuf(const struct nv_device_info * info)94 nvk_use_bindless_cbuf(const struct nv_device_info *info)
95 {
96    return info->cls_eng3d >= 0xC597 /* TURING_A */;
97 }
98 
99 static inline struct nvk_buffer_address
nvk_ubo_descriptor_addr(const struct nvk_physical_device * pdev,union nvk_buffer_descriptor desc)100 nvk_ubo_descriptor_addr(const struct nvk_physical_device *pdev,
101                         union nvk_buffer_descriptor desc)
102 {
103    if (nvk_use_bindless_cbuf(&pdev->info)) {
104       return (struct nvk_buffer_address) {
105          .base_addr = desc.cbuf.base_addr_shift_4 << 4,
106          .size = desc.cbuf.size_shift_4 << 4,
107       };
108    } else {
109       return desc.addr;
110    }
111 }
112 
113 #endif /* NVK_DESCRIPTOR_TYPES */
114