kodi
EffectLoad.h
1 //--------------------------------------------------------------------------------------
2 // File: EffectLoad.h
3 //
4 // Direct3D 11 Effects header for the FX file loader
5 // A CEffectLoader is created at load time to facilitate loading
6 //
7 // Copyright (c) Microsoft Corporation.
8 // Licensed under the MIT License.
9 //
10 // http://go.microsoft.com/fwlink/p/?LinkId=271568
11 //--------------------------------------------------------------------------------------
12 
13 #pragma once
14 
15 namespace D3DX11Effects
16 {
17 
18 // Ranges are used for dependency checking during load
19 
20 enum ERanges
21 {
22  ER_CBuffer = 0,
23  ER_Texture, // Includes TBuffers
24  ER_Sampler,
25  ER_UnorderedAccessView,
26  ER_Interfaces,
27  ER_Count // This should be the size of the enum
28 };
29 
30 struct SRange
31 {
32  uint32_t start;
33  uint32_t last;
34  CEffectVector<void *> vResources; // should be (last - start) in length, resource type depends on the range type
35 
36  SRange() noexcept :
37  start(0),
38  last(0)
39  {
40  }
41 };
42 
43 // Used during load to validate assignments
44 D3D_SHADER_VARIABLE_TYPE GetSimpleParameterTypeFromObjectType(EObjectType ObjectType);
45 
46 
47 // A class to facilitate loading an Effect. This class is a friend of CEffect.
49 {
50  friend HRESULT CEffect::CloneEffect(_In_ uint32_t Flags, _Outptr_ ID3DX11Effect** ppClonedEffect );
51 
52 protected:
53  // Load-time allocations that eventually get moved happen out of the TempHeap. This heap will grow as needed
54  CDataBlockStore m_BulkHeap;
55 
56  uint8_t *m_pData;
57  SBinaryHeader5 *m_pHeader;
58  DWORD m_Version;
59 
60  CEffect *m_pEffect;
61  CEffectReflection *m_pReflection;
62 
63  D3DX11Core::CMemoryStream m_msStructured;
64  D3DX11Core::CMemoryStream m_msUnstructured;
65 
66  // used to avoid repeated hash buffer allocations in LoadTypeAndAddToPool
67  CEffectVector<uint8_t> m_HashBuffer;
68 
69  uint32_t m_dwBufferSize; // Size of data buffer in bytes
70 
71  // List of SInterface blocks created to back class instances bound to shaders
72  CEffectVector<SInterface*> m_BackgroundInterfaces;
73 
74  // Pointers to pre-reallocation data
75  SGlobalVariable *m_pOldVars;
76  SShaderBlock *m_pOldShaders;
77  SDepthStencilBlock *m_pOldDS;
78  SBlendBlock *m_pOldAB;
79  SRasterizerBlock *m_pOldRS;
80  SConstantBuffer *m_pOldCBs;
81  SSamplerBlock *m_pOldSamplers;
82  uint32_t m_OldInterfaceCount;
83  SInterface *m_pOldInterfaces;
84  SShaderResource *m_pOldShaderResources;
85  SUnorderedAccessView *m_pOldUnorderedAccessViews;
86  SRenderTargetView *m_pOldRenderTargetViews;
87  SDepthStencilView *m_pOldDepthStencilViews;
88  SString *m_pOldStrings;
89  SMemberDataPointer *m_pOldMemberDataBlocks;
90  CEffectVectorOwner<SMember> *m_pvOldMemberInterfaces;
91  SGroup *m_pOldGroups;
92 
93  uint32_t m_EffectMemory; // Effect private heap
94  uint32_t m_ReflectionMemory; // Reflection private heap
95 
96  // Loader helpers
97  HRESULT LoadCBs();
98  HRESULT LoadNumericVariable(_In_ SConstantBuffer *pParentCB);
99  HRESULT LoadObjectVariables();
100  HRESULT LoadInterfaceVariables();
101 
102  HRESULT LoadTypeAndAddToPool(_Outptr_ SType **ppType, _In_ uint32_t dwOffset);
103  HRESULT LoadStringAndAddToPool(_Outptr_result_maybenull_z_ char **ppString, _In_ uint32_t dwOffset);
104  HRESULT LoadAssignments( _In_ uint32_t Assignments, _Out_writes_(Assignments) SAssignment **pAssignments,
105  _In_ uint8_t *pBackingStore, _Out_opt_ uint32_t *pRTVAssignments, _Out_opt_ uint32_t *pFinalAssignments );
106  HRESULT LoadGroups();
107  HRESULT LoadTechnique( STechnique* pTech );
108  HRESULT LoadAnnotations(uint32_t *pcAnnotations, SAnnotation **ppAnnotations);
109 
110  HRESULT ExecuteConstantAssignment(_In_ const SBinaryConstant *pConstant, _Out_writes_bytes_(4) void *pLHS, _In_ D3D_SHADER_VARIABLE_TYPE lhsType);
111  uint32_t UnpackData(uint8_t *pDestData, uint8_t *pSrcData, uint32_t PackedDataSize, SType *pType, uint32_t *pBytesRead);
112 
113  // Build shader blocks
114  HRESULT ConvertRangesToBindings(SShaderBlock *pShaderBlock, CEffectVector<SRange> *pvRanges );
115  HRESULT GrabShaderData(SShaderBlock *pShaderBlock);
116  HRESULT BuildShaderBlock(SShaderBlock *pShaderBlock);
117 
118  // Memory compactors
119  HRESULT InitializeReflectionDataAndMoveStrings( uint32_t KnownSize = 0 );
120  HRESULT ReallocateReflectionData( bool Cloning = false );
121  HRESULT ReallocateEffectData( bool Cloning = false );
122  HRESULT ReallocateShaderBlocks();
123  template<class T> HRESULT ReallocateBlockAssignments(T* &pBlocks, uint32_t cBlocks, T* pOldBlocks = nullptr);
124  HRESULT ReallocateAnnotationData(uint32_t cAnnotations, SAnnotation **ppAnnotations);
125 
126  HRESULT CalculateAnnotationSize(uint32_t cAnnotations, SAnnotation *pAnnotations);
127  uint32_t CalculateShaderBlockSize();
128  template<class T> uint32_t CalculateBlockAssignmentSize(T* &pBlocks, uint32_t cBlocks);
129 
130  HRESULT FixupCBPointer(_Inout_ SConstantBuffer **ppCB);
131  HRESULT FixupShaderPointer(_Inout_ SShaderBlock **ppShaderBlock);
132  HRESULT FixupDSPointer(_Inout_ SDepthStencilBlock **ppDSBlock);
133  HRESULT FixupABPointer(_Inout_ SBlendBlock **ppABBlock);
134  HRESULT FixupRSPointer(_Inout_ SRasterizerBlock **ppRSBlock);
135  HRESULT FixupInterfacePointer(_Inout_ SInterface **ppInterface, _In_ bool CheckBackgroundInterfaces);
136  HRESULT FixupShaderResourcePointer(_Inout_ SShaderResource **ppResource);
137  HRESULT FixupUnorderedAccessViewPointer(_Inout_ SUnorderedAccessView **ppResource);
138  HRESULT FixupRenderTargetViewPointer(_Inout_ SRenderTargetView **ppRenderTargetView);
139  HRESULT FixupDepthStencilViewPointer(_Inout_ SDepthStencilView **ppDepthStencilView);
140  HRESULT FixupSamplerPointer(_Inout_ SSamplerBlock **ppSampler);
141  HRESULT FixupVariablePointer(_Inout_ SGlobalVariable **ppVar);
142  HRESULT FixupStringPointer(_Inout_ SString **ppString);
143  HRESULT FixupMemberDataPointer(_Inout_ SMemberDataPointer **ppMemberData);
144  HRESULT FixupGroupPointer(_Inout_ SGroup **ppGroup);
145 
146  // Methods to retrieve data from the unstructured block
147  // (these do not make copies; they simply return pointers into the block)
148  HRESULT GetStringAndAddToReflection(_In_ uint32_t offset, _Outptr_result_maybenull_z_ char **ppPointer); // Returns a string from the file string block, updates m_EffectMemory
149  HRESULT GetUnstructuredDataBlock(_In_ uint32_t offset, _Out_ uint32_t *pdwSize, _Outptr_result_buffer_(*pdwSize) void **ppData);
150  // This function makes a copy of the array of SInterfaceParameters, but not a copy of the strings
151  HRESULT GetInterfaceParametersAndAddToReflection( _In_ uint32_t InterfaceCount, _In_ uint32_t offset, _Outptr_result_buffer_all_maybenull_(InterfaceCount) SShaderBlock::SInterfaceParameter **ppInterfaces );
152 
153 public:
154  CEffectLoader() noexcept;
155 
156  HRESULT LoadEffect(_In_ CEffect *pEffect, _In_reads_bytes_(cbEffectBuffer) const void *pEffectBuffer, _In_ uint32_t cbEffectBuffer);
157 };
158 
159 }
Definition: Effect.h:514
Definition: Effect.h:483
Definition: d3dxGlobal.h:142
Definition: EffectBinaryFormat.h:16
Definition: Effect.h:1057
Definition: d3dxGlobal.h:592
Definition: Effect.h:4949
Definition: Effect.h:800
Definition: EffectBinaryFormat.h:640
Definition: d3dxGlobal.h:429
Definition: Effect.h:524
Definition: Effect.h:600
Definition: EffectLoad.h:30
Definition: Effect.h:378
Definition: EffectLoad.h:48
Definition: Effect.h:534
Definition: Effect.h:4942
Definition: Effect.h:1065
Definition: Effect.h:937
Definition: Effect.h:349
Definition: Effect.h:680
Definition: EffectBinaryFormat.h:412
Definition: d3dxGlobal.h:98
Definition: Effect.h:135
Definition: Effect.h:492
Definition: Effect.h:501
Definition: Effect.h:544
Definition: Effect.h:554
Definition: Effect.h:151
Definition: TestJobManager.cpp:22
Definition: Effect.h:474