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_RESOURCE_H
  29. #define ILO_RESOURCE_H
  30.  
  31. #include "core/intel_winsys.h"
  32. #include "core/ilo_buffer.h"
  33. #include "core/ilo_image.h"
  34.  
  35. #include "ilo_common.h"
  36. #include "ilo_screen.h"
  37.  
  38. enum ilo_texture_flags {
  39.    /*
  40.     * Possible writers of a texture.  There can be at most one writer at any
  41.     * time.
  42.     *
  43.     * Wine set in resolve flags (in ilo_blit_resolve_slices()), they indicate
  44.     * the new writer.  When set in slice flags (ilo_texture_slice::flags),
  45.     * they indicate the writer since last resolve.
  46.     */
  47.    ILO_TEXTURE_RENDER_WRITE   = 1 << 0,
  48.    ILO_TEXTURE_BLT_WRITE      = 1 << 1,
  49.    ILO_TEXTURE_CPU_WRITE      = 1 << 2,
  50.  
  51.    /*
  52.     * Possible readers of a texture.  There may be multiple readers at any
  53.     * time.
  54.     *
  55.     * When set in resolve flags, they indicate the new readers.  They are
  56.     * never set in slice flags.
  57.     */
  58.    ILO_TEXTURE_RENDER_READ    = 1 << 3,
  59.    ILO_TEXTURE_BLT_READ       = 1 << 4,
  60.    ILO_TEXTURE_CPU_READ       = 1 << 5,
  61.  
  62.    /*
  63.     * Set when the texture is cleared.
  64.     *
  65.     * When set in resolve flags, the new writer will clear.  When set in slice
  66.     * flags, the slice has been cleared to ilo_texture_slice::clear_value.
  67.     */
  68.    ILO_TEXTURE_CLEAR          = 1 << 6,
  69. };
  70.  
  71. /**
  72.  * A 3D image slice, cube face, or array layer.
  73.  */
  74. struct ilo_texture_slice {
  75.    unsigned flags;
  76.  
  77.    /*
  78.     * Slice clear value.  It is served for two purposes
  79.     *
  80.     *  - the clear value used in commands such as 3DSTATE_CLEAR_PARAMS
  81.     *  - the clear value when ILO_TEXTURE_CLEAR is set
  82.     *
  83.     * Since commands such as 3DSTATE_CLEAR_PARAMS expect a single clear value
  84.     * for all slices, ilo_blit_resolve_slices() will silently make all slices
  85.     * to have the same clear value.
  86.     */
  87.    uint32_t clear_value;
  88. };
  89.  
  90. struct ilo_texture {
  91.    struct pipe_resource base;
  92.  
  93.    bool imported;
  94.  
  95.    struct ilo_image image;
  96.  
  97.    /* XXX thread-safety */
  98.    struct ilo_texture_slice *slices[PIPE_MAX_TEXTURE_LEVELS];
  99.  
  100.    struct ilo_texture *separate_s8;
  101. };
  102.  
  103. struct ilo_buffer_resource {
  104.    struct pipe_resource base;
  105.  
  106.    struct ilo_buffer buffer;
  107. };
  108.  
  109. static inline struct ilo_buffer *
  110. ilo_buffer(struct pipe_resource *res)
  111. {
  112.    return (res && res->target == PIPE_BUFFER) ?
  113.       &((struct ilo_buffer_resource *) res)->buffer : NULL;
  114. }
  115.  
  116. static inline struct ilo_texture *
  117. ilo_texture(struct pipe_resource *res)
  118. {
  119.    return (struct ilo_texture *)
  120.       ((res && res->target != PIPE_BUFFER) ? res : NULL);
  121. }
  122.  
  123. void
  124. ilo_init_resource_functions(struct ilo_screen *is);
  125.  
  126. bool
  127. ilo_resource_rename_bo(struct pipe_resource *res);
  128.  
  129. /**
  130.  * Return the bo of the resource.
  131.  */
  132. static inline struct intel_bo *
  133. ilo_resource_get_bo(struct pipe_resource *res)
  134. {
  135.    return (res->target == PIPE_BUFFER) ?
  136.       ilo_buffer(res)->bo : ilo_texture(res)->image.bo;
  137. }
  138.  
  139. static inline struct ilo_texture_slice *
  140. ilo_texture_get_slice(const struct ilo_texture *tex,
  141.                       unsigned level, unsigned slice)
  142. {
  143.    assert(level <= tex->base.last_level);
  144.    assert(slice < ((tex->base.target == PIPE_TEXTURE_3D) ?
  145.          u_minify(tex->base.depth0, level) : tex->base.array_size));
  146.  
  147.    return &tex->slices[level][slice];
  148. }
  149.  
  150. static inline void
  151. ilo_texture_set_slice_flags(struct ilo_texture *tex, unsigned level,
  152.                             unsigned first_slice, unsigned num_slices,
  153.                             unsigned mask, unsigned value)
  154. {
  155.    const struct ilo_texture_slice *last =
  156.       ilo_texture_get_slice(tex, level, first_slice + num_slices - 1);
  157.    struct ilo_texture_slice *slice =
  158.       ilo_texture_get_slice(tex, level, first_slice);
  159.  
  160.    while (slice <= last) {
  161.       slice->flags = (slice->flags & ~mask) | (value & mask);
  162.       slice++;
  163.    }
  164. }
  165.  
  166. static inline void
  167. ilo_texture_set_slice_clear_value(struct ilo_texture *tex, unsigned level,
  168.                                   unsigned first_slice, unsigned num_slices,
  169.                                   uint32_t clear_value)
  170. {
  171.    const struct ilo_texture_slice *last =
  172.       ilo_texture_get_slice(tex, level, first_slice + num_slices - 1);
  173.    struct ilo_texture_slice *slice =
  174.       ilo_texture_get_slice(tex, level, first_slice);
  175.  
  176.    while (slice <= last) {
  177.       slice->clear_value = clear_value;
  178.       slice++;
  179.    }
  180. }
  181.  
  182. #endif /* ILO_RESOURCE_H */
  183.