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.

r300_query.c 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
  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. #include "util/u_memory.h"
  23. #include "util/u_simple_list.h"
  24. #include "r300_context.h"
  25. #include "r300_screen.h"
  26. #include "r300_cs.h"
  27. #include "r300_emit.h"
  28. #include "r300_query.h"
  29. #include "r300_reg.h"
  30. static struct pipe_query *r300_create_query(struct pipe_context *pipe,
  31. unsigned query_type)
  32. {
  33. struct r300_context *r300 = r300_context(pipe);
  34. struct r300_screen *r300screen = r300_screen(r300->context.screen);
  35. unsigned query_size;
  36. struct r300_query *q, *qptr;
  37. q = CALLOC_STRUCT(r300_query);
  38. q->type = query_type;
  39. assert(q->type == PIPE_QUERY_OCCLUSION_COUNTER);
  40. q->active = FALSE;
  41. if (r300screen->caps->family == CHIP_FAMILY_RV530)
  42. query_size = r300screen->caps->num_z_pipes * sizeof(uint32_t);
  43. else
  44. query_size = r300screen->caps->num_frag_pipes * sizeof(uint32_t);
  45. if (!is_empty_list(&r300->query_list)) {
  46. qptr = last_elem(&r300->query_list);
  47. q->offset = qptr->offset + query_size;
  48. }
  49. insert_at_tail(&r300->query_list, q);
  50. /* XXX */
  51. if (q->offset >= 4096) {
  52. q->offset = 0;
  53. }
  54. return (struct pipe_query*)q;
  55. }
  56. static void r300_destroy_query(struct pipe_context* pipe,
  57. struct pipe_query* query)
  58. {
  59. struct r300_query* q = (struct r300_query*)query;
  60. remove_from_list(q);
  61. FREE(query);
  62. }
  63. static void r300_begin_query(struct pipe_context* pipe,
  64. struct pipe_query* query)
  65. {
  66. uint32_t* map;
  67. struct r300_context* r300 = r300_context(pipe);
  68. struct r300_query* q = (struct r300_query*)query;
  69. assert(r300->query_current == NULL);
  70. map = pipe->screen->buffer_map(pipe->screen, r300->oqbo,
  71. PIPE_BUFFER_USAGE_CPU_WRITE);
  72. map += q->offset / 4;
  73. *map = ~0U;
  74. pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
  75. q->flushed = FALSE;
  76. r300->query_current = q;
  77. r300->dirty_state |= R300_NEW_QUERY;
  78. }
  79. static void r300_end_query(struct pipe_context* pipe,
  80. struct pipe_query* query)
  81. {
  82. struct r300_context* r300 = r300_context(pipe);
  83. r300_emit_query_end(r300);
  84. r300->query_current = NULL;
  85. }
  86. static boolean r300_get_query_result(struct pipe_context* pipe,
  87. struct pipe_query* query,
  88. boolean wait,
  89. uint64_t* result)
  90. {
  91. struct r300_context* r300 = r300_context(pipe);
  92. struct r300_screen* r300screen = r300_screen(r300->context.screen);
  93. struct r300_query *q = (struct r300_query*)query;
  94. unsigned flags = PIPE_BUFFER_USAGE_CPU_READ;
  95. uint32_t* map;
  96. uint32_t temp = 0;
  97. unsigned i, num_results;
  98. if (q->flushed == FALSE)
  99. pipe->flush(pipe, 0, NULL);
  100. if (!wait) {
  101. flags |= PIPE_BUFFER_USAGE_DONTBLOCK;
  102. }
  103. map = pipe->screen->buffer_map(pipe->screen, r300->oqbo, flags);
  104. if (!map)
  105. return FALSE;
  106. map += q->offset / 4;
  107. if (r300screen->caps->family == CHIP_FAMILY_RV530)
  108. num_results = r300screen->caps->num_z_pipes;
  109. else
  110. num_results = r300screen->caps->num_frag_pipes;
  111. for (i = 0; i < num_results; i++) {
  112. if (*map == ~0U) {
  113. /* Looks like our results aren't ready yet. */
  114. if (wait) {
  115. debug_printf("r300: Despite waiting, OQ results haven't"
  116. " come in yet.\n");
  117. }
  118. temp = ~0U;
  119. break;
  120. }
  121. temp += *map;
  122. map++;
  123. }
  124. pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
  125. if (temp == ~0U) {
  126. /* Our results haven't been written yet... */
  127. return FALSE;
  128. }
  129. *result = temp;
  130. return TRUE;
  131. }
  132. void r300_init_query_functions(struct r300_context* r300) {
  133. r300->context.create_query = r300_create_query;
  134. r300->context.destroy_query = r300_destroy_query;
  135. r300->context.begin_query = r300_begin_query;
  136. r300->context.end_query = r300_end_query;
  137. r300->context.get_query_result = r300_get_query_result;
  138. }