Redoing the way we handle vertex shaders for the draw module.

This commit is contained in:
Zack Rusin
2007-09-28 04:33:55 -04:00
parent f78193f444
commit a1a989f0be
15 changed files with 152 additions and 77 deletions

View File

@@ -155,14 +155,6 @@ void draw_set_viewport_state( struct draw_context *draw,
} }
void
draw_set_vertex_shader(struct draw_context *draw,
const struct pipe_shader_state *shader)
{
draw_flush( draw );
draw->vertex_shader = *shader;
}
void void
draw_set_vertex_buffer(struct draw_context *draw, draw_set_vertex_buffer(struct draw_context *draw,

View File

@@ -92,9 +92,12 @@ void draw_set_rasterize_stage( struct draw_context *draw,
struct draw_stage *stage ); struct draw_stage *stage );
void void * draw_create_vertex_shader(struct draw_context *draw,
draw_set_vertex_shader(struct draw_context *draw,
const struct pipe_shader_state *shader); const struct pipe_shader_state *shader);
void draw_bind_vertex_shader(struct draw_context *draw,
void *vcso);
void draw_delete_vertex_shader(struct draw_context *draw,
void *vcso);
void void

View File

@@ -46,6 +46,7 @@
#include "draw_vertex.h" #include "draw_vertex.h"
#include "x86/rtasm/x86sse.h"
/** /**
* Basic vertex info. * Basic vertex info.
@@ -116,6 +117,15 @@ struct draw_stage
#define VCACHE_OVERFLOW 4 #define VCACHE_OVERFLOW 4
#define VS_QUEUE_LENGTH (VCACHE_SIZE + VCACHE_OVERFLOW + 1) /* can never fill up */ #define VS_QUEUE_LENGTH (VCACHE_SIZE + VCACHE_OVERFLOW + 1) /* can never fill up */
/**
* Private version of the compiled vertex_shader
*/
struct draw_vertex_shader {
const struct pipe_shader_state *state;
#if defined(__i386__) || defined(__386__)
struct x86_function sse2_program;
#endif
};
/** /**
* Private context for the drawing module. * Private context for the drawing module.
@@ -145,7 +155,7 @@ struct draw_context
struct pipe_viewport_state viewport; struct pipe_viewport_state viewport;
struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX];
struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
struct pipe_shader_state vertex_shader; const struct draw_vertex_shader *vertex_shader;
struct pipe_vertex_buffer feedback_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_buffer feedback_buffer[PIPE_ATTRIB_MAX];
struct pipe_vertex_element feedback_element[PIPE_ATTRIB_MAX]; struct pipe_vertex_element feedback_element[PIPE_ATTRIB_MAX];

View File

@@ -85,7 +85,7 @@ void draw_vertex_fetch( struct draw_context *draw,
/*printf("fetch vertex %u: \n", j);*/ /*printf("fetch vertex %u: \n", j);*/
/* loop over vertex attributes (vertex shader inputs) */ /* loop over vertex attributes (vertex shader inputs) */
for (attr = 0; attr < draw->vertex_shader.num_inputs; attr++) { for (attr = 0; attr < draw->vertex_shader->state->num_inputs; attr++) {
unsigned buf = draw->vertex_element[attr].vertex_buffer_index; unsigned buf = draw->vertex_element[attr].vertex_buffer_index;
const void *src const void *src

View File

@@ -36,6 +36,8 @@
#include "draw_context.h" #include "draw_context.h"
#include "draw_vertex.h" #include "draw_vertex.h"
#include "x86/rtasm/x86sse.h"
#include "pipe/tgsi/exec/tgsi_core.h" #include "pipe/tgsi/exec/tgsi_core.h"
static INLINE unsigned static INLINE unsigned
@@ -70,6 +72,7 @@ typedef void (XSTDCALL *codegen_function) (
float (*constant)[4], float (*constant)[4],
struct tgsi_exec_vector *temporary ); struct tgsi_exec_vector *temporary );
/** /**
* Transform vertices with the current vertex program/shader * Transform vertices with the current vertex program/shader
* Up to four vertices can be shaded at a time. * Up to four vertices can be shaded at a time.
@@ -92,7 +95,7 @@ run_vertex_program(struct draw_context *draw,
const float *trans = draw->viewport.translate; const float *trans = draw->viewport.translate;
assert(count <= 4); assert(count <= 4);
assert(draw->vertex_shader.output_semantic_name[0] assert(draw->vertex_shader->state->output_semantic_name[0]
== TGSI_SEMANTIC_POSITION); == TGSI_SEMANTIC_POSITION);
#ifdef DEBUG #ifdef DEBUG
@@ -101,7 +104,7 @@ run_vertex_program(struct draw_context *draw,
/* init machine state */ /* init machine state */
tgsi_exec_machine_init(&machine, tgsi_exec_machine_init(&machine,
draw->vertex_shader.tokens, draw->vertex_shader->state->tokens,
PIPE_MAX_SAMPLERS, PIPE_MAX_SAMPLERS,
NULL /*samplers*/ ); NULL /*samplers*/ );
@@ -114,8 +117,8 @@ run_vertex_program(struct draw_context *draw,
draw_vertex_fetch( draw, &machine, elts, count ); draw_vertex_fetch( draw, &machine, elts, count );
/* run shader */ /* run shader */
if( draw->vertex_shader.executable != NULL ) { if( draw->vertex_shader->state->executable != NULL ) {
codegen_function func = (codegen_function) draw->vertex_shader.executable; codegen_function func = (codegen_function) draw->vertex_shader->state->executable;
func( func(
machine.Inputs, machine.Inputs,
machine.Outputs, machine.Outputs,
@@ -206,3 +209,42 @@ void draw_vertex_shader_queue_flush( struct draw_context *draw )
draw->vs.queue_nr = 0; draw->vs.queue_nr = 0;
} }
void *
draw_create_vertex_shader(struct draw_context *draw,
const struct pipe_shader_state *shader)
{
struct draw_vertex_shader *vs = calloc(1, sizeof(struct draw_vertex_shader));
vs->state = shader;
#if defined(__i386__) || defined(__386__)
x86_init_func(&vs->sse2_program);
tgsi_emit_sse2(shader->tokens, &vs->sse2_program);
((struct pipe_shader_state*)(vs->state))->executable =
x86_get_func(&vs->sse2_program);
#endif
return vs;
}
void draw_bind_vertex_shader(struct draw_context *draw,
void *vcso)
{
draw_flush(draw);
draw->vertex_shader = (struct draw_vertex_shader*)(vcso);
}
void draw_delete_vertex_shader(struct draw_context *draw,
void *vcso)
{
struct draw_vertex_shader *vs = (struct draw_vertex_shader*)(vcso);
#if defined(__i386__) || defined(__386__)
x86_release_func(&vs->sse2_program);
#endif
free(vcso);
}

View File

@@ -443,16 +443,13 @@ static void i915_set_polygon_stipple( struct pipe_context *pipe,
{ {
} }
static void * i915_create_fs_state(struct pipe_context *pipe,
static void *
i915_create_shader_state(struct pipe_context *pipe,
const struct pipe_shader_state *templ) const struct pipe_shader_state *templ)
{ {
return 0; return 0;
} }
static void i915_bind_fs_state( struct pipe_context *pipe, static void i915_bind_fs_state(struct pipe_context *pipe, void *fs)
void *fs )
{ {
struct i915_context *i915 = i915_context(pipe); struct i915_context *i915 = i915_context(pipe);
@@ -461,20 +458,35 @@ static void i915_bind_fs_state( struct pipe_context *pipe,
i915->dirty |= I915_NEW_FS; i915->dirty |= I915_NEW_FS;
} }
static void i915_delete_fs_state(struct pipe_context *pipe, void *shader)
{
/*do nothing*/
}
static void i915_bind_vs_state(struct pipe_context *pipe, static void *
void *vs) i915_create_vs_state(struct pipe_context *pipe,
const struct pipe_shader_state *templ)
{ {
struct i915_context *i915 = i915_context(pipe); struct i915_context *i915 = i915_context(pipe);
/* just pass-through to draw module */ /* just pass-through to draw module */
draw_set_vertex_shader(i915->draw, (const struct pipe_shader_state *)vs); return draw_create_vertex_shader(i915->draw, templ);
} }
static void i915_delete_shader_state(struct pipe_context *pipe, static void i915_bind_vs_state(struct pipe_context *pipe, void *vs)
void *shader)
{ {
/*do nothing*/ struct i915_context *i915 = i915_context(pipe);
/* just pass-through to draw module */
draw_bind_vertex_shader(i915->draw, vs);
}
static void i915_delete_vs_state(struct pipe_context *pipe, void *shader)
{
struct i915_context *i915 = i915_context(pipe);
/* just pass-through to draw module */
draw_delete_vertex_shader(i915->draw, shader);
} }
static void i915_set_constant_buffer(struct pipe_context *pipe, static void i915_set_constant_buffer(struct pipe_context *pipe,
@@ -707,12 +719,12 @@ i915_init_state_functions( struct i915_context *i915 )
i915->pipe.create_rasterizer_state = i915_create_rasterizer_state; i915->pipe.create_rasterizer_state = i915_create_rasterizer_state;
i915->pipe.bind_rasterizer_state = i915_bind_rasterizer_state; i915->pipe.bind_rasterizer_state = i915_bind_rasterizer_state;
i915->pipe.delete_rasterizer_state = i915_delete_rasterizer_state; i915->pipe.delete_rasterizer_state = i915_delete_rasterizer_state;
i915->pipe.create_fs_state = i915_create_shader_state; i915->pipe.create_fs_state = i915_create_fs_state;
i915->pipe.bind_fs_state = i915_bind_fs_state; i915->pipe.bind_fs_state = i915_bind_fs_state;
i915->pipe.delete_fs_state = i915_delete_shader_state; i915->pipe.delete_fs_state = i915_delete_fs_state;
i915->pipe.create_vs_state = i915_create_shader_state; i915->pipe.create_vs_state = i915_create_vs_state;
i915->pipe.bind_vs_state = i915_bind_vs_state; i915->pipe.bind_vs_state = i915_bind_vs_state;
i915->pipe.delete_vs_state = i915_delete_shader_state; i915->pipe.delete_vs_state = i915_delete_vs_state;
i915->pipe.set_blend_color = i915_set_blend_color; i915->pipe.set_blend_color = i915_set_blend_color;
i915->pipe.set_clip_state = i915_set_clip_state; i915->pipe.set_clip_state = i915_set_clip_state;

View File

@@ -275,12 +275,12 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state; softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state;
softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state; softpipe->pipe.bind_rasterizer_state = softpipe_bind_rasterizer_state;
softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state; softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state;
softpipe->pipe.create_fs_state = softpipe_create_shader_state; softpipe->pipe.create_fs_state = softpipe_create_fs_state;
softpipe->pipe.bind_fs_state = softpipe_bind_fs_state; softpipe->pipe.bind_fs_state = softpipe_bind_fs_state;
softpipe->pipe.delete_fs_state = softpipe_delete_shader_state; softpipe->pipe.delete_fs_state = softpipe_delete_fs_state;
softpipe->pipe.create_vs_state = softpipe_create_shader_state; softpipe->pipe.create_vs_state = softpipe_create_vs_state;
softpipe->pipe.bind_vs_state = softpipe_bind_vs_state; softpipe->pipe.bind_vs_state = softpipe_bind_vs_state;
softpipe->pipe.delete_vs_state = softpipe_delete_shader_state; softpipe->pipe.delete_vs_state = softpipe_delete_vs_state;
softpipe->pipe.set_blend_color = softpipe_set_blend_color; softpipe->pipe.set_blend_color = softpipe_set_blend_color;
softpipe->pipe.set_clip_state = softpipe_set_clip_state; softpipe->pipe.set_clip_state = softpipe_set_clip_state;

View File

@@ -62,6 +62,10 @@ struct draw_stage;
#define SP_NEW_VS 0x2000 #define SP_NEW_VS 0x2000
#define SP_NEW_CONSTANTS 0x4000 #define SP_NEW_CONSTANTS 0x4000
struct sp_vertex_shader_state {
const struct pipe_shader_state *state;
void *draw_data;
};
struct softpipe_context { struct softpipe_context {
struct pipe_context pipe; /**< base class */ struct pipe_context pipe; /**< base class */
@@ -76,7 +80,7 @@ struct softpipe_context {
const struct pipe_depth_stencil_state *depth_stencil; const struct pipe_depth_stencil_state *depth_stencil;
const struct pipe_rasterizer_state *rasterizer; const struct pipe_rasterizer_state *rasterizer;
const struct pipe_shader_state *fs; const struct pipe_shader_state *fs;
const struct pipe_shader_state *vs; const struct sp_vertex_shader_state *vs;
struct pipe_blend_color blend_color; struct pipe_blend_color blend_color;
struct pipe_clear_color_state clear_color; struct pipe_clear_color_state clear_color;

View File

@@ -87,12 +87,14 @@ void softpipe_set_constant_buffer(struct pipe_context *,
void softpipe_set_feedback_state( struct pipe_context *, void softpipe_set_feedback_state( struct pipe_context *,
const struct pipe_feedback_state * ); const struct pipe_feedback_state * );
void * void *softpipe_create_fs_state(struct pipe_context *,
softpipe_create_shader_state( struct pipe_context *, const struct pipe_shader_state *);
const struct pipe_shader_state * ); void softpipe_bind_fs_state(struct pipe_context *, void *);
void softpipe_bind_fs_state( struct pipe_context *, void * ); void softpipe_delete_fs_state(struct pipe_context *, void *);
void softpipe_bind_vs_state( struct pipe_context *, void * ); void *softpipe_create_vs_state(struct pipe_context *,
void softpipe_delete_shader_state( struct pipe_context *, void * ); const struct pipe_shader_state *);
void softpipe_bind_vs_state(struct pipe_context *, void *);
void softpipe_delete_vs_state(struct pipe_context *, void *);
void softpipe_set_polygon_stipple( struct pipe_context *, void softpipe_set_polygon_stipple( struct pipe_context *,
const struct pipe_poly_stipple * ); const struct pipe_poly_stipple * );

View File

@@ -43,7 +43,7 @@
*/ */
static void calculate_vertex_layout( struct softpipe_context *softpipe ) static void calculate_vertex_layout( struct softpipe_context *softpipe )
{ {
const struct pipe_shader_state *vs = softpipe->vs; const struct pipe_shader_state *vs = softpipe->vs->state;
const struct pipe_shader_state *fs = softpipe->fs; const struct pipe_shader_state *fs = softpipe->fs;
const interp_mode colorInterp const interp_mode colorInterp
= softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; = softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;

View File

@@ -33,10 +33,13 @@
#include "pipe/draw/draw_context.h" #include "pipe/draw/draw_context.h"
void * softpipe_create_shader_state(struct pipe_context *pipe, void * softpipe_create_fs_state(struct pipe_context *pipe,
const struct pipe_shader_state *templ) const struct pipe_shader_state *templ)
{ {
/* we just want the pipe_shader_state template in the bind calls */ /* Decide whether we'll be codegenerating this shader and if so do
* that now.
*/
return 0; return 0;
} }
@@ -49,25 +52,51 @@ void softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
softpipe->dirty |= SP_NEW_FS; softpipe->dirty |= SP_NEW_FS;
} }
void softpipe_delete_fs_state(struct pipe_context *pipe,
void *shader)
{
}
void * softpipe_create_vs_state(struct pipe_context *pipe,
const struct pipe_shader_state *templ)
{
struct softpipe_context *softpipe = softpipe_context(pipe);
struct sp_vertex_shader_state *state =
malloc(sizeof(struct sp_vertex_shader_state));
state->state = templ;
state->draw_data = draw_create_vertex_shader(softpipe->draw,
state->state);
return state;
}
void softpipe_bind_vs_state(struct pipe_context *pipe, void *vs) void softpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
{ {
struct softpipe_context *softpipe = softpipe_context(pipe); struct softpipe_context *softpipe = softpipe_context(pipe);
softpipe->vs = (struct pipe_shader_state *)vs; softpipe->vs = (const struct sp_vertex_shader_state *)vs;
draw_bind_vertex_shader(softpipe->draw, softpipe->vs->draw_data);
softpipe->dirty |= SP_NEW_VS; softpipe->dirty |= SP_NEW_VS;
draw_set_vertex_shader(softpipe->draw, (struct pipe_shader_state *)vs);
} }
void softpipe_delete_vs_state(struct pipe_context *pipe,
void softpipe_delete_shader_state( struct pipe_context *pipe, void *vs)
void *shader )
{ {
/* do nothing */ struct softpipe_context *softpipe = softpipe_context(pipe);
struct sp_vertex_shader_state *state =
(struct sp_vertex_shader_state *)vs;
draw_delete_vertex_shader(softpipe->draw, state->draw_data);
free(state);
} }
void softpipe_set_constant_buffer(struct pipe_context *pipe, void softpipe_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index, uint shader, uint index,
const struct pipe_constant_buffer *buf) const struct pipe_constant_buffer *buf)

View File

@@ -86,10 +86,6 @@ static struct gl_program *st_new_program( GLcontext *ctx,
prog->serialNo = 1; prog->serialNo = 1;
#if defined(__i386__) || defined(__386__)
x86_init_func( &prog->sse2_program );
#endif
return _mesa_init_vertex_program( ctx, return _mesa_init_vertex_program( ctx,
&prog->Base, &prog->Base,
target, target,
@@ -129,9 +125,6 @@ static void st_delete_program( GLcontext *ctx,
case GL_VERTEX_PROGRAM_ARB: case GL_VERTEX_PROGRAM_ARB:
{ {
struct st_vertex_program *stvp = (struct st_vertex_program *) prog; struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
#if defined(__i386__) || defined(__386__)
x86_release_func( &stvp->sse2_program );
#endif
st_remove_vertex_program(st, stvp); st_remove_vertex_program(st, stvp);
} }
break; break;

View File

@@ -405,7 +405,7 @@ st_feedback_draw_vbo(GLcontext *ctx,
draw_set_viewport_state(draw, &st->state.viewport); draw_set_viewport_state(draw, &st->state.viewport);
draw_set_clip_state(draw, &st->state.clip); draw_set_clip_state(draw, &st->state.clip);
draw_set_rasterizer_state(draw, &st->state.rasterizer->state); draw_set_rasterizer_state(draw, &st->state.rasterizer->state);
draw_set_vertex_shader(draw, &st->state.vs->state); draw_bind_vertex_shader(draw, st->state.vs->data);
/* XXX need to set vertex info too */ /* XXX need to set vertex info too */

View File

@@ -253,14 +253,6 @@ st_translate_vertex_program(struct st_context *st,
if (TGSI_DEBUG) if (TGSI_DEBUG)
tgsi_dump( tokensOut, 0 ); tgsi_dump( tokensOut, 0 );
#if defined(__i386__) || defined(__386__)
if (stvp->sse2_program.csr == stvp->sse2_program.store)
tgsi_emit_sse2( tokensOut, &stvp->sse2_program );
if (!cso->state.executable)
((struct cso_vertex_shader*)cso)->state.executable = (void *) x86_get_func( &stvp->sse2_program );
#endif
return cso; return cso;
} }

View File

@@ -79,10 +79,6 @@ struct st_vertex_program
/** The program in TGSI format */ /** The program in TGSI format */
struct tgsi_token tokens[ST_FP_MAX_TOKENS]; struct tgsi_token tokens[ST_FP_MAX_TOKENS];
#if defined(__i386__) || defined(__386__)
struct x86_function sse2_program;
#endif
/** Pointer to the corresponding cached shader */ /** Pointer to the corresponding cached shader */
const struct cso_vertex_shader *vs; const struct cso_vertex_shader *vs;