X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fstate_tracker%2Fst_program.c;h=a9be80ce8f31be68bae8b197ad40e3397d5c4439;hb=f67bc2e87255298ac22e8ccd98f482cc62d0ec26;hp=d2da20ae424710f01e238b8e1916ca85537f2a8d;hpb=6c6fe0a7040cb7355abefcd6621b67d0458311ae;p=mesa.git diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index d2da20ae424..a9be80ce8f3 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -42,6 +42,7 @@ #include "draw/draw_context.h" #include "tgsi/tgsi_dump.h" +#include "st_debug.h" #include "st_context.h" #include "st_atom.h" #include "st_program.h" @@ -49,12 +50,6 @@ #include "cso_cache/cso_context.h" -#define ST_MAX_SHADER_TOKENS (8 * 1024) - - -#define TGSI_DEBUG 0 - - /** * Translate a Mesa vertex shader into a TGSI shader. * \param outputMapping to map vertex program output registers (VERT_RESULT_x) @@ -70,12 +65,9 @@ st_translate_vertex_program(struct st_context *st, const ubyte *outputSemanticIndex) { struct pipe_context *pipe = st->pipe; - struct tgsi_token *tokens; GLuint defaultOutputMapping[VERT_RESULT_MAX]; - struct pipe_shader_state vs; GLuint attr, i; GLuint num_generic = 0; - GLuint num_tokens; ubyte vs_input_semantic_name[PIPE_MAX_SHADER_INPUTS]; ubyte vs_input_semantic_index[PIPE_MAX_SHADER_INPUTS]; @@ -88,14 +80,7 @@ st_translate_vertex_program(struct st_context *st, GLbitfield input_flags[MAX_PROGRAM_INPUTS]; GLbitfield output_flags[MAX_PROGRAM_OUTPUTS]; - tokens = (struct tgsi_token *)MALLOC(ST_MAX_SHADER_TOKENS * sizeof *tokens); - if(!tokens) { - /* FIXME: propagate error to the caller */ - assert(0); - return; - } - - memset(&vs, 0, sizeof(vs)); +// memset(&vs, 0, sizeof(vs)); memset(input_flags, 0, sizeof(input_flags)); memset(output_flags, 0, sizeof(output_flags)); @@ -330,7 +315,7 @@ st_translate_vertex_program(struct st_context *st, /* free old shader state, if any */ if (stvp->state.tokens) { - _mesa_free((void *) stvp->state.tokens); + st_free_tokens(stvp->state.tokens); stvp->state.tokens = NULL; } if (stvp->driver_shader) { @@ -338,43 +323,36 @@ st_translate_vertex_program(struct st_context *st, stvp->driver_shader = NULL; } - /* XXX: fix static allocation of tokens: - */ - num_tokens = st_translate_mesa_program(st->ctx, - TGSI_PROCESSOR_VERTEX, - &stvp->Base.Base, - /* inputs */ - vs_num_inputs, - stvp->input_to_index, - vs_input_semantic_name, - vs_input_semantic_index, - NULL, - input_flags, - /* outputs */ - vs_num_outputs, - outputMapping, - vs_output_semantic_name, - vs_output_semantic_index, - output_flags, - /* tokenized result */ - tokens, ST_MAX_SHADER_TOKENS); - - assert(num_tokens < ST_MAX_SHADER_TOKENS); - - vs.tokens = (struct tgsi_token *) - _mesa_realloc(tokens, - ST_MAX_SHADER_TOKENS * sizeof *tokens, - num_tokens * sizeof *tokens); + stvp->state.tokens = + st_translate_mesa_program(st->ctx, + TGSI_PROCESSOR_VERTEX, + &stvp->Base.Base, + /* inputs */ + vs_num_inputs, + stvp->input_to_index, + vs_input_semantic_name, + vs_input_semantic_index, + NULL, + input_flags, + /* outputs */ + vs_num_outputs, + outputMapping, + vs_output_semantic_name, + vs_output_semantic_index, + output_flags ); stvp->num_inputs = vs_num_inputs; - stvp->state = vs; /* struct copy */ - stvp->driver_shader = pipe->create_vs_state(pipe, &vs); + stvp->driver_shader = pipe->create_vs_state(pipe, &stvp->state); - if (0) + if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) { _mesa_print_program(&stvp->Base.Base); + debug_printf("\n"); + } - if (TGSI_DEBUG) - tgsi_dump( vs.tokens, 0 ); + if (ST_DEBUG & DEBUG_TGSI) { + tgsi_dump( stvp->state.tokens, 0 ); + debug_printf("\n"); + } } @@ -383,7 +361,6 @@ st_translate_vertex_program(struct st_context *st, * Translate a Mesa fragment shader into a TGSI shader. * \param inputMapping to map fragment program input registers to TGSI * input slots - * \param tokensOut destination for TGSI tokens * \return pointer to cached pipe_shader object. */ void @@ -392,16 +369,13 @@ st_translate_fragment_program(struct st_context *st, const GLuint inputMapping[]) { struct pipe_context *pipe = st->pipe; - struct tgsi_token *tokens; GLuint outputMapping[FRAG_RESULT_MAX]; GLuint defaultInputMapping[FRAG_ATTRIB_MAX]; - struct pipe_shader_state fs; GLuint interpMode[16]; /* XXX size? */ GLuint attr; const GLbitfield inputsRead = stfp->Base.Base.InputsRead; GLuint vslot = 0; GLuint num_generic = 0; - GLuint num_tokens; uint fs_num_inputs = 0; @@ -412,14 +386,7 @@ st_translate_fragment_program(struct st_context *st, GLbitfield input_flags[MAX_PROGRAM_INPUTS]; GLbitfield output_flags[MAX_PROGRAM_OUTPUTS]; - tokens = (struct tgsi_token *)MALLOC(ST_MAX_SHADER_TOKENS * sizeof *tokens); - if(!tokens) { - /* FIXME: propagate error to the caller */ - assert(0); - return; - } - - memset(&fs, 0, sizeof(fs)); +// memset(&fs, 0, sizeof(fs)); memset(input_flags, 0, sizeof(input_flags)); memset(output_flags, 0, sizeof(output_flags)); @@ -541,42 +508,35 @@ st_translate_fragment_program(struct st_context *st, if (!inputMapping) inputMapping = defaultInputMapping; - /* XXX: fix static allocation of tokens: - */ - num_tokens = st_translate_mesa_program(st->ctx, - TGSI_PROCESSOR_FRAGMENT, - &stfp->Base.Base, - /* inputs */ - fs_num_inputs, - inputMapping, - stfp->input_semantic_name, - stfp->input_semantic_index, - interpMode, - input_flags, - /* outputs */ - fs_num_outputs, - outputMapping, - fs_output_semantic_name, - fs_output_semantic_index, - output_flags, - /* tokenized result */ - tokens, ST_MAX_SHADER_TOKENS); - - assert(num_tokens < ST_MAX_SHADER_TOKENS); - - fs.tokens = (struct tgsi_token *) - _mesa_realloc(tokens, - ST_MAX_SHADER_TOKENS * sizeof *tokens, - num_tokens * sizeof *tokens); - - stfp->state = fs; /* struct copy */ - stfp->driver_shader = pipe->create_fs_state(pipe, &fs); - - if (0) + stfp->state.tokens = + st_translate_mesa_program(st->ctx, + TGSI_PROCESSOR_FRAGMENT, + &stfp->Base.Base, + /* inputs */ + fs_num_inputs, + inputMapping, + stfp->input_semantic_name, + stfp->input_semantic_index, + interpMode, + input_flags, + /* outputs */ + fs_num_outputs, + outputMapping, + fs_output_semantic_name, + fs_output_semantic_index, + output_flags ); + + stfp->driver_shader = pipe->create_fs_state(pipe, &stfp->state); + + if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) { _mesa_print_program(&stfp->Base.Base); + debug_printf("\n"); + } - if (TGSI_DEBUG) - tgsi_dump( fs.tokens, 0/*TGSI_DUMP_VERBOSE*/ ); + if (ST_DEBUG & DEBUG_TGSI) { + tgsi_dump( stfp->state.tokens, 0/*TGSI_DUMP_VERBOSE*/ ); + debug_printf("\n"); + } }