pan/midgard: Implement shadow cubemaps
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 20 Dec 2019 22:25:05 +0000 (17:25 -0500)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 24 Dec 2019 23:46:23 +0000 (23:46 +0000)
We need to reshuffle to sync up the shadow coordinate temporary with the
cubemap coordinate temporary. Once that's in place, it's simple enough
(we load the shadow coordinate into .z like 2D).

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/midgard_compile.c

index 5e3c50f50eefdf4cbec8695a0b40aec785ff665d..a03e47708b06ce4597328ee72dbd4d038e5ecf7e 100644 (file)
@@ -1741,6 +1741,7 @@ emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
 
         bool needs_temp_coord =
                 (midgard_texop == TEXTURE_OP_TEXEL_FETCH) ||
+                (instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE) ||
                 (instr->is_shadow);
 
         unsigned coords = needs_temp_coord ? make_compiler_temp_reg(ctx) : 0;
@@ -1755,7 +1756,25 @@ emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
 
                         unsigned coord_mask = mask_of(instr->coord_components);
 
-                        if (needs_temp_coord) {
+                        if (instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE) {
+                                /* texelFetch is undefined on samplerCube */
+                                assert(midgard_texop != TEXTURE_OP_TEXEL_FETCH);
+
+                                /* For cubemaps, we use a special ld/st op to
+                                 * select the face and copy the xy into the
+                                 * texture register */
+
+                                midgard_instruction ld = m_ld_cubemap_coords(coords, 0);
+                                ld.src[1] = index;
+                                ld.mask = 0x3; /* xy */
+                                ld.load_store.arg_1 = 0x20;
+                                ld.swizzle[1][3] = COMPONENT_X;
+                                emit_mir_instruction(ctx, ld);
+
+                                /* xyzw -> xyxx */
+                                ins.swizzle[1][2] = instr->is_shadow ? COMPONENT_Z : COMPONENT_X;
+                                ins.swizzle[1][3] = COMPONENT_X;
+                        } else if (needs_temp_coord) {
                                 /* mov coord_temp, coords */
                                 midgard_instruction mov = v_mov(index, coords);
                                 mov.mask = coord_mask;
@@ -1764,6 +1783,8 @@ emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
                                 coords = index;
                         }
 
+                        ins.src[1] = coords;
+
                         /* Texelfetch coordinates uses all four elements
                          * (xyz/index) regardless of texture dimensionality,
                          * which means it's necessary to zero the unused
@@ -1778,30 +1799,6 @@ emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
                                 emit_mir_instruction(ctx, mov);
                         }
 
-                        if (instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE) {
-                                /* texelFetch is undefined on samplerCube */
-                                assert(midgard_texop != TEXTURE_OP_TEXEL_FETCH);
-
-                                /* For cubemaps, we use a special ld/st op to
-                                 * select the face and copy the xy into the
-                                 * texture register */
-
-                                unsigned temp = make_compiler_temp(ctx);
-                                midgard_instruction ld = m_ld_cubemap_coords(temp, 0);
-                                ld.src[1] = coords;
-                                ld.mask = 0x3; /* xy */
-                                ld.load_store.arg_1 = 0x20;
-                                ld.swizzle[1][3] = COMPONENT_X;
-                                emit_mir_instruction(ctx, ld);
-
-                                ins.src[1] = temp;
-                                /* xyzw -> xyxx */
-                                ins.swizzle[1][2] = COMPONENT_X;
-                                ins.swizzle[1][3] = COMPONENT_X;
-                        } else {
-                                ins.src[1] = coords;
-                        }
-
                         if (instr->sampler_dim == GLSL_SAMPLER_DIM_2D) {
                                 /* Array component in w but NIR wants it in z */
                                 if (nr_components == 3) {
@@ -1855,7 +1852,6 @@ emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
                 };
 
                 case nir_tex_src_comparator: {
-                        /* TODO: generalize */
                         unsigned comp = COMPONENT_Z;
 
                         /* mov coord_temp.foo, coords */