From: Marek Olšák <marek.ol...@amd.com>

---
 src/gallium/drivers/radeonsi/si_compute.c     | 25 ++-------
 src/gallium/drivers/radeonsi/si_state.h       |  4 ++
 .../drivers/radeonsi/si_state_shaders.c       | 53 +++++++++++--------
 3 files changed, 39 insertions(+), 43 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_compute.c 
b/src/gallium/drivers/radeonsi/si_compute.c
index e20bae0afc4..f2d9cddbf03 100644
--- a/src/gallium/drivers/radeonsi/si_compute.c
+++ b/src/gallium/drivers/radeonsi/si_compute.c
@@ -181,42 +181,25 @@ static void *si_create_compute_state(
                                return NULL;
                        }
                } else {
                        assert(cso->ir_type == PIPE_SHADER_IR_NIR);
                        program->ir.nir = (struct nir_shader *) cso->prog;
                }
 
                program->compiler_ctx_state.debug = sctx->debug;
                program->compiler_ctx_state.is_debug_context = sctx->is_debug;
                p_atomic_inc(&sscreen->num_shaders_created);
-               util_queue_fence_init(&program->ready);
 
-               struct util_async_debug_callback async_debug;
-               bool wait =
-                       (sctx->debug.debug_message && !sctx->debug.async) ||
-                       sctx->is_debug ||
-                       si_can_dump_shader(sscreen, PIPE_SHADER_COMPUTE);
-
-               if (wait) {
-                       u_async_debug_init(&async_debug);
-                       program->compiler_ctx_state.debug = async_debug.base;
-               }
-
-               util_queue_add_job(&sscreen->shader_compiler_queue,
-                                  program, &program->ready,
-                                  si_create_compute_state_async, NULL);
-
-               if (wait) {
-                       util_queue_fence_wait(&program->ready);
-                       u_async_debug_drain(&async_debug, &sctx->debug);
-                       u_async_debug_cleanup(&async_debug);
-               }
+               si_schedule_initial_compile(sctx, PIPE_SHADER_COMPUTE,
+                                           &program->ready,
+                                           &program->compiler_ctx_state,
+                                           program, 
si_create_compute_state_async);
        } else {
                const struct pipe_llvm_program_header *header;
                const char *code;
                header = cso->prog;
                code = cso->prog + sizeof(struct pipe_llvm_program_header);
 
                ac_elf_read(code, header->num_bytes, &program->shader.binary);
                if (program->use_code_object_v2) {
                        const amd_kernel_code_t *code_object =
                                si_compute_get_code_object(program, 0);
diff --git a/src/gallium/drivers/radeonsi/si_state.h 
b/src/gallium/drivers/radeonsi/si_state.h
index 5b9d7402019..99991ee771f 100644
--- a/src/gallium/drivers/radeonsi/si_state.h
+++ b/src/gallium/drivers/radeonsi/si_state.h
@@ -485,20 +485,24 @@ void si_set_occlusion_query_state(struct si_context *sctx,
                                  bool old_perfect_enable);
 
 /* si_state_binning.c */
 void si_emit_dpbb_state(struct si_context *sctx);
 
 /* si_state_shaders.c */
 bool si_update_shaders(struct si_context *sctx);
 void si_init_shader_functions(struct si_context *sctx);
 bool si_init_shader_cache(struct si_screen *sscreen);
 void si_destroy_shader_cache(struct si_screen *sscreen);
+void si_schedule_initial_compile(struct si_context *sctx, unsigned processor,
+                                struct util_queue_fence *ready_fence,
+                                struct si_compiler_ctx_state 
*compiler_ctx_state,
+                                void *job, util_queue_execute_func execute);
 void si_get_active_slot_masks(const struct tgsi_shader_info *info,
                              uint32_t *const_and_shader_buffers,
                              uint64_t *samplers_and_images);
 void *si_get_blit_vs(struct si_context *sctx, enum blitter_attrib_type type,
                     unsigned num_layers);
 
 /* si_state_draw.c */
 void si_init_ia_multi_vgt_param_table(struct si_context *sctx);
 void si_emit_cache_flush(struct si_context *sctx);
 void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo);
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c 
b/src/gallium/drivers/radeonsi/si_state_shaders.c
index e7610af2fa7..f53548131d2 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -1968,20 +1968,48 @@ static void si_init_shader_selector_async(void *job, 
int thread_index)
                sel->gs_copy_shader = si_generate_gs_copy_shader(sscreen, 
compiler, sel, debug);
                if (!sel->gs_copy_shader) {
                        fprintf(stderr, "radeonsi: can't create GS copy 
shader\n");
                        return;
                }
 
                si_shader_vs(sscreen, sel->gs_copy_shader, sel);
        }
 }
 
