radeon_cs.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright © 2008 Nicolai Haehnle
  3. * Copyright © 2008 Jérôme Glisse
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  18. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * The above copyright notice and this permission notice (including the
  23. * next paragraph) shall be included in all copies or substantial portions
  24. * of the Software.
  25. */
  26. /*
  27. * Authors:
  28. * Aapo Tahkola <aet@rasterburn.org>
  29. * Nicolai Haehnle <prefect_@gmx.net>
  30. * Jérôme Glisse <glisse@freedesktop.org>
  31. */
  32. #ifndef RADEON_CS_H
  33. #define RADEON_CS_H
  34. #include <stdint.h>
  35. #include <string.h>
  36. #include "drm.h"
  37. #include "radeon_drm.h"
  38. #include "radeon_bo.h"
  39. struct radeon_cs_reloc {
  40. struct radeon_bo *bo;
  41. uint32_t read_domain;
  42. uint32_t write_domain;
  43. uint32_t flags;
  44. };
  45. #define RADEON_CS_SPACE_OK 0
  46. #define RADEON_CS_SPACE_OP_TO_BIG 1
  47. #define RADEON_CS_SPACE_FLUSH 2
  48. struct radeon_cs {
  49. uint32_t *packets;
  50. unsigned cdw;
  51. unsigned ndw;
  52. unsigned section_ndw;
  53. unsigned section_cdw;
  54. };
  55. #define MAX_SPACE_BOS (32)
  56. struct radeon_cs_manager;
  57. extern struct radeon_cs *radeon_cs_create(struct radeon_cs_manager *csm,
  58. uint32_t ndw);
  59. extern int radeon_cs_begin(struct radeon_cs *cs,
  60. uint32_t ndw,
  61. const char *file,
  62. const char *func, int line);
  63. extern int radeon_cs_end(struct radeon_cs *cs,
  64. const char *file,
  65. const char *func,
  66. int line);
  67. extern int radeon_cs_emit(struct radeon_cs *cs);
  68. extern int radeon_cs_destroy(struct radeon_cs *cs);
  69. extern int radeon_cs_erase(struct radeon_cs *cs);
  70. extern int radeon_cs_need_flush(struct radeon_cs *cs);
  71. extern void radeon_cs_print(struct radeon_cs *cs, FILE *file);
  72. extern void radeon_cs_set_limit(struct radeon_cs *cs, uint32_t domain, uint32_t limit);
  73. extern void radeon_cs_space_set_flush(struct radeon_cs *cs, void (*fn)(void *), void *data);
  74. extern int radeon_cs_write_reloc(struct radeon_cs *cs,
  75. struct radeon_bo *bo,
  76. uint32_t read_domain,
  77. uint32_t write_domain,
  78. uint32_t flags);
  79. extern uint32_t radeon_cs_get_id(struct radeon_cs *cs);
  80. /*
  81. * add a persistent BO to the list
  82. * a persistent BO is one that will be referenced across flushes,
  83. * i.e. colorbuffer, textures etc.
  84. * They get reset when a new "operation" happens, where an operation
  85. * is a state emission with a color/textures etc followed by a bunch of vertices.
  86. */
  87. void radeon_cs_space_add_persistent_bo(struct radeon_cs *cs,
  88. struct radeon_bo *bo,
  89. uint32_t read_domains,
  90. uint32_t write_domain);
  91. /* reset the persistent BO list */
  92. void radeon_cs_space_reset_bos(struct radeon_cs *cs);
  93. /* do a space check with the current persistent BO list */
  94. int radeon_cs_space_check(struct radeon_cs *cs);
  95. /* do a space check with the current persistent BO list and a temporary BO
  96. * a temporary BO is like a DMA buffer, which gets flushed with the
  97. * command buffer */
  98. int radeon_cs_space_check_with_bo(struct radeon_cs *cs,
  99. struct radeon_bo *bo,
  100. uint32_t read_domains,
  101. uint32_t write_domain);
  102. static inline void radeon_cs_write_dword(struct radeon_cs *cs, uint32_t dword)
  103. {
  104. cs->packets[cs->cdw++] = dword;
  105. if (cs->section_ndw) {
  106. cs->section_cdw++;
  107. }
  108. }
  109. static inline void radeon_cs_write_qword(struct radeon_cs *cs, uint64_t qword)
  110. {
  111. memcpy(cs->packets + cs->cdw, &qword, sizeof(uint64_t));
  112. cs->cdw += 2;
  113. if (cs->section_ndw) {
  114. cs->section_cdw += 2;
  115. }
  116. }
  117. static inline void radeon_cs_write_table(struct radeon_cs *cs,
  118. const void *data, uint32_t size)
  119. {
  120. memcpy(cs->packets + cs->cdw, data, size * 4);
  121. cs->cdw += size;
  122. if (cs->section_ndw) {
  123. cs->section_cdw += size;
  124. }
  125. }
  126. #endif