+#include "driver_ddebug/dd_util.h"
+
+static const struct debug_named_value debug_options[] = {
+ /* Shader logging options: */
+ { "vs", DBG(VS), "Print vertex shaders" },
+ { "ps", DBG(PS), "Print pixel shaders" },
+ { "gs", DBG(GS), "Print geometry shaders" },
+ { "tcs", DBG(TCS), "Print tessellation control shaders" },
+ { "tes", DBG(TES), "Print tessellation evaluation shaders" },
+ { "cs", DBG(CS), "Print compute shaders" },
+ { "noir", DBG(NO_IR), "Don't print the LLVM IR"},
+ { "notgsi", DBG(NO_TGSI), "Don't print the TGSI"},
+ { "noasm", DBG(NO_ASM), "Don't print disassembled shaders"},
+ { "preoptir", DBG(PREOPT_IR), "Print the LLVM IR before initial optimizations" },
+
+ /* Shader compiler options the shader cache should be aware of: */
+ { "unsafemath", DBG(UNSAFE_MATH), "Enable unsafe math shader optimizations" },
+ { "sisched", DBG(SI_SCHED), "Enable LLVM SI Machine Instruction Scheduler." },
+ { "gisel", DBG(GISEL), "Enable LLVM global instruction selector." },
+
+ /* Shader compiler options (with no effect on the shader cache): */
+ { "checkir", DBG(CHECK_IR), "Enable additional sanity checks on shader IR" },
+ { "nir", DBG(NIR), "Enable experimental NIR shaders" },
+ { "mono", DBG(MONOLITHIC_SHADERS), "Use old-style monolithic shaders compiled on demand" },
+ { "nooptvariant", DBG(NO_OPT_VARIANT), "Disable compiling optimized shader variants." },
+
+ /* Information logging options: */
+ { "info", DBG(INFO), "Print driver information" },
+ { "tex", DBG(TEX), "Print texture info" },
+ { "compute", DBG(COMPUTE), "Print compute info" },
+ { "vm", DBG(VM), "Print virtual addresses when creating resources" },
+
+ /* Driver options: */
+ { "forcedma", DBG(FORCE_DMA), "Use asynchronous DMA for all operations when possible." },
+ { "nodma", DBG(NO_ASYNC_DMA), "Disable asynchronous DMA" },
+ { "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." },
+ { "nooutoforder", DBG(NO_OUT_OF_ORDER), "Disable out-of-order rasterization" },
+ { "nodpbb", DBG(NO_DPBB), "Disable DPBB." },
+ { "nodfsm", DBG(NO_DFSM), "Disable DFSM." },
+ { "dpbb", DBG(DPBB), "Enable DPBB." },
+ { "dfsm", DBG(DFSM), "Enable DFSM." },
+ { "nohyperz", DBG(NO_HYPERZ), "Disable Hyper-Z" },
+ { "norbplus", DBG(NO_RB_PLUS), "Disable RB+." },
+ { "no2d", DBG(NO_2D_TILING), "Disable 2D tiling" },
+ { "notiling", DBG(NO_TILING), "Disable tiling" },
+ { "nodcc", DBG(NO_DCC), "Disable DCC." },
+ { "nodccclear", DBG(NO_DCC_CLEAR), "Disable DCC fast clear." },
+ { "nodccfb", DBG(NO_DCC_FB), "Disable separate DCC on the main framebuffer" },
+ { "nodccmsaa", DBG(NO_DCC_MSAA), "Disable DCC for MSAA" },
+ { "nofmask", DBG(NO_FMASK), "Disable MSAA compression" },
+
+ /* Tests: */
+ { "testdma", DBG(TEST_DMA), "Invoke SDMA tests and exit." },
+ { "testvmfaultcp", DBG(TEST_VMFAULT_CP), "Invoke a CP VM fault test and exit." },
+ { "testvmfaultsdma", DBG(TEST_VMFAULT_SDMA), "Invoke a SDMA VM fault test and exit." },
+ { "testvmfaultshader", DBG(TEST_VMFAULT_SHADER), "Invoke a shader VM fault test and exit." },
+ { "testdmaperf", DBG(TEST_DMA_PERF), "Test DMA performance" },
+ { "testgds", DBG(TEST_GDS), "Test GDS." },
+ { "testgdsmm", DBG(TEST_GDS_MM), "Test GDS memory management." },
+ { "testgdsoamm", DBG(TEST_GDS_OA_MM), "Test GDS OA memory management." },
+
+ DEBUG_NAMED_VALUE_END /* must be last */
+};
+
+static void si_init_compiler(struct si_screen *sscreen,
+ struct ac_llvm_compiler *compiler)
+{
+ /* Only create the less-optimizing version of the compiler on APUs
+ * predating Ryzen (Raven). */
+ bool create_low_opt_compiler = !sscreen->info.has_dedicated_vram &&
+ sscreen->info.chip_class <= VI;
+
+ enum ac_target_machine_options tm_options =
+ (sscreen->debug_flags & DBG(SI_SCHED) ? AC_TM_SISCHED : 0) |
+ (sscreen->debug_flags & DBG(GISEL) ? AC_TM_ENABLE_GLOBAL_ISEL : 0) |
+ (sscreen->info.chip_class >= GFX9 ? AC_TM_FORCE_ENABLE_XNACK : 0) |
+ (sscreen->info.chip_class < GFX9 ? AC_TM_FORCE_DISABLE_XNACK : 0) |
+ (!sscreen->llvm_has_working_vgpr_indexing ? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH : 0) |
+ (sscreen->debug_flags & DBG(CHECK_IR) ? AC_TM_CHECK_IR : 0) |
+ (create_low_opt_compiler ? AC_TM_CREATE_LOW_OPT : 0);
+
+ ac_init_llvm_once();
+ ac_init_llvm_compiler(compiler, sscreen->info.family, tm_options);
+ compiler->passes = ac_create_llvm_passes(compiler->tm);
+
+ if (compiler->low_opt_tm)
+ compiler->low_opt_passes = ac_create_llvm_passes(compiler->low_opt_tm);
+}
+
+static void si_destroy_compiler(struct ac_llvm_compiler *compiler)
+{
+ ac_destroy_llvm_passes(compiler->passes);
+ ac_destroy_llvm_passes(compiler->low_opt_passes);
+ ac_destroy_llvm_compiler(compiler);
+}