+void si_schedule_initial_compile(struct si_context *sctx, unsigned processor,
+                                struct util_queue_fence *ready_fence,
+                                struct si_compiler_ctx_state 
*compiler_ctx_state,
+                                void *job, util_queue_execute_func execute)
+{
+       util_queue_fence_init(ready_fence);
+
+       struct util_async_debug_callback async_debug;
+       bool wait =
+               (sctx->debug.debug_message && !sctx->debug.async) ||
+               sctx->is_debug ||
+               si_can_dump_shader(sctx->screen, processor);
+
+       if (wait) {
+               u_async_debug_init(&async_debug);
+               compiler_ctx_state->debug = async_debug.base;
+       }
+
+       util_queue_add_job(&sctx->screen->shader_compiler_queue, job,
+                          ready_fence, execute, NULL);
+
+       if (wait) {
+               util_queue_fence_wait(ready_fence);
+               u_async_debug_drain(&async_debug, &sctx->debug);
+               u_async_debug_cleanup(&async_debug);
+       }
+}
+
 /* Return descriptor slot usage masks from the given shader info. */
 void si_get_active_slot_masks(const struct tgsi_shader_info *info,
                              uint32_t *const_and_shader_buffers,
                              uint64_t *samplers_and_images)
 {
        unsigned start, num_shaderbufs, num_constbufs, num_images, num_samplers;
 
        num_shaderbufs = util_last_bit(info->shader_buffers_declared);
        num_constbufs = util_last_bit(info->const_buffers_declared);
        /* two 8-byte images share one 16-byte slot */
@@ -2236,43 +2264,24 @@ static void *si_create_shader_selector(struct 
pipe_context *ctx,
        } else if (sel->info.writes_memory) {
                /* Case 2. */
                sel->db_shader_control |= S_02880C_Z_ORDER(V_02880C_LATE_Z) |
                                          S_02880C_EXEC_ON_HIER_FAIL(1);
        } else {
                /* Case 1. */
                sel->db_shader_control |= 
S_02880C_Z_ORDER(V_02880C_EARLY_Z_THEN_LATE_Z);
        }
 
        (void) mtx_init(&sel->mutex, mtx_plain);
-       util_queue_fence_init(&sel->ready);
-
-       struct util_async_debug_callback async_debug;
-       bool wait =
-               (sctx->debug.debug_message && !sctx->debug.async) ||
-               sctx->is_debug ||
-               si_can_dump_shader(sscreen, sel->info.processor);
-
-       if (wait) {
-               u_async_debug_init(&async_debug);
-               sel->compiler_ctx_state.debug = async_debug.base;
-       }
-
-       util_queue_add_job(&sscreen->shader_compiler_queue, sel,
-                          &sel->ready, si_init_shader_selector_async,
-                          NULL);
-
-       if (wait) {
-               util_queue_fence_wait(&sel->ready);
-               u_async_debug_drain(&async_debug, &sctx->debug);
-               u_async_debug_cleanup(&async_debug);
-       }
 
+       si_schedule_initial_compile(sctx, sel->info.processor, &sel->ready,
+                                   &sel->compiler_ctx_state, sel,
+                                   si_init_shader_selector_async);
        return sel;
 }
 
 static void si_update_streamout_state(struct si_context *sctx)
 {
        struct si_shader_selector *shader_with_so = si_get_vs(sctx)->cso;
 
        if (!shader_with_so)
                return;
 
-- 
2.17.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to