ac: move all LLVM module initialization into ac_create_module
[mesa.git] / src / gallium / drivers / radeonsi / si_pipe.c
index 1ca38ed55cb5e6773127679c4c0c5e1450f5bcc4..5da8a4b9873150c44fb87563a324979fdcb17bf0 100644 (file)
 #include "si_shader_internal.h"
 #include "sid.h"
 
+#include "ac_llvm_util.h"
 #include "radeon/radeon_uvd.h"
 #include "gallivm/lp_bld_misc.h"
 #include "util/disk_cache.h"
-#include "util/hash_table.h"
 #include "util/u_log.h"
 #include "util/u_memory.h"
 #include "util/u_suballoc.h"
@@ -82,6 +82,7 @@ static const struct debug_named_value debug_options[] = {
        { "nowc", DBG(NO_WC), "Disable GTT write combining" },
        { "check_vm", DBG(CHECK_VM), "Check VM faults and dump debug info." },
        { "reserve_vmid", DBG(RESERVE_VMID), "Force VMID reservation per context." },
+       { "zerovram", DBG(ZERO_VRAM), "Clear VRAM allocations." },
 
        /* 3D engine options: */
        { "switch_on_eop", DBG(SWITCH_ON_EOP), "Program WD/IA to switch on end-of-packet." },
@@ -118,13 +119,14 @@ static void si_init_compiler(struct si_screen *sscreen,
                (sscreen->info.chip_class < GFX9 ? AC_TM_FORCE_DISABLE_XNACK : 0) |
                (!sscreen->llvm_has_working_vgpr_indexing ? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH : 0);
 
+       const char *triple;
        compiler->tm = ac_create_target_machine(sscreen->info.family,
-                                               tm_options, &compiler->triple);
+                                               tm_options, &triple);
        if (!compiler->tm)
                return;
 
        compiler->target_library_info =
-               gallivm_create_target_library_info(compiler->triple);
+               gallivm_create_target_library_info(triple);
        if (!compiler->target_library_info)
                return;
 
@@ -149,22 +151,13 @@ static void si_init_compiler(struct si_screen *sscreen,
        /* This is recommended by the instruction combining pass. */
        LLVMAddEarlyCSEMemSSAPass(compiler->passmgr);
        LLVMAddInstructionCombiningPass(compiler->passmgr);
-
-       /* Get the data layout. */
-       LLVMTargetDataRef data_layout = LLVMCreateTargetDataLayout(compiler->tm);
-       if (!data_layout)
-               return;
-       compiler->data_layout = LLVMCopyStringRepOfTargetData(data_layout);
-       LLVMDisposeTargetData(data_layout);
 }
 
 static void si_destroy_compiler(struct si_compiler *compiler)
 {
-       if (compiler->data_layout)
-               LLVMDisposeMessage((char*)compiler->data_layout);
        if (compiler->passmgr)
                LLVMDisposePassManager(compiler->passmgr);
-#if HAVE_LLVM < 0x0500 || HAVE_LLVM >= 0x0700
+#if HAVE_LLVM >= 0x0700
        /* This crashes on LLVM 5.0 and 6.0 and Ubuntu 18.04, so leak it there. */
        if (compiler->target_library_info)
                gallivm_dispose_target_library_info(compiler->target_library_info);
@@ -241,7 +234,7 @@ static void si_destroy_context(struct pipe_context *context)
                                sctx->b.destroy_query(&sctx->b,
                                                        sctx->dcc_stats[i].ps_stats[j]);
 
-               r600_texture_reference(&sctx->dcc_stats[i].tex, NULL);
+               si_texture_reference(&sctx->dcc_stats[i].tex, NULL);
        }
 
        if (sctx->query_result_shader)
@@ -286,25 +279,25 @@ static void si_destroy_context(struct pipe_context *context)
        FREE(sctx);
 }
 
-static enum pipe_reset_status
-si_amdgpu_get_reset_status(struct pipe_context *ctx)
+static enum pipe_reset_status si_get_reset_status(struct pipe_context *ctx)
 {
        struct si_context *sctx = (struct si_context *)ctx;
 
-       return sctx->ws->ctx_query_reset_status(sctx->ctx);
-}
+       if (sctx->screen->info.has_gpu_reset_status_query)
+               return sctx->ws->ctx_query_reset_status(sctx->ctx);
 
