2 * Copyright © 2010 Intel Corporation
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:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 * This file drives the GLSL IR -> LIR translation, contains the
27 * optimizations on the LIR, and drives the generation of native code
33 #include <sys/types.h>
35 #include "main/hash_table.h"
36 #include "main/macros.h"
37 #include "main/shaderobj.h"
38 #include "main/uniforms.h"
39 #include "main/fbobject.h"
40 #include "program/prog_parameter.h"
41 #include "program/prog_print.h"
42 #include "program/register_allocate.h"
43 #include "program/sampler.h"
44 #include "program/hash_table.h"
45 #include "brw_context.h"
50 #include "glsl/glsl_types.h"
55 memset(this, 0, sizeof(*this));
56 this->opcode
= BRW_OPCODE_NOP
;
57 this->conditional_mod
= BRW_CONDITIONAL_NONE
;
59 this->dst
= reg_undef
;
60 this->src
[0] = reg_undef
;
61 this->src
[1] = reg_undef
;
62 this->src
[2] = reg_undef
;
64 /* This will be the case for almost all instructions. */
65 this->regs_written
= 1;
73 fs_inst::fs_inst(enum opcode opcode
)
76 this->opcode
= opcode
;
79 fs_inst::fs_inst(enum opcode opcode
, fs_reg dst
)
82 this->opcode
= opcode
;
86 assert(dst
.reg_offset
>= 0);
89 fs_inst::fs_inst(enum opcode opcode
, fs_reg dst
, fs_reg src0
)
92 this->opcode
= opcode
;
97 assert(dst
.reg_offset
>= 0);
98 if (src
[0].file
== GRF
)
99 assert(src
[0].reg_offset
>= 0);
102 fs_inst::fs_inst(enum opcode opcode
, fs_reg dst
, fs_reg src0
, fs_reg src1
)
105 this->opcode
= opcode
;
111 assert(dst
.reg_offset
>= 0);
112 if (src
[0].file
== GRF
)
113 assert(src
[0].reg_offset
>= 0);
114 if (src
[1].file
== GRF
)
115 assert(src
[1].reg_offset
>= 0);
118 fs_inst::fs_inst(enum opcode opcode
, fs_reg dst
,
119 fs_reg src0
, fs_reg src1
, fs_reg src2
)
122 this->opcode
= opcode
;
129 assert(dst
.reg_offset
>= 0);
130 if (src
[0].file
== GRF
)
131 assert(src
[0].reg_offset
>= 0);
132 if (src
[1].file
== GRF
)
133 assert(src
[1].reg_offset
>= 0);
134 if (src
[2].file
== GRF
)
135 assert(src
[2].reg_offset
>= 0);
140 fs_visitor::op(fs_reg dst, fs_reg src0) \
142 return new(mem_ctx) fs_inst(BRW_OPCODE_##op, dst, src0); \
147 fs_visitor::op(fs_reg dst, fs_reg src0, fs_reg src1) \
149 return new(mem_ctx) fs_inst(BRW_OPCODE_##op, dst, src0, src1); \
154 fs_visitor::op(fs_reg dst, fs_reg src0, fs_reg src1, fs_reg src2) \
156 return new(mem_ctx) fs_inst(BRW_OPCODE_##op, dst, src0, src1, src2);\
184 /** Gen4 predicated IF. */
186 fs_visitor::IF(uint32_t predicate
)
188 fs_inst
*inst
= new(mem_ctx
) fs_inst(BRW_OPCODE_IF
);
189 inst
->predicate
= predicate
;
193 /** Gen6+ IF with embedded comparison. */
195 fs_visitor::IF(fs_reg src0
, fs_reg src1
, uint32_t condition
)
197 assert(brw
->gen
>= 6);
198 fs_inst
*inst
= new(mem_ctx
) fs_inst(BRW_OPCODE_IF
,
199 reg_null_d
, src0
, src1
);
200 inst
->conditional_mod
= condition
;
205 * CMP: Sets the low bit of the destination channels with the result
206 * of the comparison, while the upper bits are undefined, and updates
207 * the flag register with the packed 16 bits of the result.
210 fs_visitor::CMP(fs_reg dst
, fs_reg src0
, fs_reg src1
, uint32_t condition
)
214 /* Take the instruction:
216 * CMP null<d> src0<f> src1<f>
218 * Original gen4 does type conversion to the destination type before
219 * comparison, producing garbage results for floating point comparisons.
220 * gen5 does the comparison on the execution type (resolved source types),
221 * so dst type doesn't matter. gen6 does comparison and then uses the
222 * result as if it was the dst type with no conversion, which happens to
223 * mostly work out for float-interpreted-as-int since our comparisons are
227 dst
.type
= src0
.type
;
228 if (dst
.file
== HW_REG
)
229 dst
.fixed_hw_reg
.type
= dst
.type
;
232 resolve_ud_negate(&src0
);
233 resolve_ud_negate(&src1
);
235 inst
= new(mem_ctx
) fs_inst(BRW_OPCODE_CMP
, dst
, src0
, src1
);
236 inst
->conditional_mod
= condition
;
242 fs_visitor::VARYING_PULL_CONSTANT_LOAD(fs_reg dst
, fs_reg surf_index
,
243 fs_reg varying_offset
,
244 uint32_t const_offset
)
246 exec_list instructions
;
249 /* We have our constant surface use a pitch of 4 bytes, so our index can
250 * be any component of a vector, and then we load 4 contiguous
251 * components starting from that.
253 * We break down the const_offset to a portion added to the variable
254 * offset and a portion done using reg_offset, which means that if you
255 * have GLSL using something like "uniform vec4 a[20]; gl_FragColor =
256 * a[i]", we'll temporarily generate 4 vec4 loads from offset i * 4, and
257 * CSE can later notice that those loads are all the same and eliminate
258 * the redundant ones.
260 fs_reg vec4_offset
= fs_reg(this, glsl_type::int_type
);
261 instructions
.push_tail(ADD(vec4_offset
,
262 varying_offset
, const_offset
& ~3));
265 if (brw
->gen
== 4 && dispatch_width
== 8) {
266 /* Pre-gen5, we can either use a SIMD8 message that requires (header,
267 * u, v, r) as parameters, or we can just use the SIMD16 message
268 * consisting of (header, u). We choose the second, at the cost of a
269 * longer return length.
276 op
= FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7
;
278 op
= FS_OPCODE_VARYING_PULL_CONSTANT_LOAD
;
279 fs_reg vec4_result
= fs_reg(GRF
, virtual_grf_alloc(4 * scale
), dst
.type
);
280 inst
= new(mem_ctx
) fs_inst(op
, vec4_result
, surf_index
, vec4_offset
);
281 inst
->regs_written
= 4 * scale
;
282 instructions
.push_tail(inst
);
286 inst
->header_present
= true;
290 inst
->mlen
= 1 + dispatch_width
/ 8;
293 vec4_result
.reg_offset
+= (const_offset
& 3) * scale
;
294 instructions
.push_tail(MOV(dst
, vec4_result
));
300 * A helper for MOV generation for fixing up broken hardware SEND dependency
304 fs_visitor::DEP_RESOLVE_MOV(int grf
)
306 fs_inst
*inst
= MOV(brw_null_reg(), fs_reg(GRF
, grf
, BRW_REGISTER_TYPE_F
));
309 inst
->annotation
= "send dependency resolve";
311 /* The caller always wants uncompressed to emit the minimal extra
312 * dependencies, and to avoid having to deal with aligning its regs to 2.
314 inst
->force_uncompressed
= true;
320 fs_inst::equals(fs_inst
*inst
)
322 return (opcode
== inst
->opcode
&&
323 dst
.equals(inst
->dst
) &&
324 src
[0].equals(inst
->src
[0]) &&
325 src
[1].equals(inst
->src
[1]) &&
326 src
[2].equals(inst
->src
[2]) &&
327 saturate
== inst
->saturate
&&
328 predicate
== inst
->predicate
&&
329 conditional_mod
== inst
->conditional_mod
&&
330 mlen
== inst
->mlen
&&
331 base_mrf
== inst
->base_mrf
&&
332 sampler
== inst
->sampler
&&
333 target
== inst
->target
&&
335 header_present
== inst
->header_present
&&
336 shadow_compare
== inst
->shadow_compare
&&
337 offset
== inst
->offset
);
341 fs_inst::overwrites_reg(const fs_reg
®
)
343 return (reg
.file
== dst
.file
&&
344 reg
.reg
== dst
.reg
&&
345 reg
.reg_offset
>= dst
.reg_offset
&&
346 reg
.reg_offset
< dst
.reg_offset
+ regs_written
);
350 fs_inst::is_send_from_grf()
352 return (opcode
== FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7
||
353 opcode
== SHADER_OPCODE_SHADER_TIME_ADD
||
354 (opcode
== FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
&&
355 src
[1].file
== GRF
));
359 fs_visitor::can_do_source_mods(fs_inst
*inst
)
361 if (brw
->gen
== 6 && inst
->is_math())
364 if (inst
->is_send_from_grf())
373 memset(this, 0, sizeof(*this));
377 /** Generic unset register constructor. */
381 this->file
= BAD_FILE
;
384 /** Immediate value constructor. */
385 fs_reg::fs_reg(float f
)
389 this->type
= BRW_REGISTER_TYPE_F
;
393 /** Immediate value constructor. */
394 fs_reg::fs_reg(int32_t i
)
398 this->type
= BRW_REGISTER_TYPE_D
;
402 /** Immediate value constructor. */
403 fs_reg::fs_reg(uint32_t u
)
407 this->type
= BRW_REGISTER_TYPE_UD
;
411 /** Fixed brw_reg Immediate value constructor. */
412 fs_reg::fs_reg(struct brw_reg fixed_hw_reg
)
416 this->fixed_hw_reg
= fixed_hw_reg
;
417 this->type
= fixed_hw_reg
.type
;
421 fs_reg::equals(const fs_reg
&r
) const
423 return (file
== r
.file
&&
425 reg_offset
== r
.reg_offset
&&
427 negate
== r
.negate
&&
429 !reladdr
&& !r
.reladdr
&&
430 memcmp(&fixed_hw_reg
, &r
.fixed_hw_reg
,
431 sizeof(fixed_hw_reg
)) == 0 &&
437 fs_reg::is_zero() const
442 return type
== BRW_REGISTER_TYPE_F
? imm
.f
== 0.0 : imm
.i
== 0;
446 fs_reg::is_one() const
451 return type
== BRW_REGISTER_TYPE_F
? imm
.f
== 1.0 : imm
.i
== 1;
455 fs_reg::is_valid_3src() const
457 return file
== GRF
|| file
== UNIFORM
;
461 fs_visitor::type_size(const struct glsl_type
*type
)
463 unsigned int size
, i
;
465 switch (type
->base_type
) {
468 case GLSL_TYPE_FLOAT
:
470 return type
->components();
471 case GLSL_TYPE_ARRAY
:
472 return type_size(type
->fields
.array
) * type
->length
;
473 case GLSL_TYPE_STRUCT
:
475 for (i
= 0; i
< type
->length
; i
++) {
476 size
+= type_size(type
->fields
.structure
[i
].type
);
479 case GLSL_TYPE_SAMPLER
:
480 /* Samplers take up no register space, since they're baked in at
485 case GLSL_TYPE_ERROR
:
486 case GLSL_TYPE_INTERFACE
:
487 assert(!"not reached");
495 fs_visitor::get_timestamp()
497 assert(brw
->gen
>= 7);
499 fs_reg ts
= fs_reg(retype(brw_vec1_reg(BRW_ARCHITECTURE_REGISTER_FILE
,
502 BRW_REGISTER_TYPE_UD
));
504 fs_reg dst
= fs_reg(this, glsl_type::uint_type
);
506 fs_inst
*mov
= emit(MOV(dst
, ts
));
507 /* We want to read the 3 fields we care about (mostly field 0, but also 2)
508 * even if it's not enabled in the dispatch.
510 mov
->force_writemask_all
= true;
511 mov
->force_uncompressed
= true;
513 /* The caller wants the low 32 bits of the timestamp. Since it's running
514 * at the GPU clock rate of ~1.2ghz, it will roll over every ~3 seconds,
515 * which is plenty of time for our purposes. It is identical across the
516 * EUs, but since it's tracking GPU core speed it will increment at a
517 * varying rate as render P-states change.
519 * The caller could also check if render P-states have changed (or anything
520 * else that might disrupt timing) by setting smear to 2 and checking if
521 * that field is != 0.
529 fs_visitor::emit_shader_time_begin()
531 current_annotation
= "shader time start";
532 shader_start_time
= get_timestamp();
536 fs_visitor::emit_shader_time_end()
538 current_annotation
= "shader time end";
540 enum shader_time_shader_type type
, written_type
, reset_type
;
541 if (dispatch_width
== 8) {
543 written_type
= ST_FS8_WRITTEN
;
544 reset_type
= ST_FS8_RESET
;
546 assert(dispatch_width
== 16);
548 written_type
= ST_FS16_WRITTEN
;
549 reset_type
= ST_FS16_RESET
;
552 fs_reg shader_end_time
= get_timestamp();
554 /* Check that there weren't any timestamp reset events (assuming these
555 * were the only two timestamp reads that happened).
557 fs_reg reset
= shader_end_time
;
559 fs_inst
*test
= emit(AND(reg_null_d
, reset
, fs_reg(1u)));
560 test
->conditional_mod
= BRW_CONDITIONAL_Z
;
561 emit(IF(BRW_PREDICATE_NORMAL
));
563 push_force_uncompressed();
564 fs_reg start
= shader_start_time
;
566 fs_reg diff
= fs_reg(this, glsl_type::uint_type
);
567 emit(ADD(diff
, start
, shader_end_time
));
569 /* If there were no instructions between the two timestamp gets, the diff
570 * is 2 cycles. Remove that overhead, so I can forget about that when
571 * trying to determine the time taken for single instructions.
573 emit(ADD(diff
, diff
, fs_reg(-2u)));
575 emit_shader_time_write(type
, diff
);
576 emit_shader_time_write(written_type
, fs_reg(1u));
577 emit(BRW_OPCODE_ELSE
);
578 emit_shader_time_write(reset_type
, fs_reg(1u));
579 emit(BRW_OPCODE_ENDIF
);
581 pop_force_uncompressed();
585 fs_visitor::emit_shader_time_write(enum shader_time_shader_type type
,
588 int shader_time_index
=
589 brw_get_shader_time_index(brw
, shader_prog
, &fp
->Base
, type
);
590 fs_reg offset
= fs_reg(shader_time_index
* SHADER_TIME_STRIDE
);
593 if (dispatch_width
== 8)
594 payload
= fs_reg(this, glsl_type::uvec2_type
);
596 payload
= fs_reg(this, glsl_type::uint_type
);
598 emit(fs_inst(SHADER_OPCODE_SHADER_TIME_ADD
,
599 fs_reg(), payload
, offset
, value
));
603 fs_visitor::fail(const char *format
, ...)
613 va_start(va
, format
);
614 msg
= ralloc_vasprintf(mem_ctx
, format
, va
);
616 msg
= ralloc_asprintf(mem_ctx
, "FS compile failed: %s\n", msg
);
618 this->fail_msg
= msg
;
620 if (INTEL_DEBUG
& DEBUG_WM
) {
621 fprintf(stderr
, "%s", msg
);
626 fs_visitor::emit(enum opcode opcode
)
628 return emit(fs_inst(opcode
));
632 fs_visitor::emit(enum opcode opcode
, fs_reg dst
)
634 return emit(fs_inst(opcode
, dst
));
638 fs_visitor::emit(enum opcode opcode
, fs_reg dst
, fs_reg src0
)
640 return emit(fs_inst(opcode
, dst
, src0
));
644 fs_visitor::emit(enum opcode opcode
, fs_reg dst
, fs_reg src0
, fs_reg src1
)
646 return emit(fs_inst(opcode
, dst
, src0
, src1
));
650 fs_visitor::emit(enum opcode opcode
, fs_reg dst
,
651 fs_reg src0
, fs_reg src1
, fs_reg src2
)
653 return emit(fs_inst(opcode
, dst
, src0
, src1
, src2
));
657 fs_visitor::push_force_uncompressed()
659 force_uncompressed_stack
++;
663 fs_visitor::pop_force_uncompressed()
665 force_uncompressed_stack
--;
666 assert(force_uncompressed_stack
>= 0);
670 fs_visitor::push_force_sechalf()
672 force_sechalf_stack
++;
676 fs_visitor::pop_force_sechalf()
678 force_sechalf_stack
--;
679 assert(force_sechalf_stack
>= 0);
683 * Returns true if the instruction has a flag that means it won't
684 * update an entire destination register.
686 * For example, dead code elimination and live variable analysis want to know
687 * when a write to a variable screens off any preceding values that were in
691 fs_inst::is_partial_write()
693 return ((this->predicate
&& this->opcode
!= BRW_OPCODE_SEL
) ||
694 this->force_uncompressed
||
695 this->force_sechalf
);
699 * Returns how many MRFs an FS opcode will write over.
701 * Note that this is not the 0 or 1 implied writes in an actual gen
702 * instruction -- the FS opcodes often generate MOVs in addition.
705 fs_visitor::implied_mrf_writes(fs_inst
*inst
)
710 switch (inst
->opcode
) {
711 case SHADER_OPCODE_RCP
:
712 case SHADER_OPCODE_RSQ
:
713 case SHADER_OPCODE_SQRT
:
714 case SHADER_OPCODE_EXP2
:
715 case SHADER_OPCODE_LOG2
:
716 case SHADER_OPCODE_SIN
:
717 case SHADER_OPCODE_COS
:
718 return 1 * dispatch_width
/ 8;
719 case SHADER_OPCODE_POW
:
720 case SHADER_OPCODE_INT_QUOTIENT
:
721 case SHADER_OPCODE_INT_REMAINDER
:
722 return 2 * dispatch_width
/ 8;
723 case SHADER_OPCODE_TEX
:
725 case SHADER_OPCODE_TXD
:
726 case SHADER_OPCODE_TXF
:
727 case SHADER_OPCODE_TXF_MS
:
728 case SHADER_OPCODE_TXL
:
729 case SHADER_OPCODE_TXS
:
730 case SHADER_OPCODE_LOD
:
732 case FS_OPCODE_FB_WRITE
:
734 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
:
735 case FS_OPCODE_UNSPILL
:
737 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD
:
739 case FS_OPCODE_SPILL
:
742 assert(!"not reached");
748 fs_visitor::virtual_grf_alloc(int size
)
750 if (virtual_grf_array_size
<= virtual_grf_count
) {
751 if (virtual_grf_array_size
== 0)
752 virtual_grf_array_size
= 16;
754 virtual_grf_array_size
*= 2;
755 virtual_grf_sizes
= reralloc(mem_ctx
, virtual_grf_sizes
, int,
756 virtual_grf_array_size
);
758 virtual_grf_sizes
[virtual_grf_count
] = size
;
759 return virtual_grf_count
++;
762 /** Fixed HW reg constructor. */
763 fs_reg::fs_reg(enum register_file file
, int reg
)
768 this->type
= BRW_REGISTER_TYPE_F
;
771 /** Fixed HW reg constructor. */
772 fs_reg::fs_reg(enum register_file file
, int reg
, uint32_t type
)
780 /** Automatic reg constructor. */
781 fs_reg::fs_reg(class fs_visitor
*v
, const struct glsl_type
*type
)
786 this->reg
= v
->virtual_grf_alloc(v
->type_size(type
));
787 this->reg_offset
= 0;
788 this->type
= brw_type_for_base_type(type
);
792 fs_visitor::variable_storage(ir_variable
*var
)
794 return (fs_reg
*)hash_table_find(this->variable_ht
, var
);
798 import_uniforms_callback(const void *key
,
802 struct hash_table
*dst_ht
= (struct hash_table
*)closure
;
803 const fs_reg
*reg
= (const fs_reg
*)data
;
805 if (reg
->file
!= UNIFORM
)
808 hash_table_insert(dst_ht
, data
, key
);
811 /* For 16-wide, we need to follow from the uniform setup of 8-wide dispatch.
812 * This brings in those uniform definitions
815 fs_visitor::import_uniforms(fs_visitor
*v
)
817 hash_table_call_foreach(v
->variable_ht
,
818 import_uniforms_callback
,
820 this->params_remap
= v
->params_remap
;
821 this->nr_params_remap
= v
->nr_params_remap
;
824 /* Our support for uniforms is piggy-backed on the struct
825 * gl_fragment_program, because that's where the values actually
826 * get stored, rather than in some global gl_shader_program uniform
830 fs_visitor::setup_uniform_values(ir_variable
*ir
)
832 int namelen
= strlen(ir
->name
);
834 /* The data for our (non-builtin) uniforms is stored in a series of
835 * gl_uniform_driver_storage structs for each subcomponent that
836 * glGetUniformLocation() could name. We know it's been set up in the same
837 * order we'd walk the type, so walk the list of storage and find anything
838 * with our name, or the prefix of a component that starts with our name.
840 unsigned params_before
= c
->prog_data
.nr_params
;
841 for (unsigned u
= 0; u
< shader_prog
->NumUserUniformStorage
; u
++) {
842 struct gl_uniform_storage
*storage
= &shader_prog
->UniformStorage
[u
];
844 if (strncmp(ir
->name
, storage
->name
, namelen
) != 0 ||
845 (storage
->name
[namelen
] != 0 &&
846 storage
->name
[namelen
] != '.' &&
847 storage
->name
[namelen
] != '[')) {
851 unsigned slots
= storage
->type
->component_slots();
852 if (storage
->array_elements
)
853 slots
*= storage
->array_elements
;
855 for (unsigned i
= 0; i
< slots
; i
++) {
856 c
->prog_data
.param
[c
->prog_data
.nr_params
++] =
857 &storage
->storage
[i
].f
;
861 /* Make sure we actually initialized the right amount of stuff here. */
862 assert(params_before
+ ir
->type
->component_slots() ==
863 c
->prog_data
.nr_params
);
868 /* Our support for builtin uniforms is even scarier than non-builtin.
869 * It sits on top of the PROG_STATE_VAR parameters that are
870 * automatically updated from GL context state.
873 fs_visitor::setup_builtin_uniform_values(ir_variable
*ir
)
875 const ir_state_slot
*const slots
= ir
->state_slots
;
876 assert(ir
->state_slots
!= NULL
);
878 for (unsigned int i
= 0; i
< ir
->num_state_slots
; i
++) {
879 /* This state reference has already been setup by ir_to_mesa, but we'll
880 * get the same index back here.
882 int index
= _mesa_add_state_reference(this->fp
->Base
.Parameters
,
883 (gl_state_index
*)slots
[i
].tokens
);
885 /* Add each of the unique swizzles of the element as a parameter.
886 * This'll end up matching the expected layout of the
887 * array/matrix/structure we're trying to fill in.
890 for (unsigned int j
= 0; j
< 4; j
++) {
891 int swiz
= GET_SWZ(slots
[i
].swizzle
, j
);
892 if (swiz
== last_swiz
)
896 c
->prog_data
.param
[c
->prog_data
.nr_params
++] =
897 &fp
->Base
.Parameters
->ParameterValues
[index
][swiz
].f
;
903 fs_visitor::emit_fragcoord_interpolation(ir_variable
*ir
)
905 fs_reg
*reg
= new(this->mem_ctx
) fs_reg(this, ir
->type
);
907 bool flip
= !ir
->origin_upper_left
^ c
->key
.render_to_fbo
;
910 if (ir
->pixel_center_integer
) {
911 emit(MOV(wpos
, this->pixel_x
));
913 emit(ADD(wpos
, this->pixel_x
, fs_reg(0.5f
)));
918 if (!flip
&& ir
->pixel_center_integer
) {
919 emit(MOV(wpos
, this->pixel_y
));
921 fs_reg pixel_y
= this->pixel_y
;
922 float offset
= (ir
->pixel_center_integer
? 0.0 : 0.5);
925 pixel_y
.negate
= true;
926 offset
+= c
->key
.drawable_height
- 1.0;
929 emit(ADD(wpos
, pixel_y
, fs_reg(offset
)));
935 emit(MOV(wpos
, fs_reg(brw_vec8_grf(c
->source_depth_reg
, 0))));
937 emit(FS_OPCODE_LINTERP
, wpos
,
938 this->delta_x
[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC
],
939 this->delta_y
[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC
],
940 interp_reg(VARYING_SLOT_POS
, 2));
944 /* gl_FragCoord.w: Already set up in emit_interpolation */
945 emit(BRW_OPCODE_MOV
, wpos
, this->wpos_w
);
951 fs_visitor::emit_linterp(const fs_reg
&attr
, const fs_reg
&interp
,
952 glsl_interp_qualifier interpolation_mode
,
955 brw_wm_barycentric_interp_mode barycoord_mode
;
958 if (interpolation_mode
== INTERP_QUALIFIER_SMOOTH
)
959 barycoord_mode
= BRW_WM_PERSPECTIVE_CENTROID_BARYCENTRIC
;
961 barycoord_mode
= BRW_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC
;
963 if (interpolation_mode
== INTERP_QUALIFIER_SMOOTH
)
964 barycoord_mode
= BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC
;
966 barycoord_mode
= BRW_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC
;
969 /* On Ironlake and below, there is only one interpolation mode.
970 * Centroid interpolation doesn't mean anything on this hardware --
971 * there is no multisampling.
973 barycoord_mode
= BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC
;
975 return emit(FS_OPCODE_LINTERP
, attr
,
976 this->delta_x
[barycoord_mode
],
977 this->delta_y
[barycoord_mode
], interp
);
981 fs_visitor::emit_general_interpolation(ir_variable
*ir
)
983 fs_reg
*reg
= new(this->mem_ctx
) fs_reg(this, ir
->type
);
984 reg
->type
= brw_type_for_base_type(ir
->type
->get_scalar_type());
987 unsigned int array_elements
;
988 const glsl_type
*type
;
990 if (ir
->type
->is_array()) {
991 array_elements
= ir
->type
->length
;
992 if (array_elements
== 0) {
993 fail("dereferenced array '%s' has length 0\n", ir
->name
);
995 type
= ir
->type
->fields
.array
;
1001 glsl_interp_qualifier interpolation_mode
=
1002 ir
->determine_interpolation_mode(c
->key
.flat_shade
);
1004 int location
= ir
->location
;
1005 for (unsigned int i
= 0; i
< array_elements
; i
++) {
1006 for (unsigned int j
= 0; j
< type
->matrix_columns
; j
++) {
1007 if (urb_setup
[location
] == -1) {
1008 /* If there's no incoming setup data for this slot, don't
1009 * emit interpolation for it.
1011 attr
.reg_offset
+= type
->vector_elements
;
1016 if (interpolation_mode
== INTERP_QUALIFIER_FLAT
) {
1017 /* Constant interpolation (flat shading) case. The SF has
1018 * handed us defined values in only the constant offset
1019 * field of the setup reg.
1021 for (unsigned int k
= 0; k
< type
->vector_elements
; k
++) {
1022 struct brw_reg interp
= interp_reg(location
, k
);
1023 interp
= suboffset(interp
, 3);
1024 interp
.type
= reg
->type
;
1025 emit(FS_OPCODE_CINTERP
, attr
, fs_reg(interp
));
1029 /* Smooth/noperspective interpolation case. */
1030 for (unsigned int k
= 0; k
< type
->vector_elements
; k
++) {
1031 /* FINISHME: At some point we probably want to push
1032 * this farther by giving similar treatment to the
1033 * other potentially constant components of the
1034 * attribute, as well as making brw_vs_constval.c
1035 * handle varyings other than gl_TexCoord.
1037 struct brw_reg interp
= interp_reg(location
, k
);
1038 emit_linterp(attr
, fs_reg(interp
), interpolation_mode
,
1040 if (brw
->needs_unlit_centroid_workaround
&& ir
->centroid
) {
1041 /* Get the pixel/sample mask into f0 so that we know
1042 * which pixels are lit. Then, for each channel that is
1043 * unlit, replace the centroid data with non-centroid
1046 emit(FS_OPCODE_MOV_DISPATCH_TO_FLAGS
);
1047 fs_inst
*inst
= emit_linterp(attr
, fs_reg(interp
),
1048 interpolation_mode
, false);
1049 inst
->predicate
= BRW_PREDICATE_NORMAL
;
1050 inst
->predicate_inverse
= true;
1052 if (brw
->gen
< 6 && interpolation_mode
== INTERP_QUALIFIER_SMOOTH
) {
1053 emit(BRW_OPCODE_MUL
, attr
, attr
, this->pixel_w
);
1067 fs_visitor::emit_frontfacing_interpolation(ir_variable
*ir
)
1069 fs_reg
*reg
= new(this->mem_ctx
) fs_reg(this, ir
->type
);
1071 /* The frontfacing comes in as a bit in the thread payload. */
1072 if (brw
->gen
>= 6) {
1073 emit(BRW_OPCODE_ASR
, *reg
,
1074 fs_reg(retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_D
)),
1076 emit(BRW_OPCODE_NOT
, *reg
, *reg
);
1077 emit(BRW_OPCODE_AND
, *reg
, *reg
, fs_reg(1));
1079 struct brw_reg r1_6ud
= retype(brw_vec1_grf(1, 6), BRW_REGISTER_TYPE_UD
);
1080 /* bit 31 is "primitive is back face", so checking < (1 << 31) gives
1083 emit(CMP(*reg
, fs_reg(r1_6ud
), fs_reg(1u << 31), BRW_CONDITIONAL_L
));
1084 emit(BRW_OPCODE_AND
, *reg
, *reg
, fs_reg(1u));
1091 fs_visitor::fix_math_operand(fs_reg src
)
1093 /* Can't do hstride == 0 args on gen6 math, so expand it out. We
1094 * might be able to do better by doing execsize = 1 math and then
1095 * expanding that result out, but we would need to be careful with
1098 * The hardware ignores source modifiers (negate and abs) on math
1099 * instructions, so we also move to a temp to set those up.
1101 if (brw
->gen
== 6 && src
.file
!= UNIFORM
&& src
.file
!= IMM
&&
1102 !src
.abs
&& !src
.negate
)
1105 /* Gen7 relaxes most of the above restrictions, but still can't use IMM
1108 if (brw
->gen
>= 7 && src
.file
!= IMM
)
1111 fs_reg expanded
= fs_reg(this, glsl_type::float_type
);
1112 expanded
.type
= src
.type
;
1113 emit(BRW_OPCODE_MOV
, expanded
, src
);
1118 fs_visitor::emit_math(enum opcode opcode
, fs_reg dst
, fs_reg src
)
1121 case SHADER_OPCODE_RCP
:
1122 case SHADER_OPCODE_RSQ
:
1123 case SHADER_OPCODE_SQRT
:
1124 case SHADER_OPCODE_EXP2
:
1125 case SHADER_OPCODE_LOG2
:
1126 case SHADER_OPCODE_SIN
:
1127 case SHADER_OPCODE_COS
:
1130 assert(!"not reached: bad math opcode");
1134 /* Can't do hstride == 0 args to gen6 math, so expand it out. We
1135 * might be able to do better by doing execsize = 1 math and then
1136 * expanding that result out, but we would need to be careful with
1139 * Gen 6 hardware ignores source modifiers (negate and abs) on math
1140 * instructions, so we also move to a temp to set those up.
1143 src
= fix_math_operand(src
);
1145 fs_inst
*inst
= emit(opcode
, dst
, src
);
1149 inst
->mlen
= dispatch_width
/ 8;
1156 fs_visitor::emit_math(enum opcode opcode
, fs_reg dst
, fs_reg src0
, fs_reg src1
)
1162 case SHADER_OPCODE_INT_QUOTIENT
:
1163 case SHADER_OPCODE_INT_REMAINDER
:
1164 if (brw
->gen
>= 7 && dispatch_width
== 16)
1165 fail("16-wide INTDIV unsupported\n");
1167 case SHADER_OPCODE_POW
:
1170 assert(!"not reached: unsupported binary math opcode.");
1174 if (brw
->gen
>= 6) {
1175 src0
= fix_math_operand(src0
);
1176 src1
= fix_math_operand(src1
);
1178 inst
= emit(opcode
, dst
, src0
, src1
);
1180 /* From the Ironlake PRM, Volume 4, Part 1, Section 6.1.13
1181 * "Message Payload":
1183 * "Operand0[7]. For the INT DIV functions, this operand is the
1186 * "Operand1[7]. For the INT DIV functions, this operand is the
1189 bool is_int_div
= opcode
!= SHADER_OPCODE_POW
;
1190 fs_reg
&op0
= is_int_div
? src1
: src0
;
1191 fs_reg
&op1
= is_int_div
? src0
: src1
;
1193 emit(BRW_OPCODE_MOV
, fs_reg(MRF
, base_mrf
+ 1, op1
.type
), op1
);
1194 inst
= emit(opcode
, dst
, op0
, reg_null_f
);
1196 inst
->base_mrf
= base_mrf
;
1197 inst
->mlen
= 2 * dispatch_width
/ 8;
1203 fs_visitor::assign_curb_setup()
1205 c
->prog_data
.curb_read_length
= ALIGN(c
->prog_data
.nr_params
, 8) / 8;
1206 if (dispatch_width
== 8) {
1207 c
->prog_data
.first_curbe_grf
= c
->nr_payload_regs
;
1209 c
->prog_data
.first_curbe_grf_16
= c
->nr_payload_regs
;
1212 /* Map the offsets in the UNIFORM file to fixed HW regs. */
1213 foreach_list(node
, &this->instructions
) {
1214 fs_inst
*inst
= (fs_inst
*)node
;
1216 for (unsigned int i
= 0; i
< 3; i
++) {
1217 if (inst
->src
[i
].file
== UNIFORM
) {
1218 int constant_nr
= inst
->src
[i
].reg
+ inst
->src
[i
].reg_offset
;
1219 struct brw_reg brw_reg
= brw_vec1_grf(c
->nr_payload_regs
+
1223 inst
->src
[i
].file
= HW_REG
;
1224 inst
->src
[i
].fixed_hw_reg
= retype(brw_reg
, inst
->src
[i
].type
);
1231 fs_visitor::calculate_urb_setup()
1233 for (unsigned int i
= 0; i
< VARYING_SLOT_MAX
; i
++) {
1238 /* Figure out where each of the incoming setup attributes lands. */
1239 if (brw
->gen
>= 6) {
1240 for (unsigned int i
= 0; i
< VARYING_SLOT_MAX
; i
++) {
1241 if (fp
->Base
.InputsRead
& BITFIELD64_BIT(i
)) {
1242 urb_setup
[i
] = urb_next
++;
1246 /* FINISHME: The sf doesn't map VS->FS inputs for us very well. */
1247 for (unsigned int i
= 0; i
< VARYING_SLOT_MAX
; i
++) {
1248 /* Point size is packed into the header, not as a general attribute */
1249 if (i
== VARYING_SLOT_PSIZ
)
1252 if (c
->key
.input_slots_valid
& BITFIELD64_BIT(i
)) {
1253 /* The back color slot is skipped when the front color is
1254 * also written to. In addition, some slots can be
1255 * written in the vertex shader and not read in the
1256 * fragment shader. So the register number must always be
1257 * incremented, mapped or not.
1259 if (_mesa_varying_slot_in_fs((gl_varying_slot
) i
))
1260 urb_setup
[i
] = urb_next
;
1266 * It's a FS only attribute, and we did interpolation for this attribute
1267 * in SF thread. So, count it here, too.
1269 * See compile_sf_prog() for more info.
1271 if (fp
->Base
.InputsRead
& BITFIELD64_BIT(VARYING_SLOT_PNTC
))
1272 urb_setup
[VARYING_SLOT_PNTC
] = urb_next
++;
1275 /* Each attribute is 4 setup channels, each of which is half a reg. */
1276 c
->prog_data
.urb_read_length
= urb_next
* 2;
1280 fs_visitor::assign_urb_setup()
1282 int urb_start
= c
->nr_payload_regs
+ c
->prog_data
.curb_read_length
;
1284 /* Offset all the urb_setup[] index by the actual position of the
1285 * setup regs, now that the location of the constants has been chosen.
1287 foreach_list(node
, &this->instructions
) {
1288 fs_inst
*inst
= (fs_inst
*)node
;
1290 if (inst
->opcode
== FS_OPCODE_LINTERP
) {
1291 assert(inst
->src
[2].file
== HW_REG
);
1292 inst
->src
[2].fixed_hw_reg
.nr
+= urb_start
;
1295 if (inst
->opcode
== FS_OPCODE_CINTERP
) {
1296 assert(inst
->src
[0].file
== HW_REG
);
1297 inst
->src
[0].fixed_hw_reg
.nr
+= urb_start
;
1301 this->first_non_payload_grf
= urb_start
+ c
->prog_data
.urb_read_length
;
1305 * Split large virtual GRFs into separate components if we can.
1307 * This is mostly duplicated with what brw_fs_vector_splitting does,
1308 * but that's really conservative because it's afraid of doing
1309 * splitting that doesn't result in real progress after the rest of
1310 * the optimization phases, which would cause infinite looping in
1311 * optimization. We can do it once here, safely. This also has the
1312 * opportunity to split interpolated values, or maybe even uniforms,
1313 * which we don't have at the IR level.
1315 * We want to split, because virtual GRFs are what we register
1316 * allocate and spill (due to contiguousness requirements for some
1317 * instructions), and they're what we naturally generate in the
1318 * codegen process, but most virtual GRFs don't actually need to be
1319 * contiguous sets of GRFs. If we split, we'll end up with reduced
1320 * live intervals and better dead code elimination and coalescing.
1323 fs_visitor::split_virtual_grfs()
1325 int num_vars
= this->virtual_grf_count
;
1326 bool split_grf
[num_vars
];
1327 int new_virtual_grf
[num_vars
];
1329 /* Try to split anything > 0 sized. */
1330 for (int i
= 0; i
< num_vars
; i
++) {
1331 if (this->virtual_grf_sizes
[i
] != 1)
1332 split_grf
[i
] = true;
1334 split_grf
[i
] = false;
1338 this->delta_x
[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC
].file
== GRF
) {
1339 /* PLN opcodes rely on the delta_xy being contiguous. We only have to
1340 * check this for BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC, because prior to
1341 * Gen6, that was the only supported interpolation mode, and since Gen6,
1342 * delta_x and delta_y are in fixed hardware registers.
1344 split_grf
[this->delta_x
[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC
].reg
] =
1348 foreach_list(node
, &this->instructions
) {
1349 fs_inst
*inst
= (fs_inst
*)node
;
1351 /* If there's a SEND message that requires contiguous destination
1352 * registers, no splitting is allowed.
1354 if (inst
->regs_written
> 1) {
1355 split_grf
[inst
->dst
.reg
] = false;
1358 /* If we're sending from a GRF, don't split it, on the assumption that
1359 * the send is reading the whole thing.
1361 if (inst
->is_send_from_grf()) {
1362 split_grf
[inst
->src
[0].reg
] = false;
1366 /* Allocate new space for split regs. Note that the virtual
1367 * numbers will be contiguous.
1369 for (int i
= 0; i
< num_vars
; i
++) {
1371 new_virtual_grf
[i
] = virtual_grf_alloc(1);
1372 for (int j
= 2; j
< this->virtual_grf_sizes
[i
]; j
++) {
1373 int reg
= virtual_grf_alloc(1);
1374 assert(reg
== new_virtual_grf
[i
] + j
- 1);
1377 this->virtual_grf_sizes
[i
] = 1;
1381 foreach_list(node
, &this->instructions
) {
1382 fs_inst
*inst
= (fs_inst
*)node
;
1384 if (inst
->dst
.file
== GRF
&&
1385 split_grf
[inst
->dst
.reg
] &&
1386 inst
->dst
.reg_offset
!= 0) {
1387 inst
->dst
.reg
= (new_virtual_grf
[inst
->dst
.reg
] +
1388 inst
->dst
.reg_offset
- 1);
1389 inst
->dst
.reg_offset
= 0;
1391 for (int i
= 0; i
< 3; i
++) {
1392 if (inst
->src
[i
].file
== GRF
&&
1393 split_grf
[inst
->src
[i
].reg
] &&
1394 inst
->src
[i
].reg_offset
!= 0) {
1395 inst
->src
[i
].reg
= (new_virtual_grf
[inst
->src
[i
].reg
] +
1396 inst
->src
[i
].reg_offset
- 1);
1397 inst
->src
[i
].reg_offset
= 0;
1401 this->live_intervals_valid
= false;
1405 * Remove unused virtual GRFs and compact the virtual_grf_* arrays.
1407 * During code generation, we create tons of temporary variables, many of
1408 * which get immediately killed and are never used again. Yet, in later
1409 * optimization and analysis passes, such as compute_live_intervals, we need
1410 * to loop over all the virtual GRFs. Compacting them can save a lot of
1414 fs_visitor::compact_virtual_grfs()
1416 /* Mark which virtual GRFs are used, and count how many. */
1417 int remap_table
[this->virtual_grf_count
];
1418 memset(remap_table
, -1, sizeof(remap_table
));
1420 foreach_list(node
, &this->instructions
) {
1421 const fs_inst
*inst
= (const fs_inst
*) node
;
1423 if (inst
->dst
.file
== GRF
)
1424 remap_table
[inst
->dst
.reg
] = 0;
1426 for (int i
= 0; i
< 3; i
++) {
1427 if (inst
->src
[i
].file
== GRF
)
1428 remap_table
[inst
->src
[i
].reg
] = 0;
1432 /* In addition to registers used in instructions, fs_visitor keeps
1433 * direct references to certain special values which must be patched:
1435 fs_reg
*special
[] = {
1436 &frag_depth
, &pixel_x
, &pixel_y
, &pixel_w
, &wpos_w
, &dual_src_output
,
1437 &outputs
[0], &outputs
[1], &outputs
[2], &outputs
[3],
1438 &outputs
[4], &outputs
[5], &outputs
[6], &outputs
[7],
1439 &delta_x
[0], &delta_x
[1], &delta_x
[2],
1440 &delta_x
[3], &delta_x
[4], &delta_x
[5],
1441 &delta_y
[0], &delta_y
[1], &delta_y
[2],
1442 &delta_y
[3], &delta_y
[4], &delta_y
[5],
1444 STATIC_ASSERT(BRW_WM_BARYCENTRIC_INTERP_MODE_COUNT
== 6);
1445 STATIC_ASSERT(BRW_MAX_DRAW_BUFFERS
== 8);
1447 /* Treat all special values as used, to be conservative */
1448 for (unsigned i
= 0; i
< ARRAY_SIZE(special
); i
++) {
1449 if (special
[i
]->file
== GRF
)
1450 remap_table
[special
[i
]->reg
] = 0;
1453 /* Compact the GRF arrays. */
1455 for (int i
= 0; i
< this->virtual_grf_count
; i
++) {
1456 if (remap_table
[i
] != -1) {
1457 remap_table
[i
] = new_index
;
1458 virtual_grf_sizes
[new_index
] = virtual_grf_sizes
[i
];
1459 if (live_intervals_valid
) {
1460 virtual_grf_start
[new_index
] = virtual_grf_start
[i
];
1461 virtual_grf_end
[new_index
] = virtual_grf_end
[i
];
1467 this->virtual_grf_count
= new_index
;
1469 /* Patch all the instructions to use the newly renumbered registers */
1470 foreach_list(node
, &this->instructions
) {
1471 fs_inst
*inst
= (fs_inst
*) node
;
1473 if (inst
->dst
.file
== GRF
)
1474 inst
->dst
.reg
= remap_table
[inst
->dst
.reg
];
1476 for (int i
= 0; i
< 3; i
++) {
1477 if (inst
->src
[i
].file
== GRF
)
1478 inst
->src
[i
].reg
= remap_table
[inst
->src
[i
].reg
];
1482 /* Patch all the references to special values */
1483 for (unsigned i
= 0; i
< ARRAY_SIZE(special
); i
++) {
1484 if (special
[i
]->file
== GRF
&& remap_table
[special
[i
]->reg
] != -1)
1485 special
[i
]->reg
= remap_table
[special
[i
]->reg
];
1490 fs_visitor::remove_dead_constants()
1492 if (dispatch_width
== 8) {
1493 this->params_remap
= ralloc_array(mem_ctx
, int, c
->prog_data
.nr_params
);
1494 this->nr_params_remap
= c
->prog_data
.nr_params
;
1496 for (unsigned int i
= 0; i
< c
->prog_data
.nr_params
; i
++)
1497 this->params_remap
[i
] = -1;
1499 /* Find which params are still in use. */
1500 foreach_list(node
, &this->instructions
) {
1501 fs_inst
*inst
= (fs_inst
*)node
;
1503 for (int i
= 0; i
< 3; i
++) {
1504 int constant_nr
= inst
->src
[i
].reg
+ inst
->src
[i
].reg_offset
;
1506 if (inst
->src
[i
].file
!= UNIFORM
)
1509 /* Section 5.11 of the OpenGL 4.3 spec says:
1511 * "Out-of-bounds reads return undefined values, which include
1512 * values from other variables of the active program or zero."
1514 if (constant_nr
< 0 || constant_nr
>= (int)c
->prog_data
.nr_params
) {
1518 /* For now, set this to non-negative. We'll give it the
1519 * actual new number in a moment, in order to keep the
1520 * register numbers nicely ordered.
1522 this->params_remap
[constant_nr
] = 0;
1526 /* Figure out what the new numbers for the params will be. At some
1527 * point when we're doing uniform array access, we're going to want
1528 * to keep the distinction between .reg and .reg_offset, but for
1529 * now we don't care.
1531 unsigned int new_nr_params
= 0;
1532 for (unsigned int i
= 0; i
< c
->prog_data
.nr_params
; i
++) {
1533 if (this->params_remap
[i
] != -1) {
1534 this->params_remap
[i
] = new_nr_params
++;
1538 /* Update the list of params to be uploaded to match our new numbering. */
1539 for (unsigned int i
= 0; i
< c
->prog_data
.nr_params
; i
++) {
1540 int remapped
= this->params_remap
[i
];
1545 c
->prog_data
.param
[remapped
] = c
->prog_data
.param
[i
];
1548 c
->prog_data
.nr_params
= new_nr_params
;
1550 /* This should have been generated in the 8-wide pass already. */
1551 assert(this->params_remap
);
1554 /* Now do the renumbering of the shader to remove unused params. */
1555 foreach_list(node
, &this->instructions
) {
1556 fs_inst
*inst
= (fs_inst
*)node
;
1558 for (int i
= 0; i
< 3; i
++) {
1559 int constant_nr
= inst
->src
[i
].reg
+ inst
->src
[i
].reg_offset
;
1561 if (inst
->src
[i
].file
!= UNIFORM
)
1564 /* as above alias to 0 */
1565 if (constant_nr
< 0 || constant_nr
>= (int)this->nr_params_remap
) {
1568 assert(this->params_remap
[constant_nr
] != -1);
1569 inst
->src
[i
].reg
= this->params_remap
[constant_nr
];
1570 inst
->src
[i
].reg_offset
= 0;
1578 * Implements array access of uniforms by inserting a
1579 * PULL_CONSTANT_LOAD instruction.
1581 * Unlike temporary GRF array access (where we don't support it due to
1582 * the difficulty of doing relative addressing on instruction
1583 * destinations), we could potentially do array access of uniforms
1584 * that were loaded in GRF space as push constants. In real-world
1585 * usage we've seen, though, the arrays being used are always larger
1586 * than we could load as push constants, so just always move all
1587 * uniform array access out to a pull constant buffer.
1590 fs_visitor::move_uniform_array_access_to_pull_constants()
1592 int pull_constant_loc
[c
->prog_data
.nr_params
];
1594 for (unsigned int i
= 0; i
< c
->prog_data
.nr_params
; i
++) {
1595 pull_constant_loc
[i
] = -1;
1598 /* Walk through and find array access of uniforms. Put a copy of that
1599 * uniform in the pull constant buffer.
1601 * Note that we don't move constant-indexed accesses to arrays. No
1602 * testing has been done of the performance impact of this choice.
1604 foreach_list_safe(node
, &this->instructions
) {
1605 fs_inst
*inst
= (fs_inst
*)node
;
1607 for (int i
= 0 ; i
< 3; i
++) {
1608 if (inst
->src
[i
].file
!= UNIFORM
|| !inst
->src
[i
].reladdr
)
1611 int uniform
= inst
->src
[i
].reg
;
1613 /* If this array isn't already present in the pull constant buffer,
1616 if (pull_constant_loc
[uniform
] == -1) {
1617 const float **values
= &c
->prog_data
.param
[uniform
];
1619 pull_constant_loc
[uniform
] = c
->prog_data
.nr_pull_params
;
1621 assert(param_size
[uniform
]);
1623 for (int j
= 0; j
< param_size
[uniform
]; j
++) {
1624 c
->prog_data
.pull_param
[c
->prog_data
.nr_pull_params
++] =
1629 /* Set up the annotation tracking for new generated instructions. */
1631 current_annotation
= inst
->annotation
;
1633 fs_reg surf_index
= fs_reg((unsigned)SURF_INDEX_FRAG_CONST_BUFFER
);
1634 fs_reg temp
= fs_reg(this, glsl_type::float_type
);
1635 exec_list list
= VARYING_PULL_CONSTANT_LOAD(temp
,
1637 *inst
->src
[i
].reladdr
,
1638 pull_constant_loc
[uniform
] +
1639 inst
->src
[i
].reg_offset
);
1640 inst
->insert_before(&list
);
1642 inst
->src
[i
].file
= temp
.file
;
1643 inst
->src
[i
].reg
= temp
.reg
;
1644 inst
->src
[i
].reg_offset
= temp
.reg_offset
;
1645 inst
->src
[i
].reladdr
= NULL
;
1651 * Choose accesses from the UNIFORM file to demote to using the pull
1654 * We allow a fragment shader to have more than the specified minimum
1655 * maximum number of fragment shader uniform components (64). If
1656 * there are too many of these, they'd fill up all of register space.
1657 * So, this will push some of them out to the pull constant buffer and
1658 * update the program to load them.
1661 fs_visitor::setup_pull_constants()
1663 /* Only allow 16 registers (128 uniform components) as push constants. */
1664 unsigned int max_uniform_components
= 16 * 8;
1665 if (c
->prog_data
.nr_params
<= max_uniform_components
)
1668 if (dispatch_width
== 16) {
1669 fail("Pull constants not supported in 16-wide\n");
1673 /* Just demote the end of the list. We could probably do better
1674 * here, demoting things that are rarely used in the program first.
1676 unsigned int pull_uniform_base
= max_uniform_components
;
1678 int pull_constant_loc
[c
->prog_data
.nr_params
];
1679 for (unsigned int i
= 0; i
< c
->prog_data
.nr_params
; i
++) {
1680 if (i
< pull_uniform_base
) {
1681 pull_constant_loc
[i
] = -1;
1683 pull_constant_loc
[i
] = -1;
1684 /* If our constant is already being uploaded for reladdr purposes,
1687 for (unsigned int j
= 0; j
< c
->prog_data
.nr_pull_params
; j
++) {
1688 if (c
->prog_data
.pull_param
[j
] == c
->prog_data
.param
[i
]) {
1689 pull_constant_loc
[i
] = j
;
1693 if (pull_constant_loc
[i
] == -1) {
1694 int pull_index
= c
->prog_data
.nr_pull_params
++;
1695 c
->prog_data
.pull_param
[pull_index
] = c
->prog_data
.param
[i
];
1696 pull_constant_loc
[i
] = pull_index
;;
1700 c
->prog_data
.nr_params
= pull_uniform_base
;
1702 foreach_list(node
, &this->instructions
) {
1703 fs_inst
*inst
= (fs_inst
*)node
;
1705 for (int i
= 0; i
< 3; i
++) {
1706 if (inst
->src
[i
].file
!= UNIFORM
)
1709 int pull_index
= pull_constant_loc
[inst
->src
[i
].reg
+
1710 inst
->src
[i
].reg_offset
];
1711 if (pull_index
== -1)
1714 assert(!inst
->src
[i
].reladdr
);
1716 fs_reg dst
= fs_reg(this, glsl_type::float_type
);
1717 fs_reg index
= fs_reg((unsigned)SURF_INDEX_FRAG_CONST_BUFFER
);
1718 fs_reg offset
= fs_reg((unsigned)(pull_index
* 4) & ~15);
1720 new(mem_ctx
) fs_inst(FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
,
1721 dst
, index
, offset
);
1722 pull
->ir
= inst
->ir
;
1723 pull
->annotation
= inst
->annotation
;
1725 inst
->insert_before(pull
);
1727 inst
->src
[i
].file
= GRF
;
1728 inst
->src
[i
].reg
= dst
.reg
;
1729 inst
->src
[i
].reg_offset
= 0;
1730 inst
->src
[i
].smear
= pull_index
& 3;
1736 fs_visitor::opt_algebraic()
1738 bool progress
= false;
1740 foreach_list(node
, &this->instructions
) {
1741 fs_inst
*inst
= (fs_inst
*)node
;
1743 switch (inst
->opcode
) {
1744 case BRW_OPCODE_MUL
:
1745 if (inst
->src
[1].file
!= IMM
)
1749 if (inst
->src
[1].is_one()) {
1750 inst
->opcode
= BRW_OPCODE_MOV
;
1751 inst
->src
[1] = reg_undef
;
1757 if (inst
->src
[1].is_zero()) {
1758 inst
->opcode
= BRW_OPCODE_MOV
;
1759 inst
->src
[0] = inst
->src
[1];
1760 inst
->src
[1] = reg_undef
;
1766 case BRW_OPCODE_ADD
:
1767 if (inst
->src
[1].file
!= IMM
)
1771 if (inst
->src
[1].is_zero()) {
1772 inst
->opcode
= BRW_OPCODE_MOV
;
1773 inst
->src
[1] = reg_undef
;
1787 * Removes any instructions writing a VGRF where that VGRF is not used by any
1788 * later instruction.
1791 fs_visitor::dead_code_eliminate()
1793 bool progress
= false;
1796 calculate_live_intervals();
1798 foreach_list_safe(node
, &this->instructions
) {
1799 fs_inst
*inst
= (fs_inst
*)node
;
1801 if (inst
->dst
.file
== GRF
) {
1802 assert(this->virtual_grf_end
[inst
->dst
.reg
] >= pc
);
1803 if (this->virtual_grf_end
[inst
->dst
.reg
] == pc
) {
1813 live_intervals_valid
= false;
1818 struct dead_code_hash_key
1825 dead_code_hash_compare(const void *a
, const void *b
)
1827 return memcmp(a
, b
, sizeof(struct dead_code_hash_key
)) == 0;
1831 clear_dead_code_hash(struct hash_table
*ht
)
1833 struct hash_entry
*entry
;
1835 hash_table_foreach(ht
, entry
) {
1836 _mesa_hash_table_remove(ht
, entry
);
1841 insert_dead_code_hash(struct hash_table
*ht
,
1842 int vgrf
, int reg_offset
, fs_inst
*inst
)
1844 /* We don't bother freeing keys, because they'll be GCed with the ht. */
1845 struct dead_code_hash_key
*key
= ralloc(ht
, struct dead_code_hash_key
);
1848 key
->reg_offset
= reg_offset
;
1850 _mesa_hash_table_insert(ht
, _mesa_hash_data(key
, sizeof(*key
)), key
, inst
);
1853 static struct hash_entry
*
1854 get_dead_code_hash_entry(struct hash_table
*ht
, int vgrf
, int reg_offset
)
1856 struct dead_code_hash_key key
;
1859 key
.reg_offset
= reg_offset
;
1861 return _mesa_hash_table_search(ht
, _mesa_hash_data(&key
, sizeof(key
)), &key
);
1865 remove_dead_code_hash(struct hash_table
*ht
,
1866 int vgrf
, int reg_offset
)
1868 struct hash_entry
*entry
= get_dead_code_hash_entry(ht
, vgrf
, reg_offset
);
1872 _mesa_hash_table_remove(ht
, entry
);
1876 * Walks basic blocks, removing any regs that are written but not read before
1879 * The dead_code_eliminate() function implements a global dead code
1880 * elimination, but it only handles the removing the last write to a register
1881 * if it's never read. This one can handle intermediate writes, but only
1882 * within a basic block.
1885 fs_visitor::dead_code_eliminate_local()
1887 struct hash_table
*ht
;
1888 bool progress
= false;
1890 ht
= _mesa_hash_table_create(mem_ctx
, dead_code_hash_compare
);
1892 foreach_list_safe(node
, &this->instructions
) {
1893 fs_inst
*inst
= (fs_inst
*)node
;
1895 /* At a basic block, empty the HT since we don't understand dataflow
1898 if (inst
->is_control_flow()) {
1899 clear_dead_code_hash(ht
);
1903 /* Clear the HT of any instructions that got read. */
1904 for (int i
= 0; i
< 3; i
++) {
1905 fs_reg src
= inst
->src
[i
];
1906 if (src
.file
!= GRF
)
1910 if (inst
->is_send_from_grf())
1911 read
= virtual_grf_sizes
[src
.reg
] - src
.reg_offset
;
1913 for (int reg_offset
= src
.reg_offset
;
1914 reg_offset
< src
.reg_offset
+ read
;
1916 remove_dead_code_hash(ht
, src
.reg
, reg_offset
);
1920 /* Add any update of a GRF to the HT, removing a previous write if it
1923 if (inst
->dst
.file
== GRF
) {
1924 if (inst
->regs_written
> 1) {
1925 /* We don't know how to trim channels from an instruction's
1926 * writes, so we can't incrementally remove unread channels from
1927 * it. Just remove whatever it overwrites from the table
1929 for (int i
= 0; i
< inst
->regs_written
; i
++) {
1930 remove_dead_code_hash(ht
,
1932 inst
->dst
.reg_offset
+ i
);
1935 struct hash_entry
*entry
=
1936 get_dead_code_hash_entry(ht
, inst
->dst
.reg
,
1937 inst
->dst
.reg_offset
);
1939 if (inst
->is_partial_write()) {
1940 /* For a partial write, we can't remove any previous dead code
1941 * candidate, since we're just modifying their result, but we can
1942 * be dead code eliminiated ourselves.
1947 insert_dead_code_hash(ht
, inst
->dst
.reg
, inst
->dst
.reg_offset
,
1952 /* We're completely updating a channel, and there was a
1953 * previous write to the channel that wasn't read. Kill it!
1955 fs_inst
*inst
= (fs_inst
*)entry
->data
;
1958 _mesa_hash_table_remove(ht
, entry
);
1961 insert_dead_code_hash(ht
, inst
->dst
.reg
, inst
->dst
.reg_offset
,
1968 _mesa_hash_table_destroy(ht
, NULL
);
1971 live_intervals_valid
= false;
1977 * Implements a second type of register coalescing: This one checks if
1978 * the two regs involved in a raw move don't interfere, in which case
1979 * they can both by stored in the same place and the MOV removed.
1982 fs_visitor::register_coalesce_2()
1984 bool progress
= false;
1986 calculate_live_intervals();
1988 foreach_list_safe(node
, &this->instructions
) {
1989 fs_inst
*inst
= (fs_inst
*)node
;
1991 if (inst
->opcode
!= BRW_OPCODE_MOV
||
1992 inst
->is_partial_write() ||
1994 inst
->src
[0].file
!= GRF
||
1995 inst
->src
[0].negate
||
1997 inst
->src
[0].smear
!= -1 ||
1998 inst
->dst
.file
!= GRF
||
1999 inst
->dst
.type
!= inst
->src
[0].type
||
2000 virtual_grf_sizes
[inst
->src
[0].reg
] != 1 ||
2001 virtual_grf_interferes(inst
->dst
.reg
, inst
->src
[0].reg
)) {
2005 int reg_from
= inst
->src
[0].reg
;
2006 assert(inst
->src
[0].reg_offset
== 0);
2007 int reg_to
= inst
->dst
.reg
;
2008 int reg_to_offset
= inst
->dst
.reg_offset
;
2010 foreach_list(node
, &this->instructions
) {
2011 fs_inst
*scan_inst
= (fs_inst
*)node
;
2013 if (scan_inst
->dst
.file
== GRF
&&
2014 scan_inst
->dst
.reg
== reg_from
) {
2015 scan_inst
->dst
.reg
= reg_to
;
2016 scan_inst
->dst
.reg_offset
= reg_to_offset
;
2018 for (int i
= 0; i
< 3; i
++) {
2019 if (scan_inst
->src
[i
].file
== GRF
&&
2020 scan_inst
->src
[i
].reg
== reg_from
) {
2021 scan_inst
->src
[i
].reg
= reg_to
;
2022 scan_inst
->src
[i
].reg_offset
= reg_to_offset
;
2029 /* We don't need to recalculate live intervals inside the loop despite
2030 * flagging live_intervals_valid because we only use live intervals for
2031 * the interferes test, and we must have had a situation where the
2042 * Some register R that might get coalesced with one of these two could
2043 * only be referencing "to", otherwise "from"'s range would have been
2044 * longer. R's range could also only start at the end of "to" or later,
2045 * otherwise it will conflict with "to" when we try to coalesce "to"
2048 live_intervals_valid
= false;
2058 fs_visitor::register_coalesce()
2060 bool progress
= false;
2064 foreach_list_safe(node
, &this->instructions
) {
2065 fs_inst
*inst
= (fs_inst
*)node
;
2067 /* Make sure that we dominate the instructions we're going to
2068 * scan for interfering with our coalescing, or we won't have
2069 * scanned enough to see if anything interferes with our
2070 * coalescing. We don't dominate the following instructions if
2071 * we're in a loop or an if block.
2073 switch (inst
->opcode
) {
2077 case BRW_OPCODE_WHILE
:
2083 case BRW_OPCODE_ENDIF
:
2089 if (loop_depth
|| if_depth
)
2092 if (inst
->opcode
!= BRW_OPCODE_MOV
||
2093 inst
->is_partial_write() ||
2095 inst
->dst
.file
!= GRF
|| (inst
->src
[0].file
!= GRF
&&
2096 inst
->src
[0].file
!= UNIFORM
)||
2097 inst
->dst
.type
!= inst
->src
[0].type
)
2100 bool has_source_modifiers
= (inst
->src
[0].abs
||
2101 inst
->src
[0].negate
||
2102 inst
->src
[0].smear
!= -1 ||
2103 inst
->src
[0].file
== UNIFORM
);
2105 /* Found a move of a GRF to a GRF. Let's see if we can coalesce
2106 * them: check for no writes to either one until the exit of the
2109 bool interfered
= false;
2111 for (fs_inst
*scan_inst
= (fs_inst
*)inst
->next
;
2112 !scan_inst
->is_tail_sentinel();
2113 scan_inst
= (fs_inst
*)scan_inst
->next
) {
2114 if (scan_inst
->dst
.file
== GRF
) {
2115 if (scan_inst
->overwrites_reg(inst
->dst
) ||
2116 scan_inst
->overwrites_reg(inst
->src
[0])) {
2122 if (has_source_modifiers
) {
2123 for (int i
= 0; i
< 3; i
++) {
2124 if (scan_inst
->src
[i
].file
== GRF
&&
2125 scan_inst
->src
[i
].reg
== inst
->dst
.reg
&&
2126 scan_inst
->src
[i
].reg_offset
== inst
->dst
.reg_offset
&&
2127 inst
->dst
.type
!= scan_inst
->src
[i
].type
)
2136 /* The gen6 MATH instruction can't handle source modifiers or
2137 * unusual register regions, so avoid coalescing those for
2138 * now. We should do something more specific.
2140 if (has_source_modifiers
&& !can_do_source_mods(scan_inst
)) {
2145 /* The accumulator result appears to get used for the
2146 * conditional modifier generation. When negating a UD
2147 * value, there is a 33rd bit generated for the sign in the
2148 * accumulator value, so now you can't check, for example,
2149 * equality with a 32-bit value. See piglit fs-op-neg-uint.
2151 if (scan_inst
->conditional_mod
&&
2152 inst
->src
[0].negate
&&
2153 inst
->src
[0].type
== BRW_REGISTER_TYPE_UD
) {
2162 /* Rewrite the later usage to point at the source of the move to
2165 for (fs_inst
*scan_inst
= inst
;
2166 !scan_inst
->is_tail_sentinel();
2167 scan_inst
= (fs_inst
*)scan_inst
->next
) {
2168 for (int i
= 0; i
< 3; i
++) {
2169 if (scan_inst
->src
[i
].file
== GRF
&&
2170 scan_inst
->src
[i
].reg
== inst
->dst
.reg
&&
2171 scan_inst
->src
[i
].reg_offset
== inst
->dst
.reg_offset
) {
2172 fs_reg new_src
= inst
->src
[0];
2173 if (scan_inst
->src
[i
].abs
) {
2177 new_src
.negate
^= scan_inst
->src
[i
].negate
;
2178 scan_inst
->src
[i
] = new_src
;
2188 live_intervals_valid
= false;
2195 fs_visitor::compute_to_mrf()
2197 bool progress
= false;
2200 calculate_live_intervals();
2202 foreach_list_safe(node
, &this->instructions
) {
2203 fs_inst
*inst
= (fs_inst
*)node
;
2208 if (inst
->opcode
!= BRW_OPCODE_MOV
||
2209 inst
->is_partial_write() ||
2210 inst
->dst
.file
!= MRF
|| inst
->src
[0].file
!= GRF
||
2211 inst
->dst
.type
!= inst
->src
[0].type
||
2212 inst
->src
[0].abs
|| inst
->src
[0].negate
|| inst
->src
[0].smear
!= -1)
2215 /* Work out which hardware MRF registers are written by this
2218 int mrf_low
= inst
->dst
.reg
& ~BRW_MRF_COMPR4
;
2220 if (inst
->dst
.reg
& BRW_MRF_COMPR4
) {
2221 mrf_high
= mrf_low
+ 4;
2222 } else if (dispatch_width
== 16 &&
2223 (!inst
->force_uncompressed
&& !inst
->force_sechalf
)) {
2224 mrf_high
= mrf_low
+ 1;
2229 /* Can't compute-to-MRF this GRF if someone else was going to
2232 if (this->virtual_grf_end
[inst
->src
[0].reg
] > ip
)
2235 /* Found a move of a GRF to a MRF. Let's see if we can go
2236 * rewrite the thing that made this GRF to write into the MRF.
2239 for (scan_inst
= (fs_inst
*)inst
->prev
;
2240 scan_inst
->prev
!= NULL
;
2241 scan_inst
= (fs_inst
*)scan_inst
->prev
) {
2242 if (scan_inst
->dst
.file
== GRF
&&
2243 scan_inst
->dst
.reg
== inst
->src
[0].reg
) {
2244 /* Found the last thing to write our reg we want to turn
2245 * into a compute-to-MRF.
2248 /* If this one instruction didn't populate all the
2249 * channels, bail. We might be able to rewrite everything
2250 * that writes that reg, but it would require smarter
2251 * tracking to delay the rewriting until complete success.
2253 if (scan_inst
->is_partial_write())
2256 /* Things returning more than one register would need us to
2257 * understand coalescing out more than one MOV at a time.
2259 if (scan_inst
->regs_written
> 1)
2262 /* SEND instructions can't have MRF as a destination. */
2263 if (scan_inst
->mlen
)
2266 if (brw
->gen
== 6) {
2267 /* gen6 math instructions must have the destination be
2268 * GRF, so no compute-to-MRF for them.
2270 if (scan_inst
->is_math()) {
2275 if (scan_inst
->dst
.reg_offset
== inst
->src
[0].reg_offset
) {
2276 /* Found the creator of our MRF's source value. */
2277 scan_inst
->dst
.file
= MRF
;
2278 scan_inst
->dst
.reg
= inst
->dst
.reg
;
2279 scan_inst
->saturate
|= inst
->saturate
;
2286 /* We don't handle control flow here. Most computation of
2287 * values that end up in MRFs are shortly before the MRF
2290 if (scan_inst
->is_control_flow() && scan_inst
->opcode
!= BRW_OPCODE_IF
)
2293 /* You can't read from an MRF, so if someone else reads our
2294 * MRF's source GRF that we wanted to rewrite, that stops us.
2296 bool interfered
= false;
2297 for (int i
= 0; i
< 3; i
++) {
2298 if (scan_inst
->src
[i
].file
== GRF
&&
2299 scan_inst
->src
[i
].reg
== inst
->src
[0].reg
&&
2300 scan_inst
->src
[i
].reg_offset
== inst
->src
[0].reg_offset
) {
2307 if (scan_inst
->dst
.file
== MRF
) {
2308 /* If somebody else writes our MRF here, we can't
2309 * compute-to-MRF before that.
2311 int scan_mrf_low
= scan_inst
->dst
.reg
& ~BRW_MRF_COMPR4
;
2314 if (scan_inst
->dst
.reg
& BRW_MRF_COMPR4
) {
2315 scan_mrf_high
= scan_mrf_low
+ 4;
2316 } else if (dispatch_width
== 16 &&
2317 (!scan_inst
->force_uncompressed
&&
2318 !scan_inst
->force_sechalf
)) {
2319 scan_mrf_high
= scan_mrf_low
+ 1;
2321 scan_mrf_high
= scan_mrf_low
;
2324 if (mrf_low
== scan_mrf_low
||
2325 mrf_low
== scan_mrf_high
||
2326 mrf_high
== scan_mrf_low
||
2327 mrf_high
== scan_mrf_high
) {
2332 if (scan_inst
->mlen
> 0) {
2333 /* Found a SEND instruction, which means that there are
2334 * live values in MRFs from base_mrf to base_mrf +
2335 * scan_inst->mlen - 1. Don't go pushing our MRF write up
2338 if (mrf_low
>= scan_inst
->base_mrf
&&
2339 mrf_low
< scan_inst
->base_mrf
+ scan_inst
->mlen
) {
2342 if (mrf_high
>= scan_inst
->base_mrf
&&
2343 mrf_high
< scan_inst
->base_mrf
+ scan_inst
->mlen
) {
2351 live_intervals_valid
= false;
2357 * Walks through basic blocks, looking for repeated MRF writes and
2358 * removing the later ones.
2361 fs_visitor::remove_duplicate_mrf_writes()
2363 fs_inst
*last_mrf_move
[16];
2364 bool progress
= false;
2366 /* Need to update the MRF tracking for compressed instructions. */
2367 if (dispatch_width
== 16)
2370 memset(last_mrf_move
, 0, sizeof(last_mrf_move
));
2372 foreach_list_safe(node
, &this->instructions
) {
2373 fs_inst
*inst
= (fs_inst
*)node
;
2375 if (inst
->is_control_flow()) {
2376 memset(last_mrf_move
, 0, sizeof(last_mrf_move
));
2379 if (inst
->opcode
== BRW_OPCODE_MOV
&&
2380 inst
->dst
.file
== MRF
) {
2381 fs_inst
*prev_inst
= last_mrf_move
[inst
->dst
.reg
];
2382 if (prev_inst
&& inst
->equals(prev_inst
)) {
2389 /* Clear out the last-write records for MRFs that were overwritten. */
2390 if (inst
->dst
.file
== MRF
) {
2391 last_mrf_move
[inst
->dst
.reg
] = NULL
;
2394 if (inst
->mlen
> 0) {
2395 /* Found a SEND instruction, which will include two or fewer
2396 * implied MRF writes. We could do better here.
2398 for (int i
= 0; i
< implied_mrf_writes(inst
); i
++) {
2399 last_mrf_move
[inst
->base_mrf
+ i
] = NULL
;
2403 /* Clear out any MRF move records whose sources got overwritten. */
2404 if (inst
->dst
.file
== GRF
) {
2405 for (unsigned int i
= 0; i
< Elements(last_mrf_move
); i
++) {
2406 if (last_mrf_move
[i
] &&
2407 last_mrf_move
[i
]->src
[0].reg
== inst
->dst
.reg
) {
2408 last_mrf_move
[i
] = NULL
;
2413 if (inst
->opcode
== BRW_OPCODE_MOV
&&
2414 inst
->dst
.file
== MRF
&&
2415 inst
->src
[0].file
== GRF
&&
2416 !inst
->is_partial_write()) {
2417 last_mrf_move
[inst
->dst
.reg
] = inst
;
2422 live_intervals_valid
= false;
2428 clear_deps_for_inst_src(fs_inst
*inst
, int dispatch_width
, bool *deps
,
2429 int first_grf
, int grf_len
)
2431 bool inst_16wide
= (dispatch_width
> 8 &&
2432 !inst
->force_uncompressed
&&
2433 !inst
->force_sechalf
);
2435 /* Clear the flag for registers that actually got read (as expected). */
2436 for (int i
= 0; i
< 3; i
++) {
2438 if (inst
->src
[i
].file
== GRF
) {
2439 grf
= inst
->src
[i
].reg
;
2440 } else if (inst
->src
[i
].file
== HW_REG
&&
2441 inst
->src
[i
].fixed_hw_reg
.file
== BRW_GENERAL_REGISTER_FILE
) {
2442 grf
= inst
->src
[i
].fixed_hw_reg
.nr
;
2447 if (grf
>= first_grf
&&
2448 grf
< first_grf
+ grf_len
) {
2449 deps
[grf
- first_grf
] = false;
2451 deps
[grf
- first_grf
+ 1] = false;
2457 * Implements this workaround for the original 965:
2459 * "[DevBW, DevCL] Implementation Restrictions: As the hardware does not
2460 * check for post destination dependencies on this instruction, software
2461 * must ensure that there is no destination hazard for the case of ‘write
2462 * followed by a posted write’ shown in the following example.
2465 * 2. send r3.xy <rest of send instruction>
2468 * Due to no post-destination dependency check on the ‘send’, the above
2469 * code sequence could have two instructions (1 and 2) in flight at the
2470 * same time that both consider ‘r3’ as the target of their final writes.
2473 fs_visitor::insert_gen4_pre_send_dependency_workarounds(fs_inst
*inst
)
2475 int reg_size
= dispatch_width
/ 8;
2476 int write_len
= inst
->regs_written
* reg_size
;
2477 int first_write_grf
= inst
->dst
.reg
;
2478 bool needs_dep
[BRW_MAX_MRF
];
2479 assert(write_len
< (int)sizeof(needs_dep
) - 1);
2481 memset(needs_dep
, false, sizeof(needs_dep
));
2482 memset(needs_dep
, true, write_len
);
2484 clear_deps_for_inst_src(inst
, dispatch_width
,
2485 needs_dep
, first_write_grf
, write_len
);
2487 /* Walk backwards looking for writes to registers we're writing which
2488 * aren't read since being written. If we hit the start of the program,
2489 * we assume that there are no outstanding dependencies on entry to the
2492 for (fs_inst
*scan_inst
= (fs_inst
*)inst
->prev
;
2494 scan_inst
= (fs_inst
*)scan_inst
->prev
) {
2496 /* If we hit control flow, assume that there *are* outstanding
2497 * dependencies, and force their cleanup before our instruction.
2499 if (scan_inst
->is_control_flow()) {
2500 for (int i
= 0; i
< write_len
; i
++) {
2502 inst
->insert_before(DEP_RESOLVE_MOV(first_write_grf
+ i
));
2508 bool scan_inst_16wide
= (dispatch_width
> 8 &&
2509 !scan_inst
->force_uncompressed
&&
2510 !scan_inst
->force_sechalf
);
2512 /* We insert our reads as late as possible on the assumption that any
2513 * instruction but a MOV that might have left us an outstanding
2514 * dependency has more latency than a MOV.
2516 if (scan_inst
->dst
.file
== GRF
) {
2517 for (int i
= 0; i
< scan_inst
->regs_written
; i
++) {
2518 int reg
= scan_inst
->dst
.reg
+ i
* reg_size
;
2520 if (reg
>= first_write_grf
&&
2521 reg
< first_write_grf
+ write_len
&&
2522 needs_dep
[reg
- first_write_grf
]) {
2523 inst
->insert_before(DEP_RESOLVE_MOV(reg
));
2524 needs_dep
[reg
- first_write_grf
] = false;
2525 if (scan_inst_16wide
)
2526 needs_dep
[reg
- first_write_grf
+ 1] = false;
2531 /* Clear the flag for registers that actually got read (as expected). */
2532 clear_deps_for_inst_src(scan_inst
, dispatch_width
,
2533 needs_dep
, first_write_grf
, write_len
);
2535 /* Continue the loop only if we haven't resolved all the dependencies */
2537 for (i
= 0; i
< write_len
; i
++) {
2547 * Implements this workaround for the original 965:
2549 * "[DevBW, DevCL] Errata: A destination register from a send can not be
2550 * used as a destination register until after it has been sourced by an
2551 * instruction with a different destination register.
2554 fs_visitor::insert_gen4_post_send_dependency_workarounds(fs_inst
*inst
)
2556 int write_len
= inst
->regs_written
* dispatch_width
/ 8;
2557 int first_write_grf
= inst
->dst
.reg
;
2558 bool needs_dep
[BRW_MAX_MRF
];
2559 assert(write_len
< (int)sizeof(needs_dep
) - 1);
2561 memset(needs_dep
, false, sizeof(needs_dep
));
2562 memset(needs_dep
, true, write_len
);
2563 /* Walk forwards looking for writes to registers we're writing which aren't
2564 * read before being written.
2566 for (fs_inst
*scan_inst
= (fs_inst
*)inst
->next
;
2567 !scan_inst
->is_tail_sentinel();
2568 scan_inst
= (fs_inst
*)scan_inst
->next
) {
2569 /* If we hit control flow, force resolve all remaining dependencies. */
2570 if (scan_inst
->is_control_flow()) {
2571 for (int i
= 0; i
< write_len
; i
++) {
2573 scan_inst
->insert_before(DEP_RESOLVE_MOV(first_write_grf
+ i
));
2578 /* Clear the flag for registers that actually got read (as expected). */
2579 clear_deps_for_inst_src(scan_inst
, dispatch_width
,
2580 needs_dep
, first_write_grf
, write_len
);
2582 /* We insert our reads as late as possible since they're reading the
2583 * result of a SEND, which has massive latency.
2585 if (scan_inst
->dst
.file
== GRF
&&
2586 scan_inst
->dst
.reg
>= first_write_grf
&&
2587 scan_inst
->dst
.reg
< first_write_grf
+ write_len
&&
2588 needs_dep
[scan_inst
->dst
.reg
- first_write_grf
]) {
2589 scan_inst
->insert_before(DEP_RESOLVE_MOV(scan_inst
->dst
.reg
));
2590 needs_dep
[scan_inst
->dst
.reg
- first_write_grf
] = false;
2593 /* Continue the loop only if we haven't resolved all the dependencies */
2595 for (i
= 0; i
< write_len
; i
++) {
2603 /* If we hit the end of the program, resolve all remaining dependencies out
2606 fs_inst
*last_inst
= (fs_inst
*)this->instructions
.get_tail();
2607 assert(last_inst
->eot
);
2608 for (int i
= 0; i
< write_len
; i
++) {
2610 last_inst
->insert_before(DEP_RESOLVE_MOV(first_write_grf
+ i
));
2615 fs_visitor::insert_gen4_send_dependency_workarounds()
2617 if (brw
->gen
!= 4 || brw
->is_g4x
)
2620 /* Note that we're done with register allocation, so GRF fs_regs always
2621 * have a .reg_offset of 0.
2624 foreach_list_safe(node
, &this->instructions
) {
2625 fs_inst
*inst
= (fs_inst
*)node
;
2627 if (inst
->mlen
!= 0 && inst
->dst
.file
== GRF
) {
2628 insert_gen4_pre_send_dependency_workarounds(inst
);
2629 insert_gen4_post_send_dependency_workarounds(inst
);
2635 * Turns the generic expression-style uniform pull constant load instruction
2636 * into a hardware-specific series of instructions for loading a pull
2639 * The expression style allows the CSE pass before this to optimize out
2640 * repeated loads from the same offset, and gives the pre-register-allocation
2641 * scheduling full flexibility, while the conversion to native instructions
2642 * allows the post-register-allocation scheduler the best information
2645 * Note that execution masking for setting up pull constant loads is special:
2646 * the channels that need to be written are unrelated to the current execution
2647 * mask, since a later instruction will use one of the result channels as a
2648 * source operand for all 8 or 16 of its channels.
2651 fs_visitor::lower_uniform_pull_constant_loads()
2653 foreach_list(node
, &this->instructions
) {
2654 fs_inst
*inst
= (fs_inst
*)node
;
2656 if (inst
->opcode
!= FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
)
2659 if (brw
->gen
>= 7) {
2660 /* The offset arg before was a vec4-aligned byte offset. We need to
2661 * turn it into a dword offset.
2663 fs_reg const_offset_reg
= inst
->src
[1];
2664 assert(const_offset_reg
.file
== IMM
&&
2665 const_offset_reg
.type
== BRW_REGISTER_TYPE_UD
);
2666 const_offset_reg
.imm
.u
/= 4;
2667 fs_reg payload
= fs_reg(this, glsl_type::uint_type
);
2669 /* This is actually going to be a MOV, but since only the first dword
2670 * is accessed, we have a special opcode to do just that one. Note
2671 * that this needs to be an operation that will be considered a def
2672 * by live variable analysis, or register allocation will explode.
2674 fs_inst
*setup
= new(mem_ctx
) fs_inst(FS_OPCODE_SET_SIMD4X2_OFFSET
,
2675 payload
, const_offset_reg
);
2676 setup
->force_writemask_all
= true;
2678 setup
->ir
= inst
->ir
;
2679 setup
->annotation
= inst
->annotation
;
2680 inst
->insert_before(setup
);
2682 /* Similarly, this will only populate the first 4 channels of the
2683 * result register (since we only use smear values from 0-3), but we
2684 * don't tell the optimizer.
2686 inst
->opcode
= FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD_GEN7
;
2687 inst
->src
[1] = payload
;
2689 this->live_intervals_valid
= false;
2691 /* Before register allocation, we didn't tell the scheduler about the
2692 * MRF we use. We know it's safe to use this MRF because nothing
2693 * else does except for register spill/unspill, which generates and
2694 * uses its MRF within a single IR instruction.
2696 inst
->base_mrf
= 14;
2703 fs_visitor::dump_instruction(backend_instruction
*be_inst
)
2705 fs_inst
*inst
= (fs_inst
*)be_inst
;
2707 if (inst
->predicate
) {
2708 printf("(%cf0.%d) ",
2709 inst
->predicate_inverse
? '-' : '+',
2713 printf("%s", brw_instruction_name(inst
->opcode
));
2716 if (inst
->conditional_mod
) {
2718 if (!inst
->predicate
&&
2719 (brw
->gen
< 5 || (inst
->opcode
!= BRW_OPCODE_SEL
&&
2720 inst
->opcode
!= BRW_OPCODE_IF
&&
2721 inst
->opcode
!= BRW_OPCODE_WHILE
))) {
2722 printf(".f0.%d", inst
->flag_subreg
);
2728 switch (inst
->dst
.file
) {
2730 printf("vgrf%d", inst
->dst
.reg
);
2731 if (inst
->dst
.reg_offset
)
2732 printf("+%d", inst
->dst
.reg_offset
);
2735 printf("m%d", inst
->dst
.reg
);
2741 printf("***u%d***", inst
->dst
.reg
);
2744 if (inst
->dst
.reg
== BRW_ARF_NULL
)
2747 printf("arf%d", inst
->dst
.reg
);
2755 for (int i
= 0; i
< 3; i
++) {
2756 if (inst
->src
[i
].negate
)
2758 if (inst
->src
[i
].abs
)
2760 switch (inst
->src
[i
].file
) {
2762 printf("vgrf%d", inst
->src
[i
].reg
);
2763 if (inst
->src
[i
].reg_offset
)
2764 printf("+%d", inst
->src
[i
].reg_offset
);
2767 printf("***m%d***", inst
->src
[i
].reg
);
2770 printf("u%d", inst
->src
[i
].reg
);
2771 if (inst
->src
[i
].reg_offset
)
2772 printf(".%d", inst
->src
[i
].reg_offset
);
2778 switch (inst
->src
[i
].type
) {
2779 case BRW_REGISTER_TYPE_F
:
2780 printf("%ff", inst
->src
[i
].imm
.f
);
2782 case BRW_REGISTER_TYPE_D
:
2783 printf("%dd", inst
->src
[i
].imm
.i
);
2785 case BRW_REGISTER_TYPE_UD
:
2786 printf("%uu", inst
->src
[i
].imm
.u
);
2797 if (inst
->src
[i
].abs
)
2806 if (inst
->force_uncompressed
)
2809 if (inst
->force_sechalf
)
2816 * Possibly returns an instruction that set up @param reg.
2818 * Sometimes we want to take the result of some expression/variable
2819 * dereference tree and rewrite the instruction generating the result
2820 * of the tree. When processing the tree, we know that the
2821 * instructions generated are all writing temporaries that are dead
2822 * outside of this tree. So, if we have some instructions that write
2823 * a temporary, we're free to point that temp write somewhere else.
2825 * Note that this doesn't guarantee that the instruction generated
2826 * only reg -- it might be the size=4 destination of a texture instruction.
2829 fs_visitor::get_instruction_generating_reg(fs_inst
*start
,
2834 end
->is_partial_write() ||
2836 !reg
.equals(end
->dst
)) {
2844 fs_visitor::setup_payload_gen6()
2847 (fp
->Base
.InputsRead
& (1 << VARYING_SLOT_POS
)) != 0;
2848 unsigned barycentric_interp_modes
= c
->prog_data
.barycentric_interp_modes
;
2850 assert(brw
->gen
>= 6);
2852 /* R0-1: masks, pixel X/Y coordinates. */
2853 c
->nr_payload_regs
= 2;
2854 /* R2: only for 32-pixel dispatch.*/
2856 /* R3-26: barycentric interpolation coordinates. These appear in the
2857 * same order that they appear in the brw_wm_barycentric_interp_mode
2858 * enum. Each set of coordinates occupies 2 registers if dispatch width
2859 * == 8 and 4 registers if dispatch width == 16. Coordinates only
2860 * appear if they were enabled using the "Barycentric Interpolation
2861 * Mode" bits in WM_STATE.
2863 for (int i
= 0; i
< BRW_WM_BARYCENTRIC_INTERP_MODE_COUNT
; ++i
) {
2864 if (barycentric_interp_modes
& (1 << i
)) {
2865 c
->barycentric_coord_reg
[i
] = c
->nr_payload_regs
;
2866 c
->nr_payload_regs
+= 2;
2867 if (dispatch_width
== 16) {
2868 c
->nr_payload_regs
+= 2;
2873 /* R27: interpolated depth if uses source depth */
2875 c
->source_depth_reg
= c
->nr_payload_regs
;
2876 c
->nr_payload_regs
++;
2877 if (dispatch_width
== 16) {
2878 /* R28: interpolated depth if not 8-wide. */
2879 c
->nr_payload_regs
++;
2882 /* R29: interpolated W set if GEN6_WM_USES_SOURCE_W. */
2884 c
->source_w_reg
= c
->nr_payload_regs
;
2885 c
->nr_payload_regs
++;
2886 if (dispatch_width
== 16) {
2887 /* R30: interpolated W if not 8-wide. */
2888 c
->nr_payload_regs
++;
2891 /* R31: MSAA position offsets. */
2892 /* R32-: bary for 32-pixel. */
2893 /* R58-59: interp W for 32-pixel. */
2895 if (fp
->Base
.OutputsWritten
& BITFIELD64_BIT(FRAG_RESULT_DEPTH
)) {
2896 c
->source_depth_to_render_target
= true;
2903 sanity_param_count
= fp
->Base
.Parameters
->NumParameters
;
2904 uint32_t orig_nr_params
= c
->prog_data
.nr_params
;
2907 setup_payload_gen6();
2909 setup_payload_gen4();
2914 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
)
2915 emit_shader_time_begin();
2917 calculate_urb_setup();
2919 emit_interpolation_setup_gen4();
2921 emit_interpolation_setup_gen6();
2923 /* We handle discards by keeping track of the still-live pixels in f0.1.
2924 * Initialize it with the dispatched pixels.
2927 fs_inst
*discard_init
= emit(FS_OPCODE_MOV_DISPATCH_TO_FLAGS
);
2928 discard_init
->flag_subreg
= 1;
2931 /* Generate FS IR for main(). (the visitor only descends into
2932 * functions called "main").
2935 foreach_list(node
, &*shader
->ir
) {
2936 ir_instruction
*ir
= (ir_instruction
*)node
;
2938 this->result
= reg_undef
;
2942 emit_fragment_program_code();
2948 emit(FS_OPCODE_PLACEHOLDER_HALT
);
2952 split_virtual_grfs();
2954 move_uniform_array_access_to_pull_constants();
2955 setup_pull_constants();
2961 compact_virtual_grfs();
2963 progress
= remove_duplicate_mrf_writes() || progress
;
2965 progress
= opt_algebraic() || progress
;
2966 progress
= opt_cse() || progress
;
2967 progress
= opt_copy_propagate() || progress
;
2968 progress
= dead_code_eliminate() || progress
;
2969 progress
= dead_code_eliminate_local() || progress
;
2970 progress
= register_coalesce() || progress
;
2971 progress
= register_coalesce_2() || progress
;
2972 progress
= compute_to_mrf() || progress
;
2975 remove_dead_constants();
2977 schedule_instructions(false);
2979 lower_uniform_pull_constant_loads();
2981 assign_curb_setup();
2985 /* Debug of register spilling: Go spill everything. */
2986 for (int i
= 0; i
< virtual_grf_count
; i
++) {
2992 assign_regs_trivial();
2994 while (!assign_regs()) {
3000 assert(force_uncompressed_stack
== 0);
3001 assert(force_sechalf_stack
== 0);
3003 /* This must come after all optimization and register allocation, since
3004 * it inserts dead code that happens to have side effects, and it does
3005 * so based on the actual physical registers in use.
3007 insert_gen4_send_dependency_workarounds();
3012 schedule_instructions(true);
3014 if (dispatch_width
== 8) {
3015 c
->prog_data
.reg_blocks
= brw_register_blocks(grf_used
);
3017 c
->prog_data
.reg_blocks_16
= brw_register_blocks(grf_used
);
3019 /* Make sure we didn't try to sneak in an extra uniform */
3020 assert(orig_nr_params
== c
->prog_data
.nr_params
);
3021 (void) orig_nr_params
;
3024 /* If any state parameters were appended, then ParameterValues could have
3025 * been realloced, in which case the driver uniform storage set up by
3026 * _mesa_associate_uniform_storage() would point to freed memory. Make
3027 * sure that didn't happen.
3029 assert(sanity_param_count
== fp
->Base
.Parameters
->NumParameters
);
3035 brw_wm_fs_emit(struct brw_context
*brw
, struct brw_wm_compile
*c
,
3036 struct gl_fragment_program
*fp
,
3037 struct gl_shader_program
*prog
,
3038 unsigned *final_assembly_size
)
3040 bool start_busy
= false;
3041 float start_time
= 0;
3043 if (unlikely(brw
->perf_debug
)) {
3044 start_busy
= (brw
->batch
.last_bo
&&
3045 drm_intel_bo_busy(brw
->batch
.last_bo
));
3046 start_time
= get_time();
3049 struct brw_shader
*shader
= NULL
;
3051 shader
= (brw_shader
*) prog
->_LinkedShaders
[MESA_SHADER_FRAGMENT
];
3053 if (unlikely(INTEL_DEBUG
& DEBUG_WM
)) {
3055 printf("GLSL IR for native fragment shader %d:\n", prog
->Name
);
3056 _mesa_print_ir(shader
->ir
, NULL
);
3059 printf("ARB_fragment_program %d ir for native fragment shader\n",
3061 _mesa_print_program(&fp
->Base
);
3065 /* Now the main event: Visit the shader IR and generate our FS IR for it.
3067 fs_visitor
v(brw
, c
, prog
, fp
, 8);
3070 prog
->LinkStatus
= false;
3071 ralloc_strcat(&prog
->InfoLog
, v
.fail_msg
);
3074 _mesa_problem(NULL
, "Failed to compile fragment shader: %s\n",
3080 exec_list
*simd16_instructions
= NULL
;
3081 fs_visitor
v2(brw
, c
, prog
, fp
, 16);
3082 if (brw
->gen
>= 5 && likely(!(INTEL_DEBUG
& DEBUG_NO16
))) {
3083 if (c
->prog_data
.nr_pull_params
== 0) {
3084 /* Try a 16-wide compile */
3085 v2
.import_uniforms(&v
);
3087 perf_debug("16-wide shader failed to compile, falling back to "
3088 "8-wide at a 10-20%% performance cost: %s", v2
.fail_msg
);
3090 simd16_instructions
= &v2
.instructions
;
3093 perf_debug("Skipping 16-wide due to pull parameters.\n");
3097 c
->prog_data
.dispatch_width
= 8;
3099 fs_generator
g(brw
, c
, prog
, fp
, v
.dual_src_output
.file
!= BAD_FILE
);
3100 const unsigned *generated
= g
.generate_assembly(&v
.instructions
,
3101 simd16_instructions
,
3102 final_assembly_size
);
3104 if (unlikely(brw
->perf_debug
) && shader
) {
3105 if (shader
->compiled_once
)
3106 brw_wm_debug_recompile(brw
, prog
, &c
->key
);
3107 shader
->compiled_once
= true;
3109 if (start_busy
&& !drm_intel_bo_busy(brw
->batch
.last_bo
)) {
3110 perf_debug("FS compile took %.03f ms and stalled the GPU\n",
3111 (get_time() - start_time
) * 1000);
3119 brw_fs_precompile(struct gl_context
*ctx
, struct gl_shader_program
*prog
)
3121 struct brw_context
*brw
= brw_context(ctx
);
3122 struct brw_wm_prog_key key
;
3124 if (!prog
->_LinkedShaders
[MESA_SHADER_FRAGMENT
])
3127 struct gl_fragment_program
*fp
= (struct gl_fragment_program
*)
3128 prog
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]->Program
;
3129 struct brw_fragment_program
*bfp
= brw_fragment_program(fp
);
3130 bool program_uses_dfdy
= fp
->UsesDFdy
;
3132 memset(&key
, 0, sizeof(key
));
3136 key
.iz_lookup
|= IZ_PS_KILL_ALPHATEST_BIT
;
3138 if (fp
->Base
.OutputsWritten
& BITFIELD64_BIT(FRAG_RESULT_DEPTH
))
3139 key
.iz_lookup
|= IZ_PS_COMPUTES_DEPTH_BIT
;
3141 /* Just assume depth testing. */
3142 key
.iz_lookup
|= IZ_DEPTH_TEST_ENABLE_BIT
;
3143 key
.iz_lookup
|= IZ_DEPTH_WRITE_ENABLE_BIT
;
3147 key
.input_slots_valid
|= BITFIELD64_BIT(VARYING_SLOT_POS
);
3149 for (int i
= 0; i
< VARYING_SLOT_MAX
; i
++) {
3150 if (!(fp
->Base
.InputsRead
& BITFIELD64_BIT(i
)))
3154 if (_mesa_varying_slot_in_fs((gl_varying_slot
) i
))
3155 key
.input_slots_valid
|= BITFIELD64_BIT(i
);
3159 key
.clamp_fragment_color
= ctx
->API
== API_OPENGL_COMPAT
;
3161 unsigned sampler_count
= _mesa_fls(fp
->Base
.SamplersUsed
);
3162 for (unsigned i
= 0; i
< sampler_count
; i
++) {
3163 if (fp
->Base
.ShadowSamplers
& (1 << i
)) {
3164 /* Assume DEPTH_TEXTURE_MODE is the default: X, X, X, 1 */
3165 key
.tex
.swizzles
[i
] =
3166 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_X
, SWIZZLE_X
, SWIZZLE_ONE
);
3168 /* Color sampler: assume no swizzling. */
3169 key
.tex
.swizzles
[i
] = SWIZZLE_XYZW
;
3173 if (fp
->Base
.InputsRead
& VARYING_BIT_POS
) {
3174 key
.drawable_height
= ctx
->DrawBuffer
->Height
;
3177 if ((fp
->Base
.InputsRead
& VARYING_BIT_POS
) || program_uses_dfdy
) {
3178 key
.render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
3181 key
.nr_color_regions
= 1;
3183 key
.program_string_id
= bfp
->id
;
3185 uint32_t old_prog_offset
= brw
->wm
.prog_offset
;
3186 struct brw_wm_prog_data
*old_prog_data
= brw
->wm
.prog_data
;
3188 bool success
= do_wm_prog(brw
, prog
, bfp
, &key
);
3190 brw
->wm
.prog_offset
= old_prog_offset
;
3191 brw
->wm
.prog_data
= old_prog_data
;