1 //--------------------------------------------------------------------------------------
2 // File: EffectReflection.cpp
4 // Direct3D 11 Effects public reflection APIs
6 // Copyright (c) Microsoft Corporation.
7 // Licensed under the MIT License.
9 // http://go.microsoft.com/fwlink/p/?LinkId=271568
10 //--------------------------------------------------------------------------------------
14 namespace D3DX11Effects
17 SEffectInvalidType g_InvalidType
;
19 SEffectInvalidScalarVariable g_InvalidScalarVariable
;
20 SEffectInvalidVectorVariable g_InvalidVectorVariable
;
21 SEffectInvalidMatrixVariable g_InvalidMatrixVariable
;
22 SEffectInvalidStringVariable g_InvalidStringVariable
;
23 SEffectInvalidClassInstanceVariable g_InvalidClassInstanceVariable
;
24 SEffectInvalidInterfaceVariable g_InvalidInterfaceVariable
;
25 SEffectInvalidShaderResourceVariable g_InvalidShaderResourceVariable
;
26 SEffectInvalidUnorderedAccessViewVariable g_InvalidUnorderedAccessViewVariable
;
27 SEffectInvalidRenderTargetViewVariable g_InvalidRenderTargetViewVariable
;
28 SEffectInvalidDepthStencilViewVariable g_InvalidDepthStencilViewVariable
;
29 SEffectInvalidConstantBuffer g_InvalidConstantBuffer
;
30 SEffectInvalidShaderVariable g_InvalidShaderVariable
;
31 SEffectInvalidBlendVariable g_InvalidBlendVariable
;
32 SEffectInvalidDepthStencilVariable g_InvalidDepthStencilVariable
;
33 SEffectInvalidRasterizerVariable g_InvalidRasterizerVariable
;
34 SEffectInvalidSamplerVariable g_InvalidSamplerVariable
;
36 SEffectInvalidPass g_InvalidPass
;
37 SEffectInvalidTechnique g_InvalidTechnique
;
38 SEffectInvalidGroup g_InvalidGroup
;
41 //////////////////////////////////////////////////////////////////////////
42 // Helper routine implementations
43 //////////////////////////////////////////////////////////////////////////
45 ID3DX11EffectConstantBuffer
* NoParentCB()
47 DPF(0, "ID3DX11EffectVariable::GetParentConstantBuffer: Variable does not have a parent constant buffer");
48 // have to typecast because the type of g_InvalidScalarVariable has not been declared yet
49 return &g_InvalidConstantBuffer
;
52 _Use_decl_annotations_
53 ID3DX11EffectVariable
* GetAnnotationByIndexHelper(const char *pClassName
, uint32_t Index
, uint32_t AnnotationCount
, SAnnotation
*pAnnotations
)
55 if (Index
>= AnnotationCount
)
57 DPF(0, "%s::GetAnnotationByIndex: Invalid index (%u, total: %u)", pClassName
, Index
, AnnotationCount
);
58 return &g_InvalidScalarVariable
;
61 return pAnnotations
+ Index
;
64 _Use_decl_annotations_
65 ID3DX11EffectVariable
* GetAnnotationByNameHelper(const char *pClassName
, LPCSTR Name
, uint32_t AnnotationCount
, SAnnotation
*pAnnotations
)
68 for (i
= 0; i
< AnnotationCount
; ++ i
)
70 if (strcmp(pAnnotations
[i
].pName
, Name
) == 0)
72 return pAnnotations
+ i
;
76 DPF(0, "%s::GetAnnotationByName: Annotation [%s] not found", pClassName
, Name
);
77 return &g_InvalidScalarVariable
;
80 //////////////////////////////////////////////////////////////////////////
81 // Effect routines to pool interfaces
82 //////////////////////////////////////////////////////////////////////////
84 ID3DX11EffectType
* CEffect::CreatePooledSingleElementTypeInterface(_In_ SType
*pType
)
88 DPF(0, "ID3DX11Effect: Cannot create new type interfaces since the effect has been Optimize()'ed");
89 return &g_InvalidType
;
92 for (size_t i
= 0; i
< m_pTypeInterfaces
.GetSize(); ++ i
)
94 if (m_pTypeInterfaces
[i
]->pType
== pType
)
96 return (SSingleElementType
*)m_pTypeInterfaces
[i
];
99 SSingleElementType
*pNewType
;
100 if (nullptr == (pNewType
= new SSingleElementType
))
102 DPF(0, "ID3DX11Effect: Out of memory while trying to create new type interface");
103 return &g_InvalidType
;
106 pNewType
->pType
= pType
;
107 m_pTypeInterfaces
.Add(pNewType
);
112 // Create a member variable (via GetMemberBy* or GetElement)
113 _Use_decl_annotations_
114 ID3DX11EffectVariable
* CEffect::CreatePooledVariableMemberInterface(TTopLevelVariable
<ID3DX11EffectVariable
> *pTopLevelEntity
,
115 const SVariable
*pMember
,
116 const UDataPointer Data
, bool IsSingleElement
, uint32_t Index
)
122 DPF(0, "ID3DX11Effect: Cannot create new variable interfaces since the effect has been Optimize()'ed");
123 return &g_InvalidScalarVariable
;
126 for (size_t i
= 0; i
< m_pMemberInterfaces
.GetSize(); ++ i
)
128 if (m_pMemberInterfaces
[i
]->pType
== pMember
->pType
&&
129 m_pMemberInterfaces
[i
]->pName
== pMember
->pName
&&
130 m_pMemberInterfaces
[i
]->pSemantic
== pMember
->pSemantic
&&
131 m_pMemberInterfaces
[i
]->Data
.pGeneric
== Data
.pGeneric
&&
132 m_pMemberInterfaces
[i
]->IsSingleElement
== (uint32_t)IsSingleElement
&&
133 ((SMember
*)m_pMemberInterfaces
[i
])->pTopLevelEntity
== pTopLevelEntity
)
135 return (ID3DX11EffectVariable
*) m_pMemberInterfaces
[i
];
139 // is this annotation or runtime data?
140 if( pTopLevelEntity
->pEffect
->IsReflectionData(pTopLevelEntity
) )
142 assert( pTopLevelEntity
->pEffect
->IsReflectionData(Data
.pGeneric
) );
147 // if the heap is empty, we are still loading the Effect, and thus creating a member for a variable initializer
148 // ex. Interface myInt = myClassArray[2];
149 if( pTopLevelEntity
->pEffect
->m_Heap
.GetSize() > 0 )
151 assert( pTopLevelEntity
->pEffect
->IsRuntimeData(pTopLevelEntity
) );
152 if (!pTopLevelEntity
->pType
->IsObjectType(EOT_String
))
154 // strings are funny; their data is reflection data, so ignore those
155 assert( pTopLevelEntity
->pEffect
->IsRuntimeData(Data
.pGeneric
) );
158 IsAnnotation
= false;
163 if (nullptr == (pNewMember
= CreateNewMember((SType
*)pMember
->pType
, IsAnnotation
)))
165 DPF(0, "ID3DX11Effect: Out of memory while trying to create new member variable interface");
166 return &g_InvalidScalarVariable
;
169 pNewMember
->pType
= pMember
->pType
;
170 pNewMember
->pName
= pMember
->pName
;
171 pNewMember
->pSemantic
= pMember
->pSemantic
;
172 pNewMember
->Data
.pGeneric
= Data
.pGeneric
;
173 pNewMember
->IsSingleElement
= IsSingleElement
;
174 pNewMember
->pTopLevelEntity
= pTopLevelEntity
;
176 if( IsSingleElement
&& pMember
->pMemberData
)
178 assert( !IsAnnotation
);
179 // This is an element of a global variable array
180 pNewMember
->pMemberData
= pMember
->pMemberData
+ Index
;
183 if (FAILED(m_pMemberInterfaces
.Add(pNewMember
)))
185 SAFE_DELETE(pNewMember
);
186 DPF(0, "ID3DX11Effect: Out of memory while trying to create new member variable interface");
187 return &g_InvalidScalarVariable
;
190 return (ID3DX11EffectVariable
*) pNewMember
;
193 //////////////////////////////////////////////////////////////////////////
194 // ID3DX11EffectType (SType, SSingleElementType implementations)
195 //////////////////////////////////////////////////////////////////////////
197 static ID3DX11EffectType
* GetTypeByIndexHelper(uint32_t Index
, uint32_t VariableCount
,
198 SVariable
*pVariables
, uint32_t SizeOfVariableType
)
200 static LPCSTR pFuncName
= "ID3DX11EffectType::GetMemberTypeByIndex";
202 if (Index
>= VariableCount
)
204 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName
, Index
, VariableCount
);
205 return &g_InvalidType
;
208 SVariable
*pVariable
= (SVariable
*)((uint8_t *)pVariables
+ Index
* SizeOfVariableType
);
209 if (nullptr == pVariable
->pName
)
211 DPF(0, "%s: Cannot get member types; Effect has been Optimize()'ed", pFuncName
);
212 return &g_InvalidType
;
215 return (ID3DX11EffectType
*) pVariable
->pType
;
218 static ID3DX11EffectType
* GetTypeByNameHelper(LPCSTR Name
, uint32_t VariableCount
,
219 SVariable
*pVariables
, uint32_t SizeOfVariableType
)
221 static LPCSTR pFuncName
= "ID3DX11EffectType::GetMemberTypeByName";
225 DPF(0, "%s: Parameter Name was nullptr.", pFuncName
);
226 return &g_InvalidType
;
230 SVariable
*pVariable
;
232 for (i
= 0; i
< VariableCount
; ++ i
)
234 pVariable
= (SVariable
*)((uint8_t *)pVariables
+ i
* SizeOfVariableType
);
235 if (nullptr == pVariable
->pName
)
237 DPF(0, "%s: Cannot get member types; Effect has been Optimize()'ed", pFuncName
);
238 return &g_InvalidType
;
240 if (strcmp(pVariable
->pName
, Name
) == 0)
242 return (ID3DX11EffectType
*) pVariable
->pType
;
246 DPF(0, "%s: Member type [%s] not found", pFuncName
, Name
);
247 return &g_InvalidType
;
251 static ID3DX11EffectType
* GetTypeBySemanticHelper(LPCSTR Semantic
, uint32_t VariableCount
,
252 SVariable
*pVariables
, uint32_t SizeOfVariableType
)
254 static LPCSTR pFuncName
= "ID3DX11EffectType::GetMemberTypeBySemantic";
256 if (nullptr == Semantic
)
258 DPF(0, "%s: Parameter Semantic was nullptr.", pFuncName
);
259 return &g_InvalidType
;
263 SVariable
*pVariable
;
265 for (i
= 0; i
< VariableCount
; ++ i
)
267 pVariable
= (SVariable
*)((uint8_t *)pVariables
+ i
* SizeOfVariableType
);
268 if (nullptr == pVariable
->pName
)
270 DPF(0, "%s: Cannot get member types; Effect has been Optimize()'ed", pFuncName
);
271 return &g_InvalidType
;
273 if (nullptr != pVariable
->pSemantic
&&
274 _stricmp(pVariable
->pSemantic
, Semantic
) == 0)
276 return (ID3DX11EffectType
*) pVariable
->pType
;
280 DPF(0, "%s: Member type with semantic [%s] not found", pFuncName
, Semantic
);
281 return &g_InvalidType
;
284 ID3DX11EffectType
* SType::GetMemberTypeByIndex(_In_
uint32_t Index
)
286 if (VarType
!= EVT_Struct
)
288 DPF(0, "ID3DX11EffectType::GetMemberTypeByIndex: This interface does not refer to a structure");
289 return &g_InvalidType
;
292 return GetTypeByIndexHelper(Index
, StructType
.Members
, StructType
.pMembers
, sizeof(SVariable
));
295 ID3DX11EffectType
* SType::GetMemberTypeByName(_In_z_ LPCSTR Name
)
297 if (VarType
!= EVT_Struct
)
299 DPF(0, "ID3DX11EffectType::GetMemberTypeByName: This interface does not refer to a structure");
300 return &g_InvalidType
;
303 return GetTypeByNameHelper(Name
, StructType
.Members
, StructType
.pMembers
, sizeof(SVariable
));
306 ID3DX11EffectType
* SType::GetMemberTypeBySemantic(_In_z_ LPCSTR Semantic
)
308 if (VarType
!= EVT_Struct
)
310 DPF(0, "ID3DX11EffectType::GetMemberTypeBySemantic: This interface does not refer to a structure");
311 return &g_InvalidType
;
314 return GetTypeBySemanticHelper(Semantic
, StructType
.Members
, StructType
.pMembers
, sizeof(SVariable
));
317 LPCSTR
SType::GetMemberName(_In_
uint32_t Index
)
319 static LPCSTR pFuncName
= "ID3DX11EffectType::GetMemberName";
321 if (VarType
!= EVT_Struct
)
323 DPF(0, "%s: This interface does not refer to a structure", pFuncName
);
327 if (Index
>= StructType
.Members
)
329 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName
, Index
, StructType
.Members
);
333 SVariable
*pVariable
= StructType
.pMembers
+ Index
;
335 if (nullptr == pVariable
->pName
)
337 DPF(0, "%s: Cannot get member names; Effect has been Optimize()'ed", pFuncName
);
341 return pVariable
->pName
;
344 LPCSTR
SType::GetMemberSemantic(_In_
uint32_t Index
)
346 static LPCSTR pFuncName
= "ID3DX11EffectType::GetMemberSemantic";
348 if (VarType
!= EVT_Struct
)
350 DPF(0, "%s: This interface does not refer to a structure", pFuncName
);
354 if (Index
>= StructType
.Members
)
356 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName
, Index
, StructType
.Members
);
360 SVariable
*pVariable
= StructType
.pMembers
+ Index
;
362 if (nullptr == pVariable
->pName
)
364 DPF(0, "%s: Cannot get member semantics; Effect has been Optimize()'ed", pFuncName
);
368 return pVariable
->pSemantic
;
371 HRESULT
SType::GetDescHelper(_Out_ D3DX11_EFFECT_TYPE_DESC
*pDesc
, _In_
bool IsSingleElement
) const
374 static LPCSTR pFuncName
= "ID3DX11EffectType::GetDesc";
376 VERIFYPARAMETER(pDesc
);
378 pDesc
->TypeName
= pTypeName
;
380 // intentionally return 0 so they know it's not a single element array
381 pDesc
->Elements
= IsSingleElement
? 0 : Elements
;
382 pDesc
->PackedSize
= GetTotalPackedSize(IsSingleElement
);
383 pDesc
->UnpackedSize
= GetTotalUnpackedSize(IsSingleElement
);
384 pDesc
->Stride
= Stride
;
389 switch (NumericType
.NumericLayout
)
392 if (NumericType
.IsColumnMajor
)
394 pDesc
->Class
= D3D_SVC_MATRIX_COLUMNS
;
398 pDesc
->Class
= D3D_SVC_MATRIX_ROWS
;
402 pDesc
->Class
= D3D_SVC_VECTOR
;
405 pDesc
->Class
= D3D_SVC_SCALAR
;
411 switch (NumericType
.ScalarType
)
414 pDesc
->Type
= D3D_SVT_BOOL
;
417 pDesc
->Type
= D3D_SVT_INT
;
420 pDesc
->Type
= D3D_SVT_UINT
;
423 pDesc
->Type
= D3D_SVT_FLOAT
;
429 pDesc
->Rows
= NumericType
.Rows
;
430 pDesc
->Columns
= NumericType
.Columns
;
438 pDesc
->Members
= StructType
.Members
;
439 if( StructType
.ImplementsInterface
)
441 pDesc
->Class
= D3D_SVC_INTERFACE_CLASS
;
445 pDesc
->Class
= D3D_SVC_STRUCT
;
447 pDesc
->Type
= D3D_SVT_VOID
;
454 pDesc
->Class
= D3D_SVC_INTERFACE_POINTER
;
455 pDesc
->Type
= D3D_SVT_INTERFACE_POINTER
;
462 pDesc
->Class
= D3D_SVC_OBJECT
;
467 pDesc
->Type
= D3D_SVT_STRING
;
470 pDesc
->Type
= D3D_SVT_BLEND
;
472 case EOT_DepthStencil
:
473 pDesc
->Type
= D3D_SVT_DEPTHSTENCIL
;
476 pDesc
->Type
= D3D_SVT_RASTERIZER
;
478 case EOT_PixelShader
:
479 case EOT_PixelShader5
:
480 pDesc
->Type
= D3D_SVT_PIXELSHADER
;
482 case EOT_VertexShader
:
483 case EOT_VertexShader5
:
484 pDesc
->Type
= D3D_SVT_VERTEXSHADER
;
486 case EOT_GeometryShader
:
487 case EOT_GeometryShaderSO
:
488 case EOT_GeometryShader5
:
489 pDesc
->Type
= D3D_SVT_GEOMETRYSHADER
;
491 case EOT_HullShader5
:
492 pDesc
->Type
= D3D_SVT_HULLSHADER
;
494 case EOT_DomainShader5
:
495 pDesc
->Type
= D3D_SVT_DOMAINSHADER
;
497 case EOT_ComputeShader5
:
498 pDesc
->Type
= D3D_SVT_COMPUTESHADER
;
501 pDesc
->Type
= D3D_SVT_TEXTURE
;
504 pDesc
->Type
= D3D_SVT_TEXTURE1D
;
506 case EOT_Texture1DArray
:
507 pDesc
->Type
= D3D_SVT_TEXTURE1DARRAY
;
510 pDesc
->Type
= D3D_SVT_TEXTURE2D
;
512 case EOT_Texture2DArray
:
513 pDesc
->Type
= D3D_SVT_TEXTURE2DARRAY
;
515 case EOT_Texture2DMS
:
516 pDesc
->Type
= D3D_SVT_TEXTURE2DMS
;
518 case EOT_Texture2DMSArray
:
519 pDesc
->Type
= D3D_SVT_TEXTURE2DMSARRAY
;
522 pDesc
->Type
= D3D_SVT_TEXTURE3D
;
524 case EOT_TextureCube
:
525 pDesc
->Type
= D3D_SVT_TEXTURECUBE
;
527 case EOT_TextureCubeArray
:
528 pDesc
->Type
= D3D_SVT_TEXTURECUBEARRAY
;
531 pDesc
->Type
= D3D_SVT_BUFFER
;
534 pDesc
->Type
= D3D_SVT_SAMPLER
;
536 case EOT_RenderTargetView
:
537 pDesc
->Type
= D3D_SVT_RENDERTARGETVIEW
;
539 case EOT_DepthStencilView
:
540 pDesc
->Type
= D3D_SVT_DEPTHSTENCILVIEW
;
542 case EOT_RWTexture1D
:
543 pDesc
->Type
= D3D_SVT_RWTEXTURE1D
;
545 case EOT_RWTexture1DArray
:
546 pDesc
->Type
= D3D_SVT_RWTEXTURE1DARRAY
;
548 case EOT_RWTexture2D
:
549 pDesc
->Type
= D3D_SVT_RWTEXTURE2D
;
551 case EOT_RWTexture2DArray
:
552 pDesc
->Type
= D3D_SVT_RWTEXTURE2DARRAY
;
554 case EOT_RWTexture3D
:
555 pDesc
->Type
= D3D_SVT_RWTEXTURE3D
;
558 pDesc
->Type
= D3D_SVT_RWBUFFER
;
560 case EOT_ByteAddressBuffer
:
561 pDesc
->Type
= D3D_SVT_BYTEADDRESS_BUFFER
;
563 case EOT_RWByteAddressBuffer
:
564 pDesc
->Type
= D3D_SVT_RWBYTEADDRESS_BUFFER
;
566 case EOT_StructuredBuffer
:
567 pDesc
->Type
= D3D_SVT_STRUCTURED_BUFFER
;
569 case EOT_RWStructuredBuffer
:
570 case EOT_RWStructuredBufferAlloc
:
571 case EOT_RWStructuredBufferConsume
:
572 pDesc
->Type
= D3D_SVT_RWSTRUCTURED_BUFFER
;
574 case EOT_AppendStructuredBuffer
:
575 pDesc
->Type
= D3D_SVT_APPEND_STRUCTURED_BUFFER
;
577 case EOT_ConsumeStructuredBuffer
:
578 pDesc
->Type
= D3D_SVT_CONSUME_STRUCTURED_BUFFER
;
595 ////////////////////////////////////////////////////////////////////////////////
596 // ID3DX11EffectShaderVariable (SAnonymousShader implementation)
597 ////////////////////////////////////////////////////////////////////////////////
599 SAnonymousShader::SAnonymousShader(_In_opt_ SShaderBlock
*pBlock
) noexcept
:
604 bool SAnonymousShader::IsValid()
606 return pShaderBlock
&& pShaderBlock
->IsValid
;
609 ID3DX11EffectType
* SAnonymousShader::GetType()
611 return (ID3DX11EffectType
*) this;
614 HRESULT
SAnonymousShader::GetDesc(_Out_ D3DX11_EFFECT_VARIABLE_DESC
*pDesc
)
616 pDesc
->Annotations
= 0;
619 pDesc
->Name
= "$Anonymous";
620 pDesc
->Semantic
= nullptr;
621 pDesc
->BufferOffset
= 0;
626 ID3DX11EffectVariable
* SAnonymousShader::GetAnnotationByIndex(_In_
uint32_t Index
)
628 UNREFERENCED_PARAMETER(Index
);
629 DPF(0, "ID3DX11EffectVariable::GetAnnotationByIndex: Anonymous shaders cannot have annotations");
630 return &g_InvalidScalarVariable
;
633 ID3DX11EffectVariable
* SAnonymousShader::GetAnnotationByName(_In_z_ LPCSTR Name
)
635 UNREFERENCED_PARAMETER(Name
);
636 DPF(0, "ID3DX11EffectVariable::GetAnnotationByName: Anonymous shaders cannot have annotations");
637 return &g_InvalidScalarVariable
;
640 ID3DX11EffectVariable
* SAnonymousShader::GetMemberByIndex(_In_
uint32_t Index
)
642 UNREFERENCED_PARAMETER(Index
);
643 DPF(0, "ID3DX11EffectVariable::GetMemberByIndex: Variable is not a structure");
644 return &g_InvalidScalarVariable
;
647 ID3DX11EffectVariable
* SAnonymousShader::GetMemberByName(_In_z_ LPCSTR Name
)
649 UNREFERENCED_PARAMETER(Name
);
650 DPF(0, "ID3DX11EffectVariable::GetMemberByName: Variable is not a structure");
651 return &g_InvalidScalarVariable
;
654 ID3DX11EffectVariable
* SAnonymousShader::GetMemberBySemantic(_In_z_ LPCSTR Semantic
)
656 UNREFERENCED_PARAMETER(Semantic
);
657 DPF(0, "ID3DX11EffectVariable::GetMemberBySemantic: Variable is not a structure");
658 return &g_InvalidScalarVariable
;
661 ID3DX11EffectVariable
* SAnonymousShader::GetElement(_In_
uint32_t Index
)
663 UNREFERENCED_PARAMETER(Index
);
664 DPF(0, "ID3DX11EffectVariable::GetElement: Anonymous shaders cannot have elements");
665 return &g_InvalidScalarVariable
;
668 ID3DX11EffectConstantBuffer
* SAnonymousShader::GetParentConstantBuffer()
673 ID3DX11EffectShaderVariable
* SAnonymousShader::AsShader()
675 return (ID3DX11EffectShaderVariable
*) this;
678 _Use_decl_annotations_
679 HRESULT
SAnonymousShader::SetRawValue(const void *pData
, uint32_t Offset
, uint32_t Count
)
681 UNREFERENCED_PARAMETER(pData
);
682 UNREFERENCED_PARAMETER(Offset
);
683 UNREFERENCED_PARAMETER(Count
);
684 return ObjectSetRawValue();
687 _Use_decl_annotations_
688 HRESULT
SAnonymousShader::GetRawValue(void *pData
, uint32_t Offset
, uint32_t Count
)
690 UNREFERENCED_PARAMETER(pData
);
691 UNREFERENCED_PARAMETER(Offset
);
692 UNREFERENCED_PARAMETER(Count
);
693 return ObjectGetRawValue();
696 #define ANONYMOUS_SHADER_INDEX_CHECK() \
698 if (0 != ShaderIndex) \
700 DPF(0, "%s: Invalid index specified", pFuncName); \
704 HRESULT SAnonymousShader::GetShaderDesc(_In_ uint32_t ShaderIndex, _Out_ D3DX11_EFFECT_SHADER_DESC *pDesc)
706 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetShaderDesc";
708 ANONYMOUS_SHADER_INDEX_CHECK();
710 hr
= pShaderBlock
->GetShaderDesc(pDesc
, true);
716 _Use_decl_annotations_
717 HRESULT
SAnonymousShader::GetVertexShader(uint32_t ShaderIndex
, ID3D11VertexShader
**ppVS
)
719 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetVertexShader";
721 ANONYMOUS_SHADER_INDEX_CHECK();
723 VH( pShaderBlock
->GetVertexShader(ppVS
) );
729 _Use_decl_annotations_
730 HRESULT
SAnonymousShader::GetGeometryShader(uint32_t ShaderIndex
, ID3D11GeometryShader
**ppGS
)
732 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetGeometryShader";
734 ANONYMOUS_SHADER_INDEX_CHECK();
736 VH( pShaderBlock
->GetGeometryShader(ppGS
) );
742 _Use_decl_annotations_
743 HRESULT
SAnonymousShader::GetPixelShader(uint32_t ShaderIndex
, ID3D11PixelShader
**ppPS
)
745 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetPixelShader";
747 ANONYMOUS_SHADER_INDEX_CHECK();
749 VH( pShaderBlock
->GetPixelShader(ppPS
) );
755 _Use_decl_annotations_
756 HRESULT
SAnonymousShader::GetHullShader(uint32_t ShaderIndex
, ID3D11HullShader
**ppHS
)
758 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetHullShader";
760 ANONYMOUS_SHADER_INDEX_CHECK();
762 VH( pShaderBlock
->GetHullShader(ppHS
) );
768 _Use_decl_annotations_
769 HRESULT
SAnonymousShader::GetDomainShader(uint32_t ShaderIndex
, ID3D11DomainShader
**ppDS
)
771 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetDomainShader";
773 ANONYMOUS_SHADER_INDEX_CHECK();
775 VH( pShaderBlock
->GetDomainShader(ppDS
) );
781 _Use_decl_annotations_
782 HRESULT
SAnonymousShader::GetComputeShader(uint32_t ShaderIndex
, ID3D11ComputeShader
**ppCS
)
784 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetComputeShader";
786 ANONYMOUS_SHADER_INDEX_CHECK();
788 VH( pShaderBlock
->GetComputeShader(ppCS
) );
794 _Use_decl_annotations_
795 HRESULT
SAnonymousShader::GetInputSignatureElementDesc(uint32_t ShaderIndex
, uint32_t Element
, D3D11_SIGNATURE_PARAMETER_DESC
*pDesc
)
797 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetInputSignatureElementDesc";
799 ANONYMOUS_SHADER_INDEX_CHECK();
801 VH( pShaderBlock
->GetSignatureElementDesc(SShaderBlock::ST_Input
, Element
, pDesc
) );
807 _Use_decl_annotations_
808 HRESULT
SAnonymousShader::GetOutputSignatureElementDesc(uint32_t ShaderIndex
, uint32_t Element
, D3D11_SIGNATURE_PARAMETER_DESC
*pDesc
)
810 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetOutputSignatureElementDesc";
812 ANONYMOUS_SHADER_INDEX_CHECK();
814 VH( pShaderBlock
->GetSignatureElementDesc(SShaderBlock::ST_Output
, Element
, pDesc
) );
820 _Use_decl_annotations_
821 HRESULT
SAnonymousShader::GetPatchConstantSignatureElementDesc(uint32_t ShaderIndex
, uint32_t Element
, D3D11_SIGNATURE_PARAMETER_DESC
*pDesc
)
823 static LPCSTR pFuncName
= "ID3DX11EffectShaderVariable::GetPatchConstantSignatureElementDesc";
825 ANONYMOUS_SHADER_INDEX_CHECK();
827 VH( pShaderBlock
->GetSignatureElementDesc(SShaderBlock::ST_PatchConstant
, Element
, pDesc
) );
833 HRESULT
SAnonymousShader::GetDesc(_Out_ D3DX11_EFFECT_TYPE_DESC
*pDesc
)
835 pDesc
->Class
= D3D_SVC_OBJECT
;
837 switch (pShaderBlock
->GetShaderType())
839 case EOT_VertexShader
:
840 case EOT_VertexShader5
:
841 pDesc
->TypeName
= "vertexshader";
842 pDesc
->Type
= D3D_SVT_VERTEXSHADER
;
844 case EOT_GeometryShader
:
845 case EOT_GeometryShader5
:
846 pDesc
->TypeName
= "geometryshader";
847 pDesc
->Type
= D3D_SVT_GEOMETRYSHADER
;
849 case EOT_PixelShader
:
850 case EOT_PixelShader5
:
851 pDesc
->TypeName
= "pixelshader";
852 pDesc
->Type
= D3D_SVT_PIXELSHADER
;
854 case EOT_HullShader5
:
855 pDesc
->TypeName
= "Hullshader";
856 pDesc
->Type
= D3D_SVT_HULLSHADER
;
858 case EOT_DomainShader5
:
859 pDesc
->TypeName
= "Domainshader";
860 pDesc
->Type
= D3D_SVT_DOMAINSHADER
;
862 case EOT_ComputeShader5
:
863 pDesc
->TypeName
= "Computeshader";
864 pDesc
->Type
= D3D_SVT_COMPUTESHADER
;
872 pDesc
->PackedSize
= 0;
873 pDesc
->UnpackedSize
= 0;
879 ID3DX11EffectType
* SAnonymousShader::GetMemberTypeByIndex(_In_
uint32_t Index
)
881 UNREFERENCED_PARAMETER(Index
);
882 DPF(0, "ID3DX11EffectType::GetMemberTypeByIndex: This interface does not refer to a structure");
883 return &g_InvalidType
;
886 ID3DX11EffectType
* SAnonymousShader::GetMemberTypeByName(_In_z_ LPCSTR Name
)
888 UNREFERENCED_PARAMETER(Name
);
889 DPF(0, "ID3DX11EffectType::GetMemberTypeByName: This interface does not refer to a structure");
890 return &g_InvalidType
;
893 ID3DX11EffectType
* SAnonymousShader::GetMemberTypeBySemantic(_In_z_ LPCSTR Semantic
)
895 UNREFERENCED_PARAMETER(Semantic
);
896 DPF(0, "ID3DX11EffectType::GetMemberTypeBySemantic: This interface does not refer to a structure");
897 return &g_InvalidType
;
900 LPCSTR
SAnonymousShader::GetMemberName(_In_
uint32_t Index
)
902 UNREFERENCED_PARAMETER(Index
);
903 DPF(0, "ID3DX11EffectType::GetMemberName: This interface does not refer to a structure");
907 LPCSTR
SAnonymousShader::GetMemberSemantic(_In_
uint32_t Index
)
909 UNREFERENCED_PARAMETER(Index
);
910 DPF(0, "ID3DX11EffectType::GetMemberSemantic: This interface does not refer to a structure");
914 //////////////////////////////////////////////////////////////////////////
915 // ID3DX11EffectConstantBuffer (SConstantBuffer implementation)
916 //////////////////////////////////////////////////////////////////////////
918 bool SConstantBuffer::IsValid()
923 ID3DX11EffectType
* SConstantBuffer::GetType()
925 return (ID3DX11EffectType
*) this;
928 HRESULT
SConstantBuffer::GetDesc(_Out_ D3DX11_EFFECT_VARIABLE_DESC
*pDesc
)
930 pDesc
->Annotations
= AnnotationCount
;
934 pDesc
->Semantic
= nullptr;
935 pDesc
->BufferOffset
= 0;
937 if (ExplicitBindPoint
!= static_cast<uint32_t>(- 1))
939 pDesc
->ExplicitBindPoint
= ExplicitBindPoint
;
940 pDesc
->Flags
|= D3DX11_EFFECT_VARIABLE_EXPLICIT_BIND_POINT
;
944 pDesc
->ExplicitBindPoint
= 0;
950 ID3DX11EffectVariable
* SConstantBuffer::GetAnnotationByIndex(_In_
uint32_t Index
)
952 return GetAnnotationByIndexHelper("ID3DX11EffectVariable", Index
, AnnotationCount
, pAnnotations
);
955 ID3DX11EffectVariable
* SConstantBuffer::GetAnnotationByName(_In_z_ LPCSTR Name
)
957 return GetAnnotationByNameHelper("ID3DX11EffectVariable", Name
, AnnotationCount
, pAnnotations
);
960 ID3DX11EffectVariable
* SConstantBuffer::GetMemberByIndex(_In_
uint32_t Index
)
962 SGlobalVariable
*pMember
;
963 UDataPointer dataPtr
;
965 if (IsEffectOptimized
)
967 DPF(0, "ID3DX11EffectVariable::GetMemberByIndex: Cannot get members; effect has been Optimize()'ed");
968 return &g_InvalidScalarVariable
;
971 if (!GetVariableByIndexHelper
<SGlobalVariable
>(Index
, VariableCount
, (SGlobalVariable
*)pVariables
,
972 nullptr, &pMember
, &dataPtr
.pGeneric
))
974 return &g_InvalidScalarVariable
;
977 return (ID3DX11EffectVariable
*) pMember
;
980 ID3DX11EffectVariable
* SConstantBuffer::GetMemberByName(_In_z_ LPCSTR Name
)
982 SGlobalVariable
*pMember
;
983 UDataPointer dataPtr
;
986 if (IsEffectOptimized
)
988 DPF(0, "ID3DX11EffectVariable::GetMemberByName: Cannot get members; effect has been Optimize()'ed");
989 return &g_InvalidScalarVariable
;
992 if (!GetVariableByNameHelper
<SGlobalVariable
>(Name
, VariableCount
, (SGlobalVariable
*)pVariables
,
993 nullptr, &pMember
, &dataPtr
.pGeneric
, &index
))
995 return &g_InvalidScalarVariable
;
998 return (ID3DX11EffectVariable
*) pMember
;
1001 ID3DX11EffectVariable
* SConstantBuffer::GetMemberBySemantic(_In_z_ LPCSTR Semantic
)
1003 SGlobalVariable
*pMember
;
1004 UDataPointer dataPtr
;
1007 if (IsEffectOptimized
)
1009 DPF(0, "ID3DX11EffectVariable::GetMemberBySemantic: Cannot get members; effect has been Optimize()'ed");
1010 return &g_InvalidScalarVariable
;
1013 if (!GetVariableBySemanticHelper
<SGlobalVariable
>(Semantic
, VariableCount
, (SGlobalVariable
*)pVariables
,
1014 nullptr, &pMember
, &dataPtr
.pGeneric
, &index
))
1016 return &g_InvalidScalarVariable
;
1019 return (ID3DX11EffectVariable
*) pMember
;
1022 ID3DX11EffectVariable
* SConstantBuffer::GetElement(_In_
uint32_t Index
)
1024 UNREFERENCED_PARAMETER(Index
);
1025 static LPCSTR pFuncName
= "ID3DX11EffectVariable::GetElement";
1026 DPF(0, "%s: This interface does not refer to an array", pFuncName
);
1027 return &g_InvalidScalarVariable
;
1030 ID3DX11EffectConstantBuffer
* SConstantBuffer::GetParentConstantBuffer()
1032 static LPCSTR pFuncName
= "ID3DX11EffectVariable::GetParentConstantBuffer";
1033 DPF(0, "%s: Constant buffers do not have parent constant buffers", pFuncName
);
1034 return &g_InvalidConstantBuffer
;
1037 ID3DX11EffectConstantBuffer
* SConstantBuffer::AsConstantBuffer()
1039 return (ID3DX11EffectConstantBuffer
*) this;
1042 HRESULT
SConstantBuffer::GetDesc(_Out_ D3DX11_EFFECT_TYPE_DESC
*pDesc
)
1044 pDesc
->TypeName
= IsTBuffer
? "tbuffer" : "cbuffer";
1045 pDesc
->Class
= D3D_SVC_OBJECT
;
1046 pDesc
->Type
= IsTBuffer
? D3D_SVT_TBUFFER
: D3D_SVT_CBUFFER
;
1048 pDesc
->Elements
= 0;
1049 pDesc
->Members
= VariableCount
;
1054 pDesc
->PackedSize
= 0;
1055 for (i
= 0; i
< VariableCount
; ++ i
)
1057 pDesc
->PackedSize
+= pVariables
[i
].pType
->PackedSize
;
1060 pDesc
->UnpackedSize
= Size
;
1061 assert(pDesc
->UnpackedSize
>= pDesc
->PackedSize
);
1063 pDesc
->Stride
= AlignToPowerOf2(pDesc
->UnpackedSize
, SType::c_RegisterSize
);
1068 ID3DX11EffectType
* SConstantBuffer::GetMemberTypeByIndex(_In_
uint32_t Index
)
1070 return GetTypeByIndexHelper(Index
, VariableCount
, pVariables
, sizeof (SGlobalVariable
));
1073 ID3DX11EffectType
* SConstantBuffer::GetMemberTypeByName(_In_z_ LPCSTR Name
)
1075 return GetTypeByNameHelper(Name
, VariableCount
, pVariables
, sizeof (SGlobalVariable
));
1078 ID3DX11EffectType
* SConstantBuffer::GetMemberTypeBySemantic(_In_z_ LPCSTR Semantic
)
1080 return GetTypeBySemanticHelper(Semantic
, VariableCount
, pVariables
, sizeof (SGlobalVariable
));
1083 LPCSTR
SConstantBuffer::GetMemberName(_In_
uint32_t Index
)
1085 static LPCSTR pFuncName
= "ID3DX11EffectType::GetMemberName";
1087 if (IsEffectOptimized
)
1089 DPF(0, "%s: Cannot get member names; Effect has been Optimize()'ed", pFuncName
);
1093 if (Index
>= VariableCount
)
1095 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName
, Index
, VariableCount
);
1099 return pVariables
[Index
].pName
;
1102 LPCSTR
SConstantBuffer::GetMemberSemantic(_In_
uint32_t Index
)
1104 static LPCSTR pFuncName
= "ID3DX11EffectType::GetMemberSemantic";
1106 if (IsEffectOptimized
)
1108 DPF(0, "%s: Cannot get member semantics; Effect has been Optimize()'ed", pFuncName
);
1112 if (Index
>= VariableCount
)
1114 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName
, Index
, VariableCount
);
1118 return pVariables
[Index
].pSemantic
;
1121 _Use_decl_annotations_
1122 HRESULT
SConstantBuffer::SetRawValue(const void *pData
, uint32_t Offset
, uint32_t Count
)
1127 static LPCSTR pFuncName
= "ID3DX11EffectVariable::SetRawValue";
1129 VERIFYPARAMETER(pData
);
1131 if ((Offset
+ Count
< Offset
) ||
1132 (Count
+ (uint8_t*)pData
< (uint8_t*)pData
) ||
1133 ((Offset
+ Count
) > Size
))
1135 // overflow of some kind
1136 DPF(0, "%s: Invalid range specified", pFuncName
);
1141 if (IsUsedByExpression
)
1144 for (i
= 0; i
< VariableCount
; ++ i
)
1146 ((SGlobalVariable
*)pVariables
)[i
].DirtyVariable();
1154 memcpy(pBackingStore
+ Offset
, pData
, Count
);
1160 _Use_decl_annotations_
1161 HRESULT
SConstantBuffer::GetRawValue(void *pData
, uint32_t Offset
, uint32_t Count
)
1166 static LPCSTR pFuncName
= "ID3DX11EffectVariable::GetRawValue";
1168 VERIFYPARAMETER(pData
);
1170 if ((Offset
+ Count
< Offset
) ||
1171 (Count
+ (uint8_t*)pData
< (uint8_t*)pData
) ||
1172 ((Offset
+ Count
) > Size
))
1174 // overflow of some kind
1175 DPF(0, "%s: Invalid range specified", pFuncName
);
1180 memcpy(pData
, pBackingStore
+ Offset
, Count
);
1186 bool SConstantBuffer::ClonedSingle() const
1188 return IsSingle
&& ( pEffect
->m_Flags
& D3DX11_EFFECT_CLONE
);
1191 HRESULT
SConstantBuffer::SetConstantBuffer(_In_ ID3D11Buffer
*pConstantBuffer
)
1194 static LPCSTR pFuncName
= "ID3DX11EffectConstantBuffer::SetConstantBuffer";
1198 DPF(0, "%s: This is a texture buffer; use SetTextureBuffer instead", pFuncName
);
1199 VH(D3DERR_INVALIDCALL
);
1202 // Replace all references to the old shader block with this one
1203 pEffect
->ReplaceCBReference(this, pConstantBuffer
);
1205 if( !IsUserManaged
)
1207 // Save original cbuffer in case we UndoSet
1208 assert( pMemberData
[0].Type
== MDT_Buffer
);
1209 VB( pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
== nullptr );
1210 pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
= pD3DObject
;
1211 pD3DObject
= nullptr;
1212 IsUserManaged
= true;
1213 IsNonUpdatable
= true;
1216 SAFE_ADDREF( pConstantBuffer
);
1217 SAFE_RELEASE( pD3DObject
);
1218 pD3DObject
= pConstantBuffer
;
1224 HRESULT
SConstantBuffer::GetConstantBuffer(_Outptr_ ID3D11Buffer
**ppConstantBuffer
)
1227 static LPCSTR pFuncName
= "ID3DX11EffectConstantBuffer::GetConstantBuffer";
1229 VERIFYPARAMETER(ppConstantBuffer
);
1233 DPF(0, "%s: This is a texture buffer; use GetTextureBuffer instead", pFuncName
);
1234 VH(D3DERR_INVALIDCALL
);
1237 assert( pD3DObject
);
1238 _Analysis_assume_( pD3DObject
);
1239 *ppConstantBuffer
= pD3DObject
;
1240 SAFE_ADDREF(*ppConstantBuffer
);
1246 HRESULT
SConstantBuffer::UndoSetConstantBuffer()
1249 static LPCSTR pFuncName
= "ID3DX11EffectConstantBuffer::UndoSetConstantBuffer";
1253 DPF(0, "%s: This is a texture buffer; use UndoSetTextureBuffer instead", pFuncName
);
1254 VH(D3DERR_INVALIDCALL
);
1257 if( !IsUserManaged
)
1262 // Replace all references to the old shader block with this one
1263 pEffect
->ReplaceCBReference(this, pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
);
1265 // Revert to original cbuffer
1266 SAFE_RELEASE( pD3DObject
);
1267 pD3DObject
= pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
;
1268 pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
= nullptr;
1269 IsUserManaged
= false;
1270 IsNonUpdatable
= ClonedSingle();
1276 HRESULT
SConstantBuffer::SetTextureBuffer(_In_ ID3D11ShaderResourceView
*pTextureBuffer
)
1279 static LPCSTR pFuncName
= "ID3DX11EffectConstantBuffer::SetTextureBuffer";
1283 DPF(0, "%s: This is a constant buffer; use SetConstantBuffer instead", pFuncName
);
1284 VH(D3DERR_INVALIDCALL
);
1287 if( !IsUserManaged
)
1289 // Save original cbuffer and tbuffer in case we UndoSet
1290 assert( pMemberData
[0].Type
== MDT_Buffer
);
1291 VB( pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
== nullptr );
1292 pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
= pD3DObject
;
1293 pD3DObject
= nullptr;
1294 assert( pMemberData
[1].Type
== MDT_ShaderResourceView
);
1295 VB( pMemberData
[1].Data
.pD3DEffectsManagedTextureBuffer
== nullptr );
1296 pMemberData
[1].Data
.pD3DEffectsManagedTextureBuffer
= TBuffer
.pShaderResource
;
1297 TBuffer
.pShaderResource
= nullptr;
1298 IsUserManaged
= true;
1299 IsNonUpdatable
= true;
1302 SAFE_ADDREF( pTextureBuffer
);
1303 SAFE_RELEASE(pD3DObject
); // won't be needing this anymore...
1304 SAFE_RELEASE( TBuffer
.pShaderResource
);
1305 TBuffer
.pShaderResource
= pTextureBuffer
;
1311 HRESULT
SConstantBuffer::GetTextureBuffer(_Outptr_ ID3D11ShaderResourceView
**ppTextureBuffer
)
1314 static LPCSTR pFuncName
= "ID3DX11EffectConstantBuffer::GetTextureBuffer";
1316 VERIFYPARAMETER(ppTextureBuffer
);
1320 DPF(0, "%s: This is a constant buffer; use GetConstantBuffer instead", pFuncName
);
1321 VH(D3DERR_INVALIDCALL
);
1324 assert( TBuffer
.pShaderResource
);
1325 _Analysis_assume_( TBuffer
.pShaderResource
);
1326 *ppTextureBuffer
= TBuffer
.pShaderResource
;
1327 SAFE_ADDREF(*ppTextureBuffer
);
1333 HRESULT
SConstantBuffer::UndoSetTextureBuffer()
1336 static LPCSTR pFuncName
= "ID3DX11EffectConstantBuffer::UndoSetTextureBuffer";
1340 DPF(0, "%s: This is a texture buffer; use UndoSetConstantBuffer instead", pFuncName
);
1341 VH(D3DERR_INVALIDCALL
);
1344 if( !IsUserManaged
)
1349 // Revert to original cbuffer
1350 SAFE_RELEASE( pD3DObject
);
1351 pD3DObject
= pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
;
1352 pMemberData
[0].Data
.pD3DEffectsManagedConstantBuffer
= nullptr;
1353 SAFE_RELEASE( TBuffer
.pShaderResource
);
1354 TBuffer
.pShaderResource
= pMemberData
[1].Data
.pD3DEffectsManagedTextureBuffer
;
1355 pMemberData
[1].Data
.pD3DEffectsManagedTextureBuffer
= nullptr;
1356 IsUserManaged
= false;
1357 IsNonUpdatable
= ClonedSingle();
1363 //////////////////////////////////////////////////////////////////////////
1364 // ID3DX11EffectPass (CEffectPass implementation)
1365 //////////////////////////////////////////////////////////////////////////
1367 bool SPassBlock::IsValid()
1369 if( HasDependencies
)
1370 return pEffect
->ValidatePassBlock( this );
1371 return InitiallyValid
;
1374 HRESULT
SPassBlock::GetDesc(_Out_ D3DX11_PASS_DESC
*pDesc
)
1377 static LPCSTR pFuncName
= "ID3DX11EffectPass::GetDesc";
1379 VERIFYPARAMETER(pDesc
);
1381 ZeroMemory(pDesc
, sizeof(*pDesc
));
1383 pDesc
->Name
= pName
;
1384 pDesc
->Annotations
= AnnotationCount
;
1386 SAssignment
*pAssignment
;
1387 SAssignment
*pLastAssn
;
1389 pEffect
->IncrementTimer();
1391 pAssignment
= pAssignments
;
1392 pLastAssn
= pAssignments
+ AssignmentCount
;
1394 for(; pAssignment
< pLastAssn
; pAssignment
++)
1396 pEffect
->EvaluateAssignment(pAssignment
);
1399 if( BackingStore
.pVertexShaderBlock
&& BackingStore
.pVertexShaderBlock
->pInputSignatureBlob
)
1401 // pInputSignatureBlob can be null if we're setting a nullptr VS "SetVertexShader( nullptr )"
1402 pDesc
->pIAInputSignature
= (uint8_t*)BackingStore
.pVertexShaderBlock
->pInputSignatureBlob
->GetBufferPointer();
1403 pDesc
->IAInputSignatureSize
= BackingStore
.pVertexShaderBlock
->pInputSignatureBlob
->GetBufferSize();
1406 pDesc
->StencilRef
= BackingStore
.StencilRef
;
1407 pDesc
->SampleMask
= BackingStore
.SampleMask
;
1408 pDesc
->BlendFactor
[0] = BackingStore
.BlendFactor
[0];
1409 pDesc
->BlendFactor
[1] = BackingStore
.BlendFactor
[1];
1410 pDesc
->BlendFactor
[2] = BackingStore
.BlendFactor
[2];
1411 pDesc
->BlendFactor
[3] = BackingStore
.BlendFactor
[3];
1417 extern SShaderBlock g_NullVS
;
1418 extern SShaderBlock g_NullGS
;
1419 extern SShaderBlock g_NullPS
;
1420 extern SShaderBlock g_NullHS
;
1421 extern SShaderBlock g_NullDS
;
1422 extern SShaderBlock g_NullCS
;
1424 SAnonymousShader
g_AnonymousNullVS(&g_NullVS
);
1425 SAnonymousShader
g_AnonymousNullGS(&g_NullGS
);
1426 SAnonymousShader
g_AnonymousNullPS(&g_NullPS
);
1427 SAnonymousShader
g_AnonymousNullHS(&g_NullHS
);
1428 SAnonymousShader
g_AnonymousNullDS(&g_NullDS
);
1429 SAnonymousShader
g_AnonymousNullCS(&g_NullCS
);
1431 template<EObjectType EShaderType
>
1432 HRESULT
SPassBlock::GetShaderDescHelper(D3DX11_PASS_SHADER_DESC
*pDesc
)
1436 LPCSTR pFuncName
= nullptr;
1437 SShaderBlock
*pShaderBlock
= nullptr;
1439 ApplyPassAssignments();
1442 #pragma prefast(push)
1443 #pragma prefast(disable:__WARNING_UNUSED_POINTER_ASSIGNMENT, "pFuncName used in DPF")
1445 switch (EShaderType
)
1447 case EOT_VertexShader
:
1448 case EOT_VertexShader5
:
1449 pFuncName
= "ID3DX11EffectPass::GetVertexShaderDesc";
1450 pShaderBlock
= BackingStore
.pVertexShaderBlock
;
1452 case EOT_PixelShader
:
1453 case EOT_PixelShader5
:
1454 pFuncName
= "ID3DX11EffectPass::GetPixelShaderDesc";
1455 pShaderBlock
= BackingStore
.pPixelShaderBlock
;
1457 case EOT_GeometryShader
:
1458 case EOT_GeometryShader5
:
1459 pFuncName
= "ID3DX11EffectPass::GetGeometryShaderDesc";
1460 pShaderBlock
= BackingStore
.pGeometryShaderBlock
;
1462 case EOT_HullShader5
:
1463 pFuncName
= "ID3DX11EffectPass::GetHullShaderDesc";
1464 pShaderBlock
= BackingStore
.pHullShaderBlock
;
1466 case EOT_DomainShader5
:
1467 pFuncName
= "ID3DX11EffectPass::GetDomainShaderDesc";
1468 pShaderBlock
= BackingStore
.pDomainShaderBlock
;
1470 case EOT_ComputeShader5
:
1471 pFuncName
= "ID3DX11EffectPass::GetComputeShaderDesc";
1472 pShaderBlock
= BackingStore
.pComputeShaderBlock
;
1475 #pragma prefast(pop)
1481 VERIFYPARAMETER(pDesc
);
1483 // in case of error (or in case the assignment doesn't exist), return something reasonable
1484 pDesc
->pShaderVariable
= &g_InvalidShaderVariable
;
1485 pDesc
->ShaderIndex
= 0;
1487 if (nullptr != pShaderBlock
)
1489 uint32_t elements
, varCount
, anonymousShaderCount
;
1490 SGlobalVariable
*pVariables
;
1491 SAnonymousShader
*pAnonymousShaders
;
1493 if (pShaderBlock
== &g_NullVS
)
1495 pDesc
->pShaderVariable
= &g_AnonymousNullVS
;
1496 pDesc
->ShaderIndex
= 0;
1500 else if (pShaderBlock
== &g_NullGS
)
1502 pDesc
->pShaderVariable
= &g_AnonymousNullGS
;
1503 pDesc
->ShaderIndex
= 0;
1507 else if (pShaderBlock
== &g_NullPS
)
1509 pDesc
->pShaderVariable
= &g_AnonymousNullPS
;
1510 pDesc
->ShaderIndex
= 0;
1514 else if (pShaderBlock
== &g_NullHS
)
1516 pDesc
->pShaderVariable
= &g_AnonymousNullHS
;
1517 pDesc
->ShaderIndex
= 0;
1521 else if (pShaderBlock
== &g_NullDS
)
1523 pDesc
->pShaderVariable
= &g_AnonymousNullDS
;
1524 pDesc
->ShaderIndex
= 0;
1528 else if (pShaderBlock
== &g_NullCS
)
1530 pDesc
->pShaderVariable
= &g_AnonymousNullCS
;
1531 pDesc
->ShaderIndex
= 0;
1537 VB( pEffect
->IsRuntimeData(pShaderBlock
) );
1538 varCount
= pEffect
->m_VariableCount
;
1539 pVariables
= pEffect
->m_pVariables
;
1540 anonymousShaderCount
= pEffect
->m_AnonymousShaderCount
;
1541 pAnonymousShaders
= pEffect
->m_pAnonymousShaders
;
1544 for (i
= 0; i
< varCount
; ++ i
)
1546 elements
= std::max
<uint32_t>(1, pVariables
[i
].pType
->Elements
);
1547 // make sure the variable type matches, and don't forget about GeometryShaderSO's
1548 if (pVariables
[i
].pType
->IsShader())
1550 if (pShaderBlock
>= pVariables
[i
].Data
.pShader
&& pShaderBlock
< pVariables
[i
].Data
.pShader
+ elements
)
1552 pDesc
->pShaderVariable
= (ID3DX11EffectShaderVariable
*)(pVariables
+ i
);
1553 pDesc
->ShaderIndex
= (uint32_t)(UINT_PTR
)(pShaderBlock
- pVariables
[i
].Data
.pShader
);
1560 for (i
= 0; i
< anonymousShaderCount
; ++ i
)
1562 if (pShaderBlock
== pAnonymousShaders
[i
].pShaderBlock
)
1564 VB(EShaderType
== pAnonymousShaders
[i
].pShaderBlock
->GetShaderType())
1565 pDesc
->pShaderVariable
= (pAnonymousShaders
+ i
);
1566 pDesc
->ShaderIndex
= 0;
1572 DPF(0, "%s: Internal error; shader not found", pFuncName
);
1580 HRESULT
SPassBlock::GetVertexShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC
*pDesc
)
1582 return GetShaderDescHelper
<EOT_VertexShader
>(pDesc
);
1585 HRESULT
SPassBlock::GetPixelShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC
*pDesc
)
1587 return GetShaderDescHelper
<EOT_PixelShader
>(pDesc
);
1590 HRESULT
SPassBlock::GetGeometryShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC
*pDesc
)
1592 return GetShaderDescHelper
<EOT_GeometryShader
>(pDesc
);
1595 HRESULT
SPassBlock::GetHullShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC
*pDesc
)
1597 return GetShaderDescHelper
<EOT_HullShader5
>(pDesc
);
1600 HRESULT
SPassBlock::GetDomainShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC
*pDesc
)
1602 return GetShaderDescHelper
<EOT_DomainShader5
>(pDesc
);
1605 HRESULT
SPassBlock::GetComputeShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC
*pDesc
)
1607 return GetShaderDescHelper
<EOT_ComputeShader5
>(pDesc
);
1610 ID3DX11EffectVariable
* SPassBlock::GetAnnotationByIndex(_In_
uint32_t Index
)
1612 return GetAnnotationByIndexHelper("ID3DX11EffectPass", Index
, AnnotationCount
, pAnnotations
);
1615 ID3DX11EffectVariable
* SPassBlock::GetAnnotationByName(_In_z_ LPCSTR Name
)
1617 return GetAnnotationByNameHelper("ID3DX11EffectPass", Name
, AnnotationCount
, pAnnotations
);
1620 HRESULT
SPassBlock::Apply(_In_
uint32_t Flags
, _In_ ID3D11DeviceContext
* pContext
)
1623 UNREFERENCED_PARAMETER(Flags
);
1626 // Flags are unused, so should be 0
1629 assert( pEffect
->m_pContext
== nullptr );
1630 pEffect
->m_pContext
= pContext
;
1631 pEffect
->ApplyPassBlock(this);
1632 pEffect
->m_pContext
= nullptr;
1637 HRESULT
SPassBlock::ComputeStateBlockMask(_Inout_ D3DX11_STATE_BLOCK_MASK
*pStateBlockMask
)
1641 // flags indicating whether the following shader types were caught by assignment checks or not
1642 bool bVS
= false, bGS
= false, bPS
= false, bHS
= false, bDS
= false, bCS
= false;
1644 for (size_t i
= 0; i
< AssignmentCount
; ++ i
)
1646 bool bShader
= false;
1648 switch (pAssignments
[i
].LhsType
)
1650 case ELHS_VertexShaderBlock
:
1654 case ELHS_GeometryShaderBlock
:
1658 case ELHS_PixelShaderBlock
:
1662 case ELHS_HullShaderBlock
:
1666 case ELHS_DomainShaderBlock
:
1670 case ELHS_ComputeShaderBlock
:
1675 case ELHS_RasterizerBlock
:
1676 pStateBlockMask
->RSRasterizerState
= 1;
1678 case ELHS_BlendBlock
:
1679 pStateBlockMask
->OMBlendState
= 1;
1681 case ELHS_DepthStencilBlock
:
1682 pStateBlockMask
->OMDepthStencilState
= 1;
1686 // ignore this assignment (must be a scalar/vector assignment associated with a state object)
1692 for (size_t j
= 0; j
< pAssignments
[i
].MaxElements
; ++ j
)
1694 // compute state block mask for the union of ALL shaders
1695 VH( pAssignments
[i
].Source
.pShader
[j
].ComputeStateBlockMask(pStateBlockMask
) );
1700 // go over the state block objects in case there was no corresponding assignment
1701 if (nullptr != BackingStore
.pRasterizerBlock
)
1703 pStateBlockMask
->RSRasterizerState
= 1;
1705 if (nullptr != BackingStore
.pBlendBlock
)
1707 pStateBlockMask
->OMBlendState
= 1;
1709 if (nullptr != BackingStore
.pDepthStencilBlock
)
1711 pStateBlockMask
->OMDepthStencilState
= 1;
1714 // go over the shaders only if an assignment didn't already catch them
1715 if (false == bVS
&& nullptr != BackingStore
.pVertexShaderBlock
)
1717 VH( BackingStore
.pVertexShaderBlock
->ComputeStateBlockMask(pStateBlockMask
) );
1719 if (false == bGS
&& nullptr != BackingStore
.pGeometryShaderBlock
)
1721 VH( BackingStore
.pGeometryShaderBlock
->ComputeStateBlockMask(pStateBlockMask
) );
1723 if (false == bPS
&& nullptr != BackingStore
.pPixelShaderBlock
)
1725 VH( BackingStore
.pPixelShaderBlock
->ComputeStateBlockMask(pStateBlockMask
) );
1727 if (false == bHS
&& nullptr != BackingStore
.pHullShaderBlock
)
1729 VH( BackingStore
.pHullShaderBlock
->ComputeStateBlockMask(pStateBlockMask
) );
1731 if (false == bDS
&& nullptr != BackingStore
.pDomainShaderBlock
)
1733 VH( BackingStore
.pDomainShaderBlock
->ComputeStateBlockMask(pStateBlockMask
) );
1735 if (false == bCS
&& nullptr != BackingStore
.pComputeShaderBlock
)
1737 VH( BackingStore
.pComputeShaderBlock
->ComputeStateBlockMask(pStateBlockMask
) );
1744 //////////////////////////////////////////////////////////////////////////
1745 // ID3DX11EffectTechnique (STechnique implementation)
1746 //////////////////////////////////////////////////////////////////////////
1748 bool STechnique::IsValid()
1750 if( HasDependencies
)
1752 for( size_t i
= 0; i
< PassCount
; i
++ )
1754 if( !((SPassBlock
*)pPasses
)[i
].IsValid() )
1759 return InitiallyValid
;
1762 HRESULT
STechnique::GetDesc(_Out_ D3DX11_TECHNIQUE_DESC
*pDesc
)
1766 static LPCSTR pFuncName
= "ID3DX11EffectTechnique::GetDesc";
1768 VERIFYPARAMETER(pDesc
);
1770 pDesc
->Name
= pName
;
1771 pDesc
->Annotations
= AnnotationCount
;
1772 pDesc
->Passes
= PassCount
;
1778 ID3DX11EffectVariable
* STechnique::GetAnnotationByIndex(_In_
uint32_t Index
)
1780 return GetAnnotationByIndexHelper("ID3DX11EffectTechnique", Index
, AnnotationCount
, pAnnotations
);
1783 ID3DX11EffectVariable
* STechnique::GetAnnotationByName(_In_z_ LPCSTR Name
)
1785 return GetAnnotationByNameHelper("ID3DX11EffectTechnique", Name
, AnnotationCount
, pAnnotations
);
1788 ID3DX11EffectPass
* STechnique::GetPassByIndex(_In_
uint32_t Index
)
1790 static LPCSTR pFuncName
= "ID3DX11EffectTechnique::GetPassByIndex";
1792 if (Index
>= PassCount
)
1794 DPF(0, "%s: Invalid pass index (%u, total: %u)", pFuncName
, Index
, PassCount
);
1795 return &g_InvalidPass
;
1798 return (ID3DX11EffectPass
*)(pPasses
+ Index
);
1801 ID3DX11EffectPass
* STechnique::GetPassByName(_In_z_ LPCSTR Name
)
1803 static LPCSTR pFuncName
= "ID3DX11EffectTechnique::GetPassByName";
1807 for (i
= 0; i
< PassCount
; ++ i
)
1809 if (nullptr != pPasses
[i
].pName
&&
1810 strcmp(pPasses
[i
].pName
, Name
) == 0)
1818 DPF(0, "%s: Pass [%s] not found", pFuncName
, Name
);
1819 return &g_InvalidPass
;
1822 return (ID3DX11EffectPass
*)(pPasses
+ i
);
1825 HRESULT
STechnique::ComputeStateBlockMask(_Inout_ D3DX11_STATE_BLOCK_MASK
*pStateBlockMask
)
1830 _Analysis_assume_( PassCount
== 0 || pPasses
!= 0 );
1831 for (i
= 0; i
< PassCount
; ++ i
)
1833 VH( ((SPassBlock
*)pPasses
)[i
].ComputeStateBlockMask(pStateBlockMask
) );
1840 //////////////////////////////////////////////////////////////////////////
1841 // ID3DX11EffectGroup (SGroup implementation)
1842 //////////////////////////////////////////////////////////////////////////
1844 bool SGroup::IsValid()
1846 if( HasDependencies
)
1848 for( size_t i
= 0; i
< TechniqueCount
; i
++ )
1850 if( !((STechnique
*)pTechniques
)[i
].IsValid() )
1855 return InitiallyValid
;
1858 HRESULT
SGroup::GetDesc(_Out_ D3DX11_GROUP_DESC
*pDesc
)
1862 static LPCSTR pFuncName
= "ID3DX11EffectGroup::GetDesc";
1864 VERIFYPARAMETER(pDesc
);
1866 pDesc
->Name
= pName
;
1867 pDesc
->Annotations
= AnnotationCount
;
1868 pDesc
->Techniques
= TechniqueCount
;
1874 ID3DX11EffectVariable
* SGroup::GetAnnotationByIndex(_In_
uint32_t Index
)
1876 return GetAnnotationByIndexHelper("ID3DX11EffectGroup", Index
, AnnotationCount
, pAnnotations
);
1879 ID3DX11EffectVariable
* SGroup::GetAnnotationByName(_In_z_ LPCSTR Name
)
1881 return GetAnnotationByNameHelper("ID3DX11EffectGroup", Name
, AnnotationCount
, pAnnotations
);
1884 ID3DX11EffectTechnique
* SGroup::GetTechniqueByIndex(_In_
uint32_t Index
)
1886 static LPCSTR pFuncName
= "ID3DX11EffectGroup::GetTechniqueByIndex";
1888 if (Index
>= TechniqueCount
)
1890 DPF(0, "%s: Invalid pass index (%u, total: %u)", pFuncName
, Index
, TechniqueCount
);
1891 return &g_InvalidTechnique
;
1894 return (ID3DX11EffectTechnique
*)(pTechniques
+ Index
);
1897 ID3DX11EffectTechnique
* SGroup::GetTechniqueByName(_In_z_ LPCSTR Name
)
1899 static LPCSTR pFuncName
= "ID3DX11EffectGroup::GetTechniqueByName";
1903 for (i
= 0; i
< TechniqueCount
; ++ i
)
1905 if (nullptr != pTechniques
[i
].pName
&&
1906 strcmp(pTechniques
[i
].pName
, Name
) == 0)
1912 if (i
== TechniqueCount
)
1914 DPF(0, "%s: Technique [%s] not found", pFuncName
, Name
);
1915 return &g_InvalidTechnique
;
1918 return (ID3DX11EffectTechnique
*)(pTechniques
+ i
);
1921 //////////////////////////////////////////////////////////////////////////
1922 // ID3DX11Effect Public Reflection APIs (CEffect)
1923 //////////////////////////////////////////////////////////////////////////
1925 HRESULT
CEffect::GetDevice(_Outptr_ ID3D11Device
**ppDevice
)
1928 static LPCSTR pFuncName
= "ID3DX11Effect::GetDevice";
1929 VERIFYPARAMETER(ppDevice
);
1931 m_pDevice
->AddRef();
1932 *ppDevice
= m_pDevice
;
1938 HRESULT
CEffect::GetDesc(_Out_ D3DX11_EFFECT_DESC
*pDesc
)
1942 static LPCSTR pFuncName
= "ID3DX11Effect::GetDesc";
1944 VERIFYPARAMETER(pDesc
);
1946 pDesc
->ConstantBuffers
= m_CBCount
;
1947 pDesc
->GlobalVariables
= m_VariableCount
;
1948 pDesc
->Techniques
= m_TechniqueCount
;
1949 pDesc
->Groups
= m_GroupCount
;
1950 pDesc
->InterfaceVariables
= m_InterfaceCount
;
1956 ID3DX11EffectConstantBuffer
* CEffect::GetConstantBufferByIndex(_In_
uint32_t Index
)
1958 static LPCSTR pFuncName
= "ID3DX11Effect::GetConstantBufferByIndex";
1960 if (Index
< m_CBCount
)
1962 return m_pCBs
+ Index
;
1965 DPF(0, "%s: Invalid constant buffer index", pFuncName
);
1966 return &g_InvalidConstantBuffer
;
1969 ID3DX11EffectConstantBuffer
* CEffect::GetConstantBufferByName(_In_z_ LPCSTR Name
)
1971 static LPCSTR pFuncName
= "ID3DX11Effect::GetConstantBufferByName";
1975 DPF(0, "%s: Cannot get constant buffer interfaces by name since the effect has been Optimize()'ed", pFuncName
);
1976 return &g_InvalidConstantBuffer
;
1979 if (nullptr == Name
)
1981 DPF(0, "%s: Parameter Name was nullptr.", pFuncName
);
1982 return &g_InvalidConstantBuffer
;
1985 for (uint32_t i
= 0; i
< m_CBCount
; ++ i
)
1987 if (strcmp(m_pCBs
[i
].pName
, Name
) == 0)
1993 DPF(0, "%s: Constant Buffer [%s] not found", pFuncName
, Name
);
1994 return &g_InvalidConstantBuffer
;
1997 ID3DX11EffectVariable
* CEffect::GetVariableByIndex(_In_
uint32_t Index
)
1999 static LPCSTR pFuncName
= "ID3DX11Effect::GetVariableByIndex";
2001 if (Index
< m_VariableCount
)
2003 return m_pVariables
+ Index
;
2006 DPF(0, "%s: Invalid variable index", pFuncName
);
2007 return &g_InvalidScalarVariable
;
2010 ID3DX11EffectVariable
* CEffect::GetVariableByName(_In_z_ LPCSTR Name
)
2012 static LPCSTR pFuncName
= "ID3DX11Effect::GetVariableByName";
2016 DPF(0, "%s: Cannot get variable interfaces by name since the effect has been Optimize()'ed", pFuncName
);
2017 return &g_InvalidScalarVariable
;
2020 if (nullptr == Name
)
2022 DPF(0, "%s: Parameter Name was nullptr.", pFuncName
);
2023 return &g_InvalidScalarVariable
;
2026 for (uint32_t i
= 0; i
< m_VariableCount
; ++ i
)
2028 if (strcmp(m_pVariables
[i
].pName
, Name
) == 0)
2030 return m_pVariables
+ i
;
2034 DPF(0, "%s: Variable [%s] not found", pFuncName
, Name
);
2035 return &g_InvalidScalarVariable
;
2038 ID3DX11EffectVariable
* CEffect::GetVariableBySemantic(_In_z_ LPCSTR Semantic
)
2040 static LPCSTR pFuncName
= "ID3DX11Effect::GetVariableBySemantic";
2044 DPF(0, "%s: Cannot get variable interfaces by semantic since the effect has been Optimize()'ed", pFuncName
);
2045 return &g_InvalidScalarVariable
;
2048 if (nullptr == Semantic
)
2050 DPF(0, "%s: Parameter Semantic was nullptr.", pFuncName
);
2051 return &g_InvalidScalarVariable
;
2056 for (i
= 0; i
< m_VariableCount
; ++ i
)
2058 if (nullptr != m_pVariables
[i
].pSemantic
&&
2059 _stricmp(m_pVariables
[i
].pSemantic
, Semantic
) == 0)
2061 return (ID3DX11EffectVariable
*)(m_pVariables
+ i
);
2065 DPF(0, "%s: Variable with semantic [%s] not found", pFuncName
, Semantic
);
2066 return &g_InvalidScalarVariable
;
2069 ID3DX11EffectTechnique
* CEffect::GetTechniqueByIndex(_In_
uint32_t Index
)
2071 static LPCSTR pFuncName
= "ID3DX11Effect::GetTechniqueByIndex";
2073 if( Index
< m_TechniqueCount
)
2075 for( size_t i
=0; i
< m_GroupCount
; i
++ )
2077 if( Index
< m_pGroups
[i
].TechniqueCount
)
2079 return (ID3DX11EffectTechnique
*)(m_pGroups
[i
].pTechniques
+ Index
);
2081 Index
-= m_pGroups
[i
].TechniqueCount
;
2085 DPF(0, "%s: Invalid technique index (%u)", pFuncName
, Index
);
2086 return &g_InvalidTechnique
;
2089 ID3DX11EffectTechnique
* CEffect::GetTechniqueByName(_In_z_ LPCSTR Name
)
2091 static LPCSTR pFuncName
= "ID3DX11Effect::GetTechniqueByName";
2092 const size_t MAX_GROUP_TECHNIQUE_SIZE
= 256;
2093 char NameCopy
[MAX_GROUP_TECHNIQUE_SIZE
];
2097 DPF(0, "ID3DX11Effect::GetTechniqueByName: Cannot get technique interfaces by name since the effect has been Optimize()'ed");
2098 return &g_InvalidTechnique
;
2101 if (nullptr == Name
)
2103 DPF(0, "%s: Parameter Name was nullptr.", pFuncName
);
2104 return &g_InvalidTechnique
;
2107 if( FAILED( strcpy_s( NameCopy
, MAX_GROUP_TECHNIQUE_SIZE
, Name
) ) )
2109 DPF( 0, "Group|Technique name has a length greater than %zu.", MAX_GROUP_TECHNIQUE_SIZE
);
2110 return &g_InvalidTechnique
;
2113 char* pDelimiter
= strchr( NameCopy
, '|' );
2114 if( pDelimiter
== nullptr )
2116 if ( m_pNullGroup
== nullptr )
2118 DPF( 0, "The effect contains no default group." );
2119 return &g_InvalidTechnique
;
2122 return m_pNullGroup
->GetTechniqueByName( Name
);
2125 // separate group name and technique name
2128 return GetGroupByName( NameCopy
)->GetTechniqueByName( pDelimiter
+ 1 );
2131 ID3D11ClassLinkage
* CEffect::GetClassLinkage()
2133 SAFE_ADDREF( m_pClassLinkage
);
2134 return m_pClassLinkage
;
2137 ID3DX11EffectGroup
* CEffect::GetGroupByIndex(_In_
uint32_t Index
)
2139 static LPCSTR pFuncName
= "ID3DX11Effect::GetGroupByIndex";
2141 if( Index
< m_GroupCount
)
2143 return (ID3DX11EffectGroup
*)(m_pGroups
+ Index
);
2145 DPF(0, "%s: Invalid group index (%u)", pFuncName
, Index
);
2146 return &g_InvalidGroup
;
2149 ID3DX11EffectGroup
* CEffect::GetGroupByName(_In_z_ LPCSTR Name
)
2151 static LPCSTR pFuncName
= "ID3DX11Effect::GetGroupByName";
2155 DPF(0, "ID3DX11Effect::GetGroupByName: Cannot get group interfaces by name since the effect has been Optimize()'ed");
2156 return &g_InvalidGroup
;
2159 if (nullptr == Name
|| Name
[0] == 0 )
2161 return m_pNullGroup
? (ID3DX11EffectGroup
*)m_pNullGroup
: &g_InvalidGroup
;
2165 for (; i
< m_GroupCount
; ++ i
)
2167 if (nullptr != m_pGroups
[i
].pName
&&
2168 strcmp(m_pGroups
[i
].pName
, Name
) == 0)
2174 if (i
== m_GroupCount
)
2176 DPF(0, "%s: Group [%s] not found", pFuncName
, Name
);
2177 return &g_InvalidGroup
;
2180 return (ID3DX11EffectGroup
*)(m_pGroups
+ i
);