freedreno_draw.c 16.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Authors:
 *    Rob Clark <robclark@freedesktop.org>
 */

#include "pipe/p_state.h"
28
#include "util/u_draw.h"
29 30 31
#include "util/u_string.h"
#include "util/u_memory.h"
#include "util/u_prim.h"
32
#include "util/format/u_format.h"
33
#include "util/u_helpers.h"
34

35
#include "freedreno_blitter.h"
Rob Clark's avatar
Rob Clark committed
36
#include "freedreno_draw.h"
37
#include "freedreno_context.h"
38
#include "freedreno_fence.h"
39 40
#include "freedreno_state.h"
#include "freedreno_resource.h"
41
#include "freedreno_query_acc.h"
42
#include "freedreno_query_hw.h"
43 44
#include "freedreno_util.h"

45
static void
46
resource_read(struct fd_batch *batch, struct pipe_resource *prsc)
47 48 49
{
	if (!prsc)
		return;
50
	fd_batch_resource_read(batch, fd_resource(prsc));
51 52 53
}

static void
54
resource_written(struct fd_batch *batch, struct pipe_resource *prsc)
55
{
56 57
	if (!prsc)
		return;
58
	fd_batch_resource_write(batch, fd_resource(prsc));
59
}
60

Rob Clark's avatar
Rob Clark committed
61
static void
62
batch_draw_tracking(struct fd_batch *batch, const struct pipe_draw_info *info)
Rob Clark's avatar
Rob Clark committed
63
{
64
	struct fd_context *ctx = batch->ctx;
65
	struct pipe_framebuffer_state *pfb = &batch->framebuffer;
66
	unsigned buffers = 0, restore_buffers = 0;
Rob Clark's avatar
Rob Clark committed
67

68 69 70
	/* NOTE: needs to be before resource_written(batch->query_buf), otherwise
	 * query_buf may not be created yet.
	 */
71
	fd_batch_set_stage(batch, FD_STAGE_DRAW);
Rob Clark's avatar
Rob Clark committed
72

Rob Clark's avatar
Rob Clark committed
73 74 75
	/*
	 * Figure out the buffers/features we need:
	 */
76

77
	fd_screen_lock(ctx->screen);
Rob Clark's avatar
Rob Clark committed
78

79
	if (ctx->dirty & (FD_DIRTY_FRAMEBUFFER | FD_DIRTY_ZSA)) {
80 81 82 83 84 85 86
		if (fd_depth_enabled(ctx)) {
			if (fd_resource(pfb->zsbuf->texture)->valid) {
				restore_buffers |= FD_BUFFER_DEPTH;
			} else {
				batch->invalidated |= FD_BUFFER_DEPTH;
			}
			batch->gmem_reason |= FD_GMEM_DEPTH_ENABLED;
87 88 89 90 91 92
			if (fd_depth_write_enabled(ctx)) {
				buffers |= FD_BUFFER_DEPTH;
				resource_written(batch, pfb->zsbuf->texture);
			} else {
				resource_read(batch, pfb->zsbuf->texture);
			}
93
		}
Rob Clark's avatar
Rob Clark committed
94

95 96 97 98 99 100
		if (fd_stencil_enabled(ctx)) {
			if (fd_resource(pfb->zsbuf->texture)->valid) {
				restore_buffers |= FD_BUFFER_STENCIL;
			} else {
				batch->invalidated |= FD_BUFFER_STENCIL;
			}
101
			batch->gmem_reason |= FD_GMEM_STENCIL_ENABLED;
102 103 104
			buffers |= FD_BUFFER_STENCIL;
			resource_written(batch, pfb->zsbuf->texture);
		}
105
	}
106

Rob Clark's avatar
Rob Clark committed
107
	if (fd_logicop_enabled(ctx))
108
		batch->gmem_reason |= FD_GMEM_LOGICOP_ENABLED;
Rob Clark's avatar
Rob Clark committed
109

110
	for (unsigned i = 0; i < pfb->nr_cbufs; i++) {
111 112 113 114 115 116
		struct pipe_resource *surf;

		if (!pfb->cbufs[i])
			continue;

		surf = pfb->cbufs[i]->texture;
Rob Clark's avatar
Rob Clark committed
117

118
		if (fd_resource(surf)->valid) {
119
			restore_buffers |= PIPE_CLEAR_COLOR0 << i;
120 121 122 123
		} else {
			batch->invalidated |= PIPE_CLEAR_COLOR0 << i;
		}

124
		buffers |= PIPE_CLEAR_COLOR0 << i;
Rob Clark's avatar
Rob Clark committed
125 126

		if (fd_blend_enabled(ctx, i))
127
			batch->gmem_reason |= FD_GMEM_BLEND_ENABLED;
128 129 130

		if (ctx->dirty & FD_DIRTY_FRAMEBUFFER)
			resource_written(batch, pfb->cbufs[i]->texture);
Rob Clark's avatar
Rob Clark committed
131 132
	}

133
	/* Mark SSBOs */
134
	if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_SSBO) {
135 136 137 138 139 140
		const struct fd_shaderbuf_stateobj *so = &ctx->shaderbuf[PIPE_SHADER_FRAGMENT];

		foreach_bit (i, so->enabled_mask & so->writable_mask)
			resource_written(batch, so->sb[i].buffer);

		foreach_bit (i, so->enabled_mask & ~so->writable_mask)
Rob Clark's avatar
Rob Clark committed
141
			resource_read(batch, so->sb[i].buffer);
142 143 144
	}

	if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_IMAGE) {
145
		foreach_bit (i, ctx->shaderimg[PIPE_SHADER_FRAGMENT].enabled_mask) {
146 147 148 149 150 151 152
			struct pipe_image_view *img =
					&ctx->shaderimg[PIPE_SHADER_FRAGMENT].si[i];
			if (img->access & PIPE_IMAGE_ACCESS_WRITE)
				resource_written(batch, img->resource);
			else
				resource_read(batch, img->resource);
		}
153 154
	}

