gallium: no need to keep a copy of shader tokens in state tracker

Any driver who needs a copy of the shader tokens must organize to
do so itself.  This has been the case for a long time, but there
was still defensive code in the state tracker, which is now removed.

Any bugs resulting from this need to be fixed in the offending driver...
This commit is contained in:
Keith Whitwell
2009-03-13 16:22:35 +00:00
parent b3be1651f4
commit fa0f48504a
11 changed files with 61 additions and 107 deletions

View File

@@ -60,8 +60,6 @@ struct blit_state
struct pipe_sampler_state sampler;
struct pipe_viewport_state viewport;
struct pipe_shader_state vert_shader;
struct pipe_shader_state frag_shader;
void *vs;
void *fs;
@@ -134,12 +132,11 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
TGSI_SEMANTIC_GENERIC };
const uint semantic_indexes[] = { 0, 0 };
ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
semantic_indexes,
&ctx->vert_shader);
semantic_indexes);
}
/* fragment shader */
ctx->fs = util_make_fragment_tex_shader(pipe, &ctx->frag_shader);
ctx->fs = util_make_fragment_tex_shader(pipe);
ctx->vbuf = NULL;
/* init vertex data that doesn't change */
@@ -164,9 +161,6 @@ util_destroy_blit(struct blit_state *ctx)
pipe->delete_vs_state(pipe, ctx->vs);
pipe->delete_fs_state(pipe, ctx->fs);
FREE((void*) ctx->vert_shader.tokens);
FREE((void*) ctx->frag_shader.tokens);
pipe_buffer_reference(&ctx->vbuf, NULL);
FREE(ctx);

View File

@@ -64,8 +64,6 @@ struct gen_mipmap_state
struct pipe_sampler_state sampler;
struct pipe_viewport_state viewport;
struct pipe_shader_state vert_shader;
struct pipe_shader_state frag_shader;
void *vs;
void *fs;
@@ -1322,12 +1320,11 @@ util_create_gen_mipmap(struct pipe_context *pipe,
TGSI_SEMANTIC_GENERIC };
const uint semantic_indexes[] = { 0, 0 };
ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
semantic_indexes,
&ctx->vert_shader);
semantic_indexes);
}
/* fragment shader */
ctx->fs = util_make_fragment_tex_shader(pipe, &ctx->frag_shader);
ctx->fs = util_make_fragment_tex_shader(pipe);
/* vertex data that doesn't change */
for (i = 0; i < 4; i++) {
@@ -1412,9 +1409,6 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx)
pipe->delete_vs_state(pipe, ctx->vs);
pipe->delete_fs_state(pipe, ctx->fs);
FREE((void*) ctx->vert_shader.tokens);
FREE((void*) ctx->frag_shader.tokens);
pipe_buffer_reference(&ctx->vbuf, NULL);
FREE(ctx);

View File

