2 * Copyright © 2013 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
24 #include "brw_compiler.h"
25 #include "brw_context.h"
26 #include "compiler/nir/nir.h"
28 static char const *get_qual_name(int mode
)
31 case INTERP_MODE_NONE
: return "none";
32 case INTERP_MODE_FLAT
: return "flat";
33 case INTERP_MODE_SMOOTH
: return "smooth";
34 case INTERP_MODE_NOPERSPECTIVE
: return "nopersp";
35 default: return "???";
40 gen4_frag_prog_set_interp_modes(struct gen4_fragment_program
*prog
,
41 struct brw_vue_map
*vue_map
,
42 unsigned location
, unsigned slot_count
,
43 enum glsl_interp_mode interp
)
45 for (unsigned k
= 0; k
< slot_count
; k
++) {
46 unsigned slot
= vue_map
->varying_to_slot
[location
+ k
];
47 if (slot
!= -1 && prog
->interp_mode
[slot
] == INTERP_MODE_NONE
) {
48 prog
->interp_mode
[slot
] = interp
;
50 if (prog
->interp_mode
[slot
] == INTERP_MODE_FLAT
) {
51 prog
->contains_flat_varying
= true;
52 } else if (prog
->interp_mode
[slot
] == INTERP_MODE_NOPERSPECTIVE
) {
53 prog
->contains_noperspective_varying
= true;
59 /* Set up interpolation modes for every element in the VUE */
61 brw_setup_vue_interpolation(struct brw_vue_map
*vue_map
, nir_shader
*nir
,
62 struct gl_program
*prog
,
63 const struct gen_device_info
*devinfo
)
65 struct gen4_fragment_program
*fprog
= (struct gen4_fragment_program
*) prog
;
67 /* Initialise interp_mode. INTERP_MODE_NONE == 0 */
68 memset(fprog
->interp_mode
, 0, sizeof(fprog
->interp_mode
));
73 /* HPOS always wants noperspective. setting it up here allows
74 * us to not need special handling in the SF program.
76 unsigned pos_slot
= vue_map
->varying_to_slot
[VARYING_SLOT_POS
];
77 if (pos_slot
!= -1) {;
78 fprog
->interp_mode
[pos_slot
] = INTERP_MODE_NOPERSPECTIVE
;
79 fprog
->contains_noperspective_varying
= true;
82 foreach_list_typed(nir_variable
, var
, node
, &nir
->inputs
) {
83 unsigned location
= var
->data
.location
;
84 unsigned slot_count
= glsl_count_attribute_slots(var
->type
, false);
86 gen4_frag_prog_set_interp_modes(fprog
, vue_map
, location
, slot_count
,
87 var
->data
.interpolation
);
89 if (location
== VARYING_SLOT_COL0
|| location
== VARYING_SLOT_COL1
) {
90 location
= location
+ VARYING_SLOT_BFC0
- VARYING_SLOT_COL0
;
91 gen4_frag_prog_set_interp_modes(fprog
, vue_map
, location
,
92 slot_count
, var
->data
.interpolation
);
98 fprintf(stderr
, "VUE map:\n");
99 for (int i
= 0; i
< vue_map
->num_slots
; i
++) {
100 int varying
= vue_map
->slot_to_varying
[i
];
102 fprintf(stderr
, "%d: --\n", i
);
106 fprintf(stderr
, "%d: %d %s ofs %d\n",
108 get_qual_name(fprog
->interp_mode
[i
]),
109 brw_vue_slot_to_offset(i
));