John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1 | // SwiftShader Software Renderer |
| 2 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3 | // Copyright(c) 2005-2013 TransGaming Inc. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4 | // |
| 5 | // All rights reserved. No part of this software may be copied, distributed, transmitted, |
| 6 | // transcribed, stored in a retrieval system, translated into any human or computer |
| 7 | // language by any means, or disclosed to third parties without the explicit written |
| 8 | // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express |
| 9 | // or implied, including but not limited to any patent rights, are granted to you. |
| 10 | // |
| 11 | |
| 12 | #include "PixelRoutine.hpp" |
| 13 | |
| 14 | #include "Renderer.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 15 | #include "QuadRasterizer.hpp" |
| 16 | #include "Surface.hpp" |
| 17 | #include "Primitive.hpp" |
| 18 | #include "CPUID.hpp" |
| 19 | #include "SamplerCore.hpp" |
| 20 | #include "Constants.hpp" |
| 21 | #include "Debug.hpp" |
| 22 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 23 | namespace sw |
| 24 | { |
| 25 | extern bool complementaryDepthBuffer; |
| 26 | extern bool postBlendSRGB; |
| 27 | extern bool exactColorRounding; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 28 | extern bool booleanFaceRegister; |
| 29 | extern bool halfIntegerCoordinates; // Pixel centers are not at integer coordinates |
| 30 | extern bool fullPixelPositionRegister; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 31 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 32 | PixelRoutine::PixelRoutine(const PixelProcessor::State &state, const PixelShader *shader) : Rasterizer(state), shader(shader) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 33 | { |
| 34 | perturbate = false; |
| 35 | luminance = false; |
| 36 | previousScaling = false; |
| 37 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 38 | ifDepth = 0; |
| 39 | loopRepDepth = 0; |
| 40 | breakDepth = 0; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 41 | currentLabel = -1; |
| 42 | whileTest = false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 43 | |
| 44 | for(int i = 0; i < 2048; i++) |
| 45 | { |
| 46 | labelBlock[i] = 0; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | PixelRoutine::~PixelRoutine() |
| 51 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 52 | for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 53 | { |
| 54 | delete sampler[i]; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void PixelRoutine::quad(Registers &r, Pointer<Byte> cBuffer[4], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y) |
| 59 | { |
| 60 | #if PERF_PROFILE |
| 61 | Long pipeTime = Ticks(); |
| 62 | #endif |
| 63 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 64 | for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 65 | { |
| 66 | sampler[i] = new SamplerCore(r.constants, state.sampler[i]); |
| 67 | } |
| 68 | |
| 69 | const bool earlyDepthTest = !state.depthOverride && !state.alphaTestActive(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 70 | const bool integerPipeline = shaderVersion() <= 0x0104; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 71 | |
| 72 | Int zMask[4]; // Depth mask |
| 73 | Int sMask[4]; // Stencil mask |
| 74 | |
| 75 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 76 | { |
| 77 | zMask[q] = cMask[q]; |
| 78 | sMask[q] = cMask[q]; |
| 79 | } |
| 80 | |
| 81 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 82 | { |
| 83 | stencilTest(r, sBuffer, q, x, sMask[q], cMask[q]); |
| 84 | } |
| 85 | |
| 86 | Float4 f; |
| 87 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 88 | Float4 (&z)[4] = r.z; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 89 | Float4 &w = r.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 90 | Float4 &rhw = r.rhw; |
| 91 | Float4 rhwCentroid; |
| 92 | |
| 93 | Float4 xxxx = Float4(Float(x)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,xQuad), 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 94 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 95 | if(interpolateZ()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 96 | { |
| 97 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 98 | { |
| 99 | Float4 x = xxxx; |
| 100 | |
| 101 | if(state.multiSample > 1) |
| 102 | { |
| 103 | x -= *Pointer<Float4>(r.constants + OFFSET(Constants,X) + q * sizeof(float4)); |
| 104 | } |
| 105 | |
| 106 | z[q] = interpolate(x, r.Dz[q], z[q], r.primitive + OFFSET(Primitive,z), false, false); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | Bool depthPass = false; |
| 111 | |
| 112 | if(earlyDepthTest) |
| 113 | { |
| 114 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 115 | { |
| 116 | depthPass = depthPass || depthTest(r, zBuffer, q, x, z[q], sMask[q], zMask[q], cMask[q]); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | If(depthPass || Bool(!earlyDepthTest)) |
| 121 | { |
| 122 | #if PERF_PROFILE |
| 123 | Long interpTime = Ticks(); |
| 124 | #endif |
| 125 | |
Nicolas Capens | 66be245 | 2015-01-27 14:58:57 -0500 | [diff] [blame] | 126 | Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,yQuad), 16); |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 127 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 128 | // Centroid locations |
| 129 | Float4 XXXX = Float4(0.0f); |
| 130 | Float4 YYYY = Float4(0.0f); |
| 131 | |
| 132 | if(state.centroid) |
| 133 | { |
| 134 | Float4 WWWW(1.0e-9f); |
| 135 | |
| 136 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 137 | { |
| 138 | XXXX += *Pointer<Float4>(r.constants + OFFSET(Constants,sampleX[q]) + 16 * cMask[q]); |
| 139 | YYYY += *Pointer<Float4>(r.constants + OFFSET(Constants,sampleY[q]) + 16 * cMask[q]); |
| 140 | WWWW += *Pointer<Float4>(r.constants + OFFSET(Constants,weight) + 16 * cMask[q]); |
| 141 | } |
| 142 | |
| 143 | WWWW = Rcp_pp(WWWW); |
| 144 | XXXX *= WWWW; |
| 145 | YYYY *= WWWW; |
| 146 | |
| 147 | XXXX += xxxx; |
| 148 | YYYY += yyyy; |
| 149 | } |
| 150 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 151 | if(interpolateW()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 152 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 153 | w = interpolate(xxxx, r.Dw, rhw, r.primitive + OFFSET(Primitive,w), false, false); |
| 154 | rhw = reciprocal(w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 155 | |
| 156 | if(state.centroid) |
| 157 | { |
| 158 | rhwCentroid = reciprocal(interpolateCentroid(XXXX, YYYY, rhwCentroid, r.primitive + OFFSET(Primitive,w), false, false)); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | for(int interpolant = 0; interpolant < 10; interpolant++) |
| 163 | { |
| 164 | for(int component = 0; component < 4; component++) |
| 165 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 166 | if(state.interpolant[interpolant].component & (1 << component)) |
| 167 | { |
| 168 | if(!state.interpolant[interpolant].centroid) |
| 169 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 170 | r.vf[interpolant][component] = interpolate(xxxx, r.Dv[interpolant][component], rhw, r.primitive + OFFSET(Primitive,V[interpolant][component]), (state.interpolant[interpolant].flat & (1 << component)) != 0, state.perspective); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 171 | } |
| 172 | else |
| 173 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 174 | r.vf[interpolant][component] = interpolateCentroid(XXXX, YYYY, rhwCentroid, r.primitive + OFFSET(Primitive,V[interpolant][component]), (state.interpolant[interpolant].flat & (1 << component)) != 0, state.perspective); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | Float4 rcp; |
| 180 | |
| 181 | switch(state.interpolant[interpolant].project) |
| 182 | { |
| 183 | case 0: |
| 184 | break; |
| 185 | case 1: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 186 | rcp = reciprocal(r.vf[interpolant].y); |
| 187 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 188 | break; |
| 189 | case 2: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 190 | rcp = reciprocal(r.vf[interpolant].z); |
| 191 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
| 192 | r.vf[interpolant].y = r.vf[interpolant].y * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 193 | break; |
| 194 | case 3: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 195 | rcp = reciprocal(r.vf[interpolant].w); |
| 196 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
| 197 | r.vf[interpolant].y = r.vf[interpolant].y * rcp; |
| 198 | r.vf[interpolant].z = r.vf[interpolant].z * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if(state.fog.component) |
| 204 | { |
| 205 | f = interpolate(xxxx, r.Df, rhw, r.primitive + OFFSET(Primitive,f), state.fog.flat & 0x01, state.perspective); |
| 206 | } |
| 207 | |
| 208 | if(integerPipeline) |
| 209 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 210 | if(state.color[0].component & 0x1) r.diffuse.x = convertFixed12(r.vf[0].x); else r.diffuse.x = Short4(0x1000); |
| 211 | if(state.color[0].component & 0x2) r.diffuse.y = convertFixed12(r.vf[0].y); else r.diffuse.y = Short4(0x1000); |
| 212 | if(state.color[0].component & 0x4) r.diffuse.z = convertFixed12(r.vf[0].z); else r.diffuse.z = Short4(0x1000); |
| 213 | if(state.color[0].component & 0x8) r.diffuse.w = convertFixed12(r.vf[0].w); else r.diffuse.w = Short4(0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 214 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 215 | if(state.color[1].component & 0x1) r.specular.x = convertFixed12(r.vf[1].x); else r.specular.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 216 | if(state.color[1].component & 0x2) r.specular.y = convertFixed12(r.vf[1].y); else r.specular.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 217 | if(state.color[1].component & 0x4) r.specular.z = convertFixed12(r.vf[1].z); else r.specular.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 218 | if(state.color[1].component & 0x8) r.specular.w = convertFixed12(r.vf[1].w); else r.specular.w = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 219 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 220 | else if(shaderVersion() >= 0x0300) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 221 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 222 | if(shader->vPosDeclared) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 223 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 224 | if(!halfIntegerCoordinates) |
| 225 | { |
| 226 | r.vPos.x = Float4(Float(x)) + Float4(0, 1, 0, 1); |
| 227 | r.vPos.y = Float4(Float(y)) + Float4(0, 0, 1, 1); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | r.vPos.x = Float4(Float(x)) + Float4(0.5f, 1.5f, 0.5f, 1.5f); |
| 232 | r.vPos.y = Float4(Float(y)) + Float4(0.5f, 0.5f, 1.5f, 1.5f); |
| 233 | } |
| 234 | |
| 235 | if(fullPixelPositionRegister) |
| 236 | { |
| 237 | r.vPos.z = z[0]; // FIXME: Centroid? |
| 238 | r.vPos.w = w; // FIXME: Centroid? |
| 239 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 240 | } |
| 241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 242 | if(shader->vFaceDeclared) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 243 | { |
| 244 | Float4 area = *Pointer<Float>(r.primitive + OFFSET(Primitive,area)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 245 | Float4 face = booleanFaceRegister ? Float4(As<Float4>(CmpNLT(area, Float4(0.0f)))) : area; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 246 | |
| 247 | r.vFace.x = face; |
| 248 | r.vFace.y = face; |
| 249 | r.vFace.z = face; |
| 250 | r.vFace.w = face; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | #if PERF_PROFILE |
| 255 | r.cycles[PERF_INTERP] += Ticks() - interpTime; |
| 256 | #endif |
| 257 | |
| 258 | Bool alphaPass = true; |
| 259 | |
| 260 | if(colorUsed()) |
| 261 | { |
| 262 | #if PERF_PROFILE |
| 263 | Long shaderTime = Ticks(); |
| 264 | #endif |
| 265 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 266 | if(shader) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 267 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 268 | // shader->print("PixelShader-%0.8X.txt", state.shaderID); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 269 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 270 | if(shader->getVersion() <= 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 271 | { |
| 272 | ps_1_x(r, cMask); |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | ps_2_x(r, cMask); |
| 277 | } |
| 278 | } |
| 279 | else |
| 280 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 281 | r.current = r.diffuse; |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 282 | Vector4s temp(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 283 | |
| 284 | for(int stage = 0; stage < 8; stage++) |
| 285 | { |
| 286 | if(state.textureStage[stage].stageOperation == TextureStage::STAGE_DISABLE) |
| 287 | { |
| 288 | break; |
| 289 | } |
| 290 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 291 | Vector4s texture; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 292 | |
| 293 | if(state.textureStage[stage].usesTexture) |
| 294 | { |
| 295 | sampleTexture(r, texture, stage, stage); |
| 296 | } |
| 297 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 298 | blendTexture(r, temp, texture, stage); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 299 | } |
| 300 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 301 | specularPixel(r.current, r.specular); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | #if PERF_PROFILE |
| 305 | r.cycles[PERF_SHADER] += Ticks() - shaderTime; |
| 306 | #endif |
| 307 | |
| 308 | if(integerPipeline) |
| 309 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 310 | r.current.x = Min(r.current.x, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.x = Max(r.current.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 311 | r.current.y = Min(r.current.y, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.y = Max(r.current.y, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 312 | r.current.z = Min(r.current.z, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.z = Max(r.current.z, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 313 | r.current.w = Min(r.current.w, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.w = Max(r.current.w, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 314 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 315 | alphaPass = alphaTest(r, cMask, r.current); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 316 | } |
| 317 | else |
| 318 | { |
| 319 | clampColor(r.oC); |
| 320 | |
| 321 | alphaPass = alphaTest(r, cMask, r.oC[0]); |
| 322 | } |
| 323 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 324 | if((shader && shader->containsKill()) || state.alphaTestActive()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 325 | { |
| 326 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 327 | { |
| 328 | zMask[q] &= cMask[q]; |
| 329 | sMask[q] &= cMask[q]; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | If(alphaPass) |
| 335 | { |
| 336 | if(!earlyDepthTest) |
| 337 | { |
| 338 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 339 | { |
| 340 | depthPass = depthPass || depthTest(r, zBuffer, q, x, z[q], sMask[q], zMask[q], cMask[q]); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | #if PERF_PROFILE |
| 345 | Long ropTime = Ticks(); |
| 346 | #endif |
| 347 | |
| 348 | If(depthPass || Bool(earlyDepthTest)) |
| 349 | { |
| 350 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 351 | { |
| 352 | if(state.multiSampleMask & (1 << q)) |
| 353 | { |
| 354 | writeDepth(r, zBuffer, q, x, z[q], zMask[q]); |
| 355 | |
| 356 | if(state.occlusionEnabled) |
| 357 | { |
| 358 | r.occlusion += *Pointer<UInt>(r.constants + OFFSET(Constants,occlusionCount) + 4 * (zMask[q] & sMask[q])); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if(colorUsed()) |
| 364 | { |
| 365 | #if PERF_PROFILE |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 366 | AddAtomic(Pointer<Long>(&profiler.ropOperations), 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 367 | #endif |
| 368 | |
| 369 | if(integerPipeline) |
| 370 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 371 | rasterOperation(r.current, r, f, cBuffer[0], x, sMask, zMask, cMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 372 | } |
| 373 | else |
| 374 | { |
| 375 | rasterOperation(r.oC, r, f, cBuffer, x, sMask, zMask, cMask); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | #if PERF_PROFILE |
| 381 | r.cycles[PERF_ROP] += Ticks() - ropTime; |
| 382 | #endif |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 387 | { |
| 388 | if(state.multiSampleMask & (1 << q)) |
| 389 | { |
| 390 | writeStencil(r, sBuffer, q, x, sMask[q], zMask[q], cMask[q]); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | #if PERF_PROFILE |
| 395 | r.cycles[PERF_PIPE] += Ticks() - pipeTime; |
| 396 | #endif |
| 397 | } |
| 398 | |
| 399 | Float4 PixelRoutine::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective) |
| 400 | { |
| 401 | Float4 interpolant = D; |
| 402 | |
| 403 | if(!flat) |
| 404 | { |
| 405 | interpolant += x * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,A), 16); |
| 406 | |
| 407 | if(perspective) |
| 408 | { |
| 409 | interpolant *= rhw; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | return interpolant; |
| 414 | } |
| 415 | |
| 416 | Float4 PixelRoutine::interpolateCentroid(Float4 &x, Float4 &y, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective) |
| 417 | { |
| 418 | Float4 interpolant = *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,C), 16); |
| 419 | |
| 420 | if(!flat) |
| 421 | { |
| 422 | interpolant += x * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,A), 16) + |
| 423 | y * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,B), 16); |
| 424 | |
| 425 | if(perspective) |
| 426 | { |
| 427 | interpolant *= rhw; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | return interpolant; |
| 432 | } |
| 433 | |
| 434 | void PixelRoutine::stencilTest(Registers &r, Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &cMask) |
| 435 | { |
| 436 | if(!state.stencilActive) |
| 437 | { |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | // (StencilRef & StencilMask) CompFunc (StencilBufferValue & StencilMask) |
| 442 | |
| 443 | Pointer<Byte> buffer = sBuffer + 2 * x; |
| 444 | |
| 445 | if(q > 0) |
| 446 | { |
| 447 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,stencilSliceB)); |
| 448 | } |
| 449 | |
| 450 | Byte8 value = As<Byte8>(Long1(*Pointer<UInt>(buffer))); |
| 451 | Byte8 valueCCW = value; |
| 452 | |
| 453 | if(!state.noStencilMask) |
| 454 | { |
| 455 | value &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].testMaskQ)); |
| 456 | } |
| 457 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 458 | stencilTest(r, value, state.stencilCompareMode, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 459 | |
| 460 | if(state.twoSidedStencil) |
| 461 | { |
| 462 | if(!state.noStencilMaskCCW) |
| 463 | { |
| 464 | valueCCW &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].testMaskQ)); |
| 465 | } |
| 466 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 467 | stencilTest(r, valueCCW, state.stencilCompareModeCCW, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 468 | |
| 469 | value &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,clockwiseMask)); |
| 470 | valueCCW &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,invClockwiseMask)); |
| 471 | value |= valueCCW; |
| 472 | } |
| 473 | |
| 474 | sMask = SignMask(value) & cMask; |
| 475 | } |
| 476 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 477 | void PixelRoutine::stencilTest(Registers &r, Byte8 &value, StencilCompareMode stencilCompareMode, bool CCW) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 478 | { |
| 479 | Byte8 equal; |
| 480 | |
| 481 | switch(stencilCompareMode) |
| 482 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 483 | case STENCIL_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 484 | value = Byte8(0xFFFFFFFFFFFFFFFF); |
| 485 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 486 | case STENCIL_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 487 | value = Byte8(0x0000000000000000); |
| 488 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 489 | case STENCIL_LESS: // a < b ~ b > a |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 490 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 491 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 492 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 493 | case STENCIL_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 494 | value = CmpEQ(value, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 495 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 496 | case STENCIL_NOTEQUAL: // a != b ~ !(a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 497 | value = CmpEQ(value, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 498 | value ^= Byte8(0xFFFFFFFFFFFFFFFF); |
| 499 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 500 | case STENCIL_LESSEQUAL: // a <= b ~ (b > a) || (a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 501 | equal = value; |
| 502 | equal = CmpEQ(equal, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 503 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 504 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 505 | value |= equal; |
| 506 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 507 | case STENCIL_GREATER: // a > b |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 508 | equal = *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ)); |
| 509 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 510 | equal = CmpGT(As<SByte8>(equal), As<SByte8>(value)); |
| 511 | value = equal; |
| 512 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 513 | case STENCIL_GREATEREQUAL: // a >= b ~ !(a < b) ~ !(b > a) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 514 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 515 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 516 | value ^= Byte8(0xFFFFFFFFFFFFFFFF); |
| 517 | break; |
| 518 | default: |
| 519 | ASSERT(false); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | Bool PixelRoutine::depthTest(Registers &r, Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &sMask, Int &zMask, Int &cMask) |
| 524 | { |
| 525 | if(!state.depthTestActive) |
| 526 | { |
| 527 | return true; |
| 528 | } |
| 529 | |
| 530 | Float4 Z = z; |
| 531 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 532 | if(shader && shader->depthOverride()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 533 | { |
| 534 | if(complementaryDepthBuffer) |
| 535 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 536 | Z = Float4(1.0f) - r.oDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 537 | } |
| 538 | else |
| 539 | { |
| 540 | Z = r.oDepth; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | Pointer<Byte> buffer; |
| 545 | Int pitch; |
| 546 | |
| 547 | if(!state.quadLayoutDepthBuffer) |
| 548 | { |
| 549 | buffer = zBuffer + 4 * x; |
| 550 | pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | buffer = zBuffer + 8 * x; |
| 555 | } |
| 556 | |
| 557 | if(q > 0) |
| 558 | { |
| 559 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,depthSliceB)); |
| 560 | } |
| 561 | |
| 562 | Float4 zValue; |
| 563 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 564 | if(state.depthCompareMode != DEPTH_NEVER || (state.depthCompareMode != DEPTH_ALWAYS && !state.depthWriteEnable)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 565 | { |
| 566 | if(!state.quadLayoutDepthBuffer) |
| 567 | { |
| 568 | // FIXME: Properly optimizes? |
| 569 | zValue.xy = *Pointer<Float4>(buffer); |
| 570 | zValue.zw = *Pointer<Float4>(buffer + pitch - 8); |
| 571 | } |
| 572 | else |
| 573 | { |
| 574 | zValue = *Pointer<Float4>(buffer, 16); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | Int4 zTest; |
| 579 | |
| 580 | switch(state.depthCompareMode) |
| 581 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 582 | case DEPTH_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 583 | // Optimized |
| 584 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 585 | case DEPTH_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 586 | // Optimized |
| 587 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 588 | case DEPTH_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 589 | zTest = CmpEQ(zValue, Z); |
| 590 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 591 | case DEPTH_NOTEQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 592 | zTest = CmpNEQ(zValue, Z); |
| 593 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 594 | case DEPTH_LESS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 595 | if(complementaryDepthBuffer) |
| 596 | { |
| 597 | zTest = CmpLT(zValue, Z); |
| 598 | } |
| 599 | else |
| 600 | { |
| 601 | zTest = CmpNLE(zValue, Z); |
| 602 | } |
| 603 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 604 | case DEPTH_GREATEREQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 605 | if(complementaryDepthBuffer) |
| 606 | { |
| 607 | zTest = CmpNLT(zValue, Z); |
| 608 | } |
| 609 | else |
| 610 | { |
| 611 | zTest = CmpLE(zValue, Z); |
| 612 | } |
| 613 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 614 | case DEPTH_LESSEQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 615 | if(complementaryDepthBuffer) |
| 616 | { |
| 617 | zTest = CmpLE(zValue, Z); |
| 618 | } |
| 619 | else |
| 620 | { |
| 621 | zTest = CmpNLT(zValue, Z); |
| 622 | } |
| 623 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 624 | case DEPTH_GREATER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 625 | if(complementaryDepthBuffer) |
| 626 | { |
| 627 | zTest = CmpNLE(zValue, Z); |
| 628 | } |
| 629 | else |
| 630 | { |
| 631 | zTest = CmpLT(zValue, Z); |
| 632 | } |
| 633 | break; |
| 634 | default: |
| 635 | ASSERT(false); |
| 636 | } |
| 637 | |
| 638 | switch(state.depthCompareMode) |
| 639 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 640 | case DEPTH_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 641 | zMask = cMask; |
| 642 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 643 | case DEPTH_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 644 | zMask = 0x0; |
| 645 | break; |
| 646 | default: |
| 647 | zMask = SignMask(zTest) & cMask; |
| 648 | break; |
| 649 | } |
| 650 | |
| 651 | if(state.stencilActive) |
| 652 | { |
| 653 | zMask &= sMask; |
| 654 | } |
| 655 | |
| 656 | return zMask != 0; |
| 657 | } |
| 658 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 659 | void PixelRoutine::blendTexture(Registers &r, Vector4s &temp, Vector4s &texture, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 660 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 661 | Vector4s *arg1; |
| 662 | Vector4s *arg2; |
| 663 | Vector4s *arg3; |
| 664 | Vector4s res; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 665 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 666 | Vector4s constant; |
| 667 | Vector4s tfactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 668 | |
| 669 | const TextureStage::State &textureStage = state.textureStage[stage]; |
| 670 | |
| 671 | if(textureStage.firstArgument == TextureStage::SOURCE_CONSTANT || |
| 672 | textureStage.firstArgumentAlpha == TextureStage::SOURCE_CONSTANT || |
| 673 | textureStage.secondArgument == TextureStage::SOURCE_CONSTANT || |
| 674 | textureStage.secondArgumentAlpha == TextureStage::SOURCE_CONSTANT || |
| 675 | textureStage.thirdArgument == TextureStage::SOURCE_CONSTANT || |
| 676 | textureStage.thirdArgumentAlpha == TextureStage::SOURCE_CONSTANT) |
| 677 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 678 | constant.x = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[0])); |
| 679 | constant.y = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[1])); |
| 680 | constant.z = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[2])); |
| 681 | constant.w = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | if(textureStage.firstArgument == TextureStage::SOURCE_TFACTOR || |
| 685 | textureStage.firstArgumentAlpha == TextureStage::SOURCE_TFACTOR || |
| 686 | textureStage.secondArgument == TextureStage::SOURCE_TFACTOR || |
| 687 | textureStage.secondArgumentAlpha == TextureStage::SOURCE_TFACTOR || |
| 688 | textureStage.thirdArgument == TextureStage::SOURCE_TFACTOR || |
| 689 | textureStage.thirdArgumentAlpha == TextureStage::SOURCE_TFACTOR) |
| 690 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 691 | tfactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[0])); |
| 692 | tfactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[1])); |
| 693 | tfactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[2])); |
| 694 | tfactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | // Premodulate |
| 698 | if(stage > 0 && textureStage.usesTexture) |
| 699 | { |
| 700 | if(state.textureStage[stage - 1].stageOperation == TextureStage::STAGE_PREMODULATE) |
| 701 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 702 | r.current.x = MulHigh(r.current.x, texture.x) << 4; |
| 703 | r.current.y = MulHigh(r.current.y, texture.y) << 4; |
| 704 | r.current.z = MulHigh(r.current.z, texture.z) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | if(state.textureStage[stage - 1].stageOperationAlpha == TextureStage::STAGE_PREMODULATE) |
| 708 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 709 | r.current.w = MulHigh(r.current.w, texture.w) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
| 713 | if(luminance) |
| 714 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 715 | texture.x = MulHigh(texture.x, r.L) << 4; |
| 716 | texture.y = MulHigh(texture.y, r.L) << 4; |
| 717 | texture.z = MulHigh(texture.z, r.L) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 718 | |
| 719 | luminance = false; |
| 720 | } |
| 721 | |
| 722 | switch(textureStage.firstArgument) |
| 723 | { |
| 724 | case TextureStage::SOURCE_TEXTURE: arg1 = &texture; break; |
| 725 | case TextureStage::SOURCE_CONSTANT: arg1 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 726 | case TextureStage::SOURCE_CURRENT: arg1 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 727 | case TextureStage::SOURCE_DIFFUSE: arg1 = &r.diffuse; break; |
| 728 | case TextureStage::SOURCE_SPECULAR: arg1 = &r.specular; break; |
| 729 | case TextureStage::SOURCE_TEMP: arg1 = &temp; break; |
| 730 | case TextureStage::SOURCE_TFACTOR: arg1 = &tfactor; break; |
| 731 | default: |
| 732 | ASSERT(false); |
| 733 | } |
| 734 | |
| 735 | switch(textureStage.secondArgument) |
| 736 | { |
| 737 | case TextureStage::SOURCE_TEXTURE: arg2 = &texture; break; |
| 738 | case TextureStage::SOURCE_CONSTANT: arg2 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 739 | case TextureStage::SOURCE_CURRENT: arg2 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 740 | case TextureStage::SOURCE_DIFFUSE: arg2 = &r.diffuse; break; |
| 741 | case TextureStage::SOURCE_SPECULAR: arg2 = &r.specular; break; |
| 742 | case TextureStage::SOURCE_TEMP: arg2 = &temp; break; |
| 743 | case TextureStage::SOURCE_TFACTOR: arg2 = &tfactor; break; |
| 744 | default: |
| 745 | ASSERT(false); |
| 746 | } |
| 747 | |
| 748 | switch(textureStage.thirdArgument) |
| 749 | { |
| 750 | case TextureStage::SOURCE_TEXTURE: arg3 = &texture; break; |
| 751 | case TextureStage::SOURCE_CONSTANT: arg3 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 752 | case TextureStage::SOURCE_CURRENT: arg3 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 753 | case TextureStage::SOURCE_DIFFUSE: arg3 = &r.diffuse; break; |
| 754 | case TextureStage::SOURCE_SPECULAR: arg3 = &r.specular; break; |
| 755 | case TextureStage::SOURCE_TEMP: arg3 = &temp; break; |
| 756 | case TextureStage::SOURCE_TFACTOR: arg3 = &tfactor; break; |
| 757 | default: |
| 758 | ASSERT(false); |
| 759 | } |
| 760 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 761 | Vector4s mod1; |
| 762 | Vector4s mod2; |
| 763 | Vector4s mod3; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 764 | |
| 765 | switch(textureStage.firstModifier) |
| 766 | { |
| 767 | case TextureStage::MODIFIER_COLOR: |
| 768 | break; |
| 769 | case TextureStage::MODIFIER_INVCOLOR: |
| 770 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 771 | mod1.x = SubSat(Short4(0x1000), arg1->x); |
| 772 | mod1.y = SubSat(Short4(0x1000), arg1->y); |
| 773 | mod1.z = SubSat(Short4(0x1000), arg1->z); |
| 774 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 775 | |
| 776 | arg1 = &mod1; |
| 777 | } |
| 778 | break; |
| 779 | case TextureStage::MODIFIER_ALPHA: |
| 780 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 781 | mod1.x = arg1->w; |
| 782 | mod1.y = arg1->w; |
| 783 | mod1.z = arg1->w; |
| 784 | mod1.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 785 | |
| 786 | arg1 = &mod1; |
| 787 | } |
| 788 | break; |
| 789 | case TextureStage::MODIFIER_INVALPHA: |
| 790 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 791 | mod1.x = SubSat(Short4(0x1000), arg1->w); |
| 792 | mod1.y = SubSat(Short4(0x1000), arg1->w); |
| 793 | mod1.z = SubSat(Short4(0x1000), arg1->w); |
| 794 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 795 | |
| 796 | arg1 = &mod1; |
| 797 | } |
| 798 | break; |
| 799 | default: |
| 800 | ASSERT(false); |
| 801 | } |
| 802 | |
| 803 | switch(textureStage.secondModifier) |
| 804 | { |
| 805 | case TextureStage::MODIFIER_COLOR: |
| 806 | break; |
| 807 | case TextureStage::MODIFIER_INVCOLOR: |
| 808 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 809 | mod2.x = SubSat(Short4(0x1000), arg2->x); |
| 810 | mod2.y = SubSat(Short4(0x1000), arg2->y); |
| 811 | mod2.z = SubSat(Short4(0x1000), arg2->z); |
| 812 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 813 | |
| 814 | arg2 = &mod2; |
| 815 | } |
| 816 | break; |
| 817 | case TextureStage::MODIFIER_ALPHA: |
| 818 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 819 | mod2.x = arg2->w; |
| 820 | mod2.y = arg2->w; |
| 821 | mod2.z = arg2->w; |
| 822 | mod2.w = arg2->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 823 | |
| 824 | arg2 = &mod2; |
| 825 | } |
| 826 | break; |
| 827 | case TextureStage::MODIFIER_INVALPHA: |
| 828 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 829 | mod2.x = SubSat(Short4(0x1000), arg2->w); |
| 830 | mod2.y = SubSat(Short4(0x1000), arg2->w); |
| 831 | mod2.z = SubSat(Short4(0x1000), arg2->w); |
| 832 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 833 | |
| 834 | arg2 = &mod2; |
| 835 | } |
| 836 | break; |
| 837 | default: |
| 838 | ASSERT(false); |
| 839 | } |
| 840 | |
| 841 | switch(textureStage.thirdModifier) |
| 842 | { |
| 843 | case TextureStage::MODIFIER_COLOR: |
| 844 | break; |
| 845 | case TextureStage::MODIFIER_INVCOLOR: |
| 846 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 847 | mod3.x = SubSat(Short4(0x1000), arg3->x); |
| 848 | mod3.y = SubSat(Short4(0x1000), arg3->y); |
| 849 | mod3.z = SubSat(Short4(0x1000), arg3->z); |
| 850 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 851 | |
| 852 | arg3 = &mod3; |
| 853 | } |
| 854 | break; |
| 855 | case TextureStage::MODIFIER_ALPHA: |
| 856 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 857 | mod3.x = arg3->w; |
| 858 | mod3.y = arg3->w; |
| 859 | mod3.z = arg3->w; |
| 860 | mod3.w = arg3->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 861 | |
| 862 | arg3 = &mod3; |
| 863 | } |
| 864 | break; |
| 865 | case TextureStage::MODIFIER_INVALPHA: |
| 866 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 867 | mod3.x = SubSat(Short4(0x1000), arg3->w); |
| 868 | mod3.y = SubSat(Short4(0x1000), arg3->w); |
| 869 | mod3.z = SubSat(Short4(0x1000), arg3->w); |
| 870 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 871 | |
| 872 | arg3 = &mod3; |
| 873 | } |
| 874 | break; |
| 875 | default: |
| 876 | ASSERT(false); |
| 877 | } |
| 878 | |
| 879 | switch(textureStage.stageOperation) |
| 880 | { |
| 881 | case TextureStage::STAGE_DISABLE: |
| 882 | break; |
| 883 | case TextureStage::STAGE_SELECTARG1: // Arg1 |
| 884 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 885 | res.x = arg1->x; |
| 886 | res.y = arg1->y; |
| 887 | res.z = arg1->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 888 | } |
| 889 | break; |
| 890 | case TextureStage::STAGE_SELECTARG2: // Arg2 |
| 891 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 892 | res.x = arg2->x; |
| 893 | res.y = arg2->y; |
| 894 | res.z = arg2->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 895 | } |
| 896 | break; |
| 897 | case TextureStage::STAGE_SELECTARG3: // Arg3 |
| 898 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 899 | res.x = arg3->x; |
| 900 | res.y = arg3->y; |
| 901 | res.z = arg3->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 902 | } |
| 903 | break; |
| 904 | case TextureStage::STAGE_MODULATE: // Arg1 * Arg2 |
| 905 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 906 | res.x = MulHigh(arg1->x, arg2->x) << 4; |
| 907 | res.y = MulHigh(arg1->y, arg2->y) << 4; |
| 908 | res.z = MulHigh(arg1->z, arg2->z) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 909 | } |
| 910 | break; |
| 911 | case TextureStage::STAGE_MODULATE2X: // Arg1 * Arg2 * 2 |
| 912 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 913 | res.x = MulHigh(arg1->x, arg2->x) << 5; |
| 914 | res.y = MulHigh(arg1->y, arg2->y) << 5; |
| 915 | res.z = MulHigh(arg1->z, arg2->z) << 5; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 916 | } |
| 917 | break; |
| 918 | case TextureStage::STAGE_MODULATE4X: // Arg1 * Arg2 * 4 |
| 919 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 920 | res.x = MulHigh(arg1->x, arg2->x) << 6; |
| 921 | res.y = MulHigh(arg1->y, arg2->y) << 6; |
| 922 | res.z = MulHigh(arg1->z, arg2->z) << 6; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 923 | } |
| 924 | break; |
| 925 | case TextureStage::STAGE_ADD: // Arg1 + Arg2 |
| 926 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 927 | res.x = AddSat(arg1->x, arg2->x); |
| 928 | res.y = AddSat(arg1->y, arg2->y); |
| 929 | res.z = AddSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 930 | } |
| 931 | break; |
| 932 | case TextureStage::STAGE_ADDSIGNED: // Arg1 + Arg2 - 0.5 |
| 933 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 934 | res.x = AddSat(arg1->x, arg2->x); |
| 935 | res.y = AddSat(arg1->y, arg2->y); |
| 936 | res.z = AddSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 937 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 938 | res.x = SubSat(res.x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 939 | res.y = SubSat(res.y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 940 | res.z = SubSat(res.z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 941 | } |
| 942 | break; |
| 943 | case TextureStage::STAGE_ADDSIGNED2X: // (Arg1 + Arg2 - 0.5) << 1 |
| 944 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 945 | res.x = AddSat(arg1->x, arg2->x); |
| 946 | res.y = AddSat(arg1->y, arg2->y); |
| 947 | res.z = AddSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 948 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 949 | res.x = SubSat(res.x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 950 | res.y = SubSat(res.y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 951 | res.z = SubSat(res.z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 952 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 953 | res.x = AddSat(res.x, res.x); |
| 954 | res.y = AddSat(res.y, res.y); |
| 955 | res.z = AddSat(res.z, res.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 956 | } |
| 957 | break; |
| 958 | case TextureStage::STAGE_SUBTRACT: // Arg1 - Arg2 |
| 959 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 960 | res.x = SubSat(arg1->x, arg2->x); |
| 961 | res.y = SubSat(arg1->y, arg2->y); |
| 962 | res.z = SubSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 963 | } |
| 964 | break; |
| 965 | case TextureStage::STAGE_ADDSMOOTH: // Arg1 + Arg2 - Arg1 * Arg2 |
| 966 | { |
| 967 | Short4 tmp; |
| 968 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 969 | tmp = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(arg1->x, arg2->x); res.x = SubSat(res.x, tmp); |
| 970 | tmp = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(arg1->y, arg2->y); res.y = SubSat(res.y, tmp); |
| 971 | tmp = MulHigh(arg1->z, arg2->z) << 4; res.z = AddSat(arg1->z, arg2->z); res.z = SubSat(res.z, tmp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 972 | } |
| 973 | break; |
| 974 | case TextureStage::STAGE_MULTIPLYADD: // Arg3 + Arg1 * Arg2 |
| 975 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 976 | res.x = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(res.x, arg3->x); |
| 977 | res.y = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(res.y, arg3->y); |
| 978 | res.z = MulHigh(arg1->z, arg2->z) << 4; res.z = AddSat(res.z, arg3->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 979 | } |
| 980 | break; |
| 981 | case TextureStage::STAGE_LERP: // Arg3 * (Arg1 - Arg2) + Arg2 |
| 982 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 983 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, arg3->x) << 4; res.x = AddSat(res.x, arg2->x); |
| 984 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, arg3->y) << 4; res.y = AddSat(res.y, arg2->y); |
| 985 | res.z = SubSat(arg1->z, arg2->z); res.z = MulHigh(res.z, arg3->z) << 4; res.z = AddSat(res.z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 986 | } |
| 987 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 988 | case TextureStage::STAGE_DOT3: // 2 * (Arg1.x - 0.5) * 2 * (Arg2.x - 0.5) + 2 * (Arg1.y - 0.5) * 2 * (Arg2.y - 0.5) + 2 * (Arg1.z - 0.5) * 2 * (Arg2.z - 0.5) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 989 | { |
| 990 | Short4 tmp; |
| 991 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 992 | res.x = SubSat(arg1->x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); tmp = SubSat(arg2->x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); res.x = MulHigh(res.x, tmp); |
| 993 | res.y = SubSat(arg1->y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); tmp = SubSat(arg2->y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); res.y = MulHigh(res.y, tmp); |
| 994 | res.z = SubSat(arg1->z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); tmp = SubSat(arg2->z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); res.z = MulHigh(res.z, tmp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 995 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 996 | res.x = res.x << 6; |
| 997 | res.y = res.y << 6; |
| 998 | res.z = res.z << 6; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 999 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1000 | res.x = AddSat(res.x, res.y); |
| 1001 | res.x = AddSat(res.x, res.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1002 | |
| 1003 | // Clamp to [0, 1] |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1004 | res.x = Max(res.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1005 | res.x = Min(res.x, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1006 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1007 | res.y = res.x; |
| 1008 | res.z = res.x; |
| 1009 | res.w = res.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1010 | } |
| 1011 | break; |
| 1012 | case TextureStage::STAGE_BLENDCURRENTALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1013 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1014 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, r.current.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1015 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, r.current.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1016 | res.z = SubSat(arg1->z, arg2->z); res.z = MulHigh(res.z, r.current.w) << 4; res.z = AddSat(res.z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1017 | } |
| 1018 | break; |
| 1019 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1020 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1021 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, r.diffuse.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1022 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, r.diffuse.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1023 | res.z = SubSat(arg1->z, arg2->z); res.z = MulHigh(res.z, r.diffuse.w) << 4; res.z = AddSat(res.z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1024 | } |
| 1025 | break; |
| 1026 | case TextureStage::STAGE_BLENDFACTORALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1027 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1028 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[3]))) << 4; res.x = AddSat(res.x, arg2->x); |
| 1029 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[3]))) << 4; res.y = AddSat(res.y, arg2->y); |
| 1030 | res.z = SubSat(arg1->z, arg2->z); res.z = MulHigh(res.z, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[3]))) << 4; res.z = AddSat(res.z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1031 | } |
| 1032 | break; |
| 1033 | case TextureStage::STAGE_BLENDTEXTUREALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1034 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1035 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, texture.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1036 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, texture.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1037 | res.z = SubSat(arg1->z, arg2->z); res.z = MulHigh(res.z, texture.w) << 4; res.z = AddSat(res.z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1038 | } |
| 1039 | break; |
| 1040 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: // Arg1 + Arg2 * (1 - Alpha) |
| 1041 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1042 | res.x = SubSat(Short4(0x1000), texture.w); res.x = MulHigh(res.x, arg2->x) << 4; res.x = AddSat(res.x, arg1->x); |
| 1043 | res.y = SubSat(Short4(0x1000), texture.w); res.y = MulHigh(res.y, arg2->y) << 4; res.y = AddSat(res.y, arg1->y); |
| 1044 | res.z = SubSat(Short4(0x1000), texture.w); res.z = MulHigh(res.z, arg2->z) << 4; res.z = AddSat(res.z, arg1->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1045 | } |
| 1046 | break; |
| 1047 | case TextureStage::STAGE_PREMODULATE: |
| 1048 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1049 | res.x = arg1->x; |
| 1050 | res.y = arg1->y; |
| 1051 | res.z = arg1->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1052 | } |
| 1053 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1054 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: // Arg1 + Arg1.w * Arg2 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1055 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1056 | res.x = MulHigh(arg1->w, arg2->x) << 4; res.x = AddSat(res.x, arg1->x); |
| 1057 | res.y = MulHigh(arg1->w, arg2->y) << 4; res.y = AddSat(res.y, arg1->y); |
| 1058 | res.z = MulHigh(arg1->w, arg2->z) << 4; res.z = AddSat(res.z, arg1->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1059 | } |
| 1060 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1061 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: // Arg1 * Arg2 + Arg1.w |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1062 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1063 | res.x = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(res.x, arg1->w); |
| 1064 | res.y = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(res.y, arg1->w); |
| 1065 | res.z = MulHigh(arg1->z, arg2->z) << 4; res.z = AddSat(res.z, arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1066 | } |
| 1067 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1068 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: // (1 - Arg1.w) * Arg2 + Arg1 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1069 | { |
| 1070 | Short4 tmp; |
| 1071 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1072 | res.x = AddSat(arg1->x, arg2->x); tmp = MulHigh(arg1->w, arg2->x) << 4; res.x = SubSat(res.x, tmp); |
| 1073 | res.y = AddSat(arg1->y, arg2->y); tmp = MulHigh(arg1->w, arg2->y) << 4; res.y = SubSat(res.y, tmp); |
| 1074 | res.z = AddSat(arg1->z, arg2->z); tmp = MulHigh(arg1->w, arg2->z) << 4; res.z = SubSat(res.z, tmp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1075 | } |
| 1076 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1077 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: // (1 - Arg1) * Arg2 + Arg1.w |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1078 | { |
| 1079 | Short4 tmp; |
| 1080 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1081 | res.x = AddSat(arg1->w, arg2->x); tmp = MulHigh(arg1->x, arg2->x) << 4; res.x = SubSat(res.x, tmp); |
| 1082 | res.y = AddSat(arg1->w, arg2->y); tmp = MulHigh(arg1->y, arg2->y) << 4; res.y = SubSat(res.y, tmp); |
| 1083 | res.z = AddSat(arg1->w, arg2->z); tmp = MulHigh(arg1->z, arg2->z) << 4; res.z = SubSat(res.z, tmp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1084 | } |
| 1085 | break; |
| 1086 | case TextureStage::STAGE_BUMPENVMAP: |
| 1087 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1088 | r.du = Float4(texture.x) * Float4(1.0f / 0x0FE0); |
| 1089 | r.dv = Float4(texture.y) * Float4(1.0f / 0x0FE0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1090 | |
| 1091 | Float4 du2; |
| 1092 | Float4 dv2; |
| 1093 | |
| 1094 | du2 = r.du; |
| 1095 | dv2 = r.dv; |
| 1096 | r.du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 1097 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 1098 | r.du += dv2; |
| 1099 | r.dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 1100 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 1101 | r.dv += du2; |
| 1102 | |
| 1103 | perturbate = true; |
| 1104 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1105 | res.x = r.current.x; |
| 1106 | res.y = r.current.y; |
| 1107 | res.z = r.current.z; |
| 1108 | res.w = r.current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1109 | } |
| 1110 | break; |
| 1111 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1112 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1113 | r.du = Float4(texture.x) * Float4(1.0f / 0x0FE0); |
| 1114 | r.dv = Float4(texture.y) * Float4(1.0f / 0x0FE0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1115 | |
| 1116 | Float4 du2; |
| 1117 | Float4 dv2; |
| 1118 | |
| 1119 | du2 = r.du; |
| 1120 | dv2 = r.dv; |
| 1121 | |
| 1122 | r.du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 1123 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 1124 | r.du += dv2; |
| 1125 | r.dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 1126 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 1127 | r.dv += du2; |
| 1128 | |
| 1129 | perturbate = true; |
| 1130 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1131 | r.L = texture.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1132 | r.L = MulHigh(r.L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceScale4))); |
| 1133 | r.L = r.L << 4; |
| 1134 | r.L = AddSat(r.L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceOffset4))); |
| 1135 | r.L = Max(r.L, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1136 | r.L = Min(r.L, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1137 | |
| 1138 | luminance = true; |
| 1139 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1140 | res.x = r.current.x; |
| 1141 | res.y = r.current.y; |
| 1142 | res.z = r.current.z; |
| 1143 | res.w = r.current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1144 | } |
| 1145 | break; |
| 1146 | default: |
| 1147 | ASSERT(false); |
| 1148 | } |
| 1149 | |
| 1150 | if(textureStage.stageOperation != TextureStage::STAGE_DOT3) |
| 1151 | { |
| 1152 | switch(textureStage.firstArgumentAlpha) |
| 1153 | { |
| 1154 | case TextureStage::SOURCE_TEXTURE: arg1 = &texture; break; |
| 1155 | case TextureStage::SOURCE_CONSTANT: arg1 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1156 | case TextureStage::SOURCE_CURRENT: arg1 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1157 | case TextureStage::SOURCE_DIFFUSE: arg1 = &r.diffuse; break; |
| 1158 | case TextureStage::SOURCE_SPECULAR: arg1 = &r.specular; break; |
| 1159 | case TextureStage::SOURCE_TEMP: arg1 = &temp; break; |
| 1160 | case TextureStage::SOURCE_TFACTOR: arg1 = &tfactor; break; |
| 1161 | default: |
| 1162 | ASSERT(false); |
| 1163 | } |
| 1164 | |
| 1165 | switch(textureStage.secondArgumentAlpha) |
| 1166 | { |
| 1167 | case TextureStage::SOURCE_TEXTURE: arg2 = &texture; break; |
| 1168 | case TextureStage::SOURCE_CONSTANT: arg2 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1169 | case TextureStage::SOURCE_CURRENT: arg2 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1170 | case TextureStage::SOURCE_DIFFUSE: arg2 = &r.diffuse; break; |
| 1171 | case TextureStage::SOURCE_SPECULAR: arg2 = &r.specular; break; |
| 1172 | case TextureStage::SOURCE_TEMP: arg2 = &temp; break; |
| 1173 | case TextureStage::SOURCE_TFACTOR: arg2 = &tfactor; break; |
| 1174 | default: |
| 1175 | ASSERT(false); |
| 1176 | } |
| 1177 | |
| 1178 | switch(textureStage.thirdArgumentAlpha) |
| 1179 | { |
| 1180 | case TextureStage::SOURCE_TEXTURE: arg3 = &texture; break; |
| 1181 | case TextureStage::SOURCE_CONSTANT: arg3 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1182 | case TextureStage::SOURCE_CURRENT: arg3 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1183 | case TextureStage::SOURCE_DIFFUSE: arg3 = &r.diffuse; break; |
| 1184 | case TextureStage::SOURCE_SPECULAR: arg3 = &r.specular; break; |
| 1185 | case TextureStage::SOURCE_TEMP: arg3 = &temp; break; |
| 1186 | case TextureStage::SOURCE_TFACTOR: arg3 = &tfactor; break; |
| 1187 | default: |
| 1188 | ASSERT(false); |
| 1189 | } |
| 1190 | |
| 1191 | switch(textureStage.firstModifierAlpha) // FIXME: Check if actually used |
| 1192 | { |
| 1193 | case TextureStage::MODIFIER_COLOR: |
| 1194 | break; |
| 1195 | case TextureStage::MODIFIER_INVCOLOR: |
| 1196 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1197 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1198 | |
| 1199 | arg1 = &mod1; |
| 1200 | } |
| 1201 | break; |
| 1202 | case TextureStage::MODIFIER_ALPHA: |
| 1203 | { |
| 1204 | // Redudant |
| 1205 | } |
| 1206 | break; |
| 1207 | case TextureStage::MODIFIER_INVALPHA: |
| 1208 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1209 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1210 | |
| 1211 | arg1 = &mod1; |
| 1212 | } |
| 1213 | break; |
| 1214 | default: |
| 1215 | ASSERT(false); |
| 1216 | } |
| 1217 | |
| 1218 | switch(textureStage.secondModifierAlpha) // FIXME: Check if actually used |
| 1219 | { |
| 1220 | case TextureStage::MODIFIER_COLOR: |
| 1221 | break; |
| 1222 | case TextureStage::MODIFIER_INVCOLOR: |
| 1223 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1224 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1225 | |
| 1226 | arg2 = &mod2; |
| 1227 | } |
| 1228 | break; |
| 1229 | case TextureStage::MODIFIER_ALPHA: |
| 1230 | { |
| 1231 | // Redudant |
| 1232 | } |
| 1233 | break; |
| 1234 | case TextureStage::MODIFIER_INVALPHA: |
| 1235 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1236 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1237 | |
| 1238 | arg2 = &mod2; |
| 1239 | } |
| 1240 | break; |
| 1241 | default: |
| 1242 | ASSERT(false); |
| 1243 | } |
| 1244 | |
| 1245 | switch(textureStage.thirdModifierAlpha) // FIXME: Check if actually used |
| 1246 | { |
| 1247 | case TextureStage::MODIFIER_COLOR: |
| 1248 | break; |
| 1249 | case TextureStage::MODIFIER_INVCOLOR: |
| 1250 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1251 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1252 | |
| 1253 | arg3 = &mod3; |
| 1254 | } |
| 1255 | break; |
| 1256 | case TextureStage::MODIFIER_ALPHA: |
| 1257 | { |
| 1258 | // Redudant |
| 1259 | } |
| 1260 | break; |
| 1261 | case TextureStage::MODIFIER_INVALPHA: |
| 1262 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1263 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1264 | |
| 1265 | arg3 = &mod3; |
| 1266 | } |
| 1267 | break; |
| 1268 | default: |
| 1269 | ASSERT(false); |
| 1270 | } |
| 1271 | |
| 1272 | switch(textureStage.stageOperationAlpha) |
| 1273 | { |
| 1274 | case TextureStage::STAGE_DISABLE: |
| 1275 | break; |
| 1276 | case TextureStage::STAGE_SELECTARG1: // Arg1 |
| 1277 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1278 | res.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1279 | } |
| 1280 | break; |
| 1281 | case TextureStage::STAGE_SELECTARG2: // Arg2 |
| 1282 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1283 | res.w = arg2->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1284 | } |
| 1285 | break; |
| 1286 | case TextureStage::STAGE_SELECTARG3: // Arg3 |
| 1287 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1288 | res.w = arg3->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1289 | } |
| 1290 | break; |
| 1291 | case TextureStage::STAGE_MODULATE: // Arg1 * Arg2 |
| 1292 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1293 | res.w = MulHigh(arg1->w, arg2->w) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1294 | } |
| 1295 | break; |
| 1296 | case TextureStage::STAGE_MODULATE2X: // Arg1 * Arg2 * 2 |
| 1297 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1298 | res.w = MulHigh(arg1->w, arg2->w) << 5; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1299 | } |
| 1300 | break; |
| 1301 | case TextureStage::STAGE_MODULATE4X: // Arg1 * Arg2 * 4 |
| 1302 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1303 | res.w = MulHigh(arg1->w, arg2->w) << 6; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1304 | } |
| 1305 | break; |
| 1306 | case TextureStage::STAGE_ADD: // Arg1 + Arg2 |
| 1307 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1308 | res.w = AddSat(arg1->w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1309 | } |
| 1310 | break; |
| 1311 | case TextureStage::STAGE_ADDSIGNED: // Arg1 + Arg2 - 0.5 |
| 1312 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1313 | res.w = AddSat(arg1->w, arg2->w); |
| 1314 | res.w = SubSat(res.w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1315 | } |
| 1316 | break; |
| 1317 | case TextureStage::STAGE_ADDSIGNED2X: // (Arg1 + Arg2 - 0.5) << 1 |
| 1318 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1319 | res.w = AddSat(arg1->w, arg2->w); |
| 1320 | res.w = SubSat(res.w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 1321 | res.w = AddSat(res.w, res.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1322 | } |
| 1323 | break; |
| 1324 | case TextureStage::STAGE_SUBTRACT: // Arg1 - Arg2 |
| 1325 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1326 | res.w = SubSat(arg1->w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1327 | } |
| 1328 | break; |
| 1329 | case TextureStage::STAGE_ADDSMOOTH: // Arg1 + Arg2 - Arg1 * Arg2 |
| 1330 | { |
| 1331 | Short4 tmp; |
| 1332 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1333 | tmp = MulHigh(arg1->w, arg2->w) << 4; res.w = AddSat(arg1->w, arg2->w); res.w = SubSat(res.w, tmp); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1334 | } |
| 1335 | break; |
| 1336 | case TextureStage::STAGE_MULTIPLYADD: // Arg3 + Arg1 * Arg2 |
| 1337 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1338 | res.w = MulHigh(arg1->w, arg2->w) << 4; res.w = AddSat(res.w, arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1339 | } |
| 1340 | break; |
| 1341 | case TextureStage::STAGE_LERP: // Arg3 * (Arg1 - Arg2) + Arg2 |
| 1342 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1343 | res.w = SubSat(arg1->w, arg2->w); res.w = MulHigh(res.w, arg3->w) << 4; res.w = AddSat(res.w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1344 | } |
| 1345 | break; |
| 1346 | case TextureStage::STAGE_DOT3: |
| 1347 | break; // Already computed in color channel |
| 1348 | case TextureStage::STAGE_BLENDCURRENTALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1349 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1350 | res.w = SubSat(arg1->w, arg2->w); res.w = MulHigh(res.w, r.current.w) << 4; res.w = AddSat(res.w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1351 | } |
| 1352 | break; |
| 1353 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: // Arg1 * (Alpha) + Arg2 * (1 - Alpha) |
| 1354 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1355 | res.w = SubSat(arg1->w, arg2->w); res.w = MulHigh(res.w, r.diffuse.w) << 4; res.w = AddSat(res.w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1356 | } |
| 1357 | break; |
| 1358 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1359 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1360 | res.w = SubSat(arg1->w, arg2->w); res.w = MulHigh(res.w, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[3]))) << 4; res.w = AddSat(res.w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1361 | } |
| 1362 | break; |
| 1363 | case TextureStage::STAGE_BLENDTEXTUREALPHA: // Arg1 * (Alpha) + Arg2 * (1 - Alpha) |
| 1364 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1365 | res.w = SubSat(arg1->w, arg2->w); res.w = MulHigh(res.w, texture.w) << 4; res.w = AddSat(res.w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1366 | } |
| 1367 | break; |
| 1368 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: // Arg1 + Arg2 * (1 - Alpha) |
| 1369 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1370 | res.w = SubSat(Short4(0x1000), texture.w); res.w = MulHigh(res.w, arg2->w) << 4; res.w = AddSat(res.w, arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1371 | } |
| 1372 | break; |
| 1373 | case TextureStage::STAGE_PREMODULATE: |
| 1374 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1375 | res.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1376 | } |
| 1377 | break; |
| 1378 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1379 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1380 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1381 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1382 | case TextureStage::STAGE_BUMPENVMAP: |
| 1383 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1384 | break; // Invalid alpha operations |
| 1385 | default: |
| 1386 | ASSERT(false); |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | // Clamp result to [0, 1] |
| 1391 | |
| 1392 | switch(textureStage.stageOperation) |
| 1393 | { |
| 1394 | case TextureStage::STAGE_DISABLE: |
| 1395 | case TextureStage::STAGE_SELECTARG1: |
| 1396 | case TextureStage::STAGE_SELECTARG2: |
| 1397 | case TextureStage::STAGE_SELECTARG3: |
| 1398 | case TextureStage::STAGE_MODULATE: |
| 1399 | case TextureStage::STAGE_MODULATE2X: |
| 1400 | case TextureStage::STAGE_MODULATE4X: |
| 1401 | case TextureStage::STAGE_ADD: |
| 1402 | case TextureStage::STAGE_MULTIPLYADD: |
| 1403 | case TextureStage::STAGE_LERP: |
| 1404 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1405 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1406 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1407 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1408 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1409 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1410 | case TextureStage::STAGE_PREMODULATE: |
| 1411 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1412 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1413 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1414 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1415 | case TextureStage::STAGE_BUMPENVMAP: |
| 1416 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1417 | if(state.textureStage[stage].cantUnderflow) |
| 1418 | { |
| 1419 | break; // Can't go below zero |
| 1420 | } |
| 1421 | case TextureStage::STAGE_ADDSIGNED: |
| 1422 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1423 | case TextureStage::STAGE_SUBTRACT: |
| 1424 | case TextureStage::STAGE_ADDSMOOTH: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1425 | res.x = Max(res.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1426 | res.y = Max(res.y, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1427 | res.z = Max(res.z, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1428 | break; |
| 1429 | default: |
| 1430 | ASSERT(false); |
| 1431 | } |
| 1432 | |
| 1433 | switch(textureStage.stageOperationAlpha) |
| 1434 | { |
| 1435 | case TextureStage::STAGE_DISABLE: |
| 1436 | case TextureStage::STAGE_SELECTARG1: |
| 1437 | case TextureStage::STAGE_SELECTARG2: |
| 1438 | case TextureStage::STAGE_SELECTARG3: |
| 1439 | case TextureStage::STAGE_MODULATE: |
| 1440 | case TextureStage::STAGE_MODULATE2X: |
| 1441 | case TextureStage::STAGE_MODULATE4X: |
| 1442 | case TextureStage::STAGE_ADD: |
| 1443 | case TextureStage::STAGE_MULTIPLYADD: |
| 1444 | case TextureStage::STAGE_LERP: |
| 1445 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1446 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1447 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1448 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1449 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1450 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1451 | case TextureStage::STAGE_PREMODULATE: |
| 1452 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1453 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1454 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1455 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1456 | case TextureStage::STAGE_BUMPENVMAP: |
| 1457 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1458 | if(state.textureStage[stage].cantUnderflow) |
| 1459 | { |
| 1460 | break; // Can't go below zero |
| 1461 | } |
| 1462 | case TextureStage::STAGE_ADDSIGNED: |
| 1463 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1464 | case TextureStage::STAGE_SUBTRACT: |
| 1465 | case TextureStage::STAGE_ADDSMOOTH: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1466 | res.w = Max(res.w, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1467 | break; |
| 1468 | default: |
| 1469 | ASSERT(false); |
| 1470 | } |
| 1471 | |
| 1472 | switch(textureStage.stageOperation) |
| 1473 | { |
| 1474 | case TextureStage::STAGE_DISABLE: |
| 1475 | case TextureStage::STAGE_SELECTARG1: |
| 1476 | case TextureStage::STAGE_SELECTARG2: |
| 1477 | case TextureStage::STAGE_SELECTARG3: |
| 1478 | case TextureStage::STAGE_MODULATE: |
| 1479 | case TextureStage::STAGE_SUBTRACT: |
| 1480 | case TextureStage::STAGE_ADDSMOOTH: |
| 1481 | case TextureStage::STAGE_LERP: |
| 1482 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1483 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1484 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1485 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1486 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1487 | case TextureStage::STAGE_PREMODULATE: |
| 1488 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1489 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1490 | case TextureStage::STAGE_BUMPENVMAP: |
| 1491 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1492 | break; // Can't go above one |
| 1493 | case TextureStage::STAGE_MODULATE2X: |
| 1494 | case TextureStage::STAGE_MODULATE4X: |
| 1495 | case TextureStage::STAGE_ADD: |
| 1496 | case TextureStage::STAGE_ADDSIGNED: |
| 1497 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1498 | case TextureStage::STAGE_MULTIPLYADD: |
| 1499 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1500 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1501 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1502 | res.x = Min(res.x, Short4(0x1000)); |
| 1503 | res.y = Min(res.y, Short4(0x1000)); |
| 1504 | res.z = Min(res.z, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1505 | break; |
| 1506 | default: |
| 1507 | ASSERT(false); |
| 1508 | } |
| 1509 | |
| 1510 | switch(textureStage.stageOperationAlpha) |
| 1511 | { |
| 1512 | case TextureStage::STAGE_DISABLE: |
| 1513 | case TextureStage::STAGE_SELECTARG1: |
| 1514 | case TextureStage::STAGE_SELECTARG2: |
| 1515 | case TextureStage::STAGE_SELECTARG3: |
| 1516 | case TextureStage::STAGE_MODULATE: |
| 1517 | case TextureStage::STAGE_SUBTRACT: |
| 1518 | case TextureStage::STAGE_ADDSMOOTH: |
| 1519 | case TextureStage::STAGE_LERP: |
| 1520 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1521 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1522 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1523 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1524 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1525 | case TextureStage::STAGE_PREMODULATE: |
| 1526 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1527 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1528 | case TextureStage::STAGE_BUMPENVMAP: |
| 1529 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1530 | break; // Can't go above one |
| 1531 | case TextureStage::STAGE_MODULATE2X: |
| 1532 | case TextureStage::STAGE_MODULATE4X: |
| 1533 | case TextureStage::STAGE_ADD: |
| 1534 | case TextureStage::STAGE_ADDSIGNED: |
| 1535 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1536 | case TextureStage::STAGE_MULTIPLYADD: |
| 1537 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1538 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1539 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1540 | res.w = Min(res.w, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1541 | break; |
| 1542 | default: |
| 1543 | ASSERT(false); |
| 1544 | } |
| 1545 | |
| 1546 | switch(textureStage.destinationArgument) |
| 1547 | { |
| 1548 | case TextureStage::DESTINATION_CURRENT: |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1549 | r.current.x = res.x; |
| 1550 | r.current.y = res.y; |
| 1551 | r.current.z = res.z; |
| 1552 | r.current.w = res.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1553 | break; |
| 1554 | case TextureStage::DESTINATION_TEMP: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1555 | temp.x = res.x; |
| 1556 | temp.y = res.y; |
| 1557 | temp.z = res.z; |
| 1558 | temp.w = res.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1559 | break; |
| 1560 | default: |
| 1561 | ASSERT(false); |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | void PixelRoutine::alphaTest(Registers &r, Int &aMask, Short4 &alpha) |
| 1566 | { |
| 1567 | Short4 cmp; |
| 1568 | Short4 equal; |
| 1569 | |
| 1570 | switch(state.alphaCompareMode) |
| 1571 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1572 | case ALPHA_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1573 | aMask = 0xF; |
| 1574 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1575 | case ALPHA_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1576 | aMask = 0x0; |
| 1577 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1578 | case ALPHA_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1579 | cmp = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1580 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1581 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1582 | case ALPHA_NOTEQUAL: // a != b ~ !(a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1583 | cmp = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))) ^ Short4((short)0xFFFF, (short)0xFFFF, (short)0xFFFF, (short)0xFFFF); // FIXME |
| 1584 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1585 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1586 | case ALPHA_LESS: // a < b ~ b > a |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1587 | cmp = CmpGT(*Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4)), alpha); |
| 1588 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1589 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1590 | case ALPHA_GREATEREQUAL: // a >= b ~ (a > b) || (a == b) ~ !(b > a) // TODO: Approximate |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1591 | equal = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1592 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1593 | cmp |= equal; |
| 1594 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1595 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1596 | case ALPHA_LESSEQUAL: // a <= b ~ !(a > b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1597 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))) ^ Short4((short)0xFFFF, (short)0xFFFF, (short)0xFFFF, (short)0xFFFF); // FIXME |
| 1598 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1599 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1600 | case ALPHA_GREATER: // a > b |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1601 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1602 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1603 | break; |
| 1604 | default: |
| 1605 | ASSERT(false); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | void PixelRoutine::alphaToCoverage(Registers &r, Int cMask[4], Float4 &alpha) |
| 1610 | { |
| 1611 | Int4 coverage0 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c0))); |
| 1612 | Int4 coverage1 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c1))); |
| 1613 | Int4 coverage2 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c2))); |
| 1614 | Int4 coverage3 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c3))); |
| 1615 | |
| 1616 | Int aMask0 = SignMask(coverage0); |
| 1617 | Int aMask1 = SignMask(coverage1); |
| 1618 | Int aMask2 = SignMask(coverage2); |
| 1619 | Int aMask3 = SignMask(coverage3); |
| 1620 | |
| 1621 | cMask[0] &= aMask0; |
| 1622 | cMask[1] &= aMask1; |
| 1623 | cMask[2] &= aMask2; |
| 1624 | cMask[3] &= aMask3; |
| 1625 | } |
| 1626 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 1627 | Bool PixelRoutine::alphaTest(Registers &r, Int cMask[4], Vector4s ¤t) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1628 | { |
| 1629 | if(!state.alphaTestActive()) |
| 1630 | { |
| 1631 | return true; |
| 1632 | } |
| 1633 | |
| 1634 | Int aMask; |
| 1635 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1636 | if(state.transparencyAntialiasing == TRANSPARENCY_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1637 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1638 | alphaTest(r, aMask, current.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1639 | |
| 1640 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 1641 | { |
| 1642 | cMask[q] &= aMask; |
| 1643 | } |
| 1644 | } |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1645 | else if(state.transparencyAntialiasing == TRANSPARENCY_ALPHA_TO_COVERAGE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1646 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1647 | Float4 alpha = Float4(current.w) * Float4(1.0f / 0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1648 | |
| 1649 | alphaToCoverage(r, cMask, alpha); |
| 1650 | } |
| 1651 | else ASSERT(false); |
| 1652 | |
| 1653 | Int pass = cMask[0]; |
| 1654 | |
| 1655 | for(unsigned int q = 1; q < state.multiSample; q++) |
| 1656 | { |
| 1657 | pass = pass | cMask[q]; |
| 1658 | } |
| 1659 | |
| 1660 | return pass != 0x0; |
| 1661 | } |
| 1662 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1663 | Bool PixelRoutine::alphaTest(Registers &r, Int cMask[4], Vector4f &c0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1664 | { |
| 1665 | if(!state.alphaTestActive()) |
| 1666 | { |
| 1667 | return true; |
| 1668 | } |
| 1669 | |
| 1670 | Int aMask; |
| 1671 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1672 | if(state.transparencyAntialiasing == TRANSPARENCY_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1673 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1674 | Short4 alpha = RoundShort4(c0.w * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1675 | |
| 1676 | alphaTest(r, aMask, alpha); |
| 1677 | |
| 1678 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 1679 | { |
| 1680 | cMask[q] &= aMask; |
| 1681 | } |
| 1682 | } |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1683 | else if(state.transparencyAntialiasing == TRANSPARENCY_ALPHA_TO_COVERAGE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1684 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1685 | alphaToCoverage(r, cMask, c0.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1686 | } |
| 1687 | else ASSERT(false); |
| 1688 | |
| 1689 | Int pass = cMask[0]; |
| 1690 | |
| 1691 | for(unsigned int q = 1; q < state.multiSample; q++) |
| 1692 | { |
| 1693 | pass = pass | cMask[q]; |
| 1694 | } |
| 1695 | |
| 1696 | return pass != 0x0; |
| 1697 | } |
| 1698 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 1699 | void PixelRoutine::fogBlend(Registers &r, Vector4s ¤t, Float4 &f, Float4 &z, Float4 &rhw) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1700 | { |
| 1701 | if(!state.fogActive) |
| 1702 | { |
| 1703 | return; |
| 1704 | } |
| 1705 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1706 | if(state.pixelFogMode != FOG_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1707 | { |
| 1708 | pixelFog(r, f, z, rhw); |
| 1709 | } |
| 1710 | |
| 1711 | UShort4 fog = convertFixed16(f, true); |
| 1712 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1713 | current.x = As<Short4>(MulHigh(As<UShort4>(current.x), fog)); |
| 1714 | current.y = As<Short4>(MulHigh(As<UShort4>(current.y), fog)); |
| 1715 | current.z = As<Short4>(MulHigh(As<UShort4>(current.z), fog)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1716 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1717 | UShort4 invFog = UShort4(0xFFFFu) - fog; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1718 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1719 | current.x += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData,fog.color4[0])))); |
| 1720 | current.y += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData,fog.color4[1])))); |
| 1721 | current.z += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData,fog.color4[2])))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1724 | void PixelRoutine::fogBlend(Registers &r, Vector4f &c0, Float4 &fog, Float4 &z, Float4 &rhw) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1725 | { |
| 1726 | if(!state.fogActive) |
| 1727 | { |
| 1728 | return; |
| 1729 | } |
| 1730 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1731 | if(state.pixelFogMode != FOG_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1732 | { |
| 1733 | pixelFog(r, fog, z, rhw); |
| 1734 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1735 | fog = Min(fog, Float4(1.0f)); |
| 1736 | fog = Max(fog, Float4(0.0f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1737 | } |
| 1738 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1739 | c0.x -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[0])); |
| 1740 | c0.y -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[1])); |
| 1741 | c0.z -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1742 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1743 | c0.x *= fog; |
| 1744 | c0.y *= fog; |
| 1745 | c0.z *= fog; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1746 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1747 | c0.x += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[0])); |
| 1748 | c0.y += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[1])); |
| 1749 | c0.z += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | void PixelRoutine::pixelFog(Registers &r, Float4 &visibility, Float4 &z, Float4 &rhw) |
| 1753 | { |
| 1754 | Float4 &zw = visibility; |
| 1755 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1756 | if(state.pixelFogMode != FOG_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1757 | { |
| 1758 | if(state.wBasedFog) |
| 1759 | { |
| 1760 | zw = rhw; |
| 1761 | } |
| 1762 | else |
| 1763 | { |
| 1764 | if(complementaryDepthBuffer) |
| 1765 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1766 | zw = Float4(1.0f) - z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1767 | } |
| 1768 | else |
| 1769 | { |
| 1770 | zw = z; |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | switch(state.pixelFogMode) |
| 1776 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1777 | case FOG_NONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1778 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1779 | case FOG_LINEAR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1780 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.scale)); |
| 1781 | zw += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.offset)); |
| 1782 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1783 | case FOG_EXP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1784 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.densityE)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1785 | zw = exponential2(zw, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1786 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1787 | case FOG_EXP2: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1788 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.densityE2)); |
| 1789 | zw *= zw; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1790 | zw = exponential2(zw, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1791 | zw = Rcp_pp(zw); |
| 1792 | break; |
| 1793 | default: |
| 1794 | ASSERT(false); |
| 1795 | } |
| 1796 | } |
| 1797 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 1798 | void PixelRoutine::specularPixel(Vector4s ¤t, Vector4s &specular) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1799 | { |
| 1800 | if(!state.specularAdd) |
| 1801 | { |
| 1802 | return; |
| 1803 | } |
| 1804 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1805 | current.x = AddSat(current.x, specular.x); |
| 1806 | current.y = AddSat(current.y, specular.y); |
| 1807 | current.z = AddSat(current.z, specular.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | void PixelRoutine::writeDepth(Registers &r, Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask) |
| 1811 | { |
| 1812 | if(!state.depthWriteEnable) |
| 1813 | { |
| 1814 | return; |
| 1815 | } |
| 1816 | |
| 1817 | Float4 Z = z; |
| 1818 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1819 | if(shader && shader->depthOverride()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1820 | { |
| 1821 | if(complementaryDepthBuffer) |
| 1822 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1823 | Z = Float4(1.0f) - r.oDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1824 | } |
| 1825 | else |
| 1826 | { |
| 1827 | Z = r.oDepth; |
| 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | Pointer<Byte> buffer; |
| 1832 | Int pitch; |
| 1833 | |
| 1834 | if(!state.quadLayoutDepthBuffer) |
| 1835 | { |
| 1836 | buffer = zBuffer + 4 * x; |
| 1837 | pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); |
| 1838 | } |
| 1839 | else |
| 1840 | { |
| 1841 | buffer = zBuffer + 8 * x; |
| 1842 | } |
| 1843 | |
| 1844 | if(q > 0) |
| 1845 | { |
| 1846 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,depthSliceB)); |
| 1847 | } |
| 1848 | |
| 1849 | Float4 zValue; |
| 1850 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1851 | if(state.depthCompareMode != DEPTH_NEVER || (state.depthCompareMode != DEPTH_ALWAYS && !state.depthWriteEnable)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1852 | { |
| 1853 | if(!state.quadLayoutDepthBuffer) |
| 1854 | { |
| 1855 | // FIXME: Properly optimizes? |
| 1856 | zValue.xy = *Pointer<Float4>(buffer); |
| 1857 | zValue.zw = *Pointer<Float4>(buffer + pitch - 8); |
| 1858 | } |
| 1859 | else |
| 1860 | { |
| 1861 | zValue = *Pointer<Float4>(buffer, 16); |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | Z = As<Float4>(As<Int4>(Z) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X) + zMask * 16, 16)); |
| 1866 | zValue = As<Float4>(As<Int4>(zValue) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X) + zMask * 16, 16)); |
| 1867 | Z = As<Float4>(As<Int4>(Z) | As<Int4>(zValue)); |
| 1868 | |
| 1869 | if(!state.quadLayoutDepthBuffer) |
| 1870 | { |
| 1871 | // FIXME: Properly optimizes? |
| 1872 | *Pointer<Float2>(buffer) = Float2(Z.xy); |
| 1873 | *Pointer<Float2>(buffer + pitch) = Float2(Z.zw); |
| 1874 | } |
| 1875 | else |
| 1876 | { |
| 1877 | *Pointer<Float4>(buffer, 16) = Z; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | void PixelRoutine::writeStencil(Registers &r, Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &zMask, Int &cMask) |
| 1882 | { |
| 1883 | if(!state.stencilActive) |
| 1884 | { |
| 1885 | return; |
| 1886 | } |
| 1887 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1888 | if(state.stencilPassOperation == OPERATION_KEEP && state.stencilZFailOperation == OPERATION_KEEP && state.stencilFailOperation == OPERATION_KEEP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1889 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1890 | if(!state.twoSidedStencil || (state.stencilPassOperationCCW == OPERATION_KEEP && state.stencilZFailOperationCCW == OPERATION_KEEP && state.stencilFailOperationCCW == OPERATION_KEEP)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1891 | { |
| 1892 | return; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | if(state.stencilWriteMasked && (!state.twoSidedStencil || state.stencilWriteMaskedCCW)) |
| 1897 | { |
| 1898 | return; |
| 1899 | } |
| 1900 | |
| 1901 | Pointer<Byte> buffer = sBuffer + 2 * x; |
| 1902 | |
| 1903 | if(q > 0) |
| 1904 | { |
| 1905 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,stencilSliceB)); |
| 1906 | } |
| 1907 | |
| 1908 | Byte8 bufferValue = As<Byte8>(Long1(*Pointer<UInt>(buffer))); |
| 1909 | |
| 1910 | Byte8 newValue; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1911 | stencilOperation(r, newValue, bufferValue, state.stencilPassOperation, state.stencilZFailOperation, state.stencilFailOperation, false, zMask, sMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1912 | |
| 1913 | if(!state.noStencilWriteMask) |
| 1914 | { |
| 1915 | Byte8 maskedValue = bufferValue; |
| 1916 | newValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].writeMaskQ)); |
| 1917 | maskedValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].invWriteMaskQ)); |
| 1918 | newValue |= maskedValue; |
| 1919 | } |
| 1920 | |
| 1921 | if(state.twoSidedStencil) |
| 1922 | { |
| 1923 | Byte8 newValueCCW; |
| 1924 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1925 | stencilOperation(r, newValueCCW, bufferValue, state.stencilPassOperationCCW, state.stencilZFailOperationCCW, state.stencilFailOperationCCW, true, zMask, sMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1926 | |
| 1927 | if(!state.noStencilWriteMaskCCW) |
| 1928 | { |
| 1929 | Byte8 maskedValue = bufferValue; |
| 1930 | newValueCCW &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].writeMaskQ)); |
| 1931 | maskedValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].invWriteMaskQ)); |
| 1932 | newValueCCW |= maskedValue; |
| 1933 | } |
| 1934 | |
| 1935 | newValue &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,clockwiseMask)); |
| 1936 | newValueCCW &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,invClockwiseMask)); |
| 1937 | newValue |= newValueCCW; |
| 1938 | } |
| 1939 | |
| 1940 | newValue &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * cMask); |
| 1941 | bufferValue &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * cMask); |
| 1942 | newValue |= bufferValue; |
| 1943 | |
| 1944 | *Pointer<UInt>(buffer) = UInt(As<Long>(newValue)); |
| 1945 | } |
| 1946 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1947 | void PixelRoutine::stencilOperation(Registers &r, Byte8 &newValue, Byte8 &bufferValue, StencilOperation stencilPassOperation, StencilOperation stencilZFailOperation, StencilOperation stencilFailOperation, bool CCW, Int &zMask, Int &sMask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1948 | { |
| 1949 | Byte8 &pass = newValue; |
| 1950 | Byte8 fail; |
| 1951 | Byte8 zFail; |
| 1952 | |
| 1953 | stencilOperation(r, pass, bufferValue, stencilPassOperation, CCW); |
| 1954 | |
| 1955 | if(stencilZFailOperation != stencilPassOperation) |
| 1956 | { |
| 1957 | stencilOperation(r, zFail, bufferValue, stencilZFailOperation, CCW); |
| 1958 | } |
| 1959 | |
| 1960 | if(stencilFailOperation != stencilPassOperation || stencilFailOperation != stencilZFailOperation) |
| 1961 | { |
| 1962 | stencilOperation(r, fail, bufferValue, stencilFailOperation, CCW); |
| 1963 | } |
| 1964 | |
| 1965 | if(stencilFailOperation != stencilPassOperation || stencilFailOperation != stencilZFailOperation) |
| 1966 | { |
| 1967 | if(state.depthTestActive && stencilZFailOperation != stencilPassOperation) // zMask valid and values not the same |
| 1968 | { |
| 1969 | pass &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * zMask); |
| 1970 | zFail &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * zMask); |
| 1971 | pass |= zFail; |
| 1972 | } |
| 1973 | |
| 1974 | pass &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * sMask); |
| 1975 | fail &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * sMask); |
| 1976 | pass |= fail; |
| 1977 | } |
| 1978 | } |
| 1979 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1980 | void PixelRoutine::stencilOperation(Registers &r, Byte8 &output, Byte8 &bufferValue, StencilOperation operation, bool CCW) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1981 | { |
| 1982 | switch(operation) |
| 1983 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1984 | case OPERATION_KEEP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1985 | output = bufferValue; |
| 1986 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1987 | case OPERATION_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1988 | output = Byte8(0x0000000000000000); |
| 1989 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1990 | case OPERATION_REPLACE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1991 | output = *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceQ)); |
| 1992 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1993 | case OPERATION_INCRSAT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1994 | output = AddSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1)); |
| 1995 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1996 | case OPERATION_DECRSAT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1997 | output = SubSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1)); |
| 1998 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1999 | case OPERATION_INVERT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2000 | output = bufferValue ^ Byte8(0xFFFFFFFFFFFFFFFF); |
| 2001 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2002 | case OPERATION_INCR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2003 | output = bufferValue + Byte8(1, 1, 1, 1, 1, 1, 1, 1); |
| 2004 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2005 | case OPERATION_DECR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2006 | output = bufferValue - Byte8(1, 1, 1, 1, 1, 1, 1, 1); |
| 2007 | break; |
| 2008 | default: |
| 2009 | ASSERT(false); |
| 2010 | } |
| 2011 | } |
| 2012 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2013 | void PixelRoutine::sampleTexture(Registers &r, Vector4s &c, int coordinates, int stage, bool project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2014 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2015 | Float4 u = r.vf[2 + coordinates].x; |
| 2016 | Float4 v = r.vf[2 + coordinates].y; |
| 2017 | Float4 w = r.vf[2 + coordinates].z; |
| 2018 | Float4 q = r.vf[2 + coordinates].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2019 | |
| 2020 | if(perturbate) |
| 2021 | { |
| 2022 | u += r.du; |
| 2023 | v += r.dv; |
| 2024 | |
| 2025 | perturbate = false; |
| 2026 | } |
| 2027 | |
| 2028 | sampleTexture(r, c, stage, u, v, w, q, project); |
| 2029 | } |
| 2030 | |
Nicolas Capens | cfd0e6c | 2015-05-12 15:40:20 -0400 | [diff] [blame] | 2031 | void PixelRoutine::sampleTexture(Registers &r, Vector4s &c, int stage, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project, bool bias) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2032 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2033 | Vector4f dsx; |
| 2034 | Vector4f dsy; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2035 | |
Nicolas Capens | cfd0e6c | 2015-05-12 15:40:20 -0400 | [diff] [blame] | 2036 | sampleTexture(r, c, stage, u, v, w, q, dsx, dsy, project, bias, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2037 | } |
| 2038 | |
Nicolas Capens | cfd0e6c | 2015-05-12 15:40:20 -0400 | [diff] [blame] | 2039 | void PixelRoutine::sampleTexture(Registers &r, Vector4s &c, int stage, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, bool project, bool bias, bool gradients, bool lodProvided) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2040 | { |
| 2041 | #if PERF_PROFILE |
| 2042 | Long texTime = Ticks(); |
| 2043 | #endif |
| 2044 | |
| 2045 | Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap) + stage * sizeof(Texture); |
| 2046 | |
| 2047 | if(!project) |
| 2048 | { |
Nicolas Capens | cfd0e6c | 2015-05-12 15:40:20 -0400 | [diff] [blame] | 2049 | sampler[stage]->sampleTexture(texture, c, u, v, w, q, dsx, dsy, bias, gradients, lodProvided); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2050 | } |
| 2051 | else |
| 2052 | { |
| 2053 | Float4 rq = reciprocal(q); |
| 2054 | |
| 2055 | Float4 u_q = u * rq; |
| 2056 | Float4 v_q = v * rq; |
| 2057 | Float4 w_q = w * rq; |
| 2058 | |
Nicolas Capens | cfd0e6c | 2015-05-12 15:40:20 -0400 | [diff] [blame] | 2059 | sampler[stage]->sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy, bias, gradients, lodProvided); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | #if PERF_PROFILE |
| 2063 | r.cycles[PERF_TEX] += Ticks() - texTime; |
| 2064 | #endif |
| 2065 | } |
| 2066 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2067 | void PixelRoutine::sampleTexture(Registers &r, Vector4f &c, const Src &sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, bool project, bool bias, bool gradients, bool lodProvided) |
| 2068 | { |
| 2069 | if(sampler.type == Shader::PARAMETER_SAMPLER && sampler.rel.type == Shader::PARAMETER_VOID) |
| 2070 | { |
| 2071 | sampleTexture(r, c, sampler.index, u, v, w, q, dsx, dsy, project, bias, gradients, lodProvided); |
| 2072 | } |
| 2073 | else |
| 2074 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2075 | Int index = As<Int>(Float(fetchRegisterF(r, sampler).x.x)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2076 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 2077 | for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2078 | { |
| 2079 | if(shader->usesSampler(i)) |
| 2080 | { |
| 2081 | If(index == i) |
| 2082 | { |
| 2083 | sampleTexture(r, c, i, u, v, w, q, dsx, dsy, project, bias, gradients, lodProvided); |
| 2084 | // FIXME: When the sampler states are the same, we could use one sampler and just index the texture |
| 2085 | } |
| 2086 | } |
| 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | void PixelRoutine::sampleTexture(Registers &r, Vector4f &c, int stage, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, bool project, bool bias, bool gradients, bool lodProvided) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2092 | { |
| 2093 | #if PERF_PROFILE |
| 2094 | Long texTime = Ticks(); |
| 2095 | #endif |
| 2096 | |
| 2097 | Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap) + stage * sizeof(Texture); |
| 2098 | |
| 2099 | if(!project) |
| 2100 | { |
| 2101 | sampler[stage]->sampleTexture(texture, c, u, v, w, q, dsx, dsy, bias, gradients, lodProvided); |
| 2102 | } |
| 2103 | else |
| 2104 | { |
| 2105 | Float4 rq = reciprocal(q); |
| 2106 | |
| 2107 | Float4 u_q = u * rq; |
| 2108 | Float4 v_q = v * rq; |
| 2109 | Float4 w_q = w * rq; |
| 2110 | |
| 2111 | sampler[stage]->sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy, bias, gradients, lodProvided); |
| 2112 | } |
| 2113 | |
| 2114 | #if PERF_PROFILE |
| 2115 | r.cycles[PERF_TEX] += Ticks() - texTime; |
| 2116 | #endif |
| 2117 | } |
| 2118 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2119 | void PixelRoutine::clampColor(Vector4f oC[4]) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2120 | { |
| 2121 | for(int index = 0; index < 4; index++) |
| 2122 | { |
| 2123 | if(!state.colorWriteActive(index) && !(index == 0 && state.alphaTestActive())) |
| 2124 | { |
| 2125 | continue; |
| 2126 | } |
| 2127 | |
| 2128 | switch(state.targetFormat[index]) |
| 2129 | { |
| 2130 | case FORMAT_NULL: |
| 2131 | break; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2132 | case FORMAT_R5G6B5: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2133 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2134 | case FORMAT_A8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2135 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2136 | case FORMAT_X8B8G8R8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2137 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2138 | case FORMAT_G16R16: |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2139 | case FORMAT_A16B16G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2140 | oC[index].x = Max(oC[index].x, Float4(0.0f)); oC[index].x = Min(oC[index].x, Float4(1.0f)); |
| 2141 | oC[index].y = Max(oC[index].y, Float4(0.0f)); oC[index].y = Min(oC[index].y, Float4(1.0f)); |
| 2142 | oC[index].z = Max(oC[index].z, Float4(0.0f)); oC[index].z = Min(oC[index].z, Float4(1.0f)); |
| 2143 | oC[index].w = Max(oC[index].w, Float4(0.0f)); oC[index].w = Min(oC[index].w, Float4(1.0f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2144 | break; |
| 2145 | case FORMAT_R32F: |
| 2146 | case FORMAT_G32R32F: |
| 2147 | case FORMAT_A32B32G32R32F: |
| 2148 | break; |
| 2149 | default: |
| 2150 | ASSERT(false); |
| 2151 | } |
| 2152 | } |
| 2153 | } |
| 2154 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2155 | void PixelRoutine::rasterOperation(Vector4s ¤t, Registers &r, Float4 &fog, Pointer<Byte> &cBuffer, Int &x, Int sMask[4], Int zMask[4], Int cMask[4]) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2156 | { |
| 2157 | if(!state.colorWriteActive(0)) |
| 2158 | { |
| 2159 | return; |
| 2160 | } |
| 2161 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2162 | Vector4f oC; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2163 | |
| 2164 | switch(state.targetFormat[0]) |
| 2165 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2166 | case FORMAT_R5G6B5: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2167 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2168 | case FORMAT_X8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2169 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2170 | case FORMAT_A8B8G8R8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2171 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2172 | case FORMAT_G16R16: |
| 2173 | case FORMAT_A16B16G16R16: |
| 2174 | if(!postBlendSRGB && state.writeSRGB) |
| 2175 | { |
| 2176 | linearToSRGB12_16(r, current); |
| 2177 | } |
| 2178 | else |
| 2179 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2180 | current.x <<= 4; |
| 2181 | current.y <<= 4; |
| 2182 | current.z <<= 4; |
| 2183 | current.w <<= 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2184 | } |
| 2185 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2186 | if(state.targetFormat[0] == FORMAT_R5G6B5) |
| 2187 | { |
| 2188 | current.x &= Short4(0xF800u); |
| 2189 | current.y &= Short4(0xFC00u); |
| 2190 | current.z &= Short4(0xF800u); |
| 2191 | } |
| 2192 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2193 | fogBlend(r, current, fog, r.z[0], r.rhw); |
| 2194 | |
| 2195 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2196 | { |
| 2197 | Pointer<Byte> buffer = cBuffer + q * *Pointer<Int>(r.data + OFFSET(DrawData,colorSliceB[0])); |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2198 | Vector4s color = current; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2199 | |
| 2200 | if(state.multiSampleMask & (1 << q)) |
| 2201 | { |
| 2202 | alphaBlend(r, 0, buffer, color, x); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2203 | logicOperation(r, 0, buffer, color, x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2204 | writeColor(r, 0, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2205 | } |
| 2206 | } |
| 2207 | break; |
| 2208 | case FORMAT_R32F: |
| 2209 | case FORMAT_G32R32F: |
| 2210 | case FORMAT_A32B32G32R32F: |
| 2211 | convertSigned12(oC, current); |
| 2212 | fogBlend(r, oC, fog, r.z[0], r.rhw); |
| 2213 | |
| 2214 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2215 | { |
| 2216 | Pointer<Byte> buffer = cBuffer + q * *Pointer<Int>(r.data + OFFSET(DrawData,colorSliceB[0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2217 | Vector4f color = oC; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2218 | |
| 2219 | if(state.multiSampleMask & (1 << q)) |
| 2220 | { |
| 2221 | alphaBlend(r, 0, buffer, color, x); |
| 2222 | writeColor(r, 0, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2223 | } |
| 2224 | } |
| 2225 | break; |
| 2226 | default: |
| 2227 | ASSERT(false); |
| 2228 | } |
| 2229 | } |
| 2230 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2231 | void PixelRoutine::rasterOperation(Vector4f oC[4], Registers &r, Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2232 | { |
| 2233 | for(int index = 0; index < 4; index++) |
| 2234 | { |
| 2235 | if(!state.colorWriteActive(index)) |
| 2236 | { |
| 2237 | continue; |
| 2238 | } |
| 2239 | |
| 2240 | if(!postBlendSRGB && state.writeSRGB) |
| 2241 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2242 | oC[index].x = linearToSRGB(oC[index].x); |
| 2243 | oC[index].y = linearToSRGB(oC[index].y); |
| 2244 | oC[index].z = linearToSRGB(oC[index].z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | if(index == 0) |
| 2248 | { |
| 2249 | fogBlend(r, oC[index], fog, r.z[0], r.rhw); |
| 2250 | } |
| 2251 | |
| 2252 | switch(state.targetFormat[index]) |
| 2253 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2254 | case FORMAT_R5G6B5: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2255 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2256 | case FORMAT_X8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2257 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2258 | case FORMAT_A8B8G8R8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2259 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2260 | case FORMAT_G16R16: |
| 2261 | case FORMAT_A16B16G16R16: |
| 2262 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2263 | { |
| 2264 | Pointer<Byte> buffer = cBuffer[index] + q * *Pointer<Int>(r.data + OFFSET(DrawData,colorSliceB[index])); |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2265 | Vector4s color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2266 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2267 | color.x = convertFixed16(oC[index].x, false); |
| 2268 | color.y = convertFixed16(oC[index].y, false); |
| 2269 | color.z = convertFixed16(oC[index].z, false); |
| 2270 | color.w = convertFixed16(oC[index].w, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2271 | |
| 2272 | if(state.multiSampleMask & (1 << q)) |
| 2273 | { |
| 2274 | alphaBlend(r, index, buffer, color, x); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2275 | logicOperation(r, index, buffer, color, x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2276 | writeColor(r, index, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2277 | } |
| 2278 | } |
| 2279 | break; |
| 2280 | case FORMAT_R32F: |
| 2281 | case FORMAT_G32R32F: |
| 2282 | case FORMAT_A32B32G32R32F: |
| 2283 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2284 | { |
| 2285 | Pointer<Byte> buffer = cBuffer[index] + q * *Pointer<Int>(r.data + OFFSET(DrawData,colorSliceB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2286 | Vector4f color = oC[index]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2287 | |
| 2288 | if(state.multiSampleMask & (1 << q)) |
| 2289 | { |
| 2290 | alphaBlend(r, index, buffer, color, x); |
| 2291 | writeColor(r, index, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2292 | } |
| 2293 | } |
| 2294 | break; |
| 2295 | default: |
| 2296 | ASSERT(false); |
| 2297 | } |
| 2298 | } |
| 2299 | } |
| 2300 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2301 | void PixelRoutine::blendFactor(Registers &r, const Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, BlendFactor blendFactorActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2302 | { |
| 2303 | switch(blendFactorActive) |
| 2304 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2305 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2306 | // Optimized |
| 2307 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2308 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2309 | // Optimized |
| 2310 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2311 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2312 | blendFactor.x = current.x; |
| 2313 | blendFactor.y = current.y; |
| 2314 | blendFactor.z = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2315 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2316 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2317 | blendFactor.x = Short4(0xFFFFu) - current.x; |
| 2318 | blendFactor.y = Short4(0xFFFFu) - current.y; |
| 2319 | blendFactor.z = Short4(0xFFFFu) - current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2320 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2321 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2322 | blendFactor.x = pixel.x; |
| 2323 | blendFactor.y = pixel.y; |
| 2324 | blendFactor.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2325 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2326 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2327 | blendFactor.x = Short4(0xFFFFu) - pixel.x; |
| 2328 | blendFactor.y = Short4(0xFFFFu) - pixel.y; |
| 2329 | blendFactor.z = Short4(0xFFFFu) - pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2330 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2331 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2332 | blendFactor.x = current.w; |
| 2333 | blendFactor.y = current.w; |
| 2334 | blendFactor.z = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2335 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2336 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2337 | blendFactor.x = Short4(0xFFFFu) - current.w; |
| 2338 | blendFactor.y = Short4(0xFFFFu) - current.w; |
| 2339 | blendFactor.z = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2340 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2341 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2342 | blendFactor.x = pixel.w; |
| 2343 | blendFactor.y = pixel.w; |
| 2344 | blendFactor.z = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2345 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2346 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2347 | blendFactor.x = Short4(0xFFFFu) - pixel.w; |
| 2348 | blendFactor.y = Short4(0xFFFFu) - pixel.w; |
| 2349 | blendFactor.z = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2350 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2351 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2352 | blendFactor.x = Short4(0xFFFFu) - pixel.w; |
| 2353 | blendFactor.x = Min(As<UShort4>(blendFactor.x), As<UShort4>(current.w)); |
| 2354 | blendFactor.y = blendFactor.x; |
| 2355 | blendFactor.z = blendFactor.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2356 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2357 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2358 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[0])); |
| 2359 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[1])); |
| 2360 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2361 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2362 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2363 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[0])); |
| 2364 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[1])); |
| 2365 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2366 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2367 | case BLEND_CONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2368 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
| 2369 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
| 2370 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2371 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2372 | case BLEND_INVCONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2373 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
| 2374 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
| 2375 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2376 | break; |
| 2377 | default: |
| 2378 | ASSERT(false); |
| 2379 | } |
| 2380 | } |
| 2381 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2382 | void PixelRoutine::blendFactorAlpha(Registers &r, const Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, BlendFactor blendFactorAlphaActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2383 | { |
| 2384 | switch(blendFactorAlphaActive) |
| 2385 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2386 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2387 | // Optimized |
| 2388 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2389 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2390 | // Optimized |
| 2391 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2392 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2393 | blendFactor.w = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2394 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2395 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2396 | blendFactor.w = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2397 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2398 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2399 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2400 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2401 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2402 | blendFactor.w = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2403 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2404 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2405 | blendFactor.w = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2406 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2407 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2408 | blendFactor.w = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2409 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2410 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2411 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2412 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2413 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2414 | blendFactor.w = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2415 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2416 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2417 | blendFactor.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2418 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2419 | case BLEND_CONSTANT: |
| 2420 | case BLEND_CONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2421 | blendFactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2422 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2423 | case BLEND_INVCONSTANT: |
| 2424 | case BLEND_INVCONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2425 | blendFactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2426 | break; |
| 2427 | default: |
| 2428 | ASSERT(false); |
| 2429 | } |
| 2430 | } |
| 2431 | |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2432 | void PixelRoutine::readPixel(Registers &r, int index, Pointer<Byte> &cBuffer, Vector4s ¤t, Int &x, Vector4s &pixel) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2433 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2434 | Short4 c01; |
| 2435 | Short4 c23; |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2436 | Pointer<Byte> buffer; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2437 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2438 | switch(state.targetFormat[index]) |
| 2439 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2440 | case FORMAT_R5G6B5: |
| 2441 | buffer = cBuffer + 2 * x; |
| 2442 | c01 = As<Short4>(Insert(As<Int2>(c01), *Pointer<Int>(buffer), 0)); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2443 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2444 | c01 = As<Short4>(Insert(As<Int2>(c01), *Pointer<Int>(buffer), 1)); |
| 2445 | |
| 2446 | pixel.x = c01 & Short4(0xF800u); |
| 2447 | pixel.y = (c01 & Short4(0x07E0u)) << 5; |
| 2448 | pixel.z = (c01 & Short4(0x001Fu)) << 11; |
| 2449 | pixel.w = Short4(0xFFFFu); |
| 2450 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2451 | case FORMAT_A8R8G8B8: |
| 2452 | buffer = cBuffer + 4 * x; |
| 2453 | c01 = *Pointer<Short4>(buffer); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2454 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2455 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2456 | pixel.z = c01; |
| 2457 | pixel.y = c01; |
| 2458 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2459 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2460 | pixel.x = pixel.z; |
| 2461 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2462 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2463 | pixel.y = pixel.z; |
| 2464 | pixel.w = pixel.x; |
| 2465 | pixel.x = UnpackLow(As<Byte8>(pixel.x), As<Byte8>(pixel.x)); |
| 2466 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2467 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2468 | pixel.w = UnpackHigh(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2469 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2470 | case FORMAT_A8B8G8R8: |
| 2471 | buffer = cBuffer + 4 * x; |
| 2472 | c01 = *Pointer<Short4>(buffer); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2473 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2474 | c23 = *Pointer<Short4>(buffer); |
| 2475 | pixel.z = c01; |
| 2476 | pixel.y = c01; |
| 2477 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2478 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2479 | pixel.x = pixel.z; |
| 2480 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2481 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2482 | pixel.y = pixel.z; |
| 2483 | pixel.w = pixel.x; |
| 2484 | pixel.x = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2485 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2486 | pixel.z = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2487 | pixel.w = UnpackHigh(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2488 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2489 | case FORMAT_A8: |
| 2490 | buffer = cBuffer + 1 * x; |
| 2491 | pixel.w = Insert(pixel.w, *Pointer<Short>(buffer), 0); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2492 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2493 | pixel.w = Insert(pixel.w, *Pointer<Short>(buffer), 1); |
| 2494 | pixel.w = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2495 | pixel.x = Short4(0x0000); |
| 2496 | pixel.y = Short4(0x0000); |
| 2497 | pixel.z = Short4(0x0000); |
| 2498 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2499 | case FORMAT_X8R8G8B8: |
| 2500 | buffer = cBuffer + 4 * x; |
| 2501 | c01 = *Pointer<Short4>(buffer); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2502 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2503 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2504 | pixel.z = c01; |
| 2505 | pixel.y = c01; |
| 2506 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2507 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2508 | pixel.x = pixel.z; |
| 2509 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2510 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2511 | pixel.y = pixel.z; |
| 2512 | pixel.x = UnpackLow(As<Byte8>(pixel.x), As<Byte8>(pixel.x)); |
| 2513 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2514 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2515 | pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2516 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2517 | case FORMAT_X8B8G8R8: |
| 2518 | buffer = cBuffer + 4 * x; |
| 2519 | c01 = *Pointer<Short4>(buffer); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2520 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2521 | c23 = *Pointer<Short4>(buffer); |
| 2522 | pixel.z = c01; |
| 2523 | pixel.y = c01; |
| 2524 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2525 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2526 | pixel.x = pixel.z; |
| 2527 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2528 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2529 | pixel.y = pixel.z; |
| 2530 | pixel.w = pixel.x; |
| 2531 | pixel.x = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2532 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2533 | pixel.z = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2534 | pixel.w = Short4(0xFFFFu); |
| 2535 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2536 | case FORMAT_A8G8R8B8Q: |
| 2537 | UNIMPLEMENTED(); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2538 | // pixel.z = UnpackLow(As<Byte8>(pixel.z), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2539 | // pixel.x = UnpackHigh(As<Byte8>(pixel.x), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2540 | // pixel.y = UnpackLow(As<Byte8>(pixel.y), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
| 2541 | // pixel.w = UnpackHigh(As<Byte8>(pixel.w), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2542 | break; |
| 2543 | case FORMAT_X8G8R8B8Q: |
| 2544 | UNIMPLEMENTED(); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2545 | // pixel.z = UnpackLow(As<Byte8>(pixel.z), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2546 | // pixel.x = UnpackHigh(As<Byte8>(pixel.x), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2547 | // pixel.y = UnpackLow(As<Byte8>(pixel.y), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
| 2548 | // pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2549 | break; |
| 2550 | case FORMAT_A16B16G16R16: |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2551 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2552 | pixel.x = *Pointer<Short4>(buffer + 8 * x); |
| 2553 | pixel.y = *Pointer<Short4>(buffer + 8 * x + 8); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2554 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2555 | pixel.z = *Pointer<Short4>(buffer + 8 * x); |
| 2556 | pixel.w = *Pointer<Short4>(buffer + 8 * x + 8); |
| 2557 | transpose4x4(pixel.x, pixel.y, pixel.z, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2558 | break; |
| 2559 | case FORMAT_G16R16: |
| 2560 | buffer = cBuffer; |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2561 | pixel.x = *Pointer<Short4>(buffer + 4 * x); |
| 2562 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
| 2563 | pixel.y = *Pointer<Short4>(buffer + 4 * x); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2564 | pixel.z = pixel.x; |
| 2565 | pixel.x = As<Short4>(UnpackLow(pixel.x, pixel.y)); |
| 2566 | pixel.z = As<Short4>(UnpackHigh(pixel.z, pixel.y)); |
| 2567 | pixel.y = pixel.z; |
| 2568 | pixel.x = As<Short4>(UnpackLow(pixel.x, pixel.z)); |
| 2569 | pixel.y = As<Short4>(UnpackHigh(pixel.y, pixel.z)); |
| 2570 | pixel.z = Short4(0xFFFFu); |
| 2571 | pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2572 | break; |
| 2573 | default: |
| 2574 | ASSERT(false); |
| 2575 | } |
| 2576 | |
| 2577 | if(postBlendSRGB && state.writeSRGB) |
| 2578 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2579 | sRGBtoLinear16_12_16(r, pixel); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2580 | } |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2581 | } |
| 2582 | |
| 2583 | void PixelRoutine::alphaBlend(Registers &r, int index, Pointer<Byte> &cBuffer, Vector4s ¤t, Int &x) |
| 2584 | { |
| 2585 | if(!state.alphaBlendActive) |
| 2586 | { |
| 2587 | return; |
| 2588 | } |
| 2589 | |
| 2590 | Vector4s pixel; |
| 2591 | Short4 c01; |
| 2592 | Short4 c23; |
| 2593 | |
| 2594 | readPixel(r, index, cBuffer, current, x, pixel); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2595 | |
| 2596 | // Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2597 | Vector4s sourceFactor; |
| 2598 | Vector4s destFactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2599 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2600 | blendFactor(r, sourceFactor, current, pixel, state.sourceBlendFactor); |
| 2601 | blendFactor(r, destFactor, current, pixel, state.destBlendFactor); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2602 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2603 | if(state.sourceBlendFactor != BLEND_ONE && state.sourceBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2604 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2605 | current.x = MulHigh(As<UShort4>(current.x), As<UShort4>(sourceFactor.x)); |
| 2606 | current.y = MulHigh(As<UShort4>(current.y), As<UShort4>(sourceFactor.y)); |
| 2607 | current.z = MulHigh(As<UShort4>(current.z), As<UShort4>(sourceFactor.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2608 | } |
| 2609 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2610 | if(state.destBlendFactor != BLEND_ONE && state.destBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2611 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2612 | pixel.x = MulHigh(As<UShort4>(pixel.x), As<UShort4>(destFactor.x)); |
| 2613 | pixel.y = MulHigh(As<UShort4>(pixel.y), As<UShort4>(destFactor.y)); |
| 2614 | pixel.z = MulHigh(As<UShort4>(pixel.z), As<UShort4>(destFactor.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | switch(state.blendOperation) |
| 2618 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2619 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2620 | current.x = AddSat(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2621 | current.y = AddSat(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2622 | current.z = AddSat(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2623 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2624 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2625 | current.x = SubSat(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2626 | current.y = SubSat(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2627 | current.z = SubSat(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2628 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2629 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2630 | current.x = SubSat(As<UShort4>(pixel.x), As<UShort4>(current.x)); |
| 2631 | current.y = SubSat(As<UShort4>(pixel.y), As<UShort4>(current.y)); |
| 2632 | current.z = SubSat(As<UShort4>(pixel.z), As<UShort4>(current.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2633 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2634 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2635 | current.x = Min(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2636 | current.y = Min(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2637 | current.z = Min(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2638 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2639 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2640 | current.x = Max(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2641 | current.y = Max(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2642 | current.z = Max(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2643 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2644 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2645 | // No operation |
| 2646 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2647 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2648 | current.x = pixel.x; |
| 2649 | current.y = pixel.y; |
| 2650 | current.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2651 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2652 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2653 | current.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 2654 | current.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 2655 | current.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2656 | break; |
| 2657 | default: |
| 2658 | ASSERT(false); |
| 2659 | } |
| 2660 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2661 | blendFactorAlpha(r, sourceFactor, current, pixel, state.sourceBlendFactorAlpha); |
| 2662 | blendFactorAlpha(r, destFactor, current, pixel, state.destBlendFactorAlpha); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2663 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2664 | if(state.sourceBlendFactorAlpha != BLEND_ONE && state.sourceBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2665 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2666 | current.w = MulHigh(As<UShort4>(current.w), As<UShort4>(sourceFactor.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2667 | } |
| 2668 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2669 | if(state.destBlendFactorAlpha != BLEND_ONE && state.destBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2670 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2671 | pixel.w = MulHigh(As<UShort4>(pixel.w), As<UShort4>(destFactor.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | switch(state.blendOperationAlpha) |
| 2675 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2676 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2677 | current.w = AddSat(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2678 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2679 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2680 | current.w = SubSat(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2681 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2682 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2683 | current.w = SubSat(As<UShort4>(pixel.w), As<UShort4>(current.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2684 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2685 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2686 | current.w = Min(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2687 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2688 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2689 | current.w = Max(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2690 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2691 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2692 | // No operation |
| 2693 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2694 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2695 | current.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2696 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2697 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2698 | current.w = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2699 | break; |
| 2700 | default: |
| 2701 | ASSERT(false); |
| 2702 | } |
| 2703 | } |
| 2704 | |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame^] | 2705 | void PixelRoutine::logicOperation(Registers &r, int index, Pointer<Byte> &cBuffer, Vector4s ¤t, Int &x) |
| 2706 | { |
| 2707 | if(state.logicalOperation == LogicalOperation::LOGICALOP_COPY) |
| 2708 | { |
| 2709 | return; |
| 2710 | } |
| 2711 | |
| 2712 | Vector4s pixel; |
| 2713 | |
| 2714 | // Read pixel |
| 2715 | readPixel(r, index, cBuffer, current, x, pixel); |
| 2716 | |
| 2717 | switch(state.logicalOperation) |
| 2718 | { |
| 2719 | case LOGICALOP_CLEAR: |
| 2720 | current.x = 0; |
| 2721 | current.y = 0; |
| 2722 | current.z = 0; |
| 2723 | break; |
| 2724 | case LOGICALOP_SET: |
| 2725 | current.x = 0xFFFF; |
| 2726 | current.y = 0xFFFF; |
| 2727 | current.z = 0xFFFF; |
| 2728 | break; |
| 2729 | case LOGICALOP_COPY: |
| 2730 | ASSERT(false); // Optimized out |
| 2731 | break; |
| 2732 | case LOGICALOP_COPY_INVERTED: |
| 2733 | current.x = ~current.x; |
| 2734 | current.y = ~current.y; |
| 2735 | current.z = ~current.z; |
| 2736 | break; |
| 2737 | case LOGICALOP_NOOP: |
| 2738 | current.x = pixel.x; |
| 2739 | current.y = pixel.y; |
| 2740 | current.z = pixel.z; |
| 2741 | break; |
| 2742 | case LOGICALOP_INVERT: |
| 2743 | current.x = ~pixel.x; |
| 2744 | current.y = ~pixel.y; |
| 2745 | current.z = ~pixel.z; |
| 2746 | break; |
| 2747 | case LOGICALOP_AND: |
| 2748 | current.x = pixel.x & current.x; |
| 2749 | current.y = pixel.y & current.y; |
| 2750 | current.z = pixel.z & current.z; |
| 2751 | break; |
| 2752 | case LOGICALOP_NAND: |
| 2753 | current.x = ~(pixel.x & current.x); |
| 2754 | current.y = ~(pixel.y & current.y); |
| 2755 | current.z = ~(pixel.z & current.z); |
| 2756 | break; |
| 2757 | case LOGICALOP_OR: |
| 2758 | current.x = pixel.x | current.x; |
| 2759 | current.y = pixel.y | current.y; |
| 2760 | current.z = pixel.z | current.z; |
| 2761 | break; |
| 2762 | case LOGICALOP_NOR: |
| 2763 | current.x = ~(pixel.x | current.x); |
| 2764 | current.y = ~(pixel.y | current.y); |
| 2765 | current.z = ~(pixel.z | current.z); |
| 2766 | break; |
| 2767 | case LOGICALOP_XOR: |
| 2768 | current.x = pixel.x ^ current.x; |
| 2769 | current.y = pixel.y ^ current.y; |
| 2770 | current.z = pixel.z ^ current.z; |
| 2771 | break; |
| 2772 | case LOGICALOP_EQUIV: |
| 2773 | current.x = ~(pixel.x ^ current.x); |
| 2774 | current.y = ~(pixel.y ^ current.y); |
| 2775 | current.z = ~(pixel.z ^ current.z); |
| 2776 | break; |
| 2777 | case LOGICALOP_AND_REVERSE: |
| 2778 | current.x = ~pixel.x & current.x; |
| 2779 | current.y = ~pixel.y & current.y; |
| 2780 | current.z = ~pixel.z & current.z; |
| 2781 | break; |
| 2782 | case LOGICALOP_AND_INVERTED: |
| 2783 | current.x = pixel.x & ~current.x; |
| 2784 | current.y = pixel.y & ~current.y; |
| 2785 | current.z = pixel.z & ~current.z; |
| 2786 | break; |
| 2787 | case LOGICALOP_OR_REVERSE: |
| 2788 | current.x = ~pixel.x | current.x; |
| 2789 | current.y = ~pixel.y | current.y; |
| 2790 | current.z = ~pixel.z | current.z; |
| 2791 | break; |
| 2792 | case LOGICALOP_OR_INVERTED: |
| 2793 | current.x = pixel.x | ~current.x; |
| 2794 | current.y = pixel.y | ~current.y; |
| 2795 | current.z = pixel.z | ~current.z; |
| 2796 | break; |
| 2797 | default: |
| 2798 | ASSERT(false); |
| 2799 | } |
| 2800 | } |
| 2801 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2802 | void PixelRoutine::writeColor(Registers &r, int index, Pointer<Byte> &cBuffer, Int &x, Vector4s ¤t, Int &sMask, Int &zMask, Int &cMask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2803 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2804 | if(postBlendSRGB && state.writeSRGB) |
| 2805 | { |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 2806 | linearToSRGB16_12_16(r, current); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | if(exactColorRounding) |
| 2810 | { |
| 2811 | switch(state.targetFormat[index]) |
| 2812 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2813 | case FORMAT_R5G6B5: |
| 2814 | // UNIMPLEMENTED(); // FIXME |
| 2815 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2816 | case FORMAT_X8G8R8B8Q: |
| 2817 | case FORMAT_A8G8R8B8Q: |
| 2818 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2819 | case FORMAT_X8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2820 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2821 | case FORMAT_A8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2822 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2823 | current.x = current.x - As<Short4>(As<UShort4>(current.x) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2824 | current.y = current.y - As<Short4>(As<UShort4>(current.y) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2825 | current.z = current.z - As<Short4>(As<UShort4>(current.z) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2826 | current.w = current.w - As<Short4>(As<UShort4>(current.w) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2827 | } |
| 2828 | break; |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | int rgbaWriteMask = state.colorWriteActive(index); |
| 2833 | int bgraWriteMask = rgbaWriteMask & 0x0000000A | (rgbaWriteMask & 0x00000001) << 2 | (rgbaWriteMask & 0x00000004) >> 2; |
| 2834 | int brgaWriteMask = rgbaWriteMask & 0x00000008 | (rgbaWriteMask & 0x00000001) << 1 | (rgbaWriteMask & 0x00000002) << 1 | (rgbaWriteMask & 0x00000004) >> 2; |
| 2835 | |
| 2836 | switch(state.targetFormat[index]) |
| 2837 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2838 | case FORMAT_R5G6B5: |
| 2839 | { |
| 2840 | current.x = current.x & Short4(0xF800u); |
| 2841 | current.y = As<UShort4>(current.y & Short4(0xFC00u)) >> 5; |
| 2842 | current.z = As<UShort4>(current.z) >> 11; |
| 2843 | |
| 2844 | current.x = current.x | current.y | current.z; |
| 2845 | } |
| 2846 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2847 | case FORMAT_X8G8R8B8Q: |
| 2848 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2849 | // current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2850 | // current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2851 | // current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2852 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2853 | // current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2854 | // current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.y))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2855 | break; |
| 2856 | case FORMAT_A8G8R8B8Q: |
| 2857 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2858 | // current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2859 | // current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2860 | // current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2861 | // current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2862 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2863 | // current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2864 | // current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.w))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2865 | break; |
| 2866 | case FORMAT_X8R8G8B8: |
| 2867 | case FORMAT_A8R8G8B8: |
| 2868 | if(state.targetFormat[index] == FORMAT_X8R8G8B8 || rgbaWriteMask == 0x7) |
| 2869 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2870 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2871 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2872 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2873 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2874 | current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2875 | current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.y))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2876 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2877 | current.x = current.z; |
| 2878 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2879 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2880 | current.y = current.z; |
| 2881 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2882 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2883 | } |
| 2884 | else |
| 2885 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2886 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2887 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2888 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2889 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2890 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2891 | current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2892 | current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.w))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2893 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2894 | current.x = current.z; |
| 2895 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2896 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2897 | current.y = current.z; |
| 2898 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2899 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2900 | } |
| 2901 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2902 | case FORMAT_X8B8G8R8: |
| 2903 | case FORMAT_A8B8G8R8: |
| 2904 | if(state.targetFormat[index] == FORMAT_X8B8G8R8 || rgbaWriteMask == 0x7) |
| 2905 | { |
| 2906 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2907 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2908 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2909 | |
| 2910 | current.z = As<Short4>(Pack(As<UShort4>(current.x), As<UShort4>(current.z))); |
| 2911 | current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.y))); |
| 2912 | |
| 2913 | current.x = current.z; |
| 2914 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2915 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2916 | current.y = current.z; |
| 2917 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2918 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
| 2919 | } |
| 2920 | else |
| 2921 | { |
| 2922 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2923 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2924 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2925 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
| 2926 | |
| 2927 | current.z = As<Short4>(Pack(As<UShort4>(current.x), As<UShort4>(current.z))); |
| 2928 | current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.w))); |
| 2929 | |
| 2930 | current.x = current.z; |
| 2931 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2932 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2933 | current.y = current.z; |
| 2934 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2935 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
| 2936 | } |
| 2937 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2938 | case FORMAT_A8: |
| 2939 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
| 2940 | current.w = As<Short4>(Pack(As<UShort4>(current.w), As<UShort4>(current.w))); |
| 2941 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2942 | case FORMAT_G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2943 | current.z = current.x; |
| 2944 | current.x = As<Short4>(UnpackLow(current.x, current.y)); |
| 2945 | current.z = As<Short4>(UnpackHigh(current.z, current.y)); |
| 2946 | current.y = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2947 | break; |
| 2948 | case FORMAT_A16B16G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2949 | transpose4x4(current.x, current.y, current.z, current.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2950 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2951 | default: |
| 2952 | ASSERT(false); |
| 2953 | } |
| 2954 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2955 | Short4 c01 = current.z; |
| 2956 | Short4 c23 = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2957 | |
| 2958 | Int xMask; // Combination of all masks |
| 2959 | |
| 2960 | if(state.depthTestActive) |
| 2961 | { |
| 2962 | xMask = zMask; |
| 2963 | } |
| 2964 | else |
| 2965 | { |
| 2966 | xMask = cMask; |
| 2967 | } |
| 2968 | |
| 2969 | if(state.stencilActive) |
| 2970 | { |
| 2971 | xMask &= sMask; |
| 2972 | } |
| 2973 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2974 | switch(state.targetFormat[index]) |
| 2975 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2976 | case FORMAT_R5G6B5: |
| 2977 | { |
| 2978 | Pointer<Byte> buffer = cBuffer + 2 * x; |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 2979 | Int value = *Pointer<Int>(buffer); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2980 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 2981 | Int c01 = Extract(As<Int2>(current.x), 0); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2982 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 2983 | if((bgraWriteMask & 0x00000007) != 0x00000007) |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2984 | { |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 2985 | Int masked = value; |
| 2986 | c01 &= *Pointer<Int>(r.constants + OFFSET(Constants,mask565Q[bgraWriteMask & 0x7][0])); |
| 2987 | masked &= *Pointer<Int>(r.constants + OFFSET(Constants,invMask565Q[bgraWriteMask & 0x7][0])); |
| 2988 | c01 |= masked; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2989 | } |
| 2990 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 2991 | c01 &= *Pointer<Int>(r.constants + OFFSET(Constants,maskW4Q[0][0]) + xMask * 8); |
| 2992 | value &= *Pointer<Int>(r.constants + OFFSET(Constants,invMaskW4Q[0][0]) + xMask * 8); |
| 2993 | c01 |= value; |
| 2994 | *Pointer<Int>(buffer) = c01; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2995 | |
| 2996 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 2997 | value = *Pointer<Int>(buffer); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 2998 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 2999 | Int c23 = Extract(As<Int2>(current.x), 1); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3000 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 3001 | if((bgraWriteMask & 0x00000007) != 0x00000007) |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3002 | { |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 3003 | Int masked = value; |
| 3004 | c23 &= *Pointer<Int>(r.constants + OFFSET(Constants,mask565Q[bgraWriteMask & 0x7][0])); |
| 3005 | masked &= *Pointer<Int>(r.constants + OFFSET(Constants,invMask565Q[bgraWriteMask & 0x7][0])); |
| 3006 | c23 |= masked; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 3009 | c23 &= *Pointer<Int>(r.constants + OFFSET(Constants,maskW4Q[0][2]) + xMask * 8); |
| 3010 | value &= *Pointer<Int>(r.constants + OFFSET(Constants,invMaskW4Q[0][2]) + xMask * 8); |
| 3011 | c23 |= value; |
| 3012 | *Pointer<Int>(buffer) = c23; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3013 | } |
| 3014 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3015 | case FORMAT_A8G8R8B8Q: |
| 3016 | case FORMAT_X8G8R8B8Q: // FIXME: Don't touch alpha? |
| 3017 | UNIMPLEMENTED(); |
| 3018 | // value = *Pointer<Short4>(cBuffer + 8 * x + 0); |
| 3019 | |
| 3020 | // if((state.targetFormat[index] == FORMAT_A8G8R8B8Q && bgraWriteMask != 0x0000000F) || |
| 3021 | // ((state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x00000007) && |
| 3022 | // (state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 3023 | // { |
| 3024 | // Short4 masked = value; |
| 3025 | // c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 3026 | // masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 3027 | // c01 |= masked; |
| 3028 | // } |
| 3029 | |
| 3030 | // c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 3031 | // value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 3032 | // c01 |= value; |
| 3033 | // *Pointer<Short4>(cBuffer + 8 * x + 0) = c01; |
| 3034 | |
| 3035 | // value = *Pointer<Short4>(cBuffer + 8 * x + 8); |
| 3036 | |
| 3037 | // if((state.targetFormat[index] == FORMAT_A8G8R8B8Q && bgraWriteMask != 0x0000000F) || |
| 3038 | // ((state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x00000007) && |
| 3039 | // (state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 3040 | // { |
| 3041 | // Short4 masked = value; |
| 3042 | // c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 3043 | // masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 3044 | // c23 |= masked; |
| 3045 | // } |
| 3046 | |
| 3047 | // c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 3048 | // value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 3049 | // c23 |= value; |
| 3050 | // *Pointer<Short4>(cBuffer + 8 * x + 8) = c23; |
| 3051 | break; |
| 3052 | case FORMAT_A8R8G8B8: |
| 3053 | case FORMAT_X8R8G8B8: // FIXME: Don't touch alpha? |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3054 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3055 | Pointer<Byte> buffer = cBuffer + x * 4; |
| 3056 | Short4 value = *Pointer<Short4>(buffer); |
| 3057 | |
| 3058 | if((state.targetFormat[index] == FORMAT_A8R8G8B8 && bgraWriteMask != 0x0000000F) || |
| 3059 | ((state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x00000007) && |
| 3060 | (state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 3061 | { |
| 3062 | Short4 masked = value; |
| 3063 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 3064 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 3065 | c01 |= masked; |
| 3066 | } |
| 3067 | |
| 3068 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 3069 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 3070 | c01 |= value; |
| 3071 | *Pointer<Short4>(buffer) = c01; |
| 3072 | |
| 3073 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3074 | value = *Pointer<Short4>(buffer); |
| 3075 | |
| 3076 | if((state.targetFormat[index] == FORMAT_A8R8G8B8 && bgraWriteMask != 0x0000000F) || |
| 3077 | ((state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x00000007) && |
| 3078 | (state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 3079 | { |
| 3080 | Short4 masked = value; |
| 3081 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 3082 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 3083 | c23 |= masked; |
| 3084 | } |
| 3085 | |
| 3086 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 3087 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 3088 | c23 |= value; |
| 3089 | *Pointer<Short4>(buffer) = c23; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3090 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3091 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 3092 | case FORMAT_A8B8G8R8: |
| 3093 | case FORMAT_X8B8G8R8: // FIXME: Don't touch alpha? |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 3094 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3095 | Pointer<Byte> buffer = cBuffer + x * 4; |
| 3096 | Short4 value = *Pointer<Short4>(buffer); |
| 3097 | |
| 3098 | if((state.targetFormat[index] == FORMAT_A8B8G8R8 && rgbaWriteMask != 0x0000000F) || |
| 3099 | ((state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x00000007) && |
| 3100 | (state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x0000000F))) // FIXME: Need for masking when XBGR && Fh? |
| 3101 | { |
| 3102 | Short4 masked = value; |
| 3103 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[rgbaWriteMask][0])); |
| 3104 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[rgbaWriteMask][0])); |
| 3105 | c01 |= masked; |
| 3106 | } |
| 3107 | |
| 3108 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 3109 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 3110 | c01 |= value; |
| 3111 | *Pointer<Short4>(buffer) = c01; |
| 3112 | |
| 3113 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3114 | value = *Pointer<Short4>(buffer); |
| 3115 | |
| 3116 | if((state.targetFormat[index] == FORMAT_A8B8G8R8 && rgbaWriteMask != 0x0000000F) || |
| 3117 | ((state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x00000007) && |
| 3118 | (state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x0000000F))) // FIXME: Need for masking when XBGR && Fh? |
| 3119 | { |
| 3120 | Short4 masked = value; |
| 3121 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[rgbaWriteMask][0])); |
| 3122 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[rgbaWriteMask][0])); |
| 3123 | c23 |= masked; |
| 3124 | } |
| 3125 | |
| 3126 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 3127 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 3128 | c23 |= value; |
| 3129 | *Pointer<Short4>(buffer) = c23; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 3130 | } |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 3131 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3132 | case FORMAT_A8: |
| 3133 | if(rgbaWriteMask & 0x00000008) |
| 3134 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3135 | Pointer<Byte> buffer = cBuffer + 1 * x; |
| 3136 | Short4 value; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3137 | Insert(value, *Pointer<Short>(buffer), 0); |
| 3138 | Int pitch = *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3139 | Insert(value, *Pointer<Short>(buffer + pitch), 1); |
| 3140 | value = UnpackLow(As<Byte8>(value), As<Byte8>(value)); |
| 3141 | |
| 3142 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q) + 8 * xMask); |
| 3143 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * xMask); |
| 3144 | current.w |= value; |
| 3145 | |
| 3146 | *Pointer<Short>(buffer) = Extract(current.w, 0); |
| 3147 | *Pointer<Short>(buffer + pitch) = Extract(current.w, 1); |
| 3148 | } |
| 3149 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3150 | case FORMAT_G16R16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3151 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3152 | Pointer<Byte> buffer = cBuffer + 4 * x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3153 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3154 | Short4 value = *Pointer<Short4>(buffer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3155 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3156 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3157 | { |
| 3158 | Short4 masked = value; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3159 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0])); |
| 3160 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3161 | current.x |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3162 | } |
| 3163 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3164 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 3165 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3166 | current.x |= value; |
| 3167 | *Pointer<Short4>(buffer) = current.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3168 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3169 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3170 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3171 | value = *Pointer<Short4>(buffer); |
| 3172 | |
| 3173 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3174 | { |
| 3175 | Short4 masked = value; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3176 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0])); |
| 3177 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3178 | current.y |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3179 | } |
| 3180 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3181 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 3182 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3183 | current.y |= value; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3184 | *Pointer<Short4>(buffer) = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3185 | } |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3186 | break; |
| 3187 | case FORMAT_A16B16G16R16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3188 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3189 | Pointer<Byte> buffer = cBuffer + 8 * x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3190 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3191 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3192 | Short4 value = *Pointer<Short4>(buffer); |
| 3193 | |
| 3194 | if(rgbaWriteMask != 0x0000000F) |
| 3195 | { |
| 3196 | Short4 masked = value; |
| 3197 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
| 3198 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
| 3199 | current.x |= masked; |
| 3200 | } |
| 3201 | |
| 3202 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ0Q) + xMask * 8); |
| 3203 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ0Q) + xMask * 8); |
| 3204 | current.x |= value; |
| 3205 | *Pointer<Short4>(buffer) = current.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3206 | } |
| 3207 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3208 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3209 | Short4 value = *Pointer<Short4>(buffer + 8); |
| 3210 | |
| 3211 | if(rgbaWriteMask != 0x0000000F) |
| 3212 | { |
| 3213 | Short4 masked = value; |
| 3214 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
| 3215 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
| 3216 | current.y |= masked; |
| 3217 | } |
| 3218 | |
| 3219 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ1Q) + xMask * 8); |
| 3220 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ1Q) + xMask * 8); |
| 3221 | current.y |= value; |
| 3222 | *Pointer<Short4>(buffer + 8) = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3223 | } |
| 3224 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 3225 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3226 | |
| 3227 | { |
| 3228 | Short4 value = *Pointer<Short4>(buffer); |
| 3229 | |
| 3230 | if(rgbaWriteMask != 0x0000000F) |
| 3231 | { |
| 3232 | Short4 masked = value; |
| 3233 | current.z &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
| 3234 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
| 3235 | current.z |= masked; |
| 3236 | } |
| 3237 | |
| 3238 | current.z &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ2Q) + xMask * 8); |
| 3239 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ2Q) + xMask * 8); |
| 3240 | current.z |= value; |
| 3241 | *Pointer<Short4>(buffer) = current.z; |
| 3242 | } |
| 3243 | |
| 3244 | { |
| 3245 | Short4 value = *Pointer<Short4>(buffer + 8); |
| 3246 | |
| 3247 | if(rgbaWriteMask != 0x0000000F) |
| 3248 | { |
| 3249 | Short4 masked = value; |
| 3250 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
| 3251 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
| 3252 | current.w |= masked; |
| 3253 | } |
| 3254 | |
| 3255 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ3Q) + xMask * 8); |
| 3256 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ3Q) + xMask * 8); |
| 3257 | current.w |= value; |
| 3258 | *Pointer<Short4>(buffer + 8) = current.w; |
| 3259 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3260 | } |
| 3261 | break; |
| 3262 | default: |
| 3263 | ASSERT(false); |
| 3264 | } |
| 3265 | } |
| 3266 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3267 | void PixelRoutine::blendFactor(Registers &r, const Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3268 | { |
| 3269 | switch(blendFactorActive) |
| 3270 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3271 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3272 | // Optimized |
| 3273 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3274 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3275 | // Optimized |
| 3276 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3277 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3278 | blendFactor.x = oC.x; |
| 3279 | blendFactor.y = oC.y; |
| 3280 | blendFactor.z = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3281 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3282 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3283 | blendFactor.x = Float4(1.0f) - oC.x; |
| 3284 | blendFactor.y = Float4(1.0f) - oC.y; |
| 3285 | blendFactor.z = Float4(1.0f) - oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3286 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3287 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3288 | blendFactor.x = pixel.x; |
| 3289 | blendFactor.y = pixel.y; |
| 3290 | blendFactor.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3291 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3292 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3293 | blendFactor.x = Float4(1.0f) - pixel.x; |
| 3294 | blendFactor.y = Float4(1.0f) - pixel.y; |
| 3295 | blendFactor.z = Float4(1.0f) - pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3296 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3297 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3298 | blendFactor.x = oC.w; |
| 3299 | blendFactor.y = oC.w; |
| 3300 | blendFactor.z = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3301 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3302 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3303 | blendFactor.x = Float4(1.0f) - oC.w; |
| 3304 | blendFactor.y = Float4(1.0f) - oC.w; |
| 3305 | blendFactor.z = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3306 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3307 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3308 | blendFactor.x = pixel.w; |
| 3309 | blendFactor.y = pixel.w; |
| 3310 | blendFactor.z = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3311 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3312 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3313 | blendFactor.x = Float4(1.0f) - pixel.w; |
| 3314 | blendFactor.y = Float4(1.0f) - pixel.w; |
| 3315 | blendFactor.z = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3316 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3317 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3318 | blendFactor.x = Float4(1.0f) - pixel.w; |
| 3319 | blendFactor.x = Min(blendFactor.x, oC.w); |
| 3320 | blendFactor.y = blendFactor.x; |
| 3321 | blendFactor.z = blendFactor.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3322 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3323 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3324 | blendFactor.x = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[0])); |
| 3325 | blendFactor.y = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[1])); |
| 3326 | blendFactor.z = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3327 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3328 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3329 | blendFactor.x = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[0])); |
| 3330 | blendFactor.y = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[1])); |
| 3331 | blendFactor.z = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3332 | break; |
| 3333 | default: |
| 3334 | ASSERT(false); |
| 3335 | } |
| 3336 | } |
| 3337 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3338 | void PixelRoutine::blendFactorAlpha(Registers &r, const Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorAlphaActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3339 | { |
| 3340 | switch(blendFactorAlphaActive) |
| 3341 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3342 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3343 | // Optimized |
| 3344 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3345 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3346 | // Optimized |
| 3347 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3348 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3349 | blendFactor.w = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3350 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3351 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3352 | blendFactor.w = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3353 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3354 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3355 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3356 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3357 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3358 | blendFactor.w = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3359 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3360 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3361 | blendFactor.w = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3362 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3363 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3364 | blendFactor.w = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3365 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3366 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3367 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3368 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3369 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3370 | blendFactor.w = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3371 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3372 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3373 | blendFactor.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3374 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3375 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3376 | blendFactor.w = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3377 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3378 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3379 | blendFactor.w = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3380 | break; |
| 3381 | default: |
| 3382 | ASSERT(false); |
| 3383 | } |
| 3384 | } |
| 3385 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3386 | void PixelRoutine::alphaBlend(Registers &r, int index, Pointer<Byte> &cBuffer, Vector4f &oC, Int &x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3387 | { |
| 3388 | if(!state.alphaBlendActive) |
| 3389 | { |
| 3390 | return; |
| 3391 | } |
| 3392 | |
| 3393 | Pointer<Byte> buffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3394 | Vector4f pixel; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3395 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 3396 | Vector4s color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3397 | Short4 c01; |
| 3398 | Short4 c23; |
| 3399 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3400 | switch(state.targetFormat[index]) |
| 3401 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3402 | case FORMAT_R32F: |
| 3403 | buffer = cBuffer; |
| 3404 | // FIXME: movlps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3405 | pixel.x.x = *Pointer<Float>(buffer + 4 * x + 0); |
| 3406 | pixel.x.y = *Pointer<Float>(buffer + 4 * x + 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3407 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3408 | // FIXME: movhps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3409 | pixel.x.z = *Pointer<Float>(buffer + 4 * x + 0); |
| 3410 | pixel.x.w = *Pointer<Float>(buffer + 4 * x + 4); |
| 3411 | pixel.y = Float4(1.0f); |
| 3412 | pixel.z = Float4(1.0f); |
| 3413 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3414 | break; |
| 3415 | case FORMAT_G32R32F: |
| 3416 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3417 | pixel.x = *Pointer<Float4>(buffer + 8 * x, 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3418 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3419 | pixel.y = *Pointer<Float4>(buffer + 8 * x, 16); |
| 3420 | pixel.z = pixel.x; |
| 3421 | pixel.x = ShuffleLowHigh(pixel.x, pixel.y, 0x88); |
| 3422 | pixel.z = ShuffleLowHigh(pixel.z, pixel.y, 0xDD); |
| 3423 | pixel.y = pixel.z; |
| 3424 | pixel.z = Float4(1.0f); |
| 3425 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3426 | break; |
| 3427 | case FORMAT_A32B32G32R32F: |
| 3428 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3429 | pixel.x = *Pointer<Float4>(buffer + 16 * x, 16); |
| 3430 | pixel.y = *Pointer<Float4>(buffer + 16 * x + 16, 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3431 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3432 | pixel.z = *Pointer<Float4>(buffer + 16 * x, 16); |
| 3433 | pixel.w = *Pointer<Float4>(buffer + 16 * x + 16, 16); |
| 3434 | transpose4x4(pixel.x, pixel.y, pixel.z, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3435 | break; |
| 3436 | default: |
| 3437 | ASSERT(false); |
| 3438 | } |
| 3439 | |
| 3440 | if(postBlendSRGB && state.writeSRGB) |
| 3441 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3442 | sRGBtoLinear(pixel.x); |
| 3443 | sRGBtoLinear(pixel.y); |
| 3444 | sRGBtoLinear(pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | // Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3448 | Vector4f sourceFactor; |
| 3449 | Vector4f destFactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3450 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3451 | blendFactor(r, sourceFactor, oC, pixel, state.sourceBlendFactor); |
| 3452 | blendFactor(r, destFactor, oC, pixel, state.destBlendFactor); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3453 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3454 | if(state.sourceBlendFactor != BLEND_ONE && state.sourceBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3455 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3456 | oC.x *= sourceFactor.x; |
| 3457 | oC.y *= sourceFactor.y; |
| 3458 | oC.z *= sourceFactor.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3459 | } |
| 3460 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3461 | if(state.destBlendFactor != BLEND_ONE && state.destBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3462 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3463 | pixel.x *= destFactor.x; |
| 3464 | pixel.y *= destFactor.y; |
| 3465 | pixel.z *= destFactor.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | switch(state.blendOperation) |
| 3469 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3470 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3471 | oC.x += pixel.x; |
| 3472 | oC.y += pixel.y; |
| 3473 | oC.z += pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3474 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3475 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3476 | oC.x -= pixel.x; |
| 3477 | oC.y -= pixel.y; |
| 3478 | oC.z -= pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3479 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3480 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3481 | oC.x = pixel.x - oC.x; |
| 3482 | oC.y = pixel.y - oC.y; |
| 3483 | oC.z = pixel.z - oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3484 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3485 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3486 | oC.x = Min(oC.x, pixel.x); |
| 3487 | oC.y = Min(oC.y, pixel.y); |
| 3488 | oC.z = Min(oC.z, pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3489 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3490 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3491 | oC.x = Max(oC.x, pixel.x); |
| 3492 | oC.y = Max(oC.y, pixel.y); |
| 3493 | oC.z = Max(oC.z, pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3494 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3495 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3496 | // No operation |
| 3497 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3498 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3499 | oC.x = pixel.x; |
| 3500 | oC.y = pixel.y; |
| 3501 | oC.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3502 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3503 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3504 | oC.x = Float4(0.0f); |
| 3505 | oC.y = Float4(0.0f); |
| 3506 | oC.z = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3507 | break; |
| 3508 | default: |
| 3509 | ASSERT(false); |
| 3510 | } |
| 3511 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3512 | blendFactorAlpha(r, sourceFactor, oC, pixel, state.sourceBlendFactorAlpha); |
| 3513 | blendFactorAlpha(r, destFactor, oC, pixel, state.destBlendFactorAlpha); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3514 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3515 | if(state.sourceBlendFactorAlpha != BLEND_ONE && state.sourceBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3516 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3517 | oC.w *= sourceFactor.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3518 | } |
| 3519 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3520 | if(state.destBlendFactorAlpha != BLEND_ONE && state.destBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3521 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3522 | pixel.w *= destFactor.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | switch(state.blendOperationAlpha) |
| 3526 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3527 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3528 | oC.w += pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3529 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3530 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3531 | oC.w -= pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3532 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3533 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3534 | pixel.w -= oC.w; |
| 3535 | oC.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3536 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3537 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3538 | oC.w = Min(oC.w, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3539 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3540 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3541 | oC.w = Max(oC.w, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3542 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3543 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3544 | // No operation |
| 3545 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3546 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3547 | oC.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3548 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3549 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3550 | oC.w = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3551 | break; |
| 3552 | default: |
| 3553 | ASSERT(false); |
| 3554 | } |
| 3555 | } |
| 3556 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3557 | void PixelRoutine::writeColor(Registers &r, int index, Pointer<Byte> &cBuffer, Int &x, Vector4f &oC, Int &sMask, Int &zMask, Int &cMask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3558 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3559 | switch(state.targetFormat[index]) |
| 3560 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3561 | case FORMAT_R32F: |
| 3562 | break; |
| 3563 | case FORMAT_G32R32F: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3564 | oC.z = oC.x; |
| 3565 | oC.x = UnpackLow(oC.x, oC.y); |
| 3566 | oC.z = UnpackHigh(oC.z, oC.y); |
| 3567 | oC.y = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3568 | break; |
| 3569 | case FORMAT_A32B32G32R32F: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3570 | transpose4x4(oC.x, oC.y, oC.z, oC.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3571 | break; |
| 3572 | default: |
| 3573 | ASSERT(false); |
| 3574 | } |
| 3575 | |
| 3576 | int rgbaWriteMask = state.colorWriteActive(index); |
| 3577 | |
| 3578 | Int xMask; // Combination of all masks |
| 3579 | |
| 3580 | if(state.depthTestActive) |
| 3581 | { |
| 3582 | xMask = zMask; |
| 3583 | } |
| 3584 | else |
| 3585 | { |
| 3586 | xMask = cMask; |
| 3587 | } |
| 3588 | |
| 3589 | if(state.stencilActive) |
| 3590 | { |
| 3591 | xMask &= sMask; |
| 3592 | } |
| 3593 | |
| 3594 | Pointer<Byte> buffer; |
| 3595 | Float4 value; |
| 3596 | |
| 3597 | switch(state.targetFormat[index]) |
| 3598 | { |
| 3599 | case FORMAT_R32F: |
| 3600 | if(rgbaWriteMask & 0x00000001) |
| 3601 | { |
| 3602 | buffer = cBuffer + 4 * x; |
| 3603 | |
| 3604 | // FIXME: movlps |
| 3605 | value.x = *Pointer<Float>(buffer + 0); |
| 3606 | value.y = *Pointer<Float>(buffer + 4); |
| 3607 | |
| 3608 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3609 | |
| 3610 | // FIXME: movhps |
| 3611 | value.z = *Pointer<Float>(buffer + 0); |
| 3612 | value.w = *Pointer<Float>(buffer + 4); |
| 3613 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3614 | oC.x = As<Float4>(As<Int4>(oC.x) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X) + xMask * 16, 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3615 | value = As<Float4>(As<Int4>(value) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X) + xMask * 16, 16)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3616 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3617 | |
| 3618 | // FIXME: movhps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3619 | *Pointer<Float>(buffer + 0) = oC.x.z; |
| 3620 | *Pointer<Float>(buffer + 4) = oC.x.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3621 | |
| 3622 | buffer -= *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3623 | |
| 3624 | // FIXME: movlps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3625 | *Pointer<Float>(buffer + 0) = oC.x.x; |
| 3626 | *Pointer<Float>(buffer + 4) = oC.x.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3627 | } |
| 3628 | break; |
| 3629 | case FORMAT_G32R32F: |
| 3630 | buffer = cBuffer + 8 * x; |
| 3631 | |
| 3632 | value = *Pointer<Float4>(buffer); |
| 3633 | |
| 3634 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 3635 | { |
| 3636 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3637 | oC.x = As<Float4>(As<Int4>(oC.x) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD01X[rgbaWriteMask & 0x3][0]))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3638 | masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD01X[rgbaWriteMask & 0x3][0]))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3639 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3640 | } |
| 3641 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3642 | oC.x = As<Float4>(As<Int4>(oC.x) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskQ01X) + xMask * 16, 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3643 | value = As<Float4>(As<Int4>(value) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskQ01X) + xMask * 16, 16)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3644 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
| 3645 | *Pointer<Float4>(buffer) = oC.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3646 | |
| 3647 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3648 | |
| 3649 | value = *Pointer<Float4>(buffer); |
| 3650 | |
| 3651 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 3652 | { |
| 3653 | Float4 masked; |
| 3654 | |
| 3655 | masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3656 | oC.y = As<Float4>(As<Int4>(oC.y) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD01X[rgbaWriteMask & 0x3][0]))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3657 | masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD01X[rgbaWriteMask & 0x3][0]))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3658 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3659 | } |
| 3660 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3661 | oC.y = As<Float4>(As<Int4>(oC.y) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskQ23X) + xMask * 16, 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3662 | value = As<Float4>(As<Int4>(value) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskQ23X) + xMask * 16, 16)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3663 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(value)); |
| 3664 | *Pointer<Float4>(buffer) = oC.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3665 | break; |
| 3666 | case FORMAT_A32B32G32R32F: |
| 3667 | buffer = cBuffer + 16 * x; |
| 3668 | |
| 3669 | { |
| 3670 | value = *Pointer<Float4>(buffer, 16); |
| 3671 | |
| 3672 | if(rgbaWriteMask != 0x0000000F) |
| 3673 | { |
| 3674 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3675 | oC.x = As<Float4>(As<Int4>(oC.x) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X[rgbaWriteMask][0]))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3676 | masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X[rgbaWriteMask][0]))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3677 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3678 | } |
| 3679 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3680 | oC.x = As<Float4>(As<Int4>(oC.x) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskX0X) + xMask * 16, 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3681 | value = As<Float4>(As<Int4>(value) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskX0X) + xMask * 16, 16)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3682 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
| 3683 | *Pointer<Float4>(buffer, 16) = oC.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | { |
| 3687 | value = *Pointer<Float4>(buffer + 16, 16); |
| 3688 | |
| 3689 | if(rgbaWriteMask != 0x0000000F) |
| 3690 | { |
| 3691 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3692 | oC.y = As<Float4>(As<Int4>(oC.y) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X[rgbaWriteMask][0]))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3693 | masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X[rgbaWriteMask][0]))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3694 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3695 | } |
| 3696 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3697 | oC.y = As<Float4>(As<Int4>(oC.y) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskX1X) + xMask * 16, 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3698 | value = As<Float4>(As<Int4>(value) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskX1X) + xMask * 16, 16)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3699 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(value)); |
| 3700 | *Pointer<Float4>(buffer + 16, 16) = oC.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3704 | |
| 3705 | { |
| 3706 | value = *Pointer<Float4>(buffer, 16); |
| 3707 | |
| 3708 | if(rgbaWriteMask != 0x0000000F) |
| 3709 | { |
| 3710 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3711 | oC.z = As<Float4>(As<Int4>(oC.z) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X[rgbaWriteMask][0]))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3712 | masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X[rgbaWriteMask][0]))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3713 | oC.z = As<Float4>(As<Int4>(oC.z) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3714 | } |
| 3715 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3716 | oC.z = As<Float4>(As<Int4>(oC.z) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskX2X) + xMask * 16, 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3717 | value = As<Float4>(As<Int4>(value) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskX2X) + xMask * 16, 16)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3718 | oC.z = As<Float4>(As<Int4>(oC.z) | As<Int4>(value)); |
| 3719 | *Pointer<Float4>(buffer, 16) = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | { |
| 3723 | value = *Pointer<Float4>(buffer + 16, 16); |
| 3724 | |
| 3725 | if(rgbaWriteMask != 0x0000000F) |
| 3726 | { |
| 3727 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3728 | oC.w = As<Float4>(As<Int4>(oC.w) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X[rgbaWriteMask][0]))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3729 | masked = As<Float4>(As<Int4>(masked) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X[rgbaWriteMask][0]))); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3730 | oC.w = As<Float4>(As<Int4>(oC.w) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3731 | } |
| 3732 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3733 | oC.w = As<Float4>(As<Int4>(oC.w) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskX3X) + xMask * 16, 16)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3734 | value = As<Float4>(As<Int4>(value) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskX3X) + xMask * 16, 16)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3735 | oC.w = As<Float4>(As<Int4>(oC.w) | As<Int4>(value)); |
| 3736 | *Pointer<Float4>(buffer + 16, 16) = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3737 | } |
| 3738 | break; |
| 3739 | default: |
| 3740 | ASSERT(false); |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | void PixelRoutine::ps_1_x(Registers &r, Int cMask[4]) |
| 3745 | { |
| 3746 | int pad = 0; // Count number of texm3x3pad instructions |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 3747 | Vector4s dPairing; // Destination for first pairing instruction |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3748 | |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 3749 | for(size_t i = 0; i < shader->getLength(); i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3750 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3751 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3752 | Shader::Opcode opcode = instruction->opcode; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3753 | |
| 3754 | // #ifndef NDEBUG // FIXME: Centralize debug output control |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3755 | // shader->printInstruction(i, "debug.txt"); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3756 | // #endif |
| 3757 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3758 | 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] | 3759 | { |
| 3760 | continue; |
| 3761 | } |
| 3762 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3763 | const Dst &dst = instruction->dst; |
| 3764 | const Src &src0 = instruction->src[0]; |
| 3765 | const Src &src1 = instruction->src[1]; |
| 3766 | const Src &src2 = instruction->src[2]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3767 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3768 | unsigned short version = shader->getVersion(); |
| 3769 | bool pairing = i + 1 < shader->getLength() && shader->getInstruction(i + 1)->coissue; // First instruction of pair |
| 3770 | bool coissue = instruction->coissue; // Second instruction of pair |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3771 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 3772 | Vector4s d; |
| 3773 | Vector4s s0; |
| 3774 | Vector4s s1; |
| 3775 | Vector4s s2; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3776 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 3777 | if(src0.type != Shader::PARAMETER_VOID) s0 = fetchRegisterS(r, src0); |
| 3778 | if(src1.type != Shader::PARAMETER_VOID) s1 = fetchRegisterS(r, src1); |
| 3779 | if(src2.type != Shader::PARAMETER_VOID) s2 = fetchRegisterS(r, src2); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3780 | |
| 3781 | Float4 u = version < 0x0104 ? r.vf[2 + dst.index].x : r.vf[2 + src0.index].x; |
| 3782 | Float4 v = version < 0x0104 ? r.vf[2 + dst.index].y : r.vf[2 + src0.index].y; |
| 3783 | Float4 s = version < 0x0104 ? r.vf[2 + dst.index].z : r.vf[2 + src0.index].z; |
| 3784 | Float4 t = version < 0x0104 ? r.vf[2 + dst.index].w : r.vf[2 + src0.index].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3785 | |
| 3786 | switch(opcode) |
| 3787 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3788 | case Shader::OPCODE_PS_1_0: break; |
| 3789 | case Shader::OPCODE_PS_1_1: break; |
| 3790 | case Shader::OPCODE_PS_1_2: break; |
| 3791 | case Shader::OPCODE_PS_1_3: break; |
| 3792 | case Shader::OPCODE_PS_1_4: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3793 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3794 | case Shader::OPCODE_DEF: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3795 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3796 | case Shader::OPCODE_NOP: break; |
| 3797 | case Shader::OPCODE_MOV: MOV(d, s0); break; |
| 3798 | case Shader::OPCODE_ADD: ADD(d, s0, s1); break; |
| 3799 | case Shader::OPCODE_SUB: SUB(d, s0, s1); break; |
| 3800 | case Shader::OPCODE_MAD: MAD(d, s0, s1, s2); break; |
| 3801 | case Shader::OPCODE_MUL: MUL(d, s0, s1); break; |
| 3802 | case Shader::OPCODE_DP3: DP3(d, s0, s1); break; |
| 3803 | case Shader::OPCODE_DP4: DP4(d, s0, s1); break; |
| 3804 | case Shader::OPCODE_LRP: LRP(d, s0, s1, s2); break; |
| 3805 | case Shader::OPCODE_TEXCOORD: |
| 3806 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3807 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3808 | TEXCOORD(d, u, v, s, dst.index); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3809 | } |
| 3810 | else |
| 3811 | { |
| 3812 | if((src0.swizzle & 0x30) == 0x20) // .xyz |
| 3813 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3814 | TEXCRD(d, u, v, s, src0.index, src0.modifier == Shader::MODIFIER_DZ || src0.modifier == Shader::MODIFIER_DW); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3815 | } |
| 3816 | else // .xyw |
| 3817 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3818 | TEXCRD(d, u, v, t, src0.index, src0.modifier == Shader::MODIFIER_DZ || src0.modifier == Shader::MODIFIER_DW); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3819 | } |
| 3820 | } |
| 3821 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3822 | case Shader::OPCODE_TEXKILL: |
| 3823 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3824 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3825 | TEXKILL(cMask, u, v, s); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3826 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3827 | else if(version == 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3828 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3829 | if(dst.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3830 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3831 | TEXKILL(cMask, u, v, s); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3832 | } |
| 3833 | else |
| 3834 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 3835 | TEXKILL(cMask, r.rs[dst.index]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3836 | } |
| 3837 | } |
| 3838 | else ASSERT(false); |
| 3839 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3840 | case Shader::OPCODE_TEX: |
| 3841 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3842 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3843 | TEX(r, d, u, v, s, dst.index, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3844 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3845 | else if(version == 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3846 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3847 | if(src0.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3848 | { |
| 3849 | if((src0.swizzle & 0x30) == 0x20) // .xyz |
| 3850 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3851 | TEX(r, d, u, v, s, dst.index, src0.modifier == Shader::MODIFIER_DZ || src0.modifier == Shader::MODIFIER_DW); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3852 | } |
| 3853 | else // .xyw |
| 3854 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3855 | TEX(r, d, u, v, t, dst.index, src0.modifier == Shader::MODIFIER_DZ || src0.modifier == Shader::MODIFIER_DW); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3856 | } |
| 3857 | } |
| 3858 | else |
| 3859 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3860 | TEXLD(r, d, s0, dst.index, src0.modifier == Shader::MODIFIER_DZ || src0.modifier == Shader::MODIFIER_DW); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3861 | } |
| 3862 | } |
| 3863 | else ASSERT(false); |
| 3864 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3865 | case Shader::OPCODE_TEXBEM: TEXBEM(r, d, s0, u, v, s, dst.index); break; |
| 3866 | case Shader::OPCODE_TEXBEML: TEXBEML(r, d, s0, u, v, s, dst.index); break; |
| 3867 | case Shader::OPCODE_TEXREG2AR: TEXREG2AR(r, d, s0, dst.index); break; |
| 3868 | case Shader::OPCODE_TEXREG2GB: TEXREG2GB(r, d, s0, dst.index); break; |
| 3869 | case Shader::OPCODE_TEXM3X2PAD: TEXM3X2PAD(r, u, v, s, s0, 0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3870 | case Shader::OPCODE_TEXM3X2TEX: TEXM3X2TEX(r, d, u, v, s, dst.index, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3871 | case Shader::OPCODE_TEXM3X3PAD: TEXM3X3PAD(r, u, v, s, s0, pad++ % 2, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3872 | case Shader::OPCODE_TEXM3X3TEX: TEXM3X3TEX(r, d, u, v, s, dst.index, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3873 | case Shader::OPCODE_TEXM3X3SPEC: TEXM3X3SPEC(r, d, u, v, s, dst.index, s0, s1); break; |
| 3874 | case Shader::OPCODE_TEXM3X3VSPEC: TEXM3X3VSPEC(r, d, u, v, s, dst.index, s0); break; |
| 3875 | case Shader::OPCODE_CND: CND(d, s0, s1, s2); break; |
| 3876 | case Shader::OPCODE_TEXREG2RGB: TEXREG2RGB(r, d, s0, dst.index); break; |
| 3877 | case Shader::OPCODE_TEXDP3TEX: TEXDP3TEX(r, d, u, v, s, dst.index, s0); break; |
| 3878 | case Shader::OPCODE_TEXM3X2DEPTH: TEXM3X2DEPTH(r, d, u, v, s, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3879 | case Shader::OPCODE_TEXDP3: TEXDP3(r, d, u, v, s, s0); break; |
| 3880 | case Shader::OPCODE_TEXM3X3: TEXM3X3(r, d, u, v, s, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3881 | case Shader::OPCODE_TEXDEPTH: TEXDEPTH(r); break; |
| 3882 | case Shader::OPCODE_CMP0: CMP(d, s0, s1, s2); break; |
| 3883 | case Shader::OPCODE_BEM: BEM(r, d, s0, s1, dst.index); break; |
| 3884 | case Shader::OPCODE_PHASE: break; |
| 3885 | case Shader::OPCODE_END: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3886 | default: |
| 3887 | ASSERT(false); |
| 3888 | } |
| 3889 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3890 | if(dst.type != Shader::PARAMETER_VOID && opcode != Shader::OPCODE_TEXKILL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3891 | { |
| 3892 | if(dst.shift > 0) |
| 3893 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3894 | if(dst.mask & 0x1) {d.x = AddSat(d.x, d.x); if(dst.shift > 1) d.x = AddSat(d.x, d.x); if(dst.shift > 2) d.x = AddSat(d.x, d.x);} |
| 3895 | if(dst.mask & 0x2) {d.y = AddSat(d.y, d.y); if(dst.shift > 1) d.y = AddSat(d.y, d.y); if(dst.shift > 2) d.y = AddSat(d.y, d.y);} |
| 3896 | if(dst.mask & 0x4) {d.z = AddSat(d.z, d.z); if(dst.shift > 1) d.z = AddSat(d.z, d.z); if(dst.shift > 2) d.z = AddSat(d.z, d.z);} |
| 3897 | if(dst.mask & 0x8) {d.w = AddSat(d.w, d.w); if(dst.shift > 1) d.w = AddSat(d.w, d.w); if(dst.shift > 2) d.w = AddSat(d.w, d.w);} |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3898 | } |
| 3899 | else if(dst.shift < 0) |
| 3900 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3901 | if(dst.mask & 0x1) d.x = d.x >> -dst.shift; |
| 3902 | if(dst.mask & 0x2) d.y = d.y >> -dst.shift; |
| 3903 | if(dst.mask & 0x4) d.z = d.z >> -dst.shift; |
| 3904 | if(dst.mask & 0x8) d.w = d.w >> -dst.shift; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | if(dst.saturate) |
| 3908 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3909 | if(dst.mask & 0x1) {d.x = Min(d.x, Short4(0x1000)); d.x = Max(d.x, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3910 | if(dst.mask & 0x2) {d.y = Min(d.y, Short4(0x1000)); d.y = Max(d.y, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3911 | if(dst.mask & 0x4) {d.z = Min(d.z, Short4(0x1000)); d.z = Max(d.z, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3912 | if(dst.mask & 0x8) {d.w = Min(d.w, Short4(0x1000)); d.w = Max(d.w, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | if(pairing) |
| 3916 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3917 | if(dst.mask & 0x1) dPairing.x = d.x; |
| 3918 | if(dst.mask & 0x2) dPairing.y = d.y; |
| 3919 | if(dst.mask & 0x4) dPairing.z = d.z; |
| 3920 | if(dst.mask & 0x8) dPairing.w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | if(coissue) |
| 3924 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3925 | const Dst &dst = shader->getInstruction(i - 1)->dst; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3926 | |
| 3927 | writeDestination(r, dPairing, dst); |
| 3928 | } |
| 3929 | |
| 3930 | if(!pairing) |
| 3931 | { |
| 3932 | writeDestination(r, d, dst); |
| 3933 | } |
| 3934 | } |
| 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | void PixelRoutine::ps_2_x(Registers &r, Int cMask[4]) |
| 3939 | { |
| 3940 | r.enableIndex = 0; |
| 3941 | r.stackIndex = 0; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3942 | |
Nicolas Capens | 4677a5f | 2014-05-06 16:42:26 -0400 | [diff] [blame] | 3943 | if(shader->containsLeaveInstruction()) |
| 3944 | { |
| 3945 | r.enableLeave = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 3946 | } |
| 3947 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3948 | bool out[4][4] = {false}; |
| 3949 | |
| 3950 | // Create all call site return blocks up front |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 3951 | for(size_t i = 0; i < shader->getLength(); i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3952 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3953 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3954 | Shader::Opcode opcode = instruction->opcode; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3955 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3956 | if(opcode == Shader::OPCODE_CALL || opcode == Shader::OPCODE_CALLNZ) |
| 3957 | { |
| 3958 | const Dst &dst = instruction->dst; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3959 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3960 | ASSERT(callRetBlock[dst.label].size() == dst.callSite); |
| 3961 | callRetBlock[dst.label].push_back(Nucleus::createBasicBlock()); |
| 3962 | } |
| 3963 | } |
| 3964 | |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 3965 | for(size_t i = 0; i < shader->getLength(); i++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3966 | { |
| 3967 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3968 | Shader::Opcode opcode = instruction->opcode; |
| 3969 | |
| 3970 | 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] | 3971 | { |
| 3972 | continue; |
| 3973 | } |
| 3974 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3975 | const Dst &dst = instruction->dst; |
| 3976 | const Src &src0 = instruction->src[0]; |
| 3977 | const Src &src1 = instruction->src[1]; |
| 3978 | const Src &src2 = instruction->src[2]; |
| 3979 | const Src &src3 = instruction->src[3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3980 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3981 | bool predicate = instruction->predicate; |
| 3982 | Control control = instruction->control; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3983 | bool pp = dst.partialPrecision; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3984 | bool project = instruction->project; |
| 3985 | bool bias = instruction->bias; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3986 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3987 | Vector4f d; |
| 3988 | Vector4f s0; |
| 3989 | Vector4f s1; |
| 3990 | Vector4f s2; |
| 3991 | Vector4f s3; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3992 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3993 | if(opcode == Shader::OPCODE_TEXKILL) // Takes destination as input |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3994 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3995 | if(dst.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3996 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3997 | d.x = r.vf[2 + dst.index].x; |
| 3998 | d.y = r.vf[2 + dst.index].y; |
| 3999 | d.z = r.vf[2 + dst.index].z; |
| 4000 | d.w = r.vf[2 + dst.index].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4001 | } |
| 4002 | else |
| 4003 | { |
| 4004 | d = r.rf[dst.index]; |
| 4005 | } |
| 4006 | } |
| 4007 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4008 | if(src0.type != Shader::PARAMETER_VOID) s0 = fetchRegisterF(r, src0); |
| 4009 | if(src1.type != Shader::PARAMETER_VOID) s1 = fetchRegisterF(r, src1); |
| 4010 | if(src2.type != Shader::PARAMETER_VOID) s2 = fetchRegisterF(r, src2); |
| 4011 | if(src3.type != Shader::PARAMETER_VOID) s3 = fetchRegisterF(r, src3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4012 | |
| 4013 | switch(opcode) |
| 4014 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4015 | case Shader::OPCODE_PS_2_0: break; |
| 4016 | case Shader::OPCODE_PS_2_x: break; |
| 4017 | case Shader::OPCODE_PS_3_0: break; |
| 4018 | case Shader::OPCODE_DEF: break; |
| 4019 | case Shader::OPCODE_DCL: break; |
| 4020 | case Shader::OPCODE_NOP: break; |
| 4021 | case Shader::OPCODE_MOV: mov(d, s0); break; |
| 4022 | case Shader::OPCODE_F2B: f2b(d, s0); break; |
| 4023 | case Shader::OPCODE_B2F: b2f(d, s0); break; |
| 4024 | case Shader::OPCODE_ADD: add(d, s0, s1); break; |
| 4025 | case Shader::OPCODE_SUB: sub(d, s0, s1); break; |
| 4026 | case Shader::OPCODE_MUL: mul(d, s0, s1); break; |
| 4027 | case Shader::OPCODE_MAD: mad(d, s0, s1, s2); break; |
| 4028 | case Shader::OPCODE_DP1: dp1(d, s0, s1); break; |
| 4029 | case Shader::OPCODE_DP2: dp2(d, s0, s1); break; |
| 4030 | case Shader::OPCODE_DP2ADD: dp2add(d, s0, s1, s2); break; |
| 4031 | case Shader::OPCODE_DP3: dp3(d, s0, s1); break; |
| 4032 | case Shader::OPCODE_DP4: dp4(d, s0, s1); break; |
| 4033 | case Shader::OPCODE_CMP0: cmp0(d, s0, s1, s2); break; |
| 4034 | case Shader::OPCODE_ICMP: icmp(d, s0, s1, control); break; |
| 4035 | case Shader::OPCODE_SELECT: select(d, s0, s1, s2); break; |
| 4036 | case Shader::OPCODE_EXTRACT: extract(d.x, s0, s1.x); break; |
| 4037 | case Shader::OPCODE_INSERT: insert(d, s0, s1.x, s2.x); break; |
| 4038 | case Shader::OPCODE_FRC: frc(d, s0); break; |
| 4039 | case Shader::OPCODE_TRUNC: trunc(d, s0); break; |
| 4040 | case Shader::OPCODE_FLOOR: floor(d, s0); break; |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 4041 | case Shader::OPCODE_ROUND: round(d, s0); break; |
Alexis Hetu | 8e851c1 | 2015-06-04 11:30:54 -0400 | [diff] [blame] | 4042 | case Shader::OPCODE_ROUNDEVEN: roundEven(d, s0); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4043 | case Shader::OPCODE_CEIL: ceil(d, s0); break; |
| 4044 | case Shader::OPCODE_EXP2X: exp2x(d, s0, pp); break; |
| 4045 | case Shader::OPCODE_EXP2: exp2(d, s0, pp); break; |
| 4046 | case Shader::OPCODE_LOG2X: log2x(d, s0, pp); break; |
| 4047 | case Shader::OPCODE_LOG2: log2(d, s0, pp); break; |
| 4048 | case Shader::OPCODE_EXP: exp(d, s0, pp); break; |
| 4049 | case Shader::OPCODE_LOG: log(d, s0, pp); break; |
| 4050 | case Shader::OPCODE_RCPX: rcpx(d, s0, pp); break; |
| 4051 | case Shader::OPCODE_DIV: div(d, s0, s1); break; |
| 4052 | case Shader::OPCODE_MOD: mod(d, s0, s1); break; |
| 4053 | case Shader::OPCODE_RSQX: rsqx(d, s0, pp); break; |
| 4054 | case Shader::OPCODE_SQRT: sqrt(d, s0, pp); break; |
| 4055 | case Shader::OPCODE_RSQ: rsq(d, s0, pp); break; |
| 4056 | case Shader::OPCODE_LEN2: len2(d.x, s0, pp); break; |
| 4057 | case Shader::OPCODE_LEN3: len3(d.x, s0, pp); break; |
| 4058 | case Shader::OPCODE_LEN4: len4(d.x, s0, pp); break; |
| 4059 | case Shader::OPCODE_DIST1: dist1(d.x, s0, s1, pp); break; |
| 4060 | case Shader::OPCODE_DIST2: dist2(d.x, s0, s1, pp); break; |
| 4061 | case Shader::OPCODE_DIST3: dist3(d.x, s0, s1, pp); break; |
| 4062 | case Shader::OPCODE_DIST4: dist4(d.x, s0, s1, pp); break; |
| 4063 | case Shader::OPCODE_MIN: min(d, s0, s1); break; |
| 4064 | case Shader::OPCODE_MAX: max(d, s0, s1); break; |
| 4065 | case Shader::OPCODE_LRP: lrp(d, s0, s1, s2); break; |
| 4066 | case Shader::OPCODE_STEP: step(d, s0, s1); break; |
| 4067 | case Shader::OPCODE_SMOOTH: smooth(d, s0, s1, s2); break; |
| 4068 | case Shader::OPCODE_POWX: powx(d, s0, s1, pp); break; |
| 4069 | case Shader::OPCODE_POW: pow(d, s0, s1, pp); break; |
| 4070 | case Shader::OPCODE_SGN: sgn(d, s0); break; |
| 4071 | case Shader::OPCODE_CRS: crs(d, s0, s1); break; |
| 4072 | case Shader::OPCODE_FORWARD1: forward1(d, s0, s1, s2); break; |
| 4073 | case Shader::OPCODE_FORWARD2: forward2(d, s0, s1, s2); break; |
| 4074 | case Shader::OPCODE_FORWARD3: forward3(d, s0, s1, s2); break; |
| 4075 | case Shader::OPCODE_FORWARD4: forward4(d, s0, s1, s2); break; |
| 4076 | case Shader::OPCODE_REFLECT1: reflect1(d, s0, s1); break; |
| 4077 | case Shader::OPCODE_REFLECT2: reflect2(d, s0, s1); break; |
| 4078 | case Shader::OPCODE_REFLECT3: reflect3(d, s0, s1); break; |
| 4079 | case Shader::OPCODE_REFLECT4: reflect4(d, s0, s1); break; |
| 4080 | case Shader::OPCODE_REFRACT1: refract1(d, s0, s1, s2.x); break; |
| 4081 | case Shader::OPCODE_REFRACT2: refract2(d, s0, s1, s2.x); break; |
| 4082 | case Shader::OPCODE_REFRACT3: refract3(d, s0, s1, s2.x); break; |
| 4083 | case Shader::OPCODE_REFRACT4: refract4(d, s0, s1, s2.x); break; |
| 4084 | case Shader::OPCODE_NRM2: nrm2(d, s0, pp); break; |
| 4085 | case Shader::OPCODE_NRM3: nrm3(d, s0, pp); break; |
| 4086 | case Shader::OPCODE_NRM4: nrm4(d, s0, pp); break; |
| 4087 | case Shader::OPCODE_ABS: abs(d, s0); break; |
| 4088 | case Shader::OPCODE_SINCOS: sincos(d, s0, pp); break; |
| 4089 | case Shader::OPCODE_COS: cos(d, s0, pp); break; |
| 4090 | case Shader::OPCODE_SIN: sin(d, s0, pp); break; |
| 4091 | case Shader::OPCODE_TAN: tan(d, s0, pp); break; |
| 4092 | case Shader::OPCODE_ACOS: acos(d, s0, pp); break; |
| 4093 | case Shader::OPCODE_ASIN: asin(d, s0, pp); break; |
| 4094 | case Shader::OPCODE_ATAN: atan(d, s0, pp); break; |
| 4095 | case Shader::OPCODE_ATAN2: atan2(d, s0, s1, pp); break; |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 4096 | case Shader::OPCODE_COSH: cosh(d, s0, pp); break; |
| 4097 | case Shader::OPCODE_SINH: sinh(d, s0, pp); break; |
| 4098 | case Shader::OPCODE_TANH: tanh(d, s0, pp); break; |
| 4099 | case Shader::OPCODE_ACOSH: acosh(d, s0, pp); break; |
| 4100 | case Shader::OPCODE_ASINH: asinh(d, s0, pp); break; |
| 4101 | case Shader::OPCODE_ATANH: atanh(d, s0, pp); break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4102 | case Shader::OPCODE_M4X4: M4X4(r, d, s0, src1); break; |
| 4103 | case Shader::OPCODE_M4X3: M4X3(r, d, s0, src1); break; |
| 4104 | case Shader::OPCODE_M3X4: M3X4(r, d, s0, src1); break; |
| 4105 | case Shader::OPCODE_M3X3: M3X3(r, d, s0, src1); break; |
| 4106 | case Shader::OPCODE_M3X2: M3X2(r, d, s0, src1); break; |
| 4107 | case Shader::OPCODE_TEX: TEXLD(r, d, s0, src1, project, bias); break; |
| 4108 | case Shader::OPCODE_TEXLDD: TEXLDD(r, d, s0, src1, s2, s3, project, bias); break; |
| 4109 | case Shader::OPCODE_TEXLDL: TEXLDL(r, d, s0, src1, project, bias); break; |
| 4110 | case Shader::OPCODE_TEXKILL: TEXKILL(cMask, d, dst.mask); break; |
| 4111 | case Shader::OPCODE_DISCARD: DISCARD(r, cMask, instruction); break; |
| 4112 | case Shader::OPCODE_DFDX: DFDX(d, s0); break; |
| 4113 | case Shader::OPCODE_DFDY: DFDY(d, s0); break; |
| 4114 | case Shader::OPCODE_FWIDTH: FWIDTH(d, s0); break; |
| 4115 | case Shader::OPCODE_BREAK: BREAK(r); break; |
| 4116 | case Shader::OPCODE_BREAKC: BREAKC(r, s0, s1, control); break; |
| 4117 | case Shader::OPCODE_BREAKP: BREAKP(r, src0); break; |
| 4118 | case Shader::OPCODE_CONTINUE: CONTINUE(r); break; |
| 4119 | case Shader::OPCODE_TEST: TEST(); break; |
| 4120 | case Shader::OPCODE_CALL: CALL(r, dst.label, dst.callSite); break; |
| 4121 | case Shader::OPCODE_CALLNZ: CALLNZ(r, dst.label, dst.callSite, src0); break; |
| 4122 | case Shader::OPCODE_ELSE: ELSE(r); break; |
| 4123 | case Shader::OPCODE_ENDIF: ENDIF(r); break; |
| 4124 | case Shader::OPCODE_ENDLOOP: ENDLOOP(r); break; |
| 4125 | case Shader::OPCODE_ENDREP: ENDREP(r); break; |
| 4126 | case Shader::OPCODE_ENDWHILE: ENDWHILE(r); break; |
| 4127 | case Shader::OPCODE_IF: IF(r, src0); break; |
| 4128 | case Shader::OPCODE_IFC: IFC(r, s0, s1, control); break; |
| 4129 | case Shader::OPCODE_LABEL: LABEL(dst.index); break; |
| 4130 | case Shader::OPCODE_LOOP: LOOP(r, src1); break; |
| 4131 | case Shader::OPCODE_REP: REP(r, src0); break; |
| 4132 | case Shader::OPCODE_WHILE: WHILE(r, src0); break; |
| 4133 | case Shader::OPCODE_RET: RET(r); break; |
| 4134 | case Shader::OPCODE_LEAVE: LEAVE(r); break; |
| 4135 | case Shader::OPCODE_CMP: cmp(d, s0, s1, control); break; |
| 4136 | case Shader::OPCODE_ALL: all(d.x, s0); break; |
| 4137 | case Shader::OPCODE_ANY: any(d.x, s0); break; |
| 4138 | case Shader::OPCODE_NOT: not(d, s0); break; |
| 4139 | case Shader::OPCODE_OR: or(d.x, s0.x, s1.x); break; |
| 4140 | case Shader::OPCODE_XOR: xor(d.x, s0.x, s1.x); break; |
| 4141 | case Shader::OPCODE_AND: and(d.x, s0.x, s1.x); break; |
| 4142 | case Shader::OPCODE_END: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4143 | default: |
| 4144 | ASSERT(false); |
| 4145 | } |
| 4146 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4147 | if(dst.type != Shader::PARAMETER_VOID && dst.type != Shader::PARAMETER_LABEL && opcode != Shader::OPCODE_TEXKILL && opcode != Shader::OPCODE_NOP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4148 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4149 | if(dst.integer) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4150 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4151 | switch(opcode) |
| 4152 | { |
| 4153 | case Shader::OPCODE_DIV: |
| 4154 | if(dst.x) d.x = Trunc(d.x); |
| 4155 | if(dst.y) d.y = Trunc(d.y); |
| 4156 | if(dst.z) d.z = Trunc(d.z); |
| 4157 | if(dst.w) d.w = Trunc(d.w); |
| 4158 | break; |
| 4159 | default: |
| 4160 | break; // No truncation to integer required when arguments are integer |
| 4161 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4162 | } |
| 4163 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4164 | if(dst.saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4165 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4166 | if(dst.x) d.x = Max(d.x, Float4(0.0f)); |
| 4167 | if(dst.y) d.y = Max(d.y, Float4(0.0f)); |
| 4168 | if(dst.z) d.z = Max(d.z, Float4(0.0f)); |
| 4169 | if(dst.w) d.w = Max(d.w, Float4(0.0f)); |
| 4170 | |
| 4171 | if(dst.x) d.x = Min(d.x, Float4(1.0f)); |
| 4172 | if(dst.y) d.y = Min(d.y, Float4(1.0f)); |
| 4173 | if(dst.z) d.z = Min(d.z, Float4(1.0f)); |
| 4174 | if(dst.w) d.w = Min(d.w, Float4(1.0f)); |
| 4175 | } |
| 4176 | |
Nicolas Capens | c6e8ab1 | 2014-05-06 23:31:07 -0400 | [diff] [blame] | 4177 | if(instruction->isPredicated()) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4178 | { |
| 4179 | Vector4f pDst; // FIXME: Rename |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4180 | |
| 4181 | switch(dst.type) |
| 4182 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4183 | case Shader::PARAMETER_TEMP: |
| 4184 | if(dst.rel.type == Shader::PARAMETER_VOID) |
| 4185 | { |
| 4186 | if(dst.x) pDst.x = r.rf[dst.index].x; |
| 4187 | if(dst.y) pDst.y = r.rf[dst.index].y; |
| 4188 | if(dst.z) pDst.z = r.rf[dst.index].z; |
| 4189 | if(dst.w) pDst.w = r.rf[dst.index].w; |
| 4190 | } |
| 4191 | else |
| 4192 | { |
| 4193 | Int a = relativeAddress(r, dst); |
| 4194 | |
| 4195 | if(dst.x) pDst.x = r.rf[dst.index + a].x; |
| 4196 | if(dst.y) pDst.y = r.rf[dst.index + a].y; |
| 4197 | if(dst.z) pDst.z = r.rf[dst.index + a].z; |
| 4198 | if(dst.w) pDst.w = r.rf[dst.index + a].w; |
| 4199 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4200 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4201 | case Shader::PARAMETER_COLOROUT: |
| 4202 | ASSERT(dst.rel.type == Shader::PARAMETER_VOID); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4203 | if(dst.x) pDst.x = r.oC[dst.index].x; |
| 4204 | if(dst.y) pDst.y = r.oC[dst.index].y; |
| 4205 | if(dst.z) pDst.z = r.oC[dst.index].z; |
| 4206 | if(dst.w) pDst.w = r.oC[dst.index].w; |
| 4207 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4208 | case Shader::PARAMETER_PREDICATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4209 | if(dst.x) pDst.x = r.p0.x; |
| 4210 | if(dst.y) pDst.y = r.p0.y; |
| 4211 | if(dst.z) pDst.z = r.p0.z; |
| 4212 | if(dst.w) pDst.w = r.p0.w; |
| 4213 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4214 | case Shader::PARAMETER_DEPTHOUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4215 | pDst.x = r.oDepth; |
| 4216 | break; |
| 4217 | default: |
| 4218 | ASSERT(false); |
| 4219 | } |
| 4220 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4221 | Int4 enable = enableMask(r, instruction); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4222 | |
| 4223 | Int4 xEnable = enable; |
| 4224 | Int4 yEnable = enable; |
| 4225 | Int4 zEnable = enable; |
| 4226 | Int4 wEnable = enable; |
| 4227 | |
| 4228 | if(predicate) |
| 4229 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4230 | unsigned char pSwizzle = instruction->predicateSwizzle; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4231 | |
| 4232 | Float4 xPredicate = r.p0[(pSwizzle >> 0) & 0x03]; |
| 4233 | Float4 yPredicate = r.p0[(pSwizzle >> 2) & 0x03]; |
| 4234 | Float4 zPredicate = r.p0[(pSwizzle >> 4) & 0x03]; |
| 4235 | Float4 wPredicate = r.p0[(pSwizzle >> 6) & 0x03]; |
| 4236 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4237 | if(!instruction->predicateNot) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4238 | { |
| 4239 | if(dst.x) xEnable = xEnable & As<Int4>(xPredicate); |
| 4240 | if(dst.y) yEnable = yEnable & As<Int4>(yPredicate); |
| 4241 | if(dst.z) zEnable = zEnable & As<Int4>(zPredicate); |
| 4242 | if(dst.w) wEnable = wEnable & As<Int4>(wPredicate); |
| 4243 | } |
| 4244 | else |
| 4245 | { |
| 4246 | if(dst.x) xEnable = xEnable & ~As<Int4>(xPredicate); |
| 4247 | if(dst.y) yEnable = yEnable & ~As<Int4>(yPredicate); |
| 4248 | if(dst.z) zEnable = zEnable & ~As<Int4>(zPredicate); |
| 4249 | if(dst.w) wEnable = wEnable & ~As<Int4>(wPredicate); |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | if(dst.x) d.x = As<Float4>(As<Int4>(d.x) & xEnable); |
| 4254 | if(dst.y) d.y = As<Float4>(As<Int4>(d.y) & yEnable); |
| 4255 | if(dst.z) d.z = As<Float4>(As<Int4>(d.z) & zEnable); |
| 4256 | if(dst.w) d.w = As<Float4>(As<Int4>(d.w) & wEnable); |
| 4257 | |
| 4258 | if(dst.x) d.x = As<Float4>(As<Int4>(d.x) | (As<Int4>(pDst.x) & ~xEnable)); |
| 4259 | if(dst.y) d.y = As<Float4>(As<Int4>(d.y) | (As<Int4>(pDst.y) & ~yEnable)); |
| 4260 | if(dst.z) d.z = As<Float4>(As<Int4>(d.z) | (As<Int4>(pDst.z) & ~zEnable)); |
| 4261 | if(dst.w) d.w = As<Float4>(As<Int4>(d.w) | (As<Int4>(pDst.w) & ~wEnable)); |
| 4262 | } |
| 4263 | |
| 4264 | switch(dst.type) |
| 4265 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4266 | case Shader::PARAMETER_TEMP: |
| 4267 | if(dst.rel.type == Shader::PARAMETER_VOID) |
| 4268 | { |
| 4269 | if(dst.x) r.rf[dst.index].x = d.x; |
| 4270 | if(dst.y) r.rf[dst.index].y = d.y; |
| 4271 | if(dst.z) r.rf[dst.index].z = d.z; |
| 4272 | if(dst.w) r.rf[dst.index].w = d.w; |
| 4273 | } |
| 4274 | else |
| 4275 | { |
| 4276 | Int a = relativeAddress(r, dst); |
| 4277 | |
| 4278 | if(dst.x) r.rf[dst.index + a].x = d.x; |
| 4279 | if(dst.y) r.rf[dst.index + a].y = d.y; |
| 4280 | if(dst.z) r.rf[dst.index + a].z = d.z; |
| 4281 | if(dst.w) r.rf[dst.index + a].w = d.w; |
| 4282 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4283 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4284 | case Shader::PARAMETER_COLOROUT: |
| 4285 | ASSERT(dst.rel.type == Shader::PARAMETER_VOID); |
| 4286 | if(dst.x) {r.oC[dst.index].x = d.x; out[dst.index][0] = true;} |
| 4287 | if(dst.y) {r.oC[dst.index].y = d.y; out[dst.index][1] = true;} |
| 4288 | if(dst.z) {r.oC[dst.index].z = d.z; out[dst.index][2] = true;} |
| 4289 | if(dst.w) {r.oC[dst.index].w = d.w; out[dst.index][3] = true;} |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4290 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4291 | case Shader::PARAMETER_PREDICATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4292 | if(dst.x) r.p0.x = d.x; |
| 4293 | if(dst.y) r.p0.y = d.y; |
| 4294 | if(dst.z) r.p0.z = d.z; |
| 4295 | if(dst.w) r.p0.w = d.w; |
| 4296 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4297 | case Shader::PARAMETER_DEPTHOUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4298 | r.oDepth = d.x; |
| 4299 | break; |
| 4300 | default: |
| 4301 | ASSERT(false); |
| 4302 | } |
| 4303 | } |
| 4304 | } |
| 4305 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4306 | if(currentLabel != -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4307 | { |
| 4308 | Nucleus::setInsertBlock(returnBlock); |
| 4309 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4310 | |
| 4311 | for(int i = 0; i < 4; i++) |
| 4312 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 4313 | if(state.targetFormat[i] != FORMAT_NULL) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4314 | { |
| 4315 | if(!out[i][0]) r.oC[i].x = Float4(0.0f); |
| 4316 | if(!out[i][1]) r.oC[i].y = Float4(0.0f); |
| 4317 | if(!out[i][2]) r.oC[i].z = Float4(0.0f); |
| 4318 | if(!out[i][3]) r.oC[i].w = Float4(0.0f); |
| 4319 | } |
| 4320 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4321 | } |
| 4322 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4323 | Short4 PixelRoutine::convertFixed12(RValue<Float4> cf) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4324 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4325 | return RoundShort4(cf * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4326 | } |
| 4327 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4328 | void PixelRoutine::convertFixed12(Vector4s &cs, Vector4f &cf) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4329 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4330 | cs.x = convertFixed12(cf.x); |
| 4331 | cs.y = convertFixed12(cf.y); |
| 4332 | cs.z = convertFixed12(cf.z); |
| 4333 | cs.w = convertFixed12(cf.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4334 | } |
| 4335 | |
| 4336 | UShort4 PixelRoutine::convertFixed16(Float4 &cf, bool saturate) |
| 4337 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4338 | return UShort4(cf * Float4(0xFFFF), saturate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4339 | } |
| 4340 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4341 | void PixelRoutine::convertFixed16(Vector4s &cs, Vector4f &cf, bool saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4342 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4343 | cs.x = convertFixed16(cf.x, saturate); |
| 4344 | cs.y = convertFixed16(cf.y, saturate); |
| 4345 | cs.z = convertFixed16(cf.z, saturate); |
| 4346 | cs.w = convertFixed16(cf.w, saturate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4347 | } |
| 4348 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4349 | Float4 PixelRoutine::convertSigned12(Short4 &cs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4350 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4351 | return Float4(cs) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4352 | } |
| 4353 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4354 | void PixelRoutine::convertSigned12(Vector4f &cf, Vector4s &cs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4355 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4356 | cf.x = convertSigned12(cs.x); |
| 4357 | cf.y = convertSigned12(cs.y); |
| 4358 | cf.z = convertSigned12(cs.z); |
| 4359 | cf.w = convertSigned12(cs.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4360 | } |
| 4361 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4362 | Float4 PixelRoutine::convertUnsigned16(UShort4 cs) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4363 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4364 | return Float4(cs) * Float4(1.0f / 0xFFFF); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4365 | } |
| 4366 | |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 4367 | void PixelRoutine::sRGBtoLinear16_12_16(Registers &r, Vector4s &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4368 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4369 | c.x = As<UShort4>(c.x) >> 4; |
| 4370 | c.y = As<UShort4>(c.y) >> 4; |
| 4371 | c.z = As<UShort4>(c.z) >> 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4372 | |
| 4373 | sRGBtoLinear12_16(r, c); |
| 4374 | } |
| 4375 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4376 | void PixelRoutine::sRGBtoLinear12_16(Registers &r, Vector4s &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4377 | { |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 4378 | Pointer<Byte> LUT = r.constants + OFFSET(Constants,sRGBtoLinear12_16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4379 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4380 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); |
| 4381 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); |
| 4382 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); |
| 4383 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 3))), 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4384 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4385 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 0))), 0); |
| 4386 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 1))), 1); |
| 4387 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 2))), 2); |
| 4388 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 3))), 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4389 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4390 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 0))), 0); |
| 4391 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 1))), 1); |
| 4392 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 2))), 2); |
| 4393 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 3))), 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4394 | } |
| 4395 | |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 4396 | void PixelRoutine::linearToSRGB16_12_16(Registers &r, Vector4s &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4397 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4398 | c.x = As<UShort4>(c.x) >> 4; |
| 4399 | c.y = As<UShort4>(c.y) >> 4; |
| 4400 | c.z = As<UShort4>(c.z) >> 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4401 | |
| 4402 | linearToSRGB12_16(r, c); |
| 4403 | } |
| 4404 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4405 | void PixelRoutine::linearToSRGB12_16(Registers &r, Vector4s &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4406 | { |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 4407 | Pointer<Byte> LUT = r.constants + OFFSET(Constants,linearToSRGB12_16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4408 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4409 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); |
| 4410 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); |
| 4411 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); |
| 4412 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 3))), 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4413 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4414 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 0))), 0); |
| 4415 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 1))), 1); |
| 4416 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 2))), 2); |
| 4417 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 3))), 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4418 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4419 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 0))), 0); |
| 4420 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 1))), 1); |
| 4421 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 2))), 2); |
| 4422 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 3))), 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | Float4 PixelRoutine::linearToSRGB(const Float4 &x) // Approximates x^(1.0/2.2) |
| 4426 | { |
| 4427 | Float4 sqrtx = Rcp_pp(RcpSqrt_pp(x)); |
| 4428 | Float4 sRGB = sqrtx * Float4(1.14f) - x * Float4(0.14f); |
| 4429 | |
| 4430 | return Min(Max(sRGB, Float4(0.0f)), Float4(1.0f)); |
| 4431 | } |
| 4432 | |
| 4433 | Float4 PixelRoutine::sRGBtoLinear(const Float4 &x) // Approximates x^2.2 |
| 4434 | { |
| 4435 | Float4 linear = x * x; |
| 4436 | linear = linear * Float4(0.73f) + linear * x * Float4(0.27f); |
| 4437 | |
| 4438 | return Min(Max(linear, Float4(0.0f)), Float4(1.0f)); |
| 4439 | } |
| 4440 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4441 | void PixelRoutine::MOV(Vector4s &dst, Vector4s &src0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4442 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4443 | dst.x = src0.x; |
| 4444 | dst.y = src0.y; |
| 4445 | dst.z = src0.z; |
| 4446 | dst.w = src0.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4447 | } |
| 4448 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4449 | void PixelRoutine::ADD(Vector4s &dst, Vector4s &src0, Vector4s &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4450 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4451 | dst.x = AddSat(src0.x, src1.x); |
| 4452 | dst.y = AddSat(src0.y, src1.y); |
| 4453 | dst.z = AddSat(src0.z, src1.z); |
| 4454 | dst.w = AddSat(src0.w, src1.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4455 | } |
| 4456 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4457 | void PixelRoutine::SUB(Vector4s &dst, Vector4s &src0, Vector4s &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4458 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4459 | dst.x = SubSat(src0.x, src1.x); |
| 4460 | dst.y = SubSat(src0.y, src1.y); |
| 4461 | dst.z = SubSat(src0.z, src1.z); |
| 4462 | dst.w = SubSat(src0.w, src1.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4463 | } |
| 4464 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4465 | void PixelRoutine::MAD(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4466 | { |
| 4467 | // FIXME: Long fixed-point multiply fixup |
| 4468 | {dst.x = MulHigh(src0.x, src1.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, src2.x);} |
| 4469 | {dst.y = MulHigh(src0.y, src1.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, src2.y);} |
| 4470 | {dst.z = MulHigh(src0.z, src1.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, src2.z);} |
| 4471 | {dst.w = MulHigh(src0.w, src1.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, src2.w);} |
| 4472 | } |
| 4473 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4474 | void PixelRoutine::MUL(Vector4s &dst, Vector4s &src0, Vector4s &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4475 | { |
| 4476 | // FIXME: Long fixed-point multiply fixup |
| 4477 | {dst.x = MulHigh(src0.x, src1.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x);} |
| 4478 | {dst.y = MulHigh(src0.y, src1.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y);} |
| 4479 | {dst.z = MulHigh(src0.z, src1.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z);} |
| 4480 | {dst.w = MulHigh(src0.w, src1.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w);} |
| 4481 | } |
| 4482 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4483 | void PixelRoutine::DP3(Vector4s &dst, Vector4s &src0, Vector4s &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4484 | { |
| 4485 | Short4 t0; |
| 4486 | Short4 t1; |
| 4487 | |
| 4488 | // FIXME: Long fixed-point multiply fixup |
| 4489 | t0 = MulHigh(src0.x, src1.x); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); |
| 4490 | t1 = MulHigh(src0.y, src1.y); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4491 | t0 = AddSat(t0, t1); |
| 4492 | t1 = MulHigh(src0.z, src1.z); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4493 | t0 = AddSat(t0, t1); |
| 4494 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4495 | dst.x = t0; |
| 4496 | dst.y = t0; |
| 4497 | dst.z = t0; |
| 4498 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4499 | } |
| 4500 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4501 | void PixelRoutine::DP4(Vector4s &dst, Vector4s &src0, Vector4s &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4502 | { |
| 4503 | Short4 t0; |
| 4504 | Short4 t1; |
| 4505 | |
| 4506 | // FIXME: Long fixed-point multiply fixup |
| 4507 | t0 = MulHigh(src0.x, src1.x); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); |
| 4508 | t1 = MulHigh(src0.y, src1.y); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4509 | t0 = AddSat(t0, t1); |
| 4510 | t1 = MulHigh(src0.z, src1.z); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4511 | t0 = AddSat(t0, t1); |
| 4512 | t1 = MulHigh(src0.w, src1.w); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4513 | t0 = AddSat(t0, t1); |
| 4514 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4515 | dst.x = t0; |
| 4516 | dst.y = t0; |
| 4517 | dst.z = t0; |
| 4518 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4519 | } |
| 4520 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4521 | void PixelRoutine::LRP(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4522 | { |
| 4523 | // FIXME: Long fixed-point multiply fixup |
| 4524 | {dst.x = SubSat(src1.x, src2.x); dst.x = MulHigh(dst.x, src0.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, src2.x);} |
| 4525 | {dst.y = SubSat(src1.y, src2.y); dst.y = MulHigh(dst.y, src0.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, src2.y);} |
| 4526 | {dst.z = SubSat(src1.z, src2.z); dst.z = MulHigh(dst.z, src0.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, src2.z);} |
| 4527 | {dst.w = SubSat(src1.w, src2.w); dst.w = MulHigh(dst.w, src0.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, src2.w);} |
| 4528 | } |
| 4529 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4530 | void PixelRoutine::TEXCOORD(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4531 | { |
| 4532 | Float4 uw; |
| 4533 | Float4 vw; |
| 4534 | Float4 sw; |
| 4535 | |
| 4536 | if(state.interpolant[2 + coordinate].component & 0x01) |
| 4537 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4538 | uw = Max(u, Float4(0.0f)); |
| 4539 | uw = Min(uw, Float4(1.0f)); |
| 4540 | dst.x = convertFixed12(uw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4541 | } |
| 4542 | else |
| 4543 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4544 | dst.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | if(state.interpolant[2 + coordinate].component & 0x02) |
| 4548 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4549 | vw = Max(v, Float4(0.0f)); |
| 4550 | vw = Min(vw, Float4(1.0f)); |
| 4551 | dst.y = convertFixed12(vw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4552 | } |
| 4553 | else |
| 4554 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4555 | dst.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | if(state.interpolant[2 + coordinate].component & 0x04) |
| 4559 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4560 | sw = Max(s, Float4(0.0f)); |
| 4561 | sw = Min(sw, Float4(1.0f)); |
| 4562 | dst.z = convertFixed12(sw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4563 | } |
| 4564 | else |
| 4565 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4566 | dst.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4567 | } |
| 4568 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4569 | dst.w = Short4(0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4570 | } |
| 4571 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4572 | void PixelRoutine::TEXCRD(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate, bool project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4573 | { |
| 4574 | Float4 uw = u; |
| 4575 | Float4 vw = v; |
| 4576 | Float4 sw = s; |
| 4577 | |
| 4578 | if(project) |
| 4579 | { |
| 4580 | uw *= Rcp_pp(s); |
| 4581 | vw *= Rcp_pp(s); |
| 4582 | } |
| 4583 | |
| 4584 | if(state.interpolant[2 + coordinate].component & 0x01) |
| 4585 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4586 | uw *= Float4(0x1000); |
| 4587 | uw = Max(uw, Float4(-0x8000)); |
| 4588 | uw = Min(uw, Float4(0x7FFF)); |
| 4589 | dst.x = RoundShort4(uw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4590 | } |
| 4591 | else |
| 4592 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4593 | dst.x = Short4(0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | if(state.interpolant[2 + coordinate].component & 0x02) |
| 4597 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4598 | vw *= Float4(0x1000); |
| 4599 | vw = Max(vw, Float4(-0x8000)); |
| 4600 | vw = Min(vw, Float4(0x7FFF)); |
| 4601 | dst.y = RoundShort4(vw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4602 | } |
| 4603 | else |
| 4604 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4605 | dst.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | if(state.interpolant[2 + coordinate].component & 0x04) |
| 4609 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4610 | sw *= Float4(0x1000); |
| 4611 | sw = Max(sw, Float4(-0x8000)); |
| 4612 | sw = Min(sw, Float4(0x7FFF)); |
| 4613 | dst.z = RoundShort4(sw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4614 | } |
| 4615 | else |
| 4616 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4617 | dst.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4618 | } |
| 4619 | } |
| 4620 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4621 | void PixelRoutine::TEXDP3(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4622 | { |
| 4623 | TEXM3X3PAD(r, u, v, s, src, 0, false); |
| 4624 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4625 | Short4 t0 = RoundShort4(r.u_ * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4626 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4627 | dst.x = t0; |
| 4628 | dst.y = t0; |
| 4629 | dst.z = t0; |
| 4630 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4631 | } |
| 4632 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4633 | void PixelRoutine::TEXDP3TEX(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4634 | { |
| 4635 | TEXM3X3PAD(r, u, v, s, src0, 0, false); |
| 4636 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4637 | r.v_ = Float4(0.0f); |
| 4638 | r.w_ = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4639 | |
| 4640 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4641 | } |
| 4642 | |
| 4643 | void PixelRoutine::TEXKILL(Int cMask[4], Float4 &u, Float4 &v, Float4 &s) |
| 4644 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4645 | Int kill = SignMask(CmpNLT(u, Float4(0.0f))) & |
| 4646 | SignMask(CmpNLT(v, Float4(0.0f))) & |
| 4647 | SignMask(CmpNLT(s, Float4(0.0f))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4648 | |
| 4649 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 4650 | { |
| 4651 | cMask[q] &= kill; |
| 4652 | } |
| 4653 | } |
| 4654 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4655 | void PixelRoutine::TEXKILL(Int cMask[4], Vector4s &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4656 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4657 | Short4 test = src.x | src.y | src.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4658 | Int kill = SignMask(Pack(test, test)) ^ 0x0000000F; |
| 4659 | |
| 4660 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 4661 | { |
| 4662 | cMask[q] &= kill; |
| 4663 | } |
| 4664 | } |
| 4665 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4666 | void PixelRoutine::TEX(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int sampler, bool project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4667 | { |
| 4668 | sampleTexture(r, dst, sampler, u, v, s, s, project); |
| 4669 | } |
| 4670 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4671 | void PixelRoutine::TEXLD(Registers &r, Vector4s &dst, Vector4s &src, int sampler, bool project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4672 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4673 | Float4 u = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4674 | Float4 v = Float4(src.y) * Float4(1.0f / 0x0FFE); |
| 4675 | Float4 s = Float4(src.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4676 | |
| 4677 | sampleTexture(r, dst, sampler, u, v, s, s, project); |
| 4678 | } |
| 4679 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4680 | void PixelRoutine::TEXBEM(Registers &r, Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4681 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4682 | Float4 du = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4683 | Float4 dv = Float4(src.y) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4684 | |
| 4685 | Float4 du2 = du; |
| 4686 | Float4 dv2 = dv; |
| 4687 | |
| 4688 | du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 4689 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 4690 | du += dv2; |
| 4691 | dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 4692 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 4693 | dv += du2; |
| 4694 | |
| 4695 | Float4 u_ = u + du; |
| 4696 | Float4 v_ = v + dv; |
| 4697 | |
| 4698 | sampleTexture(r, dst, stage, u_, v_, s, s); |
| 4699 | } |
| 4700 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4701 | void PixelRoutine::TEXBEML(Registers &r, Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4702 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4703 | Float4 du = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4704 | Float4 dv = Float4(src.y) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4705 | |
| 4706 | Float4 du2 = du; |
| 4707 | Float4 dv2 = dv; |
| 4708 | |
| 4709 | du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 4710 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 4711 | du += dv2; |
| 4712 | dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 4713 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 4714 | dv += du2; |
| 4715 | |
| 4716 | Float4 u_ = u + du; |
| 4717 | Float4 v_ = v + dv; |
| 4718 | |
| 4719 | sampleTexture(r, dst, stage, u_, v_, s, s); |
| 4720 | |
| 4721 | Short4 L; |
| 4722 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4723 | L = src.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4724 | L = MulHigh(L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceScale4))); |
| 4725 | L = L << 4; |
| 4726 | L = AddSat(L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceOffset4))); |
| 4727 | L = Max(L, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4728 | L = Min(L, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4729 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4730 | dst.x = MulHigh(dst.x, L); dst.x = dst.x << 4; |
| 4731 | dst.y = MulHigh(dst.y, L); dst.y = dst.y << 4; |
| 4732 | dst.z = MulHigh(dst.z, L); dst.z = dst.z << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4733 | } |
| 4734 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4735 | void PixelRoutine::TEXREG2AR(Registers &r, Vector4s &dst, Vector4s &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4736 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4737 | Float4 u = Float4(src0.w) * Float4(1.0f / 0x0FFE); |
| 4738 | Float4 v = Float4(src0.x) * Float4(1.0f / 0x0FFE); |
| 4739 | Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4740 | |
| 4741 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4742 | } |
| 4743 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4744 | void PixelRoutine::TEXREG2GB(Registers &r, Vector4s &dst, Vector4s &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4745 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4746 | Float4 u = Float4(src0.y) * Float4(1.0f / 0x0FFE); |
| 4747 | Float4 v = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4748 | Float4 s = v; |
| 4749 | |
| 4750 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4751 | } |
| 4752 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4753 | void PixelRoutine::TEXREG2RGB(Registers &r, Vector4s &dst, Vector4s &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4754 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4755 | Float4 u = Float4(src0.x) * Float4(1.0f / 0x0FFE); |
| 4756 | Float4 v = Float4(src0.y) * Float4(1.0f / 0x0FFE); |
| 4757 | Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4758 | |
| 4759 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4760 | } |
| 4761 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4762 | void PixelRoutine::TEXM3X2DEPTH(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4763 | { |
| 4764 | TEXM3X2PAD(r, u, v, s, src, 1, signedScaling); |
| 4765 | |
| 4766 | // z / w |
| 4767 | r.u_ *= Rcp_pp(r.v_); // FIXME: Set result to 1.0 when division by zero |
| 4768 | |
| 4769 | r.oDepth = r.u_; |
| 4770 | } |
| 4771 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4772 | void PixelRoutine::TEXM3X2PAD(Registers &r, Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, int component, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4773 | { |
| 4774 | TEXM3X3PAD(r, u, v, s, src0, component, signedScaling); |
| 4775 | } |
| 4776 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4777 | void PixelRoutine::TEXM3X2TEX(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4778 | { |
| 4779 | TEXM3X2PAD(r, u, v, s, src0, 1, signedScaling); |
| 4780 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4781 | r.w_ = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4782 | |
| 4783 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4784 | } |
| 4785 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4786 | void PixelRoutine::TEXM3X3(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4787 | { |
| 4788 | TEXM3X3PAD(r, u, v, s, src0, 2, signedScaling); |
| 4789 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4790 | dst.x = RoundShort4(r.u_ * Float4(0x1000)); |
| 4791 | dst.y = RoundShort4(r.v_ * Float4(0x1000)); |
| 4792 | dst.z = RoundShort4(r.w_ * Float4(0x1000)); |
| 4793 | dst.w = Short4(0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4794 | } |
| 4795 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4796 | void PixelRoutine::TEXM3X3PAD(Registers &r, Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, int component, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4797 | { |
| 4798 | if(component == 0 || previousScaling != signedScaling) // FIXME: Other source modifiers? |
| 4799 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4800 | r.U = Float4(src0.x); |
| 4801 | r.V = Float4(src0.y); |
| 4802 | r.W = Float4(src0.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4803 | |
| 4804 | previousScaling = signedScaling; |
| 4805 | } |
| 4806 | |
| 4807 | Float4 x = r.U * u + r.V * v + r.W * s; |
| 4808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4809 | x *= Float4(1.0f / 0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4810 | |
| 4811 | switch(component) |
| 4812 | { |
| 4813 | case 0: r.u_ = x; break; |
| 4814 | case 1: r.v_ = x; break; |
| 4815 | case 2: r.w_ = x; break; |
| 4816 | default: ASSERT(false); |
| 4817 | } |
| 4818 | } |
| 4819 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4820 | void PixelRoutine::TEXM3X3SPEC(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, Vector4s &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4821 | { |
| 4822 | TEXM3X3PAD(r, u, v, s, src0, 2, false); |
| 4823 | |
| 4824 | Float4 E[3]; // Eye vector |
| 4825 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4826 | E[0] = Float4(src1.x) * Float4(1.0f / 0x0FFE); |
| 4827 | E[1] = Float4(src1.y) * Float4(1.0f / 0x0FFE); |
| 4828 | E[2] = Float4(src1.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4829 | |
| 4830 | // Reflection |
| 4831 | Float4 u__; |
| 4832 | Float4 v__; |
| 4833 | Float4 w__; |
| 4834 | |
| 4835 | // (u'', v'', w'') = 2 * (N . E) * N - E * (N . N) |
| 4836 | u__ = r.u_ * E[0]; |
| 4837 | v__ = r.v_ * E[1]; |
| 4838 | w__ = r.w_ * E[2]; |
| 4839 | u__ += v__ + w__; |
| 4840 | u__ += u__; |
| 4841 | v__ = u__; |
| 4842 | w__ = u__; |
| 4843 | u__ *= r.u_; |
| 4844 | v__ *= r.v_; |
| 4845 | w__ *= r.w_; |
| 4846 | r.u_ *= r.u_; |
| 4847 | r.v_ *= r.v_; |
| 4848 | r.w_ *= r.w_; |
| 4849 | r.u_ += r.v_ + r.w_; |
| 4850 | u__ -= E[0] * r.u_; |
| 4851 | v__ -= E[1] * r.u_; |
| 4852 | w__ -= E[2] * r.u_; |
| 4853 | |
| 4854 | sampleTexture(r, dst, stage, u__, v__, w__, w__); |
| 4855 | } |
| 4856 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4857 | void PixelRoutine::TEXM3X3TEX(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4858 | { |
| 4859 | TEXM3X3PAD(r, u, v, s, src0, 2, signedScaling); |
| 4860 | |
| 4861 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4862 | } |
| 4863 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4864 | void PixelRoutine::TEXM3X3VSPEC(Registers &r, Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4865 | { |
| 4866 | TEXM3X3PAD(r, u, v, s, src0, 2, false); |
| 4867 | |
| 4868 | Float4 E[3]; // Eye vector |
| 4869 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4870 | E[0] = r.vf[2 + stage - 2].w; |
| 4871 | E[1] = r.vf[2 + stage - 1].w; |
| 4872 | E[2] = r.vf[2 + stage - 0].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4873 | |
| 4874 | // Reflection |
| 4875 | Float4 u__; |
| 4876 | Float4 v__; |
| 4877 | Float4 w__; |
| 4878 | |
| 4879 | // (u'', v'', w'') = 2 * (N . E) * N - E * (N . N) |
| 4880 | u__ = r.u_ * E[0]; |
| 4881 | v__ = r.v_ * E[1]; |
| 4882 | w__ = r.w_ * E[2]; |
| 4883 | u__ += v__ + w__; |
| 4884 | u__ += u__; |
| 4885 | v__ = u__; |
| 4886 | w__ = u__; |
| 4887 | u__ *= r.u_; |
| 4888 | v__ *= r.v_; |
| 4889 | w__ *= r.w_; |
| 4890 | r.u_ *= r.u_; |
| 4891 | r.v_ *= r.v_; |
| 4892 | r.w_ *= r.w_; |
| 4893 | r.u_ += r.v_ + r.w_; |
| 4894 | u__ -= E[0] * r.u_; |
| 4895 | v__ -= E[1] * r.u_; |
| 4896 | w__ -= E[2] * r.u_; |
| 4897 | |
| 4898 | sampleTexture(r, dst, stage, u__, v__, w__, w__); |
| 4899 | } |
| 4900 | |
| 4901 | void PixelRoutine::TEXDEPTH(Registers &r) |
| 4902 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4903 | r.u_ = Float4(r.rs[5].x); |
| 4904 | r.v_ = Float4(r.rs[5].y); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4905 | |
| 4906 | // z / w |
| 4907 | r.u_ *= Rcp_pp(r.v_); // FIXME: Set result to 1.0 when division by zero |
| 4908 | |
| 4909 | r.oDepth = r.u_; |
| 4910 | } |
| 4911 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4912 | void PixelRoutine::CND(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4913 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4914 | {Short4 t0; t0 = src0.x; t0 = CmpGT(t0, Short4(0x0800, 0x0800, 0x0800, 0x0800)); Short4 t1; t1 = src1.x; t1 = t1 & t0; t0 = ~t0 & src2.x; t0 = t0 | t1; dst.x = t0;}; |
| 4915 | {Short4 t0; t0 = src0.y; t0 = CmpGT(t0, Short4(0x0800, 0x0800, 0x0800, 0x0800)); Short4 t1; t1 = src1.y; t1 = t1 & t0; t0 = ~t0 & src2.y; t0 = t0 | t1; dst.y = t0;}; |
| 4916 | {Short4 t0; t0 = src0.z; t0 = CmpGT(t0, Short4(0x0800, 0x0800, 0x0800, 0x0800)); Short4 t1; t1 = src1.z; t1 = t1 & t0; t0 = ~t0 & src2.z; t0 = t0 | t1; dst.z = t0;}; |
| 4917 | {Short4 t0; t0 = src0.w; t0 = CmpGT(t0, Short4(0x0800, 0x0800, 0x0800, 0x0800)); Short4 t1; t1 = src1.w; t1 = t1 & t0; t0 = ~t0 & src2.w; t0 = t0 | t1; dst.w = t0;}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4918 | } |
| 4919 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4920 | void PixelRoutine::CMP(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4921 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4922 | {Short4 t0 = CmpGT(Short4(0x0000, 0x0000, 0x0000, 0x0000), src0.x); Short4 t1; t1 = src2.x; t1 &= t0; t0 = ~t0 & src1.x; t0 |= t1; dst.x = t0;}; |
| 4923 | {Short4 t0 = CmpGT(Short4(0x0000, 0x0000, 0x0000, 0x0000), src0.y); Short4 t1; t1 = src2.y; t1 &= t0; t0 = ~t0 & src1.y; t0 |= t1; dst.y = t0;}; |
| 4924 | {Short4 t0 = CmpGT(Short4(0x0000, 0x0000, 0x0000, 0x0000), src0.z); Short4 t1; t1 = src2.z; t1 &= t0; t0 = ~t0 & src1.z; t0 |= t1; dst.z = t0;}; |
| 4925 | {Short4 t0 = CmpGT(Short4(0x0000, 0x0000, 0x0000, 0x0000), src0.w); Short4 t1; t1 = src2.w; t1 &= t0; t0 = ~t0 & src1.w; t0 |= t1; dst.w = t0;}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4926 | } |
| 4927 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4928 | void PixelRoutine::BEM(Registers &r, Vector4s &dst, Vector4s &src0, Vector4s &src1, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4929 | { |
| 4930 | Short4 t0; |
| 4931 | Short4 t1; |
| 4932 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4933 | // dst.x = src0.x + BUMPENVMAT00(stage) * src1.x + BUMPENVMAT10(stage) * src1.y |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4934 | t0 = MulHigh(src1.x, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[0][0]))); t0 = t0 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4935 | t1 = MulHigh(src1.y, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[1][0]))); t1 = t1 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4936 | t0 = AddSat(t0, t1); |
| 4937 | t0 = AddSat(t0, src0.x); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4938 | dst.x = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4939 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4940 | // dst.y = src0.y + BUMPENVMAT01(stage) * src1.x + BUMPENVMAT11(stage) * src1.y |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4941 | t0 = MulHigh(src1.x, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[0][1]))); t0 = t0 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4942 | t1 = MulHigh(src1.y, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[1][1]))); t1 = t1 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4943 | t0 = AddSat(t0, t1); |
| 4944 | t0 = AddSat(t0, src0.y); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4945 | dst.y = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4946 | } |
| 4947 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4948 | void PixelRoutine::M3X2(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4949 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4950 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 4951 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4952 | |
| 4953 | dst.x = dot3(src0, row0); |
| 4954 | dst.y = dot3(src0, row1); |
| 4955 | } |
| 4956 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4957 | void PixelRoutine::M3X3(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4958 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4959 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 4960 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
| 4961 | Vector4f row2 = fetchRegisterF(r, src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4962 | |
| 4963 | dst.x = dot3(src0, row0); |
| 4964 | dst.y = dot3(src0, row1); |
| 4965 | dst.z = dot3(src0, row2); |
| 4966 | } |
| 4967 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4968 | void PixelRoutine::M3X4(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4969 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4970 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 4971 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
| 4972 | Vector4f row2 = fetchRegisterF(r, src1, 2); |
| 4973 | Vector4f row3 = fetchRegisterF(r, src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4974 | |
| 4975 | dst.x = dot3(src0, row0); |
| 4976 | dst.y = dot3(src0, row1); |
| 4977 | dst.z = dot3(src0, row2); |
| 4978 | dst.w = dot3(src0, row3); |
| 4979 | } |
| 4980 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4981 | void PixelRoutine::M4X3(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4982 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4983 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 4984 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
| 4985 | Vector4f row2 = fetchRegisterF(r, src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4986 | |
| 4987 | dst.x = dot4(src0, row0); |
| 4988 | dst.y = dot4(src0, row1); |
| 4989 | dst.z = dot4(src0, row2); |
| 4990 | } |
| 4991 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4992 | void PixelRoutine::M4X4(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4993 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 4994 | Vector4f row0 = fetchRegisterF(r, src1, 0); |
| 4995 | Vector4f row1 = fetchRegisterF(r, src1, 1); |
| 4996 | Vector4f row2 = fetchRegisterF(r, src1, 2); |
| 4997 | Vector4f row3 = fetchRegisterF(r, src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4998 | |
| 4999 | dst.x = dot4(src0, row0); |
| 5000 | dst.y = dot4(src0, row1); |
| 5001 | dst.z = dot4(src0, row2); |
| 5002 | dst.w = dot4(src0, row3); |
| 5003 | } |
| 5004 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5005 | void PixelRoutine::TEXLD(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1, bool project, bool bias) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5006 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5007 | Vector4f tmp; |
| 5008 | sampleTexture(r, tmp, src1, src0.x, src0.y, src0.z, src0.w, src0, src0, project, bias); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5009 | |
| 5010 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 5011 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 5012 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 5013 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 5014 | } |
| 5015 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5016 | void PixelRoutine::TEXLDD(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, Vector4f &src3, bool project, bool bias) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5017 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5018 | Vector4f tmp; |
| 5019 | sampleTexture(r, tmp, src1, src0.x, src0.y, src0.z, src0.w, src2, src3, project, bias, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5020 | |
| 5021 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 5022 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 5023 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 5024 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 5025 | } |
| 5026 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5027 | void PixelRoutine::TEXLDL(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1, bool project, bool bias) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5028 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5029 | Vector4f tmp; |
| 5030 | sampleTexture(r, tmp, src1, src0.x, src0.y, src0.z, src0.w, src0, src0, project, bias, false, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5031 | |
| 5032 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 5033 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 5034 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 5035 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 5036 | } |
| 5037 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5038 | void PixelRoutine::TEXKILL(Int cMask[4], Vector4f &src, unsigned char mask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5039 | { |
| 5040 | Int kill = -1; |
| 5041 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5042 | if(mask & 0x1) kill &= SignMask(CmpNLT(src.x, Float4(0.0f))); |
| 5043 | if(mask & 0x2) kill &= SignMask(CmpNLT(src.y, Float4(0.0f))); |
| 5044 | if(mask & 0x4) kill &= SignMask(CmpNLT(src.z, Float4(0.0f))); |
| 5045 | if(mask & 0x8) kill &= SignMask(CmpNLT(src.w, Float4(0.0f))); |
| 5046 | |
| 5047 | // FIXME: Dynamic branching affects TEXKILL? |
| 5048 | // if(shader->containsDynamicBranching()) |
| 5049 | // { |
| 5050 | // kill = ~SignMask(enableMask(r)); |
| 5051 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5052 | |
| 5053 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 5054 | { |
| 5055 | cMask[q] &= kill; |
| 5056 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5057 | |
| 5058 | // FIXME: Branch to end of shader if all killed? |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5059 | } |
| 5060 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5061 | void PixelRoutine::DISCARD(Registers &r, Int cMask[4], const Shader::Instruction *instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5062 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5063 | Int kill = 0; |
| 5064 | |
| 5065 | if(shader->containsDynamicBranching()) |
| 5066 | { |
| 5067 | kill = ~SignMask(enableMask(r, instruction)); |
| 5068 | } |
| 5069 | |
| 5070 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 5071 | { |
| 5072 | cMask[q] &= kill; |
| 5073 | } |
| 5074 | |
| 5075 | // FIXME: Branch to end of shader if all killed? |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5076 | } |
| 5077 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5078 | void PixelRoutine::DFDX(Vector4f &dst, Vector4f &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5079 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5080 | dst.x = src.x.yyww - src.x.xxzz; |
| 5081 | dst.y = src.y.yyww - src.y.xxzz; |
| 5082 | dst.z = src.z.yyww - src.z.xxzz; |
| 5083 | dst.w = src.w.yyww - src.w.xxzz; |
| 5084 | } |
| 5085 | |
| 5086 | void PixelRoutine::DFDY(Vector4f &dst, Vector4f &src) |
| 5087 | { |
| 5088 | dst.x = src.x.zwzw - src.x.xyxy; |
| 5089 | dst.y = src.y.zwzw - src.y.xyxy; |
| 5090 | dst.z = src.z.zwzw - src.z.xyxy; |
| 5091 | dst.w = src.w.zwzw - src.w.xyxy; |
| 5092 | } |
| 5093 | |
| 5094 | void PixelRoutine::FWIDTH(Vector4f &dst, Vector4f &src) |
| 5095 | { |
| 5096 | // abs(dFdx(src)) + abs(dFdy(src)); |
| 5097 | dst.x = Abs(src.x.yyww - src.x.xxzz) + Abs(src.x.zwzw - src.x.xyxy); |
| 5098 | dst.y = Abs(src.y.yyww - src.x.xxzz) + Abs(src.y.zwzw - src.y.xyxy); |
| 5099 | dst.z = Abs(src.z.yyww - src.x.xxzz) + Abs(src.z.zwzw - src.z.xyxy); |
| 5100 | dst.w = Abs(src.w.yyww - src.x.xxzz) + Abs(src.w.zwzw - src.w.xyxy); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | void PixelRoutine::BREAK(Registers &r) |
| 5104 | { |
| 5105 | llvm::BasicBlock *deadBlock = Nucleus::createBasicBlock(); |
| 5106 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1]; |
| 5107 | |
| 5108 | if(breakDepth == 0) |
| 5109 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5110 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5111 | Nucleus::createBr(endBlock); |
| 5112 | } |
| 5113 | else |
| 5114 | { |
| 5115 | r.enableBreak = r.enableBreak & ~r.enableStack[r.enableIndex]; |
| 5116 | Bool allBreak = SignMask(r.enableBreak) == 0x0; |
| 5117 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5118 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5119 | branch(allBreak, endBlock, deadBlock); |
| 5120 | } |
| 5121 | |
| 5122 | Nucleus::setInsertBlock(deadBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5123 | r.enableIndex = r.enableIndex + breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5124 | } |
| 5125 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5126 | void PixelRoutine::BREAKC(Registers &r, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5127 | { |
| 5128 | Int4 condition; |
| 5129 | |
| 5130 | switch(control) |
| 5131 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5132 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 5133 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 5134 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 5135 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 5136 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 5137 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5138 | default: |
| 5139 | ASSERT(false); |
| 5140 | } |
| 5141 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5142 | BREAK(r, condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | void PixelRoutine::BREAKP(Registers &r, const Src &predicateRegister) // FIXME: Factor out parts common with BREAKC |
| 5146 | { |
| 5147 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 5148 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5149 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5150 | { |
| 5151 | condition = ~condition; |
| 5152 | } |
| 5153 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5154 | BREAK(r, condition); |
| 5155 | } |
| 5156 | |
| 5157 | void PixelRoutine::BREAK(Registers &r, Int4 &condition) |
| 5158 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5159 | condition &= r.enableStack[r.enableIndex]; |
| 5160 | |
| 5161 | llvm::BasicBlock *continueBlock = Nucleus::createBasicBlock(); |
| 5162 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1]; |
| 5163 | |
| 5164 | r.enableBreak = r.enableBreak & ~condition; |
| 5165 | Bool allBreak = SignMask(r.enableBreak) == 0x0; |
| 5166 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5167 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5168 | branch(allBreak, endBlock, continueBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5169 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5170 | Nucleus::setInsertBlock(continueBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5171 | r.enableIndex = r.enableIndex + breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5172 | } |
| 5173 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5174 | void PixelRoutine::CONTINUE(Registers &r) |
| 5175 | { |
| 5176 | r.enableContinue = r.enableContinue & ~r.enableStack[r.enableIndex]; |
| 5177 | } |
| 5178 | |
| 5179 | void PixelRoutine::TEST() |
| 5180 | { |
| 5181 | whileTest = true; |
| 5182 | } |
| 5183 | |
| 5184 | void PixelRoutine::CALL(Registers &r, int labelIndex, int callSiteIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5185 | { |
| 5186 | if(!labelBlock[labelIndex]) |
| 5187 | { |
| 5188 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5189 | } |
| 5190 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5191 | if(callRetBlock[labelIndex].size() > 1) |
| 5192 | { |
| 5193 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5194 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5195 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5196 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5197 | |
| 5198 | Nucleus::createBr(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5199 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 5200 | |
| 5201 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5202 | } |
| 5203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5204 | void PixelRoutine::CALLNZ(Registers &r, int labelIndex, int callSiteIndex, const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5205 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5206 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5207 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5208 | CALLNZb(r, labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5209 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5210 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5211 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5212 | CALLNZp(r, labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5213 | } |
| 5214 | else ASSERT(false); |
| 5215 | } |
| 5216 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5217 | void PixelRoutine::CALLNZb(Registers &r, int labelIndex, int callSiteIndex, const Src &boolRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5218 | { |
| 5219 | Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,ps.b[boolRegister.index])) != Byte(0)); // FIXME |
| 5220 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5221 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5222 | { |
| 5223 | condition = !condition; |
| 5224 | } |
| 5225 | |
| 5226 | if(!labelBlock[labelIndex]) |
| 5227 | { |
| 5228 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5229 | } |
| 5230 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5231 | if(callRetBlock[labelIndex].size() > 1) |
| 5232 | { |
| 5233 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5234 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5235 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5236 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5237 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5238 | branch(condition, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 5239 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 5240 | |
| 5241 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5242 | } |
| 5243 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5244 | void PixelRoutine::CALLNZp(Registers &r, int labelIndex, int callSiteIndex, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5245 | { |
| 5246 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 5247 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5248 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5249 | { |
| 5250 | condition = ~condition; |
| 5251 | } |
| 5252 | |
| 5253 | condition &= r.enableStack[r.enableIndex]; |
| 5254 | |
| 5255 | if(!labelBlock[labelIndex]) |
| 5256 | { |
| 5257 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5258 | } |
| 5259 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5260 | if(callRetBlock[labelIndex].size() > 1) |
| 5261 | { |
| 5262 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5263 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5264 | |
| 5265 | r.enableIndex++; |
| 5266 | r.enableStack[r.enableIndex] = condition; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5267 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5268 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5269 | Bool notAllFalse = SignMask(condition) != 0; |
| 5270 | branch(notAllFalse, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 5271 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5272 | |
| 5273 | r.enableIndex--; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5274 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | void PixelRoutine::ELSE(Registers &r) |
| 5278 | { |
| 5279 | ifDepth--; |
| 5280 | |
| 5281 | llvm::BasicBlock *falseBlock = ifFalseBlock[ifDepth]; |
| 5282 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5283 | |
| 5284 | if(isConditionalIf[ifDepth]) |
| 5285 | { |
| 5286 | Int4 condition = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5287 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5288 | |
| 5289 | branch(notAllFalse, falseBlock, endBlock); |
| 5290 | |
| 5291 | r.enableStack[r.enableIndex] = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1]; |
| 5292 | } |
| 5293 | else |
| 5294 | { |
| 5295 | Nucleus::createBr(endBlock); |
| 5296 | Nucleus::setInsertBlock(falseBlock); |
| 5297 | } |
| 5298 | |
| 5299 | ifFalseBlock[ifDepth] = endBlock; |
| 5300 | |
| 5301 | ifDepth++; |
| 5302 | } |
| 5303 | |
| 5304 | void PixelRoutine::ENDIF(Registers &r) |
| 5305 | { |
| 5306 | ifDepth--; |
| 5307 | |
| 5308 | llvm::BasicBlock *endBlock = ifFalseBlock[ifDepth]; |
| 5309 | |
| 5310 | Nucleus::createBr(endBlock); |
| 5311 | Nucleus::setInsertBlock(endBlock); |
| 5312 | |
| 5313 | if(isConditionalIf[ifDepth]) |
| 5314 | { |
| 5315 | breakDepth--; |
| 5316 | r.enableIndex--; |
| 5317 | } |
| 5318 | } |
| 5319 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5320 | void PixelRoutine::ENDLOOP(Registers &r) |
| 5321 | { |
| 5322 | loopRepDepth--; |
| 5323 | |
| 5324 | r.aL[r.loopDepth] = r.aL[r.loopDepth] + r.increment[r.loopDepth]; // FIXME: += |
| 5325 | |
| 5326 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5327 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5328 | |
| 5329 | Nucleus::createBr(testBlock); |
| 5330 | Nucleus::setInsertBlock(endBlock); |
| 5331 | |
| 5332 | r.loopDepth--; |
| 5333 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5334 | } |
| 5335 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5336 | void PixelRoutine::ENDREP(Registers &r) |
| 5337 | { |
| 5338 | loopRepDepth--; |
| 5339 | |
| 5340 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5341 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5342 | |
| 5343 | Nucleus::createBr(testBlock); |
| 5344 | Nucleus::setInsertBlock(endBlock); |
| 5345 | |
| 5346 | r.loopDepth--; |
| 5347 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5348 | } |
| 5349 | |
| 5350 | void PixelRoutine::ENDWHILE(Registers &r) |
| 5351 | { |
| 5352 | loopRepDepth--; |
| 5353 | |
| 5354 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5355 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5356 | |
| 5357 | Nucleus::createBr(testBlock); |
| 5358 | Nucleus::setInsertBlock(endBlock); |
| 5359 | |
| 5360 | r.enableIndex--; |
| 5361 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5362 | whileTest = false; |
| 5363 | } |
| 5364 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5365 | void PixelRoutine::IF(Registers &r, const Src &src) |
| 5366 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5367 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5368 | { |
| 5369 | IFb(r, src); |
| 5370 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5371 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5372 | { |
| 5373 | IFp(r, src); |
| 5374 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5375 | else |
| 5376 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5377 | Int4 condition = As<Int4>(fetchRegisterF(r, src).x); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5378 | IF(r, condition); |
| 5379 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | void PixelRoutine::IFb(Registers &r, const Src &boolRegister) |
| 5383 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5384 | ASSERT(ifDepth < 24 + 4); |
| 5385 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5386 | Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,ps.b[boolRegister.index])) != Byte(0)); // FIXME |
| 5387 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5388 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5389 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5390 | condition = !condition; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 5394 | llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
| 5395 | |
| 5396 | branch(condition, trueBlock, falseBlock); |
| 5397 | |
| 5398 | isConditionalIf[ifDepth] = false; |
| 5399 | ifFalseBlock[ifDepth] = falseBlock; |
| 5400 | |
| 5401 | ifDepth++; |
| 5402 | } |
| 5403 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5404 | void PixelRoutine::IFp(Registers &r, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5405 | { |
| 5406 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 5407 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5408 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5409 | { |
| 5410 | condition = ~condition; |
| 5411 | } |
| 5412 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5413 | IF(r, condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5414 | } |
| 5415 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5416 | void PixelRoutine::IFC(Registers &r, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5417 | { |
| 5418 | Int4 condition; |
| 5419 | |
| 5420 | switch(control) |
| 5421 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5422 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 5423 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 5424 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 5425 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 5426 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 5427 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5428 | default: |
| 5429 | ASSERT(false); |
| 5430 | } |
| 5431 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5432 | IF(r, condition); |
| 5433 | } |
| 5434 | |
| 5435 | void PixelRoutine::IF(Registers &r, Int4 &condition) |
| 5436 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5437 | condition &= r.enableStack[r.enableIndex]; |
| 5438 | |
| 5439 | r.enableIndex++; |
| 5440 | r.enableStack[r.enableIndex] = condition; |
| 5441 | |
| 5442 | llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 5443 | llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
| 5444 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5445 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5446 | |
| 5447 | branch(notAllFalse, trueBlock, falseBlock); |
| 5448 | |
| 5449 | isConditionalIf[ifDepth] = true; |
| 5450 | ifFalseBlock[ifDepth] = falseBlock; |
| 5451 | |
| 5452 | ifDepth++; |
| 5453 | breakDepth++; |
| 5454 | } |
| 5455 | |
| 5456 | void PixelRoutine::LABEL(int labelIndex) |
| 5457 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5458 | if(!labelBlock[labelIndex]) |
| 5459 | { |
| 5460 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5461 | } |
| 5462 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5463 | Nucleus::setInsertBlock(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5464 | currentLabel = labelIndex; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | void PixelRoutine::LOOP(Registers &r, const Src &integerRegister) |
| 5468 | { |
| 5469 | r.loopDepth++; |
| 5470 | |
| 5471 | r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][0])); |
| 5472 | r.aL[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][1])); |
| 5473 | r.increment[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][2])); |
| 5474 | |
| 5475 | // If(r.increment[r.loopDepth] == 0) |
| 5476 | // { |
| 5477 | // r.increment[r.loopDepth] = 1; |
| 5478 | // } |
| 5479 | |
| 5480 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5481 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5482 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5483 | |
| 5484 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5485 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5486 | |
| 5487 | // FIXME: jump(testBlock) |
| 5488 | Nucleus::createBr(testBlock); |
| 5489 | Nucleus::setInsertBlock(testBlock); |
| 5490 | |
| 5491 | branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock); |
| 5492 | Nucleus::setInsertBlock(loopBlock); |
| 5493 | |
| 5494 | r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1; // FIXME: -- |
| 5495 | |
| 5496 | loopRepDepth++; |
| 5497 | breakDepth = 0; |
| 5498 | } |
| 5499 | |
| 5500 | void PixelRoutine::REP(Registers &r, const Src &integerRegister) |
| 5501 | { |
| 5502 | r.loopDepth++; |
| 5503 | |
| 5504 | r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][0])); |
| 5505 | r.aL[r.loopDepth] = r.aL[r.loopDepth - 1]; |
| 5506 | |
| 5507 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5508 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5509 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5510 | |
| 5511 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5512 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5513 | |
| 5514 | // FIXME: jump(testBlock) |
| 5515 | Nucleus::createBr(testBlock); |
| 5516 | Nucleus::setInsertBlock(testBlock); |
| 5517 | |
| 5518 | branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock); |
| 5519 | Nucleus::setInsertBlock(loopBlock); |
| 5520 | |
| 5521 | r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1; // FIXME: -- |
| 5522 | |
| 5523 | loopRepDepth++; |
| 5524 | breakDepth = 0; |
| 5525 | } |
| 5526 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5527 | void PixelRoutine::WHILE(Registers &r, const Src &temporaryRegister) |
| 5528 | { |
| 5529 | r.enableIndex++; |
| 5530 | |
| 5531 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5532 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5533 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5534 | |
| 5535 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5536 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5537 | |
| 5538 | Int4 restoreBreak = r.enableBreak; |
| 5539 | Int4 restoreContinue = r.enableContinue; |
| 5540 | |
| 5541 | // FIXME: jump(testBlock) |
| 5542 | Nucleus::createBr(testBlock); |
| 5543 | Nucleus::setInsertBlock(testBlock); |
| 5544 | r.enableContinue = restoreContinue; |
| 5545 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5546 | const Vector4f &src = fetchRegisterF(r, temporaryRegister); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5547 | Int4 condition = As<Int4>(src.x); |
| 5548 | condition &= r.enableStack[r.enableIndex - 1]; |
| 5549 | r.enableStack[r.enableIndex] = condition; |
| 5550 | |
| 5551 | Bool notAllFalse = SignMask(condition) != 0; |
| 5552 | branch(notAllFalse, loopBlock, endBlock); |
| 5553 | |
| 5554 | Nucleus::setInsertBlock(endBlock); |
| 5555 | r.enableBreak = restoreBreak; |
| 5556 | |
| 5557 | Nucleus::setInsertBlock(loopBlock); |
| 5558 | |
| 5559 | loopRepDepth++; |
| 5560 | breakDepth = 0; |
| 5561 | } |
| 5562 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5563 | void PixelRoutine::RET(Registers &r) |
| 5564 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5565 | if(currentLabel == -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5566 | { |
| 5567 | returnBlock = Nucleus::createBasicBlock(); |
| 5568 | Nucleus::createBr(returnBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5569 | } |
| 5570 | else |
| 5571 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5572 | llvm::BasicBlock *unreachableBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5573 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5574 | 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] | 5575 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5576 | // FIXME: Encapsulate |
| 5577 | UInt index = r.callStack[--r.stackIndex]; |
| 5578 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5579 | llvm::Value *value = index.loadValue(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5580 | llvm::Value *switchInst = Nucleus::createSwitch(value, unreachableBlock, (int)callRetBlock[currentLabel].size()); |
| 5581 | |
| 5582 | for(unsigned int i = 0; i < callRetBlock[currentLabel].size(); i++) |
| 5583 | { |
| 5584 | Nucleus::addSwitchCase(switchInst, i, callRetBlock[currentLabel][i]); |
| 5585 | } |
| 5586 | } |
| 5587 | else if(callRetBlock[currentLabel].size() == 1) // Jump directly to the unique return destination |
| 5588 | { |
| 5589 | Nucleus::createBr(callRetBlock[currentLabel][0]); |
| 5590 | } |
| 5591 | else // Function isn't called |
| 5592 | { |
| 5593 | Nucleus::createBr(unreachableBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | Nucleus::setInsertBlock(unreachableBlock); |
| 5597 | Nucleus::createUnreachable(); |
| 5598 | } |
| 5599 | } |
| 5600 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5601 | void PixelRoutine::LEAVE(Registers &r) |
| 5602 | { |
| 5603 | r.enableLeave = r.enableLeave & ~r.enableStack[r.enableIndex]; |
| 5604 | |
| 5605 | // FIXME: Return from function if all instances left |
| 5606 | // FIXME: Use enableLeave in other control-flow constructs |
| 5607 | } |
| 5608 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5609 | void PixelRoutine::writeDestination(Registers &r, Vector4s &d, const Dst &dst) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5610 | { |
| 5611 | switch(dst.type) |
| 5612 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5613 | case Shader::PARAMETER_TEMP: |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5614 | if(dst.mask & 0x1) r.rs[dst.index].x = d.x; |
| 5615 | if(dst.mask & 0x2) r.rs[dst.index].y = d.y; |
| 5616 | if(dst.mask & 0x4) r.rs[dst.index].z = d.z; |
| 5617 | if(dst.mask & 0x8) r.rs[dst.index].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5618 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5619 | case Shader::PARAMETER_INPUT: |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5620 | if(dst.mask & 0x1) r.vs[dst.index].x = d.x; |
| 5621 | if(dst.mask & 0x2) r.vs[dst.index].y = d.y; |
| 5622 | if(dst.mask & 0x4) r.vs[dst.index].z = d.z; |
| 5623 | if(dst.mask & 0x8) r.vs[dst.index].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5624 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5625 | case Shader::PARAMETER_CONST: ASSERT(false); break; |
| 5626 | case Shader::PARAMETER_TEXTURE: |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5627 | if(dst.mask & 0x1) r.ts[dst.index].x = d.x; |
| 5628 | if(dst.mask & 0x2) r.ts[dst.index].y = d.y; |
| 5629 | if(dst.mask & 0x4) r.ts[dst.index].z = d.z; |
| 5630 | if(dst.mask & 0x8) r.ts[dst.index].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5631 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5632 | case Shader::PARAMETER_COLOROUT: |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5633 | if(dst.mask & 0x1) r.vs[dst.index].x = d.x; |
| 5634 | if(dst.mask & 0x2) r.vs[dst.index].y = d.y; |
| 5635 | if(dst.mask & 0x4) r.vs[dst.index].z = d.z; |
| 5636 | if(dst.mask & 0x8) r.vs[dst.index].w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5637 | break; |
| 5638 | default: |
| 5639 | ASSERT(false); |
| 5640 | } |
| 5641 | } |
| 5642 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5643 | Vector4s PixelRoutine::fetchRegisterS(Registers &r, const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5644 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5645 | Vector4s *reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5646 | int i = src.index; |
| 5647 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5648 | Vector4s c; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5649 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5650 | if(src.type == Shader::PARAMETER_CONST) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5651 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5652 | c.x = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][0])); |
| 5653 | c.y = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][1])); |
| 5654 | c.z = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][2])); |
| 5655 | c.w = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | switch(src.type) |
| 5659 | { |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5660 | case Shader::PARAMETER_TEMP: reg = &r.rs[i]; break; |
| 5661 | case Shader::PARAMETER_INPUT: reg = &r.vs[i]; break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5662 | case Shader::PARAMETER_CONST: reg = &c; break; |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5663 | case Shader::PARAMETER_TEXTURE: reg = &r.ts[i]; break; |
| 5664 | case Shader::PARAMETER_VOID: return r.rs[0]; // Dummy |
| 5665 | case Shader::PARAMETER_FLOAT4LITERAL: return r.rs[0]; // Dummy |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5666 | default: |
| 5667 | ASSERT(false); |
| 5668 | } |
| 5669 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5670 | const Short4 &x = (*reg)[(src.swizzle >> 0) & 0x3]; |
| 5671 | const Short4 &y = (*reg)[(src.swizzle >> 2) & 0x3]; |
| 5672 | const Short4 &z = (*reg)[(src.swizzle >> 4) & 0x3]; |
| 5673 | const Short4 &w = (*reg)[(src.swizzle >> 6) & 0x3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5674 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5675 | Vector4s mod; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5676 | |
| 5677 | switch(src.modifier) |
| 5678 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5679 | case Shader::MODIFIER_NONE: |
| 5680 | mod.x = x; |
| 5681 | mod.y = y; |
| 5682 | mod.z = z; |
| 5683 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5684 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5685 | case Shader::MODIFIER_BIAS: |
| 5686 | mod.x = SubSat(x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5687 | mod.y = SubSat(y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5688 | mod.z = SubSat(z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5689 | mod.w = SubSat(w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5690 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5691 | case Shader::MODIFIER_BIAS_NEGATE: |
| 5692 | mod.x = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), x); |
| 5693 | mod.y = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), y); |
| 5694 | mod.z = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), z); |
| 5695 | mod.w = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5696 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5697 | case Shader::MODIFIER_COMPLEMENT: |
| 5698 | mod.x = SubSat(Short4(0x1000), x); |
| 5699 | mod.y = SubSat(Short4(0x1000), y); |
| 5700 | mod.z = SubSat(Short4(0x1000), z); |
| 5701 | mod.w = SubSat(Short4(0x1000), w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5702 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5703 | case Shader::MODIFIER_NEGATE: |
| 5704 | mod.x = -x; |
| 5705 | mod.y = -y; |
| 5706 | mod.z = -z; |
| 5707 | mod.w = -w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5708 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5709 | case Shader::MODIFIER_X2: |
| 5710 | mod.x = AddSat(x, x); |
| 5711 | mod.y = AddSat(y, y); |
| 5712 | mod.z = AddSat(z, z); |
| 5713 | mod.w = AddSat(w, w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5714 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5715 | case Shader::MODIFIER_X2_NEGATE: |
| 5716 | mod.x = -AddSat(x, x); |
| 5717 | mod.y = -AddSat(y, y); |
| 5718 | mod.z = -AddSat(z, z); |
| 5719 | mod.w = -AddSat(w, w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5720 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5721 | case Shader::MODIFIER_SIGN: |
| 5722 | mod.x = SubSat(x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5723 | mod.y = SubSat(y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5724 | mod.z = SubSat(z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5725 | mod.w = SubSat(w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5726 | mod.x = AddSat(mod.x, mod.x); |
| 5727 | mod.y = AddSat(mod.y, mod.y); |
| 5728 | mod.z = AddSat(mod.z, mod.z); |
| 5729 | mod.w = AddSat(mod.w, mod.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5730 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5731 | case Shader::MODIFIER_SIGN_NEGATE: |
| 5732 | mod.x = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), x); |
| 5733 | mod.y = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), y); |
| 5734 | mod.z = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), z); |
| 5735 | mod.w = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), w); |
| 5736 | mod.x = AddSat(mod.x, mod.x); |
| 5737 | mod.y = AddSat(mod.y, mod.y); |
| 5738 | mod.z = AddSat(mod.z, mod.z); |
| 5739 | mod.w = AddSat(mod.w, mod.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5740 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5741 | case Shader::MODIFIER_DZ: |
| 5742 | mod.x = x; |
| 5743 | mod.y = y; |
| 5744 | mod.z = z; |
| 5745 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5746 | // Projection performed by texture sampler |
| 5747 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5748 | case Shader::MODIFIER_DW: |
| 5749 | mod.x = x; |
| 5750 | mod.y = y; |
| 5751 | mod.z = z; |
| 5752 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5753 | // Projection performed by texture sampler |
| 5754 | break; |
| 5755 | default: |
| 5756 | ASSERT(false); |
| 5757 | } |
| 5758 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5759 | if(src.type == Shader::PARAMETER_CONST && (src.modifier == Shader::MODIFIER_X2 || src.modifier == Shader::MODIFIER_X2_NEGATE)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5760 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5761 | mod.x = Min(mod.x, Short4(0x1000)); mod.x = Max(mod.x, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5762 | mod.y = Min(mod.y, Short4(0x1000)); mod.y = Max(mod.y, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5763 | mod.z = Min(mod.z, Short4(0x1000)); mod.z = Max(mod.z, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5764 | mod.w = Min(mod.w, Short4(0x1000)); mod.w = Max(mod.w, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | return mod; |
| 5768 | } |
| 5769 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 5770 | Vector4f PixelRoutine::fetchRegisterF(Registers &r, const Src &src, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5771 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5772 | Vector4f reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5773 | int i = src.index + offset; |
| 5774 | |
| 5775 | switch(src.type) |
| 5776 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5777 | case Shader::PARAMETER_TEMP: |
| 5778 | if(src.rel.type == Shader::PARAMETER_VOID) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5779 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5780 | reg = r.rf[i]; |
| 5781 | } |
| 5782 | else |
| 5783 | { |
| 5784 | Int a = relativeAddress(r, src); |
| 5785 | |
| 5786 | reg = r.rf[i + a]; |
| 5787 | } |
| 5788 | break; |
| 5789 | case Shader::PARAMETER_INPUT: |
| 5790 | { |
| 5791 | if(src.rel.type == Shader::PARAMETER_VOID) // Not relative |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5792 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5793 | reg = r.vf[i]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5794 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5795 | else if(src.rel.type == Shader::PARAMETER_LOOP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5796 | { |
| 5797 | Int aL = r.aL[r.loopDepth]; |
| 5798 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5799 | reg = r.vf[i + aL]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5800 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5801 | else |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5802 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5803 | Int a = relativeAddress(r, src); |
| 5804 | |
| 5805 | reg = r.vf[i + a]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5806 | } |
| 5807 | } |
| 5808 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5809 | case Shader::PARAMETER_CONST: |
| 5810 | reg = readConstant(r, src, offset); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5811 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5812 | case Shader::PARAMETER_TEXTURE: |
| 5813 | reg = r.vf[2 + i]; |
| 5814 | break; |
| 5815 | case Shader::PARAMETER_MISCTYPE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5816 | if(src.index == 0) reg = r.vPos; |
| 5817 | if(src.index == 1) reg = r.vFace; |
| 5818 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5819 | case Shader::PARAMETER_SAMPLER: |
| 5820 | if(src.rel.type == Shader::PARAMETER_VOID) |
| 5821 | { |
| 5822 | reg.x = As<Float4>(Int4(i)); |
| 5823 | } |
| 5824 | else if(src.rel.type == Shader::PARAMETER_TEMP) |
| 5825 | { |
| 5826 | reg.x = As<Float4>(Int4(i) + RoundInt(r.rf[src.rel.index].x)); |
| 5827 | } |
| 5828 | return reg; |
| 5829 | case Shader::PARAMETER_PREDICATE: return reg; // Dummy |
| 5830 | case Shader::PARAMETER_VOID: return reg; // Dummy |
| 5831 | case Shader::PARAMETER_FLOAT4LITERAL: |
| 5832 | reg.x = Float4(src.value[0]); |
| 5833 | reg.y = Float4(src.value[1]); |
| 5834 | reg.z = Float4(src.value[2]); |
| 5835 | reg.w = Float4(src.value[3]); |
| 5836 | break; |
| 5837 | case Shader::PARAMETER_CONSTINT: return reg; // Dummy |
| 5838 | case Shader::PARAMETER_CONSTBOOL: return reg; // Dummy |
| 5839 | case Shader::PARAMETER_LOOP: return reg; // Dummy |
| 5840 | case Shader::PARAMETER_COLOROUT: |
| 5841 | reg = r.oC[i]; |
| 5842 | break; |
| 5843 | case Shader::PARAMETER_DEPTHOUT: |
| 5844 | reg.x = r.oDepth; |
| 5845 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5846 | default: |
| 5847 | ASSERT(false); |
| 5848 | } |
| 5849 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5850 | const Float4 &x = reg[(src.swizzle >> 0) & 0x3]; |
| 5851 | const Float4 &y = reg[(src.swizzle >> 2) & 0x3]; |
| 5852 | const Float4 &z = reg[(src.swizzle >> 4) & 0x3]; |
| 5853 | const Float4 &w = reg[(src.swizzle >> 6) & 0x3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5854 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5855 | Vector4f mod; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5856 | |
| 5857 | switch(src.modifier) |
| 5858 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5859 | case Shader::MODIFIER_NONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5860 | mod.x = x; |
| 5861 | mod.y = y; |
| 5862 | mod.z = z; |
| 5863 | mod.w = w; |
| 5864 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5865 | case Shader::MODIFIER_NEGATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5866 | mod.x = -x; |
| 5867 | mod.y = -y; |
| 5868 | mod.z = -z; |
| 5869 | mod.w = -w; |
| 5870 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5871 | case Shader::MODIFIER_ABS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5872 | mod.x = Abs(x); |
| 5873 | mod.y = Abs(y); |
| 5874 | mod.z = Abs(z); |
| 5875 | mod.w = Abs(w); |
| 5876 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5877 | case Shader::MODIFIER_ABS_NEGATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5878 | mod.x = -Abs(x); |
| 5879 | mod.y = -Abs(y); |
| 5880 | mod.z = -Abs(z); |
| 5881 | mod.w = -Abs(w); |
| 5882 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5883 | case Shader::MODIFIER_NOT: |
| 5884 | mod.x = As<Float4>(As<Int4>(x) ^ Int4(0xFFFFFFFF)); |
| 5885 | mod.y = As<Float4>(As<Int4>(y) ^ Int4(0xFFFFFFFF)); |
| 5886 | mod.z = As<Float4>(As<Int4>(z) ^ Int4(0xFFFFFFFF)); |
| 5887 | mod.w = As<Float4>(As<Int4>(w) ^ Int4(0xFFFFFFFF)); |
| 5888 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5889 | default: |
| 5890 | ASSERT(false); |
| 5891 | } |
| 5892 | |
| 5893 | return mod; |
| 5894 | } |
| 5895 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5896 | Vector4f PixelRoutine::readConstant(Registers &r, const Src &src, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5897 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5898 | Vector4f c; |
| 5899 | |
| 5900 | int i = src.index + offset; |
| 5901 | |
| 5902 | if(src.rel.type == Shader::PARAMETER_VOID) // Not relative |
| 5903 | { |
| 5904 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i])); |
| 5905 | |
| 5906 | c.x = c.x.xxxx; |
| 5907 | c.y = c.y.yyyy; |
| 5908 | c.z = c.z.zzzz; |
| 5909 | c.w = c.w.wwww; |
| 5910 | |
Nicolas Capens | eafdb22 | 2015-05-15 15:24:08 -0400 | [diff] [blame] | 5911 | if(shader->containsDefineInstruction()) // Constant may be known at compile time |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5912 | { |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 5913 | for(size_t j = 0; j < shader->getLength(); j++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5914 | { |
| 5915 | const Shader::Instruction &instruction = *shader->getInstruction(j); |
| 5916 | |
| 5917 | if(instruction.opcode == Shader::OPCODE_DEF) |
| 5918 | { |
| 5919 | if(instruction.dst.index == i) |
| 5920 | { |
| 5921 | c.x = Float4(instruction.src[0].value[0]); |
| 5922 | c.y = Float4(instruction.src[0].value[1]); |
| 5923 | c.z = Float4(instruction.src[0].value[2]); |
| 5924 | c.w = Float4(instruction.src[0].value[3]); |
| 5925 | |
| 5926 | break; |
| 5927 | } |
| 5928 | } |
| 5929 | } |
| 5930 | } |
| 5931 | } |
| 5932 | else if(src.rel.type == Shader::PARAMETER_LOOP) |
| 5933 | { |
| 5934 | Int loopCounter = r.aL[r.loopDepth]; |
| 5935 | |
| 5936 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i]) + loopCounter * 16); |
| 5937 | |
| 5938 | c.x = c.x.xxxx; |
| 5939 | c.y = c.y.yyyy; |
| 5940 | c.z = c.z.zzzz; |
| 5941 | c.w = c.w.wwww; |
| 5942 | } |
| 5943 | else |
| 5944 | { |
| 5945 | Int a = relativeAddress(r, src); |
| 5946 | |
| 5947 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i]) + a * 16); |
| 5948 | |
| 5949 | c.x = c.x.xxxx; |
| 5950 | c.y = c.y.yyyy; |
| 5951 | c.z = c.z.zzzz; |
| 5952 | c.w = c.w.wwww; |
| 5953 | } |
| 5954 | |
| 5955 | return c; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5956 | } |
| 5957 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5958 | Int PixelRoutine::relativeAddress(Registers &r, const Shader::Parameter &var) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5959 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5960 | ASSERT(var.rel.deterministic); |
| 5961 | |
| 5962 | if(var.rel.type == Shader::PARAMETER_TEMP) |
| 5963 | { |
| 5964 | return RoundInt(Extract(r.rf[var.rel.index].x, 0)) * var.rel.scale; |
| 5965 | } |
| 5966 | else if(var.rel.type == Shader::PARAMETER_INPUT) |
| 5967 | { |
| 5968 | return RoundInt(Extract(r.vf[var.rel.index].x, 0)) * var.rel.scale; |
| 5969 | } |
| 5970 | else if(var.rel.type == Shader::PARAMETER_OUTPUT) |
| 5971 | { |
| 5972 | return RoundInt(Extract(r.oC[var.rel.index].x, 0)) * var.rel.scale; |
| 5973 | } |
| 5974 | else if(var.rel.type == Shader::PARAMETER_CONST) |
| 5975 | { |
Nicolas Capens | b5e7a2a | 2014-05-06 16:38:19 -0400 | [diff] [blame] | 5976 | RValue<Float4> c = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[var.rel.index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5977 | |
| 5978 | return RoundInt(Extract(c, 0)) * var.rel.scale; |
| 5979 | } |
| 5980 | else ASSERT(false); |
| 5981 | |
| 5982 | return 0; |
| 5983 | } |
| 5984 | |
| 5985 | Int4 PixelRoutine::enableMask(Registers &r, const Shader::Instruction *instruction) |
| 5986 | { |
| 5987 | Int4 enable = instruction->analysisBranch ? Int4(r.enableStack[r.enableIndex]) : Int4(0xFFFFFFFF); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 5988 | |
| 5989 | if(!whileTest) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5990 | { |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 5991 | if(shader->containsBreakInstruction() && instruction->analysisBreak) |
| 5992 | { |
| 5993 | enable &= r.enableBreak; |
| 5994 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5995 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 5996 | if(shader->containsContinueInstruction() && instruction->analysisContinue) |
| 5997 | { |
| 5998 | enable &= r.enableContinue; |
| 5999 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6000 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 6001 | if(shader->containsLeaveInstruction() && instruction->analysisLeave) |
| 6002 | { |
| 6003 | enable &= r.enableLeave; |
| 6004 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6005 | } |
| 6006 | |
| 6007 | return enable; |
| 6008 | } |
| 6009 | |
| 6010 | bool PixelRoutine::colorUsed() |
| 6011 | { |
| 6012 | return state.colorWriteMask || state.alphaTestActive() || state.shaderContainsKill; |
| 6013 | } |
| 6014 | |
| 6015 | unsigned short PixelRoutine::shaderVersion() const |
| 6016 | { |
| 6017 | return shader ? shader->getVersion() : 0x0000; |
| 6018 | } |
| 6019 | |
| 6020 | bool PixelRoutine::interpolateZ() const |
| 6021 | { |
| 6022 | return state.depthTestActive || state.pixelFogActive() || (shader && shader->vPosDeclared && fullPixelPositionRegister); |
| 6023 | } |
| 6024 | |
| 6025 | bool PixelRoutine::interpolateW() const |
| 6026 | { |
| 6027 | return state.perspective || (shader && shader->vPosDeclared && fullPixelPositionRegister); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6028 | } |
| 6029 | } |