radeonsi/nir: always lower ballot masks as 64-bit, codegen handles it
[mesa.git] / src / gallium / drivers / radeonsi / si_shader_internal.h
index 5c736f61251435cc389759430b682e8071cbc64e..b576d94a63f2488376be1d88c6a38013de30dccc 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright 2016 Advanced Micro Devices, Inc.
+ * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 #include "gallivm/lp_bld_tgsi.h"
 #include "tgsi/tgsi_parse.h"
 #include "ac_shader_abi.h"
-#include "ac_llvm_util.h"
-#include "ac_llvm_build.h"
 
 #include <llvm-c/Core.h>
 #include <llvm-c/TargetMachine.h>
 
 struct pipe_debug_callback;
-struct ac_shader_binary;
 
 #define RADEON_LLVM_MAX_INPUT_SLOTS 32
 #define RADEON_LLVM_MAX_INPUTS 32 * 4
 #define RADEON_LLVM_MAX_OUTPUTS 32 * 4
 
-#define RADEON_LLVM_INITIAL_CF_DEPTH 4
-
 #define RADEON_LLVM_MAX_SYSTEM_VALUES 11
 #define RADEON_LLVM_MAX_ADDRS 16
 
-struct si_llvm_flow;
+enum si_arg_regfile {
+       ARG_SGPR,
+       ARG_VGPR
+};
+
+/**
+ * Used to collect types and other info about arguments of the LLVM function
+ * before the function is created.
+ */
+struct si_function_info {
+       LLVMTypeRef types[100];
+       LLVMValueRef *assign[100];
+       unsigned num_sgpr_params;
+       unsigned num_params;
+};
+
+struct si_shader_output_values {
+       LLVMValueRef values[4];
+       unsigned semantic_name;
+       unsigned semantic_index;
+       ubyte vertex_stream[4];
+};
 
 struct si_shader_context {
        struct lp_build_tgsi_context bld_base;
@@ -65,9 +82,6 @@ struct si_shader_context {
        unsigned num_images;
        unsigned num_samplers;
 
-       /* Whether the prolog will be compiled separately. */
-       bool separate_prolog;
-
        struct ac_shader_abi abi;
 
        /** This function is responsible for initilizing the inputs array and will be
@@ -98,11 +112,8 @@ struct si_shader_context {
        LLVMValueRef *imms;
        unsigned imms_num;
 
-       struct si_llvm_flow *flow;
-       unsigned flow_depth;
-       unsigned flow_depth_max;
-
-       struct lp_build_if_state merged_wrap_if_state;
+       LLVMBasicBlockRef merged_wrap_if_entry_block;
+       int merged_wrap_if_label;
 
        struct tgsi_array_info *temp_arrays;
        LLVMValueRef *temp_array_allocas;
@@ -162,56 +173,51 @@ struct si_shader_context {
        /* Layout of TCS outputs / TES inputs:
         *   [0:12] = stride between output patches in DW, num_outputs * num_vertices * 4
         *            max = 32*32*4 + 32*4
-        *   [26:31] = gl_PatchVerticesIn, max = 32
+        *   [13:18] = gl_PatchVerticesIn, max = 32
+        *   [19:31] = high 13 bits of the 32-bit address of tessellation ring buffers
         */
        int param_tcs_out_lds_layout;
-       int param_tcs_offchip_addr_base64k;
-       int param_tcs_factor_addr_base64k;
        int param_tcs_offchip_offset;
        int param_tcs_factor_offset;
-       int param_tcs_patch_id;
-       int param_tcs_rel_ids;
 
        /* API TES */
+       int param_tes_offchip_addr;
        int param_tes_u;
        int param_tes_v;
        int param_tes_rel_patch_id;
-       int param_tes_patch_id;
        /* HW ES */
        int param_es2gs_offset;
+       /* HW GS */
+       /* On gfx10:
+        *  - bits 0..10: ordered_wave_id
+        *  - bits 12..20: number of vertices in group
+        *  - bits 22..30: number of primitives in group
+        */
+       LLVMValueRef gs_tg_info;
        /* API GS */
        int param_gs2vs_offset;
        int param_gs_wave_id; /* GFX6 */
-       int param_gs_vtx0_offset; /* in dwords (GFX6) */
-       int param_gs_vtx1_offset; /* in dwords (GFX6) */
-       int param_gs_prim_id;
-       int param_gs_vtx2_offset; /* in dwords (GFX6) */
-       int param_gs_vtx3_offset; /* in dwords (GFX6) */
-       int param_gs_vtx4_offset; /* in dwords (GFX6) */
-       int param_gs_vtx5_offset; /* in dwords (GFX6) */
-       int param_gs_instance_id;
+       LLVMValueRef gs_vtx_offset[6]; /* in dwords (GFX6) */
        int param_gs_vtx01_offset; /* in dwords (GFX9) */
        int param_gs_vtx23_offset; /* in dwords (GFX9) */
        int param_gs_vtx45_offset; /* in dwords (GFX9) */
        /* CS */
-       int param_grid_size;
        int param_block_size;
-       int param_block_id[3];
-       int param_thread_id;
-
-       LLVMTargetMachineRef tm;
+       int param_cs_user_data;
 
-       unsigned range_md_kind;
-       unsigned fpmath_md_kind;
-       LLVMValueRef fpmath_md_2p5_ulp;
+       struct ac_llvm_compiler *compiler;
 
        /* Preloaded descriptors. */
        LLVMValueRef esgs_ring;
        LLVMValueRef gsvs_ring[4];
+       LLVMValueRef tess_offchip_ring;
 
-       LLVMValueRef lds;
        LLVMValueRef invoc0_tess_factors[6]; /* outer[4], inner[2] */
        LLVMValueRef gs_next_vertex[4];
+       LLVMValueRef gs_curprim_verts[4];
+       LLVMValueRef gs_generated_prims[4];
+       LLVMValueRef gs_ngg_emit;
+       LLVMValueRef gs_ngg_scratch;
        LLVMValueRef postponed_kill;
        LLVMValueRef return_value;
 
@@ -229,8 +235,8 @@ struct si_shader_context {
 
        LLVMValueRef i32_0;
        LLVMValueRef i32_1;
-
-       LLVMValueRef shared_memory;
+       LLVMValueRef i1false;
+       LLVMValueRef i1true;
 };
 
 static inline struct si_shader_context *
@@ -246,11 +252,19 @@ si_shader_context_from_abi(struct ac_shader_abi *abi)
        return container_of(abi, ctx, abi);
 }
 
-void si_llvm_add_attribute(LLVMValueRef F, const char *name, int value);
-
-unsigned si_llvm_compile(LLVMModuleRef M, struct ac_shader_binary *binary,
-                        LLVMTargetMachineRef tm,
-                        struct pipe_debug_callback *debug);
+void si_init_function_info(struct si_function_info *fninfo);
+unsigned add_arg_assign(struct si_function_info *fninfo,
+                       enum si_arg_regfile regfile, LLVMTypeRef type,
+                       LLVMValueRef *assign);
+void si_create_function(struct si_shader_context *ctx,
+                       const char *name,
+                       LLVMTypeRef *returns, unsigned num_returns,
+                       struct si_function_info *fninfo,
+                       unsigned max_workgroup_size);
+unsigned si_llvm_compile(LLVMModuleRef M, struct si_shader_binary *binary,
+                        struct ac_llvm_compiler *compiler,
+                        struct pipe_debug_callback *debug,
+                        bool less_optimized, unsigned wave_size);
 
 LLVMTypeRef tgsi2llvmtype(struct lp_build_tgsi_context *bld_base,
                          enum tgsi_opcode_type type);
@@ -264,9 +278,11 @@ LLVMValueRef si_llvm_bound_index(struct si_shader_context *ctx,
 
 void si_llvm_context_init(struct si_shader_context *ctx,
                          struct si_screen *sscreen,
-                         LLVMTargetMachineRef tm);
-void si_llvm_context_set_tgsi(struct si_shader_context *ctx,
-                             struct si_shader *shader);
+                         struct ac_llvm_compiler *compiler,
+                         unsigned wave_size,
+                         unsigned ballot_mask_bits);
+void si_llvm_context_set_ir(struct si_shader_context *ctx,
+                           struct si_shader *shader);
 
 void si_llvm_create_func(struct si_shader_context *ctx,
                         const char *name,
@@ -278,7 +294,7 @@ void si_llvm_dispose(struct si_shader_context *ctx);
 void si_llvm_optimize_module(struct si_shader_context *ctx);
 
 LLVMValueRef si_llvm_emit_fetch_64bit(struct lp_build_tgsi_context *bld_base,
-                                     enum tgsi_opcode_type type,
+                                     LLVMTypeRef type,
                                      LLVMValueRef ptr,
                                      LLVMValueRef ptr2);
 
@@ -287,27 +303,44 @@ LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
                                enum tgsi_opcode_type type,
                                unsigned swizzle);
 
+void si_llvm_emit_kill(struct ac_shader_abi *abi, LLVMValueRef visible);
+
+LLVMValueRef si_nir_load_input_tes(struct ac_shader_abi *abi,
+                                  LLVMTypeRef type,
+                                  LLVMValueRef vertex_index,
+                                  LLVMValueRef param_index,
+                                  unsigned const_index,
+                                  unsigned location,
+                                  unsigned driver_location,
+                                  unsigned component,
+                                  unsigned num_components,
+                                  bool is_patch,
+                                  bool is_compact,
+                                  bool load_input);
+
+LLVMValueRef si_llvm_load_input_gs(struct ac_shader_abi *abi,
+                                  unsigned input_index,
+                                  unsigned vtx_offset_param,
+                                  LLVMTypeRef type,
+                                  unsigned swizzle);
+
+LLVMValueRef si_nir_lookup_interp_param(struct ac_shader_abi *abi,
+                                       enum glsl_interp_mode interp,
+                                       unsigned location);
+
 void si_llvm_emit_store(struct lp_build_tgsi_context *bld_base,
                        const struct tgsi_full_instruction *inst,
                        const struct tgsi_opcode_info *info,
                        unsigned index,
                        LLVMValueRef dst[4]);
 
-/* Combine these with & instead of |. */
-#define NOOP_WAITCNT 0xf7f
-#define LGKM_CNT 0x07f
-#define VM_CNT 0xf70
-
-void si_emit_waitcnt(struct si_shader_context *ctx, unsigned simm16);
-
 LLVMValueRef si_get_indirect_index(struct si_shader_context *ctx,
                                   const struct tgsi_ind_register *ind,
                                   unsigned addr_mul, int rel_index);
 LLVMValueRef si_get_bounded_indirect_index(struct si_shader_context *ctx,
                                           const struct tgsi_ind_register *ind,
                                           int rel_index, unsigned num);
-
-LLVMTypeRef si_const_array(LLVMTypeRef elem_type, int num_elements);
+LLVMValueRef si_get_sample_id(struct si_shader_context *ctx);
 
 void si_shader_context_init_alu(struct lp_build_tgsi_context *bld_base);
 void si_shader_context_init_mem(struct si_shader_context *ctx);
@@ -317,13 +350,27 @@ LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
                                  enum ac_descriptor_type type);
 LLVMValueRef si_load_image_desc(struct si_shader_context *ctx,
                                LLVMValueRef list, LLVMValueRef index,
-                               enum ac_descriptor_type desc_type, bool dcc_off);
+                               enum ac_descriptor_type desc_type,
+                               bool uses_store, bool bindless);
+LLVMValueRef si_nir_emit_fbfetch(struct ac_shader_abi *abi);
 
 void si_load_system_value(struct si_shader_context *ctx,
                          unsigned index,
                          const struct tgsi_full_declaration *decl);
