radeonsi/gfx10: jump over the shader query atomic if the queries are disabled
[mesa.git] / src / gallium / drivers / radeonsi / si_shader.h
index 145a03bd1ae23b10b65534531732045a5c7720de..2649a7cd5b7496062e72c7fc6e937040f5971544 100644 (file)
 
 #include <stdio.h>
 
+// Use LDS symbols when supported by LLVM. Can be disabled for testing the old
+// path on newer LLVM for now. Should be removed in the long term.
+#define USE_LDS_SYMBOLS (true)
+
 struct nir_shader;
 struct si_shader;
 struct si_context;
@@ -237,11 +241,16 @@ enum {
 };
 
 /* Fields of driver-defined VS state SGPR. */
-/* Clamp vertex color output (only used in VS as VS). */
 #define S_VS_STATE_CLAMP_VERTEX_COLOR(x)       (((unsigned)(x) & 0x1) << 0)
 #define C_VS_STATE_CLAMP_VERTEX_COLOR          0xFFFFFFFE
 #define S_VS_STATE_INDEXED(x)                  (((unsigned)(x) & 0x1) << 1)
 #define C_VS_STATE_INDEXED                     0xFFFFFFFD
+#define S_VS_STATE_OUTPRIM(x)                  (((unsigned)(x) & 0x3) << 2)
+#define C_VS_STATE_OUTPRIM                     0xFFFFFFF3
+#define S_VS_STATE_PROVOKING_VTX_INDEX(x)      (((unsigned)(x) & 0x3) << 4)
+#define C_VS_STATE_PROVOKING_VTX_INDEX         0xFFFFFFCF
+#define S_VS_STATE_STREAMOUT_QUERY_ENABLED(x)  (((unsigned)(x) & 0x1) << 6)
+#define C_VS_STATE_STREAMOUT_QUERY_ENABLED     0xFFFFFFBF
 #define S_VS_STATE_LS_OUT_PATCH_SIZE(x)                (((unsigned)(x) & 0x1FFF) << 8)
 #define C_VS_STATE_LS_OUT_PATCH_SIZE           0xFFE000FF
 #define S_VS_STATE_LS_OUT_VERTEX_SIZE(x)       (((unsigned)(x) & 0xFF) << 24)
