ir3: Add support for gl_ViewIndex in VS & FS
[mesa.git] / src / freedreno / ir3 / ir3_shader.h
index 2ccc9a86cd355a2495282b4b5381801e145d2374..53be9a6833d87455c4c65c091e6e2238986abaf4 100644 (file)
@@ -33,6 +33,7 @@
 #include "compiler/shader_enums.h"
 #include "compiler/nir/nir.h"
 #include "util/bitscan.h"
+#include "util/disk_cache.h"
 
 #include "ir3_compiler.h"
 
@@ -73,6 +74,18 @@ enum ir3_driver_param {
 #define IR3_MAX_SO_OUTPUTS       64
 #define IR3_MAX_UBO_PUSH_RANGES  32
 
+/* mirrors SYSTEM_VALUE_BARYCENTRIC_ but starting from 0 */
+enum ir3_bary {
+       IJ_PERSP_PIXEL,
+       IJ_PERSP_SAMPLE,
+       IJ_PERSP_CENTROID,
+       IJ_PERSP_SIZE,
+       IJ_LINEAR_PIXEL,
+       IJ_LINEAR_CENTROID,
+       IJ_LINEAR_SAMPLE,
+       IJ_COUNT,
+};
+
 /**
  * Description of a lowered UBO.
  */
@@ -178,12 +191,9 @@ struct ir3_const_state {
                uint32_t off[IR3_MAX_SHADER_IMAGES];
        } image_dims;
 
-       unsigned immediate_idx;
        unsigned immediates_count;
        unsigned immediates_size;
-       struct {
-               uint32_t val[4];
-       } *immediates;
+       uint32_t *immediates;
 
        /* State of ubo access lowered to push consts: */
        struct ir3_ubo_analysis_state ubo_state;
@@ -305,6 +315,9 @@ struct ir3_shader_key {
                         * the limit:
                         */
                        unsigned safe_constlen : 1;
+
+                       /* Whether gl_Layer must be forced to 0 because it isn't written. */
+                       unsigned layer_zero : 1;
                };
                uint32_t global;
        };
@@ -372,6 +385,9 @@ ir3_shader_key_changes_fs(struct ir3_shader_key *key, struct ir3_shader_key *las
        if (last_key->rasterflat != key->rasterflat)
                return true;
 
+       if (last_key->layer_zero != key->layer_zero)
+               return true;
+
        if (last_key->ucp_enables != key->ucp_enables)
                return true;
 
@@ -481,11 +497,25 @@ struct ir3_shader_variant {
        gl_shader_stage type;
        struct ir3_shader *shader;
 
+       /*
+        * Below here is serialized when written to disk cache:
+        */
+
        /* The actual binary shader instructions, size given by info.sizedwords: */
        uint32_t *bin;
 
        struct ir3_const_state *const_state;
 
+       /*
+        * The following macros are used by the shader disk cache save/
+        * restore paths to serialize/deserialize the variant.  Any
+        * pointers that require special handling in store_variant()
+        * and retrieve_variant() should go above here.
+        */
+#define VARIANT_CACHE_START    offsetof(struct ir3_shader_variant, info)
+#define VARIANT_CACHE_PTR(v)   (((char *)v) + VARIANT_CACHE_START)
+#define VARIANT_CACHE_SIZE     (sizeof(struct ir3_shader_variant) - VARIANT_CACHE_START)
+
        struct ir3_info info;
 
        /* Levels of nesting of flow control:
@@ -531,7 +561,7 @@ struct ir3_shader_variant {
                uint8_t regid;
                bool    half : 1;
        } outputs[32 + 2];  /* +POSITION +PSIZE */
-       bool writes_pos, writes_smask, writes_psize;
+       bool writes_pos, writes_smask, writes_psize, writes_stencilref;
 
        /* Size in dwords of all outputs for VS, size of entire patch for HS. */
        uint32_t output_size;
@@ -675,12 +705,15 @@ struct ir3_shader {
 
        unsigned num_reserved_user_consts;
 
+       bool nir_finalized;
        struct nir_shader *nir;
        struct ir3_stream_output_info stream_output;
 
        struct ir3_shader_variant *variants;
        mtx_t variants_lock;
 
+       cache_key cache_key;     /* shader disk-cache key */
+
        /* Bitmask of bits of the shader key used by this shader.  Used to avoid
         * recompiles for GL NOS that doesn't actually apply to the shader.
         */
@@ -818,6 +851,9 @@ struct ir3_shader_linkage {
 
        /* location for fixed-function gl_PrimitiveID passthrough */
        uint8_t primid_loc;
+
+       /* location for fixed-function gl_ViewIndex passthrough */
+       uint8_t viewid_loc;
 };
 
 static inline void
@@ -858,6 +894,7 @@ ir3_link_shaders(struct ir3_shader_linkage *l,
        int j = -1, k;
 
        l->primid_loc = 0xff;
+       l->viewid_loc = 0xff;
 
        while (l->cnt < ARRAY_SIZE(l->var)) {
                j = ir3_next_varying(fs, j);
@@ -874,6 +911,11 @@ ir3_link_shaders(struct ir3_shader_linkage *l,
                        l->primid_loc = fs->inputs[j].inloc;
                }
 
+               if (fs->inputs[j].slot == VARYING_SLOT_VIEW_INDEX) {
+                       assert(k < 0);
+                       l->viewid_loc = fs->inputs[j].inloc;
+               }
+
                ir3_link_add(l, k >= 0 ? vs->outputs[k].regid : default_regid,
                        fs->inputs[j].compmask, fs->inputs[j].inloc);
        }