summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/lower_blend_equation_advanced.cpp
blob: c85b39bcaa343691b4c83737a77f9fb562988e02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
/*
 * Copyright © 2016 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "ir.h"
#include "ir_builder.h"
#include "ir_optimization.h"
#include "ir_hierarchical_visitor.h"
#include "program/prog_instruction.h"
#include "program/prog_statevars.h"
#include "util/bitscan.h"
#include "builtin_functions.h"
#include "main/mtypes.h"

using namespace ir_builder;

#define imm1(x) new(mem_ctx) ir_constant((float) (x), 1)
#define imm3(x) new(mem_ctx) ir_constant((float) (x), 3)

static ir_rvalue *
blend_multiply(ir_variable *src, ir_variable *dst)
{
   /* f(Cs,Cd) = Cs*Cd */
   return mul(src, dst);
}

static ir_rvalue *
blend_screen(ir_variable *src, ir_variable *dst)
{
   /* f(Cs,Cd) = Cs+Cd-Cs*Cd */
   return sub(add(src, dst), mul(src, dst));
}

static ir_rvalue *
blend_overlay(ir_variable *src, ir_variable *dst)
{
   void *mem_ctx = ralloc_parent(src);

   /* f(Cs,Cd) = 2*Cs*Cd, if Cd <= 0.5
    *            1-2*(1-Cs)*(1-Cd), otherwise
    */
   ir_rvalue *rule_1 = mul(imm3(2), mul(src, dst));
   ir_rvalue *rule_2 =
      sub(imm3(1), mul(imm3(2), mul(sub(imm3(1), src), sub(imm3(1), dst))));
   return csel(lequal(dst, imm3(0.5f)), rule_1, rule_2);
}

static ir_rvalue *
blend_darken(ir_variable *src, ir_variable *dst)
{
   /* f(Cs,Cd) = min(Cs,Cd) */
   return min2(src, dst);
}

static ir_rvalue *
blend_lighten(ir_variable *src, ir_variable *dst)
{
   /* f(Cs,Cd) = max(Cs,Cd) */
   return max2(src, dst);
}

static ir_rvalue *
blend_colordodge(ir_variable *src, ir_variable *dst)
{
   void *mem_ctx = ralloc_parent(src);

   /* f(Cs,Cd) =
    *   0, if Cd <= 0
    *   min(1,Cd/(1-Cs)), if Cd > 0 and Cs < 1
    *   1, if Cd > 0 and Cs >= 1
    */
   return csel(lequal(dst, imm3(0)), imm3(0),
               csel(gequal(src, imm3(1)), imm3(1),
                    min2(imm3(1), div(dst, sub(imm3(1), src)))));
}

static ir_rvalue *
blend_colorburn(ir_variable *src, ir_variable *dst)
{
   void *mem_ctx = ralloc_parent(src);

   /* f(Cs,Cd) =
    *   1, if Cd >= 1
    *   1 - min(1,(1-Cd)/Cs), if Cd < 1 and Cs > 0
    *   0, if Cd < 1 and Cs <= 0
    */
   return csel(gequal(dst, imm3(1)), imm3(1),
               csel(lequal(src, imm3(0)), imm3(0),
                    sub(imm3(1), min2(imm3(1), div(sub(imm3(1), dst), src)))));
}

static ir_rvalue *
blend_hardlight(ir_variable *src, ir_variable *dst)
{
   void *mem_ctx = ralloc_parent(src);

   /* f(Cs,Cd) = 2*Cs*Cd, if Cs <= 0.5
    *            1-2*(1-Cs)*(1-Cd), otherwise
    */
   ir_rvalue *rule_1 = mul(imm3(2), mul(src, dst));
   ir_rvalue *rule_2 =
      sub(imm3(1), mul(imm3(2), mul(sub(imm3(1), src), sub(imm3(1), dst))));
   return csel(lequal(src, imm3(0.5f)), rule_1, rule_2);
}

