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.

freedreno_batch.h 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
  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, sublicense,
  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 next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * 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 NONINFRINGEMENT. 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 FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Authors:
  24. * Rob Clark <robclark@freedesktop.org>
  25. */
  26. #ifndef FREEDRENO_BATCH_H_
  27. #define FREEDRENO_BATCH_H_
  28. #include "util/u_inlines.h"
  29. #include "util/u_queue.h"
  30. #include "util/list.h"
  31. #include "freedreno_util.h"
  32. struct fd_context;
  33. struct fd_resource;
  34. enum fd_resource_status;
  35. /* Bitmask of stages in rendering that a particular query query is
  36. * active. Queries will be automatically started/stopped (generating
  37. * additional fd_hw_sample_period's) on entrance/exit from stages that
  38. * are applicable to the query.
  39. *
  40. * NOTE: set the stage to NULL at end of IB to ensure no query is still
  41. * active. Things aren't going to work out the way you want if a query
  42. * is active across IB's (or between tile IB and draw IB)
  43. */
  44. enum fd_render_stage {
  45. FD_STAGE_NULL = 0x01,
  46. FD_STAGE_DRAW = 0x02,
  47. FD_STAGE_CLEAR = 0x04,
  48. /* used for driver internal draws (ie. util_blitter_blit()): */
  49. FD_STAGE_BLIT = 0x08,
  50. FD_STAGE_ALL = 0xff,
  51. };
  52. #define MAX_HW_SAMPLE_PROVIDERS 5
  53. struct fd_hw_sample_provider;
  54. struct fd_hw_sample;
  55. /* A batch tracks everything about a cmdstream batch/submit, including the
  56. * ringbuffers used for binning, draw, and gmem cmds, list of associated
  57. * fd_resource-s, etc.
  58. */
  59. struct fd_batch {
  60. struct pipe_reference reference;
  61. unsigned seqno;
  62. unsigned idx; /* index into cache->batches[] */
  63. int in_fence_fd;
  64. bool needs_out_fence_fd;
  65. struct pipe_fence_handle *fence;
  66. struct fd_context *ctx;
  67. struct util_queue_fence flush_fence;
  68. /* do we need to mem2gmem before rendering. We don't, if for example,
  69. * there was a glClear() that invalidated the entire previous buffer
  70. * contents. Keep track of which buffer(s) are cleared, or needs
  71. * restore. Masks of PIPE_CLEAR_*
  72. *
  73. * The 'cleared' bits will be set for buffers which are *entirely*
  74. * cleared, and 'partial_cleared' bits will be set if you must
  75. * check cleared_scissor.
  76. */
  77. enum {
  78. /* align bitmask values w/ PIPE_CLEAR_*.. since that is convenient.. */
  79. FD_BUFFER_COLOR = PIPE_CLEAR_COLOR,
  80. FD_BUFFER_DEPTH = PIPE_CLEAR_DEPTH,
  81. FD_BUFFER_STENCIL = PIPE_CLEAR_STENCIL,
  82. FD_BUFFER_ALL = FD_BUFFER_COLOR | FD_BUFFER_DEPTH | FD_BUFFER_STENCIL,
  83. } cleared, partial_cleared, restore, resolve;
  84. bool needs_flush : 1;
  85. bool blit : 1;
  86. bool back_blit : 1; /* only blit so far is resource shadowing back-blit */
  87. /* Keep track if WAIT_FOR_IDLE is needed for registers we need
  88. * to update via RMW:
  89. */
  90. bool needs_wfi : 1;
  91. /* To decide whether to render to system memory, keep track of the
  92. * number of draws, and whether any of them require multisample,
  93. * depth_test (or depth write), stencil_test, blending, and
  94. * color_logic_Op (since those functions are disabled when by-
  95. * passing GMEM.
  96. */
  97. enum {
  98. FD_GMEM_CLEARS_DEPTH_STENCIL = 0x01,
  99. FD_GMEM_DEPTH_ENABLED = 0x02,
  100. FD_GMEM_STENCIL_ENABLED = 0x04,
  101. FD_GMEM_MSAA_ENABLED = 0x08,
  102. FD_GMEM_BLEND_ENABLED = 0x10,
  103. FD_GMEM_LOGICOP_ENABLED = 0x20,
  104. } gmem_reason;
  105. unsigned num_draws; /* number of draws in current batch */
  106. /* Track the maximal bounds of the scissor of all the draws within a
  107. * batch. Used at the tile rendering step (fd_gmem_render_tiles(),
  108. * mem2gmem/gmem2mem) to avoid needlessly moving data in/out of gmem.
  109. */
  110. struct pipe_scissor_state max_scissor;
  111. /* Track the cleared scissor for color/depth/stencil, so we know
  112. * which, if any, tiles need to be restored (mem2gmem). Only valid
  113. * if the corresponding bit in ctx->cleared is set.
  114. */
  115. struct {
  116. struct pipe_scissor_state color, depth, stencil;
  117. } cleared_scissor;
  118. /* Keep track of DRAW initiators that need to be patched up depending
  119. * on whether we using binning or not:
  120. */
  121. struct util_dynarray draw_patches;
  122. /* Keep track of writes to RB_RENDER_CONTROL which need to be patched
  123. * once we know whether or not to use GMEM, and GMEM tile pitch.
  124. *
  125. * (only for a3xx.. but having gen specific subclasses of fd_batch
  126. * seemed overkill for now)
  127. */
  128. struct util_dynarray rbrc_patches;
  129. struct pipe_framebuffer_state framebuffer;
  130. /** draw pass cmdstream: */
  131. struct fd_ringbuffer *draw;
  132. /** binning pass cmdstream: */
  133. struct fd_ringbuffer *binning;
  134. /** tiling/gmem (IB0) cmdstream: */
  135. struct fd_ringbuffer *gmem;
  136. // TODO maybe more generically split out clear and clear_binning rings?
  137. struct fd_ringbuffer *lrz_clear;
  138. /**
  139. * hw query related state:
  140. */
  141. /*@{*/
  142. /* next sample offset.. incremented for each sample in the batch/
  143. * submit, reset to zero on next submit.
  144. */
  145. uint32_t next_sample_offset;
  146. /* cached samples (in case multiple queries need to reference
  147. * the same sample snapshot)
  148. */
  149. struct fd_hw_sample *sample_cache[MAX_HW_SAMPLE_PROVIDERS];
  150. /* which sample providers were active in the current batch: */
  151. uint32_t active_providers;
  152. /* tracking for current stage, to know when to start/stop
  153. * any active queries:
  154. */
  155. enum fd_render_stage stage;
  156. /* list of samples in current batch: */
  157. struct util_dynarray samples;
  158. /* current query result bo and tile stride: */
  159. struct pipe_resource *query_buf;
  160. uint32_t query_tile_stride;
  161. /*@}*/
  162. /* Set of resources used by currently-unsubmitted batch (read or
  163. * write).. does not hold a reference to the resource.
  164. */
  165. struct set *resources;
  166. /** key in batch-cache (if not null): */
  167. const void *key;
  168. uint32_t hash;
  169. /** set of dependent batches.. holds refs to dependent batches: */
  170. uint32_t dependents_mask;
  171. };
  172. struct fd_batch * fd_batch_create(struct fd_context *ctx);
  173. void fd_batch_reset(struct fd_batch *batch);
  174. void fd_batch_sync(struct fd_batch *batch);
  175. void fd_batch_flush(struct fd_batch *batch, bool sync, bool force);
  176. void fd_batch_resource_used(struct fd_batch *batch, struct fd_resource *rsc, bool write);
  177. void fd_batch_check_size(struct fd_batch *batch);
  178. /* not called directly: */
  179. void __fd_batch_describe(char* buf, const struct fd_batch *batch);
  180. void __fd_batch_destroy(struct fd_batch *batch);
  181. /*
  182. * NOTE the rule is, you need to hold the screen->lock when destroying
  183. * a batch.. so either use fd_batch_reference() (which grabs the lock
  184. * for you) if you don't hold the lock, or fd_batch_reference_locked()
  185. * if you do hold the lock.
  186. *
  187. * WARNING the _locked() version can briefly drop the lock. Without
  188. * recursive mutexes, I'm not sure there is much else we can do (since
  189. * __fd_batch_destroy() needs to unref resources)
  190. */
  191. static inline void
  192. fd_batch_reference(struct fd_batch **ptr, struct fd_batch *batch)
  193. {
  194. struct fd_batch *old_batch = *ptr;
  195. if (pipe_reference_described(&(*ptr)->reference, &batch->reference,
  196. (debug_reference_descriptor)__fd_batch_describe))
  197. __fd_batch_destroy(old_batch);
  198. *ptr = batch;
  199. }
  200. /* fwd-decl prototypes to untangle header dependency :-/ */
  201. static inline void fd_context_assert_locked(struct fd_context *ctx);
  202. static inline void fd_context_lock(struct fd_context *ctx);
  203. static inline void fd_context_unlock(struct fd_context *ctx);
  204. static inline void
  205. fd_batch_reference_locked(struct fd_batch **ptr, struct fd_batch *batch)
  206. {
  207. struct fd_batch *old_batch = *ptr;
  208. if (old_batch)
  209. fd_context_assert_locked(old_batch->ctx);
  210. else if (batch)
  211. fd_context_assert_locked(batch->ctx);
  212. if (pipe_reference_described(&(*ptr)->reference, &batch->reference,
  213. (debug_reference_descriptor)__fd_batch_describe)) {
  214. struct fd_context *ctx = old_batch->ctx;
  215. fd_context_unlock(ctx);
  216. __fd_batch_destroy(old_batch);
  217. fd_context_lock(ctx);
  218. }
  219. *ptr = batch;
  220. }
  221. #include "freedreno_context.h"
  222. static inline void
  223. fd_reset_wfi(struct fd_batch *batch)
  224. {
  225. batch->needs_wfi = true;
  226. }
  227. void fd_wfi(struct fd_batch *batch, struct fd_ringbuffer *ring);
  228. /* emit a CP_EVENT_WRITE:
  229. */
  230. static inline void
  231. fd_event_write(struct fd_batch *batch, struct fd_ringbuffer *ring,
  232. enum vgt_event_type evt)
  233. {
  234. OUT_PKT3(ring, CP_EVENT_WRITE, 1);
  235. OUT_RING(ring, evt);
  236. fd_reset_wfi(batch);
  237. }
  238. #endif /* FREEDRENO_BATCH_H_ */