Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

freedreno_draw.h 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2012 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_DRAW_H_
  27. #define FREEDRENO_DRAW_H_
  28. #include "pipe/p_state.h"
  29. #include "pipe/p_context.h"
  30. #include "freedreno_context.h"
  31. #include "freedreno_resource.h"
  32. #include "freedreno_screen.h"
  33. #include "freedreno_util.h"
  34. struct fd_ringbuffer;
  35. void fd_draw_init(struct pipe_context *pctx);
  36. static inline void
  37. fd_draw(struct fd_batch *batch, struct fd_ringbuffer *ring,
  38. enum pc_di_primtype primtype,
  39. enum pc_di_vis_cull_mode vismode,
  40. enum pc_di_src_sel src_sel, uint32_t count,
  41. uint8_t instances,
  42. enum pc_di_index_size idx_type,
  43. uint32_t idx_size, uint32_t idx_offset,
  44. struct pipe_resource *idx_buffer)
  45. {
  46. /* for debug after a lock up, write a unique counter value
  47. * to scratch7 for each draw, to make it easier to match up
  48. * register dumps to cmdstream. The combination of IB
  49. * (scratch6) and DRAW is enough to "triangulate" the
  50. * particular draw that caused lockup.
  51. */
  52. emit_marker(ring, 7);
  53. if (is_a3xx_p0(batch->ctx->screen)) {
  54. /* dummy-draw workaround: */
  55. OUT_PKT3(ring, CP_DRAW_INDX, 3);
  56. OUT_RING(ring, 0x00000000);
  57. OUT_RING(ring, DRAW(1, DI_SRC_SEL_AUTO_INDEX,
  58. INDEX_SIZE_IGN, USE_VISIBILITY, 0));
  59. OUT_RING(ring, 0); /* NumIndices */
  60. /* ugg, hard-code register offset to avoid pulling in the
  61. * a3xx register headers into something #included from a2xx
  62. */
  63. OUT_PKT0(ring, 0x2206, 1); /* A3XX_HLSQ_CONST_VSPRESV_RANGE_REG */
  64. OUT_RING(ring, 0);
  65. }
  66. if (is_a20x(batch->ctx->screen)) {
  67. /* a20x has a different draw command for drawing with binning data
  68. * note: if we do patching we will have to insert a NOP
  69. *
  70. * binning data is is 1 byte/vertex (8x8x4 bin position of vertex)
  71. * base ptr set by the CP_SET_DRAW_INIT_FLAGS command
  72. *
  73. * TODO: investigate the faceness_cull_select parameter to see how
  74. * it is used with hw binning to use "faceness" bits
  75. */
  76. uint32_t size = 2;
  77. if (vismode)
  78. size += 2;
  79. if (idx_buffer)
  80. size += 2;
  81. BEGIN_RING(ring, size+1);
  82. if (vismode)
  83. util_dynarray_append(&batch->draw_patches, uint32_t*, ring->cur);
  84. OUT_PKT3(ring, vismode ? CP_DRAW_INDX_BIN : CP_DRAW_INDX, size);
  85. OUT_RING(ring, 0x00000000);
  86. OUT_RING(ring, DRAW_A20X(primtype, DI_FACE_CULL_NONE, src_sel,
  87. idx_type, vismode, vismode, count));
  88. if (vismode == USE_VISIBILITY) {
  89. OUT_RING(ring, batch->num_vertices);
  90. OUT_RING(ring, count);
  91. }
  92. } else {
  93. OUT_PKT3(ring, CP_DRAW_INDX, idx_buffer ? 5 : 3);
  94. OUT_RING(ring, 0x00000000); /* viz query info. */
  95. if (vismode == USE_VISIBILITY) {
  96. /* leave vis mode blank for now, it will be patched up when
  97. * we know if we are binning or not
  98. */
  99. OUT_RINGP(ring, DRAW(primtype, src_sel, idx_type, 0, instances),
  100. &batch->draw_patches);
  101. } else {
  102. OUT_RING(ring, DRAW(primtype, src_sel, idx_type, vismode, instances));
  103. }
  104. OUT_RING(ring, count); /* NumIndices */
  105. }
  106. if (idx_buffer) {
  107. OUT_RELOC(ring, fd_resource(idx_buffer)->bo, idx_offset, 0, 0);
  108. OUT_RING (ring, idx_size);
  109. }
  110. emit_marker(ring, 7);
  111. fd_reset_wfi(batch);
  112. }
  113. static inline enum pc_di_index_size
  114. size2indextype(unsigned index_size)
  115. {
  116. switch (index_size) {
  117. case 1: return INDEX_SIZE_8_BIT;
  118. case 2: return INDEX_SIZE_16_BIT;
  119. case 4: return INDEX_SIZE_32_BIT;
  120. }
  121. DBG("unsupported index size: %d", index_size);
  122. assert(0);
  123. return INDEX_SIZE_IGN;
  124. }
  125. /* this is same for a2xx/a3xx, so split into helper: */
  126. static inline void
  127. fd_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,
  128. enum pc_di_primtype primtype,
  129. enum pc_di_vis_cull_mode vismode,
  130. const struct pipe_draw_info *info,
  131. unsigned index_offset)
  132. {
  133. struct pipe_resource *idx_buffer = NULL;
  134. enum pc_di_index_size idx_type = INDEX_SIZE_IGN;
  135. enum pc_di_src_sel src_sel;
  136. uint32_t idx_size, idx_offset;
  137. if (info->index_size) {
  138. assert(!info->has_user_indices);
  139. idx_buffer = info->index.resource;
  140. idx_type = size2indextype(info->index_size);
  141. idx_size = info->index_size * info->count;
  142. idx_offset = index_offset + info->start * info->index_size;
  143. src_sel = DI_SRC_SEL_DMA;
  144. } else {
  145. idx_buffer = NULL;
  146. idx_type = INDEX_SIZE_IGN;
  147. idx_size = 0;
  148. idx_offset = 0;
  149. src_sel = DI_SRC_SEL_AUTO_INDEX;
  150. }
  151. fd_draw(batch, ring, primtype, vismode, src_sel,
  152. info->count, info->instance_count - 1,
  153. idx_type, idx_size, idx_offset, idx_buffer);
  154. }
  155. #endif /* FREEDRENO_DRAW_H_ */