Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Mesa 3-D graphics library
  3.  *
  4.  * Copyright (C) 2012-2013 LunarG, Inc.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included
  14.  * in all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Chia-I Wu <olv@lunarg.com>
  26.  */
  27.  
  28. #ifndef ILO_BUFFER_H
  29. #define ILO_BUFFER_H
  30.  
  31. #include "intel_winsys.h"
  32.  
  33. #include "ilo_core.h"
  34. #include "ilo_dev.h"
  35.  
  36. struct ilo_buffer {
  37.    unsigned bo_size;
  38.  
  39.    struct intel_bo *bo;
  40. };
  41.  
  42. static inline void
  43. ilo_buffer_init(struct ilo_buffer *buf, const struct ilo_dev *dev,
  44.                 unsigned size, uint32_t bind, uint32_t flags)
  45. {
  46.    buf->bo_size = size;
  47.  
  48.    /*
  49.     * From the Sandy Bridge PRM, volume 1 part 1, page 118:
  50.     *
  51.     *     "For buffers, which have no inherent "height," padding requirements
  52.     *      are different. A buffer must be padded to the next multiple of 256
  53.     *      array elements, with an additional 16 bytes added beyond that to
  54.     *      account for the L1 cache line."
  55.     */
  56.    if (bind & PIPE_BIND_SAMPLER_VIEW)
  57.       buf->bo_size = align(buf->bo_size, 256) + 16;
  58.  
  59.    if ((bind & PIPE_BIND_VERTEX_BUFFER) && ilo_dev_gen(dev) < ILO_GEN(7.5)) {
  60.       /*
  61.        * As noted in ilo_format_translate(), we treat some 3-component formats
  62.        * as 4-component formats to work around hardware limitations.  Imagine
  63.        * the case where the vertex buffer holds a single
  64.        * PIPE_FORMAT_R16G16B16_FLOAT vertex, and buf->bo_size is 6.  The
  65.        * hardware would fail to fetch it at boundary check because the vertex
  66.        * buffer is expected to hold a PIPE_FORMAT_R16G16B16A16_FLOAT vertex
  67.        * and that takes at least 8 bytes.
  68.        *
  69.        * For the workaround to work, we should add 2 to the bo size.  But that
  70.        * would waste a page when the bo size is already page aligned.  Let's
  71.        * round it to page size for now and revisit this when needed.
  72.        */
  73.       buf->bo_size = align(buf->bo_size, 4096);
  74.    }
  75. }
  76.  
  77. static inline void
  78. ilo_buffer_cleanup(struct ilo_buffer *buf)
  79. {
  80.    intel_bo_unref(buf->bo);
  81. }
  82.  
  83. static inline void
  84. ilo_buffer_set_bo(struct ilo_buffer *buf, struct intel_bo *bo)
  85. {
  86.    intel_bo_unref(buf->bo);
  87.    buf->bo = intel_bo_ref(bo);
  88. }
  89.  
  90. #endif /* ILO_BUFFER_H */
  91.