ir3: Add support for gl_ViewIndex in VS & FS
authorConnor Abbott <cwabbott0@gmail.com>
Wed, 1 Jul 2020 14:46:22 +0000 (16:46 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 20 Aug 2020 19:21:17 +0000 (19:21 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5720>

src/freedreno/ir3/ir3_compiler_nir.c
src/freedreno/ir3/ir3_context.h
src/freedreno/ir3/ir3_shader.h

index c3461c85c7d912d64d0411ef75055bfb504e2b1c..8d9d8ef18d183f42ac26fb35cf79cea1efa7f74a 100644 (file)
@@ -1861,6 +1861,12 @@ emit_intrinsic(struct ir3_context *ctx, nir_intrinsic_instr *intr)
                }
                dst[0] = ctx->base_instance;
                break;
+       case nir_intrinsic_load_view_index:
+               if (!ctx->view_index) {
+                       ctx->view_index = create_sysval_input(ctx, SYSTEM_VALUE_VIEW_INDEX, 0x1);
+               }
+               dst[0] = ctx->view_index;
+               break;
        case nir_intrinsic_load_vertex_id_zero_base:
        case nir_intrinsic_load_vertex_id:
                if (!ctx->vertex_id) {
index 30caf9d7b852a764d06ef10dfaf224817dc10156..8cf2922f02c0d471c5edd1647a2a4c5298646591 100644 (file)
@@ -83,7 +83,7 @@ struct ir3_context {
        struct ir3_instruction *frag_face, *frag_coord;
 
        /* For vertex shaders, keep track of the system values sources */
-       struct ir3_instruction *vertex_id, *basevertex, *instance_id, *base_instance, *draw_id;
+       struct ir3_instruction *vertex_id, *basevertex, *instance_id, *base_instance, *draw_id, *view_index;
 
        /* For fragment shaders: */
        struct ir3_instruction *samp_id, *samp_mask_in;
index 99084e22f8c237445a63490ced5c9cc2d17908ee..53be9a6833d87455c4c65c091e6e2238986abaf4 100644 (file)
@@ -851,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
@@ -891,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);
@@ -907,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);
        }