X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fff_fragment_shader.cpp;h=9bb706cc54906b6e1bb12d047ab3949d30881852;hb=5980fc35c9e2e25a5a53cb1b38245ad763885cca;hp=d162da8db0c6878f6ae3a6db188f92a2ee6dfbc7;hpb=45595d506646f560ab16af58acdea2fc563e942b;p=mesa.git diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp index d162da8db0c..9bb706cc549 100644 --- a/src/mesa/main/ff_fragment_shader.cpp +++ b/src/mesa/main/ff_fragment_shader.cpp @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2007 VMware, Inc. * All Rights Reserved. * Copyright 2009 VMware, Inc. All Rights Reserved. * Copyright © 2010-2011 Intel Corporation @@ -20,7 +20,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -32,7 +32,6 @@ extern "C" { #include "imports.h" #include "mtypes.h" #include "main/context.h" -#include "main/uniforms.h" #include "main/macros.h" #include "main/samplerobj.h" #include "program/program.h" @@ -43,6 +42,7 @@ extern "C" { #include "program/prog_statevars.h" #include "program/programopt.h" #include "texenvprogram.h" +#include "texobj.h" } #include "main/uniforms.h" #include "../glsl/glsl_types.h" @@ -51,7 +51,6 @@ extern "C" { #include "../glsl/glsl_symbol_table.h" #include "../glsl/glsl_parser_extras.h" #include "../glsl/ir_optimization.h" -#include "../glsl/ir_print_visitor.h" #include "../program/ir_to_mesa.h" using namespace ir_builder; @@ -221,7 +220,6 @@ static GLuint translate_source( GLenum src ) #define MODE_MODULATE_SUBTRACT_ATI 12 /* r = a0 * a2 - a1 */ #define MODE_ADD_PRODUCTS 13 /* r = a0 * a1 + a2 * a3 */ #define MODE_ADD_PRODUCTS_SIGNED 14 /* r = a0 * a1 + a2 * a3 - 0.5 */ -#define MODE_BUMP_ENVMAP_ATI 15 /* special */ #define MODE_UNKNOWN 16 /** @@ -251,7 +249,6 @@ static GLuint translate_mode( GLenum envMode, GLenum mode ) case GL_MODULATE_ADD_ATI: return MODE_MODULATE_ADD_ATI; case GL_MODULATE_SIGNED_ADD_ATI: return MODE_MODULATE_SIGNED_ADD_ATI; case GL_MODULATE_SUBTRACT_ATI: return MODE_MODULATE_SUBTRACT_ATI; - case GL_BUMP_ENVMAP_ATI: return MODE_BUMP_ENVMAP_ATI; default: assert(0); return MODE_UNKNOWN; @@ -284,7 +281,6 @@ need_saturate( GLuint mode ) case MODE_MODULATE_SUBTRACT_ATI: case MODE_ADD_PRODUCTS: case MODE_ADD_PRODUCTS_SIGNED: - case MODE_BUMP_ENVMAP_ATI: return GL_TRUE; default: assert(0); @@ -292,18 +288,6 @@ need_saturate( GLuint mode ) } } - - -/** - * Translate TEXTURE_x_BIT to TEXTURE_x_INDEX. - */ -static GLuint translate_tex_src_bit( GLbitfield bit ) -{ - ASSERT(bit); - return ffs(bit) - 1; -} - - #define VERT_BIT_TEX_ANY (0xff << VERT_ATTRIB_TEX0) /** @@ -319,9 +303,9 @@ static GLbitfield get_fp_input_mask( struct gl_context *ctx ) { /* _NEW_PROGRAM */ const GLboolean vertexShader = - (ctx->Shader.CurrentVertexProgram && - ctx->Shader.CurrentVertexProgram->LinkStatus && - ctx->Shader.CurrentVertexProgram->_LinkedShaders[MESA_SHADER_VERTEX]); + (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX] && + ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX]->LinkStatus && + ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX]->_LinkedShaders[MESA_SHADER_VERTEX]); const GLboolean vertexProgram = ctx->VertexProgram._Enabled; GLbitfield fp_inputs = 0x0; @@ -385,7 +369,7 @@ static GLbitfield get_fp_input_mask( struct gl_context *ctx ) * validation (see additional comments in state.c). */ if (vertexShader) - vprog = ctx->Shader.CurrentVertexProgram->_LinkedShaders[MESA_SHADER_VERTEX]->Program; + vprog = ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX]->_LinkedShaders[MESA_SHADER_VERTEX]->Program; else vprog = &ctx->VertexProgram.Current->Base; @@ -432,7 +416,7 @@ static GLuint make_state_key( struct gl_context *ctx, struct state_key *key ) const struct gl_sampler_object *samp; GLenum format; - if (!texUnit->_ReallyEnabled || !texUnit->Enabled) + if (!texUnit->_Current || !texUnit->Enabled) continue; samp = _mesa_get_samplerobj(ctx, i); @@ -443,8 +427,8 @@ static GLuint make_state_key( struct gl_context *ctx, struct state_key *key ) key->nr_enabled_units = i + 1; inputs_referenced |= VARYING_BIT_TEX(i); - key->unit[i].source_index = - translate_tex_src_bit(texUnit->_ReallyEnabled); + key->unit[i].source_index = _mesa_tex_target_to_index(ctx, + texObj->Target); key->unit[i].shadow = ((samp->CompareMode == GL_COMPARE_R_TO_TEXTURE) && @@ -468,16 +452,6 @@ static GLuint make_state_key( struct gl_context *ctx, struct state_key *key ) key->unit[i].OptRGB[j].Source = translate_source(comb->SourceRGB[j]); key->unit[i].OptA[j].Source = translate_source(comb->SourceA[j]); } - - if (key->unit[i].ModeRGB == MODE_BUMP_ENVMAP_ATI) { - /* requires some special translation */ - key->unit[i].NumArgsRGB = 2; - key->unit[i].ScaleShiftRGB = 0; - key->unit[i].OptRGB[0].Operand = OPR_SRC_COLOR; - key->unit[i].OptRGB[0].Source = SRC_TEXTURE; - key->unit[i].OptRGB[1].Operand = OPR_SRC_COLOR; - key->unit[i].OptRGB[1].Source = texUnit->BumpTarget - GL_TEXTURE0 + SRC_TEXTURE0; - } } /* _NEW_LIGHT | _NEW_FOG */ @@ -545,7 +519,8 @@ get_current_attrib(texenv_fragment_program *p, GLuint attrib) ir_rvalue *val; current = p->shader->symbols->get_variable("gl_CurrentAttribFragMESA"); - current->max_array_access = MAX2(current->max_array_access, attrib); + assert(current); + current->data.max_array_access = MAX2(current->data.max_array_access, attrib); val = new(p->mem_ctx) ir_dereference_variable(current); ir_rvalue *index = new(p->mem_ctx) ir_constant(attrib); return new(p->mem_ctx) ir_dereference_array(val, index); @@ -589,7 +564,7 @@ get_source(texenv_fragment_program *p, var = p->shader->symbols->get_variable("gl_TextureEnvColor"); assert(var); deref = new(p->mem_ctx) ir_dereference_variable(var); - var->max_array_access = MAX2(var->max_array_access, unit); + var->data.max_array_access = MAX2(var->data.max_array_access, unit); return new(p->mem_ctx) ir_dereference_array(deref, new(p->mem_ctx) ir_constant(unit)); @@ -765,11 +740,6 @@ emit_combine(texenv_fragment_program *p, case MODE_ADD_PRODUCTS_SIGNED: return add(add(mul(src[0], src[1]), mul(src[2], src[3])), new(p->mem_ctx) ir_constant(-0.5f)); - - case MODE_BUMP_ENVMAP_ATI: - /* special - not handled here */ - assert(0); - return src[0]; default: assert(0); return src[0]; @@ -789,10 +759,6 @@ emit_texenv(texenv_fragment_program *p, GLuint unit) if (!key->unit[unit].enabled) { return get_source(p, SRC_PREVIOUS, 0); } - if (key->unit[unit].ModeRGB == MODE_BUMP_ENVMAP_ATI) { - /* this isn't really a env stage delivering a color and handled elsewhere */ - return get_source(p, SRC_PREVIOUS, 0); - } switch (key->unit[unit].ModeRGB) { case MODE_DOT3_RGB_EXT: @@ -889,14 +855,15 @@ emit_texenv(texenv_fragment_program *p, GLuint unit) shift = new(p->mem_ctx) ir_constant((float)(1 << rgb_shift)); } else { - float const_data[4] = { - float(1 << rgb_shift), - float(1 << rgb_shift), - float(1 << rgb_shift), - float(1 << alpha_shift) - }; - shift = new(p->mem_ctx) ir_constant(glsl_type::vec4_type, - (ir_constant_data *)const_data); + ir_constant_data const_data; + + const_data.f[0] = float(1 << rgb_shift); + const_data.f[1] = float(1 << rgb_shift); + const_data.f[2] = float(1 << rgb_shift); + const_data.f[3] = float(1 << alpha_shift); + + shift = new(p->mem_ctx) ir_constant(glsl_type::vec4_type, + &const_data); } return saturate(mul(deref, shift)); @@ -929,7 +896,7 @@ static void load_texture( texenv_fragment_program *p, GLuint unit ) texcoord = new(p->mem_ctx) ir_dereference_variable(tc_array); ir_rvalue *index = new(p->mem_ctx) ir_constant(unit); texcoord = new(p->mem_ctx) ir_dereference_array(texcoord, index); - tc_array->max_array_access = MAX2(tc_array->max_array_access, unit); + tc_array->data.max_array_access = MAX2(tc_array->data.max_array_access, unit); } if (!p->state->unit[unit].enabled) { @@ -947,54 +914,54 @@ static void load_texture( texenv_fragment_program *p, GLuint unit ) switch (texTarget) { case TEXTURE_1D_INDEX: if (p->state->unit[unit].shadow) - sampler_type = p->shader->symbols->get_type("sampler1DShadow"); + sampler_type = glsl_type::sampler1DShadow_type; else - sampler_type = p->shader->symbols->get_type("sampler1D"); + sampler_type = glsl_type::sampler1D_type; coords = 1; break; case TEXTURE_1D_ARRAY_INDEX: if (p->state->unit[unit].shadow) - sampler_type = p->shader->symbols->get_type("sampler1DArrayShadow"); + sampler_type = glsl_type::sampler1DArrayShadow_type; else - sampler_type = p->shader->symbols->get_type("sampler1DArray"); + sampler_type = glsl_type::sampler1DArray_type; coords = 2; break; case TEXTURE_2D_INDEX: if (p->state->unit[unit].shadow) - sampler_type = p->shader->symbols->get_type("sampler2DShadow"); + sampler_type = glsl_type::sampler2DShadow_type; else - sampler_type = p->shader->symbols->get_type("sampler2D"); + sampler_type = glsl_type::sampler2D_type; coords = 2; break; case TEXTURE_2D_ARRAY_INDEX: if (p->state->unit[unit].shadow) - sampler_type = p->shader->symbols->get_type("sampler2DArrayShadow"); + sampler_type = glsl_type::sampler2DArrayShadow_type; else - sampler_type = p->shader->symbols->get_type("sampler2DArray"); + sampler_type = glsl_type::sampler2DArray_type; coords = 3; break; case TEXTURE_RECT_INDEX: if (p->state->unit[unit].shadow) - sampler_type = p->shader->symbols->get_type("sampler2DRectShadow"); + sampler_type = glsl_type::sampler2DRectShadow_type; else - sampler_type = p->shader->symbols->get_type("sampler2DRect"); + sampler_type = glsl_type::sampler2DRect_type; coords = 2; break; case TEXTURE_3D_INDEX: assert(!p->state->unit[unit].shadow); - sampler_type = p->shader->symbols->get_type("sampler3D"); + sampler_type = glsl_type::sampler3D_type; coords = 3; break; case TEXTURE_CUBE_INDEX: if (p->state->unit[unit].shadow) - sampler_type = p->shader->symbols->get_type("samplerCubeShadow"); + sampler_type = glsl_type::samplerCubeShadow_type; else - sampler_type = p->shader->symbols->get_type("samplerCube"); + sampler_type = glsl_type::samplerCube_type; coords = 3; break; case TEXTURE_EXTERNAL_INDEX: assert(!p->state->unit[unit].shadow); - sampler_type = p->shader->symbols->get_type("samplerExternalOES"); + sampler_type = glsl_type::samplerExternalOES_type; coords = 2; break; } @@ -1085,54 +1052,6 @@ load_texunit_sources( texenv_fragment_program *p, GLuint unit ) return GL_TRUE; } -/** - * Generate instructions for loading bump map textures. - */ -static void -load_texunit_bumpmap( texenv_fragment_program *p, GLuint unit ) -{ - const struct state_key *key = p->state; - GLuint bumpedUnitNr = key->unit[unit].OptRGB[1].Source - SRC_TEXTURE0; - ir_rvalue *bump; - ir_rvalue *texcoord; - ir_variable *rot_mat_0, *rot_mat_1; - - rot_mat_0 = p->shader->symbols->get_variable("gl_BumpRotMatrix0MESA"); - rot_mat_1 = p->shader->symbols->get_variable("gl_BumpRotMatrix1MESA"); - - ir_variable *tc_array = p->shader->symbols->get_variable("gl_TexCoord"); - assert(tc_array); - texcoord = new(p->mem_ctx) ir_dereference_variable(tc_array); - ir_rvalue *index = new(p->mem_ctx) ir_constant(bumpedUnitNr); - texcoord = new(p->mem_ctx) ir_dereference_array(texcoord, index); - tc_array->max_array_access = MAX2(tc_array->max_array_access, unit); - - load_texenv_source( p, unit + SRC_TEXTURE0, unit ); - - /* Apply rot matrix and add coords to be available in next phase. - * dest = Arg1 + (Arg0.xx * rotMat0) + (Arg0.yy * rotMat1) - * note only 2 coords are affected the rest are left unchanged (mul by 0) - */ - ir_rvalue *bump_x, *bump_y; - - texcoord = smear(p, texcoord); - - /* bump_texcoord = texcoord */ - ir_variable *bumped = p->make_temp(texcoord->type, "bump_texcoord"); - p->emit(bumped); - p->emit(assign(bumped, texcoord)); - - /* bump_texcoord.xy += arg0.x * rotmat0 + arg0.y * rotmat1 */ - bump = get_source(p, key->unit[unit].OptRGB[0].Source, unit); - bump_x = mul(swizzle_x(bump), rot_mat_0); - bump_y = mul(swizzle_y(bump->clone(p->mem_ctx, NULL)), rot_mat_1); - - p->emit(assign(bumped, add(swizzle_xy(bumped), add(bump_x, bump_y)), - WRITEMASK_XY)); - - p->texcoord_tex[bumpedUnitNr] = bumped; -} - /** * Applies the fog calculations. * @@ -1159,8 +1078,11 @@ emit_fog_instructions(texenv_fragment_program *p, fragcolor = swizzle_xyz(fog_result); oparams = p->shader->symbols->get_variable("gl_FogParamsOptimizedMESA"); + assert(oparams); fogcoord = p->shader->symbols->get_variable("gl_FogFragCoord"); + assert(fogcoord); params = p->shader->symbols->get_variable("gl_Fog"); + assert(params); f = new(p->mem_ctx) ir_dereference_variable(fogcoord); ir_variable *f_var = p->make_temp(glsl_type::float_type, "fog_factor"); @@ -1220,14 +1142,6 @@ emit_instructions(texenv_fragment_program *p) GLuint unit; if (key->enabled_units) { - /* Zeroth pass - bump map textures first */ - for (unit = 0; unit < key->nr_enabled_units; unit++) { - if (key->unit[unit].enabled && - key->unit[unit].ModeRGB == MODE_BUMP_ENVMAP_ATI) { - load_texunit_bumpmap(p, unit); - } - } - /* First pass - to support texture_env_crossbar, first identify * all referenced texture sources and emit texld instructions * for each: @@ -1292,7 +1206,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key) p.mem_ctx = ralloc_context(NULL); p.shader = ctx->Driver.NewShader(ctx, 0, GL_FRAGMENT_SHADER); 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->symbols = state->symbols; p.top_instructions = p.shader->ir; @@ -1306,7 +1220,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key) * fixed function program in a GLES2 context at all, but that's a * big mess to clean up. */ - p.shader_program->InternalSeparateShader = GL_TRUE; + p.shader_program->SeparateShader = GL_TRUE; state->language_version = 130; state->es_shader = false; @@ -1327,7 +1241,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key) state->symbols->add_function(main_f); ir_function_signature *main_sig = - new(p.mem_ctx) ir_function_signature(p.shader->symbols->get_type("void")); + new(p.mem_ctx) ir_function_signature(glsl_type::void_type); main_sig->is_defined = true; main_f->add_signature(main_sig); @@ -1338,15 +1252,16 @@ create_new_program(struct gl_context *ctx, struct state_key *key) validate_ir_tree(p.shader->ir); const struct gl_shader_compiler_options *options = - &ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT]; + &ctx->Const.ShaderCompilerOptions[MESA_SHADER_FRAGMENT]; - while (do_common_optimization(p.shader->ir, false, false, 32, options)) + while (do_common_optimization(p.shader->ir, false, false, options, + ctx->Const.NativeIntegers)) ; reparent_ir(p.shader->ir, p.shader->ir); p.shader->CompileStatus = true; p.shader->Version = state->language_version; - p.shader->num_builtins_to_link = state->num_builtins_to_link; + p.shader->uses_builtin_functions = state->uses_builtin_functions; p.shader_program->Shaders = (gl_shader **)malloc(sizeof(*p.shader_program->Shaders)); p.shader_program->Shaders[0] = p.shader;