155
	if (ctx->dirty_shader[PIPE_SHADER_VERTEX] & FD_DIRTY_SHADER_CONST) {
156
		foreach_bit (i, ctx->constbuf[PIPE_SHADER_VERTEX].enabled_mask)
157 158 159 160
			resource_read(batch, ctx->constbuf[PIPE_SHADER_VERTEX].cb[i].buffer);
	}

	if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_CONST) {
161
		foreach_bit (i, ctx->constbuf[PIPE_SHADER_FRAGMENT].enabled_mask)
162 163
			resource_read(batch, ctx->constbuf[PIPE_SHADER_FRAGMENT].cb[i].buffer);
	}
164 165

	/* Mark VBOs as being read */
166
	if (ctx->dirty & FD_DIRTY_VTXBUF) {
167
		foreach_bit (i, ctx->vtx.vertexbuf.enabled_mask) {
168 169 170
			assert(!ctx->vtx.vertexbuf.vb[i].is_user_buffer);
			resource_read(batch, ctx->vtx.vertexbuf.vb[i].buffer.resource);
		}
171 172 173
	}

	/* Mark index buffer as being read */
174 175
	if (info->index_size)
		resource_read(batch, info->index.resource);
176

177
	/* Mark indirect draw buffer as being read */
178
	if (info->indirect && info->indirect->buffer)
179 180
		resource_read(batch, info->indirect->buffer);

181
	/* Mark textures as being read */
182
	if (ctx->dirty_shader[PIPE_SHADER_VERTEX] & FD_DIRTY_SHADER_TEX) {
183
		foreach_bit (i, ctx->tex[PIPE_SHADER_VERTEX].valid_textures)
184 185 186 187
			resource_read(batch, ctx->tex[PIPE_SHADER_VERTEX].textures[i]->texture);
	}

	if (ctx->dirty_shader[PIPE_SHADER_FRAGMENT] & FD_DIRTY_SHADER_TEX) {
188
		foreach_bit (i, ctx->tex[PIPE_SHADER_FRAGMENT].valid_textures)
189 190
			resource_read(batch, ctx->tex[PIPE_SHADER_FRAGMENT].textures[i]->texture);
	}
