iris: Mark cbuf0 as not needing uploading every single time
[mesa.git] / src / gallium / drivers / iris / iris_program.c
1 /*
2 * Copyright © 2017 Intel Corporation
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 shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 /**
24 * @file iris_program.c
25 *
26 * This file contains the driver interface for compiling shaders.
27 *
28 * See iris_program_cache.c for the in-memory program cache where the
29 * compiled shaders are stored.
30 */
31
32 #include <stdio.h>
33 #include <errno.h>
34 #include "pipe/p_defines.h"
35 #include "pipe/p_state.h"
36 #include "pipe/p_context.h"
37 #include "pipe/p_screen.h"
38 #include "util/u_atomic.h"
39 #include "util/u_upload_mgr.h"
40 #include "util/debug.h"
41 #include "compiler/nir/nir.h"
42 #include "compiler/nir/nir_builder.h"
43 #include "compiler/nir/nir_serialize.h"
44 #include "intel/compiler/brw_compiler.h"
45 #include "intel/compiler/brw_nir.h"
46 #include "iris_context.h"
47 #include "nir/tgsi_to_nir.h"
48
49 #define KEY_INIT_NO_ID(gen) \
50 .tex.swizzles[0 ... MAX_SAMPLERS - 1] = 0x688, \
51 .tex.compressed_multisample_layout_mask = ~0, \
52 .tex.msaa_16 = (gen >= 9 ? ~0 : 0)
53 #define KEY_INIT(gen) .program_string_id = ish->program_id, KEY_INIT_NO_ID(gen)
54
55 static unsigned
56 get_new_program_id(struct iris_screen *screen)
57 {
58 return p_atomic_inc_return(&screen->program_id);
59 }
60
61 static void *
62 upload_state(struct u_upload_mgr *uploader,
63 struct iris_state_ref *ref,
64 unsigned size,
65 unsigned alignment)
66 {
67 void *p = NULL;
68 u_upload_alloc(uploader, 0, size, alignment, &ref->offset, &ref->res, &p);
69 return p;
70 }
71
72 void
73 iris_upload_ubo_ssbo_surf_state(struct iris_context *ice,
74 struct pipe_shader_buffer *buf,
75 struct iris_state_ref *surf_state,
76 bool ssbo)
77 {
78 struct pipe_context *ctx = &ice->ctx;
79 struct iris_screen *screen = (struct iris_screen *) ctx->screen;
80
81 // XXX: these are not retained forever, use a separate uploader?
82 void *map =
83 upload_state(ice->state.surface_uploader, surf_state,
84 screen->isl_dev.ss.size, 64);
85 if (!unlikely(map)) {
86 surf_state->res = NULL;
87 return;
88 }
89
90 struct iris_resource *res = (void *) buf->buffer;
91 struct iris_bo *surf_bo = iris_resource_bo(surf_state->res);
92 surf_state->offset += iris_bo_offset_from_base_address(surf_bo);
93
94 isl_buffer_fill_state(&screen->isl_dev, map,
95 .address = res->bo->gtt_offset + res->offset +
96 buf->buffer_offset,
97 .size_B = buf->buffer_size - res->offset,
98 .format = ssbo ? ISL_FORMAT_RAW
99 : ISL_FORMAT_R32G32B32A32_FLOAT,
100 .swizzle = ISL_SWIZZLE_IDENTITY,
101 .stride_B = 1,
102 .mocs = ice->vtbl.mocs(res->bo));
103 }
104
105 static nir_ssa_def *
106 get_aoa_deref_offset(nir_builder *b,
107 nir_deref_instr *deref,
108 unsigned elem_size)
109 {
110 unsigned array_size = elem_size;
111 nir_ssa_def *offset = nir_imm_int(b, 0);
112
113 while (deref->deref_type != nir_deref_type_var) {
114 assert(deref->deref_type == nir_deref_type_array);
115
116 /* This level's element size is the previous level's array size */
117 nir_ssa_def *index = nir_ssa_for_src(b, deref->arr.index, 1);
118 assert(deref->arr.index.ssa);
119 offset = nir_iadd(b, offset,
120 nir_imul(b, index, nir_imm_int(b, array_size)));
121
122 deref = nir_deref_instr_parent(deref);
123 assert(glsl_type_is_array(deref->type));
124 array_size *= glsl_get_length(deref->type);
125 }
126
127 /* Accessing an invalid surface index with the dataport can result in a
128 * hang. According to the spec "if the index used to select an individual
129 * element is negative or greater than or equal to the size of the array,
130 * the results of the operation are undefined but may not lead to
131 * termination" -- which is one of the possible outcomes of the hang.
132 * Clamp the index to prevent access outside of the array bounds.
133 */
134 return nir_umin(b, offset, nir_imm_int(b, array_size - elem_size));
135 }
136
137 static void
138 iris_lower_storage_image_derefs(nir_shader *nir)
139 {
140 nir_function_impl *impl = nir_shader_get_entrypoint(nir);
141
142 nir_builder b;
143 nir_builder_init(&b, impl);
144
145 nir_foreach_block(block, impl) {
146 nir_foreach_instr_safe(instr, block) {
147 if (instr->type != nir_instr_type_intrinsic)
148 continue;
149
150 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
151 switch (intrin->intrinsic) {
152 case nir_intrinsic_image_deref_load:
153 case nir_intrinsic_image_deref_store:
154 case nir_intrinsic_image_deref_atomic_add:
155 case nir_intrinsic_image_deref_atomic_min:
156 case nir_intrinsic_image_deref_atomic_max:
157 case nir_intrinsic_image_deref_atomic_and:
158 case nir_intrinsic_image_deref_atomic_or:
159 case nir_intrinsic_image_deref_atomic_xor:
160 case nir_intrinsic_image_deref_atomic_exchange:
161 case nir_intrinsic_image_deref_atomic_comp_swap:
162 case nir_intrinsic_image_deref_size:
163 case nir_intrinsic_image_deref_samples:
164 case nir_intrinsic_image_deref_load_raw_intel:
165 case nir_intrinsic_image_deref_store_raw_intel: {
166 nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
167 nir_variable *var = nir_deref_instr_get_variable(deref);
168
169 b.cursor = nir_before_instr(&intrin->instr);
170 nir_ssa_def *index =
171 nir_iadd(&b, nir_imm_int(&b, var->data.driver_location),
172 get_aoa_deref_offset(&b, deref, 1));
173 nir_rewrite_image_intrinsic(intrin, index, false);
174 break;
175 }
176
177 default:
178 break;
179 }
180 }
181 }
182 }
183
184 // XXX: need unify_interfaces() at link time...
185
186 /**
187 * Fix an uncompiled shader's stream output info.
188 *
189 * Core Gallium stores output->register_index as a "slot" number, where
190 * slots are assigned consecutively to all outputs in info->outputs_written.
191 * This naive packing of outputs doesn't work for us - we too have slots,
192 * but the layout is defined by the VUE map, which we won't have until we
193 * compile a specific shader variant. So, we remap these and simply store
194 * VARYING_SLOT_* in our copy's output->register_index fields.
195 *
196 * We also fix up VARYING_SLOT_{LAYER,VIEWPORT,PSIZ} to select the Y/Z/W
197 * components of our VUE header. See brw_vue_map.c for the layout.
198 */
199 static void
200 update_so_info(struct pipe_stream_output_info *so_info,
201 uint64_t outputs_written)
202 {
203 uint8_t reverse_map[64] = {};
204 unsigned slot = 0;
205 while (outputs_written) {
206 reverse_map[slot++] = u_bit_scan64(&outputs_written);
207 }
208
209 for (unsigned i = 0; i < so_info->num_outputs; i++) {
210 struct pipe_stream_output *output = &so_info->output[i];
211
212 /* Map Gallium's condensed "slots" back to real VARYING_SLOT_* enums */
213 output->register_index = reverse_map[output->register_index];
214
215 /* The VUE header contains three scalar fields packed together:
216 * - gl_PointSize is stored in VARYING_SLOT_PSIZ.w
217 * - gl_Layer is stored in VARYING_SLOT_PSIZ.y
218 * - gl_ViewportIndex is stored in VARYING_SLOT_PSIZ.z
219 */
220 switch (output->register_index) {
221 case VARYING_SLOT_LAYER:
222 assert(output->num_components == 1);
223 output->register_index = VARYING_SLOT_PSIZ;
224 output->start_component = 1;
225 break;
226 case VARYING_SLOT_VIEWPORT:
227 assert(output->num_components == 1);
228 output->register_index = VARYING_SLOT_PSIZ;
229 output->start_component = 2;
230 break;
231 case VARYING_SLOT_PSIZ:
232 assert(output->num_components == 1);
233 output->start_component = 3;
234 break;
235 }
236
237 //info->outputs_written |= 1ull << output->register_index;
238 }
239 }
240
241 static void
242 setup_vec4_image_sysval(uint32_t *sysvals, uint32_t idx,
243 unsigned offset, unsigned n)
244 {
245 assert(offset % sizeof(uint32_t) == 0);
246
247 for (unsigned i = 0; i < n; ++i)
248 sysvals[i] = BRW_PARAM_IMAGE(idx, offset / sizeof(uint32_t) + i);
249
250 for (unsigned i = n; i < 4; ++i)
251 sysvals[i] = BRW_PARAM_BUILTIN_ZERO;
252 }
253
254 /**
255 * Associate NIR uniform variables with the prog_data->param[] mechanism
256 * used by the backend. Also, decide which UBOs we'd like to push in an
257 * ideal situation (though the backend can reduce this).
258 */
259 static void
260 iris_setup_uniforms(const struct brw_compiler *compiler,
261 void *mem_ctx,
262 nir_shader *nir,
263 struct brw_stage_prog_data *prog_data,
264 enum brw_param_builtin **out_system_values,
265 unsigned *out_num_system_values,
266 unsigned *out_num_cbufs)
267 {
268 UNUSED const struct gen_device_info *devinfo = compiler->devinfo;
269
270 /* The intel compiler assumes that num_uniforms is in bytes. For
271 * scalar that means 4 bytes per uniform slot.
272 *
273 * Ref: brw_nir_lower_uniforms, type_size_scalar_bytes.
274 */
275 nir->num_uniforms *= 4;
276
277 const unsigned IRIS_MAX_SYSTEM_VALUES =
278 PIPE_MAX_SHADER_IMAGES * BRW_IMAGE_PARAM_SIZE;
279 enum brw_param_builtin *system_values =
280 rzalloc_array(mem_ctx, enum brw_param_builtin, IRIS_MAX_SYSTEM_VALUES);
281 unsigned num_system_values = 0;
282
283 unsigned patch_vert_idx = -1;
284 unsigned ucp_idx[IRIS_MAX_CLIP_PLANES];
285 unsigned img_idx[PIPE_MAX_SHADER_IMAGES];
286 memset(ucp_idx, -1, sizeof(ucp_idx));
287 memset(img_idx, -1, sizeof(img_idx));
288
289 nir_function_impl *impl = nir_shader_get_entrypoint(nir);
290
291 nir_builder b;
292 nir_builder_init(&b, impl);
293
294 b.cursor = nir_before_block(nir_start_block(impl));
295 nir_ssa_def *temp_ubo_name = nir_ssa_undef(&b, 1, 32);
296 nir_ssa_def *temp_const_ubo_name = NULL;
297
298 /* Turn system value intrinsics into uniforms */
299 nir_foreach_block(block, impl) {
300 nir_foreach_instr_safe(instr, block) {
301 if (instr->type != nir_instr_type_intrinsic)
302 continue;
303
304 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
305 nir_ssa_def *offset;
306
307 switch (intrin->intrinsic) {
308 case nir_intrinsic_load_constant: {
309 /* This one is special because it reads from the shader constant
310 * data and not cbuf0 which gallium uploads for us.
311 */
312 b.cursor = nir_before_instr(instr);
313 nir_ssa_def *offset =
314 nir_iadd_imm(&b, nir_ssa_for_src(&b, intrin->src[0], 1),
315 nir_intrinsic_base(intrin));
316
317 if (temp_const_ubo_name == NULL)
318 temp_const_ubo_name = nir_imm_int(&b, 0);
319
320 nir_intrinsic_instr *load_ubo =
321 nir_intrinsic_instr_create(b.shader, nir_intrinsic_load_ubo);
322 load_ubo->num_components = intrin->num_components;
323 load_ubo->src[0] = nir_src_for_ssa(temp_const_ubo_name);
324 load_ubo->src[1] = nir_src_for_ssa(offset);
325 nir_ssa_dest_init(&load_ubo->instr, &load_ubo->dest,
326 intrin->dest.ssa.num_components,
327 intrin->dest.ssa.bit_size,
328 intrin->dest.ssa.name);
329 nir_builder_instr_insert(&b, &load_ubo->instr);
330
331 nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
332 nir_src_for_ssa(&load_ubo->dest.ssa));
333 nir_instr_remove(&intrin->instr);
334 continue;
335 }
336 case nir_intrinsic_load_user_clip_plane: {
337 unsigned ucp = nir_intrinsic_ucp_id(intrin);
338
339 if (ucp_idx[ucp] == -1) {
340 ucp_idx[ucp] = num_system_values;
341 num_system_values += 4;
342 }
343
344 for (int i = 0; i < 4; i++) {
345 system_values[ucp_idx[ucp] + i] =
346 BRW_PARAM_BUILTIN_CLIP_PLANE(ucp, i);
347 }
348
349 b.cursor = nir_before_instr(instr);
350 offset = nir_imm_int(&b, ucp_idx[ucp] * sizeof(uint32_t));
351 break;
352 }
353 case nir_intrinsic_load_patch_vertices_in:
354 if (patch_vert_idx == -1)
355 patch_vert_idx = num_system_values++;
356
357 system_values[patch_vert_idx] =
358 BRW_PARAM_BUILTIN_PATCH_VERTICES_IN;
359
360 b.cursor = nir_before_instr(instr);
361 offset = nir_imm_int(&b, patch_vert_idx * sizeof(uint32_t));
362 break;
363 case nir_intrinsic_image_deref_load_param_intel: {
364 assert(devinfo->gen < 9);
365 nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
366 nir_variable *var = nir_deref_instr_get_variable(deref);
367
368 /* XXX: var->data.binding is not set properly. We need to run
369 * some form of gl_nir_lower_samplers_as_deref() to get it.
370 * This breaks tests which use more than one image.
371 */
372 if (img_idx[var->data.binding] == -1) {
373 /* GL only allows arrays of arrays of images. */
374 assert(glsl_type_is_image(glsl_without_array(var->type)));
375 unsigned num_images = MAX2(1, glsl_get_aoa_size(var->type));
376
377 for (int i = 0; i < num_images; i++) {
378 const unsigned img = var->data.binding + i;
379
380 img_idx[img] = num_system_values;
381 num_system_values += BRW_IMAGE_PARAM_SIZE;
382
383 uint32_t *img_sv = &system_values[img_idx[img]];
384
385 setup_vec4_image_sysval(
386 img_sv + BRW_IMAGE_PARAM_OFFSET_OFFSET, img,
387 offsetof(struct brw_image_param, offset), 2);
388 setup_vec4_image_sysval(
389 img_sv + BRW_IMAGE_PARAM_SIZE_OFFSET, img,
390 offsetof(struct brw_image_param, size), 3);
391 setup_vec4_image_sysval(
392 img_sv + BRW_IMAGE_PARAM_STRIDE_OFFSET, img,
393 offsetof(struct brw_image_param, stride), 4);
394 setup_vec4_image_sysval(
395 img_sv + BRW_IMAGE_PARAM_TILING_OFFSET, img,
396 offsetof(struct brw_image_param, tiling), 3);
397 setup_vec4_image_sysval(
398 img_sv + BRW_IMAGE_PARAM_SWIZZLING_OFFSET, img,
399 offsetof(struct brw_image_param, swizzling), 2);
400 }
401 }
402
403 b.cursor = nir_before_instr(instr);
404 offset = nir_iadd(&b,
405 get_aoa_deref_offset(&b, deref, BRW_IMAGE_PARAM_SIZE * 4),
406 nir_imm_int(&b, img_idx[var->data.binding] * 4 +
407 nir_intrinsic_base(intrin) * 16));
408 break;
409 }
410 default:
411 continue;
412 }
413
414 unsigned comps = nir_intrinsic_dest_components(intrin);
415
416 nir_intrinsic_instr *load =
417 nir_intrinsic_instr_create(nir, nir_intrinsic_load_ubo);
418 load->num_components = comps;
419 load->src[0] = nir_src_for_ssa(temp_ubo_name);
420 load->src[1] = nir_src_for_ssa(offset);
421 nir_ssa_dest_init(&load->instr, &load->dest, comps, 32, NULL);
422 nir_builder_instr_insert(&b, &load->instr);
423 nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
424 nir_src_for_ssa(&load->dest.ssa));
425 nir_instr_remove(instr);
426 }
427 }
428
429 nir_validate_shader(nir, "before remapping");
430
431 /* Place the new params at the front of constant buffer 0. */
432 if (num_system_values > 0) {
433 nir->num_uniforms += num_system_values * sizeof(uint32_t);
434
435 system_values = reralloc(mem_ctx, system_values, enum brw_param_builtin,
436 num_system_values);
437
438 nir_foreach_block(block, impl) {
439 nir_foreach_instr_safe(instr, block) {
440 if (instr->type != nir_instr_type_intrinsic)
441 continue;
442
443 nir_intrinsic_instr *load = nir_instr_as_intrinsic(instr);
444
445 if (load->intrinsic != nir_intrinsic_load_ubo)
446 continue;
447
448 b.cursor = nir_before_instr(instr);
449
450 assert(load->src[0].is_ssa);
451
452 if (load->src[0].ssa == temp_ubo_name) {
453 nir_instr_rewrite_src(instr, &load->src[0],
454 nir_src_for_ssa(nir_imm_int(&b, 0)));
455 } else if (nir_src_is_const(load->src[0]) &&
456 nir_src_as_uint(load->src[0]) == 0) {
457 nir_ssa_def *offset =
458 nir_iadd(&b, load->src[1].ssa,
459 nir_imm_int(&b, 4 * num_system_values));
460 nir_instr_rewrite_src(instr, &load->src[1],
461 nir_src_for_ssa(offset));
462 }
463 }
464 }
465
466 /* We need to fold the new iadds for brw_nir_analyze_ubo_ranges */
467 nir_opt_constant_folding(nir);
468 } else {
469 ralloc_free(system_values);
470 system_values = NULL;
471 }
472
473 nir_validate_shader(nir, "after remap");
474
475 /* We don't use params[], but fs_visitor::nir_setup_uniforms() asserts
476 * about it for compute shaders, so go ahead and make some fake ones
477 * which the backend will dead code eliminate.
478 */
479 prog_data->nr_params = nir->num_uniforms / 4;
480 prog_data->param = rzalloc_array(mem_ctx, uint32_t, prog_data->nr_params);
481
482 /* System values and uniforms are stored in constant buffer 0, the
483 * user-facing UBOs are indexed by one. So if any constant buffer is
484 * needed, the constant buffer 0 will be needed, so account for it.
485 */
486 unsigned num_cbufs = nir->info.num_ubos;
487 if (num_cbufs || num_system_values || nir->num_uniforms)
488 num_cbufs++;
489
490 /* Constant loads (if any) need to go at the end of the constant buffers so
491 * we need to know num_cbufs before we can lower to them.
492 */
493 if (temp_const_ubo_name != NULL) {
494 nir_load_const_instr *const_ubo_index =
495 nir_instr_as_load_const(temp_const_ubo_name->parent_instr);
496 assert(const_ubo_index->def.bit_size == 32);
497 const_ubo_index->value[0].u32 = num_cbufs;
498 }
499
500 *out_system_values = system_values;
501 *out_num_system_values = num_system_values;
502 *out_num_cbufs = num_cbufs;
503 }
504
505 static const char *surface_group_names[] = {
506 [IRIS_SURFACE_GROUP_RENDER_TARGET] = "render target",
507 [IRIS_SURFACE_GROUP_CS_WORK_GROUPS] = "CS work groups",
508 [IRIS_SURFACE_GROUP_TEXTURE] = "texture",
509 [IRIS_SURFACE_GROUP_UBO] = "ubo",
510 [IRIS_SURFACE_GROUP_SSBO] = "ssbo",
511 [IRIS_SURFACE_GROUP_IMAGE] = "image",
512 };
513
514 static void
515 iris_print_binding_table(FILE *fp, const char *name,
516 const struct iris_binding_table *bt)
517 {
518 STATIC_ASSERT(ARRAY_SIZE(surface_group_names) == IRIS_SURFACE_GROUP_COUNT);
519
520 uint32_t total = 0;
521 uint32_t compacted = 0;
522
523 for (int i = 0; i < IRIS_SURFACE_GROUP_COUNT; i++) {
524 uint32_t size = bt->sizes[i];
525 total += size;
526 if (size)
527 compacted += util_bitcount64(bt->used_mask[i]);
528 }
529
530 if (total == 0) {
531 fprintf(fp, "Binding table for %s is empty\n\n", name);
532 return;
533 }
534
535 if (total != compacted) {
536 fprintf(fp, "Binding table for %s "
537 "(compacted to %u entries from %u entries)\n",
538 name, compacted, total);
539 } else {
540 fprintf(fp, "Binding table for %s (%u entries)\n", name, total);
541 }
542
543 uint32_t entry = 0;
544 for (int i = 0; i < IRIS_SURFACE_GROUP_COUNT; i++) {
545 uint64_t mask = bt->used_mask[i];
546 while (mask) {
547 int index = u_bit_scan64(&mask);
548 fprintf(fp, " [%u] %s #%d\n", entry++, surface_group_names[i], index);
549 }
550 }
551 fprintf(fp, "\n");
552 }
553
554 enum {
555 /* Max elements in a surface group. */
556 SURFACE_GROUP_MAX_ELEMENTS = 64,
557 };
558
559 /**
560 * Map a <group, index> pair to a binding table index.
561 *
562 * For example: <UBO, 5> => binding table index 12
563 */
564 uint32_t
565 iris_group_index_to_bti(const struct iris_binding_table *bt,
566 enum iris_surface_group group, uint32_t index)
567 {
568 assert(index < bt->sizes[group]);
569 uint64_t mask = bt->used_mask[group];
570 uint64_t bit = 1ull << index;
571 if (bit & mask) {
572 return bt->offsets[group] + util_bitcount64((bit - 1) & mask);
573 } else {
574 return IRIS_SURFACE_NOT_USED;
575 }
576 }
577
578 /**
579 * Map a binding table index back to a <group, index> pair.
580 *
581 * For example: binding table index 12 => <UBO, 5>
582 */
583 uint32_t
584 iris_bti_to_group_index(const struct iris_binding_table *bt,
585 enum iris_surface_group group, uint32_t bti)
586 {
587 uint64_t used_mask = bt->used_mask[group];
588 assert(bti >= bt->offsets[group]);
589
590 uint32_t c = bti - bt->offsets[group];
591 while (used_mask) {
592 int i = u_bit_scan64(&used_mask);
593 if (c == 0)
594 return i;
595 c--;
596 }
597
598 return IRIS_SURFACE_NOT_USED;
599 }
600
601 static void
602 rewrite_src_with_bti(nir_builder *b, struct iris_binding_table *bt,
603 nir_instr *instr, nir_src *src,
604 enum iris_surface_group group)
605 {
606 assert(bt->sizes[group] > 0);
607
608 b->cursor = nir_before_instr(instr);
609 nir_ssa_def *bti;
610 if (nir_src_is_const(*src)) {
611 uint32_t index = nir_src_as_uint(*src);
612 bti = nir_imm_intN_t(b, iris_group_index_to_bti(bt, group, index),
613 src->ssa->bit_size);
614 } else {
615 /* Indirect usage makes all the surfaces of the group to be available,
616 * so we can just add the base.
617 */
618 assert(bt->used_mask[group] == BITFIELD64_MASK(bt->sizes[group]));
619 bti = nir_iadd_imm(b, src->ssa, bt->offsets[group]);
620 }
621 nir_instr_rewrite_src(instr, src, nir_src_for_ssa(bti));
622 }
623
624 static void
625 mark_used_with_src(struct iris_binding_table *bt, nir_src *src,
626 enum iris_surface_group group)
627 {
628 assert(bt->sizes[group] > 0);
629
630 if (nir_src_is_const(*src)) {
631 uint64_t index = nir_src_as_uint(*src);
632 assert(index < bt->sizes[group]);
633 bt->used_mask[group] |= 1ull << index;
634 } else {
635 /* There's an indirect usage, we need all the surfaces. */
636 bt->used_mask[group] = BITFIELD64_MASK(bt->sizes[group]);
637 }
638 }
639
640 static bool
641 skip_compacting_binding_tables(void)
642 {
643 static int skip = -1;
644 if (skip < 0)
645 skip = env_var_as_boolean("INTEL_DISABLE_COMPACT_BINDING_TABLE", false);
646 return skip;
647 }
648
649 /**
650 * Set up the binding table indices and apply to the shader.
651 */
652 static void
653 iris_setup_binding_table(struct nir_shader *nir,
654 struct iris_binding_table *bt,
655 unsigned num_render_targets,
656 unsigned num_system_values,
657 unsigned num_cbufs)
658 {
659 const struct shader_info *info = &nir->info;
660
661 memset(bt, 0, sizeof(*bt));
662
663 /* Set the sizes for each surface group. For some groups, we already know
664 * upfront how many will be used, so mark them.
665 */
666 if (info->stage == MESA_SHADER_FRAGMENT) {
667 bt->sizes[IRIS_SURFACE_GROUP_RENDER_TARGET] = num_render_targets;
668 /* All render targets used. */
669 bt->used_mask[IRIS_SURFACE_GROUP_RENDER_TARGET] =
670 BITFIELD64_MASK(num_render_targets);
671 } else if (info->stage == MESA_SHADER_COMPUTE) {
672 bt->sizes[IRIS_SURFACE_GROUP_CS_WORK_GROUPS] = 1;
673 }
674
675 bt->sizes[IRIS_SURFACE_GROUP_TEXTURE] = util_last_bit(info->textures_used);
676 bt->used_mask[IRIS_SURFACE_GROUP_TEXTURE] = info->textures_used;
677
678 bt->sizes[IRIS_SURFACE_GROUP_IMAGE] = info->num_images;
679
680 /* Allocate an extra slot in the UBO section for NIR constants.
681 * Binding table compaction will remove it if unnecessary.
682 *
683 * We don't include them in iris_compiled_shader::num_cbufs because
684 * they are uploaded separately from shs->constbuf[], but from a shader
685 * point of view, they're another UBO (at the end of the section).
686 */
687 bt->sizes[IRIS_SURFACE_GROUP_UBO] = num_cbufs + 1;
688
689 /* The first IRIS_MAX_ABOs indices in the SSBO group are for atomics, real
690 * SSBOs start after that. Compaction will remove unused ABOs.
691 */
692 bt->sizes[IRIS_SURFACE_GROUP_SSBO] = IRIS_MAX_ABOS + info->num_ssbos;
693
694 for (int i = 0; i < IRIS_SURFACE_GROUP_COUNT; i++)
695 assert(bt->sizes[i] <= SURFACE_GROUP_MAX_ELEMENTS);
696
697 /* Mark surfaces used for the cases we don't have the information available
698 * upfront.
699 */
700 nir_function_impl *impl = nir_shader_get_entrypoint(nir);
701 nir_foreach_block (block, impl) {
702 nir_foreach_instr (instr, block) {
703 if (instr->type != nir_instr_type_intrinsic)
704 continue;
705
706 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
707 switch (intrin->intrinsic) {
708 case nir_intrinsic_load_num_work_groups:
709 bt->used_mask[IRIS_SURFACE_GROUP_CS_WORK_GROUPS] = 1;
710 break;
711
712 case nir_intrinsic_image_size:
713 case nir_intrinsic_image_load:
714 case nir_intrinsic_image_store:
715 case nir_intrinsic_image_atomic_add:
716 case nir_intrinsic_image_atomic_min:
717 case nir_intrinsic_image_atomic_max:
718 case nir_intrinsic_image_atomic_and:
719 case nir_intrinsic_image_atomic_or:
720 case nir_intrinsic_image_atomic_xor:
721 case nir_intrinsic_image_atomic_exchange:
722 case nir_intrinsic_image_atomic_comp_swap:
723 case nir_intrinsic_image_load_raw_intel:
724 case nir_intrinsic_image_store_raw_intel:
725 mark_used_with_src(bt, &intrin->src[0], IRIS_SURFACE_GROUP_IMAGE);
726 break;
727
728 case nir_intrinsic_load_ubo:
729 mark_used_with_src(bt, &intrin->src[0], IRIS_SURFACE_GROUP_UBO);
730 break;
731
732 case nir_intrinsic_store_ssbo:
733 mark_used_with_src(bt, &intrin->src[1], IRIS_SURFACE_GROUP_SSBO);
734 break;
735
736 case nir_intrinsic_get_buffer_size:
737 case nir_intrinsic_ssbo_atomic_add:
738 case nir_intrinsic_ssbo_atomic_imin:
739 case nir_intrinsic_ssbo_atomic_umin:
740 case nir_intrinsic_ssbo_atomic_imax:
741 case nir_intrinsic_ssbo_atomic_umax:
742 case nir_intrinsic_ssbo_atomic_and:
743 case nir_intrinsic_ssbo_atomic_or:
744 case nir_intrinsic_ssbo_atomic_xor:
745 case nir_intrinsic_ssbo_atomic_exchange:
746 case nir_intrinsic_ssbo_atomic_comp_swap:
747 case nir_intrinsic_ssbo_atomic_fmin:
748 case nir_intrinsic_ssbo_atomic_fmax:
749 case nir_intrinsic_ssbo_atomic_fcomp_swap:
750 case nir_intrinsic_load_ssbo:
751 mark_used_with_src(bt, &intrin->src[0], IRIS_SURFACE_GROUP_SSBO);
752 break;
753
754 default:
755 break;
756 }
757 }
758 }
759
760 /* When disable we just mark everything as used. */
761 if (unlikely(skip_compacting_binding_tables())) {
762 for (int i = 0; i < IRIS_SURFACE_GROUP_COUNT; i++)
763 bt->used_mask[i] = BITFIELD64_MASK(bt->sizes[i]);
764 }
765
766 /* Calculate the offsets and the binding table size based on the used
767 * surfaces. After this point, the functions to go between "group indices"
768 * and binding table indices can be used.
769 */
770 uint32_t next = 0;
771 for (int i = 0; i < IRIS_SURFACE_GROUP_COUNT; i++) {
772 if (bt->used_mask[i] != 0) {
773 bt->offsets[i] = next;
774 next += util_bitcount64(bt->used_mask[i]);
775 }
776 }
777 bt->size_bytes = next * 4;
778
779 if (unlikely(INTEL_DEBUG & DEBUG_BT)) {
780 iris_print_binding_table(stderr, gl_shader_stage_name(info->stage), bt);
781 }
782
783 /* Apply the binding table indices. The backend compiler is not expected
784 * to change those, as we haven't set any of the *_start entries in brw
785 * binding_table.
786 */
787 nir_builder b;
788 nir_builder_init(&b, impl);
789
790 nir_foreach_block (block, impl) {
791 nir_foreach_instr (instr, block) {
792 if (instr->type == nir_instr_type_tex) {
793 nir_tex_instr *tex = nir_instr_as_tex(instr);
794 tex->texture_index =
795 iris_group_index_to_bti(bt, IRIS_SURFACE_GROUP_TEXTURE,
796 tex->texture_index);
797 continue;
798 }
799
800 if (instr->type != nir_instr_type_intrinsic)
801 continue;
802
803 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
804 switch (intrin->intrinsic) {
805 case nir_intrinsic_image_size:
806 case nir_intrinsic_image_load:
807 case nir_intrinsic_image_store:
808 case nir_intrinsic_image_atomic_add:
809 case nir_intrinsic_image_atomic_min:
810 case nir_intrinsic_image_atomic_max:
811 case nir_intrinsic_image_atomic_and:
812 case nir_intrinsic_image_atomic_or:
813 case nir_intrinsic_image_atomic_xor:
814 case nir_intrinsic_image_atomic_exchange:
815 case nir_intrinsic_image_atomic_comp_swap:
816 case nir_intrinsic_image_load_raw_intel:
817 case nir_intrinsic_image_store_raw_intel:
818 rewrite_src_with_bti(&b, bt, instr, &intrin->src[0],
819 IRIS_SURFACE_GROUP_IMAGE);
820 break;
821
822 case nir_intrinsic_load_ubo:
823 rewrite_src_with_bti(&b, bt, instr, &intrin->src[0],
824 IRIS_SURFACE_GROUP_UBO);
825 break;
826
827 case nir_intrinsic_store_ssbo:
828 rewrite_src_with_bti(&b, bt, instr, &intrin->src[1],
829 IRIS_SURFACE_GROUP_SSBO);
830 break;
831
832 case nir_intrinsic_get_buffer_size:
833 case nir_intrinsic_ssbo_atomic_add:
834 case nir_intrinsic_ssbo_atomic_imin:
835 case nir_intrinsic_ssbo_atomic_umin:
836 case nir_intrinsic_ssbo_atomic_imax:
837 case nir_intrinsic_ssbo_atomic_umax:
838 case nir_intrinsic_ssbo_atomic_and:
839 case nir_intrinsic_ssbo_atomic_or:
840 case nir_intrinsic_ssbo_atomic_xor:
841 case nir_intrinsic_ssbo_atomic_exchange:
842 case nir_intrinsic_ssbo_atomic_comp_swap:
843 case nir_intrinsic_ssbo_atomic_fmin:
844 case nir_intrinsic_ssbo_atomic_fmax:
845 case nir_intrinsic_ssbo_atomic_fcomp_swap:
846 case nir_intrinsic_load_ssbo:
847 rewrite_src_with_bti(&b, bt, instr, &intrin->src[0],
848 IRIS_SURFACE_GROUP_SSBO);
849 break;
850
851 default:
852 break;
853 }
854 }
855 }
856 }
857
858 static void
859 iris_debug_recompile(struct iris_context *ice,
860 struct shader_info *info,
861 unsigned program_string_id,
862 const void *key)
863 {
864 struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
865 const struct brw_compiler *c = screen->compiler;
866
867 if (!info)
868 return;
869
870 c->shader_perf_log(&ice->dbg, "Recompiling %s shader for program %s: %s\n",
871 _mesa_shader_stage_to_string(info->stage),
872 info->name ? info->name : "(no identifier)",
873 info->label ? info->label : "");
874
875 const void *old_key =
876 iris_find_previous_compile(ice, info->stage, program_string_id);
877
878 brw_debug_key_recompile(c, &ice->dbg, info->stage, old_key, key);
879 }
880
881
882 /**
883 * Compile a vertex shader, and upload the assembly.
884 */
885 static struct iris_compiled_shader *
886 iris_compile_vs(struct iris_context *ice,
887 struct iris_uncompiled_shader *ish,
888 const struct brw_vs_prog_key *key)
889 {
890 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
891 const struct brw_compiler *compiler = screen->compiler;
892 const struct gen_device_info *devinfo = &screen->devinfo;
893 void *mem_ctx = ralloc_context(NULL);
894 struct brw_vs_prog_data *vs_prog_data =
895 rzalloc(mem_ctx, struct brw_vs_prog_data);
896 struct brw_vue_prog_data *vue_prog_data = &vs_prog_data->base;
897 struct brw_stage_prog_data *prog_data = &vue_prog_data->base;
898 enum brw_param_builtin *system_values;
899 unsigned num_system_values;
900 unsigned num_cbufs;
901
902 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
903
904 if (key->nr_userclip_plane_consts) {
905 nir_function_impl *impl = nir_shader_get_entrypoint(nir);
906 nir_lower_clip_vs(nir, (1 << key->nr_userclip_plane_consts) - 1, true);
907 nir_lower_io_to_temporaries(nir, impl, true, false);
908 nir_lower_global_vars_to_local(nir);
909 nir_lower_vars_to_ssa(nir);
910 nir_shader_gather_info(nir, impl);
911 }
912
913 prog_data->use_alt_mode = ish->use_alt_mode;
914
915 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data, &system_values,
916 &num_system_values, &num_cbufs);
917
918 struct iris_binding_table bt;
919 iris_setup_binding_table(nir, &bt, /* num_render_targets */ 0,
920 num_system_values, num_cbufs);
921
922 brw_nir_analyze_ubo_ranges(compiler, nir, NULL, prog_data->ubo_ranges);
923
924 brw_compute_vue_map(devinfo,
925 &vue_prog_data->vue_map, nir->info.outputs_written,
926 nir->info.separate_shader);
927
928 /* Don't tell the backend about our clip plane constants, we've already
929 * lowered them in NIR and we don't want it doing it again.
930 */
931 struct brw_vs_prog_key key_no_ucp = *key;
932 key_no_ucp.nr_userclip_plane_consts = 0;
933
934 char *error_str = NULL;
935 const unsigned *program =
936 brw_compile_vs(compiler, &ice->dbg, mem_ctx, &key_no_ucp, vs_prog_data,
937 nir, -1, &error_str);
938 if (program == NULL) {
939 dbg_printf("Failed to compile vertex shader: %s\n", error_str);
940 ralloc_free(mem_ctx);
941 return false;
942 }
943
944 if (ish->compiled_once) {
945 iris_debug_recompile(ice, &nir->info, key->program_string_id, key);
946 } else {
947 ish->compiled_once = true;
948 }
949
950 uint32_t *so_decls =
951 ice->vtbl.create_so_decl_list(&ish->stream_output,
952 &vue_prog_data->vue_map);
953
954 struct iris_compiled_shader *shader =
955 iris_upload_shader(ice, IRIS_CACHE_VS, sizeof(*key), key, program,
956 prog_data, so_decls, system_values, num_system_values,
957 num_cbufs, &bt);
958
959 iris_disk_cache_store(screen->disk_cache, ish, shader, key, sizeof(*key));
960
961 ralloc_free(mem_ctx);
962 return shader;
963 }
964
965 /**
966 * Update the current vertex shader variant.
967 *
968 * Fill out the key, look in the cache, compile and bind if needed.
969 */
970 static void
971 iris_update_compiled_vs(struct iris_context *ice)
972 {
973 struct iris_shader_state *shs = &ice->state.shaders[MESA_SHADER_VERTEX];
974 struct iris_uncompiled_shader *ish =
975 ice->shaders.uncompiled[MESA_SHADER_VERTEX];
976 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
977 const struct gen_device_info *devinfo = &screen->devinfo;
978
979 struct brw_vs_prog_key key = { KEY_INIT(devinfo->gen) };
980 ice->vtbl.populate_vs_key(ice, &ish->nir->info, &key);
981
982 struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_VS];
983 struct iris_compiled_shader *shader =
984 iris_find_cached_shader(ice, IRIS_CACHE_VS, sizeof(key), &key);
985
986 if (!shader)
987 shader = iris_disk_cache_retrieve(ice, ish, &key, sizeof(key));
988
989 if (!shader)
990 shader = iris_compile_vs(ice, ish, &key);
991
992 if (old != shader) {
993 ice->shaders.prog[IRIS_CACHE_VS] = shader;
994 ice->state.dirty |= IRIS_DIRTY_VS |
995 IRIS_DIRTY_BINDINGS_VS |
996 IRIS_DIRTY_CONSTANTS_VS |
997 IRIS_DIRTY_VF_SGVS;
998 shs->cbuf0_needs_upload = true;
999
1000 const struct brw_vs_prog_data *vs_prog_data =
1001 (void *) shader->prog_data;
1002 const bool uses_draw_params = vs_prog_data->uses_firstvertex ||
1003 vs_prog_data->uses_baseinstance;
1004 const bool uses_derived_draw_params = vs_prog_data->uses_drawid ||
1005 vs_prog_data->uses_is_indexed_draw;
1006 const bool needs_sgvs_element = uses_draw_params ||
1007 vs_prog_data->uses_instanceid ||
1008 vs_prog_data->uses_vertexid;
1009 bool needs_edge_flag = false;
1010 nir_foreach_variable(var, &ish->nir->inputs) {
1011 if (var->data.location == VERT_ATTRIB_EDGEFLAG)
1012 needs_edge_flag = true;
1013 }
1014
1015 if (ice->state.vs_uses_draw_params != uses_draw_params ||
1016 ice->state.vs_uses_derived_draw_params != uses_derived_draw_params ||
1017 ice->state.vs_needs_edge_flag != needs_edge_flag) {
1018 ice->state.dirty |= IRIS_DIRTY_VERTEX_BUFFERS |
1019 IRIS_DIRTY_VERTEX_ELEMENTS;
1020 }
1021 ice->state.vs_uses_draw_params = uses_draw_params;
1022 ice->state.vs_uses_derived_draw_params = uses_derived_draw_params;
1023 ice->state.vs_needs_sgvs_element = needs_sgvs_element;
1024 ice->state.vs_needs_edge_flag = needs_edge_flag;
1025 }
1026 }
1027
1028 /**
1029 * Get the shader_info for a given stage, or NULL if the stage is disabled.
1030 */
1031 const struct shader_info *
1032 iris_get_shader_info(const struct iris_context *ice, gl_shader_stage stage)
1033 {
1034 const struct iris_uncompiled_shader *ish = ice->shaders.uncompiled[stage];
1035
1036 if (!ish)
1037 return NULL;
1038
1039 const nir_shader *nir = ish->nir;
1040 return &nir->info;
1041 }
1042
1043 /**
1044 * Get the union of TCS output and TES input slots.
1045 *
1046 * TCS and TES need to agree on a common URB entry layout. In particular,
1047 * the data for all patch vertices is stored in a single URB entry (unlike
1048 * GS which has one entry per input vertex). This means that per-vertex
1049 * array indexing needs a stride.
1050 *
1051 * SSO requires locations to match, but doesn't require the number of
1052 * outputs/inputs to match (in fact, the TCS often has extra outputs).
1053 * So, we need to take the extra step of unifying these on the fly.
1054 */
1055 static void
1056 get_unified_tess_slots(const struct iris_context *ice,
1057 uint64_t *per_vertex_slots,
1058 uint32_t *per_patch_slots)
1059 {
1060 const struct shader_info *tcs =
1061 iris_get_shader_info(ice, MESA_SHADER_TESS_CTRL);
1062 const struct shader_info *tes =
1063 iris_get_shader_info(ice, MESA_SHADER_TESS_EVAL);
1064
1065 *per_vertex_slots = tes->inputs_read;
1066 *per_patch_slots = tes->patch_inputs_read;
1067
1068 if (tcs) {
1069 *per_vertex_slots |= tcs->outputs_written;
1070 *per_patch_slots |= tcs->patch_outputs_written;
1071 }
1072 }
1073
1074 /**
1075 * Compile a tessellation control shader, and upload the assembly.
1076 */
1077 static struct iris_compiled_shader *
1078 iris_compile_tcs(struct iris_context *ice,
1079 struct iris_uncompiled_shader *ish,
1080 const struct brw_tcs_prog_key *key)
1081 {
1082 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1083 const struct brw_compiler *compiler = screen->compiler;
1084 const struct nir_shader_compiler_options *options =
1085 compiler->glsl_compiler_options[MESA_SHADER_TESS_CTRL].NirOptions;
1086 void *mem_ctx = ralloc_context(NULL);
1087 struct brw_tcs_prog_data *tcs_prog_data =
1088 rzalloc(mem_ctx, struct brw_tcs_prog_data);
1089 struct brw_vue_prog_data *vue_prog_data = &tcs_prog_data->base;
1090 struct brw_stage_prog_data *prog_data = &vue_prog_data->base;
1091 enum brw_param_builtin *system_values = NULL;
1092 unsigned num_system_values = 0;
1093 unsigned num_cbufs = 0;
1094
1095 nir_shader *nir;
1096
1097 struct iris_binding_table bt;
1098
1099 if (ish) {
1100 nir = nir_shader_clone(mem_ctx, ish->nir);
1101
1102 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data, &system_values,
1103 &num_system_values, &num_cbufs);
1104 iris_setup_binding_table(nir, &bt, /* num_render_targets */ 0,
1105 num_system_values, num_cbufs);
1106 brw_nir_analyze_ubo_ranges(compiler, nir, NULL, prog_data->ubo_ranges);
1107 } else {
1108 nir = brw_nir_create_passthrough_tcs(mem_ctx, compiler, options, key);
1109
1110 /* Reserve space for passing the default tess levels as constants. */
1111 num_system_values = 8;
1112 system_values =
1113 rzalloc_array(mem_ctx, enum brw_param_builtin, num_system_values);
1114 prog_data->param = rzalloc_array(mem_ctx, uint32_t, num_system_values);
1115 prog_data->nr_params = num_system_values;
1116
1117 if (key->tes_primitive_mode == GL_QUADS) {
1118 for (int i = 0; i < 4; i++)
1119 system_values[7 - i] = BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X + i;
1120
1121 system_values[3] = BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_X;
1122 system_values[2] = BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_Y;
1123 } else if (key->tes_primitive_mode == GL_TRIANGLES) {
1124 for (int i = 0; i < 3; i++)
1125 system_values[7 - i] = BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X + i;
1126
1127 system_values[4] = BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_X;
1128 } else {
1129 assert(key->tes_primitive_mode == GL_ISOLINES);
1130 system_values[7] = BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_Y;
1131 system_values[6] = BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X;
1132 }
1133
1134 /* Manually setup the TCS binding table. */
1135 memset(&bt, 0, sizeof(bt));
1136 bt.sizes[IRIS_SURFACE_GROUP_UBO] = 1;
1137 bt.used_mask[IRIS_SURFACE_GROUP_UBO] = 1;
1138 bt.size_bytes = 4;
1139
1140 prog_data->ubo_ranges[0].length = 1;
1141 }
1142
1143 char *error_str = NULL;
1144 const unsigned *program =
1145 brw_compile_tcs(compiler, &ice->dbg, mem_ctx, key, tcs_prog_data, nir,
1146 -1, &error_str);
1147 if (program == NULL) {
1148 dbg_printf("Failed to compile control shader: %s\n", error_str);
1149 ralloc_free(mem_ctx);
1150 return false;
1151 }
1152
1153 if (ish) {
1154 if (ish->compiled_once) {
1155 iris_debug_recompile(ice, &nir->info, key->program_string_id, key);
1156 } else {
1157 ish->compiled_once = true;
1158 }
1159 }
1160
1161 struct iris_compiled_shader *shader =
1162 iris_upload_shader(ice, IRIS_CACHE_TCS, sizeof(*key), key, program,
1163 prog_data, NULL, system_values, num_system_values,
1164 num_cbufs, &bt);
1165
1166 if (ish)
1167 iris_disk_cache_store(screen->disk_cache, ish, shader, key, sizeof(*key));
1168
1169 ralloc_free(mem_ctx);
1170 return shader;
1171 }
1172
1173 /**
1174 * Update the current tessellation control shader variant.
1175 *
1176 * Fill out the key, look in the cache, compile and bind if needed.
1177 */
1178 static void
1179 iris_update_compiled_tcs(struct iris_context *ice)
1180 {
1181 struct iris_shader_state *shs = &ice->state.shaders[MESA_SHADER_TESS_CTRL];
1182 struct iris_uncompiled_shader *tcs =
1183 ice->shaders.uncompiled[MESA_SHADER_TESS_CTRL];
1184 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1185 const struct gen_device_info *devinfo = &screen->devinfo;
1186
1187 const struct shader_info *tes_info =
1188 iris_get_shader_info(ice, MESA_SHADER_TESS_EVAL);
1189 struct brw_tcs_prog_key key = {
1190 KEY_INIT_NO_ID(devinfo->gen),
1191 .program_string_id = tcs ? tcs->program_id : 0,
1192 .tes_primitive_mode = tes_info->tess.primitive_mode,
1193 .input_vertices = ice->state.vertices_per_patch,
1194 };
1195 get_unified_tess_slots(ice, &key.outputs_written,
1196 &key.patch_outputs_written);
1197 ice->vtbl.populate_tcs_key(ice, &key);
1198
1199 struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_TCS];
1200 struct iris_compiled_shader *shader =
1201 iris_find_cached_shader(ice, IRIS_CACHE_TCS, sizeof(key), &key);
1202
1203 if (tcs && !shader)
1204 shader = iris_disk_cache_retrieve(ice, tcs, &key, sizeof(key));
1205
1206 if (!shader)
1207 shader = iris_compile_tcs(ice, tcs, &key);
1208
1209 if (old != shader) {
1210 ice->shaders.prog[IRIS_CACHE_TCS] = shader;
1211 ice->state.dirty |= IRIS_DIRTY_TCS |
1212 IRIS_DIRTY_BINDINGS_TCS |
1213 IRIS_DIRTY_CONSTANTS_TCS;
1214 shs->cbuf0_needs_upload = true;
1215
1216 if (!tcs) {
1217 /* We're binding a passthrough TCS, which doesn't have uniforms.
1218 * Since there's no actual TCS, the state tracker doesn't bother
1219 * to call set_constant_buffers to clear stale constant buffers.
1220 *
1221 * We do upload TCS constants for the default tesslevel system
1222 * values, however. In this case, we would see stale constant
1223 * data and try and read a dangling cbuf0->user_buffer pointer.
1224 * Just zero out the stale constants to avoid the upload.
1225 */
1226 memset(&shs->cbuf0, 0, sizeof(shs->cbuf0));
1227 }
1228 }
1229 }
1230
1231 /**
1232 * Compile a tessellation evaluation shader, and upload the assembly.
1233 */
1234 static struct iris_compiled_shader *
1235 iris_compile_tes(struct iris_context *ice,
1236 struct iris_uncompiled_shader *ish,
1237 const struct brw_tes_prog_key *key)
1238 {
1239 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1240 const struct brw_compiler *compiler = screen->compiler;
1241 void *mem_ctx = ralloc_context(NULL);
1242 struct brw_tes_prog_data *tes_prog_data =
1243 rzalloc(mem_ctx, struct brw_tes_prog_data);
1244 struct brw_vue_prog_data *vue_prog_data = &tes_prog_data->base;
1245 struct brw_stage_prog_data *prog_data = &vue_prog_data->base;
1246 enum brw_param_builtin *system_values;
1247 unsigned num_system_values;
1248 unsigned num_cbufs;
1249
1250 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
1251
1252 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data, &system_values,
1253 &num_system_values, &num_cbufs);
1254
1255 struct iris_binding_table bt;
1256 iris_setup_binding_table(nir, &bt, /* num_render_targets */ 0,
1257 num_system_values, num_cbufs);
1258
1259 brw_nir_analyze_ubo_ranges(compiler, nir, NULL, prog_data->ubo_ranges);
1260
1261 struct brw_vue_map input_vue_map;
1262 brw_compute_tess_vue_map(&input_vue_map, key->inputs_read,
1263 key->patch_inputs_read);
1264
1265 char *error_str = NULL;
1266 const unsigned *program =
1267 brw_compile_tes(compiler, &ice->dbg, mem_ctx, key, &input_vue_map,
1268 tes_prog_data, nir, NULL, -1, &error_str);
1269 if (program == NULL) {
1270 dbg_printf("Failed to compile evaluation shader: %s\n", error_str);
1271 ralloc_free(mem_ctx);
1272 return false;
1273 }
1274
1275 if (ish->compiled_once) {
1276 iris_debug_recompile(ice, &nir->info, key->program_string_id, key);
1277 } else {
1278 ish->compiled_once = true;
1279 }
1280
1281 uint32_t *so_decls =
1282 ice->vtbl.create_so_decl_list(&ish->stream_output,
1283 &vue_prog_data->vue_map);
1284
1285
1286 struct iris_compiled_shader *shader =
1287 iris_upload_shader(ice, IRIS_CACHE_TES, sizeof(*key), key, program,
1288 prog_data, so_decls, system_values, num_system_values,
1289 num_cbufs, &bt);
1290
1291 iris_disk_cache_store(screen->disk_cache, ish, shader, key, sizeof(*key));
1292
1293 ralloc_free(mem_ctx);
1294 return shader;
1295 }
1296
1297 /**
1298 * Update the current tessellation evaluation shader variant.
1299 *
1300 * Fill out the key, look in the cache, compile and bind if needed.
1301 */
1302 static void
1303 iris_update_compiled_tes(struct iris_context *ice)
1304 {
1305 struct iris_shader_state *shs = &ice->state.shaders[MESA_SHADER_TESS_EVAL];
1306 struct iris_uncompiled_shader *ish =
1307 ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL];
1308 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1309 const struct gen_device_info *devinfo = &screen->devinfo;
1310
1311 struct brw_tes_prog_key key = { KEY_INIT(devinfo->gen) };
1312 get_unified_tess_slots(ice, &key.inputs_read, &key.patch_inputs_read);
1313 ice->vtbl.populate_tes_key(ice, &key);
1314
1315 struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_TES];
1316 struct iris_compiled_shader *shader =
1317 iris_find_cached_shader(ice, IRIS_CACHE_TES, sizeof(key), &key);
1318
1319 if (!shader)
1320 shader = iris_disk_cache_retrieve(ice, ish, &key, sizeof(key));
1321
1322 if (!shader)
1323 shader = iris_compile_tes(ice, ish, &key);
1324
1325 if (old != shader) {
1326 ice->shaders.prog[IRIS_CACHE_TES] = shader;
1327 ice->state.dirty |= IRIS_DIRTY_TES |
1328 IRIS_DIRTY_BINDINGS_TES |
1329 IRIS_DIRTY_CONSTANTS_TES;
1330 shs->cbuf0_needs_upload = true;
1331 }
1332
1333 /* TODO: Could compare and avoid flagging this. */
1334 const struct shader_info *tes_info = &ish->nir->info;
1335 if (tes_info->system_values_read & (1ull << SYSTEM_VALUE_VERTICES_IN)) {
1336 ice->state.dirty |= IRIS_DIRTY_CONSTANTS_TES;
1337 ice->state.shaders[MESA_SHADER_TESS_EVAL].cbuf0_needs_upload = true;
1338 }
1339 }
1340
1341 /**
1342 * Compile a geometry shader, and upload the assembly.
1343 */
1344 static struct iris_compiled_shader *
1345 iris_compile_gs(struct iris_context *ice,
1346 struct iris_uncompiled_shader *ish,
1347 const struct brw_gs_prog_key *key)
1348 {
1349 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1350 const struct brw_compiler *compiler = screen->compiler;
1351 const struct gen_device_info *devinfo = &screen->devinfo;
1352 void *mem_ctx = ralloc_context(NULL);
1353 struct brw_gs_prog_data *gs_prog_data =
1354 rzalloc(mem_ctx, struct brw_gs_prog_data);
1355 struct brw_vue_prog_data *vue_prog_data = &gs_prog_data->base;
1356 struct brw_stage_prog_data *prog_data = &vue_prog_data->base;
1357 enum brw_param_builtin *system_values;
1358 unsigned num_system_values;
1359 unsigned num_cbufs;
1360
1361 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
1362
1363 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data, &system_values,
1364 &num_system_values, &num_cbufs);
1365
1366 struct iris_binding_table bt;
1367 iris_setup_binding_table(nir, &bt, /* num_render_targets */ 0,
1368 num_system_values, num_cbufs);
1369
1370 brw_nir_analyze_ubo_ranges(compiler, nir, NULL, prog_data->ubo_ranges);
1371
1372 brw_compute_vue_map(devinfo,
1373 &vue_prog_data->vue_map, nir->info.outputs_written,
1374 nir->info.separate_shader);
1375
1376 char *error_str = NULL;
1377 const unsigned *program =
1378 brw_compile_gs(compiler, &ice->dbg, mem_ctx, key, gs_prog_data, nir,
1379 NULL, -1, &error_str);
1380 if (program == NULL) {
1381 dbg_printf("Failed to compile geometry shader: %s\n", error_str);
1382 ralloc_free(mem_ctx);
1383 return false;
1384 }
1385
1386 if (ish->compiled_once) {
1387 iris_debug_recompile(ice, &nir->info, key->program_string_id, key);
1388 } else {
1389 ish->compiled_once = true;
1390 }
1391
1392 uint32_t *so_decls =
1393 ice->vtbl.create_so_decl_list(&ish->stream_output,
1394 &vue_prog_data->vue_map);
1395
1396 struct iris_compiled_shader *shader =
1397 iris_upload_shader(ice, IRIS_CACHE_GS, sizeof(*key), key, program,
1398 prog_data, so_decls, system_values, num_system_values,
1399 num_cbufs, &bt);
1400
1401 iris_disk_cache_store(screen->disk_cache, ish, shader, key, sizeof(*key));
1402
1403 ralloc_free(mem_ctx);
1404 return shader;
1405 }
1406
1407 /**
1408 * Update the current geometry shader variant.
1409 *
1410 * Fill out the key, look in the cache, compile and bind if needed.
1411 */
1412 static void
1413 iris_update_compiled_gs(struct iris_context *ice)
1414 {
1415 struct iris_shader_state *shs = &ice->state.shaders[MESA_SHADER_GEOMETRY];
1416 struct iris_uncompiled_shader *ish =
1417 ice->shaders.uncompiled[MESA_SHADER_GEOMETRY];
1418 struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_GS];
1419 struct iris_compiled_shader *shader = NULL;
1420
1421 if (ish) {
1422 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1423 const struct gen_device_info *devinfo = &screen->devinfo;
1424 struct brw_gs_prog_key key = { KEY_INIT(devinfo->gen) };
1425 ice->vtbl.populate_gs_key(ice, &key);
1426
1427 shader =
1428 iris_find_cached_shader(ice, IRIS_CACHE_GS, sizeof(key), &key);
1429
1430 if (!shader)
1431 shader = iris_disk_cache_retrieve(ice, ish, &key, sizeof(key));
1432
1433 if (!shader)
1434 shader = iris_compile_gs(ice, ish, &key);
1435 }
1436
1437 if (old != shader) {
1438 ice->shaders.prog[IRIS_CACHE_GS] = shader;
1439 ice->state.dirty |= IRIS_DIRTY_GS |
1440 IRIS_DIRTY_BINDINGS_GS |
1441 IRIS_DIRTY_CONSTANTS_GS;
1442 shs->cbuf0_needs_upload = true;
1443 }
1444 }
1445
1446 /**
1447 * Compile a fragment (pixel) shader, and upload the assembly.
1448 */
1449 static struct iris_compiled_shader *
1450 iris_compile_fs(struct iris_context *ice,
1451 struct iris_uncompiled_shader *ish,
1452 const struct brw_wm_prog_key *key,
1453 struct brw_vue_map *vue_map)
1454 {
1455 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1456 const struct brw_compiler *compiler = screen->compiler;
1457 void *mem_ctx = ralloc_context(NULL);
1458 struct brw_wm_prog_data *fs_prog_data =
1459 rzalloc(mem_ctx, struct brw_wm_prog_data);
1460 struct brw_stage_prog_data *prog_data = &fs_prog_data->base;
1461 enum brw_param_builtin *system_values;
1462 unsigned num_system_values;
1463 unsigned num_cbufs;
1464
1465 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
1466
1467 prog_data->use_alt_mode = ish->use_alt_mode;
1468
1469 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data, &system_values,
1470 &num_system_values, &num_cbufs);
1471
1472 struct iris_binding_table bt;
1473 iris_setup_binding_table(nir, &bt, MAX2(key->nr_color_regions, 1),
1474 num_system_values, num_cbufs);
1475
1476 brw_nir_analyze_ubo_ranges(compiler, nir, NULL, prog_data->ubo_ranges);
1477
1478 char *error_str = NULL;
1479 const unsigned *program =
1480 brw_compile_fs(compiler, &ice->dbg, mem_ctx, key, fs_prog_data,
1481 nir, NULL, -1, -1, -1, true, false, vue_map, &error_str);
1482 if (program == NULL) {
1483 dbg_printf("Failed to compile fragment shader: %s\n", error_str);
1484 ralloc_free(mem_ctx);
1485 return false;
1486 }
1487
1488 if (ish->compiled_once) {
1489 iris_debug_recompile(ice, &nir->info, key->program_string_id, key);
1490 } else {
1491 ish->compiled_once = true;
1492 }
1493
1494 struct iris_compiled_shader *shader =
1495 iris_upload_shader(ice, IRIS_CACHE_FS, sizeof(*key), key, program,
1496 prog_data, NULL, system_values, num_system_values,
1497 num_cbufs, &bt);
1498
1499 iris_disk_cache_store(screen->disk_cache, ish, shader, key, sizeof(*key));
1500
1501 ralloc_free(mem_ctx);
1502 return shader;
1503 }
1504
1505 /**
1506 * Update the current fragment shader variant.
1507 *
1508 * Fill out the key, look in the cache, compile and bind if needed.
1509 */
1510 static void
1511 iris_update_compiled_fs(struct iris_context *ice)
1512 {
1513 struct iris_shader_state *shs = &ice->state.shaders[MESA_SHADER_FRAGMENT];
1514 struct iris_uncompiled_shader *ish =
1515 ice->shaders.uncompiled[MESA_SHADER_FRAGMENT];
1516 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1517 const struct gen_device_info *devinfo = &screen->devinfo;
1518 struct brw_wm_prog_key key = { KEY_INIT(devinfo->gen) };
1519 ice->vtbl.populate_fs_key(ice, &key);
1520
1521 if (ish->nos & (1ull << IRIS_NOS_LAST_VUE_MAP))
1522 key.input_slots_valid = ice->shaders.last_vue_map->slots_valid;
1523
1524 struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_FS];
1525 struct iris_compiled_shader *shader =
1526 iris_find_cached_shader(ice, IRIS_CACHE_FS, sizeof(key), &key);
1527
1528 if (!shader)
1529 shader = iris_disk_cache_retrieve(ice, ish, &key, sizeof(key));
1530
1531 if (!shader)
1532 shader = iris_compile_fs(ice, ish, &key, ice->shaders.last_vue_map);
1533
1534 if (old != shader) {
1535 // XXX: only need to flag CLIP if barycentric has NONPERSPECTIVE
1536 // toggles. might be able to avoid flagging SBE too.
1537 ice->shaders.prog[IRIS_CACHE_FS] = shader;
1538 ice->state.dirty |= IRIS_DIRTY_FS |
1539 IRIS_DIRTY_BINDINGS_FS |
1540 IRIS_DIRTY_CONSTANTS_FS |
1541 IRIS_DIRTY_WM |
1542 IRIS_DIRTY_CLIP |
1543 IRIS_DIRTY_SBE;
1544 shs->cbuf0_needs_upload = true;
1545 }
1546 }
1547
1548 /**
1549 * Get the compiled shader for the last enabled geometry stage.
1550 *
1551 * This stage is the one which will feed stream output and the rasterizer.
1552 */
1553 static gl_shader_stage
1554 last_vue_stage(struct iris_context *ice)
1555 {
1556 if (ice->shaders.prog[MESA_SHADER_GEOMETRY])
1557 return MESA_SHADER_GEOMETRY;
1558
1559 if (ice->shaders.prog[MESA_SHADER_TESS_EVAL])
1560 return MESA_SHADER_TESS_EVAL;
1561
1562 return MESA_SHADER_VERTEX;
1563 }
1564
1565 /**
1566 * Update the last enabled stage's VUE map.
1567 *
1568 * When the shader feeding the rasterizer's output interface changes, we
1569 * need to re-emit various packets.
1570 */
1571 static void
1572 update_last_vue_map(struct iris_context *ice,
1573 struct brw_stage_prog_data *prog_data)
1574 {
1575 struct brw_vue_prog_data *vue_prog_data = (void *) prog_data;
1576 struct brw_vue_map *vue_map = &vue_prog_data->vue_map;
1577 struct brw_vue_map *old_map = ice->shaders.last_vue_map;
1578 const uint64_t changed_slots =
1579 (old_map ? old_map->slots_valid : 0ull) ^ vue_map->slots_valid;
1580
1581 if (changed_slots & VARYING_BIT_VIEWPORT) {
1582 // XXX: could use ctx->Const.MaxViewports for old API efficiency
1583 ice->state.num_viewports =
1584 (vue_map->slots_valid & VARYING_BIT_VIEWPORT) ? IRIS_MAX_VIEWPORTS : 1;
1585 ice->state.dirty |= IRIS_DIRTY_CLIP |
1586 IRIS_DIRTY_SF_CL_VIEWPORT |
1587 IRIS_DIRTY_CC_VIEWPORT |
1588 IRIS_DIRTY_SCISSOR_RECT |
1589 IRIS_DIRTY_UNCOMPILED_FS |
1590 ice->state.dirty_for_nos[IRIS_NOS_LAST_VUE_MAP];
1591 // XXX: CC_VIEWPORT?
1592 }
1593
1594 if (changed_slots || (old_map && old_map->separate != vue_map->separate)) {
1595 ice->state.dirty |= IRIS_DIRTY_SBE;
1596 }
1597
1598 ice->shaders.last_vue_map = &vue_prog_data->vue_map;
1599 }
1600
1601 /**
1602 * Get the prog_data for a given stage, or NULL if the stage is disabled.
1603 */
1604 static struct brw_vue_prog_data *
1605 get_vue_prog_data(struct iris_context *ice, gl_shader_stage stage)
1606 {
1607 if (!ice->shaders.prog[stage])
1608 return NULL;
1609
1610 return (void *) ice->shaders.prog[stage]->prog_data;
1611 }
1612
1613 // XXX: iris_compiled_shaders are space-leaking :(
1614 // XXX: do remember to unbind them if deleting them.
1615
1616 /**
1617 * Update the current shader variants for the given state.
1618 *
1619 * This should be called on every draw call to ensure that the correct
1620 * shaders are bound. It will also flag any dirty state triggered by
1621 * swapping out those shaders.
1622 */
1623 void
1624 iris_update_compiled_shaders(struct iris_context *ice)
1625 {
1626 const uint64_t dirty = ice->state.dirty;
1627
1628 struct brw_vue_prog_data *old_prog_datas[4];
1629 if (!(dirty & IRIS_DIRTY_URB)) {
1630 for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++)
1631 old_prog_datas[i] = get_vue_prog_data(ice, i);
1632 }
1633
1634 if (dirty & (IRIS_DIRTY_UNCOMPILED_TCS | IRIS_DIRTY_UNCOMPILED_TES)) {
1635 struct iris_uncompiled_shader *tes =
1636 ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL];
1637 if (tes) {
1638 iris_update_compiled_tcs(ice);
1639 iris_update_compiled_tes(ice);
1640 } else {
1641 ice->shaders.prog[IRIS_CACHE_TCS] = NULL;
1642 ice->shaders.prog[IRIS_CACHE_TES] = NULL;
1643 ice->state.dirty |=
1644 IRIS_DIRTY_TCS | IRIS_DIRTY_TES |
1645 IRIS_DIRTY_BINDINGS_TCS | IRIS_DIRTY_BINDINGS_TES |
1646 IRIS_DIRTY_CONSTANTS_TCS | IRIS_DIRTY_CONSTANTS_TES;
1647 }
1648 }
1649
1650 if (dirty & IRIS_DIRTY_UNCOMPILED_VS)
1651 iris_update_compiled_vs(ice);
1652 if (dirty & IRIS_DIRTY_UNCOMPILED_GS)
1653 iris_update_compiled_gs(ice);
1654
1655 if (dirty & (IRIS_DIRTY_UNCOMPILED_GS | IRIS_DIRTY_UNCOMPILED_TES)) {
1656 const struct iris_compiled_shader *gs =
1657 ice->shaders.prog[MESA_SHADER_GEOMETRY];
1658 const struct iris_compiled_shader *tes =
1659 ice->shaders.prog[MESA_SHADER_TESS_EVAL];
1660
1661 bool points_or_lines = false;
1662
1663 if (gs) {
1664 const struct brw_gs_prog_data *gs_prog_data = (void *) gs->prog_data;
1665 points_or_lines =
1666 gs_prog_data->output_topology == _3DPRIM_POINTLIST ||
1667 gs_prog_data->output_topology == _3DPRIM_LINESTRIP;
1668 } else if (tes) {
1669 const struct brw_tes_prog_data *tes_data = (void *) tes->prog_data;
1670 points_or_lines =
1671 tes_data->output_topology == BRW_TESS_OUTPUT_TOPOLOGY_LINE ||
1672 tes_data->output_topology == BRW_TESS_OUTPUT_TOPOLOGY_POINT;
1673 }
1674
1675 if (ice->shaders.output_topology_is_points_or_lines != points_or_lines) {
1676 /* Outbound to XY Clip enables */
1677 ice->shaders.output_topology_is_points_or_lines = points_or_lines;
1678 ice->state.dirty |= IRIS_DIRTY_CLIP;
1679 }
1680 }
1681
1682 gl_shader_stage last_stage = last_vue_stage(ice);
1683 struct iris_compiled_shader *shader = ice->shaders.prog[last_stage];
1684 struct iris_uncompiled_shader *ish = ice->shaders.uncompiled[last_stage];
1685 update_last_vue_map(ice, shader->prog_data);
1686 if (ice->state.streamout != shader->streamout) {
1687 ice->state.streamout = shader->streamout;
1688 ice->state.dirty |= IRIS_DIRTY_SO_DECL_LIST | IRIS_DIRTY_STREAMOUT;
1689 }
1690
1691 if (ice->state.streamout_active) {
1692 for (int i = 0; i < PIPE_MAX_SO_BUFFERS; i++) {
1693 struct iris_stream_output_target *so =
1694 (void *) ice->state.so_target[i];
1695 if (so)
1696 so->stride = ish->stream_output.stride[i] * sizeof(uint32_t);
1697 }
1698 }
1699
1700 if (dirty & IRIS_DIRTY_UNCOMPILED_FS)
1701 iris_update_compiled_fs(ice);
1702
1703 /* Changing shader interfaces may require a URB configuration. */
1704 if (!(dirty & IRIS_DIRTY_URB)) {
1705 for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
1706 struct brw_vue_prog_data *old = old_prog_datas[i];
1707 struct brw_vue_prog_data *new = get_vue_prog_data(ice, i);
1708 if (!!old != !!new ||
1709 (new && new->urb_entry_size != old->urb_entry_size)) {
1710 ice->state.dirty |= IRIS_DIRTY_URB;
1711 break;
1712 }
1713 }
1714 }
1715 }
1716
1717 static struct iris_compiled_shader *
1718 iris_compile_cs(struct iris_context *ice,
1719 struct iris_uncompiled_shader *ish,
1720 const struct brw_cs_prog_key *key)
1721 {
1722 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1723 const struct brw_compiler *compiler = screen->compiler;
1724 void *mem_ctx = ralloc_context(NULL);
1725 struct brw_cs_prog_data *cs_prog_data =
1726 rzalloc(mem_ctx, struct brw_cs_prog_data);
1727 struct brw_stage_prog_data *prog_data = &cs_prog_data->base;
1728 enum brw_param_builtin *system_values;
1729 unsigned num_system_values;
1730 unsigned num_cbufs;
1731
1732 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
1733
1734 prog_data->total_shared = nir->info.cs.shared_size;
1735
1736 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data, &system_values,
1737 &num_system_values, &num_cbufs);
1738
1739 struct iris_binding_table bt;
1740 iris_setup_binding_table(nir, &bt, /* num_render_targets */ 0,
1741 num_system_values, num_cbufs);
1742
1743 char *error_str = NULL;
1744 const unsigned *program =
1745 brw_compile_cs(compiler, &ice->dbg, mem_ctx, key, cs_prog_data,
1746 nir, -1, &error_str);
1747 if (program == NULL) {
1748 dbg_printf("Failed to compile compute shader: %s\n", error_str);
1749 ralloc_free(mem_ctx);
1750 return false;
1751 }
1752
1753 if (ish->compiled_once) {
1754 iris_debug_recompile(ice, &nir->info, key->program_string_id, key);
1755 } else {
1756 ish->compiled_once = true;
1757 }
1758
1759 struct iris_compiled_shader *shader =
1760 iris_upload_shader(ice, IRIS_CACHE_CS, sizeof(*key), key, program,
1761 prog_data, NULL, system_values, num_system_values,
1762 num_cbufs, &bt);
1763
1764 iris_disk_cache_store(screen->disk_cache, ish, shader, key, sizeof(*key));
1765
1766 ralloc_free(mem_ctx);
1767 return shader;
1768 }
1769
1770 void
1771 iris_update_compiled_compute_shader(struct iris_context *ice)
1772 {
1773 struct iris_shader_state *shs = &ice->state.shaders[MESA_SHADER_COMPUTE];
1774 struct iris_uncompiled_shader *ish =
1775 ice->shaders.uncompiled[MESA_SHADER_COMPUTE];
1776
1777 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1778 const struct gen_device_info *devinfo = &screen->devinfo;
1779 struct brw_cs_prog_key key = { KEY_INIT(devinfo->gen) };
1780 ice->vtbl.populate_cs_key(ice, &key);
1781
1782 struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_CS];
1783 struct iris_compiled_shader *shader =
1784 iris_find_cached_shader(ice, IRIS_CACHE_CS, sizeof(key), &key);
1785
1786 if (!shader)
1787 shader = iris_disk_cache_retrieve(ice, ish, &key, sizeof(key));
1788
1789 if (!shader)
1790 shader = iris_compile_cs(ice, ish, &key);
1791
1792 if (old != shader) {
1793 ice->shaders.prog[IRIS_CACHE_CS] = shader;
1794 ice->state.dirty |= IRIS_DIRTY_CS |
1795 IRIS_DIRTY_BINDINGS_CS |
1796 IRIS_DIRTY_CONSTANTS_CS;
1797 shs->cbuf0_needs_upload = true;
1798 }
1799 }
1800
1801 void
1802 iris_fill_cs_push_const_buffer(struct brw_cs_prog_data *cs_prog_data,
1803 uint32_t *dst)
1804 {
1805 assert(cs_prog_data->push.total.size > 0);
1806 assert(cs_prog_data->push.cross_thread.size == 0);
1807 assert(cs_prog_data->push.per_thread.dwords == 1);
1808 assert(cs_prog_data->base.param[0] == BRW_PARAM_BUILTIN_SUBGROUP_ID);
1809 for (unsigned t = 0; t < cs_prog_data->threads; t++)
1810 dst[8 * t] = t;
1811 }
1812
1813 /**
1814 * Allocate scratch BOs as needed for the given per-thread size and stage.
1815 */
1816 struct iris_bo *
1817 iris_get_scratch_space(struct iris_context *ice,
1818 unsigned per_thread_scratch,
1819 gl_shader_stage stage)
1820 {
1821 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1822 struct iris_bufmgr *bufmgr = screen->bufmgr;
1823 const struct gen_device_info *devinfo = &screen->devinfo;
1824
1825 unsigned encoded_size = ffs(per_thread_scratch) - 11;
1826 assert(encoded_size < (1 << 16));
1827
1828 struct iris_bo **bop = &ice->shaders.scratch_bos[encoded_size][stage];
1829
1830 /* The documentation for 3DSTATE_PS "Scratch Space Base Pointer" says:
1831 *
1832 * "Scratch Space per slice is computed based on 4 sub-slices. SW
1833 * must allocate scratch space enough so that each slice has 4
1834 * slices allowed."
1835 *
1836 * According to the other driver team, this applies to compute shaders
1837 * as well. This is not currently documented at all.
1838 *
1839 * This hack is no longer necessary on Gen11+.
1840 */
1841 unsigned subslice_total = screen->subslice_total;
1842 if (devinfo->gen < 11)
1843 subslice_total = 4 * devinfo->num_slices;
1844 assert(subslice_total >= screen->subslice_total);
1845
1846 if (!*bop) {
1847 unsigned scratch_ids_per_subslice = devinfo->max_cs_threads;
1848 uint32_t max_threads[] = {
1849 [MESA_SHADER_VERTEX] = devinfo->max_vs_threads,
1850 [MESA_SHADER_TESS_CTRL] = devinfo->max_tcs_threads,
1851 [MESA_SHADER_TESS_EVAL] = devinfo->max_tes_threads,
1852 [MESA_SHADER_GEOMETRY] = devinfo->max_gs_threads,
1853 [MESA_SHADER_FRAGMENT] = devinfo->max_wm_threads,
1854 [MESA_SHADER_COMPUTE] = scratch_ids_per_subslice * subslice_total,
1855 };
1856
1857 uint32_t size = per_thread_scratch * max_threads[stage];
1858
1859 *bop = iris_bo_alloc(bufmgr, "scratch", size, IRIS_MEMZONE_SHADER);
1860 }
1861
1862 return *bop;
1863 }
1864
1865 /* ------------------------------------------------------------------- */
1866
1867 /**
1868 * The pipe->create_[stage]_state() driver hooks.
1869 *
1870 * Performs basic NIR preprocessing, records any state dependencies, and
1871 * returns an iris_uncompiled_shader as the Gallium CSO.
1872 *
1873 * Actual shader compilation to assembly happens later, at first use.
1874 */
1875 static void *
1876 iris_create_uncompiled_shader(struct pipe_context *ctx,
1877 nir_shader *nir,
1878 const struct pipe_stream_output_info *so_info)
1879 {
1880 struct iris_context *ice = (void *)ctx;
1881 struct iris_screen *screen = (struct iris_screen *)ctx->screen;
1882 const struct gen_device_info *devinfo = &screen->devinfo;
1883
1884 struct iris_uncompiled_shader *ish =
1885 calloc(1, sizeof(struct iris_uncompiled_shader));
1886 if (!ish)
1887 return NULL;
1888
1889 brw_preprocess_nir(screen->compiler, nir, NULL);
1890
1891 NIR_PASS_V(nir, brw_nir_lower_image_load_store, devinfo);
1892 NIR_PASS_V(nir, iris_lower_storage_image_derefs);
1893
1894 nir_sweep(nir);
1895
1896 if (nir->constant_data_size > 0) {
1897 unsigned data_offset;
1898 u_upload_data(ice->shaders.uploader, 0, nir->constant_data_size,
1899 32, nir->constant_data, &data_offset, &ish->const_data);
1900
1901 struct pipe_shader_buffer psb = {
1902 .buffer = ish->const_data,
1903 .buffer_offset = data_offset,
1904 .buffer_size = nir->constant_data_size,
1905 };
1906 iris_upload_ubo_ssbo_surf_state(ice, &psb, &ish->const_data_state, false);
1907 }
1908
1909 ish->program_id = get_new_program_id(screen);
1910 ish->nir = nir;
1911 if (so_info) {
1912 memcpy(&ish->stream_output, so_info, sizeof(*so_info));
1913 update_so_info(&ish->stream_output, nir->info.outputs_written);
1914 }
1915
1916 /* Save this now before potentially dropping nir->info.name */
1917 if (nir->info.name && strncmp(nir->info.name, "ARB", 3) == 0)
1918 ish->use_alt_mode = true;
1919
1920 if (screen->disk_cache) {
1921 /* Serialize the NIR to a binary blob that we can hash for the disk
1922 * cache. First, drop unnecessary information (like variable names)
1923 * so the serialized NIR is smaller, and also to let us detect more
1924 * isomorphic shaders when hashing, increasing cache hits. We clone
1925 * the NIR before stripping away this info because it can be useful
1926 * when inspecting and debugging shaders.
1927 */
1928 nir_shader *clone = nir_shader_clone(NULL, nir);
1929 nir_strip(clone);
1930
1931 struct blob blob;
1932 blob_init(&blob);
1933 nir_serialize(&blob, clone);
1934 _mesa_sha1_compute(blob.data, blob.size, ish->nir_sha1);
1935 blob_finish(&blob);
1936
1937 ralloc_free(clone);
1938 }
1939
1940 return ish;
1941 }
1942
1943 static struct iris_uncompiled_shader *
1944 iris_create_shader_state(struct pipe_context *ctx,
1945 const struct pipe_shader_state *state)
1946 {
1947 struct nir_shader *nir;
1948
1949 if (state->type == PIPE_SHADER_IR_TGSI)
1950 nir = tgsi_to_nir(state->tokens, ctx->screen);
1951 else
1952 nir = state->ir.nir;
1953
1954 return iris_create_uncompiled_shader(ctx, nir, &state->stream_output);
1955 }
1956
1957 static void *
1958 iris_create_vs_state(struct pipe_context *ctx,
1959 const struct pipe_shader_state *state)
1960 {
1961 struct iris_context *ice = (void *) ctx;
1962 struct iris_screen *screen = (void *) ctx->screen;
1963 struct iris_uncompiled_shader *ish = iris_create_shader_state(ctx, state);
1964
1965 /* User clip planes */
1966 if (ish->nir->info.clip_distance_array_size == 0)
1967 ish->nos |= (1ull << IRIS_NOS_RASTERIZER);
1968
1969 if (screen->precompile) {
1970 const struct gen_device_info *devinfo = &screen->devinfo;
1971 struct brw_vs_prog_key key = { KEY_INIT(devinfo->gen) };
1972
1973 if (!iris_disk_cache_retrieve(ice, ish, &key, sizeof(key)))
1974 iris_compile_vs(ice, ish, &key);
1975 }
1976
1977 return ish;
1978 }
1979
1980 static void *
1981 iris_create_tcs_state(struct pipe_context *ctx,
1982 const struct pipe_shader_state *state)
1983 {
1984 struct iris_context *ice = (void *) ctx;
1985 struct iris_screen *screen = (void *) ctx->screen;
1986 const struct brw_compiler *compiler = screen->compiler;
1987 struct iris_uncompiled_shader *ish = iris_create_shader_state(ctx, state);
1988 struct shader_info *info = &ish->nir->info;
1989
1990 // XXX: NOS?
1991
1992 if (screen->precompile) {
1993 const unsigned _GL_TRIANGLES = 0x0004;
1994 const struct gen_device_info *devinfo = &screen->devinfo;
1995 struct brw_tcs_prog_key key = {
1996 KEY_INIT(devinfo->gen),
1997 // XXX: make sure the linker fills this out from the TES...
1998 .tes_primitive_mode =
1999 info->tess.primitive_mode ? info->tess.primitive_mode
2000 : _GL_TRIANGLES,
2001 .outputs_written = info->outputs_written,
2002 .patch_outputs_written = info->patch_outputs_written,
2003 };
2004
2005 /* 8_PATCH mode needs the key to contain the input patch dimensionality.
2006 * We don't have that information, so we randomly guess that the input
2007 * and output patches are the same size. This is a bad guess, but we
2008 * can't do much better.
2009 */
2010 if (compiler->use_tcs_8_patch)
2011 key.input_vertices = info->tess.tcs_vertices_out;
2012
2013 if (!iris_disk_cache_retrieve(ice, ish, &key, sizeof(key)))
2014 iris_compile_tcs(ice, ish, &key);
2015 }
2016
2017 return ish;
2018 }
2019
2020 static void *
2021 iris_create_tes_state(struct pipe_context *ctx,
2022 const struct pipe_shader_state *state)
2023 {
2024 struct iris_context *ice = (void *) ctx;
2025 struct iris_screen *screen = (void *) ctx->screen;
2026 struct iris_uncompiled_shader *ish = iris_create_shader_state(ctx, state);
2027 struct shader_info *info = &ish->nir->info;
2028
2029 // XXX: NOS?
2030
2031 if (screen->precompile) {
2032 const struct gen_device_info *devinfo = &screen->devinfo;
2033 struct brw_tes_prog_key key = {
2034 KEY_INIT(devinfo->gen),
2035 // XXX: not ideal, need TCS output/TES input unification
2036 .inputs_read = info->inputs_read,
2037 .patch_inputs_read = info->patch_inputs_read,
2038 };
2039
2040 if (!iris_disk_cache_retrieve(ice, ish, &key, sizeof(key)))
2041 iris_compile_tes(ice, ish, &key);
2042 }
2043
2044 return ish;
2045 }
2046
2047 static void *
2048 iris_create_gs_state(struct pipe_context *ctx,
2049 const struct pipe_shader_state *state)
2050 {
2051 struct iris_context *ice = (void *) ctx;
2052 struct iris_screen *screen = (void *) ctx->screen;
2053 struct iris_uncompiled_shader *ish = iris_create_shader_state(ctx, state);
2054
2055 // XXX: NOS?
2056
2057 if (screen->precompile) {
2058 const struct gen_device_info *devinfo = &screen->devinfo;
2059 struct brw_gs_prog_key key = { KEY_INIT(devinfo->gen) };
2060
2061 if (!iris_disk_cache_retrieve(ice, ish, &key, sizeof(key)))
2062 iris_compile_gs(ice, ish, &key);
2063 }
2064
2065 return ish;
2066 }
2067
2068 static void *
2069 iris_create_fs_state(struct pipe_context *ctx,
2070 const struct pipe_shader_state *state)
2071 {
2072 struct iris_context *ice = (void *) ctx;
2073 struct iris_screen *screen = (void *) ctx->screen;
2074 struct iris_uncompiled_shader *ish = iris_create_shader_state(ctx, state);
2075 struct shader_info *info = &ish->nir->info;
2076
2077 ish->nos |= (1ull << IRIS_NOS_FRAMEBUFFER) |
2078 (1ull << IRIS_NOS_DEPTH_STENCIL_ALPHA) |
2079 (1ull << IRIS_NOS_RASTERIZER) |
2080 (1ull << IRIS_NOS_BLEND);
2081
2082 /* The program key needs the VUE map if there are > 16 inputs */
2083 if (util_bitcount64(ish->nir->info.inputs_read &
2084 BRW_FS_VARYING_INPUT_MASK) > 16) {
2085 ish->nos |= (1ull << IRIS_NOS_LAST_VUE_MAP);
2086 }
2087
2088 if (screen->precompile) {
2089 const uint64_t color_outputs = info->outputs_written &
2090 ~(BITFIELD64_BIT(FRAG_RESULT_DEPTH) |
2091 BITFIELD64_BIT(FRAG_RESULT_STENCIL) |
2092 BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK));
2093
2094 bool can_rearrange_varyings =
2095 util_bitcount64(info->inputs_read & BRW_FS_VARYING_INPUT_MASK) <= 16;
2096
2097 const struct gen_device_info *devinfo = &screen->devinfo;
2098 struct brw_wm_prog_key key = {
2099 KEY_INIT(devinfo->gen),
2100 .nr_color_regions = util_bitcount(color_outputs),
2101 .coherent_fb_fetch = true,
2102 .input_slots_valid =
2103 can_rearrange_varyings ? 0 : info->inputs_read | VARYING_BIT_POS,
2104 };
2105
2106 if (!iris_disk_cache_retrieve(ice, ish, &key, sizeof(key)))
2107 iris_compile_fs(ice, ish, &key, NULL);
2108 }
2109
2110 return ish;
2111 }
2112
2113 static void *
2114 iris_create_compute_state(struct pipe_context *ctx,
2115 const struct pipe_compute_state *state)
2116 {
2117 assert(state->ir_type == PIPE_SHADER_IR_NIR);
2118
2119 struct iris_context *ice = (void *) ctx;
2120 struct iris_screen *screen = (void *) ctx->screen;
2121 struct iris_uncompiled_shader *ish =
2122 iris_create_uncompiled_shader(ctx, (void *) state->prog, NULL);
2123
2124 // XXX: disallow more than 64KB of shared variables
2125
2126 if (screen->precompile) {
2127 const struct gen_device_info *devinfo = &screen->devinfo;
2128 struct brw_cs_prog_key key = { KEY_INIT(devinfo->gen) };
2129
2130 if (!iris_disk_cache_retrieve(ice, ish, &key, sizeof(key)))
2131 iris_compile_cs(ice, ish, &key);
2132 }
2133
2134 return ish;
2135 }
2136
2137 /**
2138 * The pipe->delete_[stage]_state() driver hooks.
2139 *
2140 * Frees the iris_uncompiled_shader.
2141 */
2142 static void
2143 iris_delete_shader_state(struct pipe_context *ctx, void *state, gl_shader_stage stage)
2144 {
2145 struct iris_uncompiled_shader *ish = state;
2146 struct iris_context *ice = (void *) ctx;
2147
2148 if (ice->shaders.uncompiled[stage] == ish) {
2149 ice->shaders.uncompiled[stage] = NULL;
2150 ice->state.dirty |= IRIS_DIRTY_UNCOMPILED_VS << stage;
2151 }
2152
2153 if (ish->const_data) {
2154 pipe_resource_reference(&ish->const_data, NULL);
2155 pipe_resource_reference(&ish->const_data_state.res, NULL);
2156 }
2157
2158 ralloc_free(ish->nir);
2159 free(ish);
2160 }
2161
2162 static void
2163 iris_delete_vs_state(struct pipe_context *ctx, void *state)
2164 {
2165 iris_delete_shader_state(ctx, state, MESA_SHADER_VERTEX);
2166 }
2167
2168 static void
2169 iris_delete_tcs_state(struct pipe_context *ctx, void *state)
2170 {
2171 iris_delete_shader_state(ctx, state, MESA_SHADER_TESS_CTRL);
2172 }
2173
2174 static void
2175 iris_delete_tes_state(struct pipe_context *ctx, void *state)
2176 {
2177 iris_delete_shader_state(ctx, state, MESA_SHADER_TESS_EVAL);
2178 }
2179
2180 static void
2181 iris_delete_gs_state(struct pipe_context *ctx, void *state)
2182 {
2183 iris_delete_shader_state(ctx, state, MESA_SHADER_GEOMETRY);
2184 }
2185
2186 static void
2187 iris_delete_fs_state(struct pipe_context *ctx, void *state)
2188 {
2189 iris_delete_shader_state(ctx, state, MESA_SHADER_FRAGMENT);
2190 }
2191
2192 static void
2193 iris_delete_cs_state(struct pipe_context *ctx, void *state)
2194 {
2195 iris_delete_shader_state(ctx, state, MESA_SHADER_COMPUTE);
2196 }
2197
2198 /**
2199 * The pipe->bind_[stage]_state() driver hook.
2200 *
2201 * Binds an uncompiled shader as the current one for a particular stage.
2202 * Updates dirty tracking to account for the shader's NOS.
2203 */
2204 static void
2205 bind_shader_state(struct iris_context *ice,
2206 struct iris_uncompiled_shader *ish,
2207 gl_shader_stage stage)
2208 {
2209 uint64_t dirty_bit = IRIS_DIRTY_UNCOMPILED_VS << stage;
2210 const uint64_t nos = ish ? ish->nos : 0;
2211
2212 const struct shader_info *old_info = iris_get_shader_info(ice, stage);
2213 const struct shader_info *new_info = ish ? &ish->nir->info : NULL;
2214
2215 if ((old_info ? util_last_bit(old_info->textures_used) : 0) !=
2216 (new_info ? util_last_bit(new_info->textures_used) : 0)) {
2217 ice->state.dirty |= IRIS_DIRTY_SAMPLER_STATES_VS << stage;
2218 }
2219
2220 ice->shaders.uncompiled[stage] = ish;
2221 ice->state.dirty |= dirty_bit;
2222
2223 /* Record that CSOs need to mark IRIS_DIRTY_UNCOMPILED_XS when they change
2224 * (or that they no longer need to do so).
2225 */
2226 for (int i = 0; i < IRIS_NOS_COUNT; i++) {
2227 if (nos & (1 << i))
2228 ice->state.dirty_for_nos[i] |= dirty_bit;
2229 else
2230 ice->state.dirty_for_nos[i] &= ~dirty_bit;
2231 }
2232 }
2233
2234 static void
2235 iris_bind_vs_state(struct pipe_context *ctx, void *state)
2236 {
2237 bind_shader_state((void *) ctx, state, MESA_SHADER_VERTEX);
2238 }
2239
2240 static void
2241 iris_bind_tcs_state(struct pipe_context *ctx, void *state)
2242 {
2243 bind_shader_state((void *) ctx, state, MESA_SHADER_TESS_CTRL);
2244 }
2245
2246 static void
2247 iris_bind_tes_state(struct pipe_context *ctx, void *state)
2248 {
2249 struct iris_context *ice = (struct iris_context *)ctx;
2250
2251 /* Enabling/disabling optional stages requires a URB reconfiguration. */
2252 if (!!state != !!ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL])
2253 ice->state.dirty |= IRIS_DIRTY_URB;
2254
2255 bind_shader_state((void *) ctx, state, MESA_SHADER_TESS_EVAL);
2256 }
2257
2258 static void
2259 iris_bind_gs_state(struct pipe_context *ctx, void *state)
2260 {
2261 struct iris_context *ice = (struct iris_context *)ctx;
2262
2263 /* Enabling/disabling optional stages requires a URB reconfiguration. */
2264 if (!!state != !!ice->shaders.uncompiled[MESA_SHADER_GEOMETRY])
2265 ice->state.dirty |= IRIS_DIRTY_URB;
2266
2267 bind_shader_state((void *) ctx, state, MESA_SHADER_GEOMETRY);
2268 }
2269
2270 static void
2271 iris_bind_fs_state(struct pipe_context *ctx, void *state)
2272 {
2273 struct iris_context *ice = (struct iris_context *) ctx;
2274 struct iris_uncompiled_shader *old_ish =
2275 ice->shaders.uncompiled[MESA_SHADER_FRAGMENT];
2276 struct iris_uncompiled_shader *new_ish = state;
2277
2278 const unsigned color_bits =
2279 BITFIELD64_BIT(FRAG_RESULT_COLOR) |
2280 BITFIELD64_RANGE(FRAG_RESULT_DATA0, BRW_MAX_DRAW_BUFFERS);
2281
2282 /* Fragment shader outputs influence HasWriteableRT */
2283 if (!old_ish || !new_ish ||
2284 (old_ish->nir->info.outputs_written & color_bits) !=
2285 (new_ish->nir->info.outputs_written & color_bits))
2286 ice->state.dirty |= IRIS_DIRTY_PS_BLEND;
2287
2288 bind_shader_state((void *) ctx, state, MESA_SHADER_FRAGMENT);
2289 }
2290
2291 static void
2292 iris_bind_cs_state(struct pipe_context *ctx, void *state)
2293 {
2294 bind_shader_state((void *) ctx, state, MESA_SHADER_COMPUTE);
2295 }
2296
2297 void
2298 iris_init_program_functions(struct pipe_context *ctx)
2299 {
2300 ctx->create_vs_state = iris_create_vs_state;
2301 ctx->create_tcs_state = iris_create_tcs_state;
2302 ctx->create_tes_state = iris_create_tes_state;
2303 ctx->create_gs_state = iris_create_gs_state;
2304 ctx->create_fs_state = iris_create_fs_state;
2305 ctx->create_compute_state = iris_create_compute_state;
2306
2307 ctx->delete_vs_state = iris_delete_vs_state;
2308 ctx->delete_tcs_state = iris_delete_tcs_state;
2309 ctx->delete_tes_state = iris_delete_tes_state;
2310 ctx->delete_gs_state = iris_delete_gs_state;
2311 ctx->delete_fs_state = iris_delete_fs_state;
2312 ctx->delete_compute_state = iris_delete_cs_state;
2313
2314 ctx->bind_vs_state = iris_bind_vs_state;
2315 ctx->bind_tcs_state = iris_bind_tcs_state;
2316 ctx->bind_tes_state = iris_bind_tes_state;
2317 ctx->bind_gs_state = iris_bind_gs_state;
2318 ctx->bind_fs_state = iris_bind_fs_state;
2319 ctx->bind_compute_state = iris_bind_cs_state;
2320 }