Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 2014 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.  
  25. #include "main/context.h"
  26. #include "main/blend.h"
  27. #include "main/mtypes.h"
  28. #include "main/samplerobj.h"
  29. #include "main/texformat.h"
  30. #include "program/prog_parameter.h"
  31.  
  32. #include "intel_mipmap_tree.h"
  33. #include "intel_batchbuffer.h"
  34. #include "intel_tex.h"
  35. #include "intel_fbo.h"
  36. #include "intel_buffer_objects.h"
  37.  
  38. #include "brw_context.h"
  39. #include "brw_state.h"
  40. #include "brw_defines.h"
  41. #include "brw_wm.h"
  42.  
  43. /**
  44.  * Sets up a surface state structure to point at the given region.
  45.  * While it is only used for the front/back buffer currently, it should be
  46.  * usable for further buffers when doing ARB_draw_buffer support.
  47.  */
  48. static uint32_t
  49. gen6_update_renderbuffer_surface(struct brw_context *brw,
  50.                                  struct gl_renderbuffer *rb,
  51.                                  bool layered, unsigned unit /* unused */,
  52.                                  uint32_t surf_index)
  53. {
  54.    struct gl_context *ctx = &brw->ctx;
  55.    struct intel_renderbuffer *irb = intel_renderbuffer(rb);
  56.    struct intel_mipmap_tree *mt = irb->mt;
  57.    uint32_t *surf;
  58.    uint32_t format = 0;
  59.    uint32_t offset;
  60.    /* _NEW_BUFFERS */
  61.    mesa_format rb_format = _mesa_get_render_format(ctx, intel_rb_format(irb));
  62.    uint32_t surftype;
  63.    int depth = MAX2(irb->layer_count, 1);
  64.    const GLenum gl_target =
  65.       rb->TexImage ? rb->TexImage->TexObject->Target : GL_TEXTURE_2D;
  66.  
  67.    intel_miptree_used_for_rendering(irb->mt);
  68.  
  69.    surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE, 6 * 4, 32, &offset);
  70.  
  71.    format = brw->render_target_format[rb_format];
  72.    if (unlikely(!brw->format_supported_as_render_target[rb_format])) {
  73.       _mesa_problem(ctx, "%s: renderbuffer format %s unsupported\n",
  74.                     __func__, _mesa_get_format_name(rb_format));
  75.    }
  76.  
  77.    switch (gl_target) {
  78.    case GL_TEXTURE_CUBE_MAP_ARRAY:
  79.    case GL_TEXTURE_CUBE_MAP:
  80.       surftype = BRW_SURFACE_2D;
  81.       depth *= 6;
  82.       break;
  83.    case GL_TEXTURE_3D:
  84.       depth = MAX2(irb->mt->logical_depth0, 1);
  85.       /* fallthrough */
  86.    default:
  87.       surftype = translate_tex_target(gl_target);
  88.       break;
  89.    }
  90.  
  91.    const int min_array_element = layered ? 0 : irb->mt_layer;
  92.  
  93.    surf[0] = SET_FIELD(surftype, BRW_SURFACE_TYPE) |
  94.              SET_FIELD(format, BRW_SURFACE_FORMAT);
  95.  
  96.    /* reloc */
  97.    assert(mt->offset % mt->cpp == 0);
  98.    surf[1] = mt->bo->offset64 + mt->offset;
  99.  
  100.    /* In the gen6 PRM Volume 1 Part 1: Graphics Core, Section 7.18.3.7.1
  101.     * (Surface Arrays For all surfaces other than separate stencil buffer):
  102.     *
  103.     * "[DevSNB] Errata: Sampler MSAA Qpitch will be 4 greater than the value
  104.     *  calculated in the equation above , for every other odd Surface Height
  105.     *  starting from 1 i.e. 1,5,9,13"
  106.     *
  107.     * Since this Qpitch errata only impacts the sampler, we have to adjust the
  108.     * input for the rendering surface to achieve the same qpitch. For the
  109.     * affected heights, we increment the height by 1 for the rendering
  110.     * surface.
  111.     */
  112.    int height0 = irb->mt->logical_height0;
  113.    if (brw->gen == 6 && irb->mt->num_samples > 1 && (height0 % 4) == 1)
  114.       height0++;
  115.  
  116.    surf[2] = SET_FIELD(mt->logical_width0 - 1, BRW_SURFACE_WIDTH) |
  117.              SET_FIELD(height0 - 1, BRW_SURFACE_HEIGHT) |
  118.              SET_FIELD(irb->mt_level - irb->mt->first_level, BRW_SURFACE_LOD);
  119.  
  120.    surf[3] = brw_get_surface_tiling_bits(mt->tiling) |
  121.              SET_FIELD(depth - 1, BRW_SURFACE_DEPTH) |
  122.              SET_FIELD(mt->pitch - 1, BRW_SURFACE_PITCH);
  123.  
  124.    surf[4] = brw_get_surface_num_multisamples(mt->num_samples) |
  125.              SET_FIELD(min_array_element, BRW_SURFACE_MIN_ARRAY_ELEMENT) |
  126.              SET_FIELD(depth - 1, BRW_SURFACE_RENDER_TARGET_VIEW_EXTENT);
  127.  
  128.    surf[5] = (mt->align_h == 4 ? BRW_SURFACE_VERTICAL_ALIGN_ENABLE : 0);
  129.  
  130.    drm_intel_bo_emit_reloc(brw->batch.bo,
  131.                            offset + 4,
  132.                            mt->bo,
  133.                            surf[1] - mt->bo->offset64,
  134.                            I915_GEM_DOMAIN_RENDER,
  135.                            I915_GEM_DOMAIN_RENDER);
  136.  
  137.    return offset;
  138. }
  139.  
  140. void
  141. gen6_init_vtable_surface_functions(struct brw_context *brw)
  142. {
  143.    gen4_init_vtable_surface_functions(brw);
  144.    brw->vtbl.update_renderbuffer_surface = gen6_update_renderbuffer_surface;
  145. }
  146.