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_compiler.h" 25 #include "brw_context.h" 26 #include "compiler/nir/nir.h" 27 28 static char const *get_qual_name(int mode) 29 { 30 switch (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 "???"; 36 } 37 } 38 39 static void 40 gen4_frag_prog_set_interp_modes(struct brw_wm_prog_data *prog_data, 41 struct brw_vue_map *vue_map, 42 unsigned location, unsigned slot_count, 43 enum glsl_interp_mode interp) 44 { 45 for (unsigned k = 0; k < slot_count; k++) { 46 unsigned slot = vue_map->varying_to_slot[location + k]; 47 if (slot != -1 && prog_data->interp_mode[slot] == INTERP_MODE_NONE) { 48 prog_data->interp_mode[slot] = interp; 49 50 if (prog_data->interp_mode[slot] == INTERP_MODE_FLAT) { 51 prog_data->contains_flat_varying = true; 52 } else if (prog_data->interp_mode[slot] == INTERP_MODE_NOPERSPECTIVE) { 53 prog_data->contains_noperspective_varying = true; 54 } 55 } 56 } 57 } 58 59 /* Set up interpolation modes for every element in the VUE */ 60 void 61 brw_setup_vue_interpolation(struct brw_vue_map *vue_map, nir_shader *nir, 62 struct brw_wm_prog_data *prog_data, 63 const struct gen_device_info *devinfo) 64 { 65 /* Initialise interp_mode. INTERP_MODE_NONE == 0 */ 66 memset(prog_data->interp_mode, 0, sizeof(prog_data->interp_mode)); 67 68 if (!vue_map) 69 return; 70 71 /* HPOS always wants noperspective. setting it up here allows 72 * us to not need special handling in the SF program. 73 */ 74 unsigned pos_slot = vue_map->varying_to_slot[VARYING_SLOT_POS]; 75 if (pos_slot != -1) {; 76 prog_data->interp_mode[pos_slot] = INTERP_MODE_NOPERSPECTIVE; 77 prog_data->contains_noperspective_varying = true; 78 } 79 80 foreach_list_typed(nir_variable, var, node, &nir->inputs) { 81 unsigned location = var->data.location; 82 unsigned slot_count = glsl_count_attribute_slots(var->type, false); 83 84 gen4_frag_prog_set_interp_modes(prog_data, vue_map, location, slot_count, 85 var->data.interpolation); 86 87 if (location == VARYING_SLOT_COL0 || location == VARYING_SLOT_COL1) { 88 location = location + VARYING_SLOT_BFC0 - VARYING_SLOT_COL0; 89 gen4_frag_prog_set_interp_modes(prog_data, vue_map, location, 90 slot_count, var->data.interpolation); 91 } 92 } 93 94 bool debug = false; 95 if (debug) { 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(prog_data->interp_mode[i]), 107 brw_vue_slot_to_offset(i)); 108 } 109 } 110 } 111