summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/ilo/ilo_cp.c
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2014-09-04 13:56:32 +0800
committerChia-I Wu <[email protected]>2014-09-09 13:31:36 +0800
commit55f80a3290cb0e07db780265369eb504573b4e62 (patch)
tree73f26e1b54ea39df331af02fe9092e42351da75f /src/gallium/drivers/ilo/ilo_cp.c
parentdab4a676f7590e94640461ad454911e09d95fa88 (diff)
ilo: make ilo_cp based on ilo_builder
This makes ilo_cp use the builder to manage batch buffers, and use ilo_builder_decode() to replace ilo_3d_pipeline_dump().
Diffstat (limited to 'src/gallium/drivers/ilo/ilo_cp.c')
-rw-r--r--src/gallium/drivers/ilo/ilo_cp.c236
1 files changed, 34 insertions, 202 deletions
diff --git a/src/gallium/drivers/ilo/ilo_cp.c b/src/gallium/drivers/ilo/ilo_cp.c
index 3ddec6c7bd9..4f65d443f49 100644
--- a/src/gallium/drivers/ilo/ilo_cp.c
+++ b/src/gallium/drivers/ilo/ilo_cp.c
@@ -25,168 +25,46 @@
* Chia-I Wu <[email protected]>
*/
-#include "genhw/genhw.h"
#include "intel_winsys.h"
#include "ilo_cp.h"
-/* the size of the private space */
-static const int ilo_cp_private = 2;
-
-/**
- * Dump the contents of the parser bo. This can only be called in the flush
- * callback.
- */
-void
-ilo_cp_dump(struct ilo_cp *cp)
-{
- ilo_printf("dumping %d bytes\n", cp->used * 4);
- if (cp->used)
- intel_winsys_decode_bo(cp->winsys, cp->bo, cp->used * 4);
-}
-
-/**
- * Save the command parser state for rewind.
- *
- * Note that this cannot rewind a flush, and the caller must make sure
- * that does not happend.
- */
-void
-ilo_cp_setjmp(struct ilo_cp *cp, struct ilo_cp_jmp_buf *jmp)
+static struct intel_bo *
+ilo_cp_end_batch(struct ilo_cp *cp, unsigned *used)
{
- jmp->id = pointer_to_intptr(cp->bo);
-
- jmp->size = cp->size;
- jmp->used = cp->used;
- jmp->stolen = cp->stolen;
- /* save reloc count to rewind ilo_cp_write_bo() */
- jmp->reloc_count = intel_bo_get_reloc_count(cp->bo);
-}
-
-/**
- * Rewind to the saved state.
- */
-void
-ilo_cp_longjmp(struct ilo_cp *cp, const struct ilo_cp_jmp_buf *jmp)
-{
- if (jmp->id != pointer_to_intptr(cp->bo)) {
- assert(!"invalid use of CP longjmp");
- return;
- }
-
- cp->size = jmp->size;
- cp->used = jmp->used;
- cp->stolen = jmp->stolen;
- intel_bo_truncate_relocs(cp->bo, jmp->reloc_count);
-}
-
-/**
- * Clear the parser buffer.
- */
-static void
-ilo_cp_clear_buffer(struct ilo_cp *cp)
-{
- cp->cmd_cur = 0;
- cp->cmd_end = 0;
-
- cp->used = 0;
- cp->stolen = 0;
-
- /*
- * Recalculate cp->size. This is needed not only because cp->stolen is
- * reset above, but also that ilo_cp_private are added to cp->size in
- * ilo_cp_end_buffer().
- */
- cp->size = cp->bo_size - ilo_cp_private;
-}
-
-/**
- * Add MI_BATCH_BUFFER_END to the private space of the parser buffer.
- */
-static void
-ilo_cp_end_buffer(struct ilo_cp *cp)
-{
- /* make the private space available */
- cp->size += ilo_cp_private;
-
- assert(cp->used + 2 <= cp->size);
-
- cp->ptr[cp->used++] = GEN6_MI_CMD(MI_BATCH_BUFFER_END);
-
- /*
- * From the Sandy Bridge PRM, volume 1 part 1, page 107:
- *
- * "The batch buffer must be QWord aligned and a multiple of QWords in
- * length."
- */
- if (cp->used & 1)
- cp->ptr[cp->used++] = GEN6_MI_CMD(MI_NOOP);
-}
-
-/**
- * Upload the parser buffer to the bo.
- */
-static int
-ilo_cp_upload_buffer(struct ilo_cp *cp)
-{
- int err;
-
- if (!cp->sys) {
- intel_bo_unmap(cp->bo);
- return 0;
- }
-
- err = intel_bo_pwrite(cp->bo, 0, cp->used * 4, cp->ptr);
- if (likely(!err && cp->stolen)) {
- const int offset = cp->bo_size - cp->stolen;
-
- err = intel_bo_pwrite(cp->bo, offset * 4,
- cp->stolen * 4, &cp->ptr[offset]);
- }
-
- return err;
-}
-
-/**
- * Reallocate the parser bo.
- */
-static void
-ilo_cp_realloc_bo(struct ilo_cp *cp)
-{
- struct intel_bo *bo;
+ ilo_cp_set_owner(cp, NULL, 0);
- /*
- * allocate the new bo before unreferencing the old one so that they
- * won't point at the same address, which is needed for jmpbuf
- */
- bo = intel_winsys_alloc_buffer(cp->winsys,
- "batch buffer", cp->bo_size * 4, true);
- if (unlikely(!bo)) {
- /* reuse the old one */
- bo = cp->bo;
- intel_bo_reference(bo);
+ if (!ilo_builder_batch_used(&cp->builder)) {
+ ilo_builder_batch_discard(&cp->builder);
+ return NULL;
}
- if (cp->bo)
- intel_bo_unreference(cp->bo);
- cp->bo = bo;
+ /* see ilo_cp_space() */
+ assert(ilo_builder_batch_space(&cp->builder) >= 2);
+ ilo_builder_batch_mi_batch_buffer_end(&cp->builder);
- if (!cp->sys)
- cp->ptr = intel_bo_map(cp->bo, true);
+ return ilo_builder_end(&cp->builder, used);
}
/**
- * Execute the parser bo.
+ * Flush the command parser and execute the commands. When the parser buffer
+ * is empty, the callback is not invoked.
*/
-static int
-ilo_cp_exec_bo(struct ilo_cp *cp)
+void
+ilo_cp_flush_internal(struct ilo_cp *cp)
{
const bool do_exec = !(ilo_debug & ILO_DEBUG_NOHW);
+ struct intel_bo *bo;
+ unsigned used;
int err;
+ bo = ilo_cp_end_batch(cp, &used);
+ if (!bo)
+ return;
+
if (likely(do_exec)) {
err = intel_winsys_submit_bo(cp->winsys, cp->ring,
- cp->bo, cp->used * 4, cp->render_ctx, cp->one_off_flags);
+ bo, used, cp->render_ctx, cp->one_off_flags);
}
else {
err = 0;
@@ -194,42 +72,17 @@ ilo_cp_exec_bo(struct ilo_cp *cp)
cp->one_off_flags = 0;
- return err;
-}
-
-/**
- * Flush the command parser and execute the commands. When the parser buffer
- * is empty, the callback is not invoked.
- */
-void
-ilo_cp_flush_internal(struct ilo_cp *cp)
-{
- int err;
-
- ilo_cp_set_owner(cp, NULL, 0);
-
- /* sanity check */
- assert(cp->bo_size == cp->size + cp->stolen + ilo_cp_private);
+ if (!err) {
+ if (cp->last_submitted_bo)
+ intel_bo_unreference(cp->last_submitted_bo);
+ cp->last_submitted_bo = bo;
+ intel_bo_reference(cp->last_submitted_bo);
- if (!cp->used) {
- /* return the space stolen and etc. */
- ilo_cp_clear_buffer(cp);
-
- return;
+ if (cp->flush_callback)
+ cp->flush_callback(cp, cp->flush_callback_data);
}
- ilo_cp_end_buffer(cp);
-
- /* upload and execute */
- err = ilo_cp_upload_buffer(cp);
- if (likely(!err))
- err = ilo_cp_exec_bo(cp);
-
- if (likely(!err && cp->flush_callback))
- cp->flush_callback(cp, cp->flush_callback_data);
-
- ilo_cp_clear_buffer(cp);
- ilo_cp_realloc_bo(cp);
+ ilo_builder_begin(&cp->builder);
}
/**
@@ -238,16 +91,9 @@ ilo_cp_flush_internal(struct ilo_cp *cp)
void
ilo_cp_destroy(struct ilo_cp *cp)
{
- if (cp->bo) {
- if (!cp->sys)
- intel_bo_unmap(cp->bo);
-
- intel_bo_unreference(cp->bo);
- }
+ ilo_builder_reset(&cp->builder);
intel_winsys_destroy_context(cp->winsys, cp->render_ctx);
-
- FREE(cp->sys);
FREE(cp);
}
@@ -255,7 +101,7 @@ ilo_cp_destroy(struct ilo_cp *cp)
* Create a command parser.
*/
struct ilo_cp *
-ilo_cp_create(struct intel_winsys *winsys, int size, bool direct_map)
+ilo_cp_create(const struct ilo_dev_info *dev, struct intel_winsys *winsys)
{
struct ilo_cp *cp;
@@ -273,26 +119,12 @@ ilo_cp_create(struct intel_winsys *winsys, int size, bool direct_map)
cp->ring = INTEL_RING_RENDER;
cp->no_implicit_flush = false;
- cp->bo_size = size;
+ ilo_builder_init(&cp->builder, dev, winsys);
- if (!direct_map) {
- cp->sys = MALLOC(cp->bo_size * 4);
- if (!cp->sys) {
- FREE(cp);
- return NULL;
- }
-
- cp->ptr = cp->sys;
- }
-
- ilo_cp_realloc_bo(cp);
- if (!cp->bo) {
- FREE(cp->sys);
- FREE(cp);
+ if (!ilo_builder_begin(&cp->builder)) {
+ ilo_cp_destroy(cp);
return NULL;
}
- ilo_cp_clear_buffer(cp);
-
return cp;
}