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;
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 */
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);
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;
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++) {
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);
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;
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();
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
- maxTokens - ti);
+ Elements(tokens) - ti);
}
/* declare outputs */
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
- maxTokens - ti);
+ Elements(tokens) - ti);
}
/* emit MOV instructions */
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
- maxTokens - ti );
+ Elements(tokens) - ti );
}
/* END instruction */
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);
}
* 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;
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();
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
- maxTokens - ti);
+ Elements(tokens) - ti);
/* declare color[0] output */
decl = tgsi_default_full_declaration();
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
- maxTokens - ti);
+ Elements(tokens) - ti);
/* declare sampler */
decl = tgsi_default_full_declaration();
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
- maxTokens - ti);
+ Elements(tokens) - ti);
/* TEX instruction */
inst = tgsi_default_full_instruction();
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
- maxTokens - ti );
+ Elements(tokens) - ti );
/* END instruction */
inst = tgsi_default_full_instruction();
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);
}
* 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;
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();
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
- maxTokens - ti);
+ Elements(tokens) - ti);
/* declare output */
decl = tgsi_default_full_declaration();
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
- maxTokens - ti);
+ Elements(tokens) - ti);
/* MOVE out[0], in[0]; */
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
- maxTokens - ti );
+ Elements(tokens) - ti );
/* END instruction */
inst = tgsi_default_full_instruction();
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;
-}
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
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;
/** 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;
};
#include "draw/draw_context.h"
#include "tgsi/tgsi_dump.h"
#include "tgsi/tgsi_scan.h"
+#include "tgsi/tgsi_parse.h"
void *
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;
}
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;
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))
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);
/* 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 */
{
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);
}
}
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;
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 */
/** 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;