iris: fix system value remapping
[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 "compiler/nir/nir.h"
40 #include "compiler/nir/nir_builder.h"
41 #include "intel/compiler/brw_compiler.h"
42 #include "intel/compiler/brw_nir.h"
43 #include "iris_context.h"
44
45 static unsigned
46 get_new_program_id(struct iris_screen *screen)
47 {
48 return p_atomic_inc_return(&screen->program_id);
49 }
50
51 /**
52 * An uncompiled, API-facing shader. This is the Gallium CSO for shaders.
53 * It primarily contains the NIR for the shader.
54 *
55 * Each API-facing shader can be compiled into multiple shader variants,
56 * based on non-orthogonal state dependencies, recorded in the shader key.
57 *
58 * See iris_compiled_shader, which represents a compiled shader variant.
59 */
60 struct iris_uncompiled_shader {
61 nir_shader *nir;
62
63 struct pipe_stream_output_info stream_output;
64
65 unsigned program_id;
66
67 /** Bitfield of (1 << IRIS_NOS_*) flags. */
68 unsigned nos;
69 };
70
71 static nir_ssa_def *
72 get_aoa_deref_offset(nir_builder *b,
73 nir_deref_instr *deref,
74 unsigned elem_size)
75 {
76 unsigned array_size = elem_size;
77 nir_ssa_def *offset = nir_imm_int(b, 0);
78
79 while (deref->deref_type != nir_deref_type_var) {
80 assert(deref->deref_type == nir_deref_type_array);
81
82 /* This level's element size is the previous level's array size */
83 nir_ssa_def *index = nir_ssa_for_src(b, deref->arr.index, 1);
84 assert(deref->arr.index.ssa);
85 offset = nir_iadd(b, offset,
86 nir_imul(b, index, nir_imm_int(b, array_size)));
87
88 deref = nir_deref_instr_parent(deref);
89 assert(glsl_type_is_array(deref->type));
90 array_size *= glsl_get_length(deref->type);
91 }
92
93 /* Accessing an invalid surface index with the dataport can result in a
94 * hang. According to the spec "if the index used to select an individual
95 * element is negative or greater than or equal to the size of the array,
96 * the results of the operation are undefined but may not lead to
97 * termination" -- which is one of the possible outcomes of the hang.
98 * Clamp the index to prevent access outside of the array bounds.
99 */
100 return nir_umin(b, offset, nir_imm_int(b, array_size - elem_size));
101 }
102
103 static void
104 iris_lower_storage_image_derefs(nir_shader *nir)
105 {
106 nir_function_impl *impl = nir_shader_get_entrypoint(nir);
107
108 nir_builder b;
109 nir_builder_init(&b, impl);
110
111 nir_foreach_block(block, impl) {
112 nir_foreach_instr_safe(instr, block) {
113 if (instr->type != nir_instr_type_intrinsic)
114 continue;
115
116 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
117 switch (intrin->intrinsic) {
118 case nir_intrinsic_image_deref_load:
119 case nir_intrinsic_image_deref_store:
120 case nir_intrinsic_image_deref_atomic_add:
121 case nir_intrinsic_image_deref_atomic_min:
122 case nir_intrinsic_image_deref_atomic_max:
123 case nir_intrinsic_image_deref_atomic_and:
124 case nir_intrinsic_image_deref_atomic_or:
125 case nir_intrinsic_image_deref_atomic_xor:
126 case nir_intrinsic_image_deref_atomic_exchange:
127 case nir_intrinsic_image_deref_atomic_comp_swap:
128 case nir_intrinsic_image_deref_size:
129 case nir_intrinsic_image_deref_samples: {
130 nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
131 nir_variable *var = nir_deref_instr_get_variable(deref);
132
133 b.cursor = nir_before_instr(&intrin->instr);
134 nir_ssa_def *index =
135 nir_iadd(&b, nir_imm_int(&b, var->data.driver_location),
136 get_aoa_deref_offset(&b, deref, 1));
137 brw_nir_rewrite_image_intrinsic(intrin, index);
138 break;
139 }
140
141 default:
142 break;
143 }
144 }
145 }
146 }
147
148
149
150 // XXX: need unify_interfaces() at link time...
151
152 /**
153 * The pipe->create_[stage]_state() driver hooks.
154 *
155 * Performs basic NIR preprocessing, records any state dependencies, and
156 * returns an iris_uncompiled_shader as the Gallium CSO.
157 *
158 * Actual shader compilation to assembly happens later, at first use.
159 */
160 static void *
161 iris_create_uncompiled_shader(struct pipe_context *ctx,
162 nir_shader *nir,
163 const struct pipe_stream_output_info *so_info)
164 {
165 //struct iris_context *ice = (struct iris_context *)ctx;
166 struct iris_screen *screen = (struct iris_screen *)ctx->screen;
167 const struct gen_device_info *devinfo = &screen->devinfo;
168
169 struct iris_uncompiled_shader *ish =
170 calloc(1, sizeof(struct iris_uncompiled_shader));
171 if (!ish)
172 return NULL;
173
174 nir = brw_preprocess_nir(screen->compiler, nir);
175
176 NIR_PASS_V(nir, brw_nir_lower_image_load_store, devinfo);
177 NIR_PASS_V(nir, iris_lower_storage_image_derefs);
178
179 ish->program_id = get_new_program_id(screen);
180 ish->nir = nir;
181 if (so_info)
182 memcpy(&ish->stream_output, so_info, sizeof(*so_info));
183
184 switch (nir->info.stage) {
185 case MESA_SHADER_VERTEX:
186 /* User clip planes */
187 if (nir->info.clip_distance_array_size == 0)
188 ish->nos |= IRIS_NOS_RASTERIZER;
189 // XXX: NOS
190 break;
191 case MESA_SHADER_TESS_CTRL:
192 // XXX: NOS
193 break;
194 case MESA_SHADER_TESS_EVAL:
195 // XXX: NOS
196 break;
197 case MESA_SHADER_GEOMETRY:
198 // XXX: NOS
199 break;
200 case MESA_SHADER_FRAGMENT:
201 ish->nos |= IRIS_NOS_FRAMEBUFFER |
202 IRIS_NOS_DEPTH_STENCIL_ALPHA |
203 IRIS_NOS_RASTERIZER |
204 IRIS_NOS_BLEND;
205
206 /* The program key needs the VUE map if there are > 16 inputs */
207 if (util_bitcount64(ish->nir->info.inputs_read &
208 BRW_FS_VARYING_INPUT_MASK) > 16) {
209 ish->nos |= IRIS_NOS_LAST_VUE_MAP;
210 }
211 break;
212 case MESA_SHADER_COMPUTE:
213 // XXX: NOS
214 break;
215 default:
216 break;
217 }
218
219 // XXX: precompile!
220 // XXX: disallow more than 64KB of shared variables
221
222 return ish;
223 }
224
225 /**
226 * The pipe->delete_[stage]_state() driver hooks.
227 *
228 * Frees the iris_uncompiled_shader.
229 */
230 static void *
231 iris_create_shader_state(struct pipe_context *ctx,
232 const struct pipe_shader_state *state)
233 {
234 assert(state->type == PIPE_SHADER_IR_NIR);
235
236 return iris_create_uncompiled_shader(ctx, state->ir.nir,
237 &state->stream_output);
238 }
239
240 static void *
241 iris_create_compute_state(struct pipe_context *ctx,
242 const struct pipe_compute_state *state)
243 {
244 assert(state->ir_type == PIPE_SHADER_IR_NIR);
245
246 return iris_create_uncompiled_shader(ctx, (void *) state->prog, NULL);
247 }
248
249 static void
250 iris_delete_shader_state(struct pipe_context *ctx, void *state)
251 {
252 struct iris_uncompiled_shader *ish = state;
253
254 ralloc_free(ish->nir);
255 free(ish);
256 }
257
258 /**
259 * The pipe->bind_[stage]_state() driver hook.
260 *
261 * Binds an uncompiled shader as the current one for a particular stage.
262 * Updates dirty tracking to account for the shader's NOS.
263 */
264 static void
265 bind_state(struct iris_context *ice,
266 struct iris_uncompiled_shader *ish,
267 gl_shader_stage stage)
268 {
269 uint64_t dirty_bit = IRIS_DIRTY_UNCOMPILED_VS << stage;
270 const uint64_t nos = ish ? ish->nos : 0;
271
272 ice->shaders.uncompiled[stage] = ish;
273 ice->state.dirty |= dirty_bit;
274
275 /* Record that CSOs need to mark IRIS_DIRTY_UNCOMPILED_XS when they change
276 * (or that they no longer need to do so).
277 */
278 for (int i = 0; i < IRIS_NOS_COUNT; i++) {
279 if (nos & (1 << i))
280 ice->state.dirty_for_nos[i] |= dirty_bit;
281 else
282 ice->state.dirty_for_nos[i] &= ~dirty_bit;
283 }
284 }
285
286 static void
287 iris_bind_vs_state(struct pipe_context *ctx, void *state)
288 {
289 bind_state((void *) ctx, state, MESA_SHADER_VERTEX);
290 }
291
292 static void
293 iris_bind_tcs_state(struct pipe_context *ctx, void *state)
294 {
295 bind_state((void *) ctx, state, MESA_SHADER_TESS_CTRL);
296 }
297
298 static void
299 iris_bind_tes_state(struct pipe_context *ctx, void *state)
300 {
301 struct iris_context *ice = (struct iris_context *)ctx;
302
303 /* Enabling/disabling optional stages requires a URB reconfiguration. */
304 if (!!state != !!ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL])
305 ice->state.dirty |= IRIS_DIRTY_URB;
306
307 bind_state((void *) ctx, state, MESA_SHADER_TESS_EVAL);
308 }
309
310 static void
311 iris_bind_gs_state(struct pipe_context *ctx, void *state)
312 {
313 struct iris_context *ice = (struct iris_context *)ctx;
314
315 /* Enabling/disabling optional stages requires a URB reconfiguration. */
316 if (!!state != !!ice->shaders.uncompiled[MESA_SHADER_GEOMETRY])
317 ice->state.dirty |= IRIS_DIRTY_URB;
318
319 bind_state((void *) ctx, state, MESA_SHADER_GEOMETRY);
320 }
321
322 static void
323 iris_bind_fs_state(struct pipe_context *ctx, void *state)
324 {
325 bind_state((void *) ctx, state, MESA_SHADER_FRAGMENT);
326 }
327
328 static void
329 iris_bind_cs_state(struct pipe_context *ctx, void *state)
330 {
331 bind_state((void *) ctx, state, MESA_SHADER_COMPUTE);
332 }
333
334 /**
335 * Sets up the starting offsets for the groups of binding table entries
336 * common to all pipeline stages.
337 *
338 * Unused groups are initialized to 0xd0d0d0d0 to make it obvious that they're
339 * unused but also make sure that addition of small offsets to them will
340 * trigger some of our asserts that surface indices are < BRW_MAX_SURFACES.
341 */
342 static uint32_t
343 assign_common_binding_table_offsets(const struct gen_device_info *devinfo,
344 const struct nir_shader *nir,
345 struct brw_stage_prog_data *prog_data,
346 uint32_t next_binding_table_offset)
347 {
348 const struct shader_info *info = &nir->info;
349
350 if (info->num_textures) {
351 prog_data->binding_table.texture_start = next_binding_table_offset;
352 prog_data->binding_table.gather_texture_start = next_binding_table_offset;
353 next_binding_table_offset += info->num_textures;
354 } else {
355 prog_data->binding_table.texture_start = 0xd0d0d0d0;
356 prog_data->binding_table.gather_texture_start = 0xd0d0d0d0;
357 }
358
359 if (info->num_images) {
360 prog_data->binding_table.image_start = next_binding_table_offset;
361 next_binding_table_offset += info->num_images;
362 } else {
363 prog_data->binding_table.image_start = 0xd0d0d0d0;
364 }
365
366 int num_ubos = info->num_ubos + (nir->num_uniforms > 0 ? 1 : 0);
367
368 if (num_ubos) {
369 //assert(info->num_ubos <= BRW_MAX_UBO);
370 prog_data->binding_table.ubo_start = next_binding_table_offset;
371 next_binding_table_offset += num_ubos;
372 } else {
373 prog_data->binding_table.ubo_start = 0xd0d0d0d0;
374 }
375
376 if (info->num_ssbos || info->num_abos) {
377 prog_data->binding_table.ssbo_start = next_binding_table_offset;
378 // XXX: see iris_state "wasting 16 binding table slots for ABOs" comment
379 next_binding_table_offset += IRIS_MAX_ABOS + info->num_ssbos;
380 } else {
381 prog_data->binding_table.ssbo_start = 0xd0d0d0d0;
382 }
383
384 prog_data->binding_table.shader_time_start = 0xd0d0d0d0;
385
386 /* This may or may not be used depending on how the compile goes. */
387 prog_data->binding_table.pull_constants_start = next_binding_table_offset;
388 next_binding_table_offset++;
389
390 /* Plane 0 is just the regular texture section */
391 prog_data->binding_table.plane_start[0] = prog_data->binding_table.texture_start;
392
393 prog_data->binding_table.plane_start[1] = next_binding_table_offset;
394 next_binding_table_offset += info->num_textures;
395
396 prog_data->binding_table.plane_start[2] = next_binding_table_offset;
397 next_binding_table_offset += info->num_textures;
398
399 /* Set the binding table size */
400 prog_data->binding_table.size_bytes = next_binding_table_offset * 4;
401
402 return next_binding_table_offset;
403 }
404
405 /**
406 * Associate NIR uniform variables with the prog_data->param[] mechanism
407 * used by the backend. Also, decide which UBOs we'd like to push in an
408 * ideal situation (though the backend can reduce this).
409 */
410 static void
411 iris_setup_uniforms(const struct brw_compiler *compiler,
412 void *mem_ctx,
413 nir_shader *nir,
414 struct brw_stage_prog_data *prog_data)
415 {
416 /* The intel compiler assumes that num_uniforms is in bytes. For
417 * scalar that means 4 bytes per uniform slot.
418 *
419 * Ref: brw_nir_lower_uniforms, type_size_scalar_bytes.
420 */
421 nir->num_uniforms *= 4;
422
423 prog_data->nr_params = 0;
424 prog_data->param = rzalloc_array(mem_ctx, uint32_t, 1);
425
426 nir_function_impl *impl = nir_shader_get_entrypoint(nir);
427
428 nir_builder b;
429 nir_builder_init(&b, impl);
430
431 b.cursor = nir_before_block(nir_start_block(impl));
432 nir_ssa_def *temp_ubo_name = nir_ssa_undef(&b, 1, 32);
433
434 /* Turn system value intrinsics into uniforms */
435 nir_foreach_block(block, impl) {
436 nir_foreach_instr_safe(instr, block) {
437 if (instr->type != nir_instr_type_intrinsic)
438 continue;
439
440 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
441
442 unsigned param_idx = prog_data->nr_params;
443 uint32_t *param = NULL;
444
445 switch (intrin->intrinsic) {
446 case nir_intrinsic_load_user_clip_plane: {
447 unsigned ucp = nir_intrinsic_ucp_id(intrin);
448 param = brw_stage_prog_data_add_params(prog_data, 4);
449 for (int i = 0; i < 4; i++) {
450 param[i] =
451 IRIS_PARAM(BUILTIN, BRW_PARAM_BUILTIN_CLIP_PLANE(ucp, i));
452 }
453 break;
454 }
455 default:
456 continue;
457 }
458
459 b.cursor = nir_before_instr(instr);
460
461 unsigned comps = nir_intrinsic_dest_components(intrin);
462 nir_ssa_def *offset = nir_imm_int(&b, param_idx * sizeof(uint32_t));
463
464 nir_intrinsic_instr *load =
465 nir_intrinsic_instr_create(nir, nir_intrinsic_load_ubo);
466 load->num_components = comps;
467 load->src[0] = nir_src_for_ssa(temp_ubo_name);
468 load->src[1] = nir_src_for_ssa(offset);
469 nir_ssa_dest_init(&load->instr, &load->dest, comps, 32, NULL);
470 nir_builder_instr_insert(&b, &load->instr);
471 nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
472 nir_src_for_ssa(&load->dest.ssa));
473 nir_instr_remove(instr);
474 }
475 }
476
477 nir_validate_shader(nir, "before remapping");
478
479 /* Place the new params at the front of constant buffer 0. */
480 if (prog_data->nr_params > 0) {
481 nir_foreach_block(block, impl) {
482 nir_foreach_instr_safe(instr, block) {
483 if (instr->type != nir_instr_type_intrinsic)
484 continue;
485
486 nir_intrinsic_instr *load = nir_instr_as_intrinsic(instr);
487
488 if (load->intrinsic != nir_intrinsic_load_ubo)
489 continue;
490
491 b.cursor = nir_before_instr(instr);
492
493 assert(load->src[0].is_ssa);
494
495 if (load->src[0].ssa == temp_ubo_name) {
496 nir_instr_rewrite_src(instr, &load->src[0],
497 nir_src_for_ssa(nir_imm_int(&b, 0)));
498 } else if (nir_src_as_uint(load->src[0]) == 0) {
499 nir_ssa_def *offset =
500 nir_iadd(&b, load->src[1].ssa,
501 nir_imm_int(&b, prog_data->nr_params));
502 nir_instr_rewrite_src(instr, &load->src[1],
503 nir_src_for_ssa(offset));
504 }
505 }
506 }
507 }
508
509 nir_validate_shader(nir, "after remap");
510
511 // XXX: vs clip planes?
512 if (nir->info.stage != MESA_SHADER_COMPUTE)
513 brw_nir_analyze_ubo_ranges(compiler, nir, NULL, prog_data->ubo_ranges);
514 }
515
516 /**
517 * If we still have regular uniforms as push constants after the backend
518 * compilation, set up a UBO range for them. This will be used to fill
519 * out the 3DSTATE_CONSTANT_* packets which cause the data to be pushed.
520 */
521 static void
522 iris_setup_push_uniform_range(const struct brw_compiler *compiler,
523 struct brw_stage_prog_data *prog_data)
524 {
525 if (prog_data->nr_params) {
526 for (int i = 3; i > 0; i--)
527 prog_data->ubo_ranges[i] = prog_data->ubo_ranges[i - 1];
528
529 prog_data->ubo_ranges[0] = (struct brw_ubo_range) {
530 .block = 0,
531 .start = 0,
532 .length = DIV_ROUND_UP(prog_data->nr_params, 8),
533 };
534 }
535 }
536
537 /**
538 * Compile a vertex shader, and upload the assembly.
539 */
540 static bool
541 iris_compile_vs(struct iris_context *ice,
542 struct iris_uncompiled_shader *ish,
543 const struct brw_vs_prog_key *key)
544 {
545 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
546 const struct brw_compiler *compiler = screen->compiler;
547 const struct gen_device_info *devinfo = &screen->devinfo;
548 void *mem_ctx = ralloc_context(NULL);
549 struct brw_vs_prog_data *vs_prog_data =
550 rzalloc(mem_ctx, struct brw_vs_prog_data);
551 struct brw_vue_prog_data *vue_prog_data = &vs_prog_data->base;
552 struct brw_stage_prog_data *prog_data = &vue_prog_data->base;
553
554 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
555
556 if (key->nr_userclip_plane_consts) {
557 nir_function_impl *impl = nir_shader_get_entrypoint(nir);
558 nir_lower_clip_vs(nir, (1 << key->nr_userclip_plane_consts) - 1, true);
559 nir_lower_io_to_temporaries(nir, impl, true, false);
560 nir_lower_global_vars_to_local(nir);
561 nir_lower_vars_to_ssa(nir);
562 }
563
564 // XXX: alt mode
565 assign_common_binding_table_offsets(devinfo, nir, prog_data, 0);
566
567 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data);
568
569 brw_compute_vue_map(devinfo,
570 &vue_prog_data->vue_map, nir->info.outputs_written,
571 nir->info.separate_shader);
572
573 char *error_str = NULL;
574 const unsigned *program =
575 brw_compile_vs(compiler, &ice->dbg, mem_ctx, key, vs_prog_data,
576 nir, -1, &error_str);
577 if (program == NULL) {
578 dbg_printf("Failed to compile vertex shader: %s\n", error_str);
579 ralloc_free(mem_ctx);
580 return false;
581 }
582
583 iris_setup_push_uniform_range(compiler, prog_data);
584
585 uint32_t *so_decls =
586 ice->vtbl.create_so_decl_list(&ish->stream_output,
587 &vue_prog_data->vue_map);
588
589 iris_upload_and_bind_shader(ice, IRIS_CACHE_VS, key, program, prog_data,
590 so_decls);
591
592 ralloc_free(mem_ctx);
593 return true;
594 }
595
596 /**
597 * Update the current vertex shader variant.
598 *
599 * Fill out the key, look in the cache, compile and bind if needed.
600 */
601 static void
602 iris_update_compiled_vs(struct iris_context *ice)
603 {
604 struct iris_uncompiled_shader *ish =
605 ice->shaders.uncompiled[MESA_SHADER_VERTEX];
606
607 struct brw_vs_prog_key key = { .program_string_id = ish->program_id };
608 ice->vtbl.populate_vs_key(ice, &ish->nir->info, &key);
609
610 if (iris_bind_cached_shader(ice, IRIS_CACHE_VS, &key))
611 return;
612
613 UNUSED bool success = iris_compile_vs(ice, ish, &key);
614 }
615
616 /**
617 * Get the shader_info for a given stage, or NULL if the stage is disabled.
618 */
619 const struct shader_info *
620 iris_get_shader_info(const struct iris_context *ice, gl_shader_stage stage)
621 {
622 const struct iris_uncompiled_shader *ish = ice->shaders.uncompiled[stage];
623
624 if (!ish)
625 return NULL;
626
627 const nir_shader *nir = ish->nir;
628 return &nir->info;
629 }
630
631 // XXX: this function is gross
632 unsigned
633 iris_get_shader_num_ubos(const struct iris_context *ice, gl_shader_stage stage)
634 {
635 const struct iris_uncompiled_shader *ish = ice->shaders.uncompiled[stage];
636
637 if (ish) {
638 const nir_shader *nir = ish->nir;
639 /* see assign_common_binding_table_offsets */
640 return nir->info.num_ubos + (nir->num_uniforms > 0 ? 1 : 0);
641 }
642 return 0;
643 }
644
645 /**
646 * Get the union of TCS output and TES input slots.
647 *
648 * TCS and TES need to agree on a common URB entry layout. In particular,
649 * the data for all patch vertices is stored in a single URB entry (unlike
650 * GS which has one entry per input vertex). This means that per-vertex
651 * array indexing needs a stride.
652 *
653 * SSO requires locations to match, but doesn't require the number of
654 * outputs/inputs to match (in fact, the TCS often has extra outputs).
655 * So, we need to take the extra step of unifying these on the fly.
656 */
657 static void
658 get_unified_tess_slots(const struct iris_context *ice,
659 uint64_t *per_vertex_slots,
660 uint32_t *per_patch_slots)
661 {
662 const struct shader_info *tcs =
663 iris_get_shader_info(ice, MESA_SHADER_TESS_CTRL);
664 const struct shader_info *tes =
665 iris_get_shader_info(ice, MESA_SHADER_TESS_EVAL);
666
667 *per_vertex_slots = tes->inputs_read;
668 *per_patch_slots = tes->patch_inputs_read;
669
670 if (tcs) {
671 *per_vertex_slots |= tcs->inputs_read;
672 *per_patch_slots |= tcs->patch_inputs_read;
673 }
674 }
675
676 /**
677 * Compile a tessellation control shader, and upload the assembly.
678 */
679 static bool
680 iris_compile_tcs(struct iris_context *ice,
681 struct iris_uncompiled_shader *ish,
682 const struct brw_tcs_prog_key *key)
683 {
684 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
685 const struct brw_compiler *compiler = screen->compiler;
686 const struct nir_shader_compiler_options *options =
687 compiler->glsl_compiler_options[MESA_SHADER_TESS_CTRL].NirOptions;
688 const struct gen_device_info *devinfo = &screen->devinfo;
689 void *mem_ctx = ralloc_context(NULL);
690 struct brw_tcs_prog_data *tcs_prog_data =
691 rzalloc(mem_ctx, struct brw_tcs_prog_data);
692 struct brw_vue_prog_data *vue_prog_data = &tcs_prog_data->base;
693 struct brw_stage_prog_data *prog_data = &vue_prog_data->base;
694
695 nir_shader *nir;
696
697 if (ish) {
698 nir = nir_shader_clone(mem_ctx, ish->nir);
699
700 assign_common_binding_table_offsets(devinfo, nir, prog_data, 0);
701 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data);
702 } else {
703 nir = brw_nir_create_passthrough_tcs(mem_ctx, compiler, options, key);
704
705 /* Reserve space for passing the default tess levels as constants. */
706 prog_data->param = rzalloc_array(mem_ctx, uint32_t, 8);
707 prog_data->nr_params = 8;
708 prog_data->ubo_ranges[0].length = 1;
709 }
710
711 char *error_str = NULL;
712 const unsigned *program =
713 brw_compile_tcs(compiler, &ice->dbg, mem_ctx, key, tcs_prog_data, nir,
714 -1, &error_str);
715 if (program == NULL) {
716 dbg_printf("Failed to compile evaluation shader: %s\n", error_str);
717 ralloc_free(mem_ctx);
718 return false;
719 }
720
721 iris_setup_push_uniform_range(compiler, prog_data);
722
723 iris_upload_and_bind_shader(ice, IRIS_CACHE_TCS, key, program, prog_data,
724 NULL);
725
726 ralloc_free(mem_ctx);
727 return true;
728 }
729
730 /**
731 * Update the current tessellation control shader variant.
732 *
733 * Fill out the key, look in the cache, compile and bind if needed.
734 */
735 static void
736 iris_update_compiled_tcs(struct iris_context *ice)
737 {
738 struct iris_uncompiled_shader *tcs =
739 ice->shaders.uncompiled[MESA_SHADER_TESS_CTRL];
740
741 const struct shader_info *tes_info =
742 iris_get_shader_info(ice, MESA_SHADER_TESS_EVAL);
743 struct brw_tcs_prog_key key = {
744 .program_string_id = tcs ? tcs->program_id : 0,
745 .tes_primitive_mode = tes_info->tess.primitive_mode,
746 .input_vertices = ice->state.vertices_per_patch,
747 };
748 get_unified_tess_slots(ice, &key.outputs_written,
749 &key.patch_outputs_written);
750 ice->vtbl.populate_tcs_key(ice, &key);
751
752 if (iris_bind_cached_shader(ice, IRIS_CACHE_TCS, &key))
753 return;
754
755 UNUSED bool success = iris_compile_tcs(ice, tcs, &key);
756 }
757
758 /**
759 * Compile a tessellation evaluation shader, and upload the assembly.
760 */
761 static bool
762 iris_compile_tes(struct iris_context *ice,
763 struct iris_uncompiled_shader *ish,
764 const struct brw_tes_prog_key *key)
765 {
766 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
767 const struct brw_compiler *compiler = screen->compiler;
768 const struct gen_device_info *devinfo = &screen->devinfo;
769 void *mem_ctx = ralloc_context(NULL);
770 struct brw_tes_prog_data *tes_prog_data =
771 rzalloc(mem_ctx, struct brw_tes_prog_data);
772 struct brw_vue_prog_data *vue_prog_data = &tes_prog_data->base;
773 struct brw_stage_prog_data *prog_data = &vue_prog_data->base;
774
775 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
776
777 assign_common_binding_table_offsets(devinfo, nir, prog_data, 0);
778
779 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data);
780
781 struct brw_vue_map input_vue_map;
782 brw_compute_tess_vue_map(&input_vue_map, key->inputs_read,
783 key->patch_inputs_read);
784
785 char *error_str = NULL;
786 const unsigned *program =
787 brw_compile_tes(compiler, &ice->dbg, mem_ctx, key, &input_vue_map,
788 tes_prog_data, nir, NULL, -1, &error_str);
789 if (program == NULL) {
790 dbg_printf("Failed to compile evaluation shader: %s\n", error_str);
791 ralloc_free(mem_ctx);
792 return false;
793 }
794
795 iris_setup_push_uniform_range(compiler, prog_data);
796
797 uint32_t *so_decls =
798 ice->vtbl.create_so_decl_list(&ish->stream_output,
799 &vue_prog_data->vue_map);
800
801 iris_upload_and_bind_shader(ice, IRIS_CACHE_TES, key, program, prog_data,
802 so_decls);
803
804 ralloc_free(mem_ctx);
805 return true;
806 }
807
808 /**
809 * Update the current tessellation evaluation shader variant.
810 *
811 * Fill out the key, look in the cache, compile and bind if needed.
812 */
813 static void
814 iris_update_compiled_tes(struct iris_context *ice)
815 {
816 struct iris_uncompiled_shader *ish =
817 ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL];
818
819 struct brw_tes_prog_key key = { .program_string_id = ish->program_id };
820 get_unified_tess_slots(ice, &key.inputs_read, &key.patch_inputs_read);
821 ice->vtbl.populate_tes_key(ice, &key);
822
823 if (iris_bind_cached_shader(ice, IRIS_CACHE_TES, &key))
824 return;
825
826 UNUSED bool success = iris_compile_tes(ice, ish, &key);
827 }
828
829 /**
830 * Compile a geometry shader, and upload the assembly.
831 */
832 static bool
833 iris_compile_gs(struct iris_context *ice,
834 struct iris_uncompiled_shader *ish,
835 const struct brw_gs_prog_key *key)
836 {
837 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
838 const struct brw_compiler *compiler = screen->compiler;
839 const struct gen_device_info *devinfo = &screen->devinfo;
840 void *mem_ctx = ralloc_context(NULL);
841 struct brw_gs_prog_data *gs_prog_data =
842 rzalloc(mem_ctx, struct brw_gs_prog_data);
843 struct brw_vue_prog_data *vue_prog_data = &gs_prog_data->base;
844 struct brw_stage_prog_data *prog_data = &vue_prog_data->base;
845
846 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
847
848 assign_common_binding_table_offsets(devinfo, nir, prog_data, 0);
849
850 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data);
851
852 brw_compute_vue_map(devinfo,
853 &vue_prog_data->vue_map, nir->info.outputs_written,
854 nir->info.separate_shader);
855
856 char *error_str = NULL;
857 const unsigned *program =
858 brw_compile_gs(compiler, &ice->dbg, mem_ctx, key, gs_prog_data, nir,
859 NULL, -1, &error_str);
860 if (program == NULL) {
861 dbg_printf("Failed to compile geometry shader: %s\n", error_str);
862 ralloc_free(mem_ctx);
863 return false;
864 }
865
866 iris_setup_push_uniform_range(compiler, prog_data);
867
868 uint32_t *so_decls =
869 ice->vtbl.create_so_decl_list(&ish->stream_output,
870 &vue_prog_data->vue_map);
871
872 iris_upload_and_bind_shader(ice, IRIS_CACHE_GS, key, program, prog_data,
873 so_decls);
874
875 ralloc_free(mem_ctx);
876 return true;
877 }
878
879 /**
880 * Update the current geometry shader variant.
881 *
882 * Fill out the key, look in the cache, compile and bind if needed.
883 */
884 static void
885 iris_update_compiled_gs(struct iris_context *ice)
886 {
887 struct iris_uncompiled_shader *ish =
888 ice->shaders.uncompiled[MESA_SHADER_GEOMETRY];
889
890 if (!ish) {
891 iris_unbind_shader(ice, IRIS_CACHE_GS);
892 return;
893 }
894
895 struct brw_gs_prog_key key = { .program_string_id = ish->program_id };
896 ice->vtbl.populate_gs_key(ice, &key);
897
898 if (iris_bind_cached_shader(ice, IRIS_CACHE_GS, &key))
899 return;
900
901 UNUSED bool success = iris_compile_gs(ice, ish, &key);
902 }
903
904 /**
905 * Compile a fragment (pixel) shader, and upload the assembly.
906 */
907 static bool
908 iris_compile_fs(struct iris_context *ice,
909 struct iris_uncompiled_shader *ish,
910 const struct brw_wm_prog_key *key,
911 struct brw_vue_map *vue_map)
912 {
913 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
914 const struct brw_compiler *compiler = screen->compiler;
915 const struct gen_device_info *devinfo = &screen->devinfo;
916 void *mem_ctx = ralloc_context(NULL);
917 struct brw_wm_prog_data *fs_prog_data =
918 rzalloc(mem_ctx, struct brw_wm_prog_data);
919 struct brw_stage_prog_data *prog_data = &fs_prog_data->base;
920
921 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
922
923 // XXX: alt mode
924 assign_common_binding_table_offsets(devinfo, nir, prog_data,
925 MAX2(key->nr_color_regions, 1));
926
927 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data);
928
929 char *error_str = NULL;
930 const unsigned *program =
931 brw_compile_fs(compiler, &ice->dbg, mem_ctx, key, fs_prog_data,
932 nir, NULL, -1, -1, -1, true, false, vue_map, &error_str);
933 if (program == NULL) {
934 dbg_printf("Failed to compile fragment shader: %s\n", error_str);
935 ralloc_free(mem_ctx);
936 return false;
937 }
938
939 //brw_alloc_stage_scratch(brw, &brw->wm.base, prog_data.base.total_scratch);
940
941 iris_setup_push_uniform_range(compiler, prog_data);
942
943 iris_upload_and_bind_shader(ice, IRIS_CACHE_FS, key, program, prog_data,
944 NULL);
945
946 ralloc_free(mem_ctx);
947 return true;
948 }
949
950 /**
951 * Update the current fragment shader variant.
952 *
953 * Fill out the key, look in the cache, compile and bind if needed.
954 */
955 static void
956 iris_update_compiled_fs(struct iris_context *ice)
957 {
958 struct iris_uncompiled_shader *ish =
959 ice->shaders.uncompiled[MESA_SHADER_FRAGMENT];
960 struct brw_wm_prog_key key = { .program_string_id = ish->program_id };
961 ice->vtbl.populate_fs_key(ice, &key);
962
963 if (ish->nos & IRIS_NOS_LAST_VUE_MAP)
964 key.input_slots_valid = ice->shaders.last_vue_map->slots_valid;
965
966 if (iris_bind_cached_shader(ice, IRIS_CACHE_FS, &key))
967 return;
968
969 UNUSED bool success =
970 iris_compile_fs(ice, ish, &key, ice->shaders.last_vue_map);
971 }
972
973 /**
974 * Get the compiled shader for the last enabled geometry stage.
975 *
976 * This stage is the one which will feed stream output and the rasterizer.
977 */
978 static struct iris_compiled_shader *
979 last_vue_shader(struct iris_context *ice)
980 {
981 if (ice->shaders.prog[MESA_SHADER_GEOMETRY])
982 return ice->shaders.prog[MESA_SHADER_GEOMETRY];
983
984 if (ice->shaders.prog[MESA_SHADER_TESS_EVAL])
985 return ice->shaders.prog[MESA_SHADER_TESS_EVAL];
986
987 return ice->shaders.prog[MESA_SHADER_VERTEX];
988 }
989
990 /**
991 * Update the last enabled stage's VUE map.
992 *
993 * When the shader feeding the rasterizer's output interface changes, we
994 * need to re-emit various packets.
995 */
996 static void
997 update_last_vue_map(struct iris_context *ice,
998 struct brw_stage_prog_data *prog_data)
999 {
1000 struct brw_vue_prog_data *vue_prog_data = (void *) prog_data;
1001 struct brw_vue_map *vue_map = &vue_prog_data->vue_map;
1002 struct brw_vue_map *old_map = ice->shaders.last_vue_map;
1003 const uint64_t changed_slots =
1004 (old_map ? old_map->slots_valid : 0ull) ^ vue_map->slots_valid;
1005
1006 if (changed_slots & VARYING_BIT_VIEWPORT) {
1007 // XXX: could use ctx->Const.MaxViewports for old API efficiency
1008 ice->state.num_viewports =
1009 (vue_map->slots_valid & VARYING_BIT_VIEWPORT) ? IRIS_MAX_VIEWPORTS : 1;
1010 ice->state.dirty |= IRIS_DIRTY_CLIP |
1011 IRIS_DIRTY_SF_CL_VIEWPORT |
1012 IRIS_DIRTY_CC_VIEWPORT |
1013 IRIS_DIRTY_SCISSOR_RECT |
1014 IRIS_DIRTY_UNCOMPILED_FS |
1015 ice->state.dirty_for_nos[IRIS_NOS_LAST_VUE_MAP];
1016 // XXX: CC_VIEWPORT?
1017 }
1018
1019 if (changed_slots || (old_map && old_map->separate != vue_map->separate)) {
1020 ice->state.dirty |= IRIS_DIRTY_SBE;
1021 }
1022
1023 ice->shaders.last_vue_map = &vue_prog_data->vue_map;
1024 }
1025
1026 /**
1027 * Get the prog_data for a given stage, or NULL if the stage is disabled.
1028 */
1029 static struct brw_vue_prog_data *
1030 get_vue_prog_data(struct iris_context *ice, gl_shader_stage stage)
1031 {
1032 if (!ice->shaders.prog[stage])
1033 return NULL;
1034
1035 return (void *) ice->shaders.prog[stage]->prog_data;
1036 }
1037
1038 /**
1039 * Update the current shader variants for the given state.
1040 *
1041 * This should be called on every draw call to ensure that the correct
1042 * shaders are bound. It will also flag any dirty state triggered by
1043 * swapping out those shaders.
1044 */
1045 void
1046 iris_update_compiled_shaders(struct iris_context *ice)
1047 {
1048 const uint64_t dirty = ice->state.dirty;
1049
1050 struct brw_vue_prog_data *old_prog_datas[4];
1051 if (!(dirty & IRIS_DIRTY_URB)) {
1052 for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++)
1053 old_prog_datas[i] = get_vue_prog_data(ice, i);
1054 }
1055
1056 if (dirty & (IRIS_DIRTY_UNCOMPILED_TCS | IRIS_DIRTY_UNCOMPILED_TES)) {
1057 struct iris_uncompiled_shader *tes =
1058 ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL];
1059 if (tes) {
1060 iris_update_compiled_tcs(ice);
1061 iris_update_compiled_tes(ice);
1062 } else {
1063 iris_unbind_shader(ice, IRIS_CACHE_TCS);
1064 iris_unbind_shader(ice, IRIS_CACHE_TES);
1065 }
1066 }
1067
1068 if (dirty & IRIS_DIRTY_UNCOMPILED_VS)
1069 iris_update_compiled_vs(ice);
1070 if (dirty & IRIS_DIRTY_UNCOMPILED_GS)
1071 iris_update_compiled_gs(ice);
1072
1073 struct iris_compiled_shader *shader = last_vue_shader(ice);
1074 update_last_vue_map(ice, shader->prog_data);
1075 if (ice->state.streamout != shader->streamout) {
1076 ice->state.streamout = shader->streamout;
1077 ice->state.dirty |= IRIS_DIRTY_SO_DECL_LIST | IRIS_DIRTY_STREAMOUT;
1078 }
1079
1080 if (dirty & IRIS_DIRTY_UNCOMPILED_FS)
1081 iris_update_compiled_fs(ice);
1082 // ...
1083
1084 /* Changing shader interfaces may require a URB configuration. */
1085 if (!(dirty & IRIS_DIRTY_URB)) {
1086 for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
1087 struct brw_vue_prog_data *old = old_prog_datas[i];
1088 struct brw_vue_prog_data *new = get_vue_prog_data(ice, i);
1089 if (!!old != !!new ||
1090 (new && new->urb_entry_size != old->urb_entry_size)) {
1091 ice->state.dirty |= IRIS_DIRTY_URB;
1092 break;
1093 }
1094 }
1095 }
1096 }
1097
1098 static bool
1099 iris_compile_cs(struct iris_context *ice,
1100 struct iris_uncompiled_shader *ish,
1101 const struct brw_cs_prog_key *key)
1102 {
1103 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1104 const struct brw_compiler *compiler = screen->compiler;
1105 const struct gen_device_info *devinfo = &screen->devinfo;
1106 void *mem_ctx = ralloc_context(NULL);
1107 struct brw_cs_prog_data *cs_prog_data =
1108 rzalloc(mem_ctx, struct brw_cs_prog_data);
1109 struct brw_stage_prog_data *prog_data = &cs_prog_data->base;
1110
1111 nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
1112
1113 cs_prog_data->binding_table.work_groups_start = 0;
1114 assign_common_binding_table_offsets(devinfo, nir, prog_data, 1);
1115
1116 iris_setup_uniforms(compiler, mem_ctx, nir, prog_data);
1117
1118 char *error_str = NULL;
1119 const unsigned *program =
1120 brw_compile_cs(compiler, &ice->dbg, mem_ctx, key, cs_prog_data,
1121 nir, -1, &error_str);
1122 if (program == NULL) {
1123 dbg_printf("Failed to compile compute shader: %s\n", error_str);
1124 ralloc_free(mem_ctx);
1125 return false;
1126 }
1127
1128 iris_upload_and_bind_shader(ice, IRIS_CACHE_CS, key, program, prog_data,
1129 NULL);
1130
1131 ralloc_free(mem_ctx);
1132 return true;
1133 }
1134
1135 void
1136 iris_update_compiled_compute_shader(struct iris_context *ice)
1137 {
1138 struct iris_uncompiled_shader *ish =
1139 ice->shaders.uncompiled[MESA_SHADER_COMPUTE];
1140
1141 struct brw_cs_prog_key key = { .program_string_id = ish->program_id };
1142 ice->vtbl.populate_cs_key(ice, &key);
1143
1144 if (iris_bind_cached_shader(ice, IRIS_CACHE_CS, &key))
1145 return;
1146
1147 UNUSED bool success = iris_compile_cs(ice, ish, &key);
1148 }
1149
1150 void
1151 iris_fill_cs_push_const_buffer(struct brw_cs_prog_data *cs_prog_data,
1152 uint32_t *dst)
1153 {
1154 struct brw_stage_prog_data *prog_data = &cs_prog_data->base;
1155 assert(cs_prog_data->push.total.size > 0);
1156 assert(cs_prog_data->push.cross_thread.size == 0);
1157 assert(cs_prog_data->push.per_thread.dwords == 1);
1158 assert(prog_data->param[0] == BRW_PARAM_BUILTIN_SUBGROUP_ID);
1159 for (unsigned t = 0; t < cs_prog_data->threads; t++)
1160 dst[8 * t] = t;
1161 }
1162
1163 /**
1164 * Allocate scratch BOs as needed for the given per-thread size and stage.
1165 *
1166 * Returns the 32-bit "Scratch Space Base Pointer" value.
1167 */
1168 uint32_t
1169 iris_get_scratch_space(struct iris_context *ice,
1170 unsigned per_thread_scratch,
1171 gl_shader_stage stage)
1172 {
1173 struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
1174 struct iris_bufmgr *bufmgr = screen->bufmgr;
1175 const struct gen_device_info *devinfo = &screen->devinfo;
1176
1177 unsigned encoded_size = ffs(per_thread_scratch) - 11;
1178 assert(encoded_size < (1 << 16));
1179
1180 struct iris_bo **bop = &ice->shaders.scratch_bos[encoded_size][stage];
1181
1182 /* The documentation for 3DSTATE_PS "Scratch Space Base Pointer" says:
1183 *
1184 * "Scratch Space per slice is computed based on 4 sub-slices. SW must
1185 * allocate scratch space enough so that each slice has 4 slices
1186 * allowed."
1187 *
1188 * According to the other driver team, this applies to compute shaders
1189 * as well. This is not currently documented at all.
1190 */
1191 unsigned subslice_total = 4 * devinfo->num_slices;
1192 assert(subslice_total >= screen->subslice_total);
1193
1194 if (!*bop) {
1195 unsigned scratch_ids_per_subslice = devinfo->max_cs_threads;
1196 uint32_t max_threads[] = {
1197 [MESA_SHADER_VERTEX] = devinfo->max_vs_threads,
1198 [MESA_SHADER_TESS_CTRL] = devinfo->max_tcs_threads,
1199 [MESA_SHADER_TESS_EVAL] = devinfo->max_tes_threads,
1200 [MESA_SHADER_GEOMETRY] = devinfo->max_gs_threads,
1201 [MESA_SHADER_FRAGMENT] = devinfo->max_wm_threads,
1202 [MESA_SHADER_COMPUTE] = scratch_ids_per_subslice * subslice_total,
1203 };
1204
1205 uint32_t size = per_thread_scratch * max_threads[stage];
1206
1207 *bop = iris_bo_alloc(bufmgr, "scratch", size, IRIS_MEMZONE_SHADER);
1208 }
1209
1210 return (*bop)->gtt_offset;
1211 }
1212
1213 void
1214 iris_init_program_functions(struct pipe_context *ctx)
1215 {
1216 ctx->create_vs_state = iris_create_shader_state;
1217 ctx->create_tcs_state = iris_create_shader_state;
1218 ctx->create_tes_state = iris_create_shader_state;
1219 ctx->create_gs_state = iris_create_shader_state;
1220 ctx->create_fs_state = iris_create_shader_state;
1221 ctx->create_compute_state = iris_create_compute_state;
1222
1223 ctx->delete_vs_state = iris_delete_shader_state;
1224 ctx->delete_tcs_state = iris_delete_shader_state;
1225 ctx->delete_tes_state = iris_delete_shader_state;
1226 ctx->delete_gs_state = iris_delete_shader_state;
1227 ctx->delete_fs_state = iris_delete_shader_state;
1228 ctx->delete_compute_state = iris_delete_shader_state;
1229
1230 ctx->bind_vs_state = iris_bind_vs_state;
1231 ctx->bind_tcs_state = iris_bind_tcs_state;
1232 ctx->bind_tes_state = iris_bind_tes_state;
1233 ctx->bind_gs_state = iris_bind_gs_state;
1234 ctx->bind_fs_state = iris_bind_fs_state;
1235 ctx->bind_compute_state = iris_bind_cs_state;
1236 }