Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> v2: Also rename "target" param to "stage". Reviewed-by: Brian Paul <brianp@vmware.com>tags/mesa-10.1-rc1
_mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx, | _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx, | ||||
GLenum target, void *mem_ctx) | |||||
gl_shader_stage stage, | |||||
void *mem_ctx) | |||||
: ctx(_ctx), switch_state() | : ctx(_ctx), switch_state() | ||||
{ | { | ||||
switch (target) { | |||||
case GL_VERTEX_SHADER: this->stage = MESA_SHADER_VERTEX; break; | |||||
case GL_FRAGMENT_SHADER: this->stage = MESA_SHADER_FRAGMENT; break; | |||||
case GL_GEOMETRY_SHADER: this->stage = MESA_SHADER_GEOMETRY; break; | |||||
} | |||||
assert(stage < MESA_SHADER_STAGES); | |||||
this->stage = stage; | |||||
this->scanner = NULL; | this->scanner = NULL; | ||||
this->translation_unit.make_empty(); | this->translation_unit.make_empty(); | ||||
bool dump_ast, bool dump_hir) | bool dump_ast, bool dump_hir) | ||||
{ | { | ||||
struct _mesa_glsl_parse_state *state = | struct _mesa_glsl_parse_state *state = | ||||
new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader); | |||||
new(shader) _mesa_glsl_parse_state(ctx, shader->Stage, shader); | |||||
const char *source = shader->Source; | const char *source = shader->Source; | ||||
state->error = glcpp_preprocess(state, &source, &state->info_log, | state->error = glcpp_preprocess(state, &source, &state->info_log, |
struct _mesa_glsl_parse_state { | struct _mesa_glsl_parse_state { | ||||
_mesa_glsl_parse_state(struct gl_context *_ctx, GLenum target, | |||||
_mesa_glsl_parse_state(struct gl_context *_ctx, gl_shader_stage stage, | |||||
void *mem_ctx); | void *mem_ctx); | ||||
DECLARE_RALLOC_CXX_OPERATORS(_mesa_glsl_parse_state); | DECLARE_RALLOC_CXX_OPERATORS(_mesa_glsl_parse_state); |
compile_shader(struct gl_context *ctx, struct gl_shader *shader) | compile_shader(struct gl_context *ctx, struct gl_shader *shader) | ||||
{ | { | ||||
struct _mesa_glsl_parse_state *state = | struct _mesa_glsl_parse_state *state = | ||||
new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader); | |||||
new(shader) _mesa_glsl_parse_state(ctx, shader->Stage, shader); | |||||
_mesa_glsl_compile_shader(ctx, shader, dump_ast, dump_hir); | _mesa_glsl_compile_shader(ctx, shader, dump_ast, dump_hir); | ||||
string input = read_stdin_to_eof(); | string input = read_stdin_to_eof(); | ||||
struct _mesa_glsl_parse_state *state | struct _mesa_glsl_parse_state *state | ||||
= new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader); | |||||
= new(shader) _mesa_glsl_parse_state(ctx, shader->Stage, shader); | |||||
if (input_format_ir) { | if (input_format_ir) { | ||||
shader->ir = new(shader) exec_list; | shader->ir = new(shader) exec_list; |
this->shader->Stage = _mesa_shader_enum_to_shader_stage(this->shader_type); | this->shader->Stage = _mesa_shader_enum_to_shader_stage(this->shader_type); | ||||
this->state = | this->state = | ||||
new(mem_ctx) _mesa_glsl_parse_state(&this->ctx, this->shader->Type, | |||||
new(mem_ctx) _mesa_glsl_parse_state(&this->ctx, this->shader->Stage, | |||||
this->shader); | this->shader); | ||||
_mesa_glsl_initialize_types(this->state); | _mesa_glsl_initialize_types(this->state); |
p.mem_ctx = ralloc_context(NULL); | p.mem_ctx = ralloc_context(NULL); | ||||
p.shader = ctx->Driver.NewShader(ctx, 0, GL_FRAGMENT_SHADER); | p.shader = ctx->Driver.NewShader(ctx, 0, GL_FRAGMENT_SHADER); | ||||
p.shader->ir = new(p.shader) exec_list; | p.shader->ir = new(p.shader) exec_list; | ||||
state = new(p.shader) _mesa_glsl_parse_state(ctx, GL_FRAGMENT_SHADER, | |||||
state = new(p.shader) _mesa_glsl_parse_state(ctx, MESA_SHADER_FRAGMENT, | |||||
p.shader); | p.shader); | ||||
p.shader->symbols = state->symbols; | p.shader->symbols = state->symbols; | ||||
p.top_instructions = p.shader->ir; | p.top_instructions = p.shader->ir; |