📄 vgpcommon.c
字号:
/*****************************************************************************
Name : vgpcommon.c
Title : VGP functions common to VGP and VGP lite
C Author : Imagination Technologies
Created : 22/4/2004
Copyright : 2004 by Imagination Technologies Limited. All rights reserved.
No part of this software, either material or conceptual
may be copied or distributed, transmitted, transcribed,
stored in a retrieval system or translated into any
human or computer language in any form by any means,
electronic, mechanical, manual or other-wise, or
disclosed to third parties without the express written
permission of Imagination Technologies Limited, HomePark
Industrial Estate, King's Langley, Hertfordshire,
WD4 8LZ, U.K.
Description : VGP functions common to VGP and VGP lite
Program Type : 32-bit DLL
Version : $Revision: 1.3 $
Modifications :
$Log: vgpcommon.c $
*****************************************************************************/
#include "context.h"
#if defined(SUPPORT_VGP) || defined(SUPPORT_VGP_LITE)
#include "vgp.c"
#include "vgplite.c"
/*****************************************************************************
FUNCTION : SetupVertexCopyData
PURPOSE : Sets up data copy function flags and sets correct input format
in TA state control
PARAMETERS : psIFDef - VGP input format definition structure
RETURNS : void
****************************************************************************/
IMG_VOID SetupVertexCopyData(LPD3DM_CONTEXT psContext, PVSIFDEF psIFDef)
{
VTXCOMPONENT *psComponents = &psIFDef->psComponents[0];
/*
If we have more than one component per vertex
assume each vertex is non contgious
*/
if(psIFDef->dwNumComponents == 1)
{
if(psIFDef->dwStride == psComponents[0].dwSize)
{
#if defined (FIX_HW_PRN_725_MBXLITE)
IMG_UINT32 ui32ISPTSPCtl = psContext->sHWState.sTACtl3DState.dwISPTSPCtl;
if((ui32ISPTSPCtl & MBX1_ISPTSPCTL_OFFSET) &&
((ui32ISPTSPCtl & MBX1_ISPTSPCTL_UVCOUNT) >> MBX1_ISPTSPCTL_UVCOUNTSHIFT) == 1)
{
/*
We have an offset colour and 2 sets of tex coords so
we need to limit strip length. We can't do this with
block copy so set to copy vertex by vertex
*/
#if defined (FIX_HW_PRN_721)
if(psIFDef->eDataFormat == FFVTX_DATA_FMT_FIXED)
{
/* treat components individually */
psContext->eCopyFn = COPY_FUNC_COPY_COMPONENTS;
}
else
#else
{
psContext->eCopyFn = COPY_FUNC_COPY_VERTICES;
}
#endif
}
else
#endif
{
/* 1 component with size matching stride */
psContext->eCopyFn = COPY_FUNC_BLOCK_COPY;
}
}
else
{
#if defined (FIX_HW_PRN_721)
if(psIFDef->eDataFormat == FFVTX_DATA_FMT_FIXED)
{
/* treat components individually */
psContext->eCopyFn = COPY_FUNC_COPY_COMPONENTS;
}
else
#else
{
/* 1 component but not contiguous */
psContext->eCopyFn = COPY_FUNC_COPY_VERTICES;
}
#endif
}
}
else
{
/* treat components individually */
psContext->eCopyFn = COPY_FUNC_COPY_COMPONENTS;
}
/* Set Input data format */
switch(psIFDef->eDataFormat)
{
case FFVTX_DATA_FMT_FIXED:
{
psContext->sHWState.sTACtl3DState.dwFPFormat = MBX1_TAFPFORMAT_TYPEFIXEDPOINT | (0x00000010);
break;
}
case FFVTX_DATA_FMT_FLOAT:
case FFVTX_DATA_FMT_MIXED:
{
psContext->sHWState.sTACtl3DState.dwFPFormat = MBX1_TAFPFORMAT_TYPEIEEEFLOAT;
break;
}
}
/* Flag that format has changed */
psContext->sHWStateCtl.dwTACtl3DStateChanged |= MBX1_TASTATEPRES_FP_INPUTFORMAT;
}
/*****************************************************************************
FUNCTION : PostProcessComponents
PURPOSE : Determines data format of Vertex buffer and coalesces
componenets where possible
PARAMETERS : psVSIFDef - VGP input format definition structure
RETURNS : void
****************************************************************************/
IMG_VOID PostProcessComponents(PVSIFDEF psVSIFDef)
{
PVTXCOMPONENT psComponent = psVSIFDef->psComponents;
IMG_UINT32 dwNumComponents = psVSIFDef->dwNumComponents;
IMG_UINT32 j, i;
IMG_BOOL bFixedPresent = IMG_FALSE;
IMG_BOOL bFloatPresent = IMG_FALSE;
psVSIFDef->bColourPresent = IMG_FALSE;
for(i=0; i<dwNumComponents; i++)
{
/* Check for overall vertex format */
if(psComponent[i].dwVGPIFReg != FFVTXCOMPONENT_INPUTREG_DIFFUSE &&
psComponent[i].dwVGPIFReg != FFVTXCOMPONENT_INPUTREG_SPECULAR)
{
if(psComponent[i].bFixedPoint)
{
bFixedPresent = IMG_TRUE;
}
else
{
bFloatPresent = IMG_TRUE;
}
}
else
{
psVSIFDef->bColourPresent = IMG_TRUE;
}
}
/* Set data type flag */
if(bFixedPresent && !bFloatPresent)
{
psVSIFDef->eDataFormat = FFVTX_DATA_FMT_FIXED;
}
else if(!bFixedPresent && bFloatPresent)
{
psVSIFDef->eDataFormat = FFVTX_DATA_FMT_FLOAT;
}
else
{
/* Vertex contains fixed and float so we cannot coalesce */
psVSIFDef->eDataFormat = FFVTX_DATA_FMT_MIXED;
return;
}
if(dwNumComponents == 1)
{
return;
}
#if defined (FIX_HW_PRN_721)
if(psVSIFDef->bColourPresent && (psVSIFDef->eDataFormat == FFVTX_DATA_FMT_FIXED))
{
/* We need to clamp non colour components so don't coalesce*/
return;
}
#endif
/* try to coalesce components (j ahead of i) */
for (i=0, j=1; j<dwNumComponents; j++)
{
if((psComponent[i].dwOffset + psComponent[i].dwSize) == psComponent[j].dwOffset)
{
/* comps contiguous: add comp(j) to comp(i) */
psComponent[i].dwSize += psComponent[j].dwSize;
}
else
{
/*
comps not contiguous:
move i to next free slot and copy the current j to i
*/
psComponent[++i] = psComponent[j];
}
}
/* write back new component count */
psVSIFDef->dwNumComponents = i + 1;
return;
}
/*****************************************************************************
FUNCTION : VSIFDefSetupForFVF
PURPOSE : Configures vertex-shader input-definition data for use with
FVF-type vertex-data, sourced from stream 0 only. FVF vertex-data
is only used with the 'passthrough' or fixed-function TNL code.
For both cases, the 8 VGP input registers are used as follows:
Register Component(s) IF Type (see MBX1_VGPIFDEF_SREG_xxx)
------------------------------------------------------------------
0 X,Y,Z 3D_FLOAT
0 X,Y,Z,RHW 4D_FLOAT
3 Normal 3D_FLOAT
4 Diffuse colour 4D_ARGB
5 Specular colour 4D_ARGB
6 Tex-coord set 0 1/2/3/4D_FLOAT
7 Tex-coord set 1 1/2/3/4D_FLOAT
These are fixed mappings (i.e. Diffuse-colour will always be
taken from register 4, irrespective of the preceeding vertex
components present/absent). For missing vertex-data, the
corresponding register input-format will be set to 'not-present'.
Point-size is not supported by MBX1, and is skipped.
PARAMETERS : psVSIFDef - The vertex-shader input-definition to setup
dwFVFCode - The FVF code indicating which vertex-components
are present
RETURNS : BOOL - TRUE if the FVF could be supported
*****************************************************************************/
BOOL VSIFDefSetupForFVF(LPD3DM_CONTEXT psContext, PVSIFDEF psVSIFDef, DWORD dwFVFCode, DWORD dwVertexStride)
{
PVTXCOMPONENT psComponent;
DWORD dwCoordSetCount;
DWORD dwVtxSize;
DWORD dwVGPIFDef;
DWORD dwVGPIFType;
DWORD dwVGPIFReg;
DWORD dwVGPIFShift;
DWORD dwOffsetSize;
DWORD dwComponentSize;
DWORD dwComponentOffset;
DWORD dwFFComponentType;
DWORD dwFFComponents;
DWORD i;
IMG_BOOL bFixedPoint = IMG_FALSE;
// DPFL3("VSIFDefSetupForFVF: FVF-code 0x%X (%hs)", dwFVFCode, DBG_FVF(dwFVFCode));
dwVtxSize = 0;
dwFFComponents = 0;
dwComponentOffset = 0;
psComponent = psVSIFDef->psComponents;
/*
setup stride of vertex
*/
psVSIFDef->dwStride = dwVertexStride;
/*
Default VGP input-format definition to 'all unused'
*/
dwVGPIFDef = (MBX1_VGPIFDEF_SREG_NOTPRES << MBX1_VGPIFDEF_SREG0_SHIFT) |
(MBX1_VGPIFDEF_SREG_NOTPRES << MBX1_VGPIFDEF_SREG1_SHIFT) |
(MBX1_VGPIFDEF_SREG_NOTPRES << MBX1_VGPIFDEF_SREG2_SHIFT) |
(MBX1_VGPIFDEF_SREG_NOTPRES << MBX1_VGPIFDEF_SREG3_SHIFT) |
(MBX1_VGPIFDEF_SREG_NOTPRES << MBX1_VGPIFDEF_SREG4_SHIFT) |
(MBX1_VGPIFDEF_SREG_NOTPRES << MBX1_VGPIFDEF_SREG5_SHIFT) |
(MBX1_VGPIFDEF_SREG_NOTPRES << MBX1_VGPIFDEF_SREG6_SHIFT) |
(MBX1_VGPIFDEF_SREG_NOTPRES << MBX1_VGPIFDEF_SREG7_SHIFT);
/*
Determine what position data is present (cannot be absent)
*/
switch (dwFVFCode & D3DMFVF_POSITION_MASK)
{
case D3DMFVF_XYZ_FIXED:
{
bFixedPoint = IMG_TRUE;
}
case D3DMFVF_XYZ_FLOAT:
{
/*
XYZ component present. Read as 3-floats into register 0
*/
dwComponentSize = 3 * sizeof(IMG_FLOAT);
dwOffsetSize = 3 * sizeof(IMG_FLOAT);
dwFFComponentType = FFVTXCOMPONENT_TYPE_POSITION;
dwVGPIFType = MBX1_VGPIFDEF_SREG_3D_FLOAT;
dwVGPIFReg = FFVTXCOMPONENT_INPUTREG_POS;
break;
}
case D3DMFVF_XYZRHW_FIXED:
{
bFixedPoint = IMG_TRUE;
}
case D3DMFVF_XYZRHW_FLOAT:
{
/*
XYZRHW component present. Read as 4-floats into register 0
*/
dwComponentSize = 4 * sizeof(IMG_FLOAT);
dwOffsetSize = 4 * sizeof(IMG_FLOAT);
dwFFComponentType = FFVTXCOMPONENT_TYPE_POSITION;
dwVGPIFType = MBX1_VGPIFDEF_SREG_4D_FLOAT;
dwVGPIFReg = FFVTXCOMPONENT_INPUTREG_POS;
break;
}
default:
{
//DPF("VSIFDefSetupForFVF: Unrecognised or no position-component specified! (FVF 0x%X)", dwFVFCode);
return FALSE;
}
}
if (dwComponentSize)
{
/*
Add a component for the position to the stream-format component-list
*/
psComponent->dwVGPIFReg = dwVGPIFReg;
psComponent->bFixedPoint = bFixedPoint;
psComponent->dwSize = dwComponentSize;
psComponent->dwOffset = dwComponentOffset;
psComponent->bColour = IMG_FALSE;
/*
Flag that a position component is present, and update the overall
vertex-size
*/
dwFFComponents |= dwFFComponentType;
dwVtxSize += dwComponentSize;
/*
Update the VGP input format
*/
dwVGPIFShift = MBX1_VGPIFDEF_SREG0_SHIFT + (dwVGPIFReg * MBX1_VGPIFDEF_SREG_LSHIFT);
dwVGPIFDef &= ~(MBX1_VGPIFDEF_SREG0_CLRMASK << dwVGPIFShift);
dwVGPIFDef |= dwVGPIFType << dwVGPIFShift;
psComponent++;
}
/*
Update the next-component position
*/
dwComponentOffset += dwOffsetSize;
/*
Normal present?
*/
if((dwFVFCode & D3DMFVF_NORMAL_FLOAT) || (dwFVFCode & D3DMFVF_NORMAL_FIXED))
{
/*
Add a component for the normal to the stream-format component-list
*/
psComponent->bFixedPoint = (dwFVFCode & D3DMFVF_NORMAL_FIXED);
psComponent->dwSize = 3 * sizeof(IMG_FLOAT);
psComponent->dwOffset = dwComponentOffset;
psComponent->bColour = IMG_FALSE;
/*
Read the normal as 3-floats into input-register 3
*/
psComponent->dwVGPIFReg = FFVTXCOMPONENT_INPUTREG_NORMAL;
dwVGPIFType = MBX1_VGPIFDEF_SREG_3D_FLOAT;
dwVGPIFShift = MBX1_VGPIFDEF_SREG0_SHIFT + (psComponent->dwVGPIFReg * MBX1_VGPIFDEF_SREG_LSHIFT);
dwVGPIFDef &= ~(MBX1_VGPIFDEF_SREG0_CLRMASK << dwVGPIFShift);
dwVGPIFDef |= dwVGPIFType << dwVGPIFShift;
/*
Flag that a normal component is present, and update the overall
vertex-size and next-component position
*/
dwFFComponents |= FFVTXCOMPONENT_TYPE_NORMAL;
dwVtxSize += 3 * sizeof(IMG_FLOAT);
dwComponentOffset += 3 * sizeof(IMG_FLOAT);
psComponent++;
}
/*
Diffuse-colour present?
*/
if (dwFVFCode & D3DMFVF_DIFFUSE)
{
/*
Add a component for the diffuse-colour to the stream-format
component-list
*/
psComponent->dwVGPIFReg = FFVTXCOMPONENT_INPUTREG_DIFFUSE;
psComponent->bFixedPoint = IMG_FALSE;
psComponent->dwSize = 1 * sizeof(DWORD);
psComponent->dwOffset = dwComponentOffset;
psComponent->bColour = IMG_TRUE;
/*
Read the colour as 4 colour-components into input-register 4
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -