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 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame^] | 56 | for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 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 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame^] | 68 | for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 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 | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 92 | Float4 (&z)[4] = r.z; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 93 | Float4 &w = r.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 94 | Float4 &rhw = r.rhw; |
| 95 | Float4 rhwCentroid; |
| 96 | |
| 97 | Float4 xxxx = Float4(Float(x)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,xQuad), 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 98 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 99 | if(interpolateZ()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 100 | { |
| 101 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 102 | { |
| 103 | Float4 x = xxxx; |
| 104 | |
| 105 | if(state.multiSample > 1) |
| 106 | { |
| 107 | x -= *Pointer<Float4>(r.constants + OFFSET(Constants,X) + q * sizeof(float4)); |
| 108 | } |
| 109 | |
| 110 | z[q] = interpolate(x, r.Dz[q], z[q], r.primitive + OFFSET(Primitive,z), false, false); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | Bool depthPass = false; |
| 115 | |
| 116 | if(earlyDepthTest) |
| 117 | { |
| 118 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 119 | { |
| 120 | depthPass = depthPass || depthTest(r, zBuffer, q, x, z[q], sMask[q], zMask[q], cMask[q]); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | If(depthPass || Bool(!earlyDepthTest)) |
| 125 | { |
| 126 | #if PERF_PROFILE |
| 127 | Long interpTime = Ticks(); |
| 128 | #endif |
| 129 | |
Nicolas Capens | 66be245 | 2015-01-27 14:58:57 -0500 | [diff] [blame] | 130 | Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,yQuad), 16); |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 131 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 132 | // Centroid locations |
| 133 | Float4 XXXX = Float4(0.0f); |
| 134 | Float4 YYYY = Float4(0.0f); |
| 135 | |
| 136 | if(state.centroid) |
| 137 | { |
| 138 | Float4 WWWW(1.0e-9f); |
| 139 | |
| 140 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 141 | { |
| 142 | XXXX += *Pointer<Float4>(r.constants + OFFSET(Constants,sampleX[q]) + 16 * cMask[q]); |
| 143 | YYYY += *Pointer<Float4>(r.constants + OFFSET(Constants,sampleY[q]) + 16 * cMask[q]); |
| 144 | WWWW += *Pointer<Float4>(r.constants + OFFSET(Constants,weight) + 16 * cMask[q]); |
| 145 | } |
| 146 | |
| 147 | WWWW = Rcp_pp(WWWW); |
| 148 | XXXX *= WWWW; |
| 149 | YYYY *= WWWW; |
| 150 | |
| 151 | XXXX += xxxx; |
| 152 | YYYY += yyyy; |
| 153 | } |
| 154 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 155 | if(interpolateW()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 156 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 157 | w = interpolate(xxxx, r.Dw, rhw, r.primitive + OFFSET(Primitive,w), false, false); |
| 158 | rhw = reciprocal(w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 159 | |
| 160 | if(state.centroid) |
| 161 | { |
| 162 | rhwCentroid = reciprocal(interpolateCentroid(XXXX, YYYY, rhwCentroid, r.primitive + OFFSET(Primitive,w), false, false)); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | for(int interpolant = 0; interpolant < 10; interpolant++) |
| 167 | { |
| 168 | for(int component = 0; component < 4; component++) |
| 169 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 170 | if(state.interpolant[interpolant].component & (1 << component)) |
| 171 | { |
| 172 | if(!state.interpolant[interpolant].centroid) |
| 173 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 174 | 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] | 175 | } |
| 176 | else |
| 177 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 178 | 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] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | Float4 rcp; |
| 184 | |
| 185 | switch(state.interpolant[interpolant].project) |
| 186 | { |
| 187 | case 0: |
| 188 | break; |
| 189 | case 1: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 190 | rcp = reciprocal(r.vf[interpolant].y); |
| 191 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 192 | break; |
| 193 | case 2: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 194 | rcp = reciprocal(r.vf[interpolant].z); |
| 195 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
| 196 | r.vf[interpolant].y = r.vf[interpolant].y * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 197 | break; |
| 198 | case 3: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 199 | rcp = reciprocal(r.vf[interpolant].w); |
| 200 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
| 201 | r.vf[interpolant].y = r.vf[interpolant].y * rcp; |
| 202 | r.vf[interpolant].z = r.vf[interpolant].z * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 203 | break; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | if(state.fog.component) |
| 208 | { |
| 209 | f = interpolate(xxxx, r.Df, rhw, r.primitive + OFFSET(Primitive,f), state.fog.flat & 0x01, state.perspective); |
| 210 | } |
| 211 | |
| 212 | if(integerPipeline) |
| 213 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 214 | if(state.color[0].component & 0x1) r.diffuse.x = convertFixed12(r.vf[0].x); else r.diffuse.x = Short4(0x1000); |
| 215 | if(state.color[0].component & 0x2) r.diffuse.y = convertFixed12(r.vf[0].y); else r.diffuse.y = Short4(0x1000); |
| 216 | if(state.color[0].component & 0x4) r.diffuse.z = convertFixed12(r.vf[0].z); else r.diffuse.z = Short4(0x1000); |
| 217 | if(state.color[0].component & 0x8) r.diffuse.w = convertFixed12(r.vf[0].w); else r.diffuse.w = Short4(0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 218 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 219 | if(state.color[1].component & 0x1) r.specular.x = convertFixed12(r.vf[1].x); else r.specular.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 220 | if(state.color[1].component & 0x2) r.specular.y = convertFixed12(r.vf[1].y); else r.specular.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 221 | if(state.color[1].component & 0x4) r.specular.z = convertFixed12(r.vf[1].z); else r.specular.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 222 | if(state.color[1].component & 0x8) r.specular.w = convertFixed12(r.vf[1].w); else r.specular.w = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 223 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 224 | else if(shaderVersion() >= 0x0300) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 225 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 226 | if(shader->vPosDeclared) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 227 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 228 | if(!halfIntegerCoordinates) |
| 229 | { |
| 230 | r.vPos.x = Float4(Float(x)) + Float4(0, 1, 0, 1); |
| 231 | r.vPos.y = Float4(Float(y)) + Float4(0, 0, 1, 1); |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | r.vPos.x = Float4(Float(x)) + Float4(0.5f, 1.5f, 0.5f, 1.5f); |
| 236 | r.vPos.y = Float4(Float(y)) + Float4(0.5f, 0.5f, 1.5f, 1.5f); |
| 237 | } |
| 238 | |
| 239 | if(fullPixelPositionRegister) |
| 240 | { |
| 241 | r.vPos.z = z[0]; // FIXME: Centroid? |
| 242 | r.vPos.w = w; // FIXME: Centroid? |
| 243 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 244 | } |
| 245 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 246 | if(shader->vFaceDeclared) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 247 | { |
| 248 | Float4 area = *Pointer<Float>(r.primitive + OFFSET(Primitive,area)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 249 | Float4 face = booleanFaceRegister ? Float4(As<Float4>(CmpNLT(area, Float4(0.0f)))) : area; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 250 | |
| 251 | r.vFace.x = face; |
| 252 | r.vFace.y = face; |
| 253 | r.vFace.z = face; |
| 254 | r.vFace.w = face; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | #if PERF_PROFILE |
| 259 | r.cycles[PERF_INTERP] += Ticks() - interpTime; |
| 260 | #endif |
| 261 | |
| 262 | Bool alphaPass = true; |
| 263 | |
| 264 | if(colorUsed()) |
| 265 | { |
| 266 | #if PERF_PROFILE |
| 267 | Long shaderTime = Ticks(); |
| 268 | #endif |
| 269 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 270 | if(shader) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 271 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 272 | // shader->print("PixelShader-%0.8X.txt", state.shaderID); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 273 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 274 | if(shader->getVersion() <= 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 275 | { |
| 276 | ps_1_x(r, cMask); |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | ps_2_x(r, cMask); |
| 281 | } |
| 282 | } |
| 283 | else |
| 284 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 285 | r.current = r.diffuse; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 286 | Vector4i temp(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 287 | |
| 288 | for(int stage = 0; stage < 8; stage++) |
| 289 | { |
| 290 | if(state.textureStage[stage].stageOperation == TextureStage::STAGE_DISABLE) |
| 291 | { |
| 292 | break; |
| 293 | } |
| 294 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 295 | Vector4i texture; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 296 | |
| 297 | if(state.textureStage[stage].usesTexture) |
| 298 | { |
| 299 | sampleTexture(r, texture, stage, stage); |
| 300 | } |
| 301 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 302 | blendTexture(r, temp, texture, stage); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 303 | } |
| 304 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 305 | specularPixel(r.current, r.specular); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | #if PERF_PROFILE |
| 309 | r.cycles[PERF_SHADER] += Ticks() - shaderTime; |
| 310 | #endif |
| 311 | |
| 312 | if(integerPipeline) |
| 313 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 314 | r.current.x = Min(r.current.x, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.x = Max(r.current.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 315 | r.current.y = Min(r.current.y, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.y = Max(r.current.y, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 316 | r.current.z = Min(r.current.z, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.z = Max(r.current.z, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 317 | r.current.w = Min(r.current.w, Short4(0x0FFF, 0x0FFF, 0x0FFF, 0x0FFF)); r.current.w = Max(r.current.w, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 318 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 319 | alphaPass = alphaTest(r, cMask, r.current); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 320 | } |
| 321 | else |
| 322 | { |
| 323 | clampColor(r.oC); |
| 324 | |
| 325 | alphaPass = alphaTest(r, cMask, r.oC[0]); |
| 326 | } |
| 327 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 328 | if((shader && shader->containsKill()) || state.alphaTestActive()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 329 | { |
| 330 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 331 | { |
| 332 | zMask[q] &= cMask[q]; |
| 333 | sMask[q] &= cMask[q]; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | If(alphaPass) |
| 339 | { |
| 340 | if(!earlyDepthTest) |
| 341 | { |
| 342 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 343 | { |
| 344 | depthPass = depthPass || depthTest(r, zBuffer, q, x, z[q], sMask[q], zMask[q], cMask[q]); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | #if PERF_PROFILE |
| 349 | Long ropTime = Ticks(); |
| 350 | #endif |
| 351 | |
| 352 | If(depthPass || Bool(earlyDepthTest)) |
| 353 | { |
| 354 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 355 | { |
| 356 | if(state.multiSampleMask & (1 << q)) |
| 357 | { |
| 358 | writeDepth(r, zBuffer, q, x, z[q], zMask[q]); |
| 359 | |
| 360 | if(state.occlusionEnabled) |
| 361 | { |
| 362 | r.occlusion += *Pointer<UInt>(r.constants + OFFSET(Constants,occlusionCount) + 4 * (zMask[q] & sMask[q])); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if(colorUsed()) |
| 368 | { |
| 369 | #if PERF_PROFILE |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 370 | AddAtomic(Pointer<Long>(&profiler.ropOperations), 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 371 | #endif |
| 372 | |
| 373 | if(integerPipeline) |
| 374 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 375 | rasterOperation(r.current, r, f, cBuffer[0], x, sMask, zMask, cMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 376 | } |
| 377 | else |
| 378 | { |
| 379 | rasterOperation(r.oC, r, f, cBuffer, x, sMask, zMask, cMask); |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | #if PERF_PROFILE |
| 385 | r.cycles[PERF_ROP] += Ticks() - ropTime; |
| 386 | #endif |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 391 | { |
| 392 | if(state.multiSampleMask & (1 << q)) |
| 393 | { |
| 394 | writeStencil(r, sBuffer, q, x, sMask[q], zMask[q], cMask[q]); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | #if PERF_PROFILE |
| 399 | r.cycles[PERF_PIPE] += Ticks() - pipeTime; |
| 400 | #endif |
| 401 | } |
| 402 | |
| 403 | Float4 PixelRoutine::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective) |
| 404 | { |
| 405 | Float4 interpolant = D; |
| 406 | |
| 407 | if(!flat) |
| 408 | { |
| 409 | interpolant += x * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,A), 16); |
| 410 | |
| 411 | if(perspective) |
| 412 | { |
| 413 | interpolant *= rhw; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | return interpolant; |
| 418 | } |
| 419 | |
| 420 | Float4 PixelRoutine::interpolateCentroid(Float4 &x, Float4 &y, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective) |
| 421 | { |
| 422 | Float4 interpolant = *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,C), 16); |
| 423 | |
| 424 | if(!flat) |
| 425 | { |
| 426 | interpolant += x * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,A), 16) + |
| 427 | y * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,B), 16); |
| 428 | |
| 429 | if(perspective) |
| 430 | { |
| 431 | interpolant *= rhw; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | return interpolant; |
| 436 | } |
| 437 | |
| 438 | void PixelRoutine::stencilTest(Registers &r, Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &cMask) |
| 439 | { |
| 440 | if(!state.stencilActive) |
| 441 | { |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | // (StencilRef & StencilMask) CompFunc (StencilBufferValue & StencilMask) |
| 446 | |
| 447 | Pointer<Byte> buffer = sBuffer + 2 * x; |
| 448 | |
| 449 | if(q > 0) |
| 450 | { |
| 451 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,stencilSliceB)); |
| 452 | } |
| 453 | |
| 454 | Byte8 value = As<Byte8>(Long1(*Pointer<UInt>(buffer))); |
| 455 | Byte8 valueCCW = value; |
| 456 | |
| 457 | if(!state.noStencilMask) |
| 458 | { |
| 459 | value &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].testMaskQ)); |
| 460 | } |
| 461 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 462 | stencilTest(r, value, state.stencilCompareMode, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 463 | |
| 464 | if(state.twoSidedStencil) |
| 465 | { |
| 466 | if(!state.noStencilMaskCCW) |
| 467 | { |
| 468 | valueCCW &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].testMaskQ)); |
| 469 | } |
| 470 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 471 | stencilTest(r, valueCCW, state.stencilCompareModeCCW, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 472 | |
| 473 | value &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,clockwiseMask)); |
| 474 | valueCCW &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,invClockwiseMask)); |
| 475 | value |= valueCCW; |
| 476 | } |
| 477 | |
| 478 | sMask = SignMask(value) & cMask; |
| 479 | } |
| 480 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 481 | void PixelRoutine::stencilTest(Registers &r, Byte8 &value, StencilCompareMode stencilCompareMode, bool CCW) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 482 | { |
| 483 | Byte8 equal; |
| 484 | |
| 485 | switch(stencilCompareMode) |
| 486 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 487 | case STENCIL_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 488 | value = Byte8(0xFFFFFFFFFFFFFFFF); |
| 489 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 490 | case STENCIL_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 491 | value = Byte8(0x0000000000000000); |
| 492 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 493 | case STENCIL_LESS: // a < b ~ b > a |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 494 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 495 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 496 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 497 | case STENCIL_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 498 | value = CmpEQ(value, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 499 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 500 | case STENCIL_NOTEQUAL: // a != b ~ !(a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 501 | value = CmpEQ(value, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 502 | value ^= Byte8(0xFFFFFFFFFFFFFFFF); |
| 503 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 504 | case STENCIL_LESSEQUAL: // a <= b ~ (b > a) || (a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 505 | equal = value; |
| 506 | equal = CmpEQ(equal, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 507 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 508 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 509 | value |= equal; |
| 510 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 511 | case STENCIL_GREATER: // a > b |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 512 | equal = *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ)); |
| 513 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 514 | equal = CmpGT(As<SByte8>(equal), As<SByte8>(value)); |
| 515 | value = equal; |
| 516 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 517 | case STENCIL_GREATEREQUAL: // a >= b ~ !(a < b) ~ !(b > a) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 518 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 519 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 520 | value ^= Byte8(0xFFFFFFFFFFFFFFFF); |
| 521 | break; |
| 522 | default: |
| 523 | ASSERT(false); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | Bool PixelRoutine::depthTest(Registers &r, Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &sMask, Int &zMask, Int &cMask) |
| 528 | { |
| 529 | if(!state.depthTestActive) |
| 530 | { |
| 531 | return true; |
| 532 | } |
| 533 | |
| 534 | Float4 Z = z; |
| 535 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 536 | if(shader && shader->depthOverride()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 537 | { |
| 538 | if(complementaryDepthBuffer) |
| 539 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 540 | Z = Float4(1.0f) - r.oDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 541 | } |
| 542 | else |
| 543 | { |
| 544 | Z = r.oDepth; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | Pointer<Byte> buffer; |
| 549 | Int pitch; |
| 550 | |
| 551 | if(!state.quadLayoutDepthBuffer) |
| 552 | { |
| 553 | buffer = zBuffer + 4 * x; |
| 554 | pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); |
| 555 | } |
| 556 | else |
| 557 | { |
| 558 | buffer = zBuffer + 8 * x; |
| 559 | } |
| 560 | |
| 561 | if(q > 0) |
| 562 | { |
| 563 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,depthSliceB)); |
| 564 | } |
| 565 | |
| 566 | Float4 zValue; |
| 567 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 568 | if(state.depthCompareMode != DEPTH_NEVER || (state.depthCompareMode != DEPTH_ALWAYS && !state.depthWriteEnable)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 569 | { |
| 570 | if(!state.quadLayoutDepthBuffer) |
| 571 | { |
| 572 | // FIXME: Properly optimizes? |
| 573 | zValue.xy = *Pointer<Float4>(buffer); |
| 574 | zValue.zw = *Pointer<Float4>(buffer + pitch - 8); |
| 575 | } |
| 576 | else |
| 577 | { |
| 578 | zValue = *Pointer<Float4>(buffer, 16); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | Int4 zTest; |
| 583 | |
| 584 | switch(state.depthCompareMode) |
| 585 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 586 | case DEPTH_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 587 | // Optimized |
| 588 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 589 | case DEPTH_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 590 | // Optimized |
| 591 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 592 | case DEPTH_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 593 | zTest = CmpEQ(zValue, Z); |
| 594 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 595 | case DEPTH_NOTEQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 596 | zTest = CmpNEQ(zValue, Z); |
| 597 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 598 | case DEPTH_LESS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 599 | if(complementaryDepthBuffer) |
| 600 | { |
| 601 | zTest = CmpLT(zValue, Z); |
| 602 | } |
| 603 | else |
| 604 | { |
| 605 | zTest = CmpNLE(zValue, Z); |
| 606 | } |
| 607 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 608 | case DEPTH_GREATEREQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 609 | if(complementaryDepthBuffer) |
| 610 | { |
| 611 | zTest = CmpNLT(zValue, Z); |
| 612 | } |
| 613 | else |
| 614 | { |
| 615 | zTest = CmpLE(zValue, Z); |
| 616 | } |
| 617 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 618 | case DEPTH_LESSEQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 619 | if(complementaryDepthBuffer) |
| 620 | { |
| 621 | zTest = CmpLE(zValue, Z); |
| 622 | } |
| 623 | else |
| 624 | { |
| 625 | zTest = CmpNLT(zValue, Z); |
| 626 | } |
| 627 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 628 | case DEPTH_GREATER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 629 | if(complementaryDepthBuffer) |
| 630 | { |
| 631 | zTest = CmpNLE(zValue, Z); |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | zTest = CmpLT(zValue, Z); |
| 636 | } |
| 637 | break; |
| 638 | default: |
| 639 | ASSERT(false); |
| 640 | } |
| 641 | |
| 642 | switch(state.depthCompareMode) |
| 643 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 644 | case DEPTH_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 645 | zMask = cMask; |
| 646 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 647 | case DEPTH_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 648 | zMask = 0x0; |
| 649 | break; |
| 650 | default: |
| 651 | zMask = SignMask(zTest) & cMask; |
| 652 | break; |
| 653 | } |
| 654 | |
| 655 | if(state.stencilActive) |
| 656 | { |
| 657 | zMask &= sMask; |
| 658 | } |
| 659 | |
| 660 | return zMask != 0; |
| 661 | } |
| 662 | |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 663 | void PixelRoutine::blendTexture(Registers &r, Vector4i &temp, Vector4i &texture, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 664 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 665 | Vector4i *arg1; |
| 666 | Vector4i *arg2; |
| 667 | Vector4i *arg3; |
| 668 | Vector4i res; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 669 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 670 | Vector4i constant; |
| 671 | Vector4i tfactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 672 | |
| 673 | const TextureStage::State &textureStage = state.textureStage[stage]; |
| 674 | |
| 675 | if(textureStage.firstArgument == TextureStage::SOURCE_CONSTANT || |
| 676 | textureStage.firstArgumentAlpha == TextureStage::SOURCE_CONSTANT || |
| 677 | textureStage.secondArgument == TextureStage::SOURCE_CONSTANT || |
| 678 | textureStage.secondArgumentAlpha == TextureStage::SOURCE_CONSTANT || |
| 679 | textureStage.thirdArgument == TextureStage::SOURCE_CONSTANT || |
| 680 | textureStage.thirdArgumentAlpha == TextureStage::SOURCE_CONSTANT) |
| 681 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 682 | constant.x = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[0])); |
| 683 | constant.y = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[1])); |
| 684 | constant.z = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[2])); |
| 685 | constant.w = *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].constantColor4[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | if(textureStage.firstArgument == TextureStage::SOURCE_TFACTOR || |
| 689 | textureStage.firstArgumentAlpha == TextureStage::SOURCE_TFACTOR || |
| 690 | textureStage.secondArgument == TextureStage::SOURCE_TFACTOR || |
| 691 | textureStage.secondArgumentAlpha == TextureStage::SOURCE_TFACTOR || |
| 692 | textureStage.thirdArgument == TextureStage::SOURCE_TFACTOR || |
| 693 | textureStage.thirdArgumentAlpha == TextureStage::SOURCE_TFACTOR) |
| 694 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 695 | tfactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[0])); |
| 696 | tfactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[1])); |
| 697 | tfactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[2])); |
| 698 | tfactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.textureFactor4[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | // Premodulate |
| 702 | if(stage > 0 && textureStage.usesTexture) |
| 703 | { |
| 704 | if(state.textureStage[stage - 1].stageOperation == TextureStage::STAGE_PREMODULATE) |
| 705 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 706 | r.current.x = MulHigh(r.current.x, texture.x) << 4; |
| 707 | r.current.y = MulHigh(r.current.y, texture.y) << 4; |
| 708 | r.current.z = MulHigh(r.current.z, texture.z) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | if(state.textureStage[stage - 1].stageOperationAlpha == TextureStage::STAGE_PREMODULATE) |
| 712 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 713 | r.current.w = MulHigh(r.current.w, texture.w) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | |
| 717 | if(luminance) |
| 718 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 719 | texture.x = MulHigh(texture.x, r.L) << 4; |
| 720 | texture.y = MulHigh(texture.y, r.L) << 4; |
| 721 | texture.z = MulHigh(texture.z, r.L) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 722 | |
| 723 | luminance = false; |
| 724 | } |
| 725 | |
| 726 | switch(textureStage.firstArgument) |
| 727 | { |
| 728 | case TextureStage::SOURCE_TEXTURE: arg1 = &texture; break; |
| 729 | case TextureStage::SOURCE_CONSTANT: arg1 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 730 | case TextureStage::SOURCE_CURRENT: arg1 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 731 | case TextureStage::SOURCE_DIFFUSE: arg1 = &r.diffuse; break; |
| 732 | case TextureStage::SOURCE_SPECULAR: arg1 = &r.specular; break; |
| 733 | case TextureStage::SOURCE_TEMP: arg1 = &temp; break; |
| 734 | case TextureStage::SOURCE_TFACTOR: arg1 = &tfactor; break; |
| 735 | default: |
| 736 | ASSERT(false); |
| 737 | } |
| 738 | |
| 739 | switch(textureStage.secondArgument) |
| 740 | { |
| 741 | case TextureStage::SOURCE_TEXTURE: arg2 = &texture; break; |
| 742 | case TextureStage::SOURCE_CONSTANT: arg2 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 743 | case TextureStage::SOURCE_CURRENT: arg2 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 744 | case TextureStage::SOURCE_DIFFUSE: arg2 = &r.diffuse; break; |
| 745 | case TextureStage::SOURCE_SPECULAR: arg2 = &r.specular; break; |
| 746 | case TextureStage::SOURCE_TEMP: arg2 = &temp; break; |
| 747 | case TextureStage::SOURCE_TFACTOR: arg2 = &tfactor; break; |
| 748 | default: |
| 749 | ASSERT(false); |
| 750 | } |
| 751 | |
| 752 | switch(textureStage.thirdArgument) |
| 753 | { |
| 754 | case TextureStage::SOURCE_TEXTURE: arg3 = &texture; break; |
| 755 | case TextureStage::SOURCE_CONSTANT: arg3 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 756 | case TextureStage::SOURCE_CURRENT: arg3 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 757 | case TextureStage::SOURCE_DIFFUSE: arg3 = &r.diffuse; break; |
| 758 | case TextureStage::SOURCE_SPECULAR: arg3 = &r.specular; break; |
| 759 | case TextureStage::SOURCE_TEMP: arg3 = &temp; break; |
| 760 | case TextureStage::SOURCE_TFACTOR: arg3 = &tfactor; break; |
| 761 | default: |
| 762 | ASSERT(false); |
| 763 | } |
| 764 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 765 | Vector4i mod1; |
| 766 | Vector4i mod2; |
| 767 | Vector4i mod3; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 768 | |
| 769 | switch(textureStage.firstModifier) |
| 770 | { |
| 771 | case TextureStage::MODIFIER_COLOR: |
| 772 | break; |
| 773 | case TextureStage::MODIFIER_INVCOLOR: |
| 774 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 775 | mod1.x = SubSat(Short4(0x1000), arg1->x); |
| 776 | mod1.y = SubSat(Short4(0x1000), arg1->y); |
| 777 | mod1.z = SubSat(Short4(0x1000), arg1->z); |
| 778 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 779 | |
| 780 | arg1 = &mod1; |
| 781 | } |
| 782 | break; |
| 783 | case TextureStage::MODIFIER_ALPHA: |
| 784 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 785 | mod1.x = arg1->w; |
| 786 | mod1.y = arg1->w; |
| 787 | mod1.z = arg1->w; |
| 788 | mod1.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 789 | |
| 790 | arg1 = &mod1; |
| 791 | } |
| 792 | break; |
| 793 | case TextureStage::MODIFIER_INVALPHA: |
| 794 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 795 | mod1.x = SubSat(Short4(0x1000), arg1->w); |
| 796 | mod1.y = SubSat(Short4(0x1000), arg1->w); |
| 797 | mod1.z = SubSat(Short4(0x1000), arg1->w); |
| 798 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 799 | |
| 800 | arg1 = &mod1; |
| 801 | } |
| 802 | break; |
| 803 | default: |
| 804 | ASSERT(false); |
| 805 | } |
| 806 | |
| 807 | switch(textureStage.secondModifier) |
| 808 | { |
| 809 | case TextureStage::MODIFIER_COLOR: |
| 810 | break; |
| 811 | case TextureStage::MODIFIER_INVCOLOR: |
| 812 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 813 | mod2.x = SubSat(Short4(0x1000), arg2->x); |
| 814 | mod2.y = SubSat(Short4(0x1000), arg2->y); |
| 815 | mod2.z = SubSat(Short4(0x1000), arg2->z); |
| 816 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 817 | |
| 818 | arg2 = &mod2; |
| 819 | } |
| 820 | break; |
| 821 | case TextureStage::MODIFIER_ALPHA: |
| 822 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 823 | mod2.x = arg2->w; |
| 824 | mod2.y = arg2->w; |
| 825 | mod2.z = arg2->w; |
| 826 | mod2.w = arg2->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 827 | |
| 828 | arg2 = &mod2; |
| 829 | } |
| 830 | break; |
| 831 | case TextureStage::MODIFIER_INVALPHA: |
| 832 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 833 | mod2.x = SubSat(Short4(0x1000), arg2->w); |
| 834 | mod2.y = SubSat(Short4(0x1000), arg2->w); |
| 835 | mod2.z = SubSat(Short4(0x1000), arg2->w); |
| 836 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 837 | |
| 838 | arg2 = &mod2; |
| 839 | } |
| 840 | break; |
| 841 | default: |
| 842 | ASSERT(false); |
| 843 | } |
| 844 | |
| 845 | switch(textureStage.thirdModifier) |
| 846 | { |
| 847 | case TextureStage::MODIFIER_COLOR: |
| 848 | break; |
| 849 | case TextureStage::MODIFIER_INVCOLOR: |
| 850 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 851 | mod3.x = SubSat(Short4(0x1000), arg3->x); |
| 852 | mod3.y = SubSat(Short4(0x1000), arg3->y); |
| 853 | mod3.z = SubSat(Short4(0x1000), arg3->z); |
| 854 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 855 | |
| 856 | arg3 = &mod3; |
| 857 | } |
| 858 | break; |
| 859 | case TextureStage::MODIFIER_ALPHA: |
| 860 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 861 | mod3.x = arg3->w; |
| 862 | mod3.y = arg3->w; |
| 863 | mod3.z = arg3->w; |
| 864 | mod3.w = arg3->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 865 | |
| 866 | arg3 = &mod3; |
| 867 | } |
| 868 | break; |
| 869 | case TextureStage::MODIFIER_INVALPHA: |
| 870 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 871 | mod3.x = SubSat(Short4(0x1000), arg3->w); |
| 872 | mod3.y = SubSat(Short4(0x1000), arg3->w); |
| 873 | mod3.z = SubSat(Short4(0x1000), arg3->w); |
| 874 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 875 | |
| 876 | arg3 = &mod3; |
| 877 | } |
| 878 | break; |
| 879 | default: |
| 880 | ASSERT(false); |
| 881 | } |
| 882 | |
| 883 | switch(textureStage.stageOperation) |
| 884 | { |
| 885 | case TextureStage::STAGE_DISABLE: |
| 886 | break; |
| 887 | case TextureStage::STAGE_SELECTARG1: // Arg1 |
| 888 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 889 | res.x = arg1->x; |
| 890 | res.y = arg1->y; |
| 891 | res.z = arg1->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 892 | } |
| 893 | break; |
| 894 | case TextureStage::STAGE_SELECTARG2: // Arg2 |
| 895 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 896 | res.x = arg2->x; |
| 897 | res.y = arg2->y; |
| 898 | res.z = arg2->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 899 | } |
| 900 | break; |
| 901 | case TextureStage::STAGE_SELECTARG3: // Arg3 |
| 902 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 903 | res.x = arg3->x; |
| 904 | res.y = arg3->y; |
| 905 | res.z = arg3->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 906 | } |
| 907 | break; |
| 908 | case TextureStage::STAGE_MODULATE: // Arg1 * Arg2 |
| 909 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 910 | res.x = MulHigh(arg1->x, arg2->x) << 4; |
| 911 | res.y = MulHigh(arg1->y, arg2->y) << 4; |
| 912 | res.z = MulHigh(arg1->z, arg2->z) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 913 | } |
| 914 | break; |
| 915 | case TextureStage::STAGE_MODULATE2X: // Arg1 * Arg2 * 2 |
| 916 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 917 | res.x = MulHigh(arg1->x, arg2->x) << 5; |
| 918 | res.y = MulHigh(arg1->y, arg2->y) << 5; |
| 919 | res.z = MulHigh(arg1->z, arg2->z) << 5; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 920 | } |
| 921 | break; |
| 922 | case TextureStage::STAGE_MODULATE4X: // Arg1 * Arg2 * 4 |
| 923 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 924 | res.x = MulHigh(arg1->x, arg2->x) << 6; |
| 925 | res.y = MulHigh(arg1->y, arg2->y) << 6; |
| 926 | res.z = MulHigh(arg1->z, arg2->z) << 6; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 927 | } |
| 928 | break; |
| 929 | case TextureStage::STAGE_ADD: // Arg1 + Arg2 |
| 930 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 931 | res.x = AddSat(arg1->x, arg2->x); |
| 932 | res.y = AddSat(arg1->y, arg2->y); |
| 933 | res.z = AddSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 934 | } |
| 935 | break; |
| 936 | case TextureStage::STAGE_ADDSIGNED: // Arg1 + Arg2 - 0.5 |
| 937 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 938 | res.x = AddSat(arg1->x, arg2->x); |
| 939 | res.y = AddSat(arg1->y, arg2->y); |
| 940 | res.z = AddSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 941 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 942 | res.x = SubSat(res.x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 943 | res.y = SubSat(res.y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 944 | res.z = SubSat(res.z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 945 | } |
| 946 | break; |
| 947 | case TextureStage::STAGE_ADDSIGNED2X: // (Arg1 + Arg2 - 0.5) << 1 |
| 948 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 949 | res.x = AddSat(arg1->x, arg2->x); |
| 950 | res.y = AddSat(arg1->y, arg2->y); |
| 951 | res.z = AddSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 952 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 953 | res.x = SubSat(res.x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 954 | res.y = SubSat(res.y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 955 | res.z = SubSat(res.z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 956 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 957 | res.x = AddSat(res.x, res.x); |
| 958 | res.y = AddSat(res.y, res.y); |
| 959 | res.z = AddSat(res.z, res.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 960 | } |
| 961 | break; |
| 962 | case TextureStage::STAGE_SUBTRACT: // Arg1 - Arg2 |
| 963 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 964 | res.x = SubSat(arg1->x, arg2->x); |
| 965 | res.y = SubSat(arg1->y, arg2->y); |
| 966 | res.z = SubSat(arg1->z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 967 | } |
| 968 | break; |
| 969 | case TextureStage::STAGE_ADDSMOOTH: // Arg1 + Arg2 - Arg1 * Arg2 |
| 970 | { |
| 971 | Short4 tmp; |
| 972 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 973 | tmp = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(arg1->x, arg2->x); res.x = SubSat(res.x, tmp); |
| 974 | tmp = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(arg1->y, arg2->y); res.y = SubSat(res.y, tmp); |
| 975 | 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] | 976 | } |
| 977 | break; |
| 978 | case TextureStage::STAGE_MULTIPLYADD: // Arg3 + Arg1 * Arg2 |
| 979 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 980 | res.x = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(res.x, arg3->x); |
| 981 | res.y = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(res.y, arg3->y); |
| 982 | 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] | 983 | } |
| 984 | break; |
| 985 | case TextureStage::STAGE_LERP: // Arg3 * (Arg1 - Arg2) + Arg2 |
| 986 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 987 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, arg3->x) << 4; res.x = AddSat(res.x, arg2->x); |
| 988 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, arg3->y) << 4; res.y = AddSat(res.y, arg2->y); |
| 989 | 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] | 990 | } |
| 991 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 992 | 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] | 993 | { |
| 994 | Short4 tmp; |
| 995 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 996 | 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); |
| 997 | 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); |
| 998 | 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] | 999 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1000 | res.x = res.x << 6; |
| 1001 | res.y = res.y << 6; |
| 1002 | res.z = res.z << 6; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1003 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1004 | res.x = AddSat(res.x, res.y); |
| 1005 | res.x = AddSat(res.x, res.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1006 | |
| 1007 | // Clamp to [0, 1] |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1008 | res.x = Max(res.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1009 | res.x = Min(res.x, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1010 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1011 | res.y = res.x; |
| 1012 | res.z = res.x; |
| 1013 | res.w = res.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1014 | } |
| 1015 | break; |
| 1016 | case TextureStage::STAGE_BLENDCURRENTALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1017 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1018 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, r.current.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1019 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, r.current.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1020 | res.z = SubSat(arg1->z, arg2->z); res.z = MulHigh(res.z, r.current.w) << 4; res.z = AddSat(res.z, arg2->z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1021 | } |
| 1022 | break; |
| 1023 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1024 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1025 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, r.diffuse.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1026 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, r.diffuse.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1027 | 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] | 1028 | } |
| 1029 | break; |
| 1030 | case TextureStage::STAGE_BLENDFACTORALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1031 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1032 | 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); |
| 1033 | 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); |
| 1034 | 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] | 1035 | } |
| 1036 | break; |
| 1037 | case TextureStage::STAGE_BLENDTEXTUREALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1038 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1039 | res.x = SubSat(arg1->x, arg2->x); res.x = MulHigh(res.x, texture.w) << 4; res.x = AddSat(res.x, arg2->x); |
| 1040 | res.y = SubSat(arg1->y, arg2->y); res.y = MulHigh(res.y, texture.w) << 4; res.y = AddSat(res.y, arg2->y); |
| 1041 | 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] | 1042 | } |
| 1043 | break; |
| 1044 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: // Arg1 + Arg2 * (1 - Alpha) |
| 1045 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1046 | res.x = SubSat(Short4(0x1000), texture.w); res.x = MulHigh(res.x, arg2->x) << 4; res.x = AddSat(res.x, arg1->x); |
| 1047 | res.y = SubSat(Short4(0x1000), texture.w); res.y = MulHigh(res.y, arg2->y) << 4; res.y = AddSat(res.y, arg1->y); |
| 1048 | 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] | 1049 | } |
| 1050 | break; |
| 1051 | case TextureStage::STAGE_PREMODULATE: |
| 1052 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1053 | res.x = arg1->x; |
| 1054 | res.y = arg1->y; |
| 1055 | res.z = arg1->z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1056 | } |
| 1057 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1058 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: // Arg1 + Arg1.w * Arg2 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1059 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1060 | res.x = MulHigh(arg1->w, arg2->x) << 4; res.x = AddSat(res.x, arg1->x); |
| 1061 | res.y = MulHigh(arg1->w, arg2->y) << 4; res.y = AddSat(res.y, arg1->y); |
| 1062 | 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] | 1063 | } |
| 1064 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1065 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: // Arg1 * Arg2 + Arg1.w |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1066 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1067 | res.x = MulHigh(arg1->x, arg2->x) << 4; res.x = AddSat(res.x, arg1->w); |
| 1068 | res.y = MulHigh(arg1->y, arg2->y) << 4; res.y = AddSat(res.y, arg1->w); |
| 1069 | 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] | 1070 | } |
| 1071 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1072 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: // (1 - Arg1.w) * Arg2 + Arg1 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1073 | { |
| 1074 | Short4 tmp; |
| 1075 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1076 | res.x = AddSat(arg1->x, arg2->x); tmp = MulHigh(arg1->w, arg2->x) << 4; res.x = SubSat(res.x, tmp); |
| 1077 | res.y = AddSat(arg1->y, arg2->y); tmp = MulHigh(arg1->w, arg2->y) << 4; res.y = SubSat(res.y, tmp); |
| 1078 | 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] | 1079 | } |
| 1080 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1081 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: // (1 - Arg1) * Arg2 + Arg1.w |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1082 | { |
| 1083 | Short4 tmp; |
| 1084 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1085 | res.x = AddSat(arg1->w, arg2->x); tmp = MulHigh(arg1->x, arg2->x) << 4; res.x = SubSat(res.x, tmp); |
| 1086 | res.y = AddSat(arg1->w, arg2->y); tmp = MulHigh(arg1->y, arg2->y) << 4; res.y = SubSat(res.y, tmp); |
| 1087 | 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] | 1088 | } |
| 1089 | break; |
| 1090 | case TextureStage::STAGE_BUMPENVMAP: |
| 1091 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1092 | r.du = Float4(texture.x) * Float4(1.0f / 0x0FE0); |
| 1093 | r.dv = Float4(texture.y) * Float4(1.0f / 0x0FE0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1094 | |
| 1095 | Float4 du2; |
| 1096 | Float4 dv2; |
| 1097 | |
| 1098 | du2 = r.du; |
| 1099 | dv2 = r.dv; |
| 1100 | r.du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 1101 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 1102 | r.du += dv2; |
| 1103 | r.dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 1104 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 1105 | r.dv += du2; |
| 1106 | |
| 1107 | perturbate = true; |
| 1108 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1109 | res.x = r.current.x; |
| 1110 | res.y = r.current.y; |
| 1111 | res.z = r.current.z; |
| 1112 | res.w = r.current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1113 | } |
| 1114 | break; |
| 1115 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1116 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1117 | r.du = Float4(texture.x) * Float4(1.0f / 0x0FE0); |
| 1118 | r.dv = Float4(texture.y) * Float4(1.0f / 0x0FE0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1119 | |
| 1120 | Float4 du2; |
| 1121 | Float4 dv2; |
| 1122 | |
| 1123 | du2 = r.du; |
| 1124 | dv2 = r.dv; |
| 1125 | |
| 1126 | r.du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 1127 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 1128 | r.du += dv2; |
| 1129 | r.dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 1130 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 1131 | r.dv += du2; |
| 1132 | |
| 1133 | perturbate = true; |
| 1134 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1135 | r.L = texture.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1136 | r.L = MulHigh(r.L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceScale4))); |
| 1137 | r.L = r.L << 4; |
| 1138 | r.L = AddSat(r.L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceOffset4))); |
| 1139 | r.L = Max(r.L, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1140 | r.L = Min(r.L, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1141 | |
| 1142 | luminance = true; |
| 1143 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1144 | res.x = r.current.x; |
| 1145 | res.y = r.current.y; |
| 1146 | res.z = r.current.z; |
| 1147 | res.w = r.current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1148 | } |
| 1149 | break; |
| 1150 | default: |
| 1151 | ASSERT(false); |
| 1152 | } |
| 1153 | |
| 1154 | if(textureStage.stageOperation != TextureStage::STAGE_DOT3) |
| 1155 | { |
| 1156 | switch(textureStage.firstArgumentAlpha) |
| 1157 | { |
| 1158 | case TextureStage::SOURCE_TEXTURE: arg1 = &texture; break; |
| 1159 | case TextureStage::SOURCE_CONSTANT: arg1 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1160 | case TextureStage::SOURCE_CURRENT: arg1 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1161 | case TextureStage::SOURCE_DIFFUSE: arg1 = &r.diffuse; break; |
| 1162 | case TextureStage::SOURCE_SPECULAR: arg1 = &r.specular; break; |
| 1163 | case TextureStage::SOURCE_TEMP: arg1 = &temp; break; |
| 1164 | case TextureStage::SOURCE_TFACTOR: arg1 = &tfactor; break; |
| 1165 | default: |
| 1166 | ASSERT(false); |
| 1167 | } |
| 1168 | |
| 1169 | switch(textureStage.secondArgumentAlpha) |
| 1170 | { |
| 1171 | case TextureStage::SOURCE_TEXTURE: arg2 = &texture; break; |
| 1172 | case TextureStage::SOURCE_CONSTANT: arg2 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1173 | case TextureStage::SOURCE_CURRENT: arg2 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1174 | case TextureStage::SOURCE_DIFFUSE: arg2 = &r.diffuse; break; |
| 1175 | case TextureStage::SOURCE_SPECULAR: arg2 = &r.specular; break; |
| 1176 | case TextureStage::SOURCE_TEMP: arg2 = &temp; break; |
| 1177 | case TextureStage::SOURCE_TFACTOR: arg2 = &tfactor; break; |
| 1178 | default: |
| 1179 | ASSERT(false); |
| 1180 | } |
| 1181 | |
| 1182 | switch(textureStage.thirdArgumentAlpha) |
| 1183 | { |
| 1184 | case TextureStage::SOURCE_TEXTURE: arg3 = &texture; break; |
| 1185 | case TextureStage::SOURCE_CONSTANT: arg3 = &constant; break; |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1186 | case TextureStage::SOURCE_CURRENT: arg3 = &r.current; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1187 | case TextureStage::SOURCE_DIFFUSE: arg3 = &r.diffuse; break; |
| 1188 | case TextureStage::SOURCE_SPECULAR: arg3 = &r.specular; break; |
| 1189 | case TextureStage::SOURCE_TEMP: arg3 = &temp; break; |
| 1190 | case TextureStage::SOURCE_TFACTOR: arg3 = &tfactor; break; |
| 1191 | default: |
| 1192 | ASSERT(false); |
| 1193 | } |
| 1194 | |
| 1195 | switch(textureStage.firstModifierAlpha) // FIXME: Check if actually used |
| 1196 | { |
| 1197 | case TextureStage::MODIFIER_COLOR: |
| 1198 | break; |
| 1199 | case TextureStage::MODIFIER_INVCOLOR: |
| 1200 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1201 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1202 | |
| 1203 | arg1 = &mod1; |
| 1204 | } |
| 1205 | break; |
| 1206 | case TextureStage::MODIFIER_ALPHA: |
| 1207 | { |
| 1208 | // Redudant |
| 1209 | } |
| 1210 | break; |
| 1211 | case TextureStage::MODIFIER_INVALPHA: |
| 1212 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1213 | mod1.w = SubSat(Short4(0x1000), arg1->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1214 | |
| 1215 | arg1 = &mod1; |
| 1216 | } |
| 1217 | break; |
| 1218 | default: |
| 1219 | ASSERT(false); |
| 1220 | } |
| 1221 | |
| 1222 | switch(textureStage.secondModifierAlpha) // FIXME: Check if actually used |
| 1223 | { |
| 1224 | case TextureStage::MODIFIER_COLOR: |
| 1225 | break; |
| 1226 | case TextureStage::MODIFIER_INVCOLOR: |
| 1227 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1228 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1229 | |
| 1230 | arg2 = &mod2; |
| 1231 | } |
| 1232 | break; |
| 1233 | case TextureStage::MODIFIER_ALPHA: |
| 1234 | { |
| 1235 | // Redudant |
| 1236 | } |
| 1237 | break; |
| 1238 | case TextureStage::MODIFIER_INVALPHA: |
| 1239 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1240 | mod2.w = SubSat(Short4(0x1000), arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1241 | |
| 1242 | arg2 = &mod2; |
| 1243 | } |
| 1244 | break; |
| 1245 | default: |
| 1246 | ASSERT(false); |
| 1247 | } |
| 1248 | |
| 1249 | switch(textureStage.thirdModifierAlpha) // FIXME: Check if actually used |
| 1250 | { |
| 1251 | case TextureStage::MODIFIER_COLOR: |
| 1252 | break; |
| 1253 | case TextureStage::MODIFIER_INVCOLOR: |
| 1254 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1255 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1256 | |
| 1257 | arg3 = &mod3; |
| 1258 | } |
| 1259 | break; |
| 1260 | case TextureStage::MODIFIER_ALPHA: |
| 1261 | { |
| 1262 | // Redudant |
| 1263 | } |
| 1264 | break; |
| 1265 | case TextureStage::MODIFIER_INVALPHA: |
| 1266 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1267 | mod3.w = SubSat(Short4(0x1000), arg3->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1268 | |
| 1269 | arg3 = &mod3; |
| 1270 | } |
| 1271 | break; |
| 1272 | default: |
| 1273 | ASSERT(false); |
| 1274 | } |
| 1275 | |
| 1276 | switch(textureStage.stageOperationAlpha) |
| 1277 | { |
| 1278 | case TextureStage::STAGE_DISABLE: |
| 1279 | break; |
| 1280 | case TextureStage::STAGE_SELECTARG1: // Arg1 |
| 1281 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1282 | res.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1283 | } |
| 1284 | break; |
| 1285 | case TextureStage::STAGE_SELECTARG2: // Arg2 |
| 1286 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1287 | res.w = arg2->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1288 | } |
| 1289 | break; |
| 1290 | case TextureStage::STAGE_SELECTARG3: // Arg3 |
| 1291 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1292 | res.w = arg3->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1293 | } |
| 1294 | break; |
| 1295 | case TextureStage::STAGE_MODULATE: // Arg1 * Arg2 |
| 1296 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1297 | res.w = MulHigh(arg1->w, arg2->w) << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1298 | } |
| 1299 | break; |
| 1300 | case TextureStage::STAGE_MODULATE2X: // Arg1 * Arg2 * 2 |
| 1301 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1302 | res.w = MulHigh(arg1->w, arg2->w) << 5; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1303 | } |
| 1304 | break; |
| 1305 | case TextureStage::STAGE_MODULATE4X: // Arg1 * Arg2 * 4 |
| 1306 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1307 | res.w = MulHigh(arg1->w, arg2->w) << 6; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1308 | } |
| 1309 | break; |
| 1310 | case TextureStage::STAGE_ADD: // Arg1 + Arg2 |
| 1311 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1312 | res.w = AddSat(arg1->w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1313 | } |
| 1314 | break; |
| 1315 | case TextureStage::STAGE_ADDSIGNED: // Arg1 + Arg2 - 0.5 |
| 1316 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1317 | res.w = AddSat(arg1->w, arg2->w); |
| 1318 | res.w = SubSat(res.w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1319 | } |
| 1320 | break; |
| 1321 | case TextureStage::STAGE_ADDSIGNED2X: // (Arg1 + Arg2 - 0.5) << 1 |
| 1322 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1323 | res.w = AddSat(arg1->w, arg2->w); |
| 1324 | res.w = SubSat(res.w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 1325 | res.w = AddSat(res.w, res.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1326 | } |
| 1327 | break; |
| 1328 | case TextureStage::STAGE_SUBTRACT: // Arg1 - Arg2 |
| 1329 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1330 | res.w = SubSat(arg1->w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1331 | } |
| 1332 | break; |
| 1333 | case TextureStage::STAGE_ADDSMOOTH: // Arg1 + Arg2 - Arg1 * Arg2 |
| 1334 | { |
| 1335 | Short4 tmp; |
| 1336 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1337 | 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] | 1338 | } |
| 1339 | break; |
| 1340 | case TextureStage::STAGE_MULTIPLYADD: // Arg3 + Arg1 * Arg2 |
| 1341 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1342 | 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] | 1343 | } |
| 1344 | break; |
| 1345 | case TextureStage::STAGE_LERP: // Arg3 * (Arg1 - Arg2) + Arg2 |
| 1346 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1347 | 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] | 1348 | } |
| 1349 | break; |
| 1350 | case TextureStage::STAGE_DOT3: |
| 1351 | break; // Already computed in color channel |
| 1352 | case TextureStage::STAGE_BLENDCURRENTALPHA: // Alpha * (Arg1 - Arg2) + Arg2 |
| 1353 | { |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1354 | res.w = SubSat(arg1->w, arg2->w); res.w = MulHigh(res.w, r.current.w) << 4; res.w = AddSat(res.w, arg2->w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1355 | } |
| 1356 | break; |
| 1357 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: // Arg1 * (Alpha) + Arg2 * (1 - Alpha) |
| 1358 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1359 | 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] | 1360 | } |
| 1361 | break; |
| 1362 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1363 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1364 | 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] | 1365 | } |
| 1366 | break; |
| 1367 | case TextureStage::STAGE_BLENDTEXTUREALPHA: // Arg1 * (Alpha) + Arg2 * (1 - Alpha) |
| 1368 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1369 | 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] | 1370 | } |
| 1371 | break; |
| 1372 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: // Arg1 + Arg2 * (1 - Alpha) |
| 1373 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1374 | 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] | 1375 | } |
| 1376 | break; |
| 1377 | case TextureStage::STAGE_PREMODULATE: |
| 1378 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1379 | res.w = arg1->w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1380 | } |
| 1381 | break; |
| 1382 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1383 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1384 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1385 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1386 | case TextureStage::STAGE_BUMPENVMAP: |
| 1387 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1388 | break; // Invalid alpha operations |
| 1389 | default: |
| 1390 | ASSERT(false); |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | // Clamp result to [0, 1] |
| 1395 | |
| 1396 | switch(textureStage.stageOperation) |
| 1397 | { |
| 1398 | case TextureStage::STAGE_DISABLE: |
| 1399 | case TextureStage::STAGE_SELECTARG1: |
| 1400 | case TextureStage::STAGE_SELECTARG2: |
| 1401 | case TextureStage::STAGE_SELECTARG3: |
| 1402 | case TextureStage::STAGE_MODULATE: |
| 1403 | case TextureStage::STAGE_MODULATE2X: |
| 1404 | case TextureStage::STAGE_MODULATE4X: |
| 1405 | case TextureStage::STAGE_ADD: |
| 1406 | case TextureStage::STAGE_MULTIPLYADD: |
| 1407 | case TextureStage::STAGE_LERP: |
| 1408 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1409 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1410 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1411 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1412 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1413 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1414 | case TextureStage::STAGE_PREMODULATE: |
| 1415 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1416 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1417 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1418 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1419 | case TextureStage::STAGE_BUMPENVMAP: |
| 1420 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1421 | if(state.textureStage[stage].cantUnderflow) |
| 1422 | { |
| 1423 | break; // Can't go below zero |
| 1424 | } |
| 1425 | case TextureStage::STAGE_ADDSIGNED: |
| 1426 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1427 | case TextureStage::STAGE_SUBTRACT: |
| 1428 | case TextureStage::STAGE_ADDSMOOTH: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1429 | res.x = Max(res.x, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1430 | res.y = Max(res.y, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
| 1431 | res.z = Max(res.z, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1432 | break; |
| 1433 | default: |
| 1434 | ASSERT(false); |
| 1435 | } |
| 1436 | |
| 1437 | switch(textureStage.stageOperationAlpha) |
| 1438 | { |
| 1439 | case TextureStage::STAGE_DISABLE: |
| 1440 | case TextureStage::STAGE_SELECTARG1: |
| 1441 | case TextureStage::STAGE_SELECTARG2: |
| 1442 | case TextureStage::STAGE_SELECTARG3: |
| 1443 | case TextureStage::STAGE_MODULATE: |
| 1444 | case TextureStage::STAGE_MODULATE2X: |
| 1445 | case TextureStage::STAGE_MODULATE4X: |
| 1446 | case TextureStage::STAGE_ADD: |
| 1447 | case TextureStage::STAGE_MULTIPLYADD: |
| 1448 | case TextureStage::STAGE_LERP: |
| 1449 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1450 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1451 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1452 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1453 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1454 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1455 | case TextureStage::STAGE_PREMODULATE: |
| 1456 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1457 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
| 1458 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1459 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1460 | case TextureStage::STAGE_BUMPENVMAP: |
| 1461 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1462 | if(state.textureStage[stage].cantUnderflow) |
| 1463 | { |
| 1464 | break; // Can't go below zero |
| 1465 | } |
| 1466 | case TextureStage::STAGE_ADDSIGNED: |
| 1467 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1468 | case TextureStage::STAGE_SUBTRACT: |
| 1469 | case TextureStage::STAGE_ADDSMOOTH: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1470 | res.w = Max(res.w, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1471 | break; |
| 1472 | default: |
| 1473 | ASSERT(false); |
| 1474 | } |
| 1475 | |
| 1476 | switch(textureStage.stageOperation) |
| 1477 | { |
| 1478 | case TextureStage::STAGE_DISABLE: |
| 1479 | case TextureStage::STAGE_SELECTARG1: |
| 1480 | case TextureStage::STAGE_SELECTARG2: |
| 1481 | case TextureStage::STAGE_SELECTARG3: |
| 1482 | case TextureStage::STAGE_MODULATE: |
| 1483 | case TextureStage::STAGE_SUBTRACT: |
| 1484 | case TextureStage::STAGE_ADDSMOOTH: |
| 1485 | case TextureStage::STAGE_LERP: |
| 1486 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1487 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1488 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1489 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1490 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1491 | case TextureStage::STAGE_PREMODULATE: |
| 1492 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1493 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1494 | case TextureStage::STAGE_BUMPENVMAP: |
| 1495 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1496 | break; // Can't go above one |
| 1497 | case TextureStage::STAGE_MODULATE2X: |
| 1498 | case TextureStage::STAGE_MODULATE4X: |
| 1499 | case TextureStage::STAGE_ADD: |
| 1500 | case TextureStage::STAGE_ADDSIGNED: |
| 1501 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1502 | case TextureStage::STAGE_MULTIPLYADD: |
| 1503 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1504 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1505 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1506 | res.x = Min(res.x, Short4(0x1000)); |
| 1507 | res.y = Min(res.y, Short4(0x1000)); |
| 1508 | res.z = Min(res.z, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1509 | break; |
| 1510 | default: |
| 1511 | ASSERT(false); |
| 1512 | } |
| 1513 | |
| 1514 | switch(textureStage.stageOperationAlpha) |
| 1515 | { |
| 1516 | case TextureStage::STAGE_DISABLE: |
| 1517 | case TextureStage::STAGE_SELECTARG1: |
| 1518 | case TextureStage::STAGE_SELECTARG2: |
| 1519 | case TextureStage::STAGE_SELECTARG3: |
| 1520 | case TextureStage::STAGE_MODULATE: |
| 1521 | case TextureStage::STAGE_SUBTRACT: |
| 1522 | case TextureStage::STAGE_ADDSMOOTH: |
| 1523 | case TextureStage::STAGE_LERP: |
| 1524 | case TextureStage::STAGE_BLENDCURRENTALPHA: |
| 1525 | case TextureStage::STAGE_BLENDDIFFUSEALPHA: |
| 1526 | case TextureStage::STAGE_BLENDFACTORALPHA: |
| 1527 | case TextureStage::STAGE_BLENDTEXTUREALPHA: |
| 1528 | case TextureStage::STAGE_DOT3: // Already clamped |
| 1529 | case TextureStage::STAGE_PREMODULATE: |
| 1530 | case TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR: |
| 1531 | case TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA: |
| 1532 | case TextureStage::STAGE_BUMPENVMAP: |
| 1533 | case TextureStage::STAGE_BUMPENVMAPLUMINANCE: |
| 1534 | break; // Can't go above one |
| 1535 | case TextureStage::STAGE_MODULATE2X: |
| 1536 | case TextureStage::STAGE_MODULATE4X: |
| 1537 | case TextureStage::STAGE_ADD: |
| 1538 | case TextureStage::STAGE_ADDSIGNED: |
| 1539 | case TextureStage::STAGE_ADDSIGNED2X: |
| 1540 | case TextureStage::STAGE_MULTIPLYADD: |
| 1541 | case TextureStage::STAGE_BLENDTEXTUREALPHAPM: |
| 1542 | case TextureStage::STAGE_MODULATEALPHA_ADDCOLOR: |
| 1543 | case TextureStage::STAGE_MODULATECOLOR_ADDALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1544 | res.w = Min(res.w, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1545 | break; |
| 1546 | default: |
| 1547 | ASSERT(false); |
| 1548 | } |
| 1549 | |
| 1550 | switch(textureStage.destinationArgument) |
| 1551 | { |
| 1552 | case TextureStage::DESTINATION_CURRENT: |
Nicolas Capens | cbefe53 | 2014-10-16 00:16:01 -0400 | [diff] [blame] | 1553 | r.current.x = res.x; |
| 1554 | r.current.y = res.y; |
| 1555 | r.current.z = res.z; |
| 1556 | r.current.w = res.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1557 | break; |
| 1558 | case TextureStage::DESTINATION_TEMP: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1559 | temp.x = res.x; |
| 1560 | temp.y = res.y; |
| 1561 | temp.z = res.z; |
| 1562 | temp.w = res.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1563 | break; |
| 1564 | default: |
| 1565 | ASSERT(false); |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | void PixelRoutine::alphaTest(Registers &r, Int &aMask, Short4 &alpha) |
| 1570 | { |
| 1571 | Short4 cmp; |
| 1572 | Short4 equal; |
| 1573 | |
| 1574 | switch(state.alphaCompareMode) |
| 1575 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1576 | case ALPHA_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1577 | aMask = 0xF; |
| 1578 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1579 | case ALPHA_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1580 | aMask = 0x0; |
| 1581 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1582 | case ALPHA_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1583 | cmp = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1584 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1585 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1586 | case ALPHA_NOTEQUAL: // a != b ~ !(a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1587 | cmp = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))) ^ Short4((short)0xFFFF, (short)0xFFFF, (short)0xFFFF, (short)0xFFFF); // FIXME |
| 1588 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1589 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1590 | case ALPHA_LESS: // a < b ~ b > a |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1591 | cmp = CmpGT(*Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4)), alpha); |
| 1592 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1593 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1594 | case ALPHA_GREATEREQUAL: // a >= b ~ (a > b) || (a == b) ~ !(b > a) // TODO: Approximate |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1595 | equal = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1596 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1597 | cmp |= equal; |
| 1598 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1599 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1600 | case ALPHA_LESSEQUAL: // a <= b ~ !(a > b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1601 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))) ^ Short4((short)0xFFFF, (short)0xFFFF, (short)0xFFFF, (short)0xFFFF); // FIXME |
| 1602 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1603 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1604 | case ALPHA_GREATER: // a > b |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1605 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 1606 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 1607 | break; |
| 1608 | default: |
| 1609 | ASSERT(false); |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | void PixelRoutine::alphaToCoverage(Registers &r, Int cMask[4], Float4 &alpha) |
| 1614 | { |
| 1615 | Int4 coverage0 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c0))); |
| 1616 | Int4 coverage1 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c1))); |
| 1617 | Int4 coverage2 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c2))); |
| 1618 | Int4 coverage3 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c3))); |
| 1619 | |
| 1620 | Int aMask0 = SignMask(coverage0); |
| 1621 | Int aMask1 = SignMask(coverage1); |
| 1622 | Int aMask2 = SignMask(coverage2); |
| 1623 | Int aMask3 = SignMask(coverage3); |
| 1624 | |
| 1625 | cMask[0] &= aMask0; |
| 1626 | cMask[1] &= aMask1; |
| 1627 | cMask[2] &= aMask2; |
| 1628 | cMask[3] &= aMask3; |
| 1629 | } |
| 1630 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1631 | Bool PixelRoutine::alphaTest(Registers &r, Int cMask[4], Vector4i ¤t) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1632 | { |
| 1633 | if(!state.alphaTestActive()) |
| 1634 | { |
| 1635 | return true; |
| 1636 | } |
| 1637 | |
| 1638 | Int aMask; |
| 1639 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1640 | if(state.transparencyAntialiasing == TRANSPARENCY_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1641 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1642 | alphaTest(r, aMask, current.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1643 | |
| 1644 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 1645 | { |
| 1646 | cMask[q] &= aMask; |
| 1647 | } |
| 1648 | } |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1649 | else if(state.transparencyAntialiasing == TRANSPARENCY_ALPHA_TO_COVERAGE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1650 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1651 | Float4 alpha = Float4(current.w) * Float4(1.0f / 0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1652 | |
| 1653 | alphaToCoverage(r, cMask, alpha); |
| 1654 | } |
| 1655 | else ASSERT(false); |
| 1656 | |
| 1657 | Int pass = cMask[0]; |
| 1658 | |
| 1659 | for(unsigned int q = 1; q < state.multiSample; q++) |
| 1660 | { |
| 1661 | pass = pass | cMask[q]; |
| 1662 | } |
| 1663 | |
| 1664 | return pass != 0x0; |
| 1665 | } |
| 1666 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1667 | Bool PixelRoutine::alphaTest(Registers &r, Int cMask[4], Vector4f &c0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1668 | { |
| 1669 | if(!state.alphaTestActive()) |
| 1670 | { |
| 1671 | return true; |
| 1672 | } |
| 1673 | |
| 1674 | Int aMask; |
| 1675 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1676 | if(state.transparencyAntialiasing == TRANSPARENCY_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1677 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1678 | Short4 alpha = RoundShort4(c0.w * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1679 | |
| 1680 | alphaTest(r, aMask, alpha); |
| 1681 | |
| 1682 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 1683 | { |
| 1684 | cMask[q] &= aMask; |
| 1685 | } |
| 1686 | } |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1687 | else if(state.transparencyAntialiasing == TRANSPARENCY_ALPHA_TO_COVERAGE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1688 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1689 | alphaToCoverage(r, cMask, c0.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1690 | } |
| 1691 | else ASSERT(false); |
| 1692 | |
| 1693 | Int pass = cMask[0]; |
| 1694 | |
| 1695 | for(unsigned int q = 1; q < state.multiSample; q++) |
| 1696 | { |
| 1697 | pass = pass | cMask[q]; |
| 1698 | } |
| 1699 | |
| 1700 | return pass != 0x0; |
| 1701 | } |
| 1702 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1703 | 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] | 1704 | { |
| 1705 | if(!state.fogActive) |
| 1706 | { |
| 1707 | return; |
| 1708 | } |
| 1709 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1710 | if(state.pixelFogMode != FOG_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1711 | { |
| 1712 | pixelFog(r, f, z, rhw); |
| 1713 | } |
| 1714 | |
| 1715 | UShort4 fog = convertFixed16(f, true); |
| 1716 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1717 | current.x = As<Short4>(MulHigh(As<UShort4>(current.x), fog)); |
| 1718 | current.y = As<Short4>(MulHigh(As<UShort4>(current.y), fog)); |
| 1719 | current.z = As<Short4>(MulHigh(As<UShort4>(current.z), fog)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1720 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1721 | UShort4 invFog = UShort4(0xFFFFu) - fog; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1722 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1723 | current.x += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData,fog.color4[0])))); |
| 1724 | current.y += As<Short4>(MulHigh(invFog, *Pointer<UShort4>(r.data + OFFSET(DrawData,fog.color4[1])))); |
| 1725 | 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] | 1726 | } |
| 1727 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1728 | 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] | 1729 | { |
| 1730 | if(!state.fogActive) |
| 1731 | { |
| 1732 | return; |
| 1733 | } |
| 1734 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1735 | if(state.pixelFogMode != FOG_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1736 | { |
| 1737 | pixelFog(r, fog, z, rhw); |
| 1738 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1739 | fog = Min(fog, Float4(1.0f)); |
| 1740 | fog = Max(fog, Float4(0.0f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1741 | } |
| 1742 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1743 | c0.x -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[0])); |
| 1744 | c0.y -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[1])); |
| 1745 | c0.z -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1746 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1747 | c0.x *= fog; |
| 1748 | c0.y *= fog; |
| 1749 | c0.z *= fog; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1750 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1751 | c0.x += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[0])); |
| 1752 | c0.y += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[1])); |
| 1753 | c0.z += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void PixelRoutine::pixelFog(Registers &r, Float4 &visibility, Float4 &z, Float4 &rhw) |
| 1757 | { |
| 1758 | Float4 &zw = visibility; |
| 1759 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1760 | if(state.pixelFogMode != FOG_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1761 | { |
| 1762 | if(state.wBasedFog) |
| 1763 | { |
| 1764 | zw = rhw; |
| 1765 | } |
| 1766 | else |
| 1767 | { |
| 1768 | if(complementaryDepthBuffer) |
| 1769 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1770 | zw = Float4(1.0f) - z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1771 | } |
| 1772 | else |
| 1773 | { |
| 1774 | zw = z; |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | switch(state.pixelFogMode) |
| 1780 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1781 | case FOG_NONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1782 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1783 | case FOG_LINEAR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1784 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.scale)); |
| 1785 | zw += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.offset)); |
| 1786 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1787 | case FOG_EXP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1788 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.densityE)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1789 | zw = exponential2(zw, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1790 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1791 | case FOG_EXP2: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1792 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.densityE2)); |
| 1793 | zw *= zw; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1794 | zw = exponential2(zw, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1795 | zw = Rcp_pp(zw); |
| 1796 | break; |
| 1797 | default: |
| 1798 | ASSERT(false); |
| 1799 | } |
| 1800 | } |
| 1801 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1802 | void PixelRoutine::specularPixel(Vector4i ¤t, Vector4i &specular) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1803 | { |
| 1804 | if(!state.specularAdd) |
| 1805 | { |
| 1806 | return; |
| 1807 | } |
| 1808 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1809 | current.x = AddSat(current.x, specular.x); |
| 1810 | current.y = AddSat(current.y, specular.y); |
| 1811 | current.z = AddSat(current.z, specular.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | void PixelRoutine::writeDepth(Registers &r, Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask) |
| 1815 | { |
| 1816 | if(!state.depthWriteEnable) |
| 1817 | { |
| 1818 | return; |
| 1819 | } |
| 1820 | |
| 1821 | Float4 Z = z; |
| 1822 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1823 | if(shader && shader->depthOverride()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1824 | { |
| 1825 | if(complementaryDepthBuffer) |
| 1826 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1827 | Z = Float4(1.0f) - r.oDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1828 | } |
| 1829 | else |
| 1830 | { |
| 1831 | Z = r.oDepth; |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | Pointer<Byte> buffer; |
| 1836 | Int pitch; |
| 1837 | |
| 1838 | if(!state.quadLayoutDepthBuffer) |
| 1839 | { |
| 1840 | buffer = zBuffer + 4 * x; |
| 1841 | pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); |
| 1842 | } |
| 1843 | else |
| 1844 | { |
| 1845 | buffer = zBuffer + 8 * x; |
| 1846 | } |
| 1847 | |
| 1848 | if(q > 0) |
| 1849 | { |
| 1850 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,depthSliceB)); |
| 1851 | } |
| 1852 | |
| 1853 | Float4 zValue; |
| 1854 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1855 | if(state.depthCompareMode != DEPTH_NEVER || (state.depthCompareMode != DEPTH_ALWAYS && !state.depthWriteEnable)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1856 | { |
| 1857 | if(!state.quadLayoutDepthBuffer) |
| 1858 | { |
| 1859 | // FIXME: Properly optimizes? |
| 1860 | zValue.xy = *Pointer<Float4>(buffer); |
| 1861 | zValue.zw = *Pointer<Float4>(buffer + pitch - 8); |
| 1862 | } |
| 1863 | else |
| 1864 | { |
| 1865 | zValue = *Pointer<Float4>(buffer, 16); |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | Z = As<Float4>(As<Int4>(Z) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X) + zMask * 16, 16)); |
| 1870 | zValue = As<Float4>(As<Int4>(zValue) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X) + zMask * 16, 16)); |
| 1871 | Z = As<Float4>(As<Int4>(Z) | As<Int4>(zValue)); |
| 1872 | |
| 1873 | if(!state.quadLayoutDepthBuffer) |
| 1874 | { |
| 1875 | // FIXME: Properly optimizes? |
| 1876 | *Pointer<Float2>(buffer) = Float2(Z.xy); |
| 1877 | *Pointer<Float2>(buffer + pitch) = Float2(Z.zw); |
| 1878 | } |
| 1879 | else |
| 1880 | { |
| 1881 | *Pointer<Float4>(buffer, 16) = Z; |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | void PixelRoutine::writeStencil(Registers &r, Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &zMask, Int &cMask) |
| 1886 | { |
| 1887 | if(!state.stencilActive) |
| 1888 | { |
| 1889 | return; |
| 1890 | } |
| 1891 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1892 | if(state.stencilPassOperation == OPERATION_KEEP && state.stencilZFailOperation == OPERATION_KEEP && state.stencilFailOperation == OPERATION_KEEP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1893 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1894 | if(!state.twoSidedStencil || (state.stencilPassOperationCCW == OPERATION_KEEP && state.stencilZFailOperationCCW == OPERATION_KEEP && state.stencilFailOperationCCW == OPERATION_KEEP)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1895 | { |
| 1896 | return; |
| 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | if(state.stencilWriteMasked && (!state.twoSidedStencil || state.stencilWriteMaskedCCW)) |
| 1901 | { |
| 1902 | return; |
| 1903 | } |
| 1904 | |
| 1905 | Pointer<Byte> buffer = sBuffer + 2 * x; |
| 1906 | |
| 1907 | if(q > 0) |
| 1908 | { |
| 1909 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,stencilSliceB)); |
| 1910 | } |
| 1911 | |
| 1912 | Byte8 bufferValue = As<Byte8>(Long1(*Pointer<UInt>(buffer))); |
| 1913 | |
| 1914 | Byte8 newValue; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1915 | stencilOperation(r, newValue, bufferValue, state.stencilPassOperation, state.stencilZFailOperation, state.stencilFailOperation, false, zMask, sMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1916 | |
| 1917 | if(!state.noStencilWriteMask) |
| 1918 | { |
| 1919 | Byte8 maskedValue = bufferValue; |
| 1920 | newValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].writeMaskQ)); |
| 1921 | maskedValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].invWriteMaskQ)); |
| 1922 | newValue |= maskedValue; |
| 1923 | } |
| 1924 | |
| 1925 | if(state.twoSidedStencil) |
| 1926 | { |
| 1927 | Byte8 newValueCCW; |
| 1928 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1929 | stencilOperation(r, newValueCCW, bufferValue, state.stencilPassOperationCCW, state.stencilZFailOperationCCW, state.stencilFailOperationCCW, true, zMask, sMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1930 | |
| 1931 | if(!state.noStencilWriteMaskCCW) |
| 1932 | { |
| 1933 | Byte8 maskedValue = bufferValue; |
| 1934 | newValueCCW &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].writeMaskQ)); |
| 1935 | maskedValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].invWriteMaskQ)); |
| 1936 | newValueCCW |= maskedValue; |
| 1937 | } |
| 1938 | |
| 1939 | newValue &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,clockwiseMask)); |
| 1940 | newValueCCW &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,invClockwiseMask)); |
| 1941 | newValue |= newValueCCW; |
| 1942 | } |
| 1943 | |
| 1944 | newValue &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * cMask); |
| 1945 | bufferValue &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * cMask); |
| 1946 | newValue |= bufferValue; |
| 1947 | |
| 1948 | *Pointer<UInt>(buffer) = UInt(As<Long>(newValue)); |
| 1949 | } |
| 1950 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1951 | void PixelRoutine::stencilOperation(Registers &r, Byte8 &newValue, Byte8 &bufferValue, StencilOperation stencilPassOperation, StencilOperation stencilZFailOperation, StencilOperation stencilFailOperation, bool CCW, Int &zMask, Int &sMask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1952 | { |
| 1953 | Byte8 &pass = newValue; |
| 1954 | Byte8 fail; |
| 1955 | Byte8 zFail; |
| 1956 | |
| 1957 | stencilOperation(r, pass, bufferValue, stencilPassOperation, CCW); |
| 1958 | |
| 1959 | if(stencilZFailOperation != stencilPassOperation) |
| 1960 | { |
| 1961 | stencilOperation(r, zFail, bufferValue, stencilZFailOperation, CCW); |
| 1962 | } |
| 1963 | |
| 1964 | if(stencilFailOperation != stencilPassOperation || stencilFailOperation != stencilZFailOperation) |
| 1965 | { |
| 1966 | stencilOperation(r, fail, bufferValue, stencilFailOperation, CCW); |
| 1967 | } |
| 1968 | |
| 1969 | if(stencilFailOperation != stencilPassOperation || stencilFailOperation != stencilZFailOperation) |
| 1970 | { |
| 1971 | if(state.depthTestActive && stencilZFailOperation != stencilPassOperation) // zMask valid and values not the same |
| 1972 | { |
| 1973 | pass &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * zMask); |
| 1974 | zFail &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * zMask); |
| 1975 | pass |= zFail; |
| 1976 | } |
| 1977 | |
| 1978 | pass &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * sMask); |
| 1979 | fail &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * sMask); |
| 1980 | pass |= fail; |
| 1981 | } |
| 1982 | } |
| 1983 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1984 | void PixelRoutine::stencilOperation(Registers &r, Byte8 &output, Byte8 &bufferValue, StencilOperation operation, bool CCW) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1985 | { |
| 1986 | switch(operation) |
| 1987 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1988 | case OPERATION_KEEP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1989 | output = bufferValue; |
| 1990 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1991 | case OPERATION_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1992 | output = Byte8(0x0000000000000000); |
| 1993 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1994 | case OPERATION_REPLACE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1995 | output = *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceQ)); |
| 1996 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1997 | case OPERATION_INCRSAT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1998 | output = AddSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1)); |
| 1999 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2000 | case OPERATION_DECRSAT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2001 | output = SubSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1)); |
| 2002 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2003 | case OPERATION_INVERT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2004 | output = bufferValue ^ Byte8(0xFFFFFFFFFFFFFFFF); |
| 2005 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2006 | case OPERATION_INCR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2007 | output = bufferValue + Byte8(1, 1, 1, 1, 1, 1, 1, 1); |
| 2008 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2009 | case OPERATION_DECR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2010 | output = bufferValue - Byte8(1, 1, 1, 1, 1, 1, 1, 1); |
| 2011 | break; |
| 2012 | default: |
| 2013 | ASSERT(false); |
| 2014 | } |
| 2015 | } |
| 2016 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2017 | 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] | 2018 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2019 | Float4 u = r.vf[2 + coordinates].x; |
| 2020 | Float4 v = r.vf[2 + coordinates].y; |
| 2021 | Float4 w = r.vf[2 + coordinates].z; |
| 2022 | Float4 q = r.vf[2 + coordinates].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2023 | |
| 2024 | if(perturbate) |
| 2025 | { |
| 2026 | u += r.du; |
| 2027 | v += r.dv; |
| 2028 | |
| 2029 | perturbate = false; |
| 2030 | } |
| 2031 | |
| 2032 | sampleTexture(r, c, stage, u, v, w, q, project); |
| 2033 | } |
| 2034 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2035 | 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] | 2036 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2037 | Vector4f dsx; |
| 2038 | Vector4f dsy; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2039 | |
| 2040 | sampleTexture(r, c, stage, u, v, w, q, dsx, dsy, project, bias, fixed12, false); |
| 2041 | } |
| 2042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2043 | 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] | 2044 | { |
| 2045 | #if PERF_PROFILE |
| 2046 | Long texTime = Ticks(); |
| 2047 | #endif |
| 2048 | |
| 2049 | Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap) + stage * sizeof(Texture); |
| 2050 | |
| 2051 | if(!project) |
| 2052 | { |
| 2053 | sampler[stage]->sampleTexture(texture, c, u, v, w, q, dsx, dsy, bias, fixed12, gradients, lodProvided); |
| 2054 | } |
| 2055 | else |
| 2056 | { |
| 2057 | Float4 rq = reciprocal(q); |
| 2058 | |
| 2059 | Float4 u_q = u * rq; |
| 2060 | Float4 v_q = v * rq; |
| 2061 | Float4 w_q = w * rq; |
| 2062 | |
| 2063 | sampler[stage]->sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy, bias, fixed12, gradients, lodProvided); |
| 2064 | } |
| 2065 | |
| 2066 | #if PERF_PROFILE |
| 2067 | r.cycles[PERF_TEX] += Ticks() - texTime; |
| 2068 | #endif |
| 2069 | } |
| 2070 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2071 | 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) |
| 2072 | { |
| 2073 | if(sampler.type == Shader::PARAMETER_SAMPLER && sampler.rel.type == Shader::PARAMETER_VOID) |
| 2074 | { |
| 2075 | sampleTexture(r, c, sampler.index, u, v, w, q, dsx, dsy, project, bias, gradients, lodProvided); |
| 2076 | } |
| 2077 | else |
| 2078 | { |
| 2079 | Int index = As<Int>(Float(reg(r, sampler).x.x)); |
| 2080 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame^] | 2081 | for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2082 | { |
| 2083 | if(shader->usesSampler(i)) |
| 2084 | { |
| 2085 | If(index == i) |
| 2086 | { |
| 2087 | sampleTexture(r, c, i, u, v, w, q, dsx, dsy, project, bias, gradients, lodProvided); |
| 2088 | // FIXME: When the sampler states are the same, we could use one sampler and just index the texture |
| 2089 | } |
| 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | 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] | 2096 | { |
| 2097 | #if PERF_PROFILE |
| 2098 | Long texTime = Ticks(); |
| 2099 | #endif |
| 2100 | |
| 2101 | Pointer<Byte> texture = r.data + OFFSET(DrawData,mipmap) + stage * sizeof(Texture); |
| 2102 | |
| 2103 | if(!project) |
| 2104 | { |
| 2105 | sampler[stage]->sampleTexture(texture, c, u, v, w, q, dsx, dsy, bias, gradients, lodProvided); |
| 2106 | } |
| 2107 | else |
| 2108 | { |
| 2109 | Float4 rq = reciprocal(q); |
| 2110 | |
| 2111 | Float4 u_q = u * rq; |
| 2112 | Float4 v_q = v * rq; |
| 2113 | Float4 w_q = w * rq; |
| 2114 | |
| 2115 | sampler[stage]->sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy, bias, gradients, lodProvided); |
| 2116 | } |
| 2117 | |
| 2118 | #if PERF_PROFILE |
| 2119 | r.cycles[PERF_TEX] += Ticks() - texTime; |
| 2120 | #endif |
| 2121 | } |
| 2122 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2123 | void PixelRoutine::clampColor(Vector4f oC[4]) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2124 | { |
| 2125 | for(int index = 0; index < 4; index++) |
| 2126 | { |
| 2127 | if(!state.colorWriteActive(index) && !(index == 0 && state.alphaTestActive())) |
| 2128 | { |
| 2129 | continue; |
| 2130 | } |
| 2131 | |
| 2132 | switch(state.targetFormat[index]) |
| 2133 | { |
| 2134 | case FORMAT_NULL: |
| 2135 | break; |
| 2136 | case FORMAT_A16B16G16R16: |
| 2137 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2138 | case FORMAT_A8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2139 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2140 | case FORMAT_X8B8G8R8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2141 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2142 | case FORMAT_G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2143 | oC[index].x = Max(oC[index].x, Float4(0.0f)); oC[index].x = Min(oC[index].x, Float4(1.0f)); |
| 2144 | oC[index].y = Max(oC[index].y, Float4(0.0f)); oC[index].y = Min(oC[index].y, Float4(1.0f)); |
| 2145 | oC[index].z = Max(oC[index].z, Float4(0.0f)); oC[index].z = Min(oC[index].z, Float4(1.0f)); |
| 2146 | 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] | 2147 | break; |
| 2148 | case FORMAT_R32F: |
| 2149 | case FORMAT_G32R32F: |
| 2150 | case FORMAT_A32B32G32R32F: |
| 2151 | break; |
| 2152 | default: |
| 2153 | ASSERT(false); |
| 2154 | } |
| 2155 | } |
| 2156 | } |
| 2157 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2158 | 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] | 2159 | { |
| 2160 | if(!state.colorWriteActive(0)) |
| 2161 | { |
| 2162 | return; |
| 2163 | } |
| 2164 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2165 | Vector4f oC; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2166 | |
| 2167 | switch(state.targetFormat[0]) |
| 2168 | { |
| 2169 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2170 | case FORMAT_X8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2171 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2172 | case FORMAT_A8B8G8R8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2173 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2174 | case FORMAT_G16R16: |
| 2175 | case FORMAT_A16B16G16R16: |
| 2176 | if(!postBlendSRGB && state.writeSRGB) |
| 2177 | { |
| 2178 | linearToSRGB12_16(r, current); |
| 2179 | } |
| 2180 | else |
| 2181 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2182 | current.x <<= 4; |
| 2183 | current.y <<= 4; |
| 2184 | current.z <<= 4; |
| 2185 | current.w <<= 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | fogBlend(r, current, fog, r.z[0], r.rhw); |
| 2189 | |
| 2190 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2191 | { |
| 2192 | 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] | 2193 | Vector4i color = current; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2194 | |
| 2195 | if(state.multiSampleMask & (1 << q)) |
| 2196 | { |
| 2197 | alphaBlend(r, 0, buffer, color, x); |
| 2198 | writeColor(r, 0, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2199 | } |
| 2200 | } |
| 2201 | break; |
| 2202 | case FORMAT_R32F: |
| 2203 | case FORMAT_G32R32F: |
| 2204 | case FORMAT_A32B32G32R32F: |
| 2205 | convertSigned12(oC, current); |
| 2206 | fogBlend(r, oC, fog, r.z[0], r.rhw); |
| 2207 | |
| 2208 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2209 | { |
| 2210 | 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] | 2211 | Vector4f color = oC; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2212 | |
| 2213 | if(state.multiSampleMask & (1 << q)) |
| 2214 | { |
| 2215 | alphaBlend(r, 0, buffer, color, x); |
| 2216 | writeColor(r, 0, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2217 | } |
| 2218 | } |
| 2219 | break; |
| 2220 | default: |
| 2221 | ASSERT(false); |
| 2222 | } |
| 2223 | } |
| 2224 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2225 | 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] | 2226 | { |
| 2227 | for(int index = 0; index < 4; index++) |
| 2228 | { |
| 2229 | if(!state.colorWriteActive(index)) |
| 2230 | { |
| 2231 | continue; |
| 2232 | } |
| 2233 | |
| 2234 | if(!postBlendSRGB && state.writeSRGB) |
| 2235 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2236 | oC[index].x = linearToSRGB(oC[index].x); |
| 2237 | oC[index].y = linearToSRGB(oC[index].y); |
| 2238 | oC[index].z = linearToSRGB(oC[index].z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | if(index == 0) |
| 2242 | { |
| 2243 | fogBlend(r, oC[index], fog, r.z[0], r.rhw); |
| 2244 | } |
| 2245 | |
| 2246 | switch(state.targetFormat[index]) |
| 2247 | { |
| 2248 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2249 | case FORMAT_X8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2250 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2251 | case FORMAT_A8B8G8R8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2252 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2253 | case FORMAT_G16R16: |
| 2254 | case FORMAT_A16B16G16R16: |
| 2255 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2256 | { |
| 2257 | 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] | 2258 | Vector4i color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2259 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2260 | color.x = convertFixed16(oC[index].x, false); |
| 2261 | color.y = convertFixed16(oC[index].y, false); |
| 2262 | color.z = convertFixed16(oC[index].z, false); |
| 2263 | color.w = convertFixed16(oC[index].w, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2264 | |
| 2265 | if(state.multiSampleMask & (1 << q)) |
| 2266 | { |
| 2267 | alphaBlend(r, index, buffer, color, x); |
| 2268 | writeColor(r, index, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2269 | } |
| 2270 | } |
| 2271 | break; |
| 2272 | case FORMAT_R32F: |
| 2273 | case FORMAT_G32R32F: |
| 2274 | case FORMAT_A32B32G32R32F: |
| 2275 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 2276 | { |
| 2277 | 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] | 2278 | Vector4f color = oC[index]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2279 | |
| 2280 | if(state.multiSampleMask & (1 << q)) |
| 2281 | { |
| 2282 | alphaBlend(r, index, buffer, color, x); |
| 2283 | writeColor(r, index, buffer, x, color, sMask[q], zMask[q], cMask[q]); |
| 2284 | } |
| 2285 | } |
| 2286 | break; |
| 2287 | default: |
| 2288 | ASSERT(false); |
| 2289 | } |
| 2290 | } |
| 2291 | } |
| 2292 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2293 | void PixelRoutine::blendFactor(Registers &r, const Vector4i &blendFactor, const Vector4i ¤t, const Vector4i &pixel, BlendFactor blendFactorActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2294 | { |
| 2295 | switch(blendFactorActive) |
| 2296 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2297 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2298 | // Optimized |
| 2299 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2300 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2301 | // Optimized |
| 2302 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2303 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2304 | blendFactor.x = current.x; |
| 2305 | blendFactor.y = current.y; |
| 2306 | blendFactor.z = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2307 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2308 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2309 | blendFactor.x = Short4(0xFFFFu) - current.x; |
| 2310 | blendFactor.y = Short4(0xFFFFu) - current.y; |
| 2311 | blendFactor.z = Short4(0xFFFFu) - current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2312 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2313 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2314 | blendFactor.x = pixel.x; |
| 2315 | blendFactor.y = pixel.y; |
| 2316 | blendFactor.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2317 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2318 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2319 | blendFactor.x = Short4(0xFFFFu) - pixel.x; |
| 2320 | blendFactor.y = Short4(0xFFFFu) - pixel.y; |
| 2321 | blendFactor.z = Short4(0xFFFFu) - pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2322 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2323 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2324 | blendFactor.x = current.w; |
| 2325 | blendFactor.y = current.w; |
| 2326 | blendFactor.z = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2327 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2328 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2329 | blendFactor.x = Short4(0xFFFFu) - current.w; |
| 2330 | blendFactor.y = Short4(0xFFFFu) - current.w; |
| 2331 | blendFactor.z = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2332 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2333 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2334 | blendFactor.x = pixel.w; |
| 2335 | blendFactor.y = pixel.w; |
| 2336 | blendFactor.z = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2337 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2338 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2339 | blendFactor.x = Short4(0xFFFFu) - pixel.w; |
| 2340 | blendFactor.y = Short4(0xFFFFu) - pixel.w; |
| 2341 | blendFactor.z = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2342 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2343 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2344 | blendFactor.x = Short4(0xFFFFu) - pixel.w; |
| 2345 | blendFactor.x = Min(As<UShort4>(blendFactor.x), As<UShort4>(current.w)); |
| 2346 | blendFactor.y = blendFactor.x; |
| 2347 | blendFactor.z = blendFactor.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2348 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2349 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2350 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[0])); |
| 2351 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[1])); |
| 2352 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2353 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2354 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2355 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[0])); |
| 2356 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[1])); |
| 2357 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2358 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2359 | case BLEND_CONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2360 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
| 2361 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
| 2362 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2363 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2364 | case BLEND_INVCONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2365 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
| 2366 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
| 2367 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2368 | break; |
| 2369 | default: |
| 2370 | ASSERT(false); |
| 2371 | } |
| 2372 | } |
| 2373 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2374 | void PixelRoutine::blendFactorAlpha(Registers &r, const Vector4i &blendFactor, const Vector4i ¤t, const Vector4i &pixel, BlendFactor blendFactorAlphaActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2375 | { |
| 2376 | switch(blendFactorAlphaActive) |
| 2377 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2378 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2379 | // Optimized |
| 2380 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2381 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2382 | // Optimized |
| 2383 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2384 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2385 | blendFactor.w = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2386 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2387 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2388 | blendFactor.w = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2389 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2390 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2391 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2392 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2393 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2394 | blendFactor.w = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2395 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2396 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2397 | blendFactor.w = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2398 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2399 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2400 | blendFactor.w = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2401 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2402 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2403 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2404 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2405 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2406 | blendFactor.w = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2407 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2408 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2409 | blendFactor.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2410 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2411 | case BLEND_CONSTANT: |
| 2412 | case BLEND_CONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2413 | blendFactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2414 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2415 | case BLEND_INVCONSTANT: |
| 2416 | case BLEND_INVCONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2417 | blendFactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2418 | break; |
| 2419 | default: |
| 2420 | ASSERT(false); |
| 2421 | } |
| 2422 | } |
| 2423 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2424 | 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] | 2425 | { |
| 2426 | if(!state.alphaBlendActive) |
| 2427 | { |
| 2428 | return; |
| 2429 | } |
| 2430 | |
| 2431 | Pointer<Byte> buffer; |
| 2432 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2433 | Vector4i pixel; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2434 | Short4 c01; |
| 2435 | Short4 c23; |
| 2436 | |
| 2437 | // Read pixel |
| 2438 | switch(state.targetFormat[index]) |
| 2439 | { |
| 2440 | case FORMAT_A8R8G8B8: |
| 2441 | buffer = cBuffer + 4 * x; |
| 2442 | c01 = *Pointer<Short4>(buffer); |
| 2443 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2444 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2445 | pixel.z = c01; |
| 2446 | pixel.y = c01; |
| 2447 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2448 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2449 | pixel.x = pixel.z; |
| 2450 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2451 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2452 | pixel.y = pixel.z; |
| 2453 | pixel.w = pixel.x; |
| 2454 | pixel.x = UnpackLow(As<Byte8>(pixel.x), As<Byte8>(pixel.x)); |
| 2455 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2456 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2457 | pixel.w = UnpackHigh(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2458 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2459 | case FORMAT_A8B8G8R8: |
| 2460 | buffer = cBuffer + 4 * x; |
| 2461 | c01 = *Pointer<Short4>(buffer); |
| 2462 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2463 | c23 = *Pointer<Short4>(buffer); |
| 2464 | pixel.z = c01; |
| 2465 | pixel.y = c01; |
| 2466 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2467 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2468 | pixel.x = pixel.z; |
| 2469 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2470 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2471 | pixel.y = pixel.z; |
| 2472 | pixel.w = pixel.x; |
| 2473 | pixel.x = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2474 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2475 | pixel.z = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2476 | pixel.w = UnpackHigh(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2477 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2478 | case FORMAT_A8: |
| 2479 | buffer = cBuffer + 1 * x; |
| 2480 | pixel.w = Insert(pixel.w, *Pointer<Short>(buffer), 0); |
| 2481 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2482 | pixel.w = Insert(pixel.w, *Pointer<Short>(buffer), 1); |
| 2483 | pixel.w = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2484 | pixel.x = Short4(0x0000); |
| 2485 | pixel.y = Short4(0x0000); |
| 2486 | pixel.z = Short4(0x0000); |
| 2487 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2488 | case FORMAT_X8R8G8B8: |
| 2489 | buffer = cBuffer + 4 * x; |
| 2490 | c01 = *Pointer<Short4>(buffer); |
| 2491 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2492 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2493 | pixel.z = c01; |
| 2494 | pixel.y = c01; |
| 2495 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2496 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2497 | pixel.x = pixel.z; |
| 2498 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2499 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2500 | pixel.y = pixel.z; |
| 2501 | pixel.x = UnpackLow(As<Byte8>(pixel.x), As<Byte8>(pixel.x)); |
| 2502 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2503 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2504 | pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2505 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2506 | case FORMAT_X8B8G8R8: |
| 2507 | buffer = cBuffer + 4 * x; |
| 2508 | c01 = *Pointer<Short4>(buffer); |
| 2509 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2510 | c23 = *Pointer<Short4>(buffer); |
| 2511 | pixel.z = c01; |
| 2512 | pixel.y = c01; |
| 2513 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 2514 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 2515 | pixel.x = pixel.z; |
| 2516 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 2517 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 2518 | pixel.y = pixel.z; |
| 2519 | pixel.w = pixel.x; |
| 2520 | pixel.x = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 2521 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 2522 | pixel.z = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 2523 | pixel.w = Short4(0xFFFFu); |
| 2524 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2525 | case FORMAT_A8G8R8B8Q: |
| 2526 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2527 | // pixel.z = UnpackLow(As<Byte8>(pixel.z), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2528 | // pixel.x = UnpackHigh(As<Byte8>(pixel.x), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2529 | // pixel.y = UnpackLow(As<Byte8>(pixel.y), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
| 2530 | // 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] | 2531 | break; |
| 2532 | case FORMAT_X8G8R8B8Q: |
| 2533 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2534 | // pixel.z = UnpackLow(As<Byte8>(pixel.z), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2535 | // pixel.x = UnpackHigh(As<Byte8>(pixel.x), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 2536 | // pixel.y = UnpackLow(As<Byte8>(pixel.y), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
| 2537 | // pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2538 | break; |
| 2539 | case FORMAT_A16B16G16R16: |
| 2540 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2541 | pixel.x = *Pointer<Short4>(buffer + 8 * x); |
| 2542 | pixel.y = *Pointer<Short4>(buffer + 8 * x + 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2543 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2544 | pixel.z = *Pointer<Short4>(buffer + 8 * x); |
| 2545 | pixel.w = *Pointer<Short4>(buffer + 8 * x + 8); |
| 2546 | transpose4x4(pixel.x, pixel.y, pixel.z, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2547 | break; |
| 2548 | case FORMAT_G16R16: |
| 2549 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2550 | pixel.x = *Pointer<Short4>(buffer + 4 * x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2551 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2552 | pixel.y = *Pointer<Short4>(buffer + 4 * x); |
| 2553 | pixel.z = pixel.x; |
| 2554 | pixel.x = As<Short4>(UnpackLow(pixel.x, pixel.y)); |
| 2555 | pixel.z = As<Short4>(UnpackHigh(pixel.z, pixel.y)); |
| 2556 | pixel.y = pixel.z; |
| 2557 | pixel.x = As<Short4>(UnpackLow(pixel.x, pixel.z)); |
| 2558 | pixel.y = As<Short4>(UnpackHigh(pixel.y, pixel.z)); |
| 2559 | pixel.z = Short4(0xFFFFu); |
| 2560 | pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2561 | break; |
| 2562 | default: |
| 2563 | ASSERT(false); |
| 2564 | } |
| 2565 | |
| 2566 | if(postBlendSRGB && state.writeSRGB) |
| 2567 | { |
| 2568 | sRGBtoLinear16_16(r, pixel); |
| 2569 | } |
| 2570 | |
| 2571 | // Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2572 | Vector4i sourceFactor; |
| 2573 | Vector4i destFactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2574 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2575 | blendFactor(r, sourceFactor, current, pixel, state.sourceBlendFactor); |
| 2576 | blendFactor(r, destFactor, current, pixel, state.destBlendFactor); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2577 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2578 | if(state.sourceBlendFactor != BLEND_ONE && state.sourceBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2579 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2580 | current.x = MulHigh(As<UShort4>(current.x), As<UShort4>(sourceFactor.x)); |
| 2581 | current.y = MulHigh(As<UShort4>(current.y), As<UShort4>(sourceFactor.y)); |
| 2582 | current.z = MulHigh(As<UShort4>(current.z), As<UShort4>(sourceFactor.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2583 | } |
| 2584 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2585 | if(state.destBlendFactor != BLEND_ONE && state.destBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2586 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2587 | pixel.x = MulHigh(As<UShort4>(pixel.x), As<UShort4>(destFactor.x)); |
| 2588 | pixel.y = MulHigh(As<UShort4>(pixel.y), As<UShort4>(destFactor.y)); |
| 2589 | pixel.z = MulHigh(As<UShort4>(pixel.z), As<UShort4>(destFactor.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | switch(state.blendOperation) |
| 2593 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2594 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2595 | current.x = AddSat(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2596 | current.y = AddSat(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2597 | current.z = AddSat(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2598 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2599 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2600 | current.x = SubSat(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2601 | current.y = SubSat(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2602 | current.z = SubSat(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2603 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2604 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2605 | current.x = SubSat(As<UShort4>(pixel.x), As<UShort4>(current.x)); |
| 2606 | current.y = SubSat(As<UShort4>(pixel.y), As<UShort4>(current.y)); |
| 2607 | current.z = SubSat(As<UShort4>(pixel.z), As<UShort4>(current.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2608 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2609 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2610 | current.x = Min(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2611 | current.y = Min(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2612 | current.z = Min(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2613 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2614 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2615 | current.x = Max(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 2616 | current.y = Max(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 2617 | current.z = Max(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2618 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2619 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2620 | // No operation |
| 2621 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2622 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2623 | current.x = pixel.x; |
| 2624 | current.y = pixel.y; |
| 2625 | current.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2626 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2627 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2628 | current.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 2629 | current.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 2630 | current.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2631 | break; |
| 2632 | default: |
| 2633 | ASSERT(false); |
| 2634 | } |
| 2635 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2636 | blendFactorAlpha(r, sourceFactor, current, pixel, state.sourceBlendFactorAlpha); |
| 2637 | blendFactorAlpha(r, destFactor, current, pixel, state.destBlendFactorAlpha); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2638 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2639 | if(state.sourceBlendFactorAlpha != BLEND_ONE && state.sourceBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2640 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2641 | current.w = MulHigh(As<UShort4>(current.w), As<UShort4>(sourceFactor.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2642 | } |
| 2643 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2644 | if(state.destBlendFactorAlpha != BLEND_ONE && state.destBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2645 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2646 | pixel.w = MulHigh(As<UShort4>(pixel.w), As<UShort4>(destFactor.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | switch(state.blendOperationAlpha) |
| 2650 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2651 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2652 | current.w = AddSat(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2653 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2654 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2655 | current.w = SubSat(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2656 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2657 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2658 | current.w = SubSat(As<UShort4>(pixel.w), As<UShort4>(current.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2659 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2660 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2661 | current.w = Min(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2662 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2663 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2664 | current.w = Max(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2665 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2666 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2667 | // No operation |
| 2668 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2669 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2670 | current.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2671 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2672 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2673 | current.w = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2674 | break; |
| 2675 | default: |
| 2676 | ASSERT(false); |
| 2677 | } |
| 2678 | } |
| 2679 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2680 | 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] | 2681 | { |
| 2682 | if(!state.colorWriteActive(index)) |
| 2683 | { |
| 2684 | return; |
| 2685 | } |
| 2686 | |
| 2687 | if(postBlendSRGB && state.writeSRGB) |
| 2688 | { |
| 2689 | linearToSRGB16_16(r, current); |
| 2690 | } |
| 2691 | |
| 2692 | if(exactColorRounding) |
| 2693 | { |
| 2694 | switch(state.targetFormat[index]) |
| 2695 | { |
| 2696 | case FORMAT_X8G8R8B8Q: |
| 2697 | case FORMAT_A8G8R8B8Q: |
| 2698 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2699 | case FORMAT_X8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2700 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2701 | case FORMAT_A8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2702 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2703 | current.x = current.x - As<Short4>(As<UShort4>(current.x) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2704 | current.y = current.y - As<Short4>(As<UShort4>(current.y) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2705 | current.z = current.z - As<Short4>(As<UShort4>(current.z) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 2706 | 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] | 2707 | } |
| 2708 | break; |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | int rgbaWriteMask = state.colorWriteActive(index); |
| 2713 | int bgraWriteMask = rgbaWriteMask & 0x0000000A | (rgbaWriteMask & 0x00000001) << 2 | (rgbaWriteMask & 0x00000004) >> 2; |
| 2714 | int brgaWriteMask = rgbaWriteMask & 0x00000008 | (rgbaWriteMask & 0x00000001) << 1 | (rgbaWriteMask & 0x00000002) << 1 | (rgbaWriteMask & 0x00000004) >> 2; |
| 2715 | |
| 2716 | switch(state.targetFormat[index]) |
| 2717 | { |
| 2718 | case FORMAT_X8G8R8B8Q: |
| 2719 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2720 | // current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2721 | // current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2722 | // current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2723 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2724 | // current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2725 | // 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] | 2726 | break; |
| 2727 | case FORMAT_A8G8R8B8Q: |
| 2728 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2729 | // current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2730 | // current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2731 | // current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2732 | // current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2733 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2734 | // current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2735 | // 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] | 2736 | break; |
| 2737 | case FORMAT_X8R8G8B8: |
| 2738 | case FORMAT_A8R8G8B8: |
| 2739 | if(state.targetFormat[index] == FORMAT_X8R8G8B8 || rgbaWriteMask == 0x7) |
| 2740 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2741 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2742 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2743 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2744 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2745 | current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2746 | 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] | 2747 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2748 | current.x = current.z; |
| 2749 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2750 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2751 | current.y = current.z; |
| 2752 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2753 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2754 | } |
| 2755 | else |
| 2756 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2757 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2758 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2759 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2760 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2761 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2762 | current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 2763 | 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] | 2764 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2765 | current.x = current.z; |
| 2766 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2767 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2768 | current.y = current.z; |
| 2769 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2770 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2771 | } |
| 2772 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2773 | case FORMAT_X8B8G8R8: |
| 2774 | case FORMAT_A8B8G8R8: |
| 2775 | if(state.targetFormat[index] == FORMAT_X8B8G8R8 || rgbaWriteMask == 0x7) |
| 2776 | { |
| 2777 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2778 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2779 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2780 | |
| 2781 | current.z = As<Short4>(Pack(As<UShort4>(current.x), As<UShort4>(current.z))); |
| 2782 | current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.y))); |
| 2783 | |
| 2784 | current.x = current.z; |
| 2785 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2786 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2787 | current.y = current.z; |
| 2788 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2789 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
| 2790 | } |
| 2791 | else |
| 2792 | { |
| 2793 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 2794 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 2795 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 2796 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
| 2797 | |
| 2798 | current.z = As<Short4>(Pack(As<UShort4>(current.x), As<UShort4>(current.z))); |
| 2799 | current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.w))); |
| 2800 | |
| 2801 | current.x = current.z; |
| 2802 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 2803 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 2804 | current.y = current.z; |
| 2805 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 2806 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
| 2807 | } |
| 2808 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2809 | case FORMAT_A8: |
| 2810 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
| 2811 | current.w = As<Short4>(Pack(As<UShort4>(current.w), As<UShort4>(current.w))); |
| 2812 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2813 | case FORMAT_G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2814 | current.z = current.x; |
| 2815 | current.x = As<Short4>(UnpackLow(current.x, current.y)); |
| 2816 | current.z = As<Short4>(UnpackHigh(current.z, current.y)); |
| 2817 | current.y = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2818 | break; |
| 2819 | case FORMAT_A16B16G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2820 | transpose4x4(current.x, current.y, current.z, current.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2821 | break; |
| 2822 | case FORMAT_R32F: |
| 2823 | case FORMAT_G32R32F: |
| 2824 | case FORMAT_A32B32G32R32F: |
| 2825 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2826 | Vector4f oC; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2827 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2828 | oC.x = convertUnsigned16(UShort4(current.x)); |
| 2829 | oC.y = convertUnsigned16(UShort4(current.y)); |
| 2830 | oC.z = convertUnsigned16(UShort4(current.z)); |
| 2831 | oC.w = convertUnsigned16(UShort4(current.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2832 | |
| 2833 | writeColor(r, index, cBuffer, x, oC, sMask, zMask, cMask); |
| 2834 | } |
| 2835 | return; |
| 2836 | default: |
| 2837 | ASSERT(false); |
| 2838 | } |
| 2839 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2840 | Short4 c01 = current.z; |
| 2841 | Short4 c23 = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2842 | |
| 2843 | Int xMask; // Combination of all masks |
| 2844 | |
| 2845 | if(state.depthTestActive) |
| 2846 | { |
| 2847 | xMask = zMask; |
| 2848 | } |
| 2849 | else |
| 2850 | { |
| 2851 | xMask = cMask; |
| 2852 | } |
| 2853 | |
| 2854 | if(state.stencilActive) |
| 2855 | { |
| 2856 | xMask &= sMask; |
| 2857 | } |
| 2858 | |
| 2859 | Pointer<Byte> buffer; |
| 2860 | Short4 value; |
| 2861 | |
| 2862 | switch(state.targetFormat[index]) |
| 2863 | { |
| 2864 | case FORMAT_A8G8R8B8Q: |
| 2865 | case FORMAT_X8G8R8B8Q: // FIXME: Don't touch alpha? |
| 2866 | UNIMPLEMENTED(); |
| 2867 | // value = *Pointer<Short4>(cBuffer + 8 * x + 0); |
| 2868 | |
| 2869 | // if((state.targetFormat[index] == FORMAT_A8G8R8B8Q && bgraWriteMask != 0x0000000F) || |
| 2870 | // ((state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x00000007) && |
| 2871 | // (state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 2872 | // { |
| 2873 | // Short4 masked = value; |
| 2874 | // c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 2875 | // masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 2876 | // c01 |= masked; |
| 2877 | // } |
| 2878 | |
| 2879 | // c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 2880 | // value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 2881 | // c01 |= value; |
| 2882 | // *Pointer<Short4>(cBuffer + 8 * x + 0) = c01; |
| 2883 | |
| 2884 | // value = *Pointer<Short4>(cBuffer + 8 * x + 8); |
| 2885 | |
| 2886 | // if((state.targetFormat[index] == FORMAT_A8G8R8B8Q && bgraWriteMask != 0x0000000F) || |
| 2887 | // ((state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x00000007) && |
| 2888 | // (state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 2889 | // { |
| 2890 | // Short4 masked = value; |
| 2891 | // c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 2892 | // masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 2893 | // c23 |= masked; |
| 2894 | // } |
| 2895 | |
| 2896 | // c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 2897 | // value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 2898 | // c23 |= value; |
| 2899 | // *Pointer<Short4>(cBuffer + 8 * x + 8) = c23; |
| 2900 | break; |
| 2901 | case FORMAT_A8R8G8B8: |
| 2902 | case FORMAT_X8R8G8B8: // FIXME: Don't touch alpha? |
| 2903 | buffer = cBuffer + x * 4; |
| 2904 | value = *Pointer<Short4>(buffer); |
| 2905 | |
| 2906 | if((state.targetFormat[index] == FORMAT_A8R8G8B8 && bgraWriteMask != 0x0000000F) || |
| 2907 | ((state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x00000007) && |
| 2908 | (state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 2909 | { |
| 2910 | Short4 masked = value; |
| 2911 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 2912 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 2913 | c01 |= masked; |
| 2914 | } |
| 2915 | |
| 2916 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 2917 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 2918 | c01 |= value; |
| 2919 | *Pointer<Short4>(buffer) = c01; |
| 2920 | |
| 2921 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2922 | value = *Pointer<Short4>(buffer); |
| 2923 | |
| 2924 | if((state.targetFormat[index] == FORMAT_A8R8G8B8 && bgraWriteMask != 0x0000000F) || |
| 2925 | ((state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x00000007) && |
| 2926 | (state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 2927 | { |
| 2928 | Short4 masked = value; |
| 2929 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 2930 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 2931 | c23 |= masked; |
| 2932 | } |
| 2933 | |
| 2934 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 2935 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 2936 | c23 |= value; |
| 2937 | *Pointer<Short4>(buffer) = c23; |
| 2938 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 2939 | case FORMAT_A8B8G8R8: |
| 2940 | case FORMAT_X8B8G8R8: // FIXME: Don't touch alpha? |
| 2941 | buffer = cBuffer + x * 4; |
| 2942 | value = *Pointer<Short4>(buffer); |
| 2943 | |
| 2944 | if((state.targetFormat[index] == FORMAT_A8B8G8R8 && rgbaWriteMask != 0x0000000F) || |
| 2945 | ((state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x00000007) && |
| 2946 | (state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x0000000F))) // FIXME: Need for masking when XBGR && Fh? |
| 2947 | { |
| 2948 | Short4 masked = value; |
| 2949 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[rgbaWriteMask][0])); |
| 2950 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[rgbaWriteMask][0])); |
| 2951 | c01 |= masked; |
| 2952 | } |
| 2953 | |
| 2954 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 2955 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 2956 | c01 |= value; |
| 2957 | *Pointer<Short4>(buffer) = c01; |
| 2958 | |
| 2959 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2960 | value = *Pointer<Short4>(buffer); |
| 2961 | |
| 2962 | if((state.targetFormat[index] == FORMAT_A8B8G8R8 && rgbaWriteMask != 0x0000000F) || |
| 2963 | ((state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x00000007) && |
| 2964 | (state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x0000000F))) // FIXME: Need for masking when XBGR && Fh? |
| 2965 | { |
| 2966 | Short4 masked = value; |
| 2967 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[rgbaWriteMask][0])); |
| 2968 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[rgbaWriteMask][0])); |
| 2969 | c23 |= masked; |
| 2970 | } |
| 2971 | |
| 2972 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 2973 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 2974 | c23 |= value; |
| 2975 | *Pointer<Short4>(buffer) = c23; |
| 2976 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2977 | case FORMAT_A8: |
| 2978 | if(rgbaWriteMask & 0x00000008) |
| 2979 | { |
| 2980 | buffer = cBuffer + 1 * x; |
| 2981 | Insert(value, *Pointer<Short>(buffer), 0); |
| 2982 | Int pitch = *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2983 | Insert(value, *Pointer<Short>(buffer + pitch), 1); |
| 2984 | value = UnpackLow(As<Byte8>(value), As<Byte8>(value)); |
| 2985 | |
| 2986 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q) + 8 * xMask); |
| 2987 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * xMask); |
| 2988 | current.w |= value; |
| 2989 | |
| 2990 | *Pointer<Short>(buffer) = Extract(current.w, 0); |
| 2991 | *Pointer<Short>(buffer + pitch) = Extract(current.w, 1); |
| 2992 | } |
| 2993 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2994 | case FORMAT_G16R16: |
| 2995 | buffer = cBuffer + 4 * x; |
| 2996 | |
| 2997 | value = *Pointer<Short4>(buffer); |
| 2998 | |
| 2999 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 3000 | { |
| 3001 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3002 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3003 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3004 | current.x |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3005 | } |
| 3006 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3007 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3008 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3009 | current.x |= value; |
| 3010 | *Pointer<Short4>(buffer) = current.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3011 | |
| 3012 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3013 | |
| 3014 | value = *Pointer<Short4>(buffer); |
| 3015 | |
| 3016 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 3017 | { |
| 3018 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3019 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3020 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3021 | current.y |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3022 | } |
| 3023 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3024 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3025 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3026 | current.y |= value; |
| 3027 | *Pointer<Short4>(buffer) = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3028 | break; |
| 3029 | case FORMAT_A16B16G16R16: |
| 3030 | buffer = cBuffer + 8 * x; |
| 3031 | |
| 3032 | { |
| 3033 | value = *Pointer<Short4>(buffer); |
| 3034 | |
| 3035 | if(rgbaWriteMask != 0x0000000F) |
| 3036 | { |
| 3037 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3038 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3039 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3040 | current.x |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3041 | } |
| 3042 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3043 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ0Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3044 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ0Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3045 | current.x |= value; |
| 3046 | *Pointer<Short4>(buffer) = current.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | { |
| 3050 | value = *Pointer<Short4>(buffer + 8); |
| 3051 | |
| 3052 | if(rgbaWriteMask != 0x0000000F) |
| 3053 | { |
| 3054 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3055 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3056 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3057 | current.y |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3058 | } |
| 3059 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3060 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ1Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3061 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ1Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3062 | current.y |= value; |
| 3063 | *Pointer<Short4>(buffer + 8) = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3067 | |
| 3068 | { |
| 3069 | value = *Pointer<Short4>(buffer); |
| 3070 | |
| 3071 | if(rgbaWriteMask != 0x0000000F) |
| 3072 | { |
| 3073 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3074 | current.z &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3075 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3076 | current.z |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3077 | } |
| 3078 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3079 | current.z &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ2Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3080 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ2Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3081 | current.z |= value; |
| 3082 | *Pointer<Short4>(buffer) = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | { |
| 3086 | value = *Pointer<Short4>(buffer + 8); |
| 3087 | |
| 3088 | if(rgbaWriteMask != 0x0000000F) |
| 3089 | { |
| 3090 | Short4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3091 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3092 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3093 | current.w |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3094 | } |
| 3095 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3096 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ3Q) + xMask * 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3097 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ3Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3098 | current.w |= value; |
| 3099 | *Pointer<Short4>(buffer + 8) = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3100 | } |
| 3101 | break; |
| 3102 | default: |
| 3103 | ASSERT(false); |
| 3104 | } |
| 3105 | } |
| 3106 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3107 | void PixelRoutine::blendFactor(Registers &r, const Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3108 | { |
| 3109 | switch(blendFactorActive) |
| 3110 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3111 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3112 | // Optimized |
| 3113 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3114 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3115 | // Optimized |
| 3116 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3117 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3118 | blendFactor.x = oC.x; |
| 3119 | blendFactor.y = oC.y; |
| 3120 | blendFactor.z = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3121 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3122 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3123 | blendFactor.x = Float4(1.0f) - oC.x; |
| 3124 | blendFactor.y = Float4(1.0f) - oC.y; |
| 3125 | blendFactor.z = Float4(1.0f) - oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3126 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3127 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3128 | blendFactor.x = pixel.x; |
| 3129 | blendFactor.y = pixel.y; |
| 3130 | blendFactor.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3131 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3132 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3133 | blendFactor.x = Float4(1.0f) - pixel.x; |
| 3134 | blendFactor.y = Float4(1.0f) - pixel.y; |
| 3135 | blendFactor.z = Float4(1.0f) - pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3136 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3137 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3138 | blendFactor.x = oC.w; |
| 3139 | blendFactor.y = oC.w; |
| 3140 | blendFactor.z = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3141 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3142 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3143 | blendFactor.x = Float4(1.0f) - oC.w; |
| 3144 | blendFactor.y = Float4(1.0f) - oC.w; |
| 3145 | blendFactor.z = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3146 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3147 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3148 | blendFactor.x = pixel.w; |
| 3149 | blendFactor.y = pixel.w; |
| 3150 | blendFactor.z = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3151 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3152 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3153 | blendFactor.x = Float4(1.0f) - pixel.w; |
| 3154 | blendFactor.y = Float4(1.0f) - pixel.w; |
| 3155 | blendFactor.z = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3156 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3157 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3158 | blendFactor.x = Float4(1.0f) - pixel.w; |
| 3159 | blendFactor.x = Min(blendFactor.x, oC.w); |
| 3160 | blendFactor.y = blendFactor.x; |
| 3161 | blendFactor.z = blendFactor.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3162 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3163 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3164 | blendFactor.x = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[0])); |
| 3165 | blendFactor.y = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[1])); |
| 3166 | blendFactor.z = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3167 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3168 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3169 | blendFactor.x = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[0])); |
| 3170 | blendFactor.y = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[1])); |
| 3171 | blendFactor.z = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3172 | break; |
| 3173 | default: |
| 3174 | ASSERT(false); |
| 3175 | } |
| 3176 | } |
| 3177 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3178 | void PixelRoutine::blendFactorAlpha(Registers &r, const Vector4f &blendFactor, const Vector4f &oC, const Vector4f &pixel, BlendFactor blendFactorAlphaActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3179 | { |
| 3180 | switch(blendFactorAlphaActive) |
| 3181 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3182 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3183 | // Optimized |
| 3184 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3185 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3186 | // Optimized |
| 3187 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3188 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3189 | blendFactor.w = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3190 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3191 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3192 | blendFactor.w = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3193 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3194 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3195 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3196 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3197 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3198 | blendFactor.w = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3199 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3200 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3201 | blendFactor.w = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3202 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3203 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3204 | blendFactor.w = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3205 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3206 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3207 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3208 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3209 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3210 | blendFactor.w = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3211 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3212 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3213 | blendFactor.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3214 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3215 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3216 | blendFactor.w = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3217 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3218 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3219 | blendFactor.w = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3220 | break; |
| 3221 | default: |
| 3222 | ASSERT(false); |
| 3223 | } |
| 3224 | } |
| 3225 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3226 | 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] | 3227 | { |
| 3228 | if(!state.alphaBlendActive) |
| 3229 | { |
| 3230 | return; |
| 3231 | } |
| 3232 | |
| 3233 | Pointer<Byte> buffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3234 | Vector4f pixel; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3235 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3236 | Vector4i color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3237 | Short4 c01; |
| 3238 | Short4 c23; |
| 3239 | |
| 3240 | // Read pixel |
| 3241 | switch(state.targetFormat[index]) |
| 3242 | { |
| 3243 | case FORMAT_A8R8G8B8: |
| 3244 | buffer = cBuffer + 4 * x; |
| 3245 | c01 = *Pointer<Short4>(buffer); |
| 3246 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3247 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3248 | color.z = c01; |
| 3249 | color.y = c01; |
| 3250 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(c23)); |
| 3251 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(c23)); |
| 3252 | color.x = color.z; |
| 3253 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.y)); |
| 3254 | color.x = UnpackHigh(As<Byte8>(color.x), As<Byte8>(color.y)); |
| 3255 | color.y = color.z; |
| 3256 | color.w = color.x; |
| 3257 | color.x = UnpackLow(As<Byte8>(color.x), As<Byte8>(color.x)); |
| 3258 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(color.y)); |
| 3259 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.z)); |
| 3260 | color.w = UnpackHigh(As<Byte8>(color.w), As<Byte8>(color.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3261 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3262 | pixel.x = convertUnsigned16(As<UShort4>(color.x)); |
| 3263 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3264 | pixel.z = convertUnsigned16(As<UShort4>(color.z)); |
| 3265 | pixel.w = convertUnsigned16(As<UShort4>(color.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3266 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 3267 | case FORMAT_A8B8G8R8: |
| 3268 | buffer = cBuffer + 4 * x; |
| 3269 | c01 = *Pointer<Short4>(buffer); |
| 3270 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3271 | c23 = *Pointer<Short4>(buffer); |
| 3272 | color.z = c01; |
| 3273 | color.y = c01; |
| 3274 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(c23)); |
| 3275 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(c23)); |
| 3276 | color.x = color.z; |
| 3277 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.y)); |
| 3278 | color.x = UnpackHigh(As<Byte8>(color.x), As<Byte8>(color.y)); |
| 3279 | color.y = color.z; |
| 3280 | color.w = color.x; |
| 3281 | color.x = UnpackLow(As<Byte8>(color.x), As<Byte8>(color.x)); |
| 3282 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(color.y)); |
| 3283 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.z)); |
| 3284 | color.w = UnpackHigh(As<Byte8>(color.w), As<Byte8>(color.w)); |
| 3285 | |
| 3286 | pixel.x = convertUnsigned16(As<UShort4>(color.z)); |
| 3287 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3288 | pixel.z = convertUnsigned16(As<UShort4>(color.x)); |
| 3289 | pixel.w = convertUnsigned16(As<UShort4>(color.w)); |
| 3290 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3291 | case FORMAT_X8R8G8B8: |
| 3292 | buffer = cBuffer + 4 * x; |
| 3293 | c01 = *Pointer<Short4>(buffer); |
| 3294 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3295 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3296 | color.z = c01; |
| 3297 | color.y = c01; |
| 3298 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(c23)); |
| 3299 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(c23)); |
| 3300 | color.x = color.z; |
| 3301 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.y)); |
| 3302 | color.x = UnpackHigh(As<Byte8>(color.x), As<Byte8>(color.y)); |
| 3303 | color.y = color.z; |
| 3304 | color.x = UnpackLow(As<Byte8>(color.x), As<Byte8>(color.x)); |
| 3305 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(color.y)); |
| 3306 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3307 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3308 | pixel.x = convertUnsigned16(As<UShort4>(color.x)); |
| 3309 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3310 | pixel.z = convertUnsigned16(As<UShort4>(color.z)); |
| 3311 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3312 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 3313 | case FORMAT_X8B8G8R8: |
| 3314 | buffer = cBuffer + 4 * x; |
| 3315 | c01 = *Pointer<Short4>(buffer); |
| 3316 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3317 | c23 = *Pointer<Short4>(buffer); |
| 3318 | color.z = c01; |
| 3319 | color.y = c01; |
| 3320 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(c23)); |
| 3321 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(c23)); |
| 3322 | color.x = color.z; |
| 3323 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.y)); |
| 3324 | color.x = UnpackHigh(As<Byte8>(color.x), As<Byte8>(color.y)); |
| 3325 | color.y = color.z; |
| 3326 | color.x = UnpackLow(As<Byte8>(color.x), As<Byte8>(color.x)); |
| 3327 | color.y = UnpackHigh(As<Byte8>(color.y), As<Byte8>(color.y)); |
| 3328 | color.z = UnpackLow(As<Byte8>(color.z), As<Byte8>(color.z)); |
| 3329 | |
| 3330 | pixel.x = convertUnsigned16(As<UShort4>(color.z)); |
| 3331 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3332 | pixel.z = convertUnsigned16(As<UShort4>(color.x)); |
| 3333 | pixel.w = Float4(1.0f); |
| 3334 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3335 | case FORMAT_A8: |
| 3336 | buffer = cBuffer + 1 * x; |
| 3337 | c01 = Insert(c01, *Pointer<Short>(buffer), 0); |
| 3338 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3339 | c01 = Insert(c01, *Pointer<Short>(buffer), 1); |
| 3340 | pixel.w = convertUnsigned16(As<UShort4>(UnpackLow(As<Byte8>(c01), As<Byte8>(c01)))); |
| 3341 | pixel.x = Float4(0.0f); |
| 3342 | pixel.y = Float4(0.0f); |
| 3343 | pixel.z = Float4(0.0f); |
| 3344 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3345 | case FORMAT_A8G8R8B8Q: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3346 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3347 | // UnpackLow(pixel.z, qword_ptr [cBuffer+8*x+0]); |
| 3348 | // UnpackHigh(pixel.x, qword_ptr [cBuffer+8*x+0]); |
| 3349 | // UnpackLow(pixel.y, qword_ptr [cBuffer+8*x+8]); |
| 3350 | // UnpackHigh(pixel.w, qword_ptr [cBuffer+8*x+8]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3351 | break; |
| 3352 | case FORMAT_X8G8R8B8Q: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3353 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3354 | // UnpackLow(pixel.z, qword_ptr [cBuffer+8*x+0]); |
| 3355 | // UnpackHigh(pixel.x, qword_ptr [cBuffer+8*x+0]); |
| 3356 | // UnpackLow(pixel.y, qword_ptr [cBuffer+8*x+8]); |
| 3357 | // pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3358 | break; |
| 3359 | case FORMAT_A16B16G16R16: |
| 3360 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3361 | color.x = *Pointer<Short4>(buffer + 8 * x); |
| 3362 | color.y = *Pointer<Short4>(buffer + 8 * x + 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3363 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3364 | color.z = *Pointer<Short4>(buffer + 8 * x); |
| 3365 | color.w = *Pointer<Short4>(buffer + 8 * x + 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3366 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3367 | transpose4x4(color.x, color.y, color.z, color.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3368 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3369 | pixel.x = convertUnsigned16(As<UShort4>(color.x)); |
| 3370 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3371 | pixel.z = convertUnsigned16(As<UShort4>(color.z)); |
| 3372 | pixel.w = convertUnsigned16(As<UShort4>(color.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3373 | break; |
| 3374 | case FORMAT_G16R16: |
| 3375 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3376 | color.x = *Pointer<Short4>(buffer + 4 * x); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3377 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3378 | color.y = *Pointer<Short4>(buffer + 4 * x); |
| 3379 | color.z = color.x; |
| 3380 | color.x = As<Short4>(UnpackLow(color.x, color.y)); |
| 3381 | color.z = As<Short4>(UnpackHigh(color.z, color.y)); |
| 3382 | color.y = color.z; |
| 3383 | color.x = As<Short4>(UnpackLow(color.x, color.z)); |
| 3384 | color.y = As<Short4>(UnpackHigh(color.y, color.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3385 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3386 | pixel.x = convertUnsigned16(As<UShort4>(color.x)); |
| 3387 | pixel.y = convertUnsigned16(As<UShort4>(color.y)); |
| 3388 | pixel.z = Float4(1.0f); |
| 3389 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3390 | break; |
| 3391 | case FORMAT_R32F: |
| 3392 | buffer = cBuffer; |
| 3393 | // FIXME: movlps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3394 | pixel.x.x = *Pointer<Float>(buffer + 4 * x + 0); |
| 3395 | pixel.x.y = *Pointer<Float>(buffer + 4 * x + 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3396 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3397 | // FIXME: movhps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3398 | pixel.x.z = *Pointer<Float>(buffer + 4 * x + 0); |
| 3399 | pixel.x.w = *Pointer<Float>(buffer + 4 * x + 4); |
| 3400 | pixel.y = Float4(1.0f); |
| 3401 | pixel.z = Float4(1.0f); |
| 3402 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3403 | break; |
| 3404 | case FORMAT_G32R32F: |
| 3405 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3406 | pixel.x = *Pointer<Float4>(buffer + 8 * x, 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3407 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3408 | pixel.y = *Pointer<Float4>(buffer + 8 * x, 16); |
| 3409 | pixel.z = pixel.x; |
| 3410 | pixel.x = ShuffleLowHigh(pixel.x, pixel.y, 0x88); |
| 3411 | pixel.z = ShuffleLowHigh(pixel.z, pixel.y, 0xDD); |
| 3412 | pixel.y = pixel.z; |
| 3413 | pixel.z = Float4(1.0f); |
| 3414 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3415 | break; |
| 3416 | case FORMAT_A32B32G32R32F: |
| 3417 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3418 | pixel.x = *Pointer<Float4>(buffer + 16 * x, 16); |
| 3419 | pixel.y = *Pointer<Float4>(buffer + 16 * x + 16, 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3420 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3421 | pixel.z = *Pointer<Float4>(buffer + 16 * x, 16); |
| 3422 | pixel.w = *Pointer<Float4>(buffer + 16 * x + 16, 16); |
| 3423 | transpose4x4(pixel.x, pixel.y, pixel.z, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3424 | break; |
| 3425 | default: |
| 3426 | ASSERT(false); |
| 3427 | } |
| 3428 | |
| 3429 | if(postBlendSRGB && state.writeSRGB) |
| 3430 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3431 | sRGBtoLinear(pixel.x); |
| 3432 | sRGBtoLinear(pixel.y); |
| 3433 | sRGBtoLinear(pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | // Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3437 | Vector4f sourceFactor; |
| 3438 | Vector4f destFactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3439 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3440 | blendFactor(r, sourceFactor, oC, pixel, state.sourceBlendFactor); |
| 3441 | blendFactor(r, destFactor, oC, pixel, state.destBlendFactor); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3442 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3443 | if(state.sourceBlendFactor != BLEND_ONE && state.sourceBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3444 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3445 | oC.x *= sourceFactor.x; |
| 3446 | oC.y *= sourceFactor.y; |
| 3447 | oC.z *= sourceFactor.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3448 | } |
| 3449 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3450 | if(state.destBlendFactor != BLEND_ONE && state.destBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3451 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3452 | pixel.x *= destFactor.x; |
| 3453 | pixel.y *= destFactor.y; |
| 3454 | pixel.z *= destFactor.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | switch(state.blendOperation) |
| 3458 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3459 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3460 | oC.x += pixel.x; |
| 3461 | oC.y += pixel.y; |
| 3462 | oC.z += pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3463 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3464 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3465 | oC.x -= pixel.x; |
| 3466 | oC.y -= pixel.y; |
| 3467 | oC.z -= pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3468 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3469 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3470 | oC.x = pixel.x - oC.x; |
| 3471 | oC.y = pixel.y - oC.y; |
| 3472 | oC.z = pixel.z - oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3473 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3474 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3475 | oC.x = Min(oC.x, pixel.x); |
| 3476 | oC.y = Min(oC.y, pixel.y); |
| 3477 | oC.z = Min(oC.z, pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3478 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3479 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3480 | oC.x = Max(oC.x, pixel.x); |
| 3481 | oC.y = Max(oC.y, pixel.y); |
| 3482 | oC.z = Max(oC.z, pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3483 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3484 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3485 | // No operation |
| 3486 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3487 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3488 | oC.x = pixel.x; |
| 3489 | oC.y = pixel.y; |
| 3490 | oC.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3491 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3492 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3493 | oC.x = Float4(0.0f); |
| 3494 | oC.y = Float4(0.0f); |
| 3495 | oC.z = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3496 | break; |
| 3497 | default: |
| 3498 | ASSERT(false); |
| 3499 | } |
| 3500 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3501 | blendFactorAlpha(r, sourceFactor, oC, pixel, state.sourceBlendFactorAlpha); |
| 3502 | blendFactorAlpha(r, destFactor, oC, pixel, state.destBlendFactorAlpha); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3503 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3504 | if(state.sourceBlendFactorAlpha != BLEND_ONE && state.sourceBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3505 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3506 | oC.w *= sourceFactor.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3507 | } |
| 3508 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3509 | if(state.destBlendFactorAlpha != BLEND_ONE && state.destBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3510 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3511 | pixel.w *= destFactor.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | switch(state.blendOperationAlpha) |
| 3515 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3516 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3517 | oC.w += pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3518 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3519 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3520 | oC.w -= pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3521 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3522 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3523 | pixel.w -= oC.w; |
| 3524 | oC.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3525 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3526 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3527 | oC.w = Min(oC.w, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3528 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3529 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3530 | oC.w = Max(oC.w, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3531 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3532 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3533 | // No operation |
| 3534 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3535 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3536 | oC.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3537 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 3538 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3539 | oC.w = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3540 | break; |
| 3541 | default: |
| 3542 | ASSERT(false); |
| 3543 | } |
| 3544 | } |
| 3545 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3546 | 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] | 3547 | { |
| 3548 | if(!state.colorWriteActive(index)) |
| 3549 | { |
| 3550 | return; |
| 3551 | } |
| 3552 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3553 | Vector4i color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3554 | |
| 3555 | switch(state.targetFormat[index]) |
| 3556 | { |
| 3557 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 3558 | case FORMAT_X8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3559 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 3560 | case FORMAT_A8B8G8R8: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3561 | case FORMAT_A8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3562 | case FORMAT_G16R16: |
| 3563 | case FORMAT_A16B16G16R16: |
| 3564 | convertFixed16(color, oC, true); |
| 3565 | writeColor(r, index, cBuffer, x, color, sMask, zMask, cMask); |
| 3566 | return; |
| 3567 | case FORMAT_R32F: |
| 3568 | break; |
| 3569 | case FORMAT_G32R32F: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3570 | oC.z = oC.x; |
| 3571 | oC.x = UnpackLow(oC.x, oC.y); |
| 3572 | oC.z = UnpackHigh(oC.z, oC.y); |
| 3573 | oC.y = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3574 | break; |
| 3575 | case FORMAT_A32B32G32R32F: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3576 | transpose4x4(oC.x, oC.y, oC.z, oC.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3577 | break; |
| 3578 | default: |
| 3579 | ASSERT(false); |
| 3580 | } |
| 3581 | |
| 3582 | int rgbaWriteMask = state.colorWriteActive(index); |
| 3583 | |
| 3584 | Int xMask; // Combination of all masks |
| 3585 | |
| 3586 | if(state.depthTestActive) |
| 3587 | { |
| 3588 | xMask = zMask; |
| 3589 | } |
| 3590 | else |
| 3591 | { |
| 3592 | xMask = cMask; |
| 3593 | } |
| 3594 | |
| 3595 | if(state.stencilActive) |
| 3596 | { |
| 3597 | xMask &= sMask; |
| 3598 | } |
| 3599 | |
| 3600 | Pointer<Byte> buffer; |
| 3601 | Float4 value; |
| 3602 | |
| 3603 | switch(state.targetFormat[index]) |
| 3604 | { |
| 3605 | case FORMAT_R32F: |
| 3606 | if(rgbaWriteMask & 0x00000001) |
| 3607 | { |
| 3608 | buffer = cBuffer + 4 * x; |
| 3609 | |
| 3610 | // FIXME: movlps |
| 3611 | value.x = *Pointer<Float>(buffer + 0); |
| 3612 | value.y = *Pointer<Float>(buffer + 4); |
| 3613 | |
| 3614 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3615 | |
| 3616 | // FIXME: movhps |
| 3617 | value.z = *Pointer<Float>(buffer + 0); |
| 3618 | value.w = *Pointer<Float>(buffer + 4); |
| 3619 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3620 | 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] | 3621 | 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] | 3622 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3623 | |
| 3624 | // FIXME: movhps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3625 | *Pointer<Float>(buffer + 0) = oC.x.z; |
| 3626 | *Pointer<Float>(buffer + 4) = oC.x.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3627 | |
| 3628 | buffer -= *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3629 | |
| 3630 | // FIXME: movlps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3631 | *Pointer<Float>(buffer + 0) = oC.x.x; |
| 3632 | *Pointer<Float>(buffer + 4) = oC.x.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3633 | } |
| 3634 | break; |
| 3635 | case FORMAT_G32R32F: |
| 3636 | buffer = cBuffer + 8 * x; |
| 3637 | |
| 3638 | value = *Pointer<Float4>(buffer); |
| 3639 | |
| 3640 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 3641 | { |
| 3642 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3643 | 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] | 3644 | 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] | 3645 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3646 | } |
| 3647 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3648 | 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] | 3649 | 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] | 3650 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
| 3651 | *Pointer<Float4>(buffer) = oC.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3652 | |
| 3653 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3654 | |
| 3655 | value = *Pointer<Float4>(buffer); |
| 3656 | |
| 3657 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 3658 | { |
| 3659 | Float4 masked; |
| 3660 | |
| 3661 | masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3662 | 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] | 3663 | 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] | 3664 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3665 | } |
| 3666 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3667 | 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] | 3668 | 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] | 3669 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(value)); |
| 3670 | *Pointer<Float4>(buffer) = oC.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3671 | break; |
| 3672 | case FORMAT_A32B32G32R32F: |
| 3673 | buffer = cBuffer + 16 * x; |
| 3674 | |
| 3675 | { |
| 3676 | value = *Pointer<Float4>(buffer, 16); |
| 3677 | |
| 3678 | if(rgbaWriteMask != 0x0000000F) |
| 3679 | { |
| 3680 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3681 | 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] | 3682 | 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] | 3683 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3684 | } |
| 3685 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3686 | 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] | 3687 | 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] | 3688 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
| 3689 | *Pointer<Float4>(buffer, 16) = oC.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | { |
| 3693 | value = *Pointer<Float4>(buffer + 16, 16); |
| 3694 | |
| 3695 | if(rgbaWriteMask != 0x0000000F) |
| 3696 | { |
| 3697 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3698 | 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] | 3699 | 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] | 3700 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3701 | } |
| 3702 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3703 | 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] | 3704 | 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] | 3705 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(value)); |
| 3706 | *Pointer<Float4>(buffer + 16, 16) = oC.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 3710 | |
| 3711 | { |
| 3712 | value = *Pointer<Float4>(buffer, 16); |
| 3713 | |
| 3714 | if(rgbaWriteMask != 0x0000000F) |
| 3715 | { |
| 3716 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3717 | 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] | 3718 | 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] | 3719 | oC.z = As<Float4>(As<Int4>(oC.z) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3720 | } |
| 3721 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3722 | 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] | 3723 | 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] | 3724 | oC.z = As<Float4>(As<Int4>(oC.z) | As<Int4>(value)); |
| 3725 | *Pointer<Float4>(buffer, 16) = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | { |
| 3729 | value = *Pointer<Float4>(buffer + 16, 16); |
| 3730 | |
| 3731 | if(rgbaWriteMask != 0x0000000F) |
| 3732 | { |
| 3733 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3734 | 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] | 3735 | 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] | 3736 | oC.w = As<Float4>(As<Int4>(oC.w) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3737 | } |
| 3738 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3739 | 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] | 3740 | 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] | 3741 | oC.w = As<Float4>(As<Int4>(oC.w) | As<Int4>(value)); |
| 3742 | *Pointer<Float4>(buffer + 16, 16) = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3743 | } |
| 3744 | break; |
| 3745 | default: |
| 3746 | ASSERT(false); |
| 3747 | } |
| 3748 | } |
| 3749 | |
| 3750 | void PixelRoutine::ps_1_x(Registers &r, Int cMask[4]) |
| 3751 | { |
| 3752 | int pad = 0; // Count number of texm3x3pad instructions |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3753 | Vector4i dPairing; // Destination for first pairing instruction |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3754 | |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 3755 | for(size_t i = 0; i < shader->getLength(); i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3756 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3757 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3758 | Shader::Opcode opcode = instruction->opcode; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3759 | |
| 3760 | // #ifndef NDEBUG // FIXME: Centralize debug output control |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3761 | // shader->printInstruction(i, "debug.txt"); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3762 | // #endif |
| 3763 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3764 | 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] | 3765 | { |
| 3766 | continue; |
| 3767 | } |
| 3768 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3769 | const Dst &dst = instruction->dst; |
| 3770 | const Src &src0 = instruction->src[0]; |
| 3771 | const Src &src1 = instruction->src[1]; |
| 3772 | const Src &src2 = instruction->src[2]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3773 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3774 | unsigned short version = shader->getVersion(); |
| 3775 | bool pairing = i + 1 < shader->getLength() && shader->getInstruction(i + 1)->coissue; // First instruction of pair |
| 3776 | bool coissue = instruction->coissue; // Second instruction of pair |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3777 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3778 | Vector4i d; |
| 3779 | Vector4i s0; |
| 3780 | Vector4i s1; |
| 3781 | Vector4i s2; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3782 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3783 | if(src0.type != Shader::PARAMETER_VOID) s0 = regi(r, src0); |
| 3784 | if(src1.type != Shader::PARAMETER_VOID) s1 = regi(r, src1); |
| 3785 | if(src2.type != Shader::PARAMETER_VOID) s2 = regi(r, src2); |
| 3786 | |
| 3787 | Float4 u = version < 0x0104 ? r.vf[2 + dst.index].x : r.vf[2 + src0.index].x; |
| 3788 | Float4 v = version < 0x0104 ? r.vf[2 + dst.index].y : r.vf[2 + src0.index].y; |
| 3789 | Float4 s = version < 0x0104 ? r.vf[2 + dst.index].z : r.vf[2 + src0.index].z; |
| 3790 | 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] | 3791 | |
| 3792 | switch(opcode) |
| 3793 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3794 | case Shader::OPCODE_PS_1_0: break; |
| 3795 | case Shader::OPCODE_PS_1_1: break; |
| 3796 | case Shader::OPCODE_PS_1_2: break; |
| 3797 | case Shader::OPCODE_PS_1_3: break; |
| 3798 | case Shader::OPCODE_PS_1_4: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3799 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3800 | case Shader::OPCODE_DEF: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3801 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3802 | case Shader::OPCODE_NOP: break; |
| 3803 | case Shader::OPCODE_MOV: MOV(d, s0); break; |
| 3804 | case Shader::OPCODE_ADD: ADD(d, s0, s1); break; |
| 3805 | case Shader::OPCODE_SUB: SUB(d, s0, s1); break; |
| 3806 | case Shader::OPCODE_MAD: MAD(d, s0, s1, s2); break; |
| 3807 | case Shader::OPCODE_MUL: MUL(d, s0, s1); break; |
| 3808 | case Shader::OPCODE_DP3: DP3(d, s0, s1); break; |
| 3809 | case Shader::OPCODE_DP4: DP4(d, s0, s1); break; |
| 3810 | case Shader::OPCODE_LRP: LRP(d, s0, s1, s2); break; |
| 3811 | case Shader::OPCODE_TEXCOORD: |
| 3812 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3813 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3814 | TEXCOORD(d, u, v, s, dst.index); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3815 | } |
| 3816 | else |
| 3817 | { |
| 3818 | if((src0.swizzle & 0x30) == 0x20) // .xyz |
| 3819 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3820 | 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] | 3821 | } |
| 3822 | else // .xyw |
| 3823 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3824 | 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] | 3825 | } |
| 3826 | } |
| 3827 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3828 | case Shader::OPCODE_TEXKILL: |
| 3829 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3830 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3831 | TEXKILL(cMask, u, v, s); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3832 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3833 | else if(version == 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3834 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3835 | if(dst.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3836 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3837 | TEXKILL(cMask, u, v, s); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3838 | } |
| 3839 | else |
| 3840 | { |
| 3841 | TEXKILL(cMask, r.ri[dst.index]); |
| 3842 | } |
| 3843 | } |
| 3844 | else ASSERT(false); |
| 3845 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3846 | case Shader::OPCODE_TEX: |
| 3847 | if(version < 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3848 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3849 | TEX(r, d, u, v, s, dst.index, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3850 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3851 | else if(version == 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3852 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3853 | if(src0.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3854 | { |
| 3855 | if((src0.swizzle & 0x30) == 0x20) // .xyz |
| 3856 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3857 | 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] | 3858 | } |
| 3859 | else // .xyw |
| 3860 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3861 | 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] | 3862 | } |
| 3863 | } |
| 3864 | else |
| 3865 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3866 | 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] | 3867 | } |
| 3868 | } |
| 3869 | else ASSERT(false); |
| 3870 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3871 | case Shader::OPCODE_TEXBEM: TEXBEM(r, d, s0, u, v, s, dst.index); break; |
| 3872 | case Shader::OPCODE_TEXBEML: TEXBEML(r, d, s0, u, v, s, dst.index); break; |
| 3873 | case Shader::OPCODE_TEXREG2AR: TEXREG2AR(r, d, s0, dst.index); break; |
| 3874 | case Shader::OPCODE_TEXREG2GB: TEXREG2GB(r, d, s0, dst.index); break; |
| 3875 | case Shader::OPCODE_TEXM3X2PAD: TEXM3X2PAD(r, u, v, s, s0, 0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3876 | case Shader::OPCODE_TEXM3X2TEX: TEXM3X2TEX(r, d, u, v, s, dst.index, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3877 | case Shader::OPCODE_TEXM3X3PAD: TEXM3X3PAD(r, u, v, s, s0, pad++ % 2, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3878 | case Shader::OPCODE_TEXM3X3TEX: TEXM3X3TEX(r, d, u, v, s, dst.index, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3879 | case Shader::OPCODE_TEXM3X3SPEC: TEXM3X3SPEC(r, d, u, v, s, dst.index, s0, s1); break; |
| 3880 | case Shader::OPCODE_TEXM3X3VSPEC: TEXM3X3VSPEC(r, d, u, v, s, dst.index, s0); break; |
| 3881 | case Shader::OPCODE_CND: CND(d, s0, s1, s2); break; |
| 3882 | case Shader::OPCODE_TEXREG2RGB: TEXREG2RGB(r, d, s0, dst.index); break; |
| 3883 | case Shader::OPCODE_TEXDP3TEX: TEXDP3TEX(r, d, u, v, s, dst.index, s0); break; |
| 3884 | case Shader::OPCODE_TEXM3X2DEPTH: TEXM3X2DEPTH(r, d, u, v, s, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3885 | case Shader::OPCODE_TEXDP3: TEXDP3(r, d, u, v, s, s0); break; |
| 3886 | case Shader::OPCODE_TEXM3X3: TEXM3X3(r, d, u, v, s, s0, src0.modifier == Shader::MODIFIER_SIGN); break; |
| 3887 | case Shader::OPCODE_TEXDEPTH: TEXDEPTH(r); break; |
| 3888 | case Shader::OPCODE_CMP0: CMP(d, s0, s1, s2); break; |
| 3889 | case Shader::OPCODE_BEM: BEM(r, d, s0, s1, dst.index); break; |
| 3890 | case Shader::OPCODE_PHASE: break; |
| 3891 | case Shader::OPCODE_END: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3892 | default: |
| 3893 | ASSERT(false); |
| 3894 | } |
| 3895 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3896 | if(dst.type != Shader::PARAMETER_VOID && opcode != Shader::OPCODE_TEXKILL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3897 | { |
| 3898 | if(dst.shift > 0) |
| 3899 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3900 | 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);} |
| 3901 | 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);} |
| 3902 | 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);} |
| 3903 | 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] | 3904 | } |
| 3905 | else if(dst.shift < 0) |
| 3906 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3907 | if(dst.mask & 0x1) d.x = d.x >> -dst.shift; |
| 3908 | if(dst.mask & 0x2) d.y = d.y >> -dst.shift; |
| 3909 | if(dst.mask & 0x4) d.z = d.z >> -dst.shift; |
| 3910 | if(dst.mask & 0x8) d.w = d.w >> -dst.shift; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3911 | } |
| 3912 | |
| 3913 | if(dst.saturate) |
| 3914 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3915 | if(dst.mask & 0x1) {d.x = Min(d.x, Short4(0x1000)); d.x = Max(d.x, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3916 | if(dst.mask & 0x2) {d.y = Min(d.y, Short4(0x1000)); d.y = Max(d.y, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3917 | if(dst.mask & 0x4) {d.z = Min(d.z, Short4(0x1000)); d.z = Max(d.z, Short4(0x0000, 0x0000, 0x0000, 0x0000));} |
| 3918 | 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] | 3919 | } |
| 3920 | |
| 3921 | if(pairing) |
| 3922 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3923 | if(dst.mask & 0x1) dPairing.x = d.x; |
| 3924 | if(dst.mask & 0x2) dPairing.y = d.y; |
| 3925 | if(dst.mask & 0x4) dPairing.z = d.z; |
| 3926 | if(dst.mask & 0x8) dPairing.w = d.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | if(coissue) |
| 3930 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3931 | const Dst &dst = shader->getInstruction(i - 1)->dst; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3932 | |
| 3933 | writeDestination(r, dPairing, dst); |
| 3934 | } |
| 3935 | |
| 3936 | if(!pairing) |
| 3937 | { |
| 3938 | writeDestination(r, d, dst); |
| 3939 | } |
| 3940 | } |
| 3941 | } |
| 3942 | } |
| 3943 | |
| 3944 | void PixelRoutine::ps_2_x(Registers &r, Int cMask[4]) |
| 3945 | { |
| 3946 | r.enableIndex = 0; |
| 3947 | r.stackIndex = 0; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3948 | |
Nicolas Capens | 4677a5f | 2014-05-06 16:42:26 -0400 | [diff] [blame] | 3949 | if(shader->containsLeaveInstruction()) |
| 3950 | { |
| 3951 | r.enableLeave = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 3952 | } |
| 3953 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3954 | bool out[4][4] = {false}; |
| 3955 | |
| 3956 | // Create all call site return blocks up front |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 3957 | for(size_t i = 0; i < shader->getLength(); i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3958 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3959 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3960 | Shader::Opcode opcode = instruction->opcode; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3961 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3962 | if(opcode == Shader::OPCODE_CALL || opcode == Shader::OPCODE_CALLNZ) |
| 3963 | { |
| 3964 | const Dst &dst = instruction->dst; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3965 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3966 | ASSERT(callRetBlock[dst.label].size() == dst.callSite); |
| 3967 | callRetBlock[dst.label].push_back(Nucleus::createBasicBlock()); |
| 3968 | } |
| 3969 | } |
| 3970 | |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 3971 | for(size_t i = 0; i < shader->getLength(); i++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3972 | { |
| 3973 | const Shader::Instruction *instruction = shader->getInstruction(i); |
| 3974 | Shader::Opcode opcode = instruction->opcode; |
| 3975 | |
| 3976 | 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] | 3977 | { |
| 3978 | continue; |
| 3979 | } |
| 3980 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3981 | const Dst &dst = instruction->dst; |
| 3982 | const Src &src0 = instruction->src[0]; |
| 3983 | const Src &src1 = instruction->src[1]; |
| 3984 | const Src &src2 = instruction->src[2]; |
| 3985 | const Src &src3 = instruction->src[3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3986 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3987 | bool predicate = instruction->predicate; |
| 3988 | Control control = instruction->control; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3989 | bool pp = dst.partialPrecision; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3990 | bool project = instruction->project; |
| 3991 | bool bias = instruction->bias; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3992 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3993 | Vector4f d; |
| 3994 | Vector4f s0; |
| 3995 | Vector4f s1; |
| 3996 | Vector4f s2; |
| 3997 | Vector4f s3; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3998 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 3999 | if(opcode == Shader::OPCODE_TEXKILL) // Takes destination as input |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4000 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4001 | if(dst.type == Shader::PARAMETER_TEXTURE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4002 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4003 | d.x = r.vf[2 + dst.index].x; |
| 4004 | d.y = r.vf[2 + dst.index].y; |
| 4005 | d.z = r.vf[2 + dst.index].z; |
| 4006 | d.w = r.vf[2 + dst.index].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4007 | } |
| 4008 | else |
| 4009 | { |
| 4010 | d = r.rf[dst.index]; |
| 4011 | } |
| 4012 | } |
| 4013 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4014 | if(src0.type != Shader::PARAMETER_VOID) s0 = reg(r, src0); |
| 4015 | if(src1.type != Shader::PARAMETER_VOID) s1 = reg(r, src1); |
| 4016 | if(src2.type != Shader::PARAMETER_VOID) s2 = reg(r, src2); |
| 4017 | if(src3.type != Shader::PARAMETER_VOID) s3 = reg(r, src3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4018 | |
| 4019 | switch(opcode) |
| 4020 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4021 | case Shader::OPCODE_PS_2_0: break; |
| 4022 | case Shader::OPCODE_PS_2_x: break; |
| 4023 | case Shader::OPCODE_PS_3_0: break; |
| 4024 | case Shader::OPCODE_DEF: break; |
| 4025 | case Shader::OPCODE_DCL: break; |
| 4026 | case Shader::OPCODE_NOP: break; |
| 4027 | case Shader::OPCODE_MOV: mov(d, s0); break; |
| 4028 | case Shader::OPCODE_F2B: f2b(d, s0); break; |
| 4029 | case Shader::OPCODE_B2F: b2f(d, s0); break; |
| 4030 | case Shader::OPCODE_ADD: add(d, s0, s1); break; |
| 4031 | case Shader::OPCODE_SUB: sub(d, s0, s1); break; |
| 4032 | case Shader::OPCODE_MUL: mul(d, s0, s1); break; |
| 4033 | case Shader::OPCODE_MAD: mad(d, s0, s1, s2); break; |
| 4034 | case Shader::OPCODE_DP1: dp1(d, s0, s1); break; |
| 4035 | case Shader::OPCODE_DP2: dp2(d, s0, s1); break; |
| 4036 | case Shader::OPCODE_DP2ADD: dp2add(d, s0, s1, s2); break; |
| 4037 | case Shader::OPCODE_DP3: dp3(d, s0, s1); break; |
| 4038 | case Shader::OPCODE_DP4: dp4(d, s0, s1); break; |
| 4039 | case Shader::OPCODE_CMP0: cmp0(d, s0, s1, s2); break; |
| 4040 | case Shader::OPCODE_ICMP: icmp(d, s0, s1, control); break; |
| 4041 | case Shader::OPCODE_SELECT: select(d, s0, s1, s2); break; |
| 4042 | case Shader::OPCODE_EXTRACT: extract(d.x, s0, s1.x); break; |
| 4043 | case Shader::OPCODE_INSERT: insert(d, s0, s1.x, s2.x); break; |
| 4044 | case Shader::OPCODE_FRC: frc(d, s0); break; |
| 4045 | case Shader::OPCODE_TRUNC: trunc(d, s0); break; |
| 4046 | case Shader::OPCODE_FLOOR: floor(d, s0); break; |
| 4047 | case Shader::OPCODE_CEIL: ceil(d, s0); break; |
| 4048 | case Shader::OPCODE_EXP2X: exp2x(d, s0, pp); break; |
| 4049 | case Shader::OPCODE_EXP2: exp2(d, s0, pp); break; |
| 4050 | case Shader::OPCODE_LOG2X: log2x(d, s0, pp); break; |
| 4051 | case Shader::OPCODE_LOG2: log2(d, s0, pp); break; |
| 4052 | case Shader::OPCODE_EXP: exp(d, s0, pp); break; |
| 4053 | case Shader::OPCODE_LOG: log(d, s0, pp); break; |
| 4054 | case Shader::OPCODE_RCPX: rcpx(d, s0, pp); break; |
| 4055 | case Shader::OPCODE_DIV: div(d, s0, s1); break; |
| 4056 | case Shader::OPCODE_MOD: mod(d, s0, s1); break; |
| 4057 | case Shader::OPCODE_RSQX: rsqx(d, s0, pp); break; |
| 4058 | case Shader::OPCODE_SQRT: sqrt(d, s0, pp); break; |
| 4059 | case Shader::OPCODE_RSQ: rsq(d, s0, pp); break; |
| 4060 | case Shader::OPCODE_LEN2: len2(d.x, s0, pp); break; |
| 4061 | case Shader::OPCODE_LEN3: len3(d.x, s0, pp); break; |
| 4062 | case Shader::OPCODE_LEN4: len4(d.x, s0, pp); break; |
| 4063 | case Shader::OPCODE_DIST1: dist1(d.x, s0, s1, pp); break; |
| 4064 | case Shader::OPCODE_DIST2: dist2(d.x, s0, s1, pp); break; |
| 4065 | case Shader::OPCODE_DIST3: dist3(d.x, s0, s1, pp); break; |
| 4066 | case Shader::OPCODE_DIST4: dist4(d.x, s0, s1, pp); break; |
| 4067 | case Shader::OPCODE_MIN: min(d, s0, s1); break; |
| 4068 | case Shader::OPCODE_MAX: max(d, s0, s1); break; |
| 4069 | case Shader::OPCODE_LRP: lrp(d, s0, s1, s2); break; |
| 4070 | case Shader::OPCODE_STEP: step(d, s0, s1); break; |
| 4071 | case Shader::OPCODE_SMOOTH: smooth(d, s0, s1, s2); break; |
| 4072 | case Shader::OPCODE_POWX: powx(d, s0, s1, pp); break; |
| 4073 | case Shader::OPCODE_POW: pow(d, s0, s1, pp); break; |
| 4074 | case Shader::OPCODE_SGN: sgn(d, s0); break; |
| 4075 | case Shader::OPCODE_CRS: crs(d, s0, s1); break; |
| 4076 | case Shader::OPCODE_FORWARD1: forward1(d, s0, s1, s2); break; |
| 4077 | case Shader::OPCODE_FORWARD2: forward2(d, s0, s1, s2); break; |
| 4078 | case Shader::OPCODE_FORWARD3: forward3(d, s0, s1, s2); break; |
| 4079 | case Shader::OPCODE_FORWARD4: forward4(d, s0, s1, s2); break; |
| 4080 | case Shader::OPCODE_REFLECT1: reflect1(d, s0, s1); break; |
| 4081 | case Shader::OPCODE_REFLECT2: reflect2(d, s0, s1); break; |
| 4082 | case Shader::OPCODE_REFLECT3: reflect3(d, s0, s1); break; |
| 4083 | case Shader::OPCODE_REFLECT4: reflect4(d, s0, s1); break; |
| 4084 | case Shader::OPCODE_REFRACT1: refract1(d, s0, s1, s2.x); break; |
| 4085 | case Shader::OPCODE_REFRACT2: refract2(d, s0, s1, s2.x); break; |
| 4086 | case Shader::OPCODE_REFRACT3: refract3(d, s0, s1, s2.x); break; |
| 4087 | case Shader::OPCODE_REFRACT4: refract4(d, s0, s1, s2.x); break; |
| 4088 | case Shader::OPCODE_NRM2: nrm2(d, s0, pp); break; |
| 4089 | case Shader::OPCODE_NRM3: nrm3(d, s0, pp); break; |
| 4090 | case Shader::OPCODE_NRM4: nrm4(d, s0, pp); break; |
| 4091 | case Shader::OPCODE_ABS: abs(d, s0); break; |
| 4092 | case Shader::OPCODE_SINCOS: sincos(d, s0, pp); break; |
| 4093 | case Shader::OPCODE_COS: cos(d, s0, pp); break; |
| 4094 | case Shader::OPCODE_SIN: sin(d, s0, pp); break; |
| 4095 | case Shader::OPCODE_TAN: tan(d, s0, pp); break; |
| 4096 | case Shader::OPCODE_ACOS: acos(d, s0, pp); break; |
| 4097 | case Shader::OPCODE_ASIN: asin(d, s0, pp); break; |
| 4098 | case Shader::OPCODE_ATAN: atan(d, s0, pp); break; |
| 4099 | case Shader::OPCODE_ATAN2: atan2(d, s0, s1, pp); break; |
| 4100 | case Shader::OPCODE_M4X4: M4X4(r, d, s0, src1); break; |
| 4101 | case Shader::OPCODE_M4X3: M4X3(r, d, s0, src1); break; |
| 4102 | case Shader::OPCODE_M3X4: M3X4(r, d, s0, src1); break; |
| 4103 | case Shader::OPCODE_M3X3: M3X3(r, d, s0, src1); break; |
| 4104 | case Shader::OPCODE_M3X2: M3X2(r, d, s0, src1); break; |
| 4105 | case Shader::OPCODE_TEX: TEXLD(r, d, s0, src1, project, bias); break; |
| 4106 | case Shader::OPCODE_TEXLDD: TEXLDD(r, d, s0, src1, s2, s3, project, bias); break; |
| 4107 | case Shader::OPCODE_TEXLDL: TEXLDL(r, d, s0, src1, project, bias); break; |
| 4108 | case Shader::OPCODE_TEXKILL: TEXKILL(cMask, d, dst.mask); break; |
| 4109 | case Shader::OPCODE_DISCARD: DISCARD(r, cMask, instruction); break; |
| 4110 | case Shader::OPCODE_DFDX: DFDX(d, s0); break; |
| 4111 | case Shader::OPCODE_DFDY: DFDY(d, s0); break; |
| 4112 | case Shader::OPCODE_FWIDTH: FWIDTH(d, s0); break; |
| 4113 | case Shader::OPCODE_BREAK: BREAK(r); break; |
| 4114 | case Shader::OPCODE_BREAKC: BREAKC(r, s0, s1, control); break; |
| 4115 | case Shader::OPCODE_BREAKP: BREAKP(r, src0); break; |
| 4116 | case Shader::OPCODE_CONTINUE: CONTINUE(r); break; |
| 4117 | case Shader::OPCODE_TEST: TEST(); break; |
| 4118 | case Shader::OPCODE_CALL: CALL(r, dst.label, dst.callSite); break; |
| 4119 | case Shader::OPCODE_CALLNZ: CALLNZ(r, dst.label, dst.callSite, src0); break; |
| 4120 | case Shader::OPCODE_ELSE: ELSE(r); break; |
| 4121 | case Shader::OPCODE_ENDIF: ENDIF(r); break; |
| 4122 | case Shader::OPCODE_ENDLOOP: ENDLOOP(r); break; |
| 4123 | case Shader::OPCODE_ENDREP: ENDREP(r); break; |
| 4124 | case Shader::OPCODE_ENDWHILE: ENDWHILE(r); break; |
| 4125 | case Shader::OPCODE_IF: IF(r, src0); break; |
| 4126 | case Shader::OPCODE_IFC: IFC(r, s0, s1, control); break; |
| 4127 | case Shader::OPCODE_LABEL: LABEL(dst.index); break; |
| 4128 | case Shader::OPCODE_LOOP: LOOP(r, src1); break; |
| 4129 | case Shader::OPCODE_REP: REP(r, src0); break; |
| 4130 | case Shader::OPCODE_WHILE: WHILE(r, src0); break; |
| 4131 | case Shader::OPCODE_RET: RET(r); break; |
| 4132 | case Shader::OPCODE_LEAVE: LEAVE(r); break; |
| 4133 | case Shader::OPCODE_CMP: cmp(d, s0, s1, control); break; |
| 4134 | case Shader::OPCODE_ALL: all(d.x, s0); break; |
| 4135 | case Shader::OPCODE_ANY: any(d.x, s0); break; |
| 4136 | case Shader::OPCODE_NOT: not(d, s0); break; |
| 4137 | case Shader::OPCODE_OR: or(d.x, s0.x, s1.x); break; |
| 4138 | case Shader::OPCODE_XOR: xor(d.x, s0.x, s1.x); break; |
| 4139 | case Shader::OPCODE_AND: and(d.x, s0.x, s1.x); break; |
| 4140 | case Shader::OPCODE_END: break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4141 | default: |
| 4142 | ASSERT(false); |
| 4143 | } |
| 4144 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4145 | 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] | 4146 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4147 | if(dst.integer) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4148 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4149 | switch(opcode) |
| 4150 | { |
| 4151 | case Shader::OPCODE_DIV: |
| 4152 | if(dst.x) d.x = Trunc(d.x); |
| 4153 | if(dst.y) d.y = Trunc(d.y); |
| 4154 | if(dst.z) d.z = Trunc(d.z); |
| 4155 | if(dst.w) d.w = Trunc(d.w); |
| 4156 | break; |
| 4157 | default: |
| 4158 | break; // No truncation to integer required when arguments are integer |
| 4159 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4160 | } |
| 4161 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4162 | if(dst.saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4163 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4164 | if(dst.x) d.x = Max(d.x, Float4(0.0f)); |
| 4165 | if(dst.y) d.y = Max(d.y, Float4(0.0f)); |
| 4166 | if(dst.z) d.z = Max(d.z, Float4(0.0f)); |
| 4167 | if(dst.w) d.w = Max(d.w, Float4(0.0f)); |
| 4168 | |
| 4169 | if(dst.x) d.x = Min(d.x, Float4(1.0f)); |
| 4170 | if(dst.y) d.y = Min(d.y, Float4(1.0f)); |
| 4171 | if(dst.z) d.z = Min(d.z, Float4(1.0f)); |
| 4172 | if(dst.w) d.w = Min(d.w, Float4(1.0f)); |
| 4173 | } |
| 4174 | |
Nicolas Capens | c6e8ab1 | 2014-05-06 23:31:07 -0400 | [diff] [blame] | 4175 | if(instruction->isPredicated()) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4176 | { |
| 4177 | Vector4f pDst; // FIXME: Rename |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4178 | |
| 4179 | switch(dst.type) |
| 4180 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4181 | case Shader::PARAMETER_TEMP: |
| 4182 | if(dst.rel.type == Shader::PARAMETER_VOID) |
| 4183 | { |
| 4184 | if(dst.x) pDst.x = r.rf[dst.index].x; |
| 4185 | if(dst.y) pDst.y = r.rf[dst.index].y; |
| 4186 | if(dst.z) pDst.z = r.rf[dst.index].z; |
| 4187 | if(dst.w) pDst.w = r.rf[dst.index].w; |
| 4188 | } |
| 4189 | else |
| 4190 | { |
| 4191 | Int a = relativeAddress(r, dst); |
| 4192 | |
| 4193 | if(dst.x) pDst.x = r.rf[dst.index + a].x; |
| 4194 | if(dst.y) pDst.y = r.rf[dst.index + a].y; |
| 4195 | if(dst.z) pDst.z = r.rf[dst.index + a].z; |
| 4196 | if(dst.w) pDst.w = r.rf[dst.index + a].w; |
| 4197 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4198 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4199 | case Shader::PARAMETER_COLOROUT: |
| 4200 | ASSERT(dst.rel.type == Shader::PARAMETER_VOID); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4201 | if(dst.x) pDst.x = r.oC[dst.index].x; |
| 4202 | if(dst.y) pDst.y = r.oC[dst.index].y; |
| 4203 | if(dst.z) pDst.z = r.oC[dst.index].z; |
| 4204 | if(dst.w) pDst.w = r.oC[dst.index].w; |
| 4205 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4206 | case Shader::PARAMETER_PREDICATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4207 | if(dst.x) pDst.x = r.p0.x; |
| 4208 | if(dst.y) pDst.y = r.p0.y; |
| 4209 | if(dst.z) pDst.z = r.p0.z; |
| 4210 | if(dst.w) pDst.w = r.p0.w; |
| 4211 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4212 | case Shader::PARAMETER_DEPTHOUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4213 | pDst.x = r.oDepth; |
| 4214 | break; |
| 4215 | default: |
| 4216 | ASSERT(false); |
| 4217 | } |
| 4218 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4219 | Int4 enable = enableMask(r, instruction); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4220 | |
| 4221 | Int4 xEnable = enable; |
| 4222 | Int4 yEnable = enable; |
| 4223 | Int4 zEnable = enable; |
| 4224 | Int4 wEnable = enable; |
| 4225 | |
| 4226 | if(predicate) |
| 4227 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4228 | unsigned char pSwizzle = instruction->predicateSwizzle; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4229 | |
| 4230 | Float4 xPredicate = r.p0[(pSwizzle >> 0) & 0x03]; |
| 4231 | Float4 yPredicate = r.p0[(pSwizzle >> 2) & 0x03]; |
| 4232 | Float4 zPredicate = r.p0[(pSwizzle >> 4) & 0x03]; |
| 4233 | Float4 wPredicate = r.p0[(pSwizzle >> 6) & 0x03]; |
| 4234 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4235 | if(!instruction->predicateNot) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4236 | { |
| 4237 | if(dst.x) xEnable = xEnable & As<Int4>(xPredicate); |
| 4238 | if(dst.y) yEnable = yEnable & As<Int4>(yPredicate); |
| 4239 | if(dst.z) zEnable = zEnable & As<Int4>(zPredicate); |
| 4240 | if(dst.w) wEnable = wEnable & As<Int4>(wPredicate); |
| 4241 | } |
| 4242 | else |
| 4243 | { |
| 4244 | if(dst.x) xEnable = xEnable & ~As<Int4>(xPredicate); |
| 4245 | if(dst.y) yEnable = yEnable & ~As<Int4>(yPredicate); |
| 4246 | if(dst.z) zEnable = zEnable & ~As<Int4>(zPredicate); |
| 4247 | if(dst.w) wEnable = wEnable & ~As<Int4>(wPredicate); |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | if(dst.x) d.x = As<Float4>(As<Int4>(d.x) & xEnable); |
| 4252 | if(dst.y) d.y = As<Float4>(As<Int4>(d.y) & yEnable); |
| 4253 | if(dst.z) d.z = As<Float4>(As<Int4>(d.z) & zEnable); |
| 4254 | if(dst.w) d.w = As<Float4>(As<Int4>(d.w) & wEnable); |
| 4255 | |
| 4256 | if(dst.x) d.x = As<Float4>(As<Int4>(d.x) | (As<Int4>(pDst.x) & ~xEnable)); |
| 4257 | if(dst.y) d.y = As<Float4>(As<Int4>(d.y) | (As<Int4>(pDst.y) & ~yEnable)); |
| 4258 | if(dst.z) d.z = As<Float4>(As<Int4>(d.z) | (As<Int4>(pDst.z) & ~zEnable)); |
| 4259 | if(dst.w) d.w = As<Float4>(As<Int4>(d.w) | (As<Int4>(pDst.w) & ~wEnable)); |
| 4260 | } |
| 4261 | |
| 4262 | switch(dst.type) |
| 4263 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4264 | case Shader::PARAMETER_TEMP: |
| 4265 | if(dst.rel.type == Shader::PARAMETER_VOID) |
| 4266 | { |
| 4267 | if(dst.x) r.rf[dst.index].x = d.x; |
| 4268 | if(dst.y) r.rf[dst.index].y = d.y; |
| 4269 | if(dst.z) r.rf[dst.index].z = d.z; |
| 4270 | if(dst.w) r.rf[dst.index].w = d.w; |
| 4271 | } |
| 4272 | else |
| 4273 | { |
| 4274 | Int a = relativeAddress(r, dst); |
| 4275 | |
| 4276 | if(dst.x) r.rf[dst.index + a].x = d.x; |
| 4277 | if(dst.y) r.rf[dst.index + a].y = d.y; |
| 4278 | if(dst.z) r.rf[dst.index + a].z = d.z; |
| 4279 | if(dst.w) r.rf[dst.index + a].w = d.w; |
| 4280 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4281 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4282 | case Shader::PARAMETER_COLOROUT: |
| 4283 | ASSERT(dst.rel.type == Shader::PARAMETER_VOID); |
| 4284 | if(dst.x) {r.oC[dst.index].x = d.x; out[dst.index][0] = true;} |
| 4285 | if(dst.y) {r.oC[dst.index].y = d.y; out[dst.index][1] = true;} |
| 4286 | if(dst.z) {r.oC[dst.index].z = d.z; out[dst.index][2] = true;} |
| 4287 | 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] | 4288 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4289 | case Shader::PARAMETER_PREDICATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4290 | if(dst.x) r.p0.x = d.x; |
| 4291 | if(dst.y) r.p0.y = d.y; |
| 4292 | if(dst.z) r.p0.z = d.z; |
| 4293 | if(dst.w) r.p0.w = d.w; |
| 4294 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4295 | case Shader::PARAMETER_DEPTHOUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4296 | r.oDepth = d.x; |
| 4297 | break; |
| 4298 | default: |
| 4299 | ASSERT(false); |
| 4300 | } |
| 4301 | } |
| 4302 | } |
| 4303 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4304 | if(currentLabel != -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4305 | { |
| 4306 | Nucleus::setInsertBlock(returnBlock); |
| 4307 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4308 | |
| 4309 | for(int i = 0; i < 4; i++) |
| 4310 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 4311 | if(state.targetFormat[i] != FORMAT_NULL) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4312 | { |
| 4313 | if(!out[i][0]) r.oC[i].x = Float4(0.0f); |
| 4314 | if(!out[i][1]) r.oC[i].y = Float4(0.0f); |
| 4315 | if(!out[i][2]) r.oC[i].z = Float4(0.0f); |
| 4316 | if(!out[i][3]) r.oC[i].w = Float4(0.0f); |
| 4317 | } |
| 4318 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4319 | } |
| 4320 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4321 | Short4 PixelRoutine::convertFixed12(RValue<Float4> cf) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4322 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4323 | return RoundShort4(cf * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4324 | } |
| 4325 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4326 | void PixelRoutine::convertFixed12(Vector4i &ci, Vector4f &cf) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4327 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4328 | ci.x = convertFixed12(cf.x); |
| 4329 | ci.y = convertFixed12(cf.y); |
| 4330 | ci.z = convertFixed12(cf.z); |
| 4331 | ci.w = convertFixed12(cf.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | UShort4 PixelRoutine::convertFixed16(Float4 &cf, bool saturate) |
| 4335 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4336 | return UShort4(cf * Float4(0xFFFF), saturate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4337 | } |
| 4338 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4339 | void PixelRoutine::convertFixed16(Vector4i &ci, Vector4f &cf, bool saturate) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4340 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4341 | ci.x = convertFixed16(cf.x, saturate); |
| 4342 | ci.y = convertFixed16(cf.y, saturate); |
| 4343 | ci.z = convertFixed16(cf.z, saturate); |
| 4344 | ci.w = convertFixed16(cf.w, saturate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | Float4 PixelRoutine::convertSigned12(Short4 &ci) |
| 4348 | { |
| 4349 | return Float4(ci) * Float4(1.0f / 0x0FFE); |
| 4350 | } |
| 4351 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4352 | void PixelRoutine::convertSigned12(Vector4f &cf, Vector4i &ci) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4353 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4354 | cf.x = convertSigned12(ci.x); |
| 4355 | cf.y = convertSigned12(ci.y); |
| 4356 | cf.z = convertSigned12(ci.z); |
| 4357 | cf.w = convertSigned12(ci.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | Float4 PixelRoutine::convertUnsigned16(UShort4 ci) |
| 4361 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4362 | return Float4(ci) * Float4(1.0f / 0xFFFF); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4363 | } |
| 4364 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4365 | void PixelRoutine::sRGBtoLinear16_16(Registers &r, Vector4i &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4366 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4367 | c.x = As<UShort4>(c.x) >> 4; |
| 4368 | c.y = As<UShort4>(c.y) >> 4; |
| 4369 | c.z = As<UShort4>(c.z) >> 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4370 | |
| 4371 | sRGBtoLinear12_16(r, c); |
| 4372 | } |
| 4373 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4374 | void PixelRoutine::sRGBtoLinear12_16(Registers &r, Vector4i &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4375 | { |
| 4376 | Pointer<Byte> LUT = r.constants + OFFSET(Constants,sRGBtoLin12_16); |
| 4377 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4378 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); |
| 4379 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); |
| 4380 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); |
| 4381 | 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] | 4382 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4383 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 0))), 0); |
| 4384 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 1))), 1); |
| 4385 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 2))), 2); |
| 4386 | 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] | 4387 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4388 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 0))), 0); |
| 4389 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 1))), 1); |
| 4390 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 2))), 2); |
| 4391 | 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] | 4392 | } |
| 4393 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4394 | void PixelRoutine::linearToSRGB16_16(Registers &r, Vector4i &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4395 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4396 | c.x = As<UShort4>(c.x) >> 4; |
| 4397 | c.y = As<UShort4>(c.y) >> 4; |
| 4398 | c.z = As<UShort4>(c.z) >> 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4399 | |
| 4400 | linearToSRGB12_16(r, c); |
| 4401 | } |
| 4402 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4403 | void PixelRoutine::linearToSRGB12_16(Registers &r, Vector4i &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4404 | { |
| 4405 | Pointer<Byte> LUT = r.constants + OFFSET(Constants,linToSRGB12_16); |
| 4406 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4407 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); |
| 4408 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); |
| 4409 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); |
| 4410 | 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] | 4411 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4412 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 0))), 0); |
| 4413 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 1))), 1); |
| 4414 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 2))), 2); |
| 4415 | 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] | 4416 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4417 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 0))), 0); |
| 4418 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 1))), 1); |
| 4419 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 2))), 2); |
| 4420 | 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] | 4421 | } |
| 4422 | |
| 4423 | Float4 PixelRoutine::linearToSRGB(const Float4 &x) // Approximates x^(1.0/2.2) |
| 4424 | { |
| 4425 | Float4 sqrtx = Rcp_pp(RcpSqrt_pp(x)); |
| 4426 | Float4 sRGB = sqrtx * Float4(1.14f) - x * Float4(0.14f); |
| 4427 | |
| 4428 | return Min(Max(sRGB, Float4(0.0f)), Float4(1.0f)); |
| 4429 | } |
| 4430 | |
| 4431 | Float4 PixelRoutine::sRGBtoLinear(const Float4 &x) // Approximates x^2.2 |
| 4432 | { |
| 4433 | Float4 linear = x * x; |
| 4434 | linear = linear * Float4(0.73f) + linear * x * Float4(0.27f); |
| 4435 | |
| 4436 | return Min(Max(linear, Float4(0.0f)), Float4(1.0f)); |
| 4437 | } |
| 4438 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4439 | void PixelRoutine::MOV(Vector4i &dst, Vector4i &src0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4440 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4441 | dst.x = src0.x; |
| 4442 | dst.y = src0.y; |
| 4443 | dst.z = src0.z; |
| 4444 | dst.w = src0.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4445 | } |
| 4446 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4447 | void PixelRoutine::ADD(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4448 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4449 | dst.x = AddSat(src0.x, src1.x); |
| 4450 | dst.y = AddSat(src0.y, src1.y); |
| 4451 | dst.z = AddSat(src0.z, src1.z); |
| 4452 | dst.w = AddSat(src0.w, src1.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4453 | } |
| 4454 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4455 | void PixelRoutine::SUB(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4456 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4457 | dst.x = SubSat(src0.x, src1.x); |
| 4458 | dst.y = SubSat(src0.y, src1.y); |
| 4459 | dst.z = SubSat(src0.z, src1.z); |
| 4460 | dst.w = SubSat(src0.w, src1.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4461 | } |
| 4462 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4463 | void PixelRoutine::MAD(Vector4i &dst, Vector4i &src0, Vector4i &src1, Vector4i &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4464 | { |
| 4465 | // FIXME: Long fixed-point multiply fixup |
| 4466 | {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);} |
| 4467 | {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);} |
| 4468 | {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);} |
| 4469 | {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);} |
| 4470 | } |
| 4471 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4472 | void PixelRoutine::MUL(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4473 | { |
| 4474 | // FIXME: Long fixed-point multiply fixup |
| 4475 | {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);} |
| 4476 | {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);} |
| 4477 | {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);} |
| 4478 | {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);} |
| 4479 | } |
| 4480 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4481 | void PixelRoutine::DP3(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4482 | { |
| 4483 | Short4 t0; |
| 4484 | Short4 t1; |
| 4485 | |
| 4486 | // FIXME: Long fixed-point multiply fixup |
| 4487 | t0 = MulHigh(src0.x, src1.x); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); |
| 4488 | t1 = MulHigh(src0.y, src1.y); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4489 | t0 = AddSat(t0, t1); |
| 4490 | t1 = MulHigh(src0.z, src1.z); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4491 | t0 = AddSat(t0, t1); |
| 4492 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4493 | dst.x = t0; |
| 4494 | dst.y = t0; |
| 4495 | dst.z = t0; |
| 4496 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4497 | } |
| 4498 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4499 | void PixelRoutine::DP4(Vector4i &dst, Vector4i &src0, Vector4i &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4500 | { |
| 4501 | Short4 t0; |
| 4502 | Short4 t1; |
| 4503 | |
| 4504 | // FIXME: Long fixed-point multiply fixup |
| 4505 | t0 = MulHigh(src0.x, src1.x); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); t0 = AddSat(t0, t0); |
| 4506 | t1 = MulHigh(src0.y, src1.y); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4507 | t0 = AddSat(t0, t1); |
| 4508 | t1 = MulHigh(src0.z, src1.z); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4509 | t0 = AddSat(t0, t1); |
| 4510 | t1 = MulHigh(src0.w, src1.w); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); t1 = AddSat(t1, t1); |
| 4511 | t0 = AddSat(t0, t1); |
| 4512 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4513 | dst.x = t0; |
| 4514 | dst.y = t0; |
| 4515 | dst.z = t0; |
| 4516 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4517 | } |
| 4518 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4519 | void PixelRoutine::LRP(Vector4i &dst, Vector4i &src0, Vector4i &src1, Vector4i &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4520 | { |
| 4521 | // FIXME: Long fixed-point multiply fixup |
| 4522 | {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);} |
| 4523 | {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);} |
| 4524 | {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);} |
| 4525 | {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);} |
| 4526 | } |
| 4527 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4528 | 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] | 4529 | { |
| 4530 | Float4 uw; |
| 4531 | Float4 vw; |
| 4532 | Float4 sw; |
| 4533 | |
| 4534 | if(state.interpolant[2 + coordinate].component & 0x01) |
| 4535 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4536 | uw = Max(u, Float4(0.0f)); |
| 4537 | uw = Min(uw, Float4(1.0f)); |
| 4538 | dst.x = convertFixed12(uw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4539 | } |
| 4540 | else |
| 4541 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4542 | dst.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | if(state.interpolant[2 + coordinate].component & 0x02) |
| 4546 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4547 | vw = Max(v, Float4(0.0f)); |
| 4548 | vw = Min(vw, Float4(1.0f)); |
| 4549 | dst.y = convertFixed12(vw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4550 | } |
| 4551 | else |
| 4552 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4553 | dst.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | if(state.interpolant[2 + coordinate].component & 0x04) |
| 4557 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4558 | sw = Max(s, Float4(0.0f)); |
| 4559 | sw = Min(sw, Float4(1.0f)); |
| 4560 | dst.z = convertFixed12(sw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4561 | } |
| 4562 | else |
| 4563 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4564 | dst.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4565 | } |
| 4566 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4567 | dst.w = Short4(0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4568 | } |
| 4569 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4570 | 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] | 4571 | { |
| 4572 | Float4 uw = u; |
| 4573 | Float4 vw = v; |
| 4574 | Float4 sw = s; |
| 4575 | |
| 4576 | if(project) |
| 4577 | { |
| 4578 | uw *= Rcp_pp(s); |
| 4579 | vw *= Rcp_pp(s); |
| 4580 | } |
| 4581 | |
| 4582 | if(state.interpolant[2 + coordinate].component & 0x01) |
| 4583 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4584 | uw *= Float4(0x1000); |
| 4585 | uw = Max(uw, Float4(-0x8000)); |
| 4586 | uw = Min(uw, Float4(0x7FFF)); |
| 4587 | dst.x = RoundShort4(uw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4588 | } |
| 4589 | else |
| 4590 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4591 | dst.x = Short4(0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | if(state.interpolant[2 + coordinate].component & 0x02) |
| 4595 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4596 | vw *= Float4(0x1000); |
| 4597 | vw = Max(vw, Float4(-0x8000)); |
| 4598 | vw = Min(vw, Float4(0x7FFF)); |
| 4599 | dst.y = RoundShort4(vw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4600 | } |
| 4601 | else |
| 4602 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4603 | dst.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | if(state.interpolant[2 + coordinate].component & 0x04) |
| 4607 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4608 | sw *= Float4(0x1000); |
| 4609 | sw = Max(sw, Float4(-0x8000)); |
| 4610 | sw = Min(sw, Float4(0x7FFF)); |
| 4611 | dst.z = RoundShort4(sw); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4612 | } |
| 4613 | else |
| 4614 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4615 | dst.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4616 | } |
| 4617 | } |
| 4618 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4619 | 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] | 4620 | { |
| 4621 | TEXM3X3PAD(r, u, v, s, src, 0, false); |
| 4622 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4623 | Short4 t0 = RoundShort4(r.u_ * Float4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4624 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4625 | dst.x = t0; |
| 4626 | dst.y = t0; |
| 4627 | dst.z = t0; |
| 4628 | dst.w = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4629 | } |
| 4630 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4631 | 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] | 4632 | { |
| 4633 | TEXM3X3PAD(r, u, v, s, src0, 0, false); |
| 4634 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4635 | r.v_ = Float4(0.0f); |
| 4636 | r.w_ = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4637 | |
| 4638 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4639 | } |
| 4640 | |
| 4641 | void PixelRoutine::TEXKILL(Int cMask[4], Float4 &u, Float4 &v, Float4 &s) |
| 4642 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4643 | Int kill = SignMask(CmpNLT(u, Float4(0.0f))) & |
| 4644 | SignMask(CmpNLT(v, Float4(0.0f))) & |
| 4645 | SignMask(CmpNLT(s, Float4(0.0f))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4646 | |
| 4647 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 4648 | { |
| 4649 | cMask[q] &= kill; |
| 4650 | } |
| 4651 | } |
| 4652 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4653 | void PixelRoutine::TEXKILL(Int cMask[4], Vector4i &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4654 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4655 | Short4 test = src.x | src.y | src.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4656 | Int kill = SignMask(Pack(test, test)) ^ 0x0000000F; |
| 4657 | |
| 4658 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 4659 | { |
| 4660 | cMask[q] &= kill; |
| 4661 | } |
| 4662 | } |
| 4663 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4664 | 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] | 4665 | { |
| 4666 | sampleTexture(r, dst, sampler, u, v, s, s, project); |
| 4667 | } |
| 4668 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4669 | 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] | 4670 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4671 | Float4 u = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4672 | Float4 v = Float4(src.y) * Float4(1.0f / 0x0FFE); |
| 4673 | Float4 s = Float4(src.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4674 | |
| 4675 | sampleTexture(r, dst, sampler, u, v, s, s, project); |
| 4676 | } |
| 4677 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4678 | 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] | 4679 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4680 | Float4 du = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4681 | Float4 dv = Float4(src.y) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4682 | |
| 4683 | Float4 du2 = du; |
| 4684 | Float4 dv2 = dv; |
| 4685 | |
| 4686 | du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 4687 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 4688 | du += dv2; |
| 4689 | dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 4690 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 4691 | dv += du2; |
| 4692 | |
| 4693 | Float4 u_ = u + du; |
| 4694 | Float4 v_ = v + dv; |
| 4695 | |
| 4696 | sampleTexture(r, dst, stage, u_, v_, s, s); |
| 4697 | } |
| 4698 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4699 | 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] | 4700 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4701 | Float4 du = Float4(src.x) * Float4(1.0f / 0x0FFE); |
| 4702 | Float4 dv = Float4(src.y) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4703 | |
| 4704 | Float4 du2 = du; |
| 4705 | Float4 dv2 = dv; |
| 4706 | |
| 4707 | du *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][0])); |
| 4708 | dv2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][0])); |
| 4709 | du += dv2; |
| 4710 | dv *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[1][1])); |
| 4711 | du2 *= *Pointer<Float4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4F[0][1])); |
| 4712 | dv += du2; |
| 4713 | |
| 4714 | Float4 u_ = u + du; |
| 4715 | Float4 v_ = v + dv; |
| 4716 | |
| 4717 | sampleTexture(r, dst, stage, u_, v_, s, s); |
| 4718 | |
| 4719 | Short4 L; |
| 4720 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4721 | L = src.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4722 | L = MulHigh(L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceScale4))); |
| 4723 | L = L << 4; |
| 4724 | L = AddSat(L, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].luminanceOffset4))); |
| 4725 | L = Max(L, Short4(0x0000, 0x0000, 0x0000, 0x0000)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4726 | L = Min(L, Short4(0x1000)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4727 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4728 | dst.x = MulHigh(dst.x, L); dst.x = dst.x << 4; |
| 4729 | dst.y = MulHigh(dst.y, L); dst.y = dst.y << 4; |
| 4730 | dst.z = MulHigh(dst.z, L); dst.z = dst.z << 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4731 | } |
| 4732 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4733 | void PixelRoutine::TEXREG2AR(Registers &r, Vector4i &dst, Vector4i &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4734 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4735 | Float4 u = Float4(src0.w) * Float4(1.0f / 0x0FFE); |
| 4736 | Float4 v = Float4(src0.x) * Float4(1.0f / 0x0FFE); |
| 4737 | Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4738 | |
| 4739 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4740 | } |
| 4741 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4742 | void PixelRoutine::TEXREG2GB(Registers &r, Vector4i &dst, Vector4i &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4743 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4744 | Float4 u = Float4(src0.y) * Float4(1.0f / 0x0FFE); |
| 4745 | Float4 v = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4746 | Float4 s = v; |
| 4747 | |
| 4748 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4749 | } |
| 4750 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4751 | void PixelRoutine::TEXREG2RGB(Registers &r, Vector4i &dst, Vector4i &src0, int stage) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4752 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4753 | Float4 u = Float4(src0.x) * Float4(1.0f / 0x0FFE); |
| 4754 | Float4 v = Float4(src0.y) * Float4(1.0f / 0x0FFE); |
| 4755 | Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4756 | |
| 4757 | sampleTexture(r, dst, stage, u, v, s, s); |
| 4758 | } |
| 4759 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4760 | 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] | 4761 | { |
| 4762 | TEXM3X2PAD(r, u, v, s, src, 1, signedScaling); |
| 4763 | |
| 4764 | // z / w |
| 4765 | r.u_ *= Rcp_pp(r.v_); // FIXME: Set result to 1.0 when division by zero |
| 4766 | |
| 4767 | r.oDepth = r.u_; |
| 4768 | } |
| 4769 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4770 | 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] | 4771 | { |
| 4772 | TEXM3X3PAD(r, u, v, s, src0, component, signedScaling); |
| 4773 | } |
| 4774 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4775 | 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] | 4776 | { |
| 4777 | TEXM3X2PAD(r, u, v, s, src0, 1, signedScaling); |
| 4778 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4779 | r.w_ = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4780 | |
| 4781 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4782 | } |
| 4783 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4784 | 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] | 4785 | { |
| 4786 | TEXM3X3PAD(r, u, v, s, src0, 2, signedScaling); |
| 4787 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4788 | dst.x = RoundShort4(r.u_ * Float4(0x1000)); |
| 4789 | dst.y = RoundShort4(r.v_ * Float4(0x1000)); |
| 4790 | dst.z = RoundShort4(r.w_ * Float4(0x1000)); |
| 4791 | dst.w = Short4(0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4792 | } |
| 4793 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4794 | 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] | 4795 | { |
| 4796 | if(component == 0 || previousScaling != signedScaling) // FIXME: Other source modifiers? |
| 4797 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4798 | r.U = Float4(src0.x); |
| 4799 | r.V = Float4(src0.y); |
| 4800 | r.W = Float4(src0.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4801 | |
| 4802 | previousScaling = signedScaling; |
| 4803 | } |
| 4804 | |
| 4805 | Float4 x = r.U * u + r.V * v + r.W * s; |
| 4806 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4807 | x *= Float4(1.0f / 0x1000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4808 | |
| 4809 | switch(component) |
| 4810 | { |
| 4811 | case 0: r.u_ = x; break; |
| 4812 | case 1: r.v_ = x; break; |
| 4813 | case 2: r.w_ = x; break; |
| 4814 | default: ASSERT(false); |
| 4815 | } |
| 4816 | } |
| 4817 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4818 | 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] | 4819 | { |
| 4820 | TEXM3X3PAD(r, u, v, s, src0, 2, false); |
| 4821 | |
| 4822 | Float4 E[3]; // Eye vector |
| 4823 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4824 | E[0] = Float4(src1.x) * Float4(1.0f / 0x0FFE); |
| 4825 | E[1] = Float4(src1.y) * Float4(1.0f / 0x0FFE); |
| 4826 | E[2] = Float4(src1.z) * Float4(1.0f / 0x0FFE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4827 | |
| 4828 | // Reflection |
| 4829 | Float4 u__; |
| 4830 | Float4 v__; |
| 4831 | Float4 w__; |
| 4832 | |
| 4833 | // (u'', v'', w'') = 2 * (N . E) * N - E * (N . N) |
| 4834 | u__ = r.u_ * E[0]; |
| 4835 | v__ = r.v_ * E[1]; |
| 4836 | w__ = r.w_ * E[2]; |
| 4837 | u__ += v__ + w__; |
| 4838 | u__ += u__; |
| 4839 | v__ = u__; |
| 4840 | w__ = u__; |
| 4841 | u__ *= r.u_; |
| 4842 | v__ *= r.v_; |
| 4843 | w__ *= r.w_; |
| 4844 | r.u_ *= r.u_; |
| 4845 | r.v_ *= r.v_; |
| 4846 | r.w_ *= r.w_; |
| 4847 | r.u_ += r.v_ + r.w_; |
| 4848 | u__ -= E[0] * r.u_; |
| 4849 | v__ -= E[1] * r.u_; |
| 4850 | w__ -= E[2] * r.u_; |
| 4851 | |
| 4852 | sampleTexture(r, dst, stage, u__, v__, w__, w__); |
| 4853 | } |
| 4854 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4855 | 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] | 4856 | { |
| 4857 | TEXM3X3PAD(r, u, v, s, src0, 2, signedScaling); |
| 4858 | |
| 4859 | sampleTexture(r, dst, stage, r.u_, r.v_, r.w_, r.w_); |
| 4860 | } |
| 4861 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4862 | 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] | 4863 | { |
| 4864 | TEXM3X3PAD(r, u, v, s, src0, 2, false); |
| 4865 | |
| 4866 | Float4 E[3]; // Eye vector |
| 4867 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4868 | E[0] = r.vf[2 + stage - 2].w; |
| 4869 | E[1] = r.vf[2 + stage - 1].w; |
| 4870 | E[2] = r.vf[2 + stage - 0].w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4871 | |
| 4872 | // Reflection |
| 4873 | Float4 u__; |
| 4874 | Float4 v__; |
| 4875 | Float4 w__; |
| 4876 | |
| 4877 | // (u'', v'', w'') = 2 * (N . E) * N - E * (N . N) |
| 4878 | u__ = r.u_ * E[0]; |
| 4879 | v__ = r.v_ * E[1]; |
| 4880 | w__ = r.w_ * E[2]; |
| 4881 | u__ += v__ + w__; |
| 4882 | u__ += u__; |
| 4883 | v__ = u__; |
| 4884 | w__ = u__; |
| 4885 | u__ *= r.u_; |
| 4886 | v__ *= r.v_; |
| 4887 | w__ *= r.w_; |
| 4888 | r.u_ *= r.u_; |
| 4889 | r.v_ *= r.v_; |
| 4890 | r.w_ *= r.w_; |
| 4891 | r.u_ += r.v_ + r.w_; |
| 4892 | u__ -= E[0] * r.u_; |
| 4893 | v__ -= E[1] * r.u_; |
| 4894 | w__ -= E[2] * r.u_; |
| 4895 | |
| 4896 | sampleTexture(r, dst, stage, u__, v__, w__, w__); |
| 4897 | } |
| 4898 | |
| 4899 | void PixelRoutine::TEXDEPTH(Registers &r) |
| 4900 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4901 | r.u_ = Float4(r.ri[5].x); |
| 4902 | r.v_ = Float4(r.ri[5].y); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4903 | |
| 4904 | // z / w |
| 4905 | r.u_ *= Rcp_pp(r.v_); // FIXME: Set result to 1.0 when division by zero |
| 4906 | |
| 4907 | r.oDepth = r.u_; |
| 4908 | } |
| 4909 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4910 | void PixelRoutine::CND(Vector4i &dst, Vector4i &src0, Vector4i &src1, Vector4i &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4911 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4912 | {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;}; |
| 4913 | {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;}; |
| 4914 | {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;}; |
| 4915 | {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] | 4916 | } |
| 4917 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4918 | void PixelRoutine::CMP(Vector4i &dst, Vector4i &src0, Vector4i &src1, Vector4i &src2) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4919 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4920 | {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;}; |
| 4921 | {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;}; |
| 4922 | {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;}; |
| 4923 | {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] | 4924 | } |
| 4925 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4926 | 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] | 4927 | { |
| 4928 | Short4 t0; |
| 4929 | Short4 t1; |
| 4930 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4931 | // dst.x = src0.x + BUMPENVMAT00(stage) * src1.x + BUMPENVMAT10(stage) * src1.y |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4932 | t0 = MulHigh(src1.x, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[0][0]))); t0 = t0 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4933 | t1 = MulHigh(src1.y, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[1][0]))); t1 = t1 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4934 | t0 = AddSat(t0, t1); |
| 4935 | t0 = AddSat(t0, src0.x); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4936 | dst.x = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4937 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4938 | // dst.y = src0.y + BUMPENVMAT01(stage) * src1.x + BUMPENVMAT11(stage) * src1.y |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4939 | t0 = MulHigh(src1.x, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[0][1]))); t0 = t0 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4940 | t1 = MulHigh(src1.y, *Pointer<Short4>(r.data + OFFSET(DrawData,textureStage[stage].bumpmapMatrix4W[1][1]))); t1 = t1 << 4; // FIXME: Matrix components range? Overflow hazard. |
| 4941 | t0 = AddSat(t0, t1); |
| 4942 | t0 = AddSat(t0, src0.y); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4943 | dst.y = t0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4944 | } |
| 4945 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4946 | void PixelRoutine::M3X2(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4947 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4948 | Vector4f row0 = reg(r, src1, 0); |
| 4949 | Vector4f row1 = reg(r, src1, 1); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4950 | |
| 4951 | dst.x = dot3(src0, row0); |
| 4952 | dst.y = dot3(src0, row1); |
| 4953 | } |
| 4954 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4955 | void PixelRoutine::M3X3(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4956 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4957 | Vector4f row0 = reg(r, src1, 0); |
| 4958 | Vector4f row1 = reg(r, src1, 1); |
| 4959 | Vector4f row2 = reg(r, src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4960 | |
| 4961 | dst.x = dot3(src0, row0); |
| 4962 | dst.y = dot3(src0, row1); |
| 4963 | dst.z = dot3(src0, row2); |
| 4964 | } |
| 4965 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4966 | void PixelRoutine::M3X4(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4967 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4968 | Vector4f row0 = reg(r, src1, 0); |
| 4969 | Vector4f row1 = reg(r, src1, 1); |
| 4970 | Vector4f row2 = reg(r, src1, 2); |
| 4971 | Vector4f row3 = reg(r, src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4972 | |
| 4973 | dst.x = dot3(src0, row0); |
| 4974 | dst.y = dot3(src0, row1); |
| 4975 | dst.z = dot3(src0, row2); |
| 4976 | dst.w = dot3(src0, row3); |
| 4977 | } |
| 4978 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4979 | void PixelRoutine::M4X3(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4980 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4981 | Vector4f row0 = reg(r, src1, 0); |
| 4982 | Vector4f row1 = reg(r, src1, 1); |
| 4983 | Vector4f row2 = reg(r, src1, 2); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4984 | |
| 4985 | dst.x = dot4(src0, row0); |
| 4986 | dst.y = dot4(src0, row1); |
| 4987 | dst.z = dot4(src0, row2); |
| 4988 | } |
| 4989 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4990 | void PixelRoutine::M4X4(Registers &r, Vector4f &dst, Vector4f &src0, const Src &src1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4991 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 4992 | Vector4f row0 = reg(r, src1, 0); |
| 4993 | Vector4f row1 = reg(r, src1, 1); |
| 4994 | Vector4f row2 = reg(r, src1, 2); |
| 4995 | Vector4f row3 = reg(r, src1, 3); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4996 | |
| 4997 | dst.x = dot4(src0, row0); |
| 4998 | dst.y = dot4(src0, row1); |
| 4999 | dst.z = dot4(src0, row2); |
| 5000 | dst.w = dot4(src0, row3); |
| 5001 | } |
| 5002 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5003 | 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] | 5004 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5005 | Vector4f tmp; |
| 5006 | 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] | 5007 | |
| 5008 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 5009 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 5010 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 5011 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 5012 | } |
| 5013 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5014 | 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] | 5015 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5016 | Vector4f tmp; |
| 5017 | 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] | 5018 | |
| 5019 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 5020 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 5021 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 5022 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 5023 | } |
| 5024 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5025 | 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] | 5026 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5027 | Vector4f tmp; |
| 5028 | 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] | 5029 | |
| 5030 | dst.x = tmp[(src1.swizzle >> 0) & 0x3]; |
| 5031 | dst.y = tmp[(src1.swizzle >> 2) & 0x3]; |
| 5032 | dst.z = tmp[(src1.swizzle >> 4) & 0x3]; |
| 5033 | dst.w = tmp[(src1.swizzle >> 6) & 0x3]; |
| 5034 | } |
| 5035 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5036 | void PixelRoutine::TEXKILL(Int cMask[4], Vector4f &src, unsigned char mask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5037 | { |
| 5038 | Int kill = -1; |
| 5039 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5040 | if(mask & 0x1) kill &= SignMask(CmpNLT(src.x, Float4(0.0f))); |
| 5041 | if(mask & 0x2) kill &= SignMask(CmpNLT(src.y, Float4(0.0f))); |
| 5042 | if(mask & 0x4) kill &= SignMask(CmpNLT(src.z, Float4(0.0f))); |
| 5043 | if(mask & 0x8) kill &= SignMask(CmpNLT(src.w, Float4(0.0f))); |
| 5044 | |
| 5045 | // FIXME: Dynamic branching affects TEXKILL? |
| 5046 | // if(shader->containsDynamicBranching()) |
| 5047 | // { |
| 5048 | // kill = ~SignMask(enableMask(r)); |
| 5049 | // } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5050 | |
| 5051 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 5052 | { |
| 5053 | cMask[q] &= kill; |
| 5054 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5055 | |
| 5056 | // FIXME: Branch to end of shader if all killed? |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5057 | } |
| 5058 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5059 | void PixelRoutine::DISCARD(Registers &r, Int cMask[4], const Shader::Instruction *instruction) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5060 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5061 | Int kill = 0; |
| 5062 | |
| 5063 | if(shader->containsDynamicBranching()) |
| 5064 | { |
| 5065 | kill = ~SignMask(enableMask(r, instruction)); |
| 5066 | } |
| 5067 | |
| 5068 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 5069 | { |
| 5070 | cMask[q] &= kill; |
| 5071 | } |
| 5072 | |
| 5073 | // FIXME: Branch to end of shader if all killed? |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5074 | } |
| 5075 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5076 | void PixelRoutine::DFDX(Vector4f &dst, Vector4f &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5077 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5078 | dst.x = src.x.yyww - src.x.xxzz; |
| 5079 | dst.y = src.y.yyww - src.y.xxzz; |
| 5080 | dst.z = src.z.yyww - src.z.xxzz; |
| 5081 | dst.w = src.w.yyww - src.w.xxzz; |
| 5082 | } |
| 5083 | |
| 5084 | void PixelRoutine::DFDY(Vector4f &dst, Vector4f &src) |
| 5085 | { |
| 5086 | dst.x = src.x.zwzw - src.x.xyxy; |
| 5087 | dst.y = src.y.zwzw - src.y.xyxy; |
| 5088 | dst.z = src.z.zwzw - src.z.xyxy; |
| 5089 | dst.w = src.w.zwzw - src.w.xyxy; |
| 5090 | } |
| 5091 | |
| 5092 | void PixelRoutine::FWIDTH(Vector4f &dst, Vector4f &src) |
| 5093 | { |
| 5094 | // abs(dFdx(src)) + abs(dFdy(src)); |
| 5095 | dst.x = Abs(src.x.yyww - src.x.xxzz) + Abs(src.x.zwzw - src.x.xyxy); |
| 5096 | dst.y = Abs(src.y.yyww - src.x.xxzz) + Abs(src.y.zwzw - src.y.xyxy); |
| 5097 | dst.z = Abs(src.z.yyww - src.x.xxzz) + Abs(src.z.zwzw - src.z.xyxy); |
| 5098 | 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] | 5099 | } |
| 5100 | |
| 5101 | void PixelRoutine::BREAK(Registers &r) |
| 5102 | { |
| 5103 | llvm::BasicBlock *deadBlock = Nucleus::createBasicBlock(); |
| 5104 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1]; |
| 5105 | |
| 5106 | if(breakDepth == 0) |
| 5107 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5108 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5109 | Nucleus::createBr(endBlock); |
| 5110 | } |
| 5111 | else |
| 5112 | { |
| 5113 | r.enableBreak = r.enableBreak & ~r.enableStack[r.enableIndex]; |
| 5114 | Bool allBreak = SignMask(r.enableBreak) == 0x0; |
| 5115 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5116 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5117 | branch(allBreak, endBlock, deadBlock); |
| 5118 | } |
| 5119 | |
| 5120 | Nucleus::setInsertBlock(deadBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5121 | r.enableIndex = r.enableIndex + breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5122 | } |
| 5123 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5124 | void PixelRoutine::BREAKC(Registers &r, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5125 | { |
| 5126 | Int4 condition; |
| 5127 | |
| 5128 | switch(control) |
| 5129 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5130 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 5131 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 5132 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 5133 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 5134 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 5135 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5136 | default: |
| 5137 | ASSERT(false); |
| 5138 | } |
| 5139 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5140 | BREAK(r, condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | void PixelRoutine::BREAKP(Registers &r, const Src &predicateRegister) // FIXME: Factor out parts common with BREAKC |
| 5144 | { |
| 5145 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 5146 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5147 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5148 | { |
| 5149 | condition = ~condition; |
| 5150 | } |
| 5151 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5152 | BREAK(r, condition); |
| 5153 | } |
| 5154 | |
| 5155 | void PixelRoutine::BREAK(Registers &r, Int4 &condition) |
| 5156 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5157 | condition &= r.enableStack[r.enableIndex]; |
| 5158 | |
| 5159 | llvm::BasicBlock *continueBlock = Nucleus::createBasicBlock(); |
| 5160 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth - 1]; |
| 5161 | |
| 5162 | r.enableBreak = r.enableBreak & ~condition; |
| 5163 | Bool allBreak = SignMask(r.enableBreak) == 0x0; |
| 5164 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5165 | r.enableIndex = r.enableIndex - breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5166 | branch(allBreak, endBlock, continueBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5167 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5168 | Nucleus::setInsertBlock(continueBlock); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5169 | r.enableIndex = r.enableIndex + breakDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5170 | } |
| 5171 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5172 | void PixelRoutine::CONTINUE(Registers &r) |
| 5173 | { |
| 5174 | r.enableContinue = r.enableContinue & ~r.enableStack[r.enableIndex]; |
| 5175 | } |
| 5176 | |
| 5177 | void PixelRoutine::TEST() |
| 5178 | { |
| 5179 | whileTest = true; |
| 5180 | } |
| 5181 | |
| 5182 | void PixelRoutine::CALL(Registers &r, int labelIndex, int callSiteIndex) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5183 | { |
| 5184 | if(!labelBlock[labelIndex]) |
| 5185 | { |
| 5186 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5187 | } |
| 5188 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5189 | if(callRetBlock[labelIndex].size() > 1) |
| 5190 | { |
| 5191 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5192 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5193 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5194 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5195 | |
| 5196 | Nucleus::createBr(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5197 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 5198 | |
| 5199 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5200 | } |
| 5201 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5202 | void PixelRoutine::CALLNZ(Registers &r, int labelIndex, int callSiteIndex, const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5203 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5204 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5205 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5206 | CALLNZb(r, labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5207 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5208 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5209 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5210 | CALLNZp(r, labelIndex, callSiteIndex, src); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5211 | } |
| 5212 | else ASSERT(false); |
| 5213 | } |
| 5214 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5215 | void PixelRoutine::CALLNZb(Registers &r, int labelIndex, int callSiteIndex, const Src &boolRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5216 | { |
| 5217 | Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,ps.b[boolRegister.index])) != Byte(0)); // FIXME |
| 5218 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5219 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5220 | { |
| 5221 | condition = !condition; |
| 5222 | } |
| 5223 | |
| 5224 | if(!labelBlock[labelIndex]) |
| 5225 | { |
| 5226 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5227 | } |
| 5228 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5229 | if(callRetBlock[labelIndex].size() > 1) |
| 5230 | { |
| 5231 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5232 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5233 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5234 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5235 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5236 | branch(condition, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 5237 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
| 5238 | |
| 5239 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5240 | } |
| 5241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5242 | void PixelRoutine::CALLNZp(Registers &r, int labelIndex, int callSiteIndex, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5243 | { |
| 5244 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 5245 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5246 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5247 | { |
| 5248 | condition = ~condition; |
| 5249 | } |
| 5250 | |
| 5251 | condition &= r.enableStack[r.enableIndex]; |
| 5252 | |
| 5253 | if(!labelBlock[labelIndex]) |
| 5254 | { |
| 5255 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5256 | } |
| 5257 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5258 | if(callRetBlock[labelIndex].size() > 1) |
| 5259 | { |
| 5260 | r.callStack[r.stackIndex++] = UInt(callSiteIndex); |
| 5261 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5262 | |
| 5263 | r.enableIndex++; |
| 5264 | r.enableStack[r.enableIndex] = condition; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5265 | Int4 restoreLeave = r.enableLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5266 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5267 | Bool notAllFalse = SignMask(condition) != 0; |
| 5268 | branch(notAllFalse, labelBlock[labelIndex], callRetBlock[labelIndex][callSiteIndex]); |
| 5269 | Nucleus::setInsertBlock(callRetBlock[labelIndex][callSiteIndex]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5270 | |
| 5271 | r.enableIndex--; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5272 | r.enableLeave = restoreLeave; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | void PixelRoutine::ELSE(Registers &r) |
| 5276 | { |
| 5277 | ifDepth--; |
| 5278 | |
| 5279 | llvm::BasicBlock *falseBlock = ifFalseBlock[ifDepth]; |
| 5280 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5281 | |
| 5282 | if(isConditionalIf[ifDepth]) |
| 5283 | { |
| 5284 | Int4 condition = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1]; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5285 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5286 | |
| 5287 | branch(notAllFalse, falseBlock, endBlock); |
| 5288 | |
| 5289 | r.enableStack[r.enableIndex] = ~r.enableStack[r.enableIndex] & r.enableStack[r.enableIndex - 1]; |
| 5290 | } |
| 5291 | else |
| 5292 | { |
| 5293 | Nucleus::createBr(endBlock); |
| 5294 | Nucleus::setInsertBlock(falseBlock); |
| 5295 | } |
| 5296 | |
| 5297 | ifFalseBlock[ifDepth] = endBlock; |
| 5298 | |
| 5299 | ifDepth++; |
| 5300 | } |
| 5301 | |
| 5302 | void PixelRoutine::ENDIF(Registers &r) |
| 5303 | { |
| 5304 | ifDepth--; |
| 5305 | |
| 5306 | llvm::BasicBlock *endBlock = ifFalseBlock[ifDepth]; |
| 5307 | |
| 5308 | Nucleus::createBr(endBlock); |
| 5309 | Nucleus::setInsertBlock(endBlock); |
| 5310 | |
| 5311 | if(isConditionalIf[ifDepth]) |
| 5312 | { |
| 5313 | breakDepth--; |
| 5314 | r.enableIndex--; |
| 5315 | } |
| 5316 | } |
| 5317 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5318 | void PixelRoutine::ENDLOOP(Registers &r) |
| 5319 | { |
| 5320 | loopRepDepth--; |
| 5321 | |
| 5322 | r.aL[r.loopDepth] = r.aL[r.loopDepth] + r.increment[r.loopDepth]; // FIXME: += |
| 5323 | |
| 5324 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5325 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5326 | |
| 5327 | Nucleus::createBr(testBlock); |
| 5328 | Nucleus::setInsertBlock(endBlock); |
| 5329 | |
| 5330 | r.loopDepth--; |
| 5331 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5332 | } |
| 5333 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5334 | void PixelRoutine::ENDREP(Registers &r) |
| 5335 | { |
| 5336 | loopRepDepth--; |
| 5337 | |
| 5338 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5339 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5340 | |
| 5341 | Nucleus::createBr(testBlock); |
| 5342 | Nucleus::setInsertBlock(endBlock); |
| 5343 | |
| 5344 | r.loopDepth--; |
| 5345 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5346 | } |
| 5347 | |
| 5348 | void PixelRoutine::ENDWHILE(Registers &r) |
| 5349 | { |
| 5350 | loopRepDepth--; |
| 5351 | |
| 5352 | llvm::BasicBlock *testBlock = loopRepTestBlock[loopRepDepth]; |
| 5353 | llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth]; |
| 5354 | |
| 5355 | Nucleus::createBr(testBlock); |
| 5356 | Nucleus::setInsertBlock(endBlock); |
| 5357 | |
| 5358 | r.enableIndex--; |
| 5359 | r.enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 5360 | whileTest = false; |
| 5361 | } |
| 5362 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5363 | void PixelRoutine::IF(Registers &r, const Src &src) |
| 5364 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5365 | if(src.type == Shader::PARAMETER_CONSTBOOL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5366 | { |
| 5367 | IFb(r, src); |
| 5368 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5369 | else if(src.type == Shader::PARAMETER_PREDICATE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5370 | { |
| 5371 | IFp(r, src); |
| 5372 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5373 | else |
| 5374 | { |
| 5375 | Int4 condition = As<Int4>(reg(r, src).x); |
| 5376 | IF(r, condition); |
| 5377 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | void PixelRoutine::IFb(Registers &r, const Src &boolRegister) |
| 5381 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5382 | ASSERT(ifDepth < 24 + 4); |
| 5383 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5384 | Bool condition = (*Pointer<Byte>(r.data + OFFSET(DrawData,ps.b[boolRegister.index])) != Byte(0)); // FIXME |
| 5385 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5386 | if(boolRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5387 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5388 | condition = !condition; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 5392 | llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
| 5393 | |
| 5394 | branch(condition, trueBlock, falseBlock); |
| 5395 | |
| 5396 | isConditionalIf[ifDepth] = false; |
| 5397 | ifFalseBlock[ifDepth] = falseBlock; |
| 5398 | |
| 5399 | ifDepth++; |
| 5400 | } |
| 5401 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5402 | void PixelRoutine::IFp(Registers &r, const Src &predicateRegister) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5403 | { |
| 5404 | Int4 condition = As<Int4>(r.p0[predicateRegister.swizzle & 0x3]); |
| 5405 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5406 | if(predicateRegister.modifier == Shader::MODIFIER_NOT) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5407 | { |
| 5408 | condition = ~condition; |
| 5409 | } |
| 5410 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5411 | IF(r, condition); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5412 | } |
| 5413 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5414 | void PixelRoutine::IFC(Registers &r, Vector4f &src0, Vector4f &src1, Control control) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5415 | { |
| 5416 | Int4 condition; |
| 5417 | |
| 5418 | switch(control) |
| 5419 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5420 | case Shader::CONTROL_GT: condition = CmpNLE(src0.x, src1.x); break; |
| 5421 | case Shader::CONTROL_EQ: condition = CmpEQ(src0.x, src1.x); break; |
| 5422 | case Shader::CONTROL_GE: condition = CmpNLT(src0.x, src1.x); break; |
| 5423 | case Shader::CONTROL_LT: condition = CmpLT(src0.x, src1.x); break; |
| 5424 | case Shader::CONTROL_NE: condition = CmpNEQ(src0.x, src1.x); break; |
| 5425 | case Shader::CONTROL_LE: condition = CmpLE(src0.x, src1.x); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5426 | default: |
| 5427 | ASSERT(false); |
| 5428 | } |
| 5429 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5430 | IF(r, condition); |
| 5431 | } |
| 5432 | |
| 5433 | void PixelRoutine::IF(Registers &r, Int4 &condition) |
| 5434 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5435 | condition &= r.enableStack[r.enableIndex]; |
| 5436 | |
| 5437 | r.enableIndex++; |
| 5438 | r.enableStack[r.enableIndex] = condition; |
| 5439 | |
| 5440 | llvm::BasicBlock *trueBlock = Nucleus::createBasicBlock(); |
| 5441 | llvm::BasicBlock *falseBlock = Nucleus::createBasicBlock(); |
| 5442 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5443 | Bool notAllFalse = SignMask(condition) != 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5444 | |
| 5445 | branch(notAllFalse, trueBlock, falseBlock); |
| 5446 | |
| 5447 | isConditionalIf[ifDepth] = true; |
| 5448 | ifFalseBlock[ifDepth] = falseBlock; |
| 5449 | |
| 5450 | ifDepth++; |
| 5451 | breakDepth++; |
| 5452 | } |
| 5453 | |
| 5454 | void PixelRoutine::LABEL(int labelIndex) |
| 5455 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5456 | if(!labelBlock[labelIndex]) |
| 5457 | { |
| 5458 | labelBlock[labelIndex] = Nucleus::createBasicBlock(); |
| 5459 | } |
| 5460 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5461 | Nucleus::setInsertBlock(labelBlock[labelIndex]); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5462 | currentLabel = labelIndex; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | void PixelRoutine::LOOP(Registers &r, const Src &integerRegister) |
| 5466 | { |
| 5467 | r.loopDepth++; |
| 5468 | |
| 5469 | r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][0])); |
| 5470 | r.aL[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][1])); |
| 5471 | r.increment[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][2])); |
| 5472 | |
| 5473 | // If(r.increment[r.loopDepth] == 0) |
| 5474 | // { |
| 5475 | // r.increment[r.loopDepth] = 1; |
| 5476 | // } |
| 5477 | |
| 5478 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5479 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5480 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5481 | |
| 5482 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5483 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5484 | |
| 5485 | // FIXME: jump(testBlock) |
| 5486 | Nucleus::createBr(testBlock); |
| 5487 | Nucleus::setInsertBlock(testBlock); |
| 5488 | |
| 5489 | branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock); |
| 5490 | Nucleus::setInsertBlock(loopBlock); |
| 5491 | |
| 5492 | r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1; // FIXME: -- |
| 5493 | |
| 5494 | loopRepDepth++; |
| 5495 | breakDepth = 0; |
| 5496 | } |
| 5497 | |
| 5498 | void PixelRoutine::REP(Registers &r, const Src &integerRegister) |
| 5499 | { |
| 5500 | r.loopDepth++; |
| 5501 | |
| 5502 | r.iteration[r.loopDepth] = *Pointer<Int>(r.data + OFFSET(DrawData,ps.i[integerRegister.index][0])); |
| 5503 | r.aL[r.loopDepth] = r.aL[r.loopDepth - 1]; |
| 5504 | |
| 5505 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5506 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5507 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5508 | |
| 5509 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5510 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5511 | |
| 5512 | // FIXME: jump(testBlock) |
| 5513 | Nucleus::createBr(testBlock); |
| 5514 | Nucleus::setInsertBlock(testBlock); |
| 5515 | |
| 5516 | branch(r.iteration[r.loopDepth] > 0, loopBlock, endBlock); |
| 5517 | Nucleus::setInsertBlock(loopBlock); |
| 5518 | |
| 5519 | r.iteration[r.loopDepth] = r.iteration[r.loopDepth] - 1; // FIXME: -- |
| 5520 | |
| 5521 | loopRepDepth++; |
| 5522 | breakDepth = 0; |
| 5523 | } |
| 5524 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5525 | void PixelRoutine::WHILE(Registers &r, const Src &temporaryRegister) |
| 5526 | { |
| 5527 | r.enableIndex++; |
| 5528 | |
| 5529 | llvm::BasicBlock *loopBlock = Nucleus::createBasicBlock(); |
| 5530 | llvm::BasicBlock *testBlock = Nucleus::createBasicBlock(); |
| 5531 | llvm::BasicBlock *endBlock = Nucleus::createBasicBlock(); |
| 5532 | |
| 5533 | loopRepTestBlock[loopRepDepth] = testBlock; |
| 5534 | loopRepEndBlock[loopRepDepth] = endBlock; |
| 5535 | |
| 5536 | Int4 restoreBreak = r.enableBreak; |
| 5537 | Int4 restoreContinue = r.enableContinue; |
| 5538 | |
| 5539 | // FIXME: jump(testBlock) |
| 5540 | Nucleus::createBr(testBlock); |
| 5541 | Nucleus::setInsertBlock(testBlock); |
| 5542 | r.enableContinue = restoreContinue; |
| 5543 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5544 | const Vector4f &src = reg(r, temporaryRegister); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5545 | Int4 condition = As<Int4>(src.x); |
| 5546 | condition &= r.enableStack[r.enableIndex - 1]; |
| 5547 | r.enableStack[r.enableIndex] = condition; |
| 5548 | |
| 5549 | Bool notAllFalse = SignMask(condition) != 0; |
| 5550 | branch(notAllFalse, loopBlock, endBlock); |
| 5551 | |
| 5552 | Nucleus::setInsertBlock(endBlock); |
| 5553 | r.enableBreak = restoreBreak; |
| 5554 | |
| 5555 | Nucleus::setInsertBlock(loopBlock); |
| 5556 | |
| 5557 | loopRepDepth++; |
| 5558 | breakDepth = 0; |
| 5559 | } |
| 5560 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5561 | void PixelRoutine::RET(Registers &r) |
| 5562 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5563 | if(currentLabel == -1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5564 | { |
| 5565 | returnBlock = Nucleus::createBasicBlock(); |
| 5566 | Nucleus::createBr(returnBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5567 | } |
| 5568 | else |
| 5569 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5570 | llvm::BasicBlock *unreachableBlock = Nucleus::createBasicBlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5571 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5572 | 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] | 5573 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5574 | // FIXME: Encapsulate |
| 5575 | UInt index = r.callStack[--r.stackIndex]; |
| 5576 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5577 | llvm::Value *value = index.loadValue(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5578 | llvm::Value *switchInst = Nucleus::createSwitch(value, unreachableBlock, (int)callRetBlock[currentLabel].size()); |
| 5579 | |
| 5580 | for(unsigned int i = 0; i < callRetBlock[currentLabel].size(); i++) |
| 5581 | { |
| 5582 | Nucleus::addSwitchCase(switchInst, i, callRetBlock[currentLabel][i]); |
| 5583 | } |
| 5584 | } |
| 5585 | else if(callRetBlock[currentLabel].size() == 1) // Jump directly to the unique return destination |
| 5586 | { |
| 5587 | Nucleus::createBr(callRetBlock[currentLabel][0]); |
| 5588 | } |
| 5589 | else // Function isn't called |
| 5590 | { |
| 5591 | Nucleus::createBr(unreachableBlock); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | Nucleus::setInsertBlock(unreachableBlock); |
| 5595 | Nucleus::createUnreachable(); |
| 5596 | } |
| 5597 | } |
| 5598 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5599 | void PixelRoutine::LEAVE(Registers &r) |
| 5600 | { |
| 5601 | r.enableLeave = r.enableLeave & ~r.enableStack[r.enableIndex]; |
| 5602 | |
| 5603 | // FIXME: Return from function if all instances left |
| 5604 | // FIXME: Use enableLeave in other control-flow constructs |
| 5605 | } |
| 5606 | |
| 5607 | void PixelRoutine::writeDestination(Registers &r, Vector4i &d, const Dst &dst) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5608 | { |
| 5609 | switch(dst.type) |
| 5610 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5611 | case Shader::PARAMETER_TEMP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5612 | if(dst.mask & 0x1) r.ri[dst.index].x = d.x; |
| 5613 | if(dst.mask & 0x2) r.ri[dst.index].y = d.y; |
| 5614 | if(dst.mask & 0x4) r.ri[dst.index].z = d.z; |
| 5615 | if(dst.mask & 0x8) r.ri[dst.index].w = d.w; |
| 5616 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5617 | case Shader::PARAMETER_INPUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5618 | if(dst.mask & 0x1) r.vi[dst.index].x = d.x; |
| 5619 | if(dst.mask & 0x2) r.vi[dst.index].y = d.y; |
| 5620 | if(dst.mask & 0x4) r.vi[dst.index].z = d.z; |
| 5621 | if(dst.mask & 0x8) r.vi[dst.index].w = d.w; |
| 5622 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5623 | case Shader::PARAMETER_CONST: ASSERT(false); break; |
| 5624 | case Shader::PARAMETER_TEXTURE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5625 | if(dst.mask & 0x1) r.ti[dst.index].x = d.x; |
| 5626 | if(dst.mask & 0x2) r.ti[dst.index].y = d.y; |
| 5627 | if(dst.mask & 0x4) r.ti[dst.index].z = d.z; |
| 5628 | if(dst.mask & 0x8) r.ti[dst.index].w = d.w; |
| 5629 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5630 | case Shader::PARAMETER_COLOROUT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5631 | if(dst.mask & 0x1) r.vi[dst.index].x = d.x; |
| 5632 | if(dst.mask & 0x2) r.vi[dst.index].y = d.y; |
| 5633 | if(dst.mask & 0x4) r.vi[dst.index].z = d.z; |
| 5634 | if(dst.mask & 0x8) r.vi[dst.index].w = d.w; |
| 5635 | break; |
| 5636 | default: |
| 5637 | ASSERT(false); |
| 5638 | } |
| 5639 | } |
| 5640 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5641 | Vector4i PixelRoutine::regi(Registers &r, const Src &src) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5642 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5643 | Vector4i *reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5644 | int i = src.index; |
| 5645 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5646 | Vector4i c; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5647 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5648 | if(src.type == Shader::PARAMETER_CONST) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5649 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5650 | c.x = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][0])); |
| 5651 | c.y = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][1])); |
| 5652 | c.z = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][2])); |
| 5653 | c.w = *Pointer<Short4>(r.data + OFFSET(DrawData,ps.cW[i][3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | switch(src.type) |
| 5657 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5658 | case Shader::PARAMETER_TEMP: reg = &r.ri[i]; break; |
| 5659 | case Shader::PARAMETER_INPUT: reg = &r.vi[i]; break; |
| 5660 | case Shader::PARAMETER_CONST: reg = &c; break; |
| 5661 | case Shader::PARAMETER_TEXTURE: reg = &r.ti[i]; break; |
| 5662 | case Shader::PARAMETER_VOID: return r.ri[0]; // Dummy |
| 5663 | case Shader::PARAMETER_FLOAT4LITERAL: return r.ri[0]; // Dummy |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5664 | default: |
| 5665 | ASSERT(false); |
| 5666 | } |
| 5667 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5668 | const Short4 &x = (*reg)[(src.swizzle >> 0) & 0x3]; |
| 5669 | const Short4 &y = (*reg)[(src.swizzle >> 2) & 0x3]; |
| 5670 | const Short4 &z = (*reg)[(src.swizzle >> 4) & 0x3]; |
| 5671 | const Short4 &w = (*reg)[(src.swizzle >> 6) & 0x3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5672 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5673 | Vector4i mod; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5674 | |
| 5675 | switch(src.modifier) |
| 5676 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5677 | case Shader::MODIFIER_NONE: |
| 5678 | mod.x = x; |
| 5679 | mod.y = y; |
| 5680 | mod.z = z; |
| 5681 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5682 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5683 | case Shader::MODIFIER_BIAS: |
| 5684 | mod.x = SubSat(x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5685 | mod.y = SubSat(y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5686 | mod.z = SubSat(z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5687 | mod.w = SubSat(w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5688 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5689 | case Shader::MODIFIER_BIAS_NEGATE: |
| 5690 | mod.x = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), x); |
| 5691 | mod.y = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), y); |
| 5692 | mod.z = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), z); |
| 5693 | mod.w = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5694 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5695 | case Shader::MODIFIER_COMPLEMENT: |
| 5696 | mod.x = SubSat(Short4(0x1000), x); |
| 5697 | mod.y = SubSat(Short4(0x1000), y); |
| 5698 | mod.z = SubSat(Short4(0x1000), z); |
| 5699 | mod.w = SubSat(Short4(0x1000), w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5700 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5701 | case Shader::MODIFIER_NEGATE: |
| 5702 | mod.x = -x; |
| 5703 | mod.y = -y; |
| 5704 | mod.z = -z; |
| 5705 | mod.w = -w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5706 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5707 | case Shader::MODIFIER_X2: |
| 5708 | mod.x = AddSat(x, x); |
| 5709 | mod.y = AddSat(y, y); |
| 5710 | mod.z = AddSat(z, z); |
| 5711 | mod.w = AddSat(w, w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5712 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5713 | case Shader::MODIFIER_X2_NEGATE: |
| 5714 | mod.x = -AddSat(x, x); |
| 5715 | mod.y = -AddSat(y, y); |
| 5716 | mod.z = -AddSat(z, z); |
| 5717 | mod.w = -AddSat(w, w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5718 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5719 | case Shader::MODIFIER_SIGN: |
| 5720 | mod.x = SubSat(x, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5721 | mod.y = SubSat(y, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5722 | mod.z = SubSat(z, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5723 | mod.w = SubSat(w, Short4(0x0800, 0x0800, 0x0800, 0x0800)); |
| 5724 | mod.x = AddSat(mod.x, mod.x); |
| 5725 | mod.y = AddSat(mod.y, mod.y); |
| 5726 | mod.z = AddSat(mod.z, mod.z); |
| 5727 | mod.w = AddSat(mod.w, mod.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5728 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5729 | case Shader::MODIFIER_SIGN_NEGATE: |
| 5730 | mod.x = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), x); |
| 5731 | mod.y = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), y); |
| 5732 | mod.z = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), z); |
| 5733 | mod.w = SubSat(Short4(0x0800, 0x0800, 0x0800, 0x0800), w); |
| 5734 | mod.x = AddSat(mod.x, mod.x); |
| 5735 | mod.y = AddSat(mod.y, mod.y); |
| 5736 | mod.z = AddSat(mod.z, mod.z); |
| 5737 | mod.w = AddSat(mod.w, mod.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5738 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5739 | case Shader::MODIFIER_DZ: |
| 5740 | mod.x = x; |
| 5741 | mod.y = y; |
| 5742 | mod.z = z; |
| 5743 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5744 | // Projection performed by texture sampler |
| 5745 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5746 | case Shader::MODIFIER_DW: |
| 5747 | mod.x = x; |
| 5748 | mod.y = y; |
| 5749 | mod.z = z; |
| 5750 | mod.w = w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5751 | // Projection performed by texture sampler |
| 5752 | break; |
| 5753 | default: |
| 5754 | ASSERT(false); |
| 5755 | } |
| 5756 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5757 | 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] | 5758 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5759 | mod.x = Min(mod.x, Short4(0x1000)); mod.x = Max(mod.x, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5760 | mod.y = Min(mod.y, Short4(0x1000)); mod.y = Max(mod.y, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5761 | mod.z = Min(mod.z, Short4(0x1000)); mod.z = Max(mod.z, Short4(-0x1000, -0x1000, -0x1000, -0x1000)); |
| 5762 | 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] | 5763 | } |
| 5764 | |
| 5765 | return mod; |
| 5766 | } |
| 5767 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5768 | Vector4f PixelRoutine::reg(Registers &r, const Src &src, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5769 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5770 | Vector4f reg; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5771 | int i = src.index + offset; |
| 5772 | |
| 5773 | switch(src.type) |
| 5774 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5775 | case Shader::PARAMETER_TEMP: |
| 5776 | if(src.rel.type == Shader::PARAMETER_VOID) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5777 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5778 | reg = r.rf[i]; |
| 5779 | } |
| 5780 | else |
| 5781 | { |
| 5782 | Int a = relativeAddress(r, src); |
| 5783 | |
| 5784 | reg = r.rf[i + a]; |
| 5785 | } |
| 5786 | break; |
| 5787 | case Shader::PARAMETER_INPUT: |
| 5788 | { |
| 5789 | if(src.rel.type == Shader::PARAMETER_VOID) // Not relative |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5790 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5791 | reg = r.vf[i]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5792 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5793 | else if(src.rel.type == Shader::PARAMETER_LOOP) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5794 | { |
| 5795 | Int aL = r.aL[r.loopDepth]; |
| 5796 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5797 | reg = r.vf[i + aL]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5798 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5799 | else |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5800 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5801 | Int a = relativeAddress(r, src); |
| 5802 | |
| 5803 | reg = r.vf[i + a]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5804 | } |
| 5805 | } |
| 5806 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5807 | case Shader::PARAMETER_CONST: |
| 5808 | reg = readConstant(r, src, offset); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5809 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5810 | case Shader::PARAMETER_TEXTURE: |
| 5811 | reg = r.vf[2 + i]; |
| 5812 | break; |
| 5813 | case Shader::PARAMETER_MISCTYPE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5814 | if(src.index == 0) reg = r.vPos; |
| 5815 | if(src.index == 1) reg = r.vFace; |
| 5816 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5817 | case Shader::PARAMETER_SAMPLER: |
| 5818 | if(src.rel.type == Shader::PARAMETER_VOID) |
| 5819 | { |
| 5820 | reg.x = As<Float4>(Int4(i)); |
| 5821 | } |
| 5822 | else if(src.rel.type == Shader::PARAMETER_TEMP) |
| 5823 | { |
| 5824 | reg.x = As<Float4>(Int4(i) + RoundInt(r.rf[src.rel.index].x)); |
| 5825 | } |
| 5826 | return reg; |
| 5827 | case Shader::PARAMETER_PREDICATE: return reg; // Dummy |
| 5828 | case Shader::PARAMETER_VOID: return reg; // Dummy |
| 5829 | case Shader::PARAMETER_FLOAT4LITERAL: |
| 5830 | reg.x = Float4(src.value[0]); |
| 5831 | reg.y = Float4(src.value[1]); |
| 5832 | reg.z = Float4(src.value[2]); |
| 5833 | reg.w = Float4(src.value[3]); |
| 5834 | break; |
| 5835 | case Shader::PARAMETER_CONSTINT: return reg; // Dummy |
| 5836 | case Shader::PARAMETER_CONSTBOOL: return reg; // Dummy |
| 5837 | case Shader::PARAMETER_LOOP: return reg; // Dummy |
| 5838 | case Shader::PARAMETER_COLOROUT: |
| 5839 | reg = r.oC[i]; |
| 5840 | break; |
| 5841 | case Shader::PARAMETER_DEPTHOUT: |
| 5842 | reg.x = r.oDepth; |
| 5843 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5844 | default: |
| 5845 | ASSERT(false); |
| 5846 | } |
| 5847 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5848 | const Float4 &x = reg[(src.swizzle >> 0) & 0x3]; |
| 5849 | const Float4 &y = reg[(src.swizzle >> 2) & 0x3]; |
| 5850 | const Float4 &z = reg[(src.swizzle >> 4) & 0x3]; |
| 5851 | const Float4 &w = reg[(src.swizzle >> 6) & 0x3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5852 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5853 | Vector4f mod; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5854 | |
| 5855 | switch(src.modifier) |
| 5856 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5857 | case Shader::MODIFIER_NONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5858 | mod.x = x; |
| 5859 | mod.y = y; |
| 5860 | mod.z = z; |
| 5861 | mod.w = w; |
| 5862 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5863 | case Shader::MODIFIER_NEGATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5864 | mod.x = -x; |
| 5865 | mod.y = -y; |
| 5866 | mod.z = -z; |
| 5867 | mod.w = -w; |
| 5868 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5869 | case Shader::MODIFIER_ABS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5870 | mod.x = Abs(x); |
| 5871 | mod.y = Abs(y); |
| 5872 | mod.z = Abs(z); |
| 5873 | mod.w = Abs(w); |
| 5874 | break; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5875 | case Shader::MODIFIER_ABS_NEGATE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5876 | mod.x = -Abs(x); |
| 5877 | mod.y = -Abs(y); |
| 5878 | mod.z = -Abs(z); |
| 5879 | mod.w = -Abs(w); |
| 5880 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 5881 | case Shader::MODIFIER_NOT: |
| 5882 | mod.x = As<Float4>(As<Int4>(x) ^ Int4(0xFFFFFFFF)); |
| 5883 | mod.y = As<Float4>(As<Int4>(y) ^ Int4(0xFFFFFFFF)); |
| 5884 | mod.z = As<Float4>(As<Int4>(z) ^ Int4(0xFFFFFFFF)); |
| 5885 | mod.w = As<Float4>(As<Int4>(w) ^ Int4(0xFFFFFFFF)); |
| 5886 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5887 | default: |
| 5888 | ASSERT(false); |
| 5889 | } |
| 5890 | |
| 5891 | return mod; |
| 5892 | } |
| 5893 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5894 | Vector4f PixelRoutine::readConstant(Registers &r, const Src &src, int offset) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5895 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5896 | Vector4f c; |
| 5897 | |
| 5898 | int i = src.index + offset; |
| 5899 | |
| 5900 | if(src.rel.type == Shader::PARAMETER_VOID) // Not relative |
| 5901 | { |
| 5902 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i])); |
| 5903 | |
| 5904 | c.x = c.x.xxxx; |
| 5905 | c.y = c.y.yyyy; |
| 5906 | c.z = c.z.zzzz; |
| 5907 | c.w = c.w.wwww; |
| 5908 | |
| 5909 | if(localShaderConstants) // Constant may be known at compile time |
| 5910 | { |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 5911 | for(size_t j = 0; j < shader->getLength(); j++) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5912 | { |
| 5913 | const Shader::Instruction &instruction = *shader->getInstruction(j); |
| 5914 | |
| 5915 | if(instruction.opcode == Shader::OPCODE_DEF) |
| 5916 | { |
| 5917 | if(instruction.dst.index == i) |
| 5918 | { |
| 5919 | c.x = Float4(instruction.src[0].value[0]); |
| 5920 | c.y = Float4(instruction.src[0].value[1]); |
| 5921 | c.z = Float4(instruction.src[0].value[2]); |
| 5922 | c.w = Float4(instruction.src[0].value[3]); |
| 5923 | |
| 5924 | break; |
| 5925 | } |
| 5926 | } |
| 5927 | } |
| 5928 | } |
| 5929 | } |
| 5930 | else if(src.rel.type == Shader::PARAMETER_LOOP) |
| 5931 | { |
| 5932 | Int loopCounter = r.aL[r.loopDepth]; |
| 5933 | |
| 5934 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i]) + loopCounter * 16); |
| 5935 | |
| 5936 | c.x = c.x.xxxx; |
| 5937 | c.y = c.y.yyyy; |
| 5938 | c.z = c.z.zzzz; |
| 5939 | c.w = c.w.wwww; |
| 5940 | } |
| 5941 | else |
| 5942 | { |
| 5943 | Int a = relativeAddress(r, src); |
| 5944 | |
| 5945 | c.x = c.y = c.z = c.w = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[i]) + a * 16); |
| 5946 | |
| 5947 | c.x = c.x.xxxx; |
| 5948 | c.y = c.y.yyyy; |
| 5949 | c.z = c.z.zzzz; |
| 5950 | c.w = c.w.wwww; |
| 5951 | } |
| 5952 | |
| 5953 | return c; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5954 | } |
| 5955 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5956 | Int PixelRoutine::relativeAddress(Registers &r, const Shader::Parameter &var) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 5957 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5958 | ASSERT(var.rel.deterministic); |
| 5959 | |
| 5960 | if(var.rel.type == Shader::PARAMETER_TEMP) |
| 5961 | { |
| 5962 | return RoundInt(Extract(r.rf[var.rel.index].x, 0)) * var.rel.scale; |
| 5963 | } |
| 5964 | else if(var.rel.type == Shader::PARAMETER_INPUT) |
| 5965 | { |
| 5966 | return RoundInt(Extract(r.vf[var.rel.index].x, 0)) * var.rel.scale; |
| 5967 | } |
| 5968 | else if(var.rel.type == Shader::PARAMETER_OUTPUT) |
| 5969 | { |
| 5970 | return RoundInt(Extract(r.oC[var.rel.index].x, 0)) * var.rel.scale; |
| 5971 | } |
| 5972 | else if(var.rel.type == Shader::PARAMETER_CONST) |
| 5973 | { |
Nicolas Capens | b5e7a2a | 2014-05-06 16:38:19 -0400 | [diff] [blame] | 5974 | RValue<Float4> c = *Pointer<Float4>(r.data + OFFSET(DrawData,ps.c[var.rel.index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5975 | |
| 5976 | return RoundInt(Extract(c, 0)) * var.rel.scale; |
| 5977 | } |
| 5978 | else ASSERT(false); |
| 5979 | |
| 5980 | return 0; |
| 5981 | } |
| 5982 | |
| 5983 | Int4 PixelRoutine::enableMask(Registers &r, const Shader::Instruction *instruction) |
| 5984 | { |
| 5985 | Int4 enable = instruction->analysisBranch ? Int4(r.enableStack[r.enableIndex]) : Int4(0xFFFFFFFF); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 5986 | |
| 5987 | if(!whileTest) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5988 | { |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 5989 | if(shader->containsBreakInstruction() && instruction->analysisBreak) |
| 5990 | { |
| 5991 | enable &= r.enableBreak; |
| 5992 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5993 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 5994 | if(shader->containsContinueInstruction() && instruction->analysisContinue) |
| 5995 | { |
| 5996 | enable &= r.enableContinue; |
| 5997 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 5998 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 5999 | if(shader->containsLeaveInstruction() && instruction->analysisLeave) |
| 6000 | { |
| 6001 | enable &= r.enableLeave; |
| 6002 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | return enable; |
| 6006 | } |
| 6007 | |
| 6008 | bool PixelRoutine::colorUsed() |
| 6009 | { |
| 6010 | return state.colorWriteMask || state.alphaTestActive() || state.shaderContainsKill; |
| 6011 | } |
| 6012 | |
| 6013 | unsigned short PixelRoutine::shaderVersion() const |
| 6014 | { |
| 6015 | return shader ? shader->getVersion() : 0x0000; |
| 6016 | } |
| 6017 | |
| 6018 | bool PixelRoutine::interpolateZ() const |
| 6019 | { |
| 6020 | return state.depthTestActive || state.pixelFogActive() || (shader && shader->vPosDeclared && fullPixelPositionRegister); |
| 6021 | } |
| 6022 | |
| 6023 | bool PixelRoutine::interpolateW() const |
| 6024 | { |
| 6025 | return state.perspective || (shader && shader->vPosDeclared && fullPixelPositionRegister); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6026 | } |
| 6027 | } |