📄 vgpsections.c
字号:
/*****************************************************************************
Name : vgpsections.c
Title : VGP code sections
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 fixed function code sections
Program Type : 32-bit DLL
Version : $Revision: 1.3 $
Modifications :
$Log: vgpsections.c $
Initial revision
*****************************************************************************/
#include "context.h"
#if defined(SUPPORT_VGP) || defined(SUPPORT_VGP_LITE)
/****************************************************************************************
* Position transform, output, z/w biasing code sections
* This code will be coalesced at runtime to form 1 section
****************************************************************************************/
/* Code to pass through the position */
HWVGPINST psPositionPassthruSection[] =
{
/* mov oPos, v0 */
VGPINST(MOV, DEST(OPOS, NOMASK), SRC_VN(VPOS), 0, 0, 0),
};
/* Code to pass through the position and add z-bias */
HWVGPINST psPositionZBiasPassthruSection[] =
{
/* mov oPos, v0 */
VGPINST(MOV, DEST(R0, NOMASK), SRC_VN(VPOS), 0, 0, 0),
/* add r1, c[CONST_ZBIAS_PARAMS].z, neg c[CONST_ZBIAS_PARAMS].y */
VGPINST(ADD, DEST(R0, MASKZ), SRC_SWZCN(CONST_ZBIAS_PARAMS, SWZ_ZZZZ), SRC_SWZRN(0, SWZ_ZZZZ), 0, 0),
};
/* Code to pass through the position and add W-bias */
HWVGPINST psPositionWBiasPassthruSection[] =
{
/* mov oPos, v0 */
VGPINST(MOV, DEST(R0, NOMASK), SRC_VN(VPOS), 0, 0, 0),
/* add r1, c[CONST_ZBIAS_PARAMS].z, neg c[CONST_ZBIAS_PARAMS].y */
VGPINST(ADD, DEST(R0, MASKW), SRC_SWZCN(CONST_ZBIAS_PARAMS, SWZ_ZZZZ), SRC_SWZRN(0, SWZ_WWWW), 0, 0),
};
/* Code to transform the position */
HWVGPINST psPositionTransformSection[] =
{
/* Position transform. */
/* dp4 r0.x, v0, cCONST_MODELTOPROJ_ROW0 */
VGPINST(DP4, DEST(R0, MASKX), SRC_VN(VPOS), SRC_CN(CONST_MODELTOPROJ_ROW0), 0, 0),
/* dp4 r0.y, v0, cCONST_MODELTOPROJ_ROW1 */
VGPINST(DP4, DEST(R0, MASKY), SRC_VN(VPOS), SRC_CN(CONST_MODELTOPROJ_ROW1), 0, 0),
/* dp4 r0.z, v0, cCONST_MODELTOPROJ_ROW2 */
VGPINST(DP4, DEST(R0, MASKZ), SRC_VN(VPOS), SRC_CN(CONST_MODELTOPROJ_ROW2), 0, 0),
/* dp4 r0.w, v0, cCONST_MODELTOPROJ_ROW3 */
VGPINST(DP4, DEST(R0, MASKW), SRC_VN(VPOS), SRC_CN(CONST_MODELTOPROJ_ROW3), 0, 0),
};
/* Code to do Z-Bias */
HWVGPINST psPositionZBiasSection[] =
{
/*
Perform inverse viewport transform of ZBias and add to z:-
Z += ((zbias - VPT.ZOffset) * w) * 1/VPT.ZScale
*/
/* add r1, c[CONST_ZBIAS_PARAMS].z, neg c[CONST_ZBIAS_PARAMS].y */
VGPINST(ADD, DEST(R1, MASKX), SRC_SWZCN(CONST_ZBIAS_PARAMS, SWZ_ZZZZ), SRC_NEGSWZCN(CONST_ZBIAS_PARAMS, SWZ_YYYY), 0, 0),
/* mul r1.y, r1.x, r0.w */
VGPINST(MUL, DEST(R1, MASKY), SRC_SWZRN(1, SWZ_XXXX), SRC_SWZRN(0, SWZ_WWWW), 0, 0),
/* rcp r1.w, c[CONST_ZBIAS_PARAMS].x */
VGPINST(RCP, DEST(R1, MASKW), SRC_SWZCN(CONST_ZBIAS_PARAMS, SWZ_XXXX), 0, 0, 0),
/* mad r1.y, r1.x, r0.w */
VGPINST(MAD, DEST(R0, MASKZ), SRC_SWZRN(1, SWZ_YYYY), SRC_SWZRN(1, SWZ_WWWW), SRC_SWZRN(0, SWZ_ZZZZ), 0),
};
/* Code to do W-Bias */
HWVGPINST psPositionWBiasSection[] =
{
/*
Calculate reciprocal of w, add offset, the find reciprocal of result
w = 1/(1/w + bias)
*/
/* rcp r1.x, r0.w */
VGPINST(RCP, DEST(R1, MASKX), SRC_SWZRN(0, SWZ_WWWW), 0, 0, 0),
/* add r1.y, r1.x, c[CONST_ZBIAS_PARAMS].x */
VGPINST(ADD, DEST(R1, MASKY), SRC_SWZRN(1, SWZ_XXXX), SRC_SWZCN(CONST_ZBIAS_PARAMS, SWZ_ZZZZ), 0, 0),
/* rcp r0.w, r1.y */
VGPINST(RCP, DEST(R0, MASKW), SRC_SWZRN(1, SWZ_YYYY), 0, 0, 0),
};
/* Code to do Viewport transform in ProcessVertices cases */
HWVGPINST psPositionViewPortTransformSection[] =
{
/*
Tx = ((x * XScale) * invw) + XOffset
Ty = ((y * YScale) * invw) + YOffset
Tz = ((z * ZScale) * invw) + ZOffset
Tw = invw
*/
/* (R1.x = R0.x * XScale) (R1.y = R0.y * YScale) (R1.z = R0.z * ZScale) */
VGPINST(MUL, DEST(R1, MASK_XYZ), SRC_RN(0), SRC_CN(CONST_VPORT_SCALE), 0, 0),
/* (R0.w = 1/R0.w ) */
VGPINST(RCP, DEST(R0, MASKW), SRC_SWZRN(0, SWZ_WWWW), 0, 0, 0),
/* (R0.x = (R1.x * R0.w) + XOffset) (R0.y = (R1.y * R0.w) + YOffset) (R0.z = (R1.z * R0.w) + ZOffset) */
VGPINST(MAD, DEST(R0, MASK_XYZ), SRC_RN(1), SRC_SWZRN(0, SWZ_WWWW), SRC_CN(CONST_VPORT_OFFSET), 0),
};
/* Code to copy position from r0 */
HWVGPINST psPositionOutputSection[] =
{
/* mov oPos, r0 */
VGPINST(MOV, DEST(OPOS, NOMASK), SRC_RN(0), 0, 0, 0),
};
/* Code to set front and rear clip */
HWVGPINST psPositionClipSection[] =
{
/* Front-plane clipping calculation for transformed data. */
/* dp4 oCLIPFR.x, r0, c[CONST_CLIPPLANEFRONT] */
VGPINST(DP4, DEST(OCLIPFR, MASKX), SRC_RN(0), SRC_CN(CONST_CLIPPLANEFRONT), 0, 0),
/* Back-plane clipping calculation for transformed data. */
/* dp4 oCLIPFR.y, r0, c[CONST_CLIPPLANEREAR] */
VGPINST(DP4, DEST(OCLIPFR, MASKY), SRC_RN(0), SRC_CN(CONST_CLIPPLANEREAR), 0, 0)
};
#define SECTION_POSITION_MAXIMUM_SIZE \
(sizeof(psPositionTransformSection) / sizeof(*psPositionTransformSection)) + \
(sizeof(psPositionZBiasSection) / sizeof(*psPositionZBiasSection)) + \
(sizeof(psPositionOutputSection) / sizeof(*psPositionOutputSection)) + \
(sizeof(psPositionClipSection) / sizeof(*psPositionClipSection)) + \
(sizeof(psPositionViewPortTransformSection)/sizeof(*psPositionViewPortTransformSection))
/* Place holder for code upload */
HWVGPINST psPositionSection[SECTION_POSITION_MAXIMUM_SIZE];
/****************************************************************************************
****************************************************************************************/
/*
* Code to pass through supplied colours.
*/
HWVGPINST psColourPassthruSection[] =
{
/* Diffuse colour passthrough. */
/* mov oD0, vD3DVSDE_DIFFUSE */
VGPINST(MOV, DEST(OBASE, NOMASK), SRC_VN(VDIFFUSE), 0, 0, 0),
/* Specular colour passthrough. */
/* mov oD1, v5 */
VGPINST(MOV, DEST(OOFF, NOMASK), SRC_VN(VSPECULAR), 0, 0, 0),
};
#define SECTION_COLOURPASSTHRU_MAXIMUM_SIZE \
(sizeof(psColourPassthruSection) / sizeof(*psColourPassthruSection))
/*
* Code to set the default colours - for when lighting is disabled and the
* vertex is missing them
*/
HWVGPINST psColourSetDefaultsSection[] =
{
/* Set Default diffuse colour */
/* mov oD0, cCONST_DEFAULT_DIFFUSE */
VGPINST(MOV, DEST(OBASE, NOMASK), SRC_CN(CONST_DEFAULT_DIFFUSE), 0, 0, 0),
/* Specular colour passthrough. */
/* mov oD1, cCONST_DEFAULT_SPECULAR */
VGPINST(MOV, DEST(OOFF, NOMASK), SRC_CN(CONST_DEFAULT_SPECULAR), 0, 0, 0),
};
#define SECTION_COLOURSETDEFAULTS_MAXIMUM_SIZE \
(sizeof(psColourSetDefaultsSection) / sizeof(*psColourSetDefaultsSection))
/*
* Code to pass through supplied texture coordinates.
*/
HWVGPINST psTextureCoordinatePassthruSection[] =
{
/* Texture coordinate zero passthrough. */
/* mov oT0, vD3DVSDE_TEXCOORD0 */
VGPINST(MOV, DEST(OTEX0, NOMASK), SRC_VN(VTEX0), 0, 0, 0),
/* Texture coordinate one passthrough. */
/* mov oT1, vD3DVSDE_TEXCOORD1 */
VGPINST(MOV, DEST(OTEX1, NOMASK), SRC_VN(VTEX1), 0, 0, 0),
};
#define SECTION_TEXTURECOORDINATEPASSTHRU_MAXIMUM_SIZE \
(sizeof(psTextureCoordinatePassthruSection) / \
sizeof(*psTextureCoordinatePassthruSection))
HWVGPINST psAmbientSourcePrototype[] =
{
/* Set up the ambient source from the material. */
/* mov rVGPTNL_RAMBIENTSRC, cCONST_MATERIAL_AMBIENT_COLOUR */
VGPINST(MOV, DEST(VGPTNL_OUT_RAMBIENTSRC, NOMASK), SRC_CN(CONST_MATERIAL_AMBIENT_COLOUR), 0, 0, 0),
/* Set up the ambient source from the diffuse colour. */
/* mov rVGPTNL_RAMBIENTSRC, vD3DVSDE_DIFFUSE */
VGPINST(MOV, DEST(VGPTNL_OUT_RAMBIENTSRC, NOMASK), SRC_VN(VDIFFUSE), 0, 0, 0),
/* Set up the ambient source from the specular colour. */
/* mov rVGPTNL_RAMBIENTSRC, vD3DVSDE_SPECULAR */
VGPINST(MOV, DEST(VGPTNL_OUT_RAMBIENTSRC, NOMASK), SRC_VN(VSPECULAR), 0, 0, 0),
};
HWVGPINST psDiffuseSourcePrototype[] =
{
/* Set up the diffuse source from the material. */
/* mov rVGPTNL_RDIFFUSESRC, cCONST_MATERIAL_DIFFUSE_COLOUR */
VGPINST(MOV, DEST(VGPTNL_OUT_RDIFFUSESRC, NOMASK), SRC_CN(CONST_MATERIAL_DIFFUSE_COLOUR), 0, 0, 0),
/* Set up the diffuse source from the diffuse colour. */
/* mov rVGPTNL_RDIFFUSESRC, vD3DVSDE_DIFFUSE */
VGPINST(MOV, DEST(VGPTNL_OUT_RDIFFUSESRC, NOMASK), SRC_VN(VDIFFUSE), 0, 0, 0),
/* Set up the diffuse source from the specular colour. */
/* mov rD3DVSDE_DIFFUSE, vD3DVSDE_SPECULAR */
VGPINST(MOV, DEST(VGPTNL_OUT_RDIFFUSESRC, NOMASK), SRC_VN(VSPECULAR), 0, 0, 0),
};
HWVGPINST psSpecularSourcePrototype[] =
{
/* Set up the specular source from the material. */
/* mov rVGPTNL_RSPECULARSRC, cCONST_MATERIAL_SPECULAR_COLOUR */
VGPINST(MOV, DEST(VGPTNL_OUT_RSPECULARSRC, NOMASK), SRC_CN(CONST_MATERIAL_SPECULAR_COLOUR), 0, 0, 0),
/* Set up the specular source from the diffuse colour. */
/* mov rVGPTNL_RSPECULARSRC, vD3DVSDE_DIFFUSE */
VGPINST(MOV, DEST(VGPTNL_OUT_RSPECULARSRC, NOMASK), SRC_VN(VDIFFUSE), 0, 0, 0),
/* Set up the specular source from the specular colour. */
/* mov rVGPTNL_RSPECULARSRC, vD3DVSDE_SPECULAR */
VGPINST(MOV, DEST(VGPTNL_OUT_RSPECULARSRC, NOMASK), SRC_VN(VSPECULAR), 0, 0, 0),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -