Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 14 | |
| 15 | #include "PixelShader.hpp" |
| 16 | |
Nicolas Capens | 708c24b | 2017-10-26 13:07:10 -0400 | [diff] [blame] | 17 | #include "Common/Debug.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 18 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 19 | #include <string.h> |
| 20 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 21 | namespace sw |
| 22 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 23 | PixelShader::PixelShader(const PixelShader *ps) : Shader() |
| 24 | { |
Alexis Hetu | 53ad4af | 2017-12-06 14:49:07 -0500 | [diff] [blame] | 25 | shaderModel = 0x0300; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 26 | vPosDeclared = false; |
| 27 | vFaceDeclared = false; |
| 28 | centroid = false; |
| 29 | |
| 30 | if(ps) // Make a copy |
| 31 | { |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 32 | for(size_t i = 0; i < ps->getLength(); i++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 33 | { |
| 34 | append(new sw::Shader::Instruction(*ps->getInstruction(i))); |
| 35 | } |
| 36 | |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 37 | memcpy(input, ps->input, sizeof(input)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 38 | vPosDeclared = ps->vPosDeclared; |
| 39 | vFaceDeclared = ps->vFaceDeclared; |
| 40 | usedSamplers = ps->usedSamplers; |
| 41 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 42 | optimize(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 43 | analyze(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | PixelShader::PixelShader(const unsigned long *token) : Shader() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 48 | { |
| 49 | parse(token); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 50 | |
| 51 | vPosDeclared = false; |
| 52 | vFaceDeclared = false; |
| 53 | centroid = false; |
| 54 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 55 | optimize(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 56 | analyze(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | PixelShader::~PixelShader() |
| 60 | { |
| 61 | } |
| 62 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 63 | int PixelShader::validate(const unsigned long *const token) |
| 64 | { |
| 65 | if(!token) |
| 66 | { |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | unsigned short version = (unsigned short)(token[0] & 0x0000FFFF); |
Alexis Hetu | 7208e93 | 2016-06-02 11:19:24 -0400 | [diff] [blame] | 71 | // unsigned char minorVersion = (unsigned char)(token[0] & 0x000000FF); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 72 | unsigned char majorVersion = (unsigned char)((token[0] & 0x0000FF00) >> 8); |
| 73 | ShaderType shaderType = (ShaderType)((token[0] & 0xFFFF0000) >> 16); |
| 74 | |
| 75 | if(shaderType != SHADER_PIXEL || majorVersion > 3) |
| 76 | { |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | int instructionCount = 1; |
| 81 | |
| 82 | for(int i = 0; token[i] != 0x0000FFFF; i++) |
| 83 | { |
| 84 | if((token[i] & 0x0000FFFF) == 0x0000FFFE) // Comment token |
| 85 | { |
| 86 | int length = (token[i] & 0x7FFF0000) >> 16; |
| 87 | |
| 88 | i += length; |
| 89 | } |
| 90 | else |
| 91 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 92 | Shader::Opcode opcode = (Shader::Opcode)(token[i] & 0x0000FFFF); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 93 | |
| 94 | switch(opcode) |
| 95 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 96 | case Shader::OPCODE_RESERVED0: |
| 97 | case Shader::OPCODE_MOVA: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 98 | return 0; // Unsupported operation |
| 99 | default: |
| 100 | instructionCount++; |
| 101 | break; |
| 102 | } |
| 103 | |
| 104 | i += size(token[i], version); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return instructionCount; |
| 109 | } |
| 110 | |
| 111 | bool PixelShader::depthOverride() const |
| 112 | { |
| 113 | return zOverride; |
| 114 | } |
| 115 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 116 | bool PixelShader::containsKill() const |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 117 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 118 | return kill; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | bool PixelShader::containsCentroid() const |
| 122 | { |
| 123 | return centroid; |
| 124 | } |
| 125 | |
| 126 | bool PixelShader::usesDiffuse(int component) const |
| 127 | { |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 128 | return input[0][component].active(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | bool PixelShader::usesSpecular(int component) const |
| 132 | { |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 133 | return input[1][component].active(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | bool PixelShader::usesTexture(int coordinate, int component) const |
| 137 | { |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 138 | return input[2 + coordinate][component].active(); |
| 139 | } |
| 140 | |
| 141 | void PixelShader::setInput(int inputIdx, int nbComponents, const sw::Shader::Semantic& semantic) |
| 142 | { |
| 143 | for(int i = 0; i < nbComponents; ++i) |
| 144 | { |
| 145 | input[inputIdx][i] = semantic; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | const sw::Shader::Semantic& PixelShader::getInput(int inputIdx, int component) const |
| 150 | { |
| 151 | return input[inputIdx][component]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 152 | } |
| 153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 154 | void PixelShader::analyze() |
| 155 | { |
| 156 | analyzeZOverride(); |
| 157 | analyzeKill(); |
| 158 | analyzeInterpolants(); |
| 159 | analyzeDirtyConstants(); |
| 160 | analyzeDynamicBranching(); |
| 161 | analyzeSamplers(); |
| 162 | analyzeCallSites(); |
Nicolas Capens | 5bff405 | 2018-05-28 13:18:59 -0400 | [diff] [blame] | 163 | analyzeIndirectAddressing(); |
Ben Clayton | d951f19 | 2019-02-11 20:59:19 +0000 | [diff] [blame] | 164 | analyzeLimits(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 165 | } |
| 166 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 167 | void PixelShader::analyzeZOverride() |
| 168 | { |
| 169 | zOverride = false; |
| 170 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 171 | for(const auto &inst : instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 172 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 173 | if(inst->opcode == Shader::OPCODE_TEXM3X2DEPTH || |
| 174 | inst->opcode == Shader::OPCODE_TEXDEPTH || |
| 175 | inst->dst.type == Shader::PARAMETER_DEPTHOUT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 176 | { |
| 177 | zOverride = true; |
| 178 | |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 184 | void PixelShader::analyzeKill() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 185 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 186 | kill = false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 187 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 188 | for(const auto &inst : instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 189 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 190 | if(inst->opcode == Shader::OPCODE_TEXKILL || |
| 191 | inst->opcode == Shader::OPCODE_DISCARD) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 192 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 193 | kill = true; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 194 | |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | void PixelShader::analyzeInterpolants() |
| 201 | { |
Alexis Hetu | 53ad4af | 2017-12-06 14:49:07 -0500 | [diff] [blame] | 202 | if(shaderModel < 0x0300) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 203 | { |
| 204 | // Set default mapping; disable unused interpolants below |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 205 | input[0][0] = Semantic(Shader::USAGE_COLOR, 0); |
| 206 | input[0][1] = Semantic(Shader::USAGE_COLOR, 0); |
| 207 | input[0][2] = Semantic(Shader::USAGE_COLOR, 0); |
| 208 | input[0][3] = Semantic(Shader::USAGE_COLOR, 0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 209 | |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 210 | input[1][0] = Semantic(Shader::USAGE_COLOR, 1); |
| 211 | input[1][1] = Semantic(Shader::USAGE_COLOR, 1); |
| 212 | input[1][2] = Semantic(Shader::USAGE_COLOR, 1); |
| 213 | input[1][3] = Semantic(Shader::USAGE_COLOR, 1); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 214 | |
| 215 | for(int i = 0; i < 8; i++) |
| 216 | { |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 217 | input[2 + i][0] = Semantic(Shader::USAGE_TEXCOORD, i); |
| 218 | input[2 + i][1] = Semantic(Shader::USAGE_TEXCOORD, i); |
| 219 | input[2 + i][2] = Semantic(Shader::USAGE_TEXCOORD, i); |
| 220 | input[2 + i][3] = Semantic(Shader::USAGE_TEXCOORD, i); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 221 | } |
| 222 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 223 | Shader::SamplerType samplerType[16]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 224 | |
| 225 | for(int i = 0; i < 16; i++) |
| 226 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 227 | samplerType[i] = Shader::SAMPLER_UNKNOWN; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 230 | for(const auto &inst : instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 231 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 232 | if(inst->dst.type == Shader::PARAMETER_SAMPLER) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 233 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 234 | int sampler = inst->dst.index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 235 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 236 | samplerType[sampler] = inst->samplerType; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Nicolas Capens | 3b4c93f | 2016-05-18 12:51:37 -0400 | [diff] [blame] | 240 | bool interpolant[MAX_FRAGMENT_INPUTS][4] = {{false}}; // Interpolants in use |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 241 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 242 | for(const auto &inst : instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 243 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 244 | if(inst->dst.type == Shader::PARAMETER_TEXTURE) |
Nicolas Capens | 6abe1cb | 2016-01-15 23:30:50 -0500 | [diff] [blame] | 245 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 246 | int index = inst->dst.index + 2; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 247 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 248 | switch(inst->opcode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 249 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 250 | case Shader::OPCODE_TEX: |
| 251 | case Shader::OPCODE_TEXBEM: |
| 252 | case Shader::OPCODE_TEXBEML: |
| 253 | case Shader::OPCODE_TEXCOORD: |
| 254 | case Shader::OPCODE_TEXDP3: |
| 255 | case Shader::OPCODE_TEXDP3TEX: |
| 256 | case Shader::OPCODE_TEXM3X2DEPTH: |
| 257 | case Shader::OPCODE_TEXM3X2PAD: |
| 258 | case Shader::OPCODE_TEXM3X2TEX: |
| 259 | case Shader::OPCODE_TEXM3X3: |
| 260 | case Shader::OPCODE_TEXM3X3PAD: |
| 261 | case Shader::OPCODE_TEXM3X3TEX: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 262 | interpolant[index][0] = true; |
| 263 | interpolant[index][1] = true; |
| 264 | interpolant[index][2] = true; |
| 265 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 266 | case Shader::OPCODE_TEXKILL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 267 | if(majorVersion < 2) |
| 268 | { |
| 269 | interpolant[index][0] = true; |
| 270 | interpolant[index][1] = true; |
| 271 | interpolant[index][2] = true; |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | interpolant[index][0] = true; |
| 276 | interpolant[index][1] = true; |
| 277 | interpolant[index][2] = true; |
| 278 | interpolant[index][3] = true; |
| 279 | } |
| 280 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 281 | case Shader::OPCODE_TEXM3X3VSPEC: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 282 | interpolant[index][0] = true; |
| 283 | interpolant[index][1] = true; |
| 284 | interpolant[index][2] = true; |
| 285 | interpolant[index - 2][3] = true; |
| 286 | interpolant[index - 1][3] = true; |
| 287 | interpolant[index - 0][3] = true; |
| 288 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 289 | case Shader::OPCODE_DCL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 290 | break; // Ignore |
| 291 | default: // Arithmetic instruction |
Alexis Hetu | 53ad4af | 2017-12-06 14:49:07 -0500 | [diff] [blame] | 292 | if(shaderModel >= 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 293 | { |
| 294 | ASSERT(false); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | for(int argument = 0; argument < 4; argument++) |
| 300 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 301 | if(inst->src[argument].type == Shader::PARAMETER_INPUT || |
| 302 | inst->src[argument].type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 303 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 304 | int index = inst->src[argument].index; |
| 305 | int swizzle = inst->src[argument].swizzle; |
| 306 | int mask = inst->dst.mask; |
Nicolas Capens | 6abe1cb | 2016-01-15 23:30:50 -0500 | [diff] [blame] | 307 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 308 | if(inst->src[argument].type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 309 | { |
| 310 | index += 2; |
| 311 | } |
| 312 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 313 | switch(inst->opcode) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 314 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 315 | case Shader::OPCODE_TEX: |
| 316 | case Shader::OPCODE_TEXLDD: |
| 317 | case Shader::OPCODE_TEXLDL: |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 318 | case Shader::OPCODE_TEXLOD: |
| 319 | case Shader::OPCODE_TEXBIAS: |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 320 | case Shader::OPCODE_TEXOFFSET: |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 321 | case Shader::OPCODE_TEXOFFSETBIAS: |
| 322 | case Shader::OPCODE_TEXLODOFFSET: |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 323 | case Shader::OPCODE_TEXELFETCH: |
| 324 | case Shader::OPCODE_TEXELFETCHOFFSET: |
| 325 | case Shader::OPCODE_TEXGRAD: |
| 326 | case Shader::OPCODE_TEXGRADOFFSET: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 327 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 328 | int sampler = inst->src[1].index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 329 | |
| 330 | switch(samplerType[sampler]) |
| 331 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 332 | case Shader::SAMPLER_UNKNOWN: |
Alexis Hetu | 53ad4af | 2017-12-06 14:49:07 -0500 | [diff] [blame] | 333 | if(shaderModel == 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 334 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 335 | if((inst->src[0].swizzle & 0x30) == 0x20) // .xyz |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 336 | { |
| 337 | interpolant[index][0] = true; |
| 338 | interpolant[index][1] = true; |
| 339 | interpolant[index][2] = true; |
| 340 | } |
| 341 | else // .xyw |
| 342 | { |
| 343 | interpolant[index][0] = true; |
| 344 | interpolant[index][1] = true; |
| 345 | interpolant[index][3] = true; |
| 346 | } |
| 347 | } |
| 348 | else |
| 349 | { |
| 350 | ASSERT(false); |
| 351 | } |
| 352 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 353 | case Shader::SAMPLER_1D: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 354 | interpolant[index][0] = true; |
| 355 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 356 | case Shader::SAMPLER_2D: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 357 | interpolant[index][0] = true; |
| 358 | interpolant[index][1] = true; |
| 359 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 360 | case Shader::SAMPLER_CUBE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 361 | interpolant[index][0] = true; |
| 362 | interpolant[index][1] = true; |
| 363 | interpolant[index][2] = true; |
| 364 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 365 | case Shader::SAMPLER_VOLUME: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 366 | interpolant[index][0] = true; |
| 367 | interpolant[index][1] = true; |
| 368 | interpolant[index][2] = true; |
| 369 | break; |
| 370 | default: |
| 371 | ASSERT(false); |
| 372 | } |
| 373 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 374 | if(inst->bias) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 375 | { |
| 376 | interpolant[index][3] = true; |
| 377 | } |
| 378 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 379 | if(inst->project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 380 | { |
| 381 | interpolant[index][3] = true; |
| 382 | } |
| 383 | |
Alexis Hetu | 53ad4af | 2017-12-06 14:49:07 -0500 | [diff] [blame] | 384 | if(shaderModel == 0x0104 && inst->opcode == Shader::OPCODE_TEX) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 385 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 386 | if(inst->src[0].modifier == Shader::MODIFIER_DZ) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 387 | { |
| 388 | interpolant[index][2] = true; |
| 389 | } |
| 390 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 391 | if(inst->src[0].modifier == Shader::MODIFIER_DW) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 392 | { |
| 393 | interpolant[index][3] = true; |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 398 | case Shader::OPCODE_M3X2: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 399 | if(mask & 0x1) |
| 400 | { |
| 401 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 402 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 403 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 404 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 405 | } |
| 406 | |
| 407 | if(argument == 1) |
| 408 | { |
| 409 | if(mask & 0x2) |
| 410 | { |
| 411 | interpolant[index + 1][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 412 | interpolant[index + 1][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 413 | interpolant[index + 1][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 414 | interpolant[index + 1][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 415 | } |
| 416 | } |
| 417 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 418 | case Shader::OPCODE_M3X3: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 419 | if(mask & 0x1) |
| 420 | { |
| 421 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 422 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 423 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 424 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 425 | } |
| 426 | |
| 427 | if(argument == 1) |
| 428 | { |
| 429 | if(mask & 0x2) |
| 430 | { |
| 431 | interpolant[index + 1][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 432 | interpolant[index + 1][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 433 | interpolant[index + 1][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 434 | interpolant[index + 1][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 435 | } |
| 436 | |
| 437 | if(mask & 0x4) |
| 438 | { |
| 439 | interpolant[index + 2][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 440 | interpolant[index + 2][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 441 | interpolant[index + 2][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 442 | interpolant[index + 2][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 443 | } |
| 444 | } |
| 445 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 446 | case Shader::OPCODE_M3X4: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 447 | if(mask & 0x1) |
| 448 | { |
| 449 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 450 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 451 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 452 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 453 | } |
| 454 | |
| 455 | if(argument == 1) |
| 456 | { |
| 457 | if(mask & 0x2) |
| 458 | { |
| 459 | interpolant[index + 1][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 460 | interpolant[index + 1][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 461 | interpolant[index + 1][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 462 | interpolant[index + 1][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 463 | } |
| 464 | |
| 465 | if(mask & 0x4) |
| 466 | { |
| 467 | interpolant[index + 2][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 468 | interpolant[index + 2][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 469 | interpolant[index + 2][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 470 | interpolant[index + 2][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 471 | } |
| 472 | |
| 473 | if(mask & 0x8) |
| 474 | { |
| 475 | interpolant[index + 3][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 476 | interpolant[index + 3][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 477 | interpolant[index + 3][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 478 | interpolant[index + 3][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 479 | } |
| 480 | } |
| 481 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 482 | case Shader::OPCODE_M4X3: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 483 | if(mask & 0x1) |
| 484 | { |
| 485 | interpolant[index][0] |= swizzleContainsComponent(swizzle, 0); |
| 486 | interpolant[index][1] |= swizzleContainsComponent(swizzle, 1); |
| 487 | interpolant[index][2] |= swizzleContainsComponent(swizzle, 2); |
| 488 | interpolant[index][3] |= swizzleContainsComponent(swizzle, 3); |
| 489 | } |
| 490 | |
| 491 | if(argument == 1) |
| 492 | { |
| 493 | if(mask & 0x2) |
| 494 | { |
| 495 | interpolant[index + 1][0] |= swizzleContainsComponent(swizzle, 0); |
| 496 | interpolant[index + 1][1] |= swizzleContainsComponent(swizzle, 1); |
| 497 | interpolant[index + 1][2] |= swizzleContainsComponent(swizzle, 2); |
| 498 | interpolant[index + 1][3] |= swizzleContainsComponent(swizzle, 3); |
| 499 | } |
| 500 | |
| 501 | if(mask & 0x4) |
| 502 | { |
| 503 | interpolant[index + 2][0] |= swizzleContainsComponent(swizzle, 0); |
| 504 | interpolant[index + 2][1] |= swizzleContainsComponent(swizzle, 1); |
| 505 | interpolant[index + 2][2] |= swizzleContainsComponent(swizzle, 2); |
| 506 | interpolant[index + 2][3] |= swizzleContainsComponent(swizzle, 3); |
| 507 | } |
| 508 | } |
| 509 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 510 | case Shader::OPCODE_M4X4: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 511 | if(mask & 0x1) |
| 512 | { |
| 513 | interpolant[index][0] |= swizzleContainsComponent(swizzle, 0); |
| 514 | interpolant[index][1] |= swizzleContainsComponent(swizzle, 1); |
| 515 | interpolant[index][2] |= swizzleContainsComponent(swizzle, 2); |
| 516 | interpolant[index][3] |= swizzleContainsComponent(swizzle, 3); |
| 517 | } |
| 518 | |
| 519 | if(argument == 1) |
| 520 | { |
| 521 | if(mask & 0x2) |
| 522 | { |
| 523 | interpolant[index + 1][0] |= swizzleContainsComponent(swizzle, 0); |
| 524 | interpolant[index + 1][1] |= swizzleContainsComponent(swizzle, 1); |
| 525 | interpolant[index + 1][2] |= swizzleContainsComponent(swizzle, 2); |
| 526 | interpolant[index + 1][3] |= swizzleContainsComponent(swizzle, 3); |
| 527 | } |
| 528 | |
| 529 | if(mask & 0x4) |
| 530 | { |
| 531 | interpolant[index + 2][0] |= swizzleContainsComponent(swizzle, 0); |
| 532 | interpolant[index + 2][1] |= swizzleContainsComponent(swizzle, 1); |
| 533 | interpolant[index + 2][2] |= swizzleContainsComponent(swizzle, 2); |
| 534 | interpolant[index + 2][3] |= swizzleContainsComponent(swizzle, 3); |
| 535 | } |
| 536 | |
| 537 | if(mask & 0x8) |
| 538 | { |
| 539 | interpolant[index + 3][0] |= swizzleContainsComponent(swizzle, 0); |
| 540 | interpolant[index + 3][1] |= swizzleContainsComponent(swizzle, 1); |
| 541 | interpolant[index + 3][2] |= swizzleContainsComponent(swizzle, 2); |
| 542 | interpolant[index + 3][3] |= swizzleContainsComponent(swizzle, 3); |
| 543 | } |
| 544 | } |
| 545 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 546 | case Shader::OPCODE_CRS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 547 | if(mask & 0x1) |
| 548 | { |
| 549 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x6); |
| 550 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x6); |
| 551 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x6); |
| 552 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x6); |
| 553 | } |
| 554 | |
| 555 | if(mask & 0x2) |
| 556 | { |
| 557 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x5); |
| 558 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x5); |
| 559 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x5); |
| 560 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x5); |
| 561 | } |
| 562 | |
| 563 | if(mask & 0x4) |
| 564 | { |
| 565 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x3); |
| 566 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x3); |
| 567 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x3); |
| 568 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x3); |
| 569 | } |
| 570 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 571 | case Shader::OPCODE_DP2ADD: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 572 | if(argument == 0 || argument == 1) |
| 573 | { |
| 574 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x3); |
| 575 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x3); |
| 576 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x3); |
| 577 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x3); |
| 578 | } |
| 579 | else // argument == 2 |
| 580 | { |
| 581 | interpolant[index][0] |= swizzleContainsComponent(swizzle, 0); |
| 582 | interpolant[index][1] |= swizzleContainsComponent(swizzle, 1); |
| 583 | interpolant[index][2] |= swizzleContainsComponent(swizzle, 2); |
| 584 | interpolant[index][3] |= swizzleContainsComponent(swizzle, 3); |
| 585 | } |
| 586 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 587 | case Shader::OPCODE_DP3: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 588 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7); |
| 589 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7); |
| 590 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7); |
| 591 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7); |
| 592 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 593 | case Shader::OPCODE_DP4: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 594 | interpolant[index][0] |= swizzleContainsComponent(swizzle, 0); |
| 595 | interpolant[index][1] |= swizzleContainsComponent(swizzle, 1); |
| 596 | interpolant[index][2] |= swizzleContainsComponent(swizzle, 2); |
| 597 | interpolant[index][3] |= swizzleContainsComponent(swizzle, 3); |
| 598 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 599 | case Shader::OPCODE_SINCOS: |
| 600 | case Shader::OPCODE_EXP2X: |
| 601 | case Shader::OPCODE_LOG2X: |
| 602 | case Shader::OPCODE_POWX: |
| 603 | case Shader::OPCODE_RCPX: |
| 604 | case Shader::OPCODE_RSQX: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 605 | interpolant[index][0] |= swizzleContainsComponent(swizzle, 0); |
| 606 | interpolant[index][1] |= swizzleContainsComponent(swizzle, 1); |
| 607 | interpolant[index][2] |= swizzleContainsComponent(swizzle, 2); |
| 608 | interpolant[index][3] |= swizzleContainsComponent(swizzle, 3); |
| 609 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 610 | case Shader::OPCODE_NRM3: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 611 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, 0x7 | mask); |
| 612 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, 0x7 | mask); |
| 613 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, 0x7 | mask); |
| 614 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, 0x7 | mask); |
| 615 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 616 | case Shader::OPCODE_MOV: |
| 617 | case Shader::OPCODE_ADD: |
| 618 | case Shader::OPCODE_SUB: |
| 619 | case Shader::OPCODE_MUL: |
| 620 | case Shader::OPCODE_MAD: |
| 621 | case Shader::OPCODE_ABS: |
| 622 | case Shader::OPCODE_CMP0: |
| 623 | case Shader::OPCODE_CND: |
| 624 | case Shader::OPCODE_FRC: |
| 625 | case Shader::OPCODE_LRP: |
| 626 | case Shader::OPCODE_MAX: |
| 627 | case Shader::OPCODE_MIN: |
| 628 | case Shader::OPCODE_CMP: |
| 629 | case Shader::OPCODE_BREAKC: |
| 630 | case Shader::OPCODE_DFDX: |
| 631 | case Shader::OPCODE_DFDY: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 632 | interpolant[index][0] |= swizzleContainsComponentMasked(swizzle, 0, mask); |
| 633 | interpolant[index][1] |= swizzleContainsComponentMasked(swizzle, 1, mask); |
| 634 | interpolant[index][2] |= swizzleContainsComponentMasked(swizzle, 2, mask); |
| 635 | interpolant[index][3] |= swizzleContainsComponentMasked(swizzle, 3, mask); |
| 636 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 637 | case Shader::OPCODE_TEXCOORD: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 638 | interpolant[index][0] = true; |
| 639 | interpolant[index][1] = true; |
| 640 | interpolant[index][2] = true; |
| 641 | interpolant[index][3] = true; |
| 642 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 643 | case Shader::OPCODE_TEXDP3: |
| 644 | case Shader::OPCODE_TEXDP3TEX: |
| 645 | case Shader::OPCODE_TEXM3X2PAD: |
| 646 | case Shader::OPCODE_TEXM3X3PAD: |
| 647 | case Shader::OPCODE_TEXM3X2TEX: |
| 648 | case Shader::OPCODE_TEXM3X3SPEC: |
| 649 | case Shader::OPCODE_TEXM3X3VSPEC: |
| 650 | case Shader::OPCODE_TEXBEM: |
| 651 | case Shader::OPCODE_TEXBEML: |
| 652 | case Shader::OPCODE_TEXM3X2DEPTH: |
| 653 | case Shader::OPCODE_TEXM3X3: |
| 654 | case Shader::OPCODE_TEXM3X3TEX: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 655 | interpolant[index][0] = true; |
| 656 | interpolant[index][1] = true; |
| 657 | interpolant[index][2] = true; |
| 658 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 659 | case Shader::OPCODE_TEXREG2AR: |
| 660 | case Shader::OPCODE_TEXREG2GB: |
| 661 | case Shader::OPCODE_TEXREG2RGB: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 662 | break; |
| 663 | default: |
| 664 | // ASSERT(false); // Refine component usage |
| 665 | interpolant[index][0] = true; |
| 666 | interpolant[index][1] = true; |
| 667 | interpolant[index][2] = true; |
| 668 | interpolant[index][3] = true; |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
Nicolas Capens | 3b4c93f | 2016-05-18 12:51:37 -0400 | [diff] [blame] | 674 | for(int index = 0; index < MAX_FRAGMENT_INPUTS; index++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 675 | { |
| 676 | for(int component = 0; component < 4; component++) |
| 677 | { |
| 678 | if(!interpolant[index][component]) |
| 679 | { |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 680 | input[index][component] = Semantic(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | else // Shader Model 3.0 input declaration; v# indexable |
| 686 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 687 | for(const auto &inst : instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 688 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 689 | if(inst->opcode == Shader::OPCODE_DCL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 690 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 691 | if(inst->dst.type == Shader::PARAMETER_INPUT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 692 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 693 | unsigned char usage = inst->usage; |
| 694 | unsigned char index = inst->usageIndex; |
| 695 | unsigned char mask = inst->dst.mask; |
| 696 | unsigned char reg = inst->dst.index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 697 | |
Nicolas Capens | 8af24c5 | 2017-12-11 14:45:01 -0500 | [diff] [blame] | 698 | if(mask & 0x01) input[reg][0] = Semantic(usage, index); |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 699 | if(mask & 0x02) input[reg][1] = Semantic(usage, index); |
| 700 | if(mask & 0x04) input[reg][2] = Semantic(usage, index); |
Nicolas Capens | 8af24c5 | 2017-12-11 14:45:01 -0500 | [diff] [blame] | 701 | if(mask & 0x08) input[reg][3] = Semantic(usage, index); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 702 | } |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 703 | else if(inst->dst.type == Shader::PARAMETER_MISCTYPE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 704 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 705 | unsigned char index = inst->dst.index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 706 | |
Alexis Hetu | 877ddfc | 2017-07-25 17:48:00 -0400 | [diff] [blame] | 707 | if(index == Shader::VPosIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 708 | { |
| 709 | vPosDeclared = true; |
| 710 | } |
Alexis Hetu | 877ddfc | 2017-07-25 17:48:00 -0400 | [diff] [blame] | 711 | else if(index == Shader::VFaceIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 712 | { |
| 713 | vFaceDeclared = true; |
| 714 | } |
| 715 | else ASSERT(false); |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | |
Alexis Hetu | 53ad4af | 2017-12-06 14:49:07 -0500 | [diff] [blame] | 721 | if(shaderModel >= 0x0200) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 722 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 723 | for(const auto &inst : instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 724 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 725 | if(inst->opcode == Shader::OPCODE_DCL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 726 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 727 | bool centroid = inst->dst.centroid; |
| 728 | unsigned char reg = inst->dst.index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 729 | |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 730 | switch(inst->dst.type) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 731 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 732 | case Shader::PARAMETER_INPUT: |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 733 | input[reg][0].centroid = centroid; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 734 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 735 | case Shader::PARAMETER_TEXTURE: |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 736 | input[2 + reg][0].centroid = centroid; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 737 | break; |
Nicolas Capens | b69aa27 | 2016-01-02 00:06:41 -0500 | [diff] [blame] | 738 | default: |
| 739 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | this->centroid = this->centroid || centroid; |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | } |