freedreno/ir3: stop hard-coding FS input regs
[mesa.git] / src / gallium / drivers / freedreno / ir3 / ir3_shader.h
index a06dd04904c10004d9dadc26dfda42161f54fdb7..507e89c47350edd8fc0a4e813fbedbd49c14399c 100644 (file)
 #include "ir3.h"
 #include "disasm.h"
 
+struct glsl_type;
+
 /* driver param indices: */
 enum ir3_driver_param {
+       /* compute shader driver params: */
+       IR3_DP_NUM_WORK_GROUPS_X = 0,
+       IR3_DP_NUM_WORK_GROUPS_Y = 1,
+       IR3_DP_NUM_WORK_GROUPS_Z = 2,
+       IR3_DP_LOCAL_GROUP_SIZE_X = 4,
+       IR3_DP_LOCAL_GROUP_SIZE_Y = 5,
+       IR3_DP_LOCAL_GROUP_SIZE_Z = 6,
+       /* NOTE: gl_NumWorkGroups should be vec4 aligned because
+        * glDispatchComputeIndirect() needs to load these from
+        * the info->indirect buffer.  Keep that in mind when/if
+        * adding any addition CS driver params.
+        */
+       IR3_DP_CS_COUNT   = 8,   /* must be aligned to vec4 */
+
+       /* vertex shader driver params: */
        IR3_DP_VTXID_BASE = 0,
        IR3_DP_VTXCNT_MAX = 1,
        /* user-clip-plane components, up to 8x vec4's: */
        IR3_DP_UCP0_X     = 4,
        /* .... */
        IR3_DP_UCP7_W     = 35,
-       IR3_DP_COUNT      = 36   /* must be aligned to vec4 */
+       IR3_DP_VS_COUNT   = 36   /* must be aligned to vec4 */
+};
+
+/**
+ * For consts needed to pass internal values to shader which may or may not
+ * be required, rather than allocating worst-case const space, we scan the
+ * shader and allocate consts as-needed:
+ *
+ *   + SSBO sizes: only needed if shader has a get_buffer_size intrinsic
+ *     for a given SSBO
+ *
+ *   + Image dimensions: needed to calculate pixel offset, but only for
+ *     images that have a image_store intrinsic
+ */
+struct ir3_driver_const_layout {
+       struct {
+               uint32_t mask;  /* bitmask of SSBOs that have get_buffer_size */
+               uint32_t count; /* number of consts allocated */
+               /* one const allocated per SSBO which has get_buffer_size,
+                * ssbo_sizes.off[ssbo_id] is offset from start of ssbo_sizes
+                * consts:
+                */
+               uint32_t off[PIPE_MAX_SHADER_BUFFERS];
+       } ssbo_size;
+
+       struct {
+               uint32_t mask;  /* bitmask of images that have image_store */
+               uint32_t count; /* number of consts allocated */
+               /* three const allocated per image which has image_store:
+                *  + cpp         (bytes per pixel)
+                *  + pitch       (y pitch)
+                *  + array_pitch (z pitch)
+                */
+               uint32_t off[PIPE_MAX_SHADER_IMAGES];
+       } image_dims;
 };
 
 /* Configuration key used to identify a shader variant.. different
@@ -92,6 +143,9 @@ struct ir3_shader_key {
         */
        uint16_t fsaturate_s, fsaturate_t, fsaturate_r;
 
+       /* bitmask of ms shifts */
+       uint32_t vsamples, fsamples;
+
        /* bitmask of samplers which need astc srgb workaround: */
        uint16_t vastc_srgb, fastc_srgb;
 };
@@ -113,6 +167,7 @@ ir3_shader_key_changes_fs(struct ir3_shader_key *key, struct ir3_shader_key *las
                if ((last_key->fsaturate_s != key->fsaturate_s) ||
                                (last_key->fsaturate_t != key->fsaturate_t) ||
                                (last_key->fsaturate_r != key->fsaturate_r) ||
+                               (last_key->fsamples != key->fsamples) ||
                                (last_key->fastc_srgb != key->fastc_srgb))
                        return true;
        }
