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
  21.  * DEALINGS IN THE SOFTWARE.
  22.  */
  23.  
  24. #include "brw_context.h"
  25. #include "brw_state.h"
  26. #include "brw_defines.h"
  27. #include "intel_batchbuffer.h"
  28.  
  29. static void
  30. gen8_upload_gs_state(struct brw_context *brw)
  31. {
  32.    struct gl_context *ctx = &brw->ctx;
  33.    const struct brw_stage_state *stage_state = &brw->gs.base;
  34.    /* BRW_NEW_GEOMETRY_PROGRAM */
  35.    bool active = brw->geometry_program;
  36.    /* BRW_NEW_GS_PROG_DATA */
  37.    const struct brw_vue_prog_data *prog_data = &brw->gs.prog_data->base;
  38.  
  39.    if (active) {
  40.       int urb_entry_write_offset = 1;
  41.       uint32_t urb_entry_output_length =
  42.          ((prog_data->vue_map.num_slots + 1) / 2 - urb_entry_write_offset);
  43.  
  44.       if (urb_entry_output_length == 0)
  45.          urb_entry_output_length = 1;
  46.  
  47.       BEGIN_BATCH(10);
  48.       OUT_BATCH(_3DSTATE_GS << 16 | (10 - 2));
  49.       OUT_BATCH(stage_state->prog_offset);
  50.       OUT_BATCH(0);
  51.       OUT_BATCH(GEN6_GS_VECTOR_MASK_ENABLE |
  52.                 brw->geometry_program->VerticesIn |
  53.                 ((ALIGN(stage_state->sampler_count, 4)/4) <<
  54.                  GEN6_GS_SAMPLER_COUNT_SHIFT) |
  55.                 ((prog_data->base.binding_table.size_bytes / 4) <<
  56.                  GEN6_GS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
  57.  
  58.       if (brw->gs.prog_data->base.base.total_scratch) {
  59.          OUT_RELOC64(stage_state->scratch_bo,
  60.                      I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
  61.                      ffs(brw->gs.prog_data->base.base.total_scratch) - 11);
  62.          WARN_ONCE(true,
  63.                    "May need to implement a temporary workaround: GS Number of "
  64.                    "URB Entries must be less than or equal to the GS Maximum "
  65.                    "Number of Threads.\n");
  66.       } else {
  67.          OUT_BATCH(0);
  68.          OUT_BATCH(0);
  69.       }
  70.  
  71.       /* DW6 */
  72.       OUT_BATCH(((brw->gs.prog_data->output_vertex_size_hwords * 2 - 1) <<
  73.                  GEN7_GS_OUTPUT_VERTEX_SIZE_SHIFT) |
  74.                 (brw->gs.prog_data->output_topology <<
  75.                  GEN7_GS_OUTPUT_TOPOLOGY_SHIFT) |
  76.                 (prog_data->urb_read_length <<
  77.                  GEN6_GS_URB_READ_LENGTH_SHIFT) |
  78.                 (0 << GEN6_GS_URB_ENTRY_READ_OFFSET_SHIFT) |
  79.                 (prog_data->base.dispatch_grf_start_reg <<
  80.                  GEN6_GS_DISPATCH_START_GRF_SHIFT));
  81.  
  82.       uint32_t dw7 = (brw->gs.prog_data->control_data_header_size_hwords <<
  83.                       GEN7_GS_CONTROL_DATA_HEADER_SIZE_SHIFT) |
  84.                       brw->gs.prog_data->dispatch_mode |
  85.                      ((brw->gs.prog_data->invocations - 1) <<
  86.                       GEN7_GS_INSTANCE_CONTROL_SHIFT) |
  87.                       GEN6_GS_STATISTICS_ENABLE |
  88.                       (brw->gs.prog_data->include_primitive_id ?
  89.                        GEN7_GS_INCLUDE_PRIMITIVE_ID : 0) |
  90.                       GEN7_GS_REORDER_TRAILING |
  91.                       GEN7_GS_ENABLE;
  92.       uint32_t dw8 = brw->gs.prog_data->control_data_format <<
  93.                      HSW_GS_CONTROL_DATA_FORMAT_SHIFT;
  94.  
  95.       if (brw->gen < 9)
  96.          dw7 |= (brw->max_gs_threads / 2 - 1) << HSW_GS_MAX_THREADS_SHIFT;
  97.       else
  98.          dw8 |= brw->max_gs_threads - 1;
  99.  
  100.       /* DW7 */
  101.       OUT_BATCH(dw7);
  102.  
  103.       /* DW8 */
  104.       OUT_BATCH(dw8);
  105.  
  106.       /* DW9 / _NEW_TRANSFORM */
  107.       OUT_BATCH((ctx->Transform.ClipPlanesEnabled <<
  108.                  GEN8_GS_USER_CLIP_DISTANCE_SHIFT) |
  109.                 (urb_entry_output_length << GEN8_GS_URB_OUTPUT_LENGTH_SHIFT) |
  110.                 (urb_entry_write_offset <<
  111.                  GEN8_GS_URB_ENTRY_OUTPUT_OFFSET_SHIFT));
  112.       ADVANCE_BATCH();
  113.    } else {
  114.       BEGIN_BATCH(10);
  115.       OUT_BATCH(_3DSTATE_GS << 16 | (10 - 2));
  116.       OUT_BATCH(0); /* prog_bo */
  117.       OUT_BATCH(0);
  118.       OUT_BATCH(0);
  119.       OUT_BATCH(0); /* scratch space base offset */
  120.       OUT_BATCH(0);
  121.       OUT_BATCH(0);
  122.       OUT_BATCH(GEN6_GS_STATISTICS_ENABLE);
  123.       OUT_BATCH(0);
  124.       OUT_BATCH(0);
  125.       ADVANCE_BATCH();
  126.    }
  127. }
  128.  
  129. const struct brw_tracked_state gen8_gs_state = {
  130.    .dirty = {
  131.       .mesa  = _NEW_TRANSFORM,
  132.       .brw   = BRW_NEW_BATCH |
  133.                BRW_NEW_CONTEXT |
  134.                BRW_NEW_GEOMETRY_PROGRAM |
  135.                BRW_NEW_GS_PROG_DATA,
  136.    },
  137.    .emit = gen8_upload_gs_state,
  138. };
  139.