⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shader.c

📁 SMDK6410 Test Code Revision 02. s3c6410 official test code, shifting all the controller functional
💻 C
📖 第 1 页 / 共 3 页
字号:
/*******************************************************************************
*
* NAME         : fimg_shader.c
* TITLE        : FIMGSE Low Level API 
* AUTHOR       : Thomas, Kim
* CREATED      : 30 Aug 2005
*
* COPYRIGHT    : 2005 by Samsung Electronics 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 Samsung Electronics. 
*                Semiconductor Business, System LSI Division,  Mobile 
*                Solution Development, Graphics IP Team in AP.
*
* DESCRIPTION  : Declares types for FIMG shader and functions to manipulate them.
*
* PLATFORM     : ALL
* HISTORY      : 	 
* $RCSfile: fimg_shader.c,v $
* $Revision: 1.4 $
* $Author: cheolkyoo.kim $
* $Date: 2006/05/03 05:30:03 $
* $Locker:  $
* 
* $Source: C:/CVS/CVSrepository/FIMG-3DSE_SW/fimg3dse_fpga/fimg3d/device/fimg_shader.c,v $
* $State: Exp $
* $Log: fimg_shader.c,v $
* Revision 1.4  2006/05/03 05:30:03  cheolkyoo.kim
* no message
*
* Revision 1.3  2006/04/13 10:56:31  cheolkyoo.kim
* Replace FG_TRUE with FGL_TRUE.
*
* Revision 1.2  2006/04/05 02:22:39  cheolkyoo.kim
* outw and inw are repalced by WRITEREG and READREG
*
* Revision 1.1  2006/03/10 08:29:18  cheolkyoo.kim
* Initial import of FIMG-3DSE_SW package
*
*******************************************************************************/
#include "fgl.h"
#include "register.h"
#include "macros.h"

 
/*****************************************************************************
  DEFINES
 *****************************************************************************/

typedef enum FGL_ExecuteModeTag
{
	FGL_HOST_ACCESS_MODE = 0,
	FGL_PS_EXECUTE_MODE
} FGL_ExecuteMode;

typedef enum FGL_DeclareAttribTag
{
	FGL_ATRBDEF_POSITION  = 0x10,
	FGL_ATRBDEF_NORMAL    = 0x20,
	FGL_ATRBDEF_PCOLOR    = 0x40,
	FGL_ATRBDEF_SCOLOR    = 0x41,
	FGL_ATRBDEF_TEXTURE0  = 0x80,
	FGL_ATRBDEF_TEXTURE1  = 0x81,
	FGL_ATRBDEF_TEXTURE2  = 0x82,
	FGL_ATRBDEF_TEXTURE3  = 0x83,
	FGL_ATRBDEF_TEXTURE4  = 0x84,
	FGL_ATRBDEF_TEXTURE5  = 0x85,
	FGL_ATRBDEF_TEXTURE6  = 0x86,
	FGL_ATRBDEF_TEXTURE7  = 0x87,
	FGL_ATRBDEF_POINTSIZE = 0x1,
	FGL_ATRBDEF_USERDEF0  = 0x2,
	FGL_ATRBDEF_USERDEF1  = 0x3,
	FGL_ATRBDEF_USERDEF2  = 0x4,
	FGL_ATRBDEF_USERDEF3  = 0x5
} FGL_DeclareAttrib;

/*****************************************************************************
  DEFINES
 *****************************************************************************/


/*****************************************************************************
  MACROS
 *****************************************************************************/
/* Vertex/Pixel shader PC range value is the maximum 512 slots */
#define PROGRAM_COUNT_VALUE_VALID(range)	(range < 0x200)
/* The number of attributes are the maximum 10 in the vertex shader */
#define VS_MAX_ATTRIB_NUM_VALID(num)		((0 < num) && (num <= 10))
/* The number of attributes are the maximum 9 in the pixel shader */
#define PS_MAX_ATTRIB_NUM_VALID(num)		((0 < num) && (num <= 9))
 
 
/******************************************************************************
   Local function
 ******************************************************************************/

/* Local function prototypes */

static FGL_Error 
_PSExecuteMode ( 
					FGL_ExecuteMode exeMode 
			   );

static unsigned int 
_SearchAttribTable (
						unsigned int 		*pAttribTable,
						unsigned int		tableSize,
						FGL_DeclareAttrib	dclAttribName						
   				   );
   				   
   				   
/******************************************************************************
   Exported Functions
 ******************************************************************************/

// Vertex Shader Register-level API

