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_blit.c 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright 2009 Marek Olšák <maraeo@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 "r300_context.h"
  23. #include "r300_texture.h"
  24. #include "util/u_format.h"
  25. static void r300_blitter_save_states(struct r300_context* r300)
  26. {
  27. util_blitter_save_blend(r300->blitter, r300->blend_state.state);
  28. util_blitter_save_depth_stencil_alpha(r300->blitter, r300->dsa_state.state);
  29. util_blitter_save_stencil_ref(r300->blitter, &(r300->stencil_ref));
  30. util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state);
  31. util_blitter_save_fragment_shader(r300->blitter, r300->fs.state);
  32. util_blitter_save_vertex_shader(r300->blitter, r300->vs_state.state);
  33. util_blitter_save_viewport(r300->blitter, &r300->viewport);
  34. util_blitter_save_clip(r300->blitter, &r300->clip);
  35. util_blitter_save_vertex_elements(r300->blitter, r300->velems);
  36. /* XXX this crashes the driver
  37. util_blitter_save_vertex_buffers(r300->blitter, r300->vertex_buffer_count,
  38. r300->vertex_buffer); */
  39. }
  40. /* Clear currently bound buffers. */
  41. static void r300_clear(struct pipe_context* pipe,
  42. unsigned buffers,
  43. const float* rgba,
  44. double depth,
  45. unsigned stencil)
  46. {
  47. /* XXX Implement fastfill.
  48. *
  49. * If fastfill is enabled, a few facts should be considered:
  50. *
  51. * 1) Zbuffer must be micro-tiled and whole microtiles must be
  52. * written.
  53. *
  54. * 2) ZB_DEPTHCLEARVALUE is used to clear a zbuffer and Z Mask must be
  55. * equal to 0.
  56. *
  57. * 3) For 16-bit integer buffering, compression causes a hung with one or
  58. * two samples and should not be used.
  59. *
  60. * 4) Fastfill must not be used if reading of compressed Z data is disabled
  61. * and writing of compressed Z data is enabled (RD/WR_COMP_ENABLE),
  62. * i.e. it cannot be used to compress the zbuffer.
  63. * (what the hell does that mean and how does it fit in clearing
  64. * the buffers?)
  65. *
  66. * - Marek
  67. */
  68. struct r300_context* r300 = r300_context(pipe);
  69. struct pipe_framebuffer_state* fb =
  70. (struct pipe_framebuffer_state*)r300->fb_state.state;
  71. r300_blitter_save_states(r300);
  72. util_blitter_clear(r300->blitter,
  73. fb->width,
  74. fb->height,
  75. fb->nr_cbufs,
  76. buffers, rgba, depth, stencil);
  77. }
  78. /* Copy a block of pixels from one surface to another using HW. */
  79. static void r300_hw_copy_region(struct pipe_context* pipe,
  80. struct pipe_resource *dst,
  81. struct pipe_subresource subdst,
  82. unsigned dstx, unsigned dsty, unsigned dstz,
  83. struct pipe_resource *src,
  84. struct pipe_subresource subsrc,
  85. unsigned srcx, unsigned srcy, unsigned srcz,
  86. unsigned width, unsigned height)
  87. {
  88. struct r300_context* r300 = r300_context(pipe);
  89. struct r300_textures_state* state =
  90. (struct r300_textures_state*)r300->textures_state.state;
  91. /* Yeah we have to save all those states to ensure this blitter operation
  92. * is really transparent. The states will be restored by the blitter once
  93. * copying is done. */
  94. r300_blitter_save_states(r300);
  95. util_blitter_save_framebuffer(r300->blitter, r300->fb_state.state);
  96. util_blitter_save_fragment_sampler_states(
  97. r300->blitter, state->sampler_state_count,
  98. (void**)state->sampler_states);
  99. util_blitter_save_fragment_sampler_views(
  100. r300->blitter, state->sampler_view_count,
  101. (struct pipe_sampler_view**)state->sampler_views);
  102. /* Do a copy */
  103. util_blitter_copy_region(r300->blitter, dst, subdst, dstx, dsty, dstz,
  104. src, subsrc, srcx, srcy, srcz, width, height,
  105. TRUE);
  106. }
  107. /* Copy a block of pixels from one surface to another. */
  108. static void r300_resource_copy_region(struct pipe_context *pipe,
  109. struct pipe_resource *dst,
  110. struct pipe_subresource subdst,
  111. unsigned dstx, unsigned dsty, unsigned dstz,
  112. struct pipe_resource *src,
  113. struct pipe_subresource subsrc,
  114. unsigned srcx, unsigned srcy, unsigned srcz,
  115. unsigned width, unsigned height)
  116. {
  117. enum pipe_format old_format = dst->format;
  118. enum pipe_format new_format = old_format;
  119. if (dst->format != src->format) {
  120. debug_printf("r300: Implementation error: Format mismatch in %s\n"
  121. " : src: %s dst: %s\n", __FUNCTION__,
  122. util_format_short_name(src->format),
  123. util_format_short_name(dst->format));
  124. debug_assert(0);
  125. }
  126. if (!pipe->screen->is_format_supported(pipe->screen,
  127. old_format, src->target,
  128. src->nr_samples,
  129. PIPE_BIND_RENDER_TARGET |
  130. PIPE_BIND_SAMPLER_VIEW, 0) &&
  131. util_format_is_plain(old_format)) {
  132. switch (util_format_get_blocksize(old_format)) {
  133. case 1:
  134. new_format = PIPE_FORMAT_I8_UNORM;
  135. break;
  136. case 2:
  137. new_format = PIPE_FORMAT_B4G4R4A4_UNORM;
  138. break;
  139. case 4:
  140. new_format = PIPE_FORMAT_B8G8R8A8_UNORM;
  141. break;
  142. case 8:
  143. new_format = PIPE_FORMAT_R16G16B16A16_UNORM;
  144. break;
  145. default:
  146. debug_printf("r300: surface_copy: Unhandled format: %s. Falling back to software.\n"
  147. "r300: surface_copy: Software fallback doesn't work for tiled textures.\n",
  148. util_format_short_name(old_format));
  149. }
  150. }
  151. if (old_format != new_format) {
  152. dst->format = new_format;
  153. src->format = new_format;
  154. r300_texture_reinterpret_format(pipe->screen,
  155. dst, new_format);
  156. r300_texture_reinterpret_format(pipe->screen,
  157. src, new_format);
  158. }
  159. r300_hw_copy_region(pipe, dst, subdst, dstx, dsty, dstz,
  160. src, subsrc, srcx, srcy, srcz, width, height);
  161. if (old_format != new_format) {
  162. dst->format = old_format;
  163. src->format = old_format;
  164. r300_texture_reinterpret_format(pipe->screen,
  165. dst, old_format);
  166. r300_texture_reinterpret_format(pipe->screen,
  167. src, old_format);
  168. }
  169. }
  170. /* Fill a region of a surface with a constant value. */
  171. static void r300_resource_fill_region(struct pipe_context *pipe,
  172. struct pipe_resource *dst,
  173. struct pipe_subresource subdst,
  174. unsigned dstx, unsigned dsty, unsigned dstz,
  175. unsigned width, unsigned height,
  176. unsigned value)
  177. {
  178. struct r300_context *r300 = r300_context(pipe);
  179. r300_blitter_save_states(r300);
  180. util_blitter_save_framebuffer(r300->blitter, r300->fb_state.state);
  181. util_blitter_fill_region(r300->blitter, dst, subdst,
  182. dstx, dsty, dstz, width, height, value);
  183. }
  184. void r300_init_blit_functions(struct r300_context *r300)
  185. {
  186. r300->context.clear = r300_clear;
  187. r300->context.resource_copy_region = r300_resource_copy_region;
  188. r300->context.resource_fill_region = r300_resource_fill_region;
  189. }