r600g: Use the actual Evergreen functions to query format support on Evergreen.
[mesa.git] / src / gallium / auxiliary / util / u_gen_mipmap.c
index 4f1b0e71934a6d16286e9f165345a57979da8275..4a1662462e5d1dc85fae37f507c71dd5a6ddf086 100644 (file)
@@ -67,7 +67,7 @@ struct gen_mipmap_state
    struct pipe_vertex_element velem[2];
 
    void *vs;
-   void *fs1d, *fs2d, *fs3d, *fsCube, *fs1da, *fs2da;
+   void *fs[TGSI_TEXTURE_COUNT]; /**< Not all are used, but simplifies code */
 
    struct pipe_resource *vbuf;  /**< quad vertices */
    unsigned vbuf_slot;
@@ -1301,34 +1301,6 @@ util_create_gen_mipmap(struct pipe_context *pipe,
       ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
    }
 
-   /* vertex shader - still needed to specify mapping from fragment
-    * shader input semantics to vertex elements 
-    */
-   {
-      const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
-                                      TGSI_SEMANTIC_GENERIC };
-      const uint semantic_indexes[] = { 0, 0 };
-      ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
-                                                    semantic_indexes);
-   }
-
-   /* fragment shader */
-   ctx->fs1d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_1D,
-                                             TGSI_INTERPOLATE_LINEAR);
-   ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
-                                             TGSI_INTERPOLATE_LINEAR);
-   ctx->fs3d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_3D,
-                                               TGSI_INTERPOLATE_LINEAR);
-   ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE,
-                                               TGSI_INTERPOLATE_LINEAR);
-   if (pipe->screen->get_param(pipe->screen, PIPE_CAP_ARRAY_TEXTURES)) {
-      ctx->fs1da = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_1D_ARRAY,
-                                                 TGSI_INTERPOLATE_LINEAR);
-      ctx->fs2da = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D_ARRAY,
-                                                 TGSI_INTERPOLATE_LINEAR);
-   }
-
-
    /* vertex data that doesn't change */
    for (i = 0; i < 4; i++) {
       ctx->vertices[i][0][2] = 0.0f; /* z */
@@ -1342,6 +1314,44 @@ util_create_gen_mipmap(struct pipe_context *pipe,
 }
 
 
+/**
+ * Helper function to set the fragment shaders.
+ */
+static INLINE void
+set_fragment_shader(struct gen_mipmap_state *ctx, uint type)
+{
+   if (!ctx->fs[type])
+      ctx->fs[type] =
+         util_make_fragment_tex_shader(ctx->pipe, type,
+                                       TGSI_INTERPOLATE_LINEAR);
+
+   cso_set_fragment_shader_handle(ctx->cso, ctx->fs[type]);
+}
+
+
+/**
+ * Helper function to set the vertex shader.
+ */
+static INLINE void
+set_vertex_shader(struct gen_mipmap_state *ctx)
+{
+   /* vertex shader - still required to provide the linkage between
+    * fragment shader input semantics and vertex_element/buffers.
+    */
+   if (!ctx->vs)
+   {
+      const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
+                                      TGSI_SEMANTIC_GENERIC };
+      const uint semantic_indexes[] = { 0, 0 };
+      ctx->vs = util_make_vertex_passthrough_shader(ctx->pipe, 2,
+                                                    semantic_names,
+                                                    semantic_indexes);
+   }
+
+   cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
+}
+
+
 /**
  * Get next "slot" of vertex space in the vertex buffer.
  * We're allocating one large vertex buffer and using it piece by piece.
@@ -1450,16 +1460,14 @@ void
 util_destroy_gen_mipmap(struct gen_mipmap_state *ctx)
 {
    struct pipe_context *pipe = ctx->pipe;
+   unsigned i;
+
+   for (i = 0; i < Elements(ctx->fs); i++)
+      if (ctx->fs[i])
+         pipe->delete_fs_state(pipe, ctx->fs[i]);
 
-   if (ctx->fs2da)
-      pipe->delete_fs_state(pipe, ctx->fs2da);
-   if (ctx->fs1da)
-      pipe->delete_fs_state(pipe, ctx->fs1da);
-   pipe->delete_fs_state(pipe, ctx->fsCube);
-   pipe->delete_fs_state(pipe, ctx->fs3d);
-   pipe->delete_fs_state(pipe, ctx->fs2d);
-   pipe->delete_fs_state(pipe, ctx->fs1d);
-   pipe->delete_vs_state(pipe, ctx->vs);
+   if (ctx->vs)
+      pipe->delete_vs_state(pipe, ctx->vs);
 
    pipe_resource_reference(&ctx->vbuf, NULL);
 
@@ -1498,9 +1506,9 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    struct pipe_screen *screen = pipe->screen;
    struct pipe_framebuffer_state fb;
    struct pipe_resource *pt = psv->texture;
-   void *fs;
    uint dstLevel;
    uint offset;
+   uint type;
 
    /* The texture object should have room for the levels which we're
     * about to generate.
@@ -1515,31 +1523,31 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
 
    switch (pt->target) {
    case PIPE_TEXTURE_1D:
-      fs = ctx->fs1d;
+      type = TGSI_TEXTURE_1D;
       break;
    case PIPE_TEXTURE_2D:
-      fs = ctx->fs2d;
+      type = TGSI_TEXTURE_2D;
       break;
    case PIPE_TEXTURE_3D:
-      fs = ctx->fs3d;
+      type = TGSI_TEXTURE_3D;
       break;
    case PIPE_TEXTURE_CUBE:
-      fs = ctx->fsCube;
+      type = TGSI_TEXTURE_CUBE;
       break;
    case PIPE_TEXTURE_1D_ARRAY:
-      fs = ctx->fs1da;
+      type = TGSI_TEXTURE_1D_ARRAY;
       break;
    case PIPE_TEXTURE_2D_ARRAY:
-      fs = ctx->fs2da;
+      type = TGSI_TEXTURE_2D_ARRAY;
       break;
    default:
       assert(0);
-      fs = ctx->fs2d;
+      type = TGSI_TEXTURE_2D;
    }
 
    /* check if we can render in the texture's format */
    if (!screen->is_format_supported(screen, psv->format, pt->target,
-                                    pt->nr_samples, PIPE_BIND_RENDER_TARGET, 0)) {
+                                    pt->nr_samples, PIPE_BIND_RENDER_TARGET)) {
       fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel);
       return;
    }
@@ -1564,8 +1572,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    cso_set_clip(ctx->cso, &ctx->clip);
    cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
 
-   cso_set_fragment_shader_handle(ctx->cso, fs);
-   cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
+   set_fragment_shader(ctx, type);
+   set_vertex_shader(ctx);
 
    /* init framebuffer state */
    memset(&fb, 0, sizeof(fb));
@@ -1660,8 +1668,6 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
                                  4,  /* verts */
                                  2); /* attribs/vert */
 
-         pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
-
          /* need to signal that the texture has changed _after_ rendering to it */
          pipe_surface_reference( &surf, NULL );
       }