static ir_rvalue *
blend_softlight(ir_variable *src, ir_variable *dst)
{
   void *mem_ctx = ralloc_parent(src);

   /* f(Cs,Cd) =
    *   Cd-(1-2*Cs)*Cd*(1-Cd),
    *     if Cs <= 0.5
    *   Cd+(2*Cs-1)*Cd*((16*Cd-12)*Cd+3),
    *     if Cs > 0.5 and Cd <= 0.25
    *   Cd+(2*Cs-1)*(sqrt(Cd)-Cd),
    *     if Cs > 0.5 and Cd > 0.25
    *
    * We can simplify this to
    *
    * f(Cs,Cd) = Cd+(2*Cs-1)*g(Cs,Cd) where
    * g(Cs,Cd) = Cd*Cd-Cd             if Cs <= 0.5
    *            Cd*((16*Cd-12)*Cd+3) if Cs > 0.5 and Cd <= 0.25
    *            sqrt(Cd)-Cd,         otherwise
    */
   ir_rvalue *factor_1 = mul(dst, sub(imm3(1), dst));
   ir_rvalue *factor_2 =
      mul(dst, add(mul(sub(mul(imm3(16), dst), imm3(12)), dst), imm3(3)));
   ir_rvalue *factor_3 = sub(sqrt(dst), dst);
   ir_rvalue *factor = csel(lequal(src, imm3(0.5f)), factor_1,
                            csel(lequal(dst, imm3(0.25f)),
                                        factor_2, factor_3));
   return add(dst, mul(sub(mul(imm3(2), src), imm3(1)), factor));
}

static ir_rvalue *
blend_difference(ir_variable *src, ir_variable *dst)
{
   return abs(sub(dst, src));
}

static ir_rvalue *
blend_exclusion(ir_variable *src, ir_variable *dst)
{
   void *mem_ctx = ralloc_parent(src);

   return add(src, sub(dst, mul(imm3(2), mul(src, dst))));
}

/* Return the minimum of a vec3's components */
static ir_rvalue *
minv3(ir_variable *v)
{
   return min2(min2(swizzle_x(v), swizzle_y(v)), swizzle_z(v));
}

/* Return the maximum of a vec3's components */
static ir_rvalue *
maxv3(ir_variable *v)
{
   return max2(max2(swizzle_x(v), swizzle_y(v)), swizzle_z(v));
}

static ir_rvalue *
lumv3(ir_variable *c)
{
   ir_constant_data data;
   data.f[0] = 0.30;
   data.f[1] = 0.59;
   data.f[2] = 0.11;

   void *mem_ctx = ralloc_parent(c);

   /* dot(c, vec3(0.30, 0.59, 0.11)) */
   return dot(c, new(mem_ctx) ir_constant(glsl_type::vec3_type, &data));
}

static ir_rvalue *
satv3(ir_variable *c)
{
   return sub(maxv3(c), minv3(c));
}

/* Take the base RGB color <cbase> and override its luminosity with that
 * of the RGB color <clum>.
 *
 * This follows the equations given in the ES 3.2 (June 15th, 2016)
 * specification.  Revision 16 of GL_KHR_blend_equation_advanced and
 * revision 9 of GL_NV_blend_equation_advanced specify a different set
 * of equations.  Older revisions match ES 3.2's text, and dEQP expects
 * the ES 3.2 rules implemented here.
 */
static void
set_lum(ir_factory *f,
        ir_variable *color,
        ir_variable *cbase,
        ir_variable *clum)
{
   void *mem_ctx = f->mem_ctx;
   f->emit(assign(color, add(cbase, sub(lumv3(clum), lumv3(cbase)))));

   ir_variable *llum = f->make_temp(glsl_type::float_type, "__blend_lum");
   ir_variable *mincol = f->make_temp(glsl_type::float_type, "__blend_mincol");
   ir_variable *maxcol = f->make_temp(glsl_type::float_type, "__blend_maxcol");

   f->emit(assign(llum, lumv3(color)));
   f->emit(assign(mincol, minv3(color)));
   f->emit(assign(maxcol, maxv3(color)));

   f->emit(if_tree(less(mincol, imm1(0)),
                   assign(color, add(llum, div(mul(sub(color, llum), llum),
                                               sub(llum, mincol)))),
                   if_tree(greater(maxcol, imm1(1)),
                           assign(color, add(llum, div(mul(sub(color, llum),
                                                           sub(imm3(1), llum)),
                                                       sub(maxcol, llum)))))));

}

/* Take the base RGB color <cbase> and override its saturation with
 * that of the RGB color <csat>.  The override the luminosity of the
 * result with that of the RGB color <clum>.
 */
