2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 #include "radv_debug.h"
32 #include "radv_private.h"
36 /* descriptor index into scratch ring offsets */
37 #define RING_SCRATCH 0
38 #define RING_ESGS_VS 1
39 #define RING_ESGS_GS 2
40 #define RING_GSVS_VS 3
41 #define RING_GSVS_GS 4
42 #define RING_HS_TESS_FACTOR 5
43 #define RING_HS_TESS_OFFCHIP 6
44 #define RING_PS_SAMPLE_POSITIONS 7
46 // Match MAX_SETS from radv_descriptor_set.h
47 #define RADV_UD_MAX_SETS MAX_SETS
49 struct radv_shader_module
{
50 struct nir_shader
*nir
;
51 unsigned char sha1
[20];
56 struct radv_userdata_info
{
60 uint32_t indirect_offset
;
63 struct radv_userdata_locations
{
64 struct radv_userdata_info descriptor_sets
[RADV_UD_MAX_SETS
];
65 struct radv_userdata_info shader_data
[AC_UD_MAX_UD
];
68 struct radv_vs_output_info
{
69 uint8_t vs_output_param_offset
[VARYING_SLOT_MAX
];
70 uint8_t clip_dist_mask
;
71 uint8_t cull_dist_mask
;
72 uint8_t param_exports
;
73 bool writes_pointsize
;
75 bool writes_viewport_index
;
80 struct radv_es_output_info
{
81 uint32_t esgs_itemsize
;
84 struct radv_shader_variant_info
{
85 struct radv_userdata_locations user_sgprs_locs
;
86 struct ac_shader_info info
;
87 unsigned num_user_sgprs
;
88 unsigned num_input_sgprs
;
89 unsigned num_input_vgprs
;
90 unsigned private_mem_vgprs
;
91 bool need_indirect_descriptor_sets
;
94 struct radv_vs_output_info outinfo
;
95 struct radv_es_output_info es_info
;
96 unsigned vgpr_comp_cnt
;
99 uint64_t outputs_written
;
104 uint32_t flat_shaded_mask
;
106 bool early_fragment_test
;
109 unsigned block_size
[3];
112 unsigned vertices_in
;
113 unsigned vertices_out
;
114 unsigned output_prim
;
115 unsigned invocations
;
116 unsigned gsvs_vertex_size
;
117 unsigned max_gsvs_emit_size
;
118 unsigned es_type
; /* GFX9: VS or TES */
121 unsigned tcs_vertices_out
;
122 /* Which outputs are actually written */
123 uint64_t outputs_written
;
124 /* Which patch outputs are actually written */
125 uint32_t patch_outputs_written
;
129 struct radv_vs_output_info outinfo
;
130 struct radv_es_output_info es_info
;
132 unsigned primitive_mode
;
133 enum gl_tess_spacing spacing
;
140 struct radv_shader_variant
{
143 struct radeon_winsys_bo
*bo
;
145 struct ac_shader_config config
;
147 struct radv_shader_variant_info info
;
154 struct nir_shader
*nir
;
157 struct list_head slab_list
;
160 struct radv_shader_slab
{
161 struct list_head slabs
;
162 struct list_head shaders
;
163 struct radeon_winsys_bo
*bo
;
169 radv_optimize_nir(struct nir_shader
*shader
);
172 radv_shader_compile_to_nir(struct radv_device
*device
,
173 struct radv_shader_module
*module
,
174 const char *entrypoint_name
,
175 gl_shader_stage stage
,
176 const VkSpecializationInfo
*spec_info
);
179 radv_alloc_shader_memory(struct radv_device
*device
,
180 struct radv_shader_variant
*shader
);
183 radv_destroy_shader_slabs(struct radv_device
*device
);
185 struct radv_shader_variant
*
186 radv_shader_variant_create(struct radv_device
*device
,
187 struct radv_shader_module
*module
,
188 struct nir_shader
*const *shaders
,
190 struct radv_pipeline_layout
*layout
,
191 const struct ac_shader_variant_key
*key
,
193 unsigned *code_size_out
);
195 struct radv_shader_variant
*
196 radv_create_gs_copy_shader(struct radv_device
*device
, struct nir_shader
*nir
,
197 void **code_out
, unsigned *code_size_out
,
201 radv_shader_variant_destroy(struct radv_device
*device
,
202 struct radv_shader_variant
*variant
);
205 radv_get_shader_name(struct radv_shader_variant
*var
, gl_shader_stage stage
);
208 radv_shader_dump_stats(struct radv_device
*device
,
209 struct radv_shader_variant
*variant
,
210 gl_shader_stage stage
,
214 radv_can_dump_shader(struct radv_device
*device
,
215 struct radv_shader_module
*module
)
217 /* Only dump non-meta shaders, useful for debugging purposes. */
218 return device
->instance
->debug_flags
& RADV_DEBUG_DUMP_SHADERS
&&
219 module
&& !module
->nir
;
223 radv_can_dump_shader_stats(struct radv_device
*device
,
224 struct radv_shader_module
*module
)
226 /* Only dump non-meta shader stats. */
227 return device
->instance
->debug_flags
& RADV_DEBUG_DUMP_SHADER_STATS
&&
228 module
&& !module
->nir
;