kodi
Effect.h
1 //--------------------------------------------------------------------------------------
2 // File: Effect.h
3 //
4 // Direct3D 11 Effects Header for ID3DX11Effect Implementation
5 //
6 // Copyright (c) Microsoft Corporation.
7 // Licensed under the MIT License.
8 //
9 // http://go.microsoft.com/fwlink/p/?LinkId=271568
10 //--------------------------------------------------------------------------------------
11 
12 #pragma once
13 
14 #include "EffectBinaryFormat.h"
15 #include "IUnknownImp.h"
16 
17 #ifdef _DEBUG
18 extern void __cdecl D3DXDebugPrintf(UINT lvl, _In_z_ _Printf_format_string_ LPCSTR szFormat, ...);
19 #define DPF D3DXDebugPrintf
20 #else
21 #define DPF
22 #endif
23 
24 #pragma warning(push)
25 #pragma warning(disable : 4481)
26 // VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012
27 
29 
30 using namespace D3DX11Core;
31 
32 namespace D3DX11Effects
33 {
34 
36 // Forward defines
38 
39 struct SBaseBlock;
40 struct SShaderBlock;
41 struct SPassBlock;
42 struct SClassInstance;
43 struct SInterface;
44 struct SShaderResource;
45 struct SUnorderedAccessView;
46 struct SRenderTargetView;
47 struct SDepthStencilView;
48 struct SSamplerBlock;
49 struct SDepthStencilBlock;
50 struct SBlendBlock;
51 struct SRasterizerBlock;
52 struct SString;
53 struct SD3DShaderVTable;
54 struct SClassInstanceGlobalVariable;
55 
56 struct SAssignment;
57 struct SVariable;
58 struct SGlobalVariable;
59 struct SAnnotation;
60 struct SConstantBuffer;
61 
62 class CEffect;
63 class CEffectLoader;
64 
65 enum ELhsType : int;
66 
67 // Allows the use of 32-bit and 64-bit timers depending on platform type
68 typedef size_t Timer;
69 
71 // Reflection & Type structures
73 
74 // CEffectMatrix is used internally instead of float arrays
76 {
77  union
78  {
79  struct
80  {
81  float _11, _12, _13, _14;
82  float _21, _22, _23, _24;
83  float _31, _32, _33, _34;
84  float _41, _42, _43, _44;
85 
86  };
87  float m[4][4];
88  };
89 };
90 
92 {
93  float x;
94  float y;
95  float z;
96  float w;
97 };
98 
100 {
101  void *pGeneric;
102  uint8_t *pNumeric;
103  float *pNumericFloat;
104  uint32_t *pNumericDword;
105  int *pNumericInt;
106  BOOL *pNumericBool;
107  SString *pString;
108  SShaderBlock *pShader;
109  SBaseBlock *pBlock;
110  SBlendBlock *pBlend;
111  SDepthStencilBlock *pDepthStencil;
112  SRasterizerBlock *pRasterizer;
113  SInterface *pInterface;
114  SShaderResource *pShaderResource;
115  SUnorderedAccessView *pUnorderedAccessView;
116  SRenderTargetView *pRenderTargetView;
117  SDepthStencilView *pDepthStencilView;
118  SSamplerBlock *pSampler;
119  CEffectVector4 *pVector;
120  CEffectMatrix *pMatrix;
121  UINT_PTR Offset;
122 };
123 
124 enum EMemberDataType
125 {
126  MDT_ClassInstance,
127  MDT_BlendState,
128  MDT_DepthStencilState,
129  MDT_RasterizerState,
130  MDT_SamplerState,
131  MDT_Buffer,
132  MDT_ShaderResourceView,
133 };
134 
136 {
137  EMemberDataType Type;
138  union
139  {
140  IUnknown *pGeneric;
141  ID3D11ClassInstance *pD3DClassInstance;
142  ID3D11BlendState *pD3DEffectsManagedBlendState;
143  ID3D11DepthStencilState *pD3DEffectsManagedDepthStencilState;
144  ID3D11RasterizerState *pD3DEffectsManagedRasterizerState;
145  ID3D11SamplerState *pD3DEffectsManagedSamplerState;
146  ID3D11Buffer *pD3DEffectsManagedConstantBuffer;
147  ID3D11ShaderResourceView*pD3DEffectsManagedTextureBuffer;
148  } Data;
149 };
150 
151 struct SType : public ID3DX11EffectType
152 {
153  static const UINT_PTR c_InvalidIndex = (uint32_t) -1;
154  static const uint32_t c_ScalarSize = sizeof(uint32_t);
155 
156  // packing rule constants
157  static const uint32_t c_ScalarsPerRegister = 4;
158  static const uint32_t c_RegisterSize = c_ScalarsPerRegister * c_ScalarSize; // must be a power of 2!!
159 
160  EVarType VarType; // numeric, object, struct
161  uint32_t Elements; // # of array elements (0 for non-arrays)
162  char *pTypeName; // friendly name of the type: "VS_OUTPUT", "float4", etc.
163 
164  // *Size and stride values are always 0 for object types
165  // *Annotations adhere to packing rules (even though they do not reside in constant buffers)
166  // for consistency's sake
167  //
168  // Packing rules:
169  // *Structures and array elements are always register aligned
170  // *Single-row values (or, for column major matrices, single-column) are greedily
171  // packed unless doing so would span a register boundary, in which case they are
172  // register aligned
173 
174  uint32_t TotalSize; // Total size of this data type in a constant buffer from
175  // start to finish (padding in between elements is included,
176  // but padding at the end is not since that would require
177  // knowledge of the following data type).
178 
179  uint32_t Stride; // Number of bytes to advance between elements.
180  // Typically a multiple of 16 for arrays, vectors, matrices.
181  // For scalars and small vectors/matrices, this can be 4 or 8.
182 
183  uint32_t PackedSize; // Size, in bytes, of this data typed when fully packed
184 
185  union
186  {
187  SBinaryNumericType NumericType;
188  EObjectType ObjectType; // not all values of EObjectType are valid here (e.g. constant buffer)
189  struct
190  {
191  SVariable *pMembers; // array of type instances describing structure members
192  uint32_t Members;
193  BOOL ImplementsInterface; // true if this type implements an interface
194  BOOL HasSuperClass; // true if this type has a parent class
195  } StructType;
196  void* InterfaceType; // nothing for interfaces
197  };
198 
199 
200  SType() noexcept :
201  VarType(EVT_Invalid),
202  Elements(0),
203  pTypeName(nullptr),
204  TotalSize(0),
205  Stride(0),
206  PackedSize(0),
207  StructType{}
208  {
209  static_assert(sizeof(NumericType) <= sizeof(StructType), "SType union issue");
210  static_assert(sizeof(ObjectType) <= sizeof(StructType), "SType union issue");
211  static_assert(sizeof(InterfaceType) <= sizeof(StructType), "SType union issue");
212  }
213 
214  bool IsEqual(SType *pOtherType) const;
215 
216  bool IsObjectType(EObjectType ObjType) const
217  {
218  return IsObjectTypeHelper(VarType, ObjectType, ObjType);
219  }
220  bool IsShader() const
221  {
222  return IsShaderHelper(VarType, ObjectType);
223  }
224  bool BelongsInConstantBuffer() const
225  {
226  return (VarType == EVT_Numeric) || (VarType == EVT_Struct);
227  }
228  bool IsStateBlockObject() const
229  {
230  return IsStateBlockObjectHelper(VarType, ObjectType);
231  }
232  bool IsClassInstance() const
233  {
234  return (VarType == EVT_Struct) && StructType.ImplementsInterface;
235  }
236  bool IsInterface() const
237  {
238  return IsInterfaceHelper(VarType, ObjectType);
239  }
240  bool IsShaderResource() const
241  {
242  return IsShaderResourceHelper(VarType, ObjectType);
243  }
244  bool IsUnorderedAccessView() const
245  {
246  return IsUnorderedAccessViewHelper(VarType, ObjectType);
247  }
248  bool IsSampler() const
249  {
250  return IsSamplerHelper(VarType, ObjectType);
251  }
252  bool IsRenderTargetView() const
253  {
254  return IsRenderTargetViewHelper(VarType, ObjectType);
255  }
256  bool IsDepthStencilView() const
257  {
258  return IsDepthStencilViewHelper(VarType, ObjectType);
259  }
260 
261  uint32_t GetTotalUnpackedSize(_In_ bool IsSingleElement) const;
262  uint32_t GetTotalPackedSize(_In_ bool IsSingleElement) const;
263  HRESULT GetDescHelper(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc, _In_ bool IsSingleElement) const;
264 
265  STDMETHOD_(bool, IsValid)() override { return true; }
266  STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override { return GetDescHelper(pDesc, false); }
267  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(_In_ uint32_t Index) override;
268  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(_In_z_ LPCSTR Name) override;
269  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(_In_z_ LPCSTR Semantic) override;
270  STDMETHOD_(LPCSTR, GetMemberName)(_In_ uint32_t Index) override;
271  STDMETHOD_(LPCSTR, GetMemberSemantic)(_In_ uint32_t Index) override;
272 
273  IUNKNOWN_IMP(SType, ID3DX11EffectType, IUnknown);
274 };
275 
276 // Represents a type structure for a single element.
277 // It seems pretty trivial, but it has a different virtual table which enables
278 // us to accurately represent a type that consists of a single element
279 struct SSingleElementType : public ID3DX11EffectType
280 {
281  SType *pType;
282 
283  STDMETHOD_(bool, IsValid)() override { return true; }
284  STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override { return ((SType*)pType)->GetDescHelper(pDesc, true); }
285  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(uint32_t Index) override { return ((SType*)pType)->GetMemberTypeByIndex(Index); }
286  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(LPCSTR Name) override { return ((SType*)pType)->GetMemberTypeByName(Name); }
287  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(LPCSTR Semantic) override { return ((SType*)pType)->GetMemberTypeBySemantic(Semantic); }
288  STDMETHOD_(LPCSTR, GetMemberName)(uint32_t Index) override { return ((SType*)pType)->GetMemberName(Index); }
289  STDMETHOD_(LPCSTR, GetMemberSemantic)(uint32_t Index) override { return ((SType*)pType)->GetMemberSemantic(Index); }
290 
291  IUNKNOWN_IMP(SSingleElementType, ID3DX11EffectType, IUnknown);
292 
293  SSingleElementType() noexcept :
294  pType(nullptr)
295  {
296  }
297 };
298 
300 // Block definitions
303 void * GetBlockByIndex(EVarType VarType, EObjectType ObjectType, void *pBaseBlock, uint32_t Index);
304 
306 {
307  EBlockType BlockType;
308 
309  bool IsUserManaged:1;
310 
311  uint32_t AssignmentCount;
312  SAssignment *pAssignments;
313 
314  SBaseBlock() noexcept;
315 
316  bool ApplyAssignments(CEffect *pEffect);
317 
318  inline SSamplerBlock *AsSampler() const
319  {
320  assert( BlockType == EBT_Sampler );
321  return (SSamplerBlock*) this;
322  }
323 
324  inline SDepthStencilBlock *AsDepthStencil() const
325  {
326  assert( BlockType == EBT_DepthStencil );
327  return (SDepthStencilBlock*) this;
328  }
329 
330  inline SBlendBlock *AsBlend() const
331  {
332  assert( BlockType == EBT_Blend );
333  return (SBlendBlock*) this;
334  }
335 
336  inline SRasterizerBlock *AsRasterizer() const
337  {
338  assert( BlockType == EBT_Rasterizer );
339  return (SRasterizerBlock*) this;
340  }
341 
342  inline SPassBlock *AsPass() const
343  {
344  assert( BlockType == EBT_Pass );
345  return (SPassBlock*) this;
346  }
347 };
348 
349 struct STechnique : public ID3DX11EffectTechnique
350 {
351  char *pName;
352 
353  uint32_t PassCount;
354  SPassBlock *pPasses;
355 
356  uint32_t AnnotationCount;
357  SAnnotation *pAnnotations;
358 
359  bool InitiallyValid;
360  bool HasDependencies;
361 
362  STechnique() noexcept;
364  STDMETHOD_(bool, IsValid)() override;
365  STDMETHOD(GetDesc)(_Out_ D3DX11_TECHNIQUE_DESC *pDesc) override;
366 
367  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
368  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
369 
370  STDMETHOD_(ID3DX11EffectPass*, GetPassByIndex)(_In_ uint32_t Index) override;
371  STDMETHOD_(ID3DX11EffectPass*, GetPassByName)(_In_z_ LPCSTR Name) override;
372 
373  STDMETHOD(ComputeStateBlockMask)(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask) override;
374 
375  IUNKNOWN_IMP(STechnique, ID3DX11EffectTechnique, IUnknown);
376 };
377 
378 struct SGroup : public ID3DX11EffectGroup
379 {
380  char *pName;
381 
382  uint32_t TechniqueCount;
383  STechnique *pTechniques;
384 
385  uint32_t AnnotationCount;
386  SAnnotation *pAnnotations;
387 
388  bool InitiallyValid;
389  bool HasDependencies;
390 
391  SGroup() noexcept;
392 
393  STDMETHOD_(bool, IsValid)() override;
394  STDMETHOD(GetDesc)(_Out_ D3DX11_GROUP_DESC *pDesc) override;
395 
396  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
397  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
398 
399  STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByIndex)(_In_ uint32_t Index) override;
400  STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByName)(_In_z_ LPCSTR Name) override;
401 
402  IUNKNOWN_IMP(SGroup, ID3DX11EffectGroup, IUnknown);
403 };
404 
405 struct SPassBlock : SBaseBlock, public ID3DX11EffectPass
406 {
407  struct
408  {
409  ID3D11BlendState* pBlendState;
410  FLOAT BlendFactor[4];
411  uint32_t SampleMask;
412  ID3D11DepthStencilState *pDepthStencilState;
413  uint32_t StencilRef;
414  union
415  {
416  D3D11_SO_DECLARATION_ENTRY *pEntry;
417  char *pEntryDesc;
418  } GSSODesc;
419 
420  // Pass assignments can write directly into these
421  SBlendBlock *pBlendBlock;
422  SDepthStencilBlock *pDepthStencilBlock;
423  SRasterizerBlock *pRasterizerBlock;
424  uint32_t RenderTargetViewCount;
425  SRenderTargetView *pRenderTargetViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
426  SDepthStencilView *pDepthStencilView;
427  SShaderBlock *pVertexShaderBlock;
428  SShaderBlock *pPixelShaderBlock;
429  SShaderBlock *pGeometryShaderBlock;
430  SShaderBlock *pComputeShaderBlock;
431  SShaderBlock *pDomainShaderBlock;
432  SShaderBlock *pHullShaderBlock;
433  } BackingStore;
434 
435  char *pName;
436 
437  uint32_t AnnotationCount;
438  SAnnotation *pAnnotations;
439 
440  CEffect *pEffect;
441 
442  bool InitiallyValid; // validity of all state objects and shaders in pass upon BindToDevice
443  bool HasDependencies; // if pass expressions or pass state blocks have dependencies on variables (if true, IsValid != InitiallyValid possibly)
444 
445  SPassBlock() noexcept;
447  void ApplyPassAssignments();
448  bool CheckShaderDependencies( _In_ const SShaderBlock* pBlock );
449  bool CheckDependencies();
450 
451  template<EObjectType EShaderType>
452  HRESULT GetShaderDescHelper(_Out_ D3DX11_PASS_SHADER_DESC *pDesc);
453 
454  STDMETHOD_(bool, IsValid)() override;
455  STDMETHOD(GetDesc)(_Out_ D3DX11_PASS_DESC *pDesc) override;
456 
457  STDMETHOD(GetVertexShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
458  STDMETHOD(GetGeometryShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
459  STDMETHOD(GetPixelShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
460  STDMETHOD(GetHullShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
461  STDMETHOD(GetDomainShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
462  STDMETHOD(GetComputeShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
464  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
465  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
466 
467  STDMETHOD(Apply)(_In_ uint32_t Flags, _In_ ID3D11DeviceContext* pContext) override;
468 
469  STDMETHOD(ComputeStateBlockMask)(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask) override;
470 
471  IUNKNOWN_IMP(SPassBlock, ID3DX11EffectPass, IUnknown);
472 };
473 
475 {
476  ID3D11DepthStencilState *pDSObject;
477  D3D11_DEPTH_STENCIL_DESC BackingStore;
478  bool IsValid;
479 
480  SDepthStencilBlock() noexcept;
481 };
482 
484 {
485  ID3D11BlendState *pBlendObject;
486  D3D11_BLEND_DESC BackingStore;
487  bool IsValid;
488 
489  SBlendBlock() noexcept;
490 };
491 
493 {
494  ID3D11RasterizerState *pRasterizerObject;
495  D3D11_RASTERIZER_DESC BackingStore;
496  bool IsValid;
497 
498  SRasterizerBlock() noexcept;
499 };
500 
502 {
503  ID3D11SamplerState *pD3DObject;
504  struct
505  {
506  D3D11_SAMPLER_DESC SamplerDesc;
507  // Sampler "TEXTURE" assignments can write directly into this
508  SShaderResource *pTexture;
509  } BackingStore;
510 
511  SSamplerBlock() noexcept;
512 };
513 
515 {
516  SClassInstanceGlobalVariable* pClassInstance;
517 
518  SInterface() noexcept :
519  pClassInstance(nullptr)
520  {
521  }
522 };
523 
525 {
526  ID3D11ShaderResourceView *pShaderResource;
527 
528  SShaderResource() noexcept :
529  pShaderResource(nullptr)
530  {
531  }
532 };
533 
535 {
536  ID3D11UnorderedAccessView *pUnorderedAccessView;
537 
538  SUnorderedAccessView() noexcept :
539  pUnorderedAccessView(nullptr)
540  {
541  }
542 };
543 
545 {
546  ID3D11RenderTargetView *pRenderTargetView;
547 
548  SRenderTargetView() noexcept :
549  pRenderTargetView(nullptr)
550  {
551  }
552 };
553 
555 {
556  ID3D11DepthStencilView *pDepthStencilView;
557 
558  SDepthStencilView() noexcept :
559  pDepthStencilView(nullptr)
560  {
561  }
562 };
563 
564 
565 template<class T, class D3DTYPE> struct SShaderDependency
566 {
567  uint32_t StartIndex;
568  uint32_t Count;
569 
570  T *ppFXPointers; // Array of ptrs to FX objects (CBs, SShaderResources, etc)
571  D3DTYPE *ppD3DObjects; // Array of ptrs to matching D3D objects
572 
573  SShaderDependency() noexcept :
574  StartIndex(0),
575  Count(0),
576  ppFXPointers(nullptr),
577  ppD3DObjects(nullptr)
578  {
579  }
580 };
581 
587 
588 // Shader VTables are used to eliminate branching in ApplyShaderBlock.
589 // The effect owns one D3DShaderVTables for each shader stage
591 {
592  void ( __stdcall ID3D11DeviceContext::*pSetShader)(ID3D11DeviceChild* pShader, ID3D11ClassInstance*const* ppClassInstances, uint32_t NumClassInstances);
593  void ( __stdcall ID3D11DeviceContext::*pSetConstantBuffers)(uint32_t StartConstantSlot, uint32_t NumBuffers, ID3D11Buffer *const *pBuffers);
594  void ( __stdcall ID3D11DeviceContext::*pSetSamplers)(uint32_t Offset, uint32_t NumSamplers, ID3D11SamplerState*const* pSamplers);
595  void ( __stdcall ID3D11DeviceContext::*pSetShaderResources)(uint32_t Offset, uint32_t NumResources, ID3D11ShaderResourceView *const *pResources);
596  HRESULT ( __stdcall ID3D11Device::*pCreateShader)(const void *pShaderBlob, size_t ShaderBlobSize, ID3D11ClassLinkage* pClassLinkage, ID3D11DeviceChild **ppShader);
597 };
598 
599 
601 {
602  enum ESigType
603  {
604  ST_Input,
605  ST_Output,
606  ST_PatchConstant,
607  };
608 
610  {
611  char *pName;
612  uint32_t Index;
613  };
614 
615  // this data is classified as reflection-only and will all be discarded at runtime
617  {
618  uint8_t *pBytecode;
619  uint32_t BytecodeLength;
620  char *pStreamOutDecls[4]; // set with ConstructGSWithSO
621  uint32_t RasterizedStream; // set with ConstructGSWithSO
622  BOOL IsNullGS;
623  ID3D11ShaderReflection *pReflection;
624  uint32_t InterfaceParameterCount; // set with BindInterfaces (used for function interface parameters)
625  SInterfaceParameter *pInterfaceParameters; // set with BindInterfaces (used for function interface parameters)
626  };
627 
628  bool IsValid;
629  SD3DShaderVTable *pVT;
630 
631  // This value is nullptr if the shader is nullptr or was never initialized
632  SReflectionData *pReflectionData;
633 
634  ID3D11DeviceChild *pD3DObject;
635 
636  uint32_t CBDepCount;
637  SShaderCBDependency *pCBDeps;
638 
639  uint32_t SampDepCount;
640  SShaderSamplerDependency *pSampDeps;
641 
642  uint32_t InterfaceDepCount;
643  SInterfaceDependency *pInterfaceDeps;
644 
645  uint32_t ResourceDepCount;
646  SShaderResourceDependency *pResourceDeps;
647 
648  uint32_t UAVDepCount;
649  SUnorderedAccessViewDependency *pUAVDeps;
650 
651  uint32_t TBufferDepCount;
652  SConstantBuffer **ppTbufDeps;
653 
654  ID3DBlob *pInputSignatureBlob; // The input signature is separated from the bytecode because it
655  // is always available, even after Optimize() has been called.
656 
657  SShaderBlock(SD3DShaderVTable *pVirtualTable = nullptr) noexcept;
658 
659  EObjectType GetShaderType();
660 
661  HRESULT OnDeviceBind();
662 
663  // Public API helpers
664  HRESULT ComputeStateBlockMask(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask);
665 
666  HRESULT GetShaderDesc(_Out_ D3DX11_EFFECT_SHADER_DESC *pDesc, _In_ bool IsInline);
667 
668  HRESULT GetVertexShader(_Outptr_ ID3D11VertexShader **ppVS);
669  HRESULT GetGeometryShader(_Outptr_ ID3D11GeometryShader **ppGS);
670  HRESULT GetPixelShader(_Outptr_ ID3D11PixelShader **ppPS);
671  HRESULT GetHullShader(_Outptr_ ID3D11HullShader **ppHS);
672  HRESULT GetDomainShader(_Outptr_ ID3D11DomainShader **ppDS);
673  HRESULT GetComputeShader(_Outptr_ ID3D11ComputeShader **ppCS);
674 
675  HRESULT GetSignatureElementDesc(_In_ ESigType SigType, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc);
676 };
677 
678 
679 
680 struct SString
681 {
682  char *pString;
683 
684  SString() noexcept :
685  pString(nullptr)
686  {
687  }
688 };
689 
690 
691 
693 // Global Variable & Annotation structure/interface definitions
695 
696 //
697 // This is a general structure that can describe
698 // annotations, variables, and structure members
699 //
700 struct SVariable
701 {
702  // For annotations/variables/variable members:
703  // 1) If numeric, pointer to data (for variables: points into backing store,
704  // for annotations, points into reflection heap)
705  // OR
706  // 2) If object, pointer to the block. If object array, subsequent array elements are found in
707  // contiguous blocks; the Nth block is found by ((<SpecificBlockType> *) pBlock) + N
708  // (this is because variables that are arrays of objects have their blocks allocated contiguously)
709  //
710  // For structure members:
711  // Offset of this member (in bytes) from parent structure (structure members must be numeric/struct)
712  UDataPointer Data;
713  union
714  {
715  uint32_t MemberDataOffsetPlus4; // 4 added so that 0 == nullptr can represent "unused"
716  SMemberDataPointer *pMemberData;
717  };
718 
719  SType *pType;
720  char *pName;
721  char *pSemantic;
722  uint32_t ExplicitBindPoint;
723 
724  SVariable() noexcept :
725  Data{},
726  pMemberData(nullptr),
727  pType(nullptr),
728  pName(nullptr),
729  pSemantic(nullptr),
730  ExplicitBindPoint(uint32_t(-1))
731  {
732  }
733 };
734 
735 // Template definitions for all of the various ID3DX11EffectVariable specializations
736 #include "EffectVariable.inl"
737 
738 
740 // ID3DX11EffectShaderVariable (SAnonymousShader implementation)
742 
743 struct SAnonymousShader : public TUncastableVariable<ID3DX11EffectShaderVariable>, public ID3DX11EffectType
744 {
745  SShaderBlock *pShaderBlock;
746 
747  SAnonymousShader(_In_opt_ SShaderBlock *pBlock = nullptr) noexcept;
748 
749  // ID3DX11EffectShaderVariable interface
750  STDMETHOD_(bool, IsValid)() override;
751  STDMETHOD_(ID3DX11EffectType*, GetType)() override;
752  STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override;
753 
754  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
755  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
756 
757  STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index) override;
758  STDMETHOD_(ID3DX11EffectVariable*, GetMemberByName)(_In_z_ LPCSTR Name) override;
759  STDMETHOD_(ID3DX11EffectVariable*, GetMemberBySemantic)(_In_z_ LPCSTR Semantic) override;
760 
761  STDMETHOD_(ID3DX11EffectVariable*, GetElement)(_In_ uint32_t Index) override;
762 
763  STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override;
764 
765  // other casts are handled by TUncastableVariable
766  STDMETHOD_(ID3DX11EffectShaderVariable*, AsShader)() override;
767 
768  STDMETHOD(SetRawValue)(_In_reads_bytes_(Count) const void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
769  STDMETHOD(GetRawValue)(_Out_writes_bytes_(Count) void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
770 
771  STDMETHOD(GetShaderDesc)(_In_ uint32_t ShaderIndex, _Out_ D3DX11_EFFECT_SHADER_DESC *pDesc) override;
772 
773  STDMETHOD(GetVertexShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11VertexShader **ppVS) override;
774  STDMETHOD(GetGeometryShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11GeometryShader **ppGS) override;
775  STDMETHOD(GetPixelShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11PixelShader **ppPS) override;
776  STDMETHOD(GetHullShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11HullShader **ppHS) override;
777  STDMETHOD(GetDomainShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11DomainShader **ppDS) override;
778  STDMETHOD(GetComputeShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11ComputeShader **ppCS) override;
779 
780  STDMETHOD(GetInputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
781  STDMETHOD(GetOutputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
782  STDMETHOD(GetPatchConstantSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
783 
784  // ID3DX11EffectType interface
785  STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override;
786  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(_In_ uint32_t Index) override;
787  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(_In_z_ LPCSTR Name) override;
788  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(_In_z_ LPCSTR Semantic) override;
789 
790  STDMETHOD_(LPCSTR, GetMemberName)(_In_ uint32_t Index) override;
791  STDMETHOD_(LPCSTR, GetMemberSemantic)(_In_ uint32_t Index) override;
792 
793  IUNKNOWN_IMP(SAnonymousShader, ID3DX11EffectShaderVariable, ID3DX11EffectVariable);
794 };
795 
797 // ID3DX11EffectConstantBuffer (SConstantBuffer implementation)
799 
800 struct SConstantBuffer : public TUncastableVariable<ID3DX11EffectConstantBuffer>, public ID3DX11EffectType
801 {
802  ID3D11Buffer *pD3DObject;
803  SShaderResource TBuffer; // nullptr iff IsTbuffer == false
804 
805  uint8_t *pBackingStore;
806  uint32_t Size; // in bytes
807 
808  char *pName;
809 
810  uint32_t AnnotationCount;
811  SAnnotation *pAnnotations;
812 
813  uint32_t VariableCount; // # of variables contained in this cbuffer
814  SGlobalVariable *pVariables; // array of size [VariableCount], points into effect's contiguous variable list
815  uint32_t ExplicitBindPoint; // Used when a CB has been explicitly bound (register(bXX)). -1 if not
816 
817  bool IsDirty:1; // Set when any member is updated; cleared on CB apply
818  bool IsTBuffer:1; // true iff TBuffer.pShaderResource != nullptr
819  bool IsUserManaged:1; // Set if you don't want effects to update this buffer
820  bool IsEffectOptimized:1;// Set if the effect has been optimized
821  bool IsUsedByExpression:1;// Set if used by any expressions
822  bool IsUserPacked:1; // Set if the elements have user-specified offsets
823  bool IsSingle:1; // Set to true if you want to share this CB with cloned Effects
824  bool IsNonUpdatable:1; // Set to true if you want to share this CB with cloned Effects
825 
826  union
827  {
828  // These are used to store the original ID3D11Buffer* for use in UndoSetConstantBuffer
829  uint32_t MemberDataOffsetPlus4; // 4 added so that 0 == nullptr can represent "unused"
830  SMemberDataPointer *pMemberData;
831  };
832 
833  CEffect *pEffect;
834 
835  SConstantBuffer() noexcept :
836  pD3DObject(nullptr),
837  TBuffer{},
838  pBackingStore(nullptr),
839  Size(0),
840  pName(nullptr),
841  AnnotationCount(0),
842  pAnnotations(nullptr),
843  VariableCount(0),
844  pVariables(nullptr),
845  ExplicitBindPoint(uint32_t(-1)),
846  IsDirty(false),
847  IsTBuffer(false),
848  IsUserManaged(false),
849  IsEffectOptimized(false),
850  IsUsedByExpression(false),
851  IsUserPacked(false),
852  IsSingle(false),
853  IsNonUpdatable(false),
854  pMemberData(nullptr),
855  pEffect(nullptr)
856  {
857  }
858 
859  bool ClonedSingle() const;
860 
861  // ID3DX11EffectConstantBuffer interface
862  STDMETHOD_(bool, IsValid)() override;
863  STDMETHOD_(ID3DX11EffectType*, GetType)() override;
864  STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override;
865 
866  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
867  STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
868 
869  STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index) override;
870  STDMETHOD_(ID3DX11EffectVariable*, GetMemberByName)(_In_z_ LPCSTR Name) override;
871  STDMETHOD_(ID3DX11EffectVariable*, GetMemberBySemantic)(_In_z_ LPCSTR Semantic) override;
872 
873  STDMETHOD_(ID3DX11EffectVariable*, GetElement)(_In_ uint32_t Index) override;
874 
875  STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override;
876 
877  // other casts are handled by TUncastableVariable
878  STDMETHOD_(ID3DX11EffectConstantBuffer*, AsConstantBuffer)() override;
879 
880  STDMETHOD(SetRawValue)(_In_reads_bytes_(Count) const void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
881  STDMETHOD(GetRawValue)(_Out_writes_bytes_(Count) void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
882 
883  STDMETHOD(SetConstantBuffer)(_In_ ID3D11Buffer *pConstantBuffer) override;
884  STDMETHOD(GetConstantBuffer)(_Outptr_ ID3D11Buffer **ppConstantBuffer) override;
885  STDMETHOD(UndoSetConstantBuffer)() override;
886 
887  STDMETHOD(SetTextureBuffer)(_In_ ID3D11ShaderResourceView *pTextureBuffer) override;
888  STDMETHOD(GetTextureBuffer)(_Outptr_ ID3D11ShaderResourceView **ppTextureBuffer) override;
889  STDMETHOD(UndoSetTextureBuffer)() override;
890 
891  // ID3DX11EffectType interface
892  STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override;
893  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(_In_ uint32_t Index) override;
894  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(_In_z_ LPCSTR Name) override;
895  STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(_In_z_ LPCSTR Semantic) override;
896 
897  STDMETHOD_(LPCSTR, GetMemberName)(_In_ uint32_t Index) override;
898  STDMETHOD_(LPCSTR, GetMemberSemantic)(_In_ uint32_t Index) override;
899 
900  IUNKNOWN_IMP(SConstantBuffer, ID3DX11EffectConstantBuffer, ID3DX11EffectVariable);
901 };
902 
903 
905 // Assignments
907 
908 enum ERuntimeAssignmentType
909 {
910  ERAT_Invalid,
911  // [Destination] refers to the destination location, which is always the backing store of the pass/state block.
912  // [Source] refers to the current source of data, always coming from either a constant buffer's
913  // backing store (for numeric assignments), an object variable's block array, or an anonymous (unowned) block
914 
915  // Numeric variables:
916  ERAT_Constant, // Source is unused.
917  // No dependencies; this assignment can be safely removed after load.
918  ERAT_NumericVariable, // Source points to the CB's backing store where the value lives.
919  // 1 dependency: the variable itself.
920  ERAT_NumericConstIndex, // Source points to the CB's backing store where the value lives, offset by N.
921  // 1 dependency: the variable array being indexed.
922  ERAT_NumericVariableIndex, // Source points to the last used element of the variable in the CB's backing store.
923  // 2 dependencies: the index variable followed by the array variable.
924 
925  // Object variables:
926  ERAT_ObjectInlineShader, // An anonymous, immutable shader block pointer is copied to the destination immediately.
927  // No dependencies; this assignment can be safely removed after load.
928  ERAT_ObjectVariable, // A pointer to the block owned by the object variable is copied to the destination immediately.
929  // No dependencies; this assignment can be safely removed after load.
930  ERAT_ObjectConstIndex, // A pointer to the Nth block owned by an object variable is copied to the destination immediately.
931  // No dependencies; this assignment can be safely removed after load.
932  ERAT_ObjectVariableIndex, // Source points to the first block owned by an object variable array
933  // (the offset from this, N, is taken from another variable).
934  // 1 dependency: the variable being used to index the array.
935 };
936 
938 {
939  struct SDependency
940  {
941  SGlobalVariable *pVariable;
942 
943  SDependency() noexcept :
944  pVariable(nullptr)
945  {
946  }
947  };
948 
949  ELhsType LhsType; // PS, VS, DepthStencil etc.
950 
951  // The value of SAssignment.AssignmentType determines how the other fields behave
952  // (DependencyCount, pDependencies, Destination, and Source)
953  ERuntimeAssignmentType AssignmentType;
954 
955  Timer LastRecomputedTime;
956 
957  // see comments in ERuntimeAssignmentType for how dependencies and data pointers are handled
958  uint32_t DependencyCount;
959  SDependency *pDependencies;
960 
961  UDataPointer Destination; // This value never changes after load, and always refers to the backing store
962  UDataPointer Source; // This value, on the other hand, can change if variable- or expression- driven
963 
964  uint32_t DataSize : 16; // Size of the data element to be copied in bytes (if numeric) or
965  // stride of the block type (if object)
966  uint32_t MaxElements : 16; // Max allowable index (needed because we don't store object arrays as dependencies,
967  // and therefore have no way of getting their Element count)
968 
969  bool IsObjectAssignment() // True for Shader and RObject assignments (the type that appear in pass blocks)
970  {
971  return IsObjectAssignmentHelper(LhsType);
972  }
973 
974  SAssignment() noexcept :
975  LhsType(ELHS_Invalid),
976  AssignmentType(ERAT_Invalid),
977  LastRecomputedTime(0),
978  DependencyCount(0),
979  pDependencies(nullptr),
980  Destination{0},
981  Source{0},
982  DataSize(0),
983  MaxElements(0)
984  {
985  }
986 };
987 
989 // Private effect heaps
991 
992 // Used to efficiently reallocate data
993 // 1) For every piece of data that needs reallocation, move it to its new location
994 // and add an entry into the table
995 // 2) For everyone that references one of these data blocks, do a quick table lookup
996 // to find the old pointer and then replace it with the new one
998 {
999  void *pOld;
1000  void *pNew;
1001 
1002  static bool AreMappingsEqual(const SPointerMapping &pMap1, const SPointerMapping &pMap2)
1003  {
1004  return (pMap1.pOld == pMap2.pOld);
1005  }
1006 
1007  uint32_t Hash()
1008  {
1009  // hash the pointer itself
1010  // (using the pointer as a hash would be very bad)
1011  return ComputeHash((uint8_t*)&pOld, sizeof(pOld));
1012  }
1013 };
1014 
1016 
1017 // Assist adding data to a block of memory
1019 {
1020 protected:
1021  uint8_t *m_pData;
1022  uint32_t m_dwBufferSize;
1023  uint32_t m_dwSize;
1024 
1025  template <bool bCopyData>
1026  HRESULT AddDataInternal(_In_reads_bytes_(dwSize) const void *pData, _In_ uint32_t dwSize, _Outptr_ void **ppPointer);
1027 
1028 public:
1029  HRESULT ReserveMemory(uint32_t dwSize);
1030  uint32_t GetSize();
1031  uint8_t* GetDataStart() { return m_pData; }
1032 
1033  // AddData and AddString append existing data to the buffer - they change m_dwSize. Users are
1034  // not expected to modify the data pointed to by the return pointer
1035  HRESULT AddString(_In_z_ const char *pString, _Outptr_result_z_ char **ppPointer);
1036  HRESULT AddData(_In_reads_(dwSize) const void *pData, _In_ uint32_t dwSize, _Outptr_ void **ppPointer);
1037 
1038  // Allocate behaves like a standard new - it will allocate memory, move m_dwSize. The caller is
1039  // expected to use the returned pointer
1040  void* Allocate(uint32_t dwSize);
1041 
1042  // Move data from the general heap and optional free memory
1043  HRESULT MoveData(_Inout_updates_bytes_(size) void **ppData, _In_ uint32_t size);
1044  HRESULT MoveString(_Inout_updates_z_(1) char **ppStringData);
1045  HRESULT MoveInterfaceParameters(_In_ uint32_t InterfaceCount, _Inout_updates_(1) SShaderBlock::SInterfaceParameter **ppInterfaces);
1046  HRESULT MoveEmptyDataBlock(_Inout_updates_(1) void **ppData, _In_ uint32_t size);
1047 
1048  bool IsInHeap(_In_ void *pData) const
1049  {
1050  return (pData >= m_pData && pData < (m_pData + m_dwBufferSize));
1051  }
1052 
1053  CEffectHeap() noexcept;
1054  ~CEffectHeap();
1055 };
1056 
1058 {
1059 public:
1060  // Single memory block support
1061  CEffectHeap m_Heap;
1062 };
1063 
1064 
1065 class CEffect : public ID3DX11Effect
1066 {
1067  friend struct SBaseBlock;
1068  friend struct SPassBlock;
1069  friend class CEffectLoader;
1070  friend struct SConstantBuffer;
1071  friend struct TSamplerVariable<TGlobalVariable<ID3DX11EffectSamplerVariable>>;
1072  friend struct TSamplerVariable<TVariable<TMember<ID3DX11EffectSamplerVariable>>>;
1073 
1074 protected:
1075 
1076  uint32_t m_RefCount;
1077  uint32_t m_Flags;
1078 
1079  // Private heap - all pointers should point into here
1080  CEffectHeap m_Heap;
1081 
1082  // Reflection object
1083  CEffectReflection *m_pReflection;
1084 
1085  // global variables in the effect (aka parameters)
1086  uint32_t m_VariableCount;
1087  SGlobalVariable *m_pVariables;
1088 
1089  // anonymous shader variables (one for every inline shader assignment)
1090  uint32_t m_AnonymousShaderCount;
1091  SAnonymousShader *m_pAnonymousShaders;
1092 
1093  // techniques within this effect (the actual data is located in each group)
1094  uint32_t m_TechniqueCount;
1095 
1096  // groups within this effect
1097  uint32_t m_GroupCount;
1098  SGroup *m_pGroups;
1099  SGroup *m_pNullGroup;
1100 
1101  uint32_t m_ShaderBlockCount;
1102  SShaderBlock *m_pShaderBlocks;
1103 
1104  uint32_t m_DepthStencilBlockCount;
1105  SDepthStencilBlock *m_pDepthStencilBlocks;
1106 
1107  uint32_t m_BlendBlockCount;
1108  SBlendBlock *m_pBlendBlocks;
1109 
1110  uint32_t m_RasterizerBlockCount;
1111  SRasterizerBlock *m_pRasterizerBlocks;
1112 
1113  uint32_t m_SamplerBlockCount;
1114  SSamplerBlock *m_pSamplerBlocks;
1115 
1116  uint32_t m_MemberDataCount;
1117  SMemberDataPointer *m_pMemberDataBlocks;
1118 
1119  uint32_t m_InterfaceCount;
1120  SInterface *m_pInterfaces;
1121 
1122  uint32_t m_CBCount;
1123  SConstantBuffer *m_pCBs;
1124 
1125  uint32_t m_StringCount;
1126  SString *m_pStrings;
1127 
1128  uint32_t m_ShaderResourceCount;
1129  SShaderResource *m_pShaderResources;
1130 
1131  uint32_t m_UnorderedAccessViewCount;
1132  SUnorderedAccessView *m_pUnorderedAccessViews;
1133 
1134  uint32_t m_RenderTargetViewCount;
1135  SRenderTargetView *m_pRenderTargetViews;
1136 
1137  uint32_t m_DepthStencilViewCount;
1138  SDepthStencilView *m_pDepthStencilViews;
1139 
1140  Timer m_LocalTimer;
1141 
1142  // temporary index variable for assignment evaluation
1143  uint32_t m_FXLIndex;
1144 
1145  ID3D11Device *m_pDevice;
1146  ID3D11DeviceContext *m_pContext;
1147  ID3D11ClassLinkage *m_pClassLinkage;
1148 
1149  // Master lists of reflection interfaces
1150  CEffectVectorOwner<SSingleElementType> m_pTypeInterfaces;
1151  CEffectVectorOwner<SMember> m_pMemberInterfaces;
1152 
1154  // String & Type pooling
1155 
1156  typedef SType *LPSRUNTIMETYPE;
1157  static bool AreTypesEqual(const LPSRUNTIMETYPE &pType1, const LPSRUNTIMETYPE &pType2) { return (pType1->IsEqual(pType2)); }
1158  static bool AreStringsEqual(const LPCSTR &pStr1, const LPCSTR &pStr2) { return strcmp(pStr1, pStr2) == 0; }
1159 
1162 
1163  // These are used to pool types & type-related strings
1164  // until Optimize() is called
1165  CTypeHashTable *m_pTypePool;
1166  CStringHashTable *m_pStringPool;
1167  CDataBlockStore *m_pPooledHeap;
1168  // After Optimize() is called, the type/string pools should be deleted and all
1169  // remaining data should be migrated into the optimized type heap
1170  CEffectHeap *m_pOptimizedTypeHeap;
1171 
1172  // Pools a string or type and modifies the pointer
1173  void AddStringToPool(const char **ppString);
1174  void AddTypeToPool(SType **ppType);
1176  HRESULT OptimizeTypes(_Inout_ CPointerMappingTable *pMappingTable, _In_ bool Cloning = false);
1177 
1178 
1180  // Runtime (performance critical)
1181 
1182  void ApplyShaderBlock(_In_ SShaderBlock *pBlock);
1183  bool ApplyRenderStateBlock(_In_ SBaseBlock *pBlock);
1184  bool ApplySamplerBlock(_In_ SSamplerBlock *pBlock);
1185  void ApplyPassBlock(_Inout_ SPassBlock *pBlock);
1186  bool EvaluateAssignment(_Inout_ SAssignment *pAssignment);
1187  bool ValidateShaderBlock(_Inout_ SShaderBlock* pBlock );
1188  bool ValidatePassBlock(_Inout_ SPassBlock* pBlock );
1189 
1191  // Non-runtime functions (not performance critical)
1192 
1193  SGlobalVariable *FindLocalVariableByName(_In_z_ LPCSTR pVarName); // Looks in the current effect only
1194  SGlobalVariable *FindVariableByName(_In_z_ LPCSTR pVarName);
1195  SVariable *FindVariableByNameWithParsing(_In_z_ LPCSTR pVarName);
1196  SConstantBuffer *FindCB(_In_z_ LPCSTR pName);
1197  void ReplaceCBReference(_In_ SConstantBuffer *pOldBufferBlock, _In_ ID3D11Buffer *pNewBuffer); // Used by user-managed CBs
1198  void ReplaceSamplerReference(_In_ SSamplerBlock *pOldSamplerBlock, _In_ ID3D11SamplerState *pNewSampler);
1199  void AddRefAllForCloning( _In_ CEffect* pEffectSource );
1200  HRESULT CopyMemberInterfaces( _In_ CEffect* pEffectSource );
1201  HRESULT CopyStringPool( _In_ CEffect* pEffectSource, _Inout_ CPointerMappingTable& mappingTable );
1202  HRESULT CopyTypePool( _In_ CEffect* pEffectSource, _Inout_ CPointerMappingTable& mappingTableTypes, _Inout_ CPointerMappingTable& mappingTableStrings );
1203  HRESULT CopyOptimizedTypePool( _In_ CEffect* pEffectSource, _Inout_ CPointerMappingTable& mappingTableTypes );
1204  HRESULT RecreateCBs();
1205  HRESULT FixupMemberInterface( _Inout_ SMember* pMember, _In_ CEffect* pEffectSource, _Inout_ CPointerMappingTable& mappingTableStrings );
1206 
1207  void ValidateIndex(_In_ uint32_t Elements);
1208 
1209  void IncrementTimer();
1210  void HandleLocalTimerRollover();
1211 
1212  friend struct SConstantBuffer;
1213 
1214 public:
1215  CEffect( uint32_t Flags = 0 ) noexcept;
1216  virtual ~CEffect();
1217  void ReleaseShaderRefection();
1218 
1219  // Initialize must be called after the effect is created
1220  HRESULT LoadEffect(_In_reads_bytes_(cbEffectBuffer) const void *pEffectBuffer, _In_ uint32_t cbEffectBuffer);
1221 
1222  // Once the effect is fully loaded, call BindToDevice to attach it to a device
1223  HRESULT BindToDevice(_In_ ID3D11Device *pDevice, _In_z_ LPCSTR srcName );
1224 
1225  Timer GetCurrentTime() const { return m_LocalTimer; }
1226 
1227  bool IsReflectionData(void *pData) const { return m_pReflection->m_Heap.IsInHeap(pData); }
1228  bool IsRuntimeData(void *pData) const { return m_Heap.IsInHeap(pData); }
1229 
1231  // Public interface
1232 
1233  // IUnknown
1234  STDMETHOD(QueryInterface)(REFIID iid, _COM_Outptr_ LPVOID *ppv) override;
1235  STDMETHOD_(ULONG, AddRef)() override;
1236  STDMETHOD_(ULONG, Release)() override;
1237 
1238  // ID3DX11Effect
1239  STDMETHOD_(bool, IsValid)() override { return true; }
1240 
1241  STDMETHOD(GetDevice)(_Outptr_ ID3D11Device** ppDevice) override;
1242 
1243  STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_DESC *pDesc) override;
1244 
1245  STDMETHOD_(ID3DX11EffectConstantBuffer*, GetConstantBufferByIndex)(_In_ uint32_t Index) override;
1246  STDMETHOD_(ID3DX11EffectConstantBuffer*, GetConstantBufferByName)(_In_z_ LPCSTR Name) override;
1247 
1248  STDMETHOD_(ID3DX11EffectVariable*, GetVariableByIndex)(_In_ uint32_t Index) override;
1249  STDMETHOD_(ID3DX11EffectVariable*, GetVariableByName)(_In_z_ LPCSTR Name) override;
1250  STDMETHOD_(ID3DX11EffectVariable*, GetVariableBySemantic)(_In_z_ LPCSTR Semantic) override;
1251 
1252  STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByIndex)(_In_ uint32_t Index) override;
1253  STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByName)(_In_z_ LPCSTR Name) override;
1254 
1255  STDMETHOD_(ID3DX11EffectGroup*, GetGroupByIndex)(_In_ uint32_t Index) override;
1256  STDMETHOD_(ID3DX11EffectGroup*, GetGroupByName)(_In_z_ LPCSTR Name) override;
1257 
1258  STDMETHOD_(ID3D11ClassLinkage*, GetClassLinkage)() override;
1259 
1260  STDMETHOD(CloneEffect)(_In_ uint32_t Flags, _Outptr_ ID3DX11Effect** ppClonedEffect) override;
1261  STDMETHOD(Optimize)() override;
1262  STDMETHOD_(bool, IsOptimized)() override;
1263 
1265  // New reflection helpers
1266 
1267  ID3DX11EffectType * CreatePooledSingleElementTypeInterface(_In_ SType *pType);
1268  ID3DX11EffectVariable * CreatePooledVariableMemberInterface(_In_ TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity,
1269  _In_ const SVariable *pMember,
1270  _In_ const UDataPointer Data, _In_ bool IsSingleElement, _In_ uint32_t Index);
1271 
1272 };
1273 
1274 }
1275 
1276 #pragma warning(pop)
Definition: Effect.h:743
Definition: Effect.h:997
Definition: Effect.h:514
Definition: Effect.h:483
Definition: EffectBinaryFormat.h:16
Definition: Effect.h:1057
Definition: d3dxGlobal.h:592
Definition: d3dx11effect.h:825
Definition: Effect.h:590
Definition: Effect.h:99
Definition: Effect.h:4949
Definition: Effect.h:800
Definition: Effect.h:305
Definition: d3dx11effect.h:236
Definition: Effect.h:75
Definition: d3dx11effect.h:905
Definition: EffectBinaryFormat.h:558
Definition: EffectVariable.inl:4941
Definition: d3dxGlobal.h:429
Definition: Effect.h:524
Definition: d3dx11effect.h:949
Definition: Effect.h:600
Definition: Effect.h:378
Definition: EffectLoad.h:48
Definition: Effect.h:534
Definition: Effect.h:4956
Definition: d3dx11effect.h:659
Definition: Effect.h:4942
Definition: Effect.h:1065
Definition: d3dxGlobal.cpp:19
Definition: Effect.h:405
Definition: Effect.h:937
Definition: d3dx11effect.h:845
Definition: Effect.h:565
Definition: Effect.h:349
Definition: Effect.h:4619
Definition: Effect.h:680
Definition: Effect.h:700
Definition: d3dx11effect.h:44
Definition: Effect.h:135
Definition: Effect.h:492
Definition: Effect.h:501
Definition: Effect.h:4737
Definition: Effect.h:544
Definition: EffectVariable.inl:4948
Definition: Effect.h:279
Definition: Effect.h:1018
Definition: d3dxGlobal.h:1237
Definition: d3dx11effect.h:177
Definition: Effect.h:554
Definition: Effect.h:151
Definition: d3dx11effect.h:991
Definition: TestJobManager.cpp:22
Definition: Effect.h:91
Definition: Effect.h:474