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