@@ -327,6 +336,7 @@ struct si_shader_selector {
        struct si_shader        *main_shader_part;
        struct si_shader        *main_shader_part_ls; /* as_ls is set in the key */
        struct si_shader        *main_shader_part_es; /* as_es is set in the key */
+       struct si_shader        *main_shader_part_ngg; /* as_ngg is set in the key */
 
        struct si_shader        *gs_copy_shader;
 
@@ -380,16 +390,21 @@ struct si_shader_selector {
 
 /* Valid shader configurations:
  *
- * API shaders       VS | TCS | TES | GS |pass| PS
- * are compiled as:     |     |     |    |thru|
- *                      |     |     |    |    |
- * Only VS & PS:     VS |     |     |    |    | PS
- * GFX6 - with GS:   ES |     |     | GS | VS | PS
- *      - with tess: LS | HS  | VS  |    |    | PS
- *      - with both: LS | HS  | ES  | GS | VS | PS
- * GFX9 - with GS:   -> |     |     | GS | VS | PS
- *      - with tess: -> | HS  | VS  |    |    | PS
- *      - with both: -> | HS  | ->  | GS | VS | PS
+ * API shaders           VS | TCS | TES | GS |pass| PS
+ * are compiled as:         |     |     |    |thru|
+ *                          |     |     |    |    |
+ * Only VS & PS:         VS |     |     |    |    | PS
+ * GFX6     - with GS:   ES |     |     | GS | VS | PS
+ *          - with tess: LS | HS  | VS  |    |    | PS
+ *          - with both: LS | HS  | ES  | GS | VS | PS
+ * GFX9     - with GS:   -> |     |     | GS | VS | PS
+ *          - with tess: -> | HS  | VS  |    |    | PS
+ *          - with both: -> | HS  | ->  | GS | VS | PS
+ *                          |     |     |    |    |
+ * NGG      - VS & PS:   GS |     |     |    |    | PS
+ * (GFX10+) - with GS:   -> |     |     | GS |    | PS
+ *          - with tess: -> | HS  | GS  |    |    | PS
+ *          - with both: -> | HS  | ->  | GS |    | PS
  *
  * -> = merged with the next stage
  */
@@ -460,6 +475,7 @@ union si_shader_part_key {
                unsigned        last_input:4;
                unsigned        as_ls:1;
                unsigned        as_es:1;
+               unsigned        as_ngg:1;
                /* Prologs for monolithic shaders shouldn't set EXEC. */
                unsigned        is_monolithic:1;
        } vs_prolog;
@@ -515,11 +531,12 @@ struct si_shader_key {
                } ps;
        } part;
 
-       /* These two are initially set according to the NEXT_SHADER property,
+       /* These three are initially set according to the NEXT_SHADER property,
         * or guessed if the property doesn't seem correct.
         */
        unsigned as_es:1; /* export shader, which precedes GS */
        unsigned as_ls:1; /* local shader, which precedes TCS */
+       unsigned as_ngg:1; /* VS, TES, or GS compiled as NGG primitive shader */
 
        /* Flags for monolithic compilation only. */
        struct {
@@ -588,6 +605,21 @@ struct si_shader_info {
        unsigned                max_simd_waves;
 };
 
+struct si_shader_binary {
+       const char *elf_buffer;
+       size_t elf_size;
+
+       char *llvm_ir_string;
+};
+
+struct gfx9_gs_info {
+       unsigned es_verts_per_subgroup;
+       unsigned gs_prims_per_subgroup;
+       unsigned gs_inst_prims_in_subgroup;
+       unsigned max_prims_per_subgroup;
+       unsigned esgs_ring_size; /* in bytes */
+};
+
 struct si_shader {
        struct si_compiler_ctx_state    compiler_ctx_state;
 
@@ -612,23 +644,33 @@ struct si_shader {
        bool                            is_gs_copy_shader;
 
        /* The following data is all that's needed for binary shaders. */
-       struct ac_shader_binary binary;
+       struct si_shader_binary         binary;
        struct ac_shader_config         config;
        struct si_shader_info           info;
 
+       struct {
+               uint16_t ngg_emit_size; /* in dwords */
+               uint16_t hw_max_esverts;
+               uint16_t max_gsprims;
+               uint16_t max_out_verts;
+               uint16_t prim_amp_factor;
+               bool max_vert_out_per_gs_instance;
+       } ngg;
+
        /* Shader key + LLVM IR + disassembly + statistics.
         * Generated for debug contexts only.
         */
        char                            *shader_log;
        size_t                          shader_log_size;
 
+       struct gfx9_gs_info gs_info;
+
        /* For save precompute context registers values. */
        union {
                struct {
                        unsigned        vgt_gsvs_ring_offset_1;
                        unsigned        vgt_gsvs_ring_offset_2;
                        unsigned        vgt_gsvs_ring_offset_3;
-                       unsigned        vgt_gs_out_prim_type;
                        unsigned        vgt_gsvs_ring_itemsize;
                        unsigned        vgt_gs_max_vert_out;
                        unsigned        vgt_gs_vert_itemsize;
@@ -641,6 +683,22 @@ struct si_shader {
                        unsigned        vgt_esgs_ring_itemsize;
                } gs;
 
+               struct {
+                       unsigned        ge_max_output_per_subgroup;
+                       unsigned        ge_ngg_subgrp_cntl;
+                       unsigned        vgt_primitiveid_en;
+                       unsigned        vgt_gs_onchip_cntl;
+                       unsigned        vgt_gs_instance_cnt;
+                       unsigned        vgt_esgs_ring_itemsize;
+                       unsigned        vgt_reuse_off;
+                       unsigned        spi_vs_out_config;
+                       unsigned        spi_shader_idx_format;
+                       unsigned        spi_shader_pos_format;
+                       unsigned        pa_cl_vte_cntl;
+                       unsigned        pa_cl_ngg_cntl;
+                       unsigned        vgt_gs_max_vert_out; /* for API GS */
+               } ngg;
+
                struct {
                        unsigned        vgt_gs_mode;
                        unsigned        vgt_primitiveid_en;
@@ -664,12 +722,13 @@ struct si_shader {
        /*For save precompute registers value */
        unsigned vgt_tf_param; /* VGT_TF_PARAM */
        unsigned vgt_vertex_reuse_block_cntl; /* VGT_VERTEX_REUSE_BLOCK_CNTL */
+       unsigned ge_cntl;
 };
 
 struct si_shader_part {
        struct si_shader_part *next;
        union si_shader_part_key key;
-       struct ac_shader_binary binary;
+       struct si_shader_binary binary;
        struct ac_shader_config config;
 };
 
@@ -690,17 +749,18 @@ void si_shader_destroy(struct si_shader *shader);
 unsigned si_shader_io_get_unique_index_patch(unsigned semantic_name, unsigned index);
 unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index,
                                       unsigned is_varying);
-bool si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader);
-void si_shader_dump(struct si_screen *sscreen, const struct si_shader *shader,
+bool si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader,
+                            uint64_t scratch_va);
+void si_shader_dump(struct si_screen *sscreen, struct si_shader *shader,
                    struct pipe_debug_callback *debug, unsigned processor,
                    FILE *f, bool check_debug_option);
-void si_shader_dump_stats_for_shader_db(const struct si_shader *shader,
+void si_shader_dump_stats_for_shader_db(struct si_screen *screen,
+                                       struct si_shader *shader,
                                        struct pipe_debug_callback *debug);
 void si_multiwave_lds_size_workaround(struct si_screen *sscreen,
                                      unsigned *lds_size);
-void si_shader_apply_scratch_relocs(struct si_shader *shader,
-                                   uint64_t scratch_va);
 const char *si_get_shader_name(const struct si_shader *shader, unsigned processor);
+void si_shader_binary_clean(struct si_shader_binary *binary);
 
 /* si_shader_nir.c */
 void si_nir_scan_shader(const struct nir_shader *nir,
@@ -710,6 +770,11 @@ void si_nir_scan_tess_ctrl(const struct nir_shader *nir,
 void si_lower_nir(struct si_shader_selector *sel);
 void si_nir_opts(struct nir_shader *nir);
 
+/* si_state_shaders.c */
+void gfx9_get_gs_info(struct si_shader_selector *es,
+                     struct si_shader_selector *gs,
+                     struct gfx9_gs_info *out);
+
 /* Inline helpers. */
 
 /* Return the pointer to the main shader part's pointer. */
@@ -721,6 +786,8 @@ si_get_main_shader_part(struct si_shader_selector *sel,
                return &sel->main_shader_part_ls;
        if (key->as_es)
                return &sel->main_shader_part_es;
+       if (key->as_ngg)
+               return &sel->main_shader_part_ngg;
        return &sel->main_shader_part;
 }