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.

svga_context.c 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**********************************************************
  2. * Copyright 2008-2009 VMware, Inc. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. **********************************************************/
  25. #include "svga_cmd.h"
  26. #include "pipe/p_defines.h"
  27. #include "util/u_inlines.h"
  28. #include "pipe/p_screen.h"
  29. #include "util/u_memory.h"
  30. #include "util/u_bitmask.h"
  31. #include "util/u_upload_mgr.h"
  32. #include "svga_context.h"
  33. #include "svga_screen.h"
  34. #include "svga_resource_texture.h"
  35. #include "svga_resource_buffer.h"
  36. #include "svga_resource.h"
  37. #include "svga_winsys.h"
  38. #include "svga_swtnl.h"
  39. #include "svga_draw.h"
  40. #include "svga_debug.h"
  41. #include "svga_state.h"
  42. static void svga_destroy( struct pipe_context *pipe )
  43. {
  44. struct svga_context *svga = svga_context( pipe );
  45. unsigned shader;
  46. svga_cleanup_framebuffer( svga );
  47. svga_cleanup_tss_binding( svga );
  48. svga_hwtnl_destroy( svga->hwtnl );
  49. svga_cleanup_vertex_state(svga);
  50. svga->swc->destroy(svga->swc);
  51. svga_destroy_swtnl( svga );
  52. u_upload_destroy( svga->upload_vb );
  53. u_upload_destroy( svga->upload_ib );
  54. util_bitmask_destroy( svga->vs_bm );
  55. util_bitmask_destroy( svga->fs_bm );
  56. for(shader = 0; shader < PIPE_SHADER_TYPES; ++shader)
  57. pipe_resource_reference( &svga->curr.cb[shader], NULL );
  58. FREE( svga );
  59. }
  60. struct pipe_context *svga_context_create( struct pipe_screen *screen,
  61. void *priv )
  62. {
  63. struct svga_screen *svgascreen = svga_screen(screen);
  64. struct svga_context *svga = NULL;
  65. enum pipe_error ret;
  66. svga = CALLOC_STRUCT(svga_context);
  67. if (svga == NULL)
  68. goto no_svga;
  69. svga->pipe.winsys = screen->winsys;
  70. svga->pipe.screen = screen;
  71. svga->pipe.priv = priv;
  72. svga->pipe.destroy = svga_destroy;
  73. svga->pipe.clear = svga_clear;
  74. svga->swc = svgascreen->sws->context_create(svgascreen->sws);
  75. if(!svga->swc)
  76. goto no_swc;
  77. svga_init_resource_functions(svga);
  78. svga_init_blend_functions(svga);
  79. svga_init_blit_functions(svga);
  80. svga_init_depth_stencil_functions(svga);
  81. svga_init_draw_functions(svga);
  82. svga_init_flush_functions(svga);
  83. svga_init_misc_functions(svga);
  84. svga_init_rasterizer_functions(svga);
  85. svga_init_sampler_functions(svga);
  86. svga_init_fs_functions(svga);
  87. svga_init_vs_functions(svga);
  88. svga_init_vertex_functions(svga);
  89. svga_init_constbuffer_functions(svga);
  90. svga_init_query_functions(svga);
  91. /* debug */
  92. svga->debug.no_swtnl = debug_get_bool_option("SVGA_NO_SWTNL", FALSE);
  93. svga->debug.force_swtnl = debug_get_bool_option("SVGA_FORCE_SWTNL", FALSE);
  94. svga->debug.use_min_mipmap = debug_get_bool_option("SVGA_USE_MIN_MIPMAP", FALSE);
  95. svga->debug.disable_shader = debug_get_num_option("SVGA_DISABLE_SHADER", ~0);
  96. if (!svga_init_swtnl(svga))
  97. goto no_swtnl;
  98. svga->fs_bm = util_bitmask_create();
  99. if (svga->fs_bm == NULL)
  100. goto no_fs_bm;
  101. svga->vs_bm = util_bitmask_create();
  102. if (svga->vs_bm == NULL)
  103. goto no_vs_bm;
  104. svga->upload_ib = u_upload_create( &svga->pipe,
  105. 32 * 1024,
  106. 16,
  107. PIPE_BIND_INDEX_BUFFER );
  108. if (svga->upload_ib == NULL)
  109. goto no_upload_ib;
  110. svga->upload_vb = u_upload_create( &svga->pipe,
  111. 128 * 1024,
  112. 16,
  113. PIPE_BIND_VERTEX_BUFFER );
  114. if (svga->upload_vb == NULL)
  115. goto no_upload_vb;
  116. svga->hwtnl = svga_hwtnl_create( svga,
  117. svga->upload_ib,
  118. svga->swc );
  119. if (svga->hwtnl == NULL)
  120. goto no_hwtnl;
  121. ret = svga_emit_initial_state( svga );
  122. if (ret)
  123. goto no_state;
  124. /* Avoid shortcircuiting state with initial value of zero.
  125. */
  126. memset(&svga->state.hw_clear, 0xcd, sizeof(svga->state.hw_clear));
  127. memset(&svga->state.hw_clear.framebuffer, 0x0,
  128. sizeof(svga->state.hw_clear.framebuffer));
  129. memset(&svga->state.hw_draw, 0xcd, sizeof(svga->state.hw_draw));
  130. memset(&svga->state.hw_draw.views, 0x0, sizeof(svga->state.hw_draw.views));
  131. svga->state.hw_draw.num_views = 0;
  132. svga->dirty = ~0;
  133. LIST_INITHEAD(&svga->dirty_buffers);
  134. return &svga->pipe;
  135. no_state:
  136. svga_hwtnl_destroy( svga->hwtnl );
  137. no_hwtnl:
  138. u_upload_destroy( svga->upload_vb );
  139. no_upload_vb:
  140. u_upload_destroy( svga->upload_ib );
  141. no_upload_ib:
  142. util_bitmask_destroy( svga->vs_bm );
  143. no_vs_bm:
  144. util_bitmask_destroy( svga->fs_bm );
  145. no_fs_bm:
  146. svga_destroy_swtnl(svga);
  147. no_swtnl:
  148. svga->swc->destroy(svga->swc);
  149. no_swc:
  150. FREE(svga);
  151. no_svga:
  152. return NULL;
  153. }
  154. void svga_context_flush( struct svga_context *svga,
  155. struct pipe_fence_handle **pfence )
  156. {
  157. struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
  158. struct pipe_fence_handle *fence = NULL;
  159. svga->curr.nr_fbs = 0;
  160. /* Unmap upload manager buffers:
  161. */
  162. u_upload_flush(svga->upload_vb);
  163. u_upload_flush(svga->upload_ib);
  164. /* Ensure that texture dma uploads are processed
  165. * before submitting commands.
  166. */
  167. svga_context_flush_buffers(svga);
  168. /* Flush pending commands to hardware:
  169. */
  170. svga->swc->flush(svga->swc, &fence);
  171. svga_screen_cache_flush(svgascreen, fence);
  172. if (SVGA_DEBUG & DEBUG_SYNC) {
  173. if (fence)
  174. svga->pipe.screen->fence_finish( svga->pipe.screen, fence, 0);
  175. }
  176. if(pfence)
  177. *pfence = fence;
  178. else
  179. svgascreen->sws->fence_reference(svgascreen->sws, &fence, NULL);
  180. }
  181. void svga_hwtnl_flush_retry( struct svga_context *svga )
  182. {
  183. enum pipe_error ret = PIPE_OK;
  184. ret = svga_hwtnl_flush( svga->hwtnl );
  185. if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
  186. svga_context_flush( svga, NULL );
  187. ret = svga_hwtnl_flush( svga->hwtnl );
  188. }
  189. assert(ret == 0);
  190. }
  191. struct svga_winsys_context *
  192. svga_winsys_context( struct pipe_context *pipe )
  193. {
  194. return svga_context( pipe )->swc;
  195. }