blob: d8f1be2cc692c9943c3d18146a91b76291ed09ba [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman89401822014-05-06 15:04:28 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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 Bauman89401822014-05-06 15:04:28 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman89401822014-05-06 15:04:28 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// 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 Bauman89401822014-05-06 15:04:28 -040014
15#include "PixelProcessor.hpp"
16
Alexis Hetuf2a8c372015-07-13 11:08:41 -040017#include "PixelPipeline.hpp"
18#include "PixelProgram.hpp"
John Bauman89401822014-05-06 15:04:28 -040019#include "PixelShader.hpp"
20#include "MetaMacro.hpp"
21#include "Surface.hpp"
22#include "Primitive.hpp"
23#include "Constants.hpp"
24#include "Debug.hpp"
25
John Bauman66b8ab22014-05-06 15:57:45 -040026#include <string.h>
27
John Bauman89401822014-05-06 15:04:28 -040028namespace sw
29{
30 extern bool complementaryDepthBuffer;
Nicolas Capensa0f4be82014-10-22 14:35:30 -040031 extern TransparencyAntialiasing transparencyAntialiasing;
John Bauman89401822014-05-06 15:04:28 -040032 extern bool perspectiveCorrection;
33
John Bauman66b8ab22014-05-06 15:57:45 -040034 bool precachePixel = false;
35
John Bauman89401822014-05-06 15:04:28 -040036 unsigned int PixelProcessor::States::computeHash()
37 {
38 unsigned int *state = (unsigned int*)this;
39 unsigned int hash = 0;
40
Nicolas Capens5d961882016-01-01 23:18:14 -050041 for(unsigned int i = 0; i < sizeof(States) / 4; i++)
John Bauman89401822014-05-06 15:04:28 -040042 {
43 hash ^= state[i];
44 }
45
46 return hash;
47 }
48
49 PixelProcessor::State::State()
50 {
51 memset(this, 0, sizeof(State));
52 }
53
54 bool PixelProcessor::State::operator==(const State &state) const
55 {
56 if(hash != state.hash)
57 {
58 return false;
59 }
60
61 return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
62 }
63
Alexis Hetuc6a57cb2016-04-07 10:48:31 -040064 PixelProcessor::UniformBufferInfo::UniformBufferInfo()
65 {
66 buffer = nullptr;
67 offset = 0;
68 }
69
John Bauman89401822014-05-06 15:04:28 -040070 PixelProcessor::PixelProcessor(Context *context) : context(context)
71 {
72 setGlobalMipmapBias(0.0f); // Round to highest LOD [0.5, 1.0]: -0.5
73 // Round to nearest LOD [0.7, 1.4]: 0.0
74 // Round to lowest LOD [1.0, 2.0]: 0.5
75
76 routineCache = 0;
77 setRoutineCacheSize(1024);
78 }
79
80 PixelProcessor::~PixelProcessor()
81 {
82 delete routineCache;
83 routineCache = 0;
84 }
85
86 void PixelProcessor::setFloatConstant(unsigned int index, const float value[4])
87 {
Alexis Hetu04c967a2015-07-08 15:56:17 -040088 if(index < FRAGMENT_UNIFORM_VECTORS)
John Bauman89401822014-05-06 15:04:28 -040089 {
90 c[index][0] = value[0];
91 c[index][1] = value[1];
92 c[index][2] = value[2];
93 c[index][3] = value[3];
94 }
95 else ASSERT(false);
96
97 if(index < 8) // ps_1_x constants
98 {
99 // FIXME: Compact into generic function
100 short x = iround(4095 * clamp(value[0], -1.0f, 1.0f));
101 short y = iround(4095 * clamp(value[1], -1.0f, 1.0f));
102 short z = iround(4095 * clamp(value[2], -1.0f, 1.0f));
103 short w = iround(4095 * clamp(value[3], -1.0f, 1.0f));
104
105 cW[index][0][0] = x;
106 cW[index][0][1] = x;
107 cW[index][0][2] = x;
108 cW[index][0][3] = x;
109
110 cW[index][1][0] = y;
111 cW[index][1][1] = y;
112 cW[index][1][2] = y;
113 cW[index][1][3] = y;
114
115 cW[index][2][0] = z;
116 cW[index][2][1] = z;
117 cW[index][2][2] = z;
118 cW[index][2][3] = z;
119
120 cW[index][3][0] = w;
121 cW[index][3][1] = w;
122 cW[index][3][2] = w;
123 cW[index][3][3] = w;
124 }
125 }
126
127 void PixelProcessor::setIntegerConstant(unsigned int index, const int value[4])
128 {
129 if(index < 16)
130 {
131 i[index][0] = value[0];
132 i[index][1] = value[1];
133 i[index][2] = value[2];
134 i[index][3] = value[3];
135 }
136 else ASSERT(false);
137 }
138
139 void PixelProcessor::setBooleanConstant(unsigned int index, int boolean)
140 {
141 if(index < 16)
142 {
143 b[index] = boolean != 0;
144 }
145 else ASSERT(false);
146 }
147
Alexis Hetu2c2a7b22015-10-27 16:12:11 -0400148 void PixelProcessor::setUniformBuffer(int index, sw::Resource* buffer, int offset)
149 {
Alexis Hetuc6a57cb2016-04-07 10:48:31 -0400150 uniformBufferInfo[index].buffer = buffer;
151 uniformBufferInfo[index].offset = offset;
Alexis Hetu2c2a7b22015-10-27 16:12:11 -0400152 }
153
Alexis Hetuc6a57cb2016-04-07 10:48:31 -0400154 void PixelProcessor::lockUniformBuffers(byte** u, sw::Resource* uniformBuffers[])
Alexis Hetu2c2a7b22015-10-27 16:12:11 -0400155 {
156 for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; ++i)
157 {
Alexis Hetuc6a57cb2016-04-07 10:48:31 -0400158 u[i] = uniformBufferInfo[i].buffer ? static_cast<byte*>(uniformBufferInfo[i].buffer->lock(PUBLIC, PRIVATE)) + uniformBufferInfo[i].offset : nullptr;
159 uniformBuffers[i] = uniformBufferInfo[i].buffer;
Alexis Hetu2c2a7b22015-10-27 16:12:11 -0400160 }
161 }
162
John Bauman89401822014-05-06 15:04:28 -0400163 void PixelProcessor::setRenderTarget(int index, Surface *renderTarget)
164 {
165 context->renderTarget[index] = renderTarget;
166 }
167
Nicolas Capens3751c1e2016-03-21 14:14:14 -0400168 void PixelProcessor::setDepthBuffer(Surface *depthBuffer)
John Bauman89401822014-05-06 15:04:28 -0400169 {
Nicolas Capens3751c1e2016-03-21 14:14:14 -0400170 context->depthBuffer = depthBuffer;
171 }
172
173 void PixelProcessor::setStencilBuffer(Surface *stencilBuffer)
174 {
175 context->stencilBuffer = stencilBuffer;
John Bauman89401822014-05-06 15:04:28 -0400176 }
177
178 void PixelProcessor::setTexCoordIndex(unsigned int stage, int texCoordIndex)
179 {
180 if(stage < 8)
181 {
182 context->textureStage[stage].setTexCoordIndex(texCoordIndex);
183 }
184 else ASSERT(false);
185 }
186
187 void PixelProcessor::setStageOperation(unsigned int stage, TextureStage::StageOperation stageOperation)
188 {
189 if(stage < 8)
190 {
191 context->textureStage[stage].setStageOperation(stageOperation);
192 }
193 else ASSERT(false);
194 }
195
196 void PixelProcessor::setFirstArgument(unsigned int stage, TextureStage::SourceArgument firstArgument)
197 {
198 if(stage < 8)
199 {
200 context->textureStage[stage].setFirstArgument(firstArgument);
201 }
202 else ASSERT(false);
203 }
204
205 void PixelProcessor::setSecondArgument(unsigned int stage, TextureStage::SourceArgument secondArgument)
206 {
207 if(stage < 8)
208 {
209 context->textureStage[stage].setSecondArgument(secondArgument);
210 }
211 else ASSERT(false);
212 }
213
214 void PixelProcessor::setThirdArgument(unsigned int stage, TextureStage::SourceArgument thirdArgument)
215 {
216 if(stage < 8)
217 {
218 context->textureStage[stage].setThirdArgument(thirdArgument);
219 }
220 else ASSERT(false);
221 }
222
223 void PixelProcessor::setStageOperationAlpha(unsigned int stage, TextureStage::StageOperation stageOperationAlpha)
224 {
225 if(stage < 8)
226 {
227 context->textureStage[stage].setStageOperationAlpha(stageOperationAlpha);
228 }
229 else ASSERT(false);
230 }
231
232 void PixelProcessor::setFirstArgumentAlpha(unsigned int stage, TextureStage::SourceArgument firstArgumentAlpha)
233 {
234 if(stage < 8)
235 {
236 context->textureStage[stage].setFirstArgumentAlpha(firstArgumentAlpha);
237 }
238 else ASSERT(false);
239 }
240
241 void PixelProcessor::setSecondArgumentAlpha(unsigned int stage, TextureStage::SourceArgument secondArgumentAlpha)
242 {
243 if(stage < 8)
244 {
245 context->textureStage[stage].setSecondArgumentAlpha(secondArgumentAlpha);
246 }
247 else ASSERT(false);
248 }
249
250 void PixelProcessor::setThirdArgumentAlpha(unsigned int stage, TextureStage::SourceArgument thirdArgumentAlpha)
251 {
252 if(stage < 8)
253 {
254 context->textureStage[stage].setThirdArgumentAlpha(thirdArgumentAlpha);
255 }
256 else ASSERT(false);
257 }
258
259 void PixelProcessor::setFirstModifier(unsigned int stage, TextureStage::ArgumentModifier firstModifier)
260 {
261 if(stage < 8)
262 {
263 context->textureStage[stage].setFirstModifier(firstModifier);
264 }
265 else ASSERT(false);
266 }
267
268 void PixelProcessor::setSecondModifier(unsigned int stage, TextureStage::ArgumentModifier secondModifier)
269 {
270 if(stage < 8)
271 {
272 context->textureStage[stage].setSecondModifier(secondModifier);
273 }
274 else ASSERT(false);
275 }
276
277 void PixelProcessor::setThirdModifier(unsigned int stage, TextureStage::ArgumentModifier thirdModifier)
278 {
279 if(stage < 8)
280 {
281 context->textureStage[stage].setThirdModifier(thirdModifier);
282 }
283 else ASSERT(false);
284 }
285
286 void PixelProcessor::setFirstModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier firstModifierAlpha)
287 {
288 if(stage < 8)
289 {
290 context->textureStage[stage].setFirstModifierAlpha(firstModifierAlpha);
291 }
292 else ASSERT(false);
293 }
294
295 void PixelProcessor::setSecondModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier secondModifierAlpha)
296 {
297 if(stage < 8)
298 {
299 context->textureStage[stage].setSecondModifierAlpha(secondModifierAlpha);
300 }
301 else ASSERT(false);
302 }
303
304 void PixelProcessor::setThirdModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier thirdModifierAlpha)
305 {
306 if(stage < 8)
307 {
308 context->textureStage[stage].setThirdModifierAlpha(thirdModifierAlpha);
309 }
310 else ASSERT(false);
311 }
312
313 void PixelProcessor::setDestinationArgument(unsigned int stage, TextureStage::DestinationArgument destinationArgument)
314 {
315 if(stage < 8)
316 {
317 context->textureStage[stage].setDestinationArgument(destinationArgument);
318 }
319 else ASSERT(false);
320 }
321
322 void PixelProcessor::setConstantColor(unsigned int stage, const Color<float> &constantColor)
323 {
324 if(stage < 8)
325 {
326 context->textureStage[stage].setConstantColor(constantColor);
327 }
328 else ASSERT(false);
329 }
330
331 void PixelProcessor::setBumpmapMatrix(unsigned int stage, int element, float value)
332 {
333 if(stage < 8)
334 {
335 context->textureStage[stage].setBumpmapMatrix(element, value);
336 }
337 else ASSERT(false);
338 }
339
340 void PixelProcessor::setLuminanceScale(unsigned int stage, float value)
341 {
342 if(stage < 8)
343 {
344 context->textureStage[stage].setLuminanceScale(value);
345 }
346 else ASSERT(false);
347 }
348
349 void PixelProcessor::setLuminanceOffset(unsigned int stage, float value)
350 {
351 if(stage < 8)
352 {
353 context->textureStage[stage].setLuminanceOffset(value);
354 }
355 else ASSERT(false);
356 }
357
358 void PixelProcessor::setTextureFilter(unsigned int sampler, FilterType textureFilter)
359 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400360 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400361 {
362 context->sampler[sampler].setTextureFilter(textureFilter);
363 }
364 else ASSERT(false);
365 }
366
367 void PixelProcessor::setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter)
368 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400369 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400370 {
371 context->sampler[sampler].setMipmapFilter(mipmapFilter);
372 }
373 else ASSERT(false);
374 }
375
376 void PixelProcessor::setGatherEnable(unsigned int sampler, bool enable)
377 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400378 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400379 {
380 context->sampler[sampler].setGatherEnable(enable);
381 }
382 else ASSERT(false);
383 }
384
385 void PixelProcessor::setAddressingModeU(unsigned int sampler, AddressingMode addressMode)
386 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400387 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400388 {
389 context->sampler[sampler].setAddressingModeU(addressMode);
390 }
391 else ASSERT(false);
392 }
393
394 void PixelProcessor::setAddressingModeV(unsigned int sampler, AddressingMode addressMode)
395 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400396 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400397 {
398 context->sampler[sampler].setAddressingModeV(addressMode);
399 }
400 else ASSERT(false);
401 }
402
403 void PixelProcessor::setAddressingModeW(unsigned int sampler, AddressingMode addressMode)
404 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400405 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400406 {
407 context->sampler[sampler].setAddressingModeW(addressMode);
408 }
409 else ASSERT(false);
410 }
411
412 void PixelProcessor::setReadSRGB(unsigned int sampler, bool sRGB)
413 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400414 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400415 {
416 context->sampler[sampler].setReadSRGB(sRGB);
417 }
418 else ASSERT(false);
419 }
420
421 void PixelProcessor::setMipmapLOD(unsigned int sampler, float bias)
422 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400423 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400424 {
425 context->sampler[sampler].setMipmapLOD(bias);
426 }
427 else ASSERT(false);
428 }
429
430 void PixelProcessor::setBorderColor(unsigned int sampler, const Color<float> &borderColor)
431 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400432 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400433 {
434 context->sampler[sampler].setBorderColor(borderColor);
435 }
436 else ASSERT(false);
437 }
438
Alexis Hetu617a5d52014-11-13 10:56:20 -0500439 void PixelProcessor::setMaxAnisotropy(unsigned int sampler, float maxAnisotropy)
John Bauman89401822014-05-06 15:04:28 -0400440 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400441 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400442 {
443 context->sampler[sampler].setMaxAnisotropy(maxAnisotropy);
444 }
445 else ASSERT(false);
446 }
447
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400448 void PixelProcessor::setSwizzleR(unsigned int sampler, SwizzleType swizzleR)
449 {
450 if(sampler < TEXTURE_IMAGE_UNITS)
451 {
452 context->sampler[sampler].setSwizzleR(swizzleR);
453 }
454 else ASSERT(false);
455 }
456
457 void PixelProcessor::setSwizzleG(unsigned int sampler, SwizzleType swizzleG)
458 {
459 if(sampler < TEXTURE_IMAGE_UNITS)
460 {
461 context->sampler[sampler].setSwizzleG(swizzleG);
462 }
463 else ASSERT(false);
464 }
465
466 void PixelProcessor::setSwizzleB(unsigned int sampler, SwizzleType swizzleB)
467 {
468 if(sampler < TEXTURE_IMAGE_UNITS)
469 {
470 context->sampler[sampler].setSwizzleB(swizzleB);
471 }
472 else ASSERT(false);
473 }
474
475 void PixelProcessor::setSwizzleA(unsigned int sampler, SwizzleType swizzleA)
476 {
477 if(sampler < TEXTURE_IMAGE_UNITS)
478 {
479 context->sampler[sampler].setSwizzleA(swizzleA);
480 }
481 else ASSERT(false);
482 }
483
John Bauman89401822014-05-06 15:04:28 -0400484 void PixelProcessor::setWriteSRGB(bool sRGB)
485 {
486 context->setWriteSRGB(sRGB);
487 }
488
Maxime Grégoired9762742015-07-08 16:43:48 -0400489 void PixelProcessor::setColorLogicOpEnabled(bool colorLogicOpEnabled)
490 {
491 context->setColorLogicOpEnabled(colorLogicOpEnabled);
492 }
493
494 void PixelProcessor::setLogicalOperation(LogicalOperation logicalOperation)
495 {
496 context->setLogicalOperation(logicalOperation);
497 }
498
John Bauman89401822014-05-06 15:04:28 -0400499 void PixelProcessor::setDepthBufferEnable(bool depthBufferEnable)
500 {
501 context->setDepthBufferEnable(depthBufferEnable);
502 }
503
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400504 void PixelProcessor::setDepthCompare(DepthCompareMode depthCompareMode)
John Bauman89401822014-05-06 15:04:28 -0400505 {
506 context->depthCompareMode = depthCompareMode;
507 }
508
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400509 void PixelProcessor::setAlphaCompare(AlphaCompareMode alphaCompareMode)
John Bauman89401822014-05-06 15:04:28 -0400510 {
511 context->alphaCompareMode = alphaCompareMode;
512 }
513
514 void PixelProcessor::setDepthWriteEnable(bool depthWriteEnable)
515 {
516 context->depthWriteEnable = depthWriteEnable;
517 }
518
519 void PixelProcessor::setAlphaTestEnable(bool alphaTestEnable)
520 {
521 context->alphaTestEnable = alphaTestEnable;
522 }
523
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400524 void PixelProcessor::setCullMode(CullMode cullMode)
John Bauman89401822014-05-06 15:04:28 -0400525 {
526 context->cullMode = cullMode;
527 }
528
529 void PixelProcessor::setColorWriteMask(int index, int rgbaMask)
530 {
531 context->setColorWriteMask(index, rgbaMask);
532 }
533
534 void PixelProcessor::setStencilEnable(bool stencilEnable)
535 {
536 context->stencilEnable = stencilEnable;
537 }
538
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400539 void PixelProcessor::setStencilCompare(StencilCompareMode stencilCompareMode)
John Bauman89401822014-05-06 15:04:28 -0400540 {
541 context->stencilCompareMode = stencilCompareMode;
542 }
543
544 void PixelProcessor::setStencilReference(int stencilReference)
545 {
546 context->stencilReference = stencilReference;
547 stencil.set(stencilReference, context->stencilMask, context->stencilWriteMask);
548 }
549
550 void PixelProcessor::setStencilReferenceCCW(int stencilReferenceCCW)
551 {
552 context->stencilReferenceCCW = stencilReferenceCCW;
553 stencilCCW.set(stencilReferenceCCW, context->stencilMaskCCW, context->stencilWriteMaskCCW);
554 }
555
556 void PixelProcessor::setStencilMask(int stencilMask)
557 {
558 context->stencilMask = stencilMask;
559 stencil.set(context->stencilReference, stencilMask, context->stencilWriteMask);
560 }
561
562 void PixelProcessor::setStencilMaskCCW(int stencilMaskCCW)
563 {
564 context->stencilMaskCCW = stencilMaskCCW;
565 stencilCCW.set(context->stencilReferenceCCW, stencilMaskCCW, context->stencilWriteMaskCCW);
566 }
567
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400568 void PixelProcessor::setStencilFailOperation(StencilOperation stencilFailOperation)
John Bauman89401822014-05-06 15:04:28 -0400569 {
570 context->stencilFailOperation = stencilFailOperation;
571 }
572
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400573 void PixelProcessor::setStencilPassOperation(StencilOperation stencilPassOperation)
John Bauman89401822014-05-06 15:04:28 -0400574 {
575 context->stencilPassOperation = stencilPassOperation;
576 }
577
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400578 void PixelProcessor::setStencilZFailOperation(StencilOperation stencilZFailOperation)
John Bauman89401822014-05-06 15:04:28 -0400579 {
580 context->stencilZFailOperation = stencilZFailOperation;
581 }
582
583 void PixelProcessor::setStencilWriteMask(int stencilWriteMask)
584 {
585 context->stencilWriteMask = stencilWriteMask;
586 stencil.set(context->stencilReference, context->stencilMask, stencilWriteMask);
587 }
588
589 void PixelProcessor::setStencilWriteMaskCCW(int stencilWriteMaskCCW)
590 {
591 context->stencilWriteMaskCCW = stencilWriteMaskCCW;
592 stencilCCW.set(context->stencilReferenceCCW, context->stencilMaskCCW, stencilWriteMaskCCW);
593 }
594
595 void PixelProcessor::setTwoSidedStencil(bool enable)
596 {
597 context->twoSidedStencil = enable;
598 }
599
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400600 void PixelProcessor::setStencilCompareCCW(StencilCompareMode stencilCompareMode)
John Bauman89401822014-05-06 15:04:28 -0400601 {
602 context->stencilCompareModeCCW = stencilCompareMode;
603 }
604
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400605 void PixelProcessor::setStencilFailOperationCCW(StencilOperation stencilFailOperation)
John Bauman89401822014-05-06 15:04:28 -0400606 {
607 context->stencilFailOperationCCW = stencilFailOperation;
608 }
609
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400610 void PixelProcessor::setStencilPassOperationCCW(StencilOperation stencilPassOperation)
John Bauman89401822014-05-06 15:04:28 -0400611 {
612 context->stencilPassOperationCCW = stencilPassOperation;
613 }
614
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400615 void PixelProcessor::setStencilZFailOperationCCW(StencilOperation stencilZFailOperation)
John Bauman89401822014-05-06 15:04:28 -0400616 {
617 context->stencilZFailOperationCCW = stencilZFailOperation;
618 }
619
620 void PixelProcessor::setTextureFactor(const Color<float> &textureFactor)
621 {
622 // FIXME: Compact into generic function // FIXME: Clamp
623 short textureFactorR = iround(4095 * textureFactor.r);
624 short textureFactorG = iround(4095 * textureFactor.g);
625 short textureFactorB = iround(4095 * textureFactor.b);
626 short textureFactorA = iround(4095 * textureFactor.a);
627
628 factor.textureFactor4[0][0] = textureFactorR;
629 factor.textureFactor4[0][1] = textureFactorR;
630 factor.textureFactor4[0][2] = textureFactorR;
631 factor.textureFactor4[0][3] = textureFactorR;
632
633 factor.textureFactor4[1][0] = textureFactorG;
634 factor.textureFactor4[1][1] = textureFactorG;
635 factor.textureFactor4[1][2] = textureFactorG;
636 factor.textureFactor4[1][3] = textureFactorG;
637
638 factor.textureFactor4[2][0] = textureFactorB;
639 factor.textureFactor4[2][1] = textureFactorB;
640 factor.textureFactor4[2][2] = textureFactorB;
641 factor.textureFactor4[2][3] = textureFactorB;
642
643 factor.textureFactor4[3][0] = textureFactorA;
644 factor.textureFactor4[3][1] = textureFactorA;
645 factor.textureFactor4[3][2] = textureFactorA;
646 factor.textureFactor4[3][3] = textureFactorA;
647 }
648
649 void PixelProcessor::setBlendConstant(const Color<float> &blendConstant)
650 {
651 // FIXME: Compact into generic function // FIXME: Clamp
652 short blendConstantR = iround(65535 * blendConstant.r);
653 short blendConstantG = iround(65535 * blendConstant.g);
654 short blendConstantB = iround(65535 * blendConstant.b);
655 short blendConstantA = iround(65535 * blendConstant.a);
656
657 factor.blendConstant4W[0][0] = blendConstantR;
658 factor.blendConstant4W[0][1] = blendConstantR;
659 factor.blendConstant4W[0][2] = blendConstantR;
660 factor.blendConstant4W[0][3] = blendConstantR;
661
662 factor.blendConstant4W[1][0] = blendConstantG;
663 factor.blendConstant4W[1][1] = blendConstantG;
664 factor.blendConstant4W[1][2] = blendConstantG;
665 factor.blendConstant4W[1][3] = blendConstantG;
666
667 factor.blendConstant4W[2][0] = blendConstantB;
668 factor.blendConstant4W[2][1] = blendConstantB;
669 factor.blendConstant4W[2][2] = blendConstantB;
670 factor.blendConstant4W[2][3] = blendConstantB;
671
672 factor.blendConstant4W[3][0] = blendConstantA;
673 factor.blendConstant4W[3][1] = blendConstantA;
674 factor.blendConstant4W[3][2] = blendConstantA;
675 factor.blendConstant4W[3][3] = blendConstantA;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500676
John Bauman89401822014-05-06 15:04:28 -0400677 // FIXME: Compact into generic function // FIXME: Clamp
678 short invBlendConstantR = iround(65535 * (1 - blendConstant.r));
679 short invBlendConstantG = iround(65535 * (1 - blendConstant.g));
680 short invBlendConstantB = iround(65535 * (1 - blendConstant.b));
681 short invBlendConstantA = iround(65535 * (1 - blendConstant.a));
682
683 factor.invBlendConstant4W[0][0] = invBlendConstantR;
684 factor.invBlendConstant4W[0][1] = invBlendConstantR;
685 factor.invBlendConstant4W[0][2] = invBlendConstantR;
686 factor.invBlendConstant4W[0][3] = invBlendConstantR;
687
688 factor.invBlendConstant4W[1][0] = invBlendConstantG;
689 factor.invBlendConstant4W[1][1] = invBlendConstantG;
690 factor.invBlendConstant4W[1][2] = invBlendConstantG;
691 factor.invBlendConstant4W[1][3] = invBlendConstantG;
692
693 factor.invBlendConstant4W[2][0] = invBlendConstantB;
694 factor.invBlendConstant4W[2][1] = invBlendConstantB;
695 factor.invBlendConstant4W[2][2] = invBlendConstantB;
696 factor.invBlendConstant4W[2][3] = invBlendConstantB;
697
698 factor.invBlendConstant4W[3][0] = invBlendConstantA;
699 factor.invBlendConstant4W[3][1] = invBlendConstantA;
700 factor.invBlendConstant4W[3][2] = invBlendConstantA;
701 factor.invBlendConstant4W[3][3] = invBlendConstantA;
702
703 factor.blendConstant4F[0][0] = blendConstant.r;
704 factor.blendConstant4F[0][1] = blendConstant.r;
705 factor.blendConstant4F[0][2] = blendConstant.r;
706 factor.blendConstant4F[0][3] = blendConstant.r;
707
708 factor.blendConstant4F[1][0] = blendConstant.g;
709 factor.blendConstant4F[1][1] = blendConstant.g;
710 factor.blendConstant4F[1][2] = blendConstant.g;
711 factor.blendConstant4F[1][3] = blendConstant.g;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500712
John Bauman89401822014-05-06 15:04:28 -0400713 factor.blendConstant4F[2][0] = blendConstant.b;
714 factor.blendConstant4F[2][1] = blendConstant.b;
715 factor.blendConstant4F[2][2] = blendConstant.b;
716 factor.blendConstant4F[2][3] = blendConstant.b;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500717
John Bauman89401822014-05-06 15:04:28 -0400718 factor.blendConstant4F[3][0] = blendConstant.a;
719 factor.blendConstant4F[3][1] = blendConstant.a;
720 factor.blendConstant4F[3][2] = blendConstant.a;
721 factor.blendConstant4F[3][3] = blendConstant.a;
722
723 factor.invBlendConstant4F[0][0] = 1 - blendConstant.r;
724 factor.invBlendConstant4F[0][1] = 1 - blendConstant.r;
725 factor.invBlendConstant4F[0][2] = 1 - blendConstant.r;
726 factor.invBlendConstant4F[0][3] = 1 - blendConstant.r;
727
728 factor.invBlendConstant4F[1][0] = 1 - blendConstant.g;
729 factor.invBlendConstant4F[1][1] = 1 - blendConstant.g;
730 factor.invBlendConstant4F[1][2] = 1 - blendConstant.g;
731 factor.invBlendConstant4F[1][3] = 1 - blendConstant.g;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500732
John Bauman89401822014-05-06 15:04:28 -0400733 factor.invBlendConstant4F[2][0] = 1 - blendConstant.b;
734 factor.invBlendConstant4F[2][1] = 1 - blendConstant.b;
735 factor.invBlendConstant4F[2][2] = 1 - blendConstant.b;
736 factor.invBlendConstant4F[2][3] = 1 - blendConstant.b;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500737
John Bauman89401822014-05-06 15:04:28 -0400738 factor.invBlendConstant4F[3][0] = 1 - blendConstant.a;
739 factor.invBlendConstant4F[3][1] = 1 - blendConstant.a;
740 factor.invBlendConstant4F[3][2] = 1 - blendConstant.a;
741 factor.invBlendConstant4F[3][3] = 1 - blendConstant.a;
742 }
743
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400744 void PixelProcessor::setFillMode(FillMode fillMode)
John Bauman89401822014-05-06 15:04:28 -0400745 {
746 context->fillMode = fillMode;
747 }
748
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400749 void PixelProcessor::setShadingMode(ShadingMode shadingMode)
John Bauman89401822014-05-06 15:04:28 -0400750 {
751 context->shadingMode = shadingMode;
752 }
753
754 void PixelProcessor::setAlphaBlendEnable(bool alphaBlendEnable)
755 {
756 context->setAlphaBlendEnable(alphaBlendEnable);
757 }
758
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400759 void PixelProcessor::setSourceBlendFactor(BlendFactor sourceBlendFactor)
John Bauman89401822014-05-06 15:04:28 -0400760 {
761 context->setSourceBlendFactor(sourceBlendFactor);
762 }
763
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400764 void PixelProcessor::setDestBlendFactor(BlendFactor destBlendFactor)
John Bauman89401822014-05-06 15:04:28 -0400765 {
766 context->setDestBlendFactor(destBlendFactor);
767 }
768
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400769 void PixelProcessor::setBlendOperation(BlendOperation blendOperation)
John Bauman89401822014-05-06 15:04:28 -0400770 {
771 context->setBlendOperation(blendOperation);
772 }
773
774 void PixelProcessor::setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable)
775 {
776 context->setSeparateAlphaBlendEnable(separateAlphaBlendEnable);
777 }
778
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400779 void PixelProcessor::setSourceBlendFactorAlpha(BlendFactor sourceBlendFactorAlpha)
John Bauman89401822014-05-06 15:04:28 -0400780 {
781 context->setSourceBlendFactorAlpha(sourceBlendFactorAlpha);
782 }
783
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400784 void PixelProcessor::setDestBlendFactorAlpha(BlendFactor destBlendFactorAlpha)
John Bauman89401822014-05-06 15:04:28 -0400785 {
786 context->setDestBlendFactorAlpha(destBlendFactorAlpha);
787 }
788
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400789 void PixelProcessor::setBlendOperationAlpha(BlendOperation blendOperationAlpha)
John Bauman89401822014-05-06 15:04:28 -0400790 {
791 context->setBlendOperationAlpha(blendOperationAlpha);
792 }
793
Alexis Hetua818c452015-06-11 13:06:58 -0400794 void PixelProcessor::setAlphaReference(float alphaReference)
John Bauman89401822014-05-06 15:04:28 -0400795 {
796 context->alphaReference = alphaReference;
797
Alexis Hetua818c452015-06-11 13:06:58 -0400798 factor.alphaReference4[0] = (word)iround(alphaReference * 0x1000 / 0xFF);
799 factor.alphaReference4[1] = (word)iround(alphaReference * 0x1000 / 0xFF);
800 factor.alphaReference4[2] = (word)iround(alphaReference * 0x1000 / 0xFF);
801 factor.alphaReference4[3] = (word)iround(alphaReference * 0x1000 / 0xFF);
John Bauman89401822014-05-06 15:04:28 -0400802 }
803
804 void PixelProcessor::setGlobalMipmapBias(float bias)
805 {
806 context->setGlobalMipmapBias(bias);
807 }
808
809 void PixelProcessor::setFogStart(float start)
810 {
811 setFogRanges(start, context->fogEnd);
812 }
813
814 void PixelProcessor::setFogEnd(float end)
815 {
816 setFogRanges(context->fogStart, end);
817 }
818
819 void PixelProcessor::setFogColor(Color<float> fogColor)
820 {
821 // TODO: Compact into generic function
822 word fogR = (unsigned short)(65535 * fogColor.r);
823 word fogG = (unsigned short)(65535 * fogColor.g);
824 word fogB = (unsigned short)(65535 * fogColor.b);
825
826 fog.color4[0][0] = fogR;
827 fog.color4[0][1] = fogR;
828 fog.color4[0][2] = fogR;
829 fog.color4[0][3] = fogR;
830
831 fog.color4[1][0] = fogG;
832 fog.color4[1][1] = fogG;
833 fog.color4[1][2] = fogG;
834 fog.color4[1][3] = fogG;
835
836 fog.color4[2][0] = fogB;
837 fog.color4[2][1] = fogB;
838 fog.color4[2][2] = fogB;
839 fog.color4[2][3] = fogB;
840
841 fog.colorF[0] = replicate(fogColor.r);
842 fog.colorF[1] = replicate(fogColor.g);
843 fog.colorF[2] = replicate(fogColor.b);
844 }
845
846 void PixelProcessor::setFogDensity(float fogDensity)
847 {
848 fog.densityE = replicate(-fogDensity * 1.442695f); // 1/e^x = 2^(-x*1.44)
Nicolas Capensa36f3f92015-08-04 15:34:26 -0400849 fog.density2E = replicate(-fogDensity * fogDensity * 1.442695f);
John Bauman89401822014-05-06 15:04:28 -0400850 }
851
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400852 void PixelProcessor::setPixelFogMode(FogMode fogMode)
John Bauman89401822014-05-06 15:04:28 -0400853 {
854 context->pixelFogMode = fogMode;
855 }
856
857 void PixelProcessor::setPerspectiveCorrection(bool perspectiveEnable)
858 {
859 perspectiveCorrection = perspectiveEnable;
860 }
861
862 void PixelProcessor::setOcclusionEnabled(bool enable)
863 {
864 context->occlusionEnabled = enable;
865 }
866
867 void PixelProcessor::setRoutineCacheSize(int cacheSize)
868 {
869 delete routineCache;
John Bauman66b8ab22014-05-06 15:57:45 -0400870 routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536), precachePixel ? "sw-pixel" : 0);
John Bauman89401822014-05-06 15:04:28 -0400871 }
872
873 void PixelProcessor::setFogRanges(float start, float end)
874 {
875 context->fogStart = start;
876 context->fogEnd = end;
877
878 if(start == end)
879 {
880 end += 0.001f; // Hack: ensure there is a small range
881 }
882
883 float fogScale = -1.0f / (end - start);
884 float fogOffset = end * -fogScale;
885
886 fog.scale = replicate(fogScale);
887 fog.offset = replicate(fogOffset);
888 }
889
890 const PixelProcessor::State PixelProcessor::update() const
891 {
892 State state;
893
894 if(context->pixelShader)
895 {
John Bauman19bac1e2014-05-06 15:23:49 -0400896 state.shaderID = context->pixelShader->getSerialID();
John Bauman89401822014-05-06 15:04:28 -0400897 }
898 else
899 {
John Bauman19bac1e2014-05-06 15:23:49 -0400900 state.shaderID = 0;
John Bauman89401822014-05-06 15:04:28 -0400901 }
902
903 state.depthOverride = context->pixelShader && context->pixelShader->depthOverride();
John Bauman19bac1e2014-05-06 15:23:49 -0400904 state.shaderContainsKill = context->pixelShader ? context->pixelShader->containsKill() : false;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500905
John Bauman89401822014-05-06 15:04:28 -0400906 if(context->alphaTestActive())
907 {
908 state.alphaCompareMode = context->alphaCompareMode;
909
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400910 state.transparencyAntialiasing = context->getMultiSampleCount() > 1 ? transparencyAntialiasing : TRANSPARENCY_NONE;
John Bauman89401822014-05-06 15:04:28 -0400911 }
912
913 state.depthWriteEnable = context->depthWriteActive();
914
915 if(context->stencilActive())
916 {
917 state.stencilActive = true;
918 state.stencilCompareMode = context->stencilCompareMode;
919 state.stencilFailOperation = context->stencilFailOperation;
920 state.stencilPassOperation = context->stencilPassOperation;
921 state.stencilZFailOperation = context->stencilZFailOperation;
922 state.noStencilMask = (context->stencilMask == 0xFF);
923 state.noStencilWriteMask = (context->stencilWriteMask == 0xFF);
924 state.stencilWriteMasked = (context->stencilWriteMask == 0x00);
925
926 state.twoSidedStencil = context->twoSidedStencil;
927 state.stencilCompareModeCCW = context->twoSidedStencil ? context->stencilCompareModeCCW : state.stencilCompareMode;
928 state.stencilFailOperationCCW = context->twoSidedStencil ? context->stencilFailOperationCCW : state.stencilFailOperation;
929 state.stencilPassOperationCCW = context->twoSidedStencil ? context->stencilPassOperationCCW : state.stencilPassOperation;
930 state.stencilZFailOperationCCW = context->twoSidedStencil ? context->stencilZFailOperationCCW : state.stencilZFailOperation;
931 state.noStencilMaskCCW = context->twoSidedStencil ? (context->stencilMaskCCW == 0xFF) : state.noStencilMask;
932 state.noStencilWriteMaskCCW = context->twoSidedStencil ? (context->stencilWriteMaskCCW == 0xFF) : state.noStencilWriteMask;
933 state.stencilWriteMaskedCCW = context->twoSidedStencil ? (context->stencilWriteMaskCCW == 0x00) : state.stencilWriteMasked;
934 }
935
936 if(context->depthBufferActive())
937 {
938 state.depthTestActive = true;
939 state.depthCompareMode = context->depthCompareMode;
Nicolas Capens3751c1e2016-03-21 14:14:14 -0400940 state.quadLayoutDepthBuffer = context->depthBuffer->getInternalFormat() != FORMAT_D32F_LOCKABLE &&
941 context->depthBuffer->getInternalFormat() != FORMAT_D32FS8_TEXTURE &&
942 context->depthBuffer->getInternalFormat() != FORMAT_D32FS8_SHADOW;
John Bauman89401822014-05-06 15:04:28 -0400943 }
944
945 state.occlusionEnabled = context->occlusionEnabled;
946
947 state.fogActive = context->fogActive();
948 state.pixelFogMode = context->pixelFogActive();
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400949 state.wBasedFog = context->wBasedFog && context->pixelFogActive() != FOG_NONE;
John Bauman89401822014-05-06 15:04:28 -0400950 state.perspective = context->perspectiveActive();
951
952 if(context->alphaBlendActive())
953 {
954 state.alphaBlendActive = true;
955 state.sourceBlendFactor = context->sourceBlendFactor();
956 state.destBlendFactor = context->destBlendFactor();
957 state.blendOperation = context->blendOperation();
958 state.sourceBlendFactorAlpha = context->sourceBlendFactorAlpha();
959 state.destBlendFactorAlpha = context->destBlendFactorAlpha();
960 state.blendOperationAlpha = context->blendOperationAlpha();
961 }
Maxime Grégoired9762742015-07-08 16:43:48 -0400962
963 state.logicalOperation = context->colorLogicOp();
964
Alexis Hetu1edcd8b2015-11-05 11:12:41 -0500965 for(int i = 0; i < RENDERTARGETS; i++)
John Bauman89401822014-05-06 15:04:28 -0400966 {
Nicolas Capensc98186a2016-04-18 12:07:22 -0400967 state.colorWriteMask |= context->colorWriteActive(i) << (4 * i);
John Bauman89401822014-05-06 15:04:28 -0400968 state.targetFormat[i] = context->renderTargetInternalFormat(i);
969 }
970
John Bauman66b8ab22014-05-06 15:57:45 -0400971 state.writeSRGB = context->writeSRGB && context->renderTarget[0] && Surface::isSRGBwritable(context->renderTarget[0]->getExternalFormat());
972 state.multiSample = context->getMultiSampleCount();
John Bauman89401822014-05-06 15:04:28 -0400973 state.multiSampleMask = context->multiSampleMask;
974
975 if(state.multiSample > 1 && context->pixelShader)
976 {
977 state.centroid = context->pixelShader->containsCentroid();
978 }
979
980 if(!context->pixelShader)
981 {
982 for(unsigned int i = 0; i < 8; i++)
983 {
984 state.textureStage[i] = context->textureStage[i].textureStageState();
985 }
986
987 state.specularAdd = context->specularActive() && context->specularEnable;
988 }
989
990 for(unsigned int i = 0; i < 16; i++)
991 {
992 if(context->pixelShader)
993 {
994 if(context->pixelShader->usesSampler(i))
995 {
996 state.sampler[i] = context->sampler[i].samplerState();
997 }
998 }
999 else
1000 {
1001 if(i < 8 && state.textureStage[i].stageOperation != TextureStage::STAGE_DISABLE)
1002 {
1003 state.sampler[i] = context->sampler[i].samplerState();
1004 }
1005 else break;
1006 }
1007 }
1008
1009 const bool point = context->isDrawPoint(true);
1010 const bool sprite = context->pointSpriteActive();
Nicolas Capensa0f4be82014-10-22 14:35:30 -04001011 const bool flatShading = (context->shadingMode == SHADING_FLAT) || point;
John Bauman89401822014-05-06 15:04:28 -04001012
1013 if(context->pixelShaderVersion() < 0x0300)
1014 {
1015 for(int coordinate = 0; coordinate < 8; coordinate++)
1016 {
1017 for(int component = 0; component < 4; component++)
1018 {
1019 if(context->textureActive(coordinate, component))
1020 {
1021 state.texture[coordinate].component |= 1 << component;
1022
1023 if(point && !sprite)
1024 {
1025 state.texture[coordinate].flat |= 1 << component;
1026 }
1027 }
1028 }
1029
1030 if(context->textureTransformProject[coordinate] && context->pixelShaderVersion() <= 0x0103)
1031 {
1032 if(context->textureTransformCount[coordinate] == 2)
1033 {
1034 state.texture[coordinate].project = 1;
1035 }
1036 else if(context->textureTransformCount[coordinate] == 3)
1037 {
1038 state.texture[coordinate].project = 2;
1039 }
1040 else if(context->textureTransformCount[coordinate] == 4 || context->textureTransformCount[coordinate] == 0)
1041 {
1042 state.texture[coordinate].project = 3;
1043 }
1044 }
1045 }
1046
1047 for(int color = 0; color < 2; color++)
1048 {
1049 for(int component = 0; component < 4; component++)
1050 {
1051 if(context->colorActive(color, component))
1052 {
1053 state.color[color].component |= 1 << component;
Nicolas Capens4f172c72016-01-13 08:34:30 -05001054
John Bauman89401822014-05-06 15:04:28 -04001055 if(point || flatShading)
1056 {
1057 state.color[color].flat |= 1 << component;
1058 }
1059 }
1060 }
1061 }
1062
1063 if(context->fogActive())
1064 {
1065 state.fog.component = true;
Nicolas Capens4f172c72016-01-13 08:34:30 -05001066
John Bauman89401822014-05-06 15:04:28 -04001067 if(point)
1068 {
1069 state.fog.flat = true;
1070 }
1071 }
1072 }
1073 else
1074 {
Nicolas Capens3b4c93f2016-05-18 12:51:37 -04001075 for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
John Bauman89401822014-05-06 15:04:28 -04001076 {
1077 for(int component = 0; component < 4; component++)
1078 {
1079 if(context->pixelShader->semantic[interpolant][component].active())
1080 {
1081 bool flat = point;
1082
1083 switch(context->pixelShader->semantic[interpolant][component].usage)
1084 {
Nicolas Capens3b4c93f2016-05-18 12:51:37 -04001085 case Shader::USAGE_TEXCOORD: flat = point && !sprite; break;
1086 case Shader::USAGE_COLOR: flat = flatShading; break;
John Bauman89401822014-05-06 15:04:28 -04001087 }
1088
1089 state.interpolant[interpolant].component |= 1 << component;
1090
1091 if(flat)
1092 {
1093 state.interpolant[interpolant].flat |= 1 << component;
1094 }
1095 }
1096 }
1097 }
1098 }
1099
1100 if(state.centroid)
1101 {
Nicolas Capens3b4c93f2016-05-18 12:51:37 -04001102 for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
John Bauman89401822014-05-06 15:04:28 -04001103 {
1104 for(int component = 0; component < 4; component++)
1105 {
1106 state.interpolant[interpolant].centroid = context->pixelShader->semantic[interpolant][0].centroid;
1107 }
1108 }
1109 }
1110
1111 state.hash = state.computeHash();
1112
1113 return state;
1114 }
1115
1116 Routine *PixelProcessor::routine(const State &state)
1117 {
1118 Routine *routine = routineCache->query(state);
1119
1120 if(!routine)
1121 {
Alexis Hetuf2a8c372015-07-13 11:08:41 -04001122 const bool integerPipeline = (context->pixelShaderVersion() <= 0x0104);
Nicolas Capensba53fbf2016-01-14 13:43:42 -05001123 QuadRasterizer *generator = nullptr;
Nicolas Capens4f172c72016-01-13 08:34:30 -05001124
Alexis Hetuf2a8c372015-07-13 11:08:41 -04001125 if(integerPipeline)
1126 {
1127 generator = new PixelPipeline(state, context->pixelShader);
1128 }
1129 else
1130 {
1131 generator = new PixelProgram(state, context->pixelShader);
1132 }
Nicolas Capens4f172c72016-01-13 08:34:30 -05001133
John Bauman89401822014-05-06 15:04:28 -04001134 generator->generate();
Nicolas Capens4f172c72016-01-13 08:34:30 -05001135 routine = (*generator)(L"PixelRoutine_%0.8X", state.shaderID);
John Bauman89401822014-05-06 15:04:28 -04001136 delete generator;
1137
1138 routineCache->add(state, routine);
1139 }
1140
1141 return routine;
1142 }
1143}