Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

etnaviv_resource.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (c) 2012-2015 Etnaviv Project
  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, sub license,
  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
  12. * next paragraph) shall be included in all copies or substantial portions
  13. * of the 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 NON-INFRINGEMENT. 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
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Wladimir J. van der Laan <laanwj@gmail.com>
  25. */
  26. #ifndef H_ETNAVIV_RESOURCE
  27. #define H_ETNAVIV_RESOURCE
  28. #include "etnaviv_internal.h"
  29. #include "etnaviv_tiling.h"
  30. #include "pipe/p_state.h"
  31. #include "util/list.h"
  32. #include "util/set.h"
  33. #include "util/u_helpers.h"
  34. struct etna_context;
  35. struct pipe_screen;
  36. struct util_dynarray;
  37. struct etna_resource_level {
  38. unsigned width, padded_width; /* in pixels */
  39. unsigned height, padded_height; /* in samples */
  40. unsigned depth;
  41. unsigned offset; /* offset into memory area */
  42. uint32_t stride; /* row stride */
  43. uint32_t layer_stride; /* layer stride */
  44. unsigned size; /* total size of memory area */
  45. uint32_t ts_offset;
  46. uint32_t ts_layer_stride;
  47. uint32_t ts_size;
  48. uint32_t clear_value; /* clear value of resource level (mainly for TS) */
  49. bool ts_valid;
  50. uint8_t ts_mode;
  51. int8_t ts_compress_fmt; /* COLOR_COMPRESSION_FORMAT_* (-1 = disable) */
  52. /* keep track if we have done some per block patching */
  53. bool patched;
  54. struct util_dynarray *patch_offsets;
  55. };
  56. /* status of queued up but not flushed reads and write operations.
  57. * In _transfer_map() we need to know if queued up rendering needs
  58. * to be flushed to preserve the order of cpu and gpu access. */
  59. enum etna_resource_status {
  60. ETNA_PENDING_WRITE = 0x01,
  61. ETNA_PENDING_READ = 0x02,
  62. };
  63. struct etna_resource {
  64. struct pipe_resource base;
  65. struct renderonly_scanout *scanout;
  66. uint32_t seqno;
  67. uint32_t flush_seqno;
  68. /* only lod 0 used for non-texture buffers */
  69. /* Layout for surface (tiled, multitiled, split tiled, ...) */
  70. enum etna_surface_layout layout;
  71. /* Horizontal alignment for texture unit (TEXTURE_HALIGN_*) */
  72. unsigned halign;
  73. struct etna_bo *bo; /* Surface video memory */
  74. struct etna_bo *ts_bo; /* Tile status video memory */
  75. struct etna_resource_level levels[ETNA_NUM_LOD];
  76. /* for when TE doesn't support the base layout */
  77. struct pipe_resource *texture;
  78. /* for when PE doesn't support the base layout */
  79. struct pipe_resource *render;
  80. enum etna_resource_status status;
  81. struct set *pending_ctx;
  82. };
  83. /* returns TRUE if a is newer than b */
  84. static inline bool
  85. etna_resource_newer(struct etna_resource *a, struct etna_resource *b)
  86. {
  87. return (int)(a->seqno - b->seqno) > 0;
  88. }
  89. /* returns TRUE if a is older than b */
  90. static inline bool
  91. etna_resource_older(struct etna_resource *a, struct etna_resource *b)
  92. {
  93. return (int)(a->seqno - b->seqno) < 0;
  94. }
  95. /* returns TRUE if a resource has a TS, and it is valid for at least one level */
  96. bool
  97. etna_resource_has_valid_ts(struct etna_resource *res);
  98. /* returns TRUE if the resource needs a resolve to itself */
  99. static inline bool
  100. etna_resource_needs_flush(struct etna_resource *res)
  101. {
  102. return etna_resource_has_valid_ts(res) && ((int)(res->seqno - res->flush_seqno) > 0);
  103. }
  104. /* is the resource only used on the sampler? */
  105. static inline bool
  106. etna_resource_sampler_only(const struct pipe_resource *pres)
  107. {
  108. return (pres->bind & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET |
  109. PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_BLENDABLE)) ==
  110. PIPE_BIND_SAMPLER_VIEW;
  111. }
  112. static inline struct etna_resource *
  113. etna_resource(struct pipe_resource *p)
  114. {
  115. return (struct etna_resource *)p;
  116. }
  117. enum etna_resource_status
  118. etna_resource_get_status(struct etna_context *ctx, struct etna_resource *rsc);
  119. void
  120. etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc,
  121. enum etna_resource_status status);
  122. static inline void
  123. resource_read(struct etna_context *ctx, struct pipe_resource *prsc)
  124. {
  125. etna_resource_used(ctx, prsc, ETNA_PENDING_READ);
  126. }
  127. static inline void
  128. resource_written(struct etna_context *ctx, struct pipe_resource *prsc)
  129. {
  130. etna_resource_used(ctx, prsc, ETNA_PENDING_WRITE);
  131. }
  132. /* Allocate Tile Status for an etna resource.
  133. * Tile status is a cache of the clear status per tile. This means a smaller
  134. * surface has to be cleared which is faster.
  135. * This is also called "fast clear". */
  136. bool
  137. etna_screen_resource_alloc_ts(struct pipe_screen *pscreen,
  138. struct etna_resource *prsc);
  139. struct pipe_resource *
  140. etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout,
  141. uint64_t modifier, const struct pipe_resource *templat);
  142. void
  143. etna_resource_screen_init(struct pipe_screen *pscreen);
  144. #endif