1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 **********************************************************/
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"
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"
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
);
53 static void svga_destroy( struct pipe_context
*pipe
)
55 struct svga_context
*svga
= svga_context( pipe
);
58 util_blitter_destroy(svga
->blitter
);
60 svga_cleanup_framebuffer( svga
);
61 svga_cleanup_tss_binding( svga
);
63 svga_hwtnl_destroy( svga
->hwtnl
);
65 svga_cleanup_vertex_state(svga
);
67 svga
->swc
->destroy(svga
->swc
);
69 svga_destroy_swtnl( svga
);
71 util_bitmask_destroy( svga
->shader_id_bm
);
73 for(shader
= 0; shader
< PIPE_SHADER_TYPES
; ++shader
)
74 pipe_resource_reference( &svga
->curr
.cb
[shader
], NULL
);
81 struct pipe_context
*svga_context_create( struct pipe_screen
*screen
,
84 struct svga_screen
*svgascreen
= svga_screen(screen
);
85 struct svga_context
*svga
= NULL
;
88 svga
= CALLOC_STRUCT(svga_context
);
92 svga
->pipe
.screen
= screen
;
93 svga
->pipe
.priv
= priv
;
94 svga
->pipe
.destroy
= svga_destroy
;
95 svga
->pipe
.clear
= svga_clear
;
97 svga
->swc
= svgascreen
->sws
->context_create(svgascreen
->sws
);
101 svga_init_resource_functions(svga
);
102 svga_init_blend_functions(svga
);
103 svga_init_blit_functions(svga
);
104 svga_init_depth_stencil_functions(svga
);
105 svga_init_draw_functions(svga
);
106 svga_init_flush_functions(svga
);
107 svga_init_misc_functions(svga
);
108 svga_init_rasterizer_functions(svga
);
109 svga_init_sampler_functions(svga
);
110 svga_init_fs_functions(svga
);
111 svga_init_vs_functions(svga
);
112 svga_init_vertex_functions(svga
);
113 svga_init_constbuffer_functions(svga
);
114 svga_init_query_functions(svga
);
115 svga_init_surface_functions(svga
);
119 svga
->debug
.no_swtnl
= debug_get_option_no_swtnl();
120 svga
->debug
.force_swtnl
= debug_get_option_force_swtnl();
121 svga
->debug
.use_min_mipmap
= debug_get_option_use_min_mipmap();
122 svga
->debug
.disable_shader
= debug_get_option_disable_shader();
123 svga
->debug
.no_line_width
= debug_get_option_no_line_width();
124 svga
->debug
.force_hw_line_stipple
= debug_get_option_force_hw_line_stipple();
126 svga
->shader_id_bm
= util_bitmask_create();
127 if (svga
->shader_id_bm
== NULL
)
130 svga
->hwtnl
= svga_hwtnl_create(svga
);
131 if (svga
->hwtnl
== NULL
)
134 if (!svga_init_swtnl(svga
))
137 ret
= svga_emit_initial_state( svga
);
141 /* Avoid shortcircuiting state with initial value of zero.
143 memset(&svga
->state
.hw_clear
, 0xcd, sizeof(svga
->state
.hw_clear
));
144 memset(&svga
->state
.hw_clear
.framebuffer
, 0x0,
145 sizeof(svga
->state
.hw_clear
.framebuffer
));
147 memset(&svga
->state
.hw_draw
, 0xcd, sizeof(svga
->state
.hw_draw
));
148 memset(&svga
->state
.hw_draw
.views
, 0x0, sizeof(svga
->state
.hw_draw
.views
));
149 svga
->state
.hw_draw
.num_views
= 0;
153 LIST_INITHEAD(&svga
->dirty_buffers
);
158 svga_destroy_swtnl(svga
);
160 svga_hwtnl_destroy( svga
->hwtnl
);
162 util_bitmask_destroy( svga
->shader_id_bm
);
164 svga
->swc
->destroy(svga
->swc
);
172 void svga_context_flush( struct svga_context
*svga
,
173 struct pipe_fence_handle
**pfence
)
175 struct svga_screen
*svgascreen
= svga_screen(svga
->pipe
.screen
);
176 struct pipe_fence_handle
*fence
= NULL
;
178 svga
->curr
.nr_fbs
= 0;
180 /* Ensure that texture dma uploads are processed
181 * before submitting commands.
183 svga_context_flush_buffers(svga
);
185 /* Flush pending commands to hardware:
187 svga
->swc
->flush(svga
->swc
, &fence
);
189 svga_screen_cache_flush(svgascreen
, fence
);
191 /* To force the re-emission of rendertargets and texture sampler bindings on
192 * the next command buffer.
194 svga
->rebind
.rendertargets
= TRUE
;
195 svga
->rebind
.texture_samplers
= TRUE
;
197 if (SVGA_DEBUG
& DEBUG_SYNC
) {
199 svga
->pipe
.screen
->fence_finish( svga
->pipe
.screen
, fence
,
200 PIPE_TIMEOUT_INFINITE
);
204 svgascreen
->sws
->fence_reference(svgascreen
->sws
, pfence
, fence
);
206 svgascreen
->sws
->fence_reference(svgascreen
->sws
, &fence
, NULL
);
210 void svga_hwtnl_flush_retry( struct svga_context
*svga
)
212 enum pipe_error ret
= PIPE_OK
;
214 ret
= svga_hwtnl_flush( svga
->hwtnl
);
215 if (ret
== PIPE_ERROR_OUT_OF_MEMORY
) {
216 svga_context_flush( svga
, NULL
);
217 ret
= svga_hwtnl_flush( svga
->hwtnl
);
225 * Flush the primitive queue if this buffer is referred.
227 * Otherwise DMA commands on the referred buffer will be emitted too late.
229 void svga_hwtnl_flush_buffer( struct svga_context
*svga
,
230 struct pipe_resource
*buffer
)
232 if (svga_hwtnl_is_buffer_referred(svga
->hwtnl
, buffer
)) {
233 svga_hwtnl_flush_retry(svga
);
238 /* Emit all operations pending on host surfaces.
240 void svga_surfaces_flush(struct svga_context
*svga
)
242 struct svga_screen
*svgascreen
= svga_screen(svga
->pipe
.screen
);
245 /* Emit buffered drawing commands.
247 svga_hwtnl_flush_retry( svga
);
249 /* Emit back-copy from render target view to texture.
251 for (i
= 0; i
< svgascreen
->max_color_buffers
; i
++) {
252 if (svga
->curr
.framebuffer
.cbufs
[i
])
253 svga_propagate_surface(svga
, svga
->curr
.framebuffer
.cbufs
[i
]);
256 if (svga
->curr
.framebuffer
.zsbuf
)
257 svga_propagate_surface(svga
, svga
->curr
.framebuffer
.zsbuf
);
262 struct svga_winsys_context
*
263 svga_winsys_context( struct pipe_context
*pipe
)
265 return svga_context( pipe
)->swc
;