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 | |
| 23 | #include <assert.h> |
| 24 | |
| 25 | extern bool localShaderConstants; |
| 26 | |
| 27 | namespace sw |
| 28 | { |
| 29 | extern bool complementaryDepthBuffer; |
| 30 | extern bool postBlendSRGB; |
| 31 | extern bool exactColorRounding; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 32 | extern bool booleanFaceRegister; |
| 33 | extern bool halfIntegerCoordinates; // Pixel centers are not at integer coordinates |
| 34 | extern bool fullPixelPositionRegister; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 35 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 36 | 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] | 37 | { |
| 38 | perturbate = false; |
| 39 | luminance = false; |
| 40 | previousScaling = false; |
| 41 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 42 | ifDepth = 0; |
| 43 | loopRepDepth = 0; |
| 44 | breakDepth = 0; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 45 | currentLabel = -1; |
| 46 | whileTest = false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 47 | |
| 48 | for(int i = 0; i < 2048; i++) |
| 49 | { |
| 50 | labelBlock[i] = 0; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | PixelRoutine::~PixelRoutine() |
| 55 | { |
| 56 | for(int i = 0; i < 16; i++) |
| 57 | { |
| 58 | delete sampler[i]; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void PixelRoutine::quad(Registers &r, Pointer<Byte> cBuffer[4], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y) |
| 63 | { |
| 64 | #if PERF_PROFILE |
| 65 | Long pipeTime = Ticks(); |
| 66 | #endif |
| 67 | |
| 68 | for(int i = 0; i < 16; i++) |
| 69 | { |
| 70 | sampler[i] = new SamplerCore(r.constants, state.sampler[i]); |
| 71 | } |
| 72 | |
| 73 | const bool earlyDepthTest = !state.depthOverride && !state.alphaTestActive(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 74 | const bool integerPipeline = shaderVersion() <= 0x0104; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 75 | |
| 76 | Int zMask[4]; // Depth mask |
| 77 | Int sMask[4]; // Stencil mask |
| 78 | |
| 79 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 80 | { |
| 81 | zMask[q] = cMask[q]; |
| 82 | sMask[q] = cMask[q]; |
| 83 | } |
| 84 | |
| 85 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 86 | { |
| 87 | stencilTest(r, sBuffer, q, x, sMask[q], cMask[q]); |
| 88 | } |
| 89 | |
| 90 | Float4 f; |
| 91 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 92 | Vector4i ¤t = r.ri[0]; |
| 93 | Vector4i &diffuse = r.vi[0]; |
| 94 | Vector4i &specular = r.vi[1]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 95 | |
| 96 | Float4 (&z)[4] = r.z; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 97 | Float4 &w = r.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 98 | Float4 &rhw = r.rhw; |
| 99 | Float4 rhwCentroid; |
| 100 | |
| 101 | Float4 xxxx = Float4(Float(x)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,xQuad), 16); |
| 102 | Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,yQuad), 16); |
| 103 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 104 | if(interpolateZ()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 105 | { |
| 106 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 107 | { |
| 108 | Float4 x = xxxx; |
| 109 | |
| 110 | if(state.multiSample > 1) |
| 111 | { |
| 112 | x -= *Pointer<Float4>(r.constants + OFFSET(Constants,X) + q * sizeof(float4)); |
| 113 | } |
| 114 | |
| 115 | z[q] = interpolate(x, r.Dz[q], z[q], r.primitive + OFFSET(Primitive,z), false, false); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | Bool depthPass = false; |
| 120 | |
| 121 | if(earlyDepthTest) |
| 122 | { |
| 123 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 124 | { |
| 125 | depthPass = depthPass || depthTest(r, zBuffer, q, x, z[q], sMask[q], zMask[q], cMask[q]); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | If(depthPass || Bool(!earlyDepthTest)) |
| 130 | { |
| 131 | #if PERF_PROFILE |
| 132 | Long interpTime = Ticks(); |
| 133 | #endif |
| 134 | |
| 135 | // Centroid locations |
| 136 | Float4 XXXX = Float4(0.0f); |
| 137 | Float4 YYYY = Float4(0.0f); |
| 138 | |
| 139 | if(state.centroid) |
| 140 | { |
| 141 | Float4 WWWW(1.0e-9f); |
| 142 | |
| 143 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 144 | { |
| 145 | XXXX += *Pointer<Float4>(r.constants + OFFSET(Constants,sampleX[q]) + 16 * cMask[q]); |
| 146 | YYYY += *Pointer<Float4>(r.constants + OFFSET(Constants,sampleY[q]) + 16 * cMask[q]); |
| 147 | WWWW += *Pointer<Float4>(r.constants + OFFSET(Constants,weight) + 16 * cMask[q]); |
| 148 | } |
| 149 | |
| 150 | WWWW = Rcp_pp(WWWW); |
| 151 | XXXX *= WWWW; |
| 152 | YYYY *= WWWW; |
| 153 | |
| 154 | XXXX += xxxx; |
| 155 | YYYY += yyyy; |
| 156 | } |
| 157 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 158 | if(interpolateW()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 159 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 160 | w = interpolate(xxxx, r.Dw, rhw, r.primitive + OFFSET(Primitive,w), false, false); |
| 161 | rhw = reciprocal(w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 162 | |
| 163 | if(state.centroid) |
| 164 | { |
| 165 | rhwCentroid = reciprocal(interpolateCentroid(XXXX, YYYY, rhwCentroid, r.primitive + OFFSET(Primitive,w), false, false)); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | for(int interpolant = 0; interpolant < 10; interpolant++) |
| 170 | { |
| 171 | for(int component = 0; component < 4; component++) |
| 172 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 173 | if(state.interpolant[interpolant].component & (1 << component)) |
| 174 | { |
| 175 | if(!state.interpolant[interpolant].centroid) |
| 176 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 177 | 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] | 178 | } |
| 179 | else |
| 180 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 181 | 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] | 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | Float4 rcp; |
| 187 | |
| 188 | switch(state.interpolant[interpolant].project) |
| 189 | { |
| 190 | case 0: |
| 191 | break; |
| 192 | case 1: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 193 | rcp = reciprocal(r.vf[interpolant].y); |
| 194 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 195 | break; |
| 196 | case 2: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 197 | rcp = reciprocal(r.vf[interpolant].z); |
| 198 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
| 199 | r.vf[interpolant].y = r.vf[interpolant].y * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 200 | break; |
| 201 | case 3: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 202 | rcp = reciprocal(r.vf[interpolant].w); |
| 203 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
| 204 | r.vf[interpolant].y = r.vf[interpolant].y * rcp; |
| 205 | r.vf[interpolant].z = r.vf[interpolant].z * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 206 | break; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if(state.fog.component) |
| 211 | { |
| 212 | f = interpolate(xxxx, r.Df, rhw, r.primitive + OFFSET(Primitive,f), state.fog.flat & 0x01, state.perspective); |
| 213 | } |
| 214 | |
| 215 | if(integerPipeline) |
| 216 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 217 | if(state.color[0].component & 0x1) diffuse.x = convertFixed12(r.vf[0].x); else diffuse.x = Short4(0x1000); |
| 218 | if(state.color[0].component & 0x2) diffuse.y = convertFixed12(r.vf[0].y); else diffuse.y = Short4(0x1000); |
| 219 | if(state.color[0].component & 0x4) diffuse.z = convertFixed12(r.vf[0].z); else diffuse.z = Short4(0x1000); |
| 220 | if(state.color[0].component & 0x8) diffuse.w = convertFixed12(r.vf[0].w); else diffuse.w = Short4(0x1000); |
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(state.color[1].component & 0x1) specular.x = convertFixed12(r.vf[1].x); else specular.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 223 | if(state.color[1].component & 0x2) specular.y = convertFixed12(r.vf[1].y); else specular.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 224 | if(state.color[1].component & 0x4) specular.z = convertFixed12(r.vf[1].z); else specular.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 225 | if(state.color[1].component & 0x8) specular.w = convertFixed12(r.vf[1].w); else specular.w = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 226 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 227 | else if(shaderVersion() >= 0x0300) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 228 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 229 | if(shader->vPosDeclared) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 230 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 231 | if(!halfIntegerCoordinates) |
| 232 | { |
| 233 | r.vPos.x = Float4(Float(x)) + Float4(0, 1, 0, 1); |
| 234 | r.vPos.y = Float4(Float(y)) + Float4(0, 0, 1, 1); |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | r.vPos.x = Float4(Float(x)) + Float4(0.5f, 1.5f, 0.5f, 1.5f); |
| 239 | r.vPos.y = Float4(Float(y)) + Float4(0.5f, 0.5f, 1.5f, 1.5f); |
| 240 | } |
| 241 | |
| 242 | if(fullPixelPositionRegister) |
| 243 | { |
| 244 | r.vPos.z = z[0]; // FIXME: Centroid? |
| 245 | r.vPos.w = w; // FIXME: Centroid? |
| 246 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 247 | } |
| 248 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 249 | if(shader->vFaceDeclared) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 250 | { |
| 251 | Float4 area = *Pointer<Float>(r.primitive + OFFSET(Primitive,area)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 252 | Float4 face = booleanFaceRegister ? Float4(As<Float4>(CmpNLT(area, Float4(0.0f)))) : area; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 253 | |
| 254 | r.vFace.x = face; |
| 255 | r.vFace.y = face; |
| 256 | r.vFace.z = face; |
| 257 | r.vFace.w = face; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
| 261 | #if PERF_PROFILE |
| 262 | r.cycles[PERF_INTERP] += Ticks() - interpTime; |
| 263 | #endif |
| 264 | |
| 265 | Bool alphaPass = true; |
| 266 | |
| 267 | if(colorUsed()) |
| 268 | { |
| 269 | #if PERF_PROFILE |
| 270 | Long shaderTime = Ticks(); |
| 271 | #endif |
| 272 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 273 | if(shader) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 274 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 275 | // shader->print("PixelShader-%0.8X.txt", state.shaderID); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 276 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 277 | if(shader->getVersion() <= 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 278 | { |
| 279 | ps_1_x(r, cMask); |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | ps_2_x(r, cMask); |
| 284 | } |
| 285 | } |
| 286 | else |
| 287 | { |
| 288 | current = diffuse; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 289 | Vector4i temp(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 290 | |
| 291 | for(int stage = 0; stage < 8; stage++) |
| 292 | { |
| 293 | if(state.textureStage[stage].stageOperation == TextureStage::STAGE_DISABLE) |
| 294 | { |
| 295 | break; |
| 296 | } |
| 297 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 298 | Vector4i texture; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 299 | |
| 300 | if(state.textureStage[stage].usesTexture) |
| 301 | { |
| 302 | sampleTexture(r, texture, stage, stage); |
| 303 | } |
| 304 | |
| 305 | blendTexture(r, current, temp, texture, stage); |
| 306 | } |
| 307 | |
| 308 | specularPixel(current, specular); |
| 309 | } |
| 310 | |
| 311 | #if PERF_PROFILE |
| 312 | r.cycles[PERF_SHADER] += Ticks() - shaderTime; |
| 313 | #endif |
| 314 | |
| 315 | if(integerPipeline) |
| 316 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 317 | current.x = Min(current.x, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); current.x = Max(current.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 318 | current.y = Min(current.y, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); current.y = Max(current.y, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 319 | current.z = Min(current.z, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); current.z = Max(current.z, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 320 | current.w = Min(current.w, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); current.w = Max(current.w, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 321 | |
| 322 | alphaPass = alphaTest(r, cMask, current); |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | clampColor(r.oC); |
| 327 | |
| 328 | alphaPass = alphaTest(r, cMask, r.oC[0]); |
| 329 | } |
| 330 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 331 | if((shader && shader->containsKill()) || state.alphaTestActive()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 332 | { |
| 333 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 334 | { |
| 335 | zMask[q] &= cMask[q]; |
| 336 | sMask[q] &= cMask[q]; |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | If(alphaPass) |
| 342 | { |
| 343 | if(!earlyDepthTest) |
| 344 | { |
| 345 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 346 | { |
| 347 | depthPass = depthPass || depthTest(r, zBuffer, q, x, z[q], sMask[q], zMask[q], cMask[q]); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | #if PERF_PROFILE |
| 352 | Long ropTime = Ticks(); |
| 353 | #endif |
| 354 | |
| 355 | If(depthPass || Bool(earlyDepthTest)) |
| 356 | { |
| 357 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 358 | { |
| 359 | if(state.multiSampleMask & (1 << q)) |
| 360 | { |
| 361 | writeDepth(r, zBuffer, q, x, z[q], zMask[q]); |
| 362 | |
| 363 | if(state.occlusionEnabled) |
| 364 | { |
| 365 | r.occlusion += *Pointer<UInt>(r.constants + OFFSET(Constants,occlusionCount) + 4 * (zMask[q] & sMask[q])); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | if(colorUsed()) |
| 371 | { |
| 372 | #if PERF_PROFILE |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 373 | AddAtomic(Pointer<Long>(&profiler.ropOperations), 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 374 | #endif |
| 375 | |
| 376 | if(integerPipeline) |
| 377 | { |
| 378 | rasterOperation(current, r, f, cBuffer[0], x, sMask, zMask, cMask); |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | rasterOperation(r.oC, r, f, cBuffer, x, sMask, zMask, cMask); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | #if PERF_PROFILE |
| 388 | r.cycles[PERF_ROP] += Ticks() - ropTime; |
| 389 | #endif |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 394 | { |
| 395 | if(state.multiSampleMask & (1 << q)) |
| 396 | { |
| 397 | writeStencil(r, sBuffer, q, x, sMask[q], zMask[q], cMask[q]); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | #if PERF_PROFILE |
| 402 | r.cycles[PERF_PIPE] += Ticks() - pipeTime; |
| 403 | #endif |
| 404 | } |
| 405 | |
| 406 | Float4 PixelRoutine::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective) |
| 407 | { |
| 408 | Float4 interpolant = D; |
| 409 | |
| 410 | if(!flat) |
| 411 | { |
| 412 | interpolant += x * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,A), 16); |
| 413 | |
| 414 | if(perspective) |
| 415 | { |
| 416 | interpolant *= rhw; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | return interpolant; |
| 421 | } |
| 422 | |
| 423 | Float4 PixelRoutine::interpolateCentroid(Float4 &x, Float4 &y, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective) |
| 424 | { |
| 425 | Float4 interpolant = *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,C), 16); |
| 426 | |
| 427 | if(!flat) |
| 428 | { |
| 429 | interpolant += x * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,A), 16) + |
| 430 | y * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,B), 16); |
| 431 | |
| 432 | if(perspective) |
| 433 | { |
| 434 | interpolant *= rhw; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | return interpolant; |
| 439 | } |
| 440 | |
| 441 | void PixelRoutine::stencilTest(Registers &r, Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &cMask) |
| 442 | { |
| 443 | if(!state.stencilActive) |
| 444 | { |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | // (StencilRef & StencilMask) CompFunc (StencilBufferValue & StencilMask) |
| 449 | |
| 450 | Pointer<Byte> buffer = sBuffer + 2 * x; |
| 451 | |
| 452 | if(q > 0) |
| 453 | { |
| 454 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,stencilSliceB)); |
| 455 | } |
| 456 | |
| 457 | Byte8 value = As<Byte8>(Long1(*Pointer<UInt>(buffer))); |
| 458 | Byte8 valueCCW = value; |
| 459 | |
| 460 | if(!state.noStencilMask) |
| 461 | { |
| 462 | value &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].testMaskQ)); |
| 463 | } |
| 464 | |
| 465 | stencilTest(r, value, (Context::StencilCompareMode)state.stencilCompareMode, false); |
| 466 | |
| 467 | if(state.twoSidedStencil) |
| 468 | { |
| 469 | if(!state.noStencilMaskCCW) |
| 470 | { |
| 471 | valueCCW &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].testMaskQ)); |
| 472 | } |
| 473 | |
| 474 | stencilTest(r, valueCCW, (Context::StencilCompareMode)state.stencilCompareModeCCW, true); |
| 475 | |
| 476 | value &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,clockwiseMask)); |
| 477 | valueCCW &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,invClockwiseMask)); |
| 478 | value |= valueCCW; |
| 479 | } |
| 480 | |
| 481 | sMask = SignMask(value) & cMask; |
| 482 | } |
| 483 | |
| 484 | void PixelRoutine::stencilTest(Registers &r, Byte8 &value, Context::StencilCompareMode stencilCompareMode, bool CCW) |
| 485 | { |
| 486 | Byte8 equal; |
| 487 | |
| 488 | switch(stencilCompareMode) |
| 489 | { |
| 490 | case Context::STENCIL_ALWAYS: |
| 491 | value = Byte8(0xFFFFFFFFFFFFFFFF); |
| 492 | break; |
| 493 | case Context::STENCIL_NEVER: |
| 494 | value = Byte8(0x0000000000000000); |
| 495 | break; |
| 496 | case Context::STENCIL_LESS: // a < b ~ b > a |
| 497 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 498 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 499 | break; |
| 500 | case Context::STENCIL_EQUAL: |
| 501 | value = CmpEQ(value, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 502 | break; |
| 503 | case Context::STENCIL_NOTEQUAL: // a != b ~ !(a == b) |
| 504 | value = CmpEQ(value, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 505 | value ^= Byte8(0xFFFFFFFFFFFFFFFF); |
| 506 | break; |
| 507 | case Context::STENCIL_LESSEQUAL: // a <= b ~ (b > a) || (a == b) |
| 508 | equal = value; |
| 509 | equal = CmpEQ(equal, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 510 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 511 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 512 | value |= equal; |
| 513 | break; |
| 514 | case Context::STENCIL_GREATER: // a > b |
| 515 | equal = *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ)); |
| 516 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 517 | equal = CmpGT(As<SByte8>(equal), As<SByte8>(value)); |
| 518 | value = equal; |
| 519 | break; |
| 520 | case Context::STENCIL_GREATEREQUAL: // a >= b ~ !(a < b) ~ !(b > a) |
| 521 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 522 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 523 | value ^= Byte8(0xFFFFFFFFFFFFFFFF); |
| 524 | break; |
| 525 | default: |
| 526 | ASSERT(false); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | Bool PixelRoutine::depthTest(Registers &r, Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &sMask, Int &zMask, Int &cMask) |
| 531 | { |
| 532 | if(!state.depthTestActive) |
| 533 | { |
| 534 | return true; |
| 535 | } |
| 536 | |
| 537 | Float4 Z = z; |
| 538 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 539 | if(shader && shader->depthOverride()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 540 | { |
| 541 | if(complementaryDepthBuffer) |
| 542 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 543 | Z = Float4(1.0f) - r.oDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 544 | } |
| 545 | else |
| 546 | { |
| 547 | Z = r.oDepth; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | Pointer<Byte> buffer; |
| 552 | Int pitch; |
| 553 | |
| 554 | if(!state.quadLayoutDepthBuffer) |
| 555 | { |
| 556 | buffer = zBuffer + 4 * x; |
| 557 | pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); |
| 558 | } |
| 559 | else |
| 560 | { |
| 561 | buffer = zBuffer + 8 * x; |
| 562 | } |
| 563 | |
| 564 | if(q > 0) |
| 565 | { |
| 566 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,depthSliceB)); |
| 567 | } |
| 568 | |
| 569 | Float4 zValue; |
| 570 | |
| 571 | if(state.depthCompareMode != Context::DEPTH_NEVER || (state.depthCompareMode != Context::DEPTH_ALWAYS && !state.depthWriteEnable)) |
| 572 | { |
| 573 | if(!state.quadLayoutDepthBuffer) |
| 574 | { |
| 575 | // FIXME: Properly optimizes? |
| 576 | zValue.xy = *Pointer<Float4>(buffer); |
| 577 | zValue.zw = *Pointer<Float4>(buffer + pitch - 8); |
| 578 | } |
| 579 | else |
| 580 | { |
| 581 | zValue = *Pointer<Float4>(buffer, 16); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | Int4 zTest; |
| 586 | |
| 587 | switch(state.depthCompareMode) |
| 588 | { |
| 589 | case Context::DEPTH_ALWAYS: |
| 590 | // Optimized |
| 591 | break; |
| 592 | case Context::DEPTH_NEVER: |
| 593 | // Optimized |
| 594 | break; |
| 595 | case Context::DEPTH_EQUAL: |
| 596 | zTest = CmpEQ(zValue, Z); |
| 597 | break; |
| 598 | case Context::DEPTH_NOTEQUAL: |
| 599 | zTest = CmpNEQ(zValue, Z); |
| 600 | break; |
| 601 | case Context::DEPTH_LESS: |
| 602 | if(complementaryDepthBuffer) |
| 603 | { |
| 604 | zTest = CmpLT(zValue, Z); |
| 605 | } |
| 606 | else |
| 607 | { |
| 608 | zTest = CmpNLE(zValue, Z); |
| 609 | } |
| 610 | break; |
| 611 | case Context::DEPTH_GREATEREQUAL: |
| 612 | if(complementaryDepthBuffer) |
| 613 | { |
| 614 | zTest = CmpNLT(zValue, Z); |
| 615 | } |
| 616 | else |
| 617 | { |
| 618 | zTest = CmpLE(zValue, Z); |
| 619 | } |
| 620 | break; |
| 621 | case Context::DEPTH_LESSEQUAL: |
| 622 | if(complementaryDepthBuffer) |
| 623 | { |
| 624 | zTest = CmpLE(zValue, Z); |
| 625 | } |
| 626 | else |
| 627 | { |
| 628 | zTest = CmpNLT(zValue, Z); |
| 629 | } |
| 630 | break; |
| 631 | case Context::DEPTH_GREATER: |
| 632 | if(complementaryDepthBuffer) |
| 633 | { |
| 634 | zTest = CmpNLE(zValue, Z); |
| 635 | } |
| 636 | else |
| 637 | { |
| 638 | zTest = CmpLT(zValue, Z); |
| 639 | } |
| 640 | break; |
| 641 | default: |
| 642 | ASSERT(false); |
| 643 | } |
| 644 | |
| 645 | switch(state.depthCompareMode) |
| 646 | { |
| 647 | case Context::DEPTH_ALWAYS: |
| 648 | zMask = cMask; |
| 649 | break; |
| 650 | case Context::DEPTH_NEVER: |
| 651 | zMask = 0x0; |
| 652 | break; |
| 653 | default: |
| 654 | zMask = SignMask(zTest) & cMask; |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | if(state.stencilActive) |
| 659 | { |
| 660 | zMask &= sMask; |
| 661 | } |
| 662 | |
| 663 | return zMask != 0; |
| 664 | } |
| 665 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 666 | void PixelRoutine::blendTexture(Registers &r, Vector4i ¤t, Vector4i &temp, Vector4i &texture, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 667 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 668 | Vector4i *arg1; |
| 669 | Vector4i *arg2; |
| 670 | Vector4i *arg3; |
| 671 | Vector4i res; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 672 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 673 | Vector4i constant; |
| 674 | Vector4i tfactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 675 | |
| 676 | const TextureStage::State &textureStage = state.textureStage[stage]; |
| 677 | |
| 678 | if(textureStage.firstArgument == TextureStage::SOURCE_CONSTANT || |
| 679 | textureStage.firstArgumentAlpha == TextureStage::SOURCE_CONSTANT || |
| 680 | textureStage.secondArgument == TextureStage::SOURCE_CONSTANT || |
| 681 | textureStage.secondArgumentAlpha == TextureStage::SOURCE_CONSTANT || |
| 682 | textureStage.thirdArgument == TextureStage::SOURCE_CONSTANT || |
| 683 | textureStage.thirdArgumentAlpha == TextureStage::SOURCE_CONSTANT) |
| 684 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 685 | constant.x = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[0])); |
| 686 | constant.y = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[1])); |
| 687 | constant.z = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[2])); |
| 688 | constant.w = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | if(textureStage.firstArgument == TextureStage::SOURCE_TFACTOR || |
| 692 | textureStage.firstArgumentAlpha == TextureStage::SOURCE_TFACTOR || |
| 693 | textureStage.secondArgument == TextureStage::SOURCE_TFACTOR || |
| 694 | textureStage.secondArgumentAlpha == TextureStage::SOURCE_TFACTOR || |
| 695 | textureStage.thirdArgument == TextureStage::SOURCE_TFACTOR || |
| 696 | textureStage.thirdArgumentAlpha == TextureStage::SOURCE_TFACTOR) |
| 697 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 698 | tfactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[0])); |
| 699 | tfactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[1])); |
| 700 | tfactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[2])); |
| 701 | tfactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | // Premodulate |
| 705 | if(stage > 0 && textureStage.usesTexture) |
| 706 | { |
| 707 | if(state.textureStage[stage - 1].stageOperation == TextureStage::STAGE_PREMODULATE) |
| 708 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 709 | current.x = MulHigh(current.x, texture.x) << 4; |
| 710 | current.y = MulHigh(current.y, texture.y) << 4; |
| 711 | current.z = MulHigh(current.z, texture.z) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | if(state.textureStage[stage - 1].stageOperationAlpha == TextureStage::STAGE_PREMODULATE) |
| 715 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 716 | current.w = MulHigh(current.w, texture.w) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | |
| 720 | if(luminance) |
| 721 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 722 | texture.x = MulHigh(texture.x, r.L) << 4; |
| 723 | texture.y = MulHigh(texture.y, r.L) << 4; |
| 724 | texture.z = MulHigh(texture.z, r.L) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 725 | |
| 726 | luminance = false; |
| 727 | } |
| 728 | |
| 729 | switch(textureStage.firstArgument) |
| 730 | { |
| 731 | case TextureStage::SOURCE_TEXTURE: arg1 = &texture; break; |
| 732 | case TextureStage::SOURCE_CONSTANT: arg1 = &constant; break; |
| 733 | case TextureStage::SOURCE_CURRENT: arg1 = ¤t; break; |
| 734 | case TextureStage::SOURCE_DIFFUSE: arg1 = &r.diffuse; break; |
| 735 | case TextureStage::SOURCE_SPECULAR: arg1 = &r.specular; break; |
| 736 | case TextureStage::SOURCE_TEMP: arg1 = &temp; break; |
| 737 | case TextureStage::SOURCE_TFACTOR: arg1 = &tfactor; break; |
| 738 | default: |
| 739 | ASSERT(false); |
| 740 | } |
| 741 | |
| 742 | switch(textureStage.secondArgument) |
| 743 | { |
| 744 | case TextureStage::SOURCE_TEXTURE: arg2 = &texture; break; |
| 745 | case TextureStage::SOURCE_CONSTANT: arg2 = &constant; break; |
| 746 | case TextureStage::SOURCE_CURRENT: arg2 = ¤t; break; |
| 747 | case TextureStage::SOURCE_DIFFUSE: arg2 = &r.diffuse; break; |
| 748 | case TextureStage::SOURCE_SPECULAR: arg2 = &r.specular; break; |
| 749 | case TextureStage::SOURCE_TEMP: arg2 = &temp; break; |
| 750 | case TextureStage::SOURCE_TFACTOR: arg2 = &tfactor; break; |
| 751 | default: |
| 752 | ASSERT(false); |
| 753 | } |
| 754 | |
| 755 | switch(textureStage.thirdArgument) |
| 756 | { |
| 757 | case TextureStage::SOURCE_TEXTURE: arg3 = &texture; break; |
| 758 | case TextureStage::SOURCE_CONSTANT: arg3 = &constant; break; |
| 759 | case TextureStage::SOURCE_CURRENT: arg3 = ¤t; break; |
| 760 | case TextureStage::SOURCE_DIFFUSE: arg3 = &r.diffuse; break; |
| 761 | case TextureStage::SOURCE_SPECULAR: arg3 = &r.specular; break; |
| 762 | case TextureStage::SOURCE_TEMP: arg3 = &temp; break; |
| 763 | case TextureStage::SOURCE_TFACTOR: arg3 = &tfactor; break; |
| 764 | default: |
| 765 | ASSERT(false); |
| 766 | } |
| 767 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 768 | Vector4i mod1; |
| 769 | Vector4i mod2; |
| 770 | Vector4i mod3; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 771 | |
| 772 | switch(textureStage.firstModifier) |
| 773 | { |
| 774 | case TextureStage::MODIFIER_COLOR: |
| 775 | break; |
| 776 | case TextureStage::MODIFIER_INVCOLOR: |
| 777 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 778 | mod1.x = SubSat(Short4(0x1000), arg1->x); |
| 779 | mod1.y = SubSat(Short4(0x1000), arg1->y); |
| 780 | mod1.z = SubSat(Short4(0x1000), arg1->z); |
| 781 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 782 | |
| 783 | arg1 = &mod1; |
| 784 | } |
| 785 | break; |
| 786 | case TextureStage::MODIFIER_ALPHA: |
| 787 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 788 | mod1.x = arg1->w; |
| 789 | mod1.y = arg1->w; |
| 790 | mod1.z = arg1->w; |
| 791 | mod1.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 792 | |
| 793 | arg1 = &mod1; |
| 794 | } |
| 795 | break; |
| 796 | case TextureStage::MODIFIER_INVALPHA: |
| 797 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 798 | mod1.x = SubSat(Short4(0x1000), arg1->w); |
| 799 | mod1.y = SubSat(Short4(0x1000), arg1->w); |
| 800 | mod1.z = SubSat(Short4(0x1000), arg1->w); |
| 801 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 802 | |
| 803 | arg1 = &mod1; |
| 804 | } |
| 805 | break; |
| 806 | default: |
| 807 | ASSERT(false); |
| 808 | } |
| 809 | |
| 810 | switch(textureStage.secondModifier) |
| 811 | { |
| 812 | case TextureStage::MODIFIER_COLOR: |
| 813 | break; |
| 814 | case TextureStage::MODIFIER_INVCOLOR: |
| 815 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 816 | mod2.x = SubSat(Short4(0x1000), arg2->x); |
| 817 | mod2.y = SubSat(Short4(0x1000), arg2->y); |
| 818 | mod2.z = SubSat(Short4(0x1000), arg2->z); |
| 819 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 820 | |
| 821 | arg2 = &mod2; |
| 822 | } |
| 823 | break; |
| 824 | case TextureStage::MODIFIER_ALPHA: |
| 825 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 826 | mod2.x = arg2->w; |
| 827 | mod2.y = arg2->w; |
| 828 | mod2.z = arg2->w; |
| 829 | mod2.w = arg2->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 830 | |
| 831 | arg2 = &mod2; |
| 832 | } |
| 833 | break; |
| 834 | case TextureStage::MODIFIER_INVALPHA: |
| 835 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 836 | mod2.x = SubSat(Short4(0x1000), arg2->w); |
| 837 | mod2.y = SubSat(Short4(0x1000), arg2->w); |
| 838 | mod2.z = SubSat(Short4(0x1000), arg2->w); |
| 839 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 840 | |
| 841 | arg2 = &mod2; |
| 842 | } |
| 843 | break; |
| 844 | default: |
| 845 | ASSERT(false); |
| 846 | } |
| 847 | |
| 848 | switch(textureStage.thirdModifier) |
| 849 | { |
| 850 | case TextureStage::MODIFIER_COLOR: |
| 851 | break; |
| 852 | case TextureStage::MODIFIER_INVCOLOR: |
| 853 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 854 | mod3.x = SubSat(Short4(0x1000), arg3->x); |
| 855 | mod3.y = SubSat(Short4(0x1000), arg3->y); |
| 856 | mod3.z = SubSat(Short4(0x1000), arg3->z); |
| 857 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 858 | |
| 859 | arg3 = &mod3; |
| 860 | } |
| 861 | break; |
| 862 | case TextureStage::MODIFIER_ALPHA: |
| 863 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 864 | mod3.x = arg3->w; |
| 865 | mod3.y = arg3->w; |
| 866 | mod3.z = arg3->w; |
| 867 | mod3.w = arg3->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 868 | |
| 869 | arg3 = &mod3; |
| 870 | } |
| 871 | break; |
| 872 | case TextureStage::MODIFIER_INVALPHA: |
| 873 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 874 | mod3.x = SubSat(Short4(0x1000), arg3->w); |
| 875 | mod3.y = SubSat(Short4(0x1000), arg3->w); |
| 876 | mod3.z = SubSat(Short4(0x1000), arg3->w); |
| 877 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 878 | |
| 879 | arg3 = &mod3; |
| 880 | } |
| 881 | break; |
| 882 | default: |
| 883 | ASSERT(false); |
| 884 | } |
| 885 | |
| 886 | switch(textureStage.stageOperation) |
| 887 | { |
| 888 | case TextureStage::STAGE_DISABLE: |
| 889 | break; |
| 890 | case TextureStage::STAGE_SELECTARG1: // Arg1 |
| 891 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 892 | res.x = arg1->x; |
| 893 | res.y = arg1->y; |
| 894 | res.z = arg1->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 895 | } |
| 896 | break; |
| 897 | case TextureStage::STAGE_SELECTARG2: // Arg2 |
| 898 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 899 | res.x = arg2->x; |
| 900 | res.y = arg2->y; |
| 901 | res.z = arg2->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 902 | } |
| 903 | break; |
| 904 | case TextureStage::STAGE_SELECTARG3: // Arg3 |
| 905 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 906 | res.x = arg3->x; |
| 907 | res.y = arg3->y; |
| 908 | res.z = arg3->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 909 | } |
| 910 | break; |
| 911 | case TextureStage::STAGE_MODULATE: // Arg1 * Arg2 |
| 912 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 913 | res.x = MulHigh(arg1->x, arg2->x) << 4; |
| 914 | res.y = MulHigh(arg1->y, arg2->y) << 4; |
| 915 | res.z = MulHigh(arg1->z, arg2->z) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 916 | } |
| 917 | break; |
| 918 | case TextureStage::STAGE_MODULATE2X: // Arg1 * Arg2 * 2 |
| 919 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 920 | res.x = MulHigh(arg1->x, arg2->x) << 5; |
| 921 | res.y = MulHigh(arg1->y, arg2->y) << 5; |
| 922 | res.z = MulHigh(arg1->z, arg2->z) << 5; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 923 | } |
| 924 | break; |
| 925 | case TextureStage::STAGE_MODULATE4X: // Arg1 * Arg2 * 4 |
| 926 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 927 | res.x = MulHigh(arg1->x, arg2->x) << 6; |
| 928 | res.y = MulHigh(arg1->y, arg2->y) << 6; |
| 929 | res.z = MulHigh(arg1->z, arg2->z) << 6; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 930 | } |
| 931 | break; |
| 932 | case TextureStage::STAGE_ADD: // Arg1 + Arg2 |
| 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 | } |
| 938 | break; |
| 939 | case TextureStage::STAGE_ADDSIGNED: // Arg1 + Arg2 - 0.5 |
| 940 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 941 | res.x = AddSat(arg1->x, arg2->x); |
| 942 | res.y = AddSat(arg1->y, arg2->y); |
| 943 | res.z = AddSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 944 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 945 | res.x = SubSat(res.x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 946 | res.y = SubSat(res.y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 947 | res.z = SubSat(res.z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 948 | } |
| 949 | break; |
| 950 | case TextureStage::STAGE_ADDSIGNED2X: // (Arg1 + Arg2 - 0.5) << 1 |
| 951 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 952 | res.x = AddSat(arg1->x, arg2->x); |
| 953 | res.y = AddSat(arg1->y, arg2->y); |
| 954 | res.z = AddSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 955 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 956 | res.x = SubSat(res.x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 957 | res.y = SubSat(res.y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 958 | res.z = SubSat(res.z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 959 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 960 | res.x = AddSat(res.x, res.x); |
| 961 | res.y = AddSat(res.y, res.y); |
| 962 | res.z = AddSat(res.z, res.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 963 | } |
| 964 | break; |
| 965 | case TextureStage::STAGE_SUBTRACT: // Arg1 - Arg2 |
| 966 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 967 | res.x = SubSat(arg1->x, arg2->x); |
| 968 | res.y = SubSat(arg1->y, arg2->y); |
| 969 | res.z = SubSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 970 | } |
| 971 | break; |
| 972 | case TextureStage::STAGE_ADDSMOOTH: // Arg1 + Arg2 - Arg1 * Arg2 |
| 973 | { |
| 974 | Short4 tmp; |
| 975 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 976 | tmp = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(arg1->x, arg2->x); res.x = SubSat(res.x, tmp); |
| 977 | tmp = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(arg1->y, arg2->y); res.y = SubSat(res.y, tmp); |
| 978 | 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] | 979 | } |
| 980 | break; |
| 981 | case TextureStage::STAGE_MULTIPLYADD: // Arg3 + Arg1 * Arg2 |
| 982 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 983 | res.x = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(res.x, arg3->x); |
| 984 | res.y = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(res.y, arg3->y); |
| 985 | 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] | 986 | } |
| 987 | break; |
| 988 | case TextureStage::STAGE_LERP: // Arg3 * (Arg1 - Arg2) + Arg2 |
| 989 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 990 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, arg3->x) << 4; res.x = AddSat(res.x, arg2->x); |
| 991 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, arg3->y) << 4; res.y = AddSat(res.y, arg2->y); |
| 992 | 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] | 993 | } |
| 994 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 995 | 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] | 996 | { |
| 997 | Short4 tmp; |
| 998 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 999 | 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); |
| 1000 | 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); |
| 1001 | 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] | 1002 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1003 | res.x = res.x << 6; |
| 1004 | res.y = res.y << 6; |
| 1005 | res.z = res.z << 6; |
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.x = AddSat(res.x, res.y); |
| 1008 | res.x = AddSat(res.x, res.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1009 | |
| 1010 | // Clamp to [0, 1] |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1011 | res.x = Max(res.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1012 | res.x = Min(res.x, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1013 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1014 | res.y = res.x; |
| 1015 | res.z = res.x; |
| 1016 | res.w = res.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1017 | } |
| 1018 | break; |
| 1019 | case TextureStage::STAGE_BLENDCURRENTALPHA: // 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, current.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1022 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, current.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1023 | res.z = SubSat(arg1->z, arg2->z); res.z = MulHigh(res.z, current.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_BLENDDIFFUSEALPHA: // 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, r.diffuse.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1029 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, r.diffuse.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1030 | 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] | 1031 | } |
| 1032 | break; |
| 1033 | case TextureStage::STAGE_BLENDFACTORALPHA: // 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, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[3]))) << 4; res.x = AddSat(res.x, arg2->x); |
| 1036 | 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); |
| 1037 | 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] | 1038 | } |
| 1039 | break; |
| 1040 | case TextureStage::STAGE_BLENDTEXTUREALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1041 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1042 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, texture.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1043 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, texture.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1044 | 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] | 1045 | } |
| 1046 | break; |
| 1047 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: // Arg1 + Arg2 * (1 - Alpha) |
| 1048 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1049 | res.x = SubSat(Short4(0x1000), texture.w); res.x = MulHigh(res.x, arg2->x) << 4; res.x = AddSat(res.x, arg1->x); |
| 1050 | res.y = SubSat(Short4(0x1000), texture.w); res.y = MulHigh(res.y, arg2->y) << 4; res.y = AddSat(res.y, arg1->y); |
| 1051 | 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] | 1052 | } |
| 1053 | break; |
| 1054 | case TextureStage::STAGE_PREMODULATE: |
| 1055 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1056 | res.x = arg1->x; |
| 1057 | res.y = arg1->y; |
| 1058 | 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_MODULATEALPHA_ADDCOLOR: // Arg1 + Arg1.w * Arg2 |
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->w, arg2->x) << 4; res.x = AddSat(res.x, arg1->x); |
| 1064 | res.y = MulHigh(arg1->w, arg2->y) << 4; res.y = AddSat(res.y, arg1->y); |
| 1065 | 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] | 1066 | } |
| 1067 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1068 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: // Arg1 * Arg2 + Arg1.w |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1069 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1070 | res.x = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(res.x, arg1->w); |
| 1071 | res.y = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(res.y, arg1->w); |
| 1072 | 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] | 1073 | } |
| 1074 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1075 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: // (1 - Arg1.w) * Arg2 + Arg1 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1076 | { |
| 1077 | Short4 tmp; |
| 1078 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1079 | res.x = AddSat(arg1->x, arg2->x); tmp = MulHigh(arg1->w, arg2->x) << 4; res.x = SubSat(res.x, tmp); |
| 1080 | res.y = AddSat(arg1->y, arg2->y); tmp = MulHigh(arg1->w, arg2->y) << 4; res.y = SubSat(res.y, tmp); |
| 1081 | 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] | 1082 | } |
| 1083 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1084 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: // (1 - Arg1) * Arg2 + Arg1.w |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1085 | { |
| 1086 | Short4 tmp; |
| 1087 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1088 | res.x = AddSat(arg1->w, arg2->x); tmp = MulHigh(arg1->x, arg2->x) << 4; res.x = SubSat(res.x, tmp); |
| 1089 | res.y = AddSat(arg1->w, arg2->y); tmp = MulHigh(arg1->y, arg2->y) << 4; res.y = SubSat(res.y, tmp); |
| 1090 | 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] | 1091 | } |
| 1092 | break; |
| 1093 | case TextureStage::STAGE_BUMPENVMAP: |
| 1094 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1095 | r.du = Float4(texture.x) * Float4(1.0f / 0x0FE0); |
| 1096 | r.dv = Float4(texture.y) * Float4(1.0f / 0x0FE0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1097 | |
| 1098 | Float4 du2; |
| 1099 | Float4 dv2; |
| 1100 | |
| 1101 | du2 = r.du; |
| 1102 | dv2 = r.dv; |
| 1103 | r.du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 1104 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 1105 | r.du += dv2; |
| 1106 | r.dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 1107 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 1108 | r.dv += du2; |
| 1109 | |
| 1110 | perturbate = true; |
| 1111 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1112 | res.x = r.current.x; |
| 1113 | res.y = r.current.y; |
| 1114 | res.z = r.current.z; |
| 1115 | res.w = r.current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1116 | } |
| 1117 | break; |
| 1118 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1119 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1120 | r.du = Float4(texture.x) * Float4(1.0f / 0x0FE0); |
| 1121 | r.dv = Float4(texture.y) * Float4(1.0f / 0x0FE0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1122 | |
| 1123 | Float4 du2; |
| 1124 | Float4 dv2; |
| 1125 | |
| 1126 | du2 = r.du; |
| 1127 | dv2 = r.dv; |
| 1128 | |
| 1129 | r.du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 1130 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 1131 | r.du += dv2; |
| 1132 | r.dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 1133 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 1134 | r.dv += du2; |
| 1135 | |
| 1136 | perturbate = true; |
| 1137 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1138 | r.L = texture.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1139 | r.L = MulHigh(r.L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceScale4))); |
| 1140 | r.L = r.L << 4; |
| 1141 | r.L = AddSat(r.L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceOffset4))); |
| 1142 | r.L = Max(r.L, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1143 | r.L = Min(r.L, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1144 | |
| 1145 | luminance = true; |
| 1146 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1147 | res.x = r.current.x; |
| 1148 | res.y = r.current.y; |
| 1149 | res.z = r.current.z; |
| 1150 | res.w = r.current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1151 | } |
| 1152 | break; |
| 1153 | default: |
| 1154 | ASSERT(false); |
| 1155 | } |
| 1156 | |
| 1157 | if(textureStage.stageOperation != TextureStage::STAGE_DOT3) |
| 1158 | { |
| 1159 | switch(textureStage.firstArgumentAlpha) |
| 1160 | { |
| 1161 | case TextureStage::SOURCE_TEXTURE: arg1 = &texture; break; |
| 1162 | case TextureStage::SOURCE_CONSTANT: arg1 = &constant; break; |
| 1163 | case TextureStage::SOURCE_CURRENT: arg1 = ¤t; break; |
| 1164 | case TextureStage::SOURCE_DIFFUSE: arg1 = &r.diffuse; break; |
| 1165 | case TextureStage::SOURCE_SPECULAR: arg1 = &r.specular; break; |
| 1166 | case TextureStage::SOURCE_TEMP: arg1 = &temp; break; |
| 1167 | case TextureStage::SOURCE_TFACTOR: arg1 = &tfactor; break; |
| 1168 | default: |
| 1169 | ASSERT(false); |
| 1170 | } |
| 1171 | |
| 1172 | switch(textureStage.secondArgumentAlpha) |
| 1173 | { |
| 1174 | case TextureStage::SOURCE_TEXTURE: arg2 = &texture; break; |
| 1175 | case TextureStage::SOURCE_CONSTANT: arg2 = &constant; break; |
| 1176 | case TextureStage::SOURCE_CURRENT: arg2 = ¤t; break; |
| 1177 | case TextureStage::SOURCE_DIFFUSE: arg2 = &r.diffuse; break; |
| 1178 | case TextureStage::SOURCE_SPECULAR: arg2 = &r.specular; break; |
| 1179 | case TextureStage::SOURCE_TEMP: arg2 = &temp; break; |
| 1180 | case TextureStage::SOURCE_TFACTOR: arg2 = &tfactor; break; |
| 1181 | default: |
| 1182 | ASSERT(false); |
| 1183 | } |
| 1184 | |
| 1185 | switch(textureStage.thirdArgumentAlpha) |
| 1186 | { |
| 1187 | case TextureStage::SOURCE_TEXTURE: arg3 = &texture; break; |
| 1188 | case TextureStage::SOURCE_CONSTANT: arg3 = &constant; break; |
| 1189 | case TextureStage::SOURCE_CURRENT: arg3 = ¤t; break; |
| 1190 | case TextureStage::SOURCE_DIFFUSE: arg3 = &r.diffuse; break; |
| 1191 | case TextureStage::SOURCE_SPECULAR: arg3 = &r.specular; break; |
| 1192 | case TextureStage::SOURCE_TEMP: arg3 = &temp; break; |
| 1193 | case TextureStage::SOURCE_TFACTOR: arg3 = &tfactor; break; |
| 1194 | default: |
| 1195 | ASSERT(false); |
| 1196 | } |
| 1197 | |
| 1198 | switch(textureStage.firstModifierAlpha) // FIXME: Check if actually used |
| 1199 | { |
| 1200 | case TextureStage::MODIFIER_COLOR: |
| 1201 | break; |
| 1202 | case TextureStage::MODIFIER_INVCOLOR: |
| 1203 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1204 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1205 | |
| 1206 | arg1 = &mod1; |
| 1207 | } |
| 1208 | break; |
| 1209 | case TextureStage::MODIFIER_ALPHA: |
| 1210 | { |
| 1211 | // Redudant |
| 1212 | } |
| 1213 | break; |
| 1214 | case TextureStage::MODIFIER_INVALPHA: |
| 1215 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1216 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1217 | |
| 1218 | arg1 = &mod1; |
| 1219 | } |
| 1220 | break; |
| 1221 | default: |
| 1222 | ASSERT(false); |
| 1223 | } |
| 1224 | |
| 1225 | switch(textureStage.secondModifierAlpha) // FIXME: Check if actually used |
| 1226 | { |
| 1227 | case TextureStage::MODIFIER_COLOR: |
| 1228 | break; |
| 1229 | case TextureStage::MODIFIER_INVCOLOR: |
| 1230 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1231 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1232 | |
| 1233 | arg2 = &mod2; |
| 1234 | } |
| 1235 | break; |
| 1236 | case TextureStage::MODIFIER_ALPHA: |
| 1237 | { |
| 1238 | // Redudant |
| 1239 | } |
| 1240 | break; |
| 1241 | case TextureStage::MODIFIER_INVALPHA: |
| 1242 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1243 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1244 | |
| 1245 | arg2 = &mod2; |
| 1246 | } |
| 1247 | break; |
| 1248 | default: |
| 1249 | ASSERT(false); |
| 1250 | } |
| 1251 | |
| 1252 | switch(textureStage.thirdModifierAlpha) // FIXME: Check if actually used |
| 1253 | { |
| 1254 | case TextureStage::MODIFIER_COLOR: |
| 1255 | break; |
| 1256 | case TextureStage::MODIFIER_INVCOLOR: |
| 1257 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1258 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1259 | |
| 1260 | arg3 = &mod3; |
| 1261 | } |
| 1262 | break; |
| 1263 | case TextureStage::MODIFIER_ALPHA: |
| 1264 | { |
| 1265 | // Redudant |
| 1266 | } |
| 1267 | break; |
| 1268 | case TextureStage::MODIFIER_INVALPHA: |
| 1269 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1270 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1271 | |
| 1272 | arg3 = &mod3; |
| 1273 | } |
| 1274 | break; |
| 1275 | default: |
| 1276 | ASSERT(false); |
| 1277 | } |
| 1278 | |
| 1279 | switch(textureStage.stageOperationAlpha) |
| 1280 | { |
| 1281 | case TextureStage::STAGE_DISABLE: |
| 1282 | break; |
| 1283 | case TextureStage::STAGE_SELECTARG1: // Arg1 |
| 1284 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1285 | res.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1286 | } |
| 1287 | break; |
| 1288 | case TextureStage::STAGE_SELECTARG2: // Arg2 |
| 1289 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1290 | res.w = arg2->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1291 | } |
| 1292 | break; |
| 1293 | case TextureStage::STAGE_SELECTARG3: // Arg3 |
| 1294 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1295 | res.w = arg3->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1296 | } |
| 1297 | break; |
| 1298 | case TextureStage::STAGE_MODULATE: // Arg1 * Arg2 |
| 1299 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1300 | res.w = MulHigh(arg1->w, arg2->w) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1301 | } |
| 1302 | break; |
| 1303 | case TextureStage::STAGE_MODULATE2X: // Arg1 * Arg2 * 2 |
| 1304 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1305 | res.w = MulHigh(arg1->w, arg2->w) << 5; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1306 | } |
| 1307 | break; |
| 1308 | case TextureStage::STAGE_MODULATE4X: // Arg1 * Arg2 * 4 |
| 1309 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1310 | res.w = MulHigh(arg1->w, arg2->w) << 6; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1311 | } |
| 1312 | break; |
| 1313 | case TextureStage::STAGE_ADD: // Arg1 + Arg2 |
| 1314 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1315 | res.w = AddSat(arg1->w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1316 | } |
| 1317 | break; |
| 1318 | case TextureStage::STAGE_ADDSIGNED: // Arg1 + Arg2 - 0.5 |
| 1319 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1320 | res.w = AddSat(arg1->w, arg2->w); |
| 1321 | res.w = SubSat(res.w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1322 | } |
| 1323 | break; |
| 1324 | case TextureStage::STAGE_ADDSIGNED2X: // (Arg1 + Arg2 - 0.5) << 1 |
| 1325 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1326 | res.w = AddSat(arg1->w, arg2->w); |
| 1327 | res.w = SubSat(res.w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 1328 | res.w = AddSat(res.w, res.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1329 | } |
| 1330 | break; |
| 1331 | case TextureStage::STAGE_SUBTRACT: // Arg1 - Arg2 |
| 1332 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1333 | res.w = SubSat(arg1->w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1334 | } |
| 1335 | break; |
| 1336 | case TextureStage::STAGE_ADDSMOOTH: // Arg1 + Arg2 - Arg1 * Arg2 |
| 1337 | { |
| 1338 | Short4 tmp; |
| 1339 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1340 | 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] | 1341 | } |
| 1342 | break; |
| 1343 | case TextureStage::STAGE_MULTIPLYADD: // Arg3 + Arg1 * Arg2 |
| 1344 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1345 | 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] | 1346 | } |
| 1347 | break; |
| 1348 | case TextureStage::STAGE_LERP: // Arg3 * (Arg1 - Arg2) + Arg2 |
| 1349 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1350 | 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] | 1351 | } |
| 1352 | break; |
| 1353 | case TextureStage::STAGE_DOT3: |
| 1354 | break; // Already computed in color channel |
| 1355 | case TextureStage::STAGE_BLENDCURRENTALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1356 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1357 | res.w = SubSat(arg1->w, arg2->w); res.w = MulHigh(res.w, current.w) << 4; res.w = AddSat(res.w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1358 | } |
| 1359 | break; |
| 1360 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: // Arg1 * (Alpha) + Arg2 * (1 - Alpha) |
| 1361 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1362 | 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] | 1363 | } |
| 1364 | break; |
| 1365 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1366 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1367 | 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] | 1368 | } |
| 1369 | break; |
| 1370 | case TextureStage::STAGE_BLENDTEXTUREALPHA: // Arg1 * (Alpha) + Arg2 * (1 - Alpha) |
| 1371 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1372 | 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] | 1373 | } |
| 1374 | break; |
| 1375 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: // Arg1 + Arg2 * (1 - Alpha) |
| 1376 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1377 | 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] | 1378 | } |
| 1379 | break; |
| 1380 | case TextureStage::STAGE_PREMODULATE: |
| 1381 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1382 | res.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1383 | } |
| 1384 | break; |
| 1385 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1386 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1387 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1388 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1389 | case TextureStage::STAGE_BUMPENVMAP: |
| 1390 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1391 | break; // Invalid alpha operations |
| 1392 | default: |
| 1393 | ASSERT(false); |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | // Clamp result to [0, 1] |
| 1398 | |
| 1399 | switch(textureStage.stageOperation) |
| 1400 | { |
| 1401 | case TextureStage::STAGE_DISABLE: |
| 1402 | case TextureStage::STAGE_SELECTARG1: |
| 1403 | case TextureStage::STAGE_SELECTARG2: |
| 1404 | case TextureStage::STAGE_SELECTARG3: |
| 1405 | case TextureStage::STAGE_MODULATE: |
| 1406 | case TextureStage::STAGE_MODULATE2X: |
| 1407 | case TextureStage::STAGE_MODULATE4X: |
| 1408 | case TextureStage::STAGE_ADD: |
| 1409 | case TextureStage::STAGE_MULTIPLYADD: |
| 1410 | case TextureStage::STAGE_LERP: |
| 1411 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1412 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1413 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1414 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1415 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1416 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1417 | case TextureStage::STAGE_PREMODULATE: |
| 1418 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1419 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1420 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1421 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1422 | case TextureStage::STAGE_BUMPENVMAP: |
| 1423 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1424 | if(state.textureStage[stage].cantUnderflow) |
| 1425 | { |
| 1426 | break; // Can't go below zero |
| 1427 | } |
| 1428 | case TextureStage::STAGE_ADDSIGNED: |
| 1429 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1430 | case TextureStage::STAGE_SUBTRACT: |
| 1431 | case TextureStage::STAGE_ADDSMOOTH: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1432 | res.x = Max(res.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1433 | res.y = Max(res.y, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1434 | res.z = Max(res.z, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1435 | break; |
| 1436 | default: |
| 1437 | ASSERT(false); |
| 1438 | } |
| 1439 | |
| 1440 | switch(textureStage.stageOperationAlpha) |
| 1441 | { |
| 1442 | case TextureStage::STAGE_DISABLE: |
| 1443 | case TextureStage::STAGE_SELECTARG1: |
| 1444 | case TextureStage::STAGE_SELECTARG2: |
| 1445 | case TextureStage::STAGE_SELECTARG3: |
| 1446 | case TextureStage::STAGE_MODULATE: |
| 1447 | case TextureStage::STAGE_MODULATE2X: |
| 1448 | case TextureStage::STAGE_MODULATE4X: |
| 1449 | case TextureStage::STAGE_ADD: |
| 1450 | case TextureStage::STAGE_MULTIPLYADD: |
| 1451 | case TextureStage::STAGE_LERP: |
| 1452 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1453 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1454 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1455 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1456 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1457 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1458 | case TextureStage::STAGE_PREMODULATE: |
| 1459 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1460 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1461 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1462 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1463 | case TextureStage::STAGE_BUMPENVMAP: |
| 1464 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1465 | if(state.textureStage[stage].cantUnderflow) |
| 1466 | { |
| 1467 | break; // Can't go below zero |
| 1468 | } |
| 1469 | case TextureStage::STAGE_ADDSIGNED: |
| 1470 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1471 | case TextureStage::STAGE_SUBTRACT: |
| 1472 | case TextureStage::STAGE_ADDSMOOTH: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1473 | res.w = Max(res.w, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1474 | break; |
| 1475 | default: |
| 1476 | ASSERT(false); |
| 1477 | } |
| 1478 | |
| 1479 | switch(textureStage.stageOperation) |
| 1480 | { |
| 1481 | case TextureStage::STAGE_DISABLE: |
| 1482 | case TextureStage::STAGE_SELECTARG1: |
| 1483 | case TextureStage::STAGE_SELECTARG2: |
| 1484 | case TextureStage::STAGE_SELECTARG3: |
| 1485 | case TextureStage::STAGE_MODULATE: |
| 1486 | case TextureStage::STAGE_SUBTRACT: |
| 1487 | case TextureStage::STAGE_ADDSMOOTH: |
| 1488 | case TextureStage::STAGE_LERP: |
| 1489 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1490 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1491 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1492 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1493 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1494 | case TextureStage::STAGE_PREMODULATE: |
| 1495 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1496 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1497 | case TextureStage::STAGE_BUMPENVMAP: |
| 1498 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1499 | break; // Can't go above one |
| 1500 | case TextureStage::STAGE_MODULATE2X: |
| 1501 | case TextureStage::STAGE_MODULATE4X: |
| 1502 | case TextureStage::STAGE_ADD: |
| 1503 | case TextureStage::STAGE_ADDSIGNED: |
| 1504 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1505 | case TextureStage::STAGE_MULTIPLYADD: |
| 1506 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1507 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1508 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1509 | res.x = Min(res.x, Short4(0x1000)); |
| 1510 | res.y = Min(res.y, Short4(0x1000)); |
| 1511 | res.z = Min(res.z, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1512 | break; |
| 1513 | default: |
| 1514 | ASSERT(false); |
| 1515 | } |
| 1516 | |
| 1517 | switch(textureStage.stageOperationAlpha) |
| 1518 | { |
| 1519 | case TextureStage::STAGE_DISABLE: |
| 1520 | case TextureStage::STAGE_SELECTARG1: |
| 1521 | case TextureStage::STAGE_SELECTARG2: |
| 1522 | case TextureStage::STAGE_SELECTARG3: |
| 1523 | case TextureStage::STAGE_MODULATE: |
| 1524 | case TextureStage::STAGE_SUBTRACT: |
| 1525 | case TextureStage::STAGE_ADDSMOOTH: |
| 1526 | case TextureStage::STAGE_LERP: |
| 1527 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1528 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1529 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1530 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1531 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1532 | case TextureStage::STAGE_PREMODULATE: |
| 1533 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1534 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1535 | case TextureStage::STAGE_BUMPENVMAP: |
| 1536 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1537 | break; // Can't go above one |
| 1538 | case TextureStage::STAGE_MODULATE2X: |
| 1539 | case TextureStage::STAGE_MODULATE4X: |
| 1540 | case TextureStage::STAGE_ADD: |
| 1541 | case TextureStage::STAGE_ADDSIGNED: |
| 1542 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1543 | case TextureStage::STAGE_MULTIPLYADD: |
| 1544 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1545 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1546 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1547 | res.w = Min(res.w, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1548 | break; |
| 1549 | default: |
| 1550 | ASSERT(false); |
| 1551 | } |
| 1552 | |
| 1553 | switch(textureStage.destinationArgument) |
| 1554 | { |
| 1555 | case TextureStage::DESTINATION_CURRENT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1556 | current.x = res.x; |
| 1557 | current.y = res.y; |
| 1558 | current.z = res.z; |
| 1559 | current.w = res.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1560 | break; |
| 1561 | case TextureStage::DESTINATION_TEMP: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1562 | temp.x = res.x; |
| 1563 | temp.y = res.y; |
| 1564 | temp.z = res.z; |
| 1565 | temp.w = res.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1566 | break; |
| 1567 | default: |
| 1568 | ASSERT(false); |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | void PixelRoutine::alphaTest(Registers &r, Int &aMask, Short4 &alpha) |
| 1573 | { |
| 1574 | Short4 cmp; |
| 1575 | Short4 equal; |
| 1576 | |
| 1577 | switch(state.alphaCompareMode) |
| 1578 | { |
| 1579 | case Context::ALPHA_ALWAYS: |
| 1580 | aMask = 0xF; |
| 1581 | break; |
| 1582 | case Context::ALPHA_NEVER: |
| 1583 | aMask = 0x0; |
| 1584 | break; |
| 1585 | case Context::ALPHA_EQUAL: |
| 1586 | cmp = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1587 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1588 | break; |
| 1589 | case Context::ALPHA_NOTEQUAL: // a != b ~ !(a == b) |
| 1590 | cmp = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))) ^ Short4((short)0xFFFF, (short)0xFFFF, (short)0xFFFF, (short)0xFFFF); // FIXME |
| 1591 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1592 | break; |
| 1593 | case Context::ALPHA_LESS: // a < b ~ b > a |
| 1594 | cmp = CmpGT(*Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4)), alpha); |
| 1595 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1596 | break; |
| 1597 | case Context::ALPHA_GREATEREQUAL: // a >= b ~ (a > b) || (a == b) ~ !(b > a) // TODO: Approximate |
| 1598 | equal = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1599 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1600 | cmp |= equal; |
| 1601 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1602 | break; |
| 1603 | case Context::ALPHA_LESSEQUAL: // a <= b ~ !(a > b) |
| 1604 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))) ^ Short4((short)0xFFFF, (short)0xFFFF, (short)0xFFFF, (short)0xFFFF); // FIXME |
| 1605 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1606 | break; |
| 1607 | case Context::ALPHA_GREATER: // a > b |
| 1608 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1609 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1610 | break; |
| 1611 | default: |
| 1612 | ASSERT(false); |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | void PixelRoutine::alphaToCoverage(Registers &r, Int cMask[4], Float4 &alpha) |
| 1617 | { |
| 1618 | Int4 coverage0 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c0))); |
| 1619 | Int4 coverage1 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c1))); |
| 1620 | Int4 coverage2 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c2))); |
| 1621 | Int4 coverage3 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c3))); |
| 1622 | |
| 1623 | Int aMask0 = SignMask(coverage0); |
| 1624 | Int aMask1 = SignMask(coverage1); |
| 1625 | Int aMask2 = SignMask(coverage2); |
| 1626 | Int aMask3 = SignMask(coverage3); |
| 1627 | |
| 1628 | cMask[0] &= aMask0; |
| 1629 | cMask[1] &= aMask1; |
| 1630 | cMask[2] &= aMask2; |
| 1631 | cMask[3] &= aMask3; |
| 1632 | } |
| 1633 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1634 | Bool PixelRoutine::alphaTest(Registers &r, Int cMask[4], Vector4i ¤t) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1635 | { |
| 1636 | if(!state.alphaTestActive()) |
| 1637 | { |
| 1638 | return true; |
| 1639 | } |
| 1640 | |
| 1641 | Int aMask; |
| 1642 | |
| 1643 | if(state.transparencyAntialiasing == Context::TRANSPARENCY_NONE) |
| 1644 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1645 | alphaTest(r, aMask, current.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1646 | |
| 1647 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 1648 | { |
| 1649 | cMask[q] &= aMask; |
| 1650 | } |
| 1651 | } |
| 1652 | else if(state.transparencyAntialiasing == Context::TRANSPARENCY_ALPHA_TO_COVERAGE) |
| 1653 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1654 | Float4 alpha = Float4(current.w) * Float4(1.0f / 0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1655 | |
| 1656 | alphaToCoverage(r, cMask, alpha); |
| 1657 | } |
| 1658 | else ASSERT(false); |
| 1659 | |
| 1660 | Int pass = cMask[0]; |
| 1661 | |
| 1662 | for(unsigned int q = 1; q < state.multiSample; q++) |
| 1663 | { |
| 1664 | pass = pass | cMask[q]; |
| 1665 | } |
| 1666 | |
| 1667 | return pass != 0x0; |
| 1668 | } |
| 1669 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1670 | Bool PixelRoutine::alphaTest(Registers &r, Int cMask[4], Vector4f &c0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1671 | { |
| 1672 | if(!state.alphaTestActive()) |
| 1673 | { |
| 1674 | return true; |
| 1675 | } |
| 1676 | |
| 1677 | Int aMask; |
| 1678 | |
| 1679 | if(state.transparencyAntialiasing == Context::TRANSPARENCY_NONE) |
| 1680 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1681 | Short4 alpha = RoundShort4(c0.w * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1682 | |
| 1683 | alphaTest(r, aMask, alpha); |
| 1684 | |
| 1685 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 1686 | { |
| 1687 | cMask[q] &= aMask; |
| 1688 | } |
| 1689 | } |
| 1690 | else if(state.transparencyAntialiasing == Context::TRANSPARENCY_ALPHA_TO_COVERAGE) |
| 1691 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1692 | alphaToCoverage(r, cMask, c0.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1693 | } |
| 1694 | else ASSERT(false); |
| 1695 | |
| 1696 | Int pass = cMask[0]; |
| 1697 | |
| 1698 | for(unsigned int q = 1; q < state.multiSample; q++) |
| 1699 | { |
| 1700 | pass = pass | cMask[q]; |
| 1701 | } |
| 1702 | |
| 1703 | return pass != 0x0; |
| 1704 | } |
| 1705 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1706 | void PixelRoutine::fogBlend(Registers &r, Vector4i ¤t, Float4 &f, Float4 &z, Float4 &rhw) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1707 | { |
| 1708 | if(!state.fogActive) |
| 1709 | { |
| 1710 | return; |
| 1711 | } |
| 1712 | |
| 1713 | if(state.pixelFogMode != Context::FOG_NONE) |
| 1714 | { |
| 1715 | pixelFog(r, f, z, rhw); |
| 1716 | } |
| 1717 | |
| 1718 | UShort4 fog = convertFixed16(f, true); |
| 1719 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1720 | current.x = As<Short4>(MulHigh(As<UShort4>(current.x), fog)); |
| 1721 | current.y = As<Short4>(MulHigh(As<UShort4>(current.y), fog)); |
| 1722 | current.z = As<Short4>(MulHigh(As<UShort4>(current.z), fog)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1723 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1724 | UShort4 invFog = UShort4(0xFFFFu) - fog; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1725 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1726 | current.x += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData,fog.color4[0])))); |
| 1727 | current.y += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData,fog.color4[1])))); |
| 1728 | 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] | 1729 | } |
| 1730 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1731 | 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] | 1732 | { |
| 1733 | if(!state.fogActive) |
| 1734 | { |
| 1735 | return; |
| 1736 | } |
| 1737 | |
| 1738 | if(state.pixelFogMode != Context::FOG_NONE) |
| 1739 | { |
| 1740 | pixelFog(r, fog, z, rhw); |
| 1741 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1742 | fog = Min(fog, Float4(1.0f)); |
| 1743 | fog = Max(fog, Float4(0.0f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1744 | } |
| 1745 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1746 | c0.x -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[0])); |
| 1747 | c0.y -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[1])); |
| 1748 | c0.z -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1749 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1750 | c0.x *= fog; |
| 1751 | c0.y *= fog; |
| 1752 | c0.z *= fog; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1753 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1754 | c0.x += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[0])); |
| 1755 | c0.y += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[1])); |
| 1756 | c0.z += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | void PixelRoutine::pixelFog(Registers &r, Float4 &visibility, Float4 &z, Float4 &rhw) |
| 1760 | { |
| 1761 | Float4 &zw = visibility; |
| 1762 | |
| 1763 | if(state.pixelFogMode != Context::FOG_NONE) |
| 1764 | { |
| 1765 | if(state.wBasedFog) |
| 1766 | { |
| 1767 | zw = rhw; |
| 1768 | } |
| 1769 | else |
| 1770 | { |
| 1771 | if(complementaryDepthBuffer) |
| 1772 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1773 | zw = Float4(1.0f) - z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1774 | } |
| 1775 | else |
| 1776 | { |
| 1777 | zw = z; |
| 1778 | } |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | switch(state.pixelFogMode) |
| 1783 | { |
| 1784 | case Context::FOG_NONE: |
| 1785 | break; |
| 1786 | case Context::FOG_LINEAR: |
| 1787 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.scale)); |
| 1788 | zw += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.offset)); |
| 1789 | break; |
| 1790 | case Context::FOG_EXP: |
| 1791 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.densityE)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1792 | zw = exponential2(zw, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1793 | break; |
| 1794 | case Context::FOG_EXP2: |
| 1795 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.densityE2)); |
| 1796 | zw *= zw; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1797 | zw = exponential2(zw, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1798 | zw = Rcp_pp(zw); |
| 1799 | break; |
| 1800 | default: |
| 1801 | ASSERT(false); |
| 1802 | } |
| 1803 | } |
| 1804 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1805 | void PixelRoutine::specularPixel(Vector4i ¤t, Vector4i &specular) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1806 | { |
| 1807 | if(!state.specularAdd) |
| 1808 | { |
| 1809 | return; |
| 1810 | } |
| 1811 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1812 | current.x = AddSat(current.x, specular.x); |
| 1813 | current.y = AddSat(current.y, specular.y); |
| 1814 | current.z = AddSat(current.z, specular.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void PixelRoutine::writeDepth(Registers &r, Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask) |
| 1818 | { |
| 1819 | if(!state.depthWriteEnable) |
| 1820 | { |
| 1821 | return; |
| 1822 | } |
| 1823 | |
| 1824 | Float4 Z = z; |
| 1825 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1826 | if(shader && shader->depthOverride()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1827 | { |
| 1828 | if(complementaryDepthBuffer) |
| 1829 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1830 | Z = Float4(1.0f) - r.oDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1831 | } |
| 1832 | else |
| 1833 | { |
| 1834 | Z = r.oDepth; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | Pointer<Byte> buffer; |
| 1839 | Int pitch; |
| 1840 | |
| 1841 | if(!state.quadLayoutDepthBuffer) |
| 1842 | { |
| 1843 | buffer = zBuffer + 4 * x; |
| 1844 | pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); |
| 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | buffer = zBuffer + 8 * x; |
| 1849 | } |
| 1850 | |
| 1851 | if(q > 0) |
| 1852 | { |
| 1853 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,depthSliceB)); |
| 1854 | } |
| 1855 | |
| 1856 | Float4 zValue; |
| 1857 | |
| 1858 | if(state.depthCompareMode != Context::DEPTH_NEVER || (state.depthCompareMode != Context::DEPTH_ALWAYS && !state.depthWriteEnable)) |
| 1859 | { |
| 1860 | if(!state.quadLayoutDepthBuffer) |
| 1861 | { |
| 1862 | // FIXME: Properly optimizes? |
| 1863 | zValue.xy = *Pointer<Float4>(buffer); |
| 1864 | zValue.zw = *Pointer<Float4>(buffer + pitch - 8); |
| 1865 | } |
| 1866 | else |
| 1867 | { |
| 1868 | zValue = *Pointer<Float4>(buffer, 16); |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | Z = As<Float4>(As<Int4>(Z) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X) + zMask * 16, 16)); |
| 1873 | zValue = As<Float4>(As<Int4>(zValue) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X) + zMask * 16, 16)); |
| 1874 | Z = As<Float4>(As<Int4>(Z) | As<Int4>(zValue)); |
| 1875 | |
| 1876 | if(!state.quadLayoutDepthBuffer) |
| 1877 | { |
| 1878 | // FIXME: Properly optimizes? |
| 1879 | *Pointer<Float2>(buffer) = Float2(Z.xy); |
| 1880 | *Pointer<Float2>(buffer + pitch) = Float2(Z.zw); |
| 1881 | } |
| 1882 | else |
| 1883 | { |
| 1884 | *Pointer<Float4>(buffer, 16) = Z; |
| 1885 | } |
| 1886 | } |
| 1887 | |
| 1888 | void PixelRoutine::writeStencil(Registers &r, Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &zMask, Int &cMask) |
| 1889 | { |
| 1890 | if(!state.stencilActive) |
| 1891 | { |
| 1892 | return; |
| 1893 | } |
| 1894 | |
| 1895 | if(state.stencilPassOperation == Context::OPERATION_KEEP && state.stencilZFailOperation == Context::OPERATION_KEEP && state.stencilFailOperation == Context::OPERATION_KEEP) |
| 1896 | { |
| 1897 | if(!state.twoSidedStencil || (state.stencilPassOperationCCW == Context::OPERATION_KEEP && state.stencilZFailOperationCCW == Context::OPERATION_KEEP && state.stencilFailOperationCCW == Context::OPERATION_KEEP)) |
| 1898 | { |
| 1899 | return; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | if(state.stencilWriteMasked && (!state.twoSidedStencil || state.stencilWriteMaskedCCW)) |
| 1904 | { |
| 1905 | return; |
| 1906 | } |
| 1907 | |
| 1908 | Pointer<Byte> buffer = sBuffer + 2 * x; |
| 1909 | |
| 1910 | if(q > 0) |
| 1911 | { |
| 1912 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,stencilSliceB)); |
| 1913 | } |
| 1914 | |
| 1915 | Byte8 bufferValue = As<Byte8>(Long1(*Pointer<UInt>(buffer))); |
| 1916 | |
| 1917 | Byte8 newValue; |
| 1918 | stencilOperation(r, newValue, bufferValue, (Context::StencilOperation)state.stencilPassOperation, (Context::StencilOperation)state.stencilZFailOperation, (Context::StencilOperation)state.stencilFailOperation, false, zMask, sMask); |
| 1919 | |
| 1920 | if(!state.noStencilWriteMask) |
| 1921 | { |
| 1922 | Byte8 maskedValue = bufferValue; |
| 1923 | newValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].writeMaskQ)); |
| 1924 | maskedValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].invWriteMaskQ)); |
| 1925 | newValue |= maskedValue; |
| 1926 | } |
| 1927 | |
| 1928 | if(state.twoSidedStencil) |
| 1929 | { |
| 1930 | Byte8 newValueCCW; |
| 1931 | |
| 1932 | stencilOperation(r, newValueCCW, bufferValue, (Context::StencilOperation)state.stencilPassOperationCCW, (Context::StencilOperation)state.stencilZFailOperationCCW, (Context::StencilOperation)state.stencilFailOperationCCW, true, zMask, sMask); |
| 1933 | |
| 1934 | if(!state.noStencilWriteMaskCCW) |
| 1935 | { |
| 1936 | Byte8 maskedValue = bufferValue; |
| 1937 | newValueCCW &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].writeMaskQ)); |
| 1938 | maskedValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].invWriteMaskQ)); |
| 1939 | newValueCCW |= maskedValue; |
| 1940 | } |
| 1941 | |
| 1942 | newValue &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,clockwiseMask)); |
| 1943 | newValueCCW &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,invClockwiseMask)); |
| 1944 | newValue |= newValueCCW; |
| 1945 | } |
| 1946 | |
| 1947 | newValue &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * cMask); |
| 1948 | bufferValue &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * cMask); |
| 1949 | newValue |= bufferValue; |
| 1950 | |
| 1951 | *Pointer<UInt>(buffer) = UInt(As<Long>(newValue)); |
| 1952 | } |
| 1953 | |
| 1954 | void PixelRoutine::stencilOperation(Registers &r, Byte8 &newValue, Byte8 &bufferValue, Context::StencilOperation stencilPassOperation, Context::StencilOperation stencilZFailOperation, Context::StencilOperation stencilFailOperation, bool CCW, Int &zMask, Int &sMask) |
| 1955 | { |
| 1956 | Byte8 &pass = newValue; |
| 1957 | Byte8 fail; |
| 1958 | Byte8 zFail; |
| 1959 | |
| 1960 | stencilOperation(r, pass, bufferValue, stencilPassOperation, CCW); |
| 1961 | |
| 1962 | if(stencilZFailOperation != stencilPassOperation) |
| 1963 | { |
| 1964 | stencilOperation(r, zFail, bufferValue, stencilZFailOperation, CCW); |
| 1965 | } |
| 1966 | |
| 1967 | if(stencilFailOperation != stencilPassOperation || stencilFailOperation != stencilZFailOperation) |
| 1968 | { |
| 1969 | stencilOperation(r, fail, bufferValue, stencilFailOperation, CCW); |
| 1970 | } |
| 1971 | |
| 1972 | if(stencilFailOperation != stencilPassOperation || stencilFailOperation != stencilZFailOperation) |
| 1973 | { |
| 1974 | if(state.depthTestActive && stencilZFailOperation != stencilPassOperation) // zMask valid and values not the same |
| 1975 | { |
| 1976 | pass &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * zMask); |
| 1977 | zFail &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * zMask); |
| 1978 | pass |= zFail; |
| 1979 | } |
| 1980 | |
| 1981 | pass &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * sMask); |
| 1982 | fail &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * sMask); |
| 1983 | pass |= fail; |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | void PixelRoutine::stencilOperation(Registers &r, Byte8 &output, Byte8 &bufferValue, Context::StencilOperation operation, bool CCW) |
| 1988 | { |
| 1989 | switch(operation) |
| 1990 | { |
| 1991 | case Context::OPERATION_KEEP: |
| 1992 | output = bufferValue; |
| 1993 | break; |
| 1994 | case Context::OPERATION_ZERO: |
| 1995 | output = Byte8(0x0000000000000000); |
| 1996 | break; |
| 1997 | case Context::OPERATION_REPLACE: |
| 1998 | output = *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceQ)); |
| 1999 | break; |
| 2000 | case Context::OPERATION_INCRSAT: |
| 2001 | output = AddSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1)); |
| 2002 | break; |
| 2003 | case Context::OPERATION_DECRSAT: |
| 2004 | output = SubSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1)); |
| 2005 | break; |
| 2006 | case Context::OPERATION_INVERT: |
| 2007 | output = bufferValue ^ Byte8(0xFFFFFFFFFFFFFFFF); |
| 2008 | break; |
| 2009 | case Context::OPERATION_INCR: |
| 2010 | output = bufferValue + Byte8(1, 1, 1, 1, 1, 1, 1, 1); |
| 2011 | break; |
| 2012 | case Context::OPERATION_DECR: |
| 2013 | output = bufferValue - Byte8(1, 1, 1, 1, 1, 1, 1, 1); |
| 2014 | break; |
| 2015 | default: |
| 2016 | ASSERT(false); |
| 2017 | } |
| 2018 | } |
| 2019 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2020 | void PixelRoutine::sampleTexture(Registers &r, Vector4i &c, int coordinates, int stage, bool project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2021 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2022 | Float4 u = r.vf[2 + coordinates].x; |
| 2023 | Float4 v = r.vf[2 + coordinates].y; |
| 2024 | Float4 w = r.vf[2 + coordinates].z; |
| 2025 | Float4 q = r.vf[2 + coordinates].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2026 | |
| 2027 | if(perturbate) |
| 2028 | { |
| 2029 | u += r.du; |
| 2030 | v += r.dv; |
| 2031 | |
| 2032 | perturbate = false; |
| 2033 | } |
| 2034 | |
| 2035 | sampleTexture(r, c, stage, u, v, w, q, project); |
| 2036 | } |
| 2037 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2038 | void PixelRoutine::sampleTexture(Registers &r, Vector4i &c, int stage, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project, bool bias, bool fixed12) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2039 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2040 | Vector4f dsx; |
| 2041 | Vector4f dsy; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2042 | |
| 2043 | sampleTexture(r, c, stage, u, v, w, q, dsx, dsy, project, bias, fixed12, false); |
| 2044 | } |
| 2045 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2046 | void PixelRoutine::sampleTexture(Registers &r, Vector4i &c, int stage, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, bool project, bool bias, bool fixed12, bool gradients, bool lodProvided) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2047 | { |
| 2048 | #if PERF_PROFILE |
| 2049 | Long texTime = Ticks(); |
| 2050 | #endif |
| 2051 | |
| 2052 | Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap) + stage * sizeof(Texture); |
| 2053 | |
| 2054 | if(!project) |
| 2055 | { |
| 2056 | sampler[stage]->sampleTexture(texture, c, u, v, w, q, dsx, dsy, bias, fixed12, gradients, lodProvided); |
| 2057 | } |
| 2058 | else |
| 2059 | { |
| 2060 | Float4 rq = reciprocal(q); |
| 2061 | |
| 2062 | Float4 u_q = u * rq; |
| 2063 | Float4 v_q = v * rq; |
| 2064 | Float4 w_q = w * rq; |
| 2065 | |
| 2066 | sampler[stage]->sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy, bias, fixed12, gradients, lodProvided); |
| 2067 | } |
| 2068 | |
| 2069 | #if PERF_PROFILE |
| 2070 | r.cycles[PERF_TEX] += Ticks() - texTime; |
| 2071 | #endif |
| 2072 | } |
| 2073 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2074 | 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) |
| 2075 | { |
| 2076 | if(sampler.type == Shader::PARAMETER_SAMPLER && sampler.rel.type == Shader::PARAMETER_VOID) |
| 2077 | { |
| 2078 | sampleTexture(r, c, sampler.index, u, v, w, q, dsx, dsy, project, bias, gradients, lodProvided); |
| 2079 | } |
| 2080 | else |
| 2081 | { |
| 2082 | Int index = As<Int>(Float(reg(r, sampler).x.x)); |
| 2083 | |
| 2084 | for(int i = 0; i < 16; i++) |
| 2085 | { |
| 2086 | if(shader->usesSampler(i)) |
| 2087 | { |
| 2088 | If(index == i) |
| 2089 | { |
| 2090 | sampleTexture(r, c, i, u, v, w, q, dsx, dsy, project, bias, gradients, lodProvided); |
| 2091 | // FIXME: When the sampler states are the same, we could use one sampler and just index the texture |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | 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] | 2099 | { |
| 2100 | #if PERF_PROFILE |
| 2101 | Long texTime = Ticks(); |
| 2102 | #endif |
| 2103 | |
| 2104 | Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap) + stage * sizeof(Texture); |
| 2105 | |
| 2106 | if(!project) |
| 2107 | { |
| 2108 | sampler[stage]->sampleTexture(texture, c, u, v, w, q, dsx, dsy, bias, gradients, lodProvided); |
| 2109 | } |
| 2110 | else |
| 2111 | { |
| 2112 | Float4 rq = reciprocal(q); |
| 2113 | |
| 2114 | Float4 u_q = u * rq; |
| 2115 | Float4 v_q = v * rq; |
| 2116 | Float4 w_q = w * rq; |
| 2117 | |
| 2118 | sampler[stage]->sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy, bias, gradients, lodProvided); |
| 2119 | } |
| 2120 | |
| 2121 | #if PERF_PROFILE |
| 2122 | r.cycles[PERF_TEX] += Ticks() - texTime; |
| 2123 | #endif |
| 2124 | } |
| 2125 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2126 | void PixelRoutine::clampColor(Vector4f oC[4]) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2127 | { |
| 2128 | for(int index = 0; index < 4; index++) |
| 2129 | { |
| 2130 | if(!state.colorWriteActive(index) && !(index == 0 && state.alphaTestActive())) |
| 2131 | { |
| 2132 | continue; |
| 2133 | } |
| 2134 | |
| 2135 | switch(state.targetFormat[index]) |
| 2136 | { |
| 2137 | case FORMAT_NULL: |
| 2138 | break; |
| 2139 | case FORMAT_A16B16G16R16: |
| 2140 | case FORMAT_A8R8G8B8: |
| 2141 | case FORMAT_X8R8G8B8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2142 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2143 | case FORMAT_G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2144 | oC[index].x = Max(oC[index].x, Float4(0.0f)); oC[index].x = Min(oC[index].x, Float4(1.0f)); |
| 2145 | oC[index].y = Max(oC[index].y, Float4(0.0f)); oC[index].y = Min(oC[index].y, Float4(1.0f)); |
| 2146 | oC[index].z = Max(oC[index].z, Float4(0.0f)); oC[index].z = Min(oC[index].z, Float4(1.0f)); |
| 2147 | 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] | 2148 | break; |
| 2149 | case FORMAT_R32F: |
| 2150 | case FORMAT_G32R32F: |
| 2151 | case FORMAT_A32B32G32R32F: |
| 2152 | break; |
| 2153 | default: |
| 2154 | ASSERT(false); |
| 2155 | } |
| 2156 | } |
| 2157 | } |
| 2158 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2159 | void PixelRoutine::rasterOperation(Vector4i ¤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] | 2160 | { |
| 2161 | if(!state.colorWriteActive(0)) |
| 2162 | { |
| 2163 | return; |
| 2164 | } |
| 2165 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2166 | Vector4f oC; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2167 | |
| 2168 | switch(state.targetFormat[0]) |
| 2169 | { |
| 2170 | case FORMAT_X8R8G8B8: |
| 2171 | case FORMAT_A8R8G8B8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2172 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2173 | case FORMAT_G16R16: |
| 2174 | case FORMAT_A16B16G16R16: |
| 2175 | if(!postBlendSRGB && state.writeSRGB) |
| 2176 | { |
| 2177 | linearToSRGB12_16(r, current); |
| 2178 | } |
| 2179 | else |
| 2180 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2181 | current.x <<= 4; |
| 2182 | current.y <<= 4; |
| 2183 | current.z <<= 4; |
| 2184 | current.w <<= 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | fogBlend(r, current, fog, r.z[0], r.rhw); |
| 2188 | |
| 2189 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2190 | { |
| 2191 | 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] | 2192 | Vector4i color = current; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2193 | |
| 2194 | if(state.multiSampleMask & (1 << q)) |
| 2195 | { |
| 2196 | alphaBlend(r, 0, buffer, color, x); |
| 2197 | writeColor(r, 0, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2198 | } |
| 2199 | } |
| 2200 | break; |
| 2201 | case FORMAT_R32F: |
| 2202 | case FORMAT_G32R32F: |
| 2203 | case FORMAT_A32B32G32R32F: |
| 2204 | convertSigned12(oC, current); |
| 2205 | fogBlend(r, oC, fog, r.z[0], r.rhw); |
| 2206 | |
| 2207 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2208 | { |
| 2209 | 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] | 2210 | Vector4f color = oC; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2211 | |
| 2212 | if(state.multiSampleMask & (1 << q)) |
| 2213 | { |
| 2214 | alphaBlend(r, 0, buffer, color, x); |
| 2215 | writeColor(r, 0, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2216 | } |
| 2217 | } |
| 2218 | break; |
| 2219 | default: |
| 2220 | ASSERT(false); |
| 2221 | } |
| 2222 | } |
| 2223 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2224 | 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] | 2225 | { |
| 2226 | for(int index = 0; index < 4; index++) |
| 2227 | { |
| 2228 | if(!state.colorWriteActive(index)) |
| 2229 | { |
| 2230 | continue; |
| 2231 | } |
| 2232 | |
| 2233 | if(!postBlendSRGB && state.writeSRGB) |
| 2234 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2235 | oC[index].x = linearToSRGB(oC[index].x); |
| 2236 | oC[index].y = linearToSRGB(oC[index].y); |
| 2237 | oC[index].z = linearToSRGB(oC[index].z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | if(index == 0) |
| 2241 | { |
| 2242 | fogBlend(r, oC[index], fog, r.z[0], r.rhw); |
| 2243 | } |
| 2244 | |
| 2245 | switch(state.targetFormat[index]) |
| 2246 | { |
| 2247 | case FORMAT_X8R8G8B8: |
| 2248 | case FORMAT_A8R8G8B8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2249 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2250 | case FORMAT_G16R16: |
| 2251 | case FORMAT_A16B16G16R16: |
| 2252 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2253 | { |
| 2254 | 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] | 2255 | Vector4i color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2256 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2257 | color.x = convertFixed16(oC[index].x, false); |
| 2258 | color.y = convertFixed16(oC[index].y, false); |
| 2259 | color.z = convertFixed16(oC[index].z, false); |
| 2260 | color.w = convertFixed16(oC[index].w, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2261 | |
| 2262 | if(state.multiSampleMask & (1 << q)) |
| 2263 | { |
| 2264 | alphaBlend(r, index, buffer, color, x); |
| 2265 | writeColor(r, index, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2266 | } |
| 2267 | } |
| 2268 | break; |
| 2269 | case FORMAT_R32F: |
| 2270 | case FORMAT_G32R32F: |
| 2271 | case FORMAT_A32B32G32R32F: |
| 2272 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2273 | { |
| 2274 | 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] | 2275 | Vector4f color = oC[index]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2276 | |
| 2277 | if(state.multiSampleMask & (1 << q)) |
| 2278 | { |
| 2279 | alphaBlend(r, index, buffer, color, x); |
| 2280 | writeColor(r, index, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2281 | } |
| 2282 | } |
| 2283 | break; |
| 2284 | default: |
| 2285 | ASSERT(false); |
| 2286 | } |
| 2287 | } |
| 2288 | } |
| 2289 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2290 | void PixelRoutine::blendFactor(Registers &r, const Vector4i &blendFactor, const Vector4i ¤t, const Vector4i &pixel, Context::BlendFactor blendFactorActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2291 | { |
| 2292 | switch(blendFactorActive) |
| 2293 | { |
| 2294 | case Context::BLEND_ZERO: |
| 2295 | // Optimized |
| 2296 | break; |
| 2297 | case Context::BLEND_ONE: |
| 2298 | // Optimized |
| 2299 | break; |
| 2300 | case Context::BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2301 | blendFactor.x = current.x; |
| 2302 | blendFactor.y = current.y; |
| 2303 | blendFactor.z = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2304 | break; |
| 2305 | case Context::BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2306 | blendFactor.x = Short4(0xFFFFu) - current.x; |
| 2307 | blendFactor.y = Short4(0xFFFFu) - current.y; |
| 2308 | blendFactor.z = Short4(0xFFFFu) - current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2309 | break; |
| 2310 | case Context::BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2311 | blendFactor.x = pixel.x; |
| 2312 | blendFactor.y = pixel.y; |
| 2313 | blendFactor.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2314 | break; |
| 2315 | case Context::BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2316 | blendFactor.x = Short4(0xFFFFu) - pixel.x; |
| 2317 | blendFactor.y = Short4(0xFFFFu) - pixel.y; |
| 2318 | blendFactor.z = Short4(0xFFFFu) - pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2319 | break; |
| 2320 | case Context::BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2321 | blendFactor.x = current.w; |
| 2322 | blendFactor.y = current.w; |
| 2323 | blendFactor.z = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2324 | break; |
| 2325 | case Context::BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2326 | blendFactor.x = Short4(0xFFFFu) - current.w; |
| 2327 | blendFactor.y = Short4(0xFFFFu) - current.w; |
| 2328 | blendFactor.z = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2329 | break; |
| 2330 | case Context::BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2331 | blendFactor.x = pixel.w; |
| 2332 | blendFactor.y = pixel.w; |
| 2333 | blendFactor.z = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2334 | break; |
| 2335 | case Context::BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2336 | blendFactor.x = Short4(0xFFFFu) - pixel.w; |
| 2337 | blendFactor.y = Short4(0xFFFFu) - pixel.w; |
| 2338 | blendFactor.z = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2339 | break; |
| 2340 | case Context::BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2341 | blendFactor.x = Short4(0xFFFFu) - pixel.w; |
| 2342 | blendFactor.x = Min(As<UShort4>(blendFactor.x), As<UShort4>(current.w)); |
| 2343 | blendFactor.y = blendFactor.x; |
| 2344 | blendFactor.z = blendFactor.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2345 | break; |
| 2346 | case Context::BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2347 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[0])); |
| 2348 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[1])); |
| 2349 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2350 | break; |
| 2351 | case Context::BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2352 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[0])); |
| 2353 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[1])); |
| 2354 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2355 | break; |
| 2356 | case Context::BLEND_CONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2357 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
| 2358 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
| 2359 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2360 | break; |
| 2361 | case Context::BLEND_INVCONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2362 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
| 2363 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
| 2364 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2365 | break; |
| 2366 | default: |
| 2367 | ASSERT(false); |
| 2368 | } |
| 2369 | } |
| 2370 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2371 | void PixelRoutine::blendFactorAlpha(Registers &r, const Vector4i &blendFactor, const Vector4i ¤t, const Vector4i &pixel, Context::BlendFactor blendFactorAlphaActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2372 | { |
| 2373 | switch(blendFactorAlphaActive) |
| 2374 | { |
| 2375 | case Context::BLEND_ZERO: |
| 2376 | // Optimized |
| 2377 | break; |
| 2378 | case Context::BLEND_ONE: |
| 2379 | // Optimized |
| 2380 | break; |
| 2381 | case Context::BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2382 | blendFactor.w = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2383 | break; |
| 2384 | case Context::BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2385 | blendFactor.w = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2386 | break; |
| 2387 | case Context::BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2388 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2389 | break; |
| 2390 | case Context::BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2391 | blendFactor.w = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2392 | break; |
| 2393 | case Context::BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2394 | blendFactor.w = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2395 | break; |
| 2396 | case Context::BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2397 | blendFactor.w = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2398 | break; |
| 2399 | case Context::BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2400 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2401 | break; |
| 2402 | case Context::BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2403 | blendFactor.w = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2404 | break; |
| 2405 | case Context::BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2406 | blendFactor.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2407 | break; |
| 2408 | case Context::BLEND_CONSTANT: |
| 2409 | case Context::BLEND_CONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2410 | blendFactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2411 | break; |
| 2412 | case Context::BLEND_INVCONSTANT: |
| 2413 | case Context::BLEND_INVCONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2414 | blendFactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2415 | break; |
| 2416 | default: |
| 2417 | ASSERT(false); |
| 2418 | } |
| 2419 | } |
| 2420 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2421 | void PixelRoutine::alphaBlend(Registers &r, int index, Pointer<Byte> &cBuffer, Vector4i ¤t, Int &x) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2422 | { |
| 2423 | if(!state.alphaBlendActive) |
| 2424 | { |
| 2425 | return; |
| 2426 | } |
| 2427 | |
| 2428 | Pointer<Byte> buffer; |
| 2429 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2430 | Vector4i pixel; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2431 | Short4 c01; |
| 2432 | Short4 c23; |
| 2433 | |
| 2434 | // Read pixel |
| 2435 | switch(state.targetFormat[index]) |
| 2436 | { |
| 2437 | case FORMAT_A8R8G8B8: |
| 2438 | buffer = cBuffer + 4 * x; |
| 2439 | c01 = *Pointer<Short4>(buffer); |
| 2440 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2441 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2442 | pixel.z = c01; |
| 2443 | pixel.y = c01; |
| 2444 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2445 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2446 | pixel.x = pixel.z; |
| 2447 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2448 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2449 | pixel.y = pixel.z; |
| 2450 | pixel.w = pixel.x; |
| 2451 | pixel.x = UnpackLow(As<Byte8>(pixel.x), As<Byte8>(pixel.x)); |
| 2452 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2453 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2454 | pixel.w = UnpackHigh(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2455 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2456 | case FORMAT_A8: |
| 2457 | buffer = cBuffer + 1 * x; |
| 2458 | pixel.w = Insert(pixel.w, *Pointer<Short>(buffer), 0); |
| 2459 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2460 | pixel.w = Insert(pixel.w, *Pointer<Short>(buffer), 1); |
| 2461 | pixel.w = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2462 | pixel.x = Short4(0x0000); |
| 2463 | pixel.y = Short4(0x0000); |
| 2464 | pixel.z = Short4(0x0000); |
| 2465 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2466 | case FORMAT_X8R8G8B8: |
| 2467 | buffer = cBuffer + 4 * x; |
| 2468 | c01 = *Pointer<Short4>(buffer); |
| 2469 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2470 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2471 | pixel.z = c01; |
| 2472 | pixel.y = c01; |
| 2473 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2474 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2475 | pixel.x = pixel.z; |
| 2476 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2477 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2478 | pixel.y = pixel.z; |
| 2479 | pixel.x = UnpackLow(As<Byte8>(pixel.x), As<Byte8>(pixel.x)); |
| 2480 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2481 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2482 | pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2483 | break; |
| 2484 | case FORMAT_A8G8R8B8Q: |
| 2485 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2486 | // pixel.z = UnpackLow(As<Byte8>(pixel.z), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2487 | // pixel.x = UnpackHigh(As<Byte8>(pixel.x), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2488 | // pixel.y = UnpackLow(As<Byte8>(pixel.y), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
| 2489 | // 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] | 2490 | break; |
| 2491 | case FORMAT_X8G8R8B8Q: |
| 2492 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2493 | // pixel.z = UnpackLow(As<Byte8>(pixel.z), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2494 | // pixel.x = UnpackHigh(As<Byte8>(pixel.x), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2495 | // pixel.y = UnpackLow(As<Byte8>(pixel.y), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
| 2496 | // pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2497 | break; |
| 2498 | case FORMAT_A16B16G16R16: |
| 2499 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2500 | pixel.x = *Pointer<Short4>(buffer + 8 * x); |
| 2501 | pixel.y = *Pointer<Short4>(buffer + 8 * x + 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2502 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2503 | pixel.z = *Pointer<Short4>(buffer + 8 * x); |
| 2504 | pixel.w = *Pointer<Short4>(buffer + 8 * x + 8); |
| 2505 | transpose4x4(pixel.x, pixel.y, pixel.z, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2506 | break; |
| 2507 | case FORMAT_G16R16: |
| 2508 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2509 | pixel.x = *Pointer<Short4>(buffer + 4 * x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2510 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2511 | pixel.y = *Pointer<Short4>(buffer + 4 * x); |
| 2512 | pixel.z = pixel.x; |
| 2513 | pixel.x = As<Short4>(UnpackLow(pixel.x, pixel.y)); |
| 2514 | pixel.z = As<Short4>(UnpackHigh(pixel.z, pixel.y)); |
| 2515 | pixel.y = pixel.z; |
| 2516 | pixel.x = As<Short4>(UnpackLow(pixel.x, pixel.z)); |
| 2517 | pixel.y = As<Short4>(UnpackHigh(pixel.y, pixel.z)); |
| 2518 | pixel.z = Short4(0xFFFFu); |
| 2519 | pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2520 | break; |
| 2521 | default: |
| 2522 | ASSERT(false); |
| 2523 | } |
| 2524 | |
| 2525 | if(postBlendSRGB && state.writeSRGB) |
| 2526 | { |
| 2527 | sRGBtoLinear16_16(r, pixel); |
| 2528 | } |
| 2529 | |
| 2530 | // Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2531 | Vector4i sourceFactor; |
| 2532 | Vector4i destFactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2533 | |
| 2534 | blendFactor(r, sourceFactor, current, pixel, (Context::BlendFactor)state.sourceBlendFactor); |
| 2535 | blendFactor(r, destFactor, current, pixel, (Context::BlendFactor)state.destBlendFactor); |
| 2536 | |
| 2537 | if(state.sourceBlendFactor != Context::BLEND_ONE && state.sourceBlendFactor != Context::BLEND_ZERO) |
| 2538 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2539 | current.x = MulHigh(As<UShort4>(current.x), As<UShort4>(sourceFactor.x)); |
| 2540 | current.y = MulHigh(As<UShort4>(current.y), As<UShort4>(sourceFactor.y)); |
| 2541 | current.z = MulHigh(As<UShort4>(current.z), As<UShort4>(sourceFactor.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | if(state.destBlendFactor != Context::BLEND_ONE && state.destBlendFactor != Context::BLEND_ZERO) |
| 2545 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2546 | pixel.x = MulHigh(As<UShort4>(pixel.x), As<UShort4>(destFactor.x)); |
| 2547 | pixel.y = MulHigh(As<UShort4>(pixel.y), As<UShort4>(destFactor.y)); |
| 2548 | pixel.z = MulHigh(As<UShort4>(pixel.z), As<UShort4>(destFactor.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | switch(state.blendOperation) |
| 2552 | { |
| 2553 | case Context::BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2554 | current.x = AddSat(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2555 | current.y = AddSat(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2556 | current.z = AddSat(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2557 | break; |
| 2558 | case Context::BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2559 | current.x = SubSat(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2560 | current.y = SubSat(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2561 | current.z = SubSat(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2562 | break; |
| 2563 | case Context::BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2564 | current.x = SubSat(As<UShort4>(pixel.x), As<UShort4>(current.x)); |
| 2565 | current.y = SubSat(As<UShort4>(pixel.y), As<UShort4>(current.y)); |
| 2566 | current.z = SubSat(As<UShort4>(pixel.z), As<UShort4>(current.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2567 | break; |
| 2568 | case Context::BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2569 | current.x = Min(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2570 | current.y = Min(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2571 | current.z = Min(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2572 | break; |
| 2573 | case Context::BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2574 | current.x = Max(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2575 | current.y = Max(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2576 | current.z = Max(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2577 | break; |
| 2578 | case Context::BLENDOP_SOURCE: |
| 2579 | // No operation |
| 2580 | break; |
| 2581 | case Context::BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2582 | current.x = pixel.x; |
| 2583 | current.y = pixel.y; |
| 2584 | current.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2585 | break; |
| 2586 | case Context::BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2587 | current.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 2588 | current.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 2589 | current.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2590 | break; |
| 2591 | default: |
| 2592 | ASSERT(false); |
| 2593 | } |
| 2594 | |
| 2595 | blendFactorAlpha(r, sourceFactor, current, pixel, (Context::BlendFactor)state.sourceBlendFactorAlpha); |
| 2596 | blendFactorAlpha(r, destFactor, current, pixel, (Context::BlendFactor)state.destBlendFactorAlpha); |
| 2597 | |
| 2598 | if(state.sourceBlendFactorAlpha != Context::BLEND_ONE && state.sourceBlendFactorAlpha != Context::BLEND_ZERO) |
| 2599 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2600 | current.w = MulHigh(As<UShort4>(current.w), As<UShort4>(sourceFactor.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | if(state.destBlendFactorAlpha != Context::BLEND_ONE && state.destBlendFactorAlpha != Context::BLEND_ZERO) |
| 2604 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2605 | pixel.w = MulHigh(As<UShort4>(pixel.w), As<UShort4>(destFactor.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | switch(state.blendOperationAlpha) |
| 2609 | { |
| 2610 | case Context::BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2611 | current.w = AddSat(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2612 | break; |
| 2613 | case Context::BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2614 | current.w = SubSat(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2615 | break; |
| 2616 | case Context::BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2617 | current.w = SubSat(As<UShort4>(pixel.w), As<UShort4>(current.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2618 | break; |
| 2619 | case Context::BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2620 | current.w = Min(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2621 | break; |
| 2622 | case Context::BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2623 | current.w = Max(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2624 | break; |
| 2625 | case Context::BLENDOP_SOURCE: |
| 2626 | // No operation |
| 2627 | break; |
| 2628 | case Context::BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2629 | current.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2630 | break; |
| 2631 | case Context::BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2632 | current.w = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2633 | break; |
| 2634 | default: |
| 2635 | ASSERT(false); |
| 2636 | } |
| 2637 | } |
| 2638 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2639 | void PixelRoutine::writeColor(Registers &r, int index, Pointer<Byte> &cBuffer, Int &x, Vector4i ¤t, Int &sMask, Int &zMask, Int &cMask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2640 | { |
| 2641 | if(!state.colorWriteActive(index)) |
| 2642 | { |
| 2643 | return; |
| 2644 | } |
| 2645 | |
| 2646 | if(postBlendSRGB && state.writeSRGB) |
| 2647 | { |
| 2648 | linearToSRGB16_16(r, current); |
| 2649 | } |
| 2650 | |
| 2651 | if(exactColorRounding) |
| 2652 | { |
| 2653 | switch(state.targetFormat[index]) |
| 2654 | { |
| 2655 | case FORMAT_X8G8R8B8Q: |
| 2656 | case FORMAT_A8G8R8B8Q: |
| 2657 | case FORMAT_X8R8G8B8: |
| 2658 | case FORMAT_A8R8G8B8: |
| 2659 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2660 | current.x = current.x - As<Short4>(As<UShort4>(current.x) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2661 | current.y = current.y - As<Short4>(As<UShort4>(current.y) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2662 | current.z = current.z - As<Short4>(As<UShort4>(current.z) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2663 | 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] | 2664 | } |
| 2665 | break; |
| 2666 | } |
| 2667 | } |
| 2668 | |
| 2669 | int rgbaWriteMask = state.colorWriteActive(index); |
| 2670 | int bgraWriteMask = rgbaWriteMask & 0x0000000A | (rgbaWriteMask & 0x00000001) << 2 | (rgbaWriteMask & 0x00000004) >> 2; |
| 2671 | int brgaWriteMask = rgbaWriteMask & 0x00000008 | (rgbaWriteMask & 0x00000001) << 1 | (rgbaWriteMask & 0x00000002) << 1 | (rgbaWriteMask & 0x00000004) >> 2; |
| 2672 | |
| 2673 | switch(state.targetFormat[index]) |
| 2674 | { |
| 2675 | case FORMAT_X8G8R8B8Q: |
| 2676 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2677 | // current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2678 | // current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2679 | // current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2680 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2681 | // current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2682 | // 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] | 2683 | break; |
| 2684 | case FORMAT_A8G8R8B8Q: |
| 2685 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2686 | // current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2687 | // current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2688 | // current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2689 | // current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2690 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2691 | // current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2692 | // 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] | 2693 | break; |
| 2694 | case FORMAT_X8R8G8B8: |
| 2695 | case FORMAT_A8R8G8B8: |
| 2696 | if(state.targetFormat[index] == FORMAT_X8R8G8B8 || rgbaWriteMask == 0x7) |
| 2697 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2698 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2699 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2700 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2701 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2702 | current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2703 | 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] | 2704 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2705 | current.x = current.z; |
| 2706 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2707 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2708 | current.y = current.z; |
| 2709 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2710 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2711 | } |
| 2712 | else |
| 2713 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2714 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2715 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2716 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2717 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2718 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2719 | current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2720 | 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] | 2721 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2722 | current.x = current.z; |
| 2723 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2724 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2725 | current.y = current.z; |
| 2726 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2727 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2728 | } |
| 2729 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2730 | case FORMAT_A8: |
| 2731 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
| 2732 | current.w = As<Short4>(Pack(As<UShort4>(current.w), As<UShort4>(current.w))); |
| 2733 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2734 | case FORMAT_G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2735 | current.z = current.x; |
| 2736 | current.x = As<Short4>(UnpackLow(current.x, current.y)); |
| 2737 | current.z = As<Short4>(UnpackHigh(current.z, current.y)); |
| 2738 | current.y = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2739 | break; |
| 2740 | case FORMAT_A16B16G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2741 | transpose4x4(current.x, current.y, current.z, current.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2742 | break; |
| 2743 | case FORMAT_R32F: |
| 2744 | case FORMAT_G32R32F: |
| 2745 | case FORMAT_A32B32G32R32F: |
| 2746 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2747 | Vector4f oC; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2748 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2749 | oC.x = convertUnsigned16(UShort4(current.x)); |
| 2750 | oC.y = convertUnsigned16(UShort4(current.y)); |
| 2751 | oC.z = convertUnsigned16(UShort4(current.z)); |
| 2752 | oC.w = convertUnsigned16(UShort4(current.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2753 | |
| 2754 | writeColor(r, index, cBuffer, x, oC, sMask, zMask, cMask); |
| 2755 | } |
| 2756 | return; |
| 2757 | default: |
| 2758 | ASSERT(false); |
| 2759 | } |
| 2760 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2761 | Short4 c01 = current.z; |
| 2762 | Short4 c23 = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2763 | |
| 2764 | Int xMask; // Combination of all masks |
| 2765 | |
| 2766 | if(state.depthTestActive) |
| 2767 | { |
| 2768 | xMask = zMask; |
| 2769 | } |
| 2770 | else |
| 2771 | { |
| 2772 | xMask = cMask; |
| 2773 | } |
| 2774 | |
| 2775 | if(state.stencilActive) |
| 2776 | { |
| 2777 | xMask &= sMask; |
| 2778 | } |
| 2779 | |
| 2780 | Pointer<Byte> buffer; |
| 2781 | Short4 value; |
| 2782 | |
| 2783 | switch(state.targetFormat[index]) |
| 2784 | { |
| 2785 | case FORMAT_A8G8R8B8Q: |
| 2786 | case FORMAT_X8G8R8B8Q: // FIXME: Don't touch alpha? |
| 2787 | UNIMPLEMENTED(); |
| 2788 | // value = *Pointer<Short4>(cBuffer + 8 * x + 0); |
| 2789 | |
| 2790 | // if((state.targetFormat[index] == FORMAT_A8G8R8B8Q && bgraWriteMask != 0x0000000F) || |
| 2791 | // ((state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x00000007) && |
| 2792 | // (state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 2793 | // { |
| 2794 | // Short4 masked = value; |
| 2795 | // c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 2796 | // masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 2797 | // c01 |= masked; |
| 2798 | // } |
| 2799 | |
| 2800 | // c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 2801 | // value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 2802 | // c01 |= value; |
| 2803 | // *Pointer<Short4>(cBuffer + 8 * x + 0) = c01; |
| 2804 | |
| 2805 | // value = *Pointer<Short4>(cBuffer + 8 * x + 8); |
| 2806 | |
| 2807 | // if((state.targetFormat[index] == FORMAT_A8G8R8B8Q && bgraWriteMask != 0x0000000F) || |
| 2808 | // ((state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x00000007) && |
| 2809 | // (state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 2810 | // { |
| 2811 | // Short4 masked = value; |
| 2812 | // c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 2813 | // masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 2814 | // c23 |= masked; |
| 2815 | // } |
| 2816 | |
| 2817 | // c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 2818 | // value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 2819 | // c23 |= value; |
| 2820 | // *Pointer<Short4>(cBuffer + 8 * x + 8) = c23; |
| 2821 | break; |
| 2822 | case FORMAT_A8R8G8B8: |
| 2823 | case FORMAT_X8R8G8B8: // FIXME: Don't touch alpha? |
| 2824 | buffer = cBuffer + x * 4; |
| 2825 | value = *Pointer<Short4>(buffer); |
| 2826 | |
| 2827 | if((state.targetFormat[index] == FORMAT_A8R8G8B8 && bgraWriteMask != 0x0000000F) || |
| 2828 | ((state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x00000007) && |
| 2829 | (state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 2830 | { |
| 2831 | Short4 masked = value; |
| 2832 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 2833 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 2834 | c01 |= masked; |
| 2835 | } |
| 2836 | |
| 2837 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 2838 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 2839 | c01 |= value; |
| 2840 | *Pointer<Short4>(buffer) = c01; |
| 2841 | |
| 2842 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2843 | value = *Pointer<Short4>(buffer); |
| 2844 | |
| 2845 | if((state.targetFormat[index] == FORMAT_A8R8G8B8 && bgraWriteMask != 0x0000000F) || |
| 2846 | ((state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x00000007) && |
| 2847 | (state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 2848 | { |
| 2849 | Short4 masked = value; |
| 2850 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 2851 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 2852 | c23 |= masked; |
| 2853 | } |
| 2854 | |
| 2855 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 2856 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 2857 | c23 |= value; |
| 2858 | *Pointer<Short4>(buffer) = c23; |
| 2859 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2860 | case FORMAT_A8: |
| 2861 | if(rgbaWriteMask & 0x00000008) |
| 2862 | { |
| 2863 | buffer = cBuffer + 1 * x; |
| 2864 | Insert(value, *Pointer<Short>(buffer), 0); |
| 2865 | Int pitch = *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2866 | Insert(value, *Pointer<Short>(buffer + pitch), 1); |
| 2867 | value = UnpackLow(As<Byte8>(value), As<Byte8>(value)); |
| 2868 | |
| 2869 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q) + 8 * xMask); |
| 2870 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * xMask); |
| 2871 | current.w |= value; |
| 2872 | |
| 2873 | *Pointer<Short>(buffer) = Extract(current.w, 0); |
| 2874 | *Pointer<Short>(buffer + pitch) = Extract(current.w, 1); |
| 2875 | } |
| 2876 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2877 | case FORMAT_G16R16: |
| 2878 | buffer = cBuffer + 4 * x; |
| 2879 | |
| 2880 | value = *Pointer<Short4>(buffer); |
| 2881 | |
| 2882 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 2883 | { |
| 2884 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2885 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2886 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2887 | current.x |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2888 | } |
| 2889 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2890 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2891 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2892 | current.x |= value; |
| 2893 | *Pointer<Short4>(buffer) = current.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2894 | |
| 2895 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2896 | |
| 2897 | value = *Pointer<Short4>(buffer); |
| 2898 | |
| 2899 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 2900 | { |
| 2901 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2902 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2903 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2904 | current.y |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2905 | } |
| 2906 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2907 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2908 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2909 | current.y |= value; |
| 2910 | *Pointer<Short4>(buffer) = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2911 | break; |
| 2912 | case FORMAT_A16B16G16R16: |
| 2913 | buffer = cBuffer + 8 * x; |
| 2914 | |
| 2915 | { |
| 2916 | value = *Pointer<Short4>(buffer); |
| 2917 | |
| 2918 | if(rgbaWriteMask != 0x0000000F) |
| 2919 | { |
| 2920 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2921 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2922 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2923 | current.x |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2924 | } |
| 2925 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2926 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ0Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2927 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ0Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2928 | current.x |= value; |
| 2929 | *Pointer<Short4>(buffer) = current.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | { |
| 2933 | value = *Pointer<Short4>(buffer + 8); |
| 2934 | |
| 2935 | if(rgbaWriteMask != 0x0000000F) |
| 2936 | { |
| 2937 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2938 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2939 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2940 | current.y |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2941 | } |
| 2942 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2943 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ1Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2944 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ1Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2945 | current.y |= value; |
| 2946 | *Pointer<Short4>(buffer + 8) = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2950 | |
| 2951 | { |
| 2952 | value = *Pointer<Short4>(buffer); |
| 2953 | |
| 2954 | if(rgbaWriteMask != 0x0000000F) |
| 2955 | { |
| 2956 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2957 | current.z &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2958 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2959 | current.z |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2960 | } |
| 2961 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2962 | current.z &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ2Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2963 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ2Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2964 | current.z |= value; |
| 2965 | *Pointer<Short4>(buffer) = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | { |
| 2969 | value = *Pointer<Short4>(buffer + 8); |
| 2970 | |
| 2971 | if(rgbaWriteMask != 0x0000000F) |
| 2972 | { |
| 2973 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2974 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2975 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2976 | current.w |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2977 | } |
| 2978 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2979 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ3Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2980 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ3Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2981 | current.w |= value; |
| 2982 | *Pointer<Short4>(buffer + 8) = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2983 | } |
| 2984 | break; |
| 2985 | default: |
| 2986 | ASSERT(false); |
| 2987 | } |
| 2988 | } |
| 2989 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2990 | void PixelRoutine::blendFactor(Registers &r, const Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, Context::BlendFactor blendFactorActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2991 | { |
| 2992 | switch(blendFactorActive) |
| 2993 | { |
| 2994 | case Context::BLEND_ZERO: |
| 2995 | // Optimized |
| 2996 | break; |
| 2997 | case Context::BLEND_ONE: |
| 2998 | // Optimized |
| 2999 | break; |
| 3000 | case Context::BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3001 | blendFactor.x = oC.x; |
| 3002 | blendFactor.y = oC.y; |
| 3003 | blendFactor.z = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3004 | break; |
| 3005 | case Context::BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3006 | blendFactor.x = Float4(1.0f) - oC.x; |
| 3007 | blendFactor.y = Float4(1.0f) - oC.y; |
| 3008 | blendFactor.z = Float4(1.0f) - oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3009 | break; |
| 3010 | case Context::BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3011 | blendFactor.x = pixel.x; |
| 3012 | blendFactor.y = pixel.y; |
| 3013 | blendFactor.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3014 | break; |
| 3015 | case Context::BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3016 | blendFactor.x = Float4(1.0f) - pixel.x; |
| 3017 | blendFactor.y = Float4(1.0f) - pixel.y; |
| 3018 | blendFactor.z = Float4(1.0f) - pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3019 | break; |
| 3020 | case Context::BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3021 | blendFactor.x = oC.w; |
| 3022 | blendFactor.y = oC.w; |
| 3023 | blendFactor.z = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3024 | break; |
| 3025 | case Context::BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3026 | blendFactor.x = Float4(1.0f) - oC.w; |
| 3027 | blendFactor.y = Float4(1.0f) - oC.w; |
| 3028 | blendFactor.z = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3029 | break; |
| 3030 | case Context::BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3031 | blendFactor.x = pixel.w; |
| 3032 | blendFactor.y = pixel.w; |
| 3033 | blendFactor.z = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3034 | break; |
| 3035 | case Context::BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3036 | blendFactor.x = Float4(1.0f) - pixel.w; |
| 3037 | blendFactor.y = Float4(1.0f) - pixel.w; |
| 3038 | blendFactor.z = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3039 | break; |
| 3040 | case Context::BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3041 | blendFactor.x = Float4(1.0f) - pixel.w; |
| 3042 | blendFactor.x = Min(blendFactor.x, oC.w); |
| 3043 | blendFactor.y = blendFactor.x; |
| 3044 | blendFactor.z = blendFactor.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3045 | break; |
| 3046 | case Context::BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3047 | blendFactor.x = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[0])); |
| 3048 | blendFactor.y = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[1])); |
| 3049 | blendFactor.z = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3050 | break; |
| 3051 | case Context::BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3052 | blendFactor.x = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[0])); |
| 3053 | blendFactor.y = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[1])); |
| 3054 | blendFactor.z = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3055 | break; |
| 3056 | default: |
| 3057 | ASSERT(false); |
| 3058 | } |
| 3059 | } |
| 3060 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3061 | void PixelRoutine::blendFactorAlpha(Registers &r, const Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, Context::BlendFactor blendFactorAlphaActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3062 | { |
| 3063 | switch(blendFactorAlphaActive) |
| 3064 | { |
| 3065 | case Context::BLEND_ZERO: |
| 3066 | // Optimized |
| 3067 | break; |
| 3068 | case Context::BLEND_ONE: |
| 3069 | // Optimized |
| 3070 | break; |
| 3071 | case Context::BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3072 | blendFactor.w = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3073 | break; |
| 3074 | case Context::BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3075 | blendFactor.w = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3076 | break; |
| 3077 | case Context::BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3078 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3079 | break; |
| 3080 | case Context::BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3081 | blendFactor.w = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3082 | break; |
| 3083 | case Context::BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3084 | blendFactor.w = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3085 | break; |
| 3086 | case Context::BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3087 | blendFactor.w = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3088 | break; |
| 3089 | case Context::BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3090 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3091 | break; |
| 3092 | case Context::BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3093 | blendFactor.w = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3094 | break; |
| 3095 | case Context::BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3096 | blendFactor.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3097 | break; |
| 3098 | case Context::BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3099 | blendFactor.w = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3100 | break; |
| 3101 | case Context::BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3102 | blendFactor.w = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3103 | break; |
| 3104 | default: |
| 3105 | ASSERT(false); |
| 3106 | } |
| 3107 | } |
| 3108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3109 | 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] | 3110 | { |
| 3111 | if(!state.alphaBlendActive) |
| 3112 | { |
| 3113 | return; |
| 3114 | } |
| 3115 | |
| 3116 | Pointer<Byte> buffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3117 | Vector4f pixel; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3118 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3119 | Vector4i color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3120 | Short4 c01; |
| 3121 | Short4 c23; |
| 3122 | |
| 3123 | // Read pixel |
| 3124 | switch(state.targetFormat[index]) |
| 3125 | { |
| 3126 | case FORMAT_A8R8G8B8: |
| 3127 | buffer = cBuffer + 4 * x; |
| 3128 | c01 = *Pointer<Short4>(buffer); |
| 3129 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3130 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3131 | color.z = c01; |
| 3132 | color.y = c01; |
| 3133 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(c23)); |
| 3134 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(c23)); |
| 3135 | color.x = color.z; |
| 3136 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.y)); |
| 3137 | color.x = UnpackHigh(As<Byte8>(color.x), As<Byte8>(color.y)); |
| 3138 | color.y = color.z; |
| 3139 | color.w = color.x; |
| 3140 | color.x = UnpackLow(As<Byte8>(color.x), As<Byte8>(color.x)); |
| 3141 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(color.y)); |
| 3142 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.z)); |
| 3143 | color.w = UnpackHigh(As<Byte8>(color.w), As<Byte8>(color.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3144 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3145 | pixel.x = convertUnsigned16(As<UShort4>(color.x)); |
| 3146 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3147 | pixel.z = convertUnsigned16(As<UShort4>(color.z)); |
| 3148 | pixel.w = convertUnsigned16(As<UShort4>(color.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3149 | break; |
| 3150 | case FORMAT_X8R8G8B8: |
| 3151 | buffer = cBuffer + 4 * x; |
| 3152 | c01 = *Pointer<Short4>(buffer); |
| 3153 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3154 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3155 | color.z = c01; |
| 3156 | color.y = c01; |
| 3157 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(c23)); |
| 3158 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(c23)); |
| 3159 | color.x = color.z; |
| 3160 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.y)); |
| 3161 | color.x = UnpackHigh(As<Byte8>(color.x), As<Byte8>(color.y)); |
| 3162 | color.y = color.z; |
| 3163 | color.x = UnpackLow(As<Byte8>(color.x), As<Byte8>(color.x)); |
| 3164 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(color.y)); |
| 3165 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3166 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3167 | pixel.x = convertUnsigned16(As<UShort4>(color.x)); |
| 3168 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3169 | pixel.z = convertUnsigned16(As<UShort4>(color.z)); |
| 3170 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3171 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3172 | case FORMAT_A8: |
| 3173 | buffer = cBuffer + 1 * x; |
| 3174 | c01 = Insert(c01, *Pointer<Short>(buffer), 0); |
| 3175 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3176 | c01 = Insert(c01, *Pointer<Short>(buffer), 1); |
| 3177 | pixel.w = convertUnsigned16(As<UShort4>(UnpackLow(As<Byte8>(c01), As<Byte8>(c01)))); |
| 3178 | pixel.x = Float4(0.0f); |
| 3179 | pixel.y = Float4(0.0f); |
| 3180 | pixel.z = Float4(0.0f); |
| 3181 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3182 | case FORMAT_A8G8R8B8Q: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3183 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3184 | // UnpackLow(pixel.z, qword_ptr [cBuffer+8*x+0]); |
| 3185 | // UnpackHigh(pixel.x, qword_ptr [cBuffer+8*x+0]); |
| 3186 | // UnpackLow(pixel.y, qword_ptr [cBuffer+8*x+8]); |
| 3187 | // UnpackHigh(pixel.w, qword_ptr [cBuffer+8*x+8]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3188 | break; |
| 3189 | case FORMAT_X8G8R8B8Q: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3190 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3191 | // UnpackLow(pixel.z, qword_ptr [cBuffer+8*x+0]); |
| 3192 | // UnpackHigh(pixel.x, qword_ptr [cBuffer+8*x+0]); |
| 3193 | // UnpackLow(pixel.y, qword_ptr [cBuffer+8*x+8]); |
| 3194 | // pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3195 | break; |
| 3196 | case FORMAT_A16B16G16R16: |
| 3197 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3198 | color.x = *Pointer<Short4>(buffer + 8 * x); |
| 3199 | color.y = *Pointer<Short4>(buffer + 8 * x + 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3200 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3201 | color.z = *Pointer<Short4>(buffer + 8 * x); |
| 3202 | color.w = *Pointer<Short4>(buffer + 8 * x + 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3204 | transpose4x4(color.x, color.y, color.z, color.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3205 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3206 | pixel.x = convertUnsigned16(As<UShort4>(color.x)); |
| 3207 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3208 | pixel.z = convertUnsigned16(As<UShort4>(color.z)); |
| 3209 | pixel.w = convertUnsigned16(As<UShort4>(color.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3210 | break; |
| 3211 | case FORMAT_G16R16: |
| 3212 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3213 | color.x = *Pointer<Short4>(buffer + 4 * x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3214 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3215 | color.y = *Pointer<Short4>(buffer + 4 * x); |
| 3216 | color.z = color.x; |
| 3217 | color.x = As<Short4>(UnpackLow(color.x, color.y)); |
| 3218 | color.z = As<Short4>(UnpackHigh(color.z, color.y)); |
| 3219 | color.y = color.z; |
| 3220 | color.x = As<Short4>(UnpackLow(color.x, color.z)); |
| 3221 | color.y = As<Short4>(UnpackHigh(color.y, color.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3222 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3223 | pixel.x = convertUnsigned16(As<UShort4>(color.x)); |
| 3224 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3225 | pixel.z = Float4(1.0f); |
| 3226 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3227 | break; |
| 3228 | case FORMAT_R32F: |
| 3229 | buffer = cBuffer; |
| 3230 | // FIXME: movlps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3231 | pixel.x.x = *Pointer<Float>(buffer + 4 * x + 0); |
| 3232 | pixel.x.y = *Pointer<Float>(buffer + 4 * x + 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3233 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3234 | // FIXME: movhps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3235 | pixel.x.z = *Pointer<Float>(buffer + 4 * x + 0); |
| 3236 | pixel.x.w = *Pointer<Float>(buffer + 4 * x + 4); |
| 3237 | pixel.y = Float4(1.0f); |
| 3238 | pixel.z = Float4(1.0f); |
| 3239 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3240 | break; |
| 3241 | case FORMAT_G32R32F: |
| 3242 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3243 | pixel.x = *Pointer<Float4>(buffer + 8 * x, 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3244 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3245 | pixel.y = *Pointer<Float4>(buffer + 8 * x, 16); |
| 3246 | pixel.z = pixel.x; |
| 3247 | pixel.x = ShuffleLowHigh(pixel.x, pixel.y, 0x88); |
| 3248 | pixel.z = ShuffleLowHigh(pixel.z, pixel.y, 0xDD); |
| 3249 | pixel.y = pixel.z; |
| 3250 | pixel.z = Float4(1.0f); |
| 3251 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3252 | break; |
| 3253 | case FORMAT_A32B32G32R32F: |
| 3254 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3255 | pixel.x = *Pointer<Float4>(buffer + 16 * x, 16); |
| 3256 | pixel.y = *Pointer<Float4>(buffer + 16 * x + 16, 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3257 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3258 | pixel.z = *Pointer<Float4>(buffer + 16 * x, 16); |
| 3259 | pixel.w = *Pointer<Float4>(buffer + 16 * x + 16, 16); |
| 3260 | transpose4x4(pixel.x, pixel.y, pixel.z, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3261 | break; |
| 3262 | default: |
| 3263 | ASSERT(false); |
| 3264 | } |
| 3265 | |
| 3266 | if(postBlendSRGB && state.writeSRGB) |
| 3267 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3268 | sRGBtoLinear(pixel.x); |
| 3269 | sRGBtoLinear(pixel.y); |
| 3270 | sRGBtoLinear(pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | // Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3274 | Vector4f sourceFactor; |
| 3275 | Vector4f destFactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3276 | |
| 3277 | blendFactor(r, sourceFactor, oC, pixel, (Context::BlendFactor)state.sourceBlendFactor); |
| 3278 | blendFactor(r, destFactor, oC, pixel, (Context::BlendFactor)state.destBlendFactor); |
| 3279 | |
| 3280 | if(state.sourceBlendFactor != Context::BLEND_ONE && state.sourceBlendFactor != Context::BLEND_ZERO) |
| 3281 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3282 | oC.x *= sourceFactor.x; |
| 3283 | oC.y *= sourceFactor.y; |
| 3284 | oC.z *= sourceFactor.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | if(state.destBlendFactor != Context::BLEND_ONE && state.destBlendFactor != Context::BLEND_ZERO) |
| 3288 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3289 | pixel.x *= destFactor.x; |
| 3290 | pixel.y *= destFactor.y; |
| 3291 | pixel.z *= destFactor.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | switch(state.blendOperation) |
| 3295 | { |
| 3296 | case Context::BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3297 | oC.x += pixel.x; |
| 3298 | oC.y += pixel.y; |
| 3299 | oC.z += pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3300 | break; |
| 3301 | case Context::BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3302 | oC.x -= pixel.x; |
| 3303 | oC.y -= pixel.y; |
| 3304 | oC.z -= pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3305 | break; |
| 3306 | case Context::BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3307 | oC.x = pixel.x - oC.x; |
| 3308 | oC.y = pixel.y - oC.y; |
| 3309 | oC.z = pixel.z - oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3310 | break; |
| 3311 | case Context::BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3312 | oC.x = Min(oC.x, pixel.x); |
| 3313 | oC.y = Min(oC.y, pixel.y); |
| 3314 | oC.z = Min(oC.z, pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3315 | break; |
| 3316 | case Context::BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3317 | oC.x = Max(oC.x, pixel.x); |
| 3318 | oC.y = Max(oC.y, pixel.y); |
| 3319 | oC.z = Max(oC.z, pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3320 | break; |
| 3321 | case Context::BLENDOP_SOURCE: |
| 3322 | // No operation |
| 3323 | break; |
| 3324 | case Context::BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3325 | oC.x = pixel.x; |
| 3326 | oC.y = pixel.y; |
| 3327 | oC.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3328 | break; |
| 3329 | case Context::BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3330 | oC.x = Float4(0.0f); |
| 3331 | oC.y = Float4(0.0f); |
| 3332 | oC.z = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3333 | break; |
| 3334 | default: |
| 3335 | ASSERT(false); |
| 3336 | } |
| 3337 | |
| 3338 | blendFactorAlpha(r, sourceFactor, oC, pixel, (Context::BlendFactor)state.sourceBlendFactorAlpha); |
| 3339 | blendFactorAlpha(r, destFactor, oC, pixel, (Context::BlendFactor)state.destBlendFactorAlpha); |
| 3340 | |
| 3341 | if(state.sourceBlendFactorAlpha != Context::BLEND_ONE && state.sourceBlendFactorAlpha != Context::BLEND_ZERO) |
| 3342 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3343 | oC.w *= sourceFactor.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | if(state.destBlendFactorAlpha != Context::BLEND_ONE && state.destBlendFactorAlpha != Context::BLEND_ZERO) |
| 3347 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3348 | pixel.w *= destFactor.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | switch(state.blendOperationAlpha) |
| 3352 | { |
| 3353 | case Context::BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3354 | oC.w += pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3355 | break; |
| 3356 | case Context::BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3357 | oC.w -= pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3358 | break; |
| 3359 | case Context::BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3360 | pixel.w -= oC.w; |
| 3361 | oC.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3362 | break; |
| 3363 | case Context::BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3364 | oC.w = Min(oC.w, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3365 | break; |
| 3366 | case Context::BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3367 | oC.w = Max(oC.w, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3368 | break; |
| 3369 | case Context::BLENDOP_SOURCE: |
| 3370 | // No operation |
| 3371 | break; |
| 3372 | case Context::BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3373 | oC.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3374 | break; |
| 3375 | case Context::BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3376 | oC.w = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3377 | break; |
| 3378 | default: |
| 3379 | ASSERT(false); |
| 3380 | } |
| 3381 | } |
| 3382 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3383 | 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] | 3384 | { |
| 3385 | if(!state.colorWriteActive(index)) |
| 3386 | { |
| 3387 | return; |
| 3388 | } |
| 3389 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3390 | Vector4i color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3391 | |
| 3392 | switch(state.targetFormat[index]) |
| 3393 | { |
| 3394 | case FORMAT_X8R8G8B8: |
| 3395 | case FORMAT_A8R8G8B8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3396 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3397 | case FORMAT_G16R16: |
| 3398 | case FORMAT_A16B16G16R16: |
| 3399 | convertFixed16(color, oC, true); |
| 3400 | writeColor(r, index, cBuffer, x, color, sMask, zMask, cMask); |
| 3401 | return; |
| 3402 | case FORMAT_R32F: |
| 3403 | break; |
| 3404 | case FORMAT_G32R32F: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3405 | oC.z = oC.x; |
| 3406 | oC.x = UnpackLow(oC.x, oC.y); |
| 3407 | oC.z = UnpackHigh(oC.z, oC.y); |
| 3408 | oC.y = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3409 | break; |
| 3410 | case FORMAT_A32B32G32R32F: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3411 | transpose4x4(oC.x, oC.y, oC.z, oC.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3412 | break; |
| 3413 | default: |
| 3414 | ASSERT(false); |
| 3415 | } |
| 3416 | |
| 3417 | int rgbaWriteMask = state.colorWriteActive(index); |
| 3418 | |
| 3419 | Int xMask; // Combination of all masks |
| 3420 | |
| 3421 | if(state.depthTestActive) |
| 3422 | { |
| 3423 | xMask = zMask; |
| 3424 | } |
| 3425 | else |
| 3426 | { |
| 3427 | xMask = cMask; |
| 3428 | } |
| 3429 | |
| 3430 | if(state.stencilActive) |
| 3431 | { |
| 3432 | xMask &= sMask; |
| 3433 | } |
| 3434 | |
| 3435 | Pointer<Byte> buffer; |
| 3436 | Float4 value; |
| 3437 | |
| 3438 | switch(state.targetFormat[index]) |
| 3439 | { |
| 3440 | case FORMAT_R32F: |
| 3441 | if(rgbaWriteMask & 0x00000001) |
| 3442 | { |
| 3443 | buffer = cBuffer + 4 * x; |
| 3444 | |
| 3445 | // FIXME: movlps |
| 3446 | value.x = *Pointer<Float>(buffer + 0); |
| 3447 | value.y = *Pointer<Float>(buffer + 4); |
| 3448 | |
| 3449 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3450 | |
| 3451 | // FIXME: movhps |
| 3452 | value.z = *Pointer<Float>(buffer + 0); |
| 3453 | value.w = *Pointer<Float>(buffer + 4); |
| 3454 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3455 | 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] | 3456 | 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] | 3457 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3458 | |
| 3459 | // FIXME: movhps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3460 | *Pointer<Float>(buffer + 0) = oC.x.z; |
| 3461 | *Pointer<Float>(buffer + 4) = oC.x.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3462 | |
| 3463 | buffer -= *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3464 | |
| 3465 | // FIXME: movlps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3466 | *Pointer<Float>(buffer + 0) = oC.x.x; |
| 3467 | *Pointer<Float>(buffer + 4) = oC.x.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3468 | } |
| 3469 | break; |
| 3470 | case FORMAT_G32R32F: |
| 3471 | buffer = cBuffer + 8 * x; |
| 3472 | |
| 3473 | value = *Pointer<Float4>(buffer); |
| 3474 | |
| 3475 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 3476 | { |
| 3477 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3478 | 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] | 3479 | 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] | 3480 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3481 | } |
| 3482 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3483 | 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] | 3484 | 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] | 3485 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
| 3486 | *Pointer<Float4>(buffer) = oC.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3487 | |
| 3488 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3489 | |
| 3490 | value = *Pointer<Float4>(buffer); |
| 3491 | |
| 3492 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 3493 | { |
| 3494 | Float4 masked; |
| 3495 | |
| 3496 | masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3497 | 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] | 3498 | 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] | 3499 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3500 | } |
| 3501 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3502 | 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] | 3503 | 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] | 3504 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(value)); |
| 3505 | *Pointer<Float4>(buffer) = oC.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3506 | break; |
| 3507 | case FORMAT_A32B32G32R32F: |
| 3508 | buffer = cBuffer + 16 * x; |
| 3509 | |
| 3510 | { |
| 3511 | value = *Pointer<Float4>(buffer, 16); |
| 3512 | |
| 3513 | if(rgbaWriteMask != 0x0000000F) |
| 3514 | { |
| 3515 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3516 | 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] | 3517 | 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] | 3518 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3519 | } |
| 3520 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3521 | 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] | 3522 | 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] | 3523 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
| 3524 | *Pointer<Float4>(buffer, 16) = oC.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | { |
| 3528 | value = *Pointer<Float4>(buffer + 16, 16); |
| 3529 | |
| 3530 | if(rgbaWriteMask != 0x0000000F) |
| 3531 | { |
| 3532 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3533 | 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] | 3534 | 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] | 3535 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3536 | } |
| 3537 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3538 | 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] | 3539 | 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] | 3540 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(value)); |
| 3541 | *Pointer<Float4>(buffer + 16, 16) = oC.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3545 | |
| 3546 | { |
| 3547 | value = *Pointer<Float4>(buffer, 16); |
| 3548 | |
| 3549 | if(rgbaWriteMask != 0x0000000F) |
| 3550 | { |
| 3551 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3552 | 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] | 3553 | 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] | 3554 | oC.z = As<Float4>(As<Int4>(oC.z) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3555 | } |
| 3556 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3557 | 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] | 3558 | 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] | 3559 | oC.z = As<Float4>(As<Int4>(oC.z) | As<Int4>(value)); |
| 3560 | *Pointer<Float4>(buffer, 16) = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | { |
| 3564 | value = *Pointer<Float4>(buffer + 16, 16); |
| 3565 | |
| 3566 | if(rgbaWriteMask != 0x0000000F) |
| 3567 | { |
| 3568 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3569 | 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] | 3570 | 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] | 3571 | oC.w = As<Float4>(As<Int4>(oC.w) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3572 | } |
| 3573 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3574 | 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] | 3575 | 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] | 3576 | oC.w = As<Float4>(As<Int4>(oC.w) | As<Int4>(value)); |
| 3577 | *Pointer<Float4>(buffer + 16, 16) = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3578 | } |
| 3579 | break; |
| 3580 | default: |
| 3581 | ASSERT(false); |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | void PixelRoutine::ps_1_x(Registers &r, Int cMask[4]) |
| 3586 | { |
| 3587 | int pad = 0; // Count number of texm3x3pad instructions |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3588 | Vector4i dPairing; // Destination for first pairing instruction |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3589 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3590 | for(int i = 0; i < shader->getLength(); i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3591 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3592 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3593 | Shader::Opcode opcode = instruction->opcode; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3594 | |
| 3595 | // #ifndef NDEBUG // FIXME: Centralize debug output control |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3596 | // shader->printInstruction(i, "debug.txt"); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3597 | // #endif |
| 3598 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3599 | 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] | 3600 | { |
| 3601 | continue; |
| 3602 | } |
| 3603 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3604 | const Dst &dst = instruction->dst; |
| 3605 | const Src &src0 = instruction->src[0]; |
| 3606 | const Src &src1 = instruction->src[1]; |
| 3607 | const Src &src2 = instruction->src[2]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3608 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3609 | unsigned short version = shader->getVersion(); |
| 3610 | bool pairing = i + 1 < shader->getLength() && shader->getInstruction(i + 1)->coissue; // First instruction of pair |
| 3611 | bool coissue = instruction->coissue; // Second instruction of pair |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3612 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3613 | Vector4i d; |
| 3614 | Vector4i s0; |
| 3615 | Vector4i s1; |
| 3616 | Vector4i s2; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3617 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3618 | if(src0.type != Shader::PARAMETER_VOID) s0 = regi(r, src0); |
| 3619 | if(src1.type != Shader::PARAMETER_VOID) s1 = regi(r, src1); |
| 3620 | if(src2.type != Shader::PARAMETER_VOID) s2 = regi(r, src2); |
| 3621 | |
| 3622 | Float4 u = version < 0x0104 ? r.vf[2 + dst.index].x : r.vf[2 + src0.index].x; |
| 3623 | Float4 v = version < 0x0104 ? r.vf[2 + dst.index].y : r.vf[2 + src0.index].y; |
| 3624 | Float4 s = version < 0x0104 ? r.vf[2 + dst.index].z : r.vf[2 + src0.index].z; |
| 3625 | 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] | 3626 | |
| 3627 | switch(opcode) |
| 3628 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3629 | case Shader::OPCODE_PS_1_0: break; |
| 3630 | case Shader::OPCODE_PS_1_1: break; |
| 3631 | case Shader::OPCODE_PS_1_2: break; |
| 3632 | case Shader::OPCODE_PS_1_3: break; |
| 3633 | case Shader::OPCODE_PS_1_4: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3634 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3635 | case Shader::OPCODE_DEF: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3636 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3637 | case Shader::OPCODE_NOP: break; |
| 3638 | case Shader::OPCODE_MOV: MOV(d, s0); break; |
| 3639 | case Shader::OPCODE_ADD: ADD(d, s0, s1); break; |
| 3640 | case Shader::OPCODE_SUB: SUB(d, s0, s1); break; |
| 3641 | case Shader::OPCODE_MAD: MAD(d, s0, s1, s2); break; |
| 3642 | case Shader::OPCODE_MUL: MUL(d, s0, s1); break; |
| 3643 | case Shader::OPCODE_DP3: DP3(d, s0, s1); break; |
| 3644 | case Shader::OPCODE_DP4: DP4(d, s0, s1); break; |
| 3645 | case Shader::OPCODE_LRP: LRP(d, s0, s1, s2); break; |
| 3646 | case Shader::OPCODE_TEXCOORD: |
| 3647 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3648 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3649 | TEXCOORD(d, u, v, s, dst.index); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3650 | } |
| 3651 | else |
| 3652 | { |
| 3653 | if((src0.swizzle & 0x30) == 0x20) // .xyz |
| 3654 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3655 | 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] | 3656 | } |
| 3657 | else // .xyw |
| 3658 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3659 | 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] | 3660 | } |
| 3661 | } |
| 3662 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3663 | case Shader::OPCODE_TEXKILL: |
| 3664 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3665 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3666 | TEXKILL(cMask, u, v, s); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3667 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3668 | else if(version == 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3669 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3670 | if(dst.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3671 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3672 | TEXKILL(cMask, u, v, s); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3673 | } |
| 3674 | else |
| 3675 | { |
| 3676 | TEXKILL(cMask, r.ri[dst.index]); |
| 3677 | } |
| 3678 | } |
| 3679 | else ASSERT(false); |
| 3680 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3681 | case Shader::OPCODE_TEX: |
| 3682 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3683 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3684 | TEX(r, d, u, v, s, dst.index, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3685 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3686 | else if(version == 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3687 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3688 | if(src0.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3689 | { |
| 3690 | if((src0.swizzle & 0x30) == 0x20) // .xyz |
| 3691 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3692 | 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] | 3693 | } |
| 3694 | else // .xyw |
| 3695 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3696 | 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] | 3697 | } |
| 3698 | } |
| 3699 | else |
| 3700 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3701 | 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] | 3702 | } |
| 3703 | } |
| 3704 | else ASSERT(false); |
| 3705 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3706 | case Shader::OPCODE_TEXBEM: TEXBEM(r, d, s0, u, v, s, dst.index); break; |
| 3707 | case Shader::OPCODE_TEXBEML: TEXBEML(r, d, s0, u, v, s, dst.index); break; |
| 3708 | case Shader::OPCODE_TEXREG2AR: TEXREG2AR(r, d, s0, dst.index); break; |
| 3709 | case Shader::OPCODE_TEXREG2GB: TEXREG2GB(r, d, s0, dst.index); break; |
| 3710 | case Shader::OPCODE_TEXM3X2PAD: TEXM3X2PAD(r, u, v, s, s0, 0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3711 | case Shader::OPCODE_TEXM3X2TEX: TEXM3X2TEX(r, d, u, v, s, dst.index, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3712 | case Shader::OPCODE_TEXM3X3PAD: TEXM3X3PAD(r, u, v, s, s0, pad++ % 2, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3713 | case Shader::OPCODE_TEXM3X3TEX: TEXM3X3TEX(r, d, u, v, s, dst.index, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3714 | case Shader::OPCODE_TEXM3X3SPEC: TEXM3X3SPEC(r, d, u, v, s, dst.index, s0, s1); break; |
| 3715 | case Shader::OPCODE_TEXM3X3VSPEC: TEXM3X3VSPEC(r, d, u, v, s, dst.index, s0); break; |
| 3716 | case Shader::OPCODE_CND: CND(d, s0, s1, s2); break; |
| 3717 | case Shader::OPCODE_TEXREG2RGB: TEXREG2RGB(r, d, s0, dst.index); break; |
| 3718 | case Shader::OPCODE_TEXDP3TEX: TEXDP3TEX(r, d, u, v, s, dst.index, s0); break; |
| 3719 | case Shader::OPCODE_TEXM3X2DEPTH: TEXM3X2DEPTH(r, d, u, v, s, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3720 | case Shader::OPCODE_TEXDP3: TEXDP3(r, d, u, v, s, s0); break; |
| 3721 | case Shader::OPCODE_TEXM3X3: TEXM3X3(r, d, u, v, s, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3722 | case Shader::OPCODE_TEXDEPTH: TEXDEPTH(r); break; |
| 3723 | case Shader::OPCODE_CMP0: CMP(d, s0, s1, s2); break; |
| 3724 | case Shader::OPCODE_BEM: BEM(r, d, s0, s1, dst.index); break; |
| 3725 | case Shader::OPCODE_PHASE: break; |
| 3726 | case Shader::OPCODE_END: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3727 | default: |
| 3728 | ASSERT(false); |
| 3729 | } |
| 3730 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3731 | if(dst.type != Shader::PARAMETER_VOID && opcode != Shader::OPCODE_TEXKILL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3732 | { |
| 3733 | if(dst.shift > 0) |
| 3734 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3735 | 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);} |
| 3736 | 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);} |
| 3737 | 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);} |
| 3738 | 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] | 3739 | } |
| 3740 | else if(dst.shift < 0) |
| 3741 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3742 | if(dst.mask & 0x1) d.x = d.x >> -dst.shift; |
| 3743 | if(dst.mask & 0x2) d.y = d.y >> -dst.shift; |
| 3744 | if(dst.mask & 0x4) d.z = d.z >> -dst.shift; |
| 3745 | if(dst.mask & 0x8) d.w = d.w >> -dst.shift; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | if(dst.saturate) |
| 3749 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3750 | if(dst.mask & 0x1) {d.x = Min(d.x, Short4(0x1000)); d.x = Max(d.x, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3751 | if(dst.mask & 0x2) {d.y = Min(d.y, Short4(0x1000)); d.y = Max(d.y, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3752 | if(dst.mask & 0x4) {d.z = Min(d.z, Short4(0x1000)); d.z = Max(d.z, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3753 | 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] | 3754 | } |
| 3755 | |
| 3756 | if(pairing) |
| 3757 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3758 | if(dst.mask & 0x1) dPairing.x = d.x; |
| 3759 | if(dst.mask & 0x2) dPairing.y = d.y; |
| 3760 | if(dst.mask & 0x4) dPairing.z = d.z; |
| 3761 | if(dst.mask & 0x8) dPairing.w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | if(coissue) |
| 3765 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3766 | const Dst &dst = shader->getInstruction(i - 1)->dst; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3767 | |
| 3768 | writeDestination(r, dPairing, dst); |
| 3769 | } |
| 3770 | |
| 3771 | if(!pairing) |
| 3772 | { |
| 3773 | writeDestination(r, d, dst); |
| 3774 | } |
| 3775 | } |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | void PixelRoutine::ps_2_x(Registers &r, Int cMask[4]) |
| 3780 | { |
| 3781 | r.enableIndex = 0; |
| 3782 | r.stackIndex = 0; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3783 | |
| 3784 | bool out[4][4] = {false}; |
| 3785 | |
| 3786 | // Create all call site return blocks up front |
| 3787 | for(int i = 0; i < shader->getLength(); i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3788 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3789 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3790 | Shader::Opcode opcode = instruction->opcode; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3791 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3792 | if(opcode == Shader::OPCODE_CALL || opcode == Shader::OPCODE_CALLNZ) |
| 3793 | { |
| 3794 | const Dst &dst = instruction->dst; |
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 | ASSERT(callRetBlock[dst.label].size() == dst.callSite); |
| 3797 | callRetBlock[dst.label].push_back(Nucleus::createBasicBlock()); |
| 3798 | } |
| 3799 | } |
| 3800 | |
| 3801 | for(int i = 0; i < shader->getLength(); i++) |
| 3802 | { |
| 3803 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3804 | Shader::Opcode opcode = instruction->opcode; |
| 3805 | |
| 3806 | 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] | 3807 | { |
| 3808 | continue; |
| 3809 | } |
| 3810 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3811 | const Dst &dst = instruction->dst; |
| 3812 | const Src &src0 = instruction->src[0]; |
| 3813 | const Src &src1 = instruction->src[1]; |
| 3814 | const Src &src2 = instruction->src[2]; |
| 3815 | const Src &src3 = instruction->src[3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3816 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3817 | bool predicate = instruction->predicate; |
| 3818 | Control control = instruction->control; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3819 | bool pp = dst.partialPrecision; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3820 | bool project = instruction->project; |
| 3821 | bool bias = instruction->bias; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3822 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3823 | Vector4f d; |
| 3824 | Vector4f s0; |
| 3825 | Vector4f s1; |
| 3826 | Vector4f s2; |
| 3827 | Vector4f s3; |
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(opcode == Shader::OPCODE_TEXKILL) // Takes destination as input |
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 | if(dst.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3832 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3833 | d.x = r.vf[2 + dst.index].x; |
| 3834 | d.y = r.vf[2 + dst.index].y; |
| 3835 | d.z = r.vf[2 + dst.index].z; |
| 3836 | d.w = r.vf[2 + dst.index].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3837 | } |
| 3838 | else |
| 3839 | { |
| 3840 | d = r.rf[dst.index]; |
| 3841 | } |
| 3842 | } |
| 3843 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3844 | if(src0.type != Shader::PARAMETER_VOID) s0 = reg(r, src0); |
| 3845 | if(src1.type != Shader::PARAMETER_VOID) s1 = reg(r, src1); |
| 3846 | if(src2.type != Shader::PARAMETER_VOID) s2 = reg(r, src2); |
| 3847 | if(src3.type != Shader::PARAMETER_VOID) s3 = reg(r, src3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3848 | |
| 3849 | switch(opcode) |
| 3850 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3851 | case Shader::OPCODE_PS_2_0: break; |
| 3852 | case Shader::OPCODE_PS_2_x: break; |
| 3853 | case Shader::OPCODE_PS_3_0: break; |
| 3854 | case Shader::OPCODE_DEF: break; |
| 3855 | case Shader::OPCODE_DCL: break; |
| 3856 | case Shader::OPCODE_NOP: break; |
| 3857 | case Shader::OPCODE_MOV: mov(d, s0); break; |
| 3858 | case Shader::OPCODE_F2B: f2b(d, s0); break; |
| 3859 | case Shader::OPCODE_B2F: b2f(d, s0); break; |
| 3860 | case Shader::OPCODE_ADD: add(d, s0, s1); break; |
| 3861 | case Shader::OPCODE_SUB: sub(d, s0, s1); break; |
| 3862 | case Shader::OPCODE_MUL: mul(d, s0, s1); break; |
| 3863 | case Shader::OPCODE_MAD: mad(d, s0, s1, s2); break; |
| 3864 | case Shader::OPCODE_DP1: dp1(d, s0, s1); break; |
| 3865 | case Shader::OPCODE_DP2: dp2(d, s0, s1); break; |
| 3866 | case Shader::OPCODE_DP2ADD: dp2add(d, s0, s1, s2); break; |
| 3867 | case Shader::OPCODE_DP3: dp3(d, s0, s1); break; |
| 3868 | case Shader::OPCODE_DP4: dp4(d, s0, s1); break; |
| 3869 | case Shader::OPCODE_CMP0: cmp0(d, s0, s1, s2); break; |
| 3870 | case Shader::OPCODE_ICMP: icmp(d, s0, s1, control); break; |
| 3871 | case Shader::OPCODE_SELECT: select(d, s0, s1, s2); break; |
| 3872 | case Shader::OPCODE_EXTRACT: extract(d.x, s0, s1.x); break; |
| 3873 | case Shader::OPCODE_INSERT: insert(d, s0, s1.x, s2.x); break; |
| 3874 | case Shader::OPCODE_FRC: frc(d, s0); break; |
| 3875 | case Shader::OPCODE_TRUNC: trunc(d, s0); break; |
| 3876 | case Shader::OPCODE_FLOOR: floor(d, s0); break; |
| 3877 | case Shader::OPCODE_CEIL: ceil(d, s0); break; |
| 3878 | case Shader::OPCODE_EXP2X: exp2x(d, s0, pp); break; |
| 3879 | case Shader::OPCODE_EXP2: exp2(d, s0, pp); break; |
| 3880 | case Shader::OPCODE_LOG2X: log2x(d, s0, pp); break; |
| 3881 | case Shader::OPCODE_LOG2: log2(d, s0, pp); break; |
| 3882 | case Shader::OPCODE_EXP: exp(d, s0, pp); break; |
| 3883 | case Shader::OPCODE_LOG: log(d, s0, pp); break; |
| 3884 | case Shader::OPCODE_RCPX: rcpx(d, s0, pp); break; |
| 3885 | case Shader::OPCODE_DIV: div(d, s0, s1); break; |
| 3886 | case Shader::OPCODE_MOD: mod(d, s0, s1); break; |
| 3887 | case Shader::OPCODE_RSQX: rsqx(d, s0, pp); break; |
| 3888 | case Shader::OPCODE_SQRT: sqrt(d, s0, pp); break; |
| 3889 | case Shader::OPCODE_RSQ: rsq(d, s0, pp); break; |
| 3890 | case Shader::OPCODE_LEN2: len2(d.x, s0, pp); break; |
| 3891 | case Shader::OPCODE_LEN3: len3(d.x, s0, pp); break; |
| 3892 | case Shader::OPCODE_LEN4: len4(d.x, s0, pp); break; |
| 3893 | case Shader::OPCODE_DIST1: dist1(d.x, s0, s1, pp); break; |
| 3894 | case Shader::OPCODE_DIST2: dist2(d.x, s0, s1, pp); break; |
| 3895 | case Shader::OPCODE_DIST3: dist3(d.x, s0, s1, pp); break; |
| 3896 | case Shader::OPCODE_DIST4: dist4(d.x, s0, s1, pp); break; |
| 3897 | case Shader::OPCODE_MIN: min(d, s0, s1); break; |
| 3898 | case Shader::OPCODE_MAX: max(d, s0, s1); break; |
| 3899 | case Shader::OPCODE_LRP: lrp(d, s0, s1, s2); break; |
| 3900 | case Shader::OPCODE_STEP: step(d, s0, s1); break; |
| 3901 | case Shader::OPCODE_SMOOTH: smooth(d, s0, s1, s2); break; |
| 3902 | case Shader::OPCODE_POWX: powx(d, s0, s1, pp); break; |
| 3903 | case Shader::OPCODE_POW: pow(d, s0, s1, pp); break; |
| 3904 | case Shader::OPCODE_SGN: sgn(d, s0); break; |
| 3905 | case Shader::OPCODE_CRS: crs(d, s0, s1); break; |
| 3906 | case Shader::OPCODE_FORWARD1: forward1(d, s0, s1, s2); break; |
| 3907 | case Shader::OPCODE_FORWARD2: forward2(d, s0, s1, s2); break; |
| 3908 | case Shader::OPCODE_FORWARD3: forward3(d, s0, s1, s2); break; |
| 3909 | case Shader::OPCODE_FORWARD4: forward4(d, s0, s1, s2); break; |
| 3910 | case Shader::OPCODE_REFLECT1: reflect1(d, s0, s1); break; |
| 3911 | case Shader::OPCODE_REFLECT2: reflect2(d, s0, s1); break; |
| 3912 | case Shader::OPCODE_REFLECT3: reflect3(d, s0, s1); break; |
| 3913 | case Shader::OPCODE_REFLECT4: reflect4(d, s0, s1); break; |
| 3914 | case Shader::OPCODE_REFRACT1: refract1(d, s0, s1, s2.x); break; |
| 3915 | case Shader::OPCODE_REFRACT2: refract2(d, s0, s1, s2.x); break; |
| 3916 | case Shader::OPCODE_REFRACT3: refract3(d, s0, s1, s2.x); break; |
| 3917 | case Shader::OPCODE_REFRACT4: refract4(d, s0, s1, s2.x); break; |
| 3918 | case Shader::OPCODE_NRM2: nrm2(d, s0, pp); break; |
| 3919 | case Shader::OPCODE_NRM3: nrm3(d, s0, pp); break; |
| 3920 | case Shader::OPCODE_NRM4: nrm4(d, s0, pp); break; |
| 3921 | case Shader::OPCODE_ABS: abs(d, s0); break; |
| 3922 | case Shader::OPCODE_SINCOS: sincos(d, s0, pp); break; |
| 3923 | case Shader::OPCODE_COS: cos(d, s0, pp); break; |
| 3924 | case Shader::OPCODE_SIN: sin(d, s0, pp); break; |
| 3925 | case Shader::OPCODE_TAN: tan(d, s0, pp); break; |
| 3926 | case Shader::OPCODE_ACOS: acos(d, s0, pp); break; |
| 3927 | case Shader::OPCODE_ASIN: asin(d, s0, pp); break; |
| 3928 | case Shader::OPCODE_ATAN: atan(d, s0, pp); break; |
| 3929 | case Shader::OPCODE_ATAN2: atan2(d, s0, s1, pp); break; |
| 3930 | case Shader::OPCODE_M4X4: M4X4(r, d, s0, src1); break; |
| 3931 | case Shader::OPCODE_M4X3: M4X3(r, d, s0, src1); break; |
| 3932 | case Shader::OPCODE_M3X4: M3X4(r, d, s0, src1); break; |
| 3933 | case Shader::OPCODE_M3X3: M3X3(r, d, s0, src1); break; |
| 3934 | case Shader::OPCODE_M3X2: M3X2(r, d, s0, src1); break; |
| 3935 | case Shader::OPCODE_TEX: TEXLD(r, d, s0, src1, project, bias); break; |
| 3936 | case Shader::OPCODE_TEXLDD: TEXLDD(r, d, s0, src1, s2, s3, project, bias); break; |
| 3937 | case Shader::OPCODE_TEXLDL: TEXLDL(r, d, s0, src1, project, bias); break; |
| 3938 | case Shader::OPCODE_TEXKILL: TEXKILL(cMask, d, dst.mask); break; |
| 3939 | case Shader::OPCODE_DISCARD: DISCARD(r, cMask, instruction); break; |
| 3940 | case Shader::OPCODE_DFDX: DFDX(d, s0); break; |
| 3941 | case Shader::OPCODE_DFDY: DFDY(d, s0); break; |
| 3942 | case Shader::OPCODE_FWIDTH: FWIDTH(d, s0); break; |
| 3943 | case Shader::OPCODE_BREAK: BREAK(r); break; |
| 3944 | case Shader::OPCODE_BREAKC: BREAKC(r, s0, s1, control); break; |
| 3945 | case Shader::OPCODE_BREAKP: BREAKP(r, src0); break; |
| 3946 | case Shader::OPCODE_CONTINUE: CONTINUE(r); break; |
| 3947 | case Shader::OPCODE_TEST: TEST(); break; |
| 3948 | case Shader::OPCODE_CALL: CALL(r, dst.label, dst.callSite); break; |
| 3949 | case Shader::OPCODE_CALLNZ: CALLNZ(r, dst.label, dst.callSite, src0); break; |
| 3950 | case Shader::OPCODE_ELSE: ELSE(r); break; |
| 3951 | case Shader::OPCODE_ENDIF: ENDIF(r); break; |
| 3952 | case Shader::OPCODE_ENDLOOP: ENDLOOP(r); break; |
| 3953 | case Shader::OPCODE_ENDREP: ENDREP(r); break; |
| 3954 | case Shader::OPCODE_ENDWHILE: ENDWHILE(r); break; |
| 3955 | case Shader::OPCODE_IF: IF(r, src0); break; |
| 3956 | case Shader::OPCODE_IFC: IFC(r, s0, s1, control); break; |
| 3957 | case Shader::OPCODE_LABEL: LABEL(dst.index); break; |
| 3958 | case Shader::OPCODE_LOOP: LOOP(r, src1); break; |
| 3959 | case Shader::OPCODE_REP: REP(r, src0); break; |
| 3960 | case Shader::OPCODE_WHILE: WHILE(r, src0); break; |
| 3961 | case Shader::OPCODE_RET: RET(r); break; |
| 3962 | case Shader::OPCODE_LEAVE: LEAVE(r); break; |
| 3963 | case Shader::OPCODE_CMP: cmp(d, s0, s1, control); break; |
| 3964 | case Shader::OPCODE_ALL: all(d.x, s0); break; |
| 3965 | case Shader::OPCODE_ANY: any(d.x, s0); break; |
| 3966 | case Shader::OPCODE_NOT: not(d, s0); break; |
| 3967 | case Shader::OPCODE_OR: or(d.x, s0.x, s1.x); break; |
| 3968 | case Shader::OPCODE_XOR: xor(d.x, s0.x, s1.x); break; |
| 3969 | case Shader::OPCODE_AND: and(d.x, s0.x, s1.x); break; |
| 3970 | case Shader::OPCODE_END: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3971 | default: |
| 3972 | ASSERT(false); |
| 3973 | } |
| 3974 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3975 | 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] | 3976 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3977 | if(dst.integer) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3978 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3979 | switch(opcode) |
| 3980 | { |
| 3981 | case Shader::OPCODE_DIV: |
| 3982 | if(dst.x) d.x = Trunc(d.x); |
| 3983 | if(dst.y) d.y = Trunc(d.y); |
| 3984 | if(dst.z) d.z = Trunc(d.z); |
| 3985 | if(dst.w) d.w = Trunc(d.w); |
| 3986 | break; |
| 3987 | default: |
| 3988 | break; // No truncation to integer required when arguments are integer |
| 3989 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3990 | } |
| 3991 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3992 | if(dst.saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3993 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3994 | if(dst.x) d.x = Max(d.x, Float4(0.0f)); |
| 3995 | if(dst.y) d.y = Max(d.y, Float4(0.0f)); |
| 3996 | if(dst.z) d.z = Max(d.z, Float4(0.0f)); |
| 3997 | if(dst.w) d.w = Max(d.w, Float4(0.0f)); |
| 3998 | |
| 3999 | if(dst.x) d.x = Min(d.x, Float4(1.0f)); |
| 4000 | if(dst.y) d.y = Min(d.y, Float4(1.0f)); |
| 4001 | if(dst.z) d.z = Min(d.z, Float4(1.0f)); |
| 4002 | if(dst.w) d.w = Min(d.w, Float4(1.0f)); |
| 4003 | } |
| 4004 | |
| 4005 | if(shader->containsDynamicBranching()) |
| 4006 | { |
| 4007 | Vector4f pDst; // FIXME: Rename |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4008 | |
| 4009 | switch(dst.type) |
| 4010 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4011 | case Shader::PARAMETER_TEMP: |
| 4012 | if(dst.rel.type == Shader::PARAMETER_VOID) |
| 4013 | { |
| 4014 | if(dst.x) pDst.x = r.rf[dst.index].x; |
| 4015 | if(dst.y) pDst.y = r.rf[dst.index].y; |
| 4016 | if(dst.z) pDst.z = r.rf[dst.index].z; |
| 4017 | if(dst.w) pDst.w = r.rf[dst.index].w; |
| 4018 | } |
| 4019 | else |
| 4020 | { |
| 4021 | Int a = relativeAddress(r, dst); |
| 4022 | |
| 4023 | if(dst.x) pDst.x = r.rf[dst.index + a].x; |
| 4024 | if(dst.y) pDst.y = r.rf[dst.index + a].y; |
| 4025 | if(dst.z) pDst.z = r.rf[dst.index + a].z; |
| 4026 | if(dst.w) pDst.w = r.rf[dst.index + a].w; |
| 4027 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4028 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4029 | case Shader::PARAMETER_COLOROUT: |
| 4030 | ASSERT(dst.rel.type == Shader::PARAMETER_VOID); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4031 | if(dst.x) pDst.x = r.oC[dst.index].x; |
| 4032 | if(dst.y) pDst.y = r.oC[dst.index].y; |
| 4033 | if(dst.z) pDst.z = r.oC[dst.index].z; |
| 4034 | if(dst.w) pDst.w = r.oC[dst.index].w; |
| 4035 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4036 | case Shader::PARAMETER_PREDICATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4037 | if(dst.x) pDst.x = r.p0.x; |
| 4038 | if(dst.y) pDst.y = r.p0.y; |
| 4039 | if(dst.z) pDst.z = r.p0.z; |
| 4040 | if(dst.w) pDst.w = r.p0.w; |
| 4041 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4042 | case Shader::PARAMETER_DEPTHOUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4043 | pDst.x = r.oDepth; |
| 4044 | break; |
| 4045 | default: |
| 4046 | ASSERT(false); |
| 4047 | } |
| 4048 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4049 | Int4 enable = enableMask(r, instruction); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4050 | |
| 4051 | Int4 xEnable = enable; |
| 4052 | Int4 yEnable = enable; |
| 4053 | Int4 zEnable = enable; |
| 4054 | Int4 wEnable = enable; |
| 4055 | |
| 4056 | if(predicate) |
| 4057 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4058 | unsigned char pSwizzle = instruction->predicateSwizzle; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4059 | |
| 4060 | Float4 xPredicate = r.p0[(pSwizzle >> 0) & 0x03]; |
| 4061 | Float4 yPredicate = r.p0[(pSwizzle >> 2) & 0x03]; |
| 4062 | Float4 zPredicate = r.p0[(pSwizzle >> 4) & 0x03]; |
| 4063 | Float4 wPredicate = r.p0[(pSwizzle >> 6) & 0x03]; |
| 4064 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4065 | if(!instruction->predicateNot) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4066 | { |
| 4067 | if(dst.x) xEnable = xEnable & As<Int4>(xPredicate); |
| 4068 | if(dst.y) yEnable = yEnable & As<Int4>(yPredicate); |
| 4069 | if(dst.z) zEnable = zEnable & As<Int4>(zPredicate); |
| 4070 | if(dst.w) wEnable = wEnable & As<Int4>(wPredicate); |
| 4071 | } |
| 4072 | else |
| 4073 | { |
| 4074 | if(dst.x) xEnable = xEnable & ~As<Int4>(xPredicate); |
| 4075 | if(dst.y) yEnable = yEnable & ~As<Int4>(yPredicate); |
| 4076 | if(dst.z) zEnable = zEnable & ~As<Int4>(zPredicate); |
| 4077 | if(dst.w) wEnable = wEnable & ~As<Int4>(wPredicate); |
| 4078 | } |
| 4079 | } |
| 4080 | |
| 4081 | if(dst.x) d.x = As<Float4>(As<Int4>(d.x) & xEnable); |
| 4082 | if(dst.y) d.y = As<Float4>(As<Int4>(d.y) & yEnable); |
| 4083 | if(dst.z) d.z = As<Float4>(As<Int4>(d.z) & zEnable); |
| 4084 | if(dst.w) d.w = As<Float4>(As<Int4>(d.w) & wEnable); |
| 4085 | |
| 4086 | if(dst.x) d.x = As<Float4>(As<Int4>(d.x) | (As<Int4>(pDst.x) & ~xEnable)); |
| 4087 | if(dst.y) d.y = As<Float4>(As<Int4>(d.y) | (As<Int4>(pDst.y) & ~yEnable)); |
| 4088 | if(dst.z) d.z = As<Float4>(As<Int4>(d.z) | (As<Int4>(pDst.z) & ~zEnable)); |
| 4089 | if(dst.w) d.w = As<Float4>(As<Int4>(d.w) | (As<Int4>(pDst.w) & ~wEnable)); |
| 4090 | } |
| 4091 | |
| 4092 | switch(dst.type) |
| 4093 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4094 | case Shader::PARAMETER_TEMP: |
| 4095 | if(dst.rel.type == Shader::PARAMETER_VOID) |
| 4096 | { |
| 4097 | if(dst.x) r.rf[dst.index].x = d.x; |
| 4098 | if(dst.y) r.rf[dst.index].y = d.y; |
| 4099 | if(dst.z) r.rf[dst.index].z = d.z; |
| 4100 | if(dst.w) r.rf[dst.index].w = d.w; |
| 4101 | } |
| 4102 | else |
| 4103 | { |
| 4104 | Int a = relativeAddress(r, dst); |
| 4105 | |
| 4106 | if(dst.x) r.rf[dst.index + a].x = d.x; |
| 4107 | if(dst.y) r.rf[dst.index + a].y = d.y; |
| 4108 | if(dst.z) r.rf[dst.index + a].z = d.z; |
| 4109 | if(dst.w) r.rf[dst.index + a].w = d.w; |
| 4110 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4111 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4112 | case Shader::PARAMETER_COLOROUT: |
| 4113 | ASSERT(dst.rel.type == Shader::PARAMETER_VOID); |
| 4114 | if(dst.x) {r.oC[dst.index].x = d.x; out[dst.index][0] = true;} |
| 4115 | if(dst.y) {r.oC[dst.index].y = d.y; out[dst.index][1] = true;} |
| 4116 | if(dst.z) {r.oC[dst.index].z = d.z; out[dst.index][2] = true;} |
| 4117 | 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] | 4118 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4119 | case Shader::PARAMETER_PREDICATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4120 | if(dst.x) r.p0.x = d.x; |
| 4121 | if(dst.y) r.p0.y = d.y; |
| 4122 | if(dst.z) r.p0.z = d.z; |
| 4123 | if(dst.w) r.p0.w = d.w; |
| 4124 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4125 | case Shader::PARAMETER_DEPTHOUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4126 | r.oDepth = d.x; |
| 4127 | break; |
| 4128 | default: |
| 4129 | ASSERT(false); |
| 4130 | } |
| 4131 | } |
| 4132 | } |
| 4133 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4134 | if(currentLabel != -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4135 | { |
| 4136 | Nucleus::setInsertBlock(returnBlock); |
| 4137 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4138 | |
| 4139 | for(int i = 0; i < 4; i++) |
| 4140 | { |
| 4141 | if((Format)state.targetFormat[i] != FORMAT_NULL) |
| 4142 | { |
| 4143 | if(!out[i][0]) r.oC[i].x = Float4(0.0f); |
| 4144 | if(!out[i][1]) r.oC[i].y = Float4(0.0f); |
| 4145 | if(!out[i][2]) r.oC[i].z = Float4(0.0f); |
| 4146 | if(!out[i][3]) r.oC[i].w = Float4(0.0f); |
| 4147 | } |
| 4148 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4149 | } |
| 4150 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4151 | Short4 PixelRoutine::convertFixed12(RValue<Float4> cf) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4152 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4153 | return RoundShort4(cf * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4154 | } |
| 4155 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4156 | void PixelRoutine::convertFixed12(Vector4i &ci, Vector4f &cf) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4157 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4158 | ci.x = convertFixed12(cf.x); |
| 4159 | ci.y = convertFixed12(cf.y); |
| 4160 | ci.z = convertFixed12(cf.z); |
| 4161 | ci.w = convertFixed12(cf.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | UShort4 PixelRoutine::convertFixed16(Float4 &cf, bool saturate) |
| 4165 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4166 | return UShort4(cf * Float4(0xFFFF), saturate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4167 | } |
| 4168 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4169 | void PixelRoutine::convertFixed16(Vector4i &ci, Vector4f &cf, bool saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4170 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4171 | ci.x = convertFixed16(cf.x, saturate); |
| 4172 | ci.y = convertFixed16(cf.y, saturate); |
| 4173 | ci.z = convertFixed16(cf.z, saturate); |
| 4174 | ci.w = convertFixed16(cf.w, saturate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | Float4 PixelRoutine::convertSigned12(Short4 &ci) |
| 4178 | { |
| 4179 | return Float4(ci) * Float4(1.0f / 0x0FFE); |
| 4180 | } |
| 4181 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4182 | void PixelRoutine::convertSigned12(Vector4f &cf, Vector4i &ci) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4183 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4184 | cf.x = convertSigned12(ci.x); |
| 4185 | cf.y = convertSigned12(ci.y); |
| 4186 | cf.z = convertSigned12(ci.z); |
| 4187 | cf.w = convertSigned12(ci.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | Float4 PixelRoutine::convertUnsigned16(UShort4 ci) |
| 4191 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4192 | return Float4(ci) * Float4(1.0f / 0xFFFF); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4193 | } |
| 4194 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4195 | void PixelRoutine::sRGBtoLinear16_16(Registers &r, Vector4i &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4196 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4197 | c.x = As<UShort4>(c.x) >> 4; |
| 4198 | c.y = As<UShort4>(c.y) >> 4; |
| 4199 | c.z = As<UShort4>(c.z) >> 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4200 | |
| 4201 | sRGBtoLinear12_16(r, c); |
| 4202 | } |
| 4203 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4204 | void PixelRoutine::sRGBtoLinear12_16(Registers &r, Vector4i &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4205 | { |
| 4206 | Pointer<Byte> LUT = r.constants + OFFSET(Constants,sRGBtoLin12_16); |
| 4207 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4208 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); |
| 4209 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); |
| 4210 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); |
| 4211 | 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] | 4212 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4213 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 0))), 0); |
| 4214 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 1))), 1); |
| 4215 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 2))), 2); |
| 4216 | 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] | 4217 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4218 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 0))), 0); |
| 4219 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 1))), 1); |
| 4220 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 2))), 2); |
| 4221 | 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] | 4222 | } |
| 4223 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4224 | void PixelRoutine::linearToSRGB16_16(Registers &r, Vector4i &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4225 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4226 | c.x = As<UShort4>(c.x) >> 4; |
| 4227 | c.y = As<UShort4>(c.y) >> 4; |
| 4228 | c.z = As<UShort4>(c.z) >> 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4229 | |
| 4230 | linearToSRGB12_16(r, c); |
| 4231 | } |
| 4232 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4233 | void PixelRoutine::linearToSRGB12_16(Registers &r, Vector4i &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4234 | { |
| 4235 | Pointer<Byte> LUT = r.constants + OFFSET(Constants,linToSRGB12_16); |
| 4236 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4237 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); |
| 4238 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); |
| 4239 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); |
| 4240 | 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] | 4241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4242 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 0))), 0); |
| 4243 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 1))), 1); |
| 4244 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 2))), 2); |
| 4245 | 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] | 4246 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4247 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 0))), 0); |
| 4248 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 1))), 1); |
| 4249 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 2))), 2); |
| 4250 | 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] | 4251 | } |
| 4252 | |
| 4253 | Float4 PixelRoutine::linearToSRGB(const Float4 &x) // Approximates x^(1.0/2.2) |
| 4254 | { |
| 4255 | Float4 sqrtx = Rcp_pp(RcpSqrt_pp(x)); |
| 4256 | Float4 sRGB = sqrtx * Float4(1.14f) - x * Float4(0.14f); |
| 4257 | |
| 4258 | return Min(Max(sRGB, Float4(0.0f)), Float4(1.0f)); |
| 4259 | } |
| 4260 | |
| 4261 | Float4 PixelRoutine::sRGBtoLinear(const Float4 &x) // Approximates x^2.2 |
| 4262 | { |
| 4263 | Float4 linear = x * x; |
| 4264 | linear = linear * Float4(0.73f) + linear * x * Float4(0.27f); |
| 4265 | |
| 4266 | return Min(Max(linear, Float4(0.0f)), Float4(1.0f)); |
| 4267 | } |
| 4268 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4269 | void PixelRoutine::MOV(Vector4i &dst, Vector4i &src0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4270 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4271 | dst.x = src0.x; |
| 4272 | dst.y = src0.y; |
| 4273 | dst.z = src0.z; |
| 4274 | dst.w = src0.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4275 | } |
| 4276 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4277 | void PixelRoutine::ADD(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4278 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4279 | dst.x = AddSat(src0.x, src1.x); |
| 4280 | dst.y = AddSat(src0.y, src1.y); |
| 4281 | dst.z = AddSat(src0.z, src1.z); |
| 4282 | dst.w = AddSat(src0.w, src1.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4283 | } |
| 4284 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4285 | void PixelRoutine::SUB(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4286 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4287 | dst.x = SubSat(src0.x, src1.x); |
| 4288 | dst.y = SubSat(src0.y, src1.y); |
| 4289 | dst.z = SubSat(src0.z, src1.z); |
| 4290 | dst.w = SubSat(src0.w, src1.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4291 | } |
| 4292 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4293 | void PixelRoutine::MAD(Vector4i &dst, Vector4i &src0, Vector4i &src1, Vector4i &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4294 | { |
| 4295 | // FIXME: Long fixed-point multiply fixup |
| 4296 | {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);} |
| 4297 | {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);} |
| 4298 | {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);} |
| 4299 | {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);} |
| 4300 | } |
| 4301 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4302 | void PixelRoutine::MUL(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4303 | { |
| 4304 | // FIXME: Long fixed-point multiply fixup |
| 4305 | {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);} |
| 4306 | {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);} |
| 4307 | {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);} |
| 4308 | {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);} |
| 4309 | } |
| 4310 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4311 | void PixelRoutine::DP3(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4312 | { |
| 4313 | Short4 t0; |
| 4314 | Short4 t1; |
| 4315 | |
| 4316 | // FIXME: Long fixed-point multiply fixup |
| 4317 | t0 = MulHigh(src0.x, src1.x); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); |
| 4318 | t1 = MulHigh(src0.y, src1.y); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4319 | t0 = AddSat(t0, t1); |
| 4320 | t1 = MulHigh(src0.z, src1.z); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4321 | t0 = AddSat(t0, t1); |
| 4322 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4323 | dst.x = t0; |
| 4324 | dst.y = t0; |
| 4325 | dst.z = t0; |
| 4326 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4327 | } |
| 4328 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4329 | void PixelRoutine::DP4(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4330 | { |
| 4331 | Short4 t0; |
| 4332 | Short4 t1; |
| 4333 | |
| 4334 | // FIXME: Long fixed-point multiply fixup |
| 4335 | t0 = MulHigh(src0.x, src1.x); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); |
| 4336 | t1 = MulHigh(src0.y, src1.y); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4337 | t0 = AddSat(t0, t1); |
| 4338 | t1 = MulHigh(src0.z, src1.z); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4339 | t0 = AddSat(t0, t1); |
| 4340 | t1 = MulHigh(src0.w, src1.w); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4341 | t0 = AddSat(t0, t1); |
| 4342 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4343 | dst.x = t0; |
| 4344 | dst.y = t0; |
| 4345 | dst.z = t0; |
| 4346 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4347 | } |
| 4348 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4349 | void PixelRoutine::LRP(Vector4i &dst, Vector4i &src0, Vector4i &src1, Vector4i &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4350 | { |
| 4351 | // FIXME: Long fixed-point multiply fixup |
| 4352 | {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);} |
| 4353 | {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);} |
| 4354 | {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);} |
| 4355 | {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);} |
| 4356 | } |
| 4357 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4358 | void PixelRoutine::TEXCOORD(Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4359 | { |
| 4360 | Float4 uw; |
| 4361 | Float4 vw; |
| 4362 | Float4 sw; |
| 4363 | |
| 4364 | if(state.interpolant[2 + coordinate].component & 0x01) |
| 4365 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4366 | uw = Max(u, Float4(0.0f)); |
| 4367 | uw = Min(uw, Float4(1.0f)); |
| 4368 | dst.x = convertFixed12(uw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4369 | } |
| 4370 | else |
| 4371 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4372 | dst.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | if(state.interpolant[2 + coordinate].component & 0x02) |
| 4376 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4377 | vw = Max(v, Float4(0.0f)); |
| 4378 | vw = Min(vw, Float4(1.0f)); |
| 4379 | dst.y = convertFixed12(vw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4380 | } |
| 4381 | else |
| 4382 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4383 | dst.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | if(state.interpolant[2 + coordinate].component & 0x04) |
| 4387 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4388 | sw = Max(s, Float4(0.0f)); |
| 4389 | sw = Min(sw, Float4(1.0f)); |
| 4390 | dst.z = convertFixed12(sw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4391 | } |
| 4392 | else |
| 4393 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4394 | dst.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4395 | } |
| 4396 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4397 | dst.w = Short4(0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4398 | } |
| 4399 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4400 | void PixelRoutine::TEXCRD(Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate, bool project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4401 | { |
| 4402 | Float4 uw = u; |
| 4403 | Float4 vw = v; |
| 4404 | Float4 sw = s; |
| 4405 | |
| 4406 | if(project) |
| 4407 | { |
| 4408 | uw *= Rcp_pp(s); |
| 4409 | vw *= Rcp_pp(s); |
| 4410 | } |
| 4411 | |
| 4412 | if(state.interpolant[2 + coordinate].component & 0x01) |
| 4413 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4414 | uw *= Float4(0x1000); |
| 4415 | uw = Max(uw, Float4(-0x8000)); |
| 4416 | uw = Min(uw, Float4(0x7FFF)); |
| 4417 | dst.x = RoundShort4(uw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4418 | } |
| 4419 | else |
| 4420 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4421 | dst.x = Short4(0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4422 | } |
| 4423 | |
| 4424 | if(state.interpolant[2 + coordinate].component & 0x02) |
| 4425 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4426 | vw *= Float4(0x1000); |
| 4427 | vw = Max(vw, Float4(-0x8000)); |
| 4428 | vw = Min(vw, Float4(0x7FFF)); |
| 4429 | dst.y = RoundShort4(vw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4430 | } |
| 4431 | else |
| 4432 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4433 | dst.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4434 | } |
| 4435 | |
| 4436 | if(state.interpolant[2 + coordinate].component & 0x04) |
| 4437 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4438 | sw *= Float4(0x1000); |
| 4439 | sw = Max(sw, Float4(-0x8000)); |
| 4440 | sw = Min(sw, Float4(0x7FFF)); |
| 4441 | dst.z = RoundShort4(sw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4442 | } |
| 4443 | else |
| 4444 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4445 | dst.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4446 | } |
| 4447 | } |
| 4448 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4449 | void PixelRoutine::TEXDP3(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, Vector4i &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4450 | { |
| 4451 | TEXM3X3PAD(r, u, v, s, src, 0, false); |
| 4452 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4453 | Short4 t0 = RoundShort4(r.u_ * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4454 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4455 | dst.x = t0; |
| 4456 | dst.y = t0; |
| 4457 | dst.z = t0; |
| 4458 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4459 | } |
| 4460 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4461 | void PixelRoutine::TEXDP3TEX(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4i &src0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4462 | { |
| 4463 | TEXM3X3PAD(r, u, v, s, src0, 0, false); |
| 4464 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4465 | r.v_ = Float4(0.0f); |
| 4466 | r.w_ = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4467 | |
| 4468 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4469 | } |
| 4470 | |
| 4471 | void PixelRoutine::TEXKILL(Int cMask[4], Float4 &u, Float4 &v, Float4 &s) |
| 4472 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4473 | Int kill = SignMask(CmpNLT(u, Float4(0.0f))) & |
| 4474 | SignMask(CmpNLT(v, Float4(0.0f))) & |
| 4475 | SignMask(CmpNLT(s, Float4(0.0f))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4476 | |
| 4477 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 4478 | { |
| 4479 | cMask[q] &= kill; |
| 4480 | } |
| 4481 | } |
| 4482 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4483 | void PixelRoutine::TEXKILL(Int cMask[4], Vector4i &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4484 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4485 | Short4 test = src.x | src.y | src.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4486 | Int kill = SignMask(Pack(test, test)) ^ 0x0000000F; |
| 4487 | |
| 4488 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 4489 | { |
| 4490 | cMask[q] &= kill; |
| 4491 | } |
| 4492 | } |
| 4493 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4494 | void PixelRoutine::TEX(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, int sampler, bool project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4495 | { |
| 4496 | sampleTexture(r, dst, sampler, u, v, s, s, project); |
| 4497 | } |
| 4498 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4499 | void PixelRoutine::TEXLD(Registers &r, Vector4i &dst, Vector4i &src, int sampler, bool project) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4500 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4501 | Float4 u = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4502 | Float4 v = Float4(src.y) * Float4(1.0f / 0x0FFE); |
| 4503 | Float4 s = Float4(src.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4504 | |
| 4505 | sampleTexture(r, dst, sampler, u, v, s, s, project); |
| 4506 | } |
| 4507 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4508 | void PixelRoutine::TEXBEM(Registers &r, Vector4i &dst, Vector4i &src, Float4 &u, Float4 &v, Float4 &s, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4509 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4510 | Float4 du = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4511 | Float4 dv = Float4(src.y) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4512 | |
| 4513 | Float4 du2 = du; |
| 4514 | Float4 dv2 = dv; |
| 4515 | |
| 4516 | du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 4517 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 4518 | du += dv2; |
| 4519 | dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 4520 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 4521 | dv += du2; |
| 4522 | |
| 4523 | Float4 u_ = u + du; |
| 4524 | Float4 v_ = v + dv; |
| 4525 | |
| 4526 | sampleTexture(r, dst, stage, u_, v_, s, s); |
| 4527 | } |
| 4528 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4529 | void PixelRoutine::TEXBEML(Registers &r, Vector4i &dst, Vector4i &src, Float4 &u, Float4 &v, Float4 &s, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4530 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4531 | Float4 du = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4532 | Float4 dv = Float4(src.y) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4533 | |
| 4534 | Float4 du2 = du; |
| 4535 | Float4 dv2 = dv; |
| 4536 | |
| 4537 | du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 4538 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 4539 | du += dv2; |
| 4540 | dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 4541 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 4542 | dv += du2; |
| 4543 | |
| 4544 | Float4 u_ = u + du; |
| 4545 | Float4 v_ = v + dv; |
| 4546 | |
| 4547 | sampleTexture(r, dst, stage, u_, v_, s, s); |
| 4548 | |
| 4549 | Short4 L; |
| 4550 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4551 | L = src.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4552 | L = MulHigh(L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceScale4))); |
| 4553 | L = L << 4; |
| 4554 | L = AddSat(L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceOffset4))); |
| 4555 | L = Max(L, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4556 | L = Min(L, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4557 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4558 | dst.x = MulHigh(dst.x, L); dst.x = dst.x << 4; |
| 4559 | dst.y = MulHigh(dst.y, L); dst.y = dst.y << 4; |
| 4560 | dst.z = MulHigh(dst.z, L); dst.z = dst.z << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4561 | } |
| 4562 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4563 | void PixelRoutine::TEXREG2AR(Registers &r, Vector4i &dst, Vector4i &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4564 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4565 | Float4 u = Float4(src0.w) * Float4(1.0f / 0x0FFE); |
| 4566 | Float4 v = Float4(src0.x) * Float4(1.0f / 0x0FFE); |
| 4567 | Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4568 | |
| 4569 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4570 | } |
| 4571 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4572 | void PixelRoutine::TEXREG2GB(Registers &r, Vector4i &dst, Vector4i &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4573 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4574 | Float4 u = Float4(src0.y) * Float4(1.0f / 0x0FFE); |
| 4575 | Float4 v = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4576 | Float4 s = v; |
| 4577 | |
| 4578 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4579 | } |
| 4580 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4581 | void PixelRoutine::TEXREG2RGB(Registers &r, Vector4i &dst, Vector4i &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4582 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4583 | Float4 u = Float4(src0.x) * Float4(1.0f / 0x0FFE); |
| 4584 | Float4 v = Float4(src0.y) * Float4(1.0f / 0x0FFE); |
| 4585 | Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4586 | |
| 4587 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4588 | } |
| 4589 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4590 | void PixelRoutine::TEXM3X2DEPTH(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, Vector4i &src, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4591 | { |
| 4592 | TEXM3X2PAD(r, u, v, s, src, 1, signedScaling); |
| 4593 | |
| 4594 | // z / w |
| 4595 | r.u_ *= Rcp_pp(r.v_); // FIXME: Set result to 1.0 when division by zero |
| 4596 | |
| 4597 | r.oDepth = r.u_; |
| 4598 | } |
| 4599 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4600 | void PixelRoutine::TEXM3X2PAD(Registers &r, Float4 &u, Float4 &v, Float4 &s, Vector4i &src0, int component, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4601 | { |
| 4602 | TEXM3X3PAD(r, u, v, s, src0, component, signedScaling); |
| 4603 | } |
| 4604 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4605 | void PixelRoutine::TEXM3X2TEX(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4i &src0, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4606 | { |
| 4607 | TEXM3X2PAD(r, u, v, s, src0, 1, signedScaling); |
| 4608 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4609 | r.w_ = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4610 | |
| 4611 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4612 | } |
| 4613 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4614 | void PixelRoutine::TEXM3X3(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, Vector4i &src0, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4615 | { |
| 4616 | TEXM3X3PAD(r, u, v, s, src0, 2, signedScaling); |
| 4617 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4618 | dst.x = RoundShort4(r.u_ * Float4(0x1000)); |
| 4619 | dst.y = RoundShort4(r.v_ * Float4(0x1000)); |
| 4620 | dst.z = RoundShort4(r.w_ * Float4(0x1000)); |
| 4621 | dst.w = Short4(0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4622 | } |
| 4623 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4624 | void PixelRoutine::TEXM3X3PAD(Registers &r, Float4 &u, Float4 &v, Float4 &s, Vector4i &src0, int component, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4625 | { |
| 4626 | if(component == 0 || previousScaling != signedScaling) // FIXME: Other source modifiers? |
| 4627 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4628 | r.U = Float4(src0.x); |
| 4629 | r.V = Float4(src0.y); |
| 4630 | r.W = Float4(src0.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4631 | |
| 4632 | previousScaling = signedScaling; |
| 4633 | } |
| 4634 | |
| 4635 | Float4 x = r.U * u + r.V * v + r.W * s; |
| 4636 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4637 | x *= Float4(1.0f / 0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4638 | |
| 4639 | switch(component) |
| 4640 | { |
| 4641 | case 0: r.u_ = x; break; |
| 4642 | case 1: r.v_ = x; break; |
| 4643 | case 2: r.w_ = x; break; |
| 4644 | default: ASSERT(false); |
| 4645 | } |
| 4646 | } |
| 4647 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4648 | void PixelRoutine::TEXM3X3SPEC(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4649 | { |
| 4650 | TEXM3X3PAD(r, u, v, s, src0, 2, false); |
| 4651 | |
| 4652 | Float4 E[3]; // Eye vector |
| 4653 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4654 | E[0] = Float4(src1.x) * Float4(1.0f / 0x0FFE); |
| 4655 | E[1] = Float4(src1.y) * Float4(1.0f / 0x0FFE); |
| 4656 | E[2] = Float4(src1.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4657 | |
| 4658 | // Reflection |
| 4659 | Float4 u__; |
| 4660 | Float4 v__; |
| 4661 | Float4 w__; |
| 4662 | |
| 4663 | // (u'', v'', w'') = 2 * (N . E) * N - E * (N . N) |
| 4664 | u__ = r.u_ * E[0]; |
| 4665 | v__ = r.v_ * E[1]; |
| 4666 | w__ = r.w_ * E[2]; |
| 4667 | u__ += v__ + w__; |
| 4668 | u__ += u__; |
| 4669 | v__ = u__; |
| 4670 | w__ = u__; |
| 4671 | u__ *= r.u_; |
| 4672 | v__ *= r.v_; |
| 4673 | w__ *= r.w_; |
| 4674 | r.u_ *= r.u_; |
| 4675 | r.v_ *= r.v_; |
| 4676 | r.w_ *= r.w_; |
| 4677 | r.u_ += r.v_ + r.w_; |
| 4678 | u__ -= E[0] * r.u_; |
| 4679 | v__ -= E[1] * r.u_; |
| 4680 | w__ -= E[2] * r.u_; |
| 4681 | |
| 4682 | sampleTexture(r, dst, stage, u__, v__, w__, w__); |
| 4683 | } |
| 4684 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4685 | void PixelRoutine::TEXM3X3TEX(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4i &src0, bool signedScaling) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4686 | { |
| 4687 | TEXM3X3PAD(r, u, v, s, src0, 2, signedScaling); |
| 4688 | |
| 4689 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4690 | } |
| 4691 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4692 | void PixelRoutine::TEXM3X3VSPEC(Registers &r, Vector4i &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4i &src0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4693 | { |
| 4694 | TEXM3X3PAD(r, u, v, s, src0, 2, false); |
| 4695 | |
| 4696 | Float4 E[3]; // Eye vector |
| 4697 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4698 | E[0] = r.vf[2 + stage - 2].w; |
| 4699 | E[1] = r.vf[2 + stage - 1].w; |
| 4700 | E[2] = r.vf[2 + stage - 0].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4701 | |
| 4702 | // Reflection |
| 4703 | Float4 u__; |
| 4704 | Float4 v__; |
| 4705 | Float4 w__; |
| 4706 | |
| 4707 | // (u'', v'', w'') = 2 * (N . E) * N - E * (N . N) |
| 4708 | u__ = r.u_ * E[0]; |
| 4709 | v__ = r.v_ * E[1]; |
| 4710 | w__ = r.w_ * E[2]; |
| 4711 | u__ += v__ + w__; |
| 4712 | u__ += u__; |
| 4713 | v__ = u__; |
| 4714 | w__ = u__; |
| 4715 | u__ *= r.u_; |
| 4716 | v__ *= r.v_; |
| 4717 | w__ *= r.w_; |
| 4718 | r.u_ *= r.u_; |
| 4719 | r.v_ *= r.v_; |
| 4720 | r.w_ *= r.w_; |
| 4721 | r.u_ += r.v_ + r.w_; |
| 4722 | u__ -= E[0] * r.u_; |
| 4723 | v__ -= E[1] * r.u_; |
| 4724 | w__ -= E[2] * r.u_; |
| 4725 | |
| 4726 | sampleTexture(r, dst, stage, u__, v__, w__, w__); |
| 4727 | } |
| 4728 | |
| 4729 | void PixelRoutine::TEXDEPTH(Registers &r) |
| 4730 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4731 | r.u_ = Float4(r.ri[5].x); |
| 4732 | r.v_ = Float4(r.ri[5].y); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4733 | |
| 4734 | // z / w |
| 4735 | r.u_ *= Rcp_pp(r.v_); // FIXME: Set result to 1.0 when division by zero |
| 4736 | |
| 4737 | r.oDepth = r.u_; |
| 4738 | } |
| 4739 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4740 | void PixelRoutine::CND(Vector4i &dst, Vector4i &src0, Vector4i &src1, Vector4i &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4741 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4742 | {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;}; |
| 4743 | {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;}; |
| 4744 | {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;}; |
| 4745 | {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] | 4746 | } |
| 4747 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4748 | void PixelRoutine::CMP(Vector4i &dst, Vector4i &src0, Vector4i &src1, Vector4i &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4749 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4750 | {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;}; |
| 4751 | {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;}; |
| 4752 | {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;}; |
| 4753 | {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] | 4754 | } |
| 4755 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4756 | void PixelRoutine::BEM(Registers &r, Vector4i &dst, Vector4i &src0, Vector4i &src1, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4757 | { |
| 4758 | Short4 t0; |
| 4759 | Short4 t1; |
| 4760 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4761 | // dst.x = src0.x + BUMPENVMAT00(stage) * src1.x + BUMPENVMAT10(stage) * src1.y |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4762 | t0 = MulHigh(src1.x, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[0][0]))); t0 = t0 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4763 | t1 = MulHigh(src1.y, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[1][0]))); t1 = t1 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4764 | t0 = AddSat(t0, t1); |
| 4765 | t0 = AddSat(t0, src0.x); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4766 | dst.x = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4767 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4768 | // dst.y = src0.y + BUMPENVMAT01(stage) * src1.x + BUMPENVMAT11(stage) * src1.y |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4769 | t0 = MulHigh(src1.x, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[0][1]))); t0 = t0 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4770 | t1 = MulHigh(src1.y, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[1][1]))); t1 = t1 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4771 | t0 = AddSat(t0, t1); |
| 4772 | t0 = AddSat(t0, src0.y); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4773 | dst.y = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4774 | } |
| 4775 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4776 | void PixelRoutine::M3X2(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4777 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4778 | Vector4f row0 = reg(r, src1, 0); |
| 4779 | Vector4f row1 = reg(r, src1, 1); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4780 | |
| 4781 | dst.x = dot3(src0, row0); |
| 4782 | dst.y = dot3(src0, row1); |
| 4783 | } |
| 4784 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4785 | void PixelRoutine::M3X3(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4786 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4787 | Vector4f row0 = reg(r, src1, 0); |
| 4788 | Vector4f row1 = reg(r, src1, 1); |
| 4789 | Vector4f row2 = reg(r, src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4790 | |
| 4791 | dst.x = dot3(src0, row0); |
| 4792 | dst.y = dot3(src0, row1); |
| 4793 | dst.z = dot3(src0, row2); |
| 4794 | } |
| 4795 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4796 | void PixelRoutine::M3X4(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4797 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4798 | Vector4f row0 = reg(r, src1, 0); |
| 4799 | Vector4f row1 = reg(r, src1, 1); |
| 4800 | Vector4f row2 = reg(r, src1, 2); |
| 4801 | Vector4f row3 = reg(r, src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4802 | |
| 4803 | dst.x = dot3(src0, row0); |
| 4804 | dst.y = dot3(src0, row1); |
| 4805 | dst.z = dot3(src0, row2); |
| 4806 | dst.w = dot3(src0, row3); |
| 4807 | } |
| 4808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4809 | void PixelRoutine::M4X3(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4810 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4811 | Vector4f row0 = reg(r, src1, 0); |
| 4812 | Vector4f row1 = reg(r, src1, 1); |
| 4813 | Vector4f row2 = reg(r, src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4814 | |
| 4815 | dst.x = dot4(src0, row0); |
| 4816 | dst.y = dot4(src0, row1); |
| 4817 | dst.z = dot4(src0, row2); |
| 4818 | } |
| 4819 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4820 | void PixelRoutine::M4X4(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4821 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4822 | Vector4f row0 = reg(r, src1, 0); |
| 4823 | Vector4f row1 = reg(r, src1, 1); |
| 4824 | Vector4f row2 = reg(r, src1, 2); |
| 4825 | Vector4f row3 = reg(r, src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4826 | |
| 4827 | dst.x = dot4(src0, row0); |
| 4828 | dst.y = dot4(src0, row1); |
| 4829 | dst.z = dot4(src0, row2); |
| 4830 | dst.w = dot4(src0, row3); |
| 4831 | } |
| 4832 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4833 | 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] | 4834 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4835 | Vector4f tmp; |
| 4836 | 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] | 4837 | |
| 4838 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 4839 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 4840 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 4841 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 4842 | } |
| 4843 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4844 | 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] | 4845 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4846 | Vector4f tmp; |
| 4847 | 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] | 4848 | |
| 4849 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 4850 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 4851 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 4852 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 4853 | } |
| 4854 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4855 | 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] | 4856 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4857 | Vector4f tmp; |
| 4858 | 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] | 4859 | |
| 4860 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 4861 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 4862 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 4863 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 4864 | } |
| 4865 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4866 | void PixelRoutine::TEXKILL(Int cMask[4], Vector4f &src, unsigned char mask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4867 | { |
| 4868 | Int kill = -1; |
| 4869 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4870 | if(mask & 0x1) kill &= SignMask(CmpNLT(src.x, Float4(0.0f))); |
| 4871 | if(mask & 0x2) kill &= SignMask(CmpNLT(src.y, Float4(0.0f))); |
| 4872 | if(mask & 0x4) kill &= SignMask(CmpNLT(src.z, Float4(0.0f))); |
| 4873 | if(mask & 0x8) kill &= SignMask(CmpNLT(src.w, Float4(0.0f))); |
| 4874 | |
| 4875 | // FIXME: Dynamic branching affects TEXKILL? |
| 4876 | // if(shader->containsDynamicBranching()) |
| 4877 | // { |
| 4878 | // kill = ~SignMask(enableMask(r)); |
| 4879 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4880 | |
| 4881 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 4882 | { |
| 4883 | cMask[q] &= kill; |
| 4884 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4885 | |
| 4886 | // FIXME: Branch to end of shader if all killed? |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4887 | } |
| 4888 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4889 | void PixelRoutine::DISCARD(Registers &r, Int cMask[4], const Shader::Instruction *instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4890 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4891 | Int kill = 0; |
| 4892 | |
| 4893 | if(shader->containsDynamicBranching()) |
| 4894 | { |
| 4895 | kill = ~SignMask(enableMask(r, instruction)); |
| 4896 | } |
| 4897 | |
| 4898 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 4899 | { |
| 4900 | cMask[q] &= kill; |
| 4901 | } |
| 4902 | |
| 4903 | // FIXME: Branch to end of shader if all killed? |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4904 | } |
| 4905 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4906 | void PixelRoutine::DFDX(Vector4f &dst, Vector4f &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4907 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4908 | dst.x = src.x.yyww - src.x.xxzz; |
| 4909 | dst.y = src.y.yyww - src.y.xxzz; |
| 4910 | dst.z = src.z.yyww - src.z.xxzz; |
| 4911 | dst.w = src.w.yyww - src.w.xxzz; |
| 4912 | } |
| 4913 | |
| 4914 | void PixelRoutine::DFDY(Vector4f &dst, Vector4f &src) |
| 4915 | { |
| 4916 | dst.x = src.x.zwzw - src.x.xyxy; |
| 4917 | dst.y = src.y.zwzw - src.y.xyxy; |
| 4918 | dst.z = src.z.zwzw - src.z.xyxy; |
| 4919 | dst.w = src.w.zwzw - src.w.xyxy; |
| 4920 | } |
| 4921 | |
| 4922 | void PixelRoutine::FWIDTH(Vector4f &dst, Vector4f &src) |
| 4923 | { |
| 4924 | // abs(dFdx(src)) + abs(dFdy(src)); |
| 4925 | dst.x = Abs(src.x.yyww - src.x.xxzz) + Abs(src.x.zwzw - src.x.xyxy); |
| 4926 | dst.y = Abs(src.y.yyww - src.x.xxzz) + Abs(src.y.zwzw - src.y.xyxy); |
| 4927 | dst.z = Abs(src.z.yyww - src.x.xxzz) + Abs(src.z.zwzw - src.z.xyxy); |
| 4928 | 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] | 4929 | } |
| 4930 | |
| 4931 | void PixelRoutine::BREAK(Registers &r) |
| 4932 | { |
| 4933 | llvm::BasicBlock *deadBlock = Nucleus::createBasicBlock(); |
| 4934 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1]; |
| 4935 | |
| 4936 | if(breakDepth == 0) |
| 4937 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4938 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4939 | Nucleus::createBr(endBlock); |
| 4940 | } |
| 4941 | else |
| 4942 | { |
| 4943 | r.enableBreak = r.enableBreak & ~r.enableStack[r.enableIndex]; |
| 4944 | Bool allBreak = SignMask(r.enableBreak) == 0x0; |
| 4945 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4946 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4947 | branch(allBreak, endBlock, deadBlock); |
| 4948 | } |
| 4949 | |
| 4950 | Nucleus::setInsertBlock(deadBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4951 | r.enableIndex = r.enableIndex + breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4952 | } |
| 4953 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4954 | void PixelRoutine::BREAKC(Registers &r, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4955 | { |
| 4956 | Int4 condition; |
| 4957 | |
| 4958 | switch(control) |
| 4959 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4960 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 4961 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 4962 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 4963 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 4964 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 4965 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4966 | default: |
| 4967 | ASSERT(false); |
| 4968 | } |
| 4969 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4970 | BREAK(r, condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | void PixelRoutine::BREAKP(Registers &r, const Src &predicateRegister) // FIXME: Factor out parts common with BREAKC |
| 4974 | { |
| 4975 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 4976 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4977 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4978 | { |
| 4979 | condition = ~condition; |
| 4980 | } |
| 4981 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4982 | BREAK(r, condition); |
| 4983 | } |
| 4984 | |
| 4985 | void PixelRoutine::BREAK(Registers &r, Int4 &condition) |
| 4986 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4987 | condition &= r.enableStack[r.enableIndex]; |
| 4988 | |
| 4989 | llvm::BasicBlock *continueBlock = Nucleus::createBasicBlock(); |
| 4990 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1]; |
| 4991 | |
| 4992 | r.enableBreak = r.enableBreak & ~condition; |
| 4993 | Bool allBreak = SignMask(r.enableBreak) == 0x0; |
| 4994 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4995 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4996 | branch(allBreak, endBlock, continueBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4997 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4998 | Nucleus::setInsertBlock(continueBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4999 | r.enableIndex = r.enableIndex + breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5000 | } |
| 5001 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5002 | void PixelRoutine::CONTINUE(Registers &r) |
| 5003 | { |
| 5004 | r.enableContinue = r.enableContinue & ~r.enableStack[r.enableIndex]; |
| 5005 | } |
| 5006 | |
| 5007 | void PixelRoutine::TEST() |
| 5008 | { |
| 5009 | whileTest = true; |
| 5010 | } |
| 5011 | |
| 5012 | void PixelRoutine::CALL(Registers &r, int labelIndex, int callSiteIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5013 | { |
| 5014 | if(!labelBlock[labelIndex]) |
| 5015 | { |
| 5016 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5017 | } |
| 5018 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5019 | if(callRetBlock[labelIndex].size() > 1) |
| 5020 | { |
| 5021 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5022 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5023 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5024 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5025 | |
| 5026 | Nucleus::createBr(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5027 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 5028 | |
| 5029 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5030 | } |
| 5031 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5032 | void PixelRoutine::CALLNZ(Registers &r, int labelIndex, int callSiteIndex, const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5033 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5034 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5035 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5036 | CALLNZb(r, labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5037 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5038 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5039 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5040 | CALLNZp(r, labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5041 | } |
| 5042 | else ASSERT(false); |
| 5043 | } |
| 5044 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5045 | void PixelRoutine::CALLNZb(Registers &r, int labelIndex, int callSiteIndex, const Src &boolRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5046 | { |
| 5047 | Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,ps.b[boolRegister.index])) != Byte(0)); // FIXME |
| 5048 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5049 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5050 | { |
| 5051 | condition = !condition; |
| 5052 | } |
| 5053 | |
| 5054 | if(!labelBlock[labelIndex]) |
| 5055 | { |
| 5056 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5057 | } |
| 5058 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5059 | if(callRetBlock[labelIndex].size() > 1) |
| 5060 | { |
| 5061 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5062 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5063 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5064 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5065 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5066 | branch(condition, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 5067 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 5068 | |
| 5069 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5070 | } |
| 5071 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5072 | void PixelRoutine::CALLNZp(Registers &r, int labelIndex, int callSiteIndex, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5073 | { |
| 5074 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 5075 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5076 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5077 | { |
| 5078 | condition = ~condition; |
| 5079 | } |
| 5080 | |
| 5081 | condition &= r.enableStack[r.enableIndex]; |
| 5082 | |
| 5083 | if(!labelBlock[labelIndex]) |
| 5084 | { |
| 5085 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5086 | } |
| 5087 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5088 | if(callRetBlock[labelIndex].size() > 1) |
| 5089 | { |
| 5090 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5091 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5092 | |
| 5093 | r.enableIndex++; |
| 5094 | r.enableStack[r.enableIndex] = condition; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5095 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5096 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5097 | Bool notAllFalse = SignMask(condition) != 0; |
| 5098 | branch(notAllFalse, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 5099 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5100 | |
| 5101 | r.enableIndex--; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5102 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | void PixelRoutine::ELSE(Registers &r) |
| 5106 | { |
| 5107 | ifDepth--; |
| 5108 | |
| 5109 | llvm::BasicBlock *falseBlock = ifFalseBlock[ifDepth]; |
| 5110 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5111 | |
| 5112 | if(isConditionalIf[ifDepth]) |
| 5113 | { |
| 5114 | Int4 condition = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5115 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5116 | |
| 5117 | branch(notAllFalse, falseBlock, endBlock); |
| 5118 | |
| 5119 | r.enableStack[r.enableIndex] = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1]; |
| 5120 | } |
| 5121 | else |
| 5122 | { |
| 5123 | Nucleus::createBr(endBlock); |
| 5124 | Nucleus::setInsertBlock(falseBlock); |
| 5125 | } |
| 5126 | |
| 5127 | ifFalseBlock[ifDepth] = endBlock; |
| 5128 | |
| 5129 | ifDepth++; |
| 5130 | } |
| 5131 | |
| 5132 | void PixelRoutine::ENDIF(Registers &r) |
| 5133 | { |
| 5134 | ifDepth--; |
| 5135 | |
| 5136 | llvm::BasicBlock *endBlock = ifFalseBlock[ifDepth]; |
| 5137 | |
| 5138 | Nucleus::createBr(endBlock); |
| 5139 | Nucleus::setInsertBlock(endBlock); |
| 5140 | |
| 5141 | if(isConditionalIf[ifDepth]) |
| 5142 | { |
| 5143 | breakDepth--; |
| 5144 | r.enableIndex--; |
| 5145 | } |
| 5146 | } |
| 5147 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5148 | void PixelRoutine::ENDLOOP(Registers &r) |
| 5149 | { |
| 5150 | loopRepDepth--; |
| 5151 | |
| 5152 | r.aL[r.loopDepth] = r.aL[r.loopDepth] + r.increment[r.loopDepth]; // FIXME: += |
| 5153 | |
| 5154 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5155 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5156 | |
| 5157 | Nucleus::createBr(testBlock); |
| 5158 | Nucleus::setInsertBlock(endBlock); |
| 5159 | |
| 5160 | r.loopDepth--; |
| 5161 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5162 | } |
| 5163 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5164 | void PixelRoutine::ENDREP(Registers &r) |
| 5165 | { |
| 5166 | loopRepDepth--; |
| 5167 | |
| 5168 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5169 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5170 | |
| 5171 | Nucleus::createBr(testBlock); |
| 5172 | Nucleus::setInsertBlock(endBlock); |
| 5173 | |
| 5174 | r.loopDepth--; |
| 5175 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5176 | } |
| 5177 | |
| 5178 | void PixelRoutine::ENDWHILE(Registers &r) |
| 5179 | { |
| 5180 | loopRepDepth--; |
| 5181 | |
| 5182 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5183 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5184 | |
| 5185 | Nucleus::createBr(testBlock); |
| 5186 | Nucleus::setInsertBlock(endBlock); |
| 5187 | |
| 5188 | r.enableIndex--; |
| 5189 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5190 | whileTest = false; |
| 5191 | } |
| 5192 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5193 | void PixelRoutine::IF(Registers &r, const Src &src) |
| 5194 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5195 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5196 | { |
| 5197 | IFb(r, src); |
| 5198 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5199 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5200 | { |
| 5201 | IFp(r, src); |
| 5202 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5203 | else |
| 5204 | { |
| 5205 | Int4 condition = As<Int4>(reg(r, src).x); |
| 5206 | IF(r, condition); |
| 5207 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | void PixelRoutine::IFb(Registers &r, const Src &boolRegister) |
| 5211 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5212 | ASSERT(ifDepth < 24 + 4); |
| 5213 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5214 | Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,ps.b[boolRegister.index])) != Byte(0)); // FIXME |
| 5215 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5216 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5217 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5218 | condition = !condition; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 5222 | llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
| 5223 | |
| 5224 | branch(condition, trueBlock, falseBlock); |
| 5225 | |
| 5226 | isConditionalIf[ifDepth] = false; |
| 5227 | ifFalseBlock[ifDepth] = falseBlock; |
| 5228 | |
| 5229 | ifDepth++; |
| 5230 | } |
| 5231 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5232 | void PixelRoutine::IFp(Registers &r, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5233 | { |
| 5234 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 5235 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5236 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5237 | { |
| 5238 | condition = ~condition; |
| 5239 | } |
| 5240 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5241 | IF(r, condition); |
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::IFC(Registers &r, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5245 | { |
| 5246 | Int4 condition; |
| 5247 | |
| 5248 | switch(control) |
| 5249 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5250 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 5251 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 5252 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 5253 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 5254 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 5255 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5256 | default: |
| 5257 | ASSERT(false); |
| 5258 | } |
| 5259 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5260 | IF(r, condition); |
| 5261 | } |
| 5262 | |
| 5263 | void PixelRoutine::IF(Registers &r, Int4 &condition) |
| 5264 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5265 | condition &= r.enableStack[r.enableIndex]; |
| 5266 | |
| 5267 | r.enableIndex++; |
| 5268 | r.enableStack[r.enableIndex] = condition; |
| 5269 | |
| 5270 | llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 5271 | llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
| 5272 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5273 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5274 | |
| 5275 | branch(notAllFalse, trueBlock, falseBlock); |
| 5276 | |
| 5277 | isConditionalIf[ifDepth] = true; |
| 5278 | ifFalseBlock[ifDepth] = falseBlock; |
| 5279 | |
| 5280 | ifDepth++; |
| 5281 | breakDepth++; |
| 5282 | } |
| 5283 | |
| 5284 | void PixelRoutine::LABEL(int labelIndex) |
| 5285 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5286 | if(!labelBlock[labelIndex]) |
| 5287 | { |
| 5288 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5289 | } |
| 5290 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5291 | Nucleus::setInsertBlock(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5292 | currentLabel = labelIndex; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | void PixelRoutine::LOOP(Registers &r, const Src &integerRegister) |
| 5296 | { |
| 5297 | r.loopDepth++; |
| 5298 | |
| 5299 | r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][0])); |
| 5300 | r.aL[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][1])); |
| 5301 | r.increment[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][2])); |
| 5302 | |
| 5303 | // If(r.increment[r.loopDepth] == 0) |
| 5304 | // { |
| 5305 | // r.increment[r.loopDepth] = 1; |
| 5306 | // } |
| 5307 | |
| 5308 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5309 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5310 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5311 | |
| 5312 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5313 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5314 | |
| 5315 | // FIXME: jump(testBlock) |
| 5316 | Nucleus::createBr(testBlock); |
| 5317 | Nucleus::setInsertBlock(testBlock); |
| 5318 | |
| 5319 | branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock); |
| 5320 | Nucleus::setInsertBlock(loopBlock); |
| 5321 | |
| 5322 | r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1; // FIXME: -- |
| 5323 | |
| 5324 | loopRepDepth++; |
| 5325 | breakDepth = 0; |
| 5326 | } |
| 5327 | |
| 5328 | void PixelRoutine::REP(Registers &r, const Src &integerRegister) |
| 5329 | { |
| 5330 | r.loopDepth++; |
| 5331 | |
| 5332 | r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][0])); |
| 5333 | r.aL[r.loopDepth] = r.aL[r.loopDepth - 1]; |
| 5334 | |
| 5335 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5336 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5337 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5338 | |
| 5339 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5340 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5341 | |
| 5342 | // FIXME: jump(testBlock) |
| 5343 | Nucleus::createBr(testBlock); |
| 5344 | Nucleus::setInsertBlock(testBlock); |
| 5345 | |
| 5346 | branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock); |
| 5347 | Nucleus::setInsertBlock(loopBlock); |
| 5348 | |
| 5349 | r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1; // FIXME: -- |
| 5350 | |
| 5351 | loopRepDepth++; |
| 5352 | breakDepth = 0; |
| 5353 | } |
| 5354 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5355 | void PixelRoutine::WHILE(Registers &r, const Src &temporaryRegister) |
| 5356 | { |
| 5357 | r.enableIndex++; |
| 5358 | |
| 5359 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5360 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5361 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5362 | |
| 5363 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5364 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5365 | |
| 5366 | Int4 restoreBreak = r.enableBreak; |
| 5367 | Int4 restoreContinue = r.enableContinue; |
| 5368 | |
| 5369 | // FIXME: jump(testBlock) |
| 5370 | Nucleus::createBr(testBlock); |
| 5371 | Nucleus::setInsertBlock(testBlock); |
| 5372 | r.enableContinue = restoreContinue; |
| 5373 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5374 | const Vector4f &src = reg(r, temporaryRegister); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5375 | Int4 condition = As<Int4>(src.x); |
| 5376 | condition &= r.enableStack[r.enableIndex - 1]; |
| 5377 | r.enableStack[r.enableIndex] = condition; |
| 5378 | |
| 5379 | Bool notAllFalse = SignMask(condition) != 0; |
| 5380 | branch(notAllFalse, loopBlock, endBlock); |
| 5381 | |
| 5382 | Nucleus::setInsertBlock(endBlock); |
| 5383 | r.enableBreak = restoreBreak; |
| 5384 | |
| 5385 | Nucleus::setInsertBlock(loopBlock); |
| 5386 | |
| 5387 | loopRepDepth++; |
| 5388 | breakDepth = 0; |
| 5389 | } |
| 5390 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5391 | void PixelRoutine::RET(Registers &r) |
| 5392 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5393 | if(currentLabel == -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5394 | { |
| 5395 | returnBlock = Nucleus::createBasicBlock(); |
| 5396 | Nucleus::createBr(returnBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5397 | } |
| 5398 | else |
| 5399 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5400 | llvm::BasicBlock *unreachableBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5401 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5402 | 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] | 5403 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5404 | // FIXME: Encapsulate |
| 5405 | UInt index = r.callStack[--r.stackIndex]; |
| 5406 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5407 | llvm::Value *value = index.loadValue(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5408 | llvm::Value *switchInst = Nucleus::createSwitch(value, unreachableBlock, (int)callRetBlock[currentLabel].size()); |
| 5409 | |
| 5410 | for(unsigned int i = 0; i < callRetBlock[currentLabel].size(); i++) |
| 5411 | { |
| 5412 | Nucleus::addSwitchCase(switchInst, i, callRetBlock[currentLabel][i]); |
| 5413 | } |
| 5414 | } |
| 5415 | else if(callRetBlock[currentLabel].size() == 1) // Jump directly to the unique return destination |
| 5416 | { |
| 5417 | Nucleus::createBr(callRetBlock[currentLabel][0]); |
| 5418 | } |
| 5419 | else // Function isn't called |
| 5420 | { |
| 5421 | Nucleus::createBr(unreachableBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | Nucleus::setInsertBlock(unreachableBlock); |
| 5425 | Nucleus::createUnreachable(); |
| 5426 | } |
| 5427 | } |
| 5428 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5429 | void PixelRoutine::LEAVE(Registers &r) |
| 5430 | { |
| 5431 | r.enableLeave = r.enableLeave & ~r.enableStack[r.enableIndex]; |
| 5432 | |
| 5433 | // FIXME: Return from function if all instances left |
| 5434 | // FIXME: Use enableLeave in other control-flow constructs |
| 5435 | } |
| 5436 | |
| 5437 | void PixelRoutine::writeDestination(Registers &r, Vector4i &d, const Dst &dst) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5438 | { |
| 5439 | switch(dst.type) |
| 5440 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5441 | case Shader::PARAMETER_TEMP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5442 | if(dst.mask & 0x1) r.ri[dst.index].x = d.x; |
| 5443 | if(dst.mask & 0x2) r.ri[dst.index].y = d.y; |
| 5444 | if(dst.mask & 0x4) r.ri[dst.index].z = d.z; |
| 5445 | if(dst.mask & 0x8) r.ri[dst.index].w = d.w; |
| 5446 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5447 | case Shader::PARAMETER_INPUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5448 | if(dst.mask & 0x1) r.vi[dst.index].x = d.x; |
| 5449 | if(dst.mask & 0x2) r.vi[dst.index].y = d.y; |
| 5450 | if(dst.mask & 0x4) r.vi[dst.index].z = d.z; |
| 5451 | if(dst.mask & 0x8) r.vi[dst.index].w = d.w; |
| 5452 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5453 | case Shader::PARAMETER_CONST: ASSERT(false); break; |
| 5454 | case Shader::PARAMETER_TEXTURE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5455 | if(dst.mask & 0x1) r.ti[dst.index].x = d.x; |
| 5456 | if(dst.mask & 0x2) r.ti[dst.index].y = d.y; |
| 5457 | if(dst.mask & 0x4) r.ti[dst.index].z = d.z; |
| 5458 | if(dst.mask & 0x8) r.ti[dst.index].w = d.w; |
| 5459 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5460 | case Shader::PARAMETER_COLOROUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5461 | if(dst.mask & 0x1) r.vi[dst.index].x = d.x; |
| 5462 | if(dst.mask & 0x2) r.vi[dst.index].y = d.y; |
| 5463 | if(dst.mask & 0x4) r.vi[dst.index].z = d.z; |
| 5464 | if(dst.mask & 0x8) r.vi[dst.index].w = d.w; |
| 5465 | break; |
| 5466 | default: |
| 5467 | ASSERT(false); |
| 5468 | } |
| 5469 | } |
| 5470 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5471 | Vector4i PixelRoutine::regi(Registers &r, const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5472 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5473 | Vector4i *reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5474 | int i = src.index; |
| 5475 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5476 | Vector4i c; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5477 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5478 | if(src.type == Shader::PARAMETER_CONST) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5479 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5480 | c.x = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][0])); |
| 5481 | c.y = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][1])); |
| 5482 | c.z = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][2])); |
| 5483 | c.w = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | switch(src.type) |
| 5487 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5488 | case Shader::PARAMETER_TEMP: reg = &r.ri[i]; break; |
| 5489 | case Shader::PARAMETER_INPUT: reg = &r.vi[i]; break; |
| 5490 | case Shader::PARAMETER_CONST: reg = &c; break; |
| 5491 | case Shader::PARAMETER_TEXTURE: reg = &r.ti[i]; break; |
| 5492 | case Shader::PARAMETER_VOID: return r.ri[0]; // Dummy |
| 5493 | case Shader::PARAMETER_FLOAT4LITERAL: return r.ri[0]; // Dummy |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5494 | default: |
| 5495 | ASSERT(false); |
| 5496 | } |
| 5497 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5498 | const Short4 &x = (*reg)[(src.swizzle >> 0) & 0x3]; |
| 5499 | const Short4 &y = (*reg)[(src.swizzle >> 2) & 0x3]; |
| 5500 | const Short4 &z = (*reg)[(src.swizzle >> 4) & 0x3]; |
| 5501 | const Short4 &w = (*reg)[(src.swizzle >> 6) & 0x3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5502 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5503 | Vector4i mod; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5504 | |
| 5505 | switch(src.modifier) |
| 5506 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5507 | case Shader::MODIFIER_NONE: |
| 5508 | mod.x = x; |
| 5509 | mod.y = y; |
| 5510 | mod.z = z; |
| 5511 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5512 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5513 | case Shader::MODIFIER_BIAS: |
| 5514 | mod.x = SubSat(x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5515 | mod.y = SubSat(y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5516 | mod.z = SubSat(z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5517 | mod.w = SubSat(w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5518 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5519 | case Shader::MODIFIER_BIAS_NEGATE: |
| 5520 | mod.x = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), x); |
| 5521 | mod.y = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), y); |
| 5522 | mod.z = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), z); |
| 5523 | mod.w = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5524 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5525 | case Shader::MODIFIER_COMPLEMENT: |
| 5526 | mod.x = SubSat(Short4(0x1000), x); |
| 5527 | mod.y = SubSat(Short4(0x1000), y); |
| 5528 | mod.z = SubSat(Short4(0x1000), z); |
| 5529 | mod.w = SubSat(Short4(0x1000), w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5530 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5531 | case Shader::MODIFIER_NEGATE: |
| 5532 | mod.x = -x; |
| 5533 | mod.y = -y; |
| 5534 | mod.z = -z; |
| 5535 | mod.w = -w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5536 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5537 | case Shader::MODIFIER_X2: |
| 5538 | mod.x = AddSat(x, x); |
| 5539 | mod.y = AddSat(y, y); |
| 5540 | mod.z = AddSat(z, z); |
| 5541 | mod.w = AddSat(w, w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5542 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5543 | case Shader::MODIFIER_X2_NEGATE: |
| 5544 | mod.x = -AddSat(x, x); |
| 5545 | mod.y = -AddSat(y, y); |
| 5546 | mod.z = -AddSat(z, z); |
| 5547 | mod.w = -AddSat(w, w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5548 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5549 | case Shader::MODIFIER_SIGN: |
| 5550 | mod.x = SubSat(x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5551 | mod.y = SubSat(y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5552 | mod.z = SubSat(z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5553 | mod.w = SubSat(w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5554 | mod.x = AddSat(mod.x, mod.x); |
| 5555 | mod.y = AddSat(mod.y, mod.y); |
| 5556 | mod.z = AddSat(mod.z, mod.z); |
| 5557 | mod.w = AddSat(mod.w, mod.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5558 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5559 | case Shader::MODIFIER_SIGN_NEGATE: |
| 5560 | mod.x = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), x); |
| 5561 | mod.y = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), y); |
| 5562 | mod.z = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), z); |
| 5563 | mod.w = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), w); |
| 5564 | mod.x = AddSat(mod.x, mod.x); |
| 5565 | mod.y = AddSat(mod.y, mod.y); |
| 5566 | mod.z = AddSat(mod.z, mod.z); |
| 5567 | mod.w = AddSat(mod.w, mod.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5568 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5569 | case Shader::MODIFIER_DZ: |
| 5570 | mod.x = x; |
| 5571 | mod.y = y; |
| 5572 | mod.z = z; |
| 5573 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5574 | // Projection performed by texture sampler |
| 5575 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5576 | case Shader::MODIFIER_DW: |
| 5577 | mod.x = x; |
| 5578 | mod.y = y; |
| 5579 | mod.z = z; |
| 5580 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5581 | // Projection performed by texture sampler |
| 5582 | break; |
| 5583 | default: |
| 5584 | ASSERT(false); |
| 5585 | } |
| 5586 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5587 | 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] | 5588 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5589 | mod.x = Min(mod.x, Short4(0x1000)); mod.x = Max(mod.x, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5590 | mod.y = Min(mod.y, Short4(0x1000)); mod.y = Max(mod.y, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5591 | mod.z = Min(mod.z, Short4(0x1000)); mod.z = Max(mod.z, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5592 | 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] | 5593 | } |
| 5594 | |
| 5595 | return mod; |
| 5596 | } |
| 5597 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5598 | Vector4f PixelRoutine::reg(Registers &r, const Src &src, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5599 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5600 | Vector4f reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5601 | int i = src.index + offset; |
| 5602 | |
| 5603 | switch(src.type) |
| 5604 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5605 | case Shader::PARAMETER_TEMP: |
| 5606 | if(src.rel.type == Shader::PARAMETER_VOID) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5607 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5608 | reg = r.rf[i]; |
| 5609 | } |
| 5610 | else |
| 5611 | { |
| 5612 | Int a = relativeAddress(r, src); |
| 5613 | |
| 5614 | reg = r.rf[i + a]; |
| 5615 | } |
| 5616 | break; |
| 5617 | case Shader::PARAMETER_INPUT: |
| 5618 | { |
| 5619 | if(src.rel.type == Shader::PARAMETER_VOID) // Not relative |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5620 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5621 | reg = r.vf[i]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5622 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5623 | else if(src.rel.type == Shader::PARAMETER_LOOP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5624 | { |
| 5625 | Int aL = r.aL[r.loopDepth]; |
| 5626 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5627 | reg = r.vf[i + aL]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5628 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5629 | else |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5630 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5631 | Int a = relativeAddress(r, src); |
| 5632 | |
| 5633 | reg = r.vf[i + a]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5634 | } |
| 5635 | } |
| 5636 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5637 | case Shader::PARAMETER_CONST: |
| 5638 | reg = readConstant(r, src, offset); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5639 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5640 | case Shader::PARAMETER_TEXTURE: |
| 5641 | reg = r.vf[2 + i]; |
| 5642 | break; |
| 5643 | case Shader::PARAMETER_MISCTYPE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5644 | if(src.index == 0) reg = r.vPos; |
| 5645 | if(src.index == 1) reg = r.vFace; |
| 5646 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5647 | case Shader::PARAMETER_SAMPLER: |
| 5648 | if(src.rel.type == Shader::PARAMETER_VOID) |
| 5649 | { |
| 5650 | reg.x = As<Float4>(Int4(i)); |
| 5651 | } |
| 5652 | else if(src.rel.type == Shader::PARAMETER_TEMP) |
| 5653 | { |
| 5654 | reg.x = As<Float4>(Int4(i) + RoundInt(r.rf[src.rel.index].x)); |
| 5655 | } |
| 5656 | return reg; |
| 5657 | case Shader::PARAMETER_PREDICATE: return reg; // Dummy |
| 5658 | case Shader::PARAMETER_VOID: return reg; // Dummy |
| 5659 | case Shader::PARAMETER_FLOAT4LITERAL: |
| 5660 | reg.x = Float4(src.value[0]); |
| 5661 | reg.y = Float4(src.value[1]); |
| 5662 | reg.z = Float4(src.value[2]); |
| 5663 | reg.w = Float4(src.value[3]); |
| 5664 | break; |
| 5665 | case Shader::PARAMETER_CONSTINT: return reg; // Dummy |
| 5666 | case Shader::PARAMETER_CONSTBOOL: return reg; // Dummy |
| 5667 | case Shader::PARAMETER_LOOP: return reg; // Dummy |
| 5668 | case Shader::PARAMETER_COLOROUT: |
| 5669 | reg = r.oC[i]; |
| 5670 | break; |
| 5671 | case Shader::PARAMETER_DEPTHOUT: |
| 5672 | reg.x = r.oDepth; |
| 5673 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5674 | default: |
| 5675 | ASSERT(false); |
| 5676 | } |
| 5677 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5678 | const Float4 &x = reg[(src.swizzle >> 0) & 0x3]; |
| 5679 | const Float4 &y = reg[(src.swizzle >> 2) & 0x3]; |
| 5680 | const Float4 &z = reg[(src.swizzle >> 4) & 0x3]; |
| 5681 | const Float4 &w = reg[(src.swizzle >> 6) & 0x3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5682 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5683 | Vector4f mod; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5684 | |
| 5685 | switch(src.modifier) |
| 5686 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5687 | case Shader::MODIFIER_NONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5688 | mod.x = x; |
| 5689 | mod.y = y; |
| 5690 | mod.z = z; |
| 5691 | mod.w = w; |
| 5692 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5693 | case Shader::MODIFIER_NEGATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5694 | mod.x = -x; |
| 5695 | mod.y = -y; |
| 5696 | mod.z = -z; |
| 5697 | mod.w = -w; |
| 5698 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5699 | case Shader::MODIFIER_ABS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5700 | mod.x = Abs(x); |
| 5701 | mod.y = Abs(y); |
| 5702 | mod.z = Abs(z); |
| 5703 | mod.w = Abs(w); |
| 5704 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5705 | case Shader::MODIFIER_ABS_NEGATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5706 | mod.x = -Abs(x); |
| 5707 | mod.y = -Abs(y); |
| 5708 | mod.z = -Abs(z); |
| 5709 | mod.w = -Abs(w); |
| 5710 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5711 | case Shader::MODIFIER_NOT: |
| 5712 | mod.x = As<Float4>(As<Int4>(x) ^ Int4(0xFFFFFFFF)); |
| 5713 | mod.y = As<Float4>(As<Int4>(y) ^ Int4(0xFFFFFFFF)); |
| 5714 | mod.z = As<Float4>(As<Int4>(z) ^ Int4(0xFFFFFFFF)); |
| 5715 | mod.w = As<Float4>(As<Int4>(w) ^ Int4(0xFFFFFFFF)); |
| 5716 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5717 | default: |
| 5718 | ASSERT(false); |
| 5719 | } |
| 5720 | |
| 5721 | return mod; |
| 5722 | } |
| 5723 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5724 | Vector4f PixelRoutine::readConstant(Registers &r, const Src &src, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5725 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5726 | Vector4f c; |
| 5727 | |
| 5728 | int i = src.index + offset; |
| 5729 | |
| 5730 | if(src.rel.type == Shader::PARAMETER_VOID) // Not relative |
| 5731 | { |
| 5732 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i])); |
| 5733 | |
| 5734 | c.x = c.x.xxxx; |
| 5735 | c.y = c.y.yyyy; |
| 5736 | c.z = c.z.zzzz; |
| 5737 | c.w = c.w.wwww; |
| 5738 | |
| 5739 | if(localShaderConstants) // Constant may be known at compile time |
| 5740 | { |
| 5741 | for(int j = 0; j < shader->getLength(); j++) |
| 5742 | { |
| 5743 | const Shader::Instruction &instruction = *shader->getInstruction(j); |
| 5744 | |
| 5745 | if(instruction.opcode == Shader::OPCODE_DEF) |
| 5746 | { |
| 5747 | if(instruction.dst.index == i) |
| 5748 | { |
| 5749 | c.x = Float4(instruction.src[0].value[0]); |
| 5750 | c.y = Float4(instruction.src[0].value[1]); |
| 5751 | c.z = Float4(instruction.src[0].value[2]); |
| 5752 | c.w = Float4(instruction.src[0].value[3]); |
| 5753 | |
| 5754 | break; |
| 5755 | } |
| 5756 | } |
| 5757 | } |
| 5758 | } |
| 5759 | } |
| 5760 | else if(src.rel.type == Shader::PARAMETER_LOOP) |
| 5761 | { |
| 5762 | Int loopCounter = r.aL[r.loopDepth]; |
| 5763 | |
| 5764 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i]) + loopCounter * 16); |
| 5765 | |
| 5766 | c.x = c.x.xxxx; |
| 5767 | c.y = c.y.yyyy; |
| 5768 | c.z = c.z.zzzz; |
| 5769 | c.w = c.w.wwww; |
| 5770 | } |
| 5771 | else |
| 5772 | { |
| 5773 | Int a = relativeAddress(r, src); |
| 5774 | |
| 5775 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i]) + a * 16); |
| 5776 | |
| 5777 | c.x = c.x.xxxx; |
| 5778 | c.y = c.y.yyyy; |
| 5779 | c.z = c.z.zzzz; |
| 5780 | c.w = c.w.wwww; |
| 5781 | } |
| 5782 | |
| 5783 | return c; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5784 | } |
| 5785 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5786 | Int PixelRoutine::relativeAddress(Registers &r, const Shader::Parameter &var) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5787 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5788 | ASSERT(var.rel.deterministic); |
| 5789 | |
| 5790 | if(var.rel.type == Shader::PARAMETER_TEMP) |
| 5791 | { |
| 5792 | return RoundInt(Extract(r.rf[var.rel.index].x, 0)) * var.rel.scale; |
| 5793 | } |
| 5794 | else if(var.rel.type == Shader::PARAMETER_INPUT) |
| 5795 | { |
| 5796 | return RoundInt(Extract(r.vf[var.rel.index].x, 0)) * var.rel.scale; |
| 5797 | } |
| 5798 | else if(var.rel.type == Shader::PARAMETER_OUTPUT) |
| 5799 | { |
| 5800 | return RoundInt(Extract(r.oC[var.rel.index].x, 0)) * var.rel.scale; |
| 5801 | } |
| 5802 | else if(var.rel.type == Shader::PARAMETER_CONST) |
| 5803 | { |
| 5804 | RValue<Float4> c = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[var.rel.index])); |
| 5805 | |
| 5806 | return RoundInt(Extract(c, 0)) * var.rel.scale; |
| 5807 | } |
| 5808 | else ASSERT(false); |
| 5809 | |
| 5810 | return 0; |
| 5811 | } |
| 5812 | |
| 5813 | Int4 PixelRoutine::enableMask(Registers &r, const Shader::Instruction *instruction) |
| 5814 | { |
| 5815 | Int4 enable = instruction->analysisBranch ? Int4(r.enableStack[r.enableIndex]) : Int4(0xFFFFFFFF); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame^] | 5816 | |
| 5817 | if(!whileTest) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5818 | { |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame^] | 5819 | if(shader->containsBreakInstruction() && instruction->analysisBreak) |
| 5820 | { |
| 5821 | enable &= r.enableBreak; |
| 5822 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5823 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame^] | 5824 | if(shader->containsContinueInstruction() && instruction->analysisContinue) |
| 5825 | { |
| 5826 | enable &= r.enableContinue; |
| 5827 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5828 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame^] | 5829 | if(shader->containsLeaveInstruction() && instruction->analysisLeave) |
| 5830 | { |
| 5831 | enable &= r.enableLeave; |
| 5832 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | return enable; |
| 5836 | } |
| 5837 | |
| 5838 | bool PixelRoutine::colorUsed() |
| 5839 | { |
| 5840 | return state.colorWriteMask || state.alphaTestActive() || state.shaderContainsKill; |
| 5841 | } |
| 5842 | |
| 5843 | unsigned short PixelRoutine::shaderVersion() const |
| 5844 | { |
| 5845 | return shader ? shader->getVersion() : 0x0000; |
| 5846 | } |
| 5847 | |
| 5848 | bool PixelRoutine::interpolateZ() const |
| 5849 | { |
| 5850 | return state.depthTestActive || state.pixelFogActive() || (shader && shader->vPosDeclared && fullPixelPositionRegister); |
| 5851 | } |
| 5852 | |
| 5853 | bool PixelRoutine::interpolateW() const |
| 5854 | { |
| 5855 | return state.perspective || (shader && shader->vPosDeclared && fullPixelPositionRegister); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5856 | } |
| 5857 | } |