blob: f73623394898d8fc542a6ec0bddbddfd38267b0d [file] [log] [blame]
John Bauman89401822014-05-06 15:04:28 -04001// SwiftShader Software Renderer
2//
John Bauman66b8ab22014-05-06 15:57:45 -04003// Copyright(c) 2005-2013 TransGaming Inc.
John Bauman89401822014-05-06 15:04:28 -04004//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12#include "PixelProcessor.hpp"
13
Alexis Hetuf2a8c372015-07-13 11:08:41 -040014#include "PixelPipeline.hpp"
15#include "PixelProgram.hpp"
John Bauman89401822014-05-06 15:04:28 -040016#include "PixelShader.hpp"
17#include "MetaMacro.hpp"
18#include "Surface.hpp"
19#include "Primitive.hpp"
20#include "Constants.hpp"
21#include "Debug.hpp"
22
John Bauman66b8ab22014-05-06 15:57:45 -040023#include <string.h>
24
John Bauman89401822014-05-06 15:04:28 -040025namespace sw
26{
27 extern bool complementaryDepthBuffer;
Nicolas Capensa0f4be82014-10-22 14:35:30 -040028 extern TransparencyAntialiasing transparencyAntialiasing;
John Bauman89401822014-05-06 15:04:28 -040029 extern bool perspectiveCorrection;
30
John Bauman66b8ab22014-05-06 15:57:45 -040031 bool precachePixel = false;
32
John Bauman89401822014-05-06 15:04:28 -040033 unsigned int PixelProcessor::States::computeHash()
34 {
35 unsigned int *state = (unsigned int*)this;
36 unsigned int hash = 0;
37
Nicolas Capens5d961882016-01-01 23:18:14 -050038 for(unsigned int i = 0; i < sizeof(States) / 4; i++)
John Bauman89401822014-05-06 15:04:28 -040039 {
40 hash ^= state[i];
41 }
42
43 return hash;
44 }
45
46 PixelProcessor::State::State()
47 {
48 memset(this, 0, sizeof(State));
49 }
50
51 bool PixelProcessor::State::operator==(const State &state) const
52 {
53 if(hash != state.hash)
54 {
55 return false;
56 }
57
58 return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
59 }
60
61 PixelProcessor::PixelProcessor(Context *context) : context(context)
62 {
63 setGlobalMipmapBias(0.0f); // Round to highest LOD [0.5, 1.0]: -0.5
64 // Round to nearest LOD [0.7, 1.4]: 0.0
65 // Round to lowest LOD [1.0, 2.0]: 0.5
66
67 routineCache = 0;
68 setRoutineCacheSize(1024);
Nicolas Capens3d7be4e2016-02-07 22:47:00 -050069
70 for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; i++)
71 {
72 uniformBuffer[i] = nullptr;
73 }
John Bauman89401822014-05-06 15:04:28 -040074 }
75
76 PixelProcessor::~PixelProcessor()
77 {
78 delete routineCache;
79 routineCache = 0;
80 }
81
82 void PixelProcessor::setFloatConstant(unsigned int index, const float value[4])
83 {
Alexis Hetu04c967a2015-07-08 15:56:17 -040084 if(index < FRAGMENT_UNIFORM_VECTORS)
John Bauman89401822014-05-06 15:04:28 -040085 {
86 c[index][0] = value[0];
87 c[index][1] = value[1];
88 c[index][2] = value[2];
89 c[index][3] = value[3];
90 }
91 else ASSERT(false);
92
93 if(index < 8) // ps_1_x constants
94 {
95 // FIXME: Compact into generic function
96 short x = iround(4095 * clamp(value[0], -1.0f, 1.0f));
97 short y = iround(4095 * clamp(value[1], -1.0f, 1.0f));
98 short z = iround(4095 * clamp(value[2], -1.0f, 1.0f));
99 short w = iround(4095 * clamp(value[3], -1.0f, 1.0f));
100
101 cW[index][0][0] = x;
102 cW[index][0][1] = x;
103 cW[index][0][2] = x;
104 cW[index][0][3] = x;
105
106 cW[index][1][0] = y;
107 cW[index][1][1] = y;
108 cW[index][1][2] = y;
109 cW[index][1][3] = y;
110
111 cW[index][2][0] = z;
112 cW[index][2][1] = z;
113 cW[index][2][2] = z;
114 cW[index][2][3] = z;
115
116 cW[index][3][0] = w;
117 cW[index][3][1] = w;
118 cW[index][3][2] = w;
119 cW[index][3][3] = w;
120 }
121 }
122
123 void PixelProcessor::setIntegerConstant(unsigned int index, const int value[4])
124 {
125 if(index < 16)
126 {
127 i[index][0] = value[0];
128 i[index][1] = value[1];
129 i[index][2] = value[2];
130 i[index][3] = value[3];
131 }
132 else ASSERT(false);
133 }
134
135 void PixelProcessor::setBooleanConstant(unsigned int index, int boolean)
136 {
137 if(index < 16)
138 {
139 b[index] = boolean != 0;
140 }
141 else ASSERT(false);
142 }
143
Alexis Hetu2c2a7b22015-10-27 16:12:11 -0400144 void PixelProcessor::setUniformBuffer(int index, sw::Resource* buffer, int offset)
145 {
146 uniformBuffer[index] = buffer;
147 uniformBufferOffset[index] = offset;
148 }
149
150 void PixelProcessor::lockUniformBuffers(byte** u)
151 {
152 for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; ++i)
153 {
154 u[i] = uniformBuffer[i] ? static_cast<byte*>(uniformBuffer[i]->lock(PUBLIC, PRIVATE)) + uniformBufferOffset[i] : nullptr;
155 }
156 }
157
158 void PixelProcessor::unlockUniformBuffers()
159 {
160 for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; ++i)
161 {
162 if(uniformBuffer[i])
163 {
164 uniformBuffer[i]->unlock();
165 uniformBuffer[i] = nullptr;
166 }
167 }
168 }
169
John Bauman89401822014-05-06 15:04:28 -0400170 void PixelProcessor::setRenderTarget(int index, Surface *renderTarget)
171 {
172 context->renderTarget[index] = renderTarget;
173 }
174
Nicolas Capens3751c1e2016-03-21 14:14:14 -0400175 void PixelProcessor::setDepthBuffer(Surface *depthBuffer)
John Bauman89401822014-05-06 15:04:28 -0400176 {
Nicolas Capens3751c1e2016-03-21 14:14:14 -0400177 context->depthBuffer = depthBuffer;
178 }
179
180 void PixelProcessor::setStencilBuffer(Surface *stencilBuffer)
181 {
182 context->stencilBuffer = stencilBuffer;
John Bauman89401822014-05-06 15:04:28 -0400183 }
184
185 void PixelProcessor::setTexCoordIndex(unsigned int stage, int texCoordIndex)
186 {
187 if(stage < 8)
188 {
189 context->textureStage[stage].setTexCoordIndex(texCoordIndex);
190 }
191 else ASSERT(false);
192 }
193
194 void PixelProcessor::setStageOperation(unsigned int stage, TextureStage::StageOperation stageOperation)
195 {
196 if(stage < 8)
197 {
198 context->textureStage[stage].setStageOperation(stageOperation);
199 }
200 else ASSERT(false);
201 }
202
203 void PixelProcessor::setFirstArgument(unsigned int stage, TextureStage::SourceArgument firstArgument)
204 {
205 if(stage < 8)
206 {
207 context->textureStage[stage].setFirstArgument(firstArgument);
208 }
209 else ASSERT(false);
210 }
211
212 void PixelProcessor::setSecondArgument(unsigned int stage, TextureStage::SourceArgument secondArgument)
213 {
214 if(stage < 8)
215 {
216 context->textureStage[stage].setSecondArgument(secondArgument);
217 }
218 else ASSERT(false);
219 }
220
221 void PixelProcessor::setThirdArgument(unsigned int stage, TextureStage::SourceArgument thirdArgument)
222 {
223 if(stage < 8)
224 {
225 context->textureStage[stage].setThirdArgument(thirdArgument);
226 }
227 else ASSERT(false);
228 }
229
230 void PixelProcessor::setStageOperationAlpha(unsigned int stage, TextureStage::StageOperation stageOperationAlpha)
231 {
232 if(stage < 8)
233 {
234 context->textureStage[stage].setStageOperationAlpha(stageOperationAlpha);
235 }
236 else ASSERT(false);
237 }
238
239 void PixelProcessor::setFirstArgumentAlpha(unsigned int stage, TextureStage::SourceArgument firstArgumentAlpha)
240 {
241 if(stage < 8)
242 {
243 context->textureStage[stage].setFirstArgumentAlpha(firstArgumentAlpha);
244 }
245 else ASSERT(false);
246 }
247
248 void PixelProcessor::setSecondArgumentAlpha(unsigned int stage, TextureStage::SourceArgument secondArgumentAlpha)
249 {
250 if(stage < 8)
251 {
252 context->textureStage[stage].setSecondArgumentAlpha(secondArgumentAlpha);
253 }
254 else ASSERT(false);
255 }
256
257 void PixelProcessor::setThirdArgumentAlpha(unsigned int stage, TextureStage::SourceArgument thirdArgumentAlpha)
258 {
259 if(stage < 8)
260 {
261 context->textureStage[stage].setThirdArgumentAlpha(thirdArgumentAlpha);
262 }
263 else ASSERT(false);
264 }
265
266 void PixelProcessor::setFirstModifier(unsigned int stage, TextureStage::ArgumentModifier firstModifier)
267 {
268 if(stage < 8)
269 {
270 context->textureStage[stage].setFirstModifier(firstModifier);
271 }
272 else ASSERT(false);
273 }
274
275 void PixelProcessor::setSecondModifier(unsigned int stage, TextureStage::ArgumentModifier secondModifier)
276 {
277 if(stage < 8)
278 {
279 context->textureStage[stage].setSecondModifier(secondModifier);
280 }
281 else ASSERT(false);
282 }
283
284 void PixelProcessor::setThirdModifier(unsigned int stage, TextureStage::ArgumentModifier thirdModifier)
285 {
286 if(stage < 8)
287 {
288 context->textureStage[stage].setThirdModifier(thirdModifier);
289 }
290 else ASSERT(false);
291 }
292
293 void PixelProcessor::setFirstModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier firstModifierAlpha)
294 {
295 if(stage < 8)
296 {
297 context->textureStage[stage].setFirstModifierAlpha(firstModifierAlpha);
298 }
299 else ASSERT(false);
300 }
301
302 void PixelProcessor::setSecondModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier secondModifierAlpha)
303 {
304 if(stage < 8)
305 {
306 context->textureStage[stage].setSecondModifierAlpha(secondModifierAlpha);
307 }
308 else ASSERT(false);
309 }
310
311 void PixelProcessor::setThirdModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier thirdModifierAlpha)
312 {
313 if(stage < 8)
314 {
315 context->textureStage[stage].setThirdModifierAlpha(thirdModifierAlpha);
316 }
317 else ASSERT(false);
318 }
319
320 void PixelProcessor::setDestinationArgument(unsigned int stage, TextureStage::DestinationArgument destinationArgument)
321 {
322 if(stage < 8)
323 {
324 context->textureStage[stage].setDestinationArgument(destinationArgument);
325 }
326 else ASSERT(false);
327 }
328
329 void PixelProcessor::setConstantColor(unsigned int stage, const Color<float> &constantColor)
330 {
331 if(stage < 8)
332 {
333 context->textureStage[stage].setConstantColor(constantColor);
334 }
335 else ASSERT(false);
336 }
337
338 void PixelProcessor::setBumpmapMatrix(unsigned int stage, int element, float value)
339 {
340 if(stage < 8)
341 {
342 context->textureStage[stage].setBumpmapMatrix(element, value);
343 }
344 else ASSERT(false);
345 }
346
347 void PixelProcessor::setLuminanceScale(unsigned int stage, float value)
348 {
349 if(stage < 8)
350 {
351 context->textureStage[stage].setLuminanceScale(value);
352 }
353 else ASSERT(false);
354 }
355
356 void PixelProcessor::setLuminanceOffset(unsigned int stage, float value)
357 {
358 if(stage < 8)
359 {
360 context->textureStage[stage].setLuminanceOffset(value);
361 }
362 else ASSERT(false);
363 }
364
365 void PixelProcessor::setTextureFilter(unsigned int sampler, FilterType textureFilter)
366 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400367 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400368 {
369 context->sampler[sampler].setTextureFilter(textureFilter);
370 }
371 else ASSERT(false);
372 }
373
374 void PixelProcessor::setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter)
375 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400376 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400377 {
378 context->sampler[sampler].setMipmapFilter(mipmapFilter);
379 }
380 else ASSERT(false);
381 }
382
383 void PixelProcessor::setGatherEnable(unsigned int sampler, bool enable)
384 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400385 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400386 {
387 context->sampler[sampler].setGatherEnable(enable);
388 }
389 else ASSERT(false);
390 }
391
392 void PixelProcessor::setAddressingModeU(unsigned int sampler, AddressingMode addressMode)
393 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400394 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400395 {
396 context->sampler[sampler].setAddressingModeU(addressMode);
397 }
398 else ASSERT(false);
399 }
400
401 void PixelProcessor::setAddressingModeV(unsigned int sampler, AddressingMode addressMode)
402 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400403 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400404 {
405 context->sampler[sampler].setAddressingModeV(addressMode);
406 }
407 else ASSERT(false);
408 }
409
410 void PixelProcessor::setAddressingModeW(unsigned int sampler, AddressingMode addressMode)
411 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400412 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400413 {
414 context->sampler[sampler].setAddressingModeW(addressMode);
415 }
416 else ASSERT(false);
417 }
418
419 void PixelProcessor::setReadSRGB(unsigned int sampler, bool sRGB)
420 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400421 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400422 {
423 context->sampler[sampler].setReadSRGB(sRGB);
424 }
425 else ASSERT(false);
426 }
427
428 void PixelProcessor::setMipmapLOD(unsigned int sampler, float bias)
429 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400430 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400431 {
432 context->sampler[sampler].setMipmapLOD(bias);
433 }
434 else ASSERT(false);
435 }
436
437 void PixelProcessor::setBorderColor(unsigned int sampler, const Color<float> &borderColor)
438 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400439 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400440 {
441 context->sampler[sampler].setBorderColor(borderColor);
442 }
443 else ASSERT(false);
444 }
445
Alexis Hetu617a5d52014-11-13 10:56:20 -0500446 void PixelProcessor::setMaxAnisotropy(unsigned int sampler, float maxAnisotropy)
John Bauman89401822014-05-06 15:04:28 -0400447 {
Alexis Hetu0b65c5e2015-03-31 11:48:57 -0400448 if(sampler < TEXTURE_IMAGE_UNITS)
John Bauman89401822014-05-06 15:04:28 -0400449 {
450 context->sampler[sampler].setMaxAnisotropy(maxAnisotropy);
451 }
452 else ASSERT(false);
453 }
454
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400455 void PixelProcessor::setSwizzleR(unsigned int sampler, SwizzleType swizzleR)
456 {
457 if(sampler < TEXTURE_IMAGE_UNITS)
458 {
459 context->sampler[sampler].setSwizzleR(swizzleR);
460 }
461 else ASSERT(false);
462 }
463
464 void PixelProcessor::setSwizzleG(unsigned int sampler, SwizzleType swizzleG)
465 {
466 if(sampler < TEXTURE_IMAGE_UNITS)
467 {
468 context->sampler[sampler].setSwizzleG(swizzleG);
469 }
470 else ASSERT(false);
471 }
472
473 void PixelProcessor::setSwizzleB(unsigned int sampler, SwizzleType swizzleB)
474 {
475 if(sampler < TEXTURE_IMAGE_UNITS)
476 {
477 context->sampler[sampler].setSwizzleB(swizzleB);
478 }
479 else ASSERT(false);
480 }
481
482 void PixelProcessor::setSwizzleA(unsigned int sampler, SwizzleType swizzleA)
483 {
484 if(sampler < TEXTURE_IMAGE_UNITS)
485 {
486 context->sampler[sampler].setSwizzleA(swizzleA);
487 }
488 else ASSERT(false);
489 }
490
John Bauman89401822014-05-06 15:04:28 -0400491 void PixelProcessor::setWriteSRGB(bool sRGB)
492 {
493 context->setWriteSRGB(sRGB);
494 }
495
Maxime Grégoired9762742015-07-08 16:43:48 -0400496 void PixelProcessor::setColorLogicOpEnabled(bool colorLogicOpEnabled)
497 {
498 context->setColorLogicOpEnabled(colorLogicOpEnabled);
499 }
500
501 void PixelProcessor::setLogicalOperation(LogicalOperation logicalOperation)
502 {
503 context->setLogicalOperation(logicalOperation);
504 }
505
John Bauman89401822014-05-06 15:04:28 -0400506 void PixelProcessor::setDepthBufferEnable(bool depthBufferEnable)
507 {
508 context->setDepthBufferEnable(depthBufferEnable);
509 }
510
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400511 void PixelProcessor::setDepthCompare(DepthCompareMode depthCompareMode)
John Bauman89401822014-05-06 15:04:28 -0400512 {
513 context->depthCompareMode = depthCompareMode;
514 }
515
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400516 void PixelProcessor::setAlphaCompare(AlphaCompareMode alphaCompareMode)
John Bauman89401822014-05-06 15:04:28 -0400517 {
518 context->alphaCompareMode = alphaCompareMode;
519 }
520
521 void PixelProcessor::setDepthWriteEnable(bool depthWriteEnable)
522 {
523 context->depthWriteEnable = depthWriteEnable;
524 }
525
526 void PixelProcessor::setAlphaTestEnable(bool alphaTestEnable)
527 {
528 context->alphaTestEnable = alphaTestEnable;
529 }
530
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400531 void PixelProcessor::setCullMode(CullMode cullMode)
John Bauman89401822014-05-06 15:04:28 -0400532 {
533 context->cullMode = cullMode;
534 }
535
536 void PixelProcessor::setColorWriteMask(int index, int rgbaMask)
537 {
538 context->setColorWriteMask(index, rgbaMask);
539 }
540
541 void PixelProcessor::setStencilEnable(bool stencilEnable)
542 {
543 context->stencilEnable = stencilEnable;
544 }
545
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400546 void PixelProcessor::setStencilCompare(StencilCompareMode stencilCompareMode)
John Bauman89401822014-05-06 15:04:28 -0400547 {
548 context->stencilCompareMode = stencilCompareMode;
549 }
550
551 void PixelProcessor::setStencilReference(int stencilReference)
552 {
553 context->stencilReference = stencilReference;
554 stencil.set(stencilReference, context->stencilMask, context->stencilWriteMask);
555 }
556
557 void PixelProcessor::setStencilReferenceCCW(int stencilReferenceCCW)
558 {
559 context->stencilReferenceCCW = stencilReferenceCCW;
560 stencilCCW.set(stencilReferenceCCW, context->stencilMaskCCW, context->stencilWriteMaskCCW);
561 }
562
563 void PixelProcessor::setStencilMask(int stencilMask)
564 {
565 context->stencilMask = stencilMask;
566 stencil.set(context->stencilReference, stencilMask, context->stencilWriteMask);
567 }
568
569 void PixelProcessor::setStencilMaskCCW(int stencilMaskCCW)
570 {
571 context->stencilMaskCCW = stencilMaskCCW;
572 stencilCCW.set(context->stencilReferenceCCW, stencilMaskCCW, context->stencilWriteMaskCCW);
573 }
574
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400575 void PixelProcessor::setStencilFailOperation(StencilOperation stencilFailOperation)
John Bauman89401822014-05-06 15:04:28 -0400576 {
577 context->stencilFailOperation = stencilFailOperation;
578 }
579
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400580 void PixelProcessor::setStencilPassOperation(StencilOperation stencilPassOperation)
John Bauman89401822014-05-06 15:04:28 -0400581 {
582 context->stencilPassOperation = stencilPassOperation;
583 }
584
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400585 void PixelProcessor::setStencilZFailOperation(StencilOperation stencilZFailOperation)
John Bauman89401822014-05-06 15:04:28 -0400586 {
587 context->stencilZFailOperation = stencilZFailOperation;
588 }
589
590 void PixelProcessor::setStencilWriteMask(int stencilWriteMask)
591 {
592 context->stencilWriteMask = stencilWriteMask;
593 stencil.set(context->stencilReference, context->stencilMask, stencilWriteMask);
594 }
595
596 void PixelProcessor::setStencilWriteMaskCCW(int stencilWriteMaskCCW)
597 {
598 context->stencilWriteMaskCCW = stencilWriteMaskCCW;
599 stencilCCW.set(context->stencilReferenceCCW, context->stencilMaskCCW, stencilWriteMaskCCW);
600 }
601
602 void PixelProcessor::setTwoSidedStencil(bool enable)
603 {
604 context->twoSidedStencil = enable;
605 }
606
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400607 void PixelProcessor::setStencilCompareCCW(StencilCompareMode stencilCompareMode)
John Bauman89401822014-05-06 15:04:28 -0400608 {
609 context->stencilCompareModeCCW = stencilCompareMode;
610 }
611
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400612 void PixelProcessor::setStencilFailOperationCCW(StencilOperation stencilFailOperation)
John Bauman89401822014-05-06 15:04:28 -0400613 {
614 context->stencilFailOperationCCW = stencilFailOperation;
615 }
616
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400617 void PixelProcessor::setStencilPassOperationCCW(StencilOperation stencilPassOperation)
John Bauman89401822014-05-06 15:04:28 -0400618 {
619 context->stencilPassOperationCCW = stencilPassOperation;
620 }
621
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400622 void PixelProcessor::setStencilZFailOperationCCW(StencilOperation stencilZFailOperation)
John Bauman89401822014-05-06 15:04:28 -0400623 {
624 context->stencilZFailOperationCCW = stencilZFailOperation;
625 }
626
627 void PixelProcessor::setTextureFactor(const Color<float> &textureFactor)
628 {
629 // FIXME: Compact into generic function // FIXME: Clamp
630 short textureFactorR = iround(4095 * textureFactor.r);
631 short textureFactorG = iround(4095 * textureFactor.g);
632 short textureFactorB = iround(4095 * textureFactor.b);
633 short textureFactorA = iround(4095 * textureFactor.a);
634
635 factor.textureFactor4[0][0] = textureFactorR;
636 factor.textureFactor4[0][1] = textureFactorR;
637 factor.textureFactor4[0][2] = textureFactorR;
638 factor.textureFactor4[0][3] = textureFactorR;
639
640 factor.textureFactor4[1][0] = textureFactorG;
641 factor.textureFactor4[1][1] = textureFactorG;
642 factor.textureFactor4[1][2] = textureFactorG;
643 factor.textureFactor4[1][3] = textureFactorG;
644
645 factor.textureFactor4[2][0] = textureFactorB;
646 factor.textureFactor4[2][1] = textureFactorB;
647 factor.textureFactor4[2][2] = textureFactorB;
648 factor.textureFactor4[2][3] = textureFactorB;
649
650 factor.textureFactor4[3][0] = textureFactorA;
651 factor.textureFactor4[3][1] = textureFactorA;
652 factor.textureFactor4[3][2] = textureFactorA;
653 factor.textureFactor4[3][3] = textureFactorA;
654 }
655
656 void PixelProcessor::setBlendConstant(const Color<float> &blendConstant)
657 {
658 // FIXME: Compact into generic function // FIXME: Clamp
659 short blendConstantR = iround(65535 * blendConstant.r);
660 short blendConstantG = iround(65535 * blendConstant.g);
661 short blendConstantB = iround(65535 * blendConstant.b);
662 short blendConstantA = iround(65535 * blendConstant.a);
663
664 factor.blendConstant4W[0][0] = blendConstantR;
665 factor.blendConstant4W[0][1] = blendConstantR;
666 factor.blendConstant4W[0][2] = blendConstantR;
667 factor.blendConstant4W[0][3] = blendConstantR;
668
669 factor.blendConstant4W[1][0] = blendConstantG;
670 factor.blendConstant4W[1][1] = blendConstantG;
671 factor.blendConstant4W[1][2] = blendConstantG;
672 factor.blendConstant4W[1][3] = blendConstantG;
673
674 factor.blendConstant4W[2][0] = blendConstantB;
675 factor.blendConstant4W[2][1] = blendConstantB;
676 factor.blendConstant4W[2][2] = blendConstantB;
677 factor.blendConstant4W[2][3] = blendConstantB;
678
679 factor.blendConstant4W[3][0] = blendConstantA;
680 factor.blendConstant4W[3][1] = blendConstantA;
681 factor.blendConstant4W[3][2] = blendConstantA;
682 factor.blendConstant4W[3][3] = blendConstantA;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500683
John Bauman89401822014-05-06 15:04:28 -0400684 // FIXME: Compact into generic function // FIXME: Clamp
685 short invBlendConstantR = iround(65535 * (1 - blendConstant.r));
686 short invBlendConstantG = iround(65535 * (1 - blendConstant.g));
687 short invBlendConstantB = iround(65535 * (1 - blendConstant.b));
688 short invBlendConstantA = iround(65535 * (1 - blendConstant.a));
689
690 factor.invBlendConstant4W[0][0] = invBlendConstantR;
691 factor.invBlendConstant4W[0][1] = invBlendConstantR;
692 factor.invBlendConstant4W[0][2] = invBlendConstantR;
693 factor.invBlendConstant4W[0][3] = invBlendConstantR;
694
695 factor.invBlendConstant4W[1][0] = invBlendConstantG;
696 factor.invBlendConstant4W[1][1] = invBlendConstantG;
697 factor.invBlendConstant4W[1][2] = invBlendConstantG;
698 factor.invBlendConstant4W[1][3] = invBlendConstantG;
699
700 factor.invBlendConstant4W[2][0] = invBlendConstantB;
701 factor.invBlendConstant4W[2][1] = invBlendConstantB;
702 factor.invBlendConstant4W[2][2] = invBlendConstantB;
703 factor.invBlendConstant4W[2][3] = invBlendConstantB;
704
705 factor.invBlendConstant4W[3][0] = invBlendConstantA;
706 factor.invBlendConstant4W[3][1] = invBlendConstantA;
707 factor.invBlendConstant4W[3][2] = invBlendConstantA;
708 factor.invBlendConstant4W[3][3] = invBlendConstantA;
709
710 factor.blendConstant4F[0][0] = blendConstant.r;
711 factor.blendConstant4F[0][1] = blendConstant.r;
712 factor.blendConstant4F[0][2] = blendConstant.r;
713 factor.blendConstant4F[0][3] = blendConstant.r;
714
715 factor.blendConstant4F[1][0] = blendConstant.g;
716 factor.blendConstant4F[1][1] = blendConstant.g;
717 factor.blendConstant4F[1][2] = blendConstant.g;
718 factor.blendConstant4F[1][3] = blendConstant.g;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500719
John Bauman89401822014-05-06 15:04:28 -0400720 factor.blendConstant4F[2][0] = blendConstant.b;
721 factor.blendConstant4F[2][1] = blendConstant.b;
722 factor.blendConstant4F[2][2] = blendConstant.b;
723 factor.blendConstant4F[2][3] = blendConstant.b;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500724
John Bauman89401822014-05-06 15:04:28 -0400725 factor.blendConstant4F[3][0] = blendConstant.a;
726 factor.blendConstant4F[3][1] = blendConstant.a;
727 factor.blendConstant4F[3][2] = blendConstant.a;
728 factor.blendConstant4F[3][3] = blendConstant.a;
729
730 factor.invBlendConstant4F[0][0] = 1 - blendConstant.r;
731 factor.invBlendConstant4F[0][1] = 1 - blendConstant.r;
732 factor.invBlendConstant4F[0][2] = 1 - blendConstant.r;
733 factor.invBlendConstant4F[0][3] = 1 - blendConstant.r;
734
735 factor.invBlendConstant4F[1][0] = 1 - blendConstant.g;
736 factor.invBlendConstant4F[1][1] = 1 - blendConstant.g;
737 factor.invBlendConstant4F[1][2] = 1 - blendConstant.g;
738 factor.invBlendConstant4F[1][3] = 1 - blendConstant.g;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500739
John Bauman89401822014-05-06 15:04:28 -0400740 factor.invBlendConstant4F[2][0] = 1 - blendConstant.b;
741 factor.invBlendConstant4F[2][1] = 1 - blendConstant.b;
742 factor.invBlendConstant4F[2][2] = 1 - blendConstant.b;
743 factor.invBlendConstant4F[2][3] = 1 - blendConstant.b;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500744
John Bauman89401822014-05-06 15:04:28 -0400745 factor.invBlendConstant4F[3][0] = 1 - blendConstant.a;
746 factor.invBlendConstant4F[3][1] = 1 - blendConstant.a;
747 factor.invBlendConstant4F[3][2] = 1 - blendConstant.a;
748 factor.invBlendConstant4F[3][3] = 1 - blendConstant.a;
749 }
750
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400751 void PixelProcessor::setFillMode(FillMode fillMode)
John Bauman89401822014-05-06 15:04:28 -0400752 {
753 context->fillMode = fillMode;
754 }
755
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400756 void PixelProcessor::setShadingMode(ShadingMode shadingMode)
John Bauman89401822014-05-06 15:04:28 -0400757 {
758 context->shadingMode = shadingMode;
759 }
760
761 void PixelProcessor::setAlphaBlendEnable(bool alphaBlendEnable)
762 {
763 context->setAlphaBlendEnable(alphaBlendEnable);
764 }
765
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400766 void PixelProcessor::setSourceBlendFactor(BlendFactor sourceBlendFactor)
John Bauman89401822014-05-06 15:04:28 -0400767 {
768 context->setSourceBlendFactor(sourceBlendFactor);
769 }
770
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400771 void PixelProcessor::setDestBlendFactor(BlendFactor destBlendFactor)
John Bauman89401822014-05-06 15:04:28 -0400772 {
773 context->setDestBlendFactor(destBlendFactor);
774 }
775
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400776 void PixelProcessor::setBlendOperation(BlendOperation blendOperation)
John Bauman89401822014-05-06 15:04:28 -0400777 {
778 context->setBlendOperation(blendOperation);
779 }
780
781 void PixelProcessor::setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable)
782 {
783 context->setSeparateAlphaBlendEnable(separateAlphaBlendEnable);
784 }
785
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400786 void PixelProcessor::setSourceBlendFactorAlpha(BlendFactor sourceBlendFactorAlpha)
John Bauman89401822014-05-06 15:04:28 -0400787 {
788 context->setSourceBlendFactorAlpha(sourceBlendFactorAlpha);
789 }
790
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400791 void PixelProcessor::setDestBlendFactorAlpha(BlendFactor destBlendFactorAlpha)
John Bauman89401822014-05-06 15:04:28 -0400792 {
793 context->setDestBlendFactorAlpha(destBlendFactorAlpha);
794 }
795
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400796 void PixelProcessor::setBlendOperationAlpha(BlendOperation blendOperationAlpha)
John Bauman89401822014-05-06 15:04:28 -0400797 {
798 context->setBlendOperationAlpha(blendOperationAlpha);
799 }
800
Alexis Hetua818c452015-06-11 13:06:58 -0400801 void PixelProcessor::setAlphaReference(float alphaReference)
John Bauman89401822014-05-06 15:04:28 -0400802 {
803 context->alphaReference = alphaReference;
804
Alexis Hetua818c452015-06-11 13:06:58 -0400805 factor.alphaReference4[0] = (word)iround(alphaReference * 0x1000 / 0xFF);
806 factor.alphaReference4[1] = (word)iround(alphaReference * 0x1000 / 0xFF);
807 factor.alphaReference4[2] = (word)iround(alphaReference * 0x1000 / 0xFF);
808 factor.alphaReference4[3] = (word)iround(alphaReference * 0x1000 / 0xFF);
John Bauman89401822014-05-06 15:04:28 -0400809 }
810
811 void PixelProcessor::setGlobalMipmapBias(float bias)
812 {
813 context->setGlobalMipmapBias(bias);
814 }
815
816 void PixelProcessor::setFogStart(float start)
817 {
818 setFogRanges(start, context->fogEnd);
819 }
820
821 void PixelProcessor::setFogEnd(float end)
822 {
823 setFogRanges(context->fogStart, end);
824 }
825
826 void PixelProcessor::setFogColor(Color<float> fogColor)
827 {
828 // TODO: Compact into generic function
829 word fogR = (unsigned short)(65535 * fogColor.r);
830 word fogG = (unsigned short)(65535 * fogColor.g);
831 word fogB = (unsigned short)(65535 * fogColor.b);
832
833 fog.color4[0][0] = fogR;
834 fog.color4[0][1] = fogR;
835 fog.color4[0][2] = fogR;
836 fog.color4[0][3] = fogR;
837
838 fog.color4[1][0] = fogG;
839 fog.color4[1][1] = fogG;
840 fog.color4[1][2] = fogG;
841 fog.color4[1][3] = fogG;
842
843 fog.color4[2][0] = fogB;
844 fog.color4[2][1] = fogB;
845 fog.color4[2][2] = fogB;
846 fog.color4[2][3] = fogB;
847
848 fog.colorF[0] = replicate(fogColor.r);
849 fog.colorF[1] = replicate(fogColor.g);
850 fog.colorF[2] = replicate(fogColor.b);
851 }
852
853 void PixelProcessor::setFogDensity(float fogDensity)
854 {
855 fog.densityE = replicate(-fogDensity * 1.442695f); // 1/e^x = 2^(-x*1.44)
Nicolas Capensa36f3f92015-08-04 15:34:26 -0400856 fog.density2E = replicate(-fogDensity * fogDensity * 1.442695f);
John Bauman89401822014-05-06 15:04:28 -0400857 }
858
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400859 void PixelProcessor::setPixelFogMode(FogMode fogMode)
John Bauman89401822014-05-06 15:04:28 -0400860 {
861 context->pixelFogMode = fogMode;
862 }
863
864 void PixelProcessor::setPerspectiveCorrection(bool perspectiveEnable)
865 {
866 perspectiveCorrection = perspectiveEnable;
867 }
868
869 void PixelProcessor::setOcclusionEnabled(bool enable)
870 {
871 context->occlusionEnabled = enable;
872 }
873
874 void PixelProcessor::setRoutineCacheSize(int cacheSize)
875 {
876 delete routineCache;
John Bauman66b8ab22014-05-06 15:57:45 -0400877 routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536), precachePixel ? "sw-pixel" : 0);
John Bauman89401822014-05-06 15:04:28 -0400878 }
879
880 void PixelProcessor::setFogRanges(float start, float end)
881 {
882 context->fogStart = start;
883 context->fogEnd = end;
884
885 if(start == end)
886 {
887 end += 0.001f; // Hack: ensure there is a small range
888 }
889
890 float fogScale = -1.0f / (end - start);
891 float fogOffset = end * -fogScale;
892
893 fog.scale = replicate(fogScale);
894 fog.offset = replicate(fogOffset);
895 }
896
897 const PixelProcessor::State PixelProcessor::update() const
898 {
899 State state;
900
901 if(context->pixelShader)
902 {
John Bauman19bac1e2014-05-06 15:23:49 -0400903 state.shaderID = context->pixelShader->getSerialID();
John Bauman89401822014-05-06 15:04:28 -0400904 }
905 else
906 {
John Bauman19bac1e2014-05-06 15:23:49 -0400907 state.shaderID = 0;
John Bauman89401822014-05-06 15:04:28 -0400908 }
909
910 state.depthOverride = context->pixelShader && context->pixelShader->depthOverride();
John Bauman19bac1e2014-05-06 15:23:49 -0400911 state.shaderContainsKill = context->pixelShader ? context->pixelShader->containsKill() : false;
Nicolas Capens4f172c72016-01-13 08:34:30 -0500912
John Bauman89401822014-05-06 15:04:28 -0400913 if(context->alphaTestActive())
914 {
915 state.alphaCompareMode = context->alphaCompareMode;
916
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400917 state.transparencyAntialiasing = context->getMultiSampleCount() > 1 ? transparencyAntialiasing : TRANSPARENCY_NONE;
John Bauman89401822014-05-06 15:04:28 -0400918 }
919
920 state.depthWriteEnable = context->depthWriteActive();
921
922 if(context->stencilActive())
923 {
924 state.stencilActive = true;
925 state.stencilCompareMode = context->stencilCompareMode;
926 state.stencilFailOperation = context->stencilFailOperation;
927 state.stencilPassOperation = context->stencilPassOperation;
928 state.stencilZFailOperation = context->stencilZFailOperation;
929 state.noStencilMask = (context->stencilMask == 0xFF);
930 state.noStencilWriteMask = (context->stencilWriteMask == 0xFF);
931 state.stencilWriteMasked = (context->stencilWriteMask == 0x00);
932
933 state.twoSidedStencil = context->twoSidedStencil;
934 state.stencilCompareModeCCW = context->twoSidedStencil ? context->stencilCompareModeCCW : state.stencilCompareMode;
935 state.stencilFailOperationCCW = context->twoSidedStencil ? context->stencilFailOperationCCW : state.stencilFailOperation;
936 state.stencilPassOperationCCW = context->twoSidedStencil ? context->stencilPassOperationCCW : state.stencilPassOperation;
937 state.stencilZFailOperationCCW = context->twoSidedStencil ? context->stencilZFailOperationCCW : state.stencilZFailOperation;
938 state.noStencilMaskCCW = context->twoSidedStencil ? (context->stencilMaskCCW == 0xFF) : state.noStencilMask;
939 state.noStencilWriteMaskCCW = context->twoSidedStencil ? (context->stencilWriteMaskCCW == 0xFF) : state.noStencilWriteMask;
940 state.stencilWriteMaskedCCW = context->twoSidedStencil ? (context->stencilWriteMaskCCW == 0x00) : state.stencilWriteMasked;
941 }
942
943 if(context->depthBufferActive())
944 {
945 state.depthTestActive = true;
946 state.depthCompareMode = context->depthCompareMode;
Nicolas Capens3751c1e2016-03-21 14:14:14 -0400947 state.quadLayoutDepthBuffer = context->depthBuffer->getInternalFormat() != FORMAT_D32F_LOCKABLE &&
948 context->depthBuffer->getInternalFormat() != FORMAT_D32FS8_TEXTURE &&
949 context->depthBuffer->getInternalFormat() != FORMAT_D32FS8_SHADOW;
John Bauman89401822014-05-06 15:04:28 -0400950 }
951
952 state.occlusionEnabled = context->occlusionEnabled;
953
954 state.fogActive = context->fogActive();
955 state.pixelFogMode = context->pixelFogActive();
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400956 state.wBasedFog = context->wBasedFog && context->pixelFogActive() != FOG_NONE;
John Bauman89401822014-05-06 15:04:28 -0400957 state.perspective = context->perspectiveActive();
958
959 if(context->alphaBlendActive())
960 {
961 state.alphaBlendActive = true;
962 state.sourceBlendFactor = context->sourceBlendFactor();
963 state.destBlendFactor = context->destBlendFactor();
964 state.blendOperation = context->blendOperation();
965 state.sourceBlendFactorAlpha = context->sourceBlendFactorAlpha();
966 state.destBlendFactorAlpha = context->destBlendFactorAlpha();
967 state.blendOperationAlpha = context->blendOperationAlpha();
968 }
Maxime Grégoired9762742015-07-08 16:43:48 -0400969
970 state.logicalOperation = context->colorLogicOp();
971
John Bauman89401822014-05-06 15:04:28 -0400972 state.colorWriteMask = (context->colorWriteActive(0) << 0) |
973 (context->colorWriteActive(1) << 4) |
974 (context->colorWriteActive(2) << 8) |
975 (context->colorWriteActive(3) << 12);
976
Alexis Hetu1edcd8b2015-11-05 11:12:41 -0500977 for(int i = 0; i < RENDERTARGETS; i++)
John Bauman89401822014-05-06 15:04:28 -0400978 {
979 state.targetFormat[i] = context->renderTargetInternalFormat(i);
980 }
981
John Bauman66b8ab22014-05-06 15:57:45 -0400982 state.writeSRGB = context->writeSRGB && context->renderTarget[0] && Surface::isSRGBwritable(context->renderTarget[0]->getExternalFormat());
983 state.multiSample = context->getMultiSampleCount();
John Bauman89401822014-05-06 15:04:28 -0400984 state.multiSampleMask = context->multiSampleMask;
985
986 if(state.multiSample > 1 && context->pixelShader)
987 {
988 state.centroid = context->pixelShader->containsCentroid();
989 }
990
991 if(!context->pixelShader)
992 {
993 for(unsigned int i = 0; i < 8; i++)
994 {
995 state.textureStage[i] = context->textureStage[i].textureStageState();
996 }
997
998 state.specularAdd = context->specularActive() && context->specularEnable;
999 }
1000
1001 for(unsigned int i = 0; i < 16; i++)
1002 {
1003 if(context->pixelShader)
1004 {
1005 if(context->pixelShader->usesSampler(i))
1006 {
1007 state.sampler[i] = context->sampler[i].samplerState();
1008 }
1009 }
1010 else
1011 {
1012 if(i < 8 && state.textureStage[i].stageOperation != TextureStage::STAGE_DISABLE)
1013 {
1014 state.sampler[i] = context->sampler[i].samplerState();
1015 }
1016 else break;
1017 }
1018 }
1019
1020 const bool point = context->isDrawPoint(true);
1021 const bool sprite = context->pointSpriteActive();
Nicolas Capensa0f4be82014-10-22 14:35:30 -04001022 const bool flatShading = (context->shadingMode == SHADING_FLAT) || point;
John Bauman89401822014-05-06 15:04:28 -04001023
1024 if(context->pixelShaderVersion() < 0x0300)
1025 {
1026 for(int coordinate = 0; coordinate < 8; coordinate++)
1027 {
1028 for(int component = 0; component < 4; component++)
1029 {
1030 if(context->textureActive(coordinate, component))
1031 {
1032 state.texture[coordinate].component |= 1 << component;
1033
1034 if(point && !sprite)
1035 {
1036 state.texture[coordinate].flat |= 1 << component;
1037 }
1038 }
1039 }
1040
1041 if(context->textureTransformProject[coordinate] && context->pixelShaderVersion() <= 0x0103)
1042 {
1043 if(context->textureTransformCount[coordinate] == 2)
1044 {
1045 state.texture[coordinate].project = 1;
1046 }
1047 else if(context->textureTransformCount[coordinate] == 3)
1048 {
1049 state.texture[coordinate].project = 2;
1050 }
1051 else if(context->textureTransformCount[coordinate] == 4 || context->textureTransformCount[coordinate] == 0)
1052 {
1053 state.texture[coordinate].project = 3;
1054 }
1055 }
1056 }
1057
1058 for(int color = 0; color < 2; color++)
1059 {
1060 for(int component = 0; component < 4; component++)
1061 {
1062 if(context->colorActive(color, component))
1063 {
1064 state.color[color].component |= 1 << component;
Nicolas Capens4f172c72016-01-13 08:34:30 -05001065
John Bauman89401822014-05-06 15:04:28 -04001066 if(point || flatShading)
1067 {
1068 state.color[color].flat |= 1 << component;
1069 }
1070 }
1071 }
1072 }
1073
1074 if(context->fogActive())
1075 {
1076 state.fog.component = true;
Nicolas Capens4f172c72016-01-13 08:34:30 -05001077
John Bauman89401822014-05-06 15:04:28 -04001078 if(point)
1079 {
1080 state.fog.flat = true;
1081 }
1082 }
1083 }
1084 else
1085 {
1086 for(int interpolant = 0; interpolant < 10; interpolant++)
1087 {
1088 for(int component = 0; component < 4; component++)
1089 {
1090 if(context->pixelShader->semantic[interpolant][component].active())
1091 {
1092 bool flat = point;
1093
1094 switch(context->pixelShader->semantic[interpolant][component].usage)
1095 {
John Bauman19bac1e2014-05-06 15:23:49 -04001096 case Shader::USAGE_TEXCOORD: flat = point && !sprite; break;
1097 case Shader::USAGE_COLOR: flat = flatShading; break;
John Bauman89401822014-05-06 15:04:28 -04001098 }
1099
1100 state.interpolant[interpolant].component |= 1 << component;
1101
1102 if(flat)
1103 {
1104 state.interpolant[interpolant].flat |= 1 << component;
1105 }
1106 }
1107 }
1108 }
1109 }
1110
1111 if(state.centroid)
1112 {
1113 for(int interpolant = 0; interpolant < 10; interpolant++)
1114 {
1115 for(int component = 0; component < 4; component++)
1116 {
1117 state.interpolant[interpolant].centroid = context->pixelShader->semantic[interpolant][0].centroid;
1118 }
1119 }
1120 }
1121
1122 state.hash = state.computeHash();
1123
1124 return state;
1125 }
1126
1127 Routine *PixelProcessor::routine(const State &state)
1128 {
1129 Routine *routine = routineCache->query(state);
1130
1131 if(!routine)
1132 {
Alexis Hetuf2a8c372015-07-13 11:08:41 -04001133 const bool integerPipeline = (context->pixelShaderVersion() <= 0x0104);
Nicolas Capensba53fbf2016-01-14 13:43:42 -05001134 QuadRasterizer *generator = nullptr;
Nicolas Capens4f172c72016-01-13 08:34:30 -05001135
Alexis Hetuf2a8c372015-07-13 11:08:41 -04001136 if(integerPipeline)
1137 {
1138 generator = new PixelPipeline(state, context->pixelShader);
1139 }
1140 else
1141 {
1142 generator = new PixelProgram(state, context->pixelShader);
1143 }
Nicolas Capens4f172c72016-01-13 08:34:30 -05001144
John Bauman89401822014-05-06 15:04:28 -04001145 generator->generate();
Nicolas Capens4f172c72016-01-13 08:34:30 -05001146 routine = (*generator)(L"PixelRoutine_%0.8X", state.shaderID);
John Bauman89401822014-05-06 15:04:28 -04001147 delete generator;
1148
1149 routineCache->add(state, routine);
1150 }
1151
1152 return routine;
1153 }
1154}