PageRenderTime 561ms CodeModel.GetById 298ms app.highlight 15ms RepoModel.GetById 126ms app.codeStats 0ms

/opengles/src/arm/CodeGenerator.h

http://ftk.googlecode.com/
C++ Header | 273 lines | 161 code | 49 blank | 63 comment | 0 complexity | 5b82bac318058bd0bc442895036155f1 MD5 | raw file
  1#ifndef EGL_CODE_GENERATOR_H
  2#define EGL_CODE_GENERATOR_H 1
  3
  4// ==========================================================================
  5//
  6// CodeGenerator.h		JIT Class for 3D Rendering Library
  7//
  8//						This file contains the rasterizer functions that
  9//						implement the runtime code generation support
 10//						for optimized scan line rasterization routines.
 11//
 12// --------------------------------------------------------------------------
 13//
 14// 08-07-2003	Hans-Martin Will	initial version
 15//
 16// --------------------------------------------------------------------------
 17//
 18// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
 19// 
 20// Redistribution and use in source and binary forms, with or without 
 21// modification, are permitted provided that the following conditions are 
 22// met:
 23// 
 24//	 *  Redistributions of source code must retain the above copyright
 25// 		notice, this list of conditions and the following disclaimer. 
 26//   *	Redistributions in binary form must reproduce the above copyright
 27// 		notice, this list of conditions and the following disclaimer in the 
 28// 		documentation and/or other materials provided with the distribution. 
 29// 
 30// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 31// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 32// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 33// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 34// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 35// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 36// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 37// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 38// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 39// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 40// THE POSSIBILITY OF SUCH DAMAGE.
 41//
 42// ==========================================================================
 43
 44
 45#include "OGLES.h"
 46#include "fixed.h"
 47#include "linalg.h"
 48#include "Rasterizer.h"
 49#include "RasterizerState.h"
 50#include "FunctionCache.h"
 51
 52
 53extern "C" {
 54#ifdef __GCC32__
 55    struct cg_module_t;
 56    struct cg_proc_t;
 57    struct cg_block_t;
 58    struct cg_block_ref_t;
 59    struct cg_virtual_reg_t;
 60#else
 61	typedef struct cg_module_t cg_module_t;
 62	typedef struct cg_proc_t cg_proc_t;
 63	typedef struct cg_block_t cg_block_t;
 64	typedef struct cg_block_ref_t cg_block_ref_t;
 65	typedef struct cg_virtual_reg_t cg_virtual_reg_t;
 66#endif
 67}
 68
 69
 70namespace EGL {
 71
 72	struct FragmentGenerationInfo {
 73		cg_virtual_reg_t * regX;
 74		cg_virtual_reg_t * regY;
 75		cg_virtual_reg_t * regDepth;
 76		cg_virtual_reg_t * regU[EGL_NUM_TEXTURE_UNITS];
 77		cg_virtual_reg_t * regV[EGL_NUM_TEXTURE_UNITS]; 
 78		cg_virtual_reg_t * regFog;
 79		cg_virtual_reg_t * regR;
 80		cg_virtual_reg_t * regG;
 81		cg_virtual_reg_t * regB; 
 82		cg_virtual_reg_t * regA;	
 83
 84		cg_virtual_reg_t * regInfo;
 85		cg_virtual_reg_t * regTexture[EGL_NUM_TEXTURE_UNITS];
 86	};
 87
 88	class FunctionCache;
 89
 90	class MultiTexture;
 91
 92	class CodeGenerator {
 93
 94	public:
 95		// ----------------------------------------------------------------------
 96		// Code generation of triangle scan line
 97		// ----------------------------------------------------------------------
 98		void Compile(FunctionCache * target, FunctionCache::FunctionType type,
 99			void (CodeGenerator::*function)());
100
101		void SetState(const RasterizerState * state)	{ m_State = state; }
102		const RasterizerState * GetState()				{ return m_State; }
103
104		void GenerateRasterScanLine();
105		void GenerateRasterLine();
106		void GenerateRasterPoint();
107		void GenerateRasterTriangle();
108
109	private:
110		void GenerateFragment(cg_proc_t * procedure, cg_block_t * currentBlock,
111			cg_block_ref_t * continuation, FragmentGenerationInfo & fragmentInfo,
112			int weight, bool forceScissor = false);
113
114		void GenerateFetchTexColor(cg_proc_t * proc, cg_block_t * currentBlock,
115								   size_t unit,
116								   FragmentGenerationInfo & fragmentInfo,
117								   cg_virtual_reg_t *& regTexColorR,
118								   cg_virtual_reg_t *& regTexColorG,			
119								   cg_virtual_reg_t *& regTexColorB,			
120								   cg_virtual_reg_t *& regTexColorA,
121								   cg_virtual_reg_t *& regTexColor565);
122
123		void FetchTexColor(cg_proc_t * proc, cg_block_t * currentBlock,
124								   const RasterizerState::TextureState * textureState,
125								   cg_virtual_reg_t * regTexData, 
126								   cg_virtual_reg_t * regTexOffset,
127								   cg_virtual_reg_t *& regTexColorR,
128								   cg_virtual_reg_t *& regTexColorG,			
129								   cg_virtual_reg_t *& regTexColorB,			
130								   cg_virtual_reg_t *& regTexColorA,
131								   cg_virtual_reg_t *& regTexColor565);
132
133		cg_virtual_reg_t * Mul255(cg_block_t * currentBlock, cg_virtual_reg_t * first, cg_virtual_reg_t * second);
134		cg_virtual_reg_t * Add(cg_block_t * currentBlock, cg_virtual_reg_t * first, cg_virtual_reg_t * second);
135		cg_virtual_reg_t * AddSigned(cg_block_t * currentBlock, cg_virtual_reg_t * first, cg_virtual_reg_t * second);
136		cg_virtual_reg_t * Sub(cg_block_t * currentBlock, cg_virtual_reg_t * first, cg_virtual_reg_t * second);
137		cg_virtual_reg_t * AddSaturate255(cg_block_t * currentBlock, cg_virtual_reg_t * first, cg_virtual_reg_t * second);
138		cg_virtual_reg_t * ClampTo255(cg_block_t * currentBlock, cg_virtual_reg_t * value);
139		cg_virtual_reg_t * ExtractBitFieldTo255(cg_block_t * currentBlock, cg_virtual_reg_t * value, size_t low, size_t high);
140		cg_virtual_reg_t * BitFieldFrom255(cg_block_t * currentBlock, cg_virtual_reg_t * value, size_t low, size_t high);
141		cg_virtual_reg_t * Dot3(cg_block_t * currentBlock, cg_virtual_reg_t * r[], cg_virtual_reg_t * g[], cg_virtual_reg_t * b[]);
142		cg_virtual_reg_t * SignedVal(cg_block_t * block, cg_virtual_reg_t * value);
143		void Color565FromRGB(cg_block_t * block, cg_virtual_reg_t * result,
144							 cg_virtual_reg_t * r, cg_virtual_reg_t * g, cg_virtual_reg_t * b);
145		cg_virtual_reg_t * Color565FromRGB(cg_block_t * block,
146							 cg_virtual_reg_t * r, cg_virtual_reg_t * g, cg_virtual_reg_t * b);
147
148		cg_virtual_reg_t * Blend255(cg_block_t * currentBlock, cg_virtual_reg_t * first, cg_virtual_reg_t * second,
149								    cg_virtual_reg_t * alpha);
150		cg_virtual_reg_t * Blend255(cg_block_t * currentBlock, U8 constant, cg_virtual_reg_t * second,
151								    cg_virtual_reg_t * alpha);
152
153	private:
154		const RasterizerState *	m_State;
155		struct cg_module_t *m_Module;
156	};
157
158}
159
160
161	// -------------------------------------------------------------------------
162	// Offsets of structure members within info structure
163	// -------------------------------------------------------------------------
164
165#	define OFFSET_SURFACE_WIDTH					offsetof(RasterInfo, SurfaceWidth)
166#	define OFFSET_SURFACE_HEIGHT				offsetof(RasterInfo, SurfaceHeight)
167#	define OFFSET_SURFACE_DEPTH_BUFFER			offsetof(RasterInfo, DepthBuffer)
168#	define OFFSET_SURFACE_COLOR_BUFFER			offsetof(RasterInfo, ColorBuffer)
169#	define OFFSET_SURFACE_STENCIL_BUFFER		offsetof(RasterInfo, StencilBuffer)
170#	define OFFSET_SURFACE_ALPHA_BUFFER			offsetof(RasterInfo, AlphaBuffer)
171
172#	define OFFSET_TEXTURES						offsetof(RasterInfo, Textures)
173#	define OFFSET_MIPMAP_LEVEL					offsetof(RasterInfo, MipmapLevel)
174#	define OFFSET_MAX_MIPMAP_LEVEL				offsetof(RasterInfo, MaxMipmapLevel)
175
176#	define OFFSET_TEXTURE_LOG_WIDTH				offsetof(Texture, m_LogWidth)
177#	define OFFSET_TEXTURE_LOG_HEIGHT			offsetof(Texture, m_LogHeight)
178#	define OFFSET_TEXTURE_DATA					offsetof(Texture, m_Data)
179#	define SIZE_TEXTURE							sizeof(Texture)
180
181
182#	define OFFSET_INVERSE_TABLE_PTR				offsetof(RasterInfo, InversionTablePtr)
183
184	// -------------------------------------------------------------------------
185	// For FractionalColor
186	// -------------------------------------------------------------------------
187
188#	define OFFSET_COLOR_RED					offsetof(FractionalColor, r)
189#	define OFFSET_COLOR_GREEN				offsetof(FractionalColor, g)
190#	define OFFSET_COLOR_BLUE				offsetof(FractionalColor, b)
191#	define OFFSET_COLOR_ALPHA				offsetof(FractionalColor, a)
192
193	// -------------------------------------------------------------------------
194	// For ScreenCoord
195	// -------------------------------------------------------------------------
196
197#	define OFFSET_SCREEN_X					offsetof(ScreenCoord, x)
198#	define OFFSET_SCREEN_Y					offsetof(ScreenCoord, y)
199#	define OFFSET_SCREEN_INV_Z				offsetof(ScreenCoord, invZ)
200#	define OFFSET_SCREEN_DEPTH				offsetof(ScreenCoord, depth)
201
202	// -------------------------------------------------------------------------
203	// For EdgeCoord
204	// -------------------------------------------------------------------------
205
206#	define OFFSET_EDGE_COORD_X				offsetof(EdgeCoord, x)
207#	define OFFSET_EDGE_COORD_INV_Z			offsetof(EdgeCoord, invZ)
208#	define OFFSET_EDGE_COORD_DEPTH			offsetof(EdgeCoord, depth)
209
210	// -------------------------------------------------------------------------
211	// For TexCoord
212	// -------------------------------------------------------------------------
213
214#	define OFFSET_TEX_COORD_TU				offsetof(TexCoord, tu)
215#	define OFFSET_TEX_COORD_TV				offsetof(TexCoord, tv)
216#	define OFFSET_TEX_COORD_DTUDX			offsetof(TexCoord, dtudx)
217#	define OFFSET_TEX_COORD_DTUDY			offsetof(TexCoord, dtudy)
218#	define OFFSET_TEX_COORD_DTVDX			offsetof(TexCoord, dtvdx)
219#	define OFFSET_TEX_COORD_DTVDY			offsetof(TexCoord, dtvdy)
220
221	// -------------------------------------------------------------------------
222	// For EdgeBuffer
223	// -------------------------------------------------------------------------
224
225#	define OFFSET_EDGE_BUFFER_WINDOW		offsetof(EdgePos, m_WindowCoords)
226#	define OFFSET_EDGE_BUFFER_COLOR			offsetof(EdgePos, m_Color)
227#	define OFFSET_EDGE_BUFFER_TEXTURE		offsetof(EdgePos, m_TextureCoords)
228#	define OFFSET_EDGE_BUFFER_FOG			offsetof(EdgePos, m_FogDensity)
229
230#	define OFFSET_EDGE_BUFFER_WINDOW_X		(OFFSET_EDGE_BUFFER_WINDOW + OFFSET_EDGE_COORD_X)
231#	define OFFSET_EDGE_BUFFER_WINDOW_INV_Z	(OFFSET_EDGE_BUFFER_WINDOW + OFFSET_EDGE_COORD_INV_Z)
232#	define OFFSET_EDGE_BUFFER_WINDOW_DEPTH	(OFFSET_EDGE_BUFFER_WINDOW + OFFSET_EDGE_COORD_DEPTH)
233
234#	define OFFSET_EDGE_BUFFER_COLOR_R		(OFFSET_EDGE_BUFFER_COLOR + OFFSET_COLOR_RED)
235#	define OFFSET_EDGE_BUFFER_COLOR_G		(OFFSET_EDGE_BUFFER_COLOR + OFFSET_COLOR_GREEN)
236#	define OFFSET_EDGE_BUFFER_COLOR_B		(OFFSET_EDGE_BUFFER_COLOR + OFFSET_COLOR_BLUE)
237#	define OFFSET_EDGE_BUFFER_COLOR_A		(OFFSET_EDGE_BUFFER_COLOR + OFFSET_COLOR_ALPHA)
238
239#	define OFFSET_EDGE_BUFFER_TEX_TU		(OFFSET_EDGE_BUFFER_TEXTURE + OFFSET_TEX_COORD_TU)
240#	define OFFSET_EDGE_BUFFER_TEX_TV		(OFFSET_EDGE_BUFFER_TEXTURE + OFFSET_TEX_COORD_TV)
241#	define OFFSET_EDGE_BUFFER_TEX_DTUDX		(OFFSET_EDGE_BUFFER_TEXTURE + OFFSET_TEX_COORD_DTUDX)
242#	define OFFSET_EDGE_BUFFER_TEX_DTUDY		(OFFSET_EDGE_BUFFER_TEXTURE + OFFSET_TEX_COORD_DTUDY)
243#	define OFFSET_EDGE_BUFFER_TEX_DTVDX		(OFFSET_EDGE_BUFFER_TEXTURE + OFFSET_TEX_COORD_DTVDX)
244#	define OFFSET_EDGE_BUFFER_TEX_DTVDY		(OFFSET_EDGE_BUFFER_TEXTURE + OFFSET_TEX_COORD_DTVDY)
245
246	// -------------------------------------------------------------------------
247	// For RasterPos
248	// -------------------------------------------------------------------------
249
250#	define OFFSET_RASTER_POS_WINDOW			offsetof(RasterPos, m_WindowCoords)
251#	define OFFSET_RASTER_POS_COLOR			offsetof(RasterPos, m_Color)
252#	define OFFSET_RASTER_POS_TEXTURE		offsetof(RasterPos, m_TextureCoords)
253#	define OFFSET_RASTER_POS_FOG			offsetof(RasterPos, m_FogDensity)
254
255#	define OFFSET_RASTER_POS_WINDOW_X		(OFFSET_RASTER_POS_WINDOW + OFFSET_SCREEN_X)
256#	define OFFSET_RASTER_POS_WINDOW_Y		(OFFSET_RASTER_POS_WINDOW + OFFSET_SCREEN_Y)
257#	define OFFSET_RASTER_POS_WINDOW_INV_Z	(OFFSET_RASTER_POS_WINDOW + OFFSET_SCREEN_INV_Z)
258#	define OFFSET_RASTER_POS_WINDOW_DEPTH	(OFFSET_RASTER_POS_WINDOW + OFFSET_SCREEN_DEPTH)
259
260#	define OFFSET_RASTER_POS_COLOR_R		(OFFSET_RASTER_POS_COLOR + OFFSET_COLOR_RED)
261#	define OFFSET_RASTER_POS_COLOR_G		(OFFSET_RASTER_POS_COLOR + OFFSET_COLOR_GREEN)
262#	define OFFSET_RASTER_POS_COLOR_B		(OFFSET_RASTER_POS_COLOR + OFFSET_COLOR_BLUE)
263#	define OFFSET_RASTER_POS_COLOR_A		(OFFSET_RASTER_POS_COLOR + OFFSET_COLOR_ALPHA)
264
265#	define OFFSET_RASTER_POS_TEX_TU			(OFFSET_RASTER_POS_TEXTURE + OFFSET_TEX_COORD_TU)
266#	define OFFSET_RASTER_POS_TEX_TV			(OFFSET_RASTER_POS_TEXTURE + OFFSET_TEX_COORD_TV)
267#	define OFFSET_RASTER_POS_TEX_DTUDX		(OFFSET_RASTER_POS_TEXTURE + OFFSET_TEX_COORD_DTUDX)
268#	define OFFSET_RASTER_POS_TEX_DTUDY		(OFFSET_RASTER_POS_TEXTURE + OFFSET_TEX_COORD_DTUDY)
269#	define OFFSET_RASTER_POS_TEX_DTVDX		(OFFSET_RASTER_POS_TEXTURE + OFFSET_TEX_COORD_DTVDX)
270#	define OFFSET_RASTER_POS_TEX_DTVDY		(OFFSET_RASTER_POS_TEXTURE + OFFSET_TEX_COORD_DTVDY)
271
272
273#endif //ndef EGL_CODE_GENERATOR_H