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 "Renderer.hpp" |
| 16 | |
| 17 | #include "Clipper.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 18 | #include "Surface.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 19 | #include "Primitive.hpp" |
| 20 | #include "Polygon.hpp" |
Nicolas Capens | 708c24b | 2017-10-26 13:07:10 -0400 | [diff] [blame] | 21 | #include "Main/FrameBuffer.hpp" |
| 22 | #include "Main/SwiftConfig.hpp" |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 23 | #include "Reactor/Reactor.hpp" |
Nicolas Capens | 708c24b | 2017-10-26 13:07:10 -0400 | [diff] [blame] | 24 | #include "Shader/Constants.hpp" |
| 25 | #include "Common/MutexLock.hpp" |
| 26 | #include "Common/CPUID.hpp" |
| 27 | #include "Common/Memory.hpp" |
| 28 | #include "Common/Resource.hpp" |
| 29 | #include "Common/Half.hpp" |
| 30 | #include "Common/Math.hpp" |
| 31 | #include "Common/Timer.hpp" |
| 32 | #include "Common/Debug.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 33 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 34 | #undef max |
| 35 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 36 | bool disableServer = true; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 37 | |
| 38 | #ifndef NDEBUG |
| 39 | unsigned int minPrimitives = 1; |
| 40 | unsigned int maxPrimitives = 1 << 21; |
| 41 | #endif |
| 42 | |
| 43 | namespace sw |
| 44 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 45 | extern bool halfIntegerCoordinates; // Pixel centers are not at integer coordinates |
| 46 | extern bool symmetricNormalizedDepth; // [-1, 1] instead of [0, 1] |
| 47 | extern bool booleanFaceRegister; |
| 48 | extern bool fullPixelPositionRegister; |
Nicolas Capens | 44ffb65 | 2015-08-04 16:11:24 -0400 | [diff] [blame] | 49 | extern bool leadingVertexFirst; // Flat shading uses first vertex, else last |
| 50 | extern bool secondaryColor; // Specular lighting is applied after texturing |
Alexis Hetu | 56f256e | 2017-07-21 11:41:13 -0400 | [diff] [blame] | 51 | extern bool colorsDefaultToZero; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 52 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 53 | extern bool forceWindowed; |
| 54 | extern bool complementaryDepthBuffer; |
| 55 | extern bool postBlendSRGB; |
| 56 | extern bool exactColorRounding; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 57 | extern TransparencyAntialiasing transparencyAntialiasing; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 58 | extern bool forceClearRegisters; |
| 59 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 60 | extern bool precacheVertex; |
| 61 | extern bool precacheSetup; |
| 62 | extern bool precachePixel; |
| 63 | |
Alexis Hetu | f2520e1 | 2017-10-26 14:57:17 -0400 | [diff] [blame] | 64 | static const int batchSize = 128; |
| 65 | AtomicInt threadCount(1); |
Alexis Hetu | 8beb240 | 2017-09-27 10:31:28 -0400 | [diff] [blame] | 66 | AtomicInt Renderer::unitCount(1); |
| 67 | AtomicInt Renderer::clusterCount(1); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 68 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 69 | TranscendentalPrecision logPrecision = ACCURATE; |
| 70 | TranscendentalPrecision expPrecision = ACCURATE; |
| 71 | TranscendentalPrecision rcpPrecision = ACCURATE; |
| 72 | TranscendentalPrecision rsqPrecision = ACCURATE; |
| 73 | bool perspectiveCorrection = true; |
| 74 | |
Alexis Hetu | 9e22c54 | 2018-07-30 15:09:01 -0400 | [diff] [blame] | 75 | static void setGlobalRenderingSettings(Conventions conventions, bool exactColorRounding) |
| 76 | { |
| 77 | static bool initialized = false; |
| 78 | |
| 79 | if(!initialized) |
| 80 | { |
| 81 | sw::halfIntegerCoordinates = conventions.halfIntegerCoordinates; |
| 82 | sw::symmetricNormalizedDepth = conventions.symmetricNormalizedDepth; |
| 83 | sw::booleanFaceRegister = conventions.booleanFaceRegister; |
| 84 | sw::fullPixelPositionRegister = conventions.fullPixelPositionRegister; |
| 85 | sw::leadingVertexFirst = conventions.leadingVertexFirst; |
| 86 | sw::secondaryColor = conventions.secondaryColor; |
| 87 | sw::colorsDefaultToZero = conventions.colorsDefaultToZero; |
| 88 | sw::exactColorRounding = exactColorRounding; |
| 89 | initialized = true; |
| 90 | } |
| 91 | } |
| 92 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 93 | struct Parameters |
| 94 | { |
| 95 | Renderer *renderer; |
| 96 | int threadIndex; |
| 97 | }; |
| 98 | |
Alexis Hetu | 3fc6893 | 2018-11-14 10:54:53 -0500 | [diff] [blame] | 99 | Query::Query(Type type) : building(false), data(0), type(type), reference(1) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | void Query::addRef() |
| 104 | { |
| 105 | ++reference; // Atomic |
| 106 | } |
| 107 | |
| 108 | void Query::release() |
| 109 | { |
| 110 | int ref = reference--; // Atomic |
| 111 | |
| 112 | ASSERT(ref >= 0); |
| 113 | |
| 114 | if(ref == 0) |
| 115 | { |
| 116 | delete this; |
| 117 | } |
| 118 | } |
| 119 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 120 | DrawCall::DrawCall() |
| 121 | { |
| 122 | queries = 0; |
| 123 | |
Alexis Hetu | 04c967a | 2015-07-08 15:56:17 -0400 | [diff] [blame] | 124 | vsDirtyConstF = VERTEX_UNIFORM_VECTORS + 1; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 125 | vsDirtyConstI = 16; |
| 126 | vsDirtyConstB = 16; |
| 127 | |
Alexis Hetu | 04c967a | 2015-07-08 15:56:17 -0400 | [diff] [blame] | 128 | psDirtyConstF = FRAGMENT_UNIFORM_VECTORS; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 129 | psDirtyConstI = 16; |
| 130 | psDirtyConstB = 16; |
| 131 | |
| 132 | references = -1; |
| 133 | |
| 134 | data = (DrawData*)allocate(sizeof(DrawData)); |
| 135 | data->constants = &constants; |
| 136 | } |
| 137 | |
| 138 | DrawCall::~DrawCall() |
| 139 | { |
| 140 | delete queries; |
| 141 | |
| 142 | deallocate(data); |
| 143 | } |
| 144 | |
Nicolas Capens | 485f92c | 2016-01-01 23:17:42 -0500 | [diff] [blame] | 145 | Renderer::Renderer(Context *context, Conventions conventions, bool exactColorRounding) : VertexProcessor(context), PixelProcessor(context), SetupProcessor(context), context(context), viewport() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 146 | { |
Alexis Hetu | 9e22c54 | 2018-07-30 15:09:01 -0400 | [diff] [blame] | 147 | setGlobalRenderingSettings(conventions, exactColorRounding); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 148 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 149 | setRenderTarget(0, 0); |
Nicolas Capens | 00bfa18 | 2016-05-20 21:30:54 -0700 | [diff] [blame] | 150 | clipper = new Clipper(symmetricNormalizedDepth); |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 151 | blitter = new Blitter; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 152 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 153 | updateViewMatrix = true; |
| 154 | updateBaseMatrix = true; |
| 155 | updateProjectionMatrix = true; |
| 156 | updateClipPlanes = true; |
| 157 | |
| 158 | #if PERF_HUD |
| 159 | resetTimers(); |
| 160 | #endif |
| 161 | |
| 162 | for(int i = 0; i < 16; i++) |
| 163 | { |
| 164 | vertexTask[i] = 0; |
| 165 | |
| 166 | worker[i] = 0; |
| 167 | resume[i] = 0; |
| 168 | suspend[i] = 0; |
| 169 | } |
| 170 | |
| 171 | threadsAwake = 0; |
| 172 | resumeApp = new Event(); |
| 173 | |
| 174 | currentDraw = 0; |
| 175 | nextDraw = 0; |
| 176 | |
| 177 | qHead = 0; |
| 178 | qSize = 0; |
| 179 | |
| 180 | for(int i = 0; i < 16; i++) |
| 181 | { |
| 182 | triangleBatch[i] = 0; |
| 183 | primitiveBatch[i] = 0; |
| 184 | } |
| 185 | |
| 186 | for(int draw = 0; draw < DRAW_COUNT; draw++) |
| 187 | { |
| 188 | drawCall[draw] = new DrawCall(); |
| 189 | drawList[draw] = drawCall[draw]; |
| 190 | } |
| 191 | |
| 192 | for(int unit = 0; unit < 16; unit++) |
| 193 | { |
| 194 | primitiveProgress[unit].init(); |
| 195 | } |
| 196 | |
| 197 | for(int cluster = 0; cluster < 16; cluster++) |
| 198 | { |
| 199 | pixelProgress[cluster].init(); |
| 200 | } |
| 201 | |
| 202 | clipFlags = 0; |
| 203 | |
| 204 | swiftConfig = new SwiftConfig(disableServer); |
| 205 | updateConfiguration(true); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 206 | |
| 207 | sync = new Resource(0); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | Renderer::~Renderer() |
| 211 | { |
Ben Clayton | 3fc635a | 2019-02-12 11:24:29 +0000 | [diff] [blame] | 212 | sync->lock(EXCLUSIVE); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 213 | sync->destruct(); |
Ben Clayton | 3fc635a | 2019-02-12 11:24:29 +0000 | [diff] [blame] | 214 | terminateThreads(); |
| 215 | sync->unlock(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 216 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 217 | delete clipper; |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 218 | clipper = nullptr; |
| 219 | |
| 220 | delete blitter; |
| 221 | blitter = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 222 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 223 | delete resumeApp; |
Ben Clayton | 3fc635a | 2019-02-12 11:24:29 +0000 | [diff] [blame] | 224 | resumeApp = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 225 | |
| 226 | for(int draw = 0; draw < DRAW_COUNT; draw++) |
| 227 | { |
| 228 | delete drawCall[draw]; |
Ben Clayton | 3fc635a | 2019-02-12 11:24:29 +0000 | [diff] [blame] | 229 | drawCall[draw] = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 230 | } |
| 231 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 232 | delete swiftConfig; |
Ben Clayton | 3fc635a | 2019-02-12 11:24:29 +0000 | [diff] [blame] | 233 | swiftConfig = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Alexis Hetu | 81519cf | 2016-09-08 13:59:50 -0400 | [diff] [blame] | 236 | // This object has to be mem aligned |
Nicolas Capens | edba65b | 2016-10-20 14:57:26 -0400 | [diff] [blame] | 237 | void* Renderer::operator new(size_t size) |
| 238 | { |
| 239 | ASSERT(size == sizeof(Renderer)); // This operator can't be called from a derived class |
| 240 | return sw::allocate(sizeof(Renderer), 16); |
| 241 | } |
| 242 | |
| 243 | void Renderer::operator delete(void * mem) |
| 244 | { |
| 245 | sw::deallocate(mem); |
Alexis Hetu | 81519cf | 2016-09-08 13:59:50 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 248 | void Renderer::draw(DrawType drawType, unsigned int indexOffset, unsigned int count, bool update) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 249 | { |
| 250 | #ifndef NDEBUG |
| 251 | if(count < minPrimitives || count > maxPrimitives) |
| 252 | { |
| 253 | return; |
| 254 | } |
| 255 | #endif |
| 256 | |
| 257 | context->drawType = drawType; |
| 258 | |
| 259 | updateConfiguration(); |
| 260 | updateClipper(); |
| 261 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 262 | int ss = context->getSuperSampleCount(); |
| 263 | int ms = context->getMultiSampleCount(); |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 264 | bool requiresSync = false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 265 | |
| 266 | for(int q = 0; q < ss; q++) |
| 267 | { |
Nicolas Capens | 5d96188 | 2016-01-01 23:18:14 -0500 | [diff] [blame] | 268 | unsigned int oldMultiSampleMask = context->multiSampleMask; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 269 | context->multiSampleMask = (context->sampleMask >> (ms * q)) & ((unsigned)0xFFFFFFFF >> (32 - ms)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 270 | |
| 271 | if(!context->multiSampleMask) |
| 272 | { |
| 273 | continue; |
| 274 | } |
| 275 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 276 | sync->lock(sw::PRIVATE); |
| 277 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 278 | if(update || oldMultiSampleMask != context->multiSampleMask) |
| 279 | { |
Alexis Hetu | a62a0ca | 2016-04-20 15:29:51 -0400 | [diff] [blame] | 280 | vertexState = VertexProcessor::update(drawType); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 281 | setupState = SetupProcessor::update(); |
| 282 | pixelState = PixelProcessor::update(); |
| 283 | |
| 284 | vertexRoutine = VertexProcessor::routine(vertexState); |
| 285 | setupRoutine = SetupProcessor::routine(setupState); |
| 286 | pixelRoutine = PixelProcessor::routine(pixelState); |
| 287 | } |
| 288 | |
| 289 | int batch = batchSize / ms; |
| 290 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 291 | int (Renderer::*setupPrimitives)(int batch, int count); |
Nicolas Capens | 235781d | 2015-01-27 01:46:53 -0500 | [diff] [blame] | 292 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 293 | if(context->isDrawTriangle()) |
| 294 | { |
| 295 | switch(context->fillMode) |
| 296 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 297 | case FILL_SOLID: |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 298 | setupPrimitives = &Renderer::setupSolidTriangles; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 299 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 300 | case FILL_WIREFRAME: |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 301 | setupPrimitives = &Renderer::setupWireframeTriangle; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 302 | batch = 1; |
| 303 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 304 | case FILL_VERTEX: |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 305 | setupPrimitives = &Renderer::setupVertexTriangle; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 306 | batch = 1; |
| 307 | break; |
Alexis Hetu | 05c32b9 | 2016-06-23 11:32:07 -0400 | [diff] [blame] | 308 | default: |
| 309 | ASSERT(false); |
| 310 | return; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | else if(context->isDrawLine()) |
| 314 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 315 | setupPrimitives = &Renderer::setupLines; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 316 | } |
| 317 | else // Point draw |
| 318 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 319 | setupPrimitives = &Renderer::setupPoints; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 320 | } |
| 321 | |
Nicolas Capens | a6bc61d | 2017-12-20 11:07:45 -0500 | [diff] [blame] | 322 | DrawCall *draw = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 323 | |
| 324 | do |
| 325 | { |
| 326 | for(int i = 0; i < DRAW_COUNT; i++) |
| 327 | { |
| 328 | if(drawCall[i]->references == -1) |
| 329 | { |
| 330 | draw = drawCall[i]; |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 331 | drawList[nextDraw & DRAW_COUNT_BITS] = draw; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 332 | |
| 333 | break; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if(!draw) |
| 338 | { |
| 339 | resumeApp->wait(); |
| 340 | } |
| 341 | } |
| 342 | while(!draw); |
| 343 | |
| 344 | DrawData *data = draw->data; |
| 345 | |
| 346 | if(queries.size() != 0) |
| 347 | { |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 348 | draw->queries = new std::list<Query*>(); |
| 349 | bool includePrimitivesWrittenQueries = vertexState.transformFeedbackQueryEnabled && vertexState.transformFeedbackEnabled; |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 350 | for(auto &query : queries) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 351 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 352 | if(includePrimitivesWrittenQueries || (query->type != Query::TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)) |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 353 | { |
Alexis Hetu | 3fc6893 | 2018-11-14 10:54:53 -0500 | [diff] [blame] | 354 | query->addRef(); |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 355 | draw->queries->push_back(query); |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 356 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 357 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | draw->drawType = drawType; |
| 361 | draw->batchSize = batch; |
| 362 | |
| 363 | vertexRoutine->bind(); |
| 364 | setupRoutine->bind(); |
| 365 | pixelRoutine->bind(); |
| 366 | |
| 367 | draw->vertexRoutine = vertexRoutine; |
| 368 | draw->setupRoutine = setupRoutine; |
| 369 | draw->pixelRoutine = pixelRoutine; |
Nicolas Capens | eb195b6 | 2015-04-28 17:18:42 -0700 | [diff] [blame] | 370 | draw->vertexPointer = (VertexProcessor::RoutinePointer)vertexRoutine->getEntry(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 371 | draw->setupPointer = (SetupProcessor::RoutinePointer)setupRoutine->getEntry(); |
| 372 | draw->pixelPointer = (PixelProcessor::RoutinePointer)pixelRoutine->getEntry(); |
| 373 | draw->setupPrimitives = setupPrimitives; |
| 374 | draw->setupState = setupState; |
| 375 | |
Nicolas Capens | f0aef1a | 2016-05-18 14:44:21 -0400 | [diff] [blame] | 376 | for(int i = 0; i < MAX_VERTEX_INPUTS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 377 | { |
| 378 | draw->vertexStream[i] = context->input[i].resource; |
| 379 | data->input[i] = context->input[i].buffer; |
| 380 | data->stride[i] = context->input[i].stride; |
| 381 | |
| 382 | if(draw->vertexStream[i]) |
| 383 | { |
| 384 | draw->vertexStream[i]->lock(PUBLIC, PRIVATE); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if(context->indexBuffer) |
| 389 | { |
| 390 | data->indices = (unsigned char*)context->indexBuffer->lock(PUBLIC, PRIVATE) + indexOffset; |
| 391 | } |
| 392 | |
| 393 | draw->indexBuffer = context->indexBuffer; |
| 394 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 395 | for(int sampler = 0; sampler < TOTAL_IMAGE_UNITS; sampler++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 396 | { |
| 397 | draw->texture[sampler] = 0; |
| 398 | } |
| 399 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 400 | for(int sampler = 0; sampler < TEXTURE_IMAGE_UNITS; sampler++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 401 | { |
| 402 | if(pixelState.sampler[sampler].textureType != TEXTURE_NULL) |
| 403 | { |
| 404 | draw->texture[sampler] = context->texture[sampler]; |
| 405 | draw->texture[sampler]->lock(PUBLIC, isReadWriteTexture(sampler) ? MANAGED : PRIVATE); // If the texure is both read and written, use the same read/write lock as render targets |
| 406 | |
| 407 | data->mipmap[sampler] = context->sampler[sampler].getTextureData(); |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 408 | |
| 409 | requiresSync |= context->sampler[sampler].requiresSync(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | if(context->pixelShader) |
| 414 | { |
| 415 | if(draw->psDirtyConstF) |
| 416 | { |
| 417 | memcpy(&data->ps.cW, PixelProcessor::cW, sizeof(word4) * 4 * (draw->psDirtyConstF < 8 ? draw->psDirtyConstF : 8)); |
| 418 | memcpy(&data->ps.c, PixelProcessor::c, sizeof(float4) * draw->psDirtyConstF); |
| 419 | draw->psDirtyConstF = 0; |
| 420 | } |
| 421 | |
| 422 | if(draw->psDirtyConstI) |
| 423 | { |
| 424 | memcpy(&data->ps.i, PixelProcessor::i, sizeof(int4) * draw->psDirtyConstI); |
| 425 | draw->psDirtyConstI = 0; |
| 426 | } |
| 427 | |
| 428 | if(draw->psDirtyConstB) |
| 429 | { |
| 430 | memcpy(&data->ps.b, PixelProcessor::b, sizeof(bool) * draw->psDirtyConstB); |
| 431 | draw->psDirtyConstB = 0; |
| 432 | } |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 433 | |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 434 | PixelProcessor::lockUniformBuffers(data->ps.u, draw->pUniformBuffers); |
| 435 | } |
| 436 | else |
| 437 | { |
| 438 | for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; i++) |
| 439 | { |
| 440 | draw->pUniformBuffers[i] = nullptr; |
| 441 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 442 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 443 | |
Alexis Hetu | 53ad4af | 2017-12-06 14:49:07 -0500 | [diff] [blame] | 444 | if(context->pixelShaderModel() <= 0x0104) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 445 | { |
| 446 | for(int stage = 0; stage < 8; stage++) |
| 447 | { |
| 448 | if(pixelState.textureStage[stage].stageOperation != TextureStage::STAGE_DISABLE || context->pixelShader) |
| 449 | { |
| 450 | data->textureStage[stage] = context->textureStage[stage].uniforms; |
| 451 | } |
| 452 | else break; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | if(context->vertexShader) |
| 457 | { |
Alexis Hetu | 53ad4af | 2017-12-06 14:49:07 -0500 | [diff] [blame] | 458 | if(context->vertexShader->getShaderModel() >= 0x0300) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 459 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 460 | for(int sampler = 0; sampler < VERTEX_TEXTURE_IMAGE_UNITS; sampler++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 461 | { |
Nicolas Capens | f878d50 | 2017-11-06 15:29:46 -0500 | [diff] [blame] | 462 | if(vertexState.sampler[sampler].textureType != TEXTURE_NULL) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 463 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 464 | draw->texture[TEXTURE_IMAGE_UNITS + sampler] = context->texture[TEXTURE_IMAGE_UNITS + sampler]; |
| 465 | draw->texture[TEXTURE_IMAGE_UNITS + sampler]->lock(PUBLIC, PRIVATE); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 466 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 467 | data->mipmap[TEXTURE_IMAGE_UNITS + sampler] = context->sampler[TEXTURE_IMAGE_UNITS + sampler].getTextureData(); |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 468 | |
| 469 | requiresSync |= context->sampler[TEXTURE_IMAGE_UNITS + sampler].requiresSync(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if(draw->vsDirtyConstF) |
| 475 | { |
| 476 | memcpy(&data->vs.c, VertexProcessor::c, sizeof(float4) * draw->vsDirtyConstF); |
| 477 | draw->vsDirtyConstF = 0; |
| 478 | } |
| 479 | |
| 480 | if(draw->vsDirtyConstI) |
| 481 | { |
| 482 | memcpy(&data->vs.i, VertexProcessor::i, sizeof(int4) * draw->vsDirtyConstI); |
| 483 | draw->vsDirtyConstI = 0; |
| 484 | } |
| 485 | |
| 486 | if(draw->vsDirtyConstB) |
| 487 | { |
| 488 | memcpy(&data->vs.b, VertexProcessor::b, sizeof(bool) * draw->vsDirtyConstB); |
| 489 | draw->vsDirtyConstB = 0; |
| 490 | } |
Alexis Hetu | dd8df68 | 2015-06-05 17:08:39 -0400 | [diff] [blame] | 491 | |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 492 | if(context->vertexShader->isInstanceIdDeclared()) |
Alexis Hetu | dd8df68 | 2015-06-05 17:08:39 -0400 | [diff] [blame] | 493 | { |
| 494 | data->instanceID = context->instanceID; |
| 495 | } |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 496 | |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 497 | VertexProcessor::lockUniformBuffers(data->vs.u, draw->vUniformBuffers); |
| 498 | VertexProcessor::lockTransformFeedbackBuffers(data->vs.t, data->vs.reg, data->vs.row, data->vs.col, data->vs.str, draw->transformFeedbackBuffers); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 499 | } |
| 500 | else |
| 501 | { |
| 502 | data->ff = ff; |
| 503 | |
Alexis Hetu | 04c967a | 2015-07-08 15:56:17 -0400 | [diff] [blame] | 504 | draw->vsDirtyConstF = VERTEX_UNIFORM_VECTORS + 1; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 505 | draw->vsDirtyConstI = 16; |
| 506 | draw->vsDirtyConstB = 16; |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 507 | |
| 508 | for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; i++) |
| 509 | { |
| 510 | draw->vUniformBuffers[i] = nullptr; |
| 511 | } |
| 512 | |
| 513 | for(int i = 0; i < MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS; i++) |
| 514 | { |
| 515 | draw->transformFeedbackBuffers[i] = nullptr; |
| 516 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | if(pixelState.stencilActive) |
| 520 | { |
| 521 | data->stencil[0] = stencil; |
| 522 | data->stencil[1] = stencilCCW; |
| 523 | } |
| 524 | |
| 525 | if(pixelState.fogActive) |
| 526 | { |
| 527 | data->fog = fog; |
| 528 | } |
| 529 | |
| 530 | if(setupState.isDrawPoint) |
| 531 | { |
| 532 | data->point = point; |
| 533 | } |
| 534 | |
Nicolas Capens | 235781d | 2015-01-27 01:46:53 -0500 | [diff] [blame] | 535 | data->lineWidth = context->lineWidth; |
| 536 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 537 | data->factor = factor; |
| 538 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 539 | if(pixelState.transparencyAntialiasing == TRANSPARENCY_ALPHA_TO_COVERAGE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 540 | { |
Alexis Hetu | a818c45 | 2015-06-11 13:06:58 -0400 | [diff] [blame] | 541 | float ref = context->alphaReference * (1.0f / 255.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 542 | float margin = sw::min(ref, 1.0f - ref); |
| 543 | |
| 544 | if(ms == 4) |
| 545 | { |
| 546 | data->a2c0 = replicate(ref - margin * 0.6f); |
| 547 | data->a2c1 = replicate(ref - margin * 0.2f); |
| 548 | data->a2c2 = replicate(ref + margin * 0.2f); |
| 549 | data->a2c3 = replicate(ref + margin * 0.6f); |
| 550 | } |
| 551 | else if(ms == 2) |
| 552 | { |
| 553 | data->a2c0 = replicate(ref - margin * 0.3f); |
| 554 | data->a2c1 = replicate(ref + margin * 0.3f); |
| 555 | } |
| 556 | else ASSERT(false); |
| 557 | } |
| 558 | |
| 559 | if(pixelState.occlusionEnabled) |
| 560 | { |
| 561 | for(int cluster = 0; cluster < clusterCount; cluster++) |
| 562 | { |
| 563 | data->occlusion[cluster] = 0; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | #if PERF_PROFILE |
| 568 | for(int cluster = 0; cluster < clusterCount; cluster++) |
| 569 | { |
| 570 | for(int i = 0; i < PERF_TIMERS; i++) |
| 571 | { |
| 572 | data->cycles[i][cluster] = 0; |
| 573 | } |
| 574 | } |
| 575 | #endif |
| 576 | |
| 577 | // Viewport |
| 578 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 579 | float W = 0.5f * viewport.width; |
| 580 | float H = 0.5f * viewport.height; |
| 581 | float X0 = viewport.x0 + W; |
| 582 | float Y0 = viewport.y0 + H; |
| 583 | float N = viewport.minZ; |
| 584 | float F = viewport.maxZ; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 585 | float Z = F - N; |
| 586 | |
| 587 | if(context->isDrawTriangle(false)) |
| 588 | { |
Nicolas Capens | 3cbeac5 | 2017-09-15 11:49:31 -0400 | [diff] [blame] | 589 | N += context->depthBias; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | if(complementaryDepthBuffer) |
| 593 | { |
| 594 | Z = -Z; |
| 595 | N = 1 - N; |
| 596 | } |
| 597 | |
| 598 | static const float X[5][16] = // Fragment offsets |
| 599 | { |
| 600 | {+0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f}, // 1 sample |
| 601 | {-0.2500f, +0.2500f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f}, // 2 samples |
| 602 | {-0.3000f, +0.1000f, +0.3000f, -0.1000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f}, // 4 samples |
| 603 | {+0.1875f, -0.3125f, +0.3125f, -0.4375f, -0.0625f, +0.4375f, +0.0625f, -0.1875f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f}, // 8 samples |
| 604 | {+0.2553f, -0.1155f, +0.1661f, -0.1828f, +0.2293f, -0.4132f, -0.1773f, -0.0577f, +0.3891f, -0.4656f, +0.4103f, +0.4248f, -0.2109f, +0.3966f, -0.2664f, -0.3872f} // 16 samples |
| 605 | }; |
| 606 | |
| 607 | static const float Y[5][16] = // Fragment offsets |
| 608 | { |
| 609 | {+0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f}, // 1 sample |
| 610 | {-0.2500f, +0.2500f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f}, // 2 samples |
| 611 | {-0.1000f, -0.3000f, +0.1000f, +0.3000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f}, // 4 samples |
| 612 | {-0.4375f, -0.3125f, -0.1875f, -0.0625f, +0.0625f, +0.1875f, +0.3125f, +0.4375f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f, +0.0000f}, // 8 samples |
| 613 | {-0.4503f, +0.1883f, +0.3684f, -0.4668f, -0.0690f, -0.1315f, +0.4999f, +0.0728f, +0.1070f, -0.3086f, +0.3725f, -0.1547f, -0.1102f, -0.3588f, +0.1789f, +0.0269f} // 16 samples |
| 614 | }; |
| 615 | |
| 616 | int s = sw::log2(ss); |
| 617 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 618 | data->Wx16 = replicate(W * 16); |
| 619 | data->Hx16 = replicate(H * 16); |
Nicolas Capens | 5491cb4 | 2015-07-02 15:33:29 -0400 | [diff] [blame] | 620 | data->X0x16 = replicate(X0 * 16 - 8); |
| 621 | data->Y0x16 = replicate(Y0 * 16 - 8); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 622 | data->XXXX = replicate(X[s][q] / W); |
| 623 | data->YYYY = replicate(Y[s][q] / H); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 624 | data->halfPixelX = replicate(0.5f / W); |
| 625 | data->halfPixelY = replicate(0.5f / H); |
| 626 | data->viewportHeight = abs(viewport.height); |
Nicolas Capens | 3cbeac5 | 2017-09-15 11:49:31 -0400 | [diff] [blame] | 627 | data->slopeDepthBias = context->slopeDepthBias; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 628 | data->depthRange = Z; |
| 629 | data->depthNear = N; |
| 630 | draw->clipFlags = clipFlags; |
| 631 | |
| 632 | if(clipFlags) |
| 633 | { |
| 634 | if(clipFlags & Clipper::CLIP_PLANE0) data->clipPlane[0] = clipPlane[0]; |
| 635 | if(clipFlags & Clipper::CLIP_PLANE1) data->clipPlane[1] = clipPlane[1]; |
| 636 | if(clipFlags & Clipper::CLIP_PLANE2) data->clipPlane[2] = clipPlane[2]; |
| 637 | if(clipFlags & Clipper::CLIP_PLANE3) data->clipPlane[3] = clipPlane[3]; |
| 638 | if(clipFlags & Clipper::CLIP_PLANE4) data->clipPlane[4] = clipPlane[4]; |
| 639 | if(clipFlags & Clipper::CLIP_PLANE5) data->clipPlane[5] = clipPlane[5]; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | // Target |
| 644 | { |
Alexis Hetu | 1edcd8b | 2015-11-05 11:12:41 -0500 | [diff] [blame] | 645 | for(int index = 0; index < RENDERTARGETS; index++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 646 | { |
| 647 | draw->renderTarget[index] = context->renderTarget[index]; |
| 648 | |
| 649 | if(draw->renderTarget[index]) |
| 650 | { |
Nicolas Capens | 8af24c5 | 2017-12-11 14:45:01 -0500 | [diff] [blame] | 651 | unsigned int layer = context->renderTargetLayer[index]; |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 652 | requiresSync |= context->renderTarget[index]->requiresSync(); |
Nicolas Capens | 8af24c5 | 2017-12-11 14:45:01 -0500 | [diff] [blame] | 653 | data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->lockInternal(0, 0, layer, LOCK_READWRITE, MANAGED); |
Nicolas Capens | bfa23b3 | 2017-12-11 10:06:37 -0500 | [diff] [blame] | 654 | data->colorBuffer[index] += q * ms * context->renderTarget[index]->getSliceB(true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 655 | data->colorPitchB[index] = context->renderTarget[index]->getInternalPitchB(); |
| 656 | data->colorSliceB[index] = context->renderTarget[index]->getInternalSliceB(); |
| 657 | } |
| 658 | } |
| 659 | |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 660 | draw->depthBuffer = context->depthBuffer; |
| 661 | draw->stencilBuffer = context->stencilBuffer; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 662 | |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 663 | if(draw->depthBuffer) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 664 | { |
Nicolas Capens | 8af24c5 | 2017-12-11 14:45:01 -0500 | [diff] [blame] | 665 | unsigned int layer = context->depthBufferLayer; |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 666 | requiresSync |= context->depthBuffer->requiresSync(); |
Nicolas Capens | 8af24c5 | 2017-12-11 14:45:01 -0500 | [diff] [blame] | 667 | data->depthBuffer = (float*)context->depthBuffer->lockInternal(0, 0, layer, LOCK_READWRITE, MANAGED); |
Nicolas Capens | bfa23b3 | 2017-12-11 10:06:37 -0500 | [diff] [blame] | 668 | data->depthBuffer += q * ms * context->depthBuffer->getSliceB(true); |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 669 | data->depthPitchB = context->depthBuffer->getInternalPitchB(); |
| 670 | data->depthSliceB = context->depthBuffer->getInternalSliceB(); |
| 671 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 672 | |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 673 | if(draw->stencilBuffer) |
| 674 | { |
Nicolas Capens | 8af24c5 | 2017-12-11 14:45:01 -0500 | [diff] [blame] | 675 | unsigned int layer = context->stencilBufferLayer; |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 676 | requiresSync |= context->stencilBuffer->requiresSync(); |
Nicolas Capens | 8af24c5 | 2017-12-11 14:45:01 -0500 | [diff] [blame] | 677 | data->stencilBuffer = (unsigned char*)context->stencilBuffer->lockStencil(0, 0, layer, MANAGED); |
Nicolas Capens | bfa23b3 | 2017-12-11 10:06:37 -0500 | [diff] [blame] | 678 | data->stencilBuffer += q * ms * context->stencilBuffer->getSliceB(true); |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 679 | data->stencilPitchB = context->stencilBuffer->getStencilPitchB(); |
| 680 | data->stencilSliceB = context->stencilBuffer->getStencilSliceB(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 684 | // Scissor |
| 685 | { |
| 686 | data->scissorX0 = scissor.x0; |
| 687 | data->scissorX1 = scissor.x1; |
| 688 | data->scissorY0 = scissor.y0; |
| 689 | data->scissorY1 = scissor.y1; |
| 690 | } |
| 691 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 692 | draw->primitive = 0; |
| 693 | draw->count = count; |
| 694 | |
| 695 | draw->references = (count + batch - 1) / batch; |
| 696 | |
Nicolas Capens | ebe6764 | 2015-03-20 13:34:51 -0400 | [diff] [blame] | 697 | schedulerMutex.lock(); |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 698 | ++nextDraw; // Atomic |
Nicolas Capens | ebe6764 | 2015-03-20 13:34:51 -0400 | [diff] [blame] | 699 | schedulerMutex.unlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 700 | |
Nicolas Capens | 0808b4f | 2017-03-13 17:20:39 -0400 | [diff] [blame] | 701 | #ifndef NDEBUG |
| 702 | if(threadCount == 1) // Use main thread for draw execution |
| 703 | { |
| 704 | threadsAwake = 1; |
| 705 | task[0].type = Task::RESUME; |
| 706 | |
| 707 | taskLoop(0); |
| 708 | } |
| 709 | else |
| 710 | #endif |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 711 | { |
Nicolas Capens | 20248dd | 2015-08-10 14:07:45 -0400 | [diff] [blame] | 712 | if(!threadsAwake) |
| 713 | { |
| 714 | suspend[0]->wait(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 715 | |
Nicolas Capens | 20248dd | 2015-08-10 14:07:45 -0400 | [diff] [blame] | 716 | threadsAwake = 1; |
| 717 | task[0].type = Task::RESUME; |
| 718 | |
| 719 | resume[0]->signal(); |
| 720 | } |
| 721 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 722 | } |
Alexis Hetu | 9040421 | 2018-06-04 11:38:17 -0400 | [diff] [blame] | 723 | |
| 724 | // TODO(sugoi): This is a temporary brute-force workaround to ensure IOSurface synchronization. |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 725 | if(requiresSync) |
Alexis Hetu | 9040421 | 2018-06-04 11:38:17 -0400 | [diff] [blame] | 726 | { |
| 727 | synchronize(); |
| 728 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Nicolas Capens | 426cb5e | 2017-07-20 14:14:09 -0400 | [diff] [blame] | 731 | void Renderer::clear(void *value, Format format, Surface *dest, const Rect &clearRect, unsigned int rgbaMask) |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 732 | { |
Nicolas Capens | bfa23b3 | 2017-12-11 10:06:37 -0500 | [diff] [blame] | 733 | blitter->clear(value, format, dest, clearRect, rgbaMask); |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 734 | } |
| 735 | |
Nicolas Capens | 1ab837c | 2017-12-16 02:28:02 -0500 | [diff] [blame] | 736 | void Renderer::blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil, bool sRGBconversion) |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 737 | { |
Nicolas Capens | 1ab837c | 2017-12-16 02:28:02 -0500 | [diff] [blame] | 738 | blitter->blit(source, sRect, dest, dRect, {filter, isStencil, sRGBconversion}); |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | void Renderer::blit3D(Surface *source, Surface *dest) |
| 742 | { |
| 743 | blitter->blit3D(source, dest); |
| 744 | } |
| 745 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 746 | void Renderer::threadFunction(void *parameters) |
| 747 | { |
| 748 | Renderer *renderer = static_cast<Parameters*>(parameters)->renderer; |
| 749 | int threadIndex = static_cast<Parameters*>(parameters)->threadIndex; |
| 750 | |
| 751 | if(logPrecision < IEEE) |
| 752 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 753 | CPUID::setFlushToZero(true); |
| 754 | CPUID::setDenormalsAreZero(true); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | renderer->threadLoop(threadIndex); |
| 758 | } |
| 759 | |
| 760 | void Renderer::threadLoop(int threadIndex) |
| 761 | { |
| 762 | while(!exitThreads) |
| 763 | { |
| 764 | taskLoop(threadIndex); |
| 765 | |
| 766 | suspend[threadIndex]->signal(); |
| 767 | resume[threadIndex]->wait(); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | void Renderer::taskLoop(int threadIndex) |
| 772 | { |
| 773 | while(task[threadIndex].type != Task::SUSPEND) |
| 774 | { |
| 775 | scheduleTask(threadIndex); |
| 776 | executeTask(threadIndex); |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | void Renderer::findAvailableTasks() |
| 781 | { |
| 782 | // Find pixel tasks |
| 783 | for(int cluster = 0; cluster < clusterCount; cluster++) |
| 784 | { |
| 785 | if(!pixelProgress[cluster].executing) |
| 786 | { |
| 787 | for(int unit = 0; unit < unitCount; unit++) |
| 788 | { |
| 789 | if(primitiveProgress[unit].references > 0) // Contains processed primitives |
| 790 | { |
| 791 | if(pixelProgress[cluster].drawCall == primitiveProgress[unit].drawCall) |
| 792 | { |
| 793 | if(pixelProgress[cluster].processedPrimitives == primitiveProgress[unit].firstPrimitive) // Previous primitives have been rendered |
| 794 | { |
| 795 | Task &task = taskQueue[qHead]; |
| 796 | task.type = Task::PIXELS; |
| 797 | task.primitiveUnit = unit; |
| 798 | task.pixelCluster = cluster; |
| 799 | |
| 800 | pixelProgress[cluster].executing = true; |
| 801 | |
| 802 | // Commit to the task queue |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 803 | qHead = (qHead + 1) & TASK_COUNT_BITS; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 804 | qSize++; |
| 805 | |
| 806 | break; |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 813 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 814 | // Find primitive tasks |
| 815 | if(currentDraw == nextDraw) |
| 816 | { |
| 817 | return; // No more primitives to process |
| 818 | } |
| 819 | |
| 820 | for(int unit = 0; unit < unitCount; unit++) |
| 821 | { |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 822 | DrawCall *draw = drawList[currentDraw & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 823 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 824 | int primitive = draw->primitive; |
| 825 | int count = draw->count; |
| 826 | |
| 827 | if(primitive >= count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 828 | { |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 829 | ++currentDraw; // Atomic |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 830 | |
| 831 | if(currentDraw == nextDraw) |
| 832 | { |
| 833 | return; // No more primitives to process |
| 834 | } |
| 835 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 836 | draw = drawList[currentDraw & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | if(!primitiveProgress[unit].references) // Task not already being executed and not still in use by a pixel unit |
| 840 | { |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 841 | primitive = draw->primitive; |
| 842 | count = draw->count; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 843 | int batch = draw->batchSize; |
| 844 | |
| 845 | primitiveProgress[unit].drawCall = currentDraw; |
| 846 | primitiveProgress[unit].firstPrimitive = primitive; |
| 847 | primitiveProgress[unit].primitiveCount = count - primitive >= batch ? batch : count - primitive; |
| 848 | |
| 849 | draw->primitive += batch; |
| 850 | |
| 851 | Task &task = taskQueue[qHead]; |
| 852 | task.type = Task::PRIMITIVES; |
| 853 | task.primitiveUnit = unit; |
| 854 | |
| 855 | primitiveProgress[unit].references = -1; |
| 856 | |
| 857 | // Commit to the task queue |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 858 | qHead = (qHead + 1) & TASK_COUNT_BITS; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 859 | qSize++; |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | void Renderer::scheduleTask(int threadIndex) |
| 865 | { |
Nicolas Capens | ebe6764 | 2015-03-20 13:34:51 -0400 | [diff] [blame] | 866 | schedulerMutex.lock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 867 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 868 | int curThreadsAwake = threadsAwake; |
| 869 | |
| 870 | if((int)qSize < threadCount - curThreadsAwake + 1) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 871 | { |
| 872 | findAvailableTasks(); |
| 873 | } |
| 874 | |
| 875 | if(qSize != 0) |
| 876 | { |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 877 | task[threadIndex] = taskQueue[(qHead - qSize) & TASK_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 878 | qSize--; |
| 879 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 880 | if(curThreadsAwake != threadCount) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 881 | { |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 882 | int wakeup = qSize - curThreadsAwake + 1; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 883 | |
| 884 | for(int i = 0; i < threadCount && wakeup > 0; i++) |
| 885 | { |
| 886 | if(task[i].type == Task::SUSPEND) |
| 887 | { |
| 888 | suspend[i]->wait(); |
| 889 | task[i].type = Task::RESUME; |
| 890 | resume[i]->signal(); |
| 891 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 892 | ++threadsAwake; // Atomic |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 893 | wakeup--; |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | else |
| 899 | { |
| 900 | task[threadIndex].type = Task::SUSPEND; |
| 901 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 902 | --threadsAwake; // Atomic |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 903 | } |
| 904 | |
Nicolas Capens | ebe6764 | 2015-03-20 13:34:51 -0400 | [diff] [blame] | 905 | schedulerMutex.unlock(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | void Renderer::executeTask(int threadIndex) |
| 909 | { |
| 910 | #if PERF_HUD |
| 911 | int64_t startTick = Timer::ticks(); |
| 912 | #endif |
| 913 | |
| 914 | switch(task[threadIndex].type) |
| 915 | { |
| 916 | case Task::PRIMITIVES: |
| 917 | { |
| 918 | int unit = task[threadIndex].primitiveUnit; |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 919 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 920 | int input = primitiveProgress[unit].firstPrimitive; |
| 921 | int count = primitiveProgress[unit].primitiveCount; |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 922 | DrawCall *draw = drawList[primitiveProgress[unit].drawCall & DRAW_COUNT_BITS]; |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 923 | int (Renderer::*setupPrimitives)(int batch, int count) = draw->setupPrimitives; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 924 | |
| 925 | processPrimitiveVertices(unit, input, count, draw->count, threadIndex); |
| 926 | |
| 927 | #if PERF_HUD |
| 928 | int64_t time = Timer::ticks(); |
| 929 | vertexTime[threadIndex] += time - startTick; |
| 930 | startTick = time; |
| 931 | #endif |
| 932 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 933 | int visible = 0; |
| 934 | |
| 935 | if(!draw->setupState.rasterizerDiscard) |
| 936 | { |
| 937 | visible = (this->*setupPrimitives)(unit, count); |
| 938 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 939 | |
| 940 | primitiveProgress[unit].visible = visible; |
| 941 | primitiveProgress[unit].references = clusterCount; |
| 942 | |
| 943 | #if PERF_HUD |
| 944 | setupTime[threadIndex] += Timer::ticks() - startTick; |
| 945 | #endif |
| 946 | } |
| 947 | break; |
| 948 | case Task::PIXELS: |
| 949 | { |
| 950 | int unit = task[threadIndex].primitiveUnit; |
| 951 | int visible = primitiveProgress[unit].visible; |
| 952 | |
| 953 | if(visible > 0) |
| 954 | { |
| 955 | int cluster = task[threadIndex].pixelCluster; |
| 956 | Primitive *primitive = primitiveBatch[unit]; |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 957 | DrawCall *draw = drawList[pixelProgress[cluster].drawCall & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 958 | DrawData *data = draw->data; |
| 959 | PixelProcessor::RoutinePointer pixelRoutine = draw->pixelPointer; |
| 960 | |
| 961 | pixelRoutine(primitive, visible, cluster, data); |
| 962 | } |
| 963 | |
| 964 | finishRendering(task[threadIndex]); |
| 965 | |
| 966 | #if PERF_HUD |
| 967 | pixelTime[threadIndex] += Timer::ticks() - startTick; |
| 968 | #endif |
| 969 | } |
| 970 | break; |
| 971 | case Task::RESUME: |
| 972 | break; |
| 973 | case Task::SUSPEND: |
| 974 | break; |
| 975 | default: |
| 976 | ASSERT(false); |
| 977 | } |
| 978 | } |
| 979 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 980 | void Renderer::synchronize() |
| 981 | { |
| 982 | sync->lock(sw::PUBLIC); |
| 983 | sync->unlock(); |
| 984 | } |
| 985 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 986 | void Renderer::finishRendering(Task &pixelTask) |
| 987 | { |
| 988 | int unit = pixelTask.primitiveUnit; |
| 989 | int cluster = pixelTask.pixelCluster; |
| 990 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 991 | DrawCall &draw = *drawList[primitiveProgress[unit].drawCall & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 992 | DrawData &data = *draw.data; |
| 993 | int primitive = primitiveProgress[unit].firstPrimitive; |
| 994 | int count = primitiveProgress[unit].primitiveCount; |
Alexis Hetu | f4fbcb8 | 2016-04-07 11:05:57 -0400 | [diff] [blame] | 995 | int processedPrimitives = primitive + count; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 996 | |
Alexis Hetu | f4fbcb8 | 2016-04-07 11:05:57 -0400 | [diff] [blame] | 997 | pixelProgress[cluster].processedPrimitives = processedPrimitives; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 998 | |
Nicolas Capens | f330423 | 2016-03-10 00:56:16 -0500 | [diff] [blame] | 999 | if(pixelProgress[cluster].processedPrimitives >= draw.count) |
| 1000 | { |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 1001 | ++pixelProgress[cluster].drawCall; // Atomic |
Nicolas Capens | f330423 | 2016-03-10 00:56:16 -0500 | [diff] [blame] | 1002 | pixelProgress[cluster].processedPrimitives = 0; |
| 1003 | } |
| 1004 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 1005 | int ref = primitiveProgress[unit].references--; // Atomic |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1006 | |
| 1007 | if(ref == 0) |
| 1008 | { |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 1009 | ref = draw.references--; // Atomic |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1010 | |
| 1011 | if(ref == 0) |
| 1012 | { |
| 1013 | #if PERF_PROFILE |
| 1014 | for(int cluster = 0; cluster < clusterCount; cluster++) |
| 1015 | { |
| 1016 | for(int i = 0; i < PERF_TIMERS; i++) |
| 1017 | { |
| 1018 | profiler.cycles[i] += data.cycles[i][cluster]; |
| 1019 | } |
| 1020 | } |
| 1021 | #endif |
| 1022 | |
| 1023 | if(draw.queries) |
| 1024 | { |
Alexis Hetu | bf3fc25 | 2017-12-06 14:22:10 -0500 | [diff] [blame] | 1025 | for(auto &query : *(draw.queries)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1026 | { |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 1027 | switch(query->type) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1028 | { |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 1029 | case Query::FRAGMENTS_PASSED: |
| 1030 | for(int cluster = 0; cluster < clusterCount; cluster++) |
| 1031 | { |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 1032 | query->data += data.occlusion[cluster]; |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 1033 | } |
| 1034 | break; |
| 1035 | case Query::TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 1036 | query->data += processedPrimitives; |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 1037 | break; |
| 1038 | default: |
| 1039 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Alexis Hetu | 3fc6893 | 2018-11-14 10:54:53 -0500 | [diff] [blame] | 1042 | query->release(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | delete draw.queries; |
| 1046 | draw.queries = 0; |
| 1047 | } |
| 1048 | |
Alexis Hetu | 1edcd8b | 2015-11-05 11:12:41 -0500 | [diff] [blame] | 1049 | for(int i = 0; i < RENDERTARGETS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1050 | { |
| 1051 | if(draw.renderTarget[i]) |
| 1052 | { |
| 1053 | draw.renderTarget[i]->unlockInternal(); |
| 1054 | } |
| 1055 | } |
| 1056 | |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 1057 | if(draw.depthBuffer) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1058 | { |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 1059 | draw.depthBuffer->unlockInternal(); |
| 1060 | } |
| 1061 | |
| 1062 | if(draw.stencilBuffer) |
| 1063 | { |
| 1064 | draw.stencilBuffer->unlockStencil(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 1067 | for(int i = 0; i < TOTAL_IMAGE_UNITS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1068 | { |
| 1069 | if(draw.texture[i]) |
| 1070 | { |
| 1071 | draw.texture[i]->unlock(); |
| 1072 | } |
| 1073 | } |
| 1074 | |
Nicolas Capens | f0aef1a | 2016-05-18 14:44:21 -0400 | [diff] [blame] | 1075 | for(int i = 0; i < MAX_VERTEX_INPUTS; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1076 | { |
| 1077 | if(draw.vertexStream[i]) |
| 1078 | { |
| 1079 | draw.vertexStream[i]->unlock(); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | if(draw.indexBuffer) |
| 1084 | { |
| 1085 | draw.indexBuffer->unlock(); |
| 1086 | } |
| 1087 | |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 1088 | for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; i++) |
| 1089 | { |
| 1090 | if(draw.pUniformBuffers[i]) |
| 1091 | { |
| 1092 | draw.pUniformBuffers[i]->unlock(); |
| 1093 | } |
| 1094 | if(draw.vUniformBuffers[i]) |
| 1095 | { |
| 1096 | draw.vUniformBuffers[i]->unlock(); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | for(int i = 0; i < MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS; i++) |
| 1101 | { |
| 1102 | if(draw.transformFeedbackBuffers[i]) |
| 1103 | { |
| 1104 | draw.transformFeedbackBuffers[i]->unlock(); |
| 1105 | } |
| 1106 | } |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 1107 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1108 | draw.vertexRoutine->unbind(); |
| 1109 | draw.setupRoutine->unbind(); |
| 1110 | draw.pixelRoutine->unbind(); |
| 1111 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1112 | sync->unlock(); |
| 1113 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1114 | draw.references = -1; |
| 1115 | resumeApp->signal(); |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | pixelProgress[cluster].executing = false; |
| 1120 | } |
| 1121 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1122 | void Renderer::processPrimitiveVertices(int unit, unsigned int start, unsigned int triangleCount, unsigned int loop, int thread) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1123 | { |
| 1124 | Triangle *triangle = triangleBatch[unit]; |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 1125 | int primitiveDrawCall = primitiveProgress[unit].drawCall; |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 1126 | DrawCall *draw = drawList[primitiveDrawCall & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1127 | DrawData *data = draw->data; |
| 1128 | VertexTask *task = vertexTask[thread]; |
| 1129 | |
| 1130 | const void *indices = data->indices; |
| 1131 | VertexProcessor::RoutinePointer vertexRoutine = draw->vertexPointer; |
| 1132 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 1133 | if(task->vertexCache.drawCall != primitiveDrawCall) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1134 | { |
| 1135 | task->vertexCache.clear(); |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 1136 | task->vertexCache.drawCall = primitiveDrawCall; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | unsigned int batch[128][3]; // FIXME: Adjust to dynamic batch size |
| 1140 | |
| 1141 | switch(draw->drawType) |
| 1142 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1143 | case DRAW_POINTLIST: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1144 | { |
| 1145 | unsigned int index = start; |
| 1146 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1147 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1148 | { |
| 1149 | batch[i][0] = index; |
| 1150 | batch[i][1] = index; |
| 1151 | batch[i][2] = index; |
| 1152 | |
| 1153 | index += 1; |
| 1154 | } |
| 1155 | } |
| 1156 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1157 | case DRAW_LINELIST: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1158 | { |
| 1159 | unsigned int index = 2 * start; |
| 1160 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1161 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1162 | { |
| 1163 | batch[i][0] = index + 0; |
| 1164 | batch[i][1] = index + 1; |
| 1165 | batch[i][2] = index + 1; |
| 1166 | |
| 1167 | index += 2; |
| 1168 | } |
| 1169 | } |
| 1170 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1171 | case DRAW_LINESTRIP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1172 | { |
| 1173 | unsigned int index = start; |
| 1174 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1175 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1176 | { |
| 1177 | batch[i][0] = index + 0; |
| 1178 | batch[i][1] = index + 1; |
| 1179 | batch[i][2] = index + 1; |
| 1180 | |
| 1181 | index += 1; |
| 1182 | } |
| 1183 | } |
| 1184 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1185 | case DRAW_LINELOOP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1186 | { |
| 1187 | unsigned int index = start; |
| 1188 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1189 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1190 | { |
| 1191 | batch[i][0] = (index + 0) % loop; |
| 1192 | batch[i][1] = (index + 1) % loop; |
| 1193 | batch[i][2] = (index + 1) % loop; |
| 1194 | |
| 1195 | index += 1; |
| 1196 | } |
| 1197 | } |
| 1198 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1199 | case DRAW_TRIANGLELIST: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1200 | { |
| 1201 | unsigned int index = 3 * start; |
| 1202 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1203 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1204 | { |
| 1205 | batch[i][0] = index + 0; |
| 1206 | batch[i][1] = index + 1; |
| 1207 | batch[i][2] = index + 2; |
| 1208 | |
| 1209 | index += 3; |
| 1210 | } |
| 1211 | } |
| 1212 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1213 | case DRAW_TRIANGLESTRIP: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1214 | { |
| 1215 | unsigned int index = start; |
| 1216 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1217 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1218 | { |
Alexis Hetu | 62cd2bd | 2017-12-21 13:52:00 -0500 | [diff] [blame] | 1219 | if(leadingVertexFirst) |
| 1220 | { |
| 1221 | batch[i][0] = index + 0; |
| 1222 | batch[i][1] = index + (index & 1) + 1; |
| 1223 | batch[i][2] = index + (~index & 1) + 1; |
| 1224 | } |
| 1225 | else |
| 1226 | { |
| 1227 | batch[i][0] = index + (index & 1); |
| 1228 | batch[i][1] = index + (~index & 1); |
| 1229 | batch[i][2] = index + 2; |
| 1230 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1231 | |
| 1232 | index += 1; |
| 1233 | } |
| 1234 | } |
| 1235 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1236 | case DRAW_TRIANGLEFAN: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1237 | { |
| 1238 | unsigned int index = start; |
| 1239 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1240 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1241 | { |
Alexis Hetu | 62cd2bd | 2017-12-21 13:52:00 -0500 | [diff] [blame] | 1242 | if(leadingVertexFirst) |
| 1243 | { |
| 1244 | batch[i][0] = index + 1; |
| 1245 | batch[i][1] = index + 2; |
| 1246 | batch[i][2] = 0; |
| 1247 | } |
| 1248 | else |
| 1249 | { |
| 1250 | batch[i][0] = 0; |
| 1251 | batch[i][1] = index + 1; |
| 1252 | batch[i][2] = index + 2; |
| 1253 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1254 | |
| 1255 | index += 1; |
| 1256 | } |
| 1257 | } |
| 1258 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1259 | case DRAW_INDEXEDPOINTLIST8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1260 | { |
| 1261 | const unsigned char *index = (const unsigned char*)indices + start; |
| 1262 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1263 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1264 | { |
| 1265 | batch[i][0] = *index; |
| 1266 | batch[i][1] = *index; |
| 1267 | batch[i][2] = *index; |
| 1268 | |
| 1269 | index += 1; |
| 1270 | } |
| 1271 | } |
| 1272 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1273 | case DRAW_INDEXEDPOINTLIST16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1274 | { |
| 1275 | const unsigned short *index = (const unsigned short*)indices + start; |
| 1276 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1277 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1278 | { |
| 1279 | batch[i][0] = *index; |
| 1280 | batch[i][1] = *index; |
| 1281 | batch[i][2] = *index; |
| 1282 | |
| 1283 | index += 1; |
| 1284 | } |
| 1285 | } |
| 1286 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1287 | case DRAW_INDEXEDPOINTLIST32: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1288 | { |
| 1289 | const unsigned int *index = (const unsigned int*)indices + start; |
| 1290 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1291 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1292 | { |
| 1293 | batch[i][0] = *index; |
| 1294 | batch[i][1] = *index; |
| 1295 | batch[i][2] = *index; |
| 1296 | |
| 1297 | index += 1; |
| 1298 | } |
| 1299 | } |
| 1300 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1301 | case DRAW_INDEXEDLINELIST8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1302 | { |
| 1303 | const unsigned char *index = (const unsigned char*)indices + 2 * start; |
| 1304 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1305 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1306 | { |
| 1307 | batch[i][0] = index[0]; |
| 1308 | batch[i][1] = index[1]; |
| 1309 | batch[i][2] = index[1]; |
| 1310 | |
| 1311 | index += 2; |
| 1312 | } |
| 1313 | } |
| 1314 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1315 | case DRAW_INDEXEDLINELIST16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1316 | { |
| 1317 | const unsigned short *index = (const unsigned short*)indices + 2 * start; |
| 1318 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1319 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1320 | { |
| 1321 | batch[i][0] = index[0]; |
| 1322 | batch[i][1] = index[1]; |
| 1323 | batch[i][2] = index[1]; |
| 1324 | |
| 1325 | index += 2; |
| 1326 | } |
| 1327 | } |
| 1328 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1329 | case DRAW_INDEXEDLINELIST32: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1330 | { |
| 1331 | const unsigned int *index = (const unsigned int*)indices + 2 * start; |
| 1332 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1333 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1334 | { |
| 1335 | batch[i][0] = index[0]; |
| 1336 | batch[i][1] = index[1]; |
| 1337 | batch[i][2] = index[1]; |
| 1338 | |
| 1339 | index += 2; |
| 1340 | } |
| 1341 | } |
| 1342 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1343 | case DRAW_INDEXEDLINESTRIP8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1344 | { |
| 1345 | const unsigned char *index = (const unsigned char*)indices + start; |
| 1346 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1347 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1348 | { |
| 1349 | batch[i][0] = index[0]; |
| 1350 | batch[i][1] = index[1]; |
| 1351 | batch[i][2] = index[1]; |
| 1352 | |
| 1353 | index += 1; |
| 1354 | } |
| 1355 | } |
| 1356 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1357 | case DRAW_INDEXEDLINESTRIP16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1358 | { |
| 1359 | const unsigned short *index = (const unsigned short*)indices + start; |
| 1360 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1361 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1362 | { |
| 1363 | batch[i][0] = index[0]; |
| 1364 | batch[i][1] = index[1]; |
| 1365 | batch[i][2] = index[1]; |
| 1366 | |
| 1367 | index += 1; |
| 1368 | } |
| 1369 | } |
| 1370 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1371 | case DRAW_INDEXEDLINESTRIP32: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1372 | { |
| 1373 | const unsigned int *index = (const unsigned int*)indices + start; |
| 1374 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1375 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1376 | { |
| 1377 | batch[i][0] = index[0]; |
| 1378 | batch[i][1] = index[1]; |
| 1379 | batch[i][2] = index[1]; |
| 1380 | |
| 1381 | index += 1; |
| 1382 | } |
| 1383 | } |
| 1384 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1385 | case DRAW_INDEXEDLINELOOP8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1386 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1387 | const unsigned char *index = (const unsigned char*)indices; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1388 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1389 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1390 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1391 | batch[i][0] = index[(start + i + 0) % loop]; |
| 1392 | batch[i][1] = index[(start + i + 1) % loop]; |
| 1393 | batch[i][2] = index[(start + i + 1) % loop]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1394 | } |
| 1395 | } |
| 1396 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1397 | case DRAW_INDEXEDLINELOOP16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1398 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1399 | const unsigned short *index = (const unsigned short*)indices; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1400 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1401 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1402 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1403 | batch[i][0] = index[(start + i + 0) % loop]; |
| 1404 | batch[i][1] = index[(start + i + 1) % loop]; |
| 1405 | batch[i][2] = index[(start + i + 1) % loop]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1406 | } |
| 1407 | } |
| 1408 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1409 | case DRAW_INDEXEDLINELOOP32: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1410 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1411 | const unsigned int *index = (const unsigned int*)indices; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1412 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1413 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1414 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1415 | batch[i][0] = index[(start + i + 0) % loop]; |
| 1416 | batch[i][1] = index[(start + i + 1) % loop]; |
| 1417 | batch[i][2] = index[(start + i + 1) % loop]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1421 | case DRAW_INDEXEDTRIANGLELIST8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1422 | { |
| 1423 | const unsigned char *index = (const unsigned char*)indices + 3 * start; |
| 1424 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1425 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1426 | { |
| 1427 | batch[i][0] = index[0]; |
| 1428 | batch[i][1] = index[1]; |
| 1429 | batch[i][2] = index[2]; |
| 1430 | |
| 1431 | index += 3; |
| 1432 | } |
| 1433 | } |
| 1434 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1435 | case DRAW_INDEXEDTRIANGLELIST16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1436 | { |
| 1437 | const unsigned short *index = (const unsigned short*)indices + 3 * start; |
| 1438 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1439 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1440 | { |
| 1441 | batch[i][0] = index[0]; |
| 1442 | batch[i][1] = index[1]; |
| 1443 | batch[i][2] = index[2]; |
| 1444 | |
| 1445 | index += 3; |
| 1446 | } |
| 1447 | } |
| 1448 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1449 | case DRAW_INDEXEDTRIANGLELIST32: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1450 | { |
| 1451 | const unsigned int *index = (const unsigned int*)indices + 3 * start; |
| 1452 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1453 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1454 | { |
| 1455 | batch[i][0] = index[0]; |
| 1456 | batch[i][1] = index[1]; |
| 1457 | batch[i][2] = index[2]; |
| 1458 | |
| 1459 | index += 3; |
| 1460 | } |
| 1461 | } |
| 1462 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1463 | case DRAW_INDEXEDTRIANGLESTRIP8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1464 | { |
| 1465 | const unsigned char *index = (const unsigned char*)indices + start; |
| 1466 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1467 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1468 | { |
| 1469 | batch[i][0] = index[0]; |
| 1470 | batch[i][1] = index[((start + i) & 1) + 1]; |
| 1471 | batch[i][2] = index[(~(start + i) & 1) + 1]; |
| 1472 | |
| 1473 | index += 1; |
| 1474 | } |
| 1475 | } |
| 1476 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1477 | case DRAW_INDEXEDTRIANGLESTRIP16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1478 | { |
| 1479 | const unsigned short *index = (const unsigned short*)indices + start; |
| 1480 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1481 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1482 | { |
| 1483 | batch[i][0] = index[0]; |
| 1484 | batch[i][1] = index[((start + i) & 1) + 1]; |
| 1485 | batch[i][2] = index[(~(start + i) & 1) + 1]; |
| 1486 | |
| 1487 | index += 1; |
| 1488 | } |
| 1489 | } |
| 1490 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1491 | case DRAW_INDEXEDTRIANGLESTRIP32: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1492 | { |
| 1493 | const unsigned int *index = (const unsigned int*)indices + start; |
| 1494 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1495 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1496 | { |
| 1497 | batch[i][0] = index[0]; |
| 1498 | batch[i][1] = index[((start + i) & 1) + 1]; |
| 1499 | batch[i][2] = index[(~(start + i) & 1) + 1]; |
| 1500 | |
| 1501 | index += 1; |
| 1502 | } |
| 1503 | } |
| 1504 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1505 | case DRAW_INDEXEDTRIANGLEFAN8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1506 | { |
| 1507 | const unsigned char *index = (const unsigned char*)indices; |
| 1508 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1509 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1510 | { |
| 1511 | batch[i][0] = index[start + i + 1]; |
| 1512 | batch[i][1] = index[start + i + 2]; |
| 1513 | batch[i][2] = index[0]; |
| 1514 | } |
| 1515 | } |
| 1516 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1517 | case DRAW_INDEXEDTRIANGLEFAN16: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1518 | { |
| 1519 | const unsigned short *index = (const unsigned short*)indices; |
| 1520 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1521 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1522 | { |
| 1523 | batch[i][0] = index[start + i + 1]; |
| 1524 | batch[i][1] = index[start + i + 2]; |
| 1525 | batch[i][2] = index[0]; |
| 1526 | } |
| 1527 | } |
| 1528 | break; |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1529 | case DRAW_INDEXEDTRIANGLEFAN32: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1530 | { |
| 1531 | const unsigned int *index = (const unsigned int*)indices; |
| 1532 | |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1533 | for(unsigned int i = 0; i < triangleCount; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1534 | { |
| 1535 | batch[i][0] = index[start + i + 1]; |
| 1536 | batch[i][1] = index[start + i + 2]; |
| 1537 | batch[i][2] = index[0]; |
| 1538 | } |
| 1539 | } |
| 1540 | break; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1541 | case DRAW_QUADLIST: |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1542 | { |
| 1543 | unsigned int index = 4 * start / 2; |
| 1544 | |
| 1545 | for(unsigned int i = 0; i < triangleCount; i += 2) |
| 1546 | { |
| 1547 | batch[i+0][0] = index + 0; |
| 1548 | batch[i+0][1] = index + 1; |
| 1549 | batch[i+0][2] = index + 2; |
| 1550 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1551 | batch[i+1][0] = index + 0; |
Nicolas Capens | c50d35d | 2015-01-27 01:52:41 -0500 | [diff] [blame] | 1552 | batch[i+1][1] = index + 2; |
| 1553 | batch[i+1][2] = index + 3; |
| 1554 | |
| 1555 | index += 4; |
| 1556 | } |
| 1557 | } |
| 1558 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1559 | default: |
| 1560 | ASSERT(false); |
Nicolas Capens | e5284ac | 2016-01-08 01:30:48 -0500 | [diff] [blame] | 1561 | return; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1562 | } |
| 1563 | |
Alexis Hetu | a62a0ca | 2016-04-20 15:29:51 -0400 | [diff] [blame] | 1564 | task->primitiveStart = start; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1565 | task->vertexCount = triangleCount * 3; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1566 | vertexRoutine(&triangle->v0, (unsigned int*)&batch, task, data); |
| 1567 | } |
| 1568 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1569 | int Renderer::setupSolidTriangles(int unit, int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1570 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1571 | Triangle *triangle = triangleBatch[unit]; |
| 1572 | Primitive *primitive = primitiveBatch[unit]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1573 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 1574 | DrawCall &draw = *drawList[primitiveProgress[unit].drawCall & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1575 | SetupProcessor::State &state = draw.setupState; |
| 1576 | const SetupProcessor::RoutinePointer &setupRoutine = draw.setupPointer; |
| 1577 | |
| 1578 | int ms = state.multiSample; |
| 1579 | int pos = state.positionRegister; |
| 1580 | const DrawData *data = draw.data; |
| 1581 | int visible = 0; |
| 1582 | |
| 1583 | for(int i = 0; i < count; i++, triangle++) |
| 1584 | { |
| 1585 | Vertex &v0 = triangle->v0; |
| 1586 | Vertex &v1 = triangle->v1; |
| 1587 | Vertex &v2 = triangle->v2; |
| 1588 | |
| 1589 | if((v0.clipFlags & v1.clipFlags & v2.clipFlags) == Clipper::CLIP_FINITE) |
| 1590 | { |
| 1591 | Polygon polygon(&v0.v[pos], &v1.v[pos], &v2.v[pos]); |
| 1592 | |
| 1593 | int clipFlagsOr = v0.clipFlags | v1.clipFlags | v2.clipFlags | draw.clipFlags; |
| 1594 | |
| 1595 | if(clipFlagsOr != Clipper::CLIP_FINITE) |
| 1596 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1597 | if(!clipper->clip(polygon, clipFlagsOr, draw)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1598 | { |
| 1599 | continue; |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | if(setupRoutine(primitive, triangle, &polygon, data)) |
| 1604 | { |
| 1605 | primitive += ms; |
| 1606 | visible++; |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | return visible; |
| 1612 | } |
| 1613 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1614 | int Renderer::setupWireframeTriangle(int unit, int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1615 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1616 | Triangle *triangle = triangleBatch[unit]; |
| 1617 | Primitive *primitive = primitiveBatch[unit]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1618 | int visible = 0; |
| 1619 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 1620 | DrawCall &draw = *drawList[primitiveProgress[unit].drawCall & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1621 | SetupProcessor::State &state = draw.setupState; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1622 | |
| 1623 | const Vertex &v0 = triangle[0].v0; |
| 1624 | const Vertex &v1 = triangle[0].v1; |
| 1625 | const Vertex &v2 = triangle[0].v2; |
| 1626 | |
| 1627 | float d = (v0.y * v1.x - v0.x * v1.y) * v2.w + (v0.x * v2.y - v0.y * v2.x) * v1.w + (v2.x * v1.y - v1.x * v2.y) * v0.w; |
| 1628 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1629 | if(state.cullMode == CULL_CLOCKWISE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1630 | { |
| 1631 | if(d >= 0) return 0; |
| 1632 | } |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1633 | else if(state.cullMode == CULL_COUNTERCLOCKWISE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1634 | { |
| 1635 | if(d <= 0) return 0; |
| 1636 | } |
| 1637 | |
| 1638 | // Copy attributes |
| 1639 | triangle[1].v0 = v1; |
| 1640 | triangle[1].v1 = v2; |
| 1641 | triangle[2].v0 = v2; |
| 1642 | triangle[2].v1 = v0; |
| 1643 | |
| 1644 | if(state.color[0][0].flat) // FIXME |
| 1645 | { |
| 1646 | for(int i = 0; i < 2; i++) |
| 1647 | { |
| 1648 | triangle[1].v0.C[i] = triangle[0].v0.C[i]; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1649 | triangle[1].v1.C[i] = triangle[0].v0.C[i]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1650 | triangle[2].v0.C[i] = triangle[0].v0.C[i]; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1651 | triangle[2].v1.C[i] = triangle[0].v0.C[i]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | for(int i = 0; i < 3; i++) |
| 1656 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1657 | if(setupLine(*primitive, *triangle, draw)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1658 | { |
| 1659 | primitive->area = 0.5f * d; |
| 1660 | |
| 1661 | primitive++; |
| 1662 | visible++; |
| 1663 | } |
| 1664 | |
| 1665 | triangle++; |
| 1666 | } |
| 1667 | |
| 1668 | return visible; |
| 1669 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 1670 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1671 | int Renderer::setupVertexTriangle(int unit, int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1672 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1673 | Triangle *triangle = triangleBatch[unit]; |
| 1674 | Primitive *primitive = primitiveBatch[unit]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1675 | int visible = 0; |
| 1676 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 1677 | DrawCall &draw = *drawList[primitiveProgress[unit].drawCall & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1678 | SetupProcessor::State &state = draw.setupState; |
| 1679 | |
| 1680 | const Vertex &v0 = triangle[0].v0; |
| 1681 | const Vertex &v1 = triangle[0].v1; |
| 1682 | const Vertex &v2 = triangle[0].v2; |
| 1683 | |
| 1684 | float d = (v0.y * v1.x - v0.x * v1.y) * v2.w + (v0.x * v2.y - v0.y * v2.x) * v1.w + (v2.x * v1.y - v1.x * v2.y) * v0.w; |
| 1685 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1686 | if(state.cullMode == CULL_CLOCKWISE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1687 | { |
| 1688 | if(d >= 0) return 0; |
| 1689 | } |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 1690 | else if(state.cullMode == CULL_COUNTERCLOCKWISE) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1691 | { |
| 1692 | if(d <= 0) return 0; |
| 1693 | } |
| 1694 | |
| 1695 | // Copy attributes |
| 1696 | triangle[1].v0 = v1; |
| 1697 | triangle[2].v0 = v2; |
| 1698 | |
| 1699 | for(int i = 0; i < 3; i++) |
| 1700 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1701 | if(setupPoint(*primitive, *triangle, draw)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1702 | { |
| 1703 | primitive->area = 0.5f * d; |
| 1704 | |
| 1705 | primitive++; |
| 1706 | visible++; |
| 1707 | } |
| 1708 | |
| 1709 | triangle++; |
| 1710 | } |
| 1711 | |
| 1712 | return visible; |
| 1713 | } |
| 1714 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1715 | int Renderer::setupLines(int unit, int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1716 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1717 | Triangle *triangle = triangleBatch[unit]; |
| 1718 | Primitive *primitive = primitiveBatch[unit]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1719 | int visible = 0; |
| 1720 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 1721 | DrawCall &draw = *drawList[primitiveProgress[unit].drawCall & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1722 | SetupProcessor::State &state = draw.setupState; |
| 1723 | |
| 1724 | int ms = state.multiSample; |
| 1725 | |
| 1726 | for(int i = 0; i < count; i++) |
| 1727 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1728 | if(setupLine(*primitive, *triangle, draw)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1729 | { |
| 1730 | primitive += ms; |
| 1731 | visible++; |
| 1732 | } |
| 1733 | |
| 1734 | triangle++; |
| 1735 | } |
| 1736 | |
| 1737 | return visible; |
| 1738 | } |
| 1739 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1740 | int Renderer::setupPoints(int unit, int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1741 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1742 | Triangle *triangle = triangleBatch[unit]; |
| 1743 | Primitive *primitive = primitiveBatch[unit]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1744 | int visible = 0; |
| 1745 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 1746 | DrawCall &draw = *drawList[primitiveProgress[unit].drawCall & DRAW_COUNT_BITS]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1747 | SetupProcessor::State &state = draw.setupState; |
| 1748 | |
| 1749 | int ms = state.multiSample; |
| 1750 | |
| 1751 | for(int i = 0; i < count; i++) |
| 1752 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1753 | if(setupPoint(*primitive, *triangle, draw)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1754 | { |
| 1755 | primitive += ms; |
| 1756 | visible++; |
| 1757 | } |
| 1758 | |
| 1759 | triangle++; |
| 1760 | } |
| 1761 | |
| 1762 | return visible; |
| 1763 | } |
| 1764 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1765 | bool Renderer::setupLine(Primitive &primitive, Triangle &triangle, const DrawCall &draw) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1766 | { |
| 1767 | const SetupProcessor::RoutinePointer &setupRoutine = draw.setupPointer; |
| 1768 | const SetupProcessor::State &state = draw.setupState; |
| 1769 | const DrawData &data = *draw.data; |
| 1770 | |
Nicolas Capens | 235781d | 2015-01-27 01:46:53 -0500 | [diff] [blame] | 1771 | float lineWidth = data.lineWidth; |
| 1772 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1773 | Vertex &v0 = triangle.v0; |
| 1774 | Vertex &v1 = triangle.v1; |
| 1775 | |
| 1776 | int pos = state.positionRegister; |
| 1777 | |
| 1778 | const float4 &P0 = v0.v[pos]; |
| 1779 | const float4 &P1 = v1.v[pos]; |
| 1780 | |
| 1781 | if(P0.w <= 0 && P1.w <= 0) |
| 1782 | { |
| 1783 | return false; |
| 1784 | } |
| 1785 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1786 | const float W = data.Wx16[0] * (1.0f / 16.0f); |
| 1787 | const float H = data.Hx16[0] * (1.0f / 16.0f); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1788 | |
| 1789 | float dx = W * (P1.x / P1.w - P0.x / P0.w); |
| 1790 | float dy = H * (P1.y / P1.w - P0.y / P0.w); |
| 1791 | |
| 1792 | if(dx == 0 && dy == 0) |
| 1793 | { |
| 1794 | return false; |
| 1795 | } |
| 1796 | |
Nicolas Capens | d0e4c2d | 2018-01-09 15:34:26 -0500 | [diff] [blame] | 1797 | if(state.multiSample > 1) // Rectangle |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1798 | { |
| 1799 | float4 P[4]; |
| 1800 | int C[4]; |
| 1801 | |
| 1802 | P[0] = P0; |
| 1803 | P[1] = P1; |
| 1804 | P[2] = P1; |
| 1805 | P[3] = P0; |
| 1806 | |
Nicolas Capens | 235781d | 2015-01-27 01:46:53 -0500 | [diff] [blame] | 1807 | float scale = lineWidth * 0.5f / sqrt(dx*dx + dy*dy); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1808 | |
| 1809 | dx *= scale; |
| 1810 | dy *= scale; |
| 1811 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1812 | float dx0h = dx * P0.w / H; |
| 1813 | float dy0w = dy * P0.w / W; |
| 1814 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1815 | float dx1h = dx * P1.w / H; |
| 1816 | float dy1w = dy * P1.w / W; |
| 1817 | |
Nicolas Capens | b04881b | 2018-03-16 23:23:06 -0400 | [diff] [blame] | 1818 | P[0].x += -dy0w; |
| 1819 | P[0].y += +dx0h; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1820 | C[0] = clipper->computeClipFlags(P[0]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1821 | |
Nicolas Capens | b04881b | 2018-03-16 23:23:06 -0400 | [diff] [blame] | 1822 | P[1].x += -dy1w; |
| 1823 | P[1].y += +dx1h; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1824 | C[1] = clipper->computeClipFlags(P[1]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1825 | |
Nicolas Capens | b04881b | 2018-03-16 23:23:06 -0400 | [diff] [blame] | 1826 | P[2].x += +dy1w; |
| 1827 | P[2].y += -dx1h; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1828 | C[2] = clipper->computeClipFlags(P[2]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1829 | |
Nicolas Capens | b04881b | 2018-03-16 23:23:06 -0400 | [diff] [blame] | 1830 | P[3].x += +dy0w; |
| 1831 | P[3].y += -dx0h; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1832 | C[3] = clipper->computeClipFlags(P[3]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1833 | |
| 1834 | if((C[0] & C[1] & C[2] & C[3]) == Clipper::CLIP_FINITE) |
| 1835 | { |
| 1836 | Polygon polygon(P, 4); |
| 1837 | |
| 1838 | int clipFlagsOr = C[0] | C[1] | C[2] | C[3] | draw.clipFlags; |
| 1839 | |
| 1840 | if(clipFlagsOr != Clipper::CLIP_FINITE) |
| 1841 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1842 | if(!clipper->clip(polygon, clipFlagsOr, draw)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1843 | { |
| 1844 | return false; |
| 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | return setupRoutine(&primitive, &triangle, &polygon, &data); |
| 1849 | } |
| 1850 | } |
| 1851 | else // Diamond test convention |
| 1852 | { |
| 1853 | float4 P[8]; |
| 1854 | int C[8]; |
| 1855 | |
| 1856 | P[0] = P0; |
| 1857 | P[1] = P0; |
| 1858 | P[2] = P0; |
| 1859 | P[3] = P0; |
| 1860 | P[4] = P1; |
| 1861 | P[5] = P1; |
| 1862 | P[6] = P1; |
| 1863 | P[7] = P1; |
| 1864 | |
Nicolas Capens | 235781d | 2015-01-27 01:46:53 -0500 | [diff] [blame] | 1865 | float dx0 = lineWidth * 0.5f * P0.w / W; |
| 1866 | float dy0 = lineWidth * 0.5f * P0.w / H; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1867 | |
Nicolas Capens | 235781d | 2015-01-27 01:46:53 -0500 | [diff] [blame] | 1868 | float dx1 = lineWidth * 0.5f * P1.w / W; |
| 1869 | float dy1 = lineWidth * 0.5f * P1.w / H; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1870 | |
| 1871 | P[0].x += -dx0; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1872 | C[0] = clipper->computeClipFlags(P[0]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1873 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1874 | P[1].y += +dy0; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1875 | C[1] = clipper->computeClipFlags(P[1]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1876 | |
| 1877 | P[2].x += +dx0; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1878 | C[2] = clipper->computeClipFlags(P[2]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1879 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1880 | P[3].y += -dy0; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1881 | C[3] = clipper->computeClipFlags(P[3]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1882 | |
| 1883 | P[4].x += -dx1; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1884 | C[4] = clipper->computeClipFlags(P[4]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1885 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1886 | P[5].y += +dy1; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1887 | C[5] = clipper->computeClipFlags(P[5]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1888 | |
| 1889 | P[6].x += +dx1; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1890 | C[6] = clipper->computeClipFlags(P[6]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1891 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1892 | P[7].y += -dy1; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1893 | C[7] = clipper->computeClipFlags(P[7]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1894 | |
| 1895 | if((C[0] & C[1] & C[2] & C[3] & C[4] & C[5] & C[6] & C[7]) == Clipper::CLIP_FINITE) |
| 1896 | { |
| 1897 | float4 L[6]; |
| 1898 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1899 | if(dx > -dy) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1900 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1901 | if(dx > dy) // Right |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1902 | { |
| 1903 | L[0] = P[0]; |
| 1904 | L[1] = P[1]; |
| 1905 | L[2] = P[5]; |
| 1906 | L[3] = P[6]; |
| 1907 | L[4] = P[7]; |
| 1908 | L[5] = P[3]; |
| 1909 | } |
| 1910 | else // Down |
| 1911 | { |
| 1912 | L[0] = P[0]; |
| 1913 | L[1] = P[4]; |
| 1914 | L[2] = P[5]; |
| 1915 | L[3] = P[6]; |
| 1916 | L[4] = P[2]; |
| 1917 | L[5] = P[3]; |
| 1918 | } |
| 1919 | } |
| 1920 | else |
| 1921 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1922 | if(dx > dy) // Up |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1923 | { |
| 1924 | L[0] = P[0]; |
| 1925 | L[1] = P[1]; |
| 1926 | L[2] = P[2]; |
| 1927 | L[3] = P[6]; |
| 1928 | L[4] = P[7]; |
| 1929 | L[5] = P[4]; |
| 1930 | } |
| 1931 | else // Left |
| 1932 | { |
| 1933 | L[0] = P[1]; |
| 1934 | L[1] = P[2]; |
| 1935 | L[2] = P[3]; |
| 1936 | L[3] = P[7]; |
| 1937 | L[4] = P[4]; |
| 1938 | L[5] = P[5]; |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | Polygon polygon(L, 6); |
| 1943 | |
| 1944 | int clipFlagsOr = C[0] | C[1] | C[2] | C[3] | C[4] | C[5] | C[6] | C[7] | draw.clipFlags; |
| 1945 | |
| 1946 | if(clipFlagsOr != Clipper::CLIP_FINITE) |
| 1947 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1948 | if(!clipper->clip(polygon, clipFlagsOr, draw)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1949 | { |
| 1950 | return false; |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | return setupRoutine(&primitive, &triangle, &polygon, &data); |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | return false; |
| 1959 | } |
| 1960 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 1961 | bool Renderer::setupPoint(Primitive &primitive, Triangle &triangle, const DrawCall &draw) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1962 | { |
| 1963 | const SetupProcessor::RoutinePointer &setupRoutine = draw.setupPointer; |
| 1964 | const SetupProcessor::State &state = draw.setupState; |
| 1965 | const DrawData &data = *draw.data; |
| 1966 | |
| 1967 | Vertex &v = triangle.v0; |
| 1968 | |
| 1969 | float pSize; |
| 1970 | |
| 1971 | int pts = state.pointSizeRegister; |
| 1972 | |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 1973 | if(state.pointSizeRegister != Unused) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1974 | { |
| 1975 | pSize = v.v[pts].y; |
| 1976 | } |
| 1977 | else |
| 1978 | { |
| 1979 | pSize = data.point.pointSize[0]; |
| 1980 | } |
| 1981 | |
| 1982 | pSize = clamp(pSize, data.point.pointSizeMin, data.point.pointSizeMax); |
| 1983 | |
| 1984 | float4 P[4]; |
| 1985 | int C[4]; |
| 1986 | |
| 1987 | int pos = state.positionRegister; |
| 1988 | |
| 1989 | P[0] = v.v[pos]; |
| 1990 | P[1] = v.v[pos]; |
| 1991 | P[2] = v.v[pos]; |
| 1992 | P[3] = v.v[pos]; |
| 1993 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1994 | const float X = pSize * P[0].w * data.halfPixelX[0]; |
| 1995 | const float Y = pSize * P[0].w * data.halfPixelY[0]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1996 | |
| 1997 | P[0].x -= X; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 1998 | P[0].y += Y; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 1999 | C[0] = clipper->computeClipFlags(P[0]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2000 | |
| 2001 | P[1].x += X; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2002 | P[1].y += Y; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 2003 | C[1] = clipper->computeClipFlags(P[1]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2004 | |
| 2005 | P[2].x += X; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2006 | P[2].y -= Y; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 2007 | C[2] = clipper->computeClipFlags(P[2]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2008 | |
| 2009 | P[3].x -= X; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2010 | P[3].y -= Y; |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 2011 | C[3] = clipper->computeClipFlags(P[3]); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2012 | |
| 2013 | triangle.v1 = triangle.v0; |
| 2014 | triangle.v2 = triangle.v0; |
| 2015 | |
| 2016 | triangle.v1.X += iround(16 * 0.5f * pSize); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2017 | triangle.v2.Y -= iround(16 * 0.5f * pSize) * (data.Hx16[0] > 0.0f ? 1 : -1); // Both Direct3D and OpenGL expect (0, 0) in the top-left corner |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2018 | |
| 2019 | Polygon polygon(P, 4); |
| 2020 | |
| 2021 | if((C[0] & C[1] & C[2] & C[3]) == Clipper::CLIP_FINITE) |
| 2022 | { |
| 2023 | int clipFlagsOr = C[0] | C[1] | C[2] | C[3] | draw.clipFlags; |
| 2024 | |
| 2025 | if(clipFlagsOr != Clipper::CLIP_FINITE) |
| 2026 | { |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 2027 | if(!clipper->clip(polygon, clipFlagsOr, draw)) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2028 | { |
| 2029 | return false; |
| 2030 | } |
| 2031 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2032 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2033 | return setupRoutine(&primitive, &triangle, &polygon, &data); |
| 2034 | } |
| 2035 | |
| 2036 | return false; |
| 2037 | } |
| 2038 | |
Nicolas Capens | 7381c99 | 2014-05-06 23:48:15 -0400 | [diff] [blame] | 2039 | void Renderer::initializeThreads() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2040 | { |
Nicolas Capens | 7381c99 | 2014-05-06 23:48:15 -0400 | [diff] [blame] | 2041 | unitCount = ceilPow2(threadCount); |
| 2042 | clusterCount = ceilPow2(threadCount); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2043 | |
| 2044 | for(int i = 0; i < unitCount; i++) |
| 2045 | { |
| 2046 | triangleBatch[i] = (Triangle*)allocate(batchSize * sizeof(Triangle)); |
| 2047 | primitiveBatch[i] = (Primitive*)allocate(batchSize * sizeof(Primitive)); |
| 2048 | } |
| 2049 | |
| 2050 | for(int i = 0; i < threadCount; i++) |
| 2051 | { |
| 2052 | vertexTask[i] = (VertexTask*)allocate(sizeof(VertexTask)); |
| 2053 | vertexTask[i]->vertexCache.drawCall = -1; |
| 2054 | |
| 2055 | task[i].type = Task::SUSPEND; |
| 2056 | |
| 2057 | resume[i] = new Event(); |
| 2058 | suspend[i] = new Event(); |
| 2059 | |
| 2060 | Parameters parameters; |
| 2061 | parameters.threadIndex = i; |
| 2062 | parameters.renderer = this; |
| 2063 | |
| 2064 | exitThreads = false; |
| 2065 | worker[i] = new Thread(threadFunction, ¶meters); |
| 2066 | |
| 2067 | suspend[i]->wait(); |
| 2068 | suspend[i]->signal(); |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | void Renderer::terminateThreads() |
| 2073 | { |
| 2074 | while(threadsAwake != 0) |
| 2075 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2076 | Thread::sleep(1); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | for(int thread = 0; thread < threadCount; thread++) |
| 2080 | { |
| 2081 | if(worker[thread]) |
| 2082 | { |
| 2083 | exitThreads = true; |
| 2084 | resume[thread]->signal(); |
| 2085 | worker[thread]->join(); |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2086 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2087 | delete worker[thread]; |
| 2088 | worker[thread] = 0; |
| 2089 | delete resume[thread]; |
| 2090 | resume[thread] = 0; |
| 2091 | delete suspend[thread]; |
| 2092 | suspend[thread] = 0; |
| 2093 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2094 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2095 | deallocate(vertexTask[thread]); |
| 2096 | vertexTask[thread] = 0; |
| 2097 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2098 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2099 | for(int i = 0; i < 16; i++) |
| 2100 | { |
| 2101 | deallocate(triangleBatch[i]); |
| 2102 | triangleBatch[i] = 0; |
| 2103 | |
| 2104 | deallocate(primitiveBatch[i]); |
| 2105 | primitiveBatch[i] = 0; |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | void Renderer::loadConstants(const VertexShader *vertexShader) |
| 2110 | { |
| 2111 | if(!vertexShader) return; |
| 2112 | |
Alexis Hetu | 8dcce86 | 2014-11-13 16:43:44 -0500 | [diff] [blame] | 2113 | size_t count = vertexShader->getLength(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2114 | |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 2115 | for(size_t i = 0; i < count; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2116 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2117 | const Shader::Instruction *instruction = vertexShader->getInstruction(i); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2118 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2119 | if(instruction->opcode == Shader::OPCODE_DEF) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2120 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2121 | int index = instruction->dst.index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2122 | float value[4]; |
| 2123 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2124 | value[0] = instruction->src[0].value[0]; |
| 2125 | value[1] = instruction->src[0].value[1]; |
| 2126 | value[2] = instruction->src[0].value[2]; |
| 2127 | value[3] = instruction->src[0].value[3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2128 | |
| 2129 | setVertexShaderConstantF(index, value); |
| 2130 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2131 | else if(instruction->opcode == Shader::OPCODE_DEFI) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2132 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2133 | int index = instruction->dst.index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2134 | int integer[4]; |
| 2135 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2136 | integer[0] = instruction->src[0].integer[0]; |
| 2137 | integer[1] = instruction->src[0].integer[1]; |
| 2138 | integer[2] = instruction->src[0].integer[2]; |
| 2139 | integer[3] = instruction->src[0].integer[3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2140 | |
| 2141 | setVertexShaderConstantI(index, integer); |
| 2142 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2143 | else if(instruction->opcode == Shader::OPCODE_DEFB) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2144 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2145 | int index = instruction->dst.index; |
| 2146 | int boolean = instruction->src[0].boolean[0]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2147 | |
| 2148 | setVertexShaderConstantB(index, &boolean); |
| 2149 | } |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | void Renderer::loadConstants(const PixelShader *pixelShader) |
| 2154 | { |
| 2155 | if(!pixelShader) return; |
| 2156 | |
Alexis Hetu | 8dcce86 | 2014-11-13 16:43:44 -0500 | [diff] [blame] | 2157 | size_t count = pixelShader->getLength(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2158 | |
Alexis Hetu | 903e025 | 2014-11-25 14:25:32 -0500 | [diff] [blame] | 2159 | for(size_t i = 0; i < count; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2160 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2161 | const Shader::Instruction *instruction = pixelShader->getInstruction(i); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2162 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2163 | if(instruction->opcode == Shader::OPCODE_DEF) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2164 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2165 | int index = instruction->dst.index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2166 | float value[4]; |
| 2167 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2168 | value[0] = instruction->src[0].value[0]; |
| 2169 | value[1] = instruction->src[0].value[1]; |
| 2170 | value[2] = instruction->src[0].value[2]; |
| 2171 | value[3] = instruction->src[0].value[3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2172 | |
| 2173 | setPixelShaderConstantF(index, value); |
| 2174 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2175 | else if(instruction->opcode == Shader::OPCODE_DEFI) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2176 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2177 | int index = instruction->dst.index; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2178 | int integer[4]; |
| 2179 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2180 | integer[0] = instruction->src[0].integer[0]; |
| 2181 | integer[1] = instruction->src[0].integer[1]; |
| 2182 | integer[2] = instruction->src[0].integer[2]; |
| 2183 | integer[3] = instruction->src[0].integer[3]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2184 | |
| 2185 | setPixelShaderConstantI(index, integer); |
| 2186 | } |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2187 | else if(instruction->opcode == Shader::OPCODE_DEFB) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2188 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2189 | int index = instruction->dst.index; |
| 2190 | int boolean = instruction->src[0].boolean[0]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2191 | |
| 2192 | setPixelShaderConstantB(index, &boolean); |
| 2193 | } |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | void Renderer::setIndexBuffer(Resource *indexBuffer) |
| 2198 | { |
| 2199 | context->indexBuffer = indexBuffer; |
| 2200 | } |
| 2201 | |
| 2202 | void Renderer::setMultiSampleMask(unsigned int mask) |
| 2203 | { |
| 2204 | context->sampleMask = mask; |
| 2205 | } |
| 2206 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2207 | void Renderer::setTransparencyAntialiasing(TransparencyAntialiasing transparencyAntialiasing) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2208 | { |
| 2209 | sw::transparencyAntialiasing = transparencyAntialiasing; |
| 2210 | } |
| 2211 | |
| 2212 | bool Renderer::isReadWriteTexture(int sampler) |
| 2213 | { |
Alexis Hetu | 1edcd8b | 2015-11-05 11:12:41 -0500 | [diff] [blame] | 2214 | for(int index = 0; index < RENDERTARGETS; index++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2215 | { |
| 2216 | if(context->renderTarget[index] && context->texture[sampler] == context->renderTarget[index]->getResource()) |
| 2217 | { |
| 2218 | return true; |
| 2219 | } |
| 2220 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2221 | |
Nicolas Capens | 3751c1e | 2016-03-21 14:14:14 -0400 | [diff] [blame] | 2222 | if(context->depthBuffer && context->texture[sampler] == context->depthBuffer->getResource()) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2223 | { |
| 2224 | return true; |
| 2225 | } |
| 2226 | |
| 2227 | return false; |
| 2228 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2229 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2230 | void Renderer::updateClipper() |
| 2231 | { |
| 2232 | if(updateClipPlanes) |
| 2233 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2234 | if(VertexProcessor::isFixedFunction()) // User plane in world space |
| 2235 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2236 | const Matrix &scissorWorld = getViewTransform(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2237 | |
| 2238 | if(clipFlags & Clipper::CLIP_PLANE0) clipPlane[0] = scissorWorld * userPlane[0]; |
| 2239 | if(clipFlags & Clipper::CLIP_PLANE1) clipPlane[1] = scissorWorld * userPlane[1]; |
| 2240 | if(clipFlags & Clipper::CLIP_PLANE2) clipPlane[2] = scissorWorld * userPlane[2]; |
| 2241 | if(clipFlags & Clipper::CLIP_PLANE3) clipPlane[3] = scissorWorld * userPlane[3]; |
| 2242 | if(clipFlags & Clipper::CLIP_PLANE4) clipPlane[4] = scissorWorld * userPlane[4]; |
| 2243 | if(clipFlags & Clipper::CLIP_PLANE5) clipPlane[5] = scissorWorld * userPlane[5]; |
| 2244 | } |
| 2245 | else // User plane in clip space |
| 2246 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2247 | if(clipFlags & Clipper::CLIP_PLANE0) clipPlane[0] = userPlane[0]; |
| 2248 | if(clipFlags & Clipper::CLIP_PLANE1) clipPlane[1] = userPlane[1]; |
| 2249 | if(clipFlags & Clipper::CLIP_PLANE2) clipPlane[2] = userPlane[2]; |
| 2250 | if(clipFlags & Clipper::CLIP_PLANE3) clipPlane[3] = userPlane[3]; |
| 2251 | if(clipFlags & Clipper::CLIP_PLANE4) clipPlane[4] = userPlane[4]; |
| 2252 | if(clipFlags & Clipper::CLIP_PLANE5) clipPlane[5] = userPlane[5]; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | updateClipPlanes = false; |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | void Renderer::setTextureResource(unsigned int sampler, Resource *resource) |
| 2260 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 2261 | ASSERT(sampler < TOTAL_IMAGE_UNITS); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2262 | |
| 2263 | context->texture[sampler] = resource; |
| 2264 | } |
| 2265 | |
| 2266 | void Renderer::setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type) |
| 2267 | { |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 2268 | ASSERT(sampler < TOTAL_IMAGE_UNITS && face < 6 && level < MIPMAP_LEVELS); |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2269 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2270 | context->sampler[sampler].setTextureLevel(face, level, surface, type); |
| 2271 | } |
| 2272 | |
| 2273 | void Renderer::setTextureFilter(SamplerType type, int sampler, FilterType textureFilter) |
| 2274 | { |
| 2275 | if(type == SAMPLER_PIXEL) |
| 2276 | { |
| 2277 | PixelProcessor::setTextureFilter(sampler, textureFilter); |
| 2278 | } |
| 2279 | else |
| 2280 | { |
| 2281 | VertexProcessor::setTextureFilter(sampler, textureFilter); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | void Renderer::setMipmapFilter(SamplerType type, int sampler, MipmapType mipmapFilter) |
| 2286 | { |
| 2287 | if(type == SAMPLER_PIXEL) |
| 2288 | { |
| 2289 | PixelProcessor::setMipmapFilter(sampler, mipmapFilter); |
| 2290 | } |
| 2291 | else |
| 2292 | { |
| 2293 | VertexProcessor::setMipmapFilter(sampler, mipmapFilter); |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | void Renderer::setGatherEnable(SamplerType type, int sampler, bool enable) |
| 2298 | { |
| 2299 | if(type == SAMPLER_PIXEL) |
| 2300 | { |
| 2301 | PixelProcessor::setGatherEnable(sampler, enable); |
| 2302 | } |
| 2303 | else |
| 2304 | { |
| 2305 | VertexProcessor::setGatherEnable(sampler, enable); |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | void Renderer::setAddressingModeU(SamplerType type, int sampler, AddressingMode addressMode) |
| 2310 | { |
| 2311 | if(type == SAMPLER_PIXEL) |
| 2312 | { |
| 2313 | PixelProcessor::setAddressingModeU(sampler, addressMode); |
| 2314 | } |
| 2315 | else |
| 2316 | { |
| 2317 | VertexProcessor::setAddressingModeU(sampler, addressMode); |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | void Renderer::setAddressingModeV(SamplerType type, int sampler, AddressingMode addressMode) |
| 2322 | { |
| 2323 | if(type == SAMPLER_PIXEL) |
| 2324 | { |
| 2325 | PixelProcessor::setAddressingModeV(sampler, addressMode); |
| 2326 | } |
| 2327 | else |
| 2328 | { |
| 2329 | VertexProcessor::setAddressingModeV(sampler, addressMode); |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | void Renderer::setAddressingModeW(SamplerType type, int sampler, AddressingMode addressMode) |
| 2334 | { |
| 2335 | if(type == SAMPLER_PIXEL) |
| 2336 | { |
| 2337 | PixelProcessor::setAddressingModeW(sampler, addressMode); |
| 2338 | } |
| 2339 | else |
| 2340 | { |
| 2341 | VertexProcessor::setAddressingModeW(sampler, addressMode); |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | void Renderer::setReadSRGB(SamplerType type, int sampler, bool sRGB) |
| 2346 | { |
| 2347 | if(type == SAMPLER_PIXEL) |
| 2348 | { |
| 2349 | PixelProcessor::setReadSRGB(sampler, sRGB); |
| 2350 | } |
| 2351 | else |
| 2352 | { |
| 2353 | VertexProcessor::setReadSRGB(sampler, sRGB); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | void Renderer::setMipmapLOD(SamplerType type, int sampler, float bias) |
| 2358 | { |
| 2359 | if(type == SAMPLER_PIXEL) |
| 2360 | { |
| 2361 | PixelProcessor::setMipmapLOD(sampler, bias); |
| 2362 | } |
| 2363 | else |
| 2364 | { |
| 2365 | VertexProcessor::setMipmapLOD(sampler, bias); |
| 2366 | } |
| 2367 | } |
| 2368 | |
| 2369 | void Renderer::setBorderColor(SamplerType type, int sampler, const Color<float> &borderColor) |
| 2370 | { |
| 2371 | if(type == SAMPLER_PIXEL) |
| 2372 | { |
| 2373 | PixelProcessor::setBorderColor(sampler, borderColor); |
| 2374 | } |
| 2375 | else |
| 2376 | { |
| 2377 | VertexProcessor::setBorderColor(sampler, borderColor); |
| 2378 | } |
| 2379 | } |
| 2380 | |
Alexis Hetu | 617a5d5 | 2014-11-13 10:56:20 -0500 | [diff] [blame] | 2381 | void Renderer::setMaxAnisotropy(SamplerType type, int sampler, float maxAnisotropy) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2382 | { |
| 2383 | if(type == SAMPLER_PIXEL) |
| 2384 | { |
| 2385 | PixelProcessor::setMaxAnisotropy(sampler, maxAnisotropy); |
| 2386 | } |
| 2387 | else |
| 2388 | { |
| 2389 | VertexProcessor::setMaxAnisotropy(sampler, maxAnisotropy); |
| 2390 | } |
| 2391 | } |
| 2392 | |
Alexis Hetu | 010a464 | 2017-07-18 14:33:04 -0400 | [diff] [blame] | 2393 | void Renderer::setHighPrecisionFiltering(SamplerType type, int sampler, bool highPrecisionFiltering) |
| 2394 | { |
| 2395 | if(type == SAMPLER_PIXEL) |
| 2396 | { |
| 2397 | PixelProcessor::setHighPrecisionFiltering(sampler, highPrecisionFiltering); |
| 2398 | } |
| 2399 | else |
| 2400 | { |
| 2401 | VertexProcessor::setHighPrecisionFiltering(sampler, highPrecisionFiltering); |
| 2402 | } |
| 2403 | } |
| 2404 | |
Alexis Hetu | 1d01aa3 | 2015-09-29 11:50:05 -0400 | [diff] [blame] | 2405 | void Renderer::setSwizzleR(SamplerType type, int sampler, SwizzleType swizzleR) |
| 2406 | { |
| 2407 | if(type == SAMPLER_PIXEL) |
| 2408 | { |
| 2409 | PixelProcessor::setSwizzleR(sampler, swizzleR); |
| 2410 | } |
| 2411 | else |
| 2412 | { |
| 2413 | VertexProcessor::setSwizzleR(sampler, swizzleR); |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | void Renderer::setSwizzleG(SamplerType type, int sampler, SwizzleType swizzleG) |
| 2418 | { |
| 2419 | if(type == SAMPLER_PIXEL) |
| 2420 | { |
| 2421 | PixelProcessor::setSwizzleG(sampler, swizzleG); |
| 2422 | } |
| 2423 | else |
| 2424 | { |
| 2425 | VertexProcessor::setSwizzleG(sampler, swizzleG); |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | void Renderer::setSwizzleB(SamplerType type, int sampler, SwizzleType swizzleB) |
| 2430 | { |
| 2431 | if(type == SAMPLER_PIXEL) |
| 2432 | { |
| 2433 | PixelProcessor::setSwizzleB(sampler, swizzleB); |
| 2434 | } |
| 2435 | else |
| 2436 | { |
| 2437 | VertexProcessor::setSwizzleB(sampler, swizzleB); |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | void Renderer::setSwizzleA(SamplerType type, int sampler, SwizzleType swizzleA) |
| 2442 | { |
| 2443 | if(type == SAMPLER_PIXEL) |
| 2444 | { |
| 2445 | PixelProcessor::setSwizzleA(sampler, swizzleA); |
| 2446 | } |
| 2447 | else |
| 2448 | { |
| 2449 | VertexProcessor::setSwizzleA(sampler, swizzleA); |
| 2450 | } |
| 2451 | } |
| 2452 | |
Nicolas Capens | f878d50 | 2017-11-06 15:29:46 -0500 | [diff] [blame] | 2453 | void Renderer::setCompareFunc(SamplerType type, int sampler, CompareFunc compFunc) |
| 2454 | { |
| 2455 | if(type == SAMPLER_PIXEL) |
| 2456 | { |
| 2457 | PixelProcessor::setCompareFunc(sampler, compFunc); |
| 2458 | } |
| 2459 | else |
| 2460 | { |
| 2461 | VertexProcessor::setCompareFunc(sampler, compFunc); |
| 2462 | } |
| 2463 | } |
| 2464 | |
Alexis Hetu | 95ac187 | 2016-06-06 13:26:52 -0400 | [diff] [blame] | 2465 | void Renderer::setBaseLevel(SamplerType type, int sampler, int baseLevel) |
| 2466 | { |
| 2467 | if(type == SAMPLER_PIXEL) |
| 2468 | { |
| 2469 | PixelProcessor::setBaseLevel(sampler, baseLevel); |
| 2470 | } |
| 2471 | else |
| 2472 | { |
| 2473 | VertexProcessor::setBaseLevel(sampler, baseLevel); |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | void Renderer::setMaxLevel(SamplerType type, int sampler, int maxLevel) |
| 2478 | { |
| 2479 | if(type == SAMPLER_PIXEL) |
| 2480 | { |
| 2481 | PixelProcessor::setMaxLevel(sampler, maxLevel); |
| 2482 | } |
| 2483 | else |
| 2484 | { |
| 2485 | VertexProcessor::setMaxLevel(sampler, maxLevel); |
| 2486 | } |
| 2487 | } |
| 2488 | |
Alexis Hetu | 112d81f | 2016-06-07 12:36:35 -0400 | [diff] [blame] | 2489 | void Renderer::setMinLod(SamplerType type, int sampler, float minLod) |
| 2490 | { |
| 2491 | if(type == SAMPLER_PIXEL) |
| 2492 | { |
| 2493 | PixelProcessor::setMinLod(sampler, minLod); |
| 2494 | } |
| 2495 | else |
| 2496 | { |
| 2497 | VertexProcessor::setMinLod(sampler, minLod); |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | void Renderer::setMaxLod(SamplerType type, int sampler, float maxLod) |
| 2502 | { |
| 2503 | if(type == SAMPLER_PIXEL) |
| 2504 | { |
| 2505 | PixelProcessor::setMaxLod(sampler, maxLod); |
| 2506 | } |
| 2507 | else |
| 2508 | { |
| 2509 | VertexProcessor::setMaxLod(sampler, maxLod); |
| 2510 | } |
| 2511 | } |
| 2512 | |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 2513 | void Renderer::setSyncRequired(SamplerType type, int sampler, bool syncRequired) |
| 2514 | { |
| 2515 | if(type == SAMPLER_PIXEL) |
| 2516 | { |
| 2517 | PixelProcessor::setSyncRequired(sampler, syncRequired); |
| 2518 | } |
| 2519 | else |
| 2520 | { |
| 2521 | VertexProcessor::setSyncRequired(sampler, syncRequired); |
| 2522 | } |
| 2523 | } |
| 2524 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2525 | void Renderer::setPointSpriteEnable(bool pointSpriteEnable) |
| 2526 | { |
| 2527 | context->setPointSpriteEnable(pointSpriteEnable); |
| 2528 | } |
| 2529 | |
| 2530 | void Renderer::setPointScaleEnable(bool pointScaleEnable) |
| 2531 | { |
| 2532 | context->setPointScaleEnable(pointScaleEnable); |
| 2533 | } |
| 2534 | |
Nicolas Capens | 235781d | 2015-01-27 01:46:53 -0500 | [diff] [blame] | 2535 | void Renderer::setLineWidth(float width) |
| 2536 | { |
| 2537 | context->lineWidth = width; |
| 2538 | } |
| 2539 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2540 | void Renderer::setDepthBias(float bias) |
| 2541 | { |
Nicolas Capens | 3cbeac5 | 2017-09-15 11:49:31 -0400 | [diff] [blame] | 2542 | context->depthBias = bias; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | void Renderer::setSlopeDepthBias(float slopeBias) |
| 2546 | { |
Nicolas Capens | 3cbeac5 | 2017-09-15 11:49:31 -0400 | [diff] [blame] | 2547 | context->slopeDepthBias = slopeBias; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2548 | } |
| 2549 | |
Alexis Hetu | b0f247f | 2016-02-22 11:42:39 -0500 | [diff] [blame] | 2550 | void Renderer::setRasterizerDiscard(bool rasterizerDiscard) |
| 2551 | { |
| 2552 | context->rasterizerDiscard = rasterizerDiscard; |
| 2553 | } |
| 2554 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2555 | void Renderer::setPixelShader(const PixelShader *shader) |
| 2556 | { |
| 2557 | context->pixelShader = shader; |
| 2558 | |
| 2559 | loadConstants(shader); |
| 2560 | } |
| 2561 | |
| 2562 | void Renderer::setVertexShader(const VertexShader *shader) |
| 2563 | { |
| 2564 | context->vertexShader = shader; |
| 2565 | |
| 2566 | loadConstants(shader); |
| 2567 | } |
| 2568 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2569 | void Renderer::setPixelShaderConstantF(unsigned int index, const float value[4], unsigned int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2570 | { |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2571 | for(unsigned int i = 0; i < DRAW_COUNT; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2572 | { |
| 2573 | if(drawCall[i]->psDirtyConstF < index + count) |
| 2574 | { |
| 2575 | drawCall[i]->psDirtyConstF = index + count; |
| 2576 | } |
| 2577 | } |
| 2578 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2579 | for(unsigned int i = 0; i < count; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2580 | { |
| 2581 | PixelProcessor::setFloatConstant(index + i, value); |
| 2582 | value += 4; |
| 2583 | } |
| 2584 | } |
| 2585 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2586 | void Renderer::setPixelShaderConstantI(unsigned int index, const int value[4], unsigned int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2587 | { |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2588 | for(unsigned int i = 0; i < DRAW_COUNT; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2589 | { |
| 2590 | if(drawCall[i]->psDirtyConstI < index + count) |
| 2591 | { |
| 2592 | drawCall[i]->psDirtyConstI = index + count; |
| 2593 | } |
| 2594 | } |
| 2595 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2596 | for(unsigned int i = 0; i < count; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2597 | { |
| 2598 | PixelProcessor::setIntegerConstant(index + i, value); |
| 2599 | value += 4; |
| 2600 | } |
| 2601 | } |
| 2602 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2603 | void Renderer::setPixelShaderConstantB(unsigned int index, const int *boolean, unsigned int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2604 | { |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2605 | for(unsigned int i = 0; i < DRAW_COUNT; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2606 | { |
| 2607 | if(drawCall[i]->psDirtyConstB < index + count) |
| 2608 | { |
| 2609 | drawCall[i]->psDirtyConstB = index + count; |
| 2610 | } |
| 2611 | } |
| 2612 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2613 | for(unsigned int i = 0; i < count; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2614 | { |
| 2615 | PixelProcessor::setBooleanConstant(index + i, *boolean); |
| 2616 | boolean++; |
| 2617 | } |
| 2618 | } |
| 2619 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2620 | void Renderer::setVertexShaderConstantF(unsigned int index, const float value[4], unsigned int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2621 | { |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2622 | for(unsigned int i = 0; i < DRAW_COUNT; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2623 | { |
| 2624 | if(drawCall[i]->vsDirtyConstF < index + count) |
| 2625 | { |
| 2626 | drawCall[i]->vsDirtyConstF = index + count; |
| 2627 | } |
| 2628 | } |
| 2629 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2630 | for(unsigned int i = 0; i < count; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2631 | { |
| 2632 | VertexProcessor::setFloatConstant(index + i, value); |
| 2633 | value += 4; |
| 2634 | } |
| 2635 | } |
| 2636 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2637 | void Renderer::setVertexShaderConstantI(unsigned int index, const int value[4], unsigned int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2638 | { |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2639 | for(unsigned int i = 0; i < DRAW_COUNT; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2640 | { |
| 2641 | if(drawCall[i]->vsDirtyConstI < index + count) |
| 2642 | { |
| 2643 | drawCall[i]->vsDirtyConstI = index + count; |
| 2644 | } |
| 2645 | } |
| 2646 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2647 | for(unsigned int i = 0; i < count; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2648 | { |
| 2649 | VertexProcessor::setIntegerConstant(index + i, value); |
| 2650 | value += 4; |
| 2651 | } |
| 2652 | } |
| 2653 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2654 | void Renderer::setVertexShaderConstantB(unsigned int index, const int *boolean, unsigned int count) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2655 | { |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2656 | for(unsigned int i = 0; i < DRAW_COUNT; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2657 | { |
| 2658 | if(drawCall[i]->vsDirtyConstB < index + count) |
| 2659 | { |
| 2660 | drawCall[i]->vsDirtyConstB = index + count; |
| 2661 | } |
| 2662 | } |
| 2663 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 2664 | for(unsigned int i = 0; i < count; i++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2665 | { |
| 2666 | VertexProcessor::setBooleanConstant(index + i, *boolean); |
| 2667 | boolean++; |
| 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | void Renderer::setModelMatrix(const Matrix &M, int i) |
| 2672 | { |
| 2673 | VertexProcessor::setModelMatrix(M, i); |
| 2674 | } |
| 2675 | |
| 2676 | void Renderer::setViewMatrix(const Matrix &V) |
| 2677 | { |
| 2678 | VertexProcessor::setViewMatrix(V); |
| 2679 | updateClipPlanes = true; |
| 2680 | } |
| 2681 | |
| 2682 | void Renderer::setBaseMatrix(const Matrix &B) |
| 2683 | { |
| 2684 | VertexProcessor::setBaseMatrix(B); |
| 2685 | updateClipPlanes = true; |
| 2686 | } |
| 2687 | |
| 2688 | void Renderer::setProjectionMatrix(const Matrix &P) |
| 2689 | { |
| 2690 | VertexProcessor::setProjectionMatrix(P); |
| 2691 | updateClipPlanes = true; |
| 2692 | } |
| 2693 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2694 | void Renderer::addQuery(Query *query) |
| 2695 | { |
| 2696 | queries.push_back(query); |
| 2697 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2698 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2699 | void Renderer::removeQuery(Query *query) |
| 2700 | { |
| 2701 | queries.remove(query); |
| 2702 | } |
| 2703 | |
| 2704 | #if PERF_HUD |
| 2705 | int Renderer::getThreadCount() |
| 2706 | { |
| 2707 | return threadCount; |
| 2708 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2709 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2710 | int64_t Renderer::getVertexTime(int thread) |
| 2711 | { |
| 2712 | return vertexTime[thread]; |
| 2713 | } |
| 2714 | |
| 2715 | int64_t Renderer::getSetupTime(int thread) |
| 2716 | { |
| 2717 | return setupTime[thread]; |
| 2718 | } |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 2719 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2720 | int64_t Renderer::getPixelTime(int thread) |
| 2721 | { |
| 2722 | return pixelTime[thread]; |
| 2723 | } |
| 2724 | |
| 2725 | void Renderer::resetTimers() |
| 2726 | { |
| 2727 | for(int thread = 0; thread < threadCount; thread++) |
| 2728 | { |
| 2729 | vertexTime[thread] = 0; |
| 2730 | setupTime[thread] = 0; |
| 2731 | pixelTime[thread] = 0; |
| 2732 | } |
| 2733 | } |
| 2734 | #endif |
| 2735 | |
| 2736 | void Renderer::setViewport(const Viewport &viewport) |
| 2737 | { |
| 2738 | this->viewport = viewport; |
| 2739 | } |
| 2740 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 2741 | void Renderer::setScissor(const Rect &scissor) |
| 2742 | { |
| 2743 | this->scissor = scissor; |
| 2744 | } |
| 2745 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2746 | void Renderer::setClipFlags(int flags) |
| 2747 | { |
| 2748 | clipFlags = flags << 8; // Bottom 8 bits used by legacy frustum |
| 2749 | } |
| 2750 | |
| 2751 | void Renderer::setClipPlane(unsigned int index, const float plane[4]) |
| 2752 | { |
Nicolas Capens | d226414 | 2015-07-02 17:06:53 -0400 | [diff] [blame] | 2753 | if(index < MAX_CLIP_PLANES) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2754 | { |
| 2755 | userPlane[index] = plane; |
| 2756 | } |
| 2757 | else ASSERT(false); |
| 2758 | |
| 2759 | updateClipPlanes = true; |
| 2760 | } |
| 2761 | |
| 2762 | void Renderer::updateConfiguration(bool initialUpdate) |
| 2763 | { |
| 2764 | bool newConfiguration = swiftConfig->hasNewConfiguration(); |
| 2765 | |
| 2766 | if(newConfiguration || initialUpdate) |
| 2767 | { |
| 2768 | terminateThreads(); |
| 2769 | |
Nicolas Capens | c4748c5 | 2016-01-01 01:21:18 -0500 | [diff] [blame] | 2770 | SwiftConfig::Configuration configuration = {}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2771 | swiftConfig->getConfiguration(configuration); |
| 2772 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2773 | precacheVertex = !newConfiguration && configuration.precache; |
| 2774 | precacheSetup = !newConfiguration && configuration.precache; |
| 2775 | precachePixel = !newConfiguration && configuration.precache; |
| 2776 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2777 | VertexProcessor::setRoutineCacheSize(configuration.vertexRoutineCacheSize); |
| 2778 | PixelProcessor::setRoutineCacheSize(configuration.pixelRoutineCacheSize); |
| 2779 | SetupProcessor::setRoutineCacheSize(configuration.setupRoutineCacheSize); |
| 2780 | |
| 2781 | switch(configuration.textureSampleQuality) |
| 2782 | { |
Nicolas Capens | 7381c99 | 2014-05-06 23:48:15 -0400 | [diff] [blame] | 2783 | case 0: Sampler::setFilterQuality(FILTER_POINT); break; |
| 2784 | case 1: Sampler::setFilterQuality(FILTER_LINEAR); break; |
| 2785 | case 2: Sampler::setFilterQuality(FILTER_ANISOTROPIC); break; |
| 2786 | default: Sampler::setFilterQuality(FILTER_ANISOTROPIC); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | switch(configuration.mipmapQuality) |
| 2790 | { |
| 2791 | case 0: Sampler::setMipmapQuality(MIPMAP_POINT); break; |
| 2792 | case 1: Sampler::setMipmapQuality(MIPMAP_LINEAR); break; |
Nicolas Capens | 7381c99 | 2014-05-06 23:48:15 -0400 | [diff] [blame] | 2793 | default: Sampler::setMipmapQuality(MIPMAP_LINEAR); break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | setPerspectiveCorrection(configuration.perspectiveCorrection); |
| 2797 | |
| 2798 | switch(configuration.transcendentalPrecision) |
| 2799 | { |
| 2800 | case 0: |
| 2801 | logPrecision = APPROXIMATE; |
| 2802 | expPrecision = APPROXIMATE; |
| 2803 | rcpPrecision = APPROXIMATE; |
| 2804 | rsqPrecision = APPROXIMATE; |
| 2805 | break; |
| 2806 | case 1: |
| 2807 | logPrecision = PARTIAL; |
| 2808 | expPrecision = PARTIAL; |
| 2809 | rcpPrecision = PARTIAL; |
| 2810 | rsqPrecision = PARTIAL; |
| 2811 | break; |
| 2812 | case 2: |
| 2813 | logPrecision = ACCURATE; |
| 2814 | expPrecision = ACCURATE; |
| 2815 | rcpPrecision = ACCURATE; |
| 2816 | rsqPrecision = ACCURATE; |
| 2817 | break; |
| 2818 | case 3: |
| 2819 | logPrecision = WHQL; |
| 2820 | expPrecision = WHQL; |
| 2821 | rcpPrecision = WHQL; |
| 2822 | rsqPrecision = WHQL; |
| 2823 | break; |
| 2824 | case 4: |
| 2825 | logPrecision = IEEE; |
| 2826 | expPrecision = IEEE; |
| 2827 | rcpPrecision = IEEE; |
| 2828 | rsqPrecision = IEEE; |
| 2829 | break; |
| 2830 | default: |
| 2831 | logPrecision = ACCURATE; |
| 2832 | expPrecision = ACCURATE; |
| 2833 | rcpPrecision = ACCURATE; |
| 2834 | rsqPrecision = ACCURATE; |
| 2835 | break; |
| 2836 | } |
| 2837 | |
| 2838 | switch(configuration.transparencyAntialiasing) |
| 2839 | { |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 2840 | case 0: transparencyAntialiasing = TRANSPARENCY_NONE; break; |
| 2841 | case 1: transparencyAntialiasing = TRANSPARENCY_ALPHA_TO_COVERAGE; break; |
| 2842 | default: transparencyAntialiasing = TRANSPARENCY_NONE; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | switch(configuration.threadCount) |
| 2846 | { |
Nicolas Capens | 7381c99 | 2014-05-06 23:48:15 -0400 | [diff] [blame] | 2847 | case -1: threadCount = CPUID::coreCount(); break; |
| 2848 | case 0: threadCount = CPUID::processAffinity(); break; |
| 2849 | default: threadCount = configuration.threadCount; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | CPUID::setEnableSSE4_1(configuration.enableSSE4_1); |
| 2853 | CPUID::setEnableSSSE3(configuration.enableSSSE3); |
| 2854 | CPUID::setEnableSSE3(configuration.enableSSE3); |
| 2855 | CPUID::setEnableSSE2(configuration.enableSSE2); |
| 2856 | CPUID::setEnableSSE(configuration.enableSSE); |
| 2857 | |
| 2858 | for(int pass = 0; pass < 10; pass++) |
| 2859 | { |
| 2860 | optimization[pass] = configuration.optimization[pass]; |
| 2861 | } |
| 2862 | |
| 2863 | forceWindowed = configuration.forceWindowed; |
| 2864 | complementaryDepthBuffer = configuration.complementaryDepthBuffer; |
| 2865 | postBlendSRGB = configuration.postBlendSRGB; |
| 2866 | exactColorRounding = configuration.exactColorRounding; |
| 2867 | forceClearRegisters = configuration.forceClearRegisters; |
| 2868 | |
| 2869 | #ifndef NDEBUG |
| 2870 | minPrimitives = configuration.minPrimitives; |
| 2871 | maxPrimitives = configuration.maxPrimitives; |
| 2872 | #endif |
| 2873 | } |
Nicolas Capens | 7381c99 | 2014-05-06 23:48:15 -0400 | [diff] [blame] | 2874 | |
| 2875 | if(!initialUpdate && !worker[0]) |
| 2876 | { |
| 2877 | initializeThreads(); |
| 2878 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2879 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2880 | } |