• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    /* A 32-bit integer which acts as a map from sample index to x/y position
34     * within a pixel.  Each nibble is a sample with x in the low 2 bits and y
35     * in the high 2 bits.
36     */
37    unsigned sample_map:32;
38 };
39 PRAGMA_DIAGNOSTIC_POP
40 static_assert(sizeof(struct nvk_storage_image_descriptor) == 8,
41               "nvk_storage_image_descriptor has no holes");
42 
43 PRAGMA_DIAGNOSTIC_PUSH
44 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
45 struct nvk_buffer_view_descriptor {
46    unsigned image_index:20;
47    unsigned pad:12;
48 };
49 PRAGMA_DIAGNOSTIC_POP
50 static_assert(sizeof(struct nvk_buffer_view_descriptor) == 4,
51               "nvk_buffer_view_descriptor has no holes");
52 
53 PRAGMA_DIAGNOSTIC_PUSH
54 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
55 /** See also nvk_edb_bview_cache */
56 struct nvk_edb_buffer_view_descriptor {
57    /** Index of the HW descriptor in the texture/image table */
58    uint32_t index;
59    /** Offset into the HW descriptor in surface elements */
60    uint32_t offset_el;
61    /** Size of the virtual descriptor in surface elements */
62    uint32_t size_el;
63    /** Value returned in the alpha channel for OOB buffer access */
64    uint32_t oob_alpha;
65 };
66 PRAGMA_DIAGNOSTIC_POP
67 static_assert(sizeof(struct nvk_edb_buffer_view_descriptor) == 16,
68               "nvk_edb_buffer_view_descriptor has no holes");
69 
70 PRAGMA_DIAGNOSTIC_PUSH
71 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
72 struct nvk_bindless_cbuf {
73    uint64_t base_addr_shift_4:45;
74    uint64_t size_shift_4:19;
75 };
76 PRAGMA_DIAGNOSTIC_POP
77 static_assert(sizeof(struct nvk_bindless_cbuf) == 8,
78               "nvk_bindless_cbuf has no holes");
79 
80 /* This has to match nir_address_format_64bit_bounded_global */
81 PRAGMA_DIAGNOSTIC_PUSH
82 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
83 struct nvk_buffer_address {
84    uint64_t base_addr;
85    uint32_t size;
86    uint32_t zero; /* Must be zero! */
87 };
88 PRAGMA_DIAGNOSTIC_POP
89 static_assert(sizeof(struct nvk_buffer_address) == 16,
90               "nvk_buffer_address has no holes");
91 
92 #define NVK_BUFFER_ADDRESS_NULL ((struct nvk_buffer_address) { .size = 0 })
93 
94 union nvk_buffer_descriptor {
95    struct nvk_buffer_address addr;
96    struct nvk_bindless_cbuf cbuf;
97 };
98 
99 static inline bool
nvk_use_bindless_cbuf(const struct nv_device_info * info)100 nvk_use_bindless_cbuf(const struct nv_device_info *info)
101 {
102    return info->cls_eng3d >= 0xC597 /* TURING_A */;
103 }
104 
105 static inline struct nvk_buffer_address
nvk_ubo_descriptor_addr(const struct nvk_physical_device * pdev,union nvk_buffer_descriptor desc)106 nvk_ubo_descriptor_addr(const struct nvk_physical_device *pdev,
107                         union nvk_buffer_descriptor desc)
108 {
109    if (nvk_use_bindless_cbuf(&pdev->info)) {
110       return (struct nvk_buffer_address) {
111          .base_addr = desc.cbuf.base_addr_shift_4 << 4,
112          .size = desc.cbuf.size_shift_4 << 4,
113       };
114    } else {
115       return desc.addr;
116    }
117 }
118 
119 #endif /* NVK_DESCRIPTOR_TYPES */
120