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: |
Nicolas Capens | b1d3bbf | 2019-08-31 01:32:52 -0400 | [diff] [blame] | 728 | // This is used for all literal types, and since Reactor doesn't guarantee |
| 729 | // preserving the bit pattern of float constants, we must construct them |
| 730 | // as integer constants and bitcast. |
| 731 | reg.x = As<Float4>(Int4(src.integer[0])); |
| 732 | reg.y = As<Float4>(Int4(src.integer[1])); |
| 733 | reg.z = As<Float4>(Int4(src.integer[2])); |
| 734 | reg.w = As<Float4>(Int4(src.integer[3])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 735 | break; |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 736 | case Shader::PARAMETER_ADDR: reg = a0; break; |
| 737 | case Shader::PARAMETER_CONSTBOOL: return r[0]; // Dummy |
| 738 | case Shader::PARAMETER_CONSTINT: return r[0]; // Dummy |
| 739 | case Shader::PARAMETER_LOOP: return r[0]; // Dummy |
| 740 | case Shader::PARAMETER_PREDICATE: return r[0]; // Dummy |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 741 | case Shader::PARAMETER_SAMPLER: |
| 742 | if(src.rel.type == Shader::PARAMETER_VOID) |
| 743 | { |
| 744 | reg.x = As<Float4>(Int4(i)); |
| 745 | } |
| 746 | else if(src.rel.type == Shader::PARAMETER_TEMP) |
| 747 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 748 | 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] | 749 | } |
| 750 | return reg; |
| 751 | case Shader::PARAMETER_OUTPUT: |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 752 | if(src.rel.type == Shader::PARAMETER_VOID) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 753 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 754 | reg = o[i]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 755 | } |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 756 | else if(!src.rel.dynamic) |
| 757 | { |
| 758 | reg = o[i + relativeAddress(src.rel, src.bufferIndex)]; |
| 759 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 760 | else |
| 761 | { |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 762 | reg = o[i + dynamicAddress(src.rel)]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 763 | } |
| 764 | break; |
Alexis Hetu | dd8df68 | 2015-06-05 17:08:39 -0400 | [diff] [blame] | 765 | case Shader::PARAMETER_MISCTYPE: |
Alexis Hetu | 877ddfc | 2017-07-25 17:48:00 -0400 | [diff] [blame] | 766 | if(src.index == Shader::InstanceIDIndex) |
| 767 | { |
| 768 | reg.x = As<Float>(instanceID); |
| 769 | } |
| 770 | else if(src.index == Shader::VertexIDIndex) |
| 771 | { |
| 772 | reg.x = As<Float4>(vertexID); |
| 773 | } |
| 774 | else ASSERT(false); |
Alexis Hetu | dd8df68 | 2015-06-05 17:08:39 -0400 | [diff] [blame] | 775 | return reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 776 | default: |
| 777 | ASSERT(false); |
| 778 | } |
| 779 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 780 | const Float4 &x = reg[(src.swizzle >> 0) & 0x3]; |
| 781 | const Float4 &y = reg[(src.swizzle >> 2) & 0x3]; |
| 782 | const Float4 &z = reg[(src.swizzle >> 4) & 0x3]; |
| 783 | const Float4 &w = reg[(src.swizzle >> 6) & 0x3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 784 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 785 | Vector4f mod; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 786 | |
| 787 | switch(src.modifier) |
| 788 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 789 | case Shader::MODIFIER_NONE: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 790 | mod.x = x; |
| 791 | mod.y = y; |
| 792 | mod.z = z; |
| 793 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 794 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 795 | case Shader::MODIFIER_NEGATE: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 796 | mod.x = -x; |
| 797 | mod.y = -y; |
| 798 | mod.z = -z; |
| 799 | mod.w = -w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 800 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 801 | case Shader::MODIFIER_ABS: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 802 | mod.x = Abs(x); |
| 803 | mod.y = Abs(y); |
| 804 | mod.z = Abs(z); |
| 805 | mod.w = Abs(w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 806 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 807 | case Shader::MODIFIER_ABS_NEGATE: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 808 | mod.x = -Abs(x); |
| 809 | mod.y = -Abs(y); |
| 810 | mod.z = -Abs(z); |
| 811 | mod.w = -Abs(w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 812 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 813 | case Shader::MODIFIER_NOT: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 814 | mod.x = As<Float4>(As<Int4>(x) ^ Int4(0xFFFFFFFF)); |
| 815 | mod.y = As<Float4>(As<Int4>(y) ^ Int4(0xFFFFFFFF)); |
| 816 | mod.z = As<Float4>(As<Int4>(z) ^ Int4(0xFFFFFFFF)); |
| 817 | mod.w = As<Float4>(As<Int4>(w) ^ Int4(0xFFFFFFFF)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 818 | break; |
| 819 | default: |
| 820 | ASSERT(false); |
| 821 | } |
| 822 | |
| 823 | return mod; |
| 824 | } |
| 825 | |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 826 | RValue<Pointer<Byte>> VertexProgram::uniformAddress(int bufferIndex, unsigned int index) |
| 827 | { |
| 828 | if(bufferIndex == -1) |
| 829 | { |
| 830 | return data + OFFSET(DrawData, vs.c[index]); |
| 831 | } |
| 832 | else |
| 833 | { |
| 834 | return *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, vs.u[bufferIndex])) + index; |
| 835 | } |
| 836 | } |
| 837 | |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 838 | RValue<Pointer<Byte>> VertexProgram::uniformAddress(int bufferIndex, unsigned int index, Int &offset) |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 839 | { |
| 840 | return uniformAddress(bufferIndex, index) + offset * sizeof(float4); |
| 841 | } |
| 842 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 843 | Vector4f VertexProgram::readConstant(const Src &src, unsigned int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 844 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 845 | Vector4f c; |
Nicolas Capens | 5d96188 | 2016-01-01 23:18:14 -0500 | [diff] [blame] | 846 | unsigned int i = src.index + offset; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 847 | |
| 848 | if(src.rel.type == Shader::PARAMETER_VOID) // Not relative |
| 849 | { |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 850 | 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] | 851 | |
| 852 | c.x = c.x.xxxx; |
| 853 | c.y = c.y.yyyy; |
| 854 | c.z = c.z.zzzz; |
| 855 | c.w = c.w.wwww; |
| 856 | |
Nicolas Capens | eafdb22 | 2015-05-15 15:24:08 -0400 | [diff] [blame] | 857 | if(shader->containsDefineInstruction()) // Constant may be known at compile time |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 858 | { |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 859 | for(size_t j = 0; j < shader->getLength(); j++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 860 | { |
| 861 | const Shader::Instruction &instruction = *shader->getInstruction(j); |
| 862 | |
| 863 | if(instruction.opcode == Shader::OPCODE_DEF) |
| 864 | { |
| 865 | if(instruction.dst.index == i) |
| 866 | { |
| 867 | c.x = Float4(instruction.src[0].value[0]); |
| 868 | c.y = Float4(instruction.src[0].value[1]); |
| 869 | c.z = Float4(instruction.src[0].value[2]); |
| 870 | c.w = Float4(instruction.src[0].value[3]); |
| 871 | |
| 872 | break; |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | } |
| 877 | } |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 878 | else if(!src.rel.dynamic || src.rel.type == Shader::PARAMETER_LOOP) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 879 | { |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 880 | Int a = relativeAddress(src.rel, src.bufferIndex); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 881 | |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 882 | 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] | 883 | |
| 884 | c.x = c.x.xxxx; |
| 885 | c.y = c.y.yyyy; |
| 886 | c.z = c.z.zzzz; |
| 887 | c.w = c.w.wwww; |
| 888 | } |
| 889 | else |
| 890 | { |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 891 | int component = src.rel.swizzle & 0x03; |
| 892 | Float4 a; |
| 893 | |
| 894 | switch(src.rel.type) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 895 | { |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 896 | case Shader::PARAMETER_ADDR: a = a0[component]; break; |
| 897 | case Shader::PARAMETER_TEMP: a = r[src.rel.index][component]; break; |
| 898 | case Shader::PARAMETER_INPUT: a = v[src.rel.index][component]; break; |
| 899 | case Shader::PARAMETER_OUTPUT: a = o[src.rel.index][component]; break; |
| 900 | case Shader::PARAMETER_CONST: a = *Pointer<Float>(uniformAddress(src.bufferIndex, src.rel.index) + component * sizeof(float)); break; |
| 901 | case Shader::PARAMETER_MISCTYPE: |
| 902 | switch(src.rel.index) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 903 | { |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 904 | case Shader::InstanceIDIndex: a = As<Float4>(Int4(instanceID)); break; |
| 905 | case Shader::VertexIDIndex: a = As<Float4>(vertexID); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 906 | default: ASSERT(false); |
| 907 | } |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 908 | break; |
| 909 | default: ASSERT(false); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 910 | } |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 911 | |
| 912 | Int4 index = Int4(i) + As<Int4>(a) * Int4(src.rel.scale); |
| 913 | |
Chris Forbes | ac3a67c | 2019-11-26 11:49:09 -0800 | [diff] [blame] | 914 | if (src.bufferIndex == -1) |
| 915 | { |
| 916 | index = Min(As<UInt4>(index), UInt4(VERTEX_UNIFORM_VECTORS)); // Clamp to constant register range, c[VERTEX_UNIFORM_VECTORS] = {0, 0, 0, 0} |
| 917 | } |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 918 | |
| 919 | Int index0 = Extract(index, 0); |
| 920 | Int index1 = Extract(index, 1); |
| 921 | Int index2 = Extract(index, 2); |
| 922 | Int index3 = Extract(index, 3); |
| 923 | |
| 924 | c.x = *Pointer<Float4>(uniformAddress(src.bufferIndex, 0, index0), 16); |
| 925 | c.y = *Pointer<Float4>(uniformAddress(src.bufferIndex, 0, index1), 16); |
| 926 | c.z = *Pointer<Float4>(uniformAddress(src.bufferIndex, 0, index2), 16); |
| 927 | c.w = *Pointer<Float4>(uniformAddress(src.bufferIndex, 0, index3), 16); |
| 928 | |
| 929 | transpose4x4(c.x, c.y, c.z, c.w); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | return c; |
| 933 | } |
| 934 | |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 935 | Int VertexProgram::relativeAddress(const Shader::Relative &rel, int bufferIndex) |
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 | ASSERT(!rel.dynamic); |
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 | if(rel.type == Shader::PARAMETER_TEMP) |
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 | return As<Int>(Extract(r[rel.index].x, 0)) * rel.scale; |
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 | else if(rel.type == Shader::PARAMETER_INPUT) |
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 | return As<Int>(Extract(v[rel.index].x, 0)) * rel.scale; |
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 | else if(rel.type == Shader::PARAMETER_OUTPUT) |
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 | return As<Int>(Extract(o[rel.index].x, 0)) * rel.scale; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 950 | } |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 951 | else if(rel.type == Shader::PARAMETER_CONST) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 952 | { |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 953 | return *Pointer<Int>(uniformAddress(bufferIndex, rel.index)) * rel.scale; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 954 | } |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 955 | else if(rel.type == Shader::PARAMETER_LOOP) |
Nicolas Capens | 907700d | 2016-01-20 17:09:28 -0500 | [diff] [blame] | 956 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 957 | return aL[loopDepth]; |
Nicolas Capens | 907700d | 2016-01-20 17:09:28 -0500 | [diff] [blame] | 958 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 959 | else ASSERT(false); |
| 960 | |
| 961 | return 0; |
| 962 | } |
| 963 | |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 964 | Int4 VertexProgram::dynamicAddress(const Shader::Relative &rel) |
| 965 | { |
| 966 | int component = rel.swizzle & 0x03; |
| 967 | Float4 a; |
| 968 | |
| 969 | switch(rel.type) |
| 970 | { |
| 971 | case Shader::PARAMETER_ADDR: a = a0[component]; break; |
| 972 | case Shader::PARAMETER_TEMP: a = r[rel.index][component]; break; |
| 973 | case Shader::PARAMETER_INPUT: a = v[rel.index][component]; break; |
| 974 | case Shader::PARAMETER_OUTPUT: a = o[rel.index][component]; break; |
| 975 | case Shader::PARAMETER_MISCTYPE: |
| 976 | switch(rel.index) |
| 977 | { |
| 978 | case Shader::InstanceIDIndex: a = As<Float>(instanceID); break; |
| 979 | case Shader::VertexIDIndex: a = As<Float4>(vertexID); break; |
| 980 | default: ASSERT(false); |
| 981 | } |
| 982 | break; |
| 983 | default: ASSERT(false); |
| 984 | } |
| 985 | |
| 986 | return As<Int4>(a) * Int4(rel.scale); |
| 987 | } |
| 988 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 989 | Int4 VertexProgram::enableMask(const Shader::Instruction *instruction) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 990 | { |
Nicolas Capens | 6e8ec33 | 2018-11-06 11:56:21 -0500 | [diff] [blame] | 991 | if(scalar) |
| 992 | { |
| 993 | return Int4(0xFFFFFFFF); |
| 994 | } |
| 995 | |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 996 | 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] | 997 | |
Nicolas Capens | 8a58771 | 2018-10-20 14:17:49 -0400 | [diff] [blame] | 998 | if(shader->containsBreakInstruction() && instruction->analysisBreak) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 999 | { |
Nicolas Capens | 8a58771 | 2018-10-20 14:17:49 -0400 | [diff] [blame] | 1000 | enable &= enableBreak; |
| 1001 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1002 | |
Nicolas Capens | 8a58771 | 2018-10-20 14:17:49 -0400 | [diff] [blame] | 1003 | if(shader->containsContinueInstruction() && instruction->analysisContinue) |
| 1004 | { |
| 1005 | enable &= enableContinue; |
| 1006 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1007 | |
Nicolas Capens | 8a58771 | 2018-10-20 14:17:49 -0400 | [diff] [blame] | 1008 | if(shader->containsLeaveInstruction() && instruction->analysisLeave) |
| 1009 | { |
| 1010 | enable &= enableLeave; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | return enable; |
| 1014 | } |
| 1015 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1016 | void VertexProgram::M3X2(Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1017 | { |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1018 | Vector4f row0 = fetchRegister(src1, 0); |
| 1019 | Vector4f row1 = fetchRegister(src1, 1); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1020 | |
| 1021 | dst.x = dot3(src0, row0); |
| 1022 | dst.y = dot3(src0, row1); |
| 1023 | } |
| 1024 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1025 | void VertexProgram::M3X3(Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1026 | { |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1027 | Vector4f row0 = fetchRegister(src1, 0); |
| 1028 | Vector4f row1 = fetchRegister(src1, 1); |
| 1029 | Vector4f row2 = fetchRegister(src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1030 | |
| 1031 | dst.x = dot3(src0, row0); |
| 1032 | dst.y = dot3(src0, row1); |
| 1033 | dst.z = dot3(src0, row2); |
| 1034 | } |
| 1035 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1036 | void VertexProgram::M3X4(Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1037 | { |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1038 | Vector4f row0 = fetchRegister(src1, 0); |
| 1039 | Vector4f row1 = fetchRegister(src1, 1); |
| 1040 | Vector4f row2 = fetchRegister(src1, 2); |
| 1041 | Vector4f row3 = fetchRegister(src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1042 | |
| 1043 | dst.x = dot3(src0, row0); |
| 1044 | dst.y = dot3(src0, row1); |
| 1045 | dst.z = dot3(src0, row2); |
| 1046 | dst.w = dot3(src0, row3); |
| 1047 | } |
| 1048 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1049 | void VertexProgram::M4X3(Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1050 | { |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1051 | Vector4f row0 = fetchRegister(src1, 0); |
| 1052 | Vector4f row1 = fetchRegister(src1, 1); |
| 1053 | Vector4f row2 = fetchRegister(src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1054 | |
| 1055 | dst.x = dot4(src0, row0); |
| 1056 | dst.y = dot4(src0, row1); |
| 1057 | dst.z = dot4(src0, row2); |
| 1058 | } |
| 1059 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1060 | void VertexProgram::M4X4(Vector4f &dst, Vector4f &src0, Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1061 | { |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1062 | Vector4f row0 = fetchRegister(src1, 0); |
| 1063 | Vector4f row1 = fetchRegister(src1, 1); |
| 1064 | Vector4f row2 = fetchRegister(src1, 2); |
| 1065 | Vector4f row3 = fetchRegister(src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1066 | |
| 1067 | dst.x = dot4(src0, row0); |
| 1068 | dst.y = dot4(src0, row1); |
| 1069 | dst.z = dot4(src0, row2); |
| 1070 | dst.w = dot4(src0, row3); |
| 1071 | } |
| 1072 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1073 | void VertexProgram::BREAK() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1074 | { |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1075 | enableBreak = enableBreak & ~enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1076 | } |
| 1077 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1078 | void VertexProgram::BREAKC(Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1079 | { |
| 1080 | Int4 condition; |
| 1081 | |
| 1082 | switch(control) |
| 1083 | { |
Nicolas Capens | ac6d505 | 2018-01-05 15:34:00 -0500 | [diff] [blame] | 1084 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 1085 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 1086 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 1087 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 1088 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 1089 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1090 | default: |
| 1091 | ASSERT(false); |
| 1092 | } |
| 1093 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1094 | BREAK(condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1097 | 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] | 1098 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1099 | Int4 condition = As<Int4>(p0[predicateRegister.swizzle & 0x3]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1100 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1101 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1102 | { |
| 1103 | condition = ~condition; |
| 1104 | } |
| 1105 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1106 | BREAK(condition); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1107 | } |
| 1108 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1109 | void VertexProgram::BREAK(Int4 &condition) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1110 | { |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1111 | condition &= enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1112 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1113 | enableBreak = enableBreak & ~condition; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1114 | } |
| 1115 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1116 | void VertexProgram::CONTINUE() |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1117 | { |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1118 | enableContinue = enableContinue & ~enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | void VertexProgram::TEST() |
| 1122 | { |
Nicolas Capens | 2f490f0 | 2018-11-01 16:53:36 -0400 | [diff] [blame] | 1123 | enableContinue = restoreContinue.back(); |
| 1124 | restoreContinue.pop_back(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
Nicolas Capens | 6e8ec33 | 2018-11-06 11:56:21 -0500 | [diff] [blame] | 1127 | void VertexProgram::SCALAR() |
| 1128 | { |
| 1129 | scalar = true; |
| 1130 | } |
| 1131 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1132 | void VertexProgram::CALL(int labelIndex, int callSiteIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1133 | { |
| 1134 | if(!labelBlock[labelIndex]) |
| 1135 | { |
| 1136 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 1137 | } |
| 1138 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1139 | if(callRetBlock[labelIndex].size() > 1) |
| 1140 | { |
Nicolas Capens | 0f34a98 | 2019-02-11 16:02:23 -0500 | [diff] [blame] | 1141 | callStack[stackIndex++] = UInt(callSiteIndex); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1142 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1143 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1144 | Int4 restoreLeave = enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1145 | |
| 1146 | Nucleus::createBr(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1147 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 1148 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1149 | enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1152 | void VertexProgram::CALLNZ(int labelIndex, int callSiteIndex, const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1153 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1154 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1155 | { |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1156 | CALLNZb(labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1157 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1158 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1159 | { |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1160 | CALLNZp(labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1161 | } |
| 1162 | else ASSERT(false); |
| 1163 | } |
| 1164 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1165 | void VertexProgram::CALLNZb(int labelIndex, int callSiteIndex, const Src &boolRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1166 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1167 | 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] | 1168 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1169 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1170 | { |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1171 | condition = !condition; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | if(!labelBlock[labelIndex]) |
| 1175 | { |
| 1176 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 1177 | } |
| 1178 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1179 | if(callRetBlock[labelIndex].size() > 1) |
| 1180 | { |
Nicolas Capens | 0f34a98 | 2019-02-11 16:02:23 -0500 | [diff] [blame] | 1181 | callStack[stackIndex++] = UInt(callSiteIndex); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1182 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1183 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1184 | Int4 restoreLeave = enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1185 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1186 | branch(condition, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 1187 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 1188 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1189 | enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1190 | } |
| 1191 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1192 | void VertexProgram::CALLNZp(int labelIndex, int callSiteIndex, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1193 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1194 | Int4 condition = As<Int4>(p0[predicateRegister.swizzle & 0x3]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1195 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1196 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1197 | { |
| 1198 | condition = ~condition; |
| 1199 | } |
| 1200 | |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1201 | condition &= enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1202 | |
| 1203 | if(!labelBlock[labelIndex]) |
| 1204 | { |
| 1205 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 1206 | } |
| 1207 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1208 | if(callRetBlock[labelIndex].size() > 1) |
| 1209 | { |
Nicolas Capens | 0f34a98 | 2019-02-11 16:02:23 -0500 | [diff] [blame] | 1210 | callStack[stackIndex++] = UInt(callSiteIndex); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1211 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1212 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1213 | enableIndex++; |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1214 | enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))] = condition; |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1215 | Int4 restoreLeave = enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1216 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1217 | Bool notAllFalse = SignMask(condition) != 0; |
| 1218 | branch(notAllFalse, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 1219 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1220 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1221 | enableIndex--; |
| 1222 | enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1223 | } |
| 1224 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1225 | void VertexProgram::ELSE() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1226 | { |
| 1227 | ifDepth--; |
| 1228 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1229 | BasicBlock *falseBlock = ifFalseBlock[ifDepth]; |
| 1230 | BasicBlock *endBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1231 | |
| 1232 | if(isConditionalIf[ifDepth]) |
| 1233 | { |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1234 | 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] | 1235 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1236 | |
| 1237 | branch(notAllFalse, falseBlock, endBlock); |
| 1238 | |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1239 | 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] | 1240 | } |
| 1241 | else |
| 1242 | { |
| 1243 | Nucleus::createBr(endBlock); |
| 1244 | Nucleus::setInsertBlock(falseBlock); |
| 1245 | } |
| 1246 | |
| 1247 | ifFalseBlock[ifDepth] = endBlock; |
| 1248 | |
| 1249 | ifDepth++; |
| 1250 | } |
| 1251 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1252 | void VertexProgram::ENDIF() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1253 | { |
| 1254 | ifDepth--; |
| 1255 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1256 | BasicBlock *endBlock = ifFalseBlock[ifDepth]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1257 | |
| 1258 | Nucleus::createBr(endBlock); |
| 1259 | Nucleus::setInsertBlock(endBlock); |
| 1260 | |
| 1261 | if(isConditionalIf[ifDepth]) |
| 1262 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1263 | enableIndex--; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1267 | void VertexProgram::ENDLOOP() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1268 | { |
| 1269 | loopRepDepth--; |
| 1270 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1271 | aL[loopDepth] = aL[loopDepth] + increment[loopDepth]; // FIXME: += |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1272 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1273 | BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 1274 | BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1275 | |
| 1276 | Nucleus::createBr(testBlock); |
| 1277 | Nucleus::setInsertBlock(endBlock); |
| 1278 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1279 | loopDepth--; |
| 1280 | enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1281 | } |
| 1282 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1283 | void VertexProgram::ENDREP() |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1284 | { |
| 1285 | loopRepDepth--; |
| 1286 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1287 | BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 1288 | BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1289 | |
| 1290 | Nucleus::createBr(testBlock); |
| 1291 | Nucleus::setInsertBlock(endBlock); |
| 1292 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1293 | loopDepth--; |
| 1294 | enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1295 | } |
| 1296 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1297 | void VertexProgram::ENDWHILE() |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1298 | { |
| 1299 | loopRepDepth--; |
| 1300 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1301 | BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 1302 | BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1303 | |
| 1304 | Nucleus::createBr(testBlock); |
| 1305 | Nucleus::setInsertBlock(endBlock); |
| 1306 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1307 | enableIndex--; |
Nicolas Capens | 6e8ec33 | 2018-11-06 11:56:21 -0500 | [diff] [blame] | 1308 | scalar = false; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 1311 | void VertexProgram::ENDSWITCH() |
| 1312 | { |
| 1313 | loopRepDepth--; |
| 1314 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1315 | BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 1316 | |
Nicolas Capens | ac6d505 | 2018-01-05 15:34:00 -0500 | [diff] [blame] | 1317 | Nucleus::createBr(endBlock); |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 1318 | Nucleus::setInsertBlock(endBlock); |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 1319 | } |
| 1320 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1321 | void VertexProgram::IF(const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1322 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1323 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1324 | { |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1325 | IFb(src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1326 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1327 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1328 | { |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1329 | IFp(src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1330 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1331 | else |
| 1332 | { |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1333 | Int4 condition = As<Int4>(fetchRegister(src).x); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1334 | IF(condition); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1335 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1336 | } |
| 1337 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1338 | void VertexProgram::IFb(const Src &boolRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1339 | { |
| 1340 | ASSERT(ifDepth < 24 + 4); |
| 1341 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1342 | 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] | 1343 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1344 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1345 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1346 | condition = !condition; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1347 | } |
| 1348 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1349 | BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 1350 | BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1351 | |
| 1352 | branch(condition, trueBlock, falseBlock); |
| 1353 | |
| 1354 | isConditionalIf[ifDepth] = false; |
| 1355 | ifFalseBlock[ifDepth] = falseBlock; |
| 1356 | |
| 1357 | ifDepth++; |
| 1358 | } |
| 1359 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1360 | void VertexProgram::IFp(const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1361 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1362 | Int4 condition = As<Int4>(p0[predicateRegister.swizzle & 0x3]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1363 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1364 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1365 | { |
| 1366 | condition = ~condition; |
| 1367 | } |
| 1368 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1369 | IF(condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1372 | void VertexProgram::IFC(Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1373 | { |
| 1374 | Int4 condition; |
| 1375 | |
| 1376 | switch(control) |
| 1377 | { |
Nicolas Capens | ac6d505 | 2018-01-05 15:34:00 -0500 | [diff] [blame] | 1378 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 1379 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 1380 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 1381 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 1382 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 1383 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1384 | default: |
| 1385 | ASSERT(false); |
| 1386 | } |
| 1387 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1388 | IF(condition); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1389 | } |
| 1390 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1391 | void VertexProgram::IF(Int4 &condition) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1392 | { |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1393 | condition &= enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1394 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1395 | enableIndex++; |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1396 | enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))] = condition; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1397 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1398 | BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 1399 | BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1400 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1401 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1402 | |
| 1403 | branch(notAllFalse, trueBlock, falseBlock); |
| 1404 | |
| 1405 | isConditionalIf[ifDepth] = true; |
| 1406 | ifFalseBlock[ifDepth] = falseBlock; |
| 1407 | |
| 1408 | ifDepth++; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | void VertexProgram::LABEL(int labelIndex) |
| 1412 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1413 | if(!labelBlock[labelIndex]) |
| 1414 | { |
| 1415 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 1416 | } |
| 1417 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1418 | Nucleus::setInsertBlock(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1419 | currentLabel = labelIndex; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1420 | } |
| 1421 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1422 | void VertexProgram::LOOP(const Src &integerRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1423 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1424 | loopDepth++; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1425 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1426 | iteration[loopDepth] = *Pointer<Int>(data + OFFSET(DrawData,vs.i[integerRegister.index][0])); |
| 1427 | aL[loopDepth] = *Pointer<Int>(data + OFFSET(DrawData,vs.i[integerRegister.index][1])); |
| 1428 | increment[loopDepth] = *Pointer<Int>(data + OFFSET(DrawData,vs.i[integerRegister.index][2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1429 | |
| 1430 | // FIXME: Compiles to two instructions? |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1431 | If(increment[loopDepth] == 0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1432 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1433 | increment[loopDepth] = 1; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1436 | BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 1437 | BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 1438 | BasicBlock *endBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1439 | |
| 1440 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 1441 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 1442 | |
| 1443 | // FIXME: jump(testBlock) |
| 1444 | Nucleus::createBr(testBlock); |
| 1445 | Nucleus::setInsertBlock(testBlock); |
| 1446 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1447 | branch(iteration[loopDepth] > 0, loopBlock, endBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1448 | Nucleus::setInsertBlock(loopBlock); |
| 1449 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1450 | iteration[loopDepth] = iteration[loopDepth] - 1; // FIXME: -- |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1451 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1452 | loopRepDepth++; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1453 | } |
| 1454 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1455 | void VertexProgram::REP(const Src &integerRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1456 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1457 | loopDepth++; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1458 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1459 | iteration[loopDepth] = *Pointer<Int>(data + OFFSET(DrawData,vs.i[integerRegister.index][0])); |
| 1460 | aL[loopDepth] = aL[loopDepth - 1]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1461 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1462 | BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 1463 | BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 1464 | BasicBlock *endBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1465 | |
| 1466 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 1467 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 1468 | |
| 1469 | // FIXME: jump(testBlock) |
| 1470 | Nucleus::createBr(testBlock); |
| 1471 | Nucleus::setInsertBlock(testBlock); |
| 1472 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1473 | branch(iteration[loopDepth] > 0, loopBlock, endBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1474 | Nucleus::setInsertBlock(loopBlock); |
| 1475 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1476 | iteration[loopDepth] = iteration[loopDepth] - 1; // FIXME: -- |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1477 | |
| 1478 | loopRepDepth++; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1479 | } |
| 1480 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1481 | void VertexProgram::WHILE(const Src &temporaryRegister) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1482 | { |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1483 | enableIndex++; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1484 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1485 | BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 1486 | BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 1487 | BasicBlock *endBlock = Nucleus::createBasicBlock(); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1488 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1489 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 1490 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 1491 | |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1492 | Int4 restoreBreak = enableBreak; |
Nicolas Capens | 2f490f0 | 2018-11-01 16:53:36 -0400 | [diff] [blame] | 1493 | restoreContinue.push_back(enableContinue); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1494 | |
Nicolas Capens | d6bcc11 | 2018-01-08 14:09:51 -0500 | [diff] [blame] | 1495 | // TODO: jump(testBlock) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1496 | Nucleus::createBr(testBlock); |
| 1497 | Nucleus::setInsertBlock(testBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1498 | |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1499 | const Vector4f &src = fetchRegister(temporaryRegister); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1500 | Int4 condition = As<Int4>(src.x); |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1501 | condition &= enableStack[Min(enableIndex - 1, Int(MAX_SHADER_ENABLE_STACK_SIZE))]; |
Nicolas Capens | 2ff2948 | 2016-04-28 15:28:02 -0400 | [diff] [blame] | 1502 | if(shader->containsLeaveInstruction()) condition &= enableLeave; |
Nicolas Capens | 6d12331 | 2018-01-08 12:57:52 -0500 | [diff] [blame] | 1503 | if(shader->containsBreakInstruction()) condition &= enableBreak; |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1504 | enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))] = condition; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1505 | |
| 1506 | Bool notAllFalse = SignMask(condition) != 0; |
| 1507 | branch(notAllFalse, loopBlock, endBlock); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1508 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1509 | Nucleus::setInsertBlock(endBlock); |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1510 | enableBreak = restoreBreak; |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1511 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1512 | Nucleus::setInsertBlock(loopBlock); |
| 1513 | |
| 1514 | loopRepDepth++; |
Nicolas Capens | 6e8ec33 | 2018-11-06 11:56:21 -0500 | [diff] [blame] | 1515 | scalar = false; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1516 | } |
| 1517 | |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 1518 | void VertexProgram::SWITCH() |
| 1519 | { |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1520 | BasicBlock *endBlock = Nucleus::createBasicBlock(); |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 1521 | |
| 1522 | loopRepTestBlock[loopRepDepth] = nullptr; |
| 1523 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 1524 | |
Nicolas Capens | d6bcc11 | 2018-01-08 14:09:51 -0500 | [diff] [blame] | 1525 | Int4 restoreBreak = enableBreak; |
| 1526 | |
| 1527 | BasicBlock *currentBlock = Nucleus::getInsertBlock(); |
| 1528 | |
| 1529 | Nucleus::setInsertBlock(endBlock); |
| 1530 | enableBreak = restoreBreak; |
| 1531 | |
| 1532 | Nucleus::setInsertBlock(currentBlock); |
| 1533 | |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 1534 | loopRepDepth++; |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 1535 | } |
| 1536 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1537 | void VertexProgram::RET() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1538 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1539 | if(currentLabel == -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1540 | { |
| 1541 | returnBlock = Nucleus::createBasicBlock(); |
| 1542 | Nucleus::createBr(returnBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1543 | } |
| 1544 | else |
| 1545 | { |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 1546 | BasicBlock *unreachableBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1547 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1548 | 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] | 1549 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1550 | // FIXME: Encapsulate |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 1551 | UInt index = callStack[--stackIndex]; |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1552 | |
Nicolas Capens | 1933654 | 2016-09-26 10:32:29 -0400 | [diff] [blame] | 1553 | Value *value = index.loadValue(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1554 | SwitchCases *switchCases = Nucleus::createSwitch(value, unreachableBlock, (int)callRetBlock[currentLabel].size()); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1555 | |
| 1556 | for(unsigned int i = 0; i < callRetBlock[currentLabel].size(); i++) |
| 1557 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1558 | Nucleus::addSwitchCase(switchCases, i, callRetBlock[currentLabel][i]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | else if(callRetBlock[currentLabel].size() == 1) // Jump directly to the unique return destination |
| 1562 | { |
| 1563 | Nucleus::createBr(callRetBlock[currentLabel][0]); |
| 1564 | } |
| 1565 | else // Function isn't called |
| 1566 | { |
| 1567 | Nucleus::createBr(unreachableBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | Nucleus::setInsertBlock(unreachableBlock); |
| 1571 | Nucleus::createUnreachable(); |
| 1572 | } |
| 1573 | } |
| 1574 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1575 | void VertexProgram::LEAVE() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1576 | { |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 1577 | enableLeave = enableLeave & ~enableStack[Min(enableIndex, Int(MAX_SHADER_ENABLE_STACK_SIZE))]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1578 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1579 | // FIXME: Return from function if all instances left |
| 1580 | // FIXME: Use enableLeave in other control-flow constructs |
| 1581 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1582 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1583 | void VertexProgram::TEX(Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1584 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1585 | dst = sampleTexture(src1, src0, (src0.x), (src0), (src0), (src0), Base); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1586 | } |
| 1587 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1588 | void VertexProgram::TEXOFFSET(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &offset) |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1589 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1590 | dst = sampleTexture(src1, src0, (src0.x), (src0), (src0), offset, {Base, Offset}); |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1593 | void VertexProgram::TEXLOD(Vector4f &dst, Vector4f &src0, const Src& src1, Float4 &lod) |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1594 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1595 | dst = sampleTexture(src1, src0, lod, (src0), (src0), (src0), Lod); |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1596 | } |
| 1597 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1598 | 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] | 1599 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1600 | dst = sampleTexture(src1, src0, lod, (src0), (src0), offset, {Lod, Offset}); |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1601 | } |
| 1602 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1603 | void VertexProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1, Float4 &lod) |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1604 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1605 | dst = sampleTexture(src1, src0, lod, (src0), (src0), (src0), Fetch); |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1606 | } |
| 1607 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1608 | 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] | 1609 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1610 | dst = sampleTexture(src1, src0, lod, (src0), (src0), offset, {Fetch, Offset}); |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1611 | } |
| 1612 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1613 | 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] | 1614 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1615 | dst = sampleTexture(src1, src0, (src0.x), dsx, dsy, src0, Grad); |
| 1616 | } |
| 1617 | |
| 1618 | void VertexProgram::TEXGRADOFFSET(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &dsx, Vector4f &dsy, Vector4f &offset) |
| 1619 | { |
| 1620 | dst = sampleTexture(src1, src0, (src0.x), dsx, dsy, offset, {Grad, Offset}); |
Alexis Hetu | 25d47fc | 2015-10-22 13:58:32 -0400 | [diff] [blame] | 1621 | } |
| 1622 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 1623 | void VertexProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1) |
Alexis Hetu | 9bcb31d | 2015-07-22 17:03:26 -0400 | [diff] [blame] | 1624 | { |
Nicolas Capens | 79d0e56 | 2018-11-27 17:07:49 -0500 | [diff] [blame] | 1625 | 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] | 1626 | Int offset = uniformSampler ? src1.index * sizeof(Texture) : As<Int>(Float(fetchRegister(src1).x.x)) * sizeof(Texture); |
| 1627 | Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + offset; |
Nicolas Capens | 79d0e56 | 2018-11-27 17:07:49 -0500 | [diff] [blame] | 1628 | |
Nicolas Capens | 89a218b | 2017-11-07 13:05:20 -0500 | [diff] [blame] | 1629 | dst = SamplerCore::textureSize(texture, lod); |
Alexis Hetu | 9bcb31d | 2015-07-22 17:03:26 -0400 | [diff] [blame] | 1630 | } |
| 1631 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1632 | 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] | 1633 | { |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1634 | Vector4f tmp; |
| 1635 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1636 | if(s.type == Shader::PARAMETER_SAMPLER && s.rel.type == Shader::PARAMETER_VOID) |
| 1637 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1638 | tmp = sampleTexture(s.index, uvwq, lod, dsx, dsy, offset, function); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1639 | } |
| 1640 | else |
| 1641 | { |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1642 | Int index = As<Int>(Float(fetchRegister(s).x.x)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1643 | |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1644 | for(int i = 0; i < VERTEX_TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1645 | { |
| 1646 | if(shader->usesSampler(i)) |
| 1647 | { |
| 1648 | If(index == i) |
| 1649 | { |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1650 | tmp = sampleTexture(i, uvwq, lod, dsx, dsy, offset, function); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1651 | // FIXME: When the sampler states are the same, we could use one sampler and just index the texture |
| 1652 | } |
| 1653 | } |
| 1654 | } |
| 1655 | } |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1656 | |
Nicolas Capens | 89a218b | 2017-11-07 13:05:20 -0500 | [diff] [blame] | 1657 | Vector4f c; |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 1658 | c.x = tmp[(s.swizzle >> 0) & 0x3]; |
| 1659 | c.y = tmp[(s.swizzle >> 2) & 0x3]; |
| 1660 | c.z = tmp[(s.swizzle >> 4) & 0x3]; |
| 1661 | c.w = tmp[(s.swizzle >> 6) & 0x3]; |
Nicolas Capens | 89a218b | 2017-11-07 13:05:20 -0500 | [diff] [blame] | 1662 | |
| 1663 | return c; |
| 1664 | } |
| 1665 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 1666 | 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] | 1667 | { |
| 1668 | 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] | 1669 | 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] | 1670 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1671 | } |