diff --git a/src/gallium/drivers/iris/iris_batch.c b/src/gallium/drivers/iris/iris_batch.c index 1b2b5cfb2ae..ae3c0cf3e0e 100644 --- a/src/gallium/drivers/iris/iris_batch.c +++ b/src/gallium/drivers/iris/iris_batch.c @@ -45,6 +45,7 @@ #include "iris_utrace.h" #include "common/intel_aux_map.h" +#include "common/intel_defines.h" #include "intel/common/intel_gem.h" #include "intel/ds/intel_tracepoints.h" #include "util/hash_table.h" @@ -250,8 +251,36 @@ iris_init_batch(struct iris_context *ice, iris_batch_reset(batch); } +static int +iris_context_priority_to_i915_priority(enum iris_context_priority priority) +{ + switch (priority) { + case IRIS_CONTEXT_HIGH_PRIORITY: + return INTEL_CONTEXT_HIGH_PRIORITY; + case IRIS_CONTEXT_LOW_PRIORITY: + return INTEL_CONTEXT_LOW_PRIORITY; + case IRIS_CONTEXT_MEDIUM_PRIORITY: + FALLTHROUGH; + default: + return INTEL_CONTEXT_MEDIUM_PRIORITY; + } +} + +static int +context_set_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id, + enum iris_context_priority priority) +{ + int err = 0; + int i915_priority = iris_context_priority_to_i915_priority(priority); + if (!intel_gem_set_context_param(iris_bufmgr_get_fd(bufmgr), ctx_id, + I915_CONTEXT_PARAM_PRIORITY, i915_priority)) + err = -errno; + + return err; +} + static void -iris_init_non_engine_contexts(struct iris_context *ice, int priority) +iris_init_non_engine_contexts(struct iris_context *ice) { struct iris_screen *screen = (void *) ice->ctx.screen; @@ -259,7 +288,7 @@ iris_init_non_engine_contexts(struct iris_context *ice, int priority) batch->ctx_id = iris_create_hw_context(screen->bufmgr, ice->protected); batch->exec_flags = I915_EXEC_RENDER; assert(batch->ctx_id); - iris_hw_context_set_priority(screen->bufmgr, batch->ctx_id, priority); + context_set_priority(screen->bufmgr, batch->ctx_id, ice->priority); } ice->batches[IRIS_BATCH_BLITTER].exec_flags = I915_EXEC_BLT; @@ -267,7 +296,7 @@ iris_init_non_engine_contexts(struct iris_context *ice, int priority) } static int -iris_create_engines_context(struct iris_context *ice, int priority) +iris_create_engines_context(struct iris_context *ice) { struct iris_screen *screen = (void *) ice->ctx.screen; const struct intel_device_info *devinfo = screen->devinfo; @@ -307,16 +336,16 @@ iris_create_engines_context(struct iris_context *ice, int priority) iris_hw_context_set_unrecoverable(screen->bufmgr, engines_ctx); iris_hw_context_set_vm_id(screen->bufmgr, engines_ctx); - iris_hw_context_set_priority(screen->bufmgr, engines_ctx, priority); + context_set_priority(screen->bufmgr, engines_ctx, ice->priority); free(engines_info); return engines_ctx; } static bool -iris_init_engines_context(struct iris_context *ice, int priority) +iris_init_engines_context(struct iris_context *ice) { - int engines_ctx = iris_create_engines_context(ice, priority); + int engines_ctx = iris_create_engines_context(ice); if (engines_ctx < 0) return false; @@ -331,14 +360,14 @@ iris_init_engines_context(struct iris_context *ice, int priority) } void -iris_init_batches(struct iris_context *ice, int priority) +iris_init_batches(struct iris_context *ice) { /* We have to do this early for iris_foreach_batch() to work */ for (int i = 0; i < IRIS_BATCH_COUNT; i++) ice->batches[i].screen = (void *) ice->ctx.screen; - if (!iris_init_engines_context(ice, priority)) - iris_init_non_engine_contexts(ice, priority); + if (!iris_init_engines_context(ice)) + iris_init_non_engine_contexts(ice); iris_foreach_batch(ice, batch) iris_init_batch(ice, batch - &ice->batches[0]); } @@ -732,6 +761,21 @@ iris_finish_batch(struct iris_batch *batch) record_batch_sizes(batch); } +static uint32_t +clone_hw_context(struct iris_batch *batch) +{ + struct iris_screen *screen = batch->screen; + struct iris_bufmgr *bufmgr = screen->bufmgr; + struct iris_context *ice = batch->ice; + bool protected = iris_hw_context_get_protected(bufmgr, batch->ctx_id); + uint32_t new_ctx = iris_create_hw_context(bufmgr, protected); + + if (new_ctx) + context_set_priority(bufmgr, new_ctx, ice->priority); + + return new_ctx; +} + /** * Replace our current GEM context with a new one (in case it got banned). */ @@ -743,9 +787,8 @@ replace_kernel_ctx(struct iris_batch *batch) struct iris_context *ice = batch->ice; if (ice->has_engines_context) { - int priority = iris_kernel_context_get_priority(bufmgr, batch->ctx_id); uint32_t old_ctx = batch->ctx_id; - int new_ctx = iris_create_engines_context(ice, priority); + int new_ctx = iris_create_engines_context(ice); if (new_ctx < 0) return false; iris_foreach_batch(ice, bat) { @@ -755,7 +798,7 @@ replace_kernel_ctx(struct iris_batch *batch) } iris_destroy_kernel_context(bufmgr, old_ctx); } else { - uint32_t new_ctx = iris_clone_hw_context(bufmgr, batch->ctx_id); + uint32_t new_ctx = clone_hw_context(batch); if (!new_ctx) return false; diff --git a/src/gallium/drivers/iris/iris_batch.h b/src/gallium/drivers/iris/iris_batch.h index 414740a55a7..664b9ceaa79 100644 --- a/src/gallium/drivers/iris/iris_batch.h +++ b/src/gallium/drivers/iris/iris_batch.h @@ -207,7 +207,7 @@ struct iris_batch { struct intel_ds_queue ds; }; -void iris_init_batches(struct iris_context *ice, int priority); +void iris_init_batches(struct iris_context *ice); void iris_chain_to_new_batch(struct iris_batch *batch); void iris_destroy_batches(struct iris_context *ice); void iris_batch_maybe_flush(struct iris_batch *batch, unsigned estimate); diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index d7429c80bc1..93826a9bae7 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -2100,29 +2100,7 @@ iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected) return ctx_id; } -int -iris_kernel_context_get_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id) -{ - uint64_t priority = 0; - intel_gem_get_context_param(bufmgr->fd, ctx_id, - I915_CONTEXT_PARAM_PRIORITY, &priority); - return priority; /* on error, return 0 i.e. default priority */ -} - -int -iris_hw_context_set_priority(struct iris_bufmgr *bufmgr, - uint32_t ctx_id, - int priority) -{ - int err = 0; - if (!intel_gem_set_context_param(bufmgr->fd, ctx_id, - I915_CONTEXT_PARAM_PRIORITY, priority)) - err = -errno; - - return err; -} - -static bool +bool iris_hw_context_get_protected(struct iris_bufmgr *bufmgr, uint32_t ctx_id) { uint64_t protected_content = 0; @@ -2132,21 +2110,6 @@ iris_hw_context_get_protected(struct iris_bufmgr *bufmgr, uint32_t ctx_id) return protected_content; } -uint32_t -iris_clone_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id) -{ - uint32_t new_ctx = - iris_create_hw_context(bufmgr, - iris_hw_context_get_protected(bufmgr, ctx_id)); - - if (new_ctx) { - int priority = iris_kernel_context_get_priority(bufmgr, ctx_id); - iris_hw_context_set_priority(bufmgr, new_ctx, priority); - } - - return new_ctx; -} - void iris_destroy_kernel_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id) { diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h index b70bb95346c..18ff67326bd 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.h +++ b/src/gallium/drivers/iris/iris_bufmgr.h @@ -483,13 +483,11 @@ void* iris_bufmgr_get_aux_map_context(struct iris_bufmgr *bufmgr); uint32_t iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected); uint32_t iris_clone_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id); -int iris_kernel_context_get_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id); void iris_hw_context_set_unrecoverable(struct iris_bufmgr *bufmgr, uint32_t ctx_id); void iris_hw_context_set_vm_id(struct iris_bufmgr *bufmgr, uint32_t ctx_id); -int iris_hw_context_set_priority(struct iris_bufmgr *bufmgr, - uint32_t ctx_id, int priority); +bool iris_hw_context_get_protected(struct iris_bufmgr *bufmgr, uint32_t ctx_id); void iris_destroy_kernel_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id); diff --git a/src/gallium/drivers/iris/iris_context.c b/src/gallium/drivers/iris/iris_context.c index 60ba2e7a366..cc48d535d46 100644 --- a/src/gallium/drivers/iris/iris_context.c +++ b/src/gallium/drivers/iris/iris_context.c @@ -34,7 +34,6 @@ #include "iris_resource.h" #include "iris_screen.h" #include "iris_utrace.h" -#include "common/intel_defines.h" #include "common/intel_sample_positions.h" /** @@ -360,11 +359,10 @@ iris_create_context(struct pipe_screen *pscreen, void *priv, unsigned flags) genX_call(devinfo, init_blorp, ice); genX_call(devinfo, init_query, ice); - int priority = 0; if (flags & PIPE_CONTEXT_HIGH_PRIORITY) - priority = INTEL_CONTEXT_HIGH_PRIORITY; + ice->priority = IRIS_CONTEXT_HIGH_PRIORITY; if (flags & PIPE_CONTEXT_LOW_PRIORITY) - priority = INTEL_CONTEXT_LOW_PRIORITY; + ice->priority = IRIS_CONTEXT_LOW_PRIORITY; if (flags & PIPE_CONTEXT_PROTECTED) ice->protected = true; @@ -374,7 +372,7 @@ iris_create_context(struct pipe_screen *pscreen, void *priv, unsigned flags) /* Do this before initializing the batches */ iris_utrace_init(ice); - iris_init_batches(ice, priority); + iris_init_batches(ice); screen->vtbl.init_render_context(&ice->batches[IRIS_BATCH_RENDER]); screen->vtbl.init_compute_context(&ice->batches[IRIS_BATCH_COMPUTE]); diff --git a/src/gallium/drivers/iris/iris_context.h b/src/gallium/drivers/iris/iris_context.h index 046a8ab7df6..ed418f2651a 100644 --- a/src/gallium/drivers/iris/iris_context.h +++ b/src/gallium/drivers/iris/iris_context.h @@ -612,6 +612,12 @@ struct iris_stream_output_target { bool zero_offset; }; +enum iris_context_priority { + IRIS_CONTEXT_MEDIUM_PRIORITY = 0, + IRIS_CONTEXT_LOW_PRIORITY, + IRIS_CONTEXT_HIGH_PRIORITY +}; + /** * The API context (derived from pipe_context). * @@ -642,6 +648,7 @@ struct iris_context { struct blorp_context blorp; struct iris_batch batches[IRIS_BATCH_COUNT]; + enum iris_context_priority priority; bool has_engines_context; struct u_upload_mgr *query_buffer_uploader;