@@ -55,12 +55,11 @@ void *
util_make_vertex_passthrough_shader(struct pipe_context *pipe,
uint num_attribs,
const uint *semantic_names,
const uint *semantic_indexes,
struct pipe_shader_state *shader)
const uint *semantic_indexes)
{
uint maxTokens = 100;
struct tgsi_token *tokens;
struct pipe_shader_state shader;
struct tgsi_token tokens[100];
struct tgsi_header *header;
struct tgsi_processor *processor;
struct tgsi_full_declaration decl;
@@ -68,8 +67,6 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
const uint procType = TGSI_PROCESSOR_VERTEX;
uint ti, i;
tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
/* shader header
*/
*(struct tgsi_version *) &tokens[0] = tgsi_build_version();
@@ -96,7 +93,7 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
maxTokens - ti);
Elements(tokens) - ti);
}
/* declare outputs */
@@ -111,7 +108,7 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
maxTokens - ti);
Elements(tokens) - ti);
}
/* emit MOV instructions */
@@ -128,7 +125,7 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
maxTokens - ti );
Elements(tokens) - ti );
}
/* END instruction */
@@ -139,16 +136,15 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
maxTokens - ti );
Elements(tokens) - ti );
#if 0 /*debug*/
tgsi_dump(tokens, 0);
#endif
shader->tokens = tokens;
/*shader->num_tokens = ti;*/
shader.tokens = tokens;
return pipe->create_vs_state(pipe, shader);
return pipe->create_vs_state(pipe, &shader);
}
@@ -160,11 +156,10 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
* END;
*/
void *
util_make_fragment_tex_shader(struct pipe_context *pipe,
struct pipe_shader_state *shader)
util_make_fragment_tex_shader(struct pipe_context *pipe)
{
uint maxTokens = 100;
struct tgsi_token *tokens;
struct pipe_shader_state shader;
struct tgsi_token tokens[100];
struct tgsi_header *header;
struct tgsi_processor *processor;
struct tgsi_full_declaration decl;
@@ -172,8 +167,6 @@ util_make_fragment_tex_shader(struct pipe_context *pipe,
const uint procType = TGSI_PROCESSOR_FRAGMENT;
uint ti;
tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
/* shader header
*/
*(struct tgsi_version *) &tokens[0] = tgsi_build_version();
@@ -199,7 +192,7 @@ util_make_fragment_tex_shader(struct pipe_context *pipe,
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
maxTokens - ti);
Elements(tokens) - ti);
/* declare color[0] output */
decl = tgsi_default_full_declaration();
@@ -212,7 +205,7 @@ util_make_fragment_tex_shader(struct pipe_context *pipe,
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
maxTokens - ti);
Elements(tokens) - ti);
/* declare sampler */
decl = tgsi_default_full_declaration();
@@ -222,7 +215,7 @@ util_make_fragment_tex_shader(struct pipe_context *pipe,
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
maxTokens - ti);
Elements(tokens) - ti);
/* TEX instruction */
inst = tgsi_default_full_instruction();
@@ -239,7 +232,7 @@ util_make_fragment_tex_shader(struct pipe_context *pipe,
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
maxTokens - ti );
Elements(tokens) - ti );
/* END instruction */
inst = tgsi_default_full_instruction();
@@ -249,16 +242,15 @@ util_make_fragment_tex_shader(struct pipe_context *pipe,
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
maxTokens - ti );
Elements(tokens) - ti );
#if 0 /*debug*/
tgsi_dump(tokens, 0);
#endif
shader->tokens = tokens;
/*shader->num_tokens = ti;*/
shader.tokens = tokens;
return pipe->create_fs_state(pipe, shader);
return pipe->create_fs_state(pipe, &shader);
}
@@ -269,11 +261,10 @@ util_make_fragment_tex_shader(struct pipe_context *pipe,
* Make simple fragment color pass-through shader.
*/
void *
util_make_fragment_passthrough_shader(struct pipe_context *pipe,
struct pipe_shader_state *shader)
util_make_fragment_passthrough_shader(struct pipe_context *pipe)
{
uint maxTokens = 40;
struct tgsi_token *tokens;
struct pipe_shader_state shader;
struct tgsi_token tokens[40];
struct tgsi_header *header;
struct tgsi_processor *processor;
struct tgsi_full_declaration decl;
@@ -281,8 +272,6 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe,
const uint procType = TGSI_PROCESSOR_FRAGMENT;
uint ti;
tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
/* shader header
*/
*(struct tgsi_version *) &tokens[0] = tgsi_build_version();
@@ -306,7 +295,7 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe,
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
maxTokens - ti);
Elements(tokens) - ti);
/* declare output */
decl = tgsi_default_full_declaration();
@@ -319,7 +308,7 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe,
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
maxTokens - ti);
Elements(tokens) - ti);
/* MOVE out[0], in[0]; */
@@ -334,7 +323,7 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe,
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
maxTokens - ti );
Elements(tokens) - ti );
/* END instruction */
inst = tgsi_default_full_instruction();
@@ -344,24 +333,17 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe,
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
maxTokens - ti );
Elements(tokens) - ti );
assert(ti < maxTokens);
assert(ti < Elements(tokens));
#if 0 /*debug*/
tgsi_dump(tokens, 0);
#endif
shader->tokens = tokens;
/*shader->num_tokens = ti;*/
shader.tokens = tokens;
return pipe->create_fs_state(pipe, shader);
return pipe->create_fs_state(pipe, &shader);
}
void
util_free_shader(struct pipe_shader_state *shader)
{
FREE((struct tgsi_token *)shader->tokens);
shader->tokens = NULL;
}

View File

@@ -46,22 +46,15 @@ extern void *
util_make_vertex_passthrough_shader(struct pipe_context *pipe,
uint num_attribs,
const uint *semantic_names,
const uint *semantic_indexes,
struct pipe_shader_state *shader);
const uint *semantic_indexes);
extern void *
util_make_fragment_tex_shader(struct pipe_context *pipe,
struct pipe_shader_state *shader);
util_make_fragment_tex_shader(struct pipe_context *pipe);
extern void *
util_make_fragment_passthrough_shader(struct pipe_context *pipe,
struct pipe_shader_state *shader);
extern void
util_free_shader(struct pipe_shader_state *shader);
util_make_fragment_passthrough_shader(struct pipe_context *pipe);
#ifdef __cplusplus

View File

