summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gallium/auxiliary/util/u_blit.c10
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.c10
-rw-r--r--src/gallium/auxiliary/util/u_simple_shaders.c76
-rw-r--r--src/gallium/auxiliary/util/u_simple_shaders.h13
-rw-r--r--src/gallium/drivers/softpipe/sp_fs_sse.c2
-rw-r--r--src/gallium/drivers/softpipe/sp_state.h2
-rw-r--r--src/gallium/drivers/softpipe/sp_state_fs.c26
-rw-r--r--src/mesa/state_tracker/st_atom_shader.c7
-rw-r--r--src/mesa/state_tracker/st_cb_bitmap.c4
-rw-r--r--src/mesa/state_tracker/st_cb_clear.c15
-rw-r--r--src/mesa/state_tracker/st_context.h3
11 files changed, 61 insertions, 107 deletions
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index 3b3777b8730..98bb6a2ce70 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -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);
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 2b675e71b23..847b4a6075e 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -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);
diff --git a/src/gallium/auxiliary/util/u_simple_shaders.c b/src/gallium/auxiliary/util/u_simple_shaders.c
index 8da18d67156..e519c354d25 100644
--- a/src/gallium/auxiliary/util/u_simple_shaders.c
+++ b/src/gallium/auxiliary/util/u_simple_shaders.c
@@ -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;
-}
diff --git a/src/gallium/auxiliary/util/u_simple_shaders.h b/src/gallium/auxiliary/util/u_simple_shaders.h
index 99b8d9067d6..6f8d96af9bc 100644
--- a/src/gallium/auxiliary/util/u_simple_shaders.h
+++ b/src/gallium/auxiliary/util/u_simple_shaders.h
@@ -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
diff --git a/src/gallium/drivers/softpipe/sp_fs_sse.c b/src/gallium/drivers/softpipe/sp_fs_sse.c
index abd37547a98..366abe2ed49 100644
--- a/src/gallium/drivers/softpipe/sp_fs_sse.c
+++ b/src/gallium/drivers/softpipe/sp_fs_sse.c
@@ -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;
diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h
index 6f558e6da5a..9776e978e3e 100644
--- a/src/gallium/drivers/softpipe/sp_state.h
+++ b/src/gallium/drivers/softpipe/sp_state.h
@@ -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;
};
diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c
index b63180baa53..4330c203935 100644
--- a/src/gallium/drivers/softpipe/sp_state_fs.c
+++ b/src/gallium/drivers/softpipe/sp_state_fs.c
@@ -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;
}
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 486582fce89..fc1ff5be04a 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index 3f503f12532..f9f1780ba88 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -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);
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 7d4948a64ea..8206733f766 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 3547925ad7f..d7518ab6897 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -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;