/*****************************************************************************
 * FUNCTIONS: fglVSSetPCRange
 * SYNOPSIS: This function specifies a start and end address of vetex shader  
 *            program.
 * PARAMETERS: [IN] start: the start program count of vertex shader program.
 *             [IN] end: the end program count of vertex shader program.
 * RETURNS: FGL_ERR_NO_ERROR - if successful
 *          FGL_ERR_INVALID_VALUE - invalid start or end program count value.
 * ERRNO:   FGL_ERR_NO_ERROR        1
 *          FGL_ERR_INVALID_VALUE   7
 *****************************************************************************/
FGL_Error
fglVSSetPCRange (
					unsigned int start,
					unsigned int end
				)
{
	FGL_Error ret = FGL_ERR_UNKNOWN;
	FGL_BOOL bValidPCStart = FGL_FALSE;
	FGL_BOOL bValidPCEnd = FGL_FALSE;

	unsigned int nPCRange = 0;

	bValidPCStart = PROGRAM_COUNT_VALUE_VALID(start);
	bValidPCEnd = PROGRAM_COUNT_VALUE_VALID(end);

	if(bValidPCStart && bValidPCEnd && (start <= end))
	{
		FGL_SET_BITFIELD(nPCRange, 24:16, end);
		FGL_SET_BITFIELD(nPCRange,  8:0,  start);
		WRITEREG(FGVS_PC_RANGE, nPCRange);
		WRITEREG(FGVS_CONFIG, PROGRAM_COUNT_COPYOUT); // PC_RANGE vlaue is copied to VS inside

		ret = FGL_ERR_NO_ERROR;
	}
	else
	{
		if(!bValidPCStart)
		{
			//printf((DBG_ERROR, "Cannot set vertex shader pc vlaue - invalid start pc value"));
		}

		if(!bValidPCEnd)
		{
			//printf((DBG_ERROR, "Cannot set vertex shader pc vlaue - invalid end pc value"));
		}

		ret = FGL_ERR_INVALID_VALUE;
	}

	return ret;
}

/*****************************************************************************
 * FUNCTIONS: fglVSSetAttribNum
 * SYNOPSIS: This function specifies the number of attributes of current
 *           vertex shader programs
 * PARAMETERS: [in] outAttribNum: the number of attributes for the vertex
 *             shader output
 *             [in] inAttribNum: the number of attributes for the vertex
 *             shader input
 * RETURNS: FGL_ERR_NO_ERROR, if successful
 *          FGL_ERR_INVALID_VALUE - invalid the number of input or output
 *          attributes.
 * ERRNO:   FGL_ERR_NO_ERROR        1
 *          FGL_ERR_INVALID_VALUE   7
 *****************************************************************************/
FGL_Error fglVSSetAttribNum (unsigned int inAttribNum)
{
	FGL_Error ret = FGL_ERR_UNKNOWN;
	FGL_BOOL bValidInAttrib = FGL_FALSE;

	unsigned nAttribNum = 0;

	bValidInAttrib = VS_MAX_ATTRIB_NUM_VALID(inAttribNum);

	if(bValidInAttrib)
	{
		FGL_SET_BITFIELD(nAttribNum,  3:0,  inAttribNum);
		WRITEREG(FGVS_ATTRIB_NUM, nAttribNum);

		ret = FGL_ERR_NO_ERROR;
	}
	else
	{
		if(!bValidInAttrib)
		{
			//printf((DBG_ERROR, "Cannot set the number of input attrributes - invalid inAttribNum"));
		}
		ret = FGL_ERR_INVALID_VALUE;
	}

	return ret;
}

/*****************************************************************************
 * FUNCTIONS: fglMakeShaderAttribTable
 * SYNOPSIS:  to make a attribute table which is extracted from shader program.
 * PARAMETERS: [in] pVertexShader - the pointer variable of a vertex Program.
 *             [in] pPixelShader -  the pointer variable of a fragment program.
 *             [in] attribTable - the pointer variable pointing in/out attributes
 *                                table.          
 * RETURNS: FGL_ERR_NO_ERROR, if successful
 *          FGL_ERR_INVALID_PARAMETER - the pVertexShader and pPixelShader is NULL.
 *          FGL_ERR_INVALID_VALUE - the table info. is invalid.
 *          FGL_ERR_INVALID_SHADER_CODE - either magic number or shader version  
 *                                        were not an accepted value.
 * ERRNO:   FGL_ERR_NO_ERROR                1
 *          FGL_ERR_INVALID_PARAMETER       2
 *          FGL_ERR_INVALID_VALUE           7
 *          FGL_ERR_INVALID_SHADER_CODE     8
 *****************************************************************************/
