blob: 8640da95e82b9e7ec16db12bec5a7ed23c1e84b9 [file] [log] [blame]
Jakob Bornecrantz31926332009-11-16 19:56:18 +01001/**********************************************************
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"
José Fonseca28486882010-02-02 14:42:17 +000029#include "util/u_inlines.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010030#include "pipe/p_screen.h"
31#include "util/u_memory.h"
José Fonsecacdb445f2010-01-03 00:47:30 +000032#include "util/u_bitmask.h"
Brian Paule0542512015-08-13 11:00:58 -070033#include "util/u_upload_mgr.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010034
35#include "svga_context.h"
36#include "svga_screen.h"
José Fonseca0ced7892011-02-18 14:33:55 +000037#include "svga_surface.h"
Keith Whitwell287c94e2010-04-10 16:05:54 +010038#include "svga_resource_texture.h"
39#include "svga_resource_buffer.h"
40#include "svga_resource.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010041#include "svga_winsys.h"
42#include "svga_swtnl.h"
43#include "svga_draw.h"
44#include "svga_debug.h"
45#include "svga_state.h"
Brian Paule0542512015-08-13 11:00:58 -070046#include "svga_winsys.h"
47
48#define CONST0_UPLOAD_DEFAULT_SIZE 65536
Jakob Bornecrantz31926332009-11-16 19:56:18 +010049
Jakob Bornecrantzdaaf5422010-12-29 09:59:28 +010050DEBUG_GET_ONCE_BOOL_OPTION(no_swtnl, "SVGA_NO_SWTNL", FALSE)
51DEBUG_GET_ONCE_BOOL_OPTION(force_swtnl, "SVGA_FORCE_SWTNL", FALSE);
52DEBUG_GET_ONCE_BOOL_OPTION(use_min_mipmap, "SVGA_USE_MIN_MIPMAP", FALSE);
Jakob Bornecrantzc523f312010-12-29 12:50:59 +010053DEBUG_GET_ONCE_BOOL_OPTION(no_line_width, "SVGA_NO_LINE_WIDTH", FALSE);
54DEBUG_GET_ONCE_BOOL_OPTION(force_hw_line_stipple, "SVGA_FORCE_HW_LINE_STIPPLE", FALSE);
Jakob Bornecrantz31926332009-11-16 19:56:18 +010055
Brian Paulc96f63c2016-11-01 08:17:05 -060056
57static void
58svga_destroy(struct pipe_context *pipe)
Jakob Bornecrantz31926332009-11-16 19:56:18 +010059{
Brian Paulc96f63c2016-11-01 08:17:05 -060060 struct svga_context *svga = svga_context(pipe);
Brian Paule0542512015-08-13 11:00:58 -070061 unsigned shader, i;
62
63 /* free any alternate rasterizer states used for point sprite */
Brian Paule0184b32016-04-25 09:34:40 -060064 for (i = 0; i < ARRAY_SIZE(svga->rasterizer_no_cull); i++) {
Brian Paule0542512015-08-13 11:00:58 -070065 if (svga->rasterizer_no_cull[i]) {
66 pipe->delete_rasterizer_state(pipe, svga->rasterizer_no_cull[i]);
67 }
68 }
69
Charmaine Leeb4c4ee02017-04-04 12:47:49 -060070 /* free depthstencil_disable state */
71 if (svga->depthstencil_disable) {
72 pipe->delete_depth_stencil_alpha_state(pipe, svga->depthstencil_disable);
73 }
74
Brian Paule0542512015-08-13 11:00:58 -070075 /* free HW constant buffers */
Brian Paule0184b32016-04-25 09:34:40 -060076 for (shader = 0; shader < ARRAY_SIZE(svga->state.hw_draw.constbuf); shader++) {
Brian Paule0542512015-08-13 11:00:58 -070077 pipe_resource_reference(&svga->state.hw_draw.constbuf[shader], NULL);
78 }
79
80 pipe->delete_blend_state(pipe, svga->noop_blend);
81
82 /* free query gb object */
83 if (svga->gb_query) {
84 pipe->destroy_query(pipe, NULL);
85 svga->gb_query = NULL;
86 }
Jakob Bornecrantz31926332009-11-16 19:56:18 +010087
Marek Olšákad3d5db2012-09-13 00:50:54 +020088 util_blitter_destroy(svga->blitter);
89
Charmaine Lee5313b292016-08-17 14:53:38 -070090 svga_cleanup_sampler_state(svga);
Brian Paulc96f63c2016-11-01 08:17:05 -060091 svga_cleanup_framebuffer(svga);
92 svga_cleanup_tss_binding(svga);
Jakob Bornecrantz31926332009-11-16 19:56:18 +010093 svga_cleanup_vertex_state(svga);
Brian Paulc96f63c2016-11-01 08:17:05 -060094
95 svga_destroy_swtnl(svga);
96 svga_hwtnl_destroy(svga->hwtnl);
Jakob Bornecrantz31926332009-11-16 19:56:18 +010097
Brian Paule0542512015-08-13 11:00:58 -070098 svga->swc->destroy(svga->swc);
José Fonsecacdb445f2010-01-03 00:47:30 +000099
Brian Paule0542512015-08-13 11:00:58 -0700100 util_bitmask_destroy(svga->blend_object_id_bm);
101 util_bitmask_destroy(svga->ds_object_id_bm);
102 util_bitmask_destroy(svga->input_element_object_id_bm);
103 util_bitmask_destroy(svga->rast_object_id_bm);
104 util_bitmask_destroy(svga->sampler_object_id_bm);
105 util_bitmask_destroy(svga->sampler_view_id_bm);
106 util_bitmask_destroy(svga->shader_id_bm);
107 util_bitmask_destroy(svga->surface_view_id_bm);
108 util_bitmask_destroy(svga->stream_output_id_bm);
109 util_bitmask_destroy(svga->query_id_bm);
110 u_upload_destroy(svga->const0_upload);
Marek Olšák55ad59d2017-01-27 00:12:37 +0100111 u_upload_destroy(svga->pipe.stream_uploader);
112 u_upload_destroy(svga->pipe.const_uploader);
Charmaine Leef1b33742016-09-06 11:29:41 -0700113 svga_texture_transfer_map_upload_destroy(svga);
Brian Paule0542512015-08-13 11:00:58 -0700114
115 /* free user's constant buffers */
Brian Paul2f1fc8d2014-02-08 09:51:14 -0800116 for (shader = 0; shader < PIPE_SHADER_TYPES; ++shader) {
Brian Paule0184b32016-04-25 09:34:40 -0600117 for (i = 0; i < ARRAY_SIZE(svga->curr.constbufs[shader]); ++i) {
Brian Paule0542512015-08-13 11:00:58 -0700118 pipe_resource_reference(&svga->curr.constbufs[shader][i].buffer, NULL);
119 }
Brian Paul2f1fc8d2014-02-08 09:51:14 -0800120 }
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100121
Brian Paulc96f63c2016-11-01 08:17:05 -0600122 FREE(svga);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100123}
124
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100125
Brian Paulc96f63c2016-11-01 08:17:05 -0600126struct pipe_context *
127svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100128{
129 struct svga_screen *svgascreen = svga_screen(screen);
130 struct svga_context *svga = NULL;
131 enum pipe_error ret;
132
Charmaine Lee203d8842016-11-08 11:54:56 -0800133 SVGA_STATS_TIME_PUSH(svgascreen->sws, SVGA_STATS_TIME_CREATECONTEXT);
134
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100135 svga = CALLOC_STRUCT(svga_context);
Edward O'Callaghan13eb5f52015-12-04 22:08:22 +1100136 if (!svga)
Brian Paule0542512015-08-13 11:00:58 -0700137 goto cleanup;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100138
Brian Paule853ade2014-04-09 11:35:54 -0600139 LIST_INITHEAD(&svga->dirty_buffers);
140
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100141 svga->pipe.screen = screen;
Keith Whitwell7f41f542010-02-08 12:55:59 +0000142 svga->pipe.priv = priv;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100143 svga->pipe.destroy = svga_destroy;
Marek Olšák55ad59d2017-01-27 00:12:37 +0100144 svga->pipe.stream_uploader = u_upload_create(&svga->pipe, 1024 * 1024,
145 PIPE_BIND_VERTEX_BUFFER |
146 PIPE_BIND_INDEX_BUFFER,
147 PIPE_USAGE_STREAM);
148 if (!svga->pipe.stream_uploader)
149 goto cleanup;
150
151 svga->pipe.const_uploader = u_upload_create(&svga->pipe, 128 * 1024,
152 PIPE_BIND_CONSTANT_BUFFER,
153 PIPE_USAGE_STREAM);
154 if (!svga->pipe.const_uploader)
155 goto cleanup;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100156
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100157 svga->swc = svgascreen->sws->context_create(svgascreen->sws);
Brian Paule0542512015-08-13 11:00:58 -0700158 if (!svga->swc)
159 goto cleanup;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100160
Keith Whitwell287c94e2010-04-10 16:05:54 +0100161 svga_init_resource_functions(svga);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100162 svga_init_blend_functions(svga);
163 svga_init_blit_functions(svga);
164 svga_init_depth_stencil_functions(svga);
165 svga_init_draw_functions(svga);
166 svga_init_flush_functions(svga);
167 svga_init_misc_functions(svga);
168 svga_init_rasterizer_functions(svga);
169 svga_init_sampler_functions(svga);
170 svga_init_fs_functions(svga);
171 svga_init_vs_functions(svga);
Brian Paule0542512015-08-13 11:00:58 -0700172 svga_init_gs_functions(svga);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100173 svga_init_vertex_functions(svga);
174 svga_init_constbuffer_functions(svga);
175 svga_init_query_functions(svga);
Roland Scheidegger4c700142010-12-02 04:33:43 +0100176 svga_init_surface_functions(svga);
Brian Paule0542512015-08-13 11:00:58 -0700177 svga_init_stream_output_functions(svga);
Neha Bhende40557ae2016-08-11 16:43:03 -0700178 svga_init_clear_functions(svga);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100179
Brian Paule0542512015-08-13 11:00:58 -0700180 /* init misc state */
181 svga->curr.sample_mask = ~0;
Michel Dänzer13a13fc2010-03-12 19:52:24 +0100182
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100183 /* debug */
Jakob Bornecrantzdaaf5422010-12-29 09:59:28 +0100184 svga->debug.no_swtnl = debug_get_option_no_swtnl();
185 svga->debug.force_swtnl = debug_get_option_force_swtnl();
186 svga->debug.use_min_mipmap = debug_get_option_use_min_mipmap();
Jakob Bornecrantzc523f312010-12-29 12:50:59 +0100187 svga->debug.no_line_width = debug_get_option_no_line_width();
188 svga->debug.force_hw_line_stipple = debug_get_option_force_hw_line_stipple();
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100189
Brian Paule0542512015-08-13 11:00:58 -0700190 if (!(svga->blend_object_id_bm = util_bitmask_create()))
191 goto cleanup;
192
193 if (!(svga->ds_object_id_bm = util_bitmask_create()))
194 goto cleanup;
195
196 if (!(svga->input_element_object_id_bm = util_bitmask_create()))
197 goto cleanup;
198
199 if (!(svga->rast_object_id_bm = util_bitmask_create()))
200 goto cleanup;
201
202 if (!(svga->sampler_object_id_bm = util_bitmask_create()))
203 goto cleanup;
204
205 if (!(svga->sampler_view_id_bm = util_bitmask_create()))
206 goto cleanup;
207
208 if (!(svga->shader_id_bm = util_bitmask_create()))
209 goto cleanup;
210
211 if (!(svga->surface_view_id_bm = util_bitmask_create()))
212 goto cleanup;
213
214 if (!(svga->stream_output_id_bm = util_bitmask_create()))
215 goto cleanup;
216
217 if (!(svga->query_id_bm = util_bitmask_create()))
218 goto cleanup;
José Fonsecacdb445f2010-01-03 00:47:30 +0000219
Brian Paul8d7b9132013-10-22 16:47:38 -0600220 svga->hwtnl = svga_hwtnl_create(svga);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100221 if (svga->hwtnl == NULL)
Brian Paule0542512015-08-13 11:00:58 -0700222 goto cleanup;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100223
José Fonseca0cb63292011-02-18 14:29:48 +0000224 if (!svga_init_swtnl(svga))
Brian Paule0542512015-08-13 11:00:58 -0700225 goto cleanup;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100226
Brian Paulc96f63c2016-11-01 08:17:05 -0600227 ret = svga_emit_initial_state(svga);
Brian Paul5f053bf2011-09-22 17:02:59 -0600228 if (ret != PIPE_OK)
Brian Paule0542512015-08-13 11:00:58 -0700229 goto cleanup;
230
231 svga->const0_upload = u_upload_create(&svga->pipe,
232 CONST0_UPLOAD_DEFAULT_SIZE,
Marek Olšákecb2da12015-12-19 17:54:31 +0100233 PIPE_BIND_CONSTANT_BUFFER,
234 PIPE_USAGE_STREAM);
Brian Paule0542512015-08-13 11:00:58 -0700235 if (!svga->const0_upload)
236 goto cleanup;
237
Charmaine Leef1b33742016-09-06 11:29:41 -0700238 if (!svga_texture_transfer_map_upload_create(svga))
239 goto cleanup;
240
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100241 /* Avoid shortcircuiting state with initial value of zero.
242 */
243 memset(&svga->state.hw_clear, 0xcd, sizeof(svga->state.hw_clear));
Brian Paulc96f63c2016-11-01 08:17:05 -0600244 memset(&svga->state.hw_clear.framebuffer, 0x0,
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100245 sizeof(svga->state.hw_clear.framebuffer));
Charmaine Leedc30ac52017-04-25 14:27:51 -0600246 svga->state.hw_clear.num_rendertargets = 0;
247 svga->state.hw_clear.dsv = NULL;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100248
249 memset(&svga->state.hw_draw, 0xcd, sizeof(svga->state.hw_draw));
250 memset(&svga->state.hw_draw.views, 0x0, sizeof(svga->state.hw_draw.views));
Charmaine Lee3f51a3f2016-08-15 18:35:28 -0700251 memset(&svga->state.hw_draw.num_samplers, 0,
252 sizeof(svga->state.hw_draw.num_samplers));
Brian Paule0542512015-08-13 11:00:58 -0700253 memset(&svga->state.hw_draw.num_sampler_views, 0,
254 sizeof(svga->state.hw_draw.num_sampler_views));
Charmaine Lee2781d602016-08-17 16:50:23 -0700255 memset(svga->state.hw_draw.sampler_views, 0,
256 sizeof(svga->state.hw_draw.sampler_views));
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100257 svga->state.hw_draw.num_views = 0;
Charmaine Leedbb5d2a2017-06-27 10:47:01 -0600258 svga->state.hw_draw.num_backed_views = 0;
Charmaine Leeb4c4ee02017-04-04 12:47:49 -0600259 svga->state.hw_draw.rasterizer_discard = FALSE;
Brian Paule0542512015-08-13 11:00:58 -0700260
261 /* Initialize the shader pointers */
262 svga->state.hw_draw.vs = NULL;
263 svga->state.hw_draw.gs = NULL;
264 svga->state.hw_draw.fs = NULL;
Charmaine Lee2b81e312016-05-02 18:17:48 -0700265
266 /* Initialize the currently bound buffer resources */
Brian Paule0542512015-08-13 11:00:58 -0700267 memset(svga->state.hw_draw.constbuf, 0,
268 sizeof(svga->state.hw_draw.constbuf));
269 memset(svga->state.hw_draw.default_constbuf_size, 0,
270 sizeof(svga->state.hw_draw.default_constbuf_size));
271 memset(svga->state.hw_draw.enabled_constbufs, 0,
272 sizeof(svga->state.hw_draw.enabled_constbufs));
Charmaine Lee47cfc832016-01-19 20:25:39 -0800273 svga->state.hw_draw.ib = NULL;
Charmaine Lee2b81e312016-05-02 18:17:48 -0700274 svga->state.hw_draw.num_vbuffers = 0;
275 memset(svga->state.hw_draw.vbuffers, 0,
276 sizeof(svga->state.hw_draw.vbuffers));
Brian Paulee5f5e22016-08-15 09:16:05 -0600277 svga->state.hw_draw.const0_buffer = NULL;
278 svga->state.hw_draw.const0_handle = NULL;
Brian Paule0542512015-08-13 11:00:58 -0700279
280 /* Create a no-operation blend state which we will bind whenever the
281 * requested blend state is impossible (e.g. due to having an integer
282 * render target attached).
283 *
284 * XXX: We will probably actually need 16 of these, one for each possible
285 * RGBA color mask (4 bits). Then, we would bind the one with a color mask
286 * matching the blend state it is replacing.
287 */
288 {
289 struct pipe_blend_state noop_tmpl = {0};
290 unsigned i;
291
292 for (i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) {
293 // Set the color mask to all-ones. Later this may change.
294 noop_tmpl.rt[i].colormask = PIPE_MASK_RGBA;
295 }
296 svga->noop_blend = svga->pipe.create_blend_state(&svga->pipe, &noop_tmpl);
297 }
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100298
299 svga->dirty = ~0;
Thomas Hellstromd787ce72016-10-28 11:33:53 -0700300 svga->pred.query_id = SVGA3D_INVALID_ID;
Charmaine Leeb4c4ee02017-04-04 12:47:49 -0600301 svga->disable_rasterizer = FALSE;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100302
Charmaine Lee203d8842016-11-08 11:54:56 -0800303 goto done;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100304
Brian Paule0542512015-08-13 11:00:58 -0700305cleanup:
José Fonseca0cb63292011-02-18 14:29:48 +0000306 svga_destroy_swtnl(svga);
Brian Paule0542512015-08-13 11:00:58 -0700307
308 if (svga->const0_upload)
309 u_upload_destroy(svga->const0_upload);
Marek Olšák55ad59d2017-01-27 00:12:37 +0100310 if (svga->pipe.const_uploader)
311 u_upload_destroy(svga->pipe.const_uploader);
312 if (svga->pipe.stream_uploader)
313 u_upload_destroy(svga->pipe.stream_uploader);
Charmaine Leef1b33742016-09-06 11:29:41 -0700314 svga_texture_transfer_map_upload_destroy(svga);
Brian Paule0542512015-08-13 11:00:58 -0700315 if (svga->hwtnl)
316 svga_hwtnl_destroy(svga->hwtnl);
317 if (svga->swc)
318 svga->swc->destroy(svga->swc);
319 util_bitmask_destroy(svga->blend_object_id_bm);
320 util_bitmask_destroy(svga->ds_object_id_bm);
321 util_bitmask_destroy(svga->input_element_object_id_bm);
322 util_bitmask_destroy(svga->rast_object_id_bm);
323 util_bitmask_destroy(svga->sampler_object_id_bm);
324 util_bitmask_destroy(svga->sampler_view_id_bm);
325 util_bitmask_destroy(svga->shader_id_bm);
326 util_bitmask_destroy(svga->surface_view_id_bm);
327 util_bitmask_destroy(svga->stream_output_id_bm);
328 util_bitmask_destroy(svga->query_id_bm);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100329 FREE(svga);
Charmaine Lee203d8842016-11-08 11:54:56 -0800330
331done:
332 SVGA_STATS_TIME_POP(svgascreen->sws);
333 return svga ? &svga->pipe:NULL;
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100334}
335
336
Brian Paulc96f63c2016-11-01 08:17:05 -0600337void
338svga_context_flush(struct svga_context *svga,
339 struct pipe_fence_handle **pfence)
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100340{
341 struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
José Fonsecab8459092010-05-02 23:54:42 +0100342 struct pipe_fence_handle *fence = NULL;
Brian Paul7e8cf342016-03-04 09:14:34 -0700343 uint64_t t0;
Keith Whitwellb84b7f12009-11-27 12:19:28 +0000344
Charmaine Lee2e1cfcc2016-08-19 08:49:17 -0600345 SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CONTEXTFLUSH);
346
Keith Whitwellb84b7f12009-11-27 12:19:28 +0000347 svga->curr.nr_fbs = 0;
348
Brian Paulee5f5e22016-08-15 09:16:05 -0600349 /* Unmap the 0th/default constant buffer. The u_upload_unmap() function
350 * will call pipe_context::transfer_flush_region() to indicate the
351 * region of the buffer which was modified (and needs to be uploaded).
352 */
353 if (svga->state.hw_draw.const0_handle) {
354 assert(svga->state.hw_draw.const0_buffer);
355 u_upload_unmap(svga->const0_upload);
356 pipe_resource_reference(&svga->state.hw_draw.const0_buffer, NULL);
357 svga->state.hw_draw.const0_handle = NULL;
358 }
359
José Fonsecab8459092010-05-02 23:54:42 +0100360 /* Ensure that texture dma uploads are processed
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100361 * before submitting commands.
362 */
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100363 svga_context_flush_buffers(svga);
364
Brian Paul192ee9a2016-02-29 14:26:12 -0700365 svga->hud.command_buffer_size +=
366 svga->swc->get_command_buffer_size(svga->swc);
367
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100368 /* Flush pending commands to hardware:
369 */
Brian Paulf9341172016-08-02 14:27:33 -0600370 t0 = svga_get_time(svga);
José Fonsecab8459092010-05-02 23:54:42 +0100371 svga->swc->flush(svga->swc, &fence);
Brian Paulf9341172016-08-02 14:27:33 -0600372 svga->hud.flush_time += (svga_get_time(svga) - t0);
José Fonsecab8459092010-05-02 23:54:42 +0100373
Neha Bhende9bc7e312015-10-09 16:10:16 -0600374 svga->hud.num_flushes++;
375
Charmaine Lee16bd2c62017-01-26 18:46:23 -0800376 svga_screen_cache_flush(svgascreen, svga, fence);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100377
Brian Paul581292a2016-08-31 18:28:00 -0600378 SVGA3D_ResetLastCommand(svga->swc);
379
José Fonseca6b95cfb2011-04-07 16:54:37 +0100380 /* To force the re-emission of rendertargets and texture sampler bindings on
381 * the next command buffer.
José Fonseca5a70db62010-08-15 13:36:02 +0100382 */
Brian Paule0542512015-08-13 11:00:58 -0700383 svga->rebind.flags.rendertargets = TRUE;
384 svga->rebind.flags.texture_samplers = TRUE;
385
Brian Paulf84c8302014-02-08 09:51:14 -0800386 if (svga_have_gb_objects(svga)) {
Brian Paule0542512015-08-13 11:00:58 -0700387
388 svga->rebind.flags.constbufs = TRUE;
389 svga->rebind.flags.vs = TRUE;
390 svga->rebind.flags.fs = TRUE;
391 svga->rebind.flags.gs = TRUE;
392
393 if (svga_need_to_rebind_resources(svga)) {
394 svga->rebind.flags.query = TRUE;
395 }
Brian Paulf84c8302014-02-08 09:51:14 -0800396 }
José Fonseca369ece12011-02-23 13:32:37 +0000397
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100398 if (SVGA_DEBUG & DEBUG_SYNC) {
José Fonsecab8459092010-05-02 23:54:42 +0100399 if (fence)
Brian Paulc96f63c2016-11-01 08:17:05 -0600400 svga->pipe.screen->fence_finish(svga->pipe.screen, NULL, fence,
Marek Olšákb39bccb2011-03-05 21:23:54 +0100401 PIPE_TIMEOUT_INFINITE);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100402 }
José Fonsecab8459092010-05-02 23:54:42 +0100403
Edward O'Callaghan13eb5f52015-12-04 22:08:22 +1100404 if (pfence)
Thomas Hellstrom62358462011-10-17 14:24:14 +0200405 svgascreen->sws->fence_reference(svgascreen->sws, pfence, fence);
406
407 svgascreen->sws->fence_reference(svgascreen->sws, &fence, NULL);
Charmaine Lee2e1cfcc2016-08-19 08:49:17 -0600408
409 SVGA_STATS_TIME_POP(svga_sws(svga));
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100410}
411
412
Brian Paule0542512015-08-13 11:00:58 -0700413/**
414 * Flush pending commands and wait for completion with a fence.
415 */
416void
417svga_context_finish(struct svga_context *svga)
418{
419 struct pipe_screen *screen = svga->pipe.screen;
420 struct pipe_fence_handle *fence = NULL;
421
Brian Paul1691e292016-10-28 13:04:32 -0700422 SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CONTEXTFINISH);
423
Brian Paule0542512015-08-13 11:00:58 -0700424 svga_context_flush(svga, &fence);
Marek Olšák54272e12016-08-06 16:41:42 +0200425 screen->fence_finish(screen, NULL, fence, PIPE_TIMEOUT_INFINITE);
Brian Paule0542512015-08-13 11:00:58 -0700426 screen->fence_reference(screen, &fence, NULL);
Brian Paul1691e292016-10-28 13:04:32 -0700427
428 SVGA_STATS_TIME_POP(svga_sws(svga));
Brian Paule0542512015-08-13 11:00:58 -0700429}
430
431
432/**
433 * Emit pending drawing commands to the command buffer.
434 * If the command buffer overflows, we flush it and retry.
435 * \sa svga_hwtnl_flush()
436 */
Brian Paulc96f63c2016-11-01 08:17:05 -0600437void
438svga_hwtnl_flush_retry(struct svga_context *svga)
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100439{
440 enum pipe_error ret = PIPE_OK;
441
Brian Paulc96f63c2016-11-01 08:17:05 -0600442 ret = svga_hwtnl_flush(svga->hwtnl);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100443 if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
Brian Paulc96f63c2016-11-01 08:17:05 -0600444 svga_context_flush(svga, NULL);
445 ret = svga_hwtnl_flush(svga->hwtnl);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100446 }
447
Brian Paule0542512015-08-13 11:00:58 -0700448 assert(ret == PIPE_OK);
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100449}
450
José Fonseca0ced7892011-02-18 14:33:55 +0000451
José Fonseca1e9d8932011-10-27 19:09:25 +0100452/**
453 * Flush the primitive queue if this buffer is referred.
454 *
455 * Otherwise DMA commands on the referred buffer will be emitted too late.
456 */
Brian Paulc96f63c2016-11-01 08:17:05 -0600457void
458svga_hwtnl_flush_buffer(struct svga_context *svga,
459 struct pipe_resource *buffer)
José Fonseca1e9d8932011-10-27 19:09:25 +0100460{
461 if (svga_hwtnl_is_buffer_referred(svga->hwtnl, buffer)) {
462 svga_hwtnl_flush_retry(svga);
463 }
464}
465
466
Brian Paulc96f63c2016-11-01 08:17:05 -0600467/**
468 * Emit all operations pending on host surfaces.
469 */
470void
471svga_surfaces_flush(struct svga_context *svga)
José Fonseca0ced7892011-02-18 14:33:55 +0000472{
Charmaine Lee2e1cfcc2016-08-19 08:49:17 -0600473 SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_SURFACEFLUSH);
474
José Fonseca0ced7892011-02-18 14:33:55 +0000475 /* Emit buffered drawing commands.
476 */
Brian Paulc96f63c2016-11-01 08:17:05 -0600477 svga_hwtnl_flush_retry(svga);
José Fonseca0ced7892011-02-18 14:33:55 +0000478
Brian Paul646afc62016-08-26 09:53:47 -0600479 /* Emit back-copy from render target views to textures.
José Fonseca0ced7892011-02-18 14:33:55 +0000480 */
Brian Paul646afc62016-08-26 09:53:47 -0600481 svga_propagate_rendertargets(svga);
José Fonseca0ced7892011-02-18 14:33:55 +0000482
Charmaine Lee2e1cfcc2016-08-19 08:49:17 -0600483 SVGA_STATS_TIME_POP(svga_sws(svga));
José Fonseca0ced7892011-02-18 14:33:55 +0000484}
485
486
Thomas Hellstromcd151ef2010-05-31 22:03:56 +0100487struct svga_winsys_context *
Brian Paulc96f63c2016-11-01 08:17:05 -0600488svga_winsys_context(struct pipe_context *pipe)
Thomas Hellstromcd151ef2010-05-31 22:03:56 +0100489{
Brian Paulc96f63c2016-11-01 08:17:05 -0600490 return svga_context(pipe)->swc;
Thomas Hellstromcd151ef2010-05-31 22:03:56 +0100491}