10bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
30bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// Licensed under the Apache License, Version 2.0 (the "License");
40bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// you may not use this file except in compliance with the License.
50bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// You may obtain a copy of the License at
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
70bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens//    http://www.apache.org/licenses/LICENSE-2.0
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
90bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// Unless required by applicable law or agreed to in writing, software
100bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// distributed under the License is distributed on an "AS IS" BASIS,
110bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// See the License for the specific language governing permissions and
130bac285a78df6a6d7a6b68784748b92805420ffbNicolas Capens// limitations under the License.
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "PixelShader.hpp"
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "Debug.hpp"
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
1966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include <string.h>
2066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace sw
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
2319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	PixelShader::PixelShader(const PixelShader *ps) : Shader()
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
2519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		version = 0x0300;
2619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		vPosDeclared = false;
2719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		vFaceDeclared = false;
2819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		centroid = false;
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
3019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		if(ps)   // Make a copy
31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
32903e025f6cd8d978f013c741431b87b04ae01fd1Alexis Hetu			for(size_t i = 0; i < ps->getLength(); i++)
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
3419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				append(new sw::Shader::Instruction(*ps->getInstruction(i)));
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
3702ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			memcpy(input, ps->input, sizeof(input));
3819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			vPosDeclared = ps->vPosDeclared;
3919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			vFaceDeclared = ps->vFaceDeclared;
4019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			usedSamplers = ps->usedSamplers;
41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
42d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman			optimize();
4319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			analyze();
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
4519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
4719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	PixelShader::PixelShader(const unsigned long *token) : Shader()
4819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
4919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		parse(token);
5019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
5119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		vPosDeclared = false;
5219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		vFaceDeclared = false;
5319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		centroid = false;
5419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
55d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman		optimize();
5619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyze();
5719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
5819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
5919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	PixelShader::~PixelShader()
6019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	int PixelShader::validate(const unsigned long *const token)
64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(!token)
66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			return 0;
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		unsigned short version = (unsigned short)(token[0] & 0x0000FFFF);
717208e932c933a3b52c014e558c7f3f1d03dc80b2Alexis Hetu		// unsigned char minorVersion = (unsigned char)(token[0] & 0x000000FF);
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		unsigned char majorVersion = (unsigned char)((token[0] & 0x0000FF00) >> 8);
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		ShaderType shaderType = (ShaderType)((token[0] & 0xFFFF0000) >> 16);
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(shaderType != SHADER_PIXEL || majorVersion > 3)
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			return 0;
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		int instructionCount = 1;
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		for(int i = 0; token[i] != 0x0000FFFF; i++)
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if((token[i] & 0x0000FFFF) == 0x0000FFFE)   // Comment token
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				int length = (token[i] & 0x7FFF0000) >> 16;
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				i += length;
89894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			else
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
9219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				Shader::Opcode opcode = (Shader::Opcode)(token[i] & 0x0000FFFF);
93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				switch(opcode)
95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
9619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::OPCODE_RESERVED0:
9719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				case Shader::OPCODE_MOVA:
98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					return 0;   // Unsupported operation
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				default:
100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					instructionCount++;
101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					break;
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				i += size(token[i], version);
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		return instructionCount;
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool PixelShader::depthOverride() const
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		return zOverride;
114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
11619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	bool PixelShader::containsKill() const
117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
11819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		return kill;
119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool PixelShader::containsCentroid() const
122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		return centroid;
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool PixelShader::usesDiffuse(int component) const
127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
12802ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu		return input[0][component].active();
129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool PixelShader::usesSpecular(int component) const
132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
13302ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu		return input[1][component].active();
134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool PixelShader::usesTexture(int coordinate, int component) const
137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
13802ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu		return input[2 + coordinate][component].active();
13902ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu	}
14002ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu
14102ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu	void PixelShader::setInput(int inputIdx, int nbComponents, const sw::Shader::Semantic& semantic)
14202ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu	{
14302ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu		for(int i = 0; i < nbComponents; ++i)
14402ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu		{
14502ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[inputIdx][i] = semantic;
14602ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu		}
14702ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu	}
14802ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu
14902ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu	const sw::Shader::Semantic& PixelShader::getInput(int inputIdx, int component) const
15002ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu	{
15102ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu		return input[inputIdx][component];
152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
15419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void PixelShader::analyze()
15519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	{
15619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyzeZOverride();
15719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyzeKill();
15819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyzeInterpolants();
15919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyzeDirtyConstants();
16019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyzeDynamicBranching();
16119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyzeSamplers();
16219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyzeCallSites();
16319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		analyzeDynamicIndexing();
16419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	}
16519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void PixelShader::analyzeZOverride()
167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		zOverride = false;
169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
17019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		for(unsigned int i = 0; i < instruction.size(); i++)
171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
17219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(instruction[i]->opcode == Shader::OPCODE_TEXM3X2DEPTH ||
17319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			   instruction[i]->opcode == Shader::OPCODE_TEXDEPTH ||
17419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			   instruction[i]->dst.type == Shader::PARAMETER_DEPTHOUT)
175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				zOverride = true;
177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				break;
179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
18319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	void PixelShader::analyzeKill()
184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
18519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		kill = false;
186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
18719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman		for(unsigned int i = 0; i < instruction.size(); i++)
188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
18919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			if(instruction[i]->opcode == Shader::OPCODE_TEXKILL ||
19019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			   instruction[i]->opcode == Shader::OPCODE_DISCARD)
191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
19219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				kill = true;
193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				break;
195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	void PixelShader::analyzeInterpolants()
200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(version < 0x0300)
202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			// Set default mapping; disable unused interpolants below
20402ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[0][0] = Semantic(Shader::USAGE_COLOR, 0);
20502ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[0][1] = Semantic(Shader::USAGE_COLOR, 0);
20602ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[0][2] = Semantic(Shader::USAGE_COLOR, 0);
20702ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[0][3] = Semantic(Shader::USAGE_COLOR, 0);
208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
20902ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[1][0] = Semantic(Shader::USAGE_COLOR, 1);
21002ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[1][1] = Semantic(Shader::USAGE_COLOR, 1);
21102ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[1][2] = Semantic(Shader::USAGE_COLOR, 1);
21202ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu			input[1][3] = Semantic(Shader::USAGE_COLOR, 1);
213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			for(int i = 0; i < 8; i++)
215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
21602ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu				input[2 + i][0] = Semantic(Shader::USAGE_TEXCOORD, i);
21702ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu				input[2 + i][1] = Semantic(Shader::USAGE_TEXCOORD, i);
21802ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu				input[2 + i][2] = Semantic(Shader::USAGE_TEXCOORD, i);
21902ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu				input[2 + i][3] = Semantic(Shader::USAGE_TEXCOORD, i);
220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
22219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			Shader::SamplerType samplerType[16];
223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			for(int i = 0; i < 16; i++)
225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
22619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				samplerType[i] = Shader::SAMPLER_UNKNOWN;
227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
22919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			for(unsigned int i = 0; i < instruction.size(); i++)
230894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
23119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				if(instruction[i]->dst.type == Shader::PARAMETER_SAMPLER)
232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
23319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					int sampler = instruction[i]->dst.index;
234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
23519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					samplerType[sampler] = instruction[i]->samplerType;
236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
2393b4c93fea93733b5ab29902ce2b3c864e40d156cNicolas Capens			bool interpolant[MAX_FRAGMENT_INPUTS][4] = {{false}};   // Interpolants in use
240894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
24119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			for(unsigned int i = 0; i < instruction.size(); i++)
242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
24319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				if(instruction[i]->dst.type == Shader::PARAMETER_TEXTURE)
2446abe1cbc78e0c9fdf3bb8f713f2d0ebc8cf9bbddNicolas Capens				{
24519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					int index = instruction[i]->dst.index + 2;
246894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
24719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					switch(instruction[i]->opcode)
248894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
24919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEX:
25019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXBEM:
25119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXBEML:
25219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXCOORD:
25319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXDP3:
25419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXDP3TEX:
25519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXM3X2DEPTH:
25619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXM3X2PAD:
25719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXM3X2TEX:
25819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXM3X3:
25919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXM3X3PAD:
26019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXM3X3TEX:
261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index][0] = true;
262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index][1] = true;
263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index][2] = true;
264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
26519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXKILL:
266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						if(majorVersion < 2)
267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] = true;
269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] = true;
270894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] = true;
271894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
272894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						else
273894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
274894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] = true;
275894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] = true;
276894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] = true;
277894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][3] = true;
278894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
279894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
28019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_TEXM3X3VSPEC:
281894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index][0] = true;
282894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index][1] = true;
283894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index][2] = true;
284894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index - 2][3] = true;
285894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index - 1][3] = true;
286894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						interpolant[index - 0][3] = true;
287894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
28819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::OPCODE_DCL:
289894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;   // Ignore
290894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					default:   // Arithmetic instruction
291894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						if(version >= 0x0104)
292894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
293894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							ASSERT(false);
294894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
295894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
296894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
297894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
298894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				for(int argument = 0; argument < 4; argument++)
299894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
30019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(instruction[i]->src[argument].type == Shader::PARAMETER_INPUT ||
30119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					   instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE)
302894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
30319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						int index = instruction[i]->src[argument].index;
30419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						int swizzle = instruction[i]->src[argument].swizzle;
30519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						int mask = instruction[i]->dst.mask;
3066abe1cbc78e0c9fdf3bb8f713f2d0ebc8cf9bbddNicolas Capens
30719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						if(instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE)
308894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
309894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							index += 2;
310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
311894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
31219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						switch(instruction[i]->opcode)
313894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
31419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEX:
31519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXLDD:
31619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXLDL:
31725d47fc9eb8e8aaf864fab0d6aa7305d034d807bAlexis Hetu						case Shader::OPCODE_TEXOFFSET:
31825d47fc9eb8e8aaf864fab0d6aa7305d034d807bAlexis Hetu						case Shader::OPCODE_TEXLDLOFFSET:
31925d47fc9eb8e8aaf864fab0d6aa7305d034d807bAlexis Hetu						case Shader::OPCODE_TEXELFETCH:
32025d47fc9eb8e8aaf864fab0d6aa7305d034d807bAlexis Hetu						case Shader::OPCODE_TEXELFETCHOFFSET:
32125d47fc9eb8e8aaf864fab0d6aa7305d034d807bAlexis Hetu						case Shader::OPCODE_TEXGRAD:
32225d47fc9eb8e8aaf864fab0d6aa7305d034d807bAlexis Hetu						case Shader::OPCODE_TEXGRADOFFSET:
323894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
32419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								int sampler = instruction[i]->src[1].index;
325894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
326894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								switch(samplerType[sampler])
327894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
32819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								case Shader::SAMPLER_UNKNOWN:
329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									if(version == 0x0104)
330894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									{
33119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman										if((instruction[i]->src[0].swizzle & 0x30) == 0x20)   // .xyz
332894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman										{
333894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman											interpolant[index][0] = true;
334894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman											interpolant[index][1] = true;
335894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman											interpolant[index][2] = true;
336894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman										}
337894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman										else   // .xyw
338894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman										{
339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman											interpolant[index][0] = true;
340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman											interpolant[index][1] = true;
341894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman											interpolant[index][3] = true;
342894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman										}
343894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									}
344894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									else
345894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									{
346894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman										ASSERT(false);
347894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									}
348894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									break;
34919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								case Shader::SAMPLER_1D:
350894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][0] = true;
351894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									break;
35219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								case Shader::SAMPLER_2D:
353894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][0] = true;
354894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][1] = true;
355894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									break;
35619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								case Shader::SAMPLER_CUBE:
357894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][0] = true;
358894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][1] = true;
359894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][2] = true;
360894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									break;
36119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								case Shader::SAMPLER_VOLUME:
362894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][0] = true;
363894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][1] = true;
364894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][2] = true;
365894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									break;
366894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								default:
367894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									ASSERT(false);
368894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
369894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
37019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(instruction[i]->bias)
371894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
372894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][3] = true;
373894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
374894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
37519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(instruction[i]->project)
376894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
377894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index][3] = true;
378894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
379894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
38019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman								if(version == 0x0104 && instruction[i]->opcode == Shader::OPCODE_TEX)
381894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
38219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman									if(instruction[i]->src[0].modifier == Shader::MODIFIER_DZ)
383894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									{
384894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman										interpolant[index][2] = true;
385894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									}
386894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
38719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman									if(instruction[i]->src[0].modifier == Shader::MODIFIER_DW)
388894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									{
389894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman										interpolant[index][3] = true;
390894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									}
391894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
392894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
393894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
39419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_M3X2:
395894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(mask & 0x1)
396894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
397894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
398894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
399894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
400894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
401894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
402894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
403894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(argument == 1)
404894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
405894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x2)
406894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
407894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
408894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
409894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
410894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
411894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
412894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
413894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
41419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_M3X3:
415894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(mask & 0x1)
416894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
417894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
418894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
419894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
420894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
421894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
422894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
423894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(argument == 1)
424894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
425894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x2)
426894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
427894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
428894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
429894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
430894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
431894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
432894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
433894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x4)
434894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
435894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
436894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
437894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
438894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
439894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
440894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
441894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
44219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_M3X4:
443894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(mask & 0x1)
444894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
445894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
446894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
447894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
448894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
449894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
450894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
451894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(argument == 1)
452894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
453894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x2)
454894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
455894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
456894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
457894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
458894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
459894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
460894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
461894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x4)
462894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
463894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
464894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
465894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
466894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
467894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
468894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
469894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x8)
470894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
471894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 3][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
472894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 3][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
473894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 3][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
474894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 3][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
475894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
476894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
477894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
47819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_M4X3:
479894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(mask & 0x1)
480894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
481894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponent(swizzle, 0);
482894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponent(swizzle, 1);
483894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponent(swizzle, 2);
484894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponent(swizzle, 3);
485894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
486894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
487894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(argument == 1)
488894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
489894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x2)
490894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
491894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][0] |= swizzleContainsComponent(swizzle, 0);
492894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][1] |= swizzleContainsComponent(swizzle, 1);
493894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][2] |= swizzleContainsComponent(swizzle, 2);
494894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][3] |= swizzleContainsComponent(swizzle, 3);
495894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
496894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
497894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x4)
498894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
499894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][0] |= swizzleContainsComponent(swizzle, 0);
500894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][1] |= swizzleContainsComponent(swizzle, 1);
501894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][2] |= swizzleContainsComponent(swizzle, 2);
502894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][3] |= swizzleContainsComponent(swizzle, 3);
503894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
504894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
505894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
50619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_M4X4:
507894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(mask & 0x1)
508894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
509894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponent(swizzle, 0);
510894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponent(swizzle, 1);
511894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponent(swizzle, 2);
512894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponent(swizzle, 3);
513894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
514894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
515894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(argument == 1)
516894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
517894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x2)
518894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
519894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][0] |= swizzleContainsComponent(swizzle, 0);
520894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][1] |= swizzleContainsComponent(swizzle, 1);
521894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][2] |= swizzleContainsComponent(swizzle, 2);
522894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 1][3] |= swizzleContainsComponent(swizzle, 3);
523894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
524894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
525894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x4)
526894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
527894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][0] |= swizzleContainsComponent(swizzle, 0);
528894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][1] |= swizzleContainsComponent(swizzle, 1);
529894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][2] |= swizzleContainsComponent(swizzle, 2);
530894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 2][3] |= swizzleContainsComponent(swizzle, 3);
531894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
532894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
533894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								if(mask & 0x8)
534894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								{
535894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 3][0] |= swizzleContainsComponent(swizzle, 0);
536894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 3][1] |= swizzleContainsComponent(swizzle, 1);
537894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 3][2] |= swizzleContainsComponent(swizzle, 2);
538894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman									interpolant[index + 3][3] |= swizzleContainsComponent(swizzle, 3);
539894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								}
540894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
541894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
54219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_CRS:
543894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(mask & 0x1)
544894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
545894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x6);
546894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x6);
547894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x6);
548894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x6);
549894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
550894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
551894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(mask & 0x2)
552894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
553894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x5);
554894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x5);
555894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x5);
556894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x5);
557894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
558894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
559894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(mask & 0x4)
560894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
561894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x3);
562894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x3);
563894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x3);
564894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x3);
565894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
566894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
56719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_DP2ADD:
568894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							if(argument == 0 || argument == 1)
569894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
570894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x3);
571894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x3);
572894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x3);
573894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x3);
574894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
575894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							else   // argument == 2
576894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							{
577894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][0] |= swizzleContainsComponent(swizzle, 0);
578894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][1] |= swizzleContainsComponent(swizzle, 1);
579894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][2] |= swizzleContainsComponent(swizzle, 2);
580894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman								interpolant[index][3] |= swizzleContainsComponent(swizzle, 3);
581894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							}
582894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
58319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_DP3:
584894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7);
585894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7);
586894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7);
587894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7);
588894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
58919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_DP4:
590894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] |= swizzleContainsComponent(swizzle, 0);
591894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] |= swizzleContainsComponent(swizzle, 1);
592894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] |= swizzleContainsComponent(swizzle, 2);
593894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][3] |= swizzleContainsComponent(swizzle, 3);
594894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
59519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_SINCOS:
59619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_EXP2X:
59719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_LOG2X:
59819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_POWX:
59919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_RCPX:
60019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_RSQX:
601894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] |= swizzleContainsComponent(swizzle, 0);
602894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] |= swizzleContainsComponent(swizzle, 1);
603894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] |= swizzleContainsComponent(swizzle, 2);
604894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][3] |= swizzleContainsComponent(swizzle, 3);
605894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
60619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_NRM3:
607894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7 | mask);
608894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7 | mask);
609894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7 | mask);
610894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7 | mask);
611894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
61219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_MOV:
61319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_ADD:
61419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_SUB:
61519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_MUL:
61619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_MAD:
61719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_ABS:
61819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_CMP0:
61919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_CND:
62019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_FRC:
62119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_LRP:
62219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_MAX:
62319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_MIN:
62419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_CMP:
62519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_BREAKC:
62619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_DFDX:
62719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_DFDY:
628894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, mask);
629894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, mask);
630894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, mask);
631894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, mask);
632894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
63319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXCOORD:
634894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] = true;
635894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] = true;
636894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] = true;
637894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][3] = true;
638894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
63919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXDP3:
64019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXDP3TEX:
64119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXM3X2PAD:
64219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXM3X3PAD:
64319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXM3X2TEX:
64419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXM3X3SPEC:
64519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXM3X3VSPEC:
64619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXBEM:
64719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXBEML:
64819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXM3X2DEPTH:
64919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXM3X3:
65019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXM3X3TEX:
651894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] = true;
652894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] = true;
653894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] = true;
654894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
65519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXREG2AR:
65619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXREG2GB:
65719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						case Shader::OPCODE_TEXREG2RGB:
658894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							break;
659894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						default:
660894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						//	ASSERT(false);   // Refine component usage
661894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][0] = true;
662894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][1] = true;
663894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][2] = true;
664894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							interpolant[index][3] = true;
665894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
666894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
667894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
668894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
669894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
6703b4c93fea93733b5ab29902ce2b3c864e40d156cNicolas Capens			for(int index = 0; index < MAX_FRAGMENT_INPUTS; index++)
671894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
672894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				for(int component = 0; component < 4; component++)
673894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
674894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					if(!interpolant[index][component])
675894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
67602ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu						input[index][component] = Semantic();
677894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
678894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
679894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
680894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
681894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else   // Shader Model 3.0 input declaration; v# indexable
682894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
68319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			for(unsigned int i = 0; i < instruction.size(); i++)
684894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
68519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				if(instruction[i]->opcode == Shader::OPCODE_DCL)
686894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
68719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					if(instruction[i]->dst.type == Shader::PARAMETER_INPUT)
688894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
68919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						unsigned char usage = instruction[i]->usage;
69019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						unsigned char index = instruction[i]->usageIndex;
69119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						unsigned char mask = instruction[i]->dst.mask;
69219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						unsigned char reg = instruction[i]->dst.index;
69319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
69402ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu						if(mask & 0x01)	input[reg][0] = Semantic(usage, index);
69502ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu						if(mask & 0x02) input[reg][1] = Semantic(usage, index);
69602ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu						if(mask & 0x04) input[reg][2] = Semantic(usage, index);
69702ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu						if(mask & 0x08)	input[reg][3] = Semantic(usage, index);
698894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
69919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					else if(instruction[i]->dst.type == Shader::PARAMETER_MISCTYPE)
700894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
70119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman						unsigned char index = instruction[i]->dst.index;
702894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
703877ddfc51400030afd2804a23b132ed87a2f8d2fAlexis Hetu						if(index == Shader::VPosIndex)
704894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
705894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							vPosDeclared = true;
706894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
707877ddfc51400030afd2804a23b132ed87a2f8d2fAlexis Hetu						else if(index == Shader::VFaceIndex)
708894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						{
709894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman							vFaceDeclared = true;
710894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						}
711894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						else ASSERT(false);
712894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
713894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
714894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
715894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
716894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
717894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(version >= 0x0200)
718894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
71919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman			for(unsigned int i = 0; i < instruction.size(); i++)
720894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
72119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman				if(instruction[i]->opcode == Shader::OPCODE_DCL)
722894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
72319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					bool centroid = instruction[i]->dst.centroid;
72419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					unsigned char reg = instruction[i]->dst.index;
725894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
72619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					switch(instruction[i]->dst.type)
727894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
72819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_INPUT:
72902ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu						input[reg][0].centroid = centroid;
730894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
73119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman					case Shader::PARAMETER_TEXTURE:
73202ad0aa756ab6cbfb6ca00b98ac6793536ff9820Alexis Hetu						input[2 + reg][0].centroid = centroid;
733894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						break;
734b69aa273c4caf7460a81bd3205b2b92380b836b0Nicolas Capens					default:
735b69aa273c4caf7460a81bd3205b2b92380b836b0Nicolas Capens						break;
736894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
737894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
738894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					this->centroid = this->centroid || centroid;
739894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
740894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
741894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
742894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
743894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
744