X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fffvertex_prog.c;h=43325b13529be1927e211449aa0f542cabb2422e;hb=0491142152dcc61ebe0b46b05c94957e54c44bd9;hp=e6c7c1040faf4c2e32d34975f841ea6374ac1f22;hpb=aa3ab377e6e2e5811cdd704d87c3e24acb5eff72;p=mesa.git diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index e6c7c1040fa..43325b13529 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -26,7 +26,7 @@ **************************************************************************/ /** - * \file ffvertex_prog. + * \file ffvertex_prog.c * * Create a vertex program to execute the current fixed function T&L pipeline. * \author Keith Whitwell @@ -47,25 +47,28 @@ struct state_key { + unsigned light_color_material_mask:12; + unsigned light_material_mask:12; unsigned light_global_enabled:1; unsigned light_local_viewer:1; unsigned light_twoside:1; unsigned light_color_material:1; - unsigned light_color_material_mask:12; - unsigned light_material_mask:12; unsigned material_shininess_is_zero:1; - unsigned need_eye_coords:1; unsigned normalize:1; unsigned rescale_normals:1; + unsigned fog_source_is_depth:1; unsigned tnl_do_vertex_fog:1; unsigned separate_specular:1; unsigned fog_mode:2; unsigned point_attenuated:1; + unsigned point_array:1; unsigned texture_enabled_global:1; unsigned fragprog_inputs_read:12; + unsigned varying_vp_inputs; + struct { unsigned light_enabled:1; unsigned light_eyepos3_is_zero:1; @@ -98,6 +101,7 @@ static GLuint translate_fog_mode( GLenum mode ) } } + #define TXG_NONE 0 #define TXG_OBJ_LINEAR 1 #define TXG_EYE_LINEAR 2 @@ -142,6 +146,7 @@ tnl_get_per_vertex_materials(GLcontext *ctx) return mask; } + /** * Should fog be computed per-vertex? */ @@ -156,6 +161,7 @@ tnl_get_per_vertex_fog(GLcontext *ctx) #endif } + static GLboolean check_active_shininess( GLcontext *ctx, const struct state_key *key, GLuint side ) @@ -173,16 +179,14 @@ static GLboolean check_active_shininess( GLcontext *ctx, return GL_FALSE; } - - -static struct state_key *make_state_key( GLcontext *ctx ) +static void make_state_key( GLcontext *ctx, struct state_key *key ) { const struct gl_fragment_program *fp; - struct state_key *key = CALLOC_STRUCT(state_key); GLuint i; + memset(key, 0, sizeof(struct state_key)); fp = ctx->FragmentProgram._Current; /* This now relies on texenvprogram.c being active: @@ -192,6 +196,7 @@ static struct state_key *make_state_key( GLcontext *ctx ) key->need_eye_coords = ctx->_NeedEyeCoords; key->fragprog_inputs_read = fp->Base.InputsRead; + key->varying_vp_inputs = ctx->varying_vp_inputs; if (ctx->RenderMode == GL_FEEDBACK) { /* make sure the vertprog emits color and tex0 */ @@ -264,12 +269,17 @@ static struct state_key *make_state_key( GLcontext *ctx ) if (ctx->Point._Attenuated) key->point_attenuated = 1; +#if FEATURE_point_size_array + if (ctx->Array.ArrayObj->PointSize.Enabled) + key->point_array = 1; +#endif + if (ctx->Texture._TexGenEnabled || ctx->Texture._TexMatEnabled || ctx->Texture._EnabledUnits) key->texture_enabled_global = 1; - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i]; if (texUnit->_ReallyEnabled) @@ -283,20 +293,18 @@ static struct state_key *make_state_key( GLcontext *ctx ) key->unit[i].texgen_mode0 = translate_texgen( texUnit->TexGenEnabled & (1<<0), - texUnit->GenModeS ); + texUnit->GenS.Mode ); key->unit[i].texgen_mode1 = translate_texgen( texUnit->TexGenEnabled & (1<<1), - texUnit->GenModeT ); + texUnit->GenT.Mode ); key->unit[i].texgen_mode2 = translate_texgen( texUnit->TexGenEnabled & (1<<2), - texUnit->GenModeR ); + texUnit->GenR.Mode ); key->unit[i].texgen_mode3 = translate_texgen( texUnit->TexGenEnabled & (1<<3), - texUnit->GenModeQ ); + texUnit->GenQ.Mode ); } } - - return key; } @@ -307,13 +315,6 @@ static struct state_key *make_state_key( GLcontext *ctx ) */ #define DISASSEM 0 -/* Should be tunable by the driver - do we want to do matrix - * multiplications with DP4's or with MUL/MAD's? SSE works better - * with the latter, drivers may differ. - */ -#define PREFER_DP4 0 - -#define MAX_INSN 256 /* Use uregs to represent registers internally, translate to Mesa's * expected formats on emit. @@ -329,16 +330,19 @@ static struct state_key *make_state_key( GLcontext *ctx ) */ struct ureg { GLuint file:4; - GLint idx:8; /* relative addressing may be negative */ + GLint idx:9; /* relative addressing may be negative */ + /* sizeof(idx) should == sizeof(prog_src_reg::Index) */ GLuint negate:1; GLuint swz:12; - GLuint pad:7; + GLuint pad:6; }; struct tnl_program { const struct state_key *state; struct gl_vertex_program *program; + GLint max_inst; /** number of instructions allocated for program */ + GLboolean mvp_with_dp4; GLuint temp_in_use; GLuint temp_reserved; @@ -354,9 +358,9 @@ struct tnl_program { }; -static const struct ureg undef = { +static const struct ureg undef = { PROGRAM_UNDEFINED, - ~0, + 0, 0, 0, 0 @@ -389,7 +393,7 @@ static struct ureg negate( struct ureg reg ) { reg.negate ^= 1; return reg; -} +} static struct ureg swizzle( struct ureg reg, int x, int y, int z, int w ) @@ -398,15 +402,16 @@ static struct ureg swizzle( struct ureg reg, int x, int y, int z, int w ) GET_SWZ(reg.swz, y), GET_SWZ(reg.swz, z), GET_SWZ(reg.swz, w)); - return reg; } + static struct ureg swizzle1( struct ureg reg, int x ) { return swizzle(reg, x, x, x, x); } + static struct ureg get_temp( struct tnl_program *p ) { int bit = _mesa_ffs( ~p->temp_in_use ); @@ -422,6 +427,7 @@ static struct ureg get_temp( struct tnl_program *p ) return make_ureg(PROGRAM_TEMPORARY, bit-1); } + static struct ureg reserve_temp( struct tnl_program *p ) { struct ureg temp = get_temp( p ); @@ -429,6 +435,7 @@ static struct ureg reserve_temp( struct tnl_program *p ) return temp; } + static void release_temp( struct tnl_program *p, struct ureg reg ) { if (reg.file == PROGRAM_TEMPORARY) { @@ -443,19 +450,59 @@ static void release_temps( struct tnl_program *p ) } +static struct ureg register_param5(struct tnl_program *p, + GLint s0, + GLint s1, + GLint s2, + GLint s3, + GLint s4) +{ + gl_state_index tokens[STATE_LENGTH]; + GLint idx; + tokens[0] = s0; + tokens[1] = s1; + tokens[2] = s2; + tokens[3] = s3; + tokens[4] = s4; + idx = _mesa_add_state_reference( p->program->Base.Parameters, tokens ); + return make_ureg(PROGRAM_STATE_VAR, idx); +} + + +#define register_param1(p,s0) register_param5(p,s0,0,0,0,0) +#define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0) +#define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0) +#define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0) + + +/** + * \param input one of VERT_ATTRIB_x tokens. + */ static struct ureg register_input( struct tnl_program *p, GLuint input ) { - p->program->Base.InputsRead |= (1<= 32 + */ + if (input >= 32 || (p->state->varying_vp_inputs & (1<program->Base.InputsRead |= (1<program->Base.OutputsWritten |= (1<identity)) @@ -493,31 +541,6 @@ static struct ureg get_identity_param( struct tnl_program *p ) return p->identity; } -static struct ureg register_param5(struct tnl_program *p, - GLint s0, - GLint s1, - GLint s2, - GLint s3, - GLint s4) -{ - gl_state_index tokens[STATE_LENGTH]; - GLint idx; - tokens[0] = s0; - tokens[1] = s1; - tokens[2] = s2; - tokens[3] = s3; - tokens[4] = s4; - idx = _mesa_add_state_reference( p->program->Base.Parameters, tokens ); - return make_ureg(PROGRAM_STATE_VAR, idx); -} - - -#define register_param1(p,s0) register_param5(p,s0,0,0,0,0) -#define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0) -#define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0) -#define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0) - - static void register_matrix_param5( struct tnl_program *p, GLint s0, /* modelview, projection, etc */ GLint s1, /* texture matrix number */ @@ -542,12 +565,14 @@ static void emit_arg( struct prog_src_register *src, src->File = reg.file; src->Index = reg.idx; src->Swizzle = reg.swz; - src->NegateBase = reg.negate ? NEGATE_XYZW : 0; + src->Negate = reg.negate ? NEGATE_XYZW : NEGATE_NONE; src->Abs = 0; - src->NegateAbs = 0; src->RelAddr = 0; + /* Check that bitfield sizes aren't exceeded */ + ASSERT(src->Index == reg.idx); } + static void emit_dst( struct prog_dst_register *dst, struct ureg reg, GLuint mask ) { @@ -559,8 +584,11 @@ static void emit_dst( struct prog_dst_register *dst, dst->CondSwizzle = SWIZZLE_NOOP; dst->CondSrc = 0; dst->pad = 0; + /* Check that bitfield sizes aren't exceeded */ + ASSERT(dst->Index == reg.idx); } + static void debug_insn( struct prog_instruction *inst, const char *fn, GLuint line ) { @@ -588,16 +616,38 @@ static void emit_op3fn(struct tnl_program *p, const char *fn, GLuint line) { - GLuint nr = p->program->Base.NumInstructions++; - struct prog_instruction *inst = &p->program->Base.Instructions[nr]; + GLuint nr; + struct prog_instruction *inst; - if (p->program->Base.NumInstructions > MAX_INSN) { - _mesa_problem(0, "Out of instructions in emit_op3fn\n"); - return; + assert((GLint) p->program->Base.NumInstructions <= p->max_inst); + + if (p->program->Base.NumInstructions == p->max_inst) { + /* need to extend the program's instruction array */ + struct prog_instruction *newInst; + + /* double the size */ + p->max_inst *= 2; + + newInst = _mesa_alloc_instructions(p->max_inst); + if (!newInst) { + _mesa_error(NULL, GL_OUT_OF_MEMORY, "vertex program build"); + return; + } + + _mesa_copy_instructions(newInst, + p->program->Base.Instructions, + p->program->Base.NumInstructions); + + _mesa_free_instructions(p->program->Base.Instructions, + p->program->Base.NumInstructions); + + p->program->Base.Instructions = newInst; } + nr = p->program->Base.NumInstructions++; + + inst = &p->program->Base.Instructions[nr]; inst->Opcode = (enum prog_opcode) op; - inst->StringPos = 0; inst->Data = 0; emit_arg( &inst->SrcReg[0], src0 ); @@ -648,6 +698,7 @@ static void emit_matrix_transform_vec4( struct tnl_program *p, emit_op2(p, OPCODE_DP4, dest, WRITEMASK_W, src, mat[3]); } + /* This version is much easier to implement if writemasks are not * supported natively on the target or (like SSE), the target doesn't * have a clean/obvious dotproduct implementation. @@ -673,6 +724,7 @@ static void emit_transpose_matrix_transform_vec4( struct tnl_program *p, release_temp(p, tmp); } + static void emit_matrix_transform_vec3( struct tnl_program *p, struct ureg dest, const struct ureg *mat, @@ -688,13 +740,19 @@ static void emit_normalize_vec3( struct tnl_program *p, struct ureg dest, struct ureg src ) { +#if 0 + /* XXX use this when drivers are ready for NRM3 */ + emit_op1(p, OPCODE_NRM3, dest, WRITEMASK_XYZ, src); +#else struct ureg tmp = get_temp(p); emit_op2(p, OPCODE_DP3, tmp, WRITEMASK_X, src, src); emit_op1(p, OPCODE_RSQ, tmp, WRITEMASK_X, tmp); emit_op2(p, OPCODE_MUL, dest, 0, src, swizzle1(tmp, X)); release_temp(p, tmp); +#endif } + static void emit_passthrough( struct tnl_program *p, GLuint input, GLuint output ) @@ -703,6 +761,7 @@ static void emit_passthrough( struct tnl_program *p, emit_op1(p, OPCODE_MOV, out, 0, register_input(p, input)); } + static struct ureg get_eye_position( struct tnl_program *p ) { if (is_undef(p->eye_position)) { @@ -711,7 +770,7 @@ static struct ureg get_eye_position( struct tnl_program *p ) p->eye_position = reserve_temp(p); - if (PREFER_DP4) { + if (p->mvp_with_dp4) { register_matrix_param5( p, STATE_MODELVIEW_MATRIX, 0, 0, 3, 0, modelview ); @@ -750,7 +809,6 @@ static struct ureg get_eye_position_z( struct tnl_program *p ) } - static struct ureg get_eye_position_normalized( struct tnl_program *p ) { if (is_undef(p->eye_position_normalized)) { @@ -812,14 +870,13 @@ static struct ureg get_transformed_normal( struct tnl_program *p ) } - static void build_hpos( struct tnl_program *p ) { struct ureg pos = register_input( p, VERT_ATTRIB_POS ); struct ureg hpos = register_output( p, VERT_RESULT_HPOS ); struct ureg mvp[4]; - if (PREFER_DP4) { + if (p->mvp_with_dp4) { register_matrix_param5( p, STATE_MVP_MATRIX, 0, 0, 3, 0, mvp ); emit_matrix_transform_vec4( p, hpos, mvp, pos ); @@ -834,11 +891,12 @@ static void build_hpos( struct tnl_program *p ) static GLuint material_attrib( GLuint side, GLuint property ) { - return ((property - STATE_AMBIENT) * 2 + - side); + return (property - STATE_AMBIENT) * 2 + side; } -/* Get a bitmask of which material values vary on a per-vertex basis. + +/** + * Get a bitmask of which material values vary on a per-vertex basis. */ static void set_material_flags( struct tnl_program *p ) { @@ -874,7 +932,9 @@ static struct ureg get_material( struct tnl_program *p, GLuint side, MAT_BIT_FRONT_AMBIENT | \ MAT_BIT_FRONT_DIFFUSE) << (side)) -/* Either return a precalculated constant value or emit code to + +/** + * Either return a precalculated constant value or emit code to * calculate these values dynamically in the case where material calls * are present between begin/end pairs. * @@ -892,7 +952,7 @@ static struct ureg get_scenecolor( struct tnl_program *p, GLuint side ) struct ureg material_ambient = get_material(p, side, STATE_AMBIENT); struct ureg material_diffuse = get_material(p, side, STATE_DIFFUSE); struct ureg tmp = make_temp(p, material_diffuse); - emit_op3(p, OPCODE_MAD, tmp, WRITEMASK_XYZ, lm_ambient, + emit_op3(p, OPCODE_MAD, tmp, WRITEMASK_XYZ, lm_ambient, material_ambient, material_emission); return tmp; } @@ -910,13 +970,14 @@ static struct ureg get_lightprod( struct tnl_program *p, GLuint light, register_param3(p, STATE_LIGHT, light, property); struct ureg material_value = get_material(p, side, property); struct ureg tmp = get_temp(p); - emit_op2(p, OPCODE_MUL, tmp, 0, light_value, material_value); + emit_op2(p, OPCODE_MUL, tmp, 0, light_value, material_value); return tmp; } else return register_param4(p, STATE_LIGHTPROD, light, side, property); } + static struct ureg calculate_light_attenuation( struct tnl_program *p, GLuint i, struct ureg VPpli, @@ -946,7 +1007,6 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p, /* Calculate distance attenuation: */ if (p->state->unit[i].light_attenuated) { - /* 1/d,d,d,1/d */ emit_op1(p, OPCODE_RCP, dist, WRITEMASK_YZ, dist); /* 1,d,d*d,1/d */ @@ -959,7 +1019,8 @@ static struct ureg calculate_light_attenuation( struct tnl_program *p, emit_op1(p, OPCODE_RCP, dist, 0, dist); /* spot-atten * dist-atten */ emit_op2(p, OPCODE_MUL, att, 0, dist, att); - } else { + } + else { /* dist-atten */ emit_op1(p, OPCODE_RCP, att, 0, dist); } @@ -1013,10 +1074,10 @@ static void build_lighting( struct tnl_program *p ) /* * NOTE: - * dot.x = dot(normal, VPpli) - * dot.y = dot(normal, halfAngle) - * dot.z = back.shininess - * dot.w = front.shininess + * dots.x = dot(normal, VPpli) + * dots.y = dot(normal, halfAngle) + * dots.z = back.shininess + * dots.w = front.shininess */ for (i = 0; i < MAX_LIGHTS; i++) @@ -1028,7 +1089,7 @@ static void build_lighting( struct tnl_program *p ) { if (!p->state->material_shininess_is_zero) { struct ureg shininess = get_material(p, 0, STATE_SHININESS); - emit_op1(p, OPCODE_MOV, dots, WRITEMASK_W, swizzle1(shininess,X)); + emit_op1(p, OPCODE_MOV, dots, WRITEMASK_W, swizzle1(shininess,X)); release_temp(p, shininess); } @@ -1037,11 +1098,13 @@ static void build_lighting( struct tnl_program *p ) _col1 = make_temp(p, get_identity_param(p)); else _col1 = _col0; - } if (twoside) { if (!p->state->material_shininess_is_zero) { + /* Note that we negate the back-face specular exponent here. + * The negation will be un-done later in the back-face code below. + */ struct ureg shininess = get_material(p, 1, STATE_SHININESS); emit_op1(p, OPCODE_MOV, dots, WRITEMASK_Z, negate(swizzle1(shininess,X))); @@ -1102,12 +1165,13 @@ static void build_lighting( struct tnl_program *p ) half = get_temp(p); emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat); emit_normalize_vec3(p, half, half); - } else { + } + else { half = register_param3(p, STATE_INTERNAL, STATE_LIGHT_HALF_VECTOR, i); } } - } + } else { struct ureg Ppli = register_param3(p, STATE_INTERNAL, STATE_LIGHT_POSITION, i); @@ -1173,7 +1237,6 @@ static void build_lighting( struct tnl_program *p ) struct ureg res0, res1; GLuint mask0, mask1; - if (count == nr_lights) { if (separate) { mask0 = WRITEMASK_XYZ; @@ -1187,25 +1250,25 @@ static void build_lighting( struct tnl_program *p ) res0 = _col0; res1 = register_output( p, VERT_RESULT_COL0 ); } - } else { + } + else { mask0 = 0; mask1 = 0; res0 = _col0; res1 = _col1; } - if (!is_undef(att)) { /* light is attenuated by distance */ emit_op1(p, OPCODE_LIT, lit, 0, dots); emit_op2(p, OPCODE_MUL, lit, 0, lit, att); emit_op3(p, OPCODE_MAD, _col0, 0, swizzle1(lit,X), ambient, _col0); - } + } else if (!p->state->material_shininess_is_zero) { /* there's a non-zero specular term */ emit_op1(p, OPCODE_LIT, lit, 0, dots); emit_op2(p, OPCODE_ADD, _col0, 0, ambient, _col0); - } + } else { /* no attenutation, no specular */ emit_degenerate_lit(p, lit, dots); @@ -1242,13 +1305,19 @@ static void build_lighting( struct tnl_program *p ) res0 = _bfc0; res1 = register_output( p, VERT_RESULT_BFC0 ); } - } else { + } + else { res0 = _bfc0; res1 = _bfc1; mask0 = 0; mask1 = 0; } + /* For the back face we need to negate the X and Y component + * dot products. dots.Z has the negated back-face specular + * exponent. We swizzle that into the W position. This + * negation makes the back-face specular term positive again. + */ dots = negate(swizzle(dots,X,Y,W,Z)); if (!is_undef(att)) { @@ -1258,16 +1327,19 @@ static void build_lighting( struct tnl_program *p ) } else if (!p->state->material_shininess_is_zero) { emit_op1(p, OPCODE_LIT, lit, 0, dots); - emit_op2(p, OPCODE_ADD, _col0, 0, ambient, _col0); - } + emit_op2(p, OPCODE_ADD, _bfc0, 0, ambient, _bfc0); /**/ + } else { emit_degenerate_lit(p, lit, dots); - emit_op2(p, OPCODE_ADD, _col0, 0, ambient, _col0); + emit_op2(p, OPCODE_ADD, _bfc0, 0, ambient, _bfc0); } - emit_op2(p, OPCODE_ADD, _bfc0, 0, ambient, _bfc0); emit_op3(p, OPCODE_MAD, res0, mask0, swizzle1(lit,Y), diffuse, _bfc0); emit_op3(p, OPCODE_MAD, res1, mask1, swizzle1(lit,Z), specular, _bfc1); + /* restore dots to its original state for subsequent lights + * by negating and swizzling again. + */ + dots = negate(swizzle(dots,X,Y,W,Z)); release_temp(p, ambient); release_temp(p, diffuse); @@ -1340,6 +1412,7 @@ static void build_fog( struct tnl_program *p ) emit_op1(p, useabs ? OPCODE_ABS : OPCODE_MOV, fog, WRITEMASK_X, input); } } + static void build_reflect_texgen( struct tnl_program *p, struct ureg dest, @@ -1359,6 +1432,7 @@ static void build_reflect_texgen( struct tnl_program *p, release_temp(p, tmp); } + static void build_sphere_texgen( struct tnl_program *p, struct ureg dest, GLuint writemask ) @@ -1406,7 +1480,7 @@ static void build_texture_transform( struct tnl_program *p ) { GLuint i, j; - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { if (!(p->state->fragprog_inputs_read & FRAG_BIT_TEX(i))) continue; @@ -1469,10 +1543,8 @@ static void build_texture_transform( struct tnl_program *p ) case TXG_NONE: copy_mask |= WRITEMASK_X << j; } - } - if (sphere_mask) { build_sphere_texgen(p, out_texgen, sphere_mask); } @@ -1497,7 +1569,7 @@ static void build_texture_transform( struct tnl_program *p ) struct ureg in = (!is_undef(out_texgen) ? out_texgen : register_input(p, VERT_ATTRIB_TEX0+i)); - if (PREFER_DP4) { + if (p->mvp_with_dp4) { register_matrix_param5( p, STATE_TEXTURE_MATRIX, i, 0, 3, 0, texmat ); emit_matrix_transform_vec4( p, out, texmat, in ); @@ -1510,7 +1582,7 @@ static void build_texture_transform( struct tnl_program *p ) } release_temps(p); - } + } else { emit_passthrough(p, VERT_ATTRIB_TEX0+i, VERT_RESULT_TEX0+i); } @@ -1518,7 +1590,10 @@ static void build_texture_transform( struct tnl_program *p ) } -static void build_pointsize( struct tnl_program *p ) +/** + * Point size attenuation computation. + */ +static void build_atten_pointsize( struct tnl_program *p ) { struct ureg eye = get_eye_position_z(p); struct ureg state_size = register_param1(p, STATE_POINT_SIZE); @@ -1552,18 +1627,32 @@ static void build_pointsize( struct tnl_program *p ) release_temp(p, ut); } + /** * Emit constant point size. */ -static void constant_pointsize( struct tnl_program *p ) +static void build_constant_pointsize( struct tnl_program *p ) { struct ureg state_size = register_param1(p, STATE_POINT_SIZE); struct ureg out = register_output(p, VERT_RESULT_PSIZ); emit_op1(p, OPCODE_MOV, out, WRITEMASK_X, state_size); } + +/** + * Pass-though per-vertex point size, from user's point size array. + */ +static void build_array_pointsize( struct tnl_program *p ) +{ + struct ureg in = register_input(p, VERT_ATTRIB_POINT_SIZE); + struct ureg out = register_output(p, VERT_RESULT_PSIZ); + emit_op1(p, OPCODE_MOV, out, WRITEMASK_X, in); +} + + static void build_tnl_program( struct tnl_program *p ) -{ /* Emit the program, starting with modelviewproject: +{ + /* Emit the program, starting with modelviewproject: */ build_hpos(p); @@ -1589,10 +1678,14 @@ static void build_tnl_program( struct tnl_program *p ) build_texture_transform(p); if (p->state->point_attenuated) - build_pointsize(p); + build_atten_pointsize(p); + else if (p->state->point_array) + build_array_pointsize(p); #if 0 else - constant_pointsize(p); + build_constant_pointsize(p); +#else + (void) build_constant_pointsize; #endif /* Finish up: @@ -1610,6 +1703,7 @@ static void build_tnl_program( struct tnl_program *p ) static void create_new_program( const struct state_key *key, struct gl_vertex_program *program, + GLboolean mvp_with_dp4, GLuint max_temps) { struct tnl_program p; @@ -1623,13 +1717,18 @@ create_new_program( const struct state_key *key, p.transformed_normal = undef; p.identity = undef; p.temp_in_use = 0; + p.mvp_with_dp4 = mvp_with_dp4; if (max_temps >= sizeof(int) * 8) p.temp_reserved = 0; else p.temp_reserved = ~((1<Base.Instructions = _mesa_alloc_instructions(MAX_INSN); + /* Start by allocating 32 instructions. + * If we need more, we'll grow the instruction array as needed. + */ + p.max_inst = 32; + p.program->Base.Instructions = _mesa_alloc_instructions(p.max_inst); p.program->Base.String = NULL; p.program->Base.NumInstructions = p.program->Base.NumTemporaries = @@ -1652,16 +1751,16 @@ struct gl_vertex_program * _mesa_get_fixed_func_vertex_program(GLcontext *ctx) { struct gl_vertex_program *prog; - struct state_key *key; + struct state_key key; /* Grab all the relevent state and put it in a single structure: */ - key = make_state_key(ctx); + make_state_key(ctx, &key); /* Look for an already-prepared program for this state: */ prog = (struct gl_vertex_program *) - _mesa_search_program_cache(ctx->VertexProgram.Cache, key, sizeof(*key)); + _mesa_search_program_cache(ctx->VertexProgram.Cache, &key, sizeof(key)); if (!prog) { /* OK, we'll have to build a new one */ @@ -1673,7 +1772,8 @@ _mesa_get_fixed_func_vertex_program(GLcontext *ctx) if (!prog) return NULL; - create_new_program( key, prog, + create_new_program( &key, prog, + ctx->mvp_with_dp4, ctx->Const.VertexProgram.MaxTemps ); #if 0 @@ -1682,10 +1782,8 @@ _mesa_get_fixed_func_vertex_program(GLcontext *ctx) &prog->Base ); #endif _mesa_program_cache_insert(ctx, ctx->VertexProgram.Cache, - key, sizeof(*key), &prog->Base); + &key, sizeof(key), &prog->Base); } - _mesa_free(key); - return prog; }