gallium/radeon: remove the IB flushing flag
[mesa.git] / src / gallium / drivers / radeonsi / si_hw_context.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26
27 #include "si_pipe.h"
28
29 /* initialize */
30 void si_need_cs_space(struct si_context *ctx)
31 {
32 struct radeon_winsys_cs *cs = ctx->b.rings.gfx.cs;
33 struct radeon_winsys_cs *dma = ctx->b.rings.dma.cs;
34
35 /* Flush the DMA IB if it's not empty. */
36 if (dma && dma->cdw)
37 ctx->b.rings.dma.flush(ctx, RADEON_FLUSH_ASYNC, NULL);
38
39 /* There are two memory usage counters in the winsys for all buffers
40 * that have been added (cs_add_buffer) and two counters in the pipe
41 * driver for those that haven't been added yet.
42 */
43 if (unlikely(!ctx->b.ws->cs_memory_below_limit(ctx->b.rings.gfx.cs,
44 ctx->b.vram, ctx->b.gtt))) {
45 ctx->b.gtt = 0;
46 ctx->b.vram = 0;
47 ctx->b.rings.gfx.flush(ctx, RADEON_FLUSH_ASYNC, NULL);
48 return;
49 }
50 ctx->b.gtt = 0;
51 ctx->b.vram = 0;
52
53 /* If the CS is sufficiently large, don't count the space needed
54 * and just flush if there is not enough space left.
55 */
56 if (unlikely(cs->cdw > cs->max_dw - 2048))
57 ctx->b.rings.gfx.flush(ctx, RADEON_FLUSH_ASYNC, NULL);
58 }
59
60 void si_context_gfx_flush(void *context, unsigned flags,
61 struct pipe_fence_handle **fence)
62 {
63 struct si_context *ctx = context;
64 struct radeon_winsys_cs *cs = ctx->b.rings.gfx.cs;
65 struct radeon_winsys *ws = ctx->b.ws;
66
67 if (cs->cdw == ctx->b.initial_gfx_cs_size &&
68 (!fence || ctx->last_gfx_fence)) {
69 if (fence)
70 ws->fence_reference(fence, ctx->last_gfx_fence);
71 if (!(flags & RADEON_FLUSH_ASYNC))
72 ws->cs_sync_flush(cs);
73 return;
74 }
75
76 r600_preflush_suspend_features(&ctx->b);
77
78 ctx->b.flags |= SI_CONTEXT_FLUSH_AND_INV_FRAMEBUFFER |
79 SI_CONTEXT_INV_VMEM_L1 |
80 SI_CONTEXT_INV_GLOBAL_L2 |
81 /* this is probably not needed anymore */
82 SI_CONTEXT_PS_PARTIAL_FLUSH;
83 si_emit_cache_flush(ctx, NULL);
84
85 /* force to keep tiling flags */
86 flags |= RADEON_FLUSH_KEEP_TILING_FLAGS;
87
88 if (ctx->trace_buf)
89 si_trace_emit(ctx);
90
91 if (ctx->is_debug) {
92 unsigned i;
93
94 /* Save the IB for debug contexts. */
95 free(ctx->last_ib);
96 ctx->last_ib_dw_size = cs->cdw;
97 ctx->last_ib = malloc(cs->cdw * 4);
98 memcpy(ctx->last_ib, cs->buf, cs->cdw * 4);
99 r600_resource_reference(&ctx->last_trace_buf, ctx->trace_buf);
100 r600_resource_reference(&ctx->trace_buf, NULL);
101
102 /* Save the buffer list. */
103 if (ctx->last_bo_list) {
104 for (i = 0; i < ctx->last_bo_count; i++)
105 pb_reference(&ctx->last_bo_list[i].buf, NULL);
106 free(ctx->last_bo_list);
107 }
108 ctx->last_bo_count = ws->cs_get_buffer_list(cs, NULL);
109 ctx->last_bo_list = calloc(ctx->last_bo_count,
110 sizeof(ctx->last_bo_list[0]));
111 ws->cs_get_buffer_list(cs, ctx->last_bo_list);
112 }
113
114 /* Flush the CS. */
115 ws->cs_flush(cs, flags, &ctx->last_gfx_fence,
116 ctx->screen->b.cs_count++);
117
118 if (fence)
119 ws->fence_reference(fence, ctx->last_gfx_fence);
120
121 /* Check VM faults if needed. */
122 if (ctx->screen->b.debug_flags & DBG_CHECK_VM)
123 si_check_vm_faults(ctx);
124
125 si_begin_new_cs(ctx);
126 }
127
128 void si_begin_new_cs(struct si_context *ctx)
129 {
130 if (ctx->is_debug) {
131 uint32_t zero = 0;
132
133 /* Create a buffer used for writing trace IDs and initialize it to 0. */
134 assert(!ctx->trace_buf);
135 ctx->trace_buf = (struct r600_resource*)
136 pipe_buffer_create(ctx->b.b.screen, PIPE_BIND_CUSTOM,
137 PIPE_USAGE_STAGING, 4);
138 if (ctx->trace_buf)
139 pipe_buffer_write_nooverlap(&ctx->b.b, &ctx->trace_buf->b.b,
140 0, sizeof(zero), &zero);
141 ctx->trace_id = 0;
142 }
143
144 if (ctx->trace_buf)
145 si_trace_emit(ctx);
146
147 /* Flush read caches at the beginning of CS. */
148 ctx->b.flags |= SI_CONTEXT_FLUSH_AND_INV_FRAMEBUFFER |
149 SI_CONTEXT_INV_VMEM_L1 |
150 SI_CONTEXT_INV_GLOBAL_L2 |
151 SI_CONTEXT_INV_SMEM_L1 |
152 SI_CONTEXT_INV_ICACHE;
153
154 /* set all valid group as dirty so they get reemited on
155 * next draw command
156 */
157 si_pm4_reset_emitted(ctx);
158
159 /* The CS initialization should be emitted before everything else. */
160 si_pm4_emit(ctx, ctx->init_config);
161
162 ctx->framebuffer.dirty_cbufs = (1 << 8) - 1;
163 ctx->framebuffer.dirty_zsbuf = true;
164 si_mark_atom_dirty(ctx, &ctx->framebuffer.atom);
165
166 si_mark_atom_dirty(ctx, &ctx->clip_regs);
167 si_mark_atom_dirty(ctx, &ctx->clip_state.atom);
168 si_mark_atom_dirty(ctx, &ctx->msaa_sample_locs);
169 si_mark_atom_dirty(ctx, &ctx->msaa_config);
170 si_mark_atom_dirty(ctx, &ctx->sample_mask.atom);
171 si_mark_atom_dirty(ctx, &ctx->cb_target_mask);
172 si_mark_atom_dirty(ctx, &ctx->blend_color.atom);
173 si_mark_atom_dirty(ctx, &ctx->db_render_state);
174 si_mark_atom_dirty(ctx, &ctx->stencil_ref.atom);
175 si_mark_atom_dirty(ctx, &ctx->spi_map);
176 si_mark_atom_dirty(ctx, &ctx->spi_ps_input);
177 si_mark_atom_dirty(ctx, &ctx->b.streamout.enable_atom);
178 si_all_descriptors_begin_new_cs(ctx);
179
180 ctx->scissors.dirty_mask = (1 << SI_MAX_VIEWPORTS) - 1;
181 ctx->viewports.dirty_mask = (1 << SI_MAX_VIEWPORTS) - 1;
182 si_mark_atom_dirty(ctx, &ctx->scissors.atom);
183 si_mark_atom_dirty(ctx, &ctx->viewports.atom);
184
185 r600_postflush_resume_features(&ctx->b);
186
187 ctx->b.initial_gfx_cs_size = ctx->b.rings.gfx.cs->cdw;
188
189 /* Invalidate various draw states so that they are emitted before
190 * the first draw call. */
191 si_invalidate_draw_sh_constants(ctx);
192 ctx->last_primitive_restart_en = -1;
193 ctx->last_restart_index = SI_RESTART_INDEX_UNKNOWN;
194 ctx->last_gs_out_prim = -1;
195 ctx->last_prim = -1;
196 ctx->last_multi_vgt_param = -1;
197 ctx->last_ls_hs_config = -1;
198 ctx->last_rast_prim = -1;
199 ctx->last_sc_line_stipple = ~0;
200 ctx->emit_scratch_reloc = true;
201 ctx->last_ls = NULL;
202 ctx->last_tcs = NULL;
203 ctx->last_tes_sh_base = -1;
204 ctx->last_num_tcs_input_cp = -1;
205 }