Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2014 Broadcom
  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 "vc4_context.h"
  25.  
  26. void
  27. vc4_emit_state(struct pipe_context *pctx)
  28. {
  29.         struct vc4_context *vc4 = vc4_context(pctx);
  30.  
  31.         if (vc4->dirty & (VC4_DIRTY_SCISSOR | VC4_DIRTY_VIEWPORT)) {
  32.                 float *vpscale = vc4->viewport.scale;
  33.                 float *vptranslate = vc4->viewport.translate;
  34.                 float vp_minx = -fabs(vpscale[0]) + vptranslate[0];
  35.                 float vp_maxx = fabs(vpscale[0]) + vptranslate[0];
  36.                 float vp_miny = -fabs(vpscale[1]) + vptranslate[1];
  37.                 float vp_maxy = fabs(vpscale[1]) + vptranslate[1];
  38.                 uint32_t minx = MAX2(vc4->scissor.minx, vp_minx);
  39.                 uint32_t miny = MAX2(vc4->scissor.miny, vp_miny);
  40.                 uint32_t maxx = MIN2(vc4->scissor.maxx, vp_maxx);
  41.                 uint32_t maxy = MIN2(vc4->scissor.maxy, vp_maxy);
  42.  
  43.                 cl_u8(&vc4->bcl, VC4_PACKET_CLIP_WINDOW);
  44.                 cl_u16(&vc4->bcl, minx);
  45.                 cl_u16(&vc4->bcl, miny);
  46.                 cl_u16(&vc4->bcl, maxx - minx);
  47.                 cl_u16(&vc4->bcl, maxy - miny);
  48.  
  49.                 vc4->draw_min_x = MIN2(vc4->draw_min_x, minx);
  50.                 vc4->draw_min_y = MIN2(vc4->draw_min_y, miny);
  51.                 vc4->draw_max_x = MAX2(vc4->draw_max_x, maxx);
  52.                 vc4->draw_max_y = MAX2(vc4->draw_max_y, maxy);
  53.         }
  54.  
  55.         if (vc4->dirty & (VC4_DIRTY_RASTERIZER | VC4_DIRTY_ZSA)) {
  56.                 cl_u8(&vc4->bcl, VC4_PACKET_CONFIGURATION_BITS);
  57.                 cl_u8(&vc4->bcl,
  58.                       vc4->rasterizer->config_bits[0] |
  59.                       vc4->zsa->config_bits[0]);
  60.                 cl_u8(&vc4->bcl,
  61.                       vc4->rasterizer->config_bits[1] |
  62.                       vc4->zsa->config_bits[1]);
  63.                 cl_u8(&vc4->bcl,
  64.                       vc4->rasterizer->config_bits[2] |
  65.                       vc4->zsa->config_bits[2]);
  66.         }
  67.  
  68.         if (vc4->dirty & VC4_DIRTY_RASTERIZER) {
  69.                 cl_u8(&vc4->bcl, VC4_PACKET_DEPTH_OFFSET);
  70.                 cl_u16(&vc4->bcl, vc4->rasterizer->offset_factor);
  71.                 cl_u16(&vc4->bcl, vc4->rasterizer->offset_units);
  72.  
  73.                 cl_u8(&vc4->bcl, VC4_PACKET_POINT_SIZE);
  74.                 cl_f(&vc4->bcl, vc4->rasterizer->point_size);
  75.  
  76.                 cl_u8(&vc4->bcl, VC4_PACKET_LINE_WIDTH);
  77.                 cl_f(&vc4->bcl, vc4->rasterizer->base.line_width);
  78.         }
  79.  
  80.         if (vc4->dirty & VC4_DIRTY_VIEWPORT) {
  81.                 cl_u8(&vc4->bcl, VC4_PACKET_CLIPPER_XY_SCALING);
  82.                 cl_f(&vc4->bcl, vc4->viewport.scale[0] * 16.0f);
  83.                 cl_f(&vc4->bcl, vc4->viewport.scale[1] * 16.0f);
  84.  
  85.                 cl_u8(&vc4->bcl, VC4_PACKET_CLIPPER_Z_SCALING);
  86.                 cl_f(&vc4->bcl, vc4->viewport.translate[2]);
  87.                 cl_f(&vc4->bcl, vc4->viewport.scale[2]);
  88.  
  89.                 cl_u8(&vc4->bcl, VC4_PACKET_VIEWPORT_OFFSET);
  90.                 cl_u16(&vc4->bcl, 16 * vc4->viewport.translate[0]);
  91.                 cl_u16(&vc4->bcl, 16 * vc4->viewport.translate[1]);
  92.         }
  93.  
  94.         if (vc4->dirty & VC4_DIRTY_FLAT_SHADE_FLAGS) {
  95.                 cl_u8(&vc4->bcl, VC4_PACKET_FLAT_SHADE_FLAGS);
  96.                 cl_u32(&vc4->bcl, vc4->rasterizer->base.flatshade ?
  97.                        vc4->prog.fs->color_inputs : 0);
  98.         }
  99. }
  100.