FGL_Error
fglMakeShaderAttribTable (
							const unsigned int *pVertexShader,
							const unsigned int *pPixelShader,
							pFGL_ShaderAttribTable attribTable
					     )
{
	FGL_Error ret = FGL_ERR_UNKNOWN;
	FGL_ShaderHeader *pVShaderHeader;
	FGL_ShaderHeader *pPShaderHeader;
	unsigned int *pShaderBody;
	unsigned int *pVSOutTable;
	unsigned int *pPSInTable;
	unsigned int nTableSize;
	unsigned int i;

	if((pVertexShader != FGL_NULL) && (pVertexShader != FGL_NULL))
	{
		if(attribTable != FGL_NULL)
		{

			pVShaderHeader = (FGL_ShaderHeader*)pVertexShader;

			if ( (pVShaderHeader->Magic == VERTEX_SHADER_MAGIC) &&
			     (pVShaderHeader->Version == SHADER_VERSION) )
			{
				nTableSize = pVShaderHeader->InTableSize;
				pShaderBody = (unsigned int*)(&pVShaderHeader[1]);
				pVSOutTable = (unsigned int *)(pShaderBody + nTableSize);
				nTableSize = pVShaderHeader->OutTableSize;

				if( (nTableSize < FGSP_MAX_ATTRIBTBL_SIZE) &&
				    (pVShaderHeader->OutTableSize != 0) )
				{
					attribTable->outAttribTableSize = nTableSize;

					for(i=0; i<nTableSize; i++)
					{
						attribTable->vsOutAttribTable[i] = *pVSOutTable++;
					}
				}
				else
				{
					ret = FGL_ERR_INVALID_VALUE;
				}
			}
			else
			{
				ret = FGL_ERR_INVALID_SHADER_CODE;
			}

			pPShaderHeader = (FGL_ShaderHeader*)pPixelShader;

			if ( (pPShaderHeader->Magic == PIXEL_SHADER_MAGIC) &&
			     (pPShaderHeader->Version == SHADER_VERSION) )
			{
				pPSInTable = (unsigned int*)(&pPShaderHeader[1]);

				nTableSize = pPShaderHeader->InTableSize;

				if( (nTableSize < FGSP_MAX_ATTRIBTBL_SIZE) &&
				    (pPShaderHeader->InTableSize != 0) )
				{
					attribTable->inAttribTableSize = nTableSize;

					for(i=0; i<nTableSize; i++)
					{
						attribTable->psInAttribTable[i] = *pPSInTable++;
					}
				}
				else
				{
					ret = FGL_ERR_INVALID_VALUE;
				}
			}
			else
			{
				ret = FGL_ERR_INVALID_SHADER_CODE;
			}

			attribTable->validTableInfo = FGL_TRUE;
		}
		else
		{
			// printf
			ret = FGL_ERR_INVALID_PARAMETER;
		}
	}
	else
	{
		// printf
		ret = FGL_ERR_INVALID_PARAMETER;
	}

	return ret;
}

/*****************************************************************************
 * FUNCTIONS: fglRemapVShaderOutAttrib
 * SYNOPSIS: This function remap the input attribute index registers for 
 *           flexibility. The N-th input attribute from host is actually read 
 *           from the position indicated by the index looked up from the 
 *           AttribN corresponding to the register number of input register 
 *           in the shader program.
 * PARAMETERS: [in] pShaderAttribTable - the pointer variable pointing in/out 
 *                  attribute table which is extracted from shader program. 
 * RETURNS: FGL_ERR_NO_ERROR, if successful
 *          FGL_ERR_INVALID_PARAMETER - the pointer of pShaderAttribTable is NULL. 
 *          FGL_ERR_INVALID_VALUE - the table info. is invalid.
 * ERRNO:   FGL_ERR_NO_ERROR            1
 *          FGL_ERR_INVALID_PARAMETER   2 
 *          FGL_ERR_INVALID_VALUE       7
 *****************************************************************************/
FGL_Error
fglRemapVShaderOutAttrib (
							pFGL_ShaderAttribTable pShaderAttribTable
						 )
{
	FGL_Error ret = FGL_ERR_UNKNOWN;
	FGL_BOOL bValidInfo = FGL_FALSE;
	unsigned int i;
	unsigned int nInAttribNum = 0;
	unsigned int nOutAttribNum = 0;
	unsigned int *pOutAttribTable;	
	unsigned int *pInAttribTable;
	unsigned int uAttribIndex;	
	unsigned int uIndexCount = 0;
	
	unsigned int OutAttribIndex0 = 0x03020100;
	unsigned int OutAttribIndex1 = 0x07060504;
	unsigned int OutAttribIndex2 = 0x0B0A0908;

	if(pShaderAttribTable != FGL_NULL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -