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