etnaviv: support 3D and 2D array textures
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_texture_state.c
index c3c68740f971629c10ab2fc7fe25fdf3bdd4f8e4..5b3fbf46bf44a65833bce87006c082bcc60c5cfb 100644 (file)
@@ -68,6 +68,9 @@ etna_create_sampler_state_state(struct pipe_context *pipe,
       COND(ss->lod_bias != 0.0, VIVS_TE_SAMPLER_LOD_CONFIG_BIAS_ENABLE) |
       VIVS_TE_SAMPLER_LOD_CONFIG_BIAS(etna_float_to_fixp55(ss->lod_bias));
 
+   cs->TE_SAMPLER_3D_CONFIG =
+      VIVS_TE_SAMPLER_3D_CONFIG_WRAP(translate_texture_wrapmode(ss->wrap_r));
+
    if (ss->min_mip_filter != PIPE_TEX_MIPFILTER_NONE) {
       cs->min_lod = etna_float_to_fixp55(ss->min_lod);
       cs->max_lod = etna_float_to_fixp55(ss->max_lod);
@@ -121,27 +124,36 @@ etna_create_sampler_view_state(struct pipe_context *pctx, struct pipe_resource *
    sv->base.context = pctx;
 
    /* merged with sampler state */
-   sv->TE_SAMPLER_CONFIG0 = COND(!ext && !astc, VIVS_TE_SAMPLER_CONFIG0_FORMAT(format));
+   sv->TE_SAMPLER_CONFIG0 =
+      VIVS_TE_SAMPLER_CONFIG0_TYPE(translate_texture_target(sv->base.target)) |
+      COND(!ext && !astc, VIVS_TE_SAMPLER_CONFIG0_FORMAT(format));
    sv->TE_SAMPLER_CONFIG0_MASK = 0xffffffff;
 
+   uint32_t base_height = res->base.height0;
+   uint32_t base_depth = res->base.depth0;
+   bool is_array = false;
+
    switch (sv->base.target) {
    case PIPE_TEXTURE_1D:
-      /* For 1D textures, we will have a height of 1, so we can use 2D
-       * but set T wrap to repeat */
+      /* use 2D texture with T wrap to repeat for 1D texture
+       * TODO: check if old HW supports 1D texture
+       */
       sv->TE_SAMPLER_CONFIG0_MASK = ~VIVS_TE_SAMPLER_CONFIG0_VWRAP__MASK;
-      sv->TE_SAMPLER_CONFIG0 |= VIVS_TE_SAMPLER_CONFIG0_VWRAP(TEXTURE_WRAPMODE_REPEAT);
-      /* fallthrough */
-   case PIPE_TEXTURE_2D:
-   case PIPE_TEXTURE_RECT:
-      sv->TE_SAMPLER_CONFIG0 |= VIVS_TE_SAMPLER_CONFIG0_TYPE(TEXTURE_TYPE_2D);
+      sv->TE_SAMPLER_CONFIG0 &= ~VIVS_TE_SAMPLER_CONFIG0_TYPE__MASK;
+      sv->TE_SAMPLER_CONFIG0 |=
+         VIVS_TE_SAMPLER_CONFIG0_TYPE(TEXTURE_TYPE_2D) |
+         VIVS_TE_SAMPLER_CONFIG0_VWRAP(TEXTURE_WRAPMODE_REPEAT);
+      break;
+   case PIPE_TEXTURE_1D_ARRAY:
+      is_array = true;
+      base_height = res->base.array_size;
       break;
-   case PIPE_TEXTURE_CUBE:
-      sv->TE_SAMPLER_CONFIG0 |= VIVS_TE_SAMPLER_CONFIG0_TYPE(TEXTURE_TYPE_CUBE_MAP);
+   case PIPE_TEXTURE_2D_ARRAY:
+      is_array = true;
+      base_depth = res->base.array_size;
       break;
    default:
-      BUG("Unhandled texture target");
-      free(sv);
-      return NULL;
+      break;
    }
 
    if (res->addressing_mode == ETNA_ADDRESSING_MODE_LINEAR) {
@@ -157,18 +169,22 @@ etna_create_sampler_view_state(struct pipe_context *pctx, struct pipe_resource *
 
    sv->TE_SAMPLER_CONFIG1 |= COND(ext, VIVS_TE_SAMPLER_CONFIG1_FORMAT_EXT(format)) |
                              COND(astc, VIVS_TE_SAMPLER_CONFIG1_FORMAT_EXT(TEXTURE_FORMAT_EXT_ASTC)) |
+                             COND(is_array, VIVS_TE_SAMPLER_CONFIG1_TEXTURE_ARRAY) |
                              VIVS_TE_SAMPLER_CONFIG1_HALIGN(res->halign) | swiz;
    sv->TE_SAMPLER_ASTC0 = COND(astc, VIVS_NTE_SAMPLER_ASTC0_ASTC_FORMAT(format)) |
                           VIVS_NTE_SAMPLER_ASTC0_UNK8(0xc) |
                           VIVS_NTE_SAMPLER_ASTC0_UNK16(0xc) |
                           VIVS_NTE_SAMPLER_ASTC0_UNK24(0xc);
    sv->TE_SAMPLER_SIZE = VIVS_TE_SAMPLER_SIZE_WIDTH(res->base.width0) |
-                         VIVS_TE_SAMPLER_SIZE_HEIGHT(res->base.height0);
+                         VIVS_TE_SAMPLER_SIZE_HEIGHT(base_height);
    sv->TE_SAMPLER_LOG_SIZE =
       VIVS_TE_SAMPLER_LOG_SIZE_WIDTH(etna_log2_fixp55(res->base.width0)) |
-      VIVS_TE_SAMPLER_LOG_SIZE_HEIGHT(etna_log2_fixp55(res->base.height0)) |
+      VIVS_TE_SAMPLER_LOG_SIZE_HEIGHT(etna_log2_fixp55(base_height)) |
       COND(util_format_is_srgb(so->format) && !astc, VIVS_TE_SAMPLER_LOG_SIZE_SRGB) |
       COND(astc, VIVS_TE_SAMPLER_LOG_SIZE_ASTC);
+   sv->TE_SAMPLER_3D_CONFIG =
+      VIVS_TE_SAMPLER_3D_CONFIG_DEPTH(base_depth) |
+      VIVS_TE_SAMPLER_3D_CONFIG_LOG_DEPTH(etna_log2_fixp55(base_depth));
 
    /* Set up levels-of-detail */
    for (int lod = 0; lod <= res->base.last_level; ++lod) {
@@ -304,6 +320,15 @@ etna_emit_texture_state(struct etna_context *ctx)
             ss = etna_sampler_state(ctx->sampler[x]);
             sv = etna_sampler_view(ctx->sampler_view[x]);
 
+            /*02180*/ EMIT_STATE(TE_SAMPLER_3D_CONFIG(x), ss->TE_SAMPLER_3D_CONFIG |
+                                                          sv->TE_SAMPLER_3D_CONFIG);
+         }
+      }
+      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
+         if ((1 << x) & active_samplers) {
+            ss = etna_sampler_state(ctx->sampler[x]);
+            sv = etna_sampler_view(ctx->sampler_view[x]);
+
             /*021C0*/ EMIT_STATE(TE_SAMPLER_CONFIG1(x), ss->TE_SAMPLER_CONFIG1 |
                                                         sv->TE_SAMPLER_CONFIG1 |
                                                         COND(sv->ts.enable, VIVS_TE_SAMPLER_CONFIG1_USE_TS));