radeonsi: unify duplicated code for initial shader compilation
authorMarek Olšák <marek.olsak@amd.com>
Thu, 14 Jun 2018 06:09:05 +0000 (02:09 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 29 Jun 2018 02:27:25 +0000 (22:27 -0400)
src/gallium/drivers/radeonsi/si_compute.c
src/gallium/drivers/radeonsi/si_state.h
src/gallium/drivers/radeonsi/si_state_shaders.c

index cb320323db3dd7e16befe4c6179021697db9fac2..fc419823bfa8af6b480a5cc18fbfc40e76f309c2 100644 (file)
@@ -188,28 +188,11 @@ static void *si_create_compute_state(
                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;
index 4f62c8b98f368eed8ac7c7c92ee1a21f5354774a..8fd80f73effe69af688d14c193c47da41161c1f6 100644 (file)
@@ -492,6 +492,10 @@ 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);
index f2569a53be3f9978a7e9073ed7417b2748aefc34..1a8b2c0852465ce9a21df7a7e6e18c201dbce84f 100644 (file)
@@ -1976,6 +1976,34 @@ static void si_init_shader_selector_async(void *job, int thread_index)
        }
 }
 
+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,
@@ -2244,29 +2272,10 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
        }
 
        (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;
 }