gallium: add interpolation parameter to simple shader functions

This lets us specify linear interpolation instead of perspective
interpolation for blit operations.  Might be a bit faster.
This commit is contained in:
Brian Paul
2010-06-02 18:13:00 -06:00
parent 35d75e4930
commit d18fb4822b
6 changed files with 58 additions and 48 deletions

View File

@@ -134,7 +134,8 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
/* fragment shader */
ctx->fs[TGSI_WRITEMASK_XYZW] =
util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
TGSI_INTERPOLATE_LINEAR);
ctx->vbuf = NULL;
/* init vertex data that doesn't change */
@@ -474,6 +475,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
if (ctx->fs[writemask] == NULL)
ctx->fs[writemask] =
util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D,
TGSI_INTERPOLATE_LINEAR,
writemask);
/* shaders */

View File

@@ -516,6 +516,26 @@ void *blitter_get_fs_col(struct blitter_context_priv *ctx, unsigned num_cbufs)
return ctx->fs_col[num_cbufs];
}
/** Convert PIPE_TEXTURE_x to TGSI_TEXTURE_x */
static unsigned
pipe_tex_to_tgsi_tex(unsigned pipe_tex_target)
{
switch (pipe_tex_target) {
case PIPE_TEXTURE_1D:
return TGSI_TEXTURE_1D;
case PIPE_TEXTURE_2D:
return TGSI_TEXTURE_2D;
case PIPE_TEXTURE_3D:
return TGSI_TEXTURE_3D;
case PIPE_TEXTURE_CUBE:
return TGSI_TEXTURE_CUBE;
default:
assert(0 && "unexpected texture target");
return TGSI_TEXTURE_UNKNOWN;
}
}
static INLINE
void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx,
unsigned tex_target)
@@ -526,25 +546,10 @@ void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx,
/* Create the fragment shader on-demand. */
if (!ctx->fs_texfetch_col[tex_target]) {
switch (tex_target) {
case PIPE_TEXTURE_2D:
ctx->fs_texfetch_col[PIPE_TEXTURE_2D] =
util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
break;
case PIPE_TEXTURE_3D:
ctx->fs_texfetch_col[PIPE_TEXTURE_3D] =
util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_3D);
break;
case PIPE_TEXTURE_CUBE:
ctx->fs_texfetch_col[PIPE_TEXTURE_CUBE] =
util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE);
break;
case PIPE_TEXTURE_1D:
default:
ctx->fs_texfetch_col[PIPE_TEXTURE_1D] =
util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_1D);
tex_target = PIPE_TEXTURE_1D; /* for the default case */
}
unsigned tgsi_tex = pipe_tex_to_tgsi_tex(tex_target);
ctx->fs_texfetch_col[tex_target] =
util_make_fragment_tex_shader(pipe, tgsi_tex, TGSI_INTERPOLATE_LINEAR);
}
return ctx->fs_texfetch_col[tex_target];
@@ -560,25 +565,11 @@ void *blitter_get_fs_texfetch_depth(struct blitter_context_priv *ctx,
/* Create the fragment shader on-demand. */
if (!ctx->fs_texfetch_depth[tex_target]) {
switch (tex_target) {
case PIPE_TEXTURE_2D:
ctx->fs_texfetch_depth[PIPE_TEXTURE_2D] =
util_make_fragment_tex_shader_writedepth(pipe, TGSI_TEXTURE_2D);
break;
case PIPE_TEXTURE_3D:
ctx->fs_texfetch_depth[PIPE_TEXTURE_3D] =
util_make_fragment_tex_shader_writedepth(pipe, TGSI_TEXTURE_3D);
break;
case PIPE_TEXTURE_CUBE:
ctx->fs_texfetch_depth[PIPE_TEXTURE_CUBE] =
util_make_fragment_tex_shader_writedepth(pipe,TGSI_TEXTURE_CUBE);
break;
case PIPE_TEXTURE_1D:
default:
ctx->fs_texfetch_depth[PIPE_TEXTURE_1D] =
util_make_fragment_tex_shader_writedepth(pipe, TGSI_TEXTURE_1D);
tex_target = PIPE_TEXTURE_1D; /* for the default case */
}
unsigned tgsi_tex = pipe_tex_to_tgsi_tex(tex_target);
ctx->fs_texfetch_depth[tex_target] =
util_make_fragment_tex_shader_writedepth(pipe, tgsi_tex,
TGSI_INTERPOLATE_LINEAR);
}
return ctx->fs_texfetch_depth[tex_target];

View File

@@ -1327,8 +1327,10 @@ util_create_gen_mipmap(struct pipe_context *pipe,
}
/* fragment shader */
ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE);
ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
TGSI_INTERPOLATE_LINEAR);
ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE,
TGSI_INTERPOLATE_LINEAR);
/* vertex data that doesn't change */
for (i = 0; i < 4; i++) {

View File

@@ -87,10 +87,15 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
* MOV OUT[0], IMM[0] // (if writemask != 0xf)
* TEX OUT[0].writemask, IN[0], SAMP[0], 2D;
* END;
*
* \param tex_target one of PIPE_TEXTURE_x
* \parma interp_mode either TGSI_INTERPOLATE_LINEAR or PERSPECTIVE
* \param writemask mask of TGSI_WRITEMASK_x
*/
void *
util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
unsigned tex_target,
unsigned interp_mode,
unsigned writemask )
{
struct ureg_program *ureg;
@@ -98,6 +103,9 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
struct ureg_src tex;
struct ureg_dst out;
assert(interp_mode == TGSI_INTERPOLATE_LINEAR ||
interp_mode == TGSI_INTERPOLATE_PERSPECTIVE);
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
if (ureg == NULL)
return NULL;
@@ -106,7 +114,7 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
tex = ureg_DECL_fs_input( ureg,
TGSI_SEMANTIC_GENERIC, 0,
TGSI_INTERPOLATE_PERSPECTIVE );
interp_mode );
out = ureg_DECL_output( ureg,
TGSI_SEMANTIC_COLOR,
@@ -133,10 +141,12 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
* \param tex_target one of PIPE_TEXTURE_x
*/
void *
util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target )
util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target,
unsigned interp_mode)
{
return util_make_fragment_tex_shader_writemask( pipe,
tex_target,
interp_mode,
TGSI_WRITEMASK_XYZW );
}
@@ -147,7 +157,8 @@ util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target )
*/
void *
util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
unsigned tex_target)
unsigned tex_target,
unsigned interp_mode)
{
struct ureg_program *ureg;
struct ureg_src sampler;
@@ -163,7 +174,7 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
tex = ureg_DECL_fs_input( ureg,
TGSI_SEMANTIC_GENERIC, 0,
TGSI_INTERPOLATE_PERSPECTIVE );
interp_mode );
out = ureg_DECL_output( ureg,
TGSI_SEMANTIC_COLOR,

View File

@@ -52,15 +52,18 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
extern void *
util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
unsigned tex_target,
unsigned interp_mode,
unsigned writemask);
extern void *
util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target);
util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target,
unsigned interp_mode);
extern void *
util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
unsigned tex_target);
unsigned tex_target,
unsigned interp_mode);
extern void *

View File

@@ -59,7 +59,8 @@ static void setup_shaders(struct renderer *ctx)
{
struct pipe_context *pipe = ctx->pipe;
/* fragment shader */
ctx->fs = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
ctx->fs = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
TGSI_INTERPOLATE_LINEAR);
}
static struct pipe_resource *