@@ -145,7 +145,7 @@ softpipe_create_fs_sse(struct softpipe_context *softpipe,
return NULL;
}
shader->base.shader = *templ;
shader->base.shader.tokens = NULL; /* don't hold reference to templ->tokens */
shader->base.prepare = fs_sse_prepare;
shader->base.run = fs_sse_run;
shader->base.delete = fs_sse_delete;

View File

@@ -85,7 +85,7 @@ struct sp_fragment_shader {
/** Subclass of pipe_shader_state */
struct sp_vertex_shader {
struct pipe_shader_state shader; /* Note: this field not actually used */
struct pipe_shader_state shader;
struct draw_vertex_shader *draw_data;
};

View File

@@ -36,6 +36,7 @@
#include "draw/draw_context.h"
#include "tgsi/tgsi_dump.h"
#include "tgsi/tgsi_scan.h"
#include "tgsi/tgsi_parse.h"
void *
@@ -97,17 +98,28 @@ softpipe_create_vs_state(struct pipe_context *pipe,
struct sp_vertex_shader *state;
state = CALLOC_STRUCT(sp_vertex_shader);
if (state == NULL ) {
return NULL;
}
if (state == NULL )
goto fail;
/* copy shader tokens, the ones passed in will go away.
*/
state->shader.tokens = tgsi_dup_tokens(templ->tokens);
if (state->shader.tokens == NULL)
goto fail;
state->draw_data = draw_create_vertex_shader(softpipe->draw, templ);
if (state->draw_data == NULL) {
FREE( state );
return NULL;
}
if (state->draw_data == NULL)
goto fail;
return state;
fail:
if (state) {
FREE( (void *)state->shader.tokens );
FREE( state->draw_data );
FREE( state );
}
return NULL;
}

View File

@@ -307,14 +307,9 @@ st_free_translated_vertex_programs(struct st_context *st,
static void *
get_passthrough_fs(struct st_context *st)
{
struct pipe_shader_state shader;
if (!st->passthrough_fs) {
st->passthrough_fs =
util_make_fragment_passthrough_shader(st->pipe, &shader);
#if 0 /* We actually need to keep the tokens around at this time */
util_free_shader(&shader);
#endif
util_make_fragment_passthrough_shader(st->pipe);
}
return st->passthrough_fs;

View File

@@ -740,8 +740,7 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
const uint semantic_indexes[] = { 0, 0, 0 };
st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3,
semantic_names,
semantic_indexes,
&st->bitmap.vert_shader);
semantic_indexes);
}
if (UseBitmapCache && accum_bitmap(st, x, y, width, height, unpack, bitmap))
@@ -830,7 +829,6 @@ st_destroy_bitmap(struct st_context *st)
cso_delete_vertex_shader(st->cso_context, st->bitmap.vs);
st->bitmap.vs = NULL;
}
util_free_shader(&st->bitmap.vert_shader);
if (st->bitmap.vbuf) {
pipe_buffer_reference(&st->bitmap.vbuf, NULL);

View File

@@ -77,7 +77,7 @@ st_init_clear(struct st_context *st)
/* fragment shader state: color pass-through program */
st->clear.fs =
util_make_fragment_passthrough_shader(pipe, &st->clear.frag_shader);
util_make_fragment_passthrough_shader(pipe);
/* vertex shader state: color/position pass-through */
{
@@ -86,8 +86,7 @@ st_init_clear(struct st_context *st)
const uint semantic_indexes[] = { 0, 0 };
st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2,
semantic_names,
semantic_indexes,
&st->clear.vert_shader);
semantic_indexes);
}
}
@@ -95,16 +94,6 @@ st_init_clear(struct st_context *st)
void
st_destroy_clear(struct st_context *st)
{
if (st->clear.vert_shader.tokens) {
util_free_shader(&st->clear.vert_shader);
st->clear.vert_shader.tokens = NULL;
}
if (st->clear.frag_shader.tokens) {
util_free_shader(&st->clear.frag_shader);
st->clear.frag_shader.tokens = NULL;
}
if (st->clear.fs) {
cso_delete_fragment_shader(st->cso_context, st->clear.fs);
st->clear.fs = NULL;

View File

@@ -149,7 +149,6 @@ struct st_context
struct {
struct pipe_rasterizer_state rasterizer;
struct pipe_sampler_state sampler;
struct pipe_shader_state vert_shader;
enum pipe_format tex_format;
void *vs;
float vertices[4][3][4]; /**< vertex pos + color + texcoord */
@@ -166,8 +165,6 @@ struct st_context
/** for glClear */
struct {
struct pipe_shader_state vert_shader;
struct pipe_shader_state frag_shader;
struct pipe_rasterizer_state raster;
struct pipe_viewport_state viewport;
void *vs;