static void
set_lum_sat(ir_factory *f,
            ir_variable *color,
            ir_variable *cbase,
            ir_variable *csat,
            ir_variable *clum)
{
   void *mem_ctx = f->mem_ctx;

   ir_rvalue *minbase = minv3(cbase);
   ir_rvalue *ssat = satv3(csat);

   ir_variable *sbase = f->make_temp(glsl_type::float_type, "__blend_sbase");
   f->emit(assign(sbase, satv3(cbase)));

   /* Equivalent (modulo rounding errors) to setting the
    * smallest (R,G,B) component to 0, the largest to <ssat>,
    * and interpolating the "middle" component based on its
    * original value relative to the smallest/largest.
    */
   f->emit(if_tree(greater(sbase, imm1(0)),
                   assign(color, div(mul(sub(cbase, minbase), ssat), sbase)),
                   assign(color, imm3(0))));
   set_lum(f, color, color, clum);
}

static ir_rvalue *
is_mode(ir_variable *mode, enum gl_advanced_blend_mode q)
{
   return equal(mode, new(ralloc_parent(mode)) ir_constant(unsigned(q)));
}

static ir_variable *
calc_blend_result(ir_factory f,
                  ir_variable *mode,
                  ir_variable *fb,
                  ir_rvalue *blend_src,
                  GLbitfield blend_qualifiers)
{
   void *mem_ctx = f.mem_ctx;
   ir_variable *result = f.make_temp(glsl_type::vec4_type, "__blend_result");

   /* Save blend_src to a temporary so we can reference it multiple times. */
   ir_variable *src = f.make_temp(glsl_type::vec4_type, "__blend_src");
   f.emit(assign(src, blend_src));

   /* If we're not doing advanced blending, just write the original value. */
   ir_if *if_blending = new(mem_ctx) ir_if(is_mode(mode, BLEND_NONE));
   f.emit(if_blending);
   if_blending->then_instructions.push_tail(assign(result, src));

   f.instructions = &if_blending->else_instructions;

   /* (Rs', Gs', Bs') =
    *   (0, 0, 0),              if As == 0
    *   (Rs/As, Gs/As, Bs/As),  otherwise
    */
   ir_variable *src_rgb = f.make_temp(glsl_type::vec3_type, "__blend_src_rgb");
   ir_variable *src_alpha = f.make_temp(glsl_type::float_type, "__blend_src_a");

   /* (Rd', Gd', Bd') =
    *   (0, 0, 0),              if Ad == 0
    *   (Rd/Ad, Gd/Ad, Bd/Ad),  otherwise
    */
   ir_variable *dst_rgb = f.make_temp(glsl_type::vec3_type, "__blend_dst_rgb");
   ir_variable *dst_alpha = f.make_temp(glsl_type::float_type, "__blend_dst_a");

   f.emit(assign(dst_alpha, swizzle_w(fb)));
   f.emit(if_tree(equal(dst_alpha, imm1(0)),
                     assign(dst_rgb, imm3(0)),
                     assign(dst_rgb, csel(equal(swizzle_xyz(fb),
                                                swizzle(fb, SWIZZLE_WWWW, 3)),
                                          imm3(1),
                                          div(swizzle_xyz(fb), dst_alpha)))));

   f.emit(assign(src_alpha, swizzle_w(src)));
   f.emit(if_tree(equal(src_alpha, imm1(0)),
                     assign(src_rgb, imm3(0)),
                     assign(src_rgb, csel(equal(swizzle_xyz(src),
                                                swizzle(src, SWIZZLE_WWWW, 3)),
                                          imm3(1),
                                          div(swizzle_xyz(src), src_alpha)))));

   ir_variable *factor = f.make_temp(glsl_type::vec3_type, "__blend_factor");

   ir_factory casefactory = f;

   unsigned choices = blend_qualifiers;
   while (choices) {
      enum gl_advanced_blend_mode choice = (enum gl_advanced_blend_mode)
         (1u << u_bit_scan(&choices));

      ir_if *iff = new(mem_ctx) ir_if(is_mode(mode, choice));
      casefactory.emit(iff);
      casefactory.instructions = &iff->then_instructions;

      ir_rvalue *val = NULL;

      switch (choice) {
      case BLEND_MULTIPLY:
         val = blend_multiply(src_rgb, dst_rgb);
         break;
      case BLEND_SCREEN:
         val = blend_screen(src_rgb, dst_rgb);
         break;
      case BLEND_OVERLAY:
         val = blend_overlay(src_rgb, dst_rgb);
         break;
      case BLEND_DARKEN:
         val = blend_darken(src_rgb, dst_rgb);
         break;
      case BLEND_LIGHTEN:
         val = blend_lighten(src_rgb, dst_rgb);
         break;
      case BLEND_COLORDODGE:
         val = blend_colordodge(src_rgb, dst_rgb);
         break;
      case BLEND_COLORBURN:
         val = blend_colorburn(src_rgb, dst_rgb);
         break;
      case BLEND_HARDLIGHT:
         val = blend_hardlight(src_rgb, dst_rgb);
         break;
      case BLEND_SOFTLIGHT:
         val = blend_softlight(src_rgb, dst_rgb);
         break;
      case BLEND_DIFFERENCE:
         val = blend_difference(src_rgb, dst_rgb);
         break;
      case BLEND_EXCLUSION:
         val = blend_exclusion(src_rgb, dst_rgb);
         break;
      case BLEND_HSL_HUE:
         set_lum_sat(&casefactory, factor, src_rgb, dst_rgb, dst_rgb);
         break;
      case BLEND_HSL_SATURATION:
         set_lum_sat(&casefactory, factor, dst_rgb, src_rgb, dst_rgb);
         break;
      case BLEND_HSL_COLOR:
         set_lum(&casefactory, factor, src_rgb, dst_rgb);
         break;
      case BLEND_HSL_LUMINOSITY:
         set_lum(&casefactory, factor, dst_rgb, src_rgb);
         break;
      case BLEND_NONE:
      case BLEND_ALL:
         unreachable("not real cases");
      }

      if (val)
         casefactory.emit(assign(factor, val));

      casefactory.instructions = &iff->else_instructions;
   }

   /* p0(As,Ad) = As*Ad
    * p1(As,Ad) = As*(1-Ad)
    * p2(As,Ad) = Ad*(1-As)
    */
   ir_variable *p0 = f.make_temp(glsl_type::float_type, "__blend_p0");
   ir_variable *p1 = f.make_temp(glsl_type::float_type, "__blend_p1");
   ir_variable *p2 = f.make_temp(glsl_type::float_type, "__blend_p2");

   f.emit(assign(p0, mul(src_alpha, dst_alpha)));
   f.emit(assign(p1, mul(src_alpha, sub(imm1(1), dst_alpha))));
   f.emit(assign(p2, mul(dst_alpha, sub(imm1(1), src_alpha))));

   /* R = f(Rs',Rd')*p0(As,Ad) + Y*Rs'*p1(As,Ad) + Z*Rd'*p2(As,Ad)
    * G = f(Gs',Gd')*p0(As,Ad) + Y*Gs'*p1(As,Ad) + Z*Gd'*p2(As,Ad)
    * B = f(Bs',Bd')*p0(As,Ad) + Y*Bs'*p1(As,Ad) + Z*Bd'*p2(As,Ad)
    * A =          X*p0(As,Ad) +     Y*p1(As,Ad) +     Z*p2(As,Ad)
    *
    * <X, Y, Z> is always <1, 1, 1>, so we can ignore it.
    *
    * In vector form, this is:
    * RGB = factor * p0 + Cs * p1 + Cd * p2
    *   A = p0 + p1 + p2
    */
   f.emit(assign(result,
                 add(add(mul(factor, p0), mul(src_rgb, p1)), mul(dst_rgb, p2)),
                 WRITEMASK_XYZ));
   f.emit(assign(result, add(add(p0, p1), p2), WRITEMASK_W));

   return result;
}

