diff options
Diffstat (limited to 'src/devices/video/vooddefs.h')
-rw-r--r-- | src/devices/video/vooddefs.h | 371 |
1 files changed, 185 insertions, 186 deletions
diff --git a/src/devices/video/vooddefs.h b/src/devices/video/vooddefs.h index 99c6f7f4e53..cad79c3d7f2 100644 --- a/src/devices/video/vooddefs.h +++ b/src/devices/video/vooddefs.h @@ -775,10 +775,9 @@ do } \ while (0) -inline bool ATTR_FORCE_INLINE voodoo_device::alphaTest(voodoo_device *vd, stats_block *stats, uint32_t alphaModeReg, uint8_t alpha) +inline bool ATTR_FORCE_INLINE voodoo_device::alphaTest(uint8_t alpharef, stats_block *stats, uint32_t alphaModeReg, uint8_t alpha) { { - uint8_t alpharef = vd->reg[alphaMode].rgb.a; switch (ALPHAMODE_ALPHAFUNCTION(alphaModeReg)) { case 0: /* alphaOP = never */ @@ -1045,20 +1044,20 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA { default: /* reserved */ case 0: /* AZERO */ - srcScale.set(srcAlphaScale, 0, 0, 0); + srcScale.zero(); //(RR) = (GG) = (BB) = 0; break; case 1: /* ASRC_ALPHA */ ta = sa + 1; - srcScale.set(srcAlphaScale, ta, ta, ta); + srcScale.set_all(ta); //(RR) = (sr * (sa + 1)) >> 8; //(GG) = (sg * (sa + 1)) >> 8; //(BB) = (sb * (sa + 1)) >> 8; break; case 2: /* A_COLOR */ - srcScale.set(srcAlphaScale-1, dr, dg, db); + srcScale.set(dr, dr, dg, db); srcScale.add_imm(1); //(RR) = (sr * (dr + 1)) >> 8; //(GG) = (sg * (dg + 1)) >> 8; @@ -1067,26 +1066,26 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA case 3: /* ADST_ALPHA */ ta = da + 1; - srcScale.set(srcAlphaScale, ta, ta, ta); + srcScale.set_all(ta); //(RR) = (sr * (da + 1)) >> 8; //(GG) = (sg * (da + 1)) >> 8; //(BB) = (sb * (da + 1)) >> 8; break; case 4: /* AONE */ - srcScale.set(srcAlphaScale, 256, 256, 256); + srcScale.set_all(256); break; case 5: /* AOMSRC_ALPHA */ ta = (0x100 - sa); - srcScale.set(srcAlphaScale, ta, ta, ta); + srcScale.set_all(ta); //(RR) = (sr * (0x100 - sa)) >> 8; //(GG) = (sg * (0x100 - sa)) >> 8; //(BB) = (sb * (0x100 - sa)) >> 8; break; case 6: /* AOM_COLOR */ - srcScale.set(srcAlphaScale, (0x100 - dr), (0x100 - dg), (0x100 - db)); + srcScale.set((0x100 - dr), (0x100 - dr), (0x100 - dg), (0x100 - db)); //(RR) = (sr * (0x100 - dr)) >> 8; //(GG) = (sg * (0x100 - dg)) >> 8; //(BB) = (sb * (0x100 - db)) >> 8; @@ -1094,7 +1093,7 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA case 7: /* AOMDST_ALPHA */ ta = (0x100 - da); - srcScale.set(srcAlphaScale, ta, ta, ta); + srcScale.set_all(ta); //(RR) = (sr * (0x100 - da)) >> 8; //(GG) = (sg * (0x100 - da)) >> 8; //(BB) = (sb * (0x100 - da)) >> 8; @@ -1103,12 +1102,14 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA case 15: /* ASATURATE */ ta = (sa < (0x100 - da)) ? sa : (0x100 - da); ta++; - srcScale.set(srcAlphaScale, ta, ta, ta); + srcScale.set_all(ta); //(RR) = (sr * (ta + 1)) >> 8; //(GG) = (sg * (ta + 1)) >> 8; //(BB) = (sb * (ta + 1)) >> 8; break; } + // Set srcScale alpha + srcScale.set_a16(srcAlphaScale); /* blend the dest alpha */ if (ALPHAMODE_DSTALPHABLEND(ALPHAMODE) == 4) @@ -1122,12 +1123,12 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA { default: /* reserved */ case 0: /* AZERO */ - destScale.set(destAlphaScale, 0, 0, 0); + destScale.zero(); break; case 1: /* ASRC_ALPHA */ ta = sa + 1; - destScale.set(destAlphaScale, ta, ta, ta); + destScale.set_all(ta); //(RR) += (dr * (sa + 1)) >> 8; //(GG) += (dg * (sa + 1)) >> 8; //(BB) += (db * (sa + 1)) >> 8; @@ -1136,7 +1137,6 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA case 2: /* A_COLOR */ destScale.set(srcColor); destScale.add_imm(1); - destScale.set_a(destAlphaScale); //(RR) += (dr * (sr + 1)) >> 8; //(GG) += (dg * (sg + 1)) >> 8; //(BB) += (db * (sb + 1)) >> 8; @@ -1144,14 +1144,14 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA case 3: /* ADST_ALPHA */ ta = da + 1; - destScale.set(destAlphaScale, ta, ta, ta); + destScale.set_all(ta); //(RR) += (dr * (da + 1)) >> 8; //(GG) += (dg * (da + 1)) >> 8; //(BB) += (db * (da + 1)) >> 8; break; case 4: /* AONE */ - destScale.set(destAlphaScale, 256, 256, 256); + destScale.set_all(256); //(RR) += dr; //(GG) += dg; //(BB) += db; @@ -1159,16 +1159,15 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA case 5: /* AOMSRC_ALPHA */ ta = (0x100 - sa); - destScale.set(destAlphaScale, ta, ta, ta); + destScale.set_all(ta); //(RR) += (dr * (0x100 - sa)) >> 8; //(GG) += (dg * (0x100 - sa)) >> 8; //(BB) += (db * (0x100 - sa)) >> 8; break; case 6: /* AOM_COLOR */ - destScale.set(0x100, 0x100, 0x100, 0x100); + destScale.set_all(0x100); destScale.sub(srcColor); - destScale.set_a(destAlphaScale); //destScale.set(destAlphaScale, (0x100 - color.rgb.r), (0x100 - color.rgb.g), (0x100 - color.rgb.b)); //(RR) += (dr * (0x100 - sr)) >> 8; //(GG) += (dg * (0x100 - sg)) >> 8; @@ -1177,7 +1176,7 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA case 7: /* AOMDST_ALPHA */ ta = (0x100 - da); - destScale.set(destAlphaScale, ta, ta, ta); + destScale.set_all(ta); //(RR) += (dr * (0x100 - da)) >> 8; //(GG) += (dg * (0x100 - da)) >> 8; //(BB) += (db * (0x100 - da)) >> 8; @@ -1186,14 +1185,15 @@ static inline void ATTR_FORCE_INLINE alphaBlend(uint32_t FBZMODE, uint32_t ALPHA case 15: /* A_COLORBEFOREFOG */ destScale.set(preFog); destScale.add_imm(1); - destScale.set_a(destAlphaScale); - //destScale.set((rgb_t) (((destAlphaScale-1)<<24) | (preFog.u & 0x00ffffff))); - //destScale.add_imm(1); //(RR) += (dr * (prefogr + 1)) >> 8; //(GG) += (dg * (prefogg + 1)) >> 8; //(BB) += (db * (prefogb + 1)) >> 8; break; } + + // Set destScale alpha + destScale.set_a16(destAlphaScale); + // Main blend rgbaint_t destColor(da, dr, dg, db); @@ -1355,12 +1355,13 @@ static inline void ATTR_FORCE_INLINE applyFogging(voodoo_device *vd, uint32_t fb /* if fog_add is zero, we start with the fog color */ if (FOGMODE_FOG_ADD(fogModeReg)) - fogColorLocal.set(0, 0, 0, 0); + fogColorLocal.zero(); //fr = fg = fb = 0; /* if fog_mult is zero, we subtract the incoming color */ if (!FOGMODE_FOG_MULT(fogModeReg)) { + // Need to check this, manual states 9 bits fogColorLocal.sub(color); //fog.rgb -= color.rgb; //fr -= (RR); @@ -1423,9 +1424,11 @@ static inline void ATTR_FORCE_INLINE applyFogging(voodoo_device *vd, uint32_t fb //fg = (fg * fogblend) >> 8; //fb = (fb * fogblend) >> 8; /* if fog_mult is 0, we add this to the original color */ + fogColorLocal.scale_imm_and_clamp((int16_t)fogblend); if (FOGMODE_FOG_MULT(fogModeReg) == 0) { - fogColorLocal.scale_imm_add_and_clamp(fogblend, color); + fogColorLocal.add(color); + fogColorLocal.clamp_to_uint8(); //color += fog; //(RR) += fr; //(GG) += fg; @@ -1435,7 +1438,6 @@ static inline void ATTR_FORCE_INLINE applyFogging(voodoo_device *vd, uint32_t fb /* otherwise this just becomes the new color */ else { - fogColorLocal.scale_imm_and_clamp(fogblend); //color = fog; //(RR) = fr; //(GG) = fg; @@ -1448,7 +1450,7 @@ static inline void ATTR_FORCE_INLINE applyFogging(voodoo_device *vd, uint32_t fb //CLAMP((RR), 0x00, 0xff); //CLAMP((GG), 0x00, 0xff); //CLAMP((BB), 0x00, 0xff); - fogColorLocal.merge_alpha(color); + fogColorLocal.merge_alpha16(color); color.set(fogColorLocal); } } @@ -2042,15 +2044,8 @@ inline bool ATTR_FORCE_INLINE voodoo_device::depthTest(uint16_t zaColorReg, stat return true; } -#define PIXEL_PIPELINE_END(vd, STATS, DITHER, DITHER4, DITHER_LOOKUP, XX, dest, depth, FBZMODE, FBZCOLORPATH, ALPHAMODE, FOGMODE, ITERZ, ITERW, ITERAXXX, wfloat) \ +#define PIXEL_PIPELINE_END(STATS, DITHER_LOOKUP, XX, dest, depth, FBZMODE) \ \ - /* perform fogging */ \ - preFog.set(color); \ - if (FOGMODE_ENABLE_FOG(FOGMODE)) \ - applyFogging(vd, FBZMODE, FOGMODE, FBZCOLORPATH, XX, DITHER4, wfloat, color, ITERZ, ITERW, ITERAXXX); \ - /* perform alpha blending */ \ - if (ALPHAMODE_ALPHABLEND(ALPHAMODE)) \ - alphaBlend(FBZMODE, ALPHAMODE, XX, DITHER, dest[XX], depth, preFog, color, vd->fbi.rgb565); \ r = color.get_r(); g = color.get_g(); b = color.get_b(); \ /* modify the pixel for debugging purposes */ \ MODIFY_PIXEL(VV); \ @@ -2380,11 +2375,13 @@ do } \ while (0) -inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, stats_block *STATS, uint32_t FBZCOLORPATH, uint32_t FBZMODE, uint32_t ALPHAMODE, +inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, stats_block *STATS, uint32_t FBZCOLORPATH, uint32_t FBZMODE, rgbaint_t TEXELARGB, int32_t ITERZ, int64_t ITERW, rgbaint_t &srcColor) { rgbaint_t c_other; rgbaint_t c_local; + rgbaint_t blend_color, blend_factor; + rgbaint_t add_val; /* compute c_other */ switch (FBZCP_CC_RGBSELECT(FBZCOLORPATH)) @@ -2401,8 +2398,8 @@ inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, sta c_other.set(vd->reg[color1].u); break; - default: /* reserved - voodoo3 framebufferRGB */ - c_other.set(0); + default: /* reserved - voodoo3 LFB RGB */ + c_other.zero(); break; } @@ -2416,19 +2413,19 @@ inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, sta switch (FBZCP_CC_ASELECT(FBZCOLORPATH)) { case 0: /* iterated alpha */ - c_other.merge_alpha(srcColor); + c_other.merge_alpha16(srcColor); break; case 1: /* texture alpha */ - c_other.merge_alpha(TEXELARGB); + c_other.merge_alpha16(TEXELARGB); break; case 2: /* color1 alpha */ - c_other.set_a(vd->reg[color1].rgb.a); + c_other.set_a16(vd->reg[color1].rgb.a); break; - default: /* reserved */ - c_other.set_a(0); + default: /* reserved - voodoo3 LFB Alpha*/ + c_other.zero_alpha(); break; } @@ -2460,18 +2457,18 @@ inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, sta { default: case 0: /* iterated alpha */ - c_local.merge_alpha(srcColor); + c_local.merge_alpha16(srcColor); break; case 1: /* color0 alpha */ - c_local.set_a(vd->reg[color0].rgb.a); + c_local.set_a16(vd->reg[color0].rgb.a); break; case 2: /* clamped iterated Z[27:20] */ { int temp; CLAMPED_Z(ITERZ, FBZCOLORPATH, temp); - c_local.set_a((uint8_t) temp); + c_local.set_a16((uint8_t) temp); break; } @@ -2479,37 +2476,40 @@ inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, sta { int temp; CLAMPED_W(ITERW, FBZCOLORPATH, temp); /* Voodoo 2 only */ - c_local.set_a((uint8_t) temp); + c_local.set_a16((uint8_t) temp); break; } } - uint8_t a_other = c_other.get_a(); - uint8_t a_local = c_local.get_a(); - uint8_t tmp; - rgbaint_t add_val(c_local); - /* select zero or c_other */ if (FBZCP_CC_ZERO_OTHER(FBZCOLORPATH)) - c_other.and_imm_rgba(-1, 0, 0, 0); //r = g = b = 0; + blend_color.zero(); + else + blend_color.set(c_other); /* select zero or a_other */ if (FBZCP_CCA_ZERO_OTHER(FBZCOLORPATH)) - c_other.set_a(0); + blend_color.zero_alpha(); + else + blend_color.merge_alpha16(c_other); /* subtract a/c_local */ if (FBZCP_CC_SUB_CLOCAL(FBZCOLORPATH) || (FBZCP_CCA_SUB_CLOCAL(FBZCOLORPATH))) { - rgbaint_t sub_val = c_local; + rgbaint_t sub_val; if (!FBZCP_CC_SUB_CLOCAL(FBZCOLORPATH)) - sub_val.set(a_local, 0, 0, 0); + sub_val.zero(); + else + sub_val.set(c_local); if (!FBZCP_CCA_SUB_CLOCAL(FBZCOLORPATH)) - sub_val.set_a(0); + sub_val.zero_alpha(); + else + sub_val.merge_alpha16(c_local); - c_other.sub(sub_val); + blend_color.sub(sub_val); } /* blend RGB */ @@ -2517,28 +2517,27 @@ inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, sta { default: /* reserved */ case 0: /* 0 */ - c_local.and_imm_rgba(-1, 0, 0, 0); + blend_factor.zero(); break; case 1: /* c_local */ + blend_factor.set(c_local); break; case 2: /* a_other */ - c_local.set(a_local, a_other, a_other, a_other); + blend_factor.set(c_other.select_alpha32()); break; case 3: /* a_local */ - c_local.set(a_local, a_local, a_local, a_local); + blend_factor.set(c_local.select_alpha32()); break; case 4: /* texture alpha */ - tmp = TEXELARGB.get_a(); - c_local.set(a_local, tmp, tmp, tmp); + blend_factor.set(TEXELARGB.select_alpha32()); break; case 5: /* texture RGB (Voodoo 2 only) */ - // Warning wipes out c_local alpha - c_local.set(TEXELARGB); + blend_factor.set(TEXELARGB); break; } @@ -2547,30 +2546,30 @@ inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, sta { default: /* reserved */ case 0: /* 0 */ - c_local.set_a(0); + blend_factor.zero_alpha(); break; case 1: /* a_local */ case 3: /* a_local */ - c_local.set_a(a_local); + blend_factor.merge_alpha16(c_local); break; case 2: /* a_other */ - c_local.set_a(a_other); + blend_factor.merge_alpha16(c_other); break; case 4: /* texture alpha */ - c_local.merge_alpha(TEXELARGB); + blend_factor.merge_alpha16(TEXELARGB); break; } /* reverse the RGB blend */ if (!FBZCP_CC_REVERSE_BLEND(FBZCOLORPATH)) - c_local.xor_imm_rgba(0, 0xff, 0xff, 0xff); + blend_factor.xor_imm_rgba(0, 0xff, 0xff, 0xff); /* reverse the alpha blend */ if (!FBZCP_CCA_REVERSE_BLEND(FBZCOLORPATH)) - c_local.xor_imm_rgba(0xff, 0, 0, 0); + blend_factor.xor_imm_rgba(0xff, 0, 0, 0); /* do the blend */ //color.rgb.a = (color.rgb.a * (blenda + 1)) >> 8; @@ -2583,44 +2582,41 @@ inline bool ATTR_FORCE_INLINE voodoo_device::combineColor(voodoo_device *vd, sta { case 3: /* reserved */ case 0: /* nothing */ - add_val.set(a_local, 0, 0, 0); + add_val.zero(); break; case 1: /* add c_local */ + add_val.set(c_local); break; case 2: /* add_alocal */ - add_val.set(a_local, a_local, a_local, a_local); + add_val.set(c_local.select_alpha32()); break; } /* add clocal or alocal to alpha */ if (!FBZCP_CCA_ADD_ACLOCAL(FBZCOLORPATH)) - add_val.set_a(0); + add_val.zero_alpha(); + else //color.rgb.a += c_local.rgb.a; + add_val.merge_alpha16(c_local); /* clamp */ //CLAMP(color.rgb.a, 0x00, 0xff); //CLAMP(color.rgb.r, 0x00, 0xff); //CLAMP(color.rgb.g, 0x00, 0xff); //CLAMP(color.rgb.b, 0x00, 0xff); - c_local.add_imm(1); - c_other.scale_add_and_clamp(c_local, add_val); - srcColor.set(c_other); + blend_factor.add_imm(1); + blend_color.scale_add_and_clamp(blend_factor, add_val); /* invert */ if (FBZCP_CCA_INVERT_OUTPUT(FBZCOLORPATH)) - srcColor.xor_imm_rgba(0xff, 0, 0, 0); + blend_color.xor_imm_rgba(0xff, 0, 0, 0); /* invert */ if (FBZCP_CC_INVERT_OUTPUT(FBZCOLORPATH)) - srcColor.xor_imm_rgba(0, 0xff, 0xff, 0xff); + blend_color.xor_imm_rgba(0, 0xff, 0xff, 0xff); - - /* handle alpha test */ - if (ALPHAMODE_ALPHATEST(ALPHAMODE)) - if (!alphaTest(vd, STATS, ALPHAMODE, srcColor.get_a())) - return false; - //APPLY_ALPHATEST(vd->m_vds, STATS, ALPHAMODE, color.rgb.a); + srcColor.set(blend_color); return true; } @@ -2645,9 +2641,9 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * int32_t stopx = extent->stopx; \ rgbaint_t iterargb, iterargbDelta; \ int32_t iterz; \ - int64_t iterw, iterw0 = 0, iterw1 = 0; \ - int64_t iters0 = 0, iters1 = 0; \ - int64_t itert0 = 0, itert1 = 0; \ + int64_t iterw; \ + tmu_state::stw_t iterstw0, iterstw1; \ + tmu_state::stw_t deltastw0, deltastw1; \ uint16_t *depth; \ uint16_t *dest; \ int32_t dx, dy; \ @@ -2677,6 +2673,20 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * } \ \ /* X clipping */ \ + tempclip = vd->reg[clipLeftRight].u & 0x3ff; \ + /* Check for start outsize of clipping boundary */ \ + if (startx >= tempclip) \ + { \ + stats->pixels_in += stopx - startx; \ + vd->stats.total_clipped += stopx - startx; \ + return; \ + } \ + if (stopx > tempclip) \ + { \ + stats->pixels_in += stopx - tempclip; \ + vd->stats.total_clipped += stopx - tempclip; \ + stopx = tempclip; \ + } \ tempclip = (vd->reg[clipLeftRight].u >> 16) & 0x3ff; \ if (startx < tempclip) \ { \ @@ -2684,13 +2694,6 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * vd->stats.total_clipped += tempclip - startx; \ startx = tempclip; \ } \ - tempclip = vd->reg[clipLeftRight].u & 0x3ff; \ - if (stopx >= tempclip) \ - { \ - stats->pixels_in += stopx - tempclip; \ - vd->stats.total_clipped += stopx - tempclip; \ - stopx = tempclip - 1; \ - } \ } \ \ /* get pointers to the target buffer and depth buffer */ \ @@ -2710,15 +2713,19 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * iterw = extra->startw + dy * extra->dwdy + dx * extra->dwdx; \ if (TMUS >= 1) \ { \ - iterw0 = extra->startw0 + dy * extra->dw0dy + dx * extra->dw0dx; \ - iters0 = extra->starts0 + dy * extra->ds0dy + dx * extra->ds0dx; \ - itert0 = extra->startt0 + dy * extra->dt0dy + dx * extra->dt0dx; \ + iterstw0.set( \ + extra->starts0 + dy * extra->ds0dy + dx * extra->ds0dx, \ + extra->startt0 + dy * extra->dt0dy + dx * extra->dt0dx, \ + extra->startw0 + dy * extra->dw0dy + dx * extra->dw0dx); \ + deltastw0.set(extra->ds0dx, extra->dt0dx, extra->dw0dx); \ } \ if (TMUS >= 2) \ { \ - iterw1 = extra->startw1 + dy * extra->dw1dy + dx * extra->dw1dx; \ - iters1 = extra->starts1 + dy * extra->ds1dy + dx * extra->ds1dx; \ - itert1 = extra->startt1 + dy * extra->dt1dy + dx * extra->dt1dx; \ + iterstw1.set( \ + extra->starts1 + dy * extra->ds1dy + dx * extra->ds1dx, \ + extra->startt1 + dy * extra->dt1dy + dx * extra->dt1dx, \ + extra->startw1 + dy * extra->dw1dy + dx * extra->dw1dx); \ + deltastw1.set(extra->ds1dx, extra->dt1dx, extra->dw1dx); \ } \ extra->info->hits++; \ /* loop in X */ \ @@ -2740,7 +2747,7 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * int32_t tmp; \ const rgbaint_t texelZero(0); \ texel = vd->tmu[1].genTexture(x, dither4, TEXMODE1, vd->tmu[1].lookup, extra->lodbase1, \ - iters1, itert1, iterw1, tmp); \ + iterstw1, tmp); \ texel = vd->tmu[1].combineTexture(TEXMODE1, texel, texelZero, tmp); \ } \ /* run the texture pipeline on TMU0 to produce a final */ \ @@ -2753,7 +2760,7 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * int32_t lod0; \ rgbaint_t texelT0; \ texelT0 = vd->tmu[0].genTexture(x, dither4, TEXMODE0, vd->tmu[0].lookup, extra->lodbase0, \ - iters0, itert0, iterw0, lod0); \ + iterstw0, lod0); \ texel = vd->tmu[0].combineTexture(TEXMODE0, texelT0, texel, lod0); \ } \ else \ @@ -2763,14 +2770,25 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * } \ \ /* colorpath pipeline selects source colors and does blending */ \ - color = clampARGB(iterargb, FBZCOLORPATH); \ - if (!combineColor(vd, stats, FBZCOLORPATH, FBZMODE, ALPHAMODE, texel, iterz, iterw, color)) \ - goto skipdrawdepth; \ - \ - /* pixel pipeline part 2 handles fog, alpha, and final output */ \ - PIXEL_PIPELINE_END(vd, stats, dither, dither4, dither_lookup, x, dest, depth, \ - FBZMODE, FBZCOLORPATH, ALPHAMODE, FOGMODE, \ - iterz, iterw, iterargb, wfloat); \ + color = clampARGB(iterargb, FBZCOLORPATH); \ + if (!combineColor(vd, stats, FBZCOLORPATH, FBZMODE, texel, iterz, iterw, color)) \ + goto skipdrawdepth; \ + /* handle alpha test */ \ + if (ALPHAMODE_ALPHATEST(ALPHAMODE)) \ + if (!alphaTest(vd->reg[alphaMode].rgb.a, stats, ALPHAMODE, color.get_a())) \ + goto skipdrawdepth; \ + \ + /* perform fogging */ \ + preFog.set(color); \ + if (FOGMODE_ENABLE_FOG(FOGMODE)) \ + applyFogging(vd, FBZMODE, FOGMODE, FBZCOLORPATH, x, dither4, wfloat, color, iterz, iterw, iterargb); \ + \ + /* perform alpha blending */ \ + if (ALPHAMODE_ALPHABLEND(ALPHAMODE)) \ + alphaBlend(FBZMODE, ALPHAMODE, x, dither, dest[x], depth, preFog, color, vd->fbi.rgb565); \ + \ + /* pixel pipeline part 2 handles final output */ \ + PIXEL_PIPELINE_END(stats, dither_lookup, x, dest, depth, FBZMODE); \ \ /* update the iterated parameters */ \ iterargb += iterargbDelta; \ @@ -2778,15 +2796,11 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * iterw += extra->dwdx; \ if (TMUS >= 1) \ { \ - iterw0 += extra->dw0dx; \ - iters0 += extra->ds0dx; \ - itert0 += extra->dt0dx; \ + iterstw0.add(deltastw0); \ } \ if (TMUS >= 2) \ { \ - iterw1 += extra->dw1dx; \ - iters1 += extra->ds1dx; \ - itert1 += extra->dt1dx; \ + iterstw1.add(deltastw1); \ } \ } \ } @@ -2798,38 +2812,23 @@ void voodoo_device::raster_##name(void *destbase, int32_t y, const poly_extent * // The maximum error using a 4 bit lookup from the mantissa is 0.0875, which is less than 1/2 lsb (0.125) for 2 bits of fraction. // An offset of +(56 << 8) is added for alignment in multi_reciplog // ****************************************************************************************************************************** -static inline int32_t ATTR_FORCE_INLINE new_log2(double &value) +inline int32_t ATTR_FORCE_INLINE voodoo_device::tmu_state::new_log2(double &value, const int &offset) { - static const int32_t new_log2_table[16] = {0 + (56 << 8), 22 + (56 << 8), 44 + (56 << 8), 63 + (56 << 8), 82 + (56 << 8), - 100 + (56 << 8), 118 + (56 << 8), 134 + (56 << 8), 150 + (56 << 8), 165 + (56 << 8), 179 + (56 << 8), 193 + (56 << 8), - 207 + (56 << 8), 220 + (56 << 8), 232 + (56 << 8), 244 + (56 << 8)}; + static const int32_t new_log2_table[16] = {0, 22, 44, 63, 82, 100, 118, 134, 150, 165, 179, 193, 207, 220, 232, 244}; uint64_t ival = *((uint64_t *)&value); // Return 0 if negative if (ival & ((uint64_t)1 << 63)) return 0; // We zero the result if negative so don't worry about the sign bit int32_t exp = (ival>>52); - exp -= 1023+32; + exp -= 1023+32-offset; exp <<= 8; uint32_t addr = (uint64_t)(ival>>48) & 0xf; exp += new_log2_table[addr]; return exp; } -// Computes A/C and B/C and returns log2 of 1/C -// A, B and C are 16.32 values. The results are 24.8. -static inline void ATTR_FORCE_INLINE multi_reciplog(int64_t valueA, int64_t valueB, int64_t valueC, int32_t &log, int32_t &resA, int32_t &resB) -{ - double recip = double(1ULL<<(47-39))/valueC; - double resAD = valueA * recip; - double resBD = valueB * recip; - log = new_log2(recip); - resA = resAD; - resB = resBD; -} - - -inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::genTexture(int32_t x, const uint8_t *dither4, const uint32_t TEXMODE, rgb_t *LOOKUP, int32_t LODBASE, int64_t ITERS, int64_t ITERT, int64_t ITERW, int32_t &lod) +inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::genTexture(int32_t x, const uint8_t *dither4, const uint32_t TEXMODE, rgb_t *LOOKUP, int32_t LODBASE, const stw_t &iterstw, int32_t &lod) { rgbaint_t result; int32_t s, t, ilod; @@ -2839,23 +2838,16 @@ inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::genTexture(int32_t if (TEXMODE_ENABLE_PERSPECTIVE(TEXMODE)) { int32_t wLog; - if (USE_FAST_RECIP) { - const int32_t oow = fast_reciplog((ITERW), &wLog); - s = ((int64_t)oow * (ITERS)) >> (29+10); - t = ((int64_t)oow * (ITERT)) >> (29+10); - } else { - multi_reciplog(ITERS, ITERT, ITERW, wLog, s, t); - } + iterstw.calc_stow(s, t, wLog); lod += wLog; } else { - s = (ITERS) >> (14+10); - t = (ITERT) >> (14+10); + iterstw.get_st_shiftr(s, t, (14 + 10)); } /* clamp W */ - if (TEXMODE_CLAMP_NEG_W(TEXMODE) && (ITERW) < 0) + if (TEXMODE_CLAMP_NEG_W(TEXMODE) && iterstw.is_w_neg()) { s = t = 0; } @@ -3017,33 +3009,39 @@ inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::genTexture(int32_t return result; } -inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::combineTexture(const uint32_t TEXMODE, rgbaint_t c_local, rgbaint_t c_other, int32_t lod) +inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::combineTexture(const uint32_t TEXMODE, const rgbaint_t& c_local, const rgbaint_t& c_other, int32_t lod) { - int32_t a_other = c_other.get_a(); - int32_t a_local = c_local.get_a(); - rgbaint_t add_val = c_local; - uint8_t tmp; + rgbaint_t blend_color, blend_factor; + rgbaint_t add_val; /* select zero/other for RGB */ if (TEXMODE_TC_ZERO_OTHER(TEXMODE)) - c_other.and_imm_rgba(-1, 0, 0, 0); + blend_color.zero(); + else + blend_color.set(c_other); /* select zero/other for alpha */ if (TEXMODE_TCA_ZERO_OTHER(TEXMODE)) - c_other.set_a(0); + blend_color.zero_alpha(); + else + blend_color.merge_alpha16(c_other); if (TEXMODE_TC_SUB_CLOCAL(TEXMODE) || TEXMODE_TCA_SUB_CLOCAL(TEXMODE)) { - rgbaint_t sub_val = c_local; + rgbaint_t sub_val; /* potentially subtract c_local */ if (!TEXMODE_TC_SUB_CLOCAL(TEXMODE)) - sub_val.and_imm_rgba(-1, 0, 0, 0); + sub_val.zero(); + else + sub_val.set(c_local); if (!TEXMODE_TCA_SUB_CLOCAL(TEXMODE)) - sub_val.set_a(0); + sub_val.zero_alpha(); + else + sub_val.merge_alpha16(c_local); - c_other.sub(sub_val); + blend_color.sub(sub_val); } /* blend RGB */ @@ -3051,35 +3049,36 @@ inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::combineTexture(cons { default: /* reserved */ case 0: /* zero */ - c_local.and_imm_rgba(-1, 0, 0, 0); + blend_factor.zero(); break; case 1: /* c_local */ + blend_factor.set(c_local); break; case 2: /* a_other */ - c_local.set(a_local, a_other, a_other, a_other); + blend_factor.set(c_other.select_alpha32()); break; case 3: /* a_local */ - c_local.set(a_local, a_local, a_local, a_local); + blend_factor.set(c_local.select_alpha32()); break; case 4: /* LOD (detail factor) */ if (detailbias <= lod) - c_local.and_imm_rgba(-1, 0, 0, 0); + blend_factor.zero(); else { + uint8_t tmp; tmp = (((detailbias - lod) << detailscale) >> 8); if (tmp > detailmax) tmp = detailmax; - c_local.set(a_local, tmp, tmp, tmp); + blend_factor.set_all(tmp); } break; case 5: /* LOD fraction */ - tmp = lod & 0xff; - c_local.set(a_local, tmp, tmp, tmp); + blend_factor.set_all(lod & 0xff); break; } @@ -3088,45 +3087,46 @@ inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::combineTexture(cons { default: /* reserved */ case 0: /* zero */ - c_local.set_a(0); + blend_factor.zero_alpha(); break; case 1: /* c_local */ + blend_factor.merge_alpha16(c_local); break; case 2: /* a_other */ - c_local.set_a(a_other); + blend_factor.merge_alpha16(c_other); break; case 3: /* a_local */ + blend_factor.merge_alpha16(c_local); break; case 4: /* LOD (detail factor) */ if (detailbias <= lod) - c_local.set_a(0); + blend_factor.zero_alpha(); else { + uint8_t tmp; tmp = (((detailbias - lod) << detailscale) >> 8); if (tmp > detailmax) tmp = detailmax; - c_local.set_a(tmp); + blend_factor.set_a16(tmp); } break; case 5: /* LOD fraction */ - c_local.set_a(lod & 0xff); + blend_factor.set_a16(lod & 0xff); break; } /* reverse the RGB blend */ if (!TEXMODE_TC_REVERSE_BLEND(TEXMODE)) - { - c_local.xor_imm_rgba(0, 0xff, 0xff, 0xff); - } + blend_factor.xor_imm_rgba(0, 0xff, 0xff, 0xff); /* reverse the alpha blend */ if (!TEXMODE_TCA_REVERSE_BLEND(TEXMODE)) - c_local.xor_imm_rgba(0xff, 0, 0, 0); + blend_factor.xor_imm_rgba(0xff, 0, 0, 0); /* do the blend */ //tr = (tr * (blendr + 1)) >> 8; @@ -3139,39 +3139,38 @@ inline rgbaint_t ATTR_FORCE_INLINE voodoo_device::tmu_state::combineTexture(cons { case 3: /* reserved */ case 0: /* nothing */ - add_val.set(a_local, 0, 0, 0); + add_val.zero(); break; case 1: /* add c_local */ + add_val.set(c_local); break; case 2: /* add_alocal */ - add_val.set(a_local, a_local , a_local , a_local); - //tr += c_local.rgb.a; - //tg += c_local.rgb.a; - //tb += c_local.rgb.a; + add_val.set(c_local.select_alpha32()); break; } /* add clocal or alocal to alpha */ if (!TEXMODE_TCA_ADD_ACLOCAL(TEXMODE)) - add_val.set_a(0); - //ta += c_local.rgb.a; + add_val.zero_alpha(); + else + add_val.merge_alpha16(c_local); /* clamp */ //result.rgb.r = (tr < 0) ? 0 : (tr > 0xff) ? 0xff : tr; //result.rgb.g = (tg < 0) ? 0 : (tg > 0xff) ? 0xff : tg; //result.rgb.b = (tb < 0) ? 0 : (tb > 0xff) ? 0xff : tb; //result.rgb.a = (ta < 0) ? 0 : (ta > 0xff) ? 0xff : ta; - c_local.add_imm(1); - c_other.scale_add_and_clamp(c_local, add_val); - rgbaint_t result(c_other); + blend_factor.add_imm(1); + blend_color.scale_add_and_clamp(blend_factor, add_val); + /* invert */ if (TEXMODE_TC_INVERT_OUTPUT(TEXMODE)) - result.xor_imm_rgba(0, 0xff, 0xff, 0xff); + blend_color.xor_imm_rgba(0, 0xff, 0xff, 0xff); if (TEXMODE_TCA_INVERT_OUTPUT(TEXMODE)) - result.xor_imm_rgba(0xff, 0, 0, 0); - return result; + blend_color.xor_imm_rgba(0xff, 0, 0, 0); + return blend_color; } #endif // MAME_VIDEO_VOODDEFS_H |