u_blitter: interpolate clear color using a GENERIC varying instead of COLOR
authorMarek Olšák <maraeo@gmail.com>
Sun, 28 Nov 2010 15:59:03 +0000 (16:59 +0100)
committerMarek Olšák <maraeo@gmail.com>
Sun, 28 Nov 2010 16:45:39 +0000 (17:45 +0100)
There are also some u_simple_shaders changes.

On r300, the TGSI_SEMANTIC_COLOR varying is a fixed-point number clamped
to the range [0,1] and limited to 12 bits of precision. Therefore we can't
use it for passing through a clear color in order to clear high precision
texture formats.

This also makes u_blitter use only one vertex shader instead of two.

src/gallium/auxiliary/util/u_blitter.c
src/gallium/auxiliary/util/u_simple_shaders.c
src/gallium/auxiliary/util/u_simple_shaders.h

index 31fc75aa110c0b5a6af15b64bbc1e6a120beda0d..bd9e65f43b107c2d36546c5690a88f173c484a7f 100644 (file)
@@ -63,8 +63,7 @@ struct blitter_context_priv
 
    /* Constant state objects. */
    /* Vertex shaders. */
-   void *vs_col; /**< Vertex shader which passes {pos, color} to the output */
-   void *vs_tex; /**< Vertex shader which passes {pos, texcoord} to the output.*/
+   void *vs; /**< Vertex shader which passes {pos, generic} to the output.*/
 
    /* Fragment shaders. */
    /* The shader at index i outputs color to color buffers 0,1,...,i-1. */
@@ -211,20 +210,12 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
 
    /* fragment shaders are created on-demand */
 
-   /* vertex shaders */
-   {
-      const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
-                                      TGSI_SEMANTIC_COLOR };
-      const uint semantic_indices[] = { 0, 0 };
-      ctx->vs_col =
-         util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
-                                             semantic_indices);
-   }
+   /* vertex shader */
    {
       const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
                                       TGSI_SEMANTIC_GENERIC };
       const uint semantic_indices[] = { 0, 0 };
-      ctx->vs_tex =
+      ctx->vs =
          util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
                                              semantic_indices);
    }
@@ -257,8 +248,7 @@ void util_blitter_destroy(struct blitter_context *blitter)
    pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_flush_depth_stencil);
 
    pipe->delete_rasterizer_state(pipe, ctx->rs_state);
-   pipe->delete_vs_state(pipe, ctx->vs_col);
-   pipe->delete_vs_state(pipe, ctx->vs_tex);
+   pipe->delete_vs_state(pipe, ctx->vs);
    pipe->delete_vertex_elements_state(pipe, ctx->velem_state);
 
    for (i = 0; i < PIPE_MAX_TEXTURE_TYPES; i++) {
@@ -569,7 +559,9 @@ void *blitter_get_fs_col(struct blitter_context_priv *ctx, unsigned num_cbufs)
 
    if (!ctx->fs_col[num_cbufs])
       ctx->fs_col[num_cbufs] =
-         util_make_fragment_clonecolor_shader(pipe, num_cbufs);
+         util_make_fragment_cloneinput_shader(pipe, num_cbufs,
+                                              TGSI_SEMANTIC_GENERIC,
+                                              TGSI_INTERPOLATE_LINEAR);
 
    return ctx->fs_col[num_cbufs];
 }
@@ -700,7 +692,7 @@ void util_blitter_clear(struct blitter_context *blitter,
    pipe->bind_rasterizer_state(pipe, ctx->rs_state);
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
    pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, num_cbufs));
-   pipe->bind_vs_state(pipe, ctx->vs_col);
+   pipe->bind_vs_state(pipe, ctx->vs);
 
    blitter_set_dst_dimensions(ctx, width, height);
    blitter->draw_rectangle(blitter, 0, 0, width, height, depth,
@@ -813,7 +805,7 @@ void util_blitter_copy_region(struct blitter_context *blitter,
 
    /* Set rasterizer state, shaders, and textures. */
    pipe->bind_rasterizer_state(pipe, ctx->rs_state);
-   pipe->bind_vs_state(pipe, ctx->vs_tex);
+   pipe->bind_vs_state(pipe, ctx->vs);
    pipe->bind_fragment_sampler_states(pipe, 1,
                                       blitter_get_sampler_state(ctx, subsrc.level, normalized));
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
@@ -890,7 +882,7 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
    pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
    pipe->bind_rasterizer_state(pipe, ctx->rs_state);
    pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1));
-   pipe->bind_vs_state(pipe, ctx->vs_col);
+   pipe->bind_vs_state(pipe, ctx->vs);
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
 
    /* set a framebuffer state */
@@ -950,7 +942,7 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
 
    pipe->bind_rasterizer_state(pipe, ctx->rs_state);
    pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0));
-   pipe->bind_vs_state(pipe, ctx->vs_col);
+   pipe->bind_vs_state(pipe, ctx->vs);
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
 
    /* set a framebuffer state */
@@ -991,7 +983,7 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
 
    pipe->bind_rasterizer_state(pipe, ctx->rs_state);
    pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0));
-   pipe->bind_vs_state(pipe, ctx->vs_col);
+   pipe->bind_vs_state(pipe, ctx->vs);
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
 
    /* set a framebuffer state */
index 58ef68377fcea467509125842e854c72cdf205ef..b0f2dd8aa29e8173c9620140c180fa2f6c5a4238 100644 (file)
@@ -204,7 +204,8 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
 void *
 util_make_fragment_passthrough_shader(struct pipe_context *pipe)
 {
-   return util_make_fragment_clonecolor_shader(pipe, 1);
+   return util_make_fragment_cloneinput_shader(pipe, 1, TGSI_SEMANTIC_COLOR,
+                                               TGSI_INTERPOLATE_PERSPECTIVE);
 }
 
 
@@ -212,7 +213,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe)
  * Make a fragment shader that copies the input color to N output colors.
  */
 void *
-util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs)
+util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs,
+                                     int input_semantic,
+                                     int input_interpolate)
 {
    struct ureg_program *ureg;
    struct ureg_src src;
@@ -225,8 +228,8 @@ util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs)
    if (ureg == NULL)
       return NULL;
 
-   src = ureg_DECL_fs_input( ureg, TGSI_SEMANTIC_COLOR, 0, 
-                             TGSI_INTERPOLATE_PERSPECTIVE );
+   src = ureg_DECL_fs_input( ureg, input_semantic, 0,
+                             input_interpolate );
 
    for (i = 0; i < num_cbufs; i++)
       dst[i] = ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, i );
index 4aa34bc47575289450e83ef12b9c94fe22536730..1bfec183e3471579adb3c4b85822efbf6da77fd0 100644 (file)
@@ -71,7 +71,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe);
 
 
 extern void *
-util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs);
+util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs,
+                                     int input_semantic,
+                                     int input_interpolate);
 
 #ifdef __cplusplus
 }