191

192
	/* Mark streamout buffers as being written.. */
193
	if (ctx->dirty & FD_DIRTY_STREAMOUT) {
194
		for (unsigned i = 0; i < ctx->streamout.num_targets; i++)
195 196 197
			if (ctx->streamout.targets[i])
				resource_written(batch, ctx->streamout.targets[i]->buffer);
	}
198

199 200
	resource_written(batch, batch->query_buf);

201 202 203
	list_for_each_entry(struct fd_acc_query, aq, &ctx->acc_active_queries, node)
		resource_written(batch, aq->prsc);

204
	fd_screen_unlock(ctx->screen);
Rob Clark's avatar
Rob Clark committed
205

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
	/* any buffers that haven't been cleared yet, we need to restore: */
	batch->restore |= restore_buffers & (FD_BUFFER_ALL & ~batch->invalidated);
	/* and any buffers used, need to be resolved: */
	batch->resolve |= buffers;
}

static void
fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
{
	struct fd_context *ctx = fd_context(pctx);

	/* for debugging problems with indirect draw, it is convenient
	 * to be able to emulate it, to determine if game is feeding us
	 * bogus data:
	 */
221
	if (info->indirect && info->indirect->buffer && (fd_mesa_debug & FD_DBG_NOINDR)) {
222 223 224 225
		util_draw_indirect(pctx, info);
		return;
	}

226
	if (info->mode != PIPE_PRIM_MAX &&
227
	    !info->indirect &&
228 229 230 231 232 233 234 235 236 237 238
	    !info->primitive_restart &&
	    !u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
		return;

	/* TODO: push down the region versions into the tiles */
	if (!fd_render_condition_check(pctx))
		return;

	/* emulate unsupported primitives: */
	if (!fd_supported_prim(ctx, info->mode)) {
		if (ctx->streamout.num_targets > 0)
Rob Clark's avatar
Rob Clark committed
239
			mesa_loge("stream-out with emulated prims");
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
		util_primconvert_save_rasterizer_state(ctx->primconvert, ctx->rasterizer);
		util_primconvert_draw_vbo(ctx->primconvert, info);
		return;
	}

	/* Upload a user index buffer. */
	struct pipe_resource *indexbuf = NULL;
	unsigned index_offset = 0;
	struct pipe_draw_info new_info;
	if (info->index_size) {
		if (info->has_user_indices) {
			if (!util_upload_index_buffer(pctx, info, &indexbuf, &index_offset, 4))
				return;
			new_info = *info;
			new_info.index.resource = indexbuf;
			new_info.has_user_indices = false;
			info = &new_info;
		} else {
			indexbuf = info->index.resource;
		}
	}

262
	struct fd_batch *batch = fd_context_batch(ctx);
263

264 265 266 267 268 269 270
	if (ctx->in_discard_blit) {
		fd_batch_reset(batch);
		fd_context_all_dirty(ctx);
	}

	batch_draw_tracking(batch, info);

Rob Clark's avatar
Rob Clark committed
271
	while (unlikely(!fd_batch_lock_submit(batch))) {
272 273 274 275
		/* The current batch was flushed in batch_draw_tracking()
		 * so start anew.  We know this won't happen a second time
		 * since we are dealing with a fresh batch:
		 */
276 277
		fd_batch_reference(&batch, NULL);
		batch = fd_context_batch(ctx);
278 279 280 281
		batch_draw_tracking(batch, info);
		assert(ctx->batch == batch);
	}

282 283
	batch->blit = ctx->in_discard_blit;
	batch->back_blit = ctx->in_shadow;
284
	batch->num_draws++;
Rob Clark's avatar
Rob Clark committed
285

286 287 288 289
	/* Counting prims in sw doesn't work for GS and tesselation. For older
	 * gens we don't have those stages and don't have the hw counters enabled,
	 * so keep the count accurate for non-patch geometry.
	 */
290
	unsigned prims;
291 292
	if ((info->mode != PIPE_PRIM_PATCHES) &&
			(info->mode != PIPE_PRIM_MAX))
293 294 295
		prims = u_reduced_prims_for_vertices(info->mode, info->count);
	else
		prims = 0;
296

Rob Clark's avatar
Rob Clark committed
297
	ctx->stats.draw_calls++;
Rob Clark's avatar
Rob Clark committed
298 299 300 301 302 303 304 305 306 307

	/* TODO prims_emitted should be clipped when the stream-out buffer is
	 * not large enough.  See max_tf_vtx().. probably need to move that
	 * into common code.  Although a bit more annoying since a2xx doesn't
	 * use ir3 so no common way to get at the pipe_stream_output_info
	 * which is needed for this calculation.
	 */
	if (ctx->streamout.num_targets > 0)
		ctx->stats.prims_emitted += prims;
	ctx->stats.prims_generated += prims;
Rob Clark's avatar
Rob Clark committed
308

309 310 311 312 313 314
	/* Clearing last_fence must come after the batch dependency tracking
	 * (resource_read()/resource_written()), as that can trigger a flush,
	 * re-populating last_fence
	 */
	fd_fence_ref(&ctx->last_fence, NULL);

315
	struct pipe_framebuffer_state *pfb = &batch->framebuffer;
316
	DBG("%p: %ux%u num_draws=%u (%s/%s)", batch,
317
		pfb->width, pfb->height, batch->num_draws,
318 319 320
		util_format_short_name(pipe_surface_format(pfb->cbufs[0])),
		util_format_short_name(pipe_surface_format(pfb->zsbuf)));

321
	if (ctx->draw_vbo(ctx, info, index_offset))
322
		batch->needs_flush = true;
323

324 325
	batch->num_vertices += info->count * info->instance_count;

326
	for (unsigned i = 0; i < ctx->streamout.num_targets; i++)
327
		ctx->streamout.offsets[i] += info->count;
328

329
	if (fd_mesa_debug & FD_DBG_DDRAW)
330
		fd_context_all_dirty(ctx);
331

332
	fd_batch_check_size(batch);
Rob Clark's avatar
Rob Clark committed
333
	fd_batch_unlock_submit(batch);
334
	fd_batch_reference(&batch, NULL);
Rob Clark's avatar
Rob Clark committed
335 336

	if (info == &new_info)
337
		pipe_resource_reference(&indexbuf, NULL);
Rob Clark's avatar
Rob Clark committed
338
}
339

Rob Clark's avatar
Rob Clark committed
340
static void
341
batch_clear_tracking(struct fd_batch *batch, unsigned buffers)
Rob Clark's avatar
Rob Clark committed
342
{
343
	struct fd_context *ctx = batch->ctx;
344
	struct pipe_framebuffer_state *pfb = &batch->framebuffer;
Rob Clark's avatar
Rob Clark committed
345
	unsigned cleared_buffers;
346

Rob Clark's avatar
Rob Clark committed
347 348 349 350 351 352 353 354
	/* pctx->clear() is only for full-surface clears, so scissor is
	 * equivalent to having GL_SCISSOR_TEST disabled:
	 */
	batch->max_scissor.minx = 0;
	batch->max_scissor.miny = 0;
	batch->max_scissor.maxx = pfb->width;
	batch->max_scissor.maxy = pfb->height;

Rob Clark's avatar
Rob Clark committed
355 356 357 358 359 360 361
	/* for bookkeeping about which buffers have been cleared (and thus
	 * can fully or partially skip mem2gmem) we need to ignore buffers
	 * that have already had a draw, in case apps do silly things like
	 * clear after draw (ie. if you only clear the color buffer, but
	 * something like alpha-test causes side effects from the draw in
	 * the depth buffer, etc)
	 */
362
	cleared_buffers = buffers & (FD_BUFFER_ALL & ~batch->restore);
363
	batch->cleared |= buffers;
364
	batch->invalidated |= cleared_buffers;
Rob Clark's avatar
Rob Clark committed
365

366 367
	batch->resolve |= buffers;
	batch->needs_flush = true;
368

369
	fd_screen_lock(ctx->screen);
Rob Clark's avatar
Rob Clark committed
370

Rob Clark's avatar
Rob Clark committed
371
	if (buffers & PIPE_CLEAR_COLOR)
372
		for (unsigned i = 0; i < pfb->nr_cbufs; i++)
373
			if (buffers & (PIPE_CLEAR_COLOR0 << i))
374
				resource_written(batch, pfb->cbufs[i]->texture);
375

Rob Clark's avatar
Rob Clark committed
376
	if (buffers & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) {
377 378
		resource_written(batch, pfb->zsbuf->texture);
		batch->gmem_reason |= FD_GMEM_CLEARS_DEPTH_STENCIL;
Rob Clark's avatar
Rob Clark committed
379
	}
380

381 382
	resource_written(batch, batch->query_buf);

383 384 385
	list_for_each_entry(struct fd_acc_query, aq, &ctx->acc_active_queries, node)
		resource_written(batch, aq->prsc);

386
	fd_screen_unlock(ctx->screen);
387 388 389 390 391 392 393 394 395 396 397 398 399 400
}

static void
fd_clear(struct pipe_context *pctx, unsigned buffers,
		const struct pipe_scissor_state *scissor_state,
		const union pipe_color_union *color, double depth,
		unsigned stencil)
{
	struct fd_context *ctx = fd_context(pctx);

	/* TODO: push down the region versions into the tiles */
	if (!fd_render_condition_check(pctx))
		return;

401
	struct fd_batch *batch = fd_context_batch(ctx);
402

403 404 405 406 407 408
	if (ctx->in_discard_blit) {
		fd_batch_reset(batch);
		fd_context_all_dirty(ctx);
	}

	batch_clear_tracking(batch, buffers);
Rob Clark's avatar
Rob Clark committed
409

Rob Clark's avatar
Rob Clark committed
410
	while (unlikely(!fd_batch_lock_submit(batch))) {
411 412 413 414
		/* The current batch was flushed in batch_clear_tracking()
		 * so start anew.  We know this won't happen a second time
		 * since we are dealing with a fresh batch:
		 */
415 416
		fd_batch_reference(&batch, NULL);
		batch = fd_context_batch(ctx);
417 418 419 420
		batch_clear_tracking(batch, buffers);
		assert(ctx->batch == batch);
	}

421 422 423 424 425 426
	/* Clearing last_fence must come after the batch dependency tracking
	 * (resource_read()/resource_written()), as that can trigger a flush,
	 * re-populating last_fence
	 */
	fd_fence_ref(&ctx->last_fence, NULL);

427
	struct pipe_framebuffer_state *pfb = &batch->framebuffer;
428 429
	DBG("%p: %x %ux%u depth=%f, stencil=%u (%s/%s)", batch, buffers,
		pfb->width, pfb->height, depth, stencil,
430 431
		util_format_short_name(pipe_surface_format(pfb->cbufs[0])),
		util_format_short_name(pipe_surface_format(pfb->zsbuf)));
Rob Clark's avatar
Rob Clark committed
432

433 434 435
	/* if per-gen backend doesn't implement ctx->clear() generic
	 * blitter clear:
	 */
436
	bool fallback = true;
437

438 439
	if (ctx->clear) {
		fd_batch_set_stage(batch, FD_STAGE_CLEAR);
440

441 442 443
		if (ctx->clear(ctx, buffers, color, depth, stencil)) {
			if (fd_mesa_debug & FD_DBG_DCLEAR)
				fd_context_all_dirty(ctx);
444

445 446 447 448
			fallback = false;
		}
	}

Rob Clark's avatar
Rob Clark committed
449 450 451
	fd_batch_check_size(batch);
	fd_batch_unlock_submit(batch);

452 453 454
	if (fallback) {
		fd_blitter_clear(pctx, buffers, color, depth, stencil);
	}
Rob Clark's avatar
Rob Clark committed
455

456
	fd_batch_reference(&batch, NULL);
Rob Clark's avatar
Rob Clark committed
457 458 459 460 461
}

static void
fd_clear_render_target(struct pipe_context *pctx, struct pipe_surface *ps,
		const union pipe_color_union *color,
462 463
		unsigned x, unsigned y, unsigned w, unsigned h,
		bool render_condition_enabled)
Rob Clark's avatar
Rob Clark committed
464 465 466 467 468 469 470
{
	DBG("TODO: x=%u, y=%u, w=%u, h=%u", x, y, w, h);
}

static void
fd_clear_depth_stencil(struct pipe_context *pctx, struct pipe_surface *ps,
		unsigned buffers, double depth, unsigned stencil,
471 472
		unsigned x, unsigned y, unsigned w, unsigned h,
		bool render_condition_enabled)
Rob Clark's avatar
Rob Clark committed
473 474 475
{
	DBG("TODO: buffers=%u, depth=%f, stencil=%u, x=%u, y=%u, w=%u, h=%u",
			buffers, depth, stencil, x, y, w, h);
476 477
}

478 479 480 481
static void
fd_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info)
{
	struct fd_context *ctx = fd_context(pctx);
482
	const struct fd_shaderbuf_stateobj *so = &ctx->shaderbuf[PIPE_SHADER_COMPUTE];
483 484
	struct fd_batch *batch, *save_batch = NULL;

485
	batch = fd_bc_alloc_batch(&ctx->screen->batch_cache, ctx, true);
486 487
	fd_batch_reference(&save_batch, ctx->batch);
	fd_batch_reference(&ctx->batch, batch);
488
	fd_context_all_dirty(ctx);
489

490
	fd_screen_lock(ctx->screen);
491

492 493 494 495 496 497
	/* Mark SSBOs */
	foreach_bit (i, so->enabled_mask & so->writable_mask)
		resource_written(batch, so->sb[i].buffer);

	foreach_bit (i, so->enabled_mask & ~so->writable_mask)
		resource_read(batch, so->sb[i].buffer);
498

499 500 501 502 503 504 505 506 507
	foreach_bit(i, ctx->shaderimg[PIPE_SHADER_COMPUTE].enabled_mask) {
		struct pipe_image_view *img =
			&ctx->shaderimg[PIPE_SHADER_COMPUTE].si[i];
		if (img->access & PIPE_IMAGE_ACCESS_WRITE)
			resource_written(batch, img->resource);
		else
			resource_read(batch, img->resource);
	}

508 509 510 511 512 513 514 515
	/* UBO's are read */
	foreach_bit(i, ctx->constbuf[PIPE_SHADER_COMPUTE].enabled_mask)
		resource_read(batch, ctx->constbuf[PIPE_SHADER_COMPUTE].cb[i].buffer);

	/* Mark textures as being read */
	foreach_bit(i, ctx->tex[PIPE_SHADER_COMPUTE].valid_textures)
		resource_read(batch, ctx->tex[PIPE_SHADER_COMPUTE].textures[i]->texture);

516 517 518 519 520 521
	/* For global buffers, we don't really know if read or written, so assume
	 * the worst:
	 */
	foreach_bit(i, ctx->global_bindings.enabled_mask)
		resource_written(batch, ctx->global_bindings.buf[i]);

522 523 524
	if (info->indirect)
		resource_read(batch, info->indirect);

525
	fd_screen_unlock(ctx->screen);
526

527
	batch->needs_flush = true;
528 529
	ctx->launch_grid(ctx, info);

Rob Clark's avatar
Rob Clark committed
530
	fd_batch_flush(batch);
531 532

	fd_batch_reference(&ctx->batch, save_batch);
533
	fd_context_all_dirty(ctx);
534
	fd_batch_reference(&save_batch, NULL);
535
	fd_batch_reference(&batch, NULL);
536 537
}

538
void
Rob Clark's avatar
Rob Clark committed
539
fd_draw_init(struct pipe_context *pctx)
540 541
{
	pctx->draw_vbo = fd_draw_vbo;
Rob Clark's avatar
Rob Clark committed
542 543 544
	pctx->clear = fd_clear;
	pctx->clear_render_target = fd_clear_render_target;
	pctx->clear_depth_stencil = fd_clear_depth_stencil;
545 546 547 548

	if (has_compute(fd_screen(pctx->screen))) {
		pctx->launch_grid = fd_launch_grid;
	}
549
}