John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1 | // SwiftShader Software Renderer |
| 2 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3 | // Copyright(c) 2005-2013 TransGaming Inc. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 4 | // |
| 5 | // All rights reserved. No part of this software may be copied, distributed, transmitted, |
| 6 | // transcribed, stored in a retrieval system, translated into any human or computer |
| 7 | // language by any means, or disclosed to third parties without the explicit written |
| 8 | // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express |
| 9 | // or implied, including but not limited to any patent rights, are granted to you. |
| 10 | // |
| 11 | |
| 12 | #include "PixelRoutine.hpp" |
| 13 | |
| 14 | #include "Renderer.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 15 | #include "QuadRasterizer.hpp" |
| 16 | #include "Surface.hpp" |
| 17 | #include "Primitive.hpp" |
| 18 | #include "CPUID.hpp" |
| 19 | #include "SamplerCore.hpp" |
| 20 | #include "Constants.hpp" |
| 21 | #include "Debug.hpp" |
| 22 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 23 | namespace sw |
| 24 | { |
| 25 | extern bool complementaryDepthBuffer; |
| 26 | extern bool postBlendSRGB; |
| 27 | extern bool exactColorRounding; |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 28 | extern bool forceClearRegisters; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 29 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 30 | PixelRoutine::Registers::Registers(const PixelShader *shader) : |
| 31 | QuadRasterizer::Registers(), |
| 32 | rf(shader && shader->dynamicallyIndexedTemporaries), |
| 33 | vf(shader && shader->dynamicallyIndexedInput) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 34 | { |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 35 | if(!shader || shader->getVersion() < 0x0200 || forceClearRegisters) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 36 | { |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 37 | for(int i = 0; i < 10; i++) |
| 38 | { |
| 39 | vf[i].x = Float4(0.0f); |
| 40 | vf[i].y = Float4(0.0f); |
| 41 | vf[i].z = Float4(0.0f); |
| 42 | vf[i].w = Float4(0.0f); |
| 43 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 47 | PixelRoutine::PixelRoutine(const PixelProcessor::State &state, const PixelShader *shader) : QuadRasterizer(state, shader) |
| 48 | { |
| 49 | } |
| 50 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 51 | PixelRoutine::~PixelRoutine() |
| 52 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 53 | for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 54 | { |
| 55 | delete sampler[i]; |
| 56 | } |
| 57 | } |
| 58 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 59 | void PixelRoutine::quad(QuadRasterizer::Registers &rBase, Pointer<Byte> cBuffer[4], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 60 | { |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 61 | Registers& r = *static_cast<Registers*>(&rBase); |
| 62 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 63 | #if PERF_PROFILE |
| 64 | Long pipeTime = Ticks(); |
| 65 | #endif |
| 66 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 67 | for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 68 | { |
| 69 | sampler[i] = new SamplerCore(r.constants, state.sampler[i]); |
| 70 | } |
| 71 | |
| 72 | const bool earlyDepthTest = !state.depthOverride && !state.alphaTestActive(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 73 | |
| 74 | Int zMask[4]; // Depth mask |
| 75 | Int sMask[4]; // Stencil mask |
| 76 | |
| 77 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 78 | { |
| 79 | zMask[q] = cMask[q]; |
| 80 | sMask[q] = cMask[q]; |
| 81 | } |
| 82 | |
| 83 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 84 | { |
| 85 | stencilTest(r, sBuffer, q, x, sMask[q], cMask[q]); |
| 86 | } |
| 87 | |
| 88 | Float4 f; |
| 89 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 90 | Float4 (&z)[4] = r.z; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 91 | Float4 &w = r.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 92 | Float4 &rhw = r.rhw; |
| 93 | Float4 rhwCentroid; |
| 94 | |
| 95 | 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] | 96 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 97 | if(interpolateZ()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 98 | { |
| 99 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 100 | { |
| 101 | Float4 x = xxxx; |
| 102 | |
| 103 | if(state.multiSample > 1) |
| 104 | { |
| 105 | x -= *Pointer<Float4>(r.constants + OFFSET(Constants,X) + q * sizeof(float4)); |
| 106 | } |
| 107 | |
| 108 | z[q] = interpolate(x, r.Dz[q], z[q], r.primitive + OFFSET(Primitive,z), false, false); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | Bool depthPass = false; |
| 113 | |
| 114 | if(earlyDepthTest) |
| 115 | { |
| 116 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 117 | { |
| 118 | depthPass = depthPass || depthTest(r, zBuffer, q, x, z[q], sMask[q], zMask[q], cMask[q]); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | If(depthPass || Bool(!earlyDepthTest)) |
| 123 | { |
| 124 | #if PERF_PROFILE |
| 125 | Long interpTime = Ticks(); |
| 126 | #endif |
| 127 | |
Nicolas Capens | 66be245 | 2015-01-27 14:58:57 -0500 | [diff] [blame] | 128 | 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] | 129 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 130 | // Centroid locations |
| 131 | Float4 XXXX = Float4(0.0f); |
| 132 | Float4 YYYY = Float4(0.0f); |
| 133 | |
| 134 | if(state.centroid) |
| 135 | { |
| 136 | Float4 WWWW(1.0e-9f); |
| 137 | |
| 138 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 139 | { |
| 140 | XXXX += *Pointer<Float4>(r.constants + OFFSET(Constants,sampleX[q]) + 16 * cMask[q]); |
| 141 | YYYY += *Pointer<Float4>(r.constants + OFFSET(Constants,sampleY[q]) + 16 * cMask[q]); |
| 142 | WWWW += *Pointer<Float4>(r.constants + OFFSET(Constants,weight) + 16 * cMask[q]); |
| 143 | } |
| 144 | |
| 145 | WWWW = Rcp_pp(WWWW); |
| 146 | XXXX *= WWWW; |
| 147 | YYYY *= WWWW; |
| 148 | |
| 149 | XXXX += xxxx; |
| 150 | YYYY += yyyy; |
| 151 | } |
| 152 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 153 | if(interpolateW()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 154 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 155 | w = interpolate(xxxx, r.Dw, rhw, r.primitive + OFFSET(Primitive,w), false, false); |
| 156 | rhw = reciprocal(w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 157 | |
| 158 | if(state.centroid) |
| 159 | { |
| 160 | rhwCentroid = reciprocal(interpolateCentroid(XXXX, YYYY, rhwCentroid, r.primitive + OFFSET(Primitive,w), false, false)); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | for(int interpolant = 0; interpolant < 10; interpolant++) |
| 165 | { |
| 166 | for(int component = 0; component < 4; component++) |
| 167 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 168 | if(state.interpolant[interpolant].component & (1 << component)) |
| 169 | { |
| 170 | if(!state.interpolant[interpolant].centroid) |
| 171 | { |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 172 | 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] | 173 | } |
| 174 | else |
| 175 | { |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 176 | 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] | 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | Float4 rcp; |
| 182 | |
| 183 | switch(state.interpolant[interpolant].project) |
| 184 | { |
| 185 | case 0: |
| 186 | break; |
| 187 | case 1: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 188 | rcp = reciprocal(r.vf[interpolant].y); |
| 189 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 190 | break; |
| 191 | case 2: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 192 | rcp = reciprocal(r.vf[interpolant].z); |
| 193 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
| 194 | r.vf[interpolant].y = r.vf[interpolant].y * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 195 | break; |
| 196 | case 3: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 197 | rcp = reciprocal(r.vf[interpolant].w); |
| 198 | r.vf[interpolant].x = r.vf[interpolant].x * rcp; |
| 199 | r.vf[interpolant].y = r.vf[interpolant].y * rcp; |
| 200 | r.vf[interpolant].z = r.vf[interpolant].z * rcp; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 201 | break; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | if(state.fog.component) |
| 206 | { |
| 207 | f = interpolate(xxxx, r.Df, rhw, r.primitive + OFFSET(Primitive,f), state.fog.flat & 0x01, state.perspective); |
| 208 | } |
| 209 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 210 | setBuiltins(r, x, y, z, w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 211 | |
| 212 | #if PERF_PROFILE |
| 213 | r.cycles[PERF_INTERP] += Ticks() - interpTime; |
| 214 | #endif |
| 215 | |
| 216 | Bool alphaPass = true; |
| 217 | |
| 218 | if(colorUsed()) |
| 219 | { |
| 220 | #if PERF_PROFILE |
| 221 | Long shaderTime = Ticks(); |
| 222 | #endif |
| 223 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 224 | applyShader(r, cMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 225 | |
| 226 | #if PERF_PROFILE |
| 227 | r.cycles[PERF_SHADER] += Ticks() - shaderTime; |
| 228 | #endif |
| 229 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 230 | alphaPass = alphaTest(r, cMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 231 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 232 | if((shader && shader->containsKill()) || state.alphaTestActive()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 233 | { |
| 234 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 235 | { |
| 236 | zMask[q] &= cMask[q]; |
| 237 | sMask[q] &= cMask[q]; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | If(alphaPass) |
| 243 | { |
| 244 | if(!earlyDepthTest) |
| 245 | { |
| 246 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 247 | { |
| 248 | depthPass = depthPass || depthTest(r, zBuffer, q, x, z[q], sMask[q], zMask[q], cMask[q]); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | #if PERF_PROFILE |
| 253 | Long ropTime = Ticks(); |
| 254 | #endif |
| 255 | |
| 256 | If(depthPass || Bool(earlyDepthTest)) |
| 257 | { |
| 258 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 259 | { |
| 260 | if(state.multiSampleMask & (1 << q)) |
| 261 | { |
| 262 | writeDepth(r, zBuffer, q, x, z[q], zMask[q]); |
| 263 | |
| 264 | if(state.occlusionEnabled) |
| 265 | { |
| 266 | r.occlusion += *Pointer<UInt>(r.constants + OFFSET(Constants,occlusionCount) + 4 * (zMask[q] & sMask[q])); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if(colorUsed()) |
| 272 | { |
| 273 | #if PERF_PROFILE |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 274 | AddAtomic(Pointer<Long>(&profiler.ropOperations), 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 275 | #endif |
| 276 | |
Alexis Hetu | f2a8c37 | 2015-07-13 11:08:41 -0400 | [diff] [blame^] | 277 | rasterOperation(r, f, cBuffer, x, sMask, zMask, cMask); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | #if PERF_PROFILE |
| 282 | r.cycles[PERF_ROP] += Ticks() - ropTime; |
| 283 | #endif |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | for(unsigned int q = 0; q < state.multiSample; q++) |
| 288 | { |
| 289 | if(state.multiSampleMask & (1 << q)) |
| 290 | { |
| 291 | writeStencil(r, sBuffer, q, x, sMask[q], zMask[q], cMask[q]); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | #if PERF_PROFILE |
| 296 | r.cycles[PERF_PIPE] += Ticks() - pipeTime; |
| 297 | #endif |
| 298 | } |
| 299 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 300 | Float4 PixelRoutine::interpolateCentroid(Float4 &x, Float4 &y, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective) |
| 301 | { |
| 302 | Float4 interpolant = *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,C), 16); |
| 303 | |
| 304 | if(!flat) |
| 305 | { |
| 306 | interpolant += x * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,A), 16) + |
| 307 | y * *Pointer<Float4>(planeEquation + OFFSET(PlaneEquation,B), 16); |
| 308 | |
| 309 | if(perspective) |
| 310 | { |
| 311 | interpolant *= rhw; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | return interpolant; |
| 316 | } |
| 317 | |
| 318 | void PixelRoutine::stencilTest(Registers &r, Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &cMask) |
| 319 | { |
| 320 | if(!state.stencilActive) |
| 321 | { |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | // (StencilRef & StencilMask) CompFunc (StencilBufferValue & StencilMask) |
| 326 | |
| 327 | Pointer<Byte> buffer = sBuffer + 2 * x; |
| 328 | |
| 329 | if(q > 0) |
| 330 | { |
| 331 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,stencilSliceB)); |
| 332 | } |
| 333 | |
| 334 | Byte8 value = As<Byte8>(Long1(*Pointer<UInt>(buffer))); |
| 335 | Byte8 valueCCW = value; |
| 336 | |
| 337 | if(!state.noStencilMask) |
| 338 | { |
| 339 | value &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].testMaskQ)); |
| 340 | } |
| 341 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 342 | stencilTest(r, value, state.stencilCompareMode, false); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 343 | |
| 344 | if(state.twoSidedStencil) |
| 345 | { |
| 346 | if(!state.noStencilMaskCCW) |
| 347 | { |
| 348 | valueCCW &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].testMaskQ)); |
| 349 | } |
| 350 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 351 | stencilTest(r, valueCCW, state.stencilCompareModeCCW, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 352 | |
| 353 | value &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,clockwiseMask)); |
| 354 | valueCCW &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,invClockwiseMask)); |
| 355 | value |= valueCCW; |
| 356 | } |
| 357 | |
| 358 | sMask = SignMask(value) & cMask; |
| 359 | } |
| 360 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 361 | void PixelRoutine::stencilTest(Registers &r, Byte8 &value, StencilCompareMode stencilCompareMode, bool CCW) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 362 | { |
| 363 | Byte8 equal; |
| 364 | |
| 365 | switch(stencilCompareMode) |
| 366 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 367 | case STENCIL_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 368 | value = Byte8(0xFFFFFFFFFFFFFFFF); |
| 369 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 370 | case STENCIL_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 371 | value = Byte8(0x0000000000000000); |
| 372 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 373 | case STENCIL_LESS: // a < b ~ b > a |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 374 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 375 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 376 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 377 | case STENCIL_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 378 | value = CmpEQ(value, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 379 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 380 | case STENCIL_NOTEQUAL: // a != b ~ !(a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 381 | value = CmpEQ(value, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 382 | value ^= Byte8(0xFFFFFFFFFFFFFFFF); |
| 383 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 384 | case STENCIL_LESSEQUAL: // a <= b ~ (b > a) || (a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 385 | equal = value; |
| 386 | equal = CmpEQ(equal, *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedQ))); |
| 387 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 388 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 389 | value |= equal; |
| 390 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 391 | case STENCIL_GREATER: // a > b |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 392 | equal = *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ)); |
| 393 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 394 | equal = CmpGT(As<SByte8>(equal), As<SByte8>(value)); |
| 395 | value = equal; |
| 396 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 397 | case STENCIL_GREATEREQUAL: // a >= b ~ !(a < b) ~ !(b > a) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 398 | value += Byte8(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); |
| 399 | value = CmpGT(As<SByte8>(value), *Pointer<SByte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceMaskedSignedQ))); |
| 400 | value ^= Byte8(0xFFFFFFFFFFFFFFFF); |
| 401 | break; |
| 402 | default: |
| 403 | ASSERT(false); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | Bool PixelRoutine::depthTest(Registers &r, Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &sMask, Int &zMask, Int &cMask) |
| 408 | { |
| 409 | if(!state.depthTestActive) |
| 410 | { |
| 411 | return true; |
| 412 | } |
| 413 | |
| 414 | Float4 Z = z; |
| 415 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 416 | if(shader && shader->depthOverride()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 417 | { |
| 418 | if(complementaryDepthBuffer) |
| 419 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 420 | Z = Float4(1.0f) - r.oDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 421 | } |
| 422 | else |
| 423 | { |
| 424 | Z = r.oDepth; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | Pointer<Byte> buffer; |
| 429 | Int pitch; |
| 430 | |
| 431 | if(!state.quadLayoutDepthBuffer) |
| 432 | { |
| 433 | buffer = zBuffer + 4 * x; |
| 434 | pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); |
| 435 | } |
| 436 | else |
| 437 | { |
| 438 | buffer = zBuffer + 8 * x; |
| 439 | } |
| 440 | |
| 441 | if(q > 0) |
| 442 | { |
| 443 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,depthSliceB)); |
| 444 | } |
| 445 | |
| 446 | Float4 zValue; |
| 447 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 448 | if(state.depthCompareMode != DEPTH_NEVER || (state.depthCompareMode != DEPTH_ALWAYS && !state.depthWriteEnable)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 449 | { |
| 450 | if(!state.quadLayoutDepthBuffer) |
| 451 | { |
| 452 | // FIXME: Properly optimizes? |
| 453 | zValue.xy = *Pointer<Float4>(buffer); |
| 454 | zValue.zw = *Pointer<Float4>(buffer + pitch - 8); |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | zValue = *Pointer<Float4>(buffer, 16); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | Int4 zTest; |
| 463 | |
| 464 | switch(state.depthCompareMode) |
| 465 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 466 | case DEPTH_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 467 | // Optimized |
| 468 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 469 | case DEPTH_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 470 | // Optimized |
| 471 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 472 | case DEPTH_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 473 | zTest = CmpEQ(zValue, Z); |
| 474 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 475 | case DEPTH_NOTEQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 476 | zTest = CmpNEQ(zValue, Z); |
| 477 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 478 | case DEPTH_LESS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 479 | if(complementaryDepthBuffer) |
| 480 | { |
| 481 | zTest = CmpLT(zValue, Z); |
| 482 | } |
| 483 | else |
| 484 | { |
| 485 | zTest = CmpNLE(zValue, Z); |
| 486 | } |
| 487 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 488 | case DEPTH_GREATEREQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 489 | if(complementaryDepthBuffer) |
| 490 | { |
| 491 | zTest = CmpNLT(zValue, Z); |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | zTest = CmpLE(zValue, Z); |
| 496 | } |
| 497 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 498 | case DEPTH_LESSEQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 499 | if(complementaryDepthBuffer) |
| 500 | { |
| 501 | zTest = CmpLE(zValue, Z); |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | zTest = CmpNLT(zValue, Z); |
| 506 | } |
| 507 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 508 | case DEPTH_GREATER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 509 | if(complementaryDepthBuffer) |
| 510 | { |
| 511 | zTest = CmpNLE(zValue, Z); |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | zTest = CmpLT(zValue, Z); |
| 516 | } |
| 517 | break; |
| 518 | default: |
| 519 | ASSERT(false); |
| 520 | } |
| 521 | |
| 522 | switch(state.depthCompareMode) |
| 523 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 524 | case DEPTH_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 525 | zMask = cMask; |
| 526 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 527 | case DEPTH_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 528 | zMask = 0x0; |
| 529 | break; |
| 530 | default: |
| 531 | zMask = SignMask(zTest) & cMask; |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | if(state.stencilActive) |
| 536 | { |
| 537 | zMask &= sMask; |
| 538 | } |
| 539 | |
| 540 | return zMask != 0; |
| 541 | } |
| 542 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 543 | void PixelRoutine::alphaTest(Registers &r, Int &aMask, Short4 &alpha) |
| 544 | { |
| 545 | Short4 cmp; |
| 546 | Short4 equal; |
| 547 | |
| 548 | switch(state.alphaCompareMode) |
| 549 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 550 | case ALPHA_ALWAYS: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 551 | aMask = 0xF; |
| 552 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 553 | case ALPHA_NEVER: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 554 | aMask = 0x0; |
| 555 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 556 | case ALPHA_EQUAL: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 557 | cmp = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 558 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 559 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 560 | case ALPHA_NOTEQUAL: // a != b ~ !(a == b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 561 | cmp = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))) ^ Short4((short)0xFFFF, (short)0xFFFF, (short)0xFFFF, (short)0xFFFF); // FIXME |
| 562 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 563 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 564 | case ALPHA_LESS: // a < b ~ b > a |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 565 | cmp = CmpGT(*Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4)), alpha); |
| 566 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 567 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 568 | 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] | 569 | equal = CmpEQ(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 570 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 571 | cmp |= equal; |
| 572 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 573 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 574 | case ALPHA_LESSEQUAL: // a <= b ~ !(a > b) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 575 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))) ^ Short4((short)0xFFFF, (short)0xFFFF, (short)0xFFFF, (short)0xFFFF); // FIXME |
| 576 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 577 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 578 | case ALPHA_GREATER: // a > b |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 579 | cmp = CmpGT(alpha, *Pointer<Short4>(r.data + OFFSET(DrawData,factor.alphaReference4))); |
| 580 | aMask = SignMask(Pack(cmp, Short4(0x0000, 0x0000, 0x0000, 0x0000))); |
| 581 | break; |
| 582 | default: |
| 583 | ASSERT(false); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | void PixelRoutine::alphaToCoverage(Registers &r, Int cMask[4], Float4 &alpha) |
| 588 | { |
| 589 | Int4 coverage0 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c0))); |
| 590 | Int4 coverage1 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c1))); |
| 591 | Int4 coverage2 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c2))); |
| 592 | Int4 coverage3 = CmpNLT(alpha, *Pointer<Float4>(r.data + OFFSET(DrawData,a2c3))); |
| 593 | |
| 594 | Int aMask0 = SignMask(coverage0); |
| 595 | Int aMask1 = SignMask(coverage1); |
| 596 | Int aMask2 = SignMask(coverage2); |
| 597 | Int aMask3 = SignMask(coverage3); |
| 598 | |
| 599 | cMask[0] &= aMask0; |
| 600 | cMask[1] &= aMask1; |
| 601 | cMask[2] &= aMask2; |
| 602 | cMask[3] &= aMask3; |
| 603 | } |
| 604 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 605 | 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] | 606 | { |
| 607 | if(!state.fogActive) |
| 608 | { |
| 609 | return; |
| 610 | } |
| 611 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 612 | if(state.pixelFogMode != FOG_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 613 | { |
| 614 | pixelFog(r, fog, z, rhw); |
| 615 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 616 | fog = Min(fog, Float4(1.0f)); |
| 617 | fog = Max(fog, Float4(0.0f)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 618 | } |
| 619 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 620 | c0.x -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[0])); |
| 621 | c0.y -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[1])); |
| 622 | c0.z -= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 623 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 624 | c0.x *= fog; |
| 625 | c0.y *= fog; |
| 626 | c0.z *= fog; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 627 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 628 | c0.x += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[0])); |
| 629 | c0.y += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[1])); |
| 630 | c0.z += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.colorF[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | void PixelRoutine::pixelFog(Registers &r, Float4 &visibility, Float4 &z, Float4 &rhw) |
| 634 | { |
| 635 | Float4 &zw = visibility; |
| 636 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 637 | if(state.pixelFogMode != FOG_NONE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 638 | { |
| 639 | if(state.wBasedFog) |
| 640 | { |
| 641 | zw = rhw; |
| 642 | } |
| 643 | else |
| 644 | { |
| 645 | if(complementaryDepthBuffer) |
| 646 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 647 | zw = Float4(1.0f) - z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 648 | } |
| 649 | else |
| 650 | { |
| 651 | zw = z; |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | switch(state.pixelFogMode) |
| 657 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 658 | case FOG_NONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 659 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 660 | case FOG_LINEAR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 661 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.scale)); |
| 662 | zw += *Pointer<Float4>(r.data + OFFSET(DrawData,fog.offset)); |
| 663 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 664 | case FOG_EXP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 665 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.densityE)); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 666 | zw = exponential2(zw, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 667 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 668 | case FOG_EXP2: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 669 | zw *= *Pointer<Float4>(r.data + OFFSET(DrawData,fog.densityE2)); |
| 670 | zw *= zw; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 671 | zw = exponential2(zw, true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 672 | zw = Rcp_pp(zw); |
| 673 | break; |
| 674 | default: |
| 675 | ASSERT(false); |
| 676 | } |
| 677 | } |
| 678 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 679 | void PixelRoutine::writeDepth(Registers &r, Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask) |
| 680 | { |
| 681 | if(!state.depthWriteEnable) |
| 682 | { |
| 683 | return; |
| 684 | } |
| 685 | |
| 686 | Float4 Z = z; |
| 687 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 688 | if(shader && shader->depthOverride()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 689 | { |
| 690 | if(complementaryDepthBuffer) |
| 691 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 692 | Z = Float4(1.0f) - r.oDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 693 | } |
| 694 | else |
| 695 | { |
| 696 | Z = r.oDepth; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | Pointer<Byte> buffer; |
| 701 | Int pitch; |
| 702 | |
| 703 | if(!state.quadLayoutDepthBuffer) |
| 704 | { |
| 705 | buffer = zBuffer + 4 * x; |
| 706 | pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); |
| 707 | } |
| 708 | else |
| 709 | { |
| 710 | buffer = zBuffer + 8 * x; |
| 711 | } |
| 712 | |
| 713 | if(q > 0) |
| 714 | { |
| 715 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,depthSliceB)); |
| 716 | } |
| 717 | |
| 718 | Float4 zValue; |
| 719 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 720 | if(state.depthCompareMode != DEPTH_NEVER || (state.depthCompareMode != DEPTH_ALWAYS && !state.depthWriteEnable)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 721 | { |
| 722 | if(!state.quadLayoutDepthBuffer) |
| 723 | { |
| 724 | // FIXME: Properly optimizes? |
| 725 | zValue.xy = *Pointer<Float4>(buffer); |
| 726 | zValue.zw = *Pointer<Float4>(buffer + pitch - 8); |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | zValue = *Pointer<Float4>(buffer, 16); |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | Z = As<Float4>(As<Int4>(Z) & *Pointer<Int4>(r.constants + OFFSET(Constants,maskD4X) + zMask * 16, 16)); |
| 735 | zValue = As<Float4>(As<Int4>(zValue) & *Pointer<Int4>(r.constants + OFFSET(Constants,invMaskD4X) + zMask * 16, 16)); |
| 736 | Z = As<Float4>(As<Int4>(Z) | As<Int4>(zValue)); |
| 737 | |
| 738 | if(!state.quadLayoutDepthBuffer) |
| 739 | { |
| 740 | // FIXME: Properly optimizes? |
| 741 | *Pointer<Float2>(buffer) = Float2(Z.xy); |
| 742 | *Pointer<Float2>(buffer + pitch) = Float2(Z.zw); |
| 743 | } |
| 744 | else |
| 745 | { |
| 746 | *Pointer<Float4>(buffer, 16) = Z; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | void PixelRoutine::writeStencil(Registers &r, Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &zMask, Int &cMask) |
| 751 | { |
| 752 | if(!state.stencilActive) |
| 753 | { |
| 754 | return; |
| 755 | } |
| 756 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 757 | 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] | 758 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 759 | 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] | 760 | { |
| 761 | return; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | if(state.stencilWriteMasked && (!state.twoSidedStencil || state.stencilWriteMaskedCCW)) |
| 766 | { |
| 767 | return; |
| 768 | } |
| 769 | |
| 770 | Pointer<Byte> buffer = sBuffer + 2 * x; |
| 771 | |
| 772 | if(q > 0) |
| 773 | { |
| 774 | buffer += q * *Pointer<Int>(r.data + OFFSET(DrawData,stencilSliceB)); |
| 775 | } |
| 776 | |
| 777 | Byte8 bufferValue = As<Byte8>(Long1(*Pointer<UInt>(buffer))); |
| 778 | |
| 779 | Byte8 newValue; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 780 | 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] | 781 | |
| 782 | if(!state.noStencilWriteMask) |
| 783 | { |
| 784 | Byte8 maskedValue = bufferValue; |
| 785 | newValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].writeMaskQ)); |
| 786 | maskedValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[0].invWriteMaskQ)); |
| 787 | newValue |= maskedValue; |
| 788 | } |
| 789 | |
| 790 | if(state.twoSidedStencil) |
| 791 | { |
| 792 | Byte8 newValueCCW; |
| 793 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 794 | 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] | 795 | |
| 796 | if(!state.noStencilWriteMaskCCW) |
| 797 | { |
| 798 | Byte8 maskedValue = bufferValue; |
| 799 | newValueCCW &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].writeMaskQ)); |
| 800 | maskedValue &= *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[1].invWriteMaskQ)); |
| 801 | newValueCCW |= maskedValue; |
| 802 | } |
| 803 | |
| 804 | newValue &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,clockwiseMask)); |
| 805 | newValueCCW &= *Pointer<Byte8>(r.primitive + OFFSET(Primitive,invClockwiseMask)); |
| 806 | newValue |= newValueCCW; |
| 807 | } |
| 808 | |
| 809 | newValue &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * cMask); |
| 810 | bufferValue &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * cMask); |
| 811 | newValue |= bufferValue; |
| 812 | |
| 813 | *Pointer<UInt>(buffer) = UInt(As<Long>(newValue)); |
| 814 | } |
| 815 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 816 | 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] | 817 | { |
| 818 | Byte8 &pass = newValue; |
| 819 | Byte8 fail; |
| 820 | Byte8 zFail; |
| 821 | |
| 822 | stencilOperation(r, pass, bufferValue, stencilPassOperation, CCW); |
| 823 | |
| 824 | if(stencilZFailOperation != stencilPassOperation) |
| 825 | { |
| 826 | stencilOperation(r, zFail, bufferValue, stencilZFailOperation, CCW); |
| 827 | } |
| 828 | |
| 829 | if(stencilFailOperation != stencilPassOperation || stencilFailOperation != stencilZFailOperation) |
| 830 | { |
| 831 | stencilOperation(r, fail, bufferValue, stencilFailOperation, CCW); |
| 832 | } |
| 833 | |
| 834 | if(stencilFailOperation != stencilPassOperation || stencilFailOperation != stencilZFailOperation) |
| 835 | { |
| 836 | if(state.depthTestActive && stencilZFailOperation != stencilPassOperation) // zMask valid and values not the same |
| 837 | { |
| 838 | pass &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * zMask); |
| 839 | zFail &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * zMask); |
| 840 | pass |= zFail; |
| 841 | } |
| 842 | |
| 843 | pass &= *Pointer<Byte8>(r.constants + OFFSET(Constants,maskB4Q) + 8 * sMask); |
| 844 | fail &= *Pointer<Byte8>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * sMask); |
| 845 | pass |= fail; |
| 846 | } |
| 847 | } |
| 848 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 849 | 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] | 850 | { |
| 851 | switch(operation) |
| 852 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 853 | case OPERATION_KEEP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 854 | output = bufferValue; |
| 855 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 856 | case OPERATION_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 857 | output = Byte8(0x0000000000000000); |
| 858 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 859 | case OPERATION_REPLACE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 860 | output = *Pointer<Byte8>(r.data + OFFSET(DrawData,stencil[CCW].referenceQ)); |
| 861 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 862 | case OPERATION_INCRSAT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 863 | output = AddSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1)); |
| 864 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 865 | case OPERATION_DECRSAT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 866 | output = SubSat(bufferValue, Byte8(1, 1, 1, 1, 1, 1, 1, 1)); |
| 867 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 868 | case OPERATION_INVERT: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 869 | output = bufferValue ^ Byte8(0xFFFFFFFFFFFFFFFF); |
| 870 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 871 | case OPERATION_INCR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 872 | output = bufferValue + Byte8(1, 1, 1, 1, 1, 1, 1, 1); |
| 873 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 874 | case OPERATION_DECR: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 875 | output = bufferValue - Byte8(1, 1, 1, 1, 1, 1, 1, 1); |
| 876 | break; |
| 877 | default: |
| 878 | ASSERT(false); |
| 879 | } |
| 880 | } |
| 881 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 882 | void PixelRoutine::blendFactor(Registers &r, const Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, BlendFactor blendFactorActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 883 | { |
| 884 | switch(blendFactorActive) |
| 885 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 886 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 887 | // Optimized |
| 888 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 889 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 890 | // Optimized |
| 891 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 892 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 893 | blendFactor.x = current.x; |
| 894 | blendFactor.y = current.y; |
| 895 | blendFactor.z = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 896 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 897 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 898 | blendFactor.x = Short4(0xFFFFu) - current.x; |
| 899 | blendFactor.y = Short4(0xFFFFu) - current.y; |
| 900 | blendFactor.z = Short4(0xFFFFu) - current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 901 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 902 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 903 | blendFactor.x = pixel.x; |
| 904 | blendFactor.y = pixel.y; |
| 905 | blendFactor.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 906 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 907 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 908 | blendFactor.x = Short4(0xFFFFu) - pixel.x; |
| 909 | blendFactor.y = Short4(0xFFFFu) - pixel.y; |
| 910 | blendFactor.z = Short4(0xFFFFu) - pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 911 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 912 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 913 | blendFactor.x = current.w; |
| 914 | blendFactor.y = current.w; |
| 915 | blendFactor.z = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 916 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 917 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 918 | blendFactor.x = Short4(0xFFFFu) - current.w; |
| 919 | blendFactor.y = Short4(0xFFFFu) - current.w; |
| 920 | blendFactor.z = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 921 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 922 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 923 | blendFactor.x = pixel.w; |
| 924 | blendFactor.y = pixel.w; |
| 925 | blendFactor.z = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 926 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 927 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 928 | blendFactor.x = Short4(0xFFFFu) - pixel.w; |
| 929 | blendFactor.y = Short4(0xFFFFu) - pixel.w; |
| 930 | blendFactor.z = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 931 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 932 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 933 | blendFactor.x = Short4(0xFFFFu) - pixel.w; |
| 934 | blendFactor.x = Min(As<UShort4>(blendFactor.x), As<UShort4>(current.w)); |
| 935 | blendFactor.y = blendFactor.x; |
| 936 | blendFactor.z = blendFactor.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 937 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 938 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 939 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[0])); |
| 940 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[1])); |
| 941 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 942 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 943 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 944 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[0])); |
| 945 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[1])); |
| 946 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 947 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 948 | case BLEND_CONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 949 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
| 950 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
| 951 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 952 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 953 | case BLEND_INVCONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 954 | blendFactor.x = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
| 955 | blendFactor.y = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
| 956 | blendFactor.z = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 957 | break; |
| 958 | default: |
| 959 | ASSERT(false); |
| 960 | } |
| 961 | } |
| 962 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 963 | void PixelRoutine::blendFactorAlpha(Registers &r, const Vector4s &blendFactor, const Vector4s ¤t, const Vector4s &pixel, BlendFactor blendFactorAlphaActive) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 964 | { |
| 965 | switch(blendFactorAlphaActive) |
| 966 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 967 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 968 | // Optimized |
| 969 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 970 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 971 | // Optimized |
| 972 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 973 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 974 | blendFactor.w = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 975 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 976 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 977 | blendFactor.w = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 978 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 979 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 980 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 981 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 982 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 983 | blendFactor.w = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 984 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 985 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 986 | blendFactor.w = current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 987 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 988 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 989 | blendFactor.w = Short4(0xFFFFu) - current.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 990 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 991 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 992 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 993 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 994 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 995 | blendFactor.w = Short4(0xFFFFu) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 996 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 997 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 998 | blendFactor.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 999 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1000 | case BLEND_CONSTANT: |
| 1001 | case BLEND_CONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1002 | blendFactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.blendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1003 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1004 | case BLEND_INVCONSTANT: |
| 1005 | case BLEND_INVCONSTANTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1006 | blendFactor.w = *Pointer<Short4>(r.data + OFFSET(DrawData,factor.invBlendConstant4W[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1007 | break; |
| 1008 | default: |
| 1009 | ASSERT(false); |
| 1010 | } |
| 1011 | } |
| 1012 | |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1013 | void PixelRoutine::readPixel(Registers &r, int index, Pointer<Byte> &cBuffer, Vector4s ¤t, Int &x, Vector4s &pixel) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1014 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1015 | Short4 c01; |
| 1016 | Short4 c23; |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1017 | Pointer<Byte> buffer; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1018 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1019 | switch(state.targetFormat[index]) |
| 1020 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1021 | case FORMAT_R5G6B5: |
| 1022 | buffer = cBuffer + 2 * x; |
| 1023 | c01 = As<Short4>(Insert(As<Int2>(c01), *Pointer<Int>(buffer), 0)); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1024 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1025 | c01 = As<Short4>(Insert(As<Int2>(c01), *Pointer<Int>(buffer), 1)); |
| 1026 | |
| 1027 | pixel.x = c01 & Short4(0xF800u); |
| 1028 | pixel.y = (c01 & Short4(0x07E0u)) << 5; |
| 1029 | pixel.z = (c01 & Short4(0x001Fu)) << 11; |
| 1030 | pixel.w = Short4(0xFFFFu); |
| 1031 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1032 | case FORMAT_A8R8G8B8: |
| 1033 | buffer = cBuffer + 4 * x; |
| 1034 | c01 = *Pointer<Short4>(buffer); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1035 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1036 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1037 | pixel.z = c01; |
| 1038 | pixel.y = c01; |
| 1039 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 1040 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 1041 | pixel.x = pixel.z; |
| 1042 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 1043 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 1044 | pixel.y = pixel.z; |
| 1045 | pixel.w = pixel.x; |
| 1046 | pixel.x = UnpackLow(As<Byte8>(pixel.x), As<Byte8>(pixel.x)); |
| 1047 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 1048 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 1049 | pixel.w = UnpackHigh(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1050 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1051 | case FORMAT_A8B8G8R8: |
| 1052 | buffer = cBuffer + 4 * x; |
| 1053 | c01 = *Pointer<Short4>(buffer); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1054 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1055 | c23 = *Pointer<Short4>(buffer); |
| 1056 | pixel.z = c01; |
| 1057 | pixel.y = c01; |
| 1058 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 1059 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 1060 | pixel.x = pixel.z; |
| 1061 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 1062 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 1063 | pixel.y = pixel.z; |
| 1064 | pixel.w = pixel.x; |
| 1065 | pixel.x = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 1066 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 1067 | pixel.z = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 1068 | pixel.w = UnpackHigh(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 1069 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1070 | case FORMAT_A8: |
| 1071 | buffer = cBuffer + 1 * x; |
| 1072 | pixel.w = Insert(pixel.w, *Pointer<Short>(buffer), 0); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1073 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1074 | pixel.w = Insert(pixel.w, *Pointer<Short>(buffer), 1); |
| 1075 | pixel.w = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 1076 | pixel.x = Short4(0x0000); |
| 1077 | pixel.y = Short4(0x0000); |
| 1078 | pixel.z = Short4(0x0000); |
| 1079 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1080 | case FORMAT_X8R8G8B8: |
| 1081 | buffer = cBuffer + 4 * x; |
| 1082 | c01 = *Pointer<Short4>(buffer); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1083 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1084 | c23 = *Pointer<Short4>(buffer); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1085 | pixel.z = c01; |
| 1086 | pixel.y = c01; |
| 1087 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 1088 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 1089 | pixel.x = pixel.z; |
| 1090 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 1091 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 1092 | pixel.y = pixel.z; |
| 1093 | pixel.x = UnpackLow(As<Byte8>(pixel.x), As<Byte8>(pixel.x)); |
| 1094 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 1095 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 1096 | pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1097 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1098 | case FORMAT_X8B8G8R8: |
| 1099 | buffer = cBuffer + 4 * x; |
| 1100 | c01 = *Pointer<Short4>(buffer); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1101 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1102 | c23 = *Pointer<Short4>(buffer); |
| 1103 | pixel.z = c01; |
| 1104 | pixel.y = c01; |
| 1105 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(c23)); |
| 1106 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(c23)); |
| 1107 | pixel.x = pixel.z; |
| 1108 | pixel.z = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.y)); |
| 1109 | pixel.x = UnpackHigh(As<Byte8>(pixel.x), As<Byte8>(pixel.y)); |
| 1110 | pixel.y = pixel.z; |
| 1111 | pixel.w = pixel.x; |
| 1112 | pixel.x = UnpackLow(As<Byte8>(pixel.z), As<Byte8>(pixel.z)); |
| 1113 | pixel.y = UnpackHigh(As<Byte8>(pixel.y), As<Byte8>(pixel.y)); |
| 1114 | pixel.z = UnpackLow(As<Byte8>(pixel.w), As<Byte8>(pixel.w)); |
| 1115 | pixel.w = Short4(0xFFFFu); |
| 1116 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1117 | case FORMAT_A8G8R8B8Q: |
| 1118 | UNIMPLEMENTED(); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1119 | // pixel.z = UnpackLow(As<Byte8>(pixel.z), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 1120 | // pixel.x = UnpackHigh(As<Byte8>(pixel.x), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 1121 | // pixel.y = UnpackLow(As<Byte8>(pixel.y), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
| 1122 | // 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] | 1123 | break; |
| 1124 | case FORMAT_X8G8R8B8Q: |
| 1125 | UNIMPLEMENTED(); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1126 | // pixel.z = UnpackLow(As<Byte8>(pixel.z), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 1127 | // pixel.x = UnpackHigh(As<Byte8>(pixel.x), *Pointer<Byte8>(cBuffer + 8 * x + 0)); |
| 1128 | // pixel.y = UnpackLow(As<Byte8>(pixel.y), *Pointer<Byte8>(cBuffer + 8 * x + 8)); |
| 1129 | // pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1130 | break; |
| 1131 | case FORMAT_A16B16G16R16: |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1132 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1133 | pixel.x = *Pointer<Short4>(buffer + 8 * x); |
| 1134 | pixel.y = *Pointer<Short4>(buffer + 8 * x + 8); |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1135 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1136 | pixel.z = *Pointer<Short4>(buffer + 8 * x); |
| 1137 | pixel.w = *Pointer<Short4>(buffer + 8 * x + 8); |
| 1138 | transpose4x4(pixel.x, pixel.y, pixel.z, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1139 | break; |
| 1140 | case FORMAT_G16R16: |
| 1141 | buffer = cBuffer; |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1142 | pixel.x = *Pointer<Short4>(buffer + 4 * x); |
| 1143 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData, colorPitchB[index])); |
| 1144 | pixel.y = *Pointer<Short4>(buffer + 4 * x); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1145 | pixel.z = pixel.x; |
| 1146 | pixel.x = As<Short4>(UnpackLow(pixel.x, pixel.y)); |
| 1147 | pixel.z = As<Short4>(UnpackHigh(pixel.z, pixel.y)); |
| 1148 | pixel.y = pixel.z; |
| 1149 | pixel.x = As<Short4>(UnpackLow(pixel.x, pixel.z)); |
| 1150 | pixel.y = As<Short4>(UnpackHigh(pixel.y, pixel.z)); |
| 1151 | pixel.z = Short4(0xFFFFu); |
| 1152 | pixel.w = Short4(0xFFFFu); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1153 | break; |
| 1154 | default: |
| 1155 | ASSERT(false); |
| 1156 | } |
| 1157 | |
| 1158 | if(postBlendSRGB && state.writeSRGB) |
| 1159 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1160 | sRGBtoLinear16_12_16(r, pixel); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1161 | } |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | void PixelRoutine::alphaBlend(Registers &r, int index, Pointer<Byte> &cBuffer, Vector4s ¤t, Int &x) |
| 1165 | { |
| 1166 | if(!state.alphaBlendActive) |
| 1167 | { |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | Vector4s pixel; |
| 1172 | Short4 c01; |
| 1173 | Short4 c23; |
| 1174 | |
| 1175 | readPixel(r, index, cBuffer, current, x, pixel); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1176 | |
| 1177 | // Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 1178 | Vector4s sourceFactor; |
| 1179 | Vector4s destFactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1180 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1181 | blendFactor(r, sourceFactor, current, pixel, state.sourceBlendFactor); |
| 1182 | blendFactor(r, destFactor, current, pixel, state.destBlendFactor); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1183 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1184 | if(state.sourceBlendFactor != BLEND_ONE && state.sourceBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1185 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1186 | current.x = MulHigh(As<UShort4>(current.x), As<UShort4>(sourceFactor.x)); |
| 1187 | current.y = MulHigh(As<UShort4>(current.y), As<UShort4>(sourceFactor.y)); |
| 1188 | current.z = MulHigh(As<UShort4>(current.z), As<UShort4>(sourceFactor.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1189 | } |
| 1190 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1191 | if(state.destBlendFactor != BLEND_ONE && state.destBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1192 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1193 | pixel.x = MulHigh(As<UShort4>(pixel.x), As<UShort4>(destFactor.x)); |
| 1194 | pixel.y = MulHigh(As<UShort4>(pixel.y), As<UShort4>(destFactor.y)); |
| 1195 | pixel.z = MulHigh(As<UShort4>(pixel.z), As<UShort4>(destFactor.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | switch(state.blendOperation) |
| 1199 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1200 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1201 | current.x = AddSat(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 1202 | current.y = AddSat(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 1203 | current.z = AddSat(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1204 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1205 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1206 | current.x = SubSat(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 1207 | current.y = SubSat(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 1208 | current.z = SubSat(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1209 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1210 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1211 | current.x = SubSat(As<UShort4>(pixel.x), As<UShort4>(current.x)); |
| 1212 | current.y = SubSat(As<UShort4>(pixel.y), As<UShort4>(current.y)); |
| 1213 | current.z = SubSat(As<UShort4>(pixel.z), As<UShort4>(current.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1214 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1215 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1216 | current.x = Min(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 1217 | current.y = Min(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 1218 | current.z = Min(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1219 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1220 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1221 | current.x = Max(As<UShort4>(current.x), As<UShort4>(pixel.x)); |
| 1222 | current.y = Max(As<UShort4>(current.y), As<UShort4>(pixel.y)); |
| 1223 | current.z = Max(As<UShort4>(current.z), As<UShort4>(pixel.z)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1224 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1225 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1226 | // No operation |
| 1227 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1228 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1229 | current.x = pixel.x; |
| 1230 | current.y = pixel.y; |
| 1231 | current.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1232 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1233 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1234 | current.x = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 1235 | current.y = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
| 1236 | current.z = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1237 | break; |
| 1238 | default: |
| 1239 | ASSERT(false); |
| 1240 | } |
| 1241 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1242 | blendFactorAlpha(r, sourceFactor, current, pixel, state.sourceBlendFactorAlpha); |
| 1243 | blendFactorAlpha(r, destFactor, current, pixel, state.destBlendFactorAlpha); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1244 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1245 | if(state.sourceBlendFactorAlpha != BLEND_ONE && state.sourceBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1246 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1247 | current.w = MulHigh(As<UShort4>(current.w), As<UShort4>(sourceFactor.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1250 | if(state.destBlendFactorAlpha != BLEND_ONE && state.destBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1251 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1252 | pixel.w = MulHigh(As<UShort4>(pixel.w), As<UShort4>(destFactor.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | switch(state.blendOperationAlpha) |
| 1256 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1257 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1258 | current.w = AddSat(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1259 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1260 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1261 | current.w = SubSat(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1262 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1263 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1264 | current.w = SubSat(As<UShort4>(pixel.w), As<UShort4>(current.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1265 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1266 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1267 | current.w = Min(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1268 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1269 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1270 | current.w = Max(As<UShort4>(current.w), As<UShort4>(pixel.w)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1271 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1272 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1273 | // No operation |
| 1274 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1275 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1276 | current.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1277 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1278 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1279 | current.w = Short4(0x0000, 0x0000, 0x0000, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1280 | break; |
| 1281 | default: |
| 1282 | ASSERT(false); |
| 1283 | } |
| 1284 | } |
| 1285 | |
Maxime Grégoire | d976274 | 2015-07-08 16:43:48 -0400 | [diff] [blame] | 1286 | void PixelRoutine::logicOperation(Registers &r, int index, Pointer<Byte> &cBuffer, Vector4s ¤t, Int &x) |
| 1287 | { |
| 1288 | if(state.logicalOperation == LogicalOperation::LOGICALOP_COPY) |
| 1289 | { |
| 1290 | return; |
| 1291 | } |
| 1292 | |
| 1293 | Vector4s pixel; |
| 1294 | |
| 1295 | // Read pixel |
| 1296 | readPixel(r, index, cBuffer, current, x, pixel); |
| 1297 | |
| 1298 | switch(state.logicalOperation) |
| 1299 | { |
| 1300 | case LOGICALOP_CLEAR: |
| 1301 | current.x = 0; |
| 1302 | current.y = 0; |
| 1303 | current.z = 0; |
| 1304 | break; |
| 1305 | case LOGICALOP_SET: |
| 1306 | current.x = 0xFFFF; |
| 1307 | current.y = 0xFFFF; |
| 1308 | current.z = 0xFFFF; |
| 1309 | break; |
| 1310 | case LOGICALOP_COPY: |
| 1311 | ASSERT(false); // Optimized out |
| 1312 | break; |
| 1313 | case LOGICALOP_COPY_INVERTED: |
| 1314 | current.x = ~current.x; |
| 1315 | current.y = ~current.y; |
| 1316 | current.z = ~current.z; |
| 1317 | break; |
| 1318 | case LOGICALOP_NOOP: |
| 1319 | current.x = pixel.x; |
| 1320 | current.y = pixel.y; |
| 1321 | current.z = pixel.z; |
| 1322 | break; |
| 1323 | case LOGICALOP_INVERT: |
| 1324 | current.x = ~pixel.x; |
| 1325 | current.y = ~pixel.y; |
| 1326 | current.z = ~pixel.z; |
| 1327 | break; |
| 1328 | case LOGICALOP_AND: |
| 1329 | current.x = pixel.x & current.x; |
| 1330 | current.y = pixel.y & current.y; |
| 1331 | current.z = pixel.z & current.z; |
| 1332 | break; |
| 1333 | case LOGICALOP_NAND: |
| 1334 | current.x = ~(pixel.x & current.x); |
| 1335 | current.y = ~(pixel.y & current.y); |
| 1336 | current.z = ~(pixel.z & current.z); |
| 1337 | break; |
| 1338 | case LOGICALOP_OR: |
| 1339 | current.x = pixel.x | current.x; |
| 1340 | current.y = pixel.y | current.y; |
| 1341 | current.z = pixel.z | current.z; |
| 1342 | break; |
| 1343 | case LOGICALOP_NOR: |
| 1344 | current.x = ~(pixel.x | current.x); |
| 1345 | current.y = ~(pixel.y | current.y); |
| 1346 | current.z = ~(pixel.z | current.z); |
| 1347 | break; |
| 1348 | case LOGICALOP_XOR: |
| 1349 | current.x = pixel.x ^ current.x; |
| 1350 | current.y = pixel.y ^ current.y; |
| 1351 | current.z = pixel.z ^ current.z; |
| 1352 | break; |
| 1353 | case LOGICALOP_EQUIV: |
| 1354 | current.x = ~(pixel.x ^ current.x); |
| 1355 | current.y = ~(pixel.y ^ current.y); |
| 1356 | current.z = ~(pixel.z ^ current.z); |
| 1357 | break; |
| 1358 | case LOGICALOP_AND_REVERSE: |
| 1359 | current.x = ~pixel.x & current.x; |
| 1360 | current.y = ~pixel.y & current.y; |
| 1361 | current.z = ~pixel.z & current.z; |
| 1362 | break; |
| 1363 | case LOGICALOP_AND_INVERTED: |
| 1364 | current.x = pixel.x & ~current.x; |
| 1365 | current.y = pixel.y & ~current.y; |
| 1366 | current.z = pixel.z & ~current.z; |
| 1367 | break; |
| 1368 | case LOGICALOP_OR_REVERSE: |
| 1369 | current.x = ~pixel.x | current.x; |
| 1370 | current.y = ~pixel.y | current.y; |
| 1371 | current.z = ~pixel.z | current.z; |
| 1372 | break; |
| 1373 | case LOGICALOP_OR_INVERTED: |
| 1374 | current.x = pixel.x | ~current.x; |
| 1375 | current.y = pixel.y | ~current.y; |
| 1376 | current.z = pixel.z | ~current.z; |
| 1377 | break; |
| 1378 | default: |
| 1379 | ASSERT(false); |
| 1380 | } |
| 1381 | } |
| 1382 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 1383 | void PixelRoutine::writeColor(Registers &r, int index, Pointer<Byte> &cBuffer, Int &x, Vector4s ¤t, Int &sMask, Int &zMask, Int &cMask) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1384 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1385 | if(postBlendSRGB && state.writeSRGB) |
| 1386 | { |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 1387 | linearToSRGB16_12_16(r, current); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | if(exactColorRounding) |
| 1391 | { |
| 1392 | switch(state.targetFormat[index]) |
| 1393 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1394 | case FORMAT_R5G6B5: |
| 1395 | // UNIMPLEMENTED(); // FIXME |
| 1396 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1397 | case FORMAT_X8G8R8B8Q: |
| 1398 | case FORMAT_A8G8R8B8Q: |
| 1399 | case FORMAT_X8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1400 | case FORMAT_X8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1401 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1402 | case FORMAT_A8B8G8R8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1403 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1404 | current.x = current.x - As<Short4>(As<UShort4>(current.x) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 1405 | current.y = current.y - As<Short4>(As<UShort4>(current.y) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 1406 | current.z = current.z - As<Short4>(As<UShort4>(current.z) >> 8) + Short4(0x0080, 0x0080, 0x0080, 0x0080); |
| 1407 | 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] | 1408 | } |
| 1409 | break; |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | int rgbaWriteMask = state.colorWriteActive(index); |
| 1414 | int bgraWriteMask = rgbaWriteMask & 0x0000000A | (rgbaWriteMask & 0x00000001) << 2 | (rgbaWriteMask & 0x00000004) >> 2; |
| 1415 | int brgaWriteMask = rgbaWriteMask & 0x00000008 | (rgbaWriteMask & 0x00000001) << 1 | (rgbaWriteMask & 0x00000002) << 1 | (rgbaWriteMask & 0x00000004) >> 2; |
| 1416 | |
| 1417 | switch(state.targetFormat[index]) |
| 1418 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1419 | case FORMAT_R5G6B5: |
| 1420 | { |
| 1421 | current.x = current.x & Short4(0xF800u); |
| 1422 | current.y = As<UShort4>(current.y & Short4(0xFC00u)) >> 5; |
| 1423 | current.z = As<UShort4>(current.z) >> 11; |
| 1424 | |
| 1425 | current.x = current.x | current.y | current.z; |
| 1426 | } |
| 1427 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1428 | case FORMAT_X8G8R8B8Q: |
| 1429 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1430 | // current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 1431 | // current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 1432 | // current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1433 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1434 | // current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 1435 | // 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] | 1436 | break; |
| 1437 | case FORMAT_A8G8R8B8Q: |
| 1438 | UNIMPLEMENTED(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1439 | // current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 1440 | // current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 1441 | // current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 1442 | // current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1443 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1444 | // current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 1445 | // 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] | 1446 | break; |
| 1447 | case FORMAT_X8R8G8B8: |
| 1448 | case FORMAT_A8R8G8B8: |
| 1449 | if(state.targetFormat[index] == FORMAT_X8R8G8B8 || rgbaWriteMask == 0x7) |
| 1450 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1451 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 1452 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 1453 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1454 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1455 | current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 1456 | 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] | 1457 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1458 | current.x = current.z; |
| 1459 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 1460 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 1461 | current.y = current.z; |
| 1462 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 1463 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1464 | } |
| 1465 | else |
| 1466 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1467 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 1468 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 1469 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 1470 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1471 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1472 | current.z = As<Short4>(Pack(As<UShort4>(current.z), As<UShort4>(current.x))); |
| 1473 | 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] | 1474 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1475 | current.x = current.z; |
| 1476 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 1477 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 1478 | current.y = current.z; |
| 1479 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 1480 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1481 | } |
| 1482 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1483 | case FORMAT_X8B8G8R8: |
| 1484 | case FORMAT_A8B8G8R8: |
| 1485 | if(state.targetFormat[index] == FORMAT_X8B8G8R8 || rgbaWriteMask == 0x7) |
| 1486 | { |
| 1487 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 1488 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 1489 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 1490 | |
| 1491 | current.z = As<Short4>(Pack(As<UShort4>(current.x), As<UShort4>(current.z))); |
| 1492 | current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.y))); |
| 1493 | |
| 1494 | current.x = current.z; |
| 1495 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 1496 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 1497 | current.y = current.z; |
| 1498 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 1499 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
| 1500 | } |
| 1501 | else |
| 1502 | { |
| 1503 | current.x = As<Short4>(As<UShort4>(current.x) >> 8); |
| 1504 | current.y = As<Short4>(As<UShort4>(current.y) >> 8); |
| 1505 | current.z = As<Short4>(As<UShort4>(current.z) >> 8); |
| 1506 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
| 1507 | |
| 1508 | current.z = As<Short4>(Pack(As<UShort4>(current.x), As<UShort4>(current.z))); |
| 1509 | current.y = As<Short4>(Pack(As<UShort4>(current.y), As<UShort4>(current.w))); |
| 1510 | |
| 1511 | current.x = current.z; |
| 1512 | current.z = UnpackLow(As<Byte8>(current.z), As<Byte8>(current.y)); |
| 1513 | current.x = UnpackHigh(As<Byte8>(current.x), As<Byte8>(current.y)); |
| 1514 | current.y = current.z; |
| 1515 | current.z = As<Short4>(UnpackLow(current.z, current.x)); |
| 1516 | current.y = As<Short4>(UnpackHigh(current.y, current.x)); |
| 1517 | } |
| 1518 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1519 | case FORMAT_A8: |
| 1520 | current.w = As<Short4>(As<UShort4>(current.w) >> 8); |
| 1521 | current.w = As<Short4>(Pack(As<UShort4>(current.w), As<UShort4>(current.w))); |
| 1522 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1523 | case FORMAT_G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1524 | current.z = current.x; |
| 1525 | current.x = As<Short4>(UnpackLow(current.x, current.y)); |
| 1526 | current.z = As<Short4>(UnpackHigh(current.z, current.y)); |
| 1527 | current.y = current.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1528 | break; |
| 1529 | case FORMAT_A16B16G16R16: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1530 | transpose4x4(current.x, current.y, current.z, current.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1531 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1532 | default: |
| 1533 | ASSERT(false); |
| 1534 | } |
| 1535 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1536 | Short4 c01 = current.z; |
| 1537 | Short4 c23 = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1538 | |
| 1539 | Int xMask; // Combination of all masks |
| 1540 | |
| 1541 | if(state.depthTestActive) |
| 1542 | { |
| 1543 | xMask = zMask; |
| 1544 | } |
| 1545 | else |
| 1546 | { |
| 1547 | xMask = cMask; |
| 1548 | } |
| 1549 | |
| 1550 | if(state.stencilActive) |
| 1551 | { |
| 1552 | xMask &= sMask; |
| 1553 | } |
| 1554 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1555 | switch(state.targetFormat[index]) |
| 1556 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1557 | case FORMAT_R5G6B5: |
| 1558 | { |
| 1559 | Pointer<Byte> buffer = cBuffer + 2 * x; |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1560 | Int value = *Pointer<Int>(buffer); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1561 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1562 | Int c01 = Extract(As<Int2>(current.x), 0); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1563 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1564 | if((bgraWriteMask & 0x00000007) != 0x00000007) |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1565 | { |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1566 | Int masked = value; |
| 1567 | c01 &= *Pointer<Int>(r.constants + OFFSET(Constants,mask565Q[bgraWriteMask & 0x7][0])); |
| 1568 | masked &= *Pointer<Int>(r.constants + OFFSET(Constants,invMask565Q[bgraWriteMask & 0x7][0])); |
| 1569 | c01 |= masked; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1570 | } |
| 1571 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1572 | c01 &= *Pointer<Int>(r.constants + OFFSET(Constants,maskW4Q[0][0]) + xMask * 8); |
| 1573 | value &= *Pointer<Int>(r.constants + OFFSET(Constants,invMaskW4Q[0][0]) + xMask * 8); |
| 1574 | c01 |= value; |
| 1575 | *Pointer<Int>(buffer) = c01; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1576 | |
| 1577 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1578 | value = *Pointer<Int>(buffer); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1579 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1580 | Int c23 = Extract(As<Int2>(current.x), 1); |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1581 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1582 | if((bgraWriteMask & 0x00000007) != 0x00000007) |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1583 | { |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1584 | Int masked = value; |
| 1585 | c23 &= *Pointer<Int>(r.constants + OFFSET(Constants,mask565Q[bgraWriteMask & 0x7][0])); |
| 1586 | masked &= *Pointer<Int>(r.constants + OFFSET(Constants,invMask565Q[bgraWriteMask & 0x7][0])); |
| 1587 | c23 |= masked; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1588 | } |
| 1589 | |
Nicolas Capens | 9919b6c | 2015-05-26 01:11:26 -0400 | [diff] [blame] | 1590 | c23 &= *Pointer<Int>(r.constants + OFFSET(Constants,maskW4Q[0][2]) + xMask * 8); |
| 1591 | value &= *Pointer<Int>(r.constants + OFFSET(Constants,invMaskW4Q[0][2]) + xMask * 8); |
| 1592 | c23 |= value; |
| 1593 | *Pointer<Int>(buffer) = c23; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1594 | } |
| 1595 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1596 | case FORMAT_A8G8R8B8Q: |
| 1597 | case FORMAT_X8G8R8B8Q: // FIXME: Don't touch alpha? |
| 1598 | UNIMPLEMENTED(); |
| 1599 | // value = *Pointer<Short4>(cBuffer + 8 * x + 0); |
| 1600 | |
| 1601 | // if((state.targetFormat[index] == FORMAT_A8G8R8B8Q && bgraWriteMask != 0x0000000F) || |
| 1602 | // ((state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x00000007) && |
| 1603 | // (state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 1604 | // { |
| 1605 | // Short4 masked = value; |
| 1606 | // c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 1607 | // masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 1608 | // c01 |= masked; |
| 1609 | // } |
| 1610 | |
| 1611 | // c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 1612 | // value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 1613 | // c01 |= value; |
| 1614 | // *Pointer<Short4>(cBuffer + 8 * x + 0) = c01; |
| 1615 | |
| 1616 | // value = *Pointer<Short4>(cBuffer + 8 * x + 8); |
| 1617 | |
| 1618 | // if((state.targetFormat[index] == FORMAT_A8G8R8B8Q && bgraWriteMask != 0x0000000F) || |
| 1619 | // ((state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x00000007) && |
| 1620 | // (state.targetFormat[index] == FORMAT_X8G8R8B8Q && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 1621 | // { |
| 1622 | // Short4 masked = value; |
| 1623 | // c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 1624 | // masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 1625 | // c23 |= masked; |
| 1626 | // } |
| 1627 | |
| 1628 | // c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 1629 | // value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 1630 | // c23 |= value; |
| 1631 | // *Pointer<Short4>(cBuffer + 8 * x + 8) = c23; |
| 1632 | break; |
| 1633 | case FORMAT_A8R8G8B8: |
| 1634 | case FORMAT_X8R8G8B8: // FIXME: Don't touch alpha? |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1635 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1636 | Pointer<Byte> buffer = cBuffer + x * 4; |
| 1637 | Short4 value = *Pointer<Short4>(buffer); |
| 1638 | |
| 1639 | if((state.targetFormat[index] == FORMAT_A8R8G8B8 && bgraWriteMask != 0x0000000F) || |
| 1640 | ((state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x00000007) && |
| 1641 | (state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 1642 | { |
| 1643 | Short4 masked = value; |
| 1644 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 1645 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 1646 | c01 |= masked; |
| 1647 | } |
| 1648 | |
| 1649 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 1650 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 1651 | c01 |= value; |
| 1652 | *Pointer<Short4>(buffer) = c01; |
| 1653 | |
| 1654 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 1655 | value = *Pointer<Short4>(buffer); |
| 1656 | |
| 1657 | if((state.targetFormat[index] == FORMAT_A8R8G8B8 && bgraWriteMask != 0x0000000F) || |
| 1658 | ((state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x00000007) && |
| 1659 | (state.targetFormat[index] == FORMAT_X8R8G8B8 && bgraWriteMask != 0x0000000F))) // FIXME: Need for masking when XRGB && Fh? |
| 1660 | { |
| 1661 | Short4 masked = value; |
| 1662 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[bgraWriteMask][0])); |
| 1663 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[bgraWriteMask][0])); |
| 1664 | c23 |= masked; |
| 1665 | } |
| 1666 | |
| 1667 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 1668 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 1669 | c23 |= value; |
| 1670 | *Pointer<Short4>(buffer) = c23; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1671 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1672 | break; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1673 | case FORMAT_A8B8G8R8: |
| 1674 | case FORMAT_X8B8G8R8: // FIXME: Don't touch alpha? |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1675 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1676 | Pointer<Byte> buffer = cBuffer + x * 4; |
| 1677 | Short4 value = *Pointer<Short4>(buffer); |
| 1678 | |
| 1679 | if((state.targetFormat[index] == FORMAT_A8B8G8R8 && rgbaWriteMask != 0x0000000F) || |
| 1680 | ((state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x00000007) && |
| 1681 | (state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x0000000F))) // FIXME: Need for masking when XBGR && Fh? |
| 1682 | { |
| 1683 | Short4 masked = value; |
| 1684 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[rgbaWriteMask][0])); |
| 1685 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[rgbaWriteMask][0])); |
| 1686 | c01 |= masked; |
| 1687 | } |
| 1688 | |
| 1689 | c01 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 1690 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
| 1691 | c01 |= value; |
| 1692 | *Pointer<Short4>(buffer) = c01; |
| 1693 | |
| 1694 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 1695 | value = *Pointer<Short4>(buffer); |
| 1696 | |
| 1697 | if((state.targetFormat[index] == FORMAT_A8B8G8R8 && rgbaWriteMask != 0x0000000F) || |
| 1698 | ((state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x00000007) && |
| 1699 | (state.targetFormat[index] == FORMAT_X8B8G8R8 && rgbaWriteMask != 0x0000000F))) // FIXME: Need for masking when XBGR && Fh? |
| 1700 | { |
| 1701 | Short4 masked = value; |
| 1702 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q[rgbaWriteMask][0])); |
| 1703 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q[rgbaWriteMask][0])); |
| 1704 | c23 |= masked; |
| 1705 | } |
| 1706 | |
| 1707 | c23 &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 1708 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
| 1709 | c23 |= value; |
| 1710 | *Pointer<Short4>(buffer) = c23; |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1711 | } |
Nicolas Capens | 0c42ee1 | 2015-03-28 18:54:07 -0400 | [diff] [blame] | 1712 | break; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1713 | case FORMAT_A8: |
| 1714 | if(rgbaWriteMask & 0x00000008) |
| 1715 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1716 | Pointer<Byte> buffer = cBuffer + 1 * x; |
| 1717 | Short4 value; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1718 | Insert(value, *Pointer<Short>(buffer), 0); |
| 1719 | Int pitch = *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 1720 | Insert(value, *Pointer<Short>(buffer + pitch), 1); |
| 1721 | value = UnpackLow(As<Byte8>(value), As<Byte8>(value)); |
| 1722 | |
| 1723 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskB4Q) + 8 * xMask); |
| 1724 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskB4Q) + 8 * xMask); |
| 1725 | current.w |= value; |
| 1726 | |
| 1727 | *Pointer<Short>(buffer) = Extract(current.w, 0); |
| 1728 | *Pointer<Short>(buffer + pitch) = Extract(current.w, 1); |
| 1729 | } |
| 1730 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1731 | case FORMAT_G16R16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1732 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1733 | Pointer<Byte> buffer = cBuffer + 4 * x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1734 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1735 | Short4 value = *Pointer<Short4>(buffer); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1736 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1737 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1738 | { |
| 1739 | Short4 masked = value; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1740 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0])); |
| 1741 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1742 | current.x |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1743 | } |
| 1744 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1745 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD01Q) + xMask * 8); |
| 1746 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD01Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1747 | current.x |= value; |
| 1748 | *Pointer<Short4>(buffer) = current.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1749 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1750 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1751 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1752 | value = *Pointer<Short4>(buffer); |
| 1753 | |
| 1754 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1755 | { |
| 1756 | Short4 masked = value; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1757 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW01Q[rgbaWriteMask & 0x3][0])); |
| 1758 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW01Q[rgbaWriteMask & 0x3][0])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1759 | current.y |= masked; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1760 | } |
| 1761 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1762 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskD23Q) + xMask * 8); |
| 1763 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskD23Q) + xMask * 8); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1764 | current.y |= value; |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1765 | *Pointer<Short4>(buffer) = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1766 | } |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1767 | break; |
| 1768 | case FORMAT_A16B16G16R16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1769 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1770 | Pointer<Byte> buffer = cBuffer + 8 * x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1771 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1772 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1773 | Short4 value = *Pointer<Short4>(buffer); |
| 1774 | |
| 1775 | if(rgbaWriteMask != 0x0000000F) |
| 1776 | { |
| 1777 | Short4 masked = value; |
| 1778 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
| 1779 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
| 1780 | current.x |= masked; |
| 1781 | } |
| 1782 | |
| 1783 | current.x &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ0Q) + xMask * 8); |
| 1784 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ0Q) + xMask * 8); |
| 1785 | current.x |= value; |
| 1786 | *Pointer<Short4>(buffer) = current.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1787 | } |
| 1788 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1789 | { |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1790 | Short4 value = *Pointer<Short4>(buffer + 8); |
| 1791 | |
| 1792 | if(rgbaWriteMask != 0x0000000F) |
| 1793 | { |
| 1794 | Short4 masked = value; |
| 1795 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
| 1796 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
| 1797 | current.y |= masked; |
| 1798 | } |
| 1799 | |
| 1800 | current.y &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ1Q) + xMask * 8); |
| 1801 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ1Q) + xMask * 8); |
| 1802 | current.y |= value; |
| 1803 | *Pointer<Short4>(buffer + 8) = current.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1804 | } |
| 1805 | |
Nicolas Capens | d5f0a6c | 2015-05-26 00:18:01 -0400 | [diff] [blame] | 1806 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 1807 | |
| 1808 | { |
| 1809 | Short4 value = *Pointer<Short4>(buffer); |
| 1810 | |
| 1811 | if(rgbaWriteMask != 0x0000000F) |
| 1812 | { |
| 1813 | Short4 masked = value; |
| 1814 | current.z &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
| 1815 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
| 1816 | current.z |= masked; |
| 1817 | } |
| 1818 | |
| 1819 | current.z &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ2Q) + xMask * 8); |
| 1820 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ2Q) + xMask * 8); |
| 1821 | current.z |= value; |
| 1822 | *Pointer<Short4>(buffer) = current.z; |
| 1823 | } |
| 1824 | |
| 1825 | { |
| 1826 | Short4 value = *Pointer<Short4>(buffer + 8); |
| 1827 | |
| 1828 | if(rgbaWriteMask != 0x0000000F) |
| 1829 | { |
| 1830 | Short4 masked = value; |
| 1831 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskW4Q[rgbaWriteMask][0])); |
| 1832 | masked &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskW4Q[rgbaWriteMask][0])); |
| 1833 | current.w |= masked; |
| 1834 | } |
| 1835 | |
| 1836 | current.w &= *Pointer<Short4>(r.constants + OFFSET(Constants,maskQ3Q) + xMask * 8); |
| 1837 | value &= *Pointer<Short4>(r.constants + OFFSET(Constants,invMaskQ3Q) + xMask * 8); |
| 1838 | current.w |= value; |
| 1839 | *Pointer<Short4>(buffer + 8) = current.w; |
| 1840 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1841 | } |
| 1842 | break; |
| 1843 | default: |
| 1844 | ASSERT(false); |
| 1845 | } |
| 1846 | } |
| 1847 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1848 | 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] | 1849 | { |
| 1850 | switch(blendFactorActive) |
| 1851 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1852 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1853 | // Optimized |
| 1854 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1855 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1856 | // Optimized |
| 1857 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1858 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1859 | blendFactor.x = oC.x; |
| 1860 | blendFactor.y = oC.y; |
| 1861 | blendFactor.z = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1862 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1863 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1864 | blendFactor.x = Float4(1.0f) - oC.x; |
| 1865 | blendFactor.y = Float4(1.0f) - oC.y; |
| 1866 | blendFactor.z = Float4(1.0f) - oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1867 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1868 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1869 | blendFactor.x = pixel.x; |
| 1870 | blendFactor.y = pixel.y; |
| 1871 | blendFactor.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1872 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1873 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1874 | blendFactor.x = Float4(1.0f) - pixel.x; |
| 1875 | blendFactor.y = Float4(1.0f) - pixel.y; |
| 1876 | blendFactor.z = Float4(1.0f) - pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1877 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1878 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1879 | blendFactor.x = oC.w; |
| 1880 | blendFactor.y = oC.w; |
| 1881 | blendFactor.z = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1882 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1883 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1884 | blendFactor.x = Float4(1.0f) - oC.w; |
| 1885 | blendFactor.y = Float4(1.0f) - oC.w; |
| 1886 | blendFactor.z = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1887 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1888 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1889 | blendFactor.x = pixel.w; |
| 1890 | blendFactor.y = pixel.w; |
| 1891 | blendFactor.z = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1892 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1893 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1894 | blendFactor.x = Float4(1.0f) - pixel.w; |
| 1895 | blendFactor.y = Float4(1.0f) - pixel.w; |
| 1896 | blendFactor.z = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1897 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1898 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1899 | blendFactor.x = Float4(1.0f) - pixel.w; |
| 1900 | blendFactor.x = Min(blendFactor.x, oC.w); |
| 1901 | blendFactor.y = blendFactor.x; |
| 1902 | blendFactor.z = blendFactor.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1903 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1904 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1905 | blendFactor.x = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[0])); |
| 1906 | blendFactor.y = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[1])); |
| 1907 | blendFactor.z = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1908 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1909 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1910 | blendFactor.x = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[0])); |
| 1911 | blendFactor.y = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[1])); |
| 1912 | blendFactor.z = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[2])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1913 | break; |
| 1914 | default: |
| 1915 | ASSERT(false); |
| 1916 | } |
| 1917 | } |
| 1918 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1919 | 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] | 1920 | { |
| 1921 | switch(blendFactorAlphaActive) |
| 1922 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1923 | case BLEND_ZERO: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1924 | // Optimized |
| 1925 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1926 | case BLEND_ONE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1927 | // Optimized |
| 1928 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1929 | case BLEND_SOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1930 | blendFactor.w = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1931 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1932 | case BLEND_INVSOURCE: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1933 | blendFactor.w = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1934 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1935 | case BLEND_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1936 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1937 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1938 | case BLEND_INVDEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1939 | blendFactor.w = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1940 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1941 | case BLEND_SOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1942 | blendFactor.w = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1943 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1944 | case BLEND_INVSOURCEALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1945 | blendFactor.w = Float4(1.0f) - oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1946 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1947 | case BLEND_DESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1948 | blendFactor.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1949 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1950 | case BLEND_INVDESTALPHA: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1951 | blendFactor.w = Float4(1.0f) - pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1952 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1953 | case BLEND_SRCALPHASAT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1954 | blendFactor.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1955 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1956 | case BLEND_CONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1957 | blendFactor.w = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.blendConstant4F[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1958 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1959 | case BLEND_INVCONSTANT: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1960 | blendFactor.w = *Pointer<Float4>(r.data + OFFSET(DrawData,factor.invBlendConstant4F[3])); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1961 | break; |
| 1962 | default: |
| 1963 | ASSERT(false); |
| 1964 | } |
| 1965 | } |
| 1966 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1967 | 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] | 1968 | { |
| 1969 | if(!state.alphaBlendActive) |
| 1970 | { |
| 1971 | return; |
| 1972 | } |
| 1973 | |
| 1974 | Pointer<Byte> buffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1975 | Vector4f pixel; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1976 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 1977 | Vector4s color; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1978 | Short4 c01; |
| 1979 | Short4 c23; |
| 1980 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1981 | switch(state.targetFormat[index]) |
| 1982 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1983 | case FORMAT_R32F: |
| 1984 | buffer = cBuffer; |
| 1985 | // FIXME: movlps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1986 | pixel.x.x = *Pointer<Float>(buffer + 4 * x + 0); |
| 1987 | pixel.x.y = *Pointer<Float>(buffer + 4 * x + 4); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1988 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 1989 | // FIXME: movhps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1990 | pixel.x.z = *Pointer<Float>(buffer + 4 * x + 0); |
| 1991 | pixel.x.w = *Pointer<Float>(buffer + 4 * x + 4); |
| 1992 | pixel.y = Float4(1.0f); |
| 1993 | pixel.z = Float4(1.0f); |
| 1994 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1995 | break; |
| 1996 | case FORMAT_G32R32F: |
| 1997 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1998 | pixel.x = *Pointer<Float4>(buffer + 8 * x, 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1999 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2000 | pixel.y = *Pointer<Float4>(buffer + 8 * x, 16); |
| 2001 | pixel.z = pixel.x; |
| 2002 | pixel.x = ShuffleLowHigh(pixel.x, pixel.y, 0x88); |
| 2003 | pixel.z = ShuffleLowHigh(pixel.z, pixel.y, 0xDD); |
| 2004 | pixel.y = pixel.z; |
| 2005 | pixel.z = Float4(1.0f); |
| 2006 | pixel.w = Float4(1.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2007 | break; |
| 2008 | case FORMAT_A32B32G32R32F: |
| 2009 | buffer = cBuffer; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2010 | pixel.x = *Pointer<Float4>(buffer + 16 * x, 16); |
| 2011 | pixel.y = *Pointer<Float4>(buffer + 16 * x + 16, 16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2012 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2013 | pixel.z = *Pointer<Float4>(buffer + 16 * x, 16); |
| 2014 | pixel.w = *Pointer<Float4>(buffer + 16 * x + 16, 16); |
| 2015 | transpose4x4(pixel.x, pixel.y, pixel.z, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2016 | break; |
| 2017 | default: |
| 2018 | ASSERT(false); |
| 2019 | } |
| 2020 | |
| 2021 | if(postBlendSRGB && state.writeSRGB) |
| 2022 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2023 | sRGBtoLinear(pixel.x); |
| 2024 | sRGBtoLinear(pixel.y); |
| 2025 | sRGBtoLinear(pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | // Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2029 | Vector4f sourceFactor; |
| 2030 | Vector4f destFactor; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2031 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2032 | blendFactor(r, sourceFactor, oC, pixel, state.sourceBlendFactor); |
| 2033 | blendFactor(r, destFactor, oC, pixel, state.destBlendFactor); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2034 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2035 | if(state.sourceBlendFactor != BLEND_ONE && state.sourceBlendFactor != BLEND_ZERO) |
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 | oC.x *= sourceFactor.x; |
| 2038 | oC.y *= sourceFactor.y; |
| 2039 | oC.z *= sourceFactor.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2040 | } |
| 2041 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2042 | if(state.destBlendFactor != BLEND_ONE && state.destBlendFactor != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2043 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2044 | pixel.x *= destFactor.x; |
| 2045 | pixel.y *= destFactor.y; |
| 2046 | pixel.z *= destFactor.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | switch(state.blendOperation) |
| 2050 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2051 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2052 | oC.x += pixel.x; |
| 2053 | oC.y += pixel.y; |
| 2054 | oC.z += pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2055 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2056 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2057 | oC.x -= pixel.x; |
| 2058 | oC.y -= pixel.y; |
| 2059 | oC.z -= pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2060 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2061 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2062 | oC.x = pixel.x - oC.x; |
| 2063 | oC.y = pixel.y - oC.y; |
| 2064 | oC.z = pixel.z - oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2065 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2066 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2067 | oC.x = Min(oC.x, pixel.x); |
| 2068 | oC.y = Min(oC.y, pixel.y); |
| 2069 | oC.z = Min(oC.z, pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2070 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2071 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2072 | oC.x = Max(oC.x, pixel.x); |
| 2073 | oC.y = Max(oC.y, pixel.y); |
| 2074 | oC.z = Max(oC.z, pixel.z); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2075 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2076 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2077 | // No operation |
| 2078 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2079 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2080 | oC.x = pixel.x; |
| 2081 | oC.y = pixel.y; |
| 2082 | oC.z = pixel.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2083 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2084 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2085 | oC.x = Float4(0.0f); |
| 2086 | oC.y = Float4(0.0f); |
| 2087 | oC.z = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2088 | break; |
| 2089 | default: |
| 2090 | ASSERT(false); |
| 2091 | } |
| 2092 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2093 | blendFactorAlpha(r, sourceFactor, oC, pixel, state.sourceBlendFactorAlpha); |
| 2094 | blendFactorAlpha(r, destFactor, oC, pixel, state.destBlendFactorAlpha); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2095 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2096 | if(state.sourceBlendFactorAlpha != BLEND_ONE && state.sourceBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2097 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2098 | oC.w *= sourceFactor.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2099 | } |
| 2100 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2101 | if(state.destBlendFactorAlpha != BLEND_ONE && state.destBlendFactorAlpha != BLEND_ZERO) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2102 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2103 | pixel.w *= destFactor.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | switch(state.blendOperationAlpha) |
| 2107 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2108 | case BLENDOP_ADD: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2109 | oC.w += pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2110 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2111 | case BLENDOP_SUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2112 | oC.w -= pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2113 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2114 | case BLENDOP_INVSUB: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2115 | pixel.w -= oC.w; |
| 2116 | oC.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2117 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2118 | case BLENDOP_MIN: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2119 | oC.w = Min(oC.w, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2120 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2121 | case BLENDOP_MAX: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2122 | oC.w = Max(oC.w, pixel.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2123 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2124 | case BLENDOP_SOURCE: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2125 | // No operation |
| 2126 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2127 | case BLENDOP_DEST: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2128 | oC.w = pixel.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2129 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2130 | case BLENDOP_NULL: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2131 | oC.w = Float4(0.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2132 | break; |
| 2133 | default: |
| 2134 | ASSERT(false); |
| 2135 | } |
| 2136 | } |
| 2137 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2138 | 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] | 2139 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2140 | switch(state.targetFormat[index]) |
| 2141 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2142 | case FORMAT_R32F: |
| 2143 | break; |
| 2144 | case FORMAT_G32R32F: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2145 | oC.z = oC.x; |
| 2146 | oC.x = UnpackLow(oC.x, oC.y); |
| 2147 | oC.z = UnpackHigh(oC.z, oC.y); |
| 2148 | oC.y = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2149 | break; |
| 2150 | case FORMAT_A32B32G32R32F: |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2151 | transpose4x4(oC.x, oC.y, oC.z, oC.w); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2152 | break; |
| 2153 | default: |
| 2154 | ASSERT(false); |
| 2155 | } |
| 2156 | |
| 2157 | int rgbaWriteMask = state.colorWriteActive(index); |
| 2158 | |
| 2159 | Int xMask; // Combination of all masks |
| 2160 | |
| 2161 | if(state.depthTestActive) |
| 2162 | { |
| 2163 | xMask = zMask; |
| 2164 | } |
| 2165 | else |
| 2166 | { |
| 2167 | xMask = cMask; |
| 2168 | } |
| 2169 | |
| 2170 | if(state.stencilActive) |
| 2171 | { |
| 2172 | xMask &= sMask; |
| 2173 | } |
| 2174 | |
| 2175 | Pointer<Byte> buffer; |
| 2176 | Float4 value; |
| 2177 | |
| 2178 | switch(state.targetFormat[index]) |
| 2179 | { |
| 2180 | case FORMAT_R32F: |
| 2181 | if(rgbaWriteMask & 0x00000001) |
| 2182 | { |
| 2183 | buffer = cBuffer + 4 * x; |
| 2184 | |
| 2185 | // FIXME: movlps |
| 2186 | value.x = *Pointer<Float>(buffer + 0); |
| 2187 | value.y = *Pointer<Float>(buffer + 4); |
| 2188 | |
| 2189 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2190 | |
| 2191 | // FIXME: movhps |
| 2192 | value.z = *Pointer<Float>(buffer + 0); |
| 2193 | value.w = *Pointer<Float>(buffer + 4); |
| 2194 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2195 | 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] | 2196 | 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] | 2197 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2198 | |
| 2199 | // FIXME: movhps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2200 | *Pointer<Float>(buffer + 0) = oC.x.z; |
| 2201 | *Pointer<Float>(buffer + 4) = oC.x.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2202 | |
| 2203 | buffer -= *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2204 | |
| 2205 | // FIXME: movlps |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2206 | *Pointer<Float>(buffer + 0) = oC.x.x; |
| 2207 | *Pointer<Float>(buffer + 4) = oC.x.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2208 | } |
| 2209 | break; |
| 2210 | case FORMAT_G32R32F: |
| 2211 | buffer = cBuffer + 8 * x; |
| 2212 | |
| 2213 | value = *Pointer<Float4>(buffer); |
| 2214 | |
| 2215 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 2216 | { |
| 2217 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2218 | 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] | 2219 | 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] | 2220 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2221 | } |
| 2222 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2223 | 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] | 2224 | 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] | 2225 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
| 2226 | *Pointer<Float4>(buffer) = oC.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2227 | |
| 2228 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2229 | |
| 2230 | value = *Pointer<Float4>(buffer); |
| 2231 | |
| 2232 | if((rgbaWriteMask & 0x00000003) != 0x00000003) |
| 2233 | { |
| 2234 | Float4 masked; |
| 2235 | |
| 2236 | masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2237 | 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] | 2238 | 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] | 2239 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2240 | } |
| 2241 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2242 | 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] | 2243 | 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] | 2244 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(value)); |
| 2245 | *Pointer<Float4>(buffer) = oC.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2246 | break; |
| 2247 | case FORMAT_A32B32G32R32F: |
| 2248 | buffer = cBuffer + 16 * x; |
| 2249 | |
| 2250 | { |
| 2251 | value = *Pointer<Float4>(buffer, 16); |
| 2252 | |
| 2253 | if(rgbaWriteMask != 0x0000000F) |
| 2254 | { |
| 2255 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2256 | 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] | 2257 | 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] | 2258 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2259 | } |
| 2260 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2261 | 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] | 2262 | 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] | 2263 | oC.x = As<Float4>(As<Int4>(oC.x) | As<Int4>(value)); |
| 2264 | *Pointer<Float4>(buffer, 16) = oC.x; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | { |
| 2268 | value = *Pointer<Float4>(buffer + 16, 16); |
| 2269 | |
| 2270 | if(rgbaWriteMask != 0x0000000F) |
| 2271 | { |
| 2272 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2273 | 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] | 2274 | 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] | 2275 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2276 | } |
| 2277 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2278 | 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] | 2279 | 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] | 2280 | oC.y = As<Float4>(As<Int4>(oC.y) | As<Int4>(value)); |
| 2281 | *Pointer<Float4>(buffer + 16, 16) = oC.y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | buffer += *Pointer<Int>(r.data + OFFSET(DrawData,colorPitchB[index])); |
| 2285 | |
| 2286 | { |
| 2287 | value = *Pointer<Float4>(buffer, 16); |
| 2288 | |
| 2289 | if(rgbaWriteMask != 0x0000000F) |
| 2290 | { |
| 2291 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2292 | 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] | 2293 | 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] | 2294 | oC.z = As<Float4>(As<Int4>(oC.z) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2295 | } |
| 2296 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2297 | 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] | 2298 | 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] | 2299 | oC.z = As<Float4>(As<Int4>(oC.z) | As<Int4>(value)); |
| 2300 | *Pointer<Float4>(buffer, 16) = oC.z; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | { |
| 2304 | value = *Pointer<Float4>(buffer + 16, 16); |
| 2305 | |
| 2306 | if(rgbaWriteMask != 0x0000000F) |
| 2307 | { |
| 2308 | Float4 masked = value; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2309 | 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] | 2310 | 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] | 2311 | oC.w = As<Float4>(As<Int4>(oC.w) | As<Int4>(masked)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2312 | } |
| 2313 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2314 | 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] | 2315 | 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] | 2316 | oC.w = As<Float4>(As<Int4>(oC.w) | As<Int4>(value)); |
| 2317 | *Pointer<Float4>(buffer + 16, 16) = oC.w; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2318 | } |
| 2319 | break; |
| 2320 | default: |
| 2321 | ASSERT(false); |
| 2322 | } |
| 2323 | } |
| 2324 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2325 | UShort4 PixelRoutine::convertFixed16(Float4 &cf, bool saturate) |
| 2326 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2327 | return UShort4(cf * Float4(0xFFFF), saturate); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2328 | } |
| 2329 | |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 2330 | void PixelRoutine::sRGBtoLinear16_12_16(Registers &r, Vector4s &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2331 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2332 | c.x = As<UShort4>(c.x) >> 4; |
| 2333 | c.y = As<UShort4>(c.y) >> 4; |
| 2334 | c.z = As<UShort4>(c.z) >> 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2335 | |
| 2336 | sRGBtoLinear12_16(r, c); |
| 2337 | } |
| 2338 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2339 | void PixelRoutine::sRGBtoLinear12_16(Registers &r, Vector4s &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2340 | { |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 2341 | Pointer<Byte> LUT = r.constants + OFFSET(Constants,sRGBtoLinear12_16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2342 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2343 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); |
| 2344 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); |
| 2345 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); |
| 2346 | 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] | 2347 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2348 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 0))), 0); |
| 2349 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 1))), 1); |
| 2350 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 2))), 2); |
| 2351 | 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] | 2352 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2353 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 0))), 0); |
| 2354 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 1))), 1); |
| 2355 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 2))), 2); |
| 2356 | 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] | 2357 | } |
| 2358 | |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 2359 | void PixelRoutine::linearToSRGB16_12_16(Registers &r, Vector4s &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2360 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2361 | c.x = As<UShort4>(c.x) >> 4; |
| 2362 | c.y = As<UShort4>(c.y) >> 4; |
| 2363 | c.z = As<UShort4>(c.z) >> 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2364 | |
| 2365 | linearToSRGB12_16(r, c); |
| 2366 | } |
| 2367 | |
Alexis Hetu | 9651718 | 2015-04-15 10:30:23 -0400 | [diff] [blame] | 2368 | void PixelRoutine::linearToSRGB12_16(Registers &r, Vector4s &c) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2369 | { |
Nicolas Capens | e1a50af | 2015-05-13 16:48:18 -0400 | [diff] [blame] | 2370 | Pointer<Byte> LUT = r.constants + OFFSET(Constants,linearToSRGB12_16); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2371 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2372 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); |
| 2373 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); |
| 2374 | c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); |
| 2375 | 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] | 2376 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2377 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 0))), 0); |
| 2378 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 1))), 1); |
| 2379 | c.y = Insert(c.y, *Pointer<Short>(LUT + 2 * Int(Extract(c.y, 2))), 2); |
| 2380 | 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] | 2381 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2382 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 0))), 0); |
| 2383 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 1))), 1); |
| 2384 | c.z = Insert(c.z, *Pointer<Short>(LUT + 2 * Int(Extract(c.z, 2))), 2); |
| 2385 | 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] | 2386 | } |
| 2387 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2388 | Float4 PixelRoutine::sRGBtoLinear(const Float4 &x) // Approximates x^2.2 |
| 2389 | { |
| 2390 | Float4 linear = x * x; |
| 2391 | linear = linear * Float4(0.73f) + linear * x * Float4(0.27f); |
| 2392 | |
| 2393 | return Min(Max(linear, Float4(0.0f)), Float4(1.0f)); |
| 2394 | } |
| 2395 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2396 | bool PixelRoutine::colorUsed() |
| 2397 | { |
| 2398 | return state.colorWriteMask || state.alphaTestActive() || state.shaderContainsKill; |
| 2399 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2400 | } |