forked from microsoft/FX11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EffectRuntime.cpp
722 lines (623 loc) · 26.2 KB
/
EffectRuntime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
//--------------------------------------------------------------------------------------
// File: EffectRuntime.cpp
//
// Direct3D 11 Effect runtime routines (performance critical)
// These functions are expected to be called at high frequency
// (when applying a pass).
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/p/?LinkId=271568
//--------------------------------------------------------------------------------------
#include "pchfx.h"
namespace D3DX11Effects
{
// D3D11_KEEP_UNORDERED_ACCESS_VIEWS == (uint32_t)-1
uint32_t g_pNegativeOnes[8] = { D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS,
D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS,
D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS };
bool SBaseBlock::ApplyAssignments(CEffect *pEffect)
{
SAssignment *pAssignment = pAssignments;
SAssignment *pLastAssn = pAssignments + AssignmentCount;
bool bRecreate = false;
for(; pAssignment < pLastAssn; pAssignment++)
{
bRecreate |= pEffect->EvaluateAssignment(pAssignment);
}
return bRecreate;
}
void SPassBlock::ApplyPassAssignments()
{
SAssignment *pAssignment = pAssignments;
SAssignment *pLastAssn = pAssignments + AssignmentCount;
pEffect->IncrementTimer();
for(; pAssignment < pLastAssn; pAssignment++)
{
pEffect->EvaluateAssignment(pAssignment);
}
}
// Returns true if the shader uses global interfaces (since these interfaces can be updated through SetClassInstance)
bool SPassBlock::CheckShaderDependencies( _In_ const SShaderBlock* pBlock )
{
if( pBlock->InterfaceDepCount > 0 )
{
assert( pBlock->InterfaceDepCount == 1 );
for( size_t i=0; i < pBlock->pInterfaceDeps[0].Count; i++ )
{
SInterface* pInterfaceDep = pBlock->pInterfaceDeps[0].ppFXPointers[i];
if( pInterfaceDep > pEffect->m_pInterfaces && pInterfaceDep < (pEffect->m_pInterfaces + pEffect->m_InterfaceCount) )
{
// This is a global interface pointer (as opposed to an SInterface created in a BindInterface call
return true;
}
}
}
return false;
}
// Returns true if the pass (and sets HasDependencies) if the pass sets objects whose backing stores can be updated
#pragma warning(push)
#pragma warning(disable: 4616 6282)
bool SPassBlock::CheckDependencies()
{
if( HasDependencies )
return true;
for( size_t i=0; i < AssignmentCount; i++ )
{
if( pAssignments[i].DependencyCount > 0 )
return HasDependencies = true;
}
if( BackingStore.pBlendBlock && BackingStore.pBlendBlock->AssignmentCount > 0 )
{
for( size_t i=0; i < BackingStore.pBlendBlock->AssignmentCount; i++ )
{
if( BackingStore.pBlendBlock->pAssignments[i].DependencyCount > 0 )
return HasDependencies = true;
}
}
if( BackingStore.pDepthStencilBlock && BackingStore.pDepthStencilBlock->AssignmentCount > 0 )
{
for( size_t i=0; i < BackingStore.pDepthStencilBlock->AssignmentCount; i++ )
{
if( BackingStore.pDepthStencilBlock->pAssignments[i].DependencyCount > 0 )
return HasDependencies = true;
}
}
if( BackingStore.pRasterizerBlock && BackingStore.pRasterizerBlock->AssignmentCount > 0 )
{
for( size_t i=0; i < BackingStore.pRasterizerBlock->AssignmentCount; i++ )
{
if( BackingStore.pRasterizerBlock->pAssignments[i].DependencyCount > 0 )
return HasDependencies = true;
}
}
if( BackingStore.pVertexShaderBlock && CheckShaderDependencies( BackingStore.pVertexShaderBlock ) )
{
return HasDependencies = true;
}
if( BackingStore.pGeometryShaderBlock && CheckShaderDependencies( BackingStore.pGeometryShaderBlock ) )
{
return HasDependencies = true;
}
if( BackingStore.pPixelShaderBlock && CheckShaderDependencies( BackingStore.pPixelShaderBlock ) )
{
return HasDependencies = true;
}
if( BackingStore.pHullShaderBlock && CheckShaderDependencies( BackingStore.pHullShaderBlock ) )
{
return HasDependencies = true;
}
if( BackingStore.pDomainShaderBlock && CheckShaderDependencies( BackingStore.pDomainShaderBlock ) )
{
return HasDependencies = true;
}
if( BackingStore.pComputeShaderBlock && CheckShaderDependencies( BackingStore.pComputeShaderBlock ) )
{
return HasDependencies = true;
}
return HasDependencies;
}
#pragma warning(pop)
// Update constant buffer contents if necessary
inline void CheckAndUpdateCB_FX(ID3D11DeviceContext *pContext, SConstantBuffer *pCB)
{
if (pCB->IsDirty && !pCB->IsNonUpdatable)
{
// CB out of date; rebuild it
pContext->UpdateSubresource(pCB->pD3DObject, 0, nullptr, pCB->pBackingStore, pCB->Size, pCB->Size);
pCB->IsDirty = false;
}
}
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Set the shader and dependent state (SRVs, samplers, UAVs, interfaces)
void CEffect::ApplyShaderBlock(_In_ SShaderBlock *pBlock)
{
SD3DShaderVTable *pVT = pBlock->pVT;
// Apply constant buffers first (tbuffers are done later)
SShaderCBDependency *pCBDep = pBlock->pCBDeps;
SShaderCBDependency *pLastCBDep = pBlock->pCBDeps + pBlock->CBDepCount;
for (; pCBDep<pLastCBDep; pCBDep++)
{
assert(pCBDep->ppFXPointers);
for (size_t i = 0; i < pCBDep->Count; ++ i)
{
CheckAndUpdateCB_FX(m_pContext, (SConstantBuffer*)pCBDep->ppFXPointers[i]);
}
(m_pContext->*(pVT->pSetConstantBuffers))(pCBDep->StartIndex, pCBDep->Count, pCBDep->ppD3DObjects);
}
// Next, apply samplers
SShaderSamplerDependency *pSampDep = pBlock->pSampDeps;
SShaderSamplerDependency *pLastSampDep = pBlock->pSampDeps + pBlock->SampDepCount;
for (; pSampDep<pLastSampDep; pSampDep++)
{
assert(pSampDep->ppFXPointers);
for (size_t i=0; i<pSampDep->Count; i++)
{
if ( ApplyRenderStateBlock(pSampDep->ppFXPointers[i]) )
{
// If the sampler was updated, its pointer will have changed
pSampDep->ppD3DObjects[i] = pSampDep->ppFXPointers[i]->pD3DObject;
}
}
(m_pContext->*(pVT->pSetSamplers))(pSampDep->StartIndex, pSampDep->Count, pSampDep->ppD3DObjects);
}
// Set the UAVs
// UAV ranges were combined in EffectLoad. This code remains unchanged, however, so that ranges can be easily split
assert( pBlock->UAVDepCount < 2 );
if( pBlock->UAVDepCount > 0 )
{
SUnorderedAccessViewDependency *pUAVDep = pBlock->pUAVDeps;
assert(pUAVDep->ppFXPointers != 0);
_Analysis_assume_(pUAVDep->ppFXPointers != 0);
for (size_t i=0; i<pUAVDep->Count; i++)
{
pUAVDep->ppD3DObjects[i] = pUAVDep->ppFXPointers[i]->pUnorderedAccessView;
}
if( EOT_ComputeShader5 == pBlock->GetShaderType() )
{
m_pContext->CSSetUnorderedAccessViews( pUAVDep->StartIndex, pUAVDep->Count, pUAVDep->ppD3DObjects, g_pNegativeOnes );
}
else
{
// This call could be combined with the call to set render targets if both exist in the pass
m_pContext->OMSetRenderTargetsAndUnorderedAccessViews( D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, pUAVDep->StartIndex, pUAVDep->Count, pUAVDep->ppD3DObjects, g_pNegativeOnes );
}
}
// TBuffers are funny:
// We keep two references to them. One is in as a standard texture dep, and that gets used for all sets
// The other is as a part of the TBufferDeps array, which tells us to rebuild the matching CBs.
// These two refs could be rolled into one, but then we would have to predicate on each CB or each texture.
SConstantBuffer **ppTB = pBlock->ppTbufDeps;
SConstantBuffer **ppLastTB = ppTB + pBlock->TBufferDepCount;
for (; ppTB<ppLastTB; ppTB++)
{
CheckAndUpdateCB_FX(m_pContext, (SConstantBuffer*)*ppTB);
}
// Set the textures
SShaderResourceDependency *pResourceDep = pBlock->pResourceDeps;
SShaderResourceDependency *pLastResourceDep = pBlock->pResourceDeps + pBlock->ResourceDepCount;
for (; pResourceDep<pLastResourceDep; pResourceDep++)
{
assert(pResourceDep->ppFXPointers != 0);
_Analysis_assume_(pResourceDep->ppFXPointers != 0);
for (size_t i=0; i<pResourceDep->Count; i++)
{
pResourceDep->ppD3DObjects[i] = pResourceDep->ppFXPointers[i]->pShaderResource;
}
(m_pContext->*(pVT->pSetShaderResources))(pResourceDep->StartIndex, pResourceDep->Count, pResourceDep->ppD3DObjects);
}
// Update Interface dependencies
uint32_t Interfaces = 0;
ID3D11ClassInstance** ppClassInstances = nullptr;
assert( pBlock->InterfaceDepCount < 2 );
if( pBlock->InterfaceDepCount > 0 )
{
SInterfaceDependency *pInterfaceDep = pBlock->pInterfaceDeps;
assert(pInterfaceDep->ppFXPointers);
ppClassInstances = pInterfaceDep->ppD3DObjects;
Interfaces = pInterfaceDep->Count;
for (size_t i=0; i<pInterfaceDep->Count; i++)
{
assert(pInterfaceDep->ppFXPointers != 0);
_Analysis_assume_(pInterfaceDep->ppFXPointers != 0);
SClassInstanceGlobalVariable* pCI = pInterfaceDep->ppFXPointers[i]->pClassInstance;
if( pCI )
{
assert( pCI->pMemberData != 0 );
_Analysis_assume_( pCI->pMemberData != 0 );
pInterfaceDep->ppD3DObjects[i] = pCI->pMemberData->Data.pD3DClassInstance;
}
else
{
pInterfaceDep->ppD3DObjects[i] = nullptr;
}
}
}
// Now set the shader
(m_pContext->*(pVT->pSetShader))(pBlock->pD3DObject, ppClassInstances, Interfaces);
}
// Returns true if the block D3D data was recreated
bool CEffect::ApplyRenderStateBlock(_In_ SBaseBlock *pBlock)
{
if( pBlock->IsUserManaged )
{
return false;
}
bool bRecreate = pBlock->ApplyAssignments(this);
if (bRecreate)
{
switch (pBlock->BlockType)
{
case EBT_Sampler:
{
SSamplerBlock *pSBlock = pBlock->AsSampler();
assert(pSBlock->pD3DObject != 0);
_Analysis_assume_(pSBlock->pD3DObject != 0);
pSBlock->pD3DObject->Release();
HRESULT hr = m_pDevice->CreateSamplerState( &pSBlock->BackingStore.SamplerDesc, &pSBlock->pD3DObject );
if ( SUCCEEDED(hr) )
{
SetDebugObjectName(pSBlock->pD3DObject, "D3DX11Effect");
}
}
break;
case EBT_DepthStencil:
{
SDepthStencilBlock *pDSBlock = pBlock->AsDepthStencil();
assert(nullptr != pDSBlock->pDSObject);
SAFE_RELEASE( pDSBlock->pDSObject );
if( SUCCEEDED( m_pDevice->CreateDepthStencilState( &pDSBlock->BackingStore, &pDSBlock->pDSObject ) ) )
{
pDSBlock->IsValid = true;
SetDebugObjectName( pDSBlock->pDSObject, "D3DX11Effect" );
}
else
pDSBlock->IsValid = false;
}
break;
case EBT_Blend:
{
SBlendBlock *pBBlock = pBlock->AsBlend();
assert(nullptr != pBBlock->pBlendObject);
SAFE_RELEASE( pBBlock->pBlendObject );
if( SUCCEEDED( m_pDevice->CreateBlendState( &pBBlock->BackingStore, &pBBlock->pBlendObject ) ) )
{
pBBlock->IsValid = true;
SetDebugObjectName( pBBlock->pBlendObject, "D3DX11Effect" );
}
else
pBBlock->IsValid = false;
}
break;
case EBT_Rasterizer:
{
SRasterizerBlock *pRBlock = pBlock->AsRasterizer();
assert(nullptr != pRBlock->pRasterizerObject);
SAFE_RELEASE( pRBlock->pRasterizerObject );
if( SUCCEEDED( m_pDevice->CreateRasterizerState( &pRBlock->BackingStore, &pRBlock->pRasterizerObject ) ) )
{
pRBlock->IsValid = true;
SetDebugObjectName( pRBlock->pRasterizerObject, "D3DX11Effect" );
}
else
pRBlock->IsValid = false;
}
break;
default:
assert(0);
}
}
return bRecreate;
}
void CEffect::ValidateIndex(_In_ uint32_t Elements)
{
if (m_FXLIndex >= Elements)
{
DPF(0, "ID3DX11Effect: Overindexing variable array (size: %u, index: %u), using index = 0 instead", Elements, m_FXLIndex);
m_FXLIndex = 0;
}
}
// Returns true if the assignment was changed
bool CEffect::EvaluateAssignment(_Inout_ SAssignment *pAssignment)
{
bool bNeedUpdate = false;
SGlobalVariable *pVarDep0, *pVarDep1;
switch (pAssignment->AssignmentType)
{
case ERAT_NumericVariable:
assert(pAssignment->DependencyCount == 1);
if (pAssignment->pDependencies[0].pVariable->LastModifiedTime >= pAssignment->LastRecomputedTime)
{
memcpy(pAssignment->Destination.pNumeric, pAssignment->Source.pNumeric, pAssignment->DataSize);
bNeedUpdate = true;
}
break;
case ERAT_NumericVariableIndex:
assert(pAssignment->DependencyCount == 2);
pVarDep0 = pAssignment->pDependencies[0].pVariable;
pVarDep1 = pAssignment->pDependencies[1].pVariable;
if (pVarDep0->LastModifiedTime >= pAssignment->LastRecomputedTime)
{
m_FXLIndex = *pVarDep0->Data.pNumericDword;
ValidateIndex(pVarDep1->pType->Elements);
// Array index variable is dirty, update the pointer
pAssignment->Source.pNumeric = pVarDep1->Data.pNumeric + pVarDep1->pType->Stride * m_FXLIndex;
// Copy the new data
memcpy(pAssignment->Destination.pNumeric, pAssignment->Source.pNumeric, pAssignment->DataSize);
bNeedUpdate = true;
}
else if (pVarDep1->LastModifiedTime >= pAssignment->LastRecomputedTime)
{
// Only the array variable is dirty, copy the new data
memcpy(pAssignment->Destination.pNumeric, pAssignment->Source.pNumeric, pAssignment->DataSize);
bNeedUpdate = true;
}
break;
case ERAT_ObjectVariableIndex:
assert(pAssignment->DependencyCount == 1);
pVarDep0 = pAssignment->pDependencies[0].pVariable;
if (pVarDep0->LastModifiedTime >= pAssignment->LastRecomputedTime)
{
m_FXLIndex = *pVarDep0->Data.pNumericDword;
ValidateIndex(pAssignment->MaxElements);
// Array index variable is dirty, update the destination pointer
*((void **)pAssignment->Destination.pGeneric) = pAssignment->Source.pNumeric +
pAssignment->DataSize * m_FXLIndex;
bNeedUpdate = true;
}
break;
default:
//case ERAT_Constant: -- These are consumed and discarded
//case ERAT_ObjectVariable: -- These are consumed and discarded
//case ERAT_ObjectConstIndex: -- These are consumed and discarded
//case ERAT_ObjectInlineShader: -- These are consumed and discarded
//case ERAT_NumericConstIndex: -- ERAT_NumericVariable should be generated instead
assert(0);
break;
}
// Mark the assignment as not dirty
pAssignment->LastRecomputedTime = m_LocalTimer;
return bNeedUpdate;
}
// Returns false if this shader has interface dependencies which are nullptr (SetShader will fail).
bool CEffect::ValidateShaderBlock( _Inout_ SShaderBlock* pBlock )
{
if( !pBlock->IsValid )
return false;
if( pBlock->InterfaceDepCount > 0 )
{
assert( pBlock->InterfaceDepCount == 1 );
for( size_t i=0; i < pBlock->pInterfaceDeps[0].Count; i++ )
{
SInterface* pInterfaceDep = pBlock->pInterfaceDeps[0].ppFXPointers[i];
assert( pInterfaceDep != 0 );
_Analysis_assume_( pInterfaceDep != 0 );
if( pInterfaceDep->pClassInstance == nullptr )
{
return false;
}
}
}
return true;
}
// Returns false if any state in the pass is invalid
bool CEffect::ValidatePassBlock( _Inout_ SPassBlock* pBlock )
{
pBlock->ApplyPassAssignments();
if (nullptr != pBlock->BackingStore.pBlendBlock)
{
ApplyRenderStateBlock(pBlock->BackingStore.pBlendBlock);
pBlock->BackingStore.pBlendState = pBlock->BackingStore.pBlendBlock->pBlendObject;
if( !pBlock->BackingStore.pBlendBlock->IsValid )
return false;
}
if( nullptr != pBlock->BackingStore.pDepthStencilBlock )
{
ApplyRenderStateBlock( pBlock->BackingStore.pDepthStencilBlock );
pBlock->BackingStore.pDepthStencilState = pBlock->BackingStore.pDepthStencilBlock->pDSObject;
if( !pBlock->BackingStore.pDepthStencilBlock->IsValid )
return false;
}
if( nullptr != pBlock->BackingStore.pRasterizerBlock )
{
ApplyRenderStateBlock( pBlock->BackingStore.pRasterizerBlock );
if( !pBlock->BackingStore.pRasterizerBlock->IsValid )
return false;
}
if( nullptr != pBlock->BackingStore.pVertexShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pVertexShaderBlock) )
return false;
if( nullptr != pBlock->BackingStore.pGeometryShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pGeometryShaderBlock) )
return false;
if( nullptr != pBlock->BackingStore.pPixelShaderBlock )
{
if( !ValidateShaderBlock(pBlock->BackingStore.pPixelShaderBlock) )
return false;
else if( pBlock->BackingStore.pPixelShaderBlock->UAVDepCount > 0 &&
pBlock->BackingStore.RenderTargetViewCount > pBlock->BackingStore.pPixelShaderBlock->pUAVDeps[0].StartIndex )
{
return false;
}
}
if( nullptr != pBlock->BackingStore.pHullShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pHullShaderBlock) )
return false;
if( nullptr != pBlock->BackingStore.pDomainShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pDomainShaderBlock) )
return false;
if( nullptr != pBlock->BackingStore.pComputeShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pComputeShaderBlock) )
return false;
return true;
}
// Set all state defined in the pass
void CEffect::ApplyPassBlock(_Inout_ SPassBlock *pBlock)
{
pBlock->ApplyPassAssignments();
if (nullptr != pBlock->BackingStore.pBlendBlock)
{
ApplyRenderStateBlock(pBlock->BackingStore.pBlendBlock);
#ifdef FXDEBUG
if( !pBlock->BackingStore.pBlendBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid BlendState." );
#endif
pBlock->BackingStore.pBlendState = pBlock->BackingStore.pBlendBlock->pBlendObject;
m_pContext->OMSetBlendState(pBlock->BackingStore.pBlendState,
pBlock->BackingStore.BlendFactor,
pBlock->BackingStore.SampleMask);
}
if (nullptr != pBlock->BackingStore.pDepthStencilBlock)
{
ApplyRenderStateBlock(pBlock->BackingStore.pDepthStencilBlock);
#ifdef FXDEBUG
if( !pBlock->BackingStore.pDepthStencilBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid DepthStencilState." );
#endif
pBlock->BackingStore.pDepthStencilState = pBlock->BackingStore.pDepthStencilBlock->pDSObject;
m_pContext->OMSetDepthStencilState(pBlock->BackingStore.pDepthStencilState,
pBlock->BackingStore.StencilRef);
}
if (nullptr != pBlock->BackingStore.pRasterizerBlock)
{
ApplyRenderStateBlock(pBlock->BackingStore.pRasterizerBlock);
#ifdef FXDEBUG
if( !pBlock->BackingStore.pRasterizerBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid RasterizerState." );
#endif
m_pContext->RSSetState(pBlock->BackingStore.pRasterizerBlock->pRasterizerObject);
}
if (nullptr != pBlock->BackingStore.pRenderTargetViews[0])
{
// Grab all render targets
ID3D11RenderTargetView *pRTV[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
assert(pBlock->BackingStore.RenderTargetViewCount <= D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT);
_Analysis_assume_(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT >= pBlock->BackingStore.RenderTargetViewCount);
for (uint32_t i=0; i<pBlock->BackingStore.RenderTargetViewCount; i++)
{
pRTV[i] = pBlock->BackingStore.pRenderTargetViews[i]->pRenderTargetView;
}
// This call could be combined with the call to set PS UAVs if both exist in the pass
m_pContext->OMSetRenderTargetsAndUnorderedAccessViews( pBlock->BackingStore.RenderTargetViewCount, pRTV, pBlock->BackingStore.pDepthStencilView->pDepthStencilView, 7, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, nullptr, nullptr );
}
if (nullptr != pBlock->BackingStore.pVertexShaderBlock)
{
#ifdef FXDEBUG
if( !pBlock->BackingStore.pVertexShaderBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid vertex shader." );
#endif
ApplyShaderBlock(pBlock->BackingStore.pVertexShaderBlock);
}
if (nullptr != pBlock->BackingStore.pPixelShaderBlock)
{
#ifdef FXDEBUG
if( !pBlock->BackingStore.pPixelShaderBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid pixel shader." );
#endif
ApplyShaderBlock(pBlock->BackingStore.pPixelShaderBlock);
}
if (nullptr != pBlock->BackingStore.pGeometryShaderBlock)
{
#ifdef FXDEBUG
if( !pBlock->BackingStore.pGeometryShaderBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid geometry shader." );
#endif
ApplyShaderBlock(pBlock->BackingStore.pGeometryShaderBlock);
}
if (nullptr != pBlock->BackingStore.pHullShaderBlock)
{
#ifdef FXDEBUG
if( !pBlock->BackingStore.pHullShaderBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid hull shader." );
#endif
ApplyShaderBlock(pBlock->BackingStore.pHullShaderBlock);
}
if (nullptr != pBlock->BackingStore.pDomainShaderBlock)
{
#ifdef FXDEBUG
if( !pBlock->BackingStore.pDomainShaderBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid domain shader." );
#endif
ApplyShaderBlock(pBlock->BackingStore.pDomainShaderBlock);
}
if (nullptr != pBlock->BackingStore.pComputeShaderBlock)
{
#ifdef FXDEBUG
if( !pBlock->BackingStore.pComputeShaderBlock->IsValid )
DPF( 0, "Pass::Apply - warning: applying invalid compute shader." );
#endif
ApplyShaderBlock(pBlock->BackingStore.pComputeShaderBlock);
}
}
void CEffect::IncrementTimer()
{
m_LocalTimer++;
#ifndef _M_X64
#if _DEBUG
if (m_LocalTimer > g_TimerRolloverCount)
{
DPF(0, "Rolling over timer (current time: %u, rollover cap: %u).", m_LocalTimer, g_TimerRolloverCount);
#else
if (m_LocalTimer >= 0x80000000) // check to see if we've exceeded ~2 billion
{
#endif
HandleLocalTimerRollover();
m_LocalTimer = 1;
}
#endif // _M_X64
}
// This function resets all timers, rendering all assignments dirty
// This is clearly bad for performance, but should only happen every few billion ticks
void CEffect::HandleLocalTimerRollover()
{
uint32_t i, j, k;
// step 1: update variables
for (i = 0; i < m_VariableCount; ++ i)
{
m_pVariables[i].LastModifiedTime = 0;
}
// step 2: update assignments on all blocks (pass, depth stencil, rasterizer, blend, sampler)
for (uint32_t iGroup = 0; iGroup < m_GroupCount; ++ iGroup)
{
for (i = 0; i < m_pGroups[iGroup].TechniqueCount; ++ i)
{
for (j = 0; j < m_pGroups[iGroup].pTechniques[i].PassCount; ++ j)
{
for (k = 0; k < m_pGroups[iGroup].pTechniques[i].pPasses[j].AssignmentCount; ++ k)
{
m_pGroups[iGroup].pTechniques[i].pPasses[j].pAssignments[k].LastRecomputedTime = 0;
}
}
}
}
for (i = 0; i < m_DepthStencilBlockCount; ++ i)
{
for (j = 0; j < m_pDepthStencilBlocks[i].AssignmentCount; ++ j)
{
m_pDepthStencilBlocks[i].pAssignments[j].LastRecomputedTime = 0;
}
}
for (i = 0; i < m_RasterizerBlockCount; ++ i)
{
for (j = 0; j < m_pRasterizerBlocks[i].AssignmentCount; ++ j)
{
m_pRasterizerBlocks[i].pAssignments[j].LastRecomputedTime = 0;
}
}
for (i = 0; i < m_BlendBlockCount; ++ i)
{
for (j = 0; j < m_pBlendBlocks[i].AssignmentCount; ++ j)
{
m_pBlendBlocks[i].pAssignments[j].LastRecomputedTime = 0;
}
}
for (i = 0; i < m_SamplerBlockCount; ++ i)
{
for (j = 0; j < m_pSamplerBlocks[i].AssignmentCount; ++ j)
{
m_pSamplerBlocks[i].pAssignments[j].LastRecomputedTime = 0;
}
}
}
}