mesa/i965/i915/r200: eliminate gl_vertex_program
[mesa.git] / src / mesa / drivers / dri / i965 / brw_interpolation_map.c
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include "brw_state.h"
25 #include "compiler/nir/nir.h"
26
27 static char const *get_qual_name(int mode)
28 {
29 switch (mode) {
30 case INTERP_MODE_NONE: return "none";
31 case INTERP_MODE_FLAT: return "flat";
32 case INTERP_MODE_SMOOTH: return "smooth";
33 case INTERP_MODE_NOPERSPECTIVE: return "nopersp";
34 default: return "???";
35 }
36 }
37
38
39 /* Set up interpolation modes for every element in the VUE */
40 void
41 brw_setup_vue_interpolation(struct brw_context *brw)
42 {
43 const struct gl_fragment_program *fprog = brw->fragment_program;
44 struct brw_vue_map *vue_map = &brw->vue_map_geom_out;
45
46 if (!brw_state_dirty(brw,
47 _NEW_LIGHT,
48 BRW_NEW_BLORP |
49 BRW_NEW_FRAGMENT_PROGRAM |
50 BRW_NEW_VUE_MAP_GEOM_OUT))
51 return;
52
53 memset(&brw->interpolation_mode, INTERP_MODE_NONE, sizeof(brw->interpolation_mode));
54
55 brw->ctx.NewDriverState |= BRW_NEW_INTERPOLATION_MAP;
56
57 if (!fprog)
58 return;
59
60 for (int i = 0; i < vue_map->num_slots; i++) {
61 int varying = vue_map->slot_to_varying[i];
62 if (varying == -1)
63 continue;
64
65 /* HPOS always wants noperspective. setting it up here allows
66 * us to not need special handling in the SF program. */
67 if (varying == VARYING_SLOT_POS) {
68 brw->interpolation_mode.mode[i] = INTERP_MODE_NOPERSPECTIVE;
69 continue;
70 }
71
72 int frag_attrib = varying;
73 if (varying == VARYING_SLOT_BFC0 || varying == VARYING_SLOT_BFC1)
74 frag_attrib = varying - VARYING_SLOT_BFC0 + VARYING_SLOT_COL0;
75
76 if (!(fprog->Base.nir->info->inputs_read & BITFIELD64_BIT(frag_attrib)))
77 continue;
78
79 enum glsl_interp_mode mode = fprog->InterpQualifier[frag_attrib];
80
81 /* If the mode is not specified, the default varies: Color values
82 * follow GL_SHADE_MODEL; everything else is smooth.
83 */
84 if (mode == INTERP_MODE_NONE) {
85 if (frag_attrib == VARYING_SLOT_COL0 || frag_attrib == VARYING_SLOT_COL1)
86 mode = brw->ctx.Light.ShadeModel == GL_FLAT
87 ? INTERP_MODE_FLAT : INTERP_MODE_SMOOTH;
88 else
89 mode = INTERP_MODE_SMOOTH;
90 }
91
92 brw->interpolation_mode.mode[i] = mode;
93 }
94
95 if (unlikely(INTEL_DEBUG & DEBUG_VUE)) {
96 fprintf(stderr, "VUE map:\n");
97 for (int i = 0; i < vue_map->num_slots; i++) {
98 int varying = vue_map->slot_to_varying[i];
99 if (varying == -1) {
100 fprintf(stderr, "%d: --\n", i);
101 continue;
102 }
103
104 fprintf(stderr, "%d: %d %s ofs %d\n",
105 i, varying,
106 get_qual_name(brw->interpolation_mode.mode[i]),
107 brw_vue_slot_to_offset(i));
108 }
109 }
110 }