VertexProgram.cpp revision 903e025f6cd8d978f013c741431b87b04ae01fd1
1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// SwiftShader Software Renderer
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman// Copyright(c) 2005-2013 TransGaming Inc.
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// All rights reserved. No part of this software may be copied, distributed, transmitted,
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// transcribed, stored in a retrieval system, translated into any human or computer
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// language by any means, or disclosed to third parties without the explicit written
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// or implied, including but not limited to any patent rights, are granted to you.
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "VertexProgram.hpp"
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "Renderer.hpp"
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "VertexShader.hpp"
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "Vertex.hpp"
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "Half.hpp"
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "SamplerCore.hpp"
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "Debug.hpp"
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool localShaderConstants;
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace sw
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
2519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	VertexProgram::VertexProgram(const VertexProcessor::State &state, const VertexShader *shader) : VertexRoutine(state, shader)
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifDepth = 0;
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepDepth = 0;
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		breakDepth = 0;
3019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		currentLabel = -1;
3119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		whileTest = false;
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		for(int i = 0; i < 2048; i++)
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			labelBlock[i] = 0;
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	VertexProgram::~VertexProgram()
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		for(int i = 0; i < 4; i++)
42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			delete sampler[i];
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::pipeline(Registers &r)
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		for(int i = 0; i < 4; i++)
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			sampler[i] = new SamplerCore(r.constants, state.samplerState[i]);
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(!state.preTransformed)
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
5619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			program(r);
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			passThrough(r);
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
6419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::program(Registers &r)
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	//	shader->print("VertexShader-%0.8X.txt", state.shaderID);
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
6819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		unsigned short version = shader->getVersion();
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
7019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableIndex = 0;
7119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.stackIndex = 0;
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
734677a5f7a837e06dac90521eee0cf063cbfb9c9bNicolas Capens		if(shader->containsLeaveInstruction())
744677a5f7a837e06dac90521eee0cf063cbfb9c9bNicolas Capens		{
754677a5f7a837e06dac90521eee0cf063cbfb9c9bNicolas Capens			r.enableLeave = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
764677a5f7a837e06dac90521eee0cf063cbfb9c9bNicolas Capens		}
774677a5f7a837e06dac90521eee0cf063cbfb9c9bNicolas Capens
7819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		// Create all call site return blocks up front
79903e025f6cd8d978f013c741431b87b04ae01fd1Alexis Hetu		for(size_t i = 0; i < shader->getLength(); i++)
8019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
8119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			const Shader::Instruction *instruction = shader->getInstruction(i);
8219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Shader::Opcode opcode = instruction->opcode;
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
8419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(opcode == Shader::OPCODE_CALL || opcode == Shader::OPCODE_CALLNZ)
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
8619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				const Dst &dst = instruction->dst;
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				ASSERT(callRetBlock[dst.label].size() == dst.callSite);
8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				callRetBlock[dst.label].push_back(Nucleus::createBasicBlock());
90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
9219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
93903e025f6cd8d978f013c741431b87b04ae01fd1Alexis Hetu		for(size_t i = 0; i < shader->getLength(); i++)
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
9519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			const Shader::Instruction *instruction = shader->getInstruction(i);
9619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Shader::Opcode opcode = instruction->opcode;
97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
9819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(opcode == Shader::OPCODE_DCL || opcode == Shader::OPCODE_DEF || opcode == Shader::OPCODE_DEFI || opcode == Shader::OPCODE_DEFB)
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
10019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				continue;
101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
10319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Dst dst = instruction->dst;
10419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Src src0 = instruction->src[0];
10519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Src src1 = instruction->src[1];
10619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Src src2 = instruction->src[2];
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
10819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			bool predicate = instruction->predicate;
10919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			int size = shader->size(opcode);
11019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Usage usage = instruction->usage;
11119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			unsigned char usageIndex = instruction->usageIndex;
11219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Control control = instruction->control;
11319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			bool integer = dst.type == Shader::PARAMETER_ADDR;
11419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			bool pp = dst.partialPrecision;
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
11619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Vector4f d;
11719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Vector4f s0;
11819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Vector4f s1;
11919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Vector4f s2;
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
12119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(src0.type != Shader::PARAMETER_VOID) s0 = reg(r, src0);
12219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(src1.type != Shader::PARAMETER_VOID) s1 = reg(r, src1);
12319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(src2.type != Shader::PARAMETER_VOID) s2 = reg(r, src2);
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			switch(opcode)
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
12719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_VS_1_0:										break;
12819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_VS_1_1:										break;
12919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_VS_2_0:										break;
13019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_VS_2_x:										break;
13119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_VS_2_sw:									break;
13219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_VS_3_0:										break;
13319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_VS_3_sw:									break;
13419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DCL:										break;
13519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DEF:										break;
13619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DEFI:										break;
13719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DEFB:										break;
13819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_NOP:										break;
13919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ABS:		abs(d, s0);						break;
14019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ADD:		add(d, s0, s1);					break;
14119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_CRS:		crs(d, s0, s1);					break;
14219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_FORWARD1:	forward1(d, s0, s1, s2);		break;
14319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_FORWARD2:	forward2(d, s0, s1, s2);		break;
14419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_FORWARD3:	forward3(d, s0, s1, s2);		break;
14519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_FORWARD4:	forward4(d, s0, s1, s2);		break;
14619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REFLECT1:	reflect1(d, s0, s1);			break;
14719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REFLECT2:	reflect2(d, s0, s1);			break;
14819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REFLECT3:	reflect3(d, s0, s1);			break;
14919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REFLECT4:	reflect4(d, s0, s1);			break;
15019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REFRACT1:	refract1(d, s0, s1, s2.x);		break;
15119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REFRACT2:	refract2(d, s0, s1, s2.x);		break;
15219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REFRACT3:	refract3(d, s0, s1, s2.x);		break;
15319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REFRACT4:	refract4(d, s0, s1, s2.x);		break;
15419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DP1:		dp1(d, s0, s1);					break;
15519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DP2:		dp2(d, s0, s1);					break;
15619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DP3:		dp3(d, s0, s1);					break;
15719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DP4:		dp4(d, s0, s1);					break;
15819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ATT:		att(d, s0, s1);					break;
15919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_EXP2X:		exp2x(d, s0, pp);				break;
16019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_EXP2:		exp2(d, s0, pp);				break;
16119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_EXPP:		expp(d, s0, version);			break;
16219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_EXP:		exp(d, s0, pp);					break;
16319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_FRC:		frc(d, s0);						break;
16419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_TRUNC:      trunc(d, s0);                   break;
16519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_FLOOR:      floor(d, s0);                   break;
16619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_CEIL:       ceil(d, s0);                    break;
16719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LIT:		lit(d, s0);						break;
16819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LOG2X:		log2x(d, s0, pp);				break;
16919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LOG2:		log2(d, s0, pp);				break;
17019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LOGP:		logp(d, s0, version);			break;
17119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LOG:		log(d, s0, pp);					break;
17219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LRP:		lrp(d, s0, s1, s2);				break;
17319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_STEP:		step(d, s0, s1);				break;
17419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SMOOTH:		smooth(d, s0, s1, s2);			break;
17519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_M3X2:		M3X2(r, d, s0, src1);			break;
17619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_M3X3:		M3X3(r, d, s0, src1);			break;
17719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_M3X4:		M3X4(r, d, s0, src1);			break;
17819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_M4X3:		M4X3(r, d, s0, src1);			break;
17919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_M4X4:		M4X4(r, d, s0, src1);			break;
18019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_MAD:		mad(d, s0, s1, s2);				break;
18119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_MAX:		max(d, s0, s1);					break;
18219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_MIN:		min(d, s0, s1);					break;
18319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_MOV:		mov(d, s0, integer);			break;
18419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_MOVA:		mov(d, s0);						break;
18519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_F2B:		f2b(d, s0);						break;
18619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_B2F:		b2f(d, s0);						break;
18719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_MUL:		mul(d, s0, s1);					break;
18819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_NRM2:		nrm2(d, s0, pp);				break;
18919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_NRM3:		nrm3(d, s0, pp);				break;
19019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_NRM4:		nrm4(d, s0, pp);				break;
19119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_POWX:		powx(d, s0, s1, pp);			break;
19219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_POW:		pow(d, s0, s1, pp);				break;
19319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_RCPX:		rcpx(d, s0, pp);				break;
19419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DIV:		div(d, s0, s1);					break;
19519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_MOD:		mod(d, s0, s1);					break;
19619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_RSQX:		rsqx(d, s0, pp);				break;
19719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SQRT:		sqrt(d, s0, pp);				break;
19819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_RSQ:		rsq(d, s0, pp);					break;
19919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LEN2:		len2(d.x, s0, pp);				break;
20019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LEN3:		len3(d.x, s0, pp);				break;
20119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LEN4:		len4(d.x, s0, pp);				break;
20219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DIST1:		dist1(d.x, s0, s1, pp);			break;
20319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DIST2:		dist2(d.x, s0, s1, pp);			break;
20419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DIST3:		dist3(d.x, s0, s1, pp);			break;
20519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_DIST4:		dist4(d.x, s0, s1, pp);			break;
20619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SGE:		step(d, s1, s0);				break;
20719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SGN:		sgn(d, s0);						break;
20819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SINCOS:		sincos(d, s0, pp);				break;
20919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_COS:		cos(d, s0, pp);					break;
21019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SIN:		sin(d, s0, pp);					break;
21119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_TAN:		tan(d, s0);						break;
21219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ACOS:		acos(d, s0);					break;
21319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ASIN:		asin(d, s0);					break;
21419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ATAN:		atan(d, s0);					break;
21519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ATAN2:		atan2(d, s0, s1);				break;
21619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SLT:		slt(d, s0, s1);					break;
21719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SUB:		sub(d, s0, s1);					break;
21819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_BREAK:		BREAK(r);						break;
21919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_BREAKC:		BREAKC(r, s0, s1, control);		break;
22019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_BREAKP:		BREAKP(r, src0);				break;
22119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_CONTINUE:	CONTINUE(r);					break;
22219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_TEST:		TEST();							break;
22319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_CALL:		CALL(r, dst.label, dst.callSite);         break;
22419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_CALLNZ:		CALLNZ(r, dst.label, dst.callSite, src0); break;
22519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ELSE:		ELSE(r);						break;
22619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ENDIF:		ENDIF(r);						break;
22719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ENDLOOP:	ENDLOOP(r);						break;
22819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ENDREP:		ENDREP(r);						break;
22919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ENDWHILE:	ENDWHILE(r);					break;
23019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_IF:			IF(r, src0);					break;
23119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_IFC:		IFC(r, s0, s1, control);		break;
23219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LABEL:		LABEL(dst.index);				break;
23319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LOOP:		LOOP(r, src1);					break;
23419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_REP:		REP(r, src0);					break;
23519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_WHILE:		WHILE(r, src0);					break;
23619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_RET:		RET(r);							break;
23719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_LEAVE:		LEAVE(r);						break;
23819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_CMP:		cmp(d, s0, s1, control);		break;
23919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ICMP:		icmp(d, s0, s1, control);		break;
24019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_SELECT:		select(d, s0, s1, s2);			break;
24119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_EXTRACT:	extract(d.x, s0, s1.x);			break;
24219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_INSERT:		insert(d, s0, s1.x, s2.x);		break;
24319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ALL:		all(d.x, s0);					break;
24419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_ANY:		any(d.x, s0);					break;
24519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_NOT:		not(d, s0);						break;
24619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_OR:			or(d.x, s0.x, s1.x);			break;
24719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_XOR:		xor(d.x, s0.x, s1.x);			break;
24819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_AND:		and(d.x, s0.x, s1.x);			break;
24919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_TEXLDL:		TEXLDL(r, d, s0, src1);			break;
25019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_TEX:		TEX(r, d, s0, src1);			break;
25119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			case Shader::OPCODE_END:										break;
252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			default:
253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				ASSERT(false);
254894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
255894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
25619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(dst.type != Shader::PARAMETER_VOID && dst.type != Shader::PARAMETER_LABEL && opcode != Shader::OPCODE_NOP)
257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
25819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				if(dst.integer)
25919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				{
26019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					switch(opcode)
26119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					{
26219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_DIV:
26319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.x) d.x = Trunc(d.x);
26419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.y) d.y = Trunc(d.y);
26519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.z) d.z = Trunc(d.z);
26619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.w) d.w = Trunc(d.w);
26719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						break;
26819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					default:
26919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						break;   // No truncation to integer required when arguments are integer
27019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					}
27119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				}
27219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
27319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				if(dst.saturate)
274894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
27519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.x) d.x = Max(d.x, Float4(0.0f));
27619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.y) d.y = Max(d.y, Float4(0.0f));
27719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.z) d.z = Max(d.z, Float4(0.0f));
27819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.w) d.w = Max(d.w, Float4(0.0f));
27919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
28019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.x) d.x = Min(d.x, Float4(1.0f));
28119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.y) d.y = Min(d.y, Float4(1.0f));
28219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.z) d.z = Min(d.z, Float4(1.0f));
28319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.w) d.w = Min(d.w, Float4(1.0f));
284894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
285894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
286c6e8ab13ecf20217229de8f4f19a14bbc18778f9Nicolas Capens				if(instruction->isPredicated())
287894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
28819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					Vector4f pDst;   // FIXME: Rename
289894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
29019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					switch(dst.type)
291894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
29219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_VOID:																		break;
29319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_TEMP:
29419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.rel.type == Shader::PARAMETER_VOID)
29519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						{
29619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) pDst.x = r.r[dst.index].x;
29719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) pDst.y = r.r[dst.index].y;
29819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) pDst.z = r.r[dst.index].z;
29919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) pDst.w = r.r[dst.index].w;
30019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						}
30119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						else
30219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						{
30319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							Int a = relativeAddress(r, dst);
30419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
30519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) pDst.x = r.r[dst.index + a].x;
30619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) pDst.y = r.r[dst.index + a].y;
30719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) pDst.z = r.r[dst.index + a].z;
30819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) pDst.w = r.r[dst.index + a].w;
30919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						}
31019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						break;
31119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_ADDR:		pDst = r.a0;													break;
31219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_RASTOUT:
31319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						switch(dst.index)
314894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
315894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						case 0:
31619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) pDst.x = r.o[Pos].x;
31719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) pDst.y = r.o[Pos].y;
31819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) pDst.z = r.o[Pos].z;
31919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) pDst.w = r.o[Pos].w;
320894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
321894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						case 1:
32219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							pDst.x = r.o[Fog].x;
323894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
324894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						case 2:
32519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							pDst.x = r.o[Pts].y;
326894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
327894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						default:
328894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							ASSERT(false);
329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
330894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
33119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_ATTROUT:
33219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.x) pDst.x = r.o[D0 + dst.index].x;
33319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.y) pDst.y = r.o[D0 + dst.index].y;
33419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.z) pDst.z = r.o[D0 + dst.index].z;
33519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.w) pDst.w = r.o[D0 + dst.index].w;
336894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
33719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_TEXCRDOUT:
33819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				//	case Shader::PARAMETER_OUTPUT:
339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						if(version < 0x0300)
340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
34119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) pDst.x = r.o[T0 + dst.index].x;
34219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) pDst.y = r.o[T0 + dst.index].y;
34319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) pDst.z = r.o[T0 + dst.index].z;
34419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) pDst.w = r.o[T0 + dst.index].w;
345894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
346894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						else
347894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
34819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.rel.type == Shader::PARAMETER_VOID)   // Not relative
349894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
35019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.x) pDst.x = r.o[dst.index].x;
35119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.y) pDst.y = r.o[dst.index].y;
35219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.z) pDst.z = r.o[dst.index].z;
35319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.w) pDst.w = r.o[dst.index].w;
354894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
35519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							else if(dst.rel.type == Shader::PARAMETER_LOOP)
356894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
357894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								Int aL = r.aL[r.loopDepth];
358894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
35919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.x) pDst.x = r.o[dst.index + aL].x;
36019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.y) pDst.y = r.o[dst.index + aL].y;
36119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.z) pDst.z = r.o[dst.index + aL].z;
36219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.w) pDst.w = r.o[dst.index + aL].w;
36319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							}
36419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							else
36519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							{
36619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								Int a = relativeAddress(r, dst);
36719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
36819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.x) pDst.x = r.o[dst.index + a].x;
36919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.y) pDst.y = r.o[dst.index + a].y;
37019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.z) pDst.z = r.o[dst.index + a].z;
37119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(dst.w) pDst.w = r.o[dst.index + a].w;
372894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
373894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
374894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
37519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_LABEL:																		break;
37619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_PREDICATE:	pDst = r.p0;													break;
37719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_INPUT:																		break;
378894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					default:
379894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						ASSERT(false);
380894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
381894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
38219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					Int4 enable = enableMask(r, instruction);
383894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
384894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					Int4 xEnable = enable;
385894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					Int4 yEnable = enable;
386894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					Int4 zEnable = enable;
387894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					Int4 wEnable = enable;
388894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
389894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					if(predicate)
390894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
39119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						unsigned char pSwizzle = instruction->predicateSwizzle;
392894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
393894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						Float4 xPredicate = r.p0[(pSwizzle >> 0) & 0x03];
394894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						Float4 yPredicate = r.p0[(pSwizzle >> 2) & 0x03];
395894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						Float4 zPredicate = r.p0[(pSwizzle >> 4) & 0x03];
396894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						Float4 wPredicate = r.p0[(pSwizzle >> 6) & 0x03];
397894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
39819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(!instruction->predicateNot)
399894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
40019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) xEnable = xEnable & As<Int4>(xPredicate);
40119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) yEnable = yEnable & As<Int4>(yPredicate);
40219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) zEnable = zEnable & As<Int4>(zPredicate);
40319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) wEnable = wEnable & As<Int4>(wPredicate);
404894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
405894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						else
406894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
40719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) xEnable = xEnable & ~As<Int4>(xPredicate);
40819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) yEnable = yEnable & ~As<Int4>(yPredicate);
40919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) zEnable = zEnable & ~As<Int4>(zPredicate);
41019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) wEnable = wEnable & ~As<Int4>(wPredicate);
411894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
412894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
413894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
41419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.x) d.x = As<Float4>(As<Int4>(d.x) & xEnable);
41519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.y) d.y = As<Float4>(As<Int4>(d.y) & yEnable);
41619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.z) d.z = As<Float4>(As<Int4>(d.z) & zEnable);
41719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.w) d.w = As<Float4>(As<Int4>(d.w) & wEnable);
418894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
41919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.x) d.x = As<Float4>(As<Int4>(d.x) | (As<Int4>(pDst.x) & ~xEnable));
42019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.y) d.y = As<Float4>(As<Int4>(d.y) | (As<Int4>(pDst.y) & ~yEnable));
42119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.z) d.z = As<Float4>(As<Int4>(d.z) | (As<Int4>(pDst.z) & ~zEnable));
42219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.w) d.w = As<Float4>(As<Int4>(d.w) | (As<Int4>(pDst.w) & ~wEnable));
423894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
424894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
42519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				switch(dst.type)
426894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
42719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_VOID:
428894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
42919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_TEMP:
43019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.rel.type == Shader::PARAMETER_VOID)
43119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					{
43219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.x) r.r[dst.index].x = d.x;
43319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.y) r.r[dst.index].y = d.y;
43419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.z) r.r[dst.index].z = d.z;
43519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.w) r.r[dst.index].w = d.w;
43619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					}
43719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					else
43819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					{
43919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						Int a = relativeAddress(r, dst);
44019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
44119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.x) r.r[dst.index + a].x = d.x;
44219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.y) r.r[dst.index + a].y = d.y;
44319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.z) r.r[dst.index + a].z = d.z;
44419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.w) r.r[dst.index + a].w = d.w;
44519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					}
446894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
44719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_ADDR:
44819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.x) r.a0.x = d.x;
44919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.y) r.a0.y = d.y;
45019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.z) r.a0.z = d.z;
45119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.w) r.a0.w = d.w;
452894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
45319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_RASTOUT:
45419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					switch(dst.index)
455894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
456894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					case 0:
45719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.x) r.o[Pos].x = d.x;
45819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.y) r.o[Pos].y = d.y;
45919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.z) r.o[Pos].z = d.z;
46019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.w) r.o[Pos].w = d.w;
461894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
462894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					case 1:
46319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						r.o[Fog].x = d.x;
464894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
465894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					case 2:
46619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						r.o[Pts].y = d.x;
467894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
468894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					default:	ASSERT(false);
469894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
470894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
47119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_ATTROUT:
47219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.x) r.o[D0 + dst.index].x = d.x;
47319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.y) r.o[D0 + dst.index].y = d.y;
47419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.z) r.o[D0 + dst.index].z = d.z;
47519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(dst.w) r.o[D0 + dst.index].w = d.w;
476894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
47719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_TEXCRDOUT:
47819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			//	case Shader::PARAMETER_OUTPUT:
479894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					if(version < 0x0300)
480894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
48119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.x) r.o[T0 + dst.index].x = d.x;
48219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.y) r.o[T0 + dst.index].y = d.y;
48319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.z) r.o[T0 + dst.index].z = d.z;
48419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.w) r.o[T0 + dst.index].w = d.w;
485894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
486894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					else
487894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
48819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(dst.rel.type == Shader::PARAMETER_VOID)   // Not relative
489894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
49019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) r.o[dst.index].x = d.x;
49119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) r.o[dst.index].y = d.y;
49219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) r.o[dst.index].z = d.z;
49319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) r.o[dst.index].w = d.w;
494894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
49519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						else if(dst.rel.type == Shader::PARAMETER_LOOP)
496894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
497894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							Int aL = r.aL[r.loopDepth];
498894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
49919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) r.o[dst.index + aL].x = d.x;
50019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) r.o[dst.index + aL].y = d.y;
50119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) r.o[dst.index + aL].z = d.z;
50219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) r.o[dst.index + aL].w = d.w;
50319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						}
50419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						else
50519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						{
50619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							Int a = relativeAddress(r, dst);
50719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
50819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.x) r.o[dst.index + a].x = d.x;
50919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.y) r.o[dst.index + a].y = d.y;
51019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.z) r.o[dst.index + a].z = d.z;
51119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							if(dst.w) r.o[dst.index + a].w = d.w;
512894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
513894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
514894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
51519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_LABEL:																		break;
51619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_PREDICATE:	r.p0 = d;														break;
51719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_INPUT:																		break;
518894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				default:
519894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					ASSERT(false);
520894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
521894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
522894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
523894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
52419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(currentLabel != -1)
525894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
526894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Nucleus::setInsertBlock(returnBlock);
527894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
528894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
529894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
530894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::passThrough(Registers &r)
531894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
53219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(shader)
533894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
534894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			for(int i = 0; i < 12; i++)
535894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
53619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				unsigned char usage = shader->output[i][0].usage;
53719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				unsigned char index = shader->output[i][0].index;
538894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
539894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				switch(usage)
540894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
541894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				case 0xFF:
542894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					continue;
54319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::USAGE_PSIZE:
54419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].y = r.v[i].x;
545894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
54619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::USAGE_TEXCOORD:
54719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].x = r.v[i].x;
54819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].y = r.v[i].y;
54919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].z = r.v[i].z;
55019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].w = r.v[i].w;
551894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
55219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::USAGE_POSITION:
55319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].x = r.v[i].x;
55419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].y = r.v[i].y;
55519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].z = r.v[i].z;
55619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].w = r.v[i].w;
557894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
55819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::USAGE_COLOR:
55919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].x = r.v[i].x;
56019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].y = r.v[i].y;
56119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].z = r.v[i].z;
56219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].w = r.v[i].w;
563894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
56419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::USAGE_FOG:
56519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					r.o[i].x = r.v[i].x;
566894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
567894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				default:
568894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					ASSERT(false);
569894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
570894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
571894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
572894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else
573894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
57419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.o[Pos].x = r.v[PositionT].x;
57519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.o[Pos].y = r.v[PositionT].y;
57619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.o[Pos].z = r.v[PositionT].z;
57719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.o[Pos].w = r.v[PositionT].w;
578894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
579894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			for(int i = 0; i < 2; i++)
580894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
58119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				r.o[D0 + i].x = r.v[Color0 + i].x;
58219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				r.o[D0 + i].y = r.v[Color0 + i].y;
58319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				r.o[D0 + i].z = r.v[Color0 + i].z;
58419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				r.o[D0 + i].w = r.v[Color0 + i].w;
585894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
586894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
587894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			for(int i = 0; i < 8; i++)
588894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
58919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				r.o[T0 + i].x = r.v[TexCoord0 + i].x;
59019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				r.o[T0 + i].y = r.v[TexCoord0 + i].y;
59119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				r.o[T0 + i].z = r.v[TexCoord0 + i].z;
59219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				r.o[T0 + i].w = r.v[TexCoord0 + i].w;
593894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
594894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
59566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			r.o[Pts].y = r.v[PointSize].x;
596894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
597894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
598894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
59919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	Vector4f VertexProgram::reg(Registers &r, const Src &src, int offset)
600894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
601894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		int i = src.index + offset;
602894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
60319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f reg;
604894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
605894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		switch(src.type)
606894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
60719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_TEMP:
60819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(src.rel.type == Shader::PARAMETER_VOID)
60919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
61019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				reg = r.r[i];
61119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
61219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			else
61319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
61419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				reg = r.r[i + relativeAddress(r, src)];
61519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
61619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			break;
61719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_CONST:
61819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			reg = readConstant(r, src, offset);
61919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			break;
62019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_INPUT:
62119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman            if(src.rel.type == Shader::PARAMETER_VOID)
62219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
62319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				reg = r.v[i];
62419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
62519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			else
62619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
62719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				reg = r.v[i + relativeAddress(r, src)];
62819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
62919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman            break;
63019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_VOID:			return r.r[0];   // Dummy
63119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_FLOAT4LITERAL:
63219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			reg.x = Float4(src.value[0]);
63319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			reg.y = Float4(src.value[1]);
63419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			reg.z = Float4(src.value[2]);
63519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			reg.w = Float4(src.value[3]);
63619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			break;
63719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_ADDR:			reg = r.a0;		break;
63819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_CONSTBOOL:		return r.r[0];   // Dummy
63919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_CONSTINT:		return r.r[0];   // Dummy
64019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_LOOP:			return r.r[0];   // Dummy
64119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_PREDICATE:		return r.r[0];   // Dummy
64219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_SAMPLER:
64319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(src.rel.type == Shader::PARAMETER_VOID)
64419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
64519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				reg.x = As<Float4>(Int4(i));
64619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
64719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			else if(src.rel.type == Shader::PARAMETER_TEMP)
64819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
64919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				reg.x = As<Float4>(Int4(i) + RoundInt(r.r[src.rel.index].x));
65019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
65119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			return reg;
65219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::PARAMETER_OUTPUT:
65319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman            if(src.rel.type == Shader::PARAMETER_VOID)
65419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
65519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				reg = r.o[i];
65619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
65719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			else
65819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
65919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				reg = r.o[i + relativeAddress(r, src)];
66019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
66119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			break;
662894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		default:
663894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			ASSERT(false);
664894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
665894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
66666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		const Float4 &x = reg[(src.swizzle >> 0) & 0x3];
66766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		const Float4 &y = reg[(src.swizzle >> 2) & 0x3];
66866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		const Float4 &z = reg[(src.swizzle >> 4) & 0x3];
66966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		const Float4 &w = reg[(src.swizzle >> 6) & 0x3];
670894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
67166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		Vector4f mod;
672894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
673894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		switch(src.modifier)
674894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
67519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::MODIFIER_NONE:
67666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.x = x;
67766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.y = y;
67866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.z = z;
67966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.w = w;
680894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			break;
68119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::MODIFIER_NEGATE:
68266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.x = -x;
68366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.y = -y;
68466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.z = -z;
68566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.w = -w;
686894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			break;
68719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::MODIFIER_ABS:
68866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.x = Abs(x);
68966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.y = Abs(y);
69066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.z = Abs(z);
69166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.w = Abs(w);
692894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			break;
69319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::MODIFIER_ABS_NEGATE:
69466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.x = -Abs(x);
69566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.y = -Abs(y);
69666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.z = -Abs(z);
69766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.w = -Abs(w);
698894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			break;
69919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::MODIFIER_NOT:
70066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.x = As<Float4>(As<Int4>(x) ^ Int4(0xFFFFFFFF));
70166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.y = As<Float4>(As<Int4>(y) ^ Int4(0xFFFFFFFF));
70266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.z = As<Float4>(As<Int4>(z) ^ Int4(0xFFFFFFFF));
70366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman			mod.w = As<Float4>(As<Int4>(w) ^ Int4(0xFFFFFFFF));
704894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			break;
705894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		default:
706894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			ASSERT(false);
707894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
708894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
709894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		return mod;
710894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
711894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
71219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	Vector4f VertexProgram::readConstant(Registers &r, const Src &src, int offset)
713894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
71419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f c;
71519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
71619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		int i = src.index + offset;
71719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
71819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(src.rel.type == Shader::PARAMETER_VOID)   // Not relative
71919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
72019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[i]));
72119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
72219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.x = c.x.xxxx;
72319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.y = c.y.yyyy;
72419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.z = c.z.zzzz;
72519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.w = c.w.wwww;
72619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
72719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(localShaderConstants)   // Constant may be known at compile time
72819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
729903e025f6cd8d978f013c741431b87b04ae01fd1Alexis Hetu				for(size_t j = 0; j < shader->getLength(); j++)
73019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				{
73119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					const Shader::Instruction &instruction = *shader->getInstruction(j);
73219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
73319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(instruction.opcode == Shader::OPCODE_DEF)
73419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					{
73519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(instruction.dst.index == i)
73619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						{
73719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							c.x = Float4(instruction.src[0].value[0]);
73819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							c.y = Float4(instruction.src[0].value[1]);
73919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							c.z = Float4(instruction.src[0].value[2]);
74019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							c.w = Float4(instruction.src[0].value[3]);
74119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
74219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman							break;
74319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						}
74419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					}
74519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				}
74619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
74719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
74819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else if(src.rel.type == Shader::PARAMETER_LOOP)
74919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
75019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Int loopCounter = r.aL[r.loopDepth];
75119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
75219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[i]) + loopCounter * 16);
75319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
75419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.x = c.x.xxxx;
75519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.y = c.y.yyyy;
75619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.z = c.z.zzzz;
75719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			c.w = c.w.wwww;
75819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
75919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else
76019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
76119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(src.rel.deterministic)
76219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
76319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Int a = relativeAddress(r, src);
76419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
76519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[i]) + a * 16);
76619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
76719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.x = c.x.xxxx;
76819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.y = c.y.yyyy;
76919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.z = c.z.zzzz;
77019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.w = c.w.wwww;
77119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
77219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			else
77319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
77419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				int component = src.rel.swizzle & 0x03;
77519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Float4 a;
77619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
77719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				switch(src.rel.type)
77819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				{
77919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_ADDR:   a = r.a0[component]; break;
78019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_TEMP:   a = r.r[src.rel.index][component]; break;
78119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_INPUT:  a = r.v[src.rel.index][component]; break;
78219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::PARAMETER_OUTPUT: a = r.o[src.rel.index][component]; break;
78366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman				case Shader::PARAMETER_CONST:  a = *Pointer<Float>(r.data + OFFSET(DrawData,vs.c[src.rel.index][component])); break;
78419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				default: ASSERT(false);
78519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				}
78619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
78719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Int4 index = Int4(i) + RoundInt(a) * Int4(src.rel.scale);
78819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
78919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				index = Min(As<UInt4>(index), UInt4(256));   // Clamp to constant register range, c[256] = {0, 0, 0, 0}
79019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
79119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Int index0 = Extract(index, 0);
79219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Int index1 = Extract(index, 1);
79319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Int index2 = Extract(index, 2);
79419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Int index3 = Extract(index, 3);
79519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
79619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.x = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c) + index0 * 16, 16);
79719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.y = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c) + index1 * 16, 16);
79819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.z = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c) + index2 * 16, 16);
79919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c) + index3 * 16, 16);
80019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
80119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				transpose4x4(c.x, c.y, c.z, c.w);
80219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
80319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
80419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
80519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		return c;
80619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
80719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
80819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	Int VertexProgram::relativeAddress(Registers &r, const Shader::Parameter &var)
80919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
81019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		ASSERT(var.rel.deterministic);
81119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
81219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(var.rel.type == Shader::PARAMETER_TEMP)
81319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
81419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			return RoundInt(Extract(r.r[var.rel.index].x, 0)) * var.rel.scale;
81519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
81619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else if(var.rel.type == Shader::PARAMETER_INPUT)
81719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
81819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			return RoundInt(Extract(r.v[var.rel.index].x, 0)) * var.rel.scale;
81919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
82019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else if(var.rel.type == Shader::PARAMETER_OUTPUT)
82119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
82219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			return RoundInt(Extract(r.o[var.rel.index].x, 0)) * var.rel.scale;
82319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
82419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else if(var.rel.type == Shader::PARAMETER_CONST)
82519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
82619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			RValue<Float4> c = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[var.rel.index]));
82719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
82819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			return RoundInt(Extract(c, 0)) * var.rel.scale;
82919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
83019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else ASSERT(false);
83119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
83219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		return 0;
83319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
83419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
83519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	Int4 VertexProgram::enableMask(Registers &r, const Shader::Instruction *instruction)
83619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
83719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Int4 enable = instruction->analysisBranch ? Int4(r.enableStack[r.enableIndex]) : Int4(0xFFFFFFFF);
838d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
839d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman		if(!whileTest)
84019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
841d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			if(shader->containsBreakInstruction() && instruction->analysisBreak)
842d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			{
843d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman				enable &= r.enableBreak;
844d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			}
84519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
846d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			if(shader->containsContinueInstruction() && instruction->analysisContinue)
847d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			{
848d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman				enable &= r.enableContinue;
849d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			}
85019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
851d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			if(shader->containsLeaveInstruction() && instruction->analysisLeave)
852d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			{
853d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman				enable &= r.enableLeave;
854d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			}
85519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
85619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
85719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		return enable;
85819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
85919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
86019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::M3X2(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1)
86119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
86219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row0 = reg(r, src1, 0);
86319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row1 = reg(r, src1, 1);
864894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
865894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.x = dot3(src0, row0);
866894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.y = dot3(src0, row1);
867894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
868894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
86919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::M3X3(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1)
870894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
87119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row0 = reg(r, src1, 0);
87219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row1 = reg(r, src1, 1);
87319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row2 = reg(r, src1, 2);
874894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
875894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.x = dot3(src0, row0);
876894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.y = dot3(src0, row1);
877894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.z = dot3(src0, row2);
878894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
879894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
88019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::M3X4(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1)
881894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
88219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row0 = reg(r, src1, 0);
88319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row1 = reg(r, src1, 1);
88419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row2 = reg(r, src1, 2);
88519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row3 = reg(r, src1, 3);
886894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
887894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.x = dot3(src0, row0);
888894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.y = dot3(src0, row1);
889894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.z = dot3(src0, row2);
890894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.w = dot3(src0, row3);
891894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
892894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
89319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::M4X3(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1)
894894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
89519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row0 = reg(r, src1, 0);
89619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row1 = reg(r, src1, 1);
89719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row2 = reg(r, src1, 2);
898894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
899894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.x = dot4(src0, row0);
900894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.y = dot4(src0, row1);
901894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.z = dot4(src0, row2);
902894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
903894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
90419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::M4X4(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1)
905894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
90619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row0 = reg(r, src1, 0);
90719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row1 = reg(r, src1, 1);
90819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row2 = reg(r, src1, 2);
90919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f row3 = reg(r, src1, 3);
910894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
911894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.x = dot4(src0, row0);
912894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.y = dot4(src0, row1);
913894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.z = dot4(src0, row2);
914894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.w = dot4(src0, row3);
915894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
916894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
917894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::BREAK(Registers &r)
918894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
919894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *deadBlock = Nucleus::createBasicBlock();
920894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1];
921894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
922894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(breakDepth == 0)
923894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
92419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.enableIndex = r.enableIndex - breakDepth;
925894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Nucleus::createBr(endBlock);
926894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
927894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else
928894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
929894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			r.enableBreak = r.enableBreak & ~r.enableStack[r.enableIndex];
930894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Bool allBreak = SignMask(r.enableBreak) == 0x0;
931894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
93219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.enableIndex = r.enableIndex - breakDepth;
933894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			branch(allBreak, endBlock, deadBlock);
934894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
935894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
936894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(deadBlock);
93719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableIndex = r.enableIndex + breakDepth;
938894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
939894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
94019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::BREAKC(Registers &r, Vector4f &src0, Vector4f &src1, Control control)
941894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
942894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Int4 condition;
943894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
944894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		switch(control)
945894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
94619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_GT: condition = CmpNLE(src0.x,  src1.x);	break;
94719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x);		break;
94819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x);	break;
94919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_LT: condition = CmpLT(src0.x,  src1.x);	break;
95019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x);	break;
95119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x);		break;
952894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		default:
953894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			ASSERT(false);
954894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
955894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
95619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		BREAK(r, condition);
957894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
958894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
959894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::BREAKP(Registers &r, const Src &predicateRegister)   // FIXME: Factor out parts common with BREAKC
960894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
961894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]);
962894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
96319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(predicateRegister.modifier == Shader::MODIFIER_NOT)
964894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
965894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			condition = ~condition;
966894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
967894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
96819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		BREAK(r, condition);
96919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
97019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
97119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::BREAK(Registers &r, Int4 &condition)
97219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
973894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		condition &= r.enableStack[r.enableIndex];
974894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
975894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *continueBlock = Nucleus::createBasicBlock();
976894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1];
977894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
978894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.enableBreak = r.enableBreak & ~condition;
979894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Bool allBreak = SignMask(r.enableBreak) == 0x0;
980894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
98119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableIndex = r.enableIndex - breakDepth;
982894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		branch(allBreak, endBlock, continueBlock);
98319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
984894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(continueBlock);
98519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableIndex = r.enableIndex + breakDepth;
986894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
987894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
98819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::CONTINUE(Registers &r)
98919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
99019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableContinue = r.enableContinue & ~r.enableStack[r.enableIndex];
99119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
99219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
99319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::TEST()
99419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
99519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		whileTest = true;
99619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
99719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
99819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::CALL(Registers &r, int labelIndex, int callSiteIndex)
999894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1000894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(!labelBlock[labelIndex])
1001894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1002894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			labelBlock[labelIndex] = Nucleus::createBasicBlock();
1003894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1004894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
100519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(callRetBlock[labelIndex].size() > 1)
100619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
100719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.callStack[r.stackIndex++] = UInt(callSiteIndex);
100819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
1009894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
101019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Int4 restoreLeave = r.enableLeave;
1011894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1012894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::createBr(labelBlock[labelIndex]);
101319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]);
101419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
101519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableLeave = restoreLeave;
1016894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1017894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
101819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::CALLNZ(Registers &r, int labelIndex, int callSiteIndex, const Src &src)
1019894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
102019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(src.type == Shader::PARAMETER_CONSTBOOL)
1021894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
102219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			CALLNZb(r, labelIndex, callSiteIndex, src);
1023894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
102419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else if(src.type == Shader::PARAMETER_PREDICATE)
1025894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
102619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			CALLNZp(r, labelIndex, callSiteIndex, src);
1027894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1028894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else ASSERT(false);
1029894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1030894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
103119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::CALLNZb(Registers &r, int labelIndex, int callSiteIndex, const Src &boolRegister)
1032894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1033894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,vs.b[boolRegister.index])) != Byte(0));   // FIXME
1034894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
103519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(boolRegister.modifier == Shader::MODIFIER_NOT)
1036894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1037894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			condition = !condition;
1038894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1039894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1040894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(!labelBlock[labelIndex])
1041894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1042894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			labelBlock[labelIndex] = Nucleus::createBasicBlock();
1043894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1044894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
104519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(callRetBlock[labelIndex].size() > 1)
104619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
104719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.callStack[r.stackIndex++] = UInt(callSiteIndex);
104819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
1049894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
105019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Int4 restoreLeave = r.enableLeave;
1051894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
105219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		branch(condition, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]);
105319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]);
105419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
105519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableLeave = restoreLeave;
1056894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1057894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
105819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::CALLNZp(Registers &r, int labelIndex, int callSiteIndex, const Src &predicateRegister)
1059894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1060894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]);
1061894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
106219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(predicateRegister.modifier == Shader::MODIFIER_NOT)
1063894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1064894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			condition = ~condition;
1065894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1066894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1067894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		condition &= r.enableStack[r.enableIndex];
1068894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1069894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(!labelBlock[labelIndex])
1070894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1071894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			labelBlock[labelIndex] = Nucleus::createBasicBlock();
1072894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1073894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
107419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(callRetBlock[labelIndex].size() > 1)
107519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
107619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			r.callStack[r.stackIndex++] = UInt(callSiteIndex);
107719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
1078894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1079894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.enableIndex++;
1080894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.enableStack[r.enableIndex] = condition;
108119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Int4 restoreLeave = r.enableLeave;
1082894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
108319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Bool notAllFalse = SignMask(condition) != 0;
108419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		branch(notAllFalse, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]);
108519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]);
1086894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1087894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.enableIndex--;
108819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableLeave = restoreLeave;
1089894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1090894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1091894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::ELSE(Registers &r)
1092894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1093894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifDepth--;
1094894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1095894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *falseBlock = ifFalseBlock[ifDepth];
1096894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *endBlock = Nucleus::createBasicBlock();
1097894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1098894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(isConditionalIf[ifDepth])
1099894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Int4 condition = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1];
110119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Bool notAllFalse = SignMask(condition) != 0;
1102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			branch(notAllFalse, falseBlock, endBlock);
1104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			r.enableStack[r.enableIndex] = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1];
1106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else
1108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Nucleus::createBr(endBlock);
1110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Nucleus::setInsertBlock(falseBlock);
1111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifFalseBlock[ifDepth] = endBlock;
1114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifDepth++;
1116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::ENDIF(Registers &r)
1119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifDepth--;
1121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *endBlock = ifFalseBlock[ifDepth];
1123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::createBr(endBlock);
1125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(endBlock);
1126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(isConditionalIf[ifDepth])
1128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			breakDepth--;
1130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			r.enableIndex--;
1131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
113419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::ENDLOOP(Registers &r)
1135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepDepth--;
1137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
113819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.aL[r.loopDepth] = r.aL[r.loopDepth] + r.increment[r.loopDepth];   // FIXME: +=
113919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
1140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth];
1141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth];
1142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::createBr(testBlock);
1144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(endBlock);
1145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.loopDepth--;
1147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
1148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
115019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::ENDREP(Registers &r)
1151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepDepth--;
1153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth];
1155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth];
1156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::createBr(testBlock);
1158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(endBlock);
1159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.loopDepth--;
1161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
1162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
116419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::ENDWHILE(Registers &r)
116519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
116619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		loopRepDepth--;
116719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
116819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth];
116919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth];
117019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
117119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::createBr(testBlock);
117219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::setInsertBlock(endBlock);
117319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
117419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableIndex--;
117519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
117619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		whileTest = false;
117719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
117819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
1179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::IF(Registers &r, const Src &src)
1180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
118119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(src.type == Shader::PARAMETER_CONSTBOOL)
1182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			IFb(r, src);
1184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
118519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else if(src.type == Shader::PARAMETER_PREDICATE)
1186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			IFp(r, src);
1188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
118919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else
119019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
119119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Int4 condition = As<Int4>(reg(r, src).x);
119219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			IF(r, condition);
119319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
1194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::IFb(Registers &r, const Src &boolRegister)
1197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ASSERT(ifDepth < 24 + 4);
1199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,vs.b[boolRegister.index])) != Byte(0));   // FIXME
1201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
120219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(boolRegister.modifier == Shader::MODIFIER_NOT)
1203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
120419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			condition = !condition;
1205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock();
1208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock();
1209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		branch(condition, trueBlock, falseBlock);
1211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		isConditionalIf[ifDepth] = false;
1213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifFalseBlock[ifDepth] = falseBlock;
1214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifDepth++;
1216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
121819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::IFp(Registers &r, const Src &predicateRegister)
1219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]);
1221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
122219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(predicateRegister.modifier == Shader::MODIFIER_NOT)
1223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			condition = ~condition;
1225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
122719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		IF(r, condition);
1228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
123019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::IFC(Registers &r, Vector4f &src0, Vector4f &src1, Control control)
1231894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Int4 condition;
1233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		switch(control)
1235894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
123619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_GT: condition = CmpNLE(src0.x,  src1.x);	break;
123719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x);		break;
123819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x);	break;
123919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_LT: condition = CmpLT(src0.x,  src1.x);	break;
124019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x);	break;
124119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x);		break;
1242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		default:
1243894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			ASSERT(false);
1244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1245894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
124619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		IF(r, condition);
124719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
124819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
124919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::IF(Registers &r, Int4 &condition)
125019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
1251894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		condition &= r.enableStack[r.enableIndex];
1252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.enableIndex++;
1254894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.enableStack[r.enableIndex] = condition;
1255894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1256894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock();
1257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock();
1258894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
125919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Bool notAllFalse = SignMask(condition) != 0;
1260894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		branch(notAllFalse, trueBlock, falseBlock);
1262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		isConditionalIf[ifDepth] = true;
1264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifFalseBlock[ifDepth] = falseBlock;
1265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ifDepth++;
1267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		breakDepth++;
1268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1270894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::LABEL(int labelIndex)
1271894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
127219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(!labelBlock[labelIndex])
127319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
127419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			labelBlock[labelIndex] = Nucleus::createBasicBlock();
127519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
127619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
1277894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(labelBlock[labelIndex]);
127819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		currentLabel = labelIndex;
1279894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1280894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1281894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::LOOP(Registers &r, const Src &integerRegister)
1282894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1283894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.loopDepth++;
1284894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1285894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,vs.i[integerRegister.index][0]));
1286894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.aL[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,vs.i[integerRegister.index][1]));
1287894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.increment[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,vs.i[integerRegister.index][2]));
1288894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1289894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		// FIXME: Compiles to two instructions?
1290894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		If(r.increment[r.loopDepth] == 0)
1291894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1292894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			r.increment[r.loopDepth] = 1;
1293894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1294894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1295894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock();
1296894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *testBlock = Nucleus::createBasicBlock();
1297894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *endBlock = Nucleus::createBasicBlock();
1298894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1299894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepTestBlock[loopRepDepth] = testBlock;
1300894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepEndBlock[loopRepDepth] = endBlock;
1301894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1302894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		// FIXME: jump(testBlock)
1303894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::createBr(testBlock);
1304894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(testBlock);
1305894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1306894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock);
1307894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(loopBlock);
1308894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1309894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1;   // FIXME: --
1310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1311894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepDepth++;
1312894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		breakDepth = 0;
1313894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1314894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1315894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::REP(Registers &r, const Src &integerRegister)
1316894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
1317894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.loopDepth++;
1318894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1319894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,vs.i[integerRegister.index][0]));
1320894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.aL[r.loopDepth] = r.aL[r.loopDepth - 1];
1321894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1322894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock();
1323894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *testBlock = Nucleus::createBasicBlock();
1324894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		llvm::BasicBlock *endBlock = Nucleus::createBasicBlock();
1325894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1326894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepTestBlock[loopRepDepth] = testBlock;
1327894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepEndBlock[loopRepDepth] = endBlock;
1328894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		// FIXME: jump(testBlock)
1330894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::createBr(testBlock);
1331894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(testBlock);
1332894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1333894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock);
1334894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		Nucleus::setInsertBlock(loopBlock);
1335894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1336894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1;   // FIXME: --
1337894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1338894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		loopRepDepth++;
1339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		breakDepth = 0;
1340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1341894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
134219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::WHILE(Registers &r, const Src &temporaryRegister)
134319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
134419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableIndex++;
134519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
134619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock();
134719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		llvm::BasicBlock *testBlock = Nucleus::createBasicBlock();
134819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		llvm::BasicBlock *endBlock = Nucleus::createBasicBlock();
134919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
135019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		loopRepTestBlock[loopRepDepth] = testBlock;
135119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		loopRepEndBlock[loopRepDepth] = endBlock;
135219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
135319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Int4 restoreBreak = r.enableBreak;
135419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Int4 restoreContinue = r.enableContinue;
135519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
135619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		// FIXME: jump(testBlock)
135719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::createBr(testBlock);
135819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::setInsertBlock(testBlock);
135919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableContinue = restoreContinue;
136019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
136166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		const Vector4f &src = reg(r, temporaryRegister);
136219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Int4 condition = As<Int4>(src.x);
136319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		condition &= r.enableStack[r.enableIndex - 1];
136419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableStack[r.enableIndex] = condition;
136519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
136619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Bool notAllFalse = SignMask(condition) != 0;
136719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		branch(notAllFalse, loopBlock, endBlock);
136819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
136919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::setInsertBlock(endBlock);
137019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableBreak = restoreBreak;
137119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
137219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Nucleus::setInsertBlock(loopBlock);
137319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
137419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		loopRepDepth++;
137519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		breakDepth = 0;
137619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
137719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
1378894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void VertexProgram::RET(Registers &r)
1379894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
138019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(currentLabel == -1)
1381894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1382894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			returnBlock = Nucleus::createBasicBlock();
1383894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Nucleus::createBr(returnBlock);
1384894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1385894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else
1386894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
1387894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			llvm::BasicBlock *unreachableBlock = Nucleus::createBasicBlock();
1388894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
138919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(callRetBlock[currentLabel].size() > 1)   // Pop the return destination from the call stack
1390894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
139119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				// FIXME: Encapsulate
139219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				UInt index = r.callStack[--r.stackIndex];
139319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
139466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman				llvm::Value *value = index.loadValue();
139519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				llvm::Value *switchInst = Nucleus::createSwitch(value, unreachableBlock, (int)callRetBlock[currentLabel].size());
139619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
139719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				for(unsigned int i = 0; i < callRetBlock[currentLabel].size(); i++)
139819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				{
139919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					Nucleus::addSwitchCase(switchInst, i, callRetBlock[currentLabel][i]);
140019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				}
140119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
140219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			else if(callRetBlock[currentLabel].size() == 1)   // Jump directly to the unique return destination
140319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
140419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Nucleus::createBr(callRetBlock[currentLabel][0]);
140519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
140619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			else   // Function isn't called
140719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
140819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Nucleus::createBr(unreachableBlock);
1409894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
1410894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1411894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Nucleus::setInsertBlock(unreachableBlock);
1412894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			Nucleus::createUnreachable();
1413894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
1414894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
1415894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
141619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::LEAVE(Registers &r)
1417894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
141819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		r.enableLeave = r.enableLeave & ~r.enableStack[r.enableIndex];
141919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
142019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		// FIXME: Return from function if all instances left
142119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		// FIXME: Use enableLeave in other control-flow constructs
142219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
1423894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
142419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::TEXLDL(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1)
142519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
142619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f tmp;
142719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		sampleTexture(r, tmp, src1, src0.x, src0.y, src0.z, src0.w);
142819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
142919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		dst.x = tmp[(src1.swizzle >> 0) & 0x3];
143019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		dst.y = tmp[(src1.swizzle >> 2) & 0x3];
143119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		dst.z = tmp[(src1.swizzle >> 4) & 0x3];
143219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		dst.w = tmp[(src1.swizzle >> 6) & 0x3];
143319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
1434894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
143519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::TEX(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1)
143619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
143719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Float4 lod = Float4(0.0f);
143819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		Vector4f tmp;
143919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		sampleTexture(r, tmp, src1, src0.x, src0.y, src0.z, lod);
1440894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1441894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.x = tmp[(src1.swizzle >> 0) & 0x3];
1442894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.y = tmp[(src1.swizzle >> 2) & 0x3];
1443894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.z = tmp[(src1.swizzle >> 4) & 0x3];
1444894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		dst.w = tmp[(src1.swizzle >> 6) & 0x3];
1445894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
144619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
144719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void VertexProgram::sampleTexture(Registers &r, Vector4f &c, const Src &s, Float4 &u, Float4 &v, Float4 &w, Float4 &q)
144819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
144919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(s.type == Shader::PARAMETER_SAMPLER && s.rel.type == Shader::PARAMETER_VOID)
145019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
145119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap[16]) + s.index * sizeof(Texture);
145219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			sampler[s.index]->sampleTexture(texture, c, u, v, w, q, r.a0, r.a0, false, false, true);
145319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
145419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		else
145519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		{
145619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Int index = As<Int>(Float(reg(r, s).x.x));
145719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
145819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			for(int i = 0; i < 16; i++)
145919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			{
146019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				if(shader->usesSampler(i))
146119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				{
146219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					If(index == i)
146319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					{
146419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap[16]) + i * sizeof(Texture);
146519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						sampler[i]->sampleTexture(texture, c, u, v, w, q, r.a0, r.a0, false, false, true);
146619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						// FIXME: When the sampler states are the same, we could use one sampler and just index the texture
146719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					}
146819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				}
146919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			}
147019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		}
147119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
1472894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
1473