#include "intel/common/gen_gem.h"
#include "util/hash_table.h"
#include "util/set.h"
+#include "util/u_upload_mgr.h"
#include "main/macros.h"
#include <errno.h>
#define FILE_DEBUG_FLAG DEBUG_BUFMGR
-/* Terminating the batch takes either 4 bytes for MI_BATCH_BUFFER_END
- * or 12 bytes for MI_BATCH_BUFFER_START (when chaining). Plus, we may
- * need an extra 4 bytes to pad out to the nearest QWord. So reserve 16.
- */
-#define BATCH_RESERVED 16
-
static void
iris_batch_reset(struct iris_batch *batch);
}
static unsigned
-decode_get_state_size(void *v_batch, uint32_t offset_from_base)
+decode_get_state_size(void *v_batch,
+ uint64_t address,
+ UNUSED uint64_t base_address)
{
struct iris_batch *batch = v_batch;
-
- /* The decoder gives us offsets from a base address, which is not great.
- * Binding tables are relative to surface state base address, and other
- * state is relative to dynamic state base address. These could alias,
- * but in practice it's unlikely because surface offsets are always in
- * the [0, 64K) range, and we assign dynamic state addresses starting at
- * the top of the 4GB range. We should fix this but it's likely good
- * enough for now.
- */
unsigned size = (uintptr_t)
- _mesa_hash_table_u64_search(batch->state_sizes, offset_from_base);
+ _mesa_hash_table_u64_search(batch->state_sizes, address);
return size;
}
}
void
-iris_init_batch(struct iris_batch *batch,
- struct iris_screen *screen,
- struct iris_vtable *vtbl,
- struct pipe_debug_callback *dbg,
- struct pipe_device_reset_callback *reset,
- struct hash_table_u64 *state_sizes,
- struct iris_batch *all_batches,
+iris_init_batch(struct iris_context *ice,
enum iris_batch_name name,
- uint8_t engine,
int priority)
{
+ struct iris_batch *batch = &ice->batches[name];
+ struct iris_screen *screen = (void *) ice->ctx.screen;
+
batch->screen = screen;
- batch->vtbl = vtbl;
- batch->dbg = dbg;
- batch->reset = reset;
- batch->state_sizes = state_sizes;
+ batch->dbg = &ice->dbg;
+ batch->reset = &ice->reset;
+ batch->state_sizes = ice->state.sizes;
batch->name = name;
- /* engine should be one of I915_EXEC_RENDER, I915_EXEC_BLT, etc. */
- assert((engine & ~I915_EXEC_RING_MASK) == 0);
- assert(util_bitcount(engine) == 1);
- batch->engine = engine;
+ batch->seqno.uploader =
+ u_upload_create(&ice->ctx, 4096, PIPE_BIND_CUSTOM,
+ PIPE_USAGE_STAGING, 0);
+ iris_seqno_init(batch);
batch->hw_ctx_id = iris_create_hw_context(screen->bufmgr);
assert(batch->hw_ctx_id);
iris_hw_context_set_priority(screen->bufmgr, batch->hw_ctx_id, priority);
util_dynarray_init(&batch->exec_fences, ralloc_context(NULL));
- util_dynarray_init(&batch->syncpts, ralloc_context(NULL));
+ util_dynarray_init(&batch->syncobjs, ralloc_context(NULL));
batch->exec_count = 0;
batch->exec_array_size = 100;
memset(batch->other_batches, 0, sizeof(batch->other_batches));
for (int i = 0, j = 0; i < IRIS_BATCH_COUNT; i++) {
- if (&all_batches[i] != batch)
- batch->other_batches[j++] = &all_batches[i];
+ if (i != name)
+ batch->other_batches[j++] = &ice->batches[i];
}
if (unlikely(INTEL_DEBUG)) {
if (other_entry &&
((other_entry->flags & EXEC_OBJECT_WRITE) || writable)) {
iris_batch_flush(batch->other_batches[b]);
- iris_batch_add_syncpt(batch, batch->other_batches[b]->last_syncpt,
- I915_EXEC_FENCE_WAIT);
+ iris_batch_add_syncobj(batch,
+ batch->other_batches[b]->last_seqno->syncobj,
+ I915_EXEC_FENCE_WAIT);
}
}
}
iris_use_pinned_bo(batch, batch->bo, false);
}
+static void
+iris_batch_maybe_noop(struct iris_batch *batch)
+{
+ /* We only insert the NOOP at the beginning of the batch. */
+ assert(iris_batch_bytes_used(batch) == 0);
+
+ if (batch->noop_enabled) {
+ /* Emit MI_BATCH_BUFFER_END to prevent any further command to be
+ * executed.
+ */
+ uint32_t *map = batch->map_next;
+
+ map[0] = (0xA << 23);
+
+ batch->map_next += 4;
+ }
+}
+
static void
iris_batch_reset(struct iris_batch *batch)
{
iris_bo_unreference(batch->bo);
batch->primary_batch_size = 0;
+ batch->total_chained_batch_size = 0;
batch->contains_draw = false;
batch->decoder.surface_base = batch->last_surface_base_address;
create_batch(batch);
assert(batch->bo->index == 0);
- struct iris_syncpt *syncpt = iris_create_syncpt(screen);
- iris_batch_add_syncpt(batch, syncpt, I915_EXEC_FENCE_SIGNAL);
- iris_syncpt_reference(screen, &syncpt, NULL);
+ struct iris_syncobj *syncobj = iris_create_syncobj(screen);
+ iris_batch_add_syncobj(batch, syncobj, I915_EXEC_FENCE_SIGNAL);
+ iris_syncobj_reference(screen, &syncobj, NULL);
iris_cache_sets_clear(batch);
+
+ /* Always add the workaround BO, it contains a driver identifier at the
+ * beginning quite helpful to debug error states.
+ */
+ iris_use_pinned_bo(batch, screen->workaround_bo, false);
+
+ iris_batch_maybe_noop(batch);
}
void
ralloc_free(batch->exec_fences.mem_ctx);
- util_dynarray_foreach(&batch->syncpts, struct iris_syncpt *, s)
- iris_syncpt_reference(screen, s, NULL);
- ralloc_free(batch->syncpts.mem_ctx);
+ pipe_resource_reference(&batch->seqno.ref.res, NULL);
- iris_syncpt_reference(screen, &batch->last_syncpt, NULL);
+ util_dynarray_foreach(&batch->syncobjs, struct iris_syncobj *, s)
+ iris_syncobj_reference(screen, s, NULL);
+ ralloc_free(batch->syncobjs.mem_ctx);
+
+ iris_seqno_reference(batch->screen, &batch->last_seqno, NULL);
+ u_upload_destroy(batch->seqno.uploader);
iris_bo_unreference(batch->bo);
batch->bo = NULL;
}
}
+static void
+record_batch_sizes(struct iris_batch *batch)
+{
+ unsigned batch_size = iris_batch_bytes_used(batch);
+
+ VG(VALGRIND_CHECK_MEM_IS_DEFINED(batch->map, batch_size));
+
+ if (batch->bo == batch->exec_bos[0])
+ batch->primary_batch_size = batch_size;
+
+ batch->total_chained_batch_size += batch_size;
+}
+
void
iris_chain_to_new_batch(struct iris_batch *batch)
{
- /* We only support chaining a single time. */
- assert(batch->bo == batch->exec_bos[0]);
-
- VG(void *map = batch->map);
uint32_t *cmd = batch->map_next;
uint64_t *addr = batch->map_next + 4;
batch->map_next += 12;
+ record_batch_sizes(batch);
+
/* No longer held by batch->bo, still held by validation list */
iris_bo_unreference(batch->bo);
- batch->primary_batch_size = iris_batch_bytes_used(batch);
create_batch(batch);
/* Emit MI_BATCH_BUFFER_START to chain to another batch. */
*cmd = (0x31 << 23) | (1 << 8) | (3 - 2);
*addr = batch->bo->gtt_offset;
-
- VG(VALGRIND_CHECK_MEM_IS_DEFINED(map, batch->primary_batch_size));
}
-
static void
add_aux_map_bos_to_batch(struct iris_batch *batch)
{
}
}
+static void
+finish_seqno(struct iris_batch *batch)
+{
+ struct iris_seqno *sq = iris_seqno_new(batch, IRIS_SEQNO_END);
+ if (!sq)
+ return;
+
+ iris_seqno_reference(batch->screen, &batch->last_seqno, sq);
+ iris_seqno_reference(batch->screen, &sq, NULL);
+}
+
/**
* Terminate a batch with MI_BATCH_BUFFER_END.
*/
{
add_aux_map_bos_to_batch(batch);
+ finish_seqno(batch);
+
/* Emit MI_BATCH_BUFFER_END to finish our batch. */
uint32_t *map = batch->map_next;
map[0] = (0xA << 23);
batch->map_next += 4;
- VG(VALGRIND_CHECK_MEM_IS_DEFINED(batch->map, iris_batch_bytes_used(batch)));
- if (batch->bo == batch->exec_bos[0])
- batch->primary_batch_size = iris_batch_bytes_used(batch);
+ record_batch_sizes(batch);
}
/**
.batch_start_offset = 0,
/* This must be QWord aligned. */
.batch_len = ALIGN(batch->primary_batch_size, 8),
- .flags = batch->engine |
+ .flags = I915_EXEC_RENDER |
I915_EXEC_NO_RELOC |
I915_EXEC_BATCH_FIRST |
I915_EXEC_HANDLE_LUT,
if (unlikely(INTEL_DEBUG &
(DEBUG_BATCH | DEBUG_SUBMIT | DEBUG_PIPE_CONTROL))) {
- int bytes_for_commands = iris_batch_bytes_used(batch);
- int second_bytes = 0;
- if (batch->bo != batch->exec_bos[0]) {
- second_bytes = bytes_for_commands;
- bytes_for_commands += batch->primary_batch_size;
- }
- fprintf(stderr, "%19s:%-3d: %s batch [%u] flush with %5d+%5db (%0.1f%%) "
+ const char *basefile = strstr(file, "iris/");
+ if (basefile)
+ file = basefile + 5;
+
+ fprintf(stderr, "%19s:%-3d: %s batch [%u] flush with %5db (%0.1f%%) "
"(cmds), %4d BOs (%0.1fMb aperture)\n",
file, line, batch_name_to_string(batch->name), batch->hw_ctx_id,
- batch->primary_batch_size, second_bytes,
- 100.0f * bytes_for_commands / BATCH_SZ,
+ batch->total_chained_batch_size,
+ 100.0f * batch->total_chained_batch_size / BATCH_SZ,
batch->exec_count,
(float) batch->aperture_space / (1024 * 1024));
batch->exec_count = 0;
batch->aperture_space = 0;
- struct iris_syncpt *syncpt =
- ((struct iris_syncpt **) util_dynarray_begin(&batch->syncpts))[0];
- iris_syncpt_reference(screen, &batch->last_syncpt, syncpt);
-
- util_dynarray_foreach(&batch->syncpts, struct iris_syncpt *, s)
- iris_syncpt_reference(screen, s, NULL);
- util_dynarray_clear(&batch->syncpts);
+ util_dynarray_foreach(&batch->syncobjs, struct iris_syncobj *, s)
+ iris_syncobj_reference(screen, s, NULL);
+ util_dynarray_clear(&batch->syncobjs);
util_dynarray_clear(&batch->exec_fences);
*/
if (ret == -EIO && replace_hw_ctx(batch)) {
if (batch->reset->reset) {
- /* Tell the state tracker the device is lost and it was our fault. */
+ /* Tell gallium frontends the device is lost and it was our fault. */
batch->reset->reset(batch->reset->data, PIPE_GUILTY_CONTEXT_RESET);
}
{
return find_validation_entry(batch, bo) != NULL;
}
+
+/**
+ * Updates the state of the noop feature.
+ */
+uint64_t
+iris_batch_prepare_noop(struct iris_batch *batch, bool noop_enable, uint64_t dirty_flags)
+{
+ if (batch->noop_enabled == noop_enable)
+ return 0;
+
+ batch->noop_enabled = noop_enable;
+
+ iris_batch_flush(batch);
+
+ /* If the batch was empty, flush had no effect, so insert our noop. */
+ if (iris_batch_bytes_used(batch) == 0)
+ iris_batch_maybe_noop(batch);
+
+ /* We only need to update the entire state if we transition from noop ->
+ * not-noop.
+ */
+ return !batch->noop_enabled ? dirty_flags : 0;
+}