/* libs/pixelflinger/codeflinger/x86/texturing.cpp ** ** Copyright 2006, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ #include #include #include #include #include #include #include "codeflinger/x86/GGLX86Assembler.h" namespace android { // --------------------------------------------------------------------------- // iterators are initialized like this: // (intToFixedCenter(x) * dx)>>16 + x0 // ((x<<16 + 0x8000) * dx)>>16 + x0 // ((x<<16)*dx + (0x8000*dx))>>16 + x0 // ( (x*dx) + dx>>1 ) + x0 // (x*dx) + (dx>>1 + x0) void GGLX86Assembler::init_iterated_color(fragment_parts_t& parts, const reg_t& x) { context_t const* c = mBuilderContext.c; const needs_t& needs = mBuilderContext.needs; int temp_reg; if (mSmooth) { // NOTE: we could take this case in the mDithering + !mSmooth case, // but this would use up to 4 more registers for the color components // for only a little added quality. // Currently, this causes the system to run out of registers in // some case (see issue #719496) comment("compute initial iterated color (smooth and/or dither case)"); parts.iterated_packed = 0; parts.packed = 0; // 0x1: color component // 0x2: iterators //parts.reload = 3; const int optReload = mOptLevel >> 1; if (optReload >= 3) parts.reload = 0; // reload nothing else if (optReload == 2) parts.reload = 2; // reload iterators else if (optReload == 1) parts.reload = 1; // reload colors else if (optReload <= 0) parts.reload = 3; // reload both if (!mSmooth) { // we're not smoothing (just dithering), we never have to // reload the iterators parts.reload &= ~2; } Scratch scratches(registerFile()); const int t0 = (parts.reload & 1) ? scratches.obtain() : 0; const int t1 = (parts.reload & 2) ? scratches.obtain() : 0; for (int i=0 ; i<4 ; i++) { if (!mInfo[i].iterated) continue; // this component exists in the destination and is not replaced // by a texture unit. const int c = (parts.reload & 1) ? t0 : obtainReg(); if (i==0) CONTEXT_LOAD(c, iterators.ydady); if (i==1) CONTEXT_LOAD(c, iterators.ydrdy); if (i==2) CONTEXT_LOAD(c, iterators.ydgdy); if (i==3) CONTEXT_LOAD(c, iterators.ydbdy); parts.argb[i].reg = c; if (mInfo[i].smooth) { parts.argb_dx[i].reg = (parts.reload & 2) ? t1 : obtainReg(); const int dvdx = parts.argb_dx[i].reg; temp_reg = scratches.obtain(); CONTEXT_LOAD(dvdx, generated_vars.argb[i].dx); MOV_REG_TO_REG(dvdx, temp_reg); IMUL(x.reg, temp_reg); ADD_REG_TO_REG(temp_reg, c); scratches.recycle(temp_reg); // adjust the color iterator to make sure it won't overflow if (!mAA) { // this is not needed when we're using anti-aliasing // because we will (have to) clamp the components // anyway. int end = scratches.obtain(); MOV_MEM_TO_REG(parts.count.offset_ebp, PhysicalReg_EBP, end); SHR(16, end); IMUL(end, dvdx); temp_reg = end; // c - (dvdx*end + c) = -(dvdx*end) MOV_REG_TO_REG(dvdx, temp_reg); NEG(temp_reg); ADD_REG_TO_REG(c, dvdx); CMOV_REG_TO_REG(Mnemonic_CMOVS, temp_reg, c); /* SUB_REG_TO_REG(dvdx, temp_reg); switch(i) { case 0: JCC(Mnemonic_JNS, "1f_init_iterated_color"); SUB_REG_TO_REG(dvdx, c); label("1f_init_iterated_color"); break; case 1: JCC(Mnemonic_JNS, "2f_init_iterated_color"); SUB_REG_TO_REG(dvdx, c); label("2f_init_iterated_color"); break; case 2: JCC(Mnemonic_JNS, "3f_init_iterated_color"); SUB_REG_TO_REG(dvdx, c); label("3f_init_iterated_color"); break; case 3: JCC(Mnemonic_JNS, "4f_init_iterated_color"); SUB_REG_TO_REG(dvdx, c); label("4f_init_iterated_color"); break; } */ MOV_REG_TO_REG(c, temp_reg); SAR(31, temp_reg); NOT(temp_reg); AND_REG_TO_REG(temp_reg, c); scratches.recycle(end); } if(parts.reload & 2) scratches.recycle(dvdx); else recycleReg(dvdx); } CONTEXT_STORE(c, generated_vars.argb[i].c); if(parts.reload & 1) scratches.recycle(parts.argb[i].reg); else recycleReg(parts.argb[i].reg); parts.argb[i].reg = -1; //if (parts.reload & 1) { // //MOV_MEM_TO_REG(8, PhysicalReg_EBP, mBuilderContext.Rctx); //} } } else { // We're not smoothed, so we can // just use a packed version of the color and extract the // components as needed (or not at all if we don't blend) // figure out if we need the iterated color int load = 0; for (int i=0 ; i<4 ; i++) { component_info_t& info = mInfo[i]; if ((info.inDest || info.needed) && !info.replaced) load |= 1; } parts.iterated_packed = 1; parts.packed = (!mTextureMachine.mask && !mBlending && !mFog && !mDithering); parts.reload = 0; if (load || parts.packed) { if (mBlending || mDithering || mInfo[GGLFormat::ALPHA].needed) { comment("load initial iterated color (8888 packed)"); parts.iterated.setTo(obtainReg(), &(c->formats[GGL_PIXEL_FORMAT_RGBA_8888])); CONTEXT_LOAD(parts.iterated.reg, packed8888); } else { comment("load initial iterated color (dest format packed)"); parts.iterated.setTo(obtainReg(), &mCbFormat); // pre-mask the iterated color const int bits = parts.iterated.size(); const uint32_t size = ((bits>=32) ? 0 : (1LU << bits)) - 1; uint32_t mask = 0; if (mMasking) { for (int i=0 ; i<4 ; i++) { const int component_mask = 1<=0 ; i--) { texture_unit_t& tmu = mTextureMachine.tmu[i]; if (replaced == 0xF) { // all components are replaced, skip this TMU. tmu.format_idx = 0; tmu.mask = 0; tmu.replaced = replaced; continue; } tmu.format_idx = GGL_READ_NEEDS(T_FORMAT, needs.t[i]); tmu.format = c->formats[tmu.format_idx]; tmu.bits = tmu.format.size*8; tmu.swrap = GGL_READ_NEEDS(T_S_WRAP, needs.t[i]); tmu.twrap = GGL_READ_NEEDS(T_T_WRAP, needs.t[i]); tmu.env = ggl_needs_to_env(GGL_READ_NEEDS(T_ENV, needs.t[i])); tmu.pot = GGL_READ_NEEDS(T_POT, needs.t[i]); tmu.linear = GGL_READ_NEEDS(T_LINEAR, needs.t[i]) && tmu.format.size!=3; // XXX: only 8, 16 and 32 modes for now // 5551 linear filtering is not supported if (tmu.format_idx == GGL_PIXEL_FORMAT_RGBA_5551) tmu.linear = 0; tmu.mask = 0; tmu.replaced = replaced; if (tmu.format_idx) { mTextureMachine.activeUnits++; if (tmu.format.c[0].h) tmu.mask |= 0x1; if (tmu.format.c[1].h) tmu.mask |= 0x2; if (tmu.format.c[2].h) tmu.mask |= 0x4; if (tmu.format.c[3].h) tmu.mask |= 0x8; if (tmu.env == GGL_REPLACE) { replaced |= tmu.mask; } else if (tmu.env == GGL_DECAL) { if (!tmu.format.c[GGLFormat::ALPHA].h) { // if we don't have alpha, decal does nothing tmu.mask = 0; } else { // decal always ignores At tmu.mask &= ~(1< 1; for (int i=0 ; i>16 // Ry = Ry + ti.iterators.ydtdy>>16 // Rx = Ry * ti.stide + Rx // merge base & offset CONTEXT_LOAD(txPtr.reg, generated_vars.texture[i].stride); IMUL(Ry, txPtr.reg); ADD_REG_TO_REG(txPtr.reg, Rx); CONTEXT_LOAD(txPtr.reg, generated_vars.texture[i].data); temp_reg_t.setTo(Rx); base_offset(txPtr, txPtr, temp_reg_t); //PUSH(txPtr.reg); mCurSp = mCurSp - 4; txPtr.offset_ebp = mCurSp; //ebx, esi, edi, parts.count.reg, parts.cbPtr.reg, parts.z.reg MOV_REG_TO_MEM(txPtr.reg, txPtr.offset_ebp, EBP); recycleReg(txPtr.reg); txPtr.reg=-1; } else { Scratch scratches(registerFile()); reg_t& s = coords[i].s; reg_t& t = coords[i].t; // s = (x * dsdx)>>16 + ydsdy // s = (x * dsdx)>>16 + (y*dsdy)>>16 + s0 // t = (x * dtdx)>>16 + ydtdy // t = (x * dtdx)>>16 + (y*dtdy)>>16 + t0 const int need_w = GGL_READ_NEEDS(W, needs.n); MOV_MEM_TO_REG(8, PhysicalReg_EBP, mBuilderContext.Rctx); if (need_w) { s.setTo(obtainReg()); t.setTo(obtainReg()); CONTEXT_LOAD(s.reg, state.texture[i].iterators.ydsdy); CONTEXT_LOAD(t.reg, state.texture[i].iterators.ydtdy); CONTEXT_STORE(s.reg, generated_vars.texture[i].spill[0]); CONTEXT_STORE(t.reg, generated_vars.texture[i].spill[1]); recycleReg(s.reg); recycleReg(t.reg); } else { int ydsdy = scratches.obtain(); int dsdx = scratches.obtain(); CONTEXT_LOAD(ydsdy, state.texture[i].iterators.ydsdy); CONTEXT_LOAD(dsdx, generated_vars.texture[i].dsdx); IMUL(Rx, dsdx); ADD_REG_TO_REG(dsdx, ydsdy); CONTEXT_STORE(ydsdy, generated_vars.texture[i].spill[0]); scratches.recycle(ydsdy); scratches.recycle(dsdx); int ydtdy = scratches.obtain(); int dtdx = scratches.obtain(); CONTEXT_LOAD(ydtdy, state.texture[i].iterators.ydtdy); CONTEXT_LOAD(dtdx, generated_vars.texture[i].dtdx); IMUL(Rx, dtdx); ADD_REG_TO_REG(dtdx, ydtdy); CONTEXT_STORE(ydtdy, generated_vars.texture[i].spill[1]); scratches.recycle(ydtdy); scratches.recycle(dtdx); // s.reg = Rx * ti.dsdx + ydsdy // t.reg = Rx * ti.dtdx + ydtdy } } // direct texture? if (!multiTexture && !mBlending && !mDithering && !mFog && cb_format_idx == tmu.format_idx && !tmu.linear && mTextureMachine.replaced == tmu.mask) { mTextureMachine.directTexture = i + 1; } } } void GGLX86Assembler::build_textures( fragment_parts_t& parts, Scratch& regs) { context_t const* c = mBuilderContext.c; const needs_t& needs = mBuilderContext.needs; reg_t temp_reg_t; //int Rctx = mBuilderContext.Rctx; const bool multiTexture = mTextureMachine.activeUnits > 1; for (int i=0 ; i>4) >= width) // u = width<<4 // width = 0 // else // width = 1<>4; // get integer part // if (u<0) // u = 0 // width = 0 // generated_vars.rt = width MOV_REG_TO_REG(width, temp2); SHL(FRAC_BITS, temp2); MOV_REG_TO_REG(u, temp1); SAR(FRAC_BITS, temp1); CMP_REG_TO_REG(temp1, width); CMOV_REG_TO_REG(Mnemonic_CMOVLE, temp2, u); // mov doesn't affect the flags MOV_IMM_TO_REG(0, temp2); CMOV_REG_TO_REG(Mnemonic_CMOVLE, temp2, width); MOV_IMM_TO_REG(1 << shift, temp2); CMOV_REG_TO_REG(Mnemonic_CMOVG, temp2, width); MOV_IMM_TO_REG(0, temp2); SAR(FRAC_BITS, u); CMOV_REG_TO_REG(Mnemonic_CMOVS, temp2, u); CMOV_REG_TO_REG(Mnemonic_CMOVS, temp2, width); } scratches.recycle(temp1); scratches.recycle(temp2); mBuilderContext.Rctx = scratches.obtain(); MOV_MEM_TO_REG(8, PhysicalReg_EBP, mBuilderContext.Rctx); CONTEXT_STORE(width, generated_vars.rt); const int stride = width; CONTEXT_LOAD(stride, generated_vars.texture[i].stride); scratches.recycle(mBuilderContext.Rctx); temp1 = scratches.obtain(); temp2 = scratches.obtain(); int height_offset_ebp; if (tmu.twrap == GGL_NEEDS_WRAP_REPEAT) { // v has already been REPEATed SAR(FRAC_BITS, v); CMOV_REG_TO_REG(Mnemonic_CMOVS, height, v); MOV_IMM_TO_REG(1< 1; for (int i=0 ; i>3, txPtr.offset_ebp, EBP); } else { Scratch scratches(registerFile()); int s = parts.coords[i].s.reg; int t = parts.coords[i].t.reg; mBuilderContext.Rctx = scratches.obtain(); MOV_MEM_TO_REG(8, PhysicalReg_EBP, mBuilderContext.Rctx); s = scratches.obtain(); int dsdx = scratches.obtain(); CONTEXT_LOAD(s, generated_vars.texture[i].spill[0]); CONTEXT_LOAD(dsdx, generated_vars.texture[i].dsdx); ADD_REG_TO_REG(dsdx, s); CONTEXT_STORE(s, generated_vars.texture[i].spill[0]); scratches.recycle(s); scratches.recycle(dsdx); int dtdx = scratches.obtain(); t = scratches.obtain(); CONTEXT_LOAD(t, generated_vars.texture[i].spill[1]); CONTEXT_LOAD(dtdx, generated_vars.texture[i].dtdx); ADD_REG_TO_REG(dtdx, t); CONTEXT_STORE(t, generated_vars.texture[i].spill[1]); scratches.recycle(t); scratches.recycle(dtdx); } } } void GGLX86Assembler::filter8( const fragment_parts_t& parts, pixel_t& texel, const texture_unit_t& tmu, reg_t reg_U, reg_t reg_V, pointer_t& txPtr, int FRAC_BITS, Scratch& scratches) { if (tmu.format.components != GGL_ALPHA && tmu.format.components != GGL_LUMINANCE) { // this is a packed format, and we don't support // linear filtering (it's probably RGB 332) // Should not happen with OpenGL|ES MOVZX_MEM_TO_REG(OpndSize_8, txPtr.reg, 0, texel.reg); MOV_REG_TO_MEM(texel.reg, texel.offset_ebp, EBP); scratches.recycle(texel.reg); scratches.recycle(txPtr.reg); return; } // ------------------------ //int d = scratches.obtain(); //int u = scratches.obtain(); //int k = scratches.obtain(); scratches.recycle(texel.reg); int rt = scratches.obtain(); int lb = scratches.obtain(); // RB -> U * V mBuilderContext.Rctx = scratches.obtain(); MOV_MEM_TO_REG(8, EBP, mBuilderContext.Rctx); CONTEXT_LOAD(rt, generated_vars.rt); CONTEXT_LOAD(lb, generated_vars.lb); scratches.recycle(mBuilderContext.Rctx); int pixel= scratches.obtain(); int offset = pixel; MOV_REG_TO_REG(rt, offset); ADD_REG_TO_REG(lb, offset); int temp_reg1 = scratches.obtain(); int temp_reg2 = scratches.obtain(); // it seems that the address mode with base and scale reg cannot be encoded correctly //MOV_MEM_SCALE_TO_REG(txPtr.reg, offset, 1, temp_reg1, OpndSize_8); ADD_REG_TO_REG(txPtr.reg, offset); MOVZX_MEM_TO_REG(OpndSize_8, offset, 0, temp_reg1); // pixel is only 8-bits MOV_REG_TO_REG(temp_reg1, pixel); MOVSX_MEM_TO_REG(OpndSize_16, EBP, reg_U.offset_ebp, temp_reg1); MOVSX_MEM_TO_REG(OpndSize_16, EBP, reg_V.offset_ebp, temp_reg2); IMUL(temp_reg2, temp_reg1); MOVSX_REG_TO_REG(OpndSize_16, pixel, pixel); MOVSX_REG_TO_REG(OpndSize_16, temp_reg1, temp_reg2); IMUL(temp_reg2, pixel); NEG(temp_reg1); ADD_IMM_TO_REG(1<<(FRAC_BITS*2), temp_reg1); mCurSp = mCurSp - 4; int d_offset_ebp = mCurSp; MOV_REG_TO_MEM(pixel, d_offset_ebp, EBP); mCurSp = mCurSp - 4; int k_offset_ebp = mCurSp; MOV_REG_TO_MEM(temp_reg1, k_offset_ebp, EBP); // LB -> (1-U) * V MOV_MEM_TO_REG(reg_U.offset_ebp, EBP, temp_reg2); NEG(temp_reg2); ADD_IMM_TO_REG(1< (1-U)*(1-V) MOV_MEM_TO_REG(reg_V.offset_ebp, EBP, temp_reg2); NEG(temp_reg2); ADD_IMM_TO_REG(1< U*(1-V) //MOV_MEM_SCALE_TO_REG(txPtr.reg, rt, 1, pixel, OpndSize_8); ADD_REG_TO_REG(txPtr.reg, rt); MOVZX_MEM_TO_REG(OpndSize_8, rt, 0, pixel); int k = rt; MOV_MEM_TO_REG(k_offset_ebp, EBP, k); SUB_REG_TO_REG(temp_reg2, k); MOVSX_REG_TO_REG(OpndSize_16, pixel, pixel); MOVSX_REG_TO_REG(OpndSize_16, k, k); IMUL(pixel, k); ADD_MEM_TO_REG(EBP, d_offset_ebp, k); MOV_REG_TO_MEM(k, texel.offset_ebp, EBP); scratches.recycle(rt); scratches.recycle(lb); scratches.recycle(pixel); scratches.recycle(txPtr.reg); scratches.recycle(temp_reg1); scratches.recycle(temp_reg2); for (int i=0 ; i<4 ; i++) { if (!texel.format.c[i].h) continue; texel.format.c[i].h = FRAC_BITS*2+8; texel.format.c[i].l = FRAC_BITS*2; // keeping 8 bits in enough } texel.format.size = 4; texel.format.bitsPerPixel = 32; texel.flags |= CLEAR_LO; } void GGLX86Assembler::filter16( const fragment_parts_t& parts, pixel_t& texel, const texture_unit_t& tmu, reg_t reg_U, reg_t reg_V, pointer_t& txPtr, int FRAC_BITS, Scratch& scratches) { // compute the mask // XXX: it would be nice if the mask below could be computed // automatically. uint32_t mask = 0; int shift = 0; int prec = 0; switch (tmu.format_idx) { case GGL_PIXEL_FORMAT_RGB_565: // source: 00000ggg.ggg00000 | rrrrr000.000bbbbb // result: gggggggg.gggrrrrr | rrrrr0bb.bbbbbbbb mask = 0x07E0F81F; shift = 16; prec = 5; break; case GGL_PIXEL_FORMAT_RGBA_4444: // 0000,1111,0000,1111 | 0000,1111,0000,1111 mask = 0x0F0F0F0F; shift = 12; prec = 4; break; case GGL_PIXEL_FORMAT_LA_88: // 0000,0000,1111,1111 | 0000,0000,1111,1111 // AALL -> 00AA | 00LL mask = 0x00FF00FF; shift = 8; prec = 8; break; default: // unsupported format, do something sensical... ALOGE("Unsupported 16-bits texture format (%d)", tmu.format_idx); MOVZX_MEM_TO_REG(OpndSize_16, txPtr.reg, 0, texel.reg); MOV_REG_TO_MEM(texel.reg, texel.offset_ebp, EBP); scratches.recycle(texel.reg); scratches.recycle(txPtr.reg); return; } const int adjust = FRAC_BITS*2 - prec; const int round = 0; // update the texel format texel.format.size = 4; texel.format.bitsPerPixel = 32; texel.flags |= CLEAR_HI|CLEAR_LO; for (int i=0 ; i<4 ; i++) { if (!texel.format.c[i].h) continue; const uint32_t offset = (mask & tmu.format.mask(i)) ? 0 : shift; texel.format.c[i].h = tmu.format.c[i].h + offset + prec; texel.format.c[i].l = texel.format.c[i].h - (tmu.format.bits(i) + prec); } // ------------------------ scratches.recycle(texel.reg); int pixel= scratches.obtain(); int u = scratches.obtain(); int temp_reg1 = scratches.obtain(); // RB -> U * V //printf("RB -> U * V \n"); int offset = pixel; mBuilderContext.Rctx = scratches.obtain(); MOV_MEM_TO_REG(8, EBP, mBuilderContext.Rctx); CONTEXT_LOAD(offset, generated_vars.rt); CONTEXT_LOAD(u, generated_vars.lb); ADD_REG_TO_REG(u, offset); //MOV_MEM_SCALE_TO_REG(txPtr.reg, offset, 1, temp_reg1, OpndSize_16); ADD_REG_TO_REG(txPtr.reg, offset); MOVZX_MEM_TO_REG(OpndSize_16, offset, 0, temp_reg1); MOV_REG_TO_REG(temp_reg1, pixel); MOVSX_MEM_TO_REG(OpndSize_16, EBP, reg_U.offset_ebp, u); MOVSX_MEM_TO_REG(OpndSize_16, EBP, reg_V.offset_ebp, temp_reg1); IMUL(temp_reg1, u); MOV_REG_TO_REG(pixel, temp_reg1); SHL(shift, temp_reg1); OR_REG_TO_REG(temp_reg1, pixel); build_and_immediate(pixel, pixel, mask, 32); if (adjust) { if (round) ADD_IMM_TO_REG(1<<(adjust-1), u); SHR(adjust, u); } int d = scratches.obtain(); MOV_REG_TO_REG(u, d); IMUL(pixel, d); NEG(u); ADD_IMM_TO_REG(1< (1-U) * V //printf("LB -> (1- U) * V \n"); MOV_MEM_TO_REG(reg_U.offset_ebp, EBP, temp_reg1); NEG(temp_reg1); ADD_IMM_TO_REG(1< (1-U)*(1-V) //printf("LT -> (1- U)*(1-V) \n"); MOVSX_MEM_TO_REG(OpndSize_16, EBP, reg_V.offset_ebp, temp_reg2); NEG(temp_reg2); ADD_IMM_TO_REG(1< U*(1-V) //printf("RT -> U*(1-V) \n"); SUB_REG_TO_REG(temp_reg2, u); mBuilderContext.Rctx = temp_reg2; MOV_MEM_TO_REG(8, EBP, mBuilderContext.Rctx); CONTEXT_LOAD(temp_reg1, generated_vars.rt); //MOV_MEM_SCALE_TO_REG(txPtr.reg, temp_reg1, 1, pixel, OpndSize_16); ADD_REG_TO_REG(txPtr.reg, temp_reg1); MOVZX_MEM_TO_REG(OpndSize_16, temp_reg1, 0, pixel); MOV_REG_TO_REG(pixel, temp_reg1); SHL(shift, temp_reg1); OR_REG_TO_REG(temp_reg1, pixel); build_and_immediate(pixel, pixel, mask, 32); IMUL(u, pixel); ADD_REG_TO_REG(pixel, d); MOV_REG_TO_MEM(d, texel.offset_ebp, EBP); scratches.recycle(d); scratches.recycle(pixel); scratches.recycle(u); scratches.recycle(txPtr.reg); scratches.recycle(temp_reg1); scratches.recycle(temp_reg2); } void GGLX86Assembler::filter24( const fragment_parts_t& parts, pixel_t& texel, const texture_unit_t& tmu, int U, int V, pointer_t& txPtr, int FRAC_BITS) { // not supported yet (currently disabled) load(txPtr, texel, 0); } void GGLX86Assembler::filter32( const fragment_parts_t& parts, pixel_t& texel, const texture_unit_t& tmu, reg_t reg_U, reg_t reg_V, pointer_t& txPtr, int FRAC_BITS, Scratch& scratches) { const int adjust = FRAC_BITS*2 - 8; const int round = 0; // ------------------------ scratches.recycle(texel.reg); int mask = scratches.obtain(); int pixel= scratches.obtain(); int u = scratches.obtain(); //int dh = scratches.obtain(); //int k = scratches.obtain(); //int temp = scratches.obtain(); //int dl = scratches.obtain(); MOV_IMM_TO_REG(0xFF, mask); OR_IMM_TO_REG(0xFF0000, mask); // RB -> U * V int offset = pixel; mBuilderContext.Rctx = scratches.obtain(); MOV_MEM_TO_REG(8, EBP, mBuilderContext.Rctx); CONTEXT_LOAD(offset, generated_vars.rt); CONTEXT_LOAD(u, generated_vars.lb); ADD_REG_TO_REG(u, offset); scratches.recycle(mBuilderContext.Rctx); //MOV_MEM_SCALE_TO_REG(txPtr.reg, offset, 1, u); ADD_REG_TO_REG(txPtr.reg, offset); MOV_MEM_TO_REG(0, offset, u); MOV_REG_TO_REG(u, pixel); int temp_reg1 = scratches.obtain(); MOVSX_MEM_TO_REG(OpndSize_16, EBP, reg_U.offset_ebp, temp_reg1); MOVSX_MEM_TO_REG(OpndSize_16, EBP, reg_V.offset_ebp, u); IMUL(temp_reg1, u); MOV_REG_TO_REG(mask, temp_reg1); AND_REG_TO_REG(pixel, temp_reg1); if (adjust) { if (round) ADD_IMM_TO_REG(1<<(adjust-1), u); SHR(adjust, u); } int temp_reg2 = scratches.obtain(); MOV_REG_TO_REG(temp_reg1, temp_reg2); IMUL(u, temp_reg2); SHR(8, pixel); AND_REG_TO_REG(mask, pixel); IMUL(u, pixel); NEG(u); ADD_IMM_TO_REG(0x100, u); mCurSp = mCurSp - 4; int dh_offset_ebp = mCurSp; MOV_REG_TO_MEM(temp_reg2, dh_offset_ebp, EBP); mCurSp = mCurSp - 4; int dl_offset_ebp = mCurSp; MOV_REG_TO_MEM(pixel, dl_offset_ebp, EBP); // LB -> (1-U) * V mBuilderContext.Rctx = temp_reg2; MOV_MEM_TO_REG(8, EBP, mBuilderContext.Rctx); CONTEXT_LOAD(offset, generated_vars.lb); //MOV_MEM_SCALE_TO_REG(txPtr.reg, offset, 1, temp_reg2); ADD_REG_TO_REG(txPtr.reg, offset); MOV_MEM_TO_REG(0, offset, temp_reg2); MOV_REG_TO_REG(temp_reg2, pixel); MOV_MEM_TO_REG(reg_U.offset_ebp, EBP, temp_reg1); NEG(temp_reg1); ADD_IMM_TO_REG(1< (1-U)*(1-V) MOV_MEM_TO_REG(reg_V.offset_ebp, EBP, temp_reg1); NEG(temp_reg1); ADD_IMM_TO_REG(1< U*(1-V) SUB_REG_TO_REG(temp_reg1, u); mBuilderContext.Rctx = temp_reg2; MOV_MEM_TO_REG(8, EBP, mBuilderContext.Rctx); CONTEXT_LOAD(offset, generated_vars.rt); MOV_MEM_TO_REG(txPtr_offset_ebp, EBP, txPtr.reg); //POP(txPtr.reg); //MOV_MEM_SCALE_TO_REG(txPtr.reg, offset, 1, temp_reg2); ADD_REG_TO_REG(txPtr.reg, offset); MOV_MEM_TO_REG(0, offset, temp_reg2); MOV_REG_TO_REG(temp_reg2, pixel); AND_REG_TO_REG(mask, temp_reg2); IMUL(u, temp_reg2); ADD_REG_TO_MEM(temp_reg2, EBP, dh_offset_ebp); SHR(8, pixel); AND_REG_TO_REG(mask, pixel); IMUL(u, pixel); ADD_REG_TO_MEM(pixel, EBP, dl_offset_ebp); MOV_MEM_TO_REG(dh_offset_ebp, EBP, temp_reg1); MOV_MEM_TO_REG(dl_offset_ebp, EBP, temp_reg2); SHR(8, temp_reg1); AND_REG_TO_REG(mask, temp_reg1); SHL(8, mask); AND_REG_TO_REG(mask, temp_reg2); OR_REG_TO_REG(temp_reg1, temp_reg2); MOV_REG_TO_MEM(temp_reg2, texel.offset_ebp, EBP); scratches.recycle(u); scratches.recycle(mask); scratches.recycle(pixel); scratches.recycle(txPtr.reg); scratches.recycle(temp_reg1); scratches.recycle(temp_reg2); } void GGLX86Assembler::build_texture_environment( component_t& fragment, fragment_parts_t& parts, int component, Scratch& regs) { const uint32_t component_mask = 1< 1; Scratch scratches(registerFile()); for (int i=0 ; i 32) { // we will overflow, reduce the precision of Ni to 8 bits // (Note Nt cannot be more than 10 bits which happens with // 565 textures and GGL_LINEAR) shift += Ni-8; Ni = 8; } // modulate by the component with the lowest precision if (Nt >= Ni) { if (shift) { // XXX: we should be able to avoid this shift // when shift==16 && Nt<16 && Ni<16, in which // we could use SMULBT below. MOV_REG_TO_REG(inReg, dest.reg); SHR(shift, inReg); inReg = dest.reg; shift = 0; } int temp_reg = locals.obtain(); // operation: (Cf*Ct)/((1<>(Ni-1))>>Ni // this operation doesn't change texel's size MOV_REG_TO_REG(inReg, temp_reg); SHR(Ni-1, temp_reg); MOV_REG_TO_REG(inReg, dest.reg); ADD_REG_TO_REG(temp_reg, dest.reg); locals.recycle(temp_reg); if (Nt<16 && Ni<16) { MOVSX_REG_TO_REG(OpndSize_16, texel.reg, texel.reg); MOVSX_REG_TO_REG(OpndSize_16, dest.reg, dest.reg); IMUL(texel.reg, dest.reg); } else IMUL(texel.reg, dest.reg); dest.l = Ni; dest.h = Nt + Ni; } else { if (shift && (shift != 16)) { // if shift==16, we can use 16-bits mul instructions later MOV_REG_TO_REG(inReg, dest.reg); SHR(shift, dest.reg); inReg = dest.reg; shift = 0; } // operation: (Cf*Ct)/((1<>(Nt-1))>>Nt // this operation doesn't change incoming's size Scratch scratches(registerFile()); int temp_reg = locals.obtain(); int t = (texel.flags & CORRUPTIBLE) ? texel.reg : dest.reg; if (t == inReg) t = scratches.obtain(); MOV_REG_TO_REG(texel.reg, temp_reg); SHR(Nt-1, temp_reg); ADD_REG_TO_REG(temp_reg, texel.reg); MOV_REG_TO_REG(texel.reg, t); locals.recycle(temp_reg); MOV_REG_TO_REG(inReg, dest.reg); if (Nt<16 && Ni<16) { if (shift==16) { MOVSX_REG_TO_REG(OpndSize_16, t, t); SHR(16, dest.reg); MOVSX_REG_TO_REG(OpndSize_16, dest.reg, dest.reg); IMUL(t, dest.reg); } else { MOVSX_REG_TO_REG(OpndSize_16, dest.reg, dest.reg); MOVSX_REG_TO_REG(OpndSize_16, t, t); IMUL(t, dest.reg); } } else IMUL(t, dest.reg); dest.l = Nt; dest.h = Nt + Ni; } // low bits are not valid dest.flags |= CLEAR_LO; // no need to keep more than 8 bits/component if (dest.size() > 8) dest.l = dest.h-8; } } void GGLX86Assembler::decal( component_t& dest, const component_t& incoming, const pixel_t& incomingTexel, int component) { // RGBA: // Cv = Cf*(1 - At) + Ct*At = Cf + (Ct - Cf)*At // Av = Af Scratch locals(registerFile()); integer_t texel(locals.obtain(), 32, CORRUPTIBLE); integer_t factor(locals.obtain(), 32, CORRUPTIBLE); extract(texel, incomingTexel, component); extract(factor, incomingTexel, GGLFormat::ALPHA); // no need to keep more than 8-bits for decal int Ni = incoming.size(); int shift = incoming.l; if (Ni > 8) { shift += Ni-8; Ni = 8; } integer_t incomingNorm(incoming.reg, Ni, incoming.flags); if (shift) { SHR(shift, incomingNorm.reg); MOV_REG_TO_REG(incomingNorm.reg, dest.reg); incomingNorm.reg = dest.reg; incomingNorm.flags |= CORRUPTIBLE; } int temp = locals.obtain(); MOV_REG_TO_REG(factor.reg, temp); SHR(factor.s-1, temp); ADD_REG_TO_REG(temp, factor.reg); locals.recycle(temp); build_blendOneMinusFF(dest, factor, incomingNorm, texel); } void GGLX86Assembler::blend( component_t& dest, const component_t& incoming, const pixel_t& incomingTexel, int component, int tmu) { // RGBA: // Cv = (1 - Ct)*Cf + Ct*Cc = Cf + (Cc - Cf)*Ct // Av = At*Af if (component == GGLFormat::ALPHA) { modulate(dest, incoming, incomingTexel, component); return; } Scratch locals(registerFile()); int temp = locals.obtain(); integer_t color(locals.obtain(), 8, CORRUPTIBLE); integer_t factor(locals.obtain(), 32, CORRUPTIBLE); mBuilderContext.Rctx = temp; MOV_MEM_TO_REG(8, PhysicalReg_EBP, mBuilderContext.Rctx); MOVZX_MEM_TO_REG(OpndSize_8, mBuilderContext.Rctx, GGL_OFFSETOF(state.texture[tmu].env_color[component]), color.reg); extract(factor, incomingTexel, component); // no need to keep more than 8-bits for blend int Ni = incoming.size(); int shift = incoming.l; if (Ni > 8) { shift += Ni-8; Ni = 8; } integer_t incomingNorm(incoming.reg, Ni, incoming.flags); if (shift) { MOV_REG_TO_REG(incomingNorm.reg, dest.reg); SHR(shift, dest.reg); incomingNorm.reg = dest.reg; incomingNorm.flags |= CORRUPTIBLE; } MOV_REG_TO_REG(factor.reg, temp); SHR(factor.s-1, temp); ADD_REG_TO_REG(temp, factor.reg); locals.recycle(temp); build_blendOneMinusFF(dest, factor, incomingNorm, color); } void GGLX86Assembler::add( component_t& dest, const component_t& incoming, const pixel_t& incomingTexel, int component) { // RGBA: // Cv = Cf + Ct; Scratch locals(registerFile()); component_t incomingTemp(incoming); // use "dest" as a temporary for extracting the texel, unless "dest" // overlaps "incoming". integer_t texel(dest.reg, 32, CORRUPTIBLE); if (dest.reg == incomingTemp.reg) texel.reg = locals.obtain(); extract(texel, incomingTexel, component); if (texel.s < incomingTemp.size()) { expand(texel, texel, incomingTemp.size()); } else if (texel.s > incomingTemp.size()) { if (incomingTemp.flags & CORRUPTIBLE) { expand(incomingTemp, incomingTemp, texel.s); } else { incomingTemp.reg = locals.obtain(); expand(incomingTemp, incoming, texel.s); } } if (incomingTemp.l) { MOV_REG_TO_REG(incomingTemp.reg, dest.reg); SHR(incomingTemp.l, dest.reg); ADD_REG_TO_REG(texel.reg, dest.reg); } else { MOV_REG_TO_REG(incomingTemp.reg, dest.reg); ADD_REG_TO_REG(texel.reg, dest.reg); } dest.l = 0; dest.h = texel.size(); int temp_reg = locals.obtain(); component_sat(dest, temp_reg); locals.recycle(temp_reg); } // ---------------------------------------------------------------------------- }; // namespace android