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.

r600.h 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Copyright 2010 Jerome Glisse <glisse@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. * on the rights to use, copy, modify, merge, publish, distribute, sub
  8. * license, and/or sell copies of the Software, and to permit persons to whom
  9. * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Jerome Glisse
  25. */
  26. #ifndef R600_H
  27. #define R600_H
  28. #include "../../winsys/radeon/drm/radeon_winsys.h"
  29. #include "util/u_double_list.h"
  30. #include "util/u_vbuf.h"
  31. #define R600_ERR(fmt, args...) \
  32. fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
  33. struct winsys_handle;
  34. enum radeon_family {
  35. CHIP_UNKNOWN,
  36. CHIP_R600,
  37. CHIP_RV610,
  38. CHIP_RV630,
  39. CHIP_RV670,
  40. CHIP_RV620,
  41. CHIP_RV635,
  42. CHIP_RS780,
  43. CHIP_RS880,
  44. CHIP_RV770,
  45. CHIP_RV730,
  46. CHIP_RV710,
  47. CHIP_RV740,
  48. CHIP_CEDAR,
  49. CHIP_REDWOOD,
  50. CHIP_JUNIPER,
  51. CHIP_CYPRESS,
  52. CHIP_HEMLOCK,
  53. CHIP_PALM,
  54. CHIP_SUMO,
  55. CHIP_SUMO2,
  56. CHIP_BARTS,
  57. CHIP_TURKS,
  58. CHIP_CAICOS,
  59. CHIP_CAYMAN,
  60. CHIP_ARUBA,
  61. CHIP_LAST,
  62. };
  63. enum chip_class {
  64. R600,
  65. R700,
  66. EVERGREEN,
  67. CAYMAN,
  68. };
  69. struct r600_tiling_info {
  70. unsigned num_channels;
  71. unsigned num_banks;
  72. unsigned group_bytes;
  73. };
  74. struct r600_resource {
  75. struct u_vbuf_resource b;
  76. /* Winsys objects. */
  77. struct pb_buffer *buf;
  78. struct radeon_winsys_cs_handle *cs_buf;
  79. /* Resource state. */
  80. unsigned domains;
  81. };
  82. #define R600_BLOCK_MAX_BO 32
  83. #define R600_BLOCK_MAX_REG 128
  84. /* each range covers 9 bits of dword space = 512 dwords = 2k bytes */
  85. /* there is a block entry for each register so 512 blocks */
  86. /* we have no registers to read/write below 0x8000 (0x2000 in dw space) */
  87. /* we use some fake offsets at 0x40000 to do evergreen sampler borders so take 0x42000 as a max bound*/
  88. #define RANGE_OFFSET_START 0x8000
  89. #define HASH_SHIFT 9
  90. #define NUM_RANGES (0x42000 - RANGE_OFFSET_START) / (4 << HASH_SHIFT) /* 128 << 9 = 64k */
  91. #define CTX_RANGE_ID(offset) ((((offset - RANGE_OFFSET_START) >> 2) >> HASH_SHIFT) & 255)
  92. #define CTX_BLOCK_ID(offset) (((offset - RANGE_OFFSET_START) >> 2) & ((1 << HASH_SHIFT) - 1))
  93. struct r600_pipe_reg {
  94. uint32_t value;
  95. struct r600_block *block;
  96. struct r600_resource *bo;
  97. enum radeon_bo_usage bo_usage;
  98. uint32_t id;
  99. };
  100. struct r600_pipe_state {
  101. unsigned id;
  102. unsigned nregs;
  103. struct r600_pipe_reg regs[R600_BLOCK_MAX_REG];
  104. };
  105. struct r600_pipe_resource_state {
  106. unsigned id;
  107. uint32_t val[8];
  108. struct r600_resource *bo[2];
  109. enum radeon_bo_usage bo_usage[2];
  110. };
  111. #define R600_BLOCK_STATUS_ENABLED (1 << 0)
  112. #define R600_BLOCK_STATUS_DIRTY (1 << 1)
  113. #define R600_BLOCK_STATUS_RESOURCE_DIRTY (1 << 2)
  114. #define R600_BLOCK_STATUS_RESOURCE_VERTEX (1 << 3)
  115. struct r600_block_reloc {
  116. struct r600_resource *bo;
  117. enum radeon_bo_usage bo_usage;
  118. unsigned bo_pm4_index;
  119. };
  120. struct r600_block {
  121. struct list_head list;
  122. struct list_head enable_list;
  123. unsigned status;
  124. unsigned flags;
  125. unsigned start_offset;
  126. unsigned pm4_ndwords;
  127. unsigned nbo;
  128. uint16_t nreg;
  129. uint16_t nreg_dirty;
  130. uint32_t *reg;
  131. uint32_t pm4[R600_BLOCK_MAX_REG];
  132. unsigned pm4_bo_index[R600_BLOCK_MAX_REG];
  133. struct r600_block_reloc reloc[R600_BLOCK_MAX_BO];
  134. };
  135. struct r600_range {
  136. struct r600_block **blocks;
  137. };
  138. struct r600_query_buffer {
  139. /* The buffer where query results are stored. */
  140. struct r600_resource *buf;
  141. /* Offset of the next free result after current query data */
  142. unsigned results_end;
  143. /* If a query buffer is full, a new buffer is created and the old one
  144. * is put in here. When we calculate the result, we sum up the samples
  145. * from all buffers. */
  146. struct r600_query_buffer *previous;
  147. };
  148. union r600_query_result {
  149. uint64_t u64;
  150. boolean b;
  151. struct pipe_query_data_so_statistics so;
  152. };
  153. struct r600_query {
  154. /* The query buffer and how many results are in it. */
  155. struct r600_query_buffer buffer;
  156. /* The type of query */
  157. unsigned type;
  158. /* Size of the result in memory for both begin_query and end_query,
  159. * this can be one or two numbers, or it could even be a size of a structure. */
  160. unsigned result_size;
  161. /* The number of dwords for begin_query or end_query. */
  162. unsigned num_cs_dw;
  163. /* linked list of queries */
  164. struct list_head list;
  165. };
  166. struct r600_so_target {
  167. struct pipe_stream_output_target b;
  168. /* The buffer where BUFFER_FILLED_SIZE is stored. */
  169. struct r600_resource *filled_size;
  170. unsigned stride_in_dw;
  171. unsigned so_index;
  172. };
  173. #define R600_CONTEXT_DRAW_PENDING (1 << 0)
  174. #define R600_CONTEXT_DST_CACHES_DIRTY (1 << 1)
  175. struct r600_context;
  176. struct r600_screen;
  177. void r600_get_backend_mask(struct r600_context *ctx);
  178. int r600_context_init(struct r600_context *ctx);
  179. void r600_context_fini(struct r600_context *ctx);
  180. void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state);
  181. void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
  182. void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
  183. void r600_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
  184. void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
  185. void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
  186. void r600_context_flush(struct r600_context *ctx, unsigned flags);
  187. void r600_context_emit_fence(struct r600_context *ctx, struct r600_resource *fence,
  188. unsigned offset, unsigned value);
  189. void r600_inval_shader_cache(struct r600_context *ctx);
  190. void r600_inval_texture_cache(struct r600_context *ctx);
  191. void r600_inval_vertex_cache(struct r600_context *ctx);
  192. void r600_flush_framebuffer(struct r600_context *ctx, bool flush_now);
  193. void r600_context_streamout_begin(struct r600_context *ctx);
  194. void r600_context_streamout_end(struct r600_context *ctx);
  195. void r600_context_draw_opaque_count(struct r600_context *ctx, struct r600_so_target *t);
  196. void r600_need_cs_space(struct r600_context *ctx, unsigned num_dw, boolean count_draw_in);
  197. void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *block);
  198. void r600_context_block_resource_emit_dirty(struct r600_context *ctx, struct r600_block *block);
  199. int evergreen_context_init(struct r600_context *ctx);
  200. void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
  201. void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
  202. void _r600_pipe_state_add_reg(struct r600_context *ctx,
  203. struct r600_pipe_state *state,
  204. uint32_t offset, uint32_t value,
  205. uint32_t range_id, uint32_t block_id,
  206. struct r600_resource *bo,
  207. enum radeon_bo_usage usage);
  208. void r600_pipe_state_add_reg_noblock(struct r600_pipe_state *state,
  209. uint32_t offset, uint32_t value,
  210. struct r600_resource *bo,
  211. enum radeon_bo_usage usage);
  212. #define r600_pipe_state_add_reg(state, offset, value, bo, usage) _r600_pipe_state_add_reg(rctx, state, offset, value, CTX_RANGE_ID(offset), CTX_BLOCK_ID(offset), bo, usage)
  213. static inline void r600_pipe_state_mod_reg(struct r600_pipe_state *state,
  214. uint32_t value)
  215. {
  216. state->regs[state->nregs].value = value;
  217. state->nregs++;
  218. }
  219. static inline void r600_pipe_state_mod_reg_bo(struct r600_pipe_state *state,
  220. uint32_t value, struct r600_resource *bo,
  221. enum radeon_bo_usage usage)
  222. {
  223. state->regs[state->nregs].value = value;
  224. state->regs[state->nregs].bo = bo;
  225. state->regs[state->nregs].bo_usage = usage;
  226. state->nregs++;
  227. }
  228. #endif