-void si_declare_compute_memory(struct si_shader_context *ctx,
-                              const struct tgsi_full_declaration *decl);
+void si_declare_compute_memory(struct si_shader_context *ctx);
+void si_tgsi_declare_compute_memory(struct si_shader_context *ctx,
+                                   const struct tgsi_full_declaration *decl);
+
+LLVMValueRef si_get_primitive_id(struct si_shader_context *ctx,
+                                unsigned swizzle);
+void si_llvm_export_vs(struct si_shader_context *ctx,
+                      struct si_shader_output_values *outputs,
+                      unsigned noutput);
+void si_emit_streamout_output(struct si_shader_context *ctx,
+                             LLVMValueRef const *so_buffers,
+                             LLVMValueRef const *so_write_offsets,
+                             struct pipe_stream_output *stream_out,
+                             struct si_shader_output_values *shader_out);
 
 void si_llvm_load_input_vs(
        struct si_shader_context *ctx,
@@ -336,4 +383,18 @@ void si_llvm_load_input_fs(
 
 bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir);
 
+LLVMValueRef si_unpack_param(struct si_shader_context *ctx,
+                            unsigned param, unsigned rshift,
+                            unsigned bitwidth);
+
+void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi,
+                            unsigned max_outputs,
+                            LLVMValueRef *addrs);
+void gfx10_ngg_gs_emit_vertex(struct si_shader_context *ctx,
+                             unsigned stream,
+                             LLVMValueRef *addrs);
+void gfx10_ngg_gs_emit_prologue(struct si_shader_context *ctx);
+void gfx10_ngg_gs_emit_epilogue(struct si_shader_context *ctx);
+void gfx10_ngg_calculate_subgroup_info(struct si_shader *shader);
+
 #endif