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