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