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