Subversion Repositories Kolibri OS

Rev

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

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. #ifndef INTEL_MIPMAP_TREE_H
  29. #define INTEL_MIPMAP_TREE_H
  30.  
  31. #include <assert.h>
  32.  
  33. #include "intel_regions.h"
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. /* A layer on top of the intel_regions code which adds:
  40.  *
  41.  * - Code to size and layout a region to hold a set of mipmaps.
  42.  * - Query to determine if a new image fits in an existing tree.
  43.  * - More refcounting
  44.  *     - maybe able to remove refcounting from intel_region?
  45.  * - ?
  46.  *
  47.  * The fixed mipmap layout of intel hardware where one offset
  48.  * specifies the position of all images in a mipmap hierachy
  49.  * complicates the implementation of GL texture image commands,
  50.  * compared to hardware where each image is specified with an
  51.  * independent offset.
  52.  *
  53.  * In an ideal world, each texture object would be associated with a
  54.  * single bufmgr buffer or 2d intel_region, and all the images within
  55.  * the texture object would slot into the tree as they arrive.  The
  56.  * reality can be a little messier, as images can arrive from the user
  57.  * with sizes that don't fit in the existing tree, or in an order
  58.  * where the tree layout cannot be guessed immediately.  
  59.  *
  60.  * This structure encodes an idealized mipmap tree.  The GL image
  61.  * commands build these where possible, otherwise store the images in
  62.  * temporary system buffers.
  63.  */
  64.  
  65. struct intel_texture_image;
  66.  
  67. struct intel_miptree_map {
  68.    /** Bitfield of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT, GL_MAP_INVALIDATE_BIT */
  69.    GLbitfield mode;
  70.    /** Region of interest for the map. */
  71.    int x, y, w, h;
  72.    /** Possibly malloced temporary buffer for the mapping. */
  73.    void *buffer;
  74.    /** Possible pointer to a temporary linear miptree for the mapping. */
  75.    struct intel_mipmap_tree *mt;
  76.    /** Pointer to the start of (map_x, map_y) returned by the mapping. */
  77.    void *ptr;
  78.    /** Stride of the mapping. */
  79.    int stride;
  80. };
  81.  
  82. /**
  83.  * Describes the location of each texture image within a texture region.
  84.  */
  85. struct intel_mipmap_level
  86. {
  87.    /** Offset to this miptree level, used in computing x_offset. */
  88.    GLuint level_x;
  89.    /** Offset to this miptree level, used in computing y_offset. */
  90.    GLuint level_y;
  91.    GLuint width;
  92.    GLuint height;
  93.  
  94.    /**
  95.     * \brief Number of 2D slices in this miplevel.
  96.     *
  97.     * The exact semantics of depth varies according to the texture target:
  98.     *    - For GL_TEXTURE_CUBE_MAP, depth is 6.
  99.     *    - For GL_TEXTURE_2D_ARRAY, depth is the number of array slices. It is
  100.     *      identical for all miplevels in the texture.
  101.     *    - For GL_TEXTURE_3D, it is the texture's depth at this miplevel. Its
  102.     *      value, like width and height, varies with miplevel.
  103.     *    - For other texture types, depth is 1.
  104.     */
  105.    GLuint depth;
  106.  
  107.    /**
  108.     * \brief List of 2D images in this mipmap level.
  109.     *
  110.     * This may be a list of cube faces, array slices in 2D array texture, or
  111.     * layers in a 3D texture. The list's length is \c depth.
  112.     */
  113.    struct intel_mipmap_slice {
  114.       /**
  115.        * \name Offset to slice
  116.        * \{
  117.        *
  118.        * Hardware formats are so diverse that that there is no unified way to
  119.        * compute the slice offsets, so we store them in this table.
  120.        *
  121.        * The (x, y) offset to slice \c s at level \c l relative the miptrees
  122.        * base address is
  123.        * \code
  124.        *     x = mt->level[l].slice[s].x_offset
  125.        *     y = mt->level[l].slice[s].y_offset
  126.        */
  127.       GLuint x_offset;
  128.       GLuint y_offset;
  129.       /** \} */
  130.  
  131.       /**
  132.        * Mapping information. Persistent for the duration of
  133.        * intel_miptree_map/unmap on this slice.
  134.        */
  135.       struct intel_miptree_map *map;
  136.    } *slice;
  137. };
  138.  
  139.  
  140. struct intel_mipmap_tree
  141. {
  142.    /* Effectively the key:
  143.     */
  144.    GLenum target;
  145.  
  146.    /**
  147.     * This is just the same as the gl_texture_image->TexFormat or
  148.     * gl_renderbuffer->Format.
  149.     */
  150.    gl_format format;
  151.  
  152.    /**
  153.     * The X offset of each image in the miptree must be aligned to this. See
  154.     * the "Alignment Unit Size" section of the BSpec.
  155.     */
  156.    unsigned int align_w;
  157.    unsigned int align_h; /**< \see align_w */
  158.  
  159.    GLuint first_level;
  160.    GLuint last_level;
  161.  
  162.    /**
  163.     * Level zero image dimensions.  These dimensions correspond to the
  164.     * physical layout of data in memory.  Accordingly, they account for the
  165.     * extra width, height, and or depth that must be allocated in order to
  166.     * accommodate multisample formats, and they account for the extra factor
  167.     * of 6 in depth that must be allocated in order to accommodate cubemap
  168.     * textures.
  169.     */
  170.    GLuint physical_width0, physical_height0, physical_depth0;
  171.  
  172.    GLuint cpp;
  173.    bool compressed;
  174.  
  175.    /**
  176.     * Level zero image dimensions.  These dimensions correspond to the
  177.     * logical width, height, and depth of the region as seen by client code.
  178.     * Accordingly, they do not account for the extra width, height, and/or
  179.     * depth that must be allocated in order to accommodate multisample
  180.     * formats, nor do they account for the extra factor of 6 in depth that
  181.     * must be allocated in order to accommodate cubemap textures.
  182.     */
  183.    uint32_t logical_width0, logical_height0, logical_depth0;
  184.  
  185.    /**
  186.     * For 1D array, 2D array, cube, and 2D multisampled surfaces on Gen7: true
  187.     * if the surface only contains LOD 0, and hence no space is for LOD's
  188.     * other than 0 in between array slices.
  189.     *
  190.     * Corresponds to the surface_array_spacing bit in gen7_surface_state.
  191.     */
  192.    bool array_spacing_lod0;
  193.  
  194.    /* Derived from the above:
  195.     */
  196.    GLuint total_width;
  197.    GLuint total_height;
  198.  
  199.    /* Includes image offset tables:
  200.     */
  201.    struct intel_mipmap_level level[MAX_TEXTURE_LEVELS];
  202.  
  203.    /* The data is held here:
  204.     */
  205.    struct intel_region *region;
  206.  
  207.    /* Offset into region bo where miptree starts:
  208.     */
  209.    uint32_t offset;
  210.  
  211.    /* These are also refcounted:
  212.     */
  213.    GLuint refcount;
  214. };
  215.  
  216. enum intel_miptree_tiling_mode {
  217.    INTEL_MIPTREE_TILING_ANY,
  218.    INTEL_MIPTREE_TILING_Y,
  219.    INTEL_MIPTREE_TILING_NONE,
  220. };
  221.  
  222. struct intel_mipmap_tree *intel_miptree_create(struct intel_context *intel,
  223.                                                GLenum target,
  224.                                                gl_format format,
  225.                                                GLuint first_level,
  226.                                                GLuint last_level,
  227.                                                GLuint width0,
  228.                                                GLuint height0,
  229.                                                GLuint depth0,
  230.                                                bool expect_accelerated_upload,
  231.                                                enum intel_miptree_tiling_mode);
  232.  
  233. struct intel_mipmap_tree *
  234. intel_miptree_create_layout(struct intel_context *intel,
  235.                             GLenum target,
  236.                             gl_format format,
  237.                             GLuint first_level,
  238.                             GLuint last_level,
  239.                             GLuint width0,
  240.                             GLuint height0,
  241.                             GLuint depth0,
  242.                             bool for_bo);
  243.  
  244. struct intel_mipmap_tree *
  245. intel_miptree_create_for_bo(struct intel_context *intel,
  246.                             drm_intel_bo *bo,
  247.                             gl_format format,
  248.                             uint32_t offset,
  249.                             uint32_t width,
  250.                             uint32_t height,
  251.                             int pitch,
  252.                             uint32_t tiling);
  253.  
  254. struct intel_mipmap_tree*
  255. intel_miptree_create_for_dri2_buffer(struct intel_context *intel,
  256.                                      unsigned dri_attachment,
  257.                                      gl_format format,
  258.                                      struct intel_region *region);
  259.  
  260. /**
  261.  * Create a miptree appropriate as the storage for a non-texture renderbuffer.
  262.  * The miptree has the following properties:
  263.  *     - The target is GL_TEXTURE_2D.
  264.  *     - There are no levels other than the base level 0.
  265.  *     - Depth is 1.
  266.  */
  267. struct intel_mipmap_tree*
  268. intel_miptree_create_for_renderbuffer(struct intel_context *intel,
  269.                                       gl_format format,
  270.                                       uint32_t width,
  271.                                       uint32_t height);
  272.  
  273. /** \brief Assert that the level and layer are valid for the miptree. */
  274. static inline void
  275. intel_miptree_check_level_layer(struct intel_mipmap_tree *mt,
  276.                                 uint32_t level,
  277.                                 uint32_t layer)
  278. {
  279.    assert(level >= mt->first_level);
  280.    assert(level <= mt->last_level);
  281.    assert(layer < mt->level[level].depth);
  282. }
  283.  
  284. int intel_miptree_pitch_align (struct intel_context *intel,
  285.                                struct intel_mipmap_tree *mt,
  286.                                uint32_t tiling,
  287.                                int pitch);
  288.  
  289. void intel_miptree_reference(struct intel_mipmap_tree **dst,
  290.                              struct intel_mipmap_tree *src);
  291.  
  292. void intel_miptree_release(struct intel_mipmap_tree **mt);
  293.  
  294. /* Check if an image fits an existing mipmap tree layout
  295.  */
  296. bool intel_miptree_match_image(struct intel_mipmap_tree *mt,
  297.                                     struct gl_texture_image *image);
  298.  
  299. void
  300. intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
  301.                                GLuint level, GLuint slice,
  302.                                GLuint *x, GLuint *y);
  303.  
  304. void
  305. intel_miptree_get_dimensions_for_image(struct gl_texture_image *image,
  306.                                        int *width, int *height, int *depth);
  307.  
  308. uint32_t
  309. intel_miptree_get_tile_offsets(struct intel_mipmap_tree *mt,
  310.                                GLuint level, GLuint slice,
  311.                                uint32_t *tile_x,
  312.                                uint32_t *tile_y);
  313.  
  314. void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
  315.                                   GLuint level,
  316.                                   GLuint x, GLuint y,
  317.                                   GLuint w, GLuint h, GLuint d);
  318.  
  319. void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
  320.                                     GLuint level,
  321.                                     GLuint img, GLuint x, GLuint y);
  322.  
  323. void
  324. intel_miptree_copy_teximage(struct intel_context *intel,
  325.                             struct intel_texture_image *intelImage,
  326.                             struct intel_mipmap_tree *dst_mt, bool invalidate);
  327.  
  328. /**\}*/
  329.  
  330. /* i915_mipmap_tree.c:
  331.  */
  332. void i915_miptree_layout(struct intel_mipmap_tree *mt);
  333. void i945_miptree_layout(struct intel_mipmap_tree *mt);
  334. void brw_miptree_layout(struct intel_context *intel,
  335.                         struct intel_mipmap_tree *mt);
  336.  
  337. void *intel_miptree_map_raw(struct intel_context *intel,
  338.                             struct intel_mipmap_tree *mt);
  339.  
  340. void intel_miptree_unmap_raw(struct intel_context *intel,
  341.                              struct intel_mipmap_tree *mt);
  342.  
  343. void
  344. intel_miptree_map(struct intel_context *intel,
  345.                   struct intel_mipmap_tree *mt,
  346.                   unsigned int level,
  347.                   unsigned int slice,
  348.                   unsigned int x,
  349.                   unsigned int y,
  350.                   unsigned int w,
  351.                   unsigned int h,
  352.                   GLbitfield mode,
  353.                   void **out_ptr,
  354.                   int *out_stride);
  355.  
  356. void
  357. intel_miptree_unmap(struct intel_context *intel,
  358.                     struct intel_mipmap_tree *mt,
  359.                     unsigned int level,
  360.                     unsigned int slice);
  361.  
  362.  
  363. #ifdef __cplusplus
  364. }
  365. #endif
  366.  
  367. #endif
  368.