Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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.  
  26. #include "svga_cmd.h"
  27.  
  28. #include "pipe/p_defines.h"
  29. #include "util/u_inlines.h"
  30. #include "pipe/p_screen.h"
  31. #include "util/u_memory.h"
  32. #include "util/u_bitmask.h"
  33.  
  34. #include "svga_context.h"
  35. #include "svga_screen.h"
  36. #include "svga_surface.h"
  37. #include "svga_resource_texture.h"
  38. #include "svga_resource_buffer.h"
  39. #include "svga_resource.h"
  40. #include "svga_winsys.h"
  41. #include "svga_swtnl.h"
  42. #include "svga_draw.h"
  43. #include "svga_debug.h"
  44. #include "svga_state.h"
  45.  
  46. DEBUG_GET_ONCE_BOOL_OPTION(no_swtnl, "SVGA_NO_SWTNL", FALSE)
  47. DEBUG_GET_ONCE_BOOL_OPTION(force_swtnl, "SVGA_FORCE_SWTNL", FALSE);
  48. DEBUG_GET_ONCE_BOOL_OPTION(use_min_mipmap, "SVGA_USE_MIN_MIPMAP", FALSE);
  49. DEBUG_GET_ONCE_NUM_OPTION(disable_shader, "SVGA_DISABLE_SHADER", ~0);
  50. DEBUG_GET_ONCE_BOOL_OPTION(no_line_width, "SVGA_NO_LINE_WIDTH", FALSE);
  51. DEBUG_GET_ONCE_BOOL_OPTION(force_hw_line_stipple, "SVGA_FORCE_HW_LINE_STIPPLE", FALSE);
  52.  
  53. static void svga_destroy( struct pipe_context *pipe )
  54. {
  55.    struct svga_context *svga = svga_context( pipe );
  56.    struct svga_winsys_screen *sws = svga_screen(pipe->screen)->sws;
  57.    unsigned shader;
  58.  
  59.    util_blitter_destroy(svga->blitter);
  60.  
  61.    svga_cleanup_framebuffer( svga );
  62.    svga_cleanup_tss_binding( svga );
  63.  
  64.    svga_hwtnl_destroy( svga->hwtnl );
  65.  
  66.    svga_cleanup_vertex_state(svga);
  67.    
  68.    svga->swc->destroy(svga->swc);
  69.    
  70.    svga_destroy_swtnl( svga );
  71.  
  72.    util_bitmask_destroy( svga->shader_id_bm );
  73.  
  74.    for (shader = 0; shader < PIPE_SHADER_TYPES; ++shader) {
  75.       pipe_resource_reference( &svga->curr.cbufs[shader].buffer, NULL );
  76.       sws->surface_reference(sws, &svga->state.hw_draw.hw_cb[shader], NULL);
  77.    }
  78.  
  79.    FREE( svga );
  80. }
  81.  
  82.  
  83.  
  84. struct pipe_context *svga_context_create( struct pipe_screen *screen,
  85.                                           void *priv )
  86. {
  87.    struct svga_screen *svgascreen = svga_screen(screen);
  88.    struct svga_context *svga = NULL;
  89.    enum pipe_error ret;
  90.  
  91.    svga = CALLOC_STRUCT(svga_context);
  92.    if (svga == NULL)
  93.       goto no_svga;
  94.  
  95.    LIST_INITHEAD(&svga->dirty_buffers);
  96.  
  97.    svga->pipe.screen = screen;
  98.    svga->pipe.priv = priv;
  99.    svga->pipe.destroy = svga_destroy;
  100.    svga->pipe.clear = svga_clear;
  101.  
  102.    svga->swc = svgascreen->sws->context_create(svgascreen->sws);
  103.    if(!svga->swc)
  104.       goto no_swc;
  105.  
  106.    svga_init_resource_functions(svga);
  107.    svga_init_blend_functions(svga);
  108.    svga_init_blit_functions(svga);
  109.    svga_init_depth_stencil_functions(svga);
  110.    svga_init_draw_functions(svga);
  111.    svga_init_flush_functions(svga);
  112.    svga_init_misc_functions(svga);
  113.    svga_init_rasterizer_functions(svga);
  114.    svga_init_sampler_functions(svga);
  115.    svga_init_fs_functions(svga);
  116.    svga_init_vs_functions(svga);
  117.    svga_init_vertex_functions(svga);
  118.    svga_init_constbuffer_functions(svga);
  119.    svga_init_query_functions(svga);
  120.    svga_init_surface_functions(svga);
  121.  
  122.  
  123.    /* debug */
  124.    svga->debug.no_swtnl = debug_get_option_no_swtnl();
  125.    svga->debug.force_swtnl = debug_get_option_force_swtnl();
  126.    svga->debug.use_min_mipmap = debug_get_option_use_min_mipmap();
  127.    svga->debug.disable_shader = debug_get_option_disable_shader();
  128.    svga->debug.no_line_width = debug_get_option_no_line_width();
  129.    svga->debug.force_hw_line_stipple = debug_get_option_force_hw_line_stipple();
  130.  
  131.    svga->shader_id_bm = util_bitmask_create();
  132.    if (svga->shader_id_bm == NULL)
  133.       goto no_shader_bm;
  134.  
  135.    svga->hwtnl = svga_hwtnl_create(svga);
  136.    if (svga->hwtnl == NULL)
  137.       goto no_hwtnl;
  138.  
  139.    if (!svga_init_swtnl(svga))
  140.       goto no_swtnl;
  141.  
  142.    ret = svga_emit_initial_state( svga );
  143.    if (ret != PIPE_OK)
  144.       goto no_state;
  145.    
  146.    /* Avoid shortcircuiting state with initial value of zero.
  147.     */
  148.    memset(&svga->state.hw_clear, 0xcd, sizeof(svga->state.hw_clear));
  149.    memset(&svga->state.hw_clear.framebuffer, 0x0,
  150.           sizeof(svga->state.hw_clear.framebuffer));
  151.  
  152.    memset(&svga->state.hw_draw, 0xcd, sizeof(svga->state.hw_draw));
  153.    memset(&svga->state.hw_draw.views, 0x0, sizeof(svga->state.hw_draw.views));
  154.    svga->state.hw_draw.num_views = 0;
  155.    memset(&svga->state.hw_draw.hw_cb, 0x0, sizeof(svga->state.hw_draw.hw_cb));
  156.  
  157.    svga->dirty = ~0;
  158.  
  159.    return &svga->pipe;
  160.  
  161. no_state:
  162.    svga_destroy_swtnl(svga);
  163. no_swtnl:
  164.    svga_hwtnl_destroy( svga->hwtnl );
  165. no_hwtnl:
  166.    util_bitmask_destroy( svga->shader_id_bm );
  167. no_shader_bm:
  168.    svga->swc->destroy(svga->swc);
  169. no_swc:
  170.    FREE(svga);
  171. no_svga:
  172.    return NULL;
  173. }
  174.  
  175.  
  176. void svga_context_flush( struct svga_context *svga,
  177.                          struct pipe_fence_handle **pfence )
  178. {
  179.    struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
  180.    struct pipe_fence_handle *fence = NULL;
  181.  
  182.    svga->curr.nr_fbs = 0;
  183.  
  184.    /* Ensure that texture dma uploads are processed
  185.     * before submitting commands.
  186.     */
  187.    svga_context_flush_buffers(svga);
  188.  
  189.    /* Flush pending commands to hardware:
  190.     */
  191.    svga->swc->flush(svga->swc, &fence);
  192.  
  193.    svga_screen_cache_flush(svgascreen, fence);
  194.  
  195.    /* To force the re-emission of rendertargets and texture sampler bindings on
  196.     * the next command buffer.
  197.     */
  198.    svga->rebind.rendertargets = TRUE;
  199.    svga->rebind.texture_samplers = TRUE;
  200.    if (svga_have_gb_objects(svga)) {
  201.       svga->rebind.vs = TRUE;
  202.       svga->rebind.fs = TRUE;
  203.    }
  204.  
  205.    if (SVGA_DEBUG & DEBUG_SYNC) {
  206.       if (fence)
  207.          svga->pipe.screen->fence_finish( svga->pipe.screen, fence,
  208.                                           PIPE_TIMEOUT_INFINITE);
  209.    }
  210.  
  211.    if(pfence)
  212.       svgascreen->sws->fence_reference(svgascreen->sws, pfence, fence);
  213.  
  214.    svgascreen->sws->fence_reference(svgascreen->sws, &fence, NULL);
  215. }
  216.  
  217.  
  218. void svga_hwtnl_flush_retry( struct svga_context *svga )
  219. {
  220.    enum pipe_error ret = PIPE_OK;
  221.  
  222.    ret = svga_hwtnl_flush( svga->hwtnl );
  223.    if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
  224.       svga_context_flush( svga, NULL );
  225.       ret = svga_hwtnl_flush( svga->hwtnl );
  226.    }
  227.  
  228.    assert(ret == 0);
  229. }
  230.  
  231.  
  232. /**
  233.  * Flush the primitive queue if this buffer is referred.
  234.  *
  235.  * Otherwise DMA commands on the referred buffer will be emitted too late.
  236.  */
  237. void svga_hwtnl_flush_buffer( struct svga_context *svga,
  238.                               struct pipe_resource *buffer )
  239. {
  240.    if (svga_hwtnl_is_buffer_referred(svga->hwtnl, buffer)) {
  241.       svga_hwtnl_flush_retry(svga);
  242.    }
  243. }
  244.  
  245.  
  246. /* Emit all operations pending on host surfaces.
  247.  */
  248. void svga_surfaces_flush(struct svga_context *svga)
  249. {
  250.    struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
  251.    unsigned i;
  252.  
  253.    /* Emit buffered drawing commands.
  254.     */
  255.    svga_hwtnl_flush_retry( svga );
  256.  
  257.    /* Emit back-copy from render target view to texture.
  258.     */
  259.    for (i = 0; i < svgascreen->max_color_buffers; i++) {
  260.       if (svga->curr.framebuffer.cbufs[i])
  261.          svga_propagate_surface(svga, svga->curr.framebuffer.cbufs[i]);
  262.    }
  263.  
  264.    if (svga->curr.framebuffer.zsbuf)
  265.       svga_propagate_surface(svga, svga->curr.framebuffer.zsbuf);
  266.  
  267. }
  268.  
  269.  
  270. struct svga_winsys_context *
  271. svga_winsys_context( struct pipe_context *pipe )
  272. {
  273.    return svga_context( pipe )->swc;
  274. }
  275.