ir3: Plumb through bindless support
[mesa.git] / src / freedreno / ir3 / ir3_image.c
1 /*
2 * Copyright (C) 2017-2018 Rob Clark <robclark@freedesktop.org>
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 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
26
27 #include "ir3_image.h"
28
29
30 /*
31 * SSBO/Image to/from IBO/tex hw mapping table:
32 */
33
34 void
35 ir3_ibo_mapping_init(struct ir3_ibo_mapping *mapping, unsigned num_textures)
36 {
37 memset(mapping, IBO_INVALID, sizeof(*mapping));
38 mapping->num_tex = 0;
39 mapping->tex_base = num_textures;
40 }
41
42 unsigned
43 ir3_ssbo_to_ibo(struct ir3_shader *shader, unsigned ssbo)
44 {
45 return ssbo;
46 }
47
48 unsigned
49 ir3_ssbo_to_tex(struct ir3_ibo_mapping *mapping, unsigned ssbo)
50 {
51 if (mapping->ssbo_to_tex[ssbo] == IBO_INVALID) {
52 unsigned tex = mapping->num_tex++;
53 mapping->ssbo_to_tex[ssbo] = tex;
54 mapping->tex_to_image[tex] = IBO_SSBO | ssbo;
55 }
56 return mapping->ssbo_to_tex[ssbo] + mapping->tex_base;
57 }
58
59 unsigned
60 ir3_image_to_ibo(struct ir3_shader *shader, unsigned image)
61 {
62 return shader->nir->info.num_ssbos + image;
63 }
64
65 unsigned
66 ir3_image_to_tex(struct ir3_ibo_mapping *mapping, unsigned image)
67 {
68 if (mapping->image_to_tex[image] == IBO_INVALID) {
69 unsigned tex = mapping->num_tex++;
70 mapping->image_to_tex[image] = tex;
71 mapping->tex_to_image[tex] = image;
72 }
73 return mapping->image_to_tex[image] + mapping->tex_base;
74 }
75
76 /* see tex_info() for equiv logic for texture instructions.. it would be
77 * nice if this could be better unified..
78 */
79 unsigned
80 ir3_get_image_coords(const nir_intrinsic_instr *instr, unsigned *flagsp)
81 {
82 unsigned coords = nir_image_intrinsic_coord_components(instr);
83 unsigned flags = 0;
84
85 if (coords == 3)
86 flags |= IR3_INSTR_3D;
87
88 if (nir_intrinsic_image_array(instr))
89 flags |= IR3_INSTR_A;
90
91 if (flagsp)
92 *flagsp = flags;
93
94 return coords;
95 }
96
97 type_t
98 ir3_get_type_for_image_intrinsic(const nir_intrinsic_instr *instr)
99 {
100 const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
101 int bit_size = info->has_dest ? nir_dest_bit_size(instr->dest) : 32;
102 enum pipe_format format = nir_intrinsic_format(instr);
103
104 if (util_format_is_pure_uint(format))
105 return bit_size == 16 ? TYPE_U16 : TYPE_U32;
106 else if (util_format_is_pure_sint(format))
107 return bit_size == 16 ? TYPE_S16 : TYPE_S32;
108 else
109 return bit_size == 16 ? TYPE_F16 : TYPE_F32;
110 }
111
112 /* Returns the number of components for the different image formats
113 * supported by the GLES 3.1 spec, plus those added by the
114 * GL_NV_image_formats extension.
115 */
116 unsigned
117 ir3_get_num_components_for_image_format(enum pipe_format format)
118 {
119 if (format == PIPE_FORMAT_NONE)
120 return 4;
121 else
122 return util_format_get_nr_components(format);
123 }