/** * Emit context states and 3DPRIMITIVE. */ bool ilo_3d_pipeline_emit_draw(struct ilo_3d_pipeline *p, const struct ilo_context *ilo, int *prim_generated, int *prim_emitted) { bool success; if (ilo->dirty & ILO_DIRTY_SO && ilo->so.enabled && !ilo->so.append_bitmask) { /* * We keep track of the SVBI in the driver, so that we can restore it * when the HW context is invalidated (by another process). The value * needs to be reset when stream output is enabled and the targets are * changed. */ p->state.so_num_vertices = 0; /* on GEN7+, we need SOL_RESET to reset the SO write offsets */ if (p->dev->gen >= ILO_GEN(7)) ilo_cp_set_one_off_flags(p->cp, INTEL_EXEC_GEN7_SOL_RESET); } while (true) { struct ilo_builder_snapshot snapshot; /* we will rewind if aperture check below fails */ ilo_builder_batch_snapshot(&p->cp->builder, &snapshot); handle_invalid_batch_bo(p, false); /* draw! */ p->emit_draw(p, ilo); if (ilo_builder_validate(&ilo->cp->builder, 0, NULL)) { success = true; break; } /* rewind */ ilo_builder_batch_restore(&p->cp->builder, &snapshot); if (ilo_cp_empty(p->cp)) { success = false; break; } else { /* flush and try again */ ilo_cp_flush(p->cp, "out of aperture"); } } if (success) { const int num_verts = u_vertices_per_prim(u_reduced_prim(ilo->draw->mode)); const int max_emit = (p->state.so_max_vertices - p->state.so_num_vertices) / num_verts; const int generated = u_reduced_prims_for_vertices(ilo->draw->mode, ilo->draw->count); const int emitted = MIN2(generated, max_emit); p->state.so_num_vertices += emitted * num_verts; if (prim_generated) *prim_generated = generated; if (prim_emitted) *prim_emitted = emitted; } p->invalidate_flags = 0x0; return success; }
static bool draw_vbo(struct ilo_context *ilo, const struct ilo_state_vector *vec) { bool need_flush = false; bool success = true; int max_len, before_space; /* on Gen7 and Gen7.5, we need SOL_RESET to reset the SO write offsets */ if (ilo_dev_gen(ilo->dev) >= ILO_GEN(7) && ilo_dev_gen(ilo->dev) <= ILO_GEN(7.5) && (vec->dirty & ILO_DIRTY_SO) && vec->so.enabled && !vec->so.append_bitmask) { ilo_cp_submit(ilo->cp, "SOL_RESET"); ilo_cp_set_one_off_flags(ilo->cp, INTEL_EXEC_GEN7_SOL_RESET); } if (ilo_builder_batch_used(&ilo->cp->builder)) { /* * Without a better tracking mechanism, when the framebuffer changes, we * have to assume that the old framebuffer may be sampled from. If that * happens in the middle of a batch buffer, we need to insert manual * flushes. */ need_flush = (vec->dirty & ILO_DIRTY_FB); /* same to SO target changes */ need_flush |= (vec->dirty & ILO_DIRTY_SO); } ilo_draw_set_owner(ilo); /* make sure there is enough room first */ max_len = ilo_render_get_draw_len(ilo->render, vec); if (need_flush) max_len += ilo_render_get_flush_len(ilo->render); if (max_len > ilo_cp_space(ilo->cp)) { ilo_cp_submit(ilo->cp, "out of space"); need_flush = false; assert(max_len <= ilo_cp_space(ilo->cp)); } /* space available before emission */ before_space = ilo_cp_space(ilo->cp); if (need_flush) ilo_render_emit_flush(ilo->render); while (true) { struct ilo_builder_snapshot snapshot; ilo_builder_batch_snapshot(&ilo->cp->builder, &snapshot); ilo_render_emit_draw(ilo->render, vec); if (!ilo_builder_validate(&ilo->cp->builder, 0, NULL)) { ilo_builder_batch_restore(&ilo->cp->builder, &snapshot); /* flush and try again */ if (ilo_builder_batch_used(&ilo->cp->builder)) { ilo_cp_submit(ilo->cp, "out of aperture"); continue; } success = false; } break; } /* sanity check size estimation */ assert(before_space - ilo_cp_space(ilo->cp) <= max_len); return success; }