mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 22:49:13 +02:00
gallium: return pipe_shader_state from the simple shader functions
Allows us to fix a mem leak (tokens array).
This commit is contained in:
parent
89222ee49d
commit
dccbfd8bf0
4 changed files with 42 additions and 19 deletions
|
|
@ -58,6 +58,8 @@ struct blit_state
|
|||
struct pipe_rasterizer_state rasterizer;
|
||||
struct pipe_sampler_state sampler;
|
||||
|
||||
struct pipe_shader_state vert_shader;
|
||||
struct pipe_shader_state frag_shader;
|
||||
void *vs;
|
||||
void *fs;
|
||||
|
||||
|
|
@ -129,11 +131,12 @@ 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);
|
||||
semantic_indexes,
|
||||
&ctx->vert_shader);
|
||||
}
|
||||
|
||||
/* fragment shader */
|
||||
ctx->fs = util_make_fragment_tex_shader(pipe);
|
||||
ctx->fs = util_make_fragment_tex_shader(pipe, &ctx->frag_shader);
|
||||
|
||||
ctx->vbuf = pipe->winsys->buffer_create(pipe->winsys,
|
||||
32,
|
||||
|
|
@ -168,6 +171,9 @@ 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->winsys->buffer_destroy(pipe->winsys, ctx->vbuf);
|
||||
|
||||
FREE(ctx);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ struct gen_mipmap_state
|
|||
struct pipe_rasterizer_state rasterizer;
|
||||
struct pipe_sampler_state sampler;
|
||||
|
||||
struct pipe_shader_state vert_shader;
|
||||
struct pipe_shader_state frag_shader;
|
||||
void *vs;
|
||||
void *fs;
|
||||
|
||||
|
|
@ -740,11 +742,12 @@ 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);
|
||||
semantic_indexes,
|
||||
&ctx->vert_shader);
|
||||
}
|
||||
|
||||
/* fragment shader */
|
||||
ctx->fs = util_make_fragment_tex_shader(pipe);
|
||||
ctx->fs = util_make_fragment_tex_shader(pipe, &ctx->frag_shader);
|
||||
|
||||
ctx->vbuf = pipe->winsys->buffer_create(pipe->winsys,
|
||||
32,
|
||||
|
|
@ -813,6 +816,9 @@ 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->winsys->buffer_destroy(pipe->winsys, ctx->vbuf);
|
||||
|
||||
FREE(ctx);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,9 @@ void *
|
|||
util_make_vertex_passthrough_shader(struct pipe_context *pipe,
|
||||
uint num_attribs,
|
||||
const uint *semantic_names,
|
||||
const uint *semantic_indexes)
|
||||
const uint *semantic_indexes,
|
||||
struct pipe_shader_state *shader)
|
||||
|
||||
{
|
||||
uint maxTokens = 100;
|
||||
struct tgsi_token *tokens;
|
||||
|
|
@ -66,7 +68,6 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
|
|||
struct tgsi_full_instruction inst;
|
||||
const uint procType = TGSI_PROCESSOR_VERTEX;
|
||||
uint ti, i;
|
||||
struct pipe_shader_state shader;
|
||||
|
||||
tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
|
||||
|
||||
|
|
@ -145,8 +146,10 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
|
|||
tgsi_dump(tokens, 0);
|
||||
#endif
|
||||
|
||||
shader.tokens = tokens;
|
||||
return pipe->create_vs_state(pipe, &shader);
|
||||
shader->tokens = tokens;
|
||||
/*shader->num_tokens = ti;*/
|
||||
|
||||
return pipe->create_vs_state(pipe, shader);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -158,7 +161,8 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
|
|||
* END;
|
||||
*/
|
||||
void *
|
||||
util_make_fragment_tex_shader(struct pipe_context *pipe)
|
||||
util_make_fragment_tex_shader(struct pipe_context *pipe,
|
||||
struct pipe_shader_state *shader)
|
||||
{
|
||||
uint maxTokens = 100;
|
||||
struct tgsi_token *tokens;
|
||||
|
|
@ -168,7 +172,6 @@ util_make_fragment_tex_shader(struct pipe_context *pipe)
|
|||
struct tgsi_full_instruction inst;
|
||||
const uint procType = TGSI_PROCESSOR_FRAGMENT;
|
||||
uint ti;
|
||||
struct pipe_shader_state shader;
|
||||
|
||||
tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
|
||||
|
||||
|
|
@ -254,8 +257,10 @@ util_make_fragment_tex_shader(struct pipe_context *pipe)
|
|||
tgsi_dump(tokens, 0);
|
||||
#endif
|
||||
|
||||
shader.tokens = tokens;
|
||||
return pipe->create_fs_state(pipe, &shader);
|
||||
shader->tokens = tokens;
|
||||
/*shader->num_tokens = ti;*/
|
||||
|
||||
return pipe->create_fs_state(pipe, shader);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -266,7 +271,8 @@ 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)
|
||||
util_make_fragment_passthrough_shader(struct pipe_context *pipe,
|
||||
struct pipe_shader_state *shader)
|
||||
{
|
||||
uint maxTokens = 40;
|
||||
struct tgsi_token *tokens;
|
||||
|
|
@ -276,7 +282,6 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe)
|
|||
struct tgsi_full_instruction inst;
|
||||
const uint procType = TGSI_PROCESSOR_FRAGMENT;
|
||||
uint ti;
|
||||
struct pipe_shader_state shader;
|
||||
|
||||
tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
|
||||
|
||||
|
|
@ -349,7 +354,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe)
|
|||
tgsi_dump(tokens, 0);
|
||||
#endif
|
||||
|
||||
shader.tokens = tokens;
|
||||
return pipe->create_fs_state(pipe, &shader);
|
||||
shader->tokens = tokens;
|
||||
/*shader->num_tokens = ti;*/
|
||||
|
||||
return pipe->create_fs_state(pipe, shader);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
|
||||
struct pipe_context;
|
||||
struct pipe_shader_state;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -45,15 +46,18 @@ extern void *
|
|||
util_make_vertex_passthrough_shader(struct pipe_context *pipe,
|
||||
uint num_attribs,
|
||||
const uint *semantic_names,
|
||||
const uint *semantic_indexes);
|
||||
const uint *semantic_indexes,
|
||||
struct pipe_shader_state *shader);
|
||||
|
||||
|
||||
extern void *
|
||||
util_make_fragment_tex_shader(struct pipe_context *pipe);
|
||||
util_make_fragment_tex_shader(struct pipe_context *pipe,
|
||||
struct pipe_shader_state *shader);
|
||||
|
||||
|
||||
extern void *
|
||||
util_make_fragment_passthrough_shader(struct pipe_context *pipe);
|
||||
util_make_fragment_passthrough_shader(struct pipe_context *pipe,
|
||||
struct pipe_shader_state *shader);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue