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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 <stdint.h>
  29. #include <stdio.h>
  30. #include <util/u_double_list.h>
  31. #include <pipe/p_compiler.h>
  32. #define RADEON_CTX_MAX_PM4 (64 * 1024 / 4)
  33. #define R600_ERR(fmt, args...) \
  34. fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)
  35. typedef uint64_t u64;
  36. typedef uint32_t u32;
  37. typedef uint16_t u16;
  38. typedef uint8_t u8;
  39. struct radeon;
  40. enum radeon_family {
  41. CHIP_UNKNOWN,
  42. CHIP_R100,
  43. CHIP_RV100,
  44. CHIP_RS100,
  45. CHIP_RV200,
  46. CHIP_RS200,
  47. CHIP_R200,
  48. CHIP_RV250,
  49. CHIP_RS300,
  50. CHIP_RV280,
  51. CHIP_R300,
  52. CHIP_R350,
  53. CHIP_RV350,
  54. CHIP_RV380,
  55. CHIP_R420,
  56. CHIP_R423,
  57. CHIP_RV410,
  58. CHIP_RS400,
  59. CHIP_RS480,
  60. CHIP_RS600,
  61. CHIP_RS690,
  62. CHIP_RS740,
  63. CHIP_RV515,
  64. CHIP_R520,
  65. CHIP_RV530,
  66. CHIP_RV560,
  67. CHIP_RV570,
  68. CHIP_R580,
  69. CHIP_R600,
  70. CHIP_RV610,
  71. CHIP_RV630,
  72. CHIP_RV670,
  73. CHIP_RV620,
  74. CHIP_RV635,
  75. CHIP_RS780,
  76. CHIP_RS880,
  77. CHIP_RV770,
  78. CHIP_RV730,
  79. CHIP_RV710,
  80. CHIP_RV740,
  81. CHIP_CEDAR,
  82. CHIP_REDWOOD,
  83. CHIP_JUNIPER,
  84. CHIP_CYPRESS,
  85. CHIP_HEMLOCK,
  86. CHIP_LAST,
  87. };
  88. enum chip_class {
  89. R600,
  90. R700,
  91. EVERGREEN,
  92. };
  93. enum radeon_family r600_get_family(struct radeon *rw);
  94. enum chip_class r600_get_family_class(struct radeon *radeon);
  95. /* lowlevel WS bo */
  96. struct radeon_ws_bo;
  97. struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon,
  98. unsigned size, unsigned alignment, unsigned usage);
  99. struct radeon_ws_bo *radeon_ws_bo_handle(struct radeon *radeon,
  100. unsigned handle);
  101. void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo, unsigned usage, void *ctx);
  102. void radeon_ws_bo_unmap(struct radeon *radeon, struct radeon_ws_bo *bo);
  103. void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst,
  104. struct radeon_ws_bo *src);
  105. /* R600/R700 STATES */
  106. #define R600_GROUP_MAX 16
  107. #define R600_BLOCK_MAX_BO 32
  108. #define R600_BLOCK_MAX_REG 128
  109. enum r600_group_id {
  110. R600_GROUP_CONFIG = 0,
  111. R600_GROUP_CONTEXT,
  112. R600_GROUP_ALU_CONST,
  113. R600_GROUP_RESOURCE,
  114. R600_GROUP_SAMPLER,
  115. R600_GROUP_CTL_CONST,
  116. R600_GROUP_LOOP_CONST,
  117. R600_GROUP_BOOL_CONST,
  118. R600_NGROUPS
  119. };
  120. enum evergreen_group_id {
  121. EVERGREEN_GROUP_CONFIG = 0,
  122. EVERGREEN_GROUP_CONTEXT,
  123. EVERGREEN_GROUP_RESOURCE,
  124. EVERGREEN_GROUP_SAMPLER,
  125. EVERGREEN_GROUP_CTL_CONST,
  126. EVERGREEN_GROUP_LOOP_CONST,
  127. EVERGREEN_GROUP_BOOL_CONST,
  128. EVERGREEN_NGROUPS
  129. };
  130. struct r600_pipe_reg {
  131. unsigned group_id;
  132. u32 offset;
  133. u32 mask;
  134. u32 value;
  135. struct radeon_ws_bo *bo;
  136. };
  137. struct r600_pipe_state {
  138. unsigned id;
  139. unsigned nregs;
  140. struct r600_pipe_reg regs[R600_BLOCK_MAX_REG];
  141. };
  142. static inline void r600_pipe_state_add_reg(struct r600_pipe_state *state,
  143. unsigned group_id, u32 offset,
  144. u32 value, u32 mask,
  145. struct radeon_ws_bo *bo)
  146. {
  147. state->regs[state->nregs].group_id = group_id;
  148. state->regs[state->nregs].offset = offset;
  149. state->regs[state->nregs].value = value;
  150. state->regs[state->nregs].mask = mask;
  151. state->regs[state->nregs].bo = bo;
  152. state->nregs++;
  153. assert(state->nregs < R600_BLOCK_MAX_REG);
  154. }
  155. #define R600_BLOCK_STATUS_ENABLED (1 << 0)
  156. #define R600_BLOCK_STATUS_DIRTY (1 << 1)
  157. struct r600_block_reloc {
  158. struct radeon_ws_bo *bo;
  159. unsigned nreloc;
  160. unsigned bo_pm4_index[R600_BLOCK_MAX_BO];
  161. };
  162. struct r600_group_block {
  163. unsigned status;
  164. unsigned start_offset;
  165. unsigned pm4_ndwords;
  166. unsigned nbo;
  167. unsigned nreg;
  168. u32 pm4[R600_BLOCK_MAX_REG];
  169. unsigned pm4_bo_index[R600_BLOCK_MAX_REG];
  170. struct r600_block_reloc reloc[R600_BLOCK_MAX_BO];
  171. };
  172. struct r600_group {
  173. unsigned start_offset;
  174. unsigned end_offset;
  175. unsigned nblocks;
  176. struct r600_group_block *blocks;
  177. unsigned *offset_block_id;
  178. };
  179. /*
  180. * relocation
  181. */
  182. #pragma pack(1)
  183. struct r600_reloc {
  184. uint32_t handle;
  185. uint32_t read_domain;
  186. uint32_t write_domain;
  187. uint32_t flags;
  188. };
  189. #pragma pack()
  190. /*
  191. * query
  192. */
  193. struct r600_query {
  194. u64 result;
  195. /* The kind of query. Currently only OQ is supported. */
  196. unsigned type;
  197. /* How many results have been written, in dwords. It's incremented
  198. * after end_query and flush. */
  199. unsigned num_results;
  200. /* if we've flushed the query */
  201. unsigned state;
  202. /* The buffer where query results are stored. */
  203. struct radeon_ws_bo *buffer;
  204. unsigned buffer_size;
  205. /* linked list of queries */
  206. struct list_head list;
  207. };
  208. #define R600_QUERY_STATE_STARTED (1 << 0)
  209. #define R600_QUERY_STATE_ENDED (1 << 1)
  210. #define R600_QUERY_STATE_SUSPENDED (1 << 2)
  211. struct r600_context {
  212. struct radeon *radeon;
  213. unsigned ngroups;
  214. struct r600_group groups[R600_GROUP_MAX];
  215. unsigned pm4_ndwords;
  216. unsigned pm4_cdwords;
  217. unsigned pm4_dirty_cdwords;
  218. unsigned ctx_pm4_ndwords;
  219. unsigned nreloc;
  220. unsigned creloc;
  221. struct r600_reloc *reloc;
  222. struct radeon_bo **bo;
  223. u32 *pm4;
  224. struct list_head query_list;
  225. unsigned num_query_running;
  226. };
  227. struct r600_draw {
  228. u32 vgt_num_indices;
  229. u32 vgt_num_instances;
  230. u32 vgt_index_type;
  231. u32 vgt_draw_initiator;
  232. u32 indices_bo_offset;
  233. struct radeon_ws_bo *indices;
  234. };
  235. int r600_context_init(struct r600_context *ctx, struct radeon *radeon);
  236. void r600_context_fini(struct r600_context *ctx);
  237. void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state);
  238. void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
  239. void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
  240. void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
  241. void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
  242. void r600_context_flush(struct r600_context *ctx);
  243. void r600_context_dump_bof(struct r600_context *ctx, const char *file);
  244. void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw);
  245. struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type);
  246. void r600_context_query_destroy(struct r600_context *ctx, struct r600_query *query);
  247. boolean r600_context_query_result(struct r600_context *ctx,
  248. struct r600_query *query,
  249. boolean wait, void *vresult);
  250. void r600_query_begin(struct r600_context *ctx, struct r600_query *query);
  251. void r600_query_end(struct r600_context *ctx, struct r600_query *query);
  252. int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon);
  253. void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *draw);
  254. void evergreen_ps_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
  255. void evergreen_vs_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
  256. #endif