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