@@ -143,6 +198,7 @@ ir3_shader_key_changes_vs(struct ir3_shader_key *key, struct ir3_shader_key *las
                if ((last_key->vsaturate_s != key->vsaturate_s) ||
                                (last_key->vsaturate_t != key->vsaturate_t) ||
                                (last_key->vsaturate_r != key->vsaturate_r) ||
+                               (last_key->vsamples != key->vsamples) ||
                                (last_key->vastc_srgb != key->vastc_srgb))
                        return true;
        }
@@ -164,6 +220,7 @@ struct ir3_shader_variant {
 
        struct ir3_shader_key key;
 
+       struct ir3_driver_const_layout const_layout;
        struct ir3_info info;
        struct ir3 *ir;
 
@@ -182,6 +239,7 @@ struct ir3_shader_variant {
         * constants, etc.
         */
        unsigned num_uniforms;
+
        unsigned num_ubos;
 
        /* About Linkage:
@@ -193,10 +251,6 @@ struct ir3_shader_variant {
         *   + From the vert shader, we only need the output regid
         */
 
-       /* for frag shader, pos_regid holds the frag_pos, ie. what is passed
-        * to bary.f instructions
-        */
-       uint8_t pos_regid;
        bool frag_coord, frag_face, color0_mrt;
 
        /* NOTE: for input/outputs, slot is:
@@ -262,6 +316,9 @@ struct ir3_shader_variant {
        struct {
                /* user const start at zero */
                unsigned ubo;
+               /* NOTE that a3xx might need a section for SSBO addresses too */
+               unsigned ssbo_sizes;
+               unsigned image_dims;
                unsigned driver_param;
                unsigned tfbo;
                unsigned immediate;
@@ -313,10 +370,14 @@ void * ir3_shader_assemble(struct ir3_shader_variant *v, uint32_t gpu_id);
 struct ir3_shader * ir3_shader_create(struct ir3_compiler *compiler,
                const struct pipe_shader_state *cso, enum shader_t type,
                struct pipe_debug_callback *debug);
+struct ir3_shader *
+ir3_shader_create_compute(struct ir3_compiler *compiler,
+               const struct pipe_compute_state *cso,
+               struct pipe_debug_callback *debug);
 void ir3_shader_destroy(struct ir3_shader *shader);
 struct ir3_shader_variant * ir3_shader_variant(struct ir3_shader *shader,
                struct ir3_shader_key key, struct pipe_debug_callback *debug);
-void ir3_shader_disasm(struct ir3_shader_variant *so, uint32_t *bin);
+void ir3_shader_disasm(struct ir3_shader_variant *so, uint32_t *bin, FILE *out);
 uint64_t ir3_shader_outputs(const struct ir3_shader *so);
 
 struct fd_ringbuffer;
@@ -325,6 +386,11 @@ void ir3_emit_vs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer
                struct fd_context *ctx, const struct pipe_draw_info *info);
 void ir3_emit_fs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
                struct fd_context *ctx);
+void ir3_emit_cs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
+               struct fd_context *ctx, const struct pipe_grid_info *info);
+
+int
+ir3_glsl_type_size(const struct glsl_type *type);
 
 static inline const char *
 ir3_shader_stage(struct ir3_shader *shader)
@@ -457,4 +523,13 @@ ir3_find_sysval_regid(const struct ir3_shader_variant *so, unsigned slot)
        return regid(63, 0);
 }
 
+/* calculate register footprint in terms of half-regs (ie. one full
+ * reg counts as two half-regs).
+ */
+static inline uint32_t
+ir3_shader_halfregs(const struct ir3_shader_variant *v)
+{
+       return (2 * (v->info.max_reg + 1)) + (v->info.max_half_reg + 1);
+}
+
 #endif /* IR3_SHADER_H_ */