X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmesa%2Fmain%2Fff_fragment_shader.cpp;h=c6828925f5e7a9d78a8da98188fe44af095974fe;hb=d01a7cdae576162791813c131027a6e675a4e6c7;hp=00ca0255899963c0f3741ef6448e92dd4d828b0f;hpb=911007820962d78a60c8056f64c0bde1ea724149;p=mesa.git diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp index 00ca0255899..c6828925f5e 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,20 +20,22 @@ * 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. * **************************************************************************/ -extern "C" { #include "glheader.h" #include "imports.h" #include "mtypes.h" #include "main/context.h" #include "main/macros.h" #include "main/samplerobj.h" +#include "main/texenvprogram.h" +#include "main/texobj.h" +#include "main/uniforms.h" #include "program/program.h" #include "program/prog_parameter.h" #include "program/prog_cache.h" @@ -41,9 +43,6 @@ extern "C" { #include "program/prog_print.h" #include "program/prog_statevars.h" #include "program/programopt.h" -#include "texenvprogram.h" -} -#include "main/uniforms.h" #include "../glsl/glsl_types.h" #include "../glsl/ir.h" #include "../glsl/ir_builder.h" @@ -219,7 +218,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 /** @@ -249,7 +247,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; @@ -282,7 +279,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); @@ -290,18 +286,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) /** @@ -317,9 +301,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; @@ -383,7 +367,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; @@ -430,19 +414,19 @@ 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); - format = texObj->Image[0][texObj->BaseLevel]->_BaseFormat; + format = _mesa_texture_base_format(texObj); key->unit[i].enabled = 1; key->enabled_units |= (1<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) && @@ -466,16 +450,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 */ @@ -689,7 +663,7 @@ static GLboolean args_match( const struct state_key *key, GLuint unit ) } static ir_rvalue * -smear(texenv_fragment_program *p, ir_rvalue *val) +smear(ir_rvalue *val) { if (!val->type->is_scalar()) return val; @@ -746,7 +720,7 @@ emit_combine(texenv_fragment_program *p, tmp1 = mul(src[1], new(p->mem_ctx) ir_constant(2.0f)); tmp1 = add(tmp1, new(p->mem_ctx) ir_constant(-1.0f)); - return dot(swizzle_xyz(smear(p, tmp0)), swizzle_xyz(smear(p, tmp1))); + return dot(swizzle_xyz(smear(tmp0)), swizzle_xyz(smear(tmp1))); } case MODE_MODULATE_ADD_ATI: return add(mul(src[0], src[2]), src[1]); @@ -764,11 +738,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]; @@ -788,10 +757,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: @@ -837,7 +802,7 @@ emit_texenv(texenv_fragment_program *p, GLuint unit) key->unit[unit].NumArgsRGB, key->unit[unit].ModeRGB, key->unit[unit].OptRGB); - val = smear(p, val); + val = smear(val); if (rgb_saturate) val = saturate(val); @@ -849,7 +814,7 @@ emit_texenv(texenv_fragment_program *p, GLuint unit) key->unit[unit].NumArgsRGB, key->unit[unit].ModeRGB, key->unit[unit].OptRGB); - val = smear(p, val); + val = smear(val); if (rgb_saturate) val = saturate(val); p->emit(assign(temp_var, val)); @@ -862,7 +827,7 @@ emit_texenv(texenv_fragment_program *p, GLuint unit) key->unit[unit].NumArgsRGB, key->unit[unit].ModeRGB, key->unit[unit].OptRGB); - val = swizzle_xyz(smear(p, val)); + val = swizzle_xyz(smear(val)); if (rgb_saturate) val = saturate(val); p->emit(assign(temp_var, val, WRITEMASK_XYZ)); @@ -871,7 +836,7 @@ emit_texenv(texenv_fragment_program *p, GLuint unit) key->unit[unit].NumArgsA, key->unit[unit].ModeA, key->unit[unit].OptA); - val = swizzle_w(smear(p, val)); + val = swizzle_w(smear(val)); if (alpha_saturate) val = saturate(val); p->emit(assign(temp_var, val, WRITEMASK_W)); @@ -888,14 +853,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)); @@ -946,54 +912,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; } @@ -1084,56 +1050,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"); - assert(rot_mat_0); - rot_mat_1 = p->shader->symbols->get_variable("gl_BumpRotMatrix1MESA"); - assert(rot_mat_1); - - 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->data.max_array_access = MAX2(tc_array->data.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. * @@ -1224,14 +1140,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: @@ -1302,7 +1210,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key) p.top_instructions = p.shader->ir; p.instructions = p.shader->ir; p.state = key; - p.shader_program = ctx->Driver.NewShaderProgram(ctx, 0); + p.shader_program = ctx->Driver.NewShaderProgram(0); /* Tell the linker to ignore the fact that we're building a * separate shader, in case we're in a GLES2 context that would @@ -1310,7 +1218,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; @@ -1331,7 +1239,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); @@ -1342,9 +1250,10 @@ 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);