GLuint i915_emit_texld( struct i915_fragment_program *p, GLuint dest, GLuint destmask, GLuint sampler, GLuint coord, GLuint op ) { if (coord != UREG(GET_UREG_TYPE(coord), GET_UREG_NR(coord))) { /* No real way to work around this in the general case - need to * allocate and declare a new temporary register (a utemp won't * do). Will fallback for now. */ i915_program_error(p, "Can't (yet) swizzle TEX arguments"); return 0; } /* Don't worry about saturate as we only support */ if (destmask != A0_DEST_CHANNEL_ALL) { GLuint tmp = i915_get_utemp(p); i915_emit_texld( p, tmp, A0_DEST_CHANNEL_ALL, sampler, coord, op ); i915_emit_arith( p, A0_MOV, dest, destmask, 0, tmp, 0, 0 ); return dest; } else { assert(GET_UREG_TYPE(dest) != REG_TYPE_CONST); assert(dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest))); if (GET_UREG_TYPE(coord) != REG_TYPE_T) { p->nr_tex_indirect++; } *(p->csr++) = (op | T0_DEST( dest ) | T0_SAMPLER( sampler )); *(p->csr++) = T1_ADDRESS_REG( coord ); *(p->csr++) = T2_MBZ; p->nr_tex_insn++; return dest; } }
static void enable_texture_blend_replace( i915ContextPtr i915 ) { static const GLuint prog[] = { _3DSTATE_PIXEL_SHADER_PROGRAM, /* Declare the sampler: */ (D0_DCL | D0_DECL_REG( REG_S(0) ) | D0_SAMPLE_TYPE_2D | D0_CHANNEL_NONE), D1_MBZ, D2_MBZ, /* Declare the interpolated texture coordinate: */ (D0_DCL | D0_DECL_REG( REG_T_TEX(0) ) | D0_CHANNEL_ALL), D1_MBZ, D2_MBZ, /* output-color = texld(sample0, texcoord0) */ (T0_TEXLD | T0_DEST_REG( REG_OC ) | T0_SAMPLER( 0 )), T1_ADDRESS_REG(REG_TYPE_T, 0), T2_MBZ }; memcpy( i915->meta.Program, prog, sizeof(prog) ); i915->meta.ProgramSize = sizeof(prog) / sizeof(*prog); i915->meta.Program[0] |= i915->meta.ProgramSize - 2; i915->meta.emitted &= ~I915_UPLOAD_PROGRAM; }
GLuint i915_emit_texld( struct i915_fragment_program *p, GLuint live_regs, GLuint dest, GLuint destmask, GLuint sampler, GLuint coord, GLuint op ) { if (coord != UREG(GET_UREG_TYPE(coord), GET_UREG_NR(coord))) { /* With the help of the "needed registers" table created earlier, pick * a register we can MOV the swizzled TC to (since TEX doesn't support * swizzled sources) */ GLuint swizCoord = get_free_rreg(p, live_regs); if (swizCoord == UREG_BAD) return 0; i915_emit_arith( p, A0_MOV, swizCoord, A0_DEST_CHANNEL_ALL, 0, coord, 0, 0 ); coord = swizCoord; } /* Don't worry about saturate as we only support texture formats * that are always in the 0..1 range. */ if (destmask != A0_DEST_CHANNEL_ALL) { GLuint tmp = i915_get_utemp(p); i915_emit_texld( p, 0, tmp, A0_DEST_CHANNEL_ALL, sampler, coord, op ); i915_emit_arith( p, A0_MOV, dest, destmask, 0, tmp, 0, 0 ); return dest; } else { assert(GET_UREG_TYPE(dest) != REG_TYPE_CONST); assert(dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest))); /* Can't use unsaved temps for coords, as the phase boundary would result * in the contents becoming undefined. */ assert(GET_UREG_TYPE(coord) != REG_TYPE_U); if ((GET_UREG_TYPE(coord) != REG_TYPE_R) && (GET_UREG_TYPE(coord) != REG_TYPE_OC) && (GET_UREG_TYPE(coord) != REG_TYPE_OD) && (GET_UREG_TYPE(coord) != REG_TYPE_T)) { GLuint tmpCoord = get_free_rreg(p, live_regs); if (tmpCoord == UREG_BAD) return 0; i915_emit_arith(p, A0_MOV, tmpCoord, A0_DEST_CHANNEL_ALL, 0, coord, 0, 0); coord = tmpCoord; } /* Output register being oC or oD defines a phase boundary */ if (GET_UREG_TYPE(dest) == REG_TYPE_OC || GET_UREG_TYPE(dest) == REG_TYPE_OD) p->nr_tex_indirect++; /* Reading from an r# register whose contents depend on output of the * current phase defines a phase boundary. */ if (GET_UREG_TYPE(coord) == REG_TYPE_R && p->register_phases[GET_UREG_NR(coord)] == p->nr_tex_indirect) p->nr_tex_indirect++; *(p->csr++) = (op | T0_DEST( dest ) | T0_SAMPLER( sampler )); *(p->csr++) = T1_ADDRESS_REG( coord ); *(p->csr++) = T2_MBZ; if (GET_UREG_TYPE(dest) == REG_TYPE_R) p->register_phases[GET_UREG_NR(dest)] = p->nr_tex_indirect; p->nr_tex_insn++; return dest; } }
/** * Emit a texture load or texkill instruction. * \param dest the dest i915 register * \param destmask the dest register writemask * \param sampler the i915 sampler register * \param coord the i915 source texcoord operand * \param opcode the instruction opcode */ uint i915_emit_texld( struct i915_fp_compile *p, uint dest, uint destmask, uint sampler, uint coord, uint opcode, uint num_coord ) { const uint k = UREG(GET_UREG_TYPE(coord), GET_UREG_NR(coord)); int temp = -1; uint ignore = 0; /* Eliminate the useless texture coordinates. Otherwise we end up generating * a swizzle for no reason below. */ switch(num_coord) { case 0: /* Ignore x */ ignore |= (0xf << UREG_CHANNEL_X_SHIFT); case 1: /* Ignore y */ ignore |= (0xf << UREG_CHANNEL_Y_SHIFT); case 2: /* Ignore z */ ignore |= (0xf << UREG_CHANNEL_Z_SHIFT); case 3: /* Ignore w */ ignore |= (0xf << UREG_CHANNEL_W_SHIFT); } if ( (coord &~ignore ) != (k & ~ignore) ) { /* texcoord is swizzled or negated. Need to allocate a new temporary * register (a utemp / unpreserved temp) won't do. */ uint tempReg; temp = i915_get_temp(p); /* get temp reg index */ tempReg = UREG(REG_TYPE_R, temp); /* make i915 register */ i915_emit_arith( p, A0_MOV, tempReg, A0_DEST_CHANNEL_ALL, /* dest reg, writemask */ 0, /* saturate */ coord, 0, 0 ); /* src0, src1, src2 */ /* new src texcoord is tempReg */ coord = tempReg; } /* Don't worry about saturate as we only support */ if (destmask != A0_DEST_CHANNEL_ALL) { /* if not writing to XYZW... */ uint tmp = i915_get_utemp(p); i915_emit_texld( p, tmp, A0_DEST_CHANNEL_ALL, sampler, coord, opcode, num_coord ); i915_emit_arith( p, A0_MOV, dest, destmask, 0, tmp, 0, 0 ); /* XXX release utemp here? */ } else { assert(GET_UREG_TYPE(dest) != REG_TYPE_CONST); assert(dest == UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest))); /* Output register being oC or oD defines a phase boundary */ if (GET_UREG_TYPE(dest) == REG_TYPE_OC || GET_UREG_TYPE(dest) == REG_TYPE_OD) p->nr_tex_indirect++; /* Reading from an r# register whose contents depend on output of the * current phase defines a phase boundary. */ if (GET_UREG_TYPE(coord) == REG_TYPE_R && p->register_phases[GET_UREG_NR(coord)] == p->nr_tex_indirect) p->nr_tex_indirect++; if (p->csr< p->program + I915_PROGRAM_SIZE) { *(p->csr++) = (opcode | T0_DEST( dest ) | T0_SAMPLER( sampler )); *(p->csr++) = T1_ADDRESS_REG( coord ); *(p->csr++) = T2_MBZ; } else i915_program_error(p, "Out of instructions"); if (GET_UREG_TYPE(dest) == REG_TYPE_R) p->register_phases[GET_UREG_NR(dest)] = p->nr_tex_indirect; p->nr_tex_insn++; } if (temp >= 0) i915_release_temp(p, temp); return dest; }