diff --git a/glide3x/h5/glide3/src/ditex.c b/glide3x/h5/glide3/src/ditex.c index f42c5aa..3e2bf68 100644 --- a/glide3x/h5/glide3/src/ditex.c +++ b/glide3x/h5/glide3/src/ditex.c @@ -1579,11 +1579,19 @@ FxU32 _grTexTextureMemRequired( GrLOD_t small_lod, GrLOD_t large_lod, GrAspectRatio_t aspect, GrTextureFormat_t format, FxU32 evenOdd, - FxBool roundP ) + FxBool roundP, + FxBool systemMem ) { #define FN_NAME "_grTexTextureMemRequired" FxU32 memrequired; + GDBG_INFO(80,"_grTexTextureMemRequired(%d,%d, %d,%d, %d, %d, %d)\n", + small_lod, large_lod, + aspect, format, + evenOdd, + roundP, + systemMem); + GR_CHECK_W(FN_NAME, small_lod > large_lod, "small_lod bigger than large_lod" ); @@ -1594,7 +1602,6 @@ _grTexTextureMemRequired( GrLOD_t small_lod, GrLOD_t large_lod, switch(format) { case GR_TEXFMT_ARGB_CMP_FXT1: - case GR_TEXFMT_ARGB_CMP_DXT1: /* In this case, do not mirror the aspect ratios, as the minimum * size of a mipmap level is 8x4, so the tables are not symmetric * w.r.t. sign of the aspect ratio, so keep the sign. */ @@ -1617,6 +1624,48 @@ _grTexTextureMemRequired( GrLOD_t small_lod, GrLOD_t large_lod, } break; + case GR_TEXFMT_ARGB_CMP_DXT1: /* XXX check this! */ + if(systemMem) { + /* calculating for system memory */ + /* In this case, do not mirror the aspect ratios, as the minimum + * size of a mipmap level is 8x4, so the tables are not symmetric + * w.r.t. sign of the aspect ratio, so keep the sign. */ + if ( evenOdd == GR_MIPMAPLEVELMASK_BOTH ) { + memrequired = _grMipMapOffsetCmp4Bit[G3_ASPECT_TRANSLATE(aspect)][small_lod]; + memrequired -= _grMipMapOffsetCmp4Bit[G3_ASPECT_TRANSLATE(aspect)][large_lod+1]; + } else { + memrequired = 0; + /* construct XOR mask */ + evenOdd = (evenOdd == GR_MIPMAPLEVELMASK_EVEN) ? 1 : 0; + while (large_lod >= small_lod) { /* sum up all the mipmap levels */ + if ((large_lod ^ evenOdd) & 1) { /* that match the XOR mask */ + memrequired += _grMipMapSizeCmp4Bit[G3_ASPECT_TRANSLATE(aspect)][large_lod]; + } + large_lod--; + } + } + } else { + /* for texture memory on hardware */ + /* allows us to mirror the aspect ratios because the table entries are the same */ + if (aspect < GR_ASPECT_LOG2_1x1) { + aspect = -aspect; + } + if ( evenOdd == GR_MIPMAPLEVELMASK_BOTH ) { + memrequired = _grMipMapOffsetDXT[G3_ASPECT_TRANSLATE(aspect)][small_lod]; + memrequired -= _grMipMapOffsetDXT[G3_ASPECT_TRANSLATE(aspect)][large_lod+1]; + } else { + memrequired = 0; + /* construct XOR mask */ + evenOdd = (evenOdd == GR_MIPMAPLEVELMASK_EVEN) ? 1 : 0; + while (large_lod >= small_lod) { /* sum up all the mipmap levels */ + if ((large_lod ^ evenOdd) & 1) { /* that match the XOR mask */ + memrequired += _grMipMapSizeDXT[G3_ASPECT_TRANSLATE(aspect)][large_lod]; + } + large_lod--; + } + } + } + break; case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: @@ -1709,7 +1758,6 @@ _grTexCalcBaseAddress( FxU32 start, GrLOD_t large_lod, switch(format) { case GR_TEXFMT_ARGB_CMP_FXT1: - case GR_TEXFMT_ARGB_CMP_DXT1: /* FXT1 format: Don't mirror the aspect ratios, because of the 8x4 limit */ if ( odd_even_mask == GR_MIPMAPLEVELMASK_BOTH ) { sum_of_lod_sizes = _grMipMapOffsetCmp4Bit[aspect] @@ -1726,6 +1774,7 @@ _grTexCalcBaseAddress( FxU32 start, GrLOD_t large_lod, } break; + case GR_TEXFMT_ARGB_CMP_DXT1: /* XXX check this! */ case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: @@ -1793,7 +1842,8 @@ GR_DIENTRY(grTexCalcMemRequired, FxU32, memrequired = _grTexTextureMemRequired(small_lod, large_lod, aspect, format, GR_MIPMAPLEVELMASK_BOTH, - FXTRUE); + FXTRUE, + FXFALSE); GDBG_INFO(88,"grTexCalcMemRequired(%d,%d,%d,%d) => 0x%x(%d)\n", small_lod,large_lod,aspect,format,memrequired,memrequired); return memrequired; @@ -1986,7 +2036,8 @@ GR_DIENTRY(grTexTextureMemRequired, FxU32, info->aspectRatioLog2, info->format, evenOdd, - FXTRUE ); + FXTRUE, + FXFALSE ); GDBG_INFO(88,"grTexTextureMemRequired(%d,0x%x) => 0x%x(%d)\n", evenOdd,info,memrequired,memrequired); @@ -2189,7 +2240,7 @@ GR_DIENTRY(grTexDownloadMipMapLevel, void, /* Note: Unlike in other places, we put DXT1 here because it's min size * according to the app is actually 4x4 like the other DXTC mode - */ + */ case GR_TEXFMT_ARGB_CMP_DXT1: case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: diff --git a/glide3x/h5/glide3/src/fxglide.h b/glide3x/h5/glide3/src/fxglide.h index 2503f34..4aeaae9 100644 --- a/glide3x/h5/glide3/src/fxglide.h +++ b/glide3x/h5/glide3/src/fxglide.h @@ -1803,7 +1803,7 @@ typedef struct GrGC_s FxI32 roomToReadPtr;/* Bytes until last known hw ptr */ FxI32 roomToEnd; /* # of bytes until last usable address before fifoEnd */ - FxBool lfbLockCount; /* Have we done an lfb lock? Count of the locks. */ + FxU32 lfbLockCount; /* Have we done an lfb lock? Count of the locks. */ #if GLIDE_INIT_HWC GrStateBuffer* @@ -2130,7 +2130,6 @@ struct _GlideRoot_s { FxU32 oglLfbLockHack; /* Enables disable hack to get around forced 32bit problems in OpenGL */ FxU32 useHwcAAforLfbRead; /* Specifies whether to use HwcAAReadRegion for read Locks and LfbReadRegion calls */ FxU32 ditherHwcAA; /* Specifies whether to use HwcAAReadRegion should dither */ - FxI32 lockCounter; } environment; GrHwConfiguration hwConfig; @@ -2942,7 +2941,8 @@ FxU32 _grTexTextureMemRequired(GrLOD_t small_lod, GrLOD_t large_lod, GrAspectRatio_t aspect, GrTextureFormat_t format, FxU32 evenOdd, - FxBool roundP); + FxBool roundP, + FxBool systemMem); void FX_CSTYLE _grUpdateParamIndex(void); diff --git a/glide3x/h5/glide3/src/g3df.c b/glide3x/h5/glide3/src/g3df.c index 08b3bc1..c8ea8e1 100644 --- a/glide3x/h5/glide3/src/g3df.c +++ b/glide3x/h5/glide3/src/g3df.c @@ -543,7 +543,8 @@ GR_DIENTRY(gu3dfGetInfo, FxBool, Info->header.aspect_ratio, Info->header.format, GR_MIPMAPLEVELMASK_BOTH, - FXFALSE); + FXFALSE, + FXTRUE); } GDBG_INFO(81,"gu3dfGetInfo(%s,0x%x) -> %i tex memory required\n",FileName,Info, Info->mem_required); diff --git a/glide3x/h5/glide3/src/gglide.c b/glide3x/h5/glide3/src/gglide.c index 981dcaa..4b730bb 100644 --- a/glide3x/h5/glide3/src/gglide.c +++ b/glide3x/h5/glide3/src/gglide.c @@ -2659,9 +2659,6 @@ GR_ENTRY(grBufferSwap, void, (FxU32 swapInterval)) GR_BEGIN_NOFIFOCHECK(FN_NAME,86); GDBG_INFO_MORE(gc->myLevel,"(%d)\n",swapInterval); - // First thing first. Decrement the lockCounter - if (_GlideRoot.environment.lockCounter > -10) _GlideRoot.environment.lockCounter--; - #ifdef FX_GLIDE_NAPALM #if !(GLIDE_PLATFORM & GLIDE_OS_UNIX) && !defined(__DJGPP__) /* Window hacky stuff */ diff --git a/glide3x/h5/glide3/src/glfb.c b/glide3x/h5/glide3/src/glfb.c index 72023f1..e6643e6 100644 --- a/glide3x/h5/glide3/src/glfb.c +++ b/glide3x/h5/glide3/src/glfb.c @@ -19,6 +19,9 @@ ** ** $Header$ ** $Log$ +** Revision 1.7.4.15 2003/08/04 12:44:40 dborca +** Enabled 32bit Z writes +** ** Revision 1.7.4.14 2003/07/25 07:14:59 dborca ** ... in the name of the Linux, DRI and the sacred Glide... ** @@ -999,8 +1002,6 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, rv = FXTRUE; const FxBool idleLockP = ((type & GR_LFB_NOIDLE) == 0); - FxBool - noRead = FXFALSE; FxU32 lfbMode, zaColor, @@ -1013,23 +1014,15 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, GR_BEGIN_NOFIFOCHECK_RET("_grLfbLock", 82); GDBG_INFO_MORE(gc->myLevel,"(%d,%d,0x%x)\n", type, buffer, info); - GR_CHECK_COMPATABILITY(FN_NAME, !info, - "Null info structure passed."); + GR_CHECK_COMPATABILITY(FN_NAME, !info, "Null info structure passed."); + /* there is only one revision extant */ GR_CHECK_COMPATABILITY(FN_NAME, info->size != sizeof(GrLfbInfo_t), "uninitialized info structure passed."); - type = type & ~(GR_LFB_NOIDLE); - - // LFBWOEXP Extension - if (type == GR_LFB_WRITE_ONLY_EXPLICIT_EXT) - { - type = GR_LFB_WRITE_ONLY; - noRead = FXTRUE; - } - /* Pray that no one has made any glide calls that touch the hardware... */ #ifdef FX_GLIDE_NAPALM + /* works only for minihwc with env FX_GLIDE_A0_READ_ABORT set. unused for linhwc. */ if(gc->sliCount > 1 && type == GR_LFB_READ_ONLY) hwcSLIReadDisable(gc->bInfo); #endif @@ -1043,22 +1036,18 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, zaColor = gc->state.shadow.zaColor; type = type & ~(GR_LFB_NOIDLE); - if (gc->lockPtrs[type] != (FxU32)-1) - { - GDBG_INFO(83, "Read lock failure due to existing lock"); - rv = FXFALSE; + if (gc->lockPtrs[((type == GR_LFB_WRITE_ONLY_EXPLICIT_EXT) ? GR_LFB_WRITE_ONLY : type)] != (FxU32)-1) { + GDBG_INFO(83, "Read lock failure due to existing lock\n"); + GR_RETURN(FXFALSE); } - if (rv) - { - switch(type) - { + if (rv) { + switch(type) { case GR_LFB_READ_ONLY: lfbMode &= ~(SST_LFB_READBUFSELECT | SST_LFB_YORIGIN); - switch(buffer) - { + switch(buffer) { case GR_BUFFER_FRONTBUFFER: case GR_BUFFER_BACKBUFFER: /* tbext */ @@ -1076,7 +1065,7 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, GR_CHECK_F(myName, 1, "illegal buffer parameter passed"); - rv = FXFALSE; + GR_RETURN(FXFALSE); break; } @@ -1086,40 +1075,42 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, { FxU32 fbMode = 0; FxU32 depthMode = 0; - switch(gc->grPixelFormat) - { - case GR_PIXFMT_ARGB_1555: - case GR_PIXFMT_AA_2_ARGB_1555: - case GR_PIXFMT_AA_4_ARGB_1555: - case GR_PIXFMT_AA_8_ARGB_1555: /* 8xaa */ - fbMode = GR_LFBWRITEMODE_1555; - depthMode = GR_LFBWRITEMODE_ZA16; - break; - case GR_PIXFMT_ARGB_8888: - case GR_PIXFMT_AA_2_ARGB_8888: - case GR_PIXFMT_AA_4_ARGB_8888: - case GR_PIXFMT_AA_8_ARGB_8888: /* 8xaa */ - fbMode = GR_LFBWRITEMODE_8888; - depthMode = GR_LFBWRITEMODE_Z32; - break; - case GR_PIXFMT_RGB_565: - case GR_PIXFMT_AA_2_RGB_565: - case GR_PIXFMT_AA_4_RGB_565: - case GR_PIXFMT_AA_8_RGB_565: /* 8xaa */ - default: - fbMode = GR_LFBWRITEMODE_565; - depthMode = GR_LFBWRITEMODE_ZA16; - break; - } + + switch(gc->grPixelFormat) { + case GR_PIXFMT_ARGB_1555: + case GR_PIXFMT_AA_2_ARGB_1555: + case GR_PIXFMT_AA_4_ARGB_1555: + case GR_PIXFMT_AA_8_ARGB_1555: /* 8xaa */ + fbMode = GR_LFBWRITEMODE_1555; + depthMode = GR_LFBWRITEMODE_ZA16; + break; + case GR_PIXFMT_ARGB_8888: + case GR_PIXFMT_AA_2_ARGB_8888: + case GR_PIXFMT_AA_4_ARGB_8888: + case GR_PIXFMT_AA_8_ARGB_8888: /* 8xaa */ + fbMode = GR_LFBWRITEMODE_8888; + depthMode = GR_LFBWRITEMODE_Z32; + break; + case GR_PIXFMT_RGB_565: + case GR_PIXFMT_AA_2_RGB_565: + case GR_PIXFMT_AA_4_RGB_565: + case GR_PIXFMT_AA_8_RGB_565: /* 8xaa */ + default: + fbMode = GR_LFBWRITEMODE_565; + depthMode = GR_LFBWRITEMODE_ZA16; + break; + } + info->writeMode = (((buffer == GR_BUFFER_AUXBUFFER) || (buffer == GR_BUFFER_TEXTUREAUXBUFFER_EXT)) ? depthMode : fbMode); } - + lfbMode |= (origin ? SST_LFB_YORIGIN : 0); break; case GR_LFB_WRITE_ONLY: + case GR_LFB_WRITE_ONLY_EXPLICIT_EXT: /* Set up the constant depth register because it may have * been trashed by a call to grDepthBiasLevel * (depthbiaslevel and constant depth use the same register) @@ -1137,13 +1128,11 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, #if (GLIDE_PLATFORM & GLIDE_OS_MACOS) && SET_BSWAP /* For MacOS/PowerPC we always want to enable at least byte swapping, and for the 16-bit pixel formats we want to enable word swapping as well. */ - lfbMode &= ~(SST_LFB_WRITE_BYTESWAP | SST_LFB_WRITE_SWAP16); lfbMode |= SST_LFB_WRITE_BYTESWAP; #endif /* (GLIDE_PLATFORM & GLIDE_OS_MACOS) */ - switch(writeMode) - { + switch(writeMode) { case GR_LFBWRITEMODE_RESERVED1: case GR_LFBWRITEMODE_RESERVED2: case GR_LFBWRITEMODE_RESERVED3: @@ -1155,34 +1144,32 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, } /* Default to hw */ - switch(gc->grPixelFormat) - { - case GR_PIXFMT_ARGB_1555: - case GR_PIXFMT_AA_2_ARGB_1555: - case GR_PIXFMT_AA_4_ARGB_1555: - case GR_PIXFMT_AA_8_ARGB_1555: /* 8xaa */ - fbMode = GR_LFBWRITEMODE_1555; - depthMode = GR_LFBWRITEMODE_ZA16; - break; - case GR_PIXFMT_ARGB_8888: - case GR_PIXFMT_AA_2_ARGB_8888: - case GR_PIXFMT_AA_4_ARGB_8888: - case GR_PIXFMT_AA_8_ARGB_8888: /* 8xaa */ - fbMode = GR_LFBWRITEMODE_8888; - depthMode = GR_LFBWRITEMODE_Z32; - break; - case GR_PIXFMT_RGB_565: - case GR_PIXFMT_AA_2_RGB_565: - case GR_PIXFMT_AA_4_RGB_565: - case GR_PIXFMT_AA_8_RGB_565: /* 8xaa */ - default: - fbMode = GR_LFBWRITEMODE_565; - depthMode = GR_LFBWRITEMODE_ZA16; - break; + switch(gc->grPixelFormat) { + case GR_PIXFMT_ARGB_1555: + case GR_PIXFMT_AA_2_ARGB_1555: + case GR_PIXFMT_AA_4_ARGB_1555: + case GR_PIXFMT_AA_8_ARGB_1555: /* 8xaa */ + fbMode = GR_LFBWRITEMODE_1555; + depthMode = GR_LFBWRITEMODE_ZA16; + break; + case GR_PIXFMT_ARGB_8888: + case GR_PIXFMT_AA_2_ARGB_8888: + case GR_PIXFMT_AA_4_ARGB_8888: + case GR_PIXFMT_AA_8_ARGB_8888: /* 8xaa */ + fbMode = GR_LFBWRITEMODE_8888; + depthMode = GR_LFBWRITEMODE_Z32; + break; + case GR_PIXFMT_RGB_565: + case GR_PIXFMT_AA_2_RGB_565: + case GR_PIXFMT_AA_4_RGB_565: + case GR_PIXFMT_AA_8_RGB_565: /* 8xaa */ + default: + fbMode = GR_LFBWRITEMODE_565; + depthMode = GR_LFBWRITEMODE_ZA16; + break; } - if (writeMode == GR_LFBWRITEMODE_ANY) - { + if (writeMode == GR_LFBWRITEMODE_ANY) { writeMode = (((buffer == GR_BUFFER_AUXBUFFER) || (buffer == GR_BUFFER_TEXTUREAUXBUFFER_EXT)) ? depthMode : fbMode); @@ -1191,18 +1178,16 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, #if (GLIDE_PLATFORM & GLIDE_OS_MACOS) && SET_BSWAP /* I'd do this in the switch() up above if writeMode wasn't being munged */ - switch(writeMode) - { + switch(writeMode) { case GR_LFBWRITEMODE_565: case GR_LFBWRITEMODE_555: case GR_LFBWRITEMODE_1555: case GR_LFBWRITEMODE_ZA16: - lfbMode |= SST_LFB_WRITE_SWAP16; + lfbMode |= SST_LFB_WRITE_SWAP16; } #endif /* (GLIDE_PLATFORM & GLIDE_OS_MACOS) */ - switch(buffer) - { + switch(buffer) { case GR_BUFFER_FRONTBUFFER: case GR_BUFFER_BACKBUFFER: /* tbext */ @@ -1220,40 +1205,38 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, default: GR_CHECK_F(myName, 1, "illegal buffer parameter passed"); + GR_RETURN(FXFALSE); break; } lfbMode |= (writeMode << SST_LFB_FORMAT_SHIFT); lfbMode |= (origin ? SST_LFB_YORIGIN : 0); - if (pixelPipeline) - { + if (pixelPipeline) { lfbMode |= SST_LFB_ENPIXPIPE; fbzMode &= ~SST_YORIGIN; fbzMode |= (origin ? SST_YORIGIN : 0); } + info->writeMode = writeMode; break; default: - rv = FXFALSE; GDBG_INFO(gc->myLevel, "Lock failed because of invalid lock type."); + GR_RETURN(FXFALSE); break; } } - if (rv) - { - const FxU32 - lockCount = gc->cmdTransportInfo.lfbLockCount; + if (rv) { + const FxU32 lockCount = gc->cmdTransportInfo.lfbLockCount; - gc->lockPtrs[type] = buffer; + gc->lockPtrs[((type == GR_LFB_WRITE_ONLY_EXPLICIT_EXT) ? GR_LFB_WRITE_ONLY : type)] = buffer; gc->cmdTransportInfo.lfbLockCount = 0x00UL; /* Setup the hw w/ the settings computed above. */ - switch(type) - { + switch(type) { case GR_LFB_READ_ONLY: /* I'm not sure why this is actually doing anything on UMA * architectures since reads are always done via direct LFB @@ -1264,6 +1247,7 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, break; case GR_LFB_WRITE_ONLY: + case GR_LFB_WRITE_ONLY_EXPLICIT_EXT: REG_GROUP_BEGIN(BROADCAST_ID, fbzMode, 3, 0x103); { REG_GROUP_SET(hw, fbzMode, fbzMode); @@ -1273,8 +1257,9 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, REG_GROUP_END(); break; } + gc->state.shadow.lfbMode = lfbMode; - + /* Get the current lfb buffer */ { /* FixMe: Is this true if we're triple buffering? */ @@ -1295,16 +1280,16 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, /* tbext */ case GR_BUFFER_TEXTUREBUFFER_EXT: - if ( gc->textureBuffer.on ) - { + if ( gc->textureBuffer.on ) { + } else { colBufferIndex = gc->backBuffer; } break; case GR_BUFFER_TEXTUREAUXBUFFER_EXT: - if ( gc->textureAuxBuffer.on ) - { + if ( gc->textureAuxBuffer.on ) { + } else { colBufferIndex = gc->grColBuf; } @@ -1312,26 +1297,27 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, default: GR_CHECK_F(myName, 1, "illegal buffer parameter passed"); - rv = FXFALSE; + GR_RETURN(FXFALSE); break; } - if (rv) - { -#ifdef DRI_BUILD + if (rv) { + +#ifdef DRI_BUILD if (!colBufferIndex) { info->strideInBytes = driInfo.stride; } else { - info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; + info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; } -#else /* defined(DRI_BUILD) */ +#else /* defined(DRI_BUILD) */ /* * This is the default for 3D LFBs, * which are always 2048 pixels wide. */ - info->strideInBytes = 0x1000; -#endif /* defined(DRI_BUILD) */ - info->origin = origin; + info->strideInBytes = 0x1000; +#endif /* defined(DRI_BUILD) */ + + info->origin = origin; /* tbext. Kind of ugly. Kind of duplicate / unfolded code ** needs checking before collapsing @@ -1343,57 +1329,51 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, ** the application that makes a grlfblock IS ACTUALLY USING (OR HAS TO USE) ** the tiled stride to be able to access the supposedly LINEAR lfb space... */ - if ( gc->textureBuffer.on && - ( buffer == GR_BUFFER_TEXTUREBUFFER_EXT || buffer == GR_BUFFER_TEXTUREAUXBUFFER_EXT )) - { - if (type == GR_LFB_READ_ONLY) - { - info->lfbPtr = (void *)((FxU32)gc->rawLfb + gc->textureBuffer.addr); - info->strideInBytes = gc->textureBuffer.stride ; + if(gc->textureBuffer.on && + (buffer == GR_BUFFER_TEXTUREBUFFER_EXT || buffer == GR_BUFFER_TEXTUREAUXBUFFER_EXT)) { + if(type == GR_LFB_READ_ONLY) { + info->lfbPtr = (void *)((FxU32)gc->rawLfb + gc->textureBuffer.addr); + info->strideInBytes = gc->textureBuffer.stride; #if __POWERPC__ if(IS_NAPALM(gc->bInfo->pciInfo.deviceID)) { if(gc->grPixelSize == 2) { - info->lfbPtr = (void *)((FxU32)info->lfbPtr + gc->bInfo->pciInfo.swizzleOffset[3]); + info->lfbPtr = (void *)((FxU32)info->lfbPtr + gc->bInfo->pciInfo.swizzleOffset[3]); } else { - info->lfbPtr = (void *)((FxU32)info->lfbPtr + gc->bInfo->pciInfo.swizzleOffset[1]); + info->lfbPtr = (void *)((FxU32)info->lfbPtr + gc->bInfo->pciInfo.swizzleOffset[1]); } } -#endif +#endif } -#if !__POWERPC__ +#if !__POWERPC__ /* Next, If it is writeOnly and 565 and not pixelpipe, we just return the current buffer lfbPtr as the write ptr. This fixes those games that use the lfb write pointer to do lfb reads. --mikec */ - else if ((type == GR_LFB_WRITE_ONLY) && (!noRead) && - (writeMode == (FxI32)fbMode) && - (!pixelPipeline) && - /* Origin must be upper left since we will return raw lfb */ - (origin != GR_ORIGIN_LOWER_LEFT)) - { - info->lfbPtr = (void *)((FxU32)gc->rawLfb + gc->textureBuffer.addr); - info->strideInBytes = gc->textureBuffer.stride ; - - } -#endif - else - { + else if((type == GR_LFB_WRITE_ONLY) && + (writeMode == (FxI32)fbMode) && + (!pixelPipeline) && + /* Origin must be upper left since we will return raw lfb */ + (origin != GR_ORIGIN_LOWER_LEFT)) { + info->lfbPtr = (void *)((FxU32)gc->rawLfb + gc->textureBuffer.addr); + info->strideInBytes = gc->textureBuffer.stride; + } +#endif + else { #ifdef DRI_BUILD /* * For DRI, we just return the correct address and * stride. */ - info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; + info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; info->lfbPtr = (void *)gc->lfbBuffers[colBufferIndex]; -#else /* defined(DRI_BUILD) */ +#else /* defined(DRI_BUILD) */ info->lfbPtr = (void *)gc->lfb_ptr; -#endif /* defined(DRI_BUILD) */ +#endif /* defined(DRI_BUILD) */ /* [dBorca] need to revise this */ #ifndef DRI_BUILD - switch (writeMode) - { - case GR_LFBWRITEMODE_565_DEPTH: + switch(writeMode) { + case GR_LFBWRITEMODE_565_DEPTH: case GR_LFBWRITEMODE_555_DEPTH: case GR_LFBWRITEMODE_1555_DEPTH: case GR_LFBWRITEMODE_888: @@ -1407,20 +1387,17 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, REG_GROUP_BEGIN(BROADCAST_ID, colBufferAddr, 2, 0x3); REG_GROUP_SET(hw, colBufferAddr, gc->textureBuffer.addr ); REG_GROUP_SET(hw, colBufferStride, gc->textureBuffer.stride ); - REG_GROUP_END(); - } - else /* else !gc->textureBuffer.on */ - { - if (type == GR_LFB_READ_ONLY) - { + REG_GROUP_END(); + } else { /* else !gc->textureBuffer.on */ + if(type == GR_LFB_READ_ONLY) { info->lfbPtr = (void *)gc->lfbBuffers[colBufferIndex]; -#if defined(DRI_BUILD) - if (colBufferIndex == 0) { - info->strideInBytes = driInfo.stride; +#ifdef DRI_BUILD + if(!colBufferIndex) { + info->strideInBytes = driInfo.stride; } else #endif /* defined(DRI_BUILD) */ - info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; - + info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; + #if __POWERPC__ if(IS_NAPALM(gc->bInfo->pciInfo.deviceID)) { if(gc->grPixelSize == 2) { @@ -1429,9 +1406,9 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, info->lfbPtr = (void *)((FxU32)info->lfbPtr + gc->bInfo->pciInfo.swizzleOffset[1]); } } -#endif +#endif } -#if !__POWERPC__ +#if !__POWERPC__ /* Next, If it is writeOnly and 565 (or matches the FB format exactly) and not pixelpipe, we just return the current buffer lfbPtr as the write ptr. This fixes those games that use the lfb write pointer to do @@ -1440,23 +1417,20 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, * take both a read and write lock, but only save off the stride value * from the latter one. So if we return different strides OpenGL's lfb * accesses will be whacked. -- KCD */ - else if ((type == GR_LFB_WRITE_ONLY) && (!noRead) && + else if ((type == GR_LFB_WRITE_ONLY) && (writeMode == fbMode) && (!pixelPipeline) && /* Origin must be upper left since we will return raw lfb */ - (origin != GR_ORIGIN_LOWER_LEFT)) - { - info->lfbPtr = (void *)gc->lfbBuffers[colBufferIndex]; - info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; + (origin != GR_ORIGIN_LOWER_LEFT)) { + info->lfbPtr = (void *)gc->lfbBuffers[colBufferIndex]; + info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; gc->state.shadow.colBufferAddr = gc->buffers0[colBufferIndex]; } #endif - else - { + else { gc->state.shadow.colBufferAddr = gc->buffers0[colBufferIndex]; /* tbext */ - if ( gc->textureBuffer.on ) - { + if ( gc->textureBuffer.on ) { REG_GROUP_BEGIN(BROADCAST_ID, colBufferAddr, 2, 0x3); REG_GROUP_SET(hw, colBufferAddr, gc->buffers0[colBufferIndex]); REG_GROUP_SET(hw, colBufferStride,gc->state.shadow.colBufferStride); @@ -1464,9 +1438,8 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, /* %%KCD - Make sure we don't program the colBufferAddr to point to * the AUX buffer if the user is trying to do pixel pipe writes to * the AUX buffer! */ - } - else if (colBufferIndex < (FxU32)gc->grColBuf) - { + } + else if (colBufferIndex < (FxU32)gc->grColBuf) { GR_SET_EXPECTED_SIZE(sizeof(FxU32), 1); GR_SET(BROADCAST_ID, hw, colBufferAddr, gc->buffers0[colBufferIndex]); GR_CHECK_SIZE(); @@ -1475,12 +1448,12 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, /* Make sure dither rotation is disabled for 3D LFBs. */ _3dlfb = FXTRUE; -#if defined(DRI_BUILD) +#ifdef DRI_BUILD /* * For DRI, we just return the correct address and * stride. */ - info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; + info->strideInBytes = gc->bInfo->buffInfo.bufLfbStride; info->lfbPtr = (void *)gc->lfbBuffers[colBufferIndex]; #else /* defined(DRI_BUILD) */ info->lfbPtr = (void *)gc->lfb_ptr; @@ -1488,8 +1461,7 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, /* [dBorca] need to revise this */ #ifndef DRI_BUILD - switch (writeMode) - { + switch(writeMode) { case GR_LFBWRITEMODE_565_DEPTH: case GR_LFBWRITEMODE_555_DEPTH: case GR_LFBWRITEMODE_1555_DEPTH: @@ -1507,8 +1479,7 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, /* SLI Effage. It seems that in order for flipped LFBs to work right, * we have to have renderMode set up the same way rendering would want it, * otherwise bad stuff happens. */ - if(IS_NAPALM(gc->bInfo->pciInfo.deviceID)) - { + if(IS_NAPALM(gc->bInfo->pciInfo.deviceID)) { renderMode = gc->state.shadow.renderMode; fbzMode = gc->state.shadow.fbzMode; @@ -1523,8 +1494,7 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, } #endif - if (idleLockP) - { + if (idleLockP) { /* This is required to flush the write buffers before the * actual LFB accesses. */ @@ -1539,13 +1509,13 @@ static FxBool _grLfbLock (GrLock_t type, GrBuffer_t buffer, } /* Pray that no one makes any glide calls that touch the hardware... */ #ifdef FX_GLIDE_NAPALM + /* works only for minihwc with env FX_GLIDE_A0_READ_ABORT set. unused for linhwc. */ if(gc->sliCount > 1 && type == GR_LFB_READ_ONLY) hwcSLIReadEnable(gc->bInfo); #endif #if LFB_DISABLE_SLAVE_FIFO /* Disable slave command FIFO */ - if(gc->chipCount > 1) - { + if(gc->chipCount > 1) { FxU32 depth; do { depth = GR_SLAVE_CAGP_GET(0, depth); @@ -1578,7 +1548,7 @@ GR_ENTRY(grLfbLock, FxBool,(GrLock_t _type, GrBuffer_t buffer, { #define FN_NAME "grLfbLock" FxBool rv = FXTRUE; - FxBool wantHwc; + FxBool wantHwc = FXFALSE; FxBool forbidden = FXFALSE; GrLock_t type; @@ -1594,50 +1564,32 @@ GR_ENTRY(grLfbLock, FxBool,(GrLock_t _type, GrBuffer_t buffer, type = _type & ~(GR_LFB_NOIDLE); if (gc->lockPtrs[type] != (FxU32)-1) { - GDBG_INFO(79, "Read lock failure due to existing lock"); - return FXFALSE; - } - - /* Ok, we will disallow all Hwc reads (regardless of what the app might want) */ - /* If we detect that the buffer is being locked far too much (aka a lock every frame) */ - if (_GlideRoot.environment.lockCounter > 3) - { - /* Disable HwcAAforLfbRead */ - if (_GlideRoot.environment.useHwcAAforLfbRead & 2) - { - _GlideRoot.environment.useHwcAAforLfbRead |= 4; - _GlideRoot.environment.useHwcAAforLfbRead &= ~2; - } - forbidden = FXTRUE; - } - /* Re-allow it if we drop back to 0 */ - else if ((_GlideRoot.environment.lockCounter) == -10 && (_GlideRoot.environment.useHwcAAforLfbRead & 4)) - { - /* Re-enable HwcAAforLfbRead */ - _GlideRoot.environment.useHwcAAforLfbRead |= 2; - _GlideRoot.environment.useHwcAAforLfbRead &= ~4; - forbidden = FXFALSE; + GDBG_INFO(79, "Read lock failure due to existing lock\n"); + GR_RETURN(FXFALSE); } - /* We want to read using HWC if we using FSAA with 4 chips or want dithering */ - /* or we are using forced 32 bit mode and want dithering */ - wantHwc = (_GlideRoot.environment.useHwcAAforLfbRead & 2) && - ((gc->state.forced32BPP != 0 && _GlideRoot.environment.ditherHwcAA) || - (gc->bInfo->h3pixelSample >= 2 && (gc->chipCount == 4 || _GlideRoot.environment.ditherHwcAA))); - - /* Incrememt the lockCounter */ - if (type == GR_LFB_READ_ONLY) _GlideRoot.environment.lockCounter++; +#if !(GLIDE_PLATFORM & GLIDE_OS_UNIX) /* fix me! */ + /* Read using HWC if we want dithering and using FSAA or 16 bpp mode */ + wantHwc = ((_GlideRoot.environment.useHwcAAforLfbRead & 2) && /* using HWC and */ + _GlideRoot.environment.ditherHwcAA && /* want dithering and */ + ((gc->bInfo->h3pixelSample > 1) || (gc->bInfo->h3pixelSize == 2))); /* using FSAA or 16 bit mode */ +#endif /* If we are using forced 32 bpp mode, the app is expecting 16 bit data */ /* Or we want to be using HwcAA for the Lfb read lock */ /* We need to use a hack for reading in OpenGL since they do 2 locks. Why, oh why, oh why...*/ - if (!forbidden && (gc->state.forced32BPP || wantHwc) && - (!_GlideRoot.environment.is_opengl || _GlideRoot.environment.oglLfbLockHack) && - (buffer == GR_BUFFER_FRONTBUFFER || buffer == GR_BUFFER_BACKBUFFER)) - { + if ((gc->state.forced32BPP || wantHwc) && /* using forced 32 bpp mode or using HWC and */ + (!_GlideRoot.environment.is_opengl || _GlideRoot.environment.oglLfbLockHack) && /* not OpenGL or using OpenGL lock hacks and */ + (buffer == GR_BUFFER_FRONTBUFFER || buffer == GR_BUFFER_BACKBUFFER)) /* is front or back buffer */ + { if (_GlideRoot.environment.is_opengl && type == GR_LFB_WRITE_ONLY && (gc->lockPtrs[GR_LFB_READ_ONLY] == (FxU32)buffer)) { + const FxU32 lockCount = gc->cmdTransportInfo.lfbLockCount; + GDBG_INFO_MORE(82,"OpenGL Locking forced 32bit->16bit hack(%d, %d)\n", _type, buffer); + + /* check if the buffer exists */ + if(!forced_32bpp_lock_buffer) GR_RETURN(FXFALSE); /* Now set the lock pointer */ gc->lockPtrs[type] = (FxU32) buffer; @@ -1647,13 +1599,17 @@ GR_ENTRY(grLfbLock, FxBool,(GrLock_t _type, GrBuffer_t buffer, info->writeMode = GR_LFBWRITEMODE_565; info->strideInBytes = gc->state.screen_width * 2; info->origin = origin; - + + gc->cmdTransportInfo.lfbLockCount = lockCount + 1; + GDBG_INFO_MORE(82,"OpenGL Locked forced hack (%d, %d)\n", _type, buffer); - return FXTRUE; + GR_RETURN(FXFALSE); } else if (type == GR_LFB_READ_ONLY) { + const FxU32 lockCount = gc->cmdTransportInfo.lfbLockCount; + /* Force origin */ /* origin = GR_ORIGIN_UPPER_LEFT; */ @@ -1670,15 +1626,13 @@ GR_ENTRY(grLfbLock, FxBool,(GrLock_t _type, GrBuffer_t buffer, /* Reset the useHwcAAforLfbRead setting */ _GlideRoot.environment.useHwcAAforLfbRead = old_useHwcAAforLfbRead; - - /* Increment the lock counter again */ - _GlideRoot.environment.lockCounter++; /* Failed to read */ if (!rv) { free (forced_32bpp_lock_buffer); - return FXFALSE; + forced_32bpp_lock_buffer = 0; + GR_RETURN(FXFALSE); } /* Now set the lock pointer */ @@ -1689,9 +1643,11 @@ GR_ENTRY(grLfbLock, FxBool,(GrLock_t _type, GrBuffer_t buffer, info->writeMode = GR_LFBWRITEMODE_565; info->strideInBytes = gc->state.screen_width * 2; info->origin = origin; + + gc->cmdTransportInfo.lfbLockCount = lockCount + 1; GDBG_INFO_MORE(82,"Locked forced (%d, %d)\n", _type, buffer); - return FXTRUE; + GR_RETURN(FXFALSE); } } @@ -1741,15 +1697,16 @@ static FxBool _grLfbUnlock (GrLock_t type, GrBuffer_t buffer) "Bad buffer"); rval = (gc->lockPtrs[type] == (FxU32)buffer); + if (rval) { - const FxU32 - lockCount = gc->cmdTransportInfo.lfbLockCount; + const FxU32 lockCount = gc->cmdTransportInfo.lfbLockCount; /* Clear the current lfb lock state */ gc->cmdTransportInfo.lfbLockCount = 0; gc->lockPtrs[type] = (FxU32)-1; #ifdef FX_GLIDE_NAPALM + /* works only for minihwc with env FX_GLIDE_A0_READ_ABORT set. unused for linhwc. */ if(gc->sliCount > 1 && type == GR_LFB_READ_ONLY) { hwcSLIReadDisable(gc->bInfo); } @@ -1803,16 +1760,18 @@ static FxBool _grLfbUnlock (GrLock_t type, GrBuffer_t buffer) _grEnableSliCtrl() ; } - gc->cmdTransportInfo.lfbLockCount = lockCount - 1; + if(lockCount) gc->cmdTransportInfo.lfbLockCount = lockCount - 1; #ifdef FX_GLIDE_NAPALM - if(gc->sliCount > 1) { + if(gc->sliCount > 1 && type == GR_LFB_READ_ONLY) { if(gc->cmdTransportInfo.lfbLockCount != 0) { grFinish(); - if(type == GR_LFB_READ_ONLY) hwcSLIReadEnable(gc->bInfo); + /* works only for minihwc with env FX_GLIDE_A0_READ_ABORT set. unused for linhwc. */ + hwcSLIReadEnable(gc->bInfo); } else { - if(type == GR_LFB_READ_ONLY) hwcSLIReadDisable(gc->bInfo); - } + /* works only for minihwc with env FX_GLIDE_A0_READ_ABORT set. unused for linhwc. */ + hwcSLIReadDisable(gc->bInfo); + } } #endif } @@ -1826,6 +1785,7 @@ GR_ENTRY(grLfbUnlock, FxBool, (GrLock_t _type, GrBuffer_t buffer)) { #define FN_NAME "grLfbUnlock" FxBool rval = FXFALSE; + FxBool wantHwc = FXFALSE; GrLock_t type; GR_BEGIN_NOFIFOCHECK_RET("grLfbUnLock", 83); @@ -1847,15 +1807,24 @@ GR_ENTRY(grLfbUnlock, FxBool, (GrLock_t _type, GrBuffer_t buffer)) buffer != GR_BUFFER_AUXBUFFER, "Bad buffer"); +#if !(GLIDE_PLATFORM & GLIDE_OS_UNIX) /* fix me! */ + /* Read using HWC if we want dithering and using FSAA or 16 bpp mode */ + wantHwc = ((_GlideRoot.environment.useHwcAAforLfbRead & 2) && /* using HWC and */ + _GlideRoot.environment.ditherHwcAA && /* want dithering and */ + ((gc->bInfo->h3pixelSample > 1) || (gc->bInfo->h3pixelSize == 2))); /* using FSAA or 16 bit mode */ +#endif + /* If we are using forced 32 bpp mode, the app is expecting 16 bit data */ /* Or we want to be using HwcAA for the Lfb read lock */ /* We need to use a hack for reading in OpenGL since they do 2 locks. Why, oh why, oh why...*/ - if ((gc->state.forced32BPP || _GlideRoot.environment.useHwcAAforLfbRead & 2) && + if ((gc->state.forced32BPP || wantHwc) && (!_GlideRoot.environment.is_opengl || _GlideRoot.environment.oglLfbLockHack) && (buffer == GR_BUFFER_FRONTBUFFER || buffer == GR_BUFFER_BACKBUFFER)) { if (_GlideRoot.environment.is_opengl && type == GR_LFB_WRITE_ONLY && (gc->lockPtrs[GR_LFB_READ_ONLY] == (FxU32)buffer)) { + const FxU32 lockCount = gc->cmdTransportInfo.lfbLockCount; + GDBG_INFO_MORE(82,"OpenGL UnLocking forced 32bit->16bit hack(%d, %d)\n", _type, buffer); // Not this buffer that is locked @@ -1863,6 +1832,8 @@ GR_ENTRY(grLfbUnlock, FxBool, (GrLock_t _type, GrBuffer_t buffer)) // Set unlocked gc->lockPtrs[type] = (FxU32) -1; + + if(lockCount) gc->cmdTransportInfo.lfbLockCount = lockCount - 1; GDBG_INFO_MORE(82,"OpenGL UnLocked forced hack (%d, %d)\n", _type, buffer); return FXTRUE; @@ -1870,6 +1841,8 @@ GR_ENTRY(grLfbUnlock, FxBool, (GrLock_t _type, GrBuffer_t buffer)) } else if (type == GR_LFB_READ_ONLY) { + const FxU32 lockCount = gc->cmdTransportInfo.lfbLockCount; + GDBG_INFO_MORE(82,"Unlocking forced (%d, %d)\n", _type, buffer); // Not this buffer that is locked @@ -1884,6 +1857,9 @@ GR_ENTRY(grLfbUnlock, FxBool, (GrLock_t _type, GrBuffer_t buffer)) // Free the buffer free (forced_32bpp_lock_buffer); forced_32bpp_lock_buffer = 0; + + if(lockCount) gc->cmdTransportInfo.lfbLockCount = lockCount - 1; + GDBG_INFO_MORE(82,"Unlocked forced (%d, %d)\n", _type, buffer); return FXTRUE; } @@ -2237,7 +2213,7 @@ static FxBool grLfbReadRegionOrigin (GrBuffer_t src_buffer, GrOriginLocation_t o #define FN_NAME "grLfbReadRegion" FxU32 bpp; FxBool rv; - FxBool wantHwc; + FxBool wantHwc = FXFALSE; GrLfbInfo_t info; GR_BEGIN_NOFIFOCHECK_RET("grLfbReadRegion",82); @@ -2257,191 +2233,191 @@ static FxBool grLfbReadRegionOrigin (GrBuffer_t src_buffer, GrOriginLocation_t o rv=FXFALSE; #if !(GLIDE_PLATFORM & GLIDE_OS_UNIX) /* [dBorca] fixme :D */ - /* We want to read using HWC if we using FSAA with 4 chips or want dithering */ - /* or we are using forced 32 bit mode and want dithering */ - wantHwc = (_GlideRoot.environment.useHwcAAforLfbRead & 1) && - ((gc->state.forced32BPP != 0 && _GlideRoot.environment.ditherHwcAA) || - (gc->bInfo->h3pixelSample >= 2 && (gc->chipCount == 4 || _GlideRoot.environment.ditherHwcAA))); - + /* Read using HWC if we want dithering and using FSAA or 16 bpp mode */ + wantHwc = ((_GlideRoot.environment.useHwcAAforLfbRead & 2) && /* using HWC and */ + _GlideRoot.environment.ditherHwcAA && /* want dithering and */ + ((gc->bInfo->h3pixelSample > 1) || (gc->bInfo->h3pixelSize == 2))); /* using FSAA or 16 bit mode */ + /* We want to use the 'advanced' and slow capture method */ - if (wantHwc) - { - FxU32 colBufferIndex = 0; - FxU32 bpp = 0; + if(wantHwc) { + FxU32 colBufferIndex = 0; + FxU32 bpp = 0; - if (gc->state.forced32BPP) bpp = gc->state.forced32BPP; - else switch(gc->grPixelFormat) - { - case GR_PIXFMT_ARGB_1555: - case GR_PIXFMT_AA_2_ARGB_1555: - case GR_PIXFMT_AA_4_ARGB_1555: - case GR_PIXFMT_AA_8_ARGB_1555: /* 8xaa */ - bpp = 15; - break; - case GR_PIXFMT_ARGB_8888: - case GR_PIXFMT_AA_2_ARGB_8888: - case GR_PIXFMT_AA_4_ARGB_8888: - case GR_PIXFMT_AA_8_ARGB_8888: /* 8xaa */ - bpp = 32; - break; - case GR_PIXFMT_RGB_565: - case GR_PIXFMT_AA_2_RGB_565: - case GR_PIXFMT_AA_4_RGB_565: - case GR_PIXFMT_AA_8_RGB_565: /* 8xaa */ - default: - bpp = 16; - break; - } - - switch(src_buffer) - { - case GR_BUFFER_FRONTBUFFER: - colBufferIndex = gc->frontBuffer; - break; + if(gc->state.forced32BPP) { + bpp = gc->state.forced32BPP; + } else { + switch(gc->grPixelFormat) { + case GR_PIXFMT_ARGB_1555: + case GR_PIXFMT_AA_2_ARGB_1555: + case GR_PIXFMT_AA_4_ARGB_1555: + case GR_PIXFMT_AA_8_ARGB_1555: /* 8xaa */ + bpp = 15; + break; + case GR_PIXFMT_ARGB_8888: + case GR_PIXFMT_AA_2_ARGB_8888: + case GR_PIXFMT_AA_4_ARGB_8888: + case GR_PIXFMT_AA_8_ARGB_8888: /* 8xaa */ + bpp = 32; + break; + case GR_PIXFMT_RGB_565: + case GR_PIXFMT_AA_2_RGB_565: + case GR_PIXFMT_AA_4_RGB_565: + case GR_PIXFMT_AA_8_RGB_565: /* 8xaa */ + default: + bpp = 16; + break; + } - case GR_BUFFER_BACKBUFFER: - colBufferIndex = gc->backBuffer; - break; - } + switch(src_buffer) { + case GR_BUFFER_FRONTBUFFER: + colBufferIndex = gc->frontBuffer; + break; - hwcAAReadRegion(gc->bInfo, colBufferIndex, src_x, src_y, - src_width, src_height, dst_stride, dst_data, - bpp, _GlideRoot.environment.ditherHwcAA); - rv=FXTRUE; - goto done; + case GR_BUFFER_BACKBUFFER: + colBufferIndex = gc->backBuffer; + break; + } + } + + hwcAAReadRegion(gc->bInfo, colBufferIndex, src_x, src_y, + src_width, src_height, dst_stride, dst_data, + bpp, _GlideRoot.environment.ditherHwcAA); + rv=FXTRUE; + goto done; } #endif if (_grLfbLock(GR_LFB_READ_ONLY, - src_buffer, - GR_LFBWRITEMODE_ANY, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) - { - FxU32 *src; - FxI32 len; + src_buffer, + GR_LFBWRITEMODE_ANY, + GR_ORIGIN_UPPER_LEFT, + FXFALSE, + &info)) { + FxU32 *src; + FxI32 len; #if 0 - FxU32 *dst; - FxU32 src_adjust,dst_adjust,tmp; + FxU32 *dst; + FxU32 src_adjust,dst_adjust,tmp; #endif - src=(FxU32 *) (((char*)info.lfbPtr)+ - (src_y*info.strideInBytes) + (src_x * bpp)); - len = src_width * bpp; + src=(FxU32 *) (((char*)info.lfbPtr)+ + (src_y*info.strideInBytes) + (src_x * bpp)); + len = src_width * bpp; - if (!gc->state.forced32BPP) { - if (_GlideRoot.CPUType.os_support & _CPU_FEATURE_MMX) { - do { - MMX_SRCLINE(src, dst_data, len); - /* adjust for next line */ - ((FxU8 *)src) += info.strideInBytes; - ((FxU8 *)dst_data) += dst_stride; - } while (--src_height); - MMX_RESET(); - } else { - do { - FPU_SRCLINE(src, dst_data, len); - /* adjust for next line */ - ((FxU8 *)src) += info.strideInBytes; - ((FxU8 *)dst_data) += dst_stride; - } while (--src_height); - } - goto okay; - } + if(!gc->state.forced32BPP) { + if(_GlideRoot.CPUType.os_support & _CPU_FEATURE_MMX) { + do { + MMX_SRCLINE(src, dst_data, len); + /* adjust for next line */ + ((FxU8 *)src) += info.strideInBytes; + ((FxU8 *)dst_data) += dst_stride; + } while (--src_height); + MMX_RESET(); + } else { + do { + FPU_SRCLINE(src, dst_data, len); + /* adjust for next line */ + ((FxU8 *)src) += info.strideInBytes; + ((FxU8 *)dst_data) += dst_stride; + } while (--src_height); + } + goto okay; + } #if 0 - dst=dst_data; + dst=dst_data; - /* set length - alignment fix*/ - tmp=(((FxU32)src)&2); - len -= tmp; - src_adjust=info.strideInBytes - tmp; - dst_adjust=dst_stride - tmp; + /* set length - alignment fix*/ + tmp=(((FxU32)src)&2); + len -= tmp; + src_adjust=info.strideInBytes - tmp; + dst_adjust=dst_stride - tmp; - /* should be endian and pixel size safe */ - /* it would be nice to test if quad blocks were faster */ - /* like mmx loads and stores */ - if (!gc->state.forced32BPP) while(src_height--) - { + /* should be endian and pixel size safe */ + /* it would be nice to test if quad blocks were faster */ + /* like mmx loads and stores */ + if(!gc->state.forced32BPP) { + while(src_height--) { /* adjust starting alignment */ - if (((FxU32)src)&3) - *((FxU16 *)dst)++=*((FxU16 *)src)++; + if (((FxU32)src)&3) { + *((FxU16 *)dst)++=*((FxU16 *)src)++; + } /* read in dwords of pixels */ - if(len) - { - FxU32 byte_index=0; - FxU32 aligned=len&(~3); + if(len) { + FxU32 byte_index=0; + FxU32 aligned=len&(~3); - /* copies aligned dwords */ - do - { - *((FxU32 *)(((FxU32)dst) + byte_index))=*((FxU32 *)(((FxU32)src) + byte_index)); - }while((byte_index+=4)state.forced32BPP == 16) while(src_height--) { - /* read in dwords of pixels */ - if(len) - { - FxU32 byte_index=0; - FxU32 byte_index2=0; + /* Nice I've got to convert it from 32 bit to 16 bit */ + else if(gc->state.forced32BPP == 16) { + while(src_height--) { + /* read in dwords of pixels */ + if(len) { + FxU32 byte_index=0; + FxU32 byte_index2=0; - /* copies aligned dwords */ - do - { - FxU32 s =*((FxU32 *)(((FxU32)src) + byte_index)); - FxU16 d = (FxU16) (s & 0xF8) >> 3; - d |= (s & 0xFC00) >> 5; - d |= (s & 0xF80000) >> 8; - *((FxU16 *)(((FxU32)dst_data) + (byte_index2))) = d; - byte_index +=4; - }while((byte_index2+=2)<(src_width*2)); - } - /* adjust for next line */ - ((FxU8 *)src)+=info.strideInBytes; - ((FxU8 *)dst_data) += dst_stride; - } - else if (gc->state.forced32BPP == 15) while(src_height--) { + /* copies aligned dwords */ + do { + FxU32 s =*((FxU32 *)(((FxU32)src) + byte_index)); + FxU16 d = (FxU16) (s & 0xF8) >> 3; + d |= (s & 0xFC00) >> 5; + d |= (s & 0xF80000) >> 8; + *((FxU16 *)(((FxU32)dst_data) + (byte_index2))) = d; + byte_index +=4; + } while((byte_index2+=2)<(src_width*2)); + } + + /* adjust for next line */ + ((FxU8 *)src)+=info.strideInBytes; + ((FxU8 *)dst_data) += dst_stride; + } + } else if (gc->state.forced32BPP == 15) { + while(src_height--) { + /* read in dwords of pixels */ + if(len) { + FxU32 byte_index=0; + FxU32 byte_index2=0; - /* read in dwords of pixels */ - if(len) - { - FxU32 byte_index=0; - FxU32 byte_index2=0; - - /* copies aligned dwords */ - do - { - FxU32 s =*((FxU32 *)(((FxU32)src) + byte_index)); - FxU16 d = (FxU16) (s & 0xF8) >> 3; - d |= (s & 0xF800) >> 6; - d |= (s & 0xF80000) >> 9; - *((FxU16 *)(((FxU32)dst_data) + (byte_index2))) = d; - byte_index +=4; - }while((byte_index2+=2)<(src_width*2)); - } - /* adjust for next line */ - ((FxU8 *)src)+=info.strideInBytes; - ((FxU8 *)dst_data) += dst_stride; - } + /* copies aligned dwords */ + do { + FxU32 s =*((FxU32 *)(((FxU32)src) + byte_index)); + FxU16 d = (FxU16) (s & 0xF8) >> 3; + d |= (s & 0xF800) >> 6; + d |= (s & 0xF80000) >> 9; + *((FxU16 *)(((FxU32)dst_data) + (byte_index2))) = d; + byte_index +=4; + } while((byte_index2+=2)<(src_width*2)); + } + + /* adjust for next line */ + ((FxU8 *)src)+=info.strideInBytes; + ((FxU8 *)dst_data) += dst_stride; + } + } okay: - rv=FXTRUE; - /* unlock buffer */ - _grLfbUnlock(GR_LFB_READ_ONLY,src_buffer); + rv=FXTRUE; + /* unlock buffer */ + _grLfbUnlock(GR_LFB_READ_ONLY,src_buffer); } + done: GR_RETURN(rv); } diff --git a/glide3x/h5/glide3/src/gpci.c b/glide3x/h5/glide3/src/gpci.c index 6e77bb3..e8ed691 100644 --- a/glide3x/h5/glide3/src/gpci.c +++ b/glide3x/h5/glide3/src/gpci.c @@ -1220,9 +1220,9 @@ _grSstDetectResources(void) /* Clear the tmu state */ for (tmu = 0; tmu < GC.num_tmu; tmu++) { - memset(&GC.tmu_state[0], 0, sizeof(GC.tmu_state[0])); - GC.tmu_state[0].total_mem = (0x2 << 20); - GC.tmu_state[0].ncc_mmids[0] = GC.tmu_state[0].ncc_mmids[1] = GR_NULL_MIPMAP_HANDLE; + memset(&GC.tmu_state[tmu], 0, sizeof(GC.tmu_state[0])); + GC.tmu_state[tmu].total_mem = (0x2 << 20); + GC.tmu_state[tmu].ncc_mmids[0] = GC.tmu_state[tmu].ncc_mmids[1] = GR_NULL_MIPMAP_HANDLE; } } /* iterate through boards found */ @@ -1738,7 +1738,12 @@ _GlideInitEnvironment(int which) ** AJB- This lets Joe bag-o-donuts force 32bpp & AA rendering ** for apps that call grSstWinOpen. */ - _GlideRoot.environment.outputBpp = GLIDE_GETENV("FX_GLIDE_BPP", GC.bInfo->RegPath, 0L) ; + _GlideRoot.environment.outputBpp = GLIDE_GETENV("FX_GLIDE_BPP", GC.bInfo->RegPath, 0L); + /* check for a valid value */ + if(_GlideRoot.environment.outputBpp != 32 || + _GlideRoot.environment.outputBpp != 15) { + _GlideRoot.environment.outputBpp = 0; + } /* Note- If the old school Glide env. vars for AA sample & Num chips * are active, they should ALWAYS override the control panel variable @@ -1808,8 +1813,8 @@ _GlideInitEnvironment(int which) _GlideRoot.environment.oglLfbLockHack = GLIDE_GETENV("FX_GL_LFBLOCK_HACK", GC.bInfo->RegPath, 1L) ; GDBG_INFO(80," oglLfbLockHack: %d\n",_GlideRoot.environment.oglLfbLockHack ); - /* 0 = None, 1 = grLfbReadRegion(), 2 = grLfbLock(), 3 = Both (default) */ - _GlideRoot.environment.useHwcAAforLfbRead = GLIDE_GETENV("FX_GLIDE_USE_HWC_AA_FOR_LFB_READ", GC.bInfo->RegPath, 3L) ; + /* 0 = None (default), 1 = grLfbReadRegion(), 2 = grLfbLock(), 3 = Both */ + _GlideRoot.environment.useHwcAAforLfbRead = GLIDE_GETENV("FX_GLIDE_USE_HWC_AA_FOR_LFB_READ", GC.bInfo->RegPath, 0L) ; GDBG_INFO(80," useHwcAAforLfbRead: %d\n",_GlideRoot.environment.useHwcAAforLfbRead ); /* 0 = No dithering when doing HWC AA dumps, 1 = error diffusion dithering enabled (default) */ diff --git a/glide3x/h5/glide3/src/gsfc.c b/glide3x/h5/glide3/src/gsfc.c index a82f725..5d33453 100644 --- a/glide3x/h5/glide3/src/gsfc.c +++ b/glide3x/h5/glide3/src/gsfc.c @@ -997,9 +997,9 @@ GR_EXT_ENTRY(grSurfaceCalcTextureWHD, FxBool , (GrTexInfo *tInfo, FxU32 *w, switch(tInfo->format) { case GR_TEXFMT_ARGB_CMP_FXT1: - case GR_TEXFMT_ARGB_CMP_DXT1: fmtType = 1; break; + case GR_TEXFMT_ARGB_CMP_DXT1: /* XXX check this! */ case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: diff --git a/glide3x/h5/glide3/src/gsfctabl.h b/glide3x/h5/glide3/src/gsfctabl.h index 01d3349..2a7d841 100644 --- a/glide3x/h5/glide3/src/gsfctabl.h +++ b/glide3x/h5/glide3/src/gsfctabl.h @@ -1204,8 +1204,8 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = }, }, }, - { /* FXT1, DXT1 texture format */ - { /* 8:1 aspect ratio; FXT1, DXT1 texture format */ + { /* FXT1 texture format */ + { /* 8:1 aspect ratio; FXT1 texture format */ { /* largeLod: 0 */ { 8, 4}, { 0, 0}, @@ -1375,7 +1375,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {2048, 256}, }, }, - { /* 4:1 aspect ratio; FXT1, DXT1 texture format */ + { /* 4:1 aspect ratio; FXT1 texture format */ { /* largeLod: 0 */ { 8, 4}, { 0, 0}, @@ -1475,7 +1475,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = { 0, 0}, }, { /* largeLod: 7 */ - { 128, 52},/* KoolSmoky - is this correct? */ + { 128, 52}, { 128, 48}, { 128, 48}, { 128, 48}, @@ -1545,7 +1545,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {2048, 512}, }, }, - { /* 2:1 aspect ratio; FXT1, DXT1 texture format */ + { /* 2:1 aspect ratio; FXT1 texture format */ { /* largeLod: 0 */ { 8, 4}, { 0, 0}, @@ -1715,7 +1715,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {2048,1024}, }, }, - { /* 1:1 aspect ratio; FXT1, DXT1 texture format */ + { /* 1:1 aspect ratio; FXT1 texture format */ { /* largeLod: 0 */ { 8, 4}, { 0, 0}, @@ -1885,7 +1885,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {2048,2048}, }, }, - { /* 1:2 aspect ratio; FXT1, DXT1 texture format */ + { /* 1:2 aspect ratio; FXT1 texture format */ { /* largeLod: 0 */ { 8, 4}, { 0, 0}, @@ -2055,7 +2055,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {1024,2048}, }, }, - { /* 1:4 aspect ratio; FXT1, DXT1 texture format */ + { /* 1:4 aspect ratio; FXT1 texture format */ { /* largeLod: 0 */ { 8, 4}, { 0, 0}, @@ -2225,7 +2225,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = { 512,2048}, }, }, - { /* 1:8 aspect ratio; FXT1, DXT1 texture format */ + { /* 1:8 aspect ratio; FXT1 texture format */ { /* largeLod: 0 */ { 8, 4}, { 0, 0}, @@ -2396,8 +2396,8 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = }, }, }, - { /* DXT2,3,4,5 texture format */ - { /* 8:1 aspect ratio; DXT2,3,4,5 texture format */ + { /* DXT1,2,3,4,5 texture format */ + { /* 8:1 aspect ratio; DXT1,2,3,4,5 texture format */ { /* largeLod: 0 */ { 4, 4}, { 0, 0}, @@ -2567,7 +2567,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {2048, 256}, }, }, - { /* 4:1 aspect ratio; DXT2,3,4,5 texture format */ + { /* 4:1 aspect ratio; DXT1,2,3,4,5 texture format */ { /* largeLod: 0 */ { 4, 4}, { 0, 0}, @@ -2667,7 +2667,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = { 0, 0}, }, { /* largeLod: 7 */ - { 128, 52}, /* KoolSmoky - is this correct? */ + { 128, 52}, { 128, 48}, { 128, 48}, { 128, 48}, @@ -2737,7 +2737,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {2048, 512}, }, }, - { /* 2:1 aspect ratio; DXT2,3,4,5 texture format */ + { /* 2:1 aspect ratio; DXT1,2,3,4,5 texture format */ { /* largeLod: 0 */ { 4, 4}, { 0, 0}, @@ -2907,7 +2907,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {2048,1024}, }, }, - { /* 1:1 aspect ratio; DXT2,3,4,5 texture format */ + { /* 1:1 aspect ratio; DXT1,2,3,4,5 texture format */ { /* largeLod: 0 */ { 4, 4}, { 0, 0}, @@ -3077,7 +3077,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {2048,2048}, }, }, - { /* 1:2 aspect ratio; DXT2,3,4,5 texture format */ + { /* 1:2 aspect ratio; DXT1,2,3,4,5 texture format */ { /* largeLod: 0 */ { 4, 4}, { 0, 0}, @@ -3247,7 +3247,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = {1024,2048}, }, }, - { /* 1:4 aspect ratio; DXT2,3,4,5 texture format */ + { /* 1:4 aspect ratio; DXT1,2,3,4,5 texture format */ { /* largeLod: 0 */ { 4, 4}, { 0, 0}, @@ -3417,7 +3417,7 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = { 512,2048}, }, }, - { /* 1:8 aspect ratio; DXT2,3,4,5 texture format */ + { /* 1:8 aspect ratio; DXT1,2,3,4,5 texture format */ { /* largeLod: 0 */ { 4, 4}, { 0, 0}, @@ -3517,11 +3517,11 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = { 0, 0}, }, { /* largeLod: 7 */ - { 16, 192}, - { 16, 192}, - { 16, 192}, - { 16, 192}, - { 16, 192}, + { 20, 192}, + { 20, 192}, + { 20, 192}, + { 20, 192}, + { 20, 192}, { 16, 192}, { 16, 192}, { 16, 128}, @@ -3531,11 +3531,11 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = { 0, 0}, }, { /* largeLod: 8 */ - { 48, 256}, - { 48, 256}, - { 48, 256}, - { 48, 256}, - { 48, 256}, + { 52, 256}, + { 52, 256}, + { 52, 256}, + { 52, 256}, + { 52, 256}, { 48, 256}, { 48, 256}, { 48, 256}, @@ -3545,11 +3545,11 @@ static const FxU16 boundingBoxWH[3][7][12][12][2] = { 0, 0}, }, { /* largeLod: 9 */ - { 112, 512}, - { 112, 512}, - { 112, 512}, - { 112, 512}, - { 112, 512}, + { 116, 512}, + { 116, 512}, + { 116, 512}, + { 116, 512}, + { 116, 512}, { 112, 512}, { 112, 512}, { 112, 512}, diff --git a/glide3x/h5/glide3/src/gsst.c b/glide3x/h5/glide3/src/gsst.c index 1aad201..b0d5ac8 100644 --- a/glide3x/h5/glide3/src/gsst.c +++ b/glide3x/h5/glide3/src/gsst.c @@ -1206,7 +1206,7 @@ initGC ( GrGC *gc ) #endif /* defined(DRI_BUILD) */ gc->backBuffer = (gc->grColBuf > 2) ? 2 : gc->curBuffer; - for (t = 0; t < 7; t++) { + for (t = 0; t < MAX_BUFF_PENDING; t++) { gc->bufferSwaps[t] = 0xffffffff; } @@ -1669,51 +1669,49 @@ GR_EXT_ENTRY(grSstWinOpenExt, GrContext_t, ( FxU32 hWnd, /* rendering since we don't want to scale down the */ /* apps Z or W values to fit in a 16 bit depth buffer. */ - if (_GlideRoot.environment.outputBpp == 32 || pixelformat == GR_PIXFMT_ARGB_8888) { - + if (_GlideRoot.environment.outputBpp == 32 || pixelformat == GR_PIXFMT_ARGB_8888) { // App requested 16 bit, but we are giving 32. Need to remember for framebuffer access - if (pixelformat == GR_PIXFMT_ARGB_1555 || pixelformat == GR_PIXFMT_AA_2_ARGB_1555 || - pixelformat == GR_PIXFMT_AA_4_ARGB_1555 || pixelformat == GR_PIXFMT_AA_8_ARGB_1555) { + if (pixelformat == GR_PIXFMT_ARGB_1555 || + pixelformat == GR_PIXFMT_AA_2_ARGB_1555 || + pixelformat == GR_PIXFMT_AA_4_ARGB_1555 || + pixelformat == GR_PIXFMT_AA_8_ARGB_1555) { gc->state.forced32BPP = 15; - } - else if (pixelformat == GR_PIXFMT_RGB_565 || pixelformat == GR_PIXFMT_AA_2_RGB_565 || - pixelformat == GR_PIXFMT_AA_4_RGB_565 || pixelformat == GR_PIXFMT_AA_8_RGB_565) { + } else if (pixelformat == GR_PIXFMT_RGB_565 || + pixelformat == GR_PIXFMT_AA_2_RGB_565 || + pixelformat == GR_PIXFMT_AA_4_RGB_565 || + pixelformat == GR_PIXFMT_AA_8_RGB_565) { gc->state.forced32BPP = 16; } - if ((_GlideRoot.environment.aaSample == 8) && /* 8xaa */ - (gc->chipCount > 2)) - pixelformat = GR_PIXFMT_AA_8_ARGB_8888 ; - else if ((_GlideRoot.environment.aaSample == 4) && - (gc->chipCount > 1)) - pixelformat = GR_PIXFMT_AA_4_ARGB_8888 ; - else if (_GlideRoot.environment.aaSample == 2) - pixelformat = GR_PIXFMT_AA_2_ARGB_8888 ; - else - pixelformat = GR_PIXFMT_ARGB_8888 ; - } - else if (_GlideRoot.environment.outputBpp == 15 || pixelformat == GR_PIXFMT_ARGB_1555) { - if ((_GlideRoot.environment.aaSample == 8) && /* 8xaa */ - (gc->chipCount > 2)) - pixelformat = GR_PIXFMT_AA_8_ARGB_1555 ; - else if ((_GlideRoot.environment.aaSample == 4) && - (gc->chipCount > 1)) - pixelformat = GR_PIXFMT_AA_4_ARGB_1555 ; - else if (_GlideRoot.environment.aaSample == 2) - pixelformat = GR_PIXFMT_AA_2_ARGB_1555 ; - else - pixelformat = GR_PIXFMT_ARGB_1555 ; - } - else if (pixelformat == GR_PIXFMT_RGB_565) { - if ((_GlideRoot.environment.aaSample == 8) && /* 8xaa */ - (gc->chipCount > 2)) + if ((_GlideRoot.environment.aaSample == 8) && /* 8xaa */ (gc->chipCount > 2)) { + pixelformat = GR_PIXFMT_AA_8_ARGB_8888; + } else if ((_GlideRoot.environment.aaSample == 4) && (gc->chipCount > 1)) { + pixelformat = GR_PIXFMT_AA_4_ARGB_8888; + } else if (_GlideRoot.environment.aaSample == 2) { + pixelformat = GR_PIXFMT_AA_2_ARGB_8888; + } else { + pixelformat = GR_PIXFMT_ARGB_8888; + } + } else if (_GlideRoot.environment.outputBpp == 15 || pixelformat == GR_PIXFMT_ARGB_1555) { + if ((_GlideRoot.environment.aaSample == 8) && /* 8xaa */ (gc->chipCount > 2)) { + pixelformat = GR_PIXFMT_AA_8_ARGB_1555; + } else if ((_GlideRoot.environment.aaSample == 4) && (gc->chipCount > 1)) { + pixelformat = GR_PIXFMT_AA_4_ARGB_1555; + } else if (_GlideRoot.environment.aaSample == 2) { + pixelformat = GR_PIXFMT_AA_2_ARGB_1555; + } else { + pixelformat = GR_PIXFMT_ARGB_1555; + } + } else if (pixelformat == GR_PIXFMT_RGB_565) { + if ((_GlideRoot.environment.aaSample == 8) && /* 8xaa */ (gc->chipCount > 2)) { pixelformat = GR_PIXFMT_AA_8_RGB_565; - else if ((_GlideRoot.environment.aaSample == 4) && - (gc->chipCount > 1)) - pixelformat = GR_PIXFMT_AA_4_RGB_565 ; - else - if (_GlideRoot.environment.aaSample == 2) - pixelformat = GR_PIXFMT_AA_2_RGB_565 ; + } else if ((_GlideRoot.environment.aaSample == 4) && (gc->chipCount > 1)) { + pixelformat = GR_PIXFMT_AA_4_RGB_565; + } else if (_GlideRoot.environment.aaSample == 2) { + pixelformat = GR_PIXFMT_AA_2_RGB_565; + } else { + pixelformat = GR_PIXFMT_RGB_565; + } } } @@ -3219,6 +3217,7 @@ GR_ENTRY(grSstWinClose, FxBool, (GrContext_t context)) } if (gc->sliCount > 1) _grDisableSliCtrl(); + /* Idle the 3D pipe. */ grFinish(); } diff --git a/glide3x/h5/glide3/src/gtex.c b/glide3x/h5/glide3/src/gtex.c index 7f7d5b2..e3129e6 100644 --- a/glide3x/h5/glide3/src/gtex.c +++ b/glide3x/h5/glide3/src/gtex.c @@ -702,12 +702,12 @@ _grTexCalcMipmapLevelOffsetTiled(GrChipID_t tmu, { switch(fmt) { case GR_TEXFMT_ARGB_CMP_FXT1: - case GR_TEXFMT_ARGB_CMP_DXT1: /* For these, we offset the LOD height * texture stride */ if (evenOdd & GR_MIPMAPLEVELMASK_ODD) { tileY += HEIGHT_BY_ASPECT_LOD_FXT1(aspect, GR_LOD_LOG2_16); } break; + case GR_TEXFMT_ARGB_CMP_DXT1: case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: @@ -732,12 +732,12 @@ _grTexCalcMipmapLevelOffsetTiled(GrChipID_t tmu, { switch(fmt) { case GR_TEXFMT_ARGB_CMP_FXT1: - case GR_TEXFMT_ARGB_CMP_DXT1: /* For these, we offset the LOD height * texture stride */ if (evenOdd & GR_MIPMAPLEVELMASK_EVEN) { tileY += HEIGHT_BY_ASPECT_LOD_FXT1(aspect, GR_LOD_LOG2_8); } break; + case GR_TEXFMT_ARGB_CMP_DXT1: case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: @@ -762,12 +762,12 @@ _grTexCalcMipmapLevelOffsetTiled(GrChipID_t tmu, { switch(fmt) { case GR_TEXFMT_ARGB_CMP_FXT1: - case GR_TEXFMT_ARGB_CMP_DXT1: /* For these, we offset the LOD height * texture stride */ if (evenOdd & GR_MIPMAPLEVELMASK_ODD) { tileY += HEIGHT_BY_ASPECT_LOD_FXT1(aspect, GR_LOD_LOG2_4); } break; + case GR_TEXFMT_ARGB_CMP_DXT1: case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: @@ -792,12 +792,12 @@ _grTexCalcMipmapLevelOffsetTiled(GrChipID_t tmu, { switch(fmt) { case GR_TEXFMT_ARGB_CMP_FXT1: - case GR_TEXFMT_ARGB_CMP_DXT1: /* For these, we offset the LOD height * texture stride */ if (evenOdd & GR_MIPMAPLEVELMASK_EVEN) { tileY += HEIGHT_BY_ASPECT_LOD_FXT1(aspect, GR_LOD_LOG2_2); } break; + case GR_TEXFMT_ARGB_CMP_DXT1: case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: @@ -2785,7 +2785,8 @@ GR_ENTRY(grTexSource, void, info->aspectRatioLog2, info->format, evenOdd, - FXTRUE) + FXTRUE, + FXFALSE) > gc->tmu_state[tmu].total_mem)), "insufficient texture ram at startAddress"); GR_CHECK_F(FN_NAME, evenOdd > 0x3 || evenOdd == 0, "evenOdd mask invalid"); @@ -3495,7 +3496,8 @@ GR_DIENTRY(grTextureBuffer, void, else offset = _grTexTextureMemRequired( thisLOD+1, largeLOD, aspectRatio, format, - odd_even_mask, FXTRUE); + odd_even_mask, FXTRUE, + FXFALSE ); /* How do we deal with UMA? The tmu only makes sense when the UMA is not turned on. @@ -3594,7 +3596,8 @@ GR_DIENTRY(grTextureAuxBuffer, void, else offset = _grTexTextureMemRequired( thisLOD+1, largeLOD, aspectRatio, format, - odd_even_mask, FXTRUE); + odd_even_mask, FXTRUE, + FXFALSE ); /* How do we deal with UMA? The tmu only makes sense when the UMA is not turned on. diff --git a/glide3x/h5/glide3/src/gtexdl.c b/glide3x/h5/glide3/src/gtexdl.c index 63d4948..887861f 100644 --- a/glide3x/h5/glide3/src/gtexdl.c +++ b/glide3x/h5/glide3/src/gtexdl.c @@ -731,57 +731,26 @@ _grTexDownloadMipMapLevelPartialTiled(GrChipID_t tmu, const FxU32 texelSize = _grBitsPerTexel[format], texStrideBytes = memInfo->texStrideBytes; - FxU32 minS = 0, maxS = 0; + FxU32 maxS = 0; FxU32 texOffset = 0x00UL; switch(format) { case GR_TEXFMT_ARGB_CMP_FXT1: - minS = 0; - if (!maxS) maxS = WIDTH_BY_ASPECT_LOD_FXT1(aspectRatio, thisLod); - else if (maxS < 8) maxS = 8; + maxS = WIDTH_BY_ASPECT_LOD_FXT1(aspectRatio, thisLod); break; case GR_TEXFMT_ARGB_CMP_DXT1: - minS = 0; - if (!maxS) maxS = WIDTH_BY_ASPECT_LOD_DXT(aspectRatio, thisLod); - else if (maxS < 8) maxS = 4; - break; case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: case GR_TEXFMT_ARGB_CMP_DXT5: - minS = 0; - if (!maxS) maxS = WIDTH_BY_ASPECT_LOD_DXT(aspectRatio, thisLod); - else if (maxS < 8) maxS = 4; + maxS = WIDTH_BY_ASPECT_LOD_DXT(aspectRatio, thisLod); break; default: - if (!maxS) maxS = WIDTH_BY_ASPECT_LOD(aspectRatio, thisLod); - - // 32bit Align minS - if (texelSize == 8) minS &= 4; - else if (texelSize == 16) minS &= 2; - - maxS -= minS; - - // 32bit Align maxS, and add minS to offset - if (texelSize == 8) - { - if (maxS>4) maxS = (maxS+3)&4; - texOffset+=minS; - } - else if (texelSize == 16) - { - if (maxS>2) maxS = (maxS+1)&2; - texOffset+=minS*2; - } - else - { - texOffset+=minS*4; - } + maxS = WIDTH_BY_ASPECT_LOD(aspectRatio, thisLod); break; } - data = texOffset+(char*)data; - if (thisLod < largeLod) { + if (thisLod < largeLod) { texOffset = _grTexCalcMipmapLevelOffsetTiled(tmu, thisLod, largeLod, aspectRatio, @@ -789,7 +758,8 @@ _grTexDownloadMipMapLevelPartialTiled(GrChipID_t tmu, evenOdd, NULL, NULL); - } + } + texOffset += memInfo->tramLfbAddr; GR_CHECK_F(FN_NAME, texelSize == 0, "invalid texture format"); @@ -797,20 +767,18 @@ _grTexDownloadMipMapLevelPartialTiled(GrChipID_t tmu, switch(texelSize) { case 4: /* 4-bit textures */ { - const FxU32 - *src32 = (const FxU32*)data; switch(maxS) { - case 4: -#if 0 /* come back to this !!!! */ + case 4: /* XXX need to test! */ { - const FxU16 - *src16 = (const FxU16*)data; + const FxU16 *src16 = (const FxU16*)data; src16++; for(; t <= maxT; t+=4) { FxU32 - texAddress = texOffset + t * texStrideBytes, s; + texAddress = texOffset + t * texStrideBytes, + s; + LINEAR_WRITE_BEGIN(2, SSTCP_PKT5_LFB, texAddress, 0x00UL, 0x00UL); for (s = 0; s < 2; s++) { LINEAR_WRITE_SET(texAddress, (FxU32)(*src16)); @@ -821,10 +789,11 @@ _grTexDownloadMipMapLevelPartialTiled(GrChipID_t tmu, } } -#endif break; case 8: { + const FxU32 *src32 = (const FxU32*)data; + texOffset += (t * texStrideBytes); for (; t <= maxT; t++) { LINEAR_WRITE_BEGIN(1, SSTCP_PKT5_LFB, texOffset, 0x0UL, 0x0UL); @@ -837,6 +806,8 @@ _grTexDownloadMipMapLevelPartialTiled(GrChipID_t tmu, break; default: { + const FxU32 *src32 = (const FxU32*)data; + for (; t <= maxT; t++) { FxU32 texAddress = texOffset + t * texStrideBytes, @@ -910,7 +881,7 @@ _grTexDownloadMipMapLevelPartialTiled(GrChipID_t tmu, case 16: /* 16-bit textures */ { const FxU16 - *src16 = minS + (const FxU16*)data; + *src16 = (const FxU16*)data; switch(maxS) { case 1: @@ -1063,7 +1034,8 @@ GR_ENTRY(grTexDownloadMipMapLevelPartial, (startAddress + _grTexTextureMemRequired(thisLod, largeLod, aspectRatio, format, evenOdd, - FXTRUE) + FXTRUE, + FXFALSE) > gc->tmu_state[tmu].total_mem)), "insufficient texture ram at startAddress"); GR_CHECK_F(FN_NAME, startAddress & SST_TEXTURE_ALIGN_MASK, @@ -1105,11 +1077,11 @@ GR_ENTRY(grTexDownloadMipMapLevelPartial, #ifdef FX_GLIDE_NAPALM switch(format) { case GR_TEXFMT_ARGB_CMP_FXT1: - case GR_TEXFMT_ARGB_CMP_DXT1: GR_CHECK_F(FN_NAME, max_t >= _grMipMapHostWHCmp4Bit[G3_ASPECT_TRANSLATE(aspectRatio)] [thisLod][1], "invalid end row for fxt1, dxt1"); break; + case GR_TEXFMT_ARGB_CMP_DXT1: case GR_TEXFMT_ARGB_CMP_DXT2: case GR_TEXFMT_ARGB_CMP_DXT3: case GR_TEXFMT_ARGB_CMP_DXT4: @@ -1188,9 +1160,9 @@ GR_ENTRY(grTexDownloadMipMapLevelPartial, * restriction. * same for DXT1 ((4x4x1/2)x2) minimum level size is 16 bytes */ - if(format != GR_TEXFMT_ARGB_CMP_FXT1 && format != GR_TEXFMT_ARGB_CMP_DXT1 && - format != GR_TEXFMT_ARGB_CMP_DXT2 && format != GR_TEXFMT_ARGB_CMP_DXT3 && - format != GR_TEXFMT_ARGB_CMP_DXT4 && format != GR_TEXFMT_ARGB_CMP_DXT5 ) { + if(format != GR_TEXFMT_ARGB_CMP_FXT1 && format != GR_TEXFMT_ARGB_CMP_DXT1 && + format != GR_TEXFMT_ARGB_CMP_DXT2 && format != GR_TEXFMT_ARGB_CMP_DXT3 && + format != GR_TEXFMT_ARGB_CMP_DXT4 && format != GR_TEXFMT_ARGB_CMP_DXT5 ) { const FxU32 aspectIndex = ((aspectRatio < GR_ASPECT_LOG2_1x1) ? -aspectRatio @@ -1243,6 +1215,7 @@ GR_ENTRY(grTexDownloadMipMapLevelPartial, aspectRatio, format, evenOdd, + FXFALSE, FXFALSE); } }