Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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.  
  26. static char const *get_qual_name(int mode)
  27. {
  28.    switch (mode) {
  29.       case INTERP_QUALIFIER_NONE:          return "none";
  30.       case INTERP_QUALIFIER_FLAT:          return "flat";
  31.       case INTERP_QUALIFIER_SMOOTH:        return "smooth";
  32.       case INTERP_QUALIFIER_NOPERSPECTIVE: return "nopersp";
  33.       default:                             return "???";
  34.    }
  35. }
  36.  
  37.  
  38. /* Set up interpolation modes for every element in the VUE */
  39. static void
  40. brw_setup_vue_interpolation(struct brw_context *brw)
  41. {
  42.    const struct gl_fragment_program *fprog = brw->fragment_program;
  43.    struct brw_vue_map *vue_map = &brw->vue_map_geom_out;
  44.  
  45.    memset(&brw->interpolation_mode, INTERP_QUALIFIER_NONE, sizeof(brw->interpolation_mode));
  46.  
  47.    brw->ctx.NewDriverState |= BRW_NEW_INTERPOLATION_MAP;
  48.  
  49.    if (!fprog)
  50.       return;
  51.  
  52.    for (int i = 0; i < vue_map->num_slots; i++) {
  53.       int varying = vue_map->slot_to_varying[i];
  54.       if (varying == -1)
  55.          continue;
  56.  
  57.       /* HPOS always wants noperspective. setting it up here allows
  58.        * us to not need special handling in the SF program. */
  59.       if (varying == VARYING_SLOT_POS) {
  60.          brw->interpolation_mode.mode[i] = INTERP_QUALIFIER_NOPERSPECTIVE;
  61.          continue;
  62.       }
  63.  
  64.       int frag_attrib = varying;
  65.       if (varying == VARYING_SLOT_BFC0 || varying == VARYING_SLOT_BFC1)
  66.          frag_attrib = varying - VARYING_SLOT_BFC0 + VARYING_SLOT_COL0;
  67.  
  68.       if (!(fprog->Base.InputsRead & BITFIELD64_BIT(frag_attrib)))
  69.          continue;
  70.  
  71.       enum glsl_interp_qualifier mode = fprog->InterpQualifier[frag_attrib];
  72.  
  73.       /* If the mode is not specified, the default varies: Color values
  74.        * follow GL_SHADE_MODEL; everything else is smooth.
  75.        */
  76.       if (mode == INTERP_QUALIFIER_NONE) {
  77.          if (frag_attrib == VARYING_SLOT_COL0 || frag_attrib == VARYING_SLOT_COL1)
  78.             mode = brw->ctx.Light.ShadeModel == GL_FLAT
  79.                ? INTERP_QUALIFIER_FLAT : INTERP_QUALIFIER_SMOOTH;
  80.          else
  81.             mode = INTERP_QUALIFIER_SMOOTH;
  82.       }
  83.  
  84.       brw->interpolation_mode.mode[i] = mode;
  85.    }
  86.  
  87.    if (unlikely(INTEL_DEBUG & DEBUG_VUE)) {
  88.       fprintf(stderr, "VUE map:\n");
  89.       for (int i = 0; i < vue_map->num_slots; i++) {
  90.          int varying = vue_map->slot_to_varying[i];
  91.          if (varying == -1) {
  92.             fprintf(stderr, "%d: --\n", i);
  93.             continue;
  94.          }
  95.  
  96.          fprintf(stderr, "%d: %d %s ofs %d\n",
  97.                  i, varying,
  98.                  get_qual_name(brw->interpolation_mode.mode[i]),
  99.                  brw_vue_slot_to_offset(i));
  100.       }
  101.    }
  102. }
  103.  
  104.  
  105. const struct brw_tracked_state brw_interpolation_map = {
  106.    .dirty = {
  107.       .mesa  = _NEW_LIGHT,
  108.       .brw   = BRW_NEW_FRAGMENT_PROGRAM |
  109.                BRW_NEW_VUE_MAP_GEOM_OUT,
  110.    },
  111.    .emit = brw_setup_vue_interpolation
  112. };
  113.