Subversion Repositories Kolibri OS

Rev

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

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