Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2009 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.  * Authors:
  24.  *    Eric Anholt <eric@anholt.net>
  25.  *
  26.  */
  27.  
  28. #include "brw_context.h"
  29. #include "brw_state.h"
  30. #include "brw_defines.h"
  31. #include "brw_util.h"
  32. #include "brw_wm.h"
  33. #include "program/program.h"
  34. #include "program/prog_parameter.h"
  35. #include "program/prog_statevars.h"
  36. #include "intel_batchbuffer.h"
  37.  
  38. static void
  39. gen6_upload_wm_push_constants(struct brw_context *brw)
  40. {
  41.    struct brw_stage_state *stage_state = &brw->wm.base;
  42.    /* BRW_NEW_FRAGMENT_PROGRAM */
  43.    const struct brw_fragment_program *fp =
  44.       brw_fragment_program_const(brw->fragment_program);
  45.    /* BRW_NEW_FS_PROG_DATA */
  46.    const struct brw_wm_prog_data *prog_data = brw->wm.prog_data;
  47.  
  48.    gen6_upload_push_constants(brw, &fp->program.Base, &prog_data->base,
  49.                               stage_state, AUB_TRACE_WM_CONSTANTS);
  50.  
  51.    if (brw->gen >= 7) {
  52.       gen7_upload_constant_state(brw, &brw->wm.base, true,
  53.                                  _3DSTATE_CONSTANT_PS);
  54.    }
  55. }
  56.  
  57. const struct brw_tracked_state gen6_wm_push_constants = {
  58.    .dirty = {
  59.       .mesa  = _NEW_PROGRAM_CONSTANTS,
  60.       .brw   = BRW_NEW_BATCH |
  61.                BRW_NEW_FRAGMENT_PROGRAM |
  62.                BRW_NEW_FS_PROG_DATA |
  63.                BRW_NEW_PUSH_CONSTANT_ALLOCATION,
  64.    },
  65.    .emit = gen6_upload_wm_push_constants,
  66. };
  67.  
  68. void
  69. gen6_upload_wm_state(struct brw_context *brw,
  70.                      const struct brw_fragment_program *fp,
  71.                      const struct brw_wm_prog_data *prog_data,
  72.                      const struct brw_stage_state *stage_state,
  73.                      bool multisampled_fbo, int min_inv_per_frag,
  74.                      bool dual_source_blend_enable, bool kill_enable,
  75.                      bool color_buffer_write_enable, bool msaa_enabled,
  76.                      bool line_stipple_enable, bool polygon_stipple_enable,
  77.                      bool statistic_enable)
  78. {
  79.    uint32_t dw2, dw4, dw5, dw6, ksp0, ksp2;
  80.  
  81.    /* We can't fold this into gen6_upload_wm_push_constants(), because
  82.     * according to the SNB PRM, vol 2 part 1 section 7.2.2
  83.     * (3DSTATE_CONSTANT_PS [DevSNB]):
  84.     *
  85.     *     "[DevSNB]: This packet must be followed by WM_STATE."
  86.     */
  87.    if (prog_data->base.nr_params == 0) {
  88.       /* Disable the push constant buffers. */
  89.       BEGIN_BATCH(5);
  90.       OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 | (5 - 2));
  91.       OUT_BATCH(0);
  92.       OUT_BATCH(0);
  93.       OUT_BATCH(0);
  94.       OUT_BATCH(0);
  95.       ADVANCE_BATCH();
  96.    } else {
  97.       BEGIN_BATCH(5);
  98.       OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 |
  99.                 GEN6_CONSTANT_BUFFER_0_ENABLE |
  100.                 (5 - 2));
  101.       /* Pointer to the WM constant buffer.  Covered by the set of
  102.        * state flags from gen6_upload_wm_push_constants.
  103.        */
  104.       OUT_BATCH(stage_state->push_const_offset +
  105.                 stage_state->push_const_size - 1);
  106.       OUT_BATCH(0);
  107.       OUT_BATCH(0);
  108.       OUT_BATCH(0);
  109.       ADVANCE_BATCH();
  110.    }
  111.  
  112.    dw2 = dw4 = dw5 = dw6 = ksp2 = 0;
  113.  
  114.    if (statistic_enable)
  115.       dw4 |= GEN6_WM_STATISTICS_ENABLE;
  116.  
  117.    dw5 |= GEN6_WM_LINE_AA_WIDTH_1_0;
  118.    dw5 |= GEN6_WM_LINE_END_CAP_AA_WIDTH_0_5;
  119.  
  120.    if (prog_data->base.use_alt_mode)
  121.       dw2 |= GEN6_WM_FLOATING_POINT_MODE_ALT;
  122.  
  123.    dw2 |= (ALIGN(stage_state->sampler_count, 4) / 4) <<
  124.            GEN6_WM_SAMPLER_COUNT_SHIFT;
  125.  
  126.    dw2 |= ((prog_data->base.binding_table.size_bytes / 4) <<
  127.            GEN6_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT);
  128.  
  129.    dw5 |= (brw->max_wm_threads - 1) << GEN6_WM_MAX_THREADS_SHIFT;
  130.  
  131.    assert(min_inv_per_frag >= 1);
  132.  
  133.    if (prog_data->prog_offset_16 || prog_data->no_8) {
  134.       dw5 |= GEN6_WM_16_DISPATCH_ENABLE;
  135.  
  136.       if (!prog_data->no_8 && min_inv_per_frag == 1) {
  137.          dw5 |= GEN6_WM_8_DISPATCH_ENABLE;
  138.          dw4 |= (prog_data->base.dispatch_grf_start_reg <<
  139.                  GEN6_WM_DISPATCH_START_GRF_SHIFT_0);
  140.          dw4 |= (prog_data->dispatch_grf_start_reg_16 <<
  141.                  GEN6_WM_DISPATCH_START_GRF_SHIFT_2);
  142.          ksp0 = stage_state->prog_offset;
  143.          ksp2 = stage_state->prog_offset + prog_data->prog_offset_16;
  144.       } else {
  145.          dw4 |= (prog_data->dispatch_grf_start_reg_16 <<
  146.                 GEN6_WM_DISPATCH_START_GRF_SHIFT_0);
  147.          ksp0 = stage_state->prog_offset + prog_data->prog_offset_16;
  148.       }
  149.    }
  150.    else {
  151.       dw5 |= GEN6_WM_8_DISPATCH_ENABLE;
  152.       dw4 |= (prog_data->base.dispatch_grf_start_reg <<
  153.               GEN6_WM_DISPATCH_START_GRF_SHIFT_0);
  154.       ksp0 = stage_state->prog_offset;
  155.    }
  156.  
  157.    if (dual_source_blend_enable)
  158.       dw5 |= GEN6_WM_DUAL_SOURCE_BLEND_ENABLE;
  159.  
  160.    if (line_stipple_enable)
  161.       dw5 |= GEN6_WM_LINE_STIPPLE_ENABLE;
  162.  
  163.    if (polygon_stipple_enable)
  164.       dw5 |= GEN6_WM_POLYGON_STIPPLE_ENABLE;
  165.  
  166.    /* BRW_NEW_FRAGMENT_PROGRAM */
  167.    if (fp->program.Base.InputsRead & VARYING_BIT_POS)
  168.       dw5 |= GEN6_WM_USES_SOURCE_DEPTH | GEN6_WM_USES_SOURCE_W;
  169.    if (fp->program.Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH))
  170.       dw5 |= GEN6_WM_COMPUTED_DEPTH;
  171.    dw6 |= prog_data->barycentric_interp_modes <<
  172.       GEN6_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT;
  173.  
  174.    if (kill_enable)
  175.       dw5 |= GEN6_WM_KILL_ENABLE;
  176.  
  177.    if (color_buffer_write_enable ||
  178.        dw5 & (GEN6_WM_KILL_ENABLE | GEN6_WM_COMPUTED_DEPTH))
  179.       dw5 |= GEN6_WM_DISPATCH_ENABLE;
  180.  
  181.    /* From the SNB PRM, volume 2 part 1, page 278:
  182.     * "This bit is inserted in the PS payload header and made available to
  183.     * the DataPort (either via the message header or via header bypass) to
  184.     * indicate that oMask data (one or two phases) is included in Render
  185.     * Target Write messages. If present, the oMask data is used to mask off
  186.     * samples."
  187.     */
  188.     if (prog_data->uses_omask)
  189.       dw5 |= GEN6_WM_OMASK_TO_RENDER_TARGET;
  190.  
  191.    dw6 |= prog_data->num_varying_inputs <<
  192.       GEN6_WM_NUM_SF_OUTPUTS_SHIFT;
  193.    if (multisampled_fbo) {
  194.       if (msaa_enabled)
  195.          dw6 |= GEN6_WM_MSRAST_ON_PATTERN;
  196.       else
  197.          dw6 |= GEN6_WM_MSRAST_OFF_PIXEL;
  198.  
  199.       if (min_inv_per_frag > 1)
  200.          dw6 |= GEN6_WM_MSDISPMODE_PERSAMPLE;
  201.       else {
  202.          dw6 |= GEN6_WM_MSDISPMODE_PERPIXEL;
  203.  
  204.          /* From the Sandy Bridge PRM, Vol 2 part 1, 7.7.1 ("Pixel Grouping
  205.           * (Dispatch Size) Control"), p.334:
  206.           *
  207.           *     Note: in the table below, the Valid column indicates which
  208.           *     products that combination is supported on. Combinations of
  209.           *     dispatch enables not listed in the table are not available on
  210.           *     any product.
  211.           *
  212.           *     A: Valid on all products
  213.           *
  214.           *     B: Not valid on [DevSNB] if 4x PERPIXEL mode with pixel shader
  215.           *     computed depth.
  216.           *
  217.           *     D: Valid on all products, except when in non-1x PERSAMPLE mode
  218.           *     (applies to [DevSNB+] only). Not valid on [DevSNB] if 4x
  219.           *     PERPIXEL mode with pixel shader computed depth.
  220.           *
  221.           *     E: Not valid on [DevSNB] if 4x PERPIXEL mode with pixel shader
  222.           *     computed depth.
  223.           *
  224.           *     F: Valid on all products, except not valid on [DevSNB] if 4x
  225.           *     PERPIXEL mode with pixel shader computed depth.
  226.           *
  227.           * In the table that follows, the only entry with "A" in the Valid
  228.           * column is the entry where only 8 pixel dispatch is enabled.
  229.           * Therefore, when we are in PERPIXEL mode with pixel shader computed
  230.           * depth, we need to disable SIMD16 dispatch.
  231.           */
  232.          if (dw5 & GEN6_WM_COMPUTED_DEPTH)
  233.             dw5 &= ~GEN6_WM_16_DISPATCH_ENABLE;
  234.       }
  235.    } else {
  236.       dw6 |= GEN6_WM_MSRAST_OFF_PIXEL;
  237.       dw6 |= GEN6_WM_MSDISPMODE_PERSAMPLE;
  238.    }
  239.  
  240.    /* From the SNB PRM, volume 2 part 1, page 281:
  241.     * "If the PS kernel does not need the Position XY Offsets
  242.     * to compute a Position XY value, then this field should be
  243.     * programmed to POSOFFSET_NONE."
  244.     *
  245.     * "SW Recommendation: If the PS kernel needs the Position Offsets
  246.     * to compute a Position XY value, this field should match Position
  247.     * ZW Interpolation Mode to ensure a consistent position.xyzw
  248.     * computation."
  249.     * We only require XY sample offsets. So, this recommendation doesn't
  250.     * look useful at the moment. We might need this in future.
  251.     */
  252.    if (prog_data->uses_pos_offset)
  253.       dw6 |= GEN6_WM_POSOFFSET_SAMPLE;
  254.    else
  255.       dw6 |= GEN6_WM_POSOFFSET_NONE;
  256.  
  257.    BEGIN_BATCH(9);
  258.    OUT_BATCH(_3DSTATE_WM << 16 | (9 - 2));
  259.    OUT_BATCH(ksp0);
  260.    OUT_BATCH(dw2);
  261.    if (prog_data->base.total_scratch) {
  262.       OUT_RELOC(stage_state->scratch_bo,
  263.                 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
  264.                 ffs(prog_data->base.total_scratch) - 11);
  265.    } else {
  266.       OUT_BATCH(0);
  267.    }
  268.    OUT_BATCH(dw4);
  269.    OUT_BATCH(dw5);
  270.    OUT_BATCH(dw6);
  271.    OUT_BATCH(0); /* kernel 1 pointer */
  272.    OUT_BATCH(ksp2);
  273.    ADVANCE_BATCH();
  274. }
  275.  
  276. static void
  277. upload_wm_state(struct brw_context *brw)
  278. {
  279.    struct gl_context *ctx = &brw->ctx;
  280.    /* BRW_NEW_FRAGMENT_PROGRAM */
  281.    const struct brw_fragment_program *fp =
  282.       brw_fragment_program_const(brw->fragment_program);
  283.    /* BRW_NEW_FS_PROG_DATA */
  284.    const struct brw_wm_prog_data *prog_data = brw->wm.prog_data;
  285.  
  286.    /* _NEW_BUFFERS */
  287.    const bool multisampled_fbo = ctx->DrawBuffer->Visual.samples > 1;
  288.  
  289.    /* In case of non 1x per sample shading, only one of SIMD8 and SIMD16
  290.     * should be enabled. We do 'SIMD16 only' dispatch if a SIMD16 shader
  291.     * is successfully compiled. In majority of the cases that bring us
  292.     * better performance than 'SIMD8 only' dispatch.
  293.     */
  294.    const int min_inv_per_frag = _mesa_get_min_invocations_per_fragment(
  295.                                    ctx, brw->fragment_program, false);
  296.  
  297.    /* BRW_NEW_FS_PROG_DATA | _NEW_COLOR */
  298.    const bool dual_src_blend_enable = prog_data->dual_src_blend &&
  299.                                       (ctx->Color.BlendEnabled & 1) &&
  300.                                       ctx->Color.Blend[0]._UsesDualSrc;
  301.  
  302.    /* _NEW_COLOR, _NEW_MULTISAMPLE */
  303.    const bool kill_enable = prog_data->uses_kill || ctx->Color.AlphaEnabled ||
  304.                             ctx->Multisample.SampleAlphaToCoverage ||
  305.                             prog_data->uses_omask;
  306.  
  307.    /* Rendering against the gl-context is always taken into account. */
  308.    const bool statistic_enable = true;
  309.  
  310.    /* _NEW_LINE | _NEW_POLYGON | _NEW_BUFFERS | _NEW_COLOR |
  311.     * _NEW_MULTISAMPLE
  312.     */
  313.    gen6_upload_wm_state(brw, fp, prog_data, &brw->wm.base,
  314.                         multisampled_fbo, min_inv_per_frag,
  315.                         dual_src_blend_enable, kill_enable,
  316.                         brw_color_buffer_write_enabled(brw),
  317.                         ctx->Multisample.Enabled,
  318.                         ctx->Line.StippleFlag, ctx->Polygon.StippleFlag,
  319.                         statistic_enable);
  320. }
  321.  
  322. const struct brw_tracked_state gen6_wm_state = {
  323.    .dirty = {
  324.       .mesa  = _NEW_BUFFERS |
  325.                _NEW_COLOR |
  326.                _NEW_LINE |
  327.                _NEW_MULTISAMPLE |
  328.                _NEW_POLYGON |
  329.                _NEW_PROGRAM_CONSTANTS,
  330.       .brw   = BRW_NEW_BATCH |
  331.                BRW_NEW_FRAGMENT_PROGRAM |
  332.                BRW_NEW_FS_PROG_DATA |
  333.                BRW_NEW_PUSH_CONSTANT_ALLOCATION,
  334.    },
  335.    .emit = upload_wm_state,
  336. };
  337.