/**
 * Dereference var, or var[0] if it's an array.
 */
static ir_dereference *
deref_output(ir_variable *var)
{
   void *mem_ctx = ralloc_parent(var);

   ir_dereference *val = new(mem_ctx) ir_dereference_variable(var);
   if (val->type->is_array()) {
      ir_constant *index = new(mem_ctx) ir_constant(0);
      val = new(mem_ctx) ir_dereference_array(val, index);
   }

   return val;
}

static ir_function_signature *
get_main(gl_linked_shader *sh)
{
   ir_function_signature *sig = NULL;
   /* We can't use _mesa_get_main_function_signature() because we don't
    * have a symbol table at this point.  Just go find main() by hand.
    */
   foreach_in_list(ir_instruction, ir, sh->ir) {
      ir_function *f = ir->as_function();
      if (f && strcmp(f->name, "main") == 0) {
         exec_list void_parameters;
         sig = f->matching_signature(NULL, &void_parameters, false);
         break;
      }
   }
   assert(sig != NULL); /* main() must exist */
   return sig;
}

bool
lower_blend_equation_advanced(struct gl_linked_shader *sh, bool coherent)
{
   if (sh->Program->sh.fs.BlendSupport == 0)
      return false;

   /* Lower early returns in main() so there's a single exit point
    * where we can insert our lowering code.
    */
   do_lower_jumps(sh->ir, false, false, true, false, false);

   void *mem_ctx = ralloc_parent(sh->ir);

   ir_variable *fb = new(mem_ctx) ir_variable(glsl_type::vec4_type,
                                              "__blend_fb_fetch",
                                              ir_var_shader_out);
   fb->data.location = FRAG_RESULT_DATA0;
   fb->data.read_only = 1;
   fb->data.fb_fetch_output = 1;
   fb->data.memory_coherent = coherent;
   fb->data.how_declared = ir_var_hidden;

   ir_variable *mode = new(mem_ctx) ir_variable(glsl_type::uint_type,
                                                "gl_AdvancedBlendModeMESA",
                                                ir_var_uniform);
   mode->data.how_declared = ir_var_hidden;
   mode->allocate_state_slots(1);
   ir_state_slot *slot0 = &mode->get_state_slots()[0];
   slot0->swizzle = SWIZZLE_XXXX;
   slot0->tokens[0] = STATE_INTERNAL;
   slot0->tokens[1] = STATE_ADVANCED_BLENDING_MODE;
   for (int i = 2; i < STATE_LENGTH; i++)
      slot0->tokens[i] = 0;

   sh->ir->push_head(fb);
   sh->ir->push_head(mode);

   /* Gather any output variables referring to render target 0.
    *
    * ARB_enhanced_layouts irritatingly allows the shader to specify
    * multiple output variables for the same render target, each of
    * which writes a subset of the components, starting at location_frac.
    * The variables can't overlap, thankfully.
    */
   ir_variable *outputs[4] = { NULL, NULL, NULL, NULL };
   foreach_in_list(ir_instruction, ir, sh->ir) {
      ir_variable *var = ir->as_variable();
      if (!var || var->data.mode != ir_var_shader_out)
         continue;

      if (var->data.location == FRAG_RESULT_DATA0 ||
          var->data.location == FRAG_RESULT_COLOR) {
         const int components = var->type->without_array()->vector_elements;

         for (int i = 0; i < components; i++) {
            outputs[var->data.location_frac + i] = var;
         }
      }
   }

   /* Combine values written to outputs into a single RGBA blend source.
    * We assign <0, 0, 0, 1> to any components with no corresponding output.
    */
   ir_rvalue *blend_source;
   if (outputs[0] && outputs[0]->type->without_array()->vector_elements == 4) {
      blend_source = deref_output(outputs[0]);
   } else {
      ir_rvalue *blend_comps[4];
      for (int i = 0; i < 4; i++) {
         ir_variable *var = outputs[i];
         if (var) {
            blend_comps[i] = swizzle(deref_output(outputs[i]),
                                     i - outputs[i]->data.location_frac, 1);
         } else {
            blend_comps[i] = new(mem_ctx) ir_constant(i < 3 ? 0.0f : 1.0f);
         }
      }

      blend_source =
         new(mem_ctx) ir_expression(ir_quadop_vector, glsl_type::vec4_type,
                                    blend_comps[0], blend_comps[1],
                                    blend_comps[2], blend_comps[3]);
   }

   ir_function_signature *main = get_main(sh);
   ir_factory f(&main->body, mem_ctx);

   ir_variable *result_dest =
      calc_blend_result(f, mode, fb, blend_source,
                        sh->Program->sh.fs.BlendSupport);

   /* Copy the result back to the original values.  It would be simpler
    * to demote the program's output variables, and create a new vec4
    * output for our result, but this pass runs before we create the
    * ARB_program_interface_query resource list.  So we have to leave
    * the original outputs in place and use them.
    */
   for (int i = 0; i < 4; i++) {
      if (!outputs[i])
         continue;

      f.emit(assign(deref_output(outputs[i]), swizzle(result_dest, i, 1),
                    1 << i));
   }

   validate_ir_tree(sh->ir);
   return true;
}