-static enum pipe_reset_status si_get_reset_status(struct pipe_context *ctx)
-{
-       struct si_context *sctx = (struct si_context *)ctx;
-       unsigned latest = sctx->ws->query_value(sctx->ws,
-                                                 RADEON_GPU_RESET_COUNTER);
+       if (sctx->screen->info.has_gpu_reset_counter_query) {
+               unsigned latest = sctx->ws->query_value(sctx->ws,
+                                                       RADEON_GPU_RESET_COUNTER);
 
-       if (sctx->gpu_reset_counter == latest)
-               return PIPE_NO_RESET;
+               if (sctx->gpu_reset_counter == latest)
+                       return PIPE_NO_RESET;
 
-       sctx->gpu_reset_counter = latest;
-       return PIPE_UNKNOWN_CONTEXT_RESET;
+               sctx->gpu_reset_counter = latest;
+               return PIPE_UNKNOWN_CONTEXT_RESET;
+       }
+
+       return PIPE_NO_RESET;
 }
 
 static void si_set_device_reset_callback(struct pipe_context *ctx,
@@ -411,13 +404,12 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen,
        sctx->family = sscreen->info.family;
        sctx->chip_class = sscreen->info.chip_class;
 
-       if (sscreen->info.drm_major == 2 && sscreen->info.drm_minor >= 43) {
-               sctx->b.get_device_reset_status = si_get_reset_status;
+       if (sscreen->info.has_gpu_reset_counter_query) {
                sctx->gpu_reset_counter =
-                               sctx->ws->query_value(sctx->ws,
-                                                       RADEON_GPU_RESET_COUNTER);
+                       sctx->ws->query_value(sctx->ws, RADEON_GPU_RESET_COUNTER);
        }
 
+       sctx->b.get_device_reset_status = si_get_reset_status;
        sctx->b.set_device_reset_callback = si_set_device_reset_callback;
 
        si_init_context_texture_functions(sctx);
@@ -468,9 +460,6 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen,
                                                       sctx);
        }
 
-       if (sscreen->info.drm_major == 3)
-               sctx->b.get_device_reset_status = si_amdgpu_get_reset_status;
-
        si_init_buffer_functions(sctx);
        si_init_clear_functions(sctx);
        si_init_blit_functions(sctx);
@@ -540,7 +529,7 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen,
                        goto fail;
 
                /* Initialize the memory. */
-               struct radeon_winsys_cs *cs = sctx->gfx_cs;
+               struct radeon_cmdbuf *cs = sctx->gfx_cs;
                radeon_emit(cs, PKT3(PKT3_WRITE_DATA, 3, 0));
                radeon_emit(cs, S_370_DST_SEL(V_370_MEMORY_SYNC) |
                            S_370_WR_CONFIRM(1) |
@@ -869,7 +858,7 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
                ac_print_gpu_info(&sscreen->info);
 
        slab_create_parent(&sscreen->pool_transfers,
-                          sizeof(struct r600_transfer), 64);
+                          sizeof(struct si_transfer), 64);
 
        sscreen->force_aniso = MIN2(16, debug_get_num_option("R600_TEX_ANISO", -1));
        if (sscreen->force_aniso >= 0) {
@@ -1072,6 +1061,31 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
        if (debug_get_bool_option("RADEON_DUMP_SHADERS", false))
                sscreen->debug_flags |= DBG_ALL_SHADERS;
 
+       /* Syntax:
+        *     EQAA=s,z,c
+        * Example:
+        *     EQAA=8,4,2
+
+        * That means 8 coverage samples, 4 Z/S samples, and 2 color samples.
+        * Constraints:
+        *     s >= z >= c (ignoring this only wastes memory)
+        *     s = [2..16]
+        *     z = [2..8]
+        *     c = [2..8]
+        *
+        * Only MSAA color and depth buffers are overriden.
+        */
+       if (sscreen->info.has_eqaa_surface_allocator) {
+               const char *eqaa = debug_get_option("EQAA", NULL);
+               unsigned s,z,f;
+
+               if (eqaa && sscanf(eqaa, "%u,%u,%u", &s, &z, &f) == 3 && s && z && f) {
+                       sscreen->eqaa_force_coverage_samples = s;
+                       sscreen->eqaa_force_z_samples = z;
+                       sscreen->eqaa_force_color_samples = f;
+               }
+       }
+
        for (i = 0; i < num_comp_hi_threads; i++)
                si_init_compiler(sscreen, &sscreen->compiler[i]);
        for (i = 0; i < num_comp_lo_threads; i++)