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