1848b8605Smrg/********************************************************** 2848b8605Smrg * Copyright 2008-2009 VMware, Inc. All rights reserved. 3848b8605Smrg * 4848b8605Smrg * Permission is hereby granted, free of charge, to any person 5848b8605Smrg * obtaining a copy of this software and associated documentation 6848b8605Smrg * files (the "Software"), to deal in the Software without 7848b8605Smrg * restriction, including without limitation the rights to use, copy, 8848b8605Smrg * modify, merge, publish, distribute, sublicense, and/or sell copies 9848b8605Smrg * of the Software, and to permit persons to whom the Software is 10848b8605Smrg * furnished to do so, subject to the following conditions: 11848b8605Smrg * 12848b8605Smrg * The above copyright notice and this permission notice shall be 13848b8605Smrg * included in all copies or substantial portions of the Software. 14848b8605Smrg * 15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16848b8605Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18848b8605Smrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19848b8605Smrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20848b8605Smrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21848b8605Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22848b8605Smrg * SOFTWARE. 23848b8605Smrg * 24848b8605Smrg **********************************************************/ 25848b8605Smrg 26848b8605Smrg#include "svga_cmd.h" 27848b8605Smrg 28848b8605Smrg#include "pipe/p_defines.h" 29848b8605Smrg#include "util/u_inlines.h" 30848b8605Smrg#include "pipe/p_screen.h" 31848b8605Smrg#include "util/u_memory.h" 32848b8605Smrg#include "util/u_bitmask.h" 33b8e80941Smrg#include "util/u_upload_mgr.h" 34848b8605Smrg 35848b8605Smrg#include "svga_context.h" 36848b8605Smrg#include "svga_screen.h" 37848b8605Smrg#include "svga_surface.h" 38848b8605Smrg#include "svga_resource_texture.h" 39848b8605Smrg#include "svga_resource_buffer.h" 40848b8605Smrg#include "svga_resource.h" 41848b8605Smrg#include "svga_winsys.h" 42848b8605Smrg#include "svga_swtnl.h" 43848b8605Smrg#include "svga_draw.h" 44848b8605Smrg#include "svga_debug.h" 45848b8605Smrg#include "svga_state.h" 46b8e80941Smrg#include "svga_winsys.h" 47b8e80941Smrg 48b8e80941Smrg#define CONST0_UPLOAD_DEFAULT_SIZE 65536 49848b8605Smrg 50848b8605SmrgDEBUG_GET_ONCE_BOOL_OPTION(no_swtnl, "SVGA_NO_SWTNL", FALSE) 51848b8605SmrgDEBUG_GET_ONCE_BOOL_OPTION(force_swtnl, "SVGA_FORCE_SWTNL", FALSE); 52848b8605SmrgDEBUG_GET_ONCE_BOOL_OPTION(use_min_mipmap, "SVGA_USE_MIN_MIPMAP", FALSE); 53848b8605SmrgDEBUG_GET_ONCE_BOOL_OPTION(no_line_width, "SVGA_NO_LINE_WIDTH", FALSE); 54848b8605SmrgDEBUG_GET_ONCE_BOOL_OPTION(force_hw_line_stipple, "SVGA_FORCE_HW_LINE_STIPPLE", FALSE); 55848b8605Smrg 56b8e80941Smrg 57b8e80941Smrgstatic void 58b8e80941Smrgsvga_destroy(struct pipe_context *pipe) 59848b8605Smrg{ 60b8e80941Smrg struct svga_context *svga = svga_context(pipe); 61b8e80941Smrg unsigned shader, i; 62b8e80941Smrg 63b8e80941Smrg /* free any alternate rasterizer states used for point sprite */ 64b8e80941Smrg for (i = 0; i < ARRAY_SIZE(svga->rasterizer_no_cull); i++) { 65b8e80941Smrg if (svga->rasterizer_no_cull[i]) { 66b8e80941Smrg pipe->delete_rasterizer_state(pipe, svga->rasterizer_no_cull[i]); 67b8e80941Smrg } 68b8e80941Smrg } 69848b8605Smrg 70b8e80941Smrg /* free depthstencil_disable state */ 71b8e80941Smrg if (svga->depthstencil_disable) { 72b8e80941Smrg pipe->delete_depth_stencil_alpha_state(pipe, svga->depthstencil_disable); 73b8e80941Smrg } 74b8e80941Smrg 75b8e80941Smrg /* free HW constant buffers */ 76b8e80941Smrg for (shader = 0; shader < ARRAY_SIZE(svga->state.hw_draw.constbuf); shader++) { 77b8e80941Smrg pipe_resource_reference(&svga->state.hw_draw.constbuf[shader], NULL); 78b8e80941Smrg } 79848b8605Smrg 80b8e80941Smrg pipe->delete_blend_state(pipe, svga->noop_blend); 81848b8605Smrg 82b8e80941Smrg /* free query gb object */ 83b8e80941Smrg if (svga->gb_query) { 84b8e80941Smrg pipe->destroy_query(pipe, NULL); 85b8e80941Smrg svga->gb_query = NULL; 86b8e80941Smrg } 87b8e80941Smrg 88b8e80941Smrg util_blitter_destroy(svga->blitter); 89848b8605Smrg 90b8e80941Smrg svga_cleanup_sampler_state(svga); 91b8e80941Smrg svga_cleanup_framebuffer(svga); 92b8e80941Smrg svga_cleanup_tss_binding(svga); 93848b8605Smrg svga_cleanup_vertex_state(svga); 94848b8605Smrg 95b8e80941Smrg svga_destroy_swtnl(svga); 96b8e80941Smrg svga_hwtnl_destroy(svga->hwtnl); 97b8e80941Smrg 98b8e80941Smrg svga->swc->destroy(svga->swc); 99848b8605Smrg 100b8e80941Smrg util_bitmask_destroy(svga->blend_object_id_bm); 101b8e80941Smrg util_bitmask_destroy(svga->ds_object_id_bm); 102b8e80941Smrg util_bitmask_destroy(svga->input_element_object_id_bm); 103b8e80941Smrg util_bitmask_destroy(svga->rast_object_id_bm); 104b8e80941Smrg util_bitmask_destroy(svga->sampler_object_id_bm); 105b8e80941Smrg util_bitmask_destroy(svga->sampler_view_id_bm); 106b8e80941Smrg util_bitmask_destroy(svga->shader_id_bm); 107b8e80941Smrg util_bitmask_destroy(svga->surface_view_id_bm); 108b8e80941Smrg util_bitmask_destroy(svga->stream_output_id_bm); 109b8e80941Smrg util_bitmask_destroy(svga->query_id_bm); 110b8e80941Smrg u_upload_destroy(svga->const0_upload); 111b8e80941Smrg u_upload_destroy(svga->pipe.stream_uploader); 112b8e80941Smrg u_upload_destroy(svga->pipe.const_uploader); 113b8e80941Smrg svga_texture_transfer_map_upload_destroy(svga); 114b8e80941Smrg 115b8e80941Smrg /* free user's constant buffers */ 116848b8605Smrg for (shader = 0; shader < PIPE_SHADER_TYPES; ++shader) { 117b8e80941Smrg for (i = 0; i < ARRAY_SIZE(svga->curr.constbufs[shader]); ++i) { 118b8e80941Smrg pipe_resource_reference(&svga->curr.constbufs[shader][i].buffer, NULL); 119b8e80941Smrg } 120848b8605Smrg } 121848b8605Smrg 122b8e80941Smrg FREE(svga); 123848b8605Smrg} 124848b8605Smrg 125848b8605Smrg 126b8e80941Smrgstruct pipe_context * 127b8e80941Smrgsvga_context_create(struct pipe_screen *screen, void *priv, unsigned flags) 128848b8605Smrg{ 129848b8605Smrg struct svga_screen *svgascreen = svga_screen(screen); 130848b8605Smrg struct svga_context *svga = NULL; 131848b8605Smrg enum pipe_error ret; 132848b8605Smrg 133b8e80941Smrg SVGA_STATS_TIME_PUSH(svgascreen->sws, SVGA_STATS_TIME_CREATECONTEXT); 134b8e80941Smrg 135848b8605Smrg svga = CALLOC_STRUCT(svga_context); 136b8e80941Smrg if (!svga) 137b8e80941Smrg goto done; 138848b8605Smrg 139848b8605Smrg LIST_INITHEAD(&svga->dirty_buffers); 140848b8605Smrg 141848b8605Smrg svga->pipe.screen = screen; 142848b8605Smrg svga->pipe.priv = priv; 143848b8605Smrg svga->pipe.destroy = svga_destroy; 144b8e80941Smrg svga->pipe.stream_uploader = u_upload_create(&svga->pipe, 1024 * 1024, 145b8e80941Smrg PIPE_BIND_VERTEX_BUFFER | 146b8e80941Smrg PIPE_BIND_INDEX_BUFFER, 147b8e80941Smrg PIPE_USAGE_STREAM, 0); 148b8e80941Smrg if (!svga->pipe.stream_uploader) 149b8e80941Smrg goto cleanup; 150b8e80941Smrg 151b8e80941Smrg svga->pipe.const_uploader = u_upload_create(&svga->pipe, 128 * 1024, 152b8e80941Smrg PIPE_BIND_CONSTANT_BUFFER, 153b8e80941Smrg PIPE_USAGE_STREAM, 0); 154b8e80941Smrg if (!svga->pipe.const_uploader) 155b8e80941Smrg goto cleanup; 156848b8605Smrg 157848b8605Smrg svga->swc = svgascreen->sws->context_create(svgascreen->sws); 158b8e80941Smrg if (!svga->swc) 159b8e80941Smrg goto cleanup; 160848b8605Smrg 161848b8605Smrg svga_init_resource_functions(svga); 162848b8605Smrg svga_init_blend_functions(svga); 163848b8605Smrg svga_init_blit_functions(svga); 164848b8605Smrg svga_init_depth_stencil_functions(svga); 165848b8605Smrg svga_init_draw_functions(svga); 166848b8605Smrg svga_init_flush_functions(svga); 167848b8605Smrg svga_init_misc_functions(svga); 168848b8605Smrg svga_init_rasterizer_functions(svga); 169848b8605Smrg svga_init_sampler_functions(svga); 170848b8605Smrg svga_init_fs_functions(svga); 171848b8605Smrg svga_init_vs_functions(svga); 172b8e80941Smrg svga_init_gs_functions(svga); 173848b8605Smrg svga_init_vertex_functions(svga); 174848b8605Smrg svga_init_constbuffer_functions(svga); 175848b8605Smrg svga_init_query_functions(svga); 176848b8605Smrg svga_init_surface_functions(svga); 177b8e80941Smrg svga_init_stream_output_functions(svga); 178b8e80941Smrg svga_init_clear_functions(svga); 179848b8605Smrg 180b8e80941Smrg /* init misc state */ 181b8e80941Smrg svga->curr.sample_mask = ~0; 182848b8605Smrg 183848b8605Smrg /* debug */ 184848b8605Smrg svga->debug.no_swtnl = debug_get_option_no_swtnl(); 185848b8605Smrg svga->debug.force_swtnl = debug_get_option_force_swtnl(); 186848b8605Smrg svga->debug.use_min_mipmap = debug_get_option_use_min_mipmap(); 187848b8605Smrg svga->debug.no_line_width = debug_get_option_no_line_width(); 188848b8605Smrg svga->debug.force_hw_line_stipple = debug_get_option_force_hw_line_stipple(); 189848b8605Smrg 190b8e80941Smrg if (!(svga->blend_object_id_bm = util_bitmask_create())) 191b8e80941Smrg goto cleanup; 192b8e80941Smrg 193b8e80941Smrg if (!(svga->ds_object_id_bm = util_bitmask_create())) 194b8e80941Smrg goto cleanup; 195b8e80941Smrg 196b8e80941Smrg if (!(svga->input_element_object_id_bm = util_bitmask_create())) 197b8e80941Smrg goto cleanup; 198b8e80941Smrg 199b8e80941Smrg if (!(svga->rast_object_id_bm = util_bitmask_create())) 200b8e80941Smrg goto cleanup; 201b8e80941Smrg 202b8e80941Smrg if (!(svga->sampler_object_id_bm = util_bitmask_create())) 203b8e80941Smrg goto cleanup; 204b8e80941Smrg 205b8e80941Smrg if (!(svga->sampler_view_id_bm = util_bitmask_create())) 206b8e80941Smrg goto cleanup; 207b8e80941Smrg 208b8e80941Smrg if (!(svga->shader_id_bm = util_bitmask_create())) 209b8e80941Smrg goto cleanup; 210b8e80941Smrg 211b8e80941Smrg if (!(svga->surface_view_id_bm = util_bitmask_create())) 212b8e80941Smrg goto cleanup; 213b8e80941Smrg 214b8e80941Smrg if (!(svga->stream_output_id_bm = util_bitmask_create())) 215b8e80941Smrg goto cleanup; 216b8e80941Smrg 217b8e80941Smrg if (!(svga->query_id_bm = util_bitmask_create())) 218b8e80941Smrg goto cleanup; 219848b8605Smrg 220848b8605Smrg svga->hwtnl = svga_hwtnl_create(svga); 221848b8605Smrg if (svga->hwtnl == NULL) 222b8e80941Smrg goto cleanup; 223848b8605Smrg 224848b8605Smrg if (!svga_init_swtnl(svga)) 225b8e80941Smrg goto cleanup; 226848b8605Smrg 227b8e80941Smrg ret = svga_emit_initial_state(svga); 228848b8605Smrg if (ret != PIPE_OK) 229b8e80941Smrg goto cleanup; 230b8e80941Smrg 231b8e80941Smrg svga->const0_upload = u_upload_create(&svga->pipe, 232b8e80941Smrg CONST0_UPLOAD_DEFAULT_SIZE, 233b8e80941Smrg PIPE_BIND_CONSTANT_BUFFER | 234b8e80941Smrg PIPE_BIND_CUSTOM, 235b8e80941Smrg PIPE_USAGE_STREAM, 0); 236b8e80941Smrg if (!svga->const0_upload) 237b8e80941Smrg goto cleanup; 238b8e80941Smrg 239b8e80941Smrg if (!svga_texture_transfer_map_upload_create(svga)) 240b8e80941Smrg goto cleanup; 241b8e80941Smrg 242848b8605Smrg /* Avoid shortcircuiting state with initial value of zero. 243848b8605Smrg */ 244848b8605Smrg memset(&svga->state.hw_clear, 0xcd, sizeof(svga->state.hw_clear)); 245b8e80941Smrg memset(&svga->state.hw_clear.framebuffer, 0x0, 246848b8605Smrg sizeof(svga->state.hw_clear.framebuffer)); 247b8e80941Smrg svga->state.hw_clear.num_rendertargets = 0; 248b8e80941Smrg svga->state.hw_clear.dsv = NULL; 249848b8605Smrg 250848b8605Smrg memset(&svga->state.hw_draw, 0xcd, sizeof(svga->state.hw_draw)); 251848b8605Smrg memset(&svga->state.hw_draw.views, 0x0, sizeof(svga->state.hw_draw.views)); 252b8e80941Smrg memset(&svga->state.hw_draw.num_samplers, 0, 253b8e80941Smrg sizeof(svga->state.hw_draw.num_samplers)); 254b8e80941Smrg memset(&svga->state.hw_draw.num_sampler_views, 0, 255b8e80941Smrg sizeof(svga->state.hw_draw.num_sampler_views)); 256b8e80941Smrg memset(svga->state.hw_draw.sampler_views, 0, 257b8e80941Smrg sizeof(svga->state.hw_draw.sampler_views)); 258848b8605Smrg svga->state.hw_draw.num_views = 0; 259b8e80941Smrg svga->state.hw_draw.num_backed_views = 0; 260b8e80941Smrg svga->state.hw_draw.rasterizer_discard = FALSE; 261b8e80941Smrg 262b8e80941Smrg /* Initialize the shader pointers */ 263b8e80941Smrg svga->state.hw_draw.vs = NULL; 264b8e80941Smrg svga->state.hw_draw.gs = NULL; 265b8e80941Smrg svga->state.hw_draw.fs = NULL; 266b8e80941Smrg 267b8e80941Smrg /* Initialize the currently bound buffer resources */ 268b8e80941Smrg memset(svga->state.hw_draw.constbuf, 0, 269b8e80941Smrg sizeof(svga->state.hw_draw.constbuf)); 270b8e80941Smrg memset(svga->state.hw_draw.default_constbuf_size, 0, 271b8e80941Smrg sizeof(svga->state.hw_draw.default_constbuf_size)); 272b8e80941Smrg memset(svga->state.hw_draw.enabled_constbufs, 0, 273b8e80941Smrg sizeof(svga->state.hw_draw.enabled_constbufs)); 274b8e80941Smrg svga->state.hw_draw.ib = NULL; 275b8e80941Smrg svga->state.hw_draw.num_vbuffers = 0; 276b8e80941Smrg memset(svga->state.hw_draw.vbuffers, 0, 277b8e80941Smrg sizeof(svga->state.hw_draw.vbuffers)); 278b8e80941Smrg svga->state.hw_draw.const0_buffer = NULL; 279b8e80941Smrg svga->state.hw_draw.const0_handle = NULL; 280b8e80941Smrg 281b8e80941Smrg /* Create a no-operation blend state which we will bind whenever the 282b8e80941Smrg * requested blend state is impossible (e.g. due to having an integer 283b8e80941Smrg * render target attached). 284b8e80941Smrg * 285b8e80941Smrg * XXX: We will probably actually need 16 of these, one for each possible 286b8e80941Smrg * RGBA color mask (4 bits). Then, we would bind the one with a color mask 287b8e80941Smrg * matching the blend state it is replacing. 288b8e80941Smrg */ 289b8e80941Smrg { 290b8e80941Smrg struct pipe_blend_state noop_tmpl = {0}; 291b8e80941Smrg unsigned i; 292b8e80941Smrg 293b8e80941Smrg for (i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) { 294b8e80941Smrg // Set the color mask to all-ones. Later this may change. 295b8e80941Smrg noop_tmpl.rt[i].colormask = PIPE_MASK_RGBA; 296b8e80941Smrg } 297b8e80941Smrg svga->noop_blend = svga->pipe.create_blend_state(&svga->pipe, &noop_tmpl); 298b8e80941Smrg } 299848b8605Smrg 300848b8605Smrg svga->dirty = ~0; 301b8e80941Smrg svga->pred.query_id = SVGA3D_INVALID_ID; 302b8e80941Smrg svga->disable_rasterizer = FALSE; 303848b8605Smrg 304b8e80941Smrg goto done; 305848b8605Smrg 306b8e80941Smrgcleanup: 307848b8605Smrg svga_destroy_swtnl(svga); 308b8e80941Smrg 309b8e80941Smrg if (svga->const0_upload) 310b8e80941Smrg u_upload_destroy(svga->const0_upload); 311b8e80941Smrg if (svga->pipe.const_uploader) 312b8e80941Smrg u_upload_destroy(svga->pipe.const_uploader); 313b8e80941Smrg if (svga->pipe.stream_uploader) 314b8e80941Smrg u_upload_destroy(svga->pipe.stream_uploader); 315b8e80941Smrg svga_texture_transfer_map_upload_destroy(svga); 316b8e80941Smrg if (svga->hwtnl) 317b8e80941Smrg svga_hwtnl_destroy(svga->hwtnl); 318b8e80941Smrg if (svga->swc) 319b8e80941Smrg svga->swc->destroy(svga->swc); 320b8e80941Smrg util_bitmask_destroy(svga->blend_object_id_bm); 321b8e80941Smrg util_bitmask_destroy(svga->ds_object_id_bm); 322b8e80941Smrg util_bitmask_destroy(svga->input_element_object_id_bm); 323b8e80941Smrg util_bitmask_destroy(svga->rast_object_id_bm); 324b8e80941Smrg util_bitmask_destroy(svga->sampler_object_id_bm); 325b8e80941Smrg util_bitmask_destroy(svga->sampler_view_id_bm); 326b8e80941Smrg util_bitmask_destroy(svga->shader_id_bm); 327b8e80941Smrg util_bitmask_destroy(svga->surface_view_id_bm); 328b8e80941Smrg util_bitmask_destroy(svga->stream_output_id_bm); 329b8e80941Smrg util_bitmask_destroy(svga->query_id_bm); 330848b8605Smrg FREE(svga); 331b8e80941Smrg svga = NULL; 332b8e80941Smrg 333b8e80941Smrgdone: 334b8e80941Smrg SVGA_STATS_TIME_POP(svgascreen->sws); 335b8e80941Smrg return svga ? &svga->pipe:NULL; 336848b8605Smrg} 337848b8605Smrg 338848b8605Smrg 339b8e80941Smrgvoid 340b8e80941Smrgsvga_context_flush(struct svga_context *svga, 341b8e80941Smrg struct pipe_fence_handle **pfence) 342848b8605Smrg{ 343848b8605Smrg struct svga_screen *svgascreen = svga_screen(svga->pipe.screen); 344848b8605Smrg struct pipe_fence_handle *fence = NULL; 345b8e80941Smrg uint64_t t0; 346b8e80941Smrg 347b8e80941Smrg SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CONTEXTFLUSH); 348848b8605Smrg 349848b8605Smrg svga->curr.nr_fbs = 0; 350848b8605Smrg 351b8e80941Smrg /* Unmap the 0th/default constant buffer. The u_upload_unmap() function 352b8e80941Smrg * will call pipe_context::transfer_flush_region() to indicate the 353b8e80941Smrg * region of the buffer which was modified (and needs to be uploaded). 354b8e80941Smrg */ 355b8e80941Smrg if (svga->state.hw_draw.const0_handle) { 356b8e80941Smrg assert(svga->state.hw_draw.const0_buffer); 357b8e80941Smrg u_upload_unmap(svga->const0_upload); 358b8e80941Smrg pipe_resource_reference(&svga->state.hw_draw.const0_buffer, NULL); 359b8e80941Smrg svga->state.hw_draw.const0_handle = NULL; 360b8e80941Smrg } 361b8e80941Smrg 362848b8605Smrg /* Ensure that texture dma uploads are processed 363848b8605Smrg * before submitting commands. 364848b8605Smrg */ 365848b8605Smrg svga_context_flush_buffers(svga); 366848b8605Smrg 367b8e80941Smrg svga->hud.command_buffer_size += 368b8e80941Smrg svga->swc->get_command_buffer_size(svga->swc); 369b8e80941Smrg 370848b8605Smrg /* Flush pending commands to hardware: 371848b8605Smrg */ 372b8e80941Smrg t0 = svga_get_time(svga); 373848b8605Smrg svga->swc->flush(svga->swc, &fence); 374b8e80941Smrg svga->hud.flush_time += (svga_get_time(svga) - t0); 375848b8605Smrg 376b8e80941Smrg svga->hud.num_flushes++; 377b8e80941Smrg 378b8e80941Smrg svga_screen_cache_flush(svgascreen, svga, fence); 379b8e80941Smrg 380b8e80941Smrg SVGA3D_ResetLastCommand(svga->swc); 381848b8605Smrg 382848b8605Smrg /* To force the re-emission of rendertargets and texture sampler bindings on 383848b8605Smrg * the next command buffer. 384848b8605Smrg */ 385b8e80941Smrg svga->rebind.flags.rendertargets = TRUE; 386b8e80941Smrg svga->rebind.flags.texture_samplers = TRUE; 387b8e80941Smrg 388848b8605Smrg if (svga_have_gb_objects(svga)) { 389b8e80941Smrg 390b8e80941Smrg svga->rebind.flags.constbufs = TRUE; 391b8e80941Smrg svga->rebind.flags.vs = TRUE; 392b8e80941Smrg svga->rebind.flags.fs = TRUE; 393b8e80941Smrg svga->rebind.flags.gs = TRUE; 394b8e80941Smrg 395b8e80941Smrg if (svga_need_to_rebind_resources(svga)) { 396b8e80941Smrg svga->rebind.flags.query = TRUE; 397b8e80941Smrg } 398848b8605Smrg } 399848b8605Smrg 400848b8605Smrg if (SVGA_DEBUG & DEBUG_SYNC) { 401848b8605Smrg if (fence) 402b8e80941Smrg svga->pipe.screen->fence_finish(svga->pipe.screen, NULL, fence, 403848b8605Smrg PIPE_TIMEOUT_INFINITE); 404848b8605Smrg } 405848b8605Smrg 406b8e80941Smrg if (pfence) 407848b8605Smrg svgascreen->sws->fence_reference(svgascreen->sws, pfence, fence); 408848b8605Smrg 409848b8605Smrg svgascreen->sws->fence_reference(svgascreen->sws, &fence, NULL); 410b8e80941Smrg 411b8e80941Smrg SVGA_STATS_TIME_POP(svga_sws(svga)); 412848b8605Smrg} 413848b8605Smrg 414848b8605Smrg 415b8e80941Smrg/** 416b8e80941Smrg * Flush pending commands and wait for completion with a fence. 417b8e80941Smrg */ 418b8e80941Smrgvoid 419b8e80941Smrgsvga_context_finish(struct svga_context *svga) 420b8e80941Smrg{ 421b8e80941Smrg struct pipe_screen *screen = svga->pipe.screen; 422b8e80941Smrg struct pipe_fence_handle *fence = NULL; 423b8e80941Smrg 424b8e80941Smrg SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CONTEXTFINISH); 425b8e80941Smrg 426b8e80941Smrg svga_context_flush(svga, &fence); 427b8e80941Smrg screen->fence_finish(screen, NULL, fence, PIPE_TIMEOUT_INFINITE); 428b8e80941Smrg screen->fence_reference(screen, &fence, NULL); 429b8e80941Smrg 430b8e80941Smrg SVGA_STATS_TIME_POP(svga_sws(svga)); 431b8e80941Smrg} 432b8e80941Smrg 433b8e80941Smrg 434b8e80941Smrg/** 435b8e80941Smrg * Emit pending drawing commands to the command buffer. 436b8e80941Smrg * If the command buffer overflows, we flush it and retry. 437b8e80941Smrg * \sa svga_hwtnl_flush() 438b8e80941Smrg */ 439b8e80941Smrgvoid 440b8e80941Smrgsvga_hwtnl_flush_retry(struct svga_context *svga) 441848b8605Smrg{ 442848b8605Smrg enum pipe_error ret = PIPE_OK; 443848b8605Smrg 444b8e80941Smrg ret = svga_hwtnl_flush(svga->hwtnl); 445848b8605Smrg if (ret == PIPE_ERROR_OUT_OF_MEMORY) { 446b8e80941Smrg svga_context_flush(svga, NULL); 447b8e80941Smrg ret = svga_hwtnl_flush(svga->hwtnl); 448848b8605Smrg } 449848b8605Smrg 450b8e80941Smrg assert(ret == PIPE_OK); 451848b8605Smrg} 452848b8605Smrg 453848b8605Smrg 454848b8605Smrg/** 455848b8605Smrg * Flush the primitive queue if this buffer is referred. 456848b8605Smrg * 457848b8605Smrg * Otherwise DMA commands on the referred buffer will be emitted too late. 458848b8605Smrg */ 459b8e80941Smrgvoid 460b8e80941Smrgsvga_hwtnl_flush_buffer(struct svga_context *svga, 461b8e80941Smrg struct pipe_resource *buffer) 462848b8605Smrg{ 463848b8605Smrg if (svga_hwtnl_is_buffer_referred(svga->hwtnl, buffer)) { 464848b8605Smrg svga_hwtnl_flush_retry(svga); 465848b8605Smrg } 466848b8605Smrg} 467848b8605Smrg 468848b8605Smrg 469b8e80941Smrg/** 470b8e80941Smrg * Emit all operations pending on host surfaces. 471b8e80941Smrg */ 472b8e80941Smrgvoid 473b8e80941Smrgsvga_surfaces_flush(struct svga_context *svga) 474848b8605Smrg{ 475b8e80941Smrg SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_SURFACEFLUSH); 476848b8605Smrg 477848b8605Smrg /* Emit buffered drawing commands. 478848b8605Smrg */ 479b8e80941Smrg svga_hwtnl_flush_retry(svga); 480848b8605Smrg 481b8e80941Smrg /* Emit back-copy from render target views to textures. 482848b8605Smrg */ 483b8e80941Smrg svga_propagate_rendertargets(svga); 484848b8605Smrg 485b8e80941Smrg SVGA_STATS_TIME_POP(svga_sws(svga)); 486848b8605Smrg} 487848b8605Smrg 488848b8605Smrg 489848b8605Smrgstruct svga_winsys_context * 490b8e80941Smrgsvga_winsys_context(struct pipe_context *pipe) 491848b8605Smrg{ 492b8e80941Smrg return svga_context(pipe)->swc; 493848b8605Smrg} 494