John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1 | // SwiftShader Software Renderer |
| 2 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 3 | // Copyright(c) 2005-2013 TransGaming Inc. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4 | // |
| 5 | // All rights reserved. No part of this software may be copied, distributed, transmitted, |
| 6 | // transcribed, stored in a retrieval system, translated into any human or computer |
| 7 | // language by any means, or disclosed to third parties without the explicit written |
| 8 | // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express |
| 9 | // or implied, including but not limited to any patent rights, are granted to you. |
| 10 | // |
| 11 | |
| 12 | #include "VertexProgram.hpp" |
| 13 | |
| 14 | #include "Renderer.hpp" |
| 15 | #include "VertexShader.hpp" |
| 16 | #include "Vertex.hpp" |
| 17 | #include "Half.hpp" |
| 18 | #include "SamplerCore.hpp" |
| 19 | #include "Debug.hpp" |
| 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 | VertexProgram::VertexProgram(const VertexProcessor::State &state, const VertexShader *shader) : VertexRoutine(state, shader) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 24 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 25 | ifDepth = 0; |
| 26 | loopRepDepth = 0; |
| 27 | breakDepth = 0; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 28 | currentLabel = -1; |
| 29 | whileTest = false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 30 | |
| 31 | for(int i = 0; i < 2048; i++) |
| 32 | { |
| 33 | labelBlock[i] = 0; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | VertexProgram::~VertexProgram() |
| 38 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 39 | for(int i = 0; i < VERTEX_TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 40 | { |
| 41 | delete sampler[i]; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void VertexProgram::pipeline(Registers &r) |
| 46 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 47 | for(int i = 0; i < VERTEX_TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 48 | { |
| 49 | sampler[i] = new SamplerCore(r.constants, state.samplerState[i]); |
| 50 | } |
| 51 | |
| 52 | if(!state.preTransformed) |
| 53 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 54 | program(r); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 55 | } |
| 56 | else |
| 57 | { |
| 58 | passThrough(r); |
| 59 | } |
| 60 | } |
| 61 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 62 | void VertexProgram::program(Registers &r) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 63 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 64 | // shader->print("VertexShader-%0.8X.txt", state.shaderID); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 65 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 66 | unsigned short version = shader->getVersion(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 67 | |
| 68 | r.enableIndex = 0; |
| 69 | r.stackIndex = 0; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 70 | |
Nicolas Capens | 4677a5f | 2014-05-06 16:42:26 -0400 | [diff] [blame] | 71 | if(shader->containsLeaveInstruction()) |
| 72 | { |
| 73 | r.enableLeave = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 74 | } |
| 75 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 76 | // Create all call site return blocks up front |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 77 | for(size_t i = 0; i < shader->getLength(); i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 78 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 79 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 80 | Shader::Opcode opcode = instruction->opcode; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 81 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 82 | if(opcode == Shader::OPCODE_CALL || opcode == Shader::OPCODE_CALLNZ) |
| 83 | { |
| 84 | const Dst &dst = instruction->dst; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 85 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 86 | ASSERT(callRetBlock[dst.label].size() == dst.callSite); |
| 87 | callRetBlock[dst.label].push_back(Nucleus::createBasicBlock()); |
| 88 | } |
| 89 | } |
| 90 | |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 91 | for(size_t i = 0; i < shader->getLength(); i++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 92 | { |
| 93 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 94 | Shader::Opcode opcode = instruction->opcode; |
| 95 | |
| 96 | if(opcode == Shader::OPCODE_DCL || opcode == Shader::OPCODE_DEF || opcode == Shader::OPCODE_DEFI || opcode == Shader::OPCODE_DEFB) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 97 | { |
| 98 | continue; |
| 99 | } |
| 100 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 101 | Dst dst = instruction->dst; |
| 102 | Src src0 = instruction->src[0]; |
| 103 | Src src1 = instruction->src[1]; |
| 104 | Src src2 = instruction->src[2]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 105 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 106 | bool predicate = instruction->predicate; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 107 | Control control = instruction->control; |
| 108 | bool integer = dst.type == Shader::PARAMETER_ADDR; |
| 109 | bool pp = dst.partialPrecision; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 110 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 111 | Vector4f d; |
| 112 | Vector4f s0; |
| 113 | Vector4f s1; |
| 114 | Vector4f s2; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 115 | |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 116 | if(src0.type != Shader::PARAMETER_VOID) s0 = fetchRegisterF(r, src0); |
| 117 | if(src1.type != Shader::PARAMETER_VOID) s1 = fetchRegisterF(r, src1); |
| 118 | if(src2.type != Shader::PARAMETER_VOID) s2 = fetchRegisterF(r, src2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 119 | |
| 120 | switch(opcode) |
| 121 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 122 | case Shader::OPCODE_VS_1_0: break; |
| 123 | case Shader::OPCODE_VS_1_1: break; |
| 124 | case Shader::OPCODE_VS_2_0: break; |
| 125 | case Shader::OPCODE_VS_2_x: break; |
| 126 | case Shader::OPCODE_VS_2_sw: break; |
| 127 | case Shader::OPCODE_VS_3_0: break; |
| 128 | case Shader::OPCODE_VS_3_sw: break; |
| 129 | case Shader::OPCODE_DCL: break; |
| 130 | case Shader::OPCODE_DEF: break; |
| 131 | case Shader::OPCODE_DEFI: break; |
| 132 | case Shader::OPCODE_DEFB: break; |
| 133 | case Shader::OPCODE_NOP: break; |
| 134 | case Shader::OPCODE_ABS: abs(d, s0); break; |
| 135 | case Shader::OPCODE_ADD: add(d, s0, s1); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 136 | case Shader::OPCODE_IADD: iadd(d, s0, s1); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 137 | case Shader::OPCODE_CRS: crs(d, s0, s1); break; |
| 138 | case Shader::OPCODE_FORWARD1: forward1(d, s0, s1, s2); break; |
| 139 | case Shader::OPCODE_FORWARD2: forward2(d, s0, s1, s2); break; |
| 140 | case Shader::OPCODE_FORWARD3: forward3(d, s0, s1, s2); break; |
| 141 | case Shader::OPCODE_FORWARD4: forward4(d, s0, s1, s2); break; |
| 142 | case Shader::OPCODE_REFLECT1: reflect1(d, s0, s1); break; |
| 143 | case Shader::OPCODE_REFLECT2: reflect2(d, s0, s1); break; |
| 144 | case Shader::OPCODE_REFLECT3: reflect3(d, s0, s1); break; |
| 145 | case Shader::OPCODE_REFLECT4: reflect4(d, s0, s1); break; |
| 146 | case Shader::OPCODE_REFRACT1: refract1(d, s0, s1, s2.x); break; |
| 147 | case Shader::OPCODE_REFRACT2: refract2(d, s0, s1, s2.x); break; |
| 148 | case Shader::OPCODE_REFRACT3: refract3(d, s0, s1, s2.x); break; |
| 149 | case Shader::OPCODE_REFRACT4: refract4(d, s0, s1, s2.x); break; |
| 150 | case Shader::OPCODE_DP1: dp1(d, s0, s1); break; |
| 151 | case Shader::OPCODE_DP2: dp2(d, s0, s1); break; |
| 152 | case Shader::OPCODE_DP3: dp3(d, s0, s1); break; |
| 153 | case Shader::OPCODE_DP4: dp4(d, s0, s1); break; |
| 154 | case Shader::OPCODE_ATT: att(d, s0, s1); break; |
| 155 | case Shader::OPCODE_EXP2X: exp2x(d, s0, pp); break; |
| 156 | case Shader::OPCODE_EXP2: exp2(d, s0, pp); break; |
| 157 | case Shader::OPCODE_EXPP: expp(d, s0, version); break; |
| 158 | case Shader::OPCODE_EXP: exp(d, s0, pp); break; |
| 159 | case Shader::OPCODE_FRC: frc(d, s0); break; |
| 160 | case Shader::OPCODE_TRUNC: trunc(d, s0); break; |
| 161 | case Shader::OPCODE_FLOOR: floor(d, s0); break; |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 162 | case Shader::OPCODE_ROUND: round(d, s0); break; |
Alexis Hetu | 8e851c1 | 2015-06-04 11:30:54 -0400 | [diff] [blame] | 163 | case Shader::OPCODE_ROUNDEVEN: roundEven(d, s0); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 164 | case Shader::OPCODE_CEIL: ceil(d, s0); break; |
| 165 | case Shader::OPCODE_LIT: lit(d, s0); break; |
| 166 | case Shader::OPCODE_LOG2X: log2x(d, s0, pp); break; |
| 167 | case Shader::OPCODE_LOG2: log2(d, s0, pp); break; |
| 168 | case Shader::OPCODE_LOGP: logp(d, s0, version); break; |
| 169 | case Shader::OPCODE_LOG: log(d, s0, pp); break; |
| 170 | case Shader::OPCODE_LRP: lrp(d, s0, s1, s2); break; |
| 171 | case Shader::OPCODE_STEP: step(d, s0, s1); break; |
| 172 | case Shader::OPCODE_SMOOTH: smooth(d, s0, s1, s2); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 173 | case Shader::OPCODE_FLOATBITSTOINT: |
| 174 | case Shader::OPCODE_FLOATBITSTOUINT: |
| 175 | case Shader::OPCODE_INTBITSTOFLOAT: |
| 176 | case Shader::OPCODE_UINTBITSTOFLOAT: d = s0; break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 177 | case Shader::OPCODE_M3X2: M3X2(r, d, s0, src1); break; |
| 178 | case Shader::OPCODE_M3X3: M3X3(r, d, s0, src1); break; |
| 179 | case Shader::OPCODE_M3X4: M3X4(r, d, s0, src1); break; |
| 180 | case Shader::OPCODE_M4X3: M4X3(r, d, s0, src1); break; |
| 181 | case Shader::OPCODE_M4X4: M4X4(r, d, s0, src1); break; |
| 182 | case Shader::OPCODE_MAD: mad(d, s0, s1, s2); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 183 | case Shader::OPCODE_IMAD: imad(d, s0, s1, s2); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 184 | case Shader::OPCODE_MAX: max(d, s0, s1); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 185 | case Shader::OPCODE_IMAX: imax(d, s0, s1); break; |
| 186 | case Shader::OPCODE_UMAX: umax(d, s0, s1); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 187 | case Shader::OPCODE_MIN: min(d, s0, s1); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 188 | case Shader::OPCODE_IMIN: imin(d, s0, s1); break; |
| 189 | case Shader::OPCODE_UMIN: umin(d, s0, s1); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 190 | case Shader::OPCODE_MOV: mov(d, s0, integer); break; |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 191 | case Shader::OPCODE_MOVA: mov(d, s0, true); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 192 | case Shader::OPCODE_NEG: neg(d, s0); break; |
| 193 | case Shader::OPCODE_INEG: ineg(d, s0); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 194 | case Shader::OPCODE_F2B: f2b(d, s0); break; |
| 195 | case Shader::OPCODE_B2F: b2f(d, s0); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 196 | case Shader::OPCODE_F2I: f2i(d, s0); break; |
| 197 | case Shader::OPCODE_I2F: i2f(d, s0); break; |
| 198 | case Shader::OPCODE_F2U: f2u(d, s0); break; |
| 199 | case Shader::OPCODE_U2F: u2f(d, s0); break; |
| 200 | case Shader::OPCODE_I2B: i2b(d, s0); break; |
| 201 | case Shader::OPCODE_B2I: b2i(d, s0); break; |
| 202 | case Shader::OPCODE_U2B: u2b(d, s0); break; |
| 203 | case Shader::OPCODE_B2U: b2u(d, s0); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 204 | case Shader::OPCODE_MUL: mul(d, s0, s1); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 205 | case Shader::OPCODE_IMUL: imul(d, s0, s1); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 206 | case Shader::OPCODE_NRM2: nrm2(d, s0, pp); break; |
| 207 | case Shader::OPCODE_NRM3: nrm3(d, s0, pp); break; |
| 208 | case Shader::OPCODE_NRM4: nrm4(d, s0, pp); break; |
| 209 | case Shader::OPCODE_POWX: powx(d, s0, s1, pp); break; |
| 210 | case Shader::OPCODE_POW: pow(d, s0, s1, pp); break; |
| 211 | case Shader::OPCODE_RCPX: rcpx(d, s0, pp); break; |
| 212 | case Shader::OPCODE_DIV: div(d, s0, s1); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 213 | case Shader::OPCODE_IDIV: idiv(d, s0, s1); break; |
| 214 | case Shader::OPCODE_UDIV: udiv(d, s0, s1); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 215 | case Shader::OPCODE_MOD: mod(d, s0, s1); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 216 | case Shader::OPCODE_IMOD: imod(d, s0, s1); break; |
| 217 | case Shader::OPCODE_UMOD: umod(d, s0, s1); break; |
| 218 | case Shader::OPCODE_SHL: shl(d, s0, s1); break; |
| 219 | case Shader::OPCODE_ISHR: ishr(d, s0, s1); break; |
| 220 | case Shader::OPCODE_USHR: ushr(d, s0, s1); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 221 | case Shader::OPCODE_RSQX: rsqx(d, s0, pp); break; |
| 222 | case Shader::OPCODE_SQRT: sqrt(d, s0, pp); break; |
| 223 | case Shader::OPCODE_RSQ: rsq(d, s0, pp); break; |
| 224 | case Shader::OPCODE_LEN2: len2(d.x, s0, pp); break; |
| 225 | case Shader::OPCODE_LEN3: len3(d.x, s0, pp); break; |
| 226 | case Shader::OPCODE_LEN4: len4(d.x, s0, pp); break; |
| 227 | case Shader::OPCODE_DIST1: dist1(d.x, s0, s1, pp); break; |
| 228 | case Shader::OPCODE_DIST2: dist2(d.x, s0, s1, pp); break; |
| 229 | case Shader::OPCODE_DIST3: dist3(d.x, s0, s1, pp); break; |
| 230 | case Shader::OPCODE_DIST4: dist4(d.x, s0, s1, pp); break; |
| 231 | case Shader::OPCODE_SGE: step(d, s1, s0); break; |
| 232 | case Shader::OPCODE_SGN: sgn(d, s0); break; |
| 233 | case Shader::OPCODE_SINCOS: sincos(d, s0, pp); break; |
| 234 | case Shader::OPCODE_COS: cos(d, s0, pp); break; |
| 235 | case Shader::OPCODE_SIN: sin(d, s0, pp); break; |
| 236 | case Shader::OPCODE_TAN: tan(d, s0); break; |
| 237 | case Shader::OPCODE_ACOS: acos(d, s0); break; |
| 238 | case Shader::OPCODE_ASIN: asin(d, s0); break; |
| 239 | case Shader::OPCODE_ATAN: atan(d, s0); break; |
| 240 | case Shader::OPCODE_ATAN2: atan2(d, s0, s1); break; |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 241 | case Shader::OPCODE_COSH: cosh(d, s0, pp); break; |
| 242 | case Shader::OPCODE_SINH: sinh(d, s0, pp); break; |
| 243 | case Shader::OPCODE_TANH: tanh(d, s0, pp); break; |
| 244 | case Shader::OPCODE_ACOSH: acosh(d, s0, pp); break; |
| 245 | case Shader::OPCODE_ASINH: asinh(d, s0, pp); break; |
| 246 | case Shader::OPCODE_ATANH: atanh(d, s0, pp); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 247 | case Shader::OPCODE_SLT: slt(d, s0, s1); break; |
| 248 | case Shader::OPCODE_SUB: sub(d, s0, s1); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 249 | case Shader::OPCODE_ISUB: isub(d, s0, s1); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 250 | case Shader::OPCODE_BREAK: BREAK(r); break; |
| 251 | case Shader::OPCODE_BREAKC: BREAKC(r, s0, s1, control); break; |
| 252 | case Shader::OPCODE_BREAKP: BREAKP(r, src0); break; |
| 253 | case Shader::OPCODE_CONTINUE: CONTINUE(r); break; |
| 254 | case Shader::OPCODE_TEST: TEST(); break; |
| 255 | case Shader::OPCODE_CALL: CALL(r, dst.label, dst.callSite); break; |
| 256 | case Shader::OPCODE_CALLNZ: CALLNZ(r, dst.label, dst.callSite, src0); break; |
| 257 | case Shader::OPCODE_ELSE: ELSE(r); break; |
| 258 | case Shader::OPCODE_ENDIF: ENDIF(r); break; |
| 259 | case Shader::OPCODE_ENDLOOP: ENDLOOP(r); break; |
| 260 | case Shader::OPCODE_ENDREP: ENDREP(r); break; |
| 261 | case Shader::OPCODE_ENDWHILE: ENDWHILE(r); break; |
| 262 | case Shader::OPCODE_IF: IF(r, src0); break; |
| 263 | case Shader::OPCODE_IFC: IFC(r, s0, s1, control); break; |
| 264 | case Shader::OPCODE_LABEL: LABEL(dst.index); break; |
| 265 | case Shader::OPCODE_LOOP: LOOP(r, src1); break; |
| 266 | case Shader::OPCODE_REP: REP(r, src0); break; |
| 267 | case Shader::OPCODE_WHILE: WHILE(r, src0); break; |
| 268 | case Shader::OPCODE_RET: RET(r); break; |
| 269 | case Shader::OPCODE_LEAVE: LEAVE(r); break; |
| 270 | case Shader::OPCODE_CMP: cmp(d, s0, s1, control); break; |
| 271 | case Shader::OPCODE_ICMP: icmp(d, s0, s1, control); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 272 | case Shader::OPCODE_UCMP: ucmp(d, s0, s1, control); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 273 | case Shader::OPCODE_SELECT: select(d, s0, s1, s2); break; |
| 274 | case Shader::OPCODE_EXTRACT: extract(d.x, s0, s1.x); break; |
| 275 | case Shader::OPCODE_INSERT: insert(d, s0, s1.x, s2.x); break; |
| 276 | case Shader::OPCODE_ALL: all(d.x, s0); break; |
| 277 | case Shader::OPCODE_ANY: any(d.x, s0); break; |
| 278 | case Shader::OPCODE_NOT: not(d, s0); break; |
Alexis Hetu | 8d78cf7 | 2015-08-28 14:24:45 -0400 | [diff] [blame] | 279 | case Shader::OPCODE_OR: or(d, s0, s1); break; |
| 280 | case Shader::OPCODE_XOR: xor(d, s0, s1); break; |
| 281 | case Shader::OPCODE_AND: and(d, s0, s1); break; |
| 282 | case Shader::OPCODE_EQ: equal(d, s0, s1); break; |
| 283 | case Shader::OPCODE_NE: notEqual(d, s0, s1); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 284 | case Shader::OPCODE_TEXLDL: TEXLDL(r, d, s0, src1); break; |
| 285 | case Shader::OPCODE_TEX: TEX(r, d, s0, src1); break; |
| 286 | case Shader::OPCODE_END: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 287 | default: |
| 288 | ASSERT(false); |
| 289 | } |
| 290 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 291 | if(dst.type != Shader::PARAMETER_VOID && dst.type != Shader::PARAMETER_LABEL && opcode != Shader::OPCODE_NOP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 292 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 293 | if(dst.integer) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 294 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 295 | switch(opcode) |
| 296 | { |
| 297 | case Shader::OPCODE_DIV: |
| 298 | if(dst.x) d.x = Trunc(d.x); |
| 299 | if(dst.y) d.y = Trunc(d.y); |
| 300 | if(dst.z) d.z = Trunc(d.z); |
| 301 | if(dst.w) d.w = Trunc(d.w); |
| 302 | break; |
| 303 | default: |
| 304 | break; // No truncation to integer required when arguments are integer |
| 305 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 306 | } |
| 307 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 308 | if(dst.saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 309 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 310 | if(dst.x) d.x = Max(d.x, Float4(0.0f)); |
| 311 | if(dst.y) d.y = Max(d.y, Float4(0.0f)); |
| 312 | if(dst.z) d.z = Max(d.z, Float4(0.0f)); |
| 313 | if(dst.w) d.w = Max(d.w, Float4(0.0f)); |
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 | if(dst.x) d.x = Min(d.x, Float4(1.0f)); |
| 316 | if(dst.y) d.y = Min(d.y, Float4(1.0f)); |
| 317 | if(dst.z) d.z = Min(d.z, Float4(1.0f)); |
| 318 | if(dst.w) d.w = Min(d.w, Float4(1.0f)); |
| 319 | } |
| 320 | |
Nicolas Capens | c6e8ab1 | 2014-05-06 23:31:07 -0400 | [diff] [blame] | 321 | if(instruction->isPredicated()) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 322 | { |
| 323 | Vector4f pDst; // FIXME: Rename |
| 324 | |
| 325 | switch(dst.type) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 326 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 327 | case Shader::PARAMETER_VOID: break; |
| 328 | case Shader::PARAMETER_TEMP: |
| 329 | if(dst.rel.type == Shader::PARAMETER_VOID) |
| 330 | { |
| 331 | if(dst.x) pDst.x = r.r[dst.index].x; |
| 332 | if(dst.y) pDst.y = r.r[dst.index].y; |
| 333 | if(dst.z) pDst.z = r.r[dst.index].z; |
| 334 | if(dst.w) pDst.w = r.r[dst.index].w; |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | Int a = relativeAddress(r, dst); |
| 339 | |
| 340 | if(dst.x) pDst.x = r.r[dst.index + a].x; |
| 341 | if(dst.y) pDst.y = r.r[dst.index + a].y; |
| 342 | if(dst.z) pDst.z = r.r[dst.index + a].z; |
| 343 | if(dst.w) pDst.w = r.r[dst.index + a].w; |
| 344 | } |
| 345 | break; |
| 346 | case Shader::PARAMETER_ADDR: pDst = r.a0; break; |
| 347 | case Shader::PARAMETER_RASTOUT: |
| 348 | switch(dst.index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 349 | { |
| 350 | case 0: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 351 | if(dst.x) pDst.x = r.o[Pos].x; |
| 352 | if(dst.y) pDst.y = r.o[Pos].y; |
| 353 | if(dst.z) pDst.z = r.o[Pos].z; |
| 354 | if(dst.w) pDst.w = r.o[Pos].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 355 | break; |
| 356 | case 1: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 357 | pDst.x = r.o[Fog].x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 358 | break; |
| 359 | case 2: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 360 | pDst.x = r.o[Pts].y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 361 | break; |
| 362 | default: |
| 363 | ASSERT(false); |
| 364 | } |
| 365 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 366 | case Shader::PARAMETER_ATTROUT: |
| 367 | if(dst.x) pDst.x = r.o[D0 + dst.index].x; |
| 368 | if(dst.y) pDst.y = r.o[D0 + dst.index].y; |
| 369 | if(dst.z) pDst.z = r.o[D0 + dst.index].z; |
| 370 | if(dst.w) pDst.w = r.o[D0 + dst.index].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 371 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 372 | case Shader::PARAMETER_TEXCRDOUT: |
| 373 | // case Shader::PARAMETER_OUTPUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 374 | if(version < 0x0300) |
| 375 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 376 | if(dst.x) pDst.x = r.o[T0 + dst.index].x; |
| 377 | if(dst.y) pDst.y = r.o[T0 + dst.index].y; |
| 378 | if(dst.z) pDst.z = r.o[T0 + dst.index].z; |
| 379 | if(dst.w) pDst.w = r.o[T0 + dst.index].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 380 | } |
| 381 | else |
| 382 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 383 | if(dst.rel.type == Shader::PARAMETER_VOID) // Not relative |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 384 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 385 | if(dst.x) pDst.x = r.o[dst.index].x; |
| 386 | if(dst.y) pDst.y = r.o[dst.index].y; |
| 387 | if(dst.z) pDst.z = r.o[dst.index].z; |
| 388 | if(dst.w) pDst.w = r.o[dst.index].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 389 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 390 | else if(dst.rel.type == Shader::PARAMETER_LOOP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 391 | { |
| 392 | Int aL = r.aL[r.loopDepth]; |
| 393 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 394 | if(dst.x) pDst.x = r.o[dst.index + aL].x; |
| 395 | if(dst.y) pDst.y = r.o[dst.index + aL].y; |
| 396 | if(dst.z) pDst.z = r.o[dst.index + aL].z; |
| 397 | if(dst.w) pDst.w = r.o[dst.index + aL].w; |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | Int a = relativeAddress(r, dst); |
| 402 | |
| 403 | if(dst.x) pDst.x = r.o[dst.index + a].x; |
| 404 | if(dst.y) pDst.y = r.o[dst.index + a].y; |
| 405 | if(dst.z) pDst.z = r.o[dst.index + a].z; |
| 406 | if(dst.w) pDst.w = r.o[dst.index + a].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 410 | case Shader::PARAMETER_LABEL: break; |
| 411 | case Shader::PARAMETER_PREDICATE: pDst = r.p0; break; |
| 412 | case Shader::PARAMETER_INPUT: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 413 | default: |
| 414 | ASSERT(false); |
| 415 | } |
| 416 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 417 | Int4 enable = enableMask(r, instruction); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 418 | |
| 419 | Int4 xEnable = enable; |
| 420 | Int4 yEnable = enable; |
| 421 | Int4 zEnable = enable; |
| 422 | Int4 wEnable = enable; |
| 423 | |
| 424 | if(predicate) |
| 425 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 426 | unsigned char pSwizzle = instruction->predicateSwizzle; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 427 | |
| 428 | Float4 xPredicate = r.p0[(pSwizzle >> 0) & 0x03]; |
| 429 | Float4 yPredicate = r.p0[(pSwizzle >> 2) & 0x03]; |
| 430 | Float4 zPredicate = r.p0[(pSwizzle >> 4) & 0x03]; |
| 431 | Float4 wPredicate = r.p0[(pSwizzle >> 6) & 0x03]; |
| 432 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 433 | if(!instruction->predicateNot) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 434 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 435 | if(dst.x) xEnable = xEnable & As<Int4>(xPredicate); |
| 436 | if(dst.y) yEnable = yEnable & As<Int4>(yPredicate); |
| 437 | if(dst.z) zEnable = zEnable & As<Int4>(zPredicate); |
| 438 | if(dst.w) wEnable = wEnable & As<Int4>(wPredicate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 439 | } |
| 440 | else |
| 441 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 442 | if(dst.x) xEnable = xEnable & ~As<Int4>(xPredicate); |
| 443 | if(dst.y) yEnable = yEnable & ~As<Int4>(yPredicate); |
| 444 | if(dst.z) zEnable = zEnable & ~As<Int4>(zPredicate); |
| 445 | if(dst.w) wEnable = wEnable & ~As<Int4>(wPredicate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 449 | if(dst.x) d.x = As<Float4>(As<Int4>(d.x) & xEnable); |
| 450 | if(dst.y) d.y = As<Float4>(As<Int4>(d.y) & yEnable); |
| 451 | if(dst.z) d.z = As<Float4>(As<Int4>(d.z) & zEnable); |
| 452 | if(dst.w) d.w = As<Float4>(As<Int4>(d.w) & wEnable); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 453 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 454 | if(dst.x) d.x = As<Float4>(As<Int4>(d.x) | (As<Int4>(pDst.x) & ~xEnable)); |
| 455 | if(dst.y) d.y = As<Float4>(As<Int4>(d.y) | (As<Int4>(pDst.y) & ~yEnable)); |
| 456 | if(dst.z) d.z = As<Float4>(As<Int4>(d.z) | (As<Int4>(pDst.z) & ~zEnable)); |
| 457 | if(dst.w) d.w = As<Float4>(As<Int4>(d.w) | (As<Int4>(pDst.w) & ~wEnable)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 458 | } |
| 459 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 460 | switch(dst.type) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 461 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 462 | case Shader::PARAMETER_VOID: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 463 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 464 | case Shader::PARAMETER_TEMP: |
| 465 | if(dst.rel.type == Shader::PARAMETER_VOID) |
| 466 | { |
| 467 | if(dst.x) r.r[dst.index].x = d.x; |
| 468 | if(dst.y) r.r[dst.index].y = d.y; |
| 469 | if(dst.z) r.r[dst.index].z = d.z; |
| 470 | if(dst.w) r.r[dst.index].w = d.w; |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | Int a = relativeAddress(r, dst); |
| 475 | |
| 476 | if(dst.x) r.r[dst.index + a].x = d.x; |
| 477 | if(dst.y) r.r[dst.index + a].y = d.y; |
| 478 | if(dst.z) r.r[dst.index + a].z = d.z; |
| 479 | if(dst.w) r.r[dst.index + a].w = d.w; |
| 480 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 481 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 482 | case Shader::PARAMETER_ADDR: |
| 483 | if(dst.x) r.a0.x = d.x; |
| 484 | if(dst.y) r.a0.y = d.y; |
| 485 | if(dst.z) r.a0.z = d.z; |
| 486 | if(dst.w) r.a0.w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 487 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 488 | case Shader::PARAMETER_RASTOUT: |
| 489 | switch(dst.index) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 490 | { |
| 491 | case 0: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 492 | if(dst.x) r.o[Pos].x = d.x; |
| 493 | if(dst.y) r.o[Pos].y = d.y; |
| 494 | if(dst.z) r.o[Pos].z = d.z; |
| 495 | if(dst.w) r.o[Pos].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 496 | break; |
| 497 | case 1: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 498 | r.o[Fog].x = d.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 499 | break; |
| 500 | case 2: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 501 | r.o[Pts].y = d.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 502 | break; |
| 503 | default: ASSERT(false); |
| 504 | } |
| 505 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 506 | case Shader::PARAMETER_ATTROUT: |
| 507 | if(dst.x) r.o[D0 + dst.index].x = d.x; |
| 508 | if(dst.y) r.o[D0 + dst.index].y = d.y; |
| 509 | if(dst.z) r.o[D0 + dst.index].z = d.z; |
| 510 | if(dst.w) r.o[D0 + dst.index].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 511 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 512 | case Shader::PARAMETER_TEXCRDOUT: |
| 513 | // case Shader::PARAMETER_OUTPUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 514 | if(version < 0x0300) |
| 515 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 516 | if(dst.x) r.o[T0 + dst.index].x = d.x; |
| 517 | if(dst.y) r.o[T0 + dst.index].y = d.y; |
| 518 | if(dst.z) r.o[T0 + dst.index].z = d.z; |
| 519 | if(dst.w) r.o[T0 + dst.index].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 520 | } |
| 521 | else |
| 522 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 523 | if(dst.rel.type == Shader::PARAMETER_VOID) // Not relative |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 524 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 525 | if(dst.x) r.o[dst.index].x = d.x; |
| 526 | if(dst.y) r.o[dst.index].y = d.y; |
| 527 | if(dst.z) r.o[dst.index].z = d.z; |
| 528 | if(dst.w) r.o[dst.index].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 529 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 530 | else if(dst.rel.type == Shader::PARAMETER_LOOP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 531 | { |
| 532 | Int aL = r.aL[r.loopDepth]; |
| 533 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 534 | if(dst.x) r.o[dst.index + aL].x = d.x; |
| 535 | if(dst.y) r.o[dst.index + aL].y = d.y; |
| 536 | if(dst.z) r.o[dst.index + aL].z = d.z; |
| 537 | if(dst.w) r.o[dst.index + aL].w = d.w; |
| 538 | } |
| 539 | else |
| 540 | { |
| 541 | Int a = relativeAddress(r, dst); |
| 542 | |
| 543 | if(dst.x) r.o[dst.index + a].x = d.x; |
| 544 | if(dst.y) r.o[dst.index + a].y = d.y; |
| 545 | if(dst.z) r.o[dst.index + a].z = d.z; |
| 546 | if(dst.w) r.o[dst.index + a].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 550 | case Shader::PARAMETER_LABEL: break; |
| 551 | case Shader::PARAMETER_PREDICATE: r.p0 = d; break; |
| 552 | case Shader::PARAMETER_INPUT: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 553 | default: |
| 554 | ASSERT(false); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 559 | if(currentLabel != -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 560 | { |
| 561 | Nucleus::setInsertBlock(returnBlock); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | void VertexProgram::passThrough(Registers &r) |
| 566 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 567 | if(shader) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 568 | { |
| 569 | for(int i = 0; i < 12; i++) |
| 570 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 571 | unsigned char usage = shader->output[i][0].usage; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 572 | |
| 573 | switch(usage) |
| 574 | { |
| 575 | case 0xFF: |
| 576 | continue; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 577 | case Shader::USAGE_PSIZE: |
| 578 | r.o[i].y = r.v[i].x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 579 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 580 | case Shader::USAGE_TEXCOORD: |
| 581 | r.o[i].x = r.v[i].x; |
| 582 | r.o[i].y = r.v[i].y; |
| 583 | r.o[i].z = r.v[i].z; |
| 584 | r.o[i].w = r.v[i].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 585 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 586 | case Shader::USAGE_POSITION: |
| 587 | r.o[i].x = r.v[i].x; |
| 588 | r.o[i].y = r.v[i].y; |
| 589 | r.o[i].z = r.v[i].z; |
| 590 | r.o[i].w = r.v[i].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 591 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 592 | case Shader::USAGE_COLOR: |
| 593 | r.o[i].x = r.v[i].x; |
| 594 | r.o[i].y = r.v[i].y; |
| 595 | r.o[i].z = r.v[i].z; |
| 596 | r.o[i].w = r.v[i].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 597 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 598 | case Shader::USAGE_FOG: |
| 599 | r.o[i].x = r.v[i].x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 600 | break; |
| 601 | default: |
| 602 | ASSERT(false); |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | else |
| 607 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 608 | r.o[Pos].x = r.v[PositionT].x; |
| 609 | r.o[Pos].y = r.v[PositionT].y; |
| 610 | r.o[Pos].z = r.v[PositionT].z; |
| 611 | r.o[Pos].w = r.v[PositionT].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 612 | |
| 613 | for(int i = 0; i < 2; i++) |
| 614 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 615 | r.o[D0 + i].x = r.v[Color0 + i].x; |
| 616 | r.o[D0 + i].y = r.v[Color0 + i].y; |
| 617 | r.o[D0 + i].z = r.v[Color0 + i].z; |
| 618 | r.o[D0 + i].w = r.v[Color0 + i].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | for(int i = 0; i < 8; i++) |
| 622 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 623 | r.o[T0 + i].x = r.v[TexCoord0 + i].x; |
| 624 | r.o[T0 + i].y = r.v[TexCoord0 + i].y; |
| 625 | r.o[T0 + i].z = r.v[TexCoord0 + i].z; |
| 626 | r.o[T0 + i].w = r.v[TexCoord0 + i].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 627 | } |
| 628 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 629 | r.o[Pts].y = r.v[PointSize].x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 633 | Vector4f VertexProgram::fetchRegisterF(Registers &r, const Src &src, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 634 | { |
| 635 | int i = src.index + offset; |
| 636 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 637 | Vector4f reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 638 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 639 | switch(src.type) |
| 640 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 641 | case Shader::PARAMETER_TEMP: |
| 642 | if(src.rel.type == Shader::PARAMETER_VOID) |
| 643 | { |
| 644 | reg = r.r[i]; |
| 645 | } |
| 646 | else |
| 647 | { |
| 648 | reg = r.r[i + relativeAddress(r, src)]; |
| 649 | } |
| 650 | break; |
| 651 | case Shader::PARAMETER_CONST: |
| 652 | reg = readConstant(r, src, offset); |
| 653 | break; |
| 654 | case Shader::PARAMETER_INPUT: |
| 655 | if(src.rel.type == Shader::PARAMETER_VOID) |
| 656 | { |
| 657 | reg = r.v[i]; |
| 658 | } |
| 659 | else |
| 660 | { |
| 661 | reg = r.v[i + relativeAddress(r, src)]; |
| 662 | } |
| 663 | break; |
| 664 | case Shader::PARAMETER_VOID: return r.r[0]; // Dummy |
| 665 | case Shader::PARAMETER_FLOAT4LITERAL: |
| 666 | reg.x = Float4(src.value[0]); |
| 667 | reg.y = Float4(src.value[1]); |
| 668 | reg.z = Float4(src.value[2]); |
| 669 | reg.w = Float4(src.value[3]); |
| 670 | break; |
| 671 | case Shader::PARAMETER_ADDR: reg = r.a0; break; |
| 672 | case Shader::PARAMETER_CONSTBOOL: return r.r[0]; // Dummy |
| 673 | case Shader::PARAMETER_CONSTINT: return r.r[0]; // Dummy |
| 674 | case Shader::PARAMETER_LOOP: return r.r[0]; // Dummy |
| 675 | case Shader::PARAMETER_PREDICATE: return r.r[0]; // Dummy |
| 676 | case Shader::PARAMETER_SAMPLER: |
| 677 | if(src.rel.type == Shader::PARAMETER_VOID) |
| 678 | { |
| 679 | reg.x = As<Float4>(Int4(i)); |
| 680 | } |
| 681 | else if(src.rel.type == Shader::PARAMETER_TEMP) |
| 682 | { |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 683 | reg.x = As<Float4>(Int4(i) + As<Int4>(r.r[src.rel.index].x)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 684 | } |
| 685 | return reg; |
| 686 | case Shader::PARAMETER_OUTPUT: |
| 687 | if(src.rel.type == Shader::PARAMETER_VOID) |
| 688 | { |
| 689 | reg = r.o[i]; |
| 690 | } |
| 691 | else |
| 692 | { |
| 693 | reg = r.o[i + relativeAddress(r, src)]; |
| 694 | } |
| 695 | break; |
Alexis Hetu | dd8df68 | 2015-06-05 17:08:39 -0400 | [diff] [blame] | 696 | case Shader::PARAMETER_MISCTYPE: |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 697 | reg.x = As<Float>(Int(r.instanceID)); |
Alexis Hetu | dd8df68 | 2015-06-05 17:08:39 -0400 | [diff] [blame] | 698 | return reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 699 | default: |
| 700 | ASSERT(false); |
| 701 | } |
| 702 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 703 | const Float4 &x = reg[(src.swizzle >> 0) & 0x3]; |
| 704 | const Float4 &y = reg[(src.swizzle >> 2) & 0x3]; |
| 705 | const Float4 &z = reg[(src.swizzle >> 4) & 0x3]; |
| 706 | const Float4 &w = reg[(src.swizzle >> 6) & 0x3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 707 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 708 | Vector4f mod; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 709 | |
| 710 | switch(src.modifier) |
| 711 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 712 | case Shader::MODIFIER_NONE: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 713 | mod.x = x; |
| 714 | mod.y = y; |
| 715 | mod.z = z; |
| 716 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 717 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 718 | case Shader::MODIFIER_NEGATE: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 719 | mod.x = -x; |
| 720 | mod.y = -y; |
| 721 | mod.z = -z; |
| 722 | mod.w = -w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 723 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 724 | case Shader::MODIFIER_ABS: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 725 | mod.x = Abs(x); |
| 726 | mod.y = Abs(y); |
| 727 | mod.z = Abs(z); |
| 728 | mod.w = Abs(w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 729 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 730 | case Shader::MODIFIER_ABS_NEGATE: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 731 | mod.x = -Abs(x); |
| 732 | mod.y = -Abs(y); |
| 733 | mod.z = -Abs(z); |
| 734 | mod.w = -Abs(w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 735 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 736 | case Shader::MODIFIER_NOT: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 737 | mod.x = As<Float4>(As<Int4>(x) ^ Int4(0xFFFFFFFF)); |
| 738 | mod.y = As<Float4>(As<Int4>(y) ^ Int4(0xFFFFFFFF)); |
| 739 | mod.z = As<Float4>(As<Int4>(z) ^ Int4(0xFFFFFFFF)); |
| 740 | mod.w = As<Float4>(As<Int4>(w) ^ Int4(0xFFFFFFFF)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 741 | break; |
| 742 | default: |
| 743 | ASSERT(false); |
| 744 | } |
| 745 | |
| 746 | return mod; |
| 747 | } |
| 748 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 749 | Vector4f VertexProgram::readConstant(Registers &r, const Src &src, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 750 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 751 | Vector4f c; |
| 752 | |
| 753 | int i = src.index + offset; |
| 754 | |
| 755 | if(src.rel.type == Shader::PARAMETER_VOID) // Not relative |
| 756 | { |
| 757 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[i])); |
| 758 | |
| 759 | c.x = c.x.xxxx; |
| 760 | c.y = c.y.yyyy; |
| 761 | c.z = c.z.zzzz; |
| 762 | c.w = c.w.wwww; |
| 763 | |
Nicolas Capens | eafdb22 | 2015-05-15 15:24:08 -0400 | [diff] [blame] | 764 | if(shader->containsDefineInstruction()) // Constant may be known at compile time |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 765 | { |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 766 | for(size_t j = 0; j < shader->getLength(); j++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 767 | { |
| 768 | const Shader::Instruction &instruction = *shader->getInstruction(j); |
| 769 | |
| 770 | if(instruction.opcode == Shader::OPCODE_DEF) |
| 771 | { |
| 772 | if(instruction.dst.index == i) |
| 773 | { |
| 774 | c.x = Float4(instruction.src[0].value[0]); |
| 775 | c.y = Float4(instruction.src[0].value[1]); |
| 776 | c.z = Float4(instruction.src[0].value[2]); |
| 777 | c.w = Float4(instruction.src[0].value[3]); |
| 778 | |
| 779 | break; |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | else if(src.rel.type == Shader::PARAMETER_LOOP) |
| 786 | { |
| 787 | Int loopCounter = r.aL[r.loopDepth]; |
| 788 | |
| 789 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[i]) + loopCounter * 16); |
| 790 | |
| 791 | c.x = c.x.xxxx; |
| 792 | c.y = c.y.yyyy; |
| 793 | c.z = c.z.zzzz; |
| 794 | c.w = c.w.wwww; |
| 795 | } |
| 796 | else |
| 797 | { |
| 798 | if(src.rel.deterministic) |
| 799 | { |
| 800 | Int a = relativeAddress(r, src); |
| 801 | |
| 802 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[i]) + a * 16); |
| 803 | |
| 804 | c.x = c.x.xxxx; |
| 805 | c.y = c.y.yyyy; |
| 806 | c.z = c.z.zzzz; |
| 807 | c.w = c.w.wwww; |
| 808 | } |
| 809 | else |
| 810 | { |
| 811 | int component = src.rel.swizzle & 0x03; |
| 812 | Float4 a; |
| 813 | |
| 814 | switch(src.rel.type) |
| 815 | { |
| 816 | case Shader::PARAMETER_ADDR: a = r.a0[component]; break; |
| 817 | case Shader::PARAMETER_TEMP: a = r.r[src.rel.index][component]; break; |
| 818 | case Shader::PARAMETER_INPUT: a = r.v[src.rel.index][component]; break; |
| 819 | case Shader::PARAMETER_OUTPUT: a = r.o[src.rel.index][component]; break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 820 | case Shader::PARAMETER_CONST: a = *Pointer<Float>(r.data + OFFSET(DrawData,vs.c[src.rel.index][component])); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 821 | default: ASSERT(false); |
| 822 | } |
| 823 | |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 824 | Int4 index = Int4(i) + As<Int4>(a) * Int4(src.rel.scale); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 825 | |
| 826 | index = Min(As<UInt4>(index), UInt4(256)); // Clamp to constant register range, c[256] = {0, 0, 0, 0} |
| 827 | |
| 828 | Int index0 = Extract(index, 0); |
| 829 | Int index1 = Extract(index, 1); |
| 830 | Int index2 = Extract(index, 2); |
| 831 | Int index3 = Extract(index, 3); |
| 832 | |
| 833 | c.x = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c) + index0 * 16, 16); |
| 834 | c.y = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c) + index1 * 16, 16); |
| 835 | c.z = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c) + index2 * 16, 16); |
| 836 | c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c) + index3 * 16, 16); |
| 837 | |
| 838 | transpose4x4(c.x, c.y, c.z, c.w); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | return c; |
| 843 | } |
| 844 | |
| 845 | Int VertexProgram::relativeAddress(Registers &r, const Shader::Parameter &var) |
| 846 | { |
| 847 | ASSERT(var.rel.deterministic); |
| 848 | |
| 849 | if(var.rel.type == Shader::PARAMETER_TEMP) |
| 850 | { |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 851 | return As<Int>(Extract(r.r[var.rel.index].x, 0)) * var.rel.scale; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 852 | } |
| 853 | else if(var.rel.type == Shader::PARAMETER_INPUT) |
| 854 | { |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 855 | return As<Int>(Extract(r.v[var.rel.index].x, 0)) * var.rel.scale; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 856 | } |
| 857 | else if(var.rel.type == Shader::PARAMETER_OUTPUT) |
| 858 | { |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 859 | return As<Int>(Extract(r.o[var.rel.index].x, 0)) * var.rel.scale; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 860 | } |
| 861 | else if(var.rel.type == Shader::PARAMETER_CONST) |
| 862 | { |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 863 | RValue<Int4> c = *Pointer<Int4>(r.data + OFFSET(DrawData, vs.c[var.rel.index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 864 | |
Alexis Hetu | 02a2bb8 | 2015-08-20 14:10:33 -0400 | [diff] [blame] | 865 | return Extract(c, 0) * var.rel.scale; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 866 | } |
| 867 | else ASSERT(false); |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | Int4 VertexProgram::enableMask(Registers &r, const Shader::Instruction *instruction) |
| 873 | { |
| 874 | Int4 enable = instruction->analysisBranch ? Int4(r.enableStack[r.enableIndex]) : Int4(0xFFFFFFFF); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 875 | |
| 876 | if(!whileTest) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 877 | { |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 878 | if(shader->containsBreakInstruction() && instruction->analysisBreak) |
| 879 | { |
| 880 | enable &= r.enableBreak; |
| 881 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 882 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 883 | if(shader->containsContinueInstruction() && instruction->analysisContinue) |
| 884 | { |
| 885 | enable &= r.enableContinue; |
| 886 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 887 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 888 | if(shader->containsLeaveInstruction() && instruction->analysisLeave) |
| 889 | { |
| 890 | enable &= r.enableLeave; |
| 891 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | return enable; |
| 895 | } |
| 896 | |
| 897 | void VertexProgram::M3X2(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1) |
| 898 | { |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 899 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 900 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 901 | |
| 902 | dst.x = dot3(src0, row0); |
| 903 | dst.y = dot3(src0, row1); |
| 904 | } |
| 905 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 906 | void VertexProgram::M3X3(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 907 | { |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 908 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 909 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
| 910 | Vector4f row2 = fetchRegisterF(r, src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 911 | |
| 912 | dst.x = dot3(src0, row0); |
| 913 | dst.y = dot3(src0, row1); |
| 914 | dst.z = dot3(src0, row2); |
| 915 | } |
| 916 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 917 | void VertexProgram::M3X4(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 918 | { |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 919 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 920 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
| 921 | Vector4f row2 = fetchRegisterF(r, src1, 2); |
| 922 | Vector4f row3 = fetchRegisterF(r, src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 923 | |
| 924 | dst.x = dot3(src0, row0); |
| 925 | dst.y = dot3(src0, row1); |
| 926 | dst.z = dot3(src0, row2); |
| 927 | dst.w = dot3(src0, row3); |
| 928 | } |
| 929 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 930 | void VertexProgram::M4X3(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 931 | { |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 932 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 933 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
| 934 | Vector4f row2 = fetchRegisterF(r, src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 935 | |
| 936 | dst.x = dot4(src0, row0); |
| 937 | dst.y = dot4(src0, row1); |
| 938 | dst.z = dot4(src0, row2); |
| 939 | } |
| 940 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 941 | void VertexProgram::M4X4(Registers &r, Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 942 | { |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 943 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 944 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
| 945 | Vector4f row2 = fetchRegisterF(r, src1, 2); |
| 946 | Vector4f row3 = fetchRegisterF(r, src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 947 | |
| 948 | dst.x = dot4(src0, row0); |
| 949 | dst.y = dot4(src0, row1); |
| 950 | dst.z = dot4(src0, row2); |
| 951 | dst.w = dot4(src0, row3); |
| 952 | } |
| 953 | |
| 954 | void VertexProgram::BREAK(Registers &r) |
| 955 | { |
| 956 | llvm::BasicBlock *deadBlock = Nucleus::createBasicBlock(); |
| 957 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1]; |
| 958 | |
| 959 | if(breakDepth == 0) |
| 960 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 961 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 962 | Nucleus::createBr(endBlock); |
| 963 | } |
| 964 | else |
| 965 | { |
| 966 | r.enableBreak = r.enableBreak & ~r.enableStack[r.enableIndex]; |
| 967 | Bool allBreak = SignMask(r.enableBreak) == 0x0; |
| 968 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 969 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 970 | branch(allBreak, endBlock, deadBlock); |
| 971 | } |
| 972 | |
| 973 | Nucleus::setInsertBlock(deadBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 974 | r.enableIndex = r.enableIndex + breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 975 | } |
| 976 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 977 | void VertexProgram::BREAKC(Registers &r, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 978 | { |
| 979 | Int4 condition; |
| 980 | |
| 981 | switch(control) |
| 982 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 983 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 984 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 985 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 986 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 987 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 988 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 989 | default: |
| 990 | ASSERT(false); |
| 991 | } |
| 992 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 993 | BREAK(r, condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | void VertexProgram::BREAKP(Registers &r, const Src &predicateRegister) // FIXME: Factor out parts common with BREAKC |
| 997 | { |
| 998 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 999 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1000 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1001 | { |
| 1002 | condition = ~condition; |
| 1003 | } |
| 1004 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1005 | BREAK(r, condition); |
| 1006 | } |
| 1007 | |
| 1008 | void VertexProgram::BREAK(Registers &r, Int4 &condition) |
| 1009 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1010 | condition &= r.enableStack[r.enableIndex]; |
| 1011 | |
| 1012 | llvm::BasicBlock *continueBlock = Nucleus::createBasicBlock(); |
| 1013 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1]; |
| 1014 | |
| 1015 | r.enableBreak = r.enableBreak & ~condition; |
| 1016 | Bool allBreak = SignMask(r.enableBreak) == 0x0; |
| 1017 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1018 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1019 | branch(allBreak, endBlock, continueBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1020 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1021 | Nucleus::setInsertBlock(continueBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1022 | r.enableIndex = r.enableIndex + breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1023 | } |
| 1024 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1025 | void VertexProgram::CONTINUE(Registers &r) |
| 1026 | { |
| 1027 | r.enableContinue = r.enableContinue & ~r.enableStack[r.enableIndex]; |
| 1028 | } |
| 1029 | |
| 1030 | void VertexProgram::TEST() |
| 1031 | { |
| 1032 | whileTest = true; |
| 1033 | } |
| 1034 | |
| 1035 | void VertexProgram::CALL(Registers &r, int labelIndex, int callSiteIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1036 | { |
| 1037 | if(!labelBlock[labelIndex]) |
| 1038 | { |
| 1039 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 1040 | } |
| 1041 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1042 | if(callRetBlock[labelIndex].size() > 1) |
| 1043 | { |
| 1044 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 1045 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1046 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1047 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1048 | |
| 1049 | Nucleus::createBr(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1050 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 1051 | |
| 1052 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1055 | void VertexProgram::CALLNZ(Registers &r, int labelIndex, int callSiteIndex, const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1056 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1057 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1058 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1059 | CALLNZb(r, labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1060 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1061 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1062 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1063 | CALLNZp(r, labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1064 | } |
| 1065 | else ASSERT(false); |
| 1066 | } |
| 1067 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1068 | void VertexProgram::CALLNZb(Registers &r, int labelIndex, int callSiteIndex, const Src &boolRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1069 | { |
| 1070 | Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,vs.b[boolRegister.index])) != Byte(0)); // FIXME |
| 1071 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1072 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1073 | { |
| 1074 | condition = !condition; |
| 1075 | } |
| 1076 | |
| 1077 | if(!labelBlock[labelIndex]) |
| 1078 | { |
| 1079 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 1080 | } |
| 1081 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1082 | if(callRetBlock[labelIndex].size() > 1) |
| 1083 | { |
| 1084 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 1085 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1086 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1087 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1088 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1089 | branch(condition, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 1090 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 1091 | |
| 1092 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1095 | void VertexProgram::CALLNZp(Registers &r, int labelIndex, int callSiteIndex, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1096 | { |
| 1097 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 1098 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1099 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1100 | { |
| 1101 | condition = ~condition; |
| 1102 | } |
| 1103 | |
| 1104 | condition &= r.enableStack[r.enableIndex]; |
| 1105 | |
| 1106 | if(!labelBlock[labelIndex]) |
| 1107 | { |
| 1108 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 1109 | } |
| 1110 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1111 | if(callRetBlock[labelIndex].size() > 1) |
| 1112 | { |
| 1113 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 1114 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1115 | |
| 1116 | r.enableIndex++; |
| 1117 | r.enableStack[r.enableIndex] = condition; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1118 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1119 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1120 | Bool notAllFalse = SignMask(condition) != 0; |
| 1121 | branch(notAllFalse, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 1122 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1123 | |
| 1124 | r.enableIndex--; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1125 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | void VertexProgram::ELSE(Registers &r) |
| 1129 | { |
| 1130 | ifDepth--; |
| 1131 | |
| 1132 | llvm::BasicBlock *falseBlock = ifFalseBlock[ifDepth]; |
| 1133 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 1134 | |
| 1135 | if(isConditionalIf[ifDepth]) |
| 1136 | { |
| 1137 | Int4 condition = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1138 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1139 | |
| 1140 | branch(notAllFalse, falseBlock, endBlock); |
| 1141 | |
| 1142 | r.enableStack[r.enableIndex] = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1]; |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | Nucleus::createBr(endBlock); |
| 1147 | Nucleus::setInsertBlock(falseBlock); |
| 1148 | } |
| 1149 | |
| 1150 | ifFalseBlock[ifDepth] = endBlock; |
| 1151 | |
| 1152 | ifDepth++; |
| 1153 | } |
| 1154 | |
| 1155 | void VertexProgram::ENDIF(Registers &r) |
| 1156 | { |
| 1157 | ifDepth--; |
| 1158 | |
| 1159 | llvm::BasicBlock *endBlock = ifFalseBlock[ifDepth]; |
| 1160 | |
| 1161 | Nucleus::createBr(endBlock); |
| 1162 | Nucleus::setInsertBlock(endBlock); |
| 1163 | |
| 1164 | if(isConditionalIf[ifDepth]) |
| 1165 | { |
| 1166 | breakDepth--; |
| 1167 | r.enableIndex--; |
| 1168 | } |
| 1169 | } |
| 1170 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1171 | void VertexProgram::ENDLOOP(Registers &r) |
| 1172 | { |
| 1173 | loopRepDepth--; |
| 1174 | |
| 1175 | r.aL[r.loopDepth] = r.aL[r.loopDepth] + r.increment[r.loopDepth]; // FIXME: += |
| 1176 | |
| 1177 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 1178 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 1179 | |
| 1180 | Nucleus::createBr(testBlock); |
| 1181 | Nucleus::setInsertBlock(endBlock); |
| 1182 | |
| 1183 | r.loopDepth--; |
| 1184 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 1185 | } |
| 1186 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1187 | void VertexProgram::ENDREP(Registers &r) |
| 1188 | { |
| 1189 | loopRepDepth--; |
| 1190 | |
| 1191 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 1192 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 1193 | |
| 1194 | Nucleus::createBr(testBlock); |
| 1195 | Nucleus::setInsertBlock(endBlock); |
| 1196 | |
| 1197 | r.loopDepth--; |
| 1198 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 1199 | } |
| 1200 | |
| 1201 | void VertexProgram::ENDWHILE(Registers &r) |
| 1202 | { |
| 1203 | loopRepDepth--; |
| 1204 | |
| 1205 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 1206 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 1207 | |
| 1208 | Nucleus::createBr(testBlock); |
| 1209 | Nucleus::setInsertBlock(endBlock); |
| 1210 | |
| 1211 | r.enableIndex--; |
| 1212 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 1213 | whileTest = false; |
| 1214 | } |
| 1215 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1216 | void VertexProgram::IF(Registers &r, const Src &src) |
| 1217 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1218 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1219 | { |
| 1220 | IFb(r, src); |
| 1221 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1222 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1223 | { |
| 1224 | IFp(r, src); |
| 1225 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1226 | else |
| 1227 | { |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 1228 | Int4 condition = As<Int4>(fetchRegisterF(r, src).x); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1229 | IF(r, condition); |
| 1230 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | void VertexProgram::IFb(Registers &r, const Src &boolRegister) |
| 1234 | { |
| 1235 | ASSERT(ifDepth < 24 + 4); |
| 1236 | |
| 1237 | Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,vs.b[boolRegister.index])) != Byte(0)); // FIXME |
| 1238 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1239 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1240 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1241 | condition = !condition; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 1245 | llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
| 1246 | |
| 1247 | branch(condition, trueBlock, falseBlock); |
| 1248 | |
| 1249 | isConditionalIf[ifDepth] = false; |
| 1250 | ifFalseBlock[ifDepth] = falseBlock; |
| 1251 | |
| 1252 | ifDepth++; |
| 1253 | } |
| 1254 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1255 | void VertexProgram::IFp(Registers &r, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1256 | { |
| 1257 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 1258 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1259 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1260 | { |
| 1261 | condition = ~condition; |
| 1262 | } |
| 1263 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1264 | IF(r, condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1265 | } |
| 1266 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1267 | void VertexProgram::IFC(Registers &r, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1268 | { |
| 1269 | Int4 condition; |
| 1270 | |
| 1271 | switch(control) |
| 1272 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1273 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 1274 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 1275 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 1276 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 1277 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 1278 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1279 | default: |
| 1280 | ASSERT(false); |
| 1281 | } |
| 1282 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1283 | IF(r, condition); |
| 1284 | } |
| 1285 | |
| 1286 | void VertexProgram::IF(Registers &r, Int4 &condition) |
| 1287 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1288 | condition &= r.enableStack[r.enableIndex]; |
| 1289 | |
| 1290 | r.enableIndex++; |
| 1291 | r.enableStack[r.enableIndex] = condition; |
| 1292 | |
| 1293 | llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 1294 | llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
| 1295 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1296 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1297 | |
| 1298 | branch(notAllFalse, trueBlock, falseBlock); |
| 1299 | |
| 1300 | isConditionalIf[ifDepth] = true; |
| 1301 | ifFalseBlock[ifDepth] = falseBlock; |
| 1302 | |
| 1303 | ifDepth++; |
| 1304 | breakDepth++; |
| 1305 | } |
| 1306 | |
| 1307 | void VertexProgram::LABEL(int labelIndex) |
| 1308 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1309 | if(!labelBlock[labelIndex]) |
| 1310 | { |
| 1311 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 1312 | } |
| 1313 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1314 | Nucleus::setInsertBlock(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1315 | currentLabel = labelIndex; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | void VertexProgram::LOOP(Registers &r, const Src &integerRegister) |
| 1319 | { |
| 1320 | r.loopDepth++; |
| 1321 | |
| 1322 | r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,vs.i[integerRegister.index][0])); |
| 1323 | r.aL[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,vs.i[integerRegister.index][1])); |
| 1324 | r.increment[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,vs.i[integerRegister.index][2])); |
| 1325 | |
| 1326 | // FIXME: Compiles to two instructions? |
| 1327 | If(r.increment[r.loopDepth] == 0) |
| 1328 | { |
| 1329 | r.increment[r.loopDepth] = 1; |
| 1330 | } |
| 1331 | |
| 1332 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 1333 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 1334 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 1335 | |
| 1336 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 1337 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 1338 | |
| 1339 | // FIXME: jump(testBlock) |
| 1340 | Nucleus::createBr(testBlock); |
| 1341 | Nucleus::setInsertBlock(testBlock); |
| 1342 | |
| 1343 | branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock); |
| 1344 | Nucleus::setInsertBlock(loopBlock); |
| 1345 | |
| 1346 | r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1; // FIXME: -- |
| 1347 | |
| 1348 | loopRepDepth++; |
| 1349 | breakDepth = 0; |
| 1350 | } |
| 1351 | |
| 1352 | void VertexProgram::REP(Registers &r, const Src &integerRegister) |
| 1353 | { |
| 1354 | r.loopDepth++; |
| 1355 | |
| 1356 | r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,vs.i[integerRegister.index][0])); |
| 1357 | r.aL[r.loopDepth] = r.aL[r.loopDepth - 1]; |
| 1358 | |
| 1359 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 1360 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 1361 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 1362 | |
| 1363 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 1364 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 1365 | |
| 1366 | // FIXME: jump(testBlock) |
| 1367 | Nucleus::createBr(testBlock); |
| 1368 | Nucleus::setInsertBlock(testBlock); |
| 1369 | |
| 1370 | branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock); |
| 1371 | Nucleus::setInsertBlock(loopBlock); |
| 1372 | |
| 1373 | r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1; // FIXME: -- |
| 1374 | |
| 1375 | loopRepDepth++; |
| 1376 | breakDepth = 0; |
| 1377 | } |
| 1378 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1379 | void VertexProgram::WHILE(Registers &r, const Src &temporaryRegister) |
| 1380 | { |
| 1381 | r.enableIndex++; |
| 1382 | |
| 1383 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 1384 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 1385 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 1386 | |
| 1387 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 1388 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 1389 | |
| 1390 | Int4 restoreBreak = r.enableBreak; |
| 1391 | Int4 restoreContinue = r.enableContinue; |
| 1392 | |
| 1393 | // FIXME: jump(testBlock) |
| 1394 | Nucleus::createBr(testBlock); |
| 1395 | Nucleus::setInsertBlock(testBlock); |
| 1396 | r.enableContinue = restoreContinue; |
| 1397 | |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 1398 | const Vector4f &src = fetchRegisterF(r, temporaryRegister); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1399 | Int4 condition = As<Int4>(src.x); |
| 1400 | condition &= r.enableStack[r.enableIndex - 1]; |
| 1401 | r.enableStack[r.enableIndex] = condition; |
| 1402 | |
| 1403 | Bool notAllFalse = SignMask(condition) != 0; |
| 1404 | branch(notAllFalse, loopBlock, endBlock); |
| 1405 | |
| 1406 | Nucleus::setInsertBlock(endBlock); |
| 1407 | r.enableBreak = restoreBreak; |
| 1408 | |
| 1409 | Nucleus::setInsertBlock(loopBlock); |
| 1410 | |
| 1411 | loopRepDepth++; |
| 1412 | breakDepth = 0; |
| 1413 | } |
| 1414 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1415 | void VertexProgram::RET(Registers &r) |
| 1416 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1417 | if(currentLabel == -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1418 | { |
| 1419 | returnBlock = Nucleus::createBasicBlock(); |
| 1420 | Nucleus::createBr(returnBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1421 | } |
| 1422 | else |
| 1423 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1424 | llvm::BasicBlock *unreachableBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1425 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1426 | if(callRetBlock[currentLabel].size() > 1) // Pop the return destination from the call stack |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1427 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1428 | // FIXME: Encapsulate |
| 1429 | UInt index = r.callStack[--r.stackIndex]; |
| 1430 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1431 | llvm::Value *value = index.loadValue(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1432 | llvm::Value *switchInst = Nucleus::createSwitch(value, unreachableBlock, (int)callRetBlock[currentLabel].size()); |
| 1433 | |
| 1434 | for(unsigned int i = 0; i < callRetBlock[currentLabel].size(); i++) |
| 1435 | { |
| 1436 | Nucleus::addSwitchCase(switchInst, i, callRetBlock[currentLabel][i]); |
| 1437 | } |
| 1438 | } |
| 1439 | else if(callRetBlock[currentLabel].size() == 1) // Jump directly to the unique return destination |
| 1440 | { |
| 1441 | Nucleus::createBr(callRetBlock[currentLabel][0]); |
| 1442 | } |
| 1443 | else // Function isn't called |
| 1444 | { |
| 1445 | Nucleus::createBr(unreachableBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | Nucleus::setInsertBlock(unreachableBlock); |
| 1449 | Nucleus::createUnreachable(); |
| 1450 | } |
| 1451 | } |
| 1452 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1453 | void VertexProgram::LEAVE(Registers &r) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1454 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1455 | r.enableLeave = r.enableLeave & ~r.enableStack[r.enableIndex]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1456 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1457 | // FIXME: Return from function if all instances left |
| 1458 | // FIXME: Use enableLeave in other control-flow constructs |
| 1459 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1460 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1461 | void VertexProgram::TEXLDL(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
| 1462 | { |
| 1463 | Vector4f tmp; |
| 1464 | sampleTexture(r, tmp, src1, src0.x, src0.y, src0.z, src0.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1465 | |
| 1466 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 1467 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 1468 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 1469 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 1470 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1471 | |
| 1472 | void VertexProgram::TEX(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
| 1473 | { |
| 1474 | Float4 lod = Float4(0.0f); |
| 1475 | Vector4f tmp; |
| 1476 | sampleTexture(r, tmp, src1, src0.x, src0.y, src0.z, lod); |
| 1477 | |
| 1478 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 1479 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 1480 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 1481 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 1482 | } |
| 1483 | |
| 1484 | void VertexProgram::sampleTexture(Registers &r, Vector4f &c, const Src &s, Float4 &u, Float4 &v, Float4 &w, Float4 &q) |
| 1485 | { |
| 1486 | if(s.type == Shader::PARAMETER_SAMPLER && s.rel.type == Shader::PARAMETER_VOID) |
| 1487 | { |
| 1488 | Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap[16]) + s.index * sizeof(Texture); |
| 1489 | sampler[s.index]->sampleTexture(texture, c, u, v, w, q, r.a0, r.a0, false, false, true); |
| 1490 | } |
| 1491 | else |
| 1492 | { |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 1493 | Int index = As<Int>(Float(fetchRegisterF(r, s).x.x)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1494 | |
| 1495 | for(int i = 0; i < 16; i++) |
| 1496 | { |
| 1497 | if(shader->usesSampler(i)) |
| 1498 | { |
| 1499 | If(index == i) |
| 1500 | { |
| 1501 | Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap[16]) + i * sizeof(Texture); |
| 1502 | sampler[i]->sampleTexture(texture, c, u, v, w, q, r.a0, r.a0, false, false, true); |
| 1503 | // FIXME: When the sampler states are the same, we could use one sampler and just index the texture |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1509 | } |