1 /*
2 * Copyright © 2022 Google, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #ifndef IR3_DESCRIPTOR_H_
25 #define IR3_DESCRIPTOR_H_
26
27 #include "ir3/ir3_shader.h"
28
29 /*
30 * When using bindless descriptor sets for image/SSBO (and fb-read) state,
31 * since the descriptor sets are large, layout the descriptor set with the
32 * first IR3_BINDLESS_SSBO_COUNT slots for SSBOs followed by
33 * IR3_BINDLESS_IMAGE_COUNT slots for images. (For fragment shaders, the
34 * last image slot is reserved for fb-read tex descriptor.)
35 *
36 * Note that these limits are more or less arbitrary. But the enable_mask
37 * in fd_shaderbuf_stateobj / fd_shaderimg_stateobj would need to be more
38 * than uint32_t to support more than 32.
39 */
40
41 #define IR3_BINDLESS_SSBO_OFFSET 0
42 #define IR3_BINDLESS_SSBO_COUNT 32
43 #define IR3_BINDLESS_IMAGE_OFFSET IR3_BINDLESS_SSBO_COUNT
44 #define IR3_BINDLESS_IMAGE_COUNT 32
45 #define IR3_BINDLESS_DESC_COUNT (IR3_BINDLESS_IMAGE_OFFSET + IR3_BINDLESS_IMAGE_COUNT)
46
47 /**
48 * When using bindless descriptor sets for IBO/etc, each shader stage gets
49 * it's own descriptor set, avoiding the need to merge image/ssbo state
50 * across shader stages.
51 */
52 static inline unsigned
ir3_shader_descriptor_set(enum pipe_shader_type shader)53 ir3_shader_descriptor_set(enum pipe_shader_type shader)
54 {
55 switch (shader) {
56 case PIPE_SHADER_VERTEX: return 0;
57 case PIPE_SHADER_TESS_CTRL: return 1;
58 case PIPE_SHADER_TESS_EVAL: return 2;
59 case PIPE_SHADER_GEOMETRY: return 3;
60 case PIPE_SHADER_FRAGMENT: return 4;
61 case PIPE_SHADER_COMPUTE: return 0;
62 default:
63 unreachable("bad shader stage");
64 return ~0;
65 }
66 }
67
68 bool ir3_nir_lower_io_to_bindless(nir_shader *shader);
69
70 #endif /* IR3_DESCRIPTOR_H_ */
71