blob: b4974e43c1a4b781b12584064dccd9aff50f6703 [file] [log] [blame]
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +00001/*
2 * © Copyright 2018 Alyssa Rosenzweig
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
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
Boris Brezillon154cb722019-09-14 09:58:55 +020028#include "pan_bo.h"
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +000029#include "pan_context.h"
Alyssa Rosenzweig35418f62019-12-16 18:05:21 -050030#include "pan_util.h"
Alyssa Rosenzweig80169062020-04-06 16:44:17 -040031#include "panfrost-quirks.h"
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +000032
33#include "compiler/nir/nir.h"
34#include "nir/tgsi_to_nir.h"
35#include "midgard/midgard_compile.h"
Alyssa Rosenzweig80169062020-04-06 16:44:17 -040036#include "bifrost/bifrost_compile.h"
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +000037#include "util/u_dynarray.h"
Alyssa Rosenzweig1e4c49e2020-08-21 14:16:18 -040038#include "util/u_upload_mgr.h"
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +000039
40#include "tgsi/tgsi_dump.h"
41
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -040042static void
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020043pan_prepare_midgard_props(struct panfrost_shader_state *state,
44 gl_shader_stage stage)
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -040045{
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020046 pan_prepare(&state->properties, RENDERER_PROPERTIES);
47 state->properties.uniform_buffer_count = state->ubo_count;
Boris Brezillon519643b2020-10-13 18:32:14 +020048 state->properties.midgard.uniform_count = state->uniform_count;
49 state->properties.midgard.shader_has_side_effects = state->writes_global;
50
51 /* TODO: Select the appropriate mode. Suppresing inf/nan works around
52 * some bugs in gles2 apps (eg glmark2's terrain scene) but isn't
53 * conformant on gles3 */
54 state->properties.midgard.fp_mode = MALI_FP_MODE_GL_INF_NAN_SUPPRESSED;
Alyssa Rosenzweig55d9c252020-08-21 13:14:09 -040055
Alyssa Rosenzweigcd66aa72020-11-04 11:17:43 -050056 /* For fragment shaders, work register count, early-z, reads at draw-time */
57
58 if (stage != MESA_SHADER_FRAGMENT)
Boris Brezillon519643b2020-10-13 18:32:14 +020059 state->properties.midgard.work_register_count = state->work_reg_count;
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -040060}
61
62static void
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020063pan_prepare_bifrost_props(struct panfrost_shader_state *state,
64 gl_shader_stage stage)
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -040065{
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020066
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -040067 switch (stage) {
68 case MESA_SHADER_VERTEX:
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020069 pan_prepare(&state->properties, RENDERER_PROPERTIES);
Boris Brezillon519643b2020-10-13 18:32:14 +020070 state->properties.bifrost.zs_update_operation = MALI_PIXEL_KILL_STRONG_EARLY;
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020071 state->properties.uniform_buffer_count = state->ubo_count;
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -040072
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020073 pan_prepare(&state->preload, PRELOAD);
74 state->preload.uniform_count = state->uniform_count;
Boris Brezillon7486b5d2020-10-17 11:02:12 +020075 state->preload.vertex.vertex_id = true;
76 state->preload.vertex.instance_id = true;
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -040077 break;
78 case MESA_SHADER_FRAGMENT:
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020079 pan_prepare(&state->properties, RENDERER_PROPERTIES);
80 /* Early-Z set at draw-time */
Boris Brezillon519643b2020-10-13 18:32:14 +020081 state->properties.bifrost.zs_update_operation = MALI_PIXEL_KILL_STRONG_EARLY;
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020082 state->properties.uniform_buffer_count = state->ubo_count;
Boris Brezillon519643b2020-10-13 18:32:14 +020083 state->properties.bifrost.shader_modifies_coverage = state->can_discard;
Alyssa Rosenzweig55d9c252020-08-21 13:14:09 -040084
Boris Brezillon7bb85ea2020-09-15 17:03:28 +020085 pan_prepare(&state->preload, PRELOAD);
86 state->preload.uniform_count = state->uniform_count;
Boris Brezillon7486b5d2020-10-17 11:02:12 +020087 state->preload.fragment.fragment_position = state->reads_frag_coord;
88 state->preload.fragment.coverage = true;
Boris Brezillon0a582b52020-10-18 18:08:48 +020089 state->preload.fragment.primitive_flags = state->reads_face;
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -040090 break;
91 default:
92 unreachable("TODO");
93 }
94}
95
Alyssa Rosenzweig1e4c49e2020-08-21 14:16:18 -040096static void
97pan_upload_shader_descriptor(struct panfrost_context *ctx,
98 struct panfrost_shader_state *state)
99{
100 const struct panfrost_device *dev = pan_device(ctx->base.screen);
Alyssa Rosenzweigc86b51a2020-08-21 18:06:24 -0400101 struct mali_state_packed *out;
Alyssa Rosenzweig1e4c49e2020-08-21 14:16:18 -0400102
Boris Brezillonf734e672020-09-29 15:47:04 +0200103 u_upload_alloc(ctx->state_uploader, 0, MALI_RENDERER_STATE_LENGTH, MALI_RENDERER_STATE_LENGTH,
Alyssa Rosenzweigc86b51a2020-08-21 18:06:24 -0400104 &state->upload.offset, &state->upload.rsrc, (void **) &out);
Alyssa Rosenzweig1e4c49e2020-08-21 14:16:18 -0400105
Boris Brezillon7bb85ea2020-09-15 17:03:28 +0200106 pan_pack(out, RENDERER_STATE, cfg) {
Alyssa Rosenzweigc86b51a2020-08-21 18:06:24 -0400107 cfg.shader = state->shader;
Boris Brezillon7bb85ea2020-09-15 17:03:28 +0200108 cfg.properties = state->properties;
Alyssa Rosenzweig1e4c49e2020-08-21 14:16:18 -0400109
Alyssa Rosenzweigc86b51a2020-08-21 18:06:24 -0400110 if (dev->quirks & IS_BIFROST)
111 cfg.preload = state->preload;
112 }
113
114 u_upload_unmap(ctx->state_uploader);
Alyssa Rosenzweig1e4c49e2020-08-21 14:16:18 -0400115}
116
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400117static unsigned
118pan_format_from_nir_base(nir_alu_type base)
119{
120 switch (base) {
121 case nir_type_int:
122 return MALI_FORMAT_SINT;
123 case nir_type_uint:
124 case nir_type_bool:
125 return MALI_FORMAT_UINT;
126 case nir_type_float:
127 return MALI_CHANNEL_FLOAT;
128 default:
129 unreachable("Invalid base");
130 }
131}
132
133static unsigned
134pan_format_from_nir_size(nir_alu_type base, unsigned size)
135{
136 if (base == nir_type_float) {
137 switch (size) {
138 case 16: return MALI_FORMAT_SINT;
139 case 32: return MALI_FORMAT_UNORM;
140 default:
141 unreachable("Invalid float size for format");
142 }
143 } else {
144 switch (size) {
145 case 1:
146 case 8: return MALI_CHANNEL_8;
147 case 16: return MALI_CHANNEL_16;
148 case 32: return MALI_CHANNEL_32;
149 default:
150 unreachable("Invalid int size for format");
151 }
152 }
153}
154
155static enum mali_format
Alyssa Rosenzweig1c1782c2020-06-09 18:15:20 -0400156pan_format_from_glsl(const struct glsl_type *type, unsigned precision, unsigned frac)
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400157{
Alyssa Rosenzweig8462ca02020-06-10 15:47:45 -0400158 const struct glsl_type *column = glsl_without_array_or_matrix(type);
159 enum glsl_base_type glsl_base = glsl_get_base_type(column);
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400160 nir_alu_type t = nir_get_nir_type_for_glsl_base_type(glsl_base);
Alyssa Rosenzweig8462ca02020-06-10 15:47:45 -0400161 unsigned chan = glsl_get_components(column);
162
163 /* If we have a fractional location added, we need to increase the size
164 * so it will fit, i.e. a vec3 in YZW requires us to allocate a vec4.
165 * We could do better but this is an edge case as it is, normally
166 * packed varyings will be aligned. */
167 chan += frac;
168
169 assert(chan >= 1 && chan <= 4);
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400170
171 unsigned base = nir_alu_type_get_base_type(t);
172 unsigned size = nir_alu_type_get_type_size(t);
173
Alyssa Rosenzweig1c1782c2020-06-09 18:15:20 -0400174 /* Demote to fp16 where possible. int16 varyings are TODO as the hw
175 * will saturate instead of wrap which is not conformant, so we need to
176 * insert i2i16/u2u16 instructions before the st_vary_32i/32u to get
177 * the intended behaviour */
178
179 bool is_16 = (precision == GLSL_PRECISION_MEDIUM)
180 || (precision == GLSL_PRECISION_LOW);
181
182 if (is_16 && base == nir_type_float)
183 size = 16;
184 else
185 size = 32;
186
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400187 return pan_format_from_nir_base(base) |
188 pan_format_from_nir_size(base, size) |
Alyssa Rosenzweig8462ca02020-06-10 15:47:45 -0400189 MALI_NR_CHANNELS(chan);
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400190}
191
Boris Brezillon83899762020-09-16 13:31:37 +0200192static enum mali_bifrost_register_file_format
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200193bifrost_blend_type_from_nir(nir_alu_type nir_type)
194{
195 switch(nir_type) {
196 case 0: /* Render target not in use */
197 return 0;
198 case nir_type_float16:
Boris Brezillon83899762020-09-16 13:31:37 +0200199 return MALI_BIFROST_REGISTER_FILE_FORMAT_F16;
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200200 case nir_type_float32:
Boris Brezillon83899762020-09-16 13:31:37 +0200201 return MALI_BIFROST_REGISTER_FILE_FORMAT_F32;
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200202 case nir_type_int32:
Boris Brezillon83899762020-09-16 13:31:37 +0200203 return MALI_BIFROST_REGISTER_FILE_FORMAT_I32;
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200204 case nir_type_uint32:
Boris Brezillon83899762020-09-16 13:31:37 +0200205 return MALI_BIFROST_REGISTER_FILE_FORMAT_U32;
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200206 case nir_type_int16:
Boris Brezillon83899762020-09-16 13:31:37 +0200207 return MALI_BIFROST_REGISTER_FILE_FORMAT_I16;
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200208 case nir_type_uint16:
Boris Brezillon83899762020-09-16 13:31:37 +0200209 return MALI_BIFROST_REGISTER_FILE_FORMAT_U16;
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200210 default:
Alyssa Rosenzweiged1910d2020-07-07 16:15:45 -0400211 unreachable("Unsupported blend shader type for NIR alu type");
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200212 return 0;
213 }
214}
215
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000216void
Boris Brezillonb02f97c2020-03-05 16:20:18 +0100217panfrost_shader_compile(struct panfrost_context *ctx,
218 enum pipe_shader_ir ir_type,
219 const void *ir,
220 gl_shader_stage stage,
221 struct panfrost_shader_state *state,
222 uint64_t *outputs_written)
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000223{
Alyssa Rosenzweigca8c6252020-03-23 18:44:21 -0400224 struct panfrost_device *dev = pan_device(ctx->base.screen);
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000225
226 nir_shader *s;
227
Alyssa Rosenzweigc2280462019-07-31 15:19:09 -0700228 if (ir_type == PIPE_SHADER_IR_NIR) {
229 s = nir_shader_clone(NULL, ir);
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000230 } else {
Alyssa Rosenzweigc2280462019-07-31 15:19:09 -0700231 assert (ir_type == PIPE_SHADER_IR_TGSI);
Axel Davy522bd412020-05-12 21:52:40 +0200232 s = tgsi_to_nir(ir, ctx->base.screen, false);
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000233 }
234
Alyssa Rosenzweig46479992019-07-31 15:49:13 -0700235 s->info.stage = stage;
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000236
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000237 /* Call out to Midgard compiler given the above NIR */
Boris Brezillon0a74a042020-10-08 10:09:56 +0200238 struct panfrost_compile_inputs inputs = {
239 .gpu_id = dev->gpu_id,
240 .shaderdb = !!(dev->debug & PAN_DBG_PRECOMPILE),
241 };
Icecream9575018f62020-07-06 19:40:05 +1200242
Boris Brezillon0a74a042020-10-08 10:09:56 +0200243 memcpy(inputs.rt_formats, state->rt_formats, sizeof(inputs.rt_formats));
244
Boris Brezillon69c864b2020-10-17 12:08:17 +0200245 panfrost_program *program;
246
Boris Brezillon0a74a042020-10-08 10:09:56 +0200247 if (dev->quirks & IS_BIFROST)
Boris Brezillon69c864b2020-10-17 12:08:17 +0200248 program = bifrost_compile_shader_nir(NULL, s, &inputs);
Boris Brezillon0a74a042020-10-08 10:09:56 +0200249 else
Boris Brezillon69c864b2020-10-17 12:08:17 +0200250 program = midgard_compile_shader_nir(NULL, s, &inputs);
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000251
252 /* Prepare the compiled binary for upload */
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400253 mali_ptr shader = 0;
254 unsigned attribute_count = 0, varying_count = 0;
Boris Brezillon69c864b2020-10-17 12:08:17 +0200255 int size = program->compiled.size;
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000256
Alyssa Rosenzweigbf5d8cf2019-12-16 16:45:28 -0500257 if (size) {
Alyssa Rosenzweig1d88f072020-07-07 16:19:39 -0400258 state->bo = panfrost_bo_create(dev, size, PAN_BO_EXECUTE);
Boris Brezillon1b3b2892020-10-18 10:13:18 +0200259 memcpy(state->bo->ptr.cpu, program->compiled.data, size);
260 shader = state->bo->ptr.gpu;
Alyssa Rosenzweig80169062020-04-06 16:44:17 -0400261 }
262
Alyssa Rosenzweig9f832172020-08-19 10:13:59 -0400263 /* Midgard needs the first tag on the bottom nibble */
264
Alyssa Rosenzweig80169062020-04-06 16:44:17 -0400265 if (!(dev->quirks & IS_BIFROST)) {
Alyssa Rosenzweig9f832172020-08-19 10:13:59 -0400266 /* If size = 0, we tag as "end-of-shader" */
267
268 if (size)
Boris Brezillon69c864b2020-10-17 12:08:17 +0200269 shader |= program->first_tag;
Alyssa Rosenzweig9f832172020-08-19 10:13:59 -0400270 else
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400271 shader = 0x1;
Alyssa Rosenzweigbf5d8cf2019-12-16 16:45:28 -0500272 }
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000273
Boris Brezillon69c864b2020-10-17 12:08:17 +0200274 state->sysval_count = program->sysval_count;
275 memcpy(state->sysval, program->sysvals, sizeof(state->sysval[0]) * state->sysval_count);
Alyssa Rosenzweig7e8de5a2019-04-03 01:48:09 +0000276
Alyssa Rosenzweig87813782019-12-19 13:39:14 -0500277 bool vertex_id = s->info.system_values_read & (1 << SYSTEM_VALUE_VERTEX_ID);
278 bool instance_id = s->info.system_values_read & (1 << SYSTEM_VALUE_INSTANCE_ID);
279
Alyssa Rosenzweig1d194f82020-05-29 16:06:10 -0400280 /* On Bifrost it's a sysval, on Midgard it's a varying */
281 state->reads_frag_coord = s->info.system_values_read & (1 << SYSTEM_VALUE_FRAG_COORD);
282
Alyssa Rosenzweigdce77222020-06-02 14:12:29 -0400283 state->writes_global = s->info.writes_memory;
284
Alyssa Rosenzweig46479992019-07-31 15:49:13 -0700285 switch (stage) {
Alyssa Rosenzweig5534fdb2019-07-23 17:02:38 -0700286 case MESA_SHADER_VERTEX:
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400287 attribute_count = util_bitcount64(s->info.inputs_read);
288 varying_count = util_bitcount64(s->info.outputs_written);
Alyssa Rosenzweig87813782019-12-19 13:39:14 -0500289
290 if (vertex_id)
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400291 attribute_count = MAX2(attribute_count, PAN_VERTEX_ID + 1);
Alyssa Rosenzweig87813782019-12-19 13:39:14 -0500292
293 if (instance_id)
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400294 attribute_count = MAX2(attribute_count, PAN_INSTANCE_ID + 1);
Alyssa Rosenzweig87813782019-12-19 13:39:14 -0500295
Alyssa Rosenzweig5534fdb2019-07-23 17:02:38 -0700296 break;
297 case MESA_SHADER_FRAGMENT:
Boris Brezillon91d9c552020-10-12 15:18:35 +0200298 for (unsigned i = 0; i < ARRAY_SIZE(state->blend_ret_addrs); i++) {
Boris Brezillon69c864b2020-10-17 12:08:17 +0200299 if (!program->blend_ret_offsets[i])
Boris Brezillon91d9c552020-10-12 15:18:35 +0200300 continue;
301
Boris Brezillon1b3b2892020-10-18 10:13:18 +0200302 state->blend_ret_addrs[i] = (state->bo->ptr.gpu & UINT32_MAX) +
Boris Brezillon69c864b2020-10-17 12:08:17 +0200303 program->blend_ret_offsets[i];
Boris Brezillon91d9c552020-10-12 15:18:35 +0200304 assert(!(state->blend_ret_addrs[i] & 0x7));
305 }
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400306 varying_count = util_bitcount64(s->info.inputs_read);
Boris Brezillon38c20692020-01-31 10:55:49 +0100307 if (s->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH))
308 state->writes_depth = true;
309 if (s->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_STENCIL))
310 state->writes_stencil = true;
Alyssa Rosenzweig1085f742020-05-21 15:49:30 -0400311
Icecream95e6032482020-07-06 19:41:28 +1200312 uint64_t outputs_read = s->info.outputs_read;
313 if (outputs_read & BITFIELD64_BIT(FRAG_RESULT_COLOR))
314 outputs_read |= BITFIELD64_BIT(FRAG_RESULT_DATA0);
315
316 state->outputs_read = outputs_read >> FRAG_RESULT_DATA0;
317
Alyssa Rosenzweig1085f742020-05-21 15:49:30 -0400318 /* List of reasons we need to execute frag shaders when things
319 * are masked off */
320
321 state->fs_sidefx =
322 s->info.writes_memory ||
323 s->info.fs.uses_discard ||
324 s->info.fs.uses_demote;
Alyssa Rosenzweig5534fdb2019-07-23 17:02:38 -0700325 break;
Alyssa Rosenzweigff345d42019-07-31 15:52:04 -0700326 case MESA_SHADER_COMPUTE:
327 /* TODO: images */
Alyssa Rosenzweig96031262020-02-06 14:29:42 -0500328 state->shared_size = s->info.cs.shared_size;
Alyssa Rosenzweigff345d42019-07-31 15:52:04 -0700329 break;
Alyssa Rosenzweig5534fdb2019-07-23 17:02:38 -0700330 default:
331 unreachable("Unknown shader state");
332 }
333
Alyssa Rosenzweigbab4f6c2019-07-23 16:52:40 -0700334 state->can_discard = s->info.fs.uses_discard;
Alyssa Rosenzweig48991c72019-07-23 16:49:37 -0700335 state->helper_invocations = s->info.fs.needs_helper_invocations;
Boris Brezillon69c864b2020-10-17 12:08:17 +0200336 state->stack_size = program->tls_size;
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000337
Alyssa Rosenzweigf1de9522020-06-08 18:05:21 -0400338 state->reads_frag_coord = s->info.inputs_read & (1 << VARYING_SLOT_POS);
339 state->reads_point_coord = s->info.inputs_read & (1 << VARYING_SLOT_PNTC);
Boris Brezillon0a582b52020-10-18 18:08:48 +0200340 state->reads_face = (s->info.inputs_read & (1 << VARYING_SLOT_FACE)) ||
341 (s->info.system_values_read & (1 << SYSTEM_VALUE_FRONT_FACE));
Alyssa Rosenzweigf1de9522020-06-08 18:05:21 -0400342 state->writes_point_size = s->info.outputs_written & (1 << VARYING_SLOT_PSIZ);
343
Alyssa Rosenzweig5b0a1a42019-08-07 10:26:12 -0700344 if (outputs_written)
345 *outputs_written = s->info.outputs_written;
346
Alyssa Rosenzweige30091b2020-04-08 14:44:31 -0400347 /* Separate as primary uniform count is truncated. Sysvals are prefix
348 * uniforms */
Boris Brezillon69c864b2020-10-17 12:08:17 +0200349 state->uniform_count = MIN2(s->num_uniforms + program->sysval_count, program->uniform_cutoff);
350 state->work_reg_count = program->work_register_count;
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000351
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200352 if (dev->quirks & IS_BIFROST)
Boris Brezillon83899762020-09-16 13:31:37 +0200353 for (unsigned i = 0; i < ARRAY_SIZE(state->blend_types); i++)
Boris Brezillon69c864b2020-10-17 12:08:17 +0200354 state->blend_types[i] = bifrost_blend_type_from_nir(program->blend_types[i]);
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200355
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400356 /* Record the varying mapping for the command stream's bookkeeping */
357
Jason Ekstranda61be312020-07-21 18:13:34 -0500358 nir_variable_mode varying_mode =
359 stage == MESA_SHADER_VERTEX ? nir_var_shader_out : nir_var_shader_in;
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400360
Jason Ekstranda61be312020-07-21 18:13:34 -0500361 nir_foreach_variable_with_modes(var, s, varying_mode) {
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400362 unsigned loc = var->data.driver_location;
363 unsigned sz = glsl_count_attribute_slots(var->type, FALSE);
364
365 for (int c = 0; c < sz; ++c) {
Alyssa Rosenzweig3cc425e2020-06-10 15:48:33 -0400366 state->varyings_loc[loc + c] = var->data.location + c;
Alyssa Rosenzweig1c1782c2020-06-09 18:15:20 -0400367 state->varyings[loc + c] = pan_format_from_glsl(var->type,
368 var->data.precision, var->data.location_frac);
Alyssa Rosenzweigd1042392020-04-08 13:54:17 -0400369 }
370 }
Alyssa Rosenzweig9146f592020-08-18 08:07:15 -0400371
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -0400372 /* Needed for linkage */
373 state->attribute_count = attribute_count;
374 state->varying_count = varying_count;
375 state->ubo_count = s->info.num_ubos + 1; /* off-by-one for uniforms */
376
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400377 /* Prepare the descriptors at compile-time */
Boris Brezillon7bb85ea2020-09-15 17:03:28 +0200378 state->shader.shader = shader;
379 state->shader.attribute_count = attribute_count;
380 state->shader.varying_count = varying_count;
381 state->shader.texture_count = s->info.num_textures;
382 state->shader.sampler_count = s->info.num_textures;
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400383
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -0400384 if (dev->quirks & IS_BIFROST)
Boris Brezillon7bb85ea2020-09-15 17:03:28 +0200385 pan_prepare_bifrost_props(state, stage);
Alyssa Rosenzweiga29fb642020-08-21 12:34:24 -0400386 else
Boris Brezillon7bb85ea2020-09-15 17:03:28 +0200387 pan_prepare_midgard_props(state, stage);
Alyssa Rosenzweig661b4692020-08-21 10:34:06 -0400388
Alyssa Rosenzweigcd66aa72020-11-04 11:17:43 -0500389 state->properties.stencil_from_shader = state->writes_stencil;
390 state->properties.shader_contains_barrier = state->helper_invocations;
391 state->properties.depth_source = state->writes_depth ?
392 MALI_DEPTH_SOURCE_SHADER :
393 MALI_DEPTH_SOURCE_FIXED_FUNCTION;
394
Alyssa Rosenzweig1e4c49e2020-08-21 14:16:18 -0400395 if (stage != MESA_SHADER_FRAGMENT)
396 pan_upload_shader_descriptor(ctx, state);
397
Boris Brezillon69c864b2020-10-17 12:08:17 +0200398 ralloc_free(program);
399
Alyssa Rosenzweig9146f592020-08-18 08:07:15 -0400400 /* In both clone and tgsi_to_nir paths, the shader is ralloc'd against
401 * a NULL context */
402 ralloc_free(s);
Alyssa Rosenzweig7da251f2019-02-05 04:32:27 +0000403}