Merge pull request #23092 from webosbrew/feature/webOS
[xbmc.git] / lib / win32 / Effects11 / EffectReflection.cpp
blob48e7b67de448532bc5c62e669336908ee97e8b0c
1 //--------------------------------------------------------------------------------------
2 // File: EffectReflection.cpp
3 //
4 // Direct3D 11 Effects public reflection APIs
5 //
6 // Copyright (c) Microsoft Corporation.
7 // Licensed under the MIT License.
8 //
9 // http://go.microsoft.com/fwlink/p/?LinkId=271568
10 //--------------------------------------------------------------------------------------
12 #include "pchfx.h"
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)
67 uint32_t i;
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)
86 if (IsOptimized())
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);
109 return 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)
118 bool IsAnnotation;
120 if (IsOptimized())
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) );
143 IsAnnotation = true;
145 else
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;
161 SMember *pNewMember;
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";
223 if (nullptr == Name)
225 DPF(0, "%s: Parameter Name was nullptr.", pFuncName);
226 return &g_InvalidType;
229 uint32_t i;
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;
262 uint32_t i;
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);
324 return nullptr;
327 if (Index >= StructType.Members)
329 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, StructType.Members);
330 return nullptr;
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);
338 return nullptr;
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);
351 return nullptr;
354 if (Index >= StructType.Members)
356 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, StructType.Members);
357 return nullptr;
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);
365 return nullptr;
368 return pVariable->pSemantic;
371 HRESULT SType::GetDescHelper(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc, _In_ bool IsSingleElement) const
373 HRESULT hr = S_OK;
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;
386 switch (VarType)
388 case EVT_Numeric:
389 switch (NumericType.NumericLayout)
391 case ENL_Matrix:
392 if (NumericType.IsColumnMajor)
394 pDesc->Class = D3D_SVC_MATRIX_COLUMNS;
396 else
398 pDesc->Class = D3D_SVC_MATRIX_ROWS;
400 break;
401 case ENL_Vector:
402 pDesc->Class = D3D_SVC_VECTOR;
403 break;
404 case ENL_Scalar:
405 pDesc->Class = D3D_SVC_SCALAR;
406 break;
407 default:
408 assert(0);
411 switch (NumericType.ScalarType)
413 case EST_Bool:
414 pDesc->Type = D3D_SVT_BOOL;
415 break;
416 case EST_Int:
417 pDesc->Type = D3D_SVT_INT;
418 break;
419 case EST_UInt:
420 pDesc->Type = D3D_SVT_UINT;
421 break;
422 case EST_Float:
423 pDesc->Type = D3D_SVT_FLOAT;
424 break;
425 default:
426 assert(0);
429 pDesc->Rows = NumericType.Rows;
430 pDesc->Columns = NumericType.Columns;
431 pDesc->Members = 0;
433 break;
435 case EVT_Struct:
436 pDesc->Rows = 0;
437 pDesc->Columns = 0;
438 pDesc->Members = StructType.Members;
439 if( StructType.ImplementsInterface )
441 pDesc->Class = D3D_SVC_INTERFACE_CLASS;
443 else
445 pDesc->Class = D3D_SVC_STRUCT;
447 pDesc->Type = D3D_SVT_VOID;
448 break;
450 case EVT_Interface:
451 pDesc->Rows = 0;
452 pDesc->Columns = 0;
453 pDesc->Members = 0;
454 pDesc->Class = D3D_SVC_INTERFACE_POINTER;
455 pDesc->Type = D3D_SVT_INTERFACE_POINTER;
456 break;
458 case EVT_Object:
459 pDesc->Rows = 0;
460 pDesc->Columns = 0;
461 pDesc->Members = 0;
462 pDesc->Class = D3D_SVC_OBJECT;
464 switch (ObjectType)
466 case EOT_String:
467 pDesc->Type = D3D_SVT_STRING;
468 break;
469 case EOT_Blend:
470 pDesc->Type = D3D_SVT_BLEND;
471 break;
472 case EOT_DepthStencil:
473 pDesc->Type = D3D_SVT_DEPTHSTENCIL;
474 break;
475 case EOT_Rasterizer:
476 pDesc->Type = D3D_SVT_RASTERIZER;
477 break;
478 case EOT_PixelShader:
479 case EOT_PixelShader5:
480 pDesc->Type = D3D_SVT_PIXELSHADER;
481 break;
482 case EOT_VertexShader:
483 case EOT_VertexShader5:
484 pDesc->Type = D3D_SVT_VERTEXSHADER;
485 break;
486 case EOT_GeometryShader:
487 case EOT_GeometryShaderSO:
488 case EOT_GeometryShader5:
489 pDesc->Type = D3D_SVT_GEOMETRYSHADER;
490 break;
491 case EOT_HullShader5:
492 pDesc->Type = D3D_SVT_HULLSHADER;
493 break;
494 case EOT_DomainShader5:
495 pDesc->Type = D3D_SVT_DOMAINSHADER;
496 break;
497 case EOT_ComputeShader5:
498 pDesc->Type = D3D_SVT_COMPUTESHADER;
499 break;
500 case EOT_Texture:
501 pDesc->Type = D3D_SVT_TEXTURE;
502 break;
503 case EOT_Texture1D:
504 pDesc->Type = D3D_SVT_TEXTURE1D;
505 break;
506 case EOT_Texture1DArray:
507 pDesc->Type = D3D_SVT_TEXTURE1DARRAY;
508 break;
509 case EOT_Texture2D:
510 pDesc->Type = D3D_SVT_TEXTURE2D;
511 break;
512 case EOT_Texture2DArray:
513 pDesc->Type = D3D_SVT_TEXTURE2DARRAY;
514 break;
515 case EOT_Texture2DMS:
516 pDesc->Type = D3D_SVT_TEXTURE2DMS;
517 break;
518 case EOT_Texture2DMSArray:
519 pDesc->Type = D3D_SVT_TEXTURE2DMSARRAY;
520 break;
521 case EOT_Texture3D:
522 pDesc->Type = D3D_SVT_TEXTURE3D;
523 break;
524 case EOT_TextureCube:
525 pDesc->Type = D3D_SVT_TEXTURECUBE;
526 break;
527 case EOT_TextureCubeArray:
528 pDesc->Type = D3D_SVT_TEXTURECUBEARRAY;
529 break;
530 case EOT_Buffer:
531 pDesc->Type = D3D_SVT_BUFFER;
532 break;
533 case EOT_Sampler:
534 pDesc->Type = D3D_SVT_SAMPLER;
535 break;
536 case EOT_RenderTargetView:
537 pDesc->Type = D3D_SVT_RENDERTARGETVIEW;
538 break;
539 case EOT_DepthStencilView:
540 pDesc->Type = D3D_SVT_DEPTHSTENCILVIEW;
541 break;
542 case EOT_RWTexture1D:
543 pDesc->Type = D3D_SVT_RWTEXTURE1D;
544 break;
545 case EOT_RWTexture1DArray:
546 pDesc->Type = D3D_SVT_RWTEXTURE1DARRAY;
547 break;
548 case EOT_RWTexture2D:
549 pDesc->Type = D3D_SVT_RWTEXTURE2D;
550 break;
551 case EOT_RWTexture2DArray:
552 pDesc->Type = D3D_SVT_RWTEXTURE2DARRAY;
553 break;
554 case EOT_RWTexture3D:
555 pDesc->Type = D3D_SVT_RWTEXTURE3D;
556 break;
557 case EOT_RWBuffer:
558 pDesc->Type = D3D_SVT_RWBUFFER;
559 break;
560 case EOT_ByteAddressBuffer:
561 pDesc->Type = D3D_SVT_BYTEADDRESS_BUFFER;
562 break;
563 case EOT_RWByteAddressBuffer:
564 pDesc->Type = D3D_SVT_RWBYTEADDRESS_BUFFER;
565 break;
566 case EOT_StructuredBuffer:
567 pDesc->Type = D3D_SVT_STRUCTURED_BUFFER;
568 break;
569 case EOT_RWStructuredBuffer:
570 case EOT_RWStructuredBufferAlloc:
571 case EOT_RWStructuredBufferConsume:
572 pDesc->Type = D3D_SVT_RWSTRUCTURED_BUFFER;
573 break;
574 case EOT_AppendStructuredBuffer:
575 pDesc->Type = D3D_SVT_APPEND_STRUCTURED_BUFFER;
576 break;
577 case EOT_ConsumeStructuredBuffer:
578 pDesc->Type = D3D_SVT_CONSUME_STRUCTURED_BUFFER;
579 break;
581 default:
582 assert(0);
584 break;
586 default:
587 assert(0);
590 lExit:
591 return hr;
595 ////////////////////////////////////////////////////////////////////////////////
596 // ID3DX11EffectShaderVariable (SAnonymousShader implementation)
597 ////////////////////////////////////////////////////////////////////////////////
599 SAnonymousShader::SAnonymousShader(_In_opt_ SShaderBlock *pBlock) noexcept :
600 pShaderBlock(pBlock)
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;
617 pDesc->Flags = 0;
619 pDesc->Name = "$Anonymous";
620 pDesc->Semantic = nullptr;
621 pDesc->BufferOffset = 0;
623 return S_OK;
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()
670 return NoParentCB();
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() \
697 HRESULT hr = S_OK; \
698 if (0 != ShaderIndex) \
700 DPF(0, "%s: Invalid index specified", pFuncName); \
701 VH(E_INVALIDARG); \
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);
712 lExit:
713 return hr;
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) );
725 lExit:
726 return hr;
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) );
738 lExit:
739 return hr;
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) );
751 lExit:
752 return hr;
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) );
764 lExit:
765 return hr;
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) );
777 lExit:
778 return hr;
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) );
790 lExit:
791 return hr;
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) );
803 lExit:
804 return hr;
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) );
816 lExit:
817 return hr;
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) );
829 lExit:
830 return hr;
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;
843 break;
844 case EOT_GeometryShader:
845 case EOT_GeometryShader5:
846 pDesc->TypeName = "geometryshader";
847 pDesc->Type = D3D_SVT_GEOMETRYSHADER;
848 break;
849 case EOT_PixelShader:
850 case EOT_PixelShader5:
851 pDesc->TypeName = "pixelshader";
852 pDesc->Type = D3D_SVT_PIXELSHADER;
853 break;
854 case EOT_HullShader5:
855 pDesc->TypeName = "Hullshader";
856 pDesc->Type = D3D_SVT_HULLSHADER;
857 break;
858 case EOT_DomainShader5:
859 pDesc->TypeName = "Domainshader";
860 pDesc->Type = D3D_SVT_DOMAINSHADER;
861 break;
862 case EOT_ComputeShader5:
863 pDesc->TypeName = "Computeshader";
864 pDesc->Type = D3D_SVT_COMPUTESHADER;
865 break;
868 pDesc->Elements = 0;
869 pDesc->Members = 0;
870 pDesc->Rows = 0;
871 pDesc->Columns = 0;
872 pDesc->PackedSize = 0;
873 pDesc->UnpackedSize = 0;
874 pDesc->Stride = 0;
876 return S_OK;
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");
904 return nullptr;
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");
911 return nullptr;
914 //////////////////////////////////////////////////////////////////////////
915 // ID3DX11EffectConstantBuffer (SConstantBuffer implementation)
916 //////////////////////////////////////////////////////////////////////////
918 bool SConstantBuffer::IsValid()
920 return true;
923 ID3DX11EffectType * SConstantBuffer::GetType()
925 return (ID3DX11EffectType *) this;
928 HRESULT SConstantBuffer::GetDesc(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc)
930 pDesc->Annotations = AnnotationCount;
931 pDesc->Flags = 0;
933 pDesc->Name = pName;
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;
942 else
944 pDesc->ExplicitBindPoint = 0;
947 return S_OK;
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;
984 uint32_t index;
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;
1005 uint32_t index;
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;
1050 pDesc->Rows = 0;
1051 pDesc->Columns = 0;
1053 uint32_t i;
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);
1065 return S_OK;
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);
1090 return nullptr;
1093 if (Index >= VariableCount)
1095 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, VariableCount);
1096 return nullptr;
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);
1109 return nullptr;
1112 if (Index >= VariableCount)
1114 DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, VariableCount);
1115 return nullptr;
1118 return pVariables[Index].pSemantic;
1121 _Use_decl_annotations_
1122 HRESULT SConstantBuffer::SetRawValue(const void *pData, uint32_t Offset, uint32_t Count)
1124 HRESULT hr = S_OK;
1126 #ifdef _DEBUG
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);
1137 VH(E_INVALIDARG);
1139 #endif
1141 if (IsUsedByExpression)
1143 uint32_t i;
1144 for (i = 0; i < VariableCount; ++ i)
1146 ((SGlobalVariable*)pVariables)[i].DirtyVariable();
1149 else
1151 IsDirty = true;
1154 memcpy(pBackingStore + Offset, pData, Count);
1156 lExit:
1157 return hr;
1160 _Use_decl_annotations_
1161 HRESULT SConstantBuffer::GetRawValue(void *pData, uint32_t Offset, uint32_t Count)
1163 HRESULT hr = S_OK;
1165 #ifdef _DEBUG
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);
1176 VH(E_INVALIDARG);
1178 #endif
1180 memcpy(pData, pBackingStore + Offset, Count);
1182 lExit:
1183 return hr;
1186 bool SConstantBuffer::ClonedSingle() const
1188 return IsSingle && ( pEffect->m_Flags & D3DX11_EFFECT_CLONE );
1191 HRESULT SConstantBuffer::SetConstantBuffer(_In_ ID3D11Buffer *pConstantBuffer)
1193 HRESULT hr = S_OK;
1194 static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::SetConstantBuffer";
1196 if (IsTBuffer)
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;
1220 lExit:
1221 return hr;
1224 HRESULT SConstantBuffer::GetConstantBuffer(_Outptr_ ID3D11Buffer **ppConstantBuffer)
1226 HRESULT hr = S_OK;
1227 static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::GetConstantBuffer";
1229 VERIFYPARAMETER(ppConstantBuffer);
1231 if (IsTBuffer)
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);
1242 lExit:
1243 return hr;
1246 HRESULT SConstantBuffer::UndoSetConstantBuffer()
1248 HRESULT hr = S_OK;
1249 static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::UndoSetConstantBuffer";
1251 if (IsTBuffer)
1253 DPF(0, "%s: This is a texture buffer; use UndoSetTextureBuffer instead", pFuncName);
1254 VH(D3DERR_INVALIDCALL);
1257 if( !IsUserManaged )
1259 return S_FALSE;
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();
1272 lExit:
1273 return hr;
1276 HRESULT SConstantBuffer::SetTextureBuffer(_In_ ID3D11ShaderResourceView *pTextureBuffer)
1278 HRESULT hr = S_OK;
1279 static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::SetTextureBuffer";
1281 if (!IsTBuffer)
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;
1307 lExit:
1308 return hr;
1311 HRESULT SConstantBuffer::GetTextureBuffer(_Outptr_ ID3D11ShaderResourceView **ppTextureBuffer)
1313 HRESULT hr = S_OK;
1314 static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::GetTextureBuffer";
1316 VERIFYPARAMETER(ppTextureBuffer);
1318 if (!IsTBuffer)
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);
1329 lExit:
1330 return hr;
1333 HRESULT SConstantBuffer::UndoSetTextureBuffer()
1335 HRESULT hr = S_OK;
1336 static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::UndoSetTextureBuffer";
1338 if (!IsTBuffer)
1340 DPF(0, "%s: This is a texture buffer; use UndoSetConstantBuffer instead", pFuncName);
1341 VH(D3DERR_INVALIDCALL);
1344 if( !IsUserManaged )
1346 return S_FALSE;
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();
1359 lExit:
1360 return hr;
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)
1376 HRESULT hr = S_OK;
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];
1413 lExit:
1414 return hr;
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)
1434 HRESULT hr = S_OK;
1435 uint32_t i;
1436 LPCSTR pFuncName = nullptr;
1437 SShaderBlock *pShaderBlock = nullptr;
1439 ApplyPassAssignments();
1441 #ifdef _PREFAST_
1442 #pragma prefast(push)
1443 #pragma prefast(disable:__WARNING_UNUSED_POINTER_ASSIGNMENT, "pFuncName used in DPF")
1444 #endif
1445 switch (EShaderType)
1447 case EOT_VertexShader:
1448 case EOT_VertexShader5:
1449 pFuncName = "ID3DX11EffectPass::GetVertexShaderDesc";
1450 pShaderBlock = BackingStore.pVertexShaderBlock;
1451 break;
1452 case EOT_PixelShader:
1453 case EOT_PixelShader5:
1454 pFuncName = "ID3DX11EffectPass::GetPixelShaderDesc";
1455 pShaderBlock = BackingStore.pPixelShaderBlock;
1456 break;
1457 case EOT_GeometryShader:
1458 case EOT_GeometryShader5:
1459 pFuncName = "ID3DX11EffectPass::GetGeometryShaderDesc";
1460 pShaderBlock = BackingStore.pGeometryShaderBlock;
1461 break;
1462 case EOT_HullShader5:
1463 pFuncName = "ID3DX11EffectPass::GetHullShaderDesc";
1464 pShaderBlock = BackingStore.pHullShaderBlock;
1465 break;
1466 case EOT_DomainShader5:
1467 pFuncName = "ID3DX11EffectPass::GetDomainShaderDesc";
1468 pShaderBlock = BackingStore.pDomainShaderBlock;
1469 break;
1470 case EOT_ComputeShader5:
1471 pFuncName = "ID3DX11EffectPass::GetComputeShaderDesc";
1472 pShaderBlock = BackingStore.pComputeShaderBlock;
1473 break;
1474 #ifdef _PREFAST_
1475 #pragma prefast(pop)
1476 #endif
1477 default:
1478 assert(0);
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;
1497 // we're done
1498 goto lExit;
1500 else if (pShaderBlock == &g_NullGS)
1502 pDesc->pShaderVariable = &g_AnonymousNullGS;
1503 pDesc->ShaderIndex = 0;
1504 // we're done
1505 goto lExit;
1507 else if (pShaderBlock == &g_NullPS)
1509 pDesc->pShaderVariable = &g_AnonymousNullPS;
1510 pDesc->ShaderIndex = 0;
1511 // we're done
1512 goto lExit;
1514 else if (pShaderBlock == &g_NullHS)
1516 pDesc->pShaderVariable = &g_AnonymousNullHS;
1517 pDesc->ShaderIndex = 0;
1518 // we're done
1519 goto lExit;
1521 else if (pShaderBlock == &g_NullDS)
1523 pDesc->pShaderVariable = &g_AnonymousNullDS;
1524 pDesc->ShaderIndex = 0;
1525 // we're done
1526 goto lExit;
1528 else if (pShaderBlock == &g_NullCS)
1530 pDesc->pShaderVariable = &g_AnonymousNullCS;
1531 pDesc->ShaderIndex = 0;
1532 // we're done
1533 goto lExit;
1535 else
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);
1554 // we're done
1555 goto lExit;
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;
1567 // we're done
1568 goto lExit;
1572 DPF(0, "%s: Internal error; shader not found", pFuncName);
1573 VH( E_FAIL );
1576 lExit:
1577 return hr;
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);
1624 HRESULT hr = S_OK;
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;
1634 return hr;
1637 HRESULT SPassBlock::ComputeStateBlockMask(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask)
1639 HRESULT hr = S_OK;
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:
1651 bVS = true;
1652 bShader = true;
1653 break;
1654 case ELHS_GeometryShaderBlock:
1655 bGS = true;
1656 bShader = true;
1657 break;
1658 case ELHS_PixelShaderBlock:
1659 bPS = true;
1660 bShader = true;
1661 break;
1662 case ELHS_HullShaderBlock:
1663 bHS = true;
1664 bShader = true;
1665 break;
1666 case ELHS_DomainShaderBlock:
1667 bDS = true;
1668 bShader = true;
1669 break;
1670 case ELHS_ComputeShaderBlock:
1671 bCS = true;
1672 bShader = true;
1673 break;
1675 case ELHS_RasterizerBlock:
1676 pStateBlockMask->RSRasterizerState = 1;
1677 break;
1678 case ELHS_BlendBlock:
1679 pStateBlockMask->OMBlendState = 1;
1680 break;
1681 case ELHS_DepthStencilBlock:
1682 pStateBlockMask->OMDepthStencilState = 1;
1683 break;
1685 default:
1686 // ignore this assignment (must be a scalar/vector assignment associated with a state object)
1687 break;
1690 if (bShader)
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) );
1740 lExit:
1741 return hr;
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() )
1755 return false;
1757 return true;
1759 return InitiallyValid;
1762 HRESULT STechnique::GetDesc(_Out_ D3DX11_TECHNIQUE_DESC *pDesc)
1764 HRESULT hr = S_OK;
1766 static LPCSTR pFuncName = "ID3DX11EffectTechnique::GetDesc";
1768 VERIFYPARAMETER(pDesc);
1770 pDesc->Name = pName;
1771 pDesc->Annotations = AnnotationCount;
1772 pDesc->Passes = PassCount;
1774 lExit:
1775 return hr;
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";
1805 uint32_t i;
1807 for (i = 0; i < PassCount; ++ i)
1809 if (nullptr != pPasses[i].pName &&
1810 strcmp(pPasses[i].pName, Name) == 0)
1812 break;
1816 if (i == PassCount)
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)
1827 HRESULT hr = S_OK;
1828 uint32_t i;
1830 _Analysis_assume_( PassCount == 0 || pPasses != 0 );
1831 for (i = 0; i < PassCount; ++ i)
1833 VH( ((SPassBlock*)pPasses)[i].ComputeStateBlockMask(pStateBlockMask) );
1836 lExit:
1837 return hr;
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() )
1851 return false;
1853 return true;
1855 return InitiallyValid;
1858 HRESULT SGroup::GetDesc(_Out_ D3DX11_GROUP_DESC *pDesc)
1860 HRESULT hr = S_OK;
1862 static LPCSTR pFuncName = "ID3DX11EffectGroup::GetDesc";
1864 VERIFYPARAMETER(pDesc);
1866 pDesc->Name = pName;
1867 pDesc->Annotations = AnnotationCount;
1868 pDesc->Techniques = TechniqueCount;
1870 lExit:
1871 return hr;
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";
1901 uint32_t i;
1903 for (i = 0; i < TechniqueCount; ++ i)
1905 if (nullptr != pTechniques[i].pName &&
1906 strcmp(pTechniques[i].pName, Name) == 0)
1908 break;
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)
1927 HRESULT hr = S_OK;
1928 static LPCSTR pFuncName = "ID3DX11Effect::GetDevice";
1929 VERIFYPARAMETER(ppDevice);
1931 m_pDevice->AddRef();
1932 *ppDevice = m_pDevice;
1934 lExit:
1935 return hr;
1938 HRESULT CEffect::GetDesc(_Out_ D3DX11_EFFECT_DESC *pDesc)
1940 HRESULT hr = S_OK;
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;
1952 lExit:
1953 return hr;
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";
1973 if (IsOptimized())
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)
1989 return m_pCBs + i;
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";
2014 if (IsOptimized())
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";
2042 if (IsOptimized())
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;
2054 uint32_t i;
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;
2083 assert( false );
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];
2095 if (IsOptimized())
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
2126 *pDelimiter = 0;
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";
2153 if (IsOptimized())
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;
2164 uint32_t i = 0;
2165 for (; i < m_GroupCount; ++ i)
2167 if (nullptr != m_pGroups[i].pName &&
2168 strcmp(m_pGroups[i].pName, Name) == 0)
2170 break;
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);