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