+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: Effect.h
-//
-// Direct3D 11 Effects Header for ID3DX11Effect Implementation
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-#include "EffectBinaryFormat.h"
-#include "IUnknownImp.h"
-
-#ifdef _DEBUG
-extern void __cdecl D3DXDebugPrintf(UINT lvl, _In_z_ _Printf_format_string_ LPCSTR szFormat, ...);
-#define DPF D3DXDebugPrintf
-#else
-#define DPF
-#endif
-
-#pragma warning(push)
-#pragma warning(disable : 4481)
-// VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012
-
-//////////////////////////////////////////////////////////////////////////
-
-using namespace D3DX11Core;
-
-namespace D3DX11Effects
-{
-
-//////////////////////////////////////////////////////////////////////////
-// Forward defines
-//////////////////////////////////////////////////////////////////////////
-
-struct SBaseBlock;
-struct SShaderBlock;
-struct SPassBlock;
-struct SClassInstance;
-struct SInterface;
-struct SShaderResource;
-struct SUnorderedAccessView;
-struct SRenderTargetView;
-struct SDepthStencilView;
-struct SSamplerBlock;
-struct SDepthStencilBlock;
-struct SBlendBlock;
-struct SRasterizerBlock;
-struct SString;
-struct SD3DShaderVTable;
-struct SClassInstanceGlobalVariable;
-
-struct SAssignment;
-struct SVariable;
-struct SGlobalVariable;
-struct SAnnotation;
-struct SConstantBuffer;
-
-class CEffect;
-class CEffectLoader;
-
-enum ELhsType : int;
-
-// Allows the use of 32-bit and 64-bit timers depending on platform type
-typedef size_t Timer;
-
-//////////////////////////////////////////////////////////////////////////
-// Reflection & Type structures
-//////////////////////////////////////////////////////////////////////////
-
-// CEffectMatrix is used internally instead of float arrays
-struct CEffectMatrix
-{
- union
- {
- struct
- {
- float _11, _12, _13, _14;
- float _21, _22, _23, _24;
- float _31, _32, _33, _34;
- float _41, _42, _43, _44;
-
- };
- float m[4][4];
- };
-};
-
-struct CEffectVector4
-{
- float x;
- float y;
- float z;
- float w;
-};
-
-union UDataPointer
-{
- void *pGeneric;
- uint8_t *pNumeric;
- float *pNumericFloat;
- uint32_t *pNumericDword;
- int *pNumericInt;
- BOOL *pNumericBool;
- SString *pString;
- SShaderBlock *pShader;
- SBaseBlock *pBlock;
- SBlendBlock *pBlend;
- SDepthStencilBlock *pDepthStencil;
- SRasterizerBlock *pRasterizer;
- SInterface *pInterface;
- SShaderResource *pShaderResource;
- SUnorderedAccessView *pUnorderedAccessView;
- SRenderTargetView *pRenderTargetView;
- SDepthStencilView *pDepthStencilView;
- SSamplerBlock *pSampler;
- CEffectVector4 *pVector;
- CEffectMatrix *pMatrix;
- UINT_PTR Offset;
-};
-
-enum EMemberDataType
-{
- MDT_ClassInstance,
- MDT_BlendState,
- MDT_DepthStencilState,
- MDT_RasterizerState,
- MDT_SamplerState,
- MDT_Buffer,
- MDT_ShaderResourceView,
-};
-
-struct SMemberDataPointer
-{
- EMemberDataType Type;
- union
- {
- IUnknown *pGeneric;
- ID3D11ClassInstance *pD3DClassInstance;
- ID3D11BlendState *pD3DEffectsManagedBlendState;
- ID3D11DepthStencilState *pD3DEffectsManagedDepthStencilState;
- ID3D11RasterizerState *pD3DEffectsManagedRasterizerState;
- ID3D11SamplerState *pD3DEffectsManagedSamplerState;
- ID3D11Buffer *pD3DEffectsManagedConstantBuffer;
- ID3D11ShaderResourceView*pD3DEffectsManagedTextureBuffer;
- } Data;
-};
-
-struct SType : public ID3DX11EffectType
-{
- static const UINT_PTR c_InvalidIndex = (uint32_t) -1;
- static const uint32_t c_ScalarSize = sizeof(uint32_t);
-
- // packing rule constants
- static const uint32_t c_ScalarsPerRegister = 4;
- static const uint32_t c_RegisterSize = c_ScalarsPerRegister * c_ScalarSize; // must be a power of 2!!
-
- EVarType VarType; // numeric, object, struct
- uint32_t Elements; // # of array elements (0 for non-arrays)
- char *pTypeName; // friendly name of the type: "VS_OUTPUT", "float4", etc.
-
- // *Size and stride values are always 0 for object types
- // *Annotations adhere to packing rules (even though they do not reside in constant buffers)
- // for consistency's sake
- //
- // Packing rules:
- // *Structures and array elements are always register aligned
- // *Single-row values (or, for column major matrices, single-column) are greedily
- // packed unless doing so would span a register boundary, in which case they are
- // register aligned
-
- uint32_t TotalSize; // Total size of this data type in a constant buffer from
- // start to finish (padding in between elements is included,
- // but padding at the end is not since that would require
- // knowledge of the following data type).
-
- uint32_t Stride; // Number of bytes to advance between elements.
- // Typically a multiple of 16 for arrays, vectors, matrices.
- // For scalars and small vectors/matrices, this can be 4 or 8.
-
- uint32_t PackedSize; // Size, in bytes, of this data typed when fully packed
-
- union
- {
- SBinaryNumericType NumericType;
- EObjectType ObjectType; // not all values of EObjectType are valid here (e.g. constant buffer)
- struct
- {
- SVariable *pMembers; // array of type instances describing structure members
- uint32_t Members;
- BOOL ImplementsInterface; // true if this type implements an interface
- BOOL HasSuperClass; // true if this type has a parent class
- } StructType;
- void* InterfaceType; // nothing for interfaces
- };
-
-
- SType() noexcept :
- VarType(EVT_Invalid),
- Elements(0),
- pTypeName(nullptr),
- TotalSize(0),
- Stride(0),
- PackedSize(0),
- StructType{}
- {
- static_assert(sizeof(NumericType) <= sizeof(StructType), "SType union issue");
- static_assert(sizeof(ObjectType) <= sizeof(StructType), "SType union issue");
- static_assert(sizeof(InterfaceType) <= sizeof(StructType), "SType union issue");
- }
-
- bool IsEqual(SType *pOtherType) const;
-
- bool IsObjectType(EObjectType ObjType) const
- {
- return IsObjectTypeHelper(VarType, ObjectType, ObjType);
- }
- bool IsShader() const
- {
- return IsShaderHelper(VarType, ObjectType);
- }
- bool BelongsInConstantBuffer() const
- {
- return (VarType == EVT_Numeric) || (VarType == EVT_Struct);
- }
- bool IsStateBlockObject() const
- {
- return IsStateBlockObjectHelper(VarType, ObjectType);
- }
- bool IsClassInstance() const
- {
- return (VarType == EVT_Struct) && StructType.ImplementsInterface;
- }
- bool IsInterface() const
- {
- return IsInterfaceHelper(VarType, ObjectType);
- }
- bool IsShaderResource() const
- {
- return IsShaderResourceHelper(VarType, ObjectType);
- }
- bool IsUnorderedAccessView() const
- {
- return IsUnorderedAccessViewHelper(VarType, ObjectType);
- }
- bool IsSampler() const
- {
- return IsSamplerHelper(VarType, ObjectType);
- }
- bool IsRenderTargetView() const
- {
- return IsRenderTargetViewHelper(VarType, ObjectType);
- }
- bool IsDepthStencilView() const
- {
- return IsDepthStencilViewHelper(VarType, ObjectType);
- }
-
- uint32_t GetTotalUnpackedSize(_In_ bool IsSingleElement) const;
- uint32_t GetTotalPackedSize(_In_ bool IsSingleElement) const;
- HRESULT GetDescHelper(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc, _In_ bool IsSingleElement) const;
-
- STDMETHOD_(bool, IsValid)() override { return true; }
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override { return GetDescHelper(pDesc, false); }
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(_In_z_ LPCSTR Name) override;
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(_In_z_ LPCSTR Semantic) override;
- STDMETHOD_(LPCSTR, GetMemberName)(_In_ uint32_t Index) override;
- STDMETHOD_(LPCSTR, GetMemberSemantic)(_In_ uint32_t Index) override;
-
- IUNKNOWN_IMP(SType, ID3DX11EffectType, IUnknown);
-};
-
-// Represents a type structure for a single element.
-// It seems pretty trivial, but it has a different virtual table which enables
-// us to accurately represent a type that consists of a single element
-struct SSingleElementType : public ID3DX11EffectType
-{
- SType *pType;
-
- STDMETHOD_(bool, IsValid)() override { return true; }
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override { return ((SType*)pType)->GetDescHelper(pDesc, true); }
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(uint32_t Index) override { return ((SType*)pType)->GetMemberTypeByIndex(Index); }
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(LPCSTR Name) override { return ((SType*)pType)->GetMemberTypeByName(Name); }
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(LPCSTR Semantic) override { return ((SType*)pType)->GetMemberTypeBySemantic(Semantic); }
- STDMETHOD_(LPCSTR, GetMemberName)(uint32_t Index) override { return ((SType*)pType)->GetMemberName(Index); }
- STDMETHOD_(LPCSTR, GetMemberSemantic)(uint32_t Index) override { return ((SType*)pType)->GetMemberSemantic(Index); }
-
- IUNKNOWN_IMP(SSingleElementType, ID3DX11EffectType, IUnknown);
-
- SSingleElementType() noexcept :
- pType(nullptr)
- {
- }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Block definitions
-//////////////////////////////////////////////////////////////////////////
-
-void * GetBlockByIndex(EVarType VarType, EObjectType ObjectType, void *pBaseBlock, uint32_t Index);
-
-struct SBaseBlock
-{
- EBlockType BlockType;
-
- bool IsUserManaged:1;
-
- uint32_t AssignmentCount;
- SAssignment *pAssignments;
-
- SBaseBlock() noexcept;
-
- bool ApplyAssignments(CEffect *pEffect);
-
- inline SSamplerBlock *AsSampler() const
- {
- assert( BlockType == EBT_Sampler );
- return (SSamplerBlock*) this;
- }
-
- inline SDepthStencilBlock *AsDepthStencil() const
- {
- assert( BlockType == EBT_DepthStencil );
- return (SDepthStencilBlock*) this;
- }
-
- inline SBlendBlock *AsBlend() const
- {
- assert( BlockType == EBT_Blend );
- return (SBlendBlock*) this;
- }
-
- inline SRasterizerBlock *AsRasterizer() const
- {
- assert( BlockType == EBT_Rasterizer );
- return (SRasterizerBlock*) this;
- }
-
- inline SPassBlock *AsPass() const
- {
- assert( BlockType == EBT_Pass );
- return (SPassBlock*) this;
- }
-};
-
-struct STechnique : public ID3DX11EffectTechnique
-{
- char *pName;
-
- uint32_t PassCount;
- SPassBlock *pPasses;
-
- uint32_t AnnotationCount;
- SAnnotation *pAnnotations;
-
- bool InitiallyValid;
- bool HasDependencies;
-
- STechnique() noexcept;
-
- STDMETHOD_(bool, IsValid)() override;
- STDMETHOD(GetDesc)(_Out_ D3DX11_TECHNIQUE_DESC *pDesc) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD_(ID3DX11EffectPass*, GetPassByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectPass*, GetPassByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD(ComputeStateBlockMask)(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask) override;
-
- IUNKNOWN_IMP(STechnique, ID3DX11EffectTechnique, IUnknown);
-};
-
-struct SGroup : public ID3DX11EffectGroup
-{
- char *pName;
-
- uint32_t TechniqueCount;
- STechnique *pTechniques;
-
- uint32_t AnnotationCount;
- SAnnotation *pAnnotations;
-
- bool InitiallyValid;
- bool HasDependencies;
-
- SGroup() noexcept;
-
- STDMETHOD_(bool, IsValid)() override;
- STDMETHOD(GetDesc)(_Out_ D3DX11_GROUP_DESC *pDesc) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByName)(_In_z_ LPCSTR Name) override;
-
- IUNKNOWN_IMP(SGroup, ID3DX11EffectGroup, IUnknown);
-};
-
-struct SPassBlock : SBaseBlock, public ID3DX11EffectPass
-{
- struct
- {
- ID3D11BlendState* pBlendState;
- FLOAT BlendFactor[4];
- uint32_t SampleMask;
- ID3D11DepthStencilState *pDepthStencilState;
- uint32_t StencilRef;
- union
- {
- D3D11_SO_DECLARATION_ENTRY *pEntry;
- char *pEntryDesc;
- } GSSODesc;
-
- // Pass assignments can write directly into these
- SBlendBlock *pBlendBlock;
- SDepthStencilBlock *pDepthStencilBlock;
- SRasterizerBlock *pRasterizerBlock;
- uint32_t RenderTargetViewCount;
- SRenderTargetView *pRenderTargetViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
- SDepthStencilView *pDepthStencilView;
- SShaderBlock *pVertexShaderBlock;
- SShaderBlock *pPixelShaderBlock;
- SShaderBlock *pGeometryShaderBlock;
- SShaderBlock *pComputeShaderBlock;
- SShaderBlock *pDomainShaderBlock;
- SShaderBlock *pHullShaderBlock;
- } BackingStore;
-
- char *pName;
-
- uint32_t AnnotationCount;
- SAnnotation *pAnnotations;
-
- CEffect *pEffect;
-
- bool InitiallyValid; // validity of all state objects and shaders in pass upon BindToDevice
- bool HasDependencies; // if pass expressions or pass state blocks have dependencies on variables (if true, IsValid != InitiallyValid possibly)
-
- SPassBlock() noexcept;
-
- void ApplyPassAssignments();
- bool CheckShaderDependencies( _In_ const SShaderBlock* pBlock );
- bool CheckDependencies();
-
- template<EObjectType EShaderType>
- HRESULT GetShaderDescHelper(_Out_ D3DX11_PASS_SHADER_DESC *pDesc);
-
- STDMETHOD_(bool, IsValid)() override;
- STDMETHOD(GetDesc)(_Out_ D3DX11_PASS_DESC *pDesc) override;
-
- STDMETHOD(GetVertexShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
- STDMETHOD(GetGeometryShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
- STDMETHOD(GetPixelShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
- STDMETHOD(GetHullShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
- STDMETHOD(GetDomainShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
- STDMETHOD(GetComputeShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD(Apply)(_In_ uint32_t Flags, _In_ ID3D11DeviceContext* pContext) override;
-
- STDMETHOD(ComputeStateBlockMask)(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask) override;
-
- IUNKNOWN_IMP(SPassBlock, ID3DX11EffectPass, IUnknown);
-};
-
-struct SDepthStencilBlock : SBaseBlock
-{
- ID3D11DepthStencilState *pDSObject;
- D3D11_DEPTH_STENCIL_DESC BackingStore;
- bool IsValid;
-
- SDepthStencilBlock() noexcept;
-};
-
-struct SBlendBlock : SBaseBlock
-{
- ID3D11BlendState *pBlendObject;
- D3D11_BLEND_DESC BackingStore;
- bool IsValid;
-
- SBlendBlock() noexcept;
-};
-
-struct SRasterizerBlock : SBaseBlock
-{
- ID3D11RasterizerState *pRasterizerObject;
- D3D11_RASTERIZER_DESC BackingStore;
- bool IsValid;
-
- SRasterizerBlock() noexcept;
-};
-
-struct SSamplerBlock : SBaseBlock
-{
- ID3D11SamplerState *pD3DObject;
- struct
- {
- D3D11_SAMPLER_DESC SamplerDesc;
- // Sampler "TEXTURE" assignments can write directly into this
- SShaderResource *pTexture;
- } BackingStore;
-
- SSamplerBlock() noexcept;
-};
-
-struct SInterface
-{
- SClassInstanceGlobalVariable* pClassInstance;
-
- SInterface() noexcept :
- pClassInstance(nullptr)
- {
- }
-};
-
-struct SShaderResource
-{
- ID3D11ShaderResourceView *pShaderResource;
-
- SShaderResource() noexcept :
- pShaderResource(nullptr)
- {
- }
-};
-
-struct SUnorderedAccessView
-{
- ID3D11UnorderedAccessView *pUnorderedAccessView;
-
- SUnorderedAccessView() noexcept :
- pUnorderedAccessView(nullptr)
- {
- }
-};
-
-struct SRenderTargetView
-{
- ID3D11RenderTargetView *pRenderTargetView;
-
- SRenderTargetView() noexcept :
- pRenderTargetView(nullptr)
- {
- }
-};
-
-struct SDepthStencilView
-{
- ID3D11DepthStencilView *pDepthStencilView;
-
- SDepthStencilView() noexcept :
- pDepthStencilView(nullptr)
- {
- }
-};
-
-
-template<class T, class D3DTYPE> struct SShaderDependency
-{
- uint32_t StartIndex;
- uint32_t Count;
-
- T *ppFXPointers; // Array of ptrs to FX objects (CBs, SShaderResources, etc)
- D3DTYPE *ppD3DObjects; // Array of ptrs to matching D3D objects
-
- SShaderDependency() noexcept :
- StartIndex(0),
- Count(0),
- ppFXPointers(nullptr),
- ppD3DObjects(nullptr)
- {
- }
-};
-
-typedef SShaderDependency<SConstantBuffer*, ID3D11Buffer*> SShaderCBDependency;
-typedef SShaderDependency<SSamplerBlock*, ID3D11SamplerState*> SShaderSamplerDependency;
-typedef SShaderDependency<SShaderResource*, ID3D11ShaderResourceView*> SShaderResourceDependency;
-typedef SShaderDependency<SUnorderedAccessView*, ID3D11UnorderedAccessView*> SUnorderedAccessViewDependency;
-typedef SShaderDependency<SInterface*, ID3D11ClassInstance*> SInterfaceDependency;
-
-// Shader VTables are used to eliminate branching in ApplyShaderBlock.
-// The effect owns one D3DShaderVTables for each shader stage
-struct SD3DShaderVTable
-{
- void ( __stdcall ID3D11DeviceContext::*pSetShader)(ID3D11DeviceChild* pShader, ID3D11ClassInstance*const* ppClassInstances, uint32_t NumClassInstances);
- void ( __stdcall ID3D11DeviceContext::*pSetConstantBuffers)(uint32_t StartConstantSlot, uint32_t NumBuffers, ID3D11Buffer *const *pBuffers);
- void ( __stdcall ID3D11DeviceContext::*pSetSamplers)(uint32_t Offset, uint32_t NumSamplers, ID3D11SamplerState*const* pSamplers);
- void ( __stdcall ID3D11DeviceContext::*pSetShaderResources)(uint32_t Offset, uint32_t NumResources, ID3D11ShaderResourceView *const *pResources);
- HRESULT ( __stdcall ID3D11Device::*pCreateShader)(const void *pShaderBlob, size_t ShaderBlobSize, ID3D11ClassLinkage* pClassLinkage, ID3D11DeviceChild **ppShader);
-};
-
-
-struct SShaderBlock
-{
- enum ESigType
- {
- ST_Input,
- ST_Output,
- ST_PatchConstant,
- };
-
- struct SInterfaceParameter
- {
- char *pName;
- uint32_t Index;
- };
-
- // this data is classified as reflection-only and will all be discarded at runtime
- struct SReflectionData
- {
- uint8_t *pBytecode;
- uint32_t BytecodeLength;
- char *pStreamOutDecls[4]; // set with ConstructGSWithSO
- uint32_t RasterizedStream; // set with ConstructGSWithSO
- BOOL IsNullGS;
- ID3D11ShaderReflection *pReflection;
- uint32_t InterfaceParameterCount; // set with BindInterfaces (used for function interface parameters)
- SInterfaceParameter *pInterfaceParameters; // set with BindInterfaces (used for function interface parameters)
- };
-
- bool IsValid;
- SD3DShaderVTable *pVT;
-
- // This value is nullptr if the shader is nullptr or was never initialized
- SReflectionData *pReflectionData;
-
- ID3D11DeviceChild *pD3DObject;
-
- uint32_t CBDepCount;
- SShaderCBDependency *pCBDeps;
-
- uint32_t SampDepCount;
- SShaderSamplerDependency *pSampDeps;
-
- uint32_t InterfaceDepCount;
- SInterfaceDependency *pInterfaceDeps;
-
- uint32_t ResourceDepCount;
- SShaderResourceDependency *pResourceDeps;
-
- uint32_t UAVDepCount;
- SUnorderedAccessViewDependency *pUAVDeps;
-
- uint32_t TBufferDepCount;
- SConstantBuffer **ppTbufDeps;
-
- ID3DBlob *pInputSignatureBlob; // The input signature is separated from the bytecode because it
- // is always available, even after Optimize() has been called.
-
- SShaderBlock(SD3DShaderVTable *pVirtualTable = nullptr) noexcept;
-
- EObjectType GetShaderType();
-
- HRESULT OnDeviceBind();
-
- // Public API helpers
- HRESULT ComputeStateBlockMask(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask);
-
- HRESULT GetShaderDesc(_Out_ D3DX11_EFFECT_SHADER_DESC *pDesc, _In_ bool IsInline);
-
- HRESULT GetVertexShader(_Outptr_ ID3D11VertexShader **ppVS);
- HRESULT GetGeometryShader(_Outptr_ ID3D11GeometryShader **ppGS);
- HRESULT GetPixelShader(_Outptr_ ID3D11PixelShader **ppPS);
- HRESULT GetHullShader(_Outptr_ ID3D11HullShader **ppHS);
- HRESULT GetDomainShader(_Outptr_ ID3D11DomainShader **ppDS);
- HRESULT GetComputeShader(_Outptr_ ID3D11ComputeShader **ppCS);
-
- HRESULT GetSignatureElementDesc(_In_ ESigType SigType, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc);
-};
-
-
-
-struct SString
-{
- char *pString;
-
- SString() noexcept :
- pString(nullptr)
- {
- }
-};
-
-
-
-//////////////////////////////////////////////////////////////////////////
-// Global Variable & Annotation structure/interface definitions
-//////////////////////////////////////////////////////////////////////////
-
-//
-// This is a general structure that can describe
-// annotations, variables, and structure members
-//
-struct SVariable
-{
- // For annotations/variables/variable members:
- // 1) If numeric, pointer to data (for variables: points into backing store,
- // for annotations, points into reflection heap)
- // OR
- // 2) If object, pointer to the block. If object array, subsequent array elements are found in
- // contiguous blocks; the Nth block is found by ((<SpecificBlockType> *) pBlock) + N
- // (this is because variables that are arrays of objects have their blocks allocated contiguously)
- //
- // For structure members:
- // Offset of this member (in bytes) from parent structure (structure members must be numeric/struct)
- UDataPointer Data;
- union
- {
- uint32_t MemberDataOffsetPlus4; // 4 added so that 0 == nullptr can represent "unused"
- SMemberDataPointer *pMemberData;
- };
-
- SType *pType;
- char *pName;
- char *pSemantic;
- uint32_t ExplicitBindPoint;
-
- SVariable() noexcept
- {
- ZeroMemory(this, sizeof(*this));
- ExplicitBindPoint = uint32_t(-1);
- }
-};
-
-// Template definitions for all of the various ID3DX11EffectVariable specializations
-#include "EffectVariable.inl"
-
-
-////////////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectShaderVariable (SAnonymousShader implementation)
-////////////////////////////////////////////////////////////////////////////////
-
-struct SAnonymousShader : public TUncastableVariable<ID3DX11EffectShaderVariable>, public ID3DX11EffectType
-{
- SShaderBlock *pShaderBlock;
-
- SAnonymousShader(_In_opt_ SShaderBlock *pBlock = nullptr) noexcept;
-
- // ID3DX11EffectShaderVariable interface
- STDMETHOD_(bool, IsValid)() override;
- STDMETHOD_(ID3DX11EffectType*, GetType)() override;
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberByName)(_In_z_ LPCSTR Name) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberBySemantic)(_In_z_ LPCSTR Semantic) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetElement)(_In_ uint32_t Index) override;
-
- STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override;
-
- // other casts are handled by TUncastableVariable
- STDMETHOD_(ID3DX11EffectShaderVariable*, AsShader)() override;
-
- STDMETHOD(SetRawValue)(_In_reads_bytes_(Count) const void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetRawValue)(_Out_writes_bytes_(Count) void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(GetShaderDesc)(_In_ uint32_t ShaderIndex, _Out_ D3DX11_EFFECT_SHADER_DESC *pDesc) override;
-
- STDMETHOD(GetVertexShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11VertexShader **ppVS) override;
- STDMETHOD(GetGeometryShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11GeometryShader **ppGS) override;
- STDMETHOD(GetPixelShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11PixelShader **ppPS) override;
- STDMETHOD(GetHullShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11HullShader **ppHS) override;
- STDMETHOD(GetDomainShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11DomainShader **ppDS) override;
- STDMETHOD(GetComputeShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11ComputeShader **ppCS) override;
-
- STDMETHOD(GetInputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
- STDMETHOD(GetOutputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
- STDMETHOD(GetPatchConstantSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
-
- // ID3DX11EffectType interface
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override;
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(_In_z_ LPCSTR Name) override;
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(_In_z_ LPCSTR Semantic) override;
-
- STDMETHOD_(LPCSTR, GetMemberName)(_In_ uint32_t Index) override;
- STDMETHOD_(LPCSTR, GetMemberSemantic)(_In_ uint32_t Index) override;
-
- IUNKNOWN_IMP(SAnonymousShader, ID3DX11EffectShaderVariable, ID3DX11EffectVariable);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectConstantBuffer (SConstantBuffer implementation)
-////////////////////////////////////////////////////////////////////////////////
-
-struct SConstantBuffer : public TUncastableVariable<ID3DX11EffectConstantBuffer>, public ID3DX11EffectType
-{
- ID3D11Buffer *pD3DObject;
- SShaderResource TBuffer; // nullptr iff IsTbuffer == false
-
- uint8_t *pBackingStore;
- uint32_t Size; // in bytes
-
- char *pName;
-
- uint32_t AnnotationCount;
- SAnnotation *pAnnotations;
-
- uint32_t VariableCount; // # of variables contained in this cbuffer
- SGlobalVariable *pVariables; // array of size [VariableCount], points into effect's contiguous variable list
- uint32_t ExplicitBindPoint; // Used when a CB has been explicitly bound (register(bXX)). -1 if not
-
- bool IsDirty:1; // Set when any member is updated; cleared on CB apply
- bool IsTBuffer:1; // true iff TBuffer.pShaderResource != nullptr
- bool IsUserManaged:1; // Set if you don't want effects to update this buffer
- bool IsEffectOptimized:1;// Set if the effect has been optimized
- bool IsUsedByExpression:1;// Set if used by any expressions
- bool IsUserPacked:1; // Set if the elements have user-specified offsets
- bool IsSingle:1; // Set to true if you want to share this CB with cloned Effects
- bool IsNonUpdatable:1; // Set to true if you want to share this CB with cloned Effects
-
- union
- {
- // These are used to store the original ID3D11Buffer* for use in UndoSetConstantBuffer
- uint32_t MemberDataOffsetPlus4; // 4 added so that 0 == nullptr can represent "unused"
- SMemberDataPointer *pMemberData;
- };
-
- CEffect *pEffect;
-
- SConstantBuffer() noexcept :
- pD3DObject(nullptr),
- TBuffer{},
- pBackingStore(nullptr),
- Size(0),
- pName(nullptr),
- AnnotationCount(0),
- pAnnotations(nullptr),
- VariableCount(0),
- pVariables(nullptr),
- ExplicitBindPoint(uint32_t(-1)),
- IsDirty(false),
- IsTBuffer(false),
- IsUserManaged(false),
- IsEffectOptimized(false),
- IsUsedByExpression(false),
- IsUserPacked(false),
- IsSingle(false),
- IsNonUpdatable(false),
- pMemberData(nullptr),
- pEffect(nullptr)
- {
- }
-
- bool ClonedSingle() const;
-
- // ID3DX11EffectConstantBuffer interface
- STDMETHOD_(bool, IsValid)() override;
- STDMETHOD_(ID3DX11EffectType*, GetType)() override;
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberByName)(_In_z_ LPCSTR Name) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberBySemantic)(_In_z_ LPCSTR Semantic) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetElement)(_In_ uint32_t Index) override;
-
- STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override;
-
- // other casts are handled by TUncastableVariable
- STDMETHOD_(ID3DX11EffectConstantBuffer*, AsConstantBuffer)() override;
-
- STDMETHOD(SetRawValue)(_In_reads_bytes_(Count) const void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetRawValue)(_Out_writes_bytes_(Count) void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(SetConstantBuffer)(_In_ ID3D11Buffer *pConstantBuffer) override;
- STDMETHOD(GetConstantBuffer)(_Outptr_ ID3D11Buffer **ppConstantBuffer) override;
- STDMETHOD(UndoSetConstantBuffer)() override;
-
- STDMETHOD(SetTextureBuffer)(_In_ ID3D11ShaderResourceView *pTextureBuffer) override;
- STDMETHOD(GetTextureBuffer)(_Outptr_ ID3D11ShaderResourceView **ppTextureBuffer) override;
- STDMETHOD(UndoSetTextureBuffer)() override;
-
- // ID3DX11EffectType interface
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override;
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(_In_z_ LPCSTR Name) override;
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(_In_z_ LPCSTR Semantic) override;
-
- STDMETHOD_(LPCSTR, GetMemberName)(_In_ uint32_t Index) override;
- STDMETHOD_(LPCSTR, GetMemberSemantic)(_In_ uint32_t Index) override;
-
- IUNKNOWN_IMP(SConstantBuffer, ID3DX11EffectConstantBuffer, ID3DX11EffectVariable);
-};
-
-
-//////////////////////////////////////////////////////////////////////////
-// Assignments
-//////////////////////////////////////////////////////////////////////////
-
-enum ERuntimeAssignmentType
-{
- ERAT_Invalid,
- // [Destination] refers to the destination location, which is always the backing store of the pass/state block.
- // [Source] refers to the current source of data, always coming from either a constant buffer's
- // backing store (for numeric assignments), an object variable's block array, or an anonymous (unowned) block
-
- // Numeric variables:
- ERAT_Constant, // Source is unused.
- // No dependencies; this assignment can be safely removed after load.
- ERAT_NumericVariable, // Source points to the CB's backing store where the value lives.
- // 1 dependency: the variable itself.
- ERAT_NumericConstIndex, // Source points to the CB's backing store where the value lives, offset by N.
- // 1 dependency: the variable array being indexed.
- ERAT_NumericVariableIndex, // Source points to the last used element of the variable in the CB's backing store.
- // 2 dependencies: the index variable followed by the array variable.
-
- // Object variables:
- ERAT_ObjectInlineShader, // An anonymous, immutable shader block pointer is copied to the destination immediately.
- // No dependencies; this assignment can be safely removed after load.
- ERAT_ObjectVariable, // A pointer to the block owned by the object variable is copied to the destination immediately.
- // No dependencies; this assignment can be safely removed after load.
- ERAT_ObjectConstIndex, // A pointer to the Nth block owned by an object variable is copied to the destination immediately.
- // No dependencies; this assignment can be safely removed after load.
- ERAT_ObjectVariableIndex, // Source points to the first block owned by an object variable array
- // (the offset from this, N, is taken from another variable).
- // 1 dependency: the variable being used to index the array.
-};
-
-struct SAssignment
-{
- struct SDependency
- {
- SGlobalVariable *pVariable;
-
- SDependency() noexcept :
- pVariable(nullptr)
- {
- }
- };
-
- ELhsType LhsType; // PS, VS, DepthStencil etc.
-
- // The value of SAssignment.AssignmentType determines how the other fields behave
- // (DependencyCount, pDependencies, Destination, and Source)
- ERuntimeAssignmentType AssignmentType;
-
- Timer LastRecomputedTime;
-
- // see comments in ERuntimeAssignmentType for how dependencies and data pointers are handled
- uint32_t DependencyCount;
- SDependency *pDependencies;
-
- UDataPointer Destination; // This value never changes after load, and always refers to the backing store
- UDataPointer Source; // This value, on the other hand, can change if variable- or expression- driven
-
- uint32_t DataSize : 16; // Size of the data element to be copied in bytes (if numeric) or
- // stride of the block type (if object)
- uint32_t MaxElements : 16; // Max allowable index (needed because we don't store object arrays as dependencies,
- // and therefore have no way of getting their Element count)
-
- bool IsObjectAssignment() // True for Shader and RObject assignments (the type that appear in pass blocks)
- {
- return IsObjectAssignmentHelper(LhsType);
- }
-
- SAssignment() noexcept :
- LhsType(ELHS_Invalid),
- AssignmentType(ERAT_Invalid),
- LastRecomputedTime(0),
- DependencyCount(0),
- pDependencies(nullptr),
- Destination{0},
- Source{0},
- DataSize(0),
- MaxElements(0)
- {
- }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Private effect heaps
-//////////////////////////////////////////////////////////////////////////
-
-// Used to efficiently reallocate data
-// 1) For every piece of data that needs reallocation, move it to its new location
-// and add an entry into the table
-// 2) For everyone that references one of these data blocks, do a quick table lookup
-// to find the old pointer and then replace it with the new one
-struct SPointerMapping
-{
- void *pOld;
- void *pNew;
-
- static bool AreMappingsEqual(const SPointerMapping &pMap1, const SPointerMapping &pMap2)
- {
- return (pMap1.pOld == pMap2.pOld);
- }
-
- uint32_t Hash()
- {
- // hash the pointer itself
- // (using the pointer as a hash would be very bad)
- return ComputeHash((uint8_t*)&pOld, sizeof(pOld));
- }
-};
-
-typedef CEffectHashTableWithPrivateHeap<SPointerMapping, SPointerMapping::AreMappingsEqual> CPointerMappingTable;
-
-// Assist adding data to a block of memory
-class CEffectHeap
-{
-protected:
- uint8_t *m_pData;
- uint32_t m_dwBufferSize;
- uint32_t m_dwSize;
-
- template <bool bCopyData>
- HRESULT AddDataInternal(_In_reads_bytes_(dwSize) const void *pData, _In_ uint32_t dwSize, _Outptr_ void **ppPointer);
-
-public:
- HRESULT ReserveMemory(uint32_t dwSize);
- uint32_t GetSize();
- uint8_t* GetDataStart() { return m_pData; }
-
- // AddData and AddString append existing data to the buffer - they change m_dwSize. Users are
- // not expected to modify the data pointed to by the return pointer
- HRESULT AddString(_In_z_ const char *pString, _Outptr_result_z_ char **ppPointer);
- HRESULT AddData(_In_reads_(dwSize) const void *pData, _In_ uint32_t dwSize, _Outptr_ void **ppPointer);
-
- // Allocate behaves like a standard new - it will allocate memory, move m_dwSize. The caller is
- // expected to use the returned pointer
- void* Allocate(uint32_t dwSize);
-
- // Move data from the general heap and optional free memory
- HRESULT MoveData(_Inout_updates_bytes_(size) void **ppData, _In_ uint32_t size);
- HRESULT MoveString(_Inout_updates_z_(1) char **ppStringData);
- HRESULT MoveInterfaceParameters(_In_ uint32_t InterfaceCount, _Inout_updates_(1) SShaderBlock::SInterfaceParameter **ppInterfaces);
- HRESULT MoveEmptyDataBlock(_Inout_updates_(1) void **ppData, _In_ uint32_t size);
-
- bool IsInHeap(_In_ void *pData) const
- {
- return (pData >= m_pData && pData < (m_pData + m_dwBufferSize));
- }
-
- CEffectHeap() noexcept;
- ~CEffectHeap();
-};
-
-class CEffectReflection
-{
-public:
- // Single memory block support
- CEffectHeap m_Heap;
-};
-
-
-class CEffect : public ID3DX11Effect
-{
- friend struct SBaseBlock;
- friend struct SPassBlock;
- friend class CEffectLoader;
- friend struct SConstantBuffer;
- friend struct TSamplerVariable<TGlobalVariable<ID3DX11EffectSamplerVariable>>;
- friend struct TSamplerVariable<TVariable<TMember<ID3DX11EffectSamplerVariable>>>;
-
-protected:
-
- uint32_t m_RefCount;
- uint32_t m_Flags;
-
- // Private heap - all pointers should point into here
- CEffectHeap m_Heap;
-
- // Reflection object
- CEffectReflection *m_pReflection;
-
- // global variables in the effect (aka parameters)
- uint32_t m_VariableCount;
- SGlobalVariable *m_pVariables;
-
- // anonymous shader variables (one for every inline shader assignment)
- uint32_t m_AnonymousShaderCount;
- SAnonymousShader *m_pAnonymousShaders;
-
- // techniques within this effect (the actual data is located in each group)
- uint32_t m_TechniqueCount;
-
- // groups within this effect
- uint32_t m_GroupCount;
- SGroup *m_pGroups;
- SGroup *m_pNullGroup;
-
- uint32_t m_ShaderBlockCount;
- SShaderBlock *m_pShaderBlocks;
-
- uint32_t m_DepthStencilBlockCount;
- SDepthStencilBlock *m_pDepthStencilBlocks;
-
- uint32_t m_BlendBlockCount;
- SBlendBlock *m_pBlendBlocks;
-
- uint32_t m_RasterizerBlockCount;
- SRasterizerBlock *m_pRasterizerBlocks;
-
- uint32_t m_SamplerBlockCount;
- SSamplerBlock *m_pSamplerBlocks;
-
- uint32_t m_MemberDataCount;
- SMemberDataPointer *m_pMemberDataBlocks;
-
- uint32_t m_InterfaceCount;
- SInterface *m_pInterfaces;
-
- uint32_t m_CBCount;
- SConstantBuffer *m_pCBs;
-
- uint32_t m_StringCount;
- SString *m_pStrings;
-
- uint32_t m_ShaderResourceCount;
- SShaderResource *m_pShaderResources;
-
- uint32_t m_UnorderedAccessViewCount;
- SUnorderedAccessView *m_pUnorderedAccessViews;
-
- uint32_t m_RenderTargetViewCount;
- SRenderTargetView *m_pRenderTargetViews;
-
- uint32_t m_DepthStencilViewCount;
- SDepthStencilView *m_pDepthStencilViews;
-
- Timer m_LocalTimer;
-
- // temporary index variable for assignment evaluation
- uint32_t m_FXLIndex;
-
- ID3D11Device *m_pDevice;
- ID3D11DeviceContext *m_pContext;
- ID3D11ClassLinkage *m_pClassLinkage;
-
- // Master lists of reflection interfaces
- CEffectVectorOwner<SSingleElementType> m_pTypeInterfaces;
- CEffectVectorOwner<SMember> m_pMemberInterfaces;
-
- //////////////////////////////////////////////////////////////////////////
- // String & Type pooling
-
- typedef SType *LPSRUNTIMETYPE;
- static bool AreTypesEqual(const LPSRUNTIMETYPE &pType1, const LPSRUNTIMETYPE &pType2) { return (pType1->IsEqual(pType2)); }
- static bool AreStringsEqual(const LPCSTR &pStr1, const LPCSTR &pStr2) { return strcmp(pStr1, pStr2) == 0; }
-
- typedef CEffectHashTableWithPrivateHeap<SType *, AreTypesEqual> CTypeHashTable;
- typedef CEffectHashTableWithPrivateHeap<LPCSTR, AreStringsEqual> CStringHashTable;
-
- // These are used to pool types & type-related strings
- // until Optimize() is called
- CTypeHashTable *m_pTypePool;
- CStringHashTable *m_pStringPool;
- CDataBlockStore *m_pPooledHeap;
- // After Optimize() is called, the type/string pools should be deleted and all
- // remaining data should be migrated into the optimized type heap
- CEffectHeap *m_pOptimizedTypeHeap;
-
- // Pools a string or type and modifies the pointer
- void AddStringToPool(const char **ppString);
- void AddTypeToPool(SType **ppType);
-
- HRESULT OptimizeTypes(_Inout_ CPointerMappingTable *pMappingTable, _In_ bool Cloning = false);
-
-
- //////////////////////////////////////////////////////////////////////////
- // Runtime (performance critical)
-
- void ApplyShaderBlock(_In_ SShaderBlock *pBlock);
- bool ApplyRenderStateBlock(_In_ SBaseBlock *pBlock);
- bool ApplySamplerBlock(_In_ SSamplerBlock *pBlock);
- void ApplyPassBlock(_Inout_ SPassBlock *pBlock);
- bool EvaluateAssignment(_Inout_ SAssignment *pAssignment);
- bool ValidateShaderBlock(_Inout_ SShaderBlock* pBlock );
- bool ValidatePassBlock(_Inout_ SPassBlock* pBlock );
-
- //////////////////////////////////////////////////////////////////////////
- // Non-runtime functions (not performance critical)
-
- SGlobalVariable *FindLocalVariableByName(_In_z_ LPCSTR pVarName); // Looks in the current effect only
- SGlobalVariable *FindVariableByName(_In_z_ LPCSTR pVarName);
- SVariable *FindVariableByNameWithParsing(_In_z_ LPCSTR pVarName);
- SConstantBuffer *FindCB(_In_z_ LPCSTR pName);
- void ReplaceCBReference(_In_ SConstantBuffer *pOldBufferBlock, _In_ ID3D11Buffer *pNewBuffer); // Used by user-managed CBs
- void ReplaceSamplerReference(_In_ SSamplerBlock *pOldSamplerBlock, _In_ ID3D11SamplerState *pNewSampler);
- void AddRefAllForCloning( _In_ CEffect* pEffectSource );
- HRESULT CopyMemberInterfaces( _In_ CEffect* pEffectSource );
- HRESULT CopyStringPool( _In_ CEffect* pEffectSource, _Inout_ CPointerMappingTable& mappingTable );
- HRESULT CopyTypePool( _In_ CEffect* pEffectSource, _Inout_ CPointerMappingTable& mappingTableTypes, _Inout_ CPointerMappingTable& mappingTableStrings );
- HRESULT CopyOptimizedTypePool( _In_ CEffect* pEffectSource, _Inout_ CPointerMappingTable& mappingTableTypes );
- HRESULT RecreateCBs();
- HRESULT FixupMemberInterface( _Inout_ SMember* pMember, _In_ CEffect* pEffectSource, _Inout_ CPointerMappingTable& mappingTableStrings );
-
- void ValidateIndex(_In_ uint32_t Elements);
-
- void IncrementTimer();
- void HandleLocalTimerRollover();
-
- friend struct SConstantBuffer;
-
-public:
- CEffect( uint32_t Flags = 0 ) noexcept;
- virtual ~CEffect();
- void ReleaseShaderRefection();
-
- // Initialize must be called after the effect is created
- HRESULT LoadEffect(_In_reads_bytes_(cbEffectBuffer) const void *pEffectBuffer, _In_ uint32_t cbEffectBuffer);
-
- // Once the effect is fully loaded, call BindToDevice to attach it to a device
- HRESULT BindToDevice(_In_ ID3D11Device *pDevice, _In_z_ LPCSTR srcName );
-
- Timer GetCurrentTime() const { return m_LocalTimer; }
-
- bool IsReflectionData(void *pData) const { return m_pReflection->m_Heap.IsInHeap(pData); }
- bool IsRuntimeData(void *pData) const { return m_Heap.IsInHeap(pData); }
-
- //////////////////////////////////////////////////////////////////////////
- // Public interface
-
- // IUnknown
- STDMETHOD(QueryInterface)(REFIID iid, _COM_Outptr_ LPVOID *ppv) override;
- STDMETHOD_(ULONG, AddRef)() override;
- STDMETHOD_(ULONG, Release)() override;
-
- // ID3DX11Effect
- STDMETHOD_(bool, IsValid)() override { return true; }
-
- STDMETHOD(GetDevice)(_Outptr_ ID3D11Device** ppDevice) override;
-
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_DESC *pDesc) override;
-
- STDMETHOD_(ID3DX11EffectConstantBuffer*, GetConstantBufferByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectConstantBuffer*, GetConstantBufferByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD_(ID3DX11EffectVariable*, GetVariableByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetVariableByName)(_In_z_ LPCSTR Name) override;
- STDMETHOD_(ID3DX11EffectVariable*, GetVariableBySemantic)(_In_z_ LPCSTR Semantic) override;
-
- STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD_(ID3DX11EffectGroup*, GetGroupByIndex)(_In_ uint32_t Index) override;
- STDMETHOD_(ID3DX11EffectGroup*, GetGroupByName)(_In_z_ LPCSTR Name) override;
-
- STDMETHOD_(ID3D11ClassLinkage*, GetClassLinkage)() override;
-
- STDMETHOD(CloneEffect)(_In_ uint32_t Flags, _Outptr_ ID3DX11Effect** ppClonedEffect) override;
- STDMETHOD(Optimize)() override;
- STDMETHOD_(bool, IsOptimized)() override;
-
- //////////////////////////////////////////////////////////////////////////
- // New reflection helpers
-
- ID3DX11EffectType * CreatePooledSingleElementTypeInterface(_In_ SType *pType);
- ID3DX11EffectVariable * CreatePooledVariableMemberInterface(_In_ TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity,
- _In_ const SVariable *pMember,
- _In_ const UDataPointer Data, _In_ bool IsSingleElement, _In_ uint32_t Index);
-
-};
-
-}
-
-#pragma warning(pop)
+++ /dev/null
-#ifdef FX11
-
-//--------------------------------------------------------------------------------------
-// File: EffectAPI.cpp
-//
-// Effect API entry point
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#include "pchfx.h"
-
-#include <memory>
-
-using namespace D3DX11Effects;
-
-//-------------------------------------------------------------------------------------
-
-struct handle_closer { void operator()(HANDLE h) { if (h) CloseHandle(h); } };
-
-typedef std::unique_ptr<void, handle_closer> ScopedHandle;
-
-inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
-
-//-------------------------------------------------------------------------------------
-
-static HRESULT LoadBinaryFromFile( _In_z_ LPCWSTR pFileName, _Inout_ std::unique_ptr<uint8_t[]>& data, _Out_ uint32_t& size )
-{
- // open the file
-#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
- ScopedHandle hFile( safe_handle( CreateFile2( pFileName,
- GENERIC_READ,
- FILE_SHARE_READ,
- OPEN_EXISTING,
- nullptr ) ) );
-#else
- ScopedHandle hFile( safe_handle( CreateFileW( pFileName,
- GENERIC_READ,
- FILE_SHARE_READ,
- nullptr,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- nullptr ) ) );
-#endif
-
- if ( !hFile )
- {
- return HRESULT_FROM_WIN32( GetLastError() );
- }
-
- // Get the file size
- FILE_STANDARD_INFO fileInfo;
- if ( !GetFileInformationByHandleEx( hFile.get(), FileStandardInfo, &fileInfo, sizeof(fileInfo) ) )
- {
- return HRESULT_FROM_WIN32( GetLastError() );
- }
-
- // File is too big for 32-bit allocation or contains no data, so reject read
- if ( !fileInfo.EndOfFile.LowPart || fileInfo.EndOfFile.HighPart > 0 )
- {
- return E_FAIL;
- }
-
- // create enough space for the file data
- data.reset( new uint8_t[ fileInfo.EndOfFile.LowPart ] );
- if (!data)
- {
- return E_OUTOFMEMORY;
- }
-
- // read the data in
- DWORD BytesRead = 0;
- if (!ReadFile( hFile.get(),
- data.get(),
- fileInfo.EndOfFile.LowPart,
- &BytesRead,
- nullptr
- ))
- {
- return HRESULT_FROM_WIN32( GetLastError() );
- }
-
- if (BytesRead < fileInfo.EndOfFile.LowPart)
- {
- return E_FAIL;
- }
-
- size = BytesRead;
-
- return S_OK;
-}
-
-//--------------------------------------------------------------------------------------
-
-_Use_decl_annotations_
-HRESULT WINAPI D3DX11CreateEffectFromMemory(LPCVOID pData, SIZE_T DataLength, UINT FXFlags,
- ID3D11Device *pDevice, ID3DX11Effect **ppEffect, LPCSTR srcName )
-{
- if ( !pData || !DataLength || !pDevice || !ppEffect )
- return E_INVALIDARG;
-
- if ( DataLength > UINT32_MAX )
- return E_INVALIDARG;
-
- HRESULT hr = S_OK;
-
- // Note that pData must point to a compiled effect, not HLSL
- VN( *ppEffect = new CEffect( FXFlags & D3DX11_EFFECT_RUNTIME_VALID_FLAGS) );
- VH( ((CEffect*)(*ppEffect))->LoadEffect(pData, static_cast<uint32_t>(DataLength) ) );
- VH( ((CEffect*)(*ppEffect))->BindToDevice(pDevice, (srcName) ? srcName : "D3DX11Effect" ) );
-
-lExit:
- if (FAILED(hr))
- {
- SAFE_RELEASE(*ppEffect);
- }
- return hr;
-}
-
-//--------------------------------------------------------------------------------------
-
-_Use_decl_annotations_
-HRESULT WINAPI D3DX11CreateEffectFromFile( LPCWSTR pFileName, UINT FXFlags, ID3D11Device *pDevice, ID3DX11Effect **ppEffect )
-{
- if ( !pFileName || !pDevice || !ppEffect )
- return E_INVALIDARG;
-
- std::unique_ptr<uint8_t[]> fileData;
- uint32_t size;
- HRESULT hr = LoadBinaryFromFile( pFileName, fileData, size );
- if ( FAILED(hr) )
- return hr;
-
- hr = S_OK;
-
- // Note that pData must point to a compiled effect, not HLSL
- VN( *ppEffect = new CEffect( FXFlags & D3DX11_EFFECT_RUNTIME_VALID_FLAGS) );
- VH( ((CEffect*)(*ppEffect))->LoadEffect( fileData.get(), size ) );
-
- // Create debug object name from input filename
- CHAR strFileA[MAX_PATH];
- int result = WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH, nullptr, FALSE );
- if ( !result )
- {
- DPF(0, "Failed to load effect file due to WC to MB conversion failure: %ls", pFileName);
- hr = E_FAIL;
- goto lExit;
- }
-
- const CHAR* pstrName = strrchr( strFileA, '\\' );
- if (!pstrName)
- {
- pstrName = strFileA;
- }
- else
- {
- pstrName++;
- }
-
- VH( ((CEffect*)(*ppEffect))->BindToDevice(pDevice, pstrName) );
-
-lExit:
- if (FAILED(hr))
- {
- SAFE_RELEASE(*ppEffect);
- }
- return hr;
-}
-
-
-//--------------------------------------------------------------------------------------
-
-_Use_decl_annotations_
-HRESULT D3DX11CompileEffectFromMemory( LPCVOID pData, SIZE_T DataLength, LPCSTR srcName,
- const D3D_SHADER_MACRO *pDefines, ID3DInclude *pInclude, UINT HLSLFlags, UINT FXFlags,
- ID3D11Device *pDevice, ID3DX11Effect **ppEffect, ID3DBlob **ppErrors )
-{
- if ( !pData || !DataLength || !pDevice || !ppEffect )
- return E_INVALIDARG;
-
- if ( FXFlags & D3DCOMPILE_EFFECT_CHILD_EFFECT )
- {
- DPF(0, "Effect pools (i.e. D3DCOMPILE_EFFECT_CHILD_EFFECT) not supported" );
- return E_NOTIMPL;
- }
-
- ID3DBlob *blob = nullptr;
- HRESULT hr = D3DCompile( pData, DataLength, srcName, pDefines, pInclude, "", "fx_5_0", HLSLFlags, FXFlags, &blob, ppErrors );
- if ( FAILED(hr) )
- {
- DPF(0, "D3DCompile of fx_5_0 profile failed: %08X", hr );
- return hr;
- }
-
- hr = S_OK;
-
- VN( *ppEffect = new CEffect( FXFlags & D3DX11_EFFECT_RUNTIME_VALID_FLAGS ) );
- VH( ((CEffect*)(*ppEffect))->LoadEffect(blob->GetBufferPointer(), static_cast<uint32_t>( blob->GetBufferSize() ) ) );
- SAFE_RELEASE( blob );
-
- VH( ((CEffect*)(*ppEffect))->BindToDevice(pDevice, (srcName) ? srcName : "D3DX11Effect" ) );
-
-lExit:
- if (FAILED(hr))
- {
- SAFE_RELEASE(*ppEffect);
- }
- return hr;
-}
-
-//--------------------------------------------------------------------------------------
-
-_Use_decl_annotations_
-HRESULT D3DX11CompileEffectFromFile( LPCWSTR pFileName,
- const D3D_SHADER_MACRO *pDefines, ID3DInclude *pInclude, UINT HLSLFlags, UINT FXFlags,
- ID3D11Device *pDevice, ID3DX11Effect **ppEffect, ID3DBlob **ppErrors )
-{
- if ( !pFileName || !pDevice || !ppEffect )
- return E_INVALIDARG;
-
- if ( FXFlags & D3DCOMPILE_EFFECT_CHILD_EFFECT )
- {
- DPF(0, "Effect pools (i.e. D3DCOMPILE_EFFECT_CHILD_EFFECT) not supported" );
- return E_NOTIMPL;
- }
-
- ID3DBlob *blob = nullptr;
-
-#if (D3D_COMPILER_VERSION >= 46) && ( !defined(WINAPI_FAMILY) || ( (WINAPI_FAMILY != WINAPI_FAMILY_APP) && (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) ) )
-
- HRESULT hr = D3DCompileFromFile( pFileName, pDefines, pInclude, "", "fx_5_0", HLSLFlags, FXFlags, &blob, ppErrors );
- if ( FAILED(hr) )
- {
- DPF(0, "D3DCompileFromFile of fx_5_0 profile failed %08X: %ls", hr, pFileName );
- return hr;
- }
-
-#else // D3D_COMPILER_VERSION < 46
-
- std::unique_ptr<uint8_t[]> fileData;
- uint32_t size;
- HRESULT hr = LoadBinaryFromFile( pFileName, fileData, size );
- if ( FAILED(hr) )
- {
- DPF(0, "Failed to load effect file %08X: %ls", hr, pFileName);
- return hr;
- }
-
- // Create debug object name from input filename
- CHAR strFileA[MAX_PATH];
- int result = WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH, nullptr, FALSE );
- if ( !result )
- {
- DPF(0, "Failed to load effect file due to WC to MB conversion failure: %ls", pFileName);
- return E_FAIL;
- }
-
- const CHAR* pstrName = strrchr( strFileA, '\\' );
- if (!pstrName)
- {
- pstrName = strFileA;
- }
- else
- {
- pstrName++;
- }
-
- hr = D3DCompile( fileData.get(), size, pstrName, pDefines, pInclude, "", "fx_5_0", HLSLFlags, FXFlags, &blob, ppErrors );
- if ( FAILED(hr) )
- {
- DPF(0, "D3DCompile of fx_5_0 profile failed: %08X", hr );
- return hr;
- }
-
-#endif // D3D_COMPILER_VERSION
-
- if ( blob->GetBufferSize() > UINT32_MAX)
- {
- SAFE_RELEASE( blob );
- return E_FAIL;
- }
-
- hr = S_OK;
-
- VN( *ppEffect = new CEffect( FXFlags & D3DX11_EFFECT_RUNTIME_VALID_FLAGS ) );
- VH( ((CEffect*)(*ppEffect))->LoadEffect(blob->GetBufferPointer(), static_cast<uint32_t>( blob->GetBufferSize() ) ) );
- SAFE_RELEASE( blob );
-
-#if (D3D_COMPILER_VERSION >= 46) && ( !defined(WINAPI_FAMILY) || ( (WINAPI_FAMILY != WINAPI_FAMILY_APP) && (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) ) )
- // Create debug object name from input filename
- CHAR strFileA[MAX_PATH];
- int result = WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH, nullptr, FALSE );
- if ( !result )
- {
- DPF(0, "Failed to load effect file due to WC to MB conversion failure: %ls", pFileName);
- hr = E_FAIL;
- goto lExit;
- }
-
- const CHAR* pstrName = strrchr( strFileA, '\\' );
- if (!pstrName)
- {
- pstrName = strFileA;
- }
- else
- {
- pstrName++;
- }
-#endif
-
- VH( ((CEffect*)(*ppEffect))->BindToDevice(pDevice, pstrName) );
-
-lExit:
- if (FAILED(hr))
- {
- SAFE_RELEASE(*ppEffect);
- }
- return hr;
-}
-
-#endif
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: EffectBinaryFormat.h
-//
-// Direct3D11 Effects Binary Format
-// This is the binary file interface shared between the Effects
-// compiler and runtime.
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-namespace D3DX11Effects
-{
-
-//////////////////////////////////////////////////////////////////////////
-// Version Control
-//////////////////////////////////////////////////////////////////////////
-
-#define D3DX11_FXL_VERSION(_Major,_Minor) (('F' << 24) | ('X' << 16) | ((_Major) << 8) | (_Minor))
-
-struct EVersionTag
-{
- const char* m_pName;
- DWORD m_Version;
- uint32_t m_Tag;
-};
-
-// versions must be listed in ascending order
-static const EVersionTag g_EffectVersions[] =
-{
- { "fx_4_0", D3DX11_FXL_VERSION(4,0), 0xFEFF1001 },
- { "fx_4_1", D3DX11_FXL_VERSION(4,1), 0xFEFF1011 },
- { "fx_5_0", D3DX11_FXL_VERSION(5,0), 0xFEFF2001 },
-};
-
-
-//////////////////////////////////////////////////////////////////////////
-// Reflection & Type structures
-//////////////////////////////////////////////////////////////////////////
-
-// Enumeration of the possible left-hand side values of an assignment,
-// divided up categorically by the type of block they may appear in
-enum ELhsType
-{
- ELHS_Invalid,
-
- // Pass block assignment types
-
- ELHS_PixelShaderBlock, // SBlock *pValue points to the block to apply
- ELHS_VertexShaderBlock,
- ELHS_GeometryShaderBlock,
- ELHS_RenderTargetView,
- ELHS_DepthStencilView,
-
- ELHS_RasterizerBlock,
- ELHS_DepthStencilBlock,
- ELHS_BlendBlock,
-
- ELHS_GenerateMips, // This is really a call to D3D::GenerateMips
-
- // Various SAssignment.Value.*
-
- ELHS_DS_StencilRef, // SAssignment.Value.pdValue
- ELHS_B_BlendFactor, // D3D11_BLEND_CONFIG.BlendFactor, points to a float4
- ELHS_B_SampleMask, // D3D11_BLEND_CONFIG.SampleMask
-
- ELHS_GeometryShaderSO, // When setting SO assignments, GeometryShaderSO precedes the actual GeometryShader assn
-
- ELHS_ComputeShaderBlock,
- ELHS_HullShaderBlock,
- ELHS_DomainShaderBlock,
-
- // Rasterizer
-
- ELHS_FillMode = 0x20000,
- ELHS_CullMode,
- ELHS_FrontCC,
- ELHS_DepthBias,
- ELHS_DepthBiasClamp,
- ELHS_SlopeScaledDepthBias,
- ELHS_DepthClipEnable,
- ELHS_ScissorEnable,
- ELHS_MultisampleEnable,
- ELHS_AntialiasedLineEnable,
-
- // Sampler
-
- ELHS_Filter = 0x30000,
- ELHS_AddressU,
- ELHS_AddressV,
- ELHS_AddressW,
- ELHS_MipLODBias,
- ELHS_MaxAnisotropy,
- ELHS_ComparisonFunc,
- ELHS_BorderColor,
- ELHS_MinLOD,
- ELHS_MaxLOD,
- ELHS_Texture,
-
- // DepthStencil
-
- ELHS_DepthEnable = 0x40000,
- ELHS_DepthWriteMask,
- ELHS_DepthFunc,
- ELHS_StencilEnable,
- ELHS_StencilReadMask,
- ELHS_StencilWriteMask,
- ELHS_FrontFaceStencilFailOp,
- ELHS_FrontFaceStencilDepthFailOp,
- ELHS_FrontFaceStencilPassOp,
- ELHS_FrontFaceStencilFunc,
- ELHS_BackFaceStencilFailOp,
- ELHS_BackFaceStencilDepthFailOp,
- ELHS_BackFaceStencilPassOp,
- ELHS_BackFaceStencilFunc,
-
- // BlendState
-
- ELHS_AlphaToCoverage = 0x50000,
- ELHS_BlendEnable,
- ELHS_SrcBlend,
- ELHS_DestBlend,
- ELHS_BlendOp,
- ELHS_SrcBlendAlpha,
- ELHS_DestBlendAlpha,
- ELHS_BlendOpAlpha,
- ELHS_RenderTargetWriteMask,
-};
-
-enum EBlockType
-{
- EBT_Invalid,
- EBT_DepthStencil,
- EBT_Blend,
- EBT_Rasterizer,
- EBT_Sampler,
- EBT_Pass
-};
-
-enum EVarType
-{
- EVT_Invalid,
- EVT_Numeric,
- EVT_Object,
- EVT_Struct,
- EVT_Interface,
-};
-
-enum EScalarType
-{
- EST_Invalid,
- EST_Float,
- EST_Int,
- EST_UInt,
- EST_Bool,
- EST_Count
-};
-
-enum ENumericLayout
-{
- ENL_Invalid,
- ENL_Scalar,
- ENL_Vector,
- ENL_Matrix,
- ENL_Count
-};
-
-enum EObjectType
-{
- EOT_Invalid,
- EOT_String,
- EOT_Blend,
- EOT_DepthStencil,
- EOT_Rasterizer,
- EOT_PixelShader,
- EOT_VertexShader,
- EOT_GeometryShader, // Regular geometry shader
- EOT_GeometryShaderSO, // Geometry shader with a attached StreamOut decl
- EOT_Texture,
- EOT_Texture1D,
- EOT_Texture1DArray,
- EOT_Texture2D,
- EOT_Texture2DArray,
- EOT_Texture2DMS,
- EOT_Texture2DMSArray,
- EOT_Texture3D,
- EOT_TextureCube,
- EOT_ConstantBuffer,
- EOT_RenderTargetView,
- EOT_DepthStencilView,
- EOT_Sampler,
- EOT_Buffer,
- EOT_TextureCubeArray,
- EOT_Count,
- EOT_PixelShader5,
- EOT_VertexShader5,
- EOT_GeometryShader5,
- EOT_ComputeShader5,
- EOT_HullShader5,
- EOT_DomainShader5,
- EOT_RWTexture1D,
- EOT_RWTexture1DArray,
- EOT_RWTexture2D,
- EOT_RWTexture2DArray,
- EOT_RWTexture3D,
- EOT_RWBuffer,
- EOT_ByteAddressBuffer,
- EOT_RWByteAddressBuffer,
- EOT_StructuredBuffer,
- EOT_RWStructuredBuffer,
- EOT_RWStructuredBufferAlloc,
- EOT_RWStructuredBufferConsume,
- EOT_AppendStructuredBuffer,
- EOT_ConsumeStructuredBuffer,
-};
-
-inline bool IsObjectTypeHelper(EVarType InVarType,
- EObjectType InObjType,
- EObjectType TargetObjType)
-{
- return (InVarType == EVT_Object) && (InObjType == TargetObjType);
-}
-
-inline bool IsSamplerHelper(EVarType InVarType,
- EObjectType InObjType)
-{
- return (InVarType == EVT_Object) && (InObjType == EOT_Sampler);
-}
-
-inline bool IsStateBlockObjectHelper(EVarType InVarType,
- EObjectType InObjType)
-{
- return (InVarType == EVT_Object) && ((InObjType == EOT_Blend) || (InObjType == EOT_DepthStencil) || (InObjType == EOT_Rasterizer) || IsSamplerHelper(InVarType, InObjType));
-}
-
-inline bool IsShaderHelper(EVarType InVarType,
- EObjectType InObjType)
-{
- return (InVarType == EVT_Object) && ((InObjType == EOT_VertexShader) ||
- (InObjType == EOT_VertexShader5) ||
- (InObjType == EOT_HullShader5) ||
- (InObjType == EOT_DomainShader5) ||
- (InObjType == EOT_ComputeShader5) ||
- (InObjType == EOT_GeometryShader) ||
- (InObjType == EOT_GeometryShaderSO) ||
- (InObjType == EOT_GeometryShader5) ||
- (InObjType == EOT_PixelShader) ||
- (InObjType == EOT_PixelShader5));
-}
-
-inline bool IsShader5Helper(EVarType InVarType,
- EObjectType InObjType)
-{
- return (InVarType == EVT_Object) && ((InObjType == EOT_VertexShader5) ||
- (InObjType == EOT_HullShader5) ||
- (InObjType == EOT_DomainShader5) ||
- (InObjType == EOT_ComputeShader5) ||
- (InObjType == EOT_GeometryShader5) ||
- (InObjType == EOT_PixelShader5));
-}
-
-inline bool IsInterfaceHelper(EVarType InVarType, EObjectType InObjType)
-{
- UNREFERENCED_PARAMETER(InObjType);
- return (InVarType == EVT_Interface);
-}
-
-inline bool IsShaderResourceHelper(EVarType InVarType,
- EObjectType InObjType)
-{
- return (InVarType == EVT_Object) && ((InObjType == EOT_Texture) ||
- (InObjType == EOT_Texture1D) ||
- (InObjType == EOT_Texture1DArray) ||
- (InObjType == EOT_Texture2D) ||
- (InObjType == EOT_Texture2DArray) ||
- (InObjType == EOT_Texture2DMS) ||
- (InObjType == EOT_Texture2DMSArray) ||
- (InObjType == EOT_Texture3D) ||
- (InObjType == EOT_TextureCube) ||
- (InObjType == EOT_TextureCubeArray) ||
- (InObjType == EOT_Buffer) ||
- (InObjType == EOT_StructuredBuffer) ||
- (InObjType == EOT_ByteAddressBuffer));
-}
-
-inline bool IsUnorderedAccessViewHelper(EVarType InVarType,
- EObjectType InObjType)
-{
- return (InVarType == EVT_Object) &&
- ((InObjType == EOT_RWTexture1D) ||
- (InObjType == EOT_RWTexture1DArray) ||
- (InObjType == EOT_RWTexture2D) ||
- (InObjType == EOT_RWTexture2DArray) ||
- (InObjType == EOT_RWTexture3D) ||
- (InObjType == EOT_RWBuffer) ||
- (InObjType == EOT_RWByteAddressBuffer) ||
- (InObjType == EOT_RWStructuredBuffer) ||
- (InObjType == EOT_RWStructuredBufferAlloc) ||
- (InObjType == EOT_RWStructuredBufferConsume) ||
- (InObjType == EOT_AppendStructuredBuffer) ||
- (InObjType == EOT_ConsumeStructuredBuffer));
-}
-
-inline bool IsRenderTargetViewHelper(EVarType InVarType,
- EObjectType InObjType)
-{
- return (InVarType == EVT_Object) && (InObjType == EOT_RenderTargetView);
-}
-
-inline bool IsDepthStencilViewHelper(EVarType InVarType,
- EObjectType InObjType)
-{
- return (InVarType == EVT_Object) && (InObjType == EOT_DepthStencilView);
-}
-
-inline bool IsObjectAssignmentHelper(ELhsType LhsType)
-{
- switch(LhsType)
- {
- case ELHS_VertexShaderBlock:
- case ELHS_HullShaderBlock:
- case ELHS_DepthStencilView:
- case ELHS_GeometryShaderBlock:
- case ELHS_PixelShaderBlock:
- case ELHS_ComputeShaderBlock:
- case ELHS_DepthStencilBlock:
- case ELHS_RasterizerBlock:
- case ELHS_BlendBlock:
- case ELHS_Texture:
- case ELHS_RenderTargetView:
- case ELHS_DomainShaderBlock:
- return true;
- }
- return false;
-}
-
-
-
-
-// Effect file format structures /////////////////////////////////////////////
-// File format:
-// File header (SBinaryHeader Header)
-// Unstructured data block (uint8_t[Header.cbUnstructured))
-// Structured data block
-// ConstantBuffer (SBinaryConstantBuffer CB) * Header.Effect.cCBs
-// uint32_t NumAnnotations
-// Annotation data (SBinaryAnnotation) * (NumAnnotations) *this structure is variable sized
-// Variable data (SBinaryNumericVariable Var) * (CB.cVariables)
-// uint32_t NumAnnotations
-// Annotation data (SBinaryAnnotation) * (NumAnnotations) *this structure is variable sized
-// Object variables (SBinaryObjectVariable Var) * (Header.cObjectVariables) *this structure is variable sized
-// uint32_t NumAnnotations
-// Annotation data (SBinaryAnnotation) * (NumAnnotations) *this structure is variable sized
-// Interface variables (SBinaryInterfaceVariable Var) * (Header.cInterfaceVariables) *this structure is variable sized
-// uint32_t NumAnnotations
-// Annotation data (SBinaryAnnotation) * (NumAnnotations) *this structure is variable sized
-// Groups (SBinaryGroup Group) * Header.cGroups
-// uint32_t NumAnnotations
-// Annotation data (SBinaryAnnotation) * (NumAnnotations) *this structure is variable sized
-// Techniques (SBinaryTechnique Technique) * Group.cTechniques
-// uint32_t NumAnnotations
-// Annotation data (SBinaryAnnotation) * (NumAnnotations) *this structure is variable sized
-// Pass (SBinaryPass Pass) * Technique.cPasses
-// uint32_t NumAnnotations
-// Annotation data (SBinaryAnnotation) * (NumAnnotations) *this structure is variable sized
-// Pass assignments (SBinaryAssignment) * Pass.cAssignments
-
-struct SBinaryHeader
-{
- struct SVarCounts
- {
- uint32_t cCBs;
- uint32_t cNumericVariables;
- uint32_t cObjectVariables;
- };
-
- uint32_t Tag; // should be equal to c_EffectFileTag
- // this is used to identify ASCII vs Binary files
-
- SVarCounts Effect;
- SVarCounts Pool;
-
- uint32_t cTechniques;
- uint32_t cbUnstructured;
-
- uint32_t cStrings;
- uint32_t cShaderResources;
-
- uint32_t cDepthStencilBlocks;
- uint32_t cBlendStateBlocks;
- uint32_t cRasterizerStateBlocks;
- uint32_t cSamplers;
- uint32_t cRenderTargetViews;
- uint32_t cDepthStencilViews;
-
- uint32_t cTotalShaders;
- uint32_t cInlineShaders; // of the aforementioned shaders, the number that are defined inline within pass blocks
-
- inline bool RequiresPool() const
- {
- return (Pool.cCBs != 0) ||
- (Pool.cNumericVariables != 0) ||
- (Pool.cObjectVariables != 0);
- }
-};
-
-struct SBinaryHeader5 : public SBinaryHeader
-{
- uint32_t cGroups;
- uint32_t cUnorderedAccessViews;
- uint32_t cInterfaceVariables;
- uint32_t cInterfaceVariableElements;
- uint32_t cClassInstanceElements;
-};
-
-// Constant buffer definition
-struct SBinaryConstantBuffer
-{
- // private flags
- static const uint32_t c_IsTBuffer = (1 << 0);
- static const uint32_t c_IsSingle = (1 << 1);
-
- uint32_t oName; // Offset to constant buffer name
- uint32_t Size; // Size, in bytes
- uint32_t Flags;
- uint32_t cVariables; // # of variables inside this buffer
- uint32_t ExplicitBindPoint; // Defined if the effect file specifies a bind point using the register keyword
- // otherwise, -1
-};
-
-struct SBinaryAnnotation
-{
- uint32_t oName; // Offset to variable name
- uint32_t oType; // Offset to type information (SBinaryType)
-
- // For numeric annotations:
- // uint32_t oDefaultValue; // Offset to default initializer value
- //
- // For string annotations:
- // uint32_t oStringOffsets[Elements]; // Elements comes from the type data at oType
-};
-
-struct SBinaryNumericVariable
-{
- uint32_t oName; // Offset to variable name
- uint32_t oType; // Offset to type information (SBinaryType)
- uint32_t oSemantic; // Offset to semantic information
- uint32_t Offset; // Offset in parent constant buffer
- uint32_t oDefaultValue; // Offset to default initializer value
- uint32_t Flags; // Explicit bind point
-};
-
-struct SBinaryInterfaceVariable
-{
- uint32_t oName; // Offset to variable name
- uint32_t oType; // Offset to type information (SBinaryType)
- uint32_t oDefaultValue; // Offset to default initializer array (SBinaryInterfaceInitializer[Elements])
- uint32_t Flags;
-};
-
-struct SBinaryInterfaceInitializer
-{
- uint32_t oInstanceName;
- uint32_t ArrayIndex;
-};
-
-struct SBinaryObjectVariable
-{
- uint32_t oName; // Offset to variable name
- uint32_t oType; // Offset to type information (SBinaryType)
- uint32_t oSemantic; // Offset to semantic information
- uint32_t ExplicitBindPoint; // Used when a variable has been explicitly bound (register(XX)). -1 if not
-
- // Initializer data:
- //
- // The type structure pointed to by oType gives you Elements,
- // VarType (must be EVT_Object), and ObjectType
- //
- // For ObjectType == EOT_Blend, EOT_DepthStencil, EOT_Rasterizer, EOT_Sampler
- // struct
- // {
- // uint32_t cAssignments;
- // SBinaryAssignment Assignments[cAssignments];
- // } Blocks[Elements]
- //
- // For EObjectType == EOT_Texture*, EOT_Buffer
- // <nothing>
- //
- // For EObjectType == EOT_*Shader, EOT_String
- // uint32_t oData[Elements]; // offsets to a shader data block or a nullptr-terminated string
- //
- // For EObjectType == EOT_GeometryShaderSO
- // SBinaryGSSOInitializer[Elements]
- //
- // For EObjectType == EOT_*Shader5
- // SBinaryShaderData5[Elements]
-};
-
-struct SBinaryGSSOInitializer
-{
- uint32_t oShader; // Offset to shader bytecode data block
- uint32_t oSODecl; // Offset to StreamOutput decl string
-};
-
-struct SBinaryShaderData5
-{
- uint32_t oShader; // Offset to shader bytecode data block
- uint32_t oSODecls[4]; // Offset to StreamOutput decl strings
- uint32_t cSODecls; // Count of valid oSODecls entries.
- uint32_t RasterizedStream; // Which stream is used for rasterization
- uint32_t cInterfaceBindings; // Count of interface bindings.
- uint32_t oInterfaceBindings; // Offset to SBinaryInterfaceInitializer[cInterfaceBindings].
-};
-
-struct SBinaryType
-{
- uint32_t oTypeName; // Offset to friendly type name ("float4", "VS_OUTPUT")
- EVarType VarType; // Numeric, Object, or Struct
- uint32_t Elements; // # of array elements (0 for non-arrays)
- uint32_t TotalSize; // Size in bytes; not necessarily Stride * Elements for arrays
- // because of possible gap left in final register
- uint32_t Stride; // If an array, this is the spacing between elements.
- // For unpacked arrays, always divisible by 16-bytes (1 register).
- // No support for packed arrays
- uint32_t PackedSize; // Size, in bytes, of this data typed when fully packed
-
- struct SBinaryMember
- {
- uint32_t oName; // Offset to structure member name ("m_pFoo")
- uint32_t oSemantic; // Offset to semantic ("POSITION0")
- uint32_t Offset; // Offset, in bytes, relative to start of parent structure
- uint32_t oType; // Offset to member's type descriptor
- };
-
- // the data that follows depends on the VarType:
- // Numeric: SType::SNumericType
- // Object: EObjectType
- // Struct:
- // struct
- // {
- // uint32_t cMembers;
- // SBinaryMembers Members[cMembers];
- // } MemberInfo
- // struct
- // {
- // uint32_t oBaseClassType; // Offset to type information (SBinaryType)
- // uint32_t cInterfaces;
- // uint32_t oInterfaceTypes[cInterfaces];
- // } SBinaryTypeInheritance
- // Interface: (nothing)
-};
-
-struct SBinaryNumericType
-{
- ENumericLayout NumericLayout : 3; // scalar (1x1), vector (1xN), matrix (NxN)
- EScalarType ScalarType : 5; // float32, int32, int8, etc.
- uint32_t Rows : 3; // 1 <= Rows <= 4
- uint32_t Columns : 3; // 1 <= Columns <= 4
- uint32_t IsColumnMajor : 1; // applies only to matrices
- uint32_t IsPackedArray : 1; // if this is an array, indicates whether elements should be greedily packed
-};
-
-struct SBinaryTypeInheritance
-{
- uint32_t oBaseClass; // Offset to base class type info or 0 if no base class.
- uint32_t cInterfaces;
-
- // Followed by uint32_t[cInterfaces] with offsets to the type
- // info of each interface.
-};
-
-struct SBinaryGroup
-{
- uint32_t oName;
- uint32_t cTechniques;
-};
-
-struct SBinaryTechnique
-{
- uint32_t oName;
- uint32_t cPasses;
-};
-
-struct SBinaryPass
-{
- uint32_t oName;
- uint32_t cAssignments;
-};
-
-enum ECompilerAssignmentType
-{
- ECAT_Invalid, // Assignment-specific data (always in the unstructured blob)
- ECAT_Constant, // -N SConstant structures
- ECAT_Variable, // -nullptr terminated string with variable name ("foo")
- ECAT_ConstIndex, // -SConstantIndex structure
- ECAT_VariableIndex, // -SVariableIndex structure
- ECAT_ExpressionIndex, // -SIndexedObjectExpression structure
- ECAT_Expression, // -Data block containing FXLVM code
- ECAT_InlineShader, // -Data block containing shader
- ECAT_InlineShader5, // -Data block containing shader with extended 5.0 data (SBinaryShaderData5)
-};
-
-struct SBinaryAssignment
-{
- uint32_t iState; // index into g_lvGeneral
- uint32_t Index; // the particular index to assign to (see g_lvGeneral to find the # of valid indices)
- ECompilerAssignmentType AssignmentType;
- uint32_t oInitializer; // Offset of assignment-specific data
-
- struct SConstantIndex
- {
- uint32_t oArrayName;
- uint32_t Index;
- };
-
- struct SVariableIndex
- {
- uint32_t oArrayName;
- uint32_t oIndexVarName;
- };
-
- struct SIndexedObjectExpression
- {
- uint32_t oArrayName;
- uint32_t oCode;
- };
-
- struct SInlineShader
- {
- uint32_t oShader;
- uint32_t oSODecl;
- };
-};
-
-struct SBinaryConstant
-{
- EScalarType Type;
- union
- {
- BOOL bValue;
- INT iValue;
- float fValue;
- };
-};
-
-static_assert( sizeof(SBinaryHeader) == 76, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryHeader::SVarCounts) == 12, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryHeader5) == 96, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryConstantBuffer) == 20, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryAnnotation) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryNumericVariable) == 24, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryInterfaceVariable) == 16, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryInterfaceInitializer) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryObjectVariable) == 16, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryGSSOInitializer) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryShaderData5) == 36, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryType) == 24, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryType::SBinaryMember) == 16, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryNumericType) == 4, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryTypeInheritance) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryGroup) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryTechnique) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryPass) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryAssignment) == 16, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryAssignment::SConstantIndex) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryAssignment::SVariableIndex) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryAssignment::SIndexedObjectExpression) == 8, "FX11 binary size mismatch" );
-static_assert( sizeof(SBinaryAssignment::SInlineShader) == 8, "FX11 binary size mismatch" );
-
-} // end namespace D3DX11Effects
-
+++ /dev/null
-#ifdef FX11
-
-//--------------------------------------------------------------------------------------
-// File: EffectLoad.cpp
-//
-// Direct3D Effects file loading code
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#include "pchfx.h"
-
-#include "EffectStates11.h"
-
-#define PRIVATENEW new(m_BulkHeap)
-
-namespace D3DX11Effects
-{
-
-static LPCSTR g_szEffectLoadArea = "D3D11EffectLoader";
-
-SRasterizerBlock g_NullRasterizer;
-SDepthStencilBlock g_NullDepthStencil;
-SBlendBlock g_NullBlend;
-SShaderResource g_NullTexture;
-SInterface g_NullInterface;
-SUnorderedAccessView g_NullUnorderedAccessView;
-SRenderTargetView g_NullRenderTargetView;
-SDepthStencilView g_NullDepthStencilView;
-
-// these VTables must be setup in the proper order:
-// 1) SetShader
-// 2) SetConstantBuffers
-// 3) SetSamplers
-// 4) SetShaderResources
-// 5) CreateShader
-SD3DShaderVTable g_vtPS = {
- (void (__stdcall ID3D11DeviceContext::*)(ID3D11DeviceChild*, ID3D11ClassInstance*const*, uint32_t)) &ID3D11DeviceContext::PSSetShader,
- &ID3D11DeviceContext::PSSetConstantBuffers,
- &ID3D11DeviceContext::PSSetSamplers,
- &ID3D11DeviceContext::PSSetShaderResources,
- (HRESULT (__stdcall ID3D11Device::*)(const void *, size_t, ID3D11ClassLinkage*, ID3D11DeviceChild **)) &ID3D11Device::CreatePixelShader
-};
-
-SD3DShaderVTable g_vtVS = {
- (void (__stdcall ID3D11DeviceContext::*)(ID3D11DeviceChild*, ID3D11ClassInstance*const*, uint32_t)) &ID3D11DeviceContext::VSSetShader,
- &ID3D11DeviceContext::VSSetConstantBuffers,
- &ID3D11DeviceContext::VSSetSamplers,
- &ID3D11DeviceContext::VSSetShaderResources,
- (HRESULT (__stdcall ID3D11Device::*)(const void *, size_t, ID3D11ClassLinkage*, ID3D11DeviceChild **)) &ID3D11Device::CreateVertexShader
-};
-
-SD3DShaderVTable g_vtGS = {
- (void (__stdcall ID3D11DeviceContext::*)(ID3D11DeviceChild*, ID3D11ClassInstance*const*, uint32_t)) &ID3D11DeviceContext::GSSetShader,
- &ID3D11DeviceContext::GSSetConstantBuffers,
- &ID3D11DeviceContext::GSSetSamplers,
- &ID3D11DeviceContext::GSSetShaderResources,
- (HRESULT (__stdcall ID3D11Device::*)(const void *, size_t, ID3D11ClassLinkage*, ID3D11DeviceChild **)) &ID3D11Device::CreateGeometryShader
-};
-
-SD3DShaderVTable g_vtHS = {
- (void (__stdcall ID3D11DeviceContext::*)(ID3D11DeviceChild*, ID3D11ClassInstance*const*, uint32_t)) &ID3D11DeviceContext::HSSetShader,
- &ID3D11DeviceContext::HSSetConstantBuffers,
- &ID3D11DeviceContext::HSSetSamplers,
- &ID3D11DeviceContext::HSSetShaderResources,
- (HRESULT (__stdcall ID3D11Device::*)(const void *, size_t, ID3D11ClassLinkage*, ID3D11DeviceChild **)) &ID3D11Device::CreateHullShader
-};
-
-SD3DShaderVTable g_vtDS = {
- (void (__stdcall ID3D11DeviceContext::*)(ID3D11DeviceChild*, ID3D11ClassInstance*const*, uint32_t)) &ID3D11DeviceContext::DSSetShader,
- &ID3D11DeviceContext::DSSetConstantBuffers,
- &ID3D11DeviceContext::DSSetSamplers,
- &ID3D11DeviceContext::DSSetShaderResources,
- (HRESULT (__stdcall ID3D11Device::*)(const void *, size_t, ID3D11ClassLinkage*, ID3D11DeviceChild **)) &ID3D11Device::CreateDomainShader
-};
-
-SD3DShaderVTable g_vtCS = {
- (void (__stdcall ID3D11DeviceContext::*)(ID3D11DeviceChild*, ID3D11ClassInstance*const*, uint32_t)) &ID3D11DeviceContext::CSSetShader,
- &ID3D11DeviceContext::CSSetConstantBuffers,
- &ID3D11DeviceContext::CSSetSamplers,
- &ID3D11DeviceContext::CSSetShaderResources,
- (HRESULT (__stdcall ID3D11Device::*)(const void *, size_t, ID3D11ClassLinkage*, ID3D11DeviceChild **)) &ID3D11Device::CreateComputeShader
-};
-
-SShaderBlock g_NullVS(&g_vtVS);
-SShaderBlock g_NullGS(&g_vtGS);
-SShaderBlock g_NullPS(&g_vtPS);
-SShaderBlock g_NullHS(&g_vtHS);
-SShaderBlock g_NullDS(&g_vtDS);
-SShaderBlock g_NullCS(&g_vtCS);
-
-D3D_SHADER_VARIABLE_TYPE GetSimpleParameterTypeFromObjectType(EObjectType ObjectType)
-{
- switch (ObjectType)
- {
- case EOT_String:
- return D3D_SVT_STRING;
- case EOT_Blend:
- return D3D_SVT_BLEND;
- case EOT_DepthStencil:
- return D3D_SVT_DEPTHSTENCIL;
- case EOT_Rasterizer:
- return D3D_SVT_RASTERIZER;
- case EOT_PixelShader:
- case EOT_PixelShader5:
- return D3D_SVT_PIXELSHADER;
- case EOT_VertexShader:
- case EOT_VertexShader5:
- return D3D_SVT_VERTEXSHADER;
- case EOT_GeometryShader:
- case EOT_GeometryShaderSO:
- case EOT_GeometryShader5:
- return D3D_SVT_GEOMETRYSHADER;
- case EOT_HullShader5:
- return D3D_SVT_HULLSHADER;
- case EOT_DomainShader5:
- return D3D_SVT_DOMAINSHADER;
- case EOT_ComputeShader5:
- return D3D_SVT_COMPUTESHADER;
- case EOT_RenderTargetView:
- return D3D_SVT_RENDERTARGETVIEW;
- case EOT_DepthStencilView:
- return D3D_SVT_DEPTHSTENCILVIEW;
- case EOT_Texture:
- case EOT_Texture1D:
- case EOT_Texture1DArray:
- case EOT_Texture2D:
- case EOT_Texture2DArray:
- case EOT_Texture2DMS:
- case EOT_Texture2DMSArray:
- case EOT_Texture3D:
- case EOT_TextureCube:
- case EOT_TextureCubeArray:
- return D3D_SVT_TEXTURE;
- case EOT_Buffer:
- return D3D_SVT_BUFFER;
- case EOT_Sampler:
- return D3D_SVT_SAMPLER;
- case EOT_ByteAddressBuffer:
- return D3D_SVT_BYTEADDRESS_BUFFER;
- case EOT_StructuredBuffer:
- return D3D_SVT_STRUCTURED_BUFFER;
- case EOT_RWTexture1D:
- return D3D_SVT_RWTEXTURE1D;
- case EOT_RWTexture1DArray:
- return D3D_SVT_RWTEXTURE1DARRAY;
- case EOT_RWTexture2D:
- return D3D_SVT_RWTEXTURE2D;
- case EOT_RWTexture2DArray:
- return D3D_SVT_RWTEXTURE2DARRAY;
- case EOT_RWTexture3D:
- return D3D_SVT_RWTEXTURE3D;
- case EOT_RWBuffer:
- return D3D_SVT_RWBUFFER;
- case EOT_RWByteAddressBuffer:
- return D3D_SVT_RWBYTEADDRESS_BUFFER;
- case EOT_RWStructuredBuffer:
- case EOT_RWStructuredBufferAlloc:
- case EOT_RWStructuredBufferConsume:
- return D3D_SVT_RWSTRUCTURED_BUFFER;
- case EOT_AppendStructuredBuffer:
- return D3D_SVT_APPEND_STRUCTURED_BUFFER;
- case EOT_ConsumeStructuredBuffer:
- return D3D_SVT_CONSUME_STRUCTURED_BUFFER;
- default:
- assert(0);
- }
- return D3D_SVT_VOID;
-}
-
-inline HRESULT VerifyPointer(uint32_t oBase, uint32_t dwSize, uint32_t dwMaxSize)
-{
- uint32_t dwAdd = oBase + dwSize;
- if (dwAdd < oBase || dwAdd > dwMaxSize)
- return E_FAIL;
- return S_OK;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// EffectHeap
-// A simple class which assists in adding data to a block of memory
-//////////////////////////////////////////////////////////////////////////
-
-CEffectHeap::CEffectHeap() noexcept :
- m_pData(nullptr),
- m_dwSize(0),
- m_dwBufferSize(0)
-{
-}
-
-CEffectHeap::~CEffectHeap()
-{
- SAFE_DELETE_ARRAY(m_pData);
-}
-
-uint32_t CEffectHeap::GetSize()
-{
- return m_dwSize;
-}
-
-HRESULT CEffectHeap::ReserveMemory(uint32_t dwSize)
-{
- HRESULT hr = S_OK;
-
- assert(!m_pData);
- assert(dwSize == AlignToPowerOf2(dwSize, c_DataAlignment));
-
- m_dwBufferSize = dwSize;
-
- VN( m_pData = new uint8_t[m_dwBufferSize] );
-
- // make sure that we have machine word alignment
- assert(m_pData == AlignToPowerOf2(m_pData, c_DataAlignment));
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT CEffectHeap::AddString(const char *pString, char **ppPointer)
-{
- size_t size = strlen(pString) + 1;
- assert( size <= 0xffffffff );
- return AddData(pString, (uint32_t)size, (void**) ppPointer);
-}
-
-// This data is forcibly aligned, so make sure you account for that in calculating heap size
-template <bool bCopyData>
-HRESULT CEffectHeap::AddDataInternal(_In_reads_bytes_(dwSize) const void *pData, _In_ uint32_t dwSize, _Outptr_ void **ppPointer)
-{
- CCheckedDword chkFinalSize( m_dwSize );
- uint32_t finalSize;
- HRESULT hr = S_OK;
-
- chkFinalSize += dwSize;
- chkFinalSize += c_DataAlignment; // account for alignment
-
- VHD( chkFinalSize.GetValue(&finalSize), "Overflow while adding data to Effect heap." );
-
- // align original value
- finalSize = AlignToPowerOf2(finalSize - c_DataAlignment, c_DataAlignment);
- VBD( finalSize <= m_dwBufferSize, "Overflow adding data to Effect heap." );
-
- *ppPointer = m_pData + m_dwSize;
- assert(*ppPointer == AlignToPowerOf2(*ppPointer, c_DataAlignment));
-
- if( bCopyData )
- {
- memcpy(*ppPointer, pData, dwSize);
- }
- m_dwSize = finalSize;
-
-lExit:
- if (FAILED(hr))
- *ppPointer = nullptr;
-
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT CEffectHeap::AddData(const void *pData, uint32_t dwSize, void **ppPointer)
-{
- return AddDataInternal<true>( pData, dwSize, ppPointer );
-}
-
-// Moves a string from the general heap to the private heap and modifies the pointer to
-// point to the new memory block.
-// The general heap is freed as a whole, so we don't worry about leaking the given string pointer.
-// This data is forcibly aligned, so make sure you account for that in calculating heap size
-_Use_decl_annotations_
-HRESULT CEffectHeap::MoveString(char **ppString)
-{
- HRESULT hr;
- char *pNewPointer;
-
- if (*ppString == nullptr)
- return S_OK;
-
- hr = AddString(*ppString, &pNewPointer);
- if ( SUCCEEDED(hr) )
- *ppString = pNewPointer;
-
- return hr;
-}
-
-// Allocates space but does not move data
-// The general heap is freed as a whole, so we don't worry about leaking the given string pointer.
-// This data is forcibly aligned, so make sure you account for that in calculating heap size
-_Use_decl_annotations_
-HRESULT CEffectHeap::MoveEmptyDataBlock(void **ppData, uint32_t size)
-{
- HRESULT hr;
- void *pNewPointer;
-
- hr = AddDataInternal<false>(*ppData, size, &pNewPointer);
-
- if (SUCCEEDED(hr))
- {
- *ppData = pNewPointer;
- if (size == 0)
- {
- // To help catch bugs, set zero-byte blocks to null. There's no real reason to do this
- *ppData = nullptr;
- }
- }
-
- return hr;
-}
-
-// Moves an array of SInterfaceParameters from the general heap to the private heap and modifies the pointer to
-// point to the new memory block.
-// The general heap is freed as a whole, so we don't worry about leaking the given string pointer.
-// This data is forcibly aligned, so make sure you account for that in calculating heap size
-_Use_decl_annotations_
-HRESULT CEffectHeap::MoveInterfaceParameters(uint32_t InterfaceCount, SShaderBlock::SInterfaceParameter **ppInterfaces)
-{
- HRESULT hr;
- SShaderBlock::SInterfaceParameter *pNewPointer;
-
- if (*ppInterfaces == nullptr)
- return S_OK;
-
- VBD( InterfaceCount <= D3D11_SHADER_MAX_INTERFACES, "Internal loading error: InterfaceCount > D3D11_SHADER_MAX_INTERFACES." );
- VH( AddData(*ppInterfaces, InterfaceCount * sizeof(SShaderBlock::SInterfaceParameter), (void**)&pNewPointer) );
-
- for( size_t i=0; i < InterfaceCount; i++ )
- {
- VH( MoveString( &pNewPointer[i].pName ) );
- }
-
- *ppInterfaces = pNewPointer;
-
-lExit:
- return hr;
-}
-
-
-// Moves data from the general heap to the private heap and modifies the pointer to
-// point to the new memory block
-// The general heap is freed as a whole, so we don't worry about leaking the given pointer.
-// This data is forcibly aligned, so make sure you account for that in calculating heap size
-_Use_decl_annotations_
-HRESULT CEffectHeap::MoveData(void **ppData, uint32_t size)
-{
- HRESULT hr;
- void *pNewPointer;
-
- hr = AddData(*ppData, size, &pNewPointer);
- if ( SUCCEEDED(hr) )
- {
- *ppData = pNewPointer;
- if (size == 0)
- {
- // To help catch bugs, set zero-byte blocks to null. There's no real reason to do this
- *ppData = nullptr;
- }
- }
-
- return hr;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-// Load API
-//////////////////////////////////////////////////////////////////////////
-
-_Use_decl_annotations_
-HRESULT CEffect::LoadEffect(const void *pEffectBuffer, uint32_t cbEffectBuffer)
-{
- HRESULT hr = S_OK;
- CEffectLoader loader;
-
- if (!pEffectBuffer)
- {
- DPF(0, "%s: pEffectBuffer is nullptr.", g_szEffectLoadArea);
- VH( E_INVALIDARG );
- }
-
- VH( loader.LoadEffect(this, pEffectBuffer, cbEffectBuffer) );
-
-lExit:
- if( FAILED( hr ) )
- {
- // Release here because m_pShaderBlocks may still be in loader.m_BulkHeap if loading failed before we reallocated the memory
- ReleaseShaderRefection();
- }
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// CEffectLoader
-// A helper class which loads an effect
-//////////////////////////////////////////////////////////////////////////
-
-CEffectLoader::CEffectLoader() noexcept :
- m_pData(nullptr),
- m_pHeader(nullptr),
- m_Version(0),
- m_pEffect(nullptr),
- m_pReflection(nullptr),
- m_dwBufferSize(0),
- m_pOldVars(nullptr),
- m_pOldShaders(nullptr),
- m_pOldDS(nullptr),
- m_pOldAB(nullptr),
- m_pOldRS(nullptr),
- m_pOldCBs(nullptr),
- m_pOldSamplers(nullptr),
- m_OldInterfaceCount(0),
- m_pOldInterfaces(nullptr),
- m_pOldShaderResources(nullptr),
- m_pOldUnorderedAccessViews(nullptr),
- m_pOldRenderTargetViews(nullptr),
- m_pOldDepthStencilViews(nullptr),
- m_pOldStrings(nullptr),
- m_pOldMemberDataBlocks(nullptr),
- m_pvOldMemberInterfaces(nullptr),
- m_pOldGroups(nullptr),
- m_EffectMemory(0),
- m_ReflectionMemory(0)
-{
-}
-
-_Use_decl_annotations_
-HRESULT CEffectLoader::GetUnstructuredDataBlock(uint32_t offset, uint32_t *pdwSize, void **ppData)
-{
- HRESULT hr = S_OK;
- uint32_t *pBlockSize;
-
- VH( m_msUnstructured.ReadAtOffset(offset, sizeof(*pBlockSize), (void**) &pBlockSize ) );
- *pdwSize = *pBlockSize;
-
- VH( m_msUnstructured.Read(ppData, *pdwSize) );
-
-lExit:
- return hr;
-}
-
-// position in buffer is lost on error
-//
-// This function should be used in 1:1 conjunction with CEffectHeap::MoveString;
-// that is, any string added to the reflection heap with this function
-// must be relocated with MoveString at some point later on.
-_Use_decl_annotations_
-HRESULT CEffectLoader::GetStringAndAddToReflection(uint32_t offset, char **ppString)
-{
- HRESULT hr = S_OK;
- LPCSTR pName;
- size_t oldPos;
-
- if (offset == 0)
- {
- *ppString = nullptr;
- goto lExit;
- }
-
- oldPos = m_msUnstructured.GetPosition();
-
- VH( m_msUnstructured.ReadAtOffset(offset, &pName) );
- m_ReflectionMemory += AlignToPowerOf2( (uint32_t)strlen(pName) + 1, c_DataAlignment);
- *ppString = const_cast<char*>(pName);
-
- m_msUnstructured.Seek(oldPos);
-
-lExit:
- return hr;
-}
-
-// position in buffer is lost on error
-//
-// This function should be used in 1:1 conjunction with CEffectHeap::MoveInterfaceParameters;
-// that is, any array of parameters added to the reflection heap with this function
-// must be relocated with MoveInterfaceParameters at some point later on.
-_Use_decl_annotations_
-HRESULT CEffectLoader::GetInterfaceParametersAndAddToReflection( uint32_t InterfaceCount, uint32_t offset, SShaderBlock::SInterfaceParameter **ppInterfaces )
-{
- HRESULT hr = S_OK;
- SBinaryInterfaceInitializer* pInterfaceInitializer;
- size_t oldPos;
-
- if (offset == 0)
- {
- *ppInterfaces = nullptr;
- goto lExit;
- }
-
- oldPos = m_msUnstructured.GetPosition();
-
- VBD( InterfaceCount <= D3D11_SHADER_MAX_INTERFACES, "Internal loading error: InterfaceCount > D3D11_SHADER_MAX_INTERFACES." );
- m_ReflectionMemory += AlignToPowerOf2(InterfaceCount * sizeof(SShaderBlock::SInterfaceParameter), c_DataAlignment);
- assert( ppInterfaces != 0 );
- _Analysis_assume_( ppInterfaces != 0 );
- (*ppInterfaces) = PRIVATENEW SShaderBlock::SInterfaceParameter[InterfaceCount];
- VN( *ppInterfaces );
-
- VHD( m_msUnstructured.ReadAtOffset(offset, sizeof(SBinaryInterfaceInitializer) * InterfaceCount, (void**)&pInterfaceInitializer),
- "Invalid pEffectBuffer: cannot read interface initializer." );
-
- for( size_t i=0; i < InterfaceCount; i++ )
- {
- (*ppInterfaces)[i].Index = pInterfaceInitializer[i].ArrayIndex;
- VHD( m_msUnstructured.ReadAtOffset(pInterfaceInitializer[i].oInstanceName, const_cast<LPCSTR*>(&(*ppInterfaces)[i].pName)),
- "Invalid pEffectBuffer: cannot read interface initializer." );
- m_ReflectionMemory += AlignToPowerOf2( (uint32_t)strlen((*ppInterfaces)[i].pName) + 1, c_DataAlignment);
- }
-
- m_msUnstructured.Seek(oldPos);
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupCBPointer(_Inout_ SConstantBuffer **ppCB)
-{
- HRESULT hr = S_OK;
-
- size_t index = (SConstantBuffer*)*ppCB - m_pOldCBs;
- assert( index * sizeof(SConstantBuffer) == ((size_t)(SConstantBuffer*)*ppCB - (size_t)m_pOldCBs) );
- VBD( index < m_pEffect->m_CBCount, "Internal loading error: invalid constant buffer index." );
- *ppCB = (SConstantBuffer*)(m_pEffect->m_pCBs + index);
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupShaderPointer(_Inout_ SShaderBlock **ppShaderBlock)
-{
- HRESULT hr = S_OK;
- if (*ppShaderBlock != &g_NullVS && *ppShaderBlock != &g_NullGS && *ppShaderBlock != &g_NullPS &&
- *ppShaderBlock != &g_NullHS && *ppShaderBlock != &g_NullDS && *ppShaderBlock != &g_NullCS &&
- *ppShaderBlock != nullptr)
- {
- size_t index = *ppShaderBlock - m_pOldShaders;
- assert( index * sizeof(SShaderBlock) == ((size_t)*ppShaderBlock - (size_t)m_pOldShaders) );
- VBD( index < m_pEffect->m_ShaderBlockCount, "Internal loading error: invalid shader index." );
- *ppShaderBlock = m_pEffect->m_pShaderBlocks + index;
- }
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupDSPointer(_Inout_ SDepthStencilBlock **ppDSBlock)
-{
- HRESULT hr = S_OK;
- if (*ppDSBlock != &g_NullDepthStencil && *ppDSBlock != nullptr)
- {
- size_t index = *ppDSBlock - m_pOldDS;
- assert( index * sizeof(SDepthStencilBlock) == ((size_t)*ppDSBlock - (size_t)m_pOldDS) );
- VBD( index < m_pEffect->m_DepthStencilBlockCount, "Internal loading error: invalid depth-stencil state index." );
- *ppDSBlock = m_pEffect->m_pDepthStencilBlocks + index;
- }
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupABPointer(_Inout_ SBlendBlock **ppABBlock)
-{
- HRESULT hr = S_OK;
- if (*ppABBlock != &g_NullBlend && *ppABBlock != nullptr)
- {
- size_t index = *ppABBlock - m_pOldAB;
- assert( index * sizeof(SBlendBlock) == ((size_t)*ppABBlock - (size_t)m_pOldAB) );
- VBD( index < m_pEffect->m_BlendBlockCount, "Internal loading error: invalid blend state index." );
- *ppABBlock = m_pEffect->m_pBlendBlocks + index;
- }
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupRSPointer(_Inout_ SRasterizerBlock **ppRSBlock)
-{
- HRESULT hr = S_OK;
- if (*ppRSBlock != &g_NullRasterizer && *ppRSBlock != nullptr)
- {
- size_t index = *ppRSBlock - m_pOldRS;
- assert( index * sizeof(SRasterizerBlock) == ((size_t)*ppRSBlock - (size_t)m_pOldRS) );
- VBD( index < m_pEffect->m_RasterizerBlockCount, "Internal loading error: invalid rasterizer state index." );
- *ppRSBlock = m_pEffect->m_pRasterizerBlocks + index;
- }
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupSamplerPointer(_Inout_ SSamplerBlock **ppSampler)
-{
- HRESULT hr = S_OK;
- size_t index = *ppSampler - m_pOldSamplers;
- assert( index * sizeof(SSamplerBlock) == ((size_t)*ppSampler - (size_t)m_pOldSamplers) );
- VBD( index < m_pEffect->m_SamplerBlockCount, "Internal loading error: invalid sampler index." );
- *ppSampler = m_pEffect->m_pSamplerBlocks + index;
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupInterfacePointer(_Inout_ SInterface **ppInterface, _In_ bool CheckBackgroundInterfaces)
-{
- HRESULT hr = S_OK;
- if (*ppInterface != &g_NullInterface && *ppInterface != nullptr)
- {
- size_t index = *ppInterface - m_pOldInterfaces;
- if(index < m_OldInterfaceCount)
- {
- assert( index * sizeof(SInterface) == ((size_t)*ppInterface - (size_t)m_pOldInterfaces) );
- *ppInterface = m_pEffect->m_pInterfaces + index;
- }
- else
- {
- VBD( CheckBackgroundInterfaces, "Internal loading error: invalid interface pointer." );
- for( index=0; index < m_BackgroundInterfaces.GetSize(); index++ )
- {
- if( *ppInterface == m_BackgroundInterfaces[ (uint32_t)index ] )
- {
- // The interfaces m_BackgroundInterfaces were concatenated to the original ones in m_pEffect->m_pInterfaces
- *ppInterface = m_pEffect->m_pInterfaces + (m_OldInterfaceCount + index);
- break;
- }
- }
- VBD( index < m_BackgroundInterfaces.GetSize(), "Internal loading error: invalid interface pointer." );
- }
- }
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupShaderResourcePointer(_Inout_ SShaderResource **ppResource)
-{
- HRESULT hr = S_OK;
- if (*ppResource != &g_NullTexture && *ppResource != nullptr)
- {
- size_t index = *ppResource - m_pOldShaderResources;
- assert( index * sizeof(SShaderResource) == ((size_t)*ppResource - (size_t)m_pOldShaderResources) );
-
- // could be a TBuffer or a texture; better check first
- if (index < m_pEffect->m_ShaderResourceCount)
- {
- *ppResource = m_pEffect->m_pShaderResources + index;
- }
- else
- {
- // if this is a TBuffer, then the shader resource pointer
- // actually points into a SConstantBuffer's TBuffer field
- index = (SConstantBuffer*)*ppResource - (SConstantBuffer*)&m_pOldCBs->TBuffer;
- assert( index * sizeof(SConstantBuffer) == ((size_t)(SConstantBuffer*)*ppResource - (size_t)(SConstantBuffer*)&m_pOldCBs->TBuffer) );
- VBD( index < m_pEffect->m_CBCount, "Internal loading error: invalid SRV index." );
- *ppResource = &m_pEffect->m_pCBs[index].TBuffer;
- }
- }
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupUnorderedAccessViewPointer(_Inout_ SUnorderedAccessView **ppUnorderedAccessView)
-{
- HRESULT hr = S_OK;
- if (*ppUnorderedAccessView != &g_NullUnorderedAccessView && *ppUnorderedAccessView != nullptr)
- {
- size_t index = *ppUnorderedAccessView - m_pOldUnorderedAccessViews;
- assert( index * sizeof(SUnorderedAccessView) == ((size_t)*ppUnorderedAccessView - (size_t)m_pOldUnorderedAccessViews) );
-
- VBD( index < m_pEffect->m_UnorderedAccessViewCount, "Internal loading error: invalid UAV index." );
- *ppUnorderedAccessView = m_pEffect->m_pUnorderedAccessViews + index;
- }
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupRenderTargetViewPointer(_Inout_ SRenderTargetView **ppRenderTargetView)
-{
- HRESULT hr = S_OK;
- if (*ppRenderTargetView != &g_NullRenderTargetView && *ppRenderTargetView != nullptr)
- {
- size_t index = *ppRenderTargetView - m_pOldRenderTargetViews;
- assert( index * sizeof(SRenderTargetView) == ((size_t)*ppRenderTargetView - (size_t)m_pOldRenderTargetViews) );
- VBD( index < m_pEffect->m_RenderTargetViewCount, "Internal loading error: invalid RTV index." );
- *ppRenderTargetView = m_pEffect->m_pRenderTargetViews + index;
- }
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupDepthStencilViewPointer(_Inout_ SDepthStencilView **ppDepthStencilView)
-{
- HRESULT hr = S_OK;
- if (*ppDepthStencilView != &g_NullDepthStencilView && *ppDepthStencilView != nullptr)
- {
- size_t index = *ppDepthStencilView - m_pOldDepthStencilViews;
- assert( index * sizeof(SDepthStencilView) == ((size_t)*ppDepthStencilView - (size_t)m_pOldDepthStencilViews) );
- VBD( index < m_pEffect->m_DepthStencilViewCount, "Internal loading error: invalid DSV index." );
- *ppDepthStencilView = m_pEffect->m_pDepthStencilViews + index;
- }
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupStringPointer(_Inout_ SString **ppString)
-{
- HRESULT hr = S_OK;
- size_t index = *ppString - m_pOldStrings;
- assert( index * sizeof(SString) == ((size_t)*ppString - (size_t)m_pOldStrings) );
- VBD(index < m_pEffect->m_StringCount, "Internal loading error: invalid string index." );
- *ppString = m_pEffect->m_pStrings + index;
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupMemberDataPointer(_Inout_ SMemberDataPointer **ppMemberData)
-{
- HRESULT hr = S_OK;
- size_t index = *ppMemberData - m_pOldMemberDataBlocks;
- assert( index * sizeof(SMemberDataPointer) == ((size_t)*ppMemberData - (size_t)m_pOldMemberDataBlocks) );
- VBD( index < m_pEffect->m_MemberDataCount, "Internal loading error: invalid member block index." );
- *ppMemberData = m_pEffect->m_pMemberDataBlocks + index;
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupVariablePointer(_Inout_ SGlobalVariable **ppVar)
-{
- HRESULT hr = S_OK;
- size_t index = *ppVar - m_pOldVars;
-
- if( index < m_pEffect->m_VariableCount )
- {
- assert( index * sizeof(SGlobalVariable) == ((size_t)*ppVar - (size_t)m_pOldVars) );
- *ppVar = m_pEffect->m_pVariables + index;
- }
- else if( m_pvOldMemberInterfaces )
- {
- // When cloning, m_pvOldMemberInterfaces may be non-nullptr, and *ppVar may point to a variable in it.
- const size_t Members = m_pvOldMemberInterfaces->GetSize();
- for( index=0; index < Members; index++ )
- {
- if( (ID3DX11EffectVariable*)(*m_pvOldMemberInterfaces)[ (uint32_t)index] == (ID3DX11EffectVariable*)*ppVar )
- {
- break;
- }
- }
- VBD( index < Members, "Internal loading error: invalid member pointer." );
- *ppVar = (SGlobalVariable*)m_pEffect->m_pMemberInterfaces[ (uint32_t)index];
- }
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::FixupGroupPointer(_Inout_ SGroup **ppGroup)
-{
- HRESULT hr = S_OK;
- if( *ppGroup != nullptr )
- {
- size_t index = *ppGroup - m_pOldGroups;
- assert( index * sizeof(SGroup) == ((size_t)*ppGroup - (size_t)m_pOldGroups) );
- VBD( index < m_pEffect->m_GroupCount, "Internal loading error: invalid group index." );
- *ppGroup = m_pEffect->m_pGroups + index;
- }
-lExit:
- return hr;
-}
-
-static HRESULT GetEffectVersion( _In_ uint32_t effectFileTag, _Out_ DWORD* pVersion )
-{
- assert( pVersion != nullptr );
- if( !pVersion )
- return E_FAIL;
-
- for( size_t i = 0; i < _countof(g_EffectVersions); i++ )
- {
- if( g_EffectVersions[i].m_Tag == effectFileTag )
- {
- *pVersion = g_EffectVersions[i].m_Version;
- return S_OK;
- }
- }
-
- return E_FAIL;
-}
-
-_Use_decl_annotations_
-HRESULT CEffectLoader::LoadEffect(CEffect *pEffect, const void *pEffectBuffer, uint32_t cbEffectBuffer)
-{
-
- HRESULT hr = S_OK;
- uint32_t i, varSize, cMemberDataBlocks;
- CCheckedDword chkVariables = 0;
-
- // Used for cloning
- m_pvOldMemberInterfaces = nullptr;
-
- m_BulkHeap.EnableAlignment();
-
- assert(pEffect && pEffectBuffer);
- m_pEffect = pEffect;
- m_EffectMemory = m_ReflectionMemory = 0;
-
- VN( m_pEffect->m_pReflection = new CEffectReflection() );
- m_pReflection = m_pEffect->m_pReflection;
-
- // Begin effect load
- VN( m_pEffect->m_pTypePool = new CEffect::CTypeHashTable );
- VN( m_pEffect->m_pStringPool = new CEffect::CStringHashTable );
- VN( m_pEffect->m_pPooledHeap = new CDataBlockStore );
- m_pEffect->m_pPooledHeap->EnableAlignment();
- m_pEffect->m_pTypePool->SetPrivateHeap(m_pEffect->m_pPooledHeap);
- m_pEffect->m_pStringPool->SetPrivateHeap(m_pEffect->m_pPooledHeap);
-
- VH( m_pEffect->m_pTypePool->AutoGrow() );
- VH( m_pEffect->m_pStringPool->AutoGrow() );
-
- // Load from blob
- m_pData = (uint8_t*)pEffectBuffer;
- m_dwBufferSize = cbEffectBuffer;
-
- VH( m_msStructured.SetData(m_pData, m_dwBufferSize) );
-
- // At this point, we assume that the blob is valid
- VHD( m_msStructured.Read((void**) &m_pHeader, sizeof(*m_pHeader)), "pEffectBuffer is too small." );
-
- // Verify the version
- if( FAILED( hr = GetEffectVersion( m_pHeader->Tag, &m_Version ) ) )
- {
- DPF(0, "Effect version is unrecognized. This runtime supports fx_5_0 to %s.", g_EffectVersions[_countof(g_EffectVersions)-1].m_pName );
- VH( hr );
- }
-
- if( m_pHeader->RequiresPool() || m_pHeader->Pool.cObjectVariables > 0 || m_pHeader->Pool.cNumericVariables > 0 )
- {
- DPF(0, "Effect11 does not support EffectPools." );
- VH( E_FAIL );
- }
-
- // Get shader block count
- VBD( m_pHeader->cInlineShaders <= m_pHeader->cTotalShaders, "Invalid Effect header: cInlineShaders > cTotalShaders." );
-
- // Make sure the counts for the Effect don't overflow
- chkVariables = m_pHeader->Effect.cObjectVariables;
- chkVariables += m_pHeader->Effect.cNumericVariables;
- chkVariables += m_pHeader->cInterfaceVariables;
- chkVariables *= sizeof(SGlobalVariable);
- VH( chkVariables.GetValue(&varSize) );
-
- // Make sure the counts for the SMemberDataPointers don't overflow
- chkVariables = m_pHeader->cClassInstanceElements;
- chkVariables += m_pHeader->cBlendStateBlocks;
- chkVariables += m_pHeader->cRasterizerStateBlocks;
- chkVariables += m_pHeader->cDepthStencilBlocks;
- chkVariables += m_pHeader->cSamplers;
- chkVariables += m_pHeader->Effect.cCBs; // Buffer (for CBuffers and TBuffers)
- chkVariables += m_pHeader->Effect.cCBs; // SRV (for TBuffers)
- VHD( chkVariables.GetValue(&cMemberDataBlocks), "Overflow: too many Effect variables." );
-
- // Allocate effect resources
- VN( m_pEffect->m_pCBs = PRIVATENEW SConstantBuffer[m_pHeader->Effect.cCBs] );
- VN( m_pEffect->m_pDepthStencilBlocks = PRIVATENEW SDepthStencilBlock[m_pHeader->cDepthStencilBlocks] );
- VN( m_pEffect->m_pRasterizerBlocks = PRIVATENEW SRasterizerBlock[m_pHeader->cRasterizerStateBlocks] );
- VN( m_pEffect->m_pBlendBlocks = PRIVATENEW SBlendBlock[m_pHeader->cBlendStateBlocks] );
- VN( m_pEffect->m_pSamplerBlocks = PRIVATENEW SSamplerBlock[m_pHeader->cSamplers] );
-
- // we allocate raw bytes for variables because they are polymorphic types that need to be placement new'ed
- VN( m_pEffect->m_pVariables = (SGlobalVariable *)PRIVATENEW uint8_t[varSize] );
- VN( m_pEffect->m_pAnonymousShaders = PRIVATENEW SAnonymousShader[m_pHeader->cInlineShaders] );
-
- VN( m_pEffect->m_pGroups = PRIVATENEW SGroup[m_pHeader->cGroups] );
- VN( m_pEffect->m_pShaderBlocks = PRIVATENEW SShaderBlock[m_pHeader->cTotalShaders] );
- VN( m_pEffect->m_pStrings = PRIVATENEW SString[m_pHeader->cStrings] );
- VN( m_pEffect->m_pShaderResources = PRIVATENEW SShaderResource[m_pHeader->cShaderResources] );
- VN( m_pEffect->m_pUnorderedAccessViews = PRIVATENEW SUnorderedAccessView[m_pHeader->cUnorderedAccessViews] );
- VN( m_pEffect->m_pInterfaces = PRIVATENEW SInterface[m_pHeader->cInterfaceVariableElements] );
- VN( m_pEffect->m_pMemberDataBlocks = PRIVATENEW SMemberDataPointer[cMemberDataBlocks] );
- VN( m_pEffect->m_pRenderTargetViews = PRIVATENEW SRenderTargetView[m_pHeader->cRenderTargetViews] );
- VN( m_pEffect->m_pDepthStencilViews = PRIVATENEW SDepthStencilView[m_pHeader->cDepthStencilViews] );
-
- uint32_t oStructured = m_pHeader->cbUnstructured + sizeof(SBinaryHeader5);
- VHD( m_msStructured.Seek(oStructured), "Invalid pEffectBuffer: Missing structured data block." );
- VH( m_msUnstructured.SetData(m_pData + sizeof(SBinaryHeader5), oStructured - sizeof(SBinaryHeader5)) );
-
- VH( LoadCBs() );
- VH( LoadObjectVariables() );
- VH( LoadInterfaceVariables() );
- VH( LoadGroups() );
-
- // Build shader dependencies
- for (i=0; i<m_pEffect->m_ShaderBlockCount; i++)
- {
- VH( BuildShaderBlock(&m_pEffect->m_pShaderBlocks[i]) );
- }
-
- for( size_t iGroup=0; iGroup<m_pHeader->cGroups; iGroup++ )
- {
- SGroup *pGroup = &m_pEffect->m_pGroups[iGroup];
- pGroup->HasDependencies = false;
-
- for( size_t iTechnique=0; iTechnique < pGroup->TechniqueCount; iTechnique++ )
- {
- STechnique* pTech = &pGroup->pTechniques[iTechnique];
- pTech->HasDependencies = false;
-
- for( size_t iPass=0; iPass < pTech->PassCount; iPass++ )
- {
- SPassBlock *pPass = &pTech->pPasses[iPass];
-
- pTech->HasDependencies |= pPass->CheckDependencies();
- }
- pGroup->HasDependencies |= pTech->HasDependencies;
- }
- }
-
- VH( InitializeReflectionDataAndMoveStrings() );
- VH( ReallocateReflectionData() );
- VH( ReallocateEffectData() );
-
- VB( m_pReflection->m_Heap.GetSize() == m_ReflectionMemory );
-
- // Verify that all of the various block/variable types were loaded
- VBD( m_pEffect->m_VariableCount == (m_pHeader->Effect.cObjectVariables + m_pHeader->Effect.cNumericVariables + m_pHeader->cInterfaceVariables), "Internal loading error: mismatched variable count." );
- VBD( m_pEffect->m_ShaderBlockCount == m_pHeader->cTotalShaders, "Internal loading error: mismatched shader block count." );
- VBD( m_pEffect->m_AnonymousShaderCount == m_pHeader->cInlineShaders, "Internal loading error: mismatched anonymous variable count." );
- VBD( m_pEffect->m_ShaderResourceCount == m_pHeader->cShaderResources, "Internal loading error: mismatched SRV count." );
- VBD( m_pEffect->m_InterfaceCount == m_pHeader->cInterfaceVariableElements + m_BackgroundInterfaces.GetSize(), "Internal loading error: mismatched interface count." );
- VBD( m_pEffect->m_UnorderedAccessViewCount == m_pHeader->cUnorderedAccessViews, "Internal loading error: mismatched UAV count." );
- VBD( m_pEffect->m_MemberDataCount == cMemberDataBlocks, "Internal loading error: mismatched member data block count." );
- VBD( m_pEffect->m_RenderTargetViewCount == m_pHeader->cRenderTargetViews, "Internal loading error: mismatched RTV count." );
- VBD( m_pEffect->m_DepthStencilViewCount == m_pHeader->cDepthStencilViews, "Internal loading error: mismatched DSV count." );
- VBD( m_pEffect->m_DepthStencilBlockCount == m_pHeader->cDepthStencilBlocks, "Internal loading error: mismatched depth-stencil state count." );
- VBD( m_pEffect->m_BlendBlockCount == m_pHeader->cBlendStateBlocks, "Internal loading error: mismatched blend state count." );
- VBD( m_pEffect->m_RasterizerBlockCount == m_pHeader->cRasterizerStateBlocks, "Internal loading error: mismatched rasterizer state count." );
- VBD( m_pEffect->m_SamplerBlockCount == m_pHeader->cSamplers, "Internal loading error: mismatched sampler count." );
- VBD( m_pEffect->m_StringCount == m_pHeader->cStrings, "Internal loading error: mismatched string count." );
-
- // Uncomment if you really need this information
- // DPF(0, "Effect heap size: %d, reflection heap size: %d, allocations avoided: %d", m_EffectMemory, m_ReflectionMemory, m_BulkHeap.m_cAllocations);
-
-lExit:
- return hr;
-}
-
-// position in buffer is lost on error
-_Use_decl_annotations_
-HRESULT CEffectLoader::LoadStringAndAddToPool(char **ppString, uint32_t dwOffset)
-{
- HRESULT hr = S_OK;
- char *pName;
- uint32_t hash;
- size_t oldPos;
- CEffect::CStringHashTable::CIterator iter;
- uint32_t len;
-
- if (dwOffset == 0)
- {
- *ppString = nullptr;
- goto lExit;
- }
-
- oldPos = m_msUnstructured.GetPosition();
-
- VHD( m_msUnstructured.ReadAtOffset(dwOffset, (LPCSTR *) &pName), "Invalid pEffectBuffer: cannot read string." );
- len = (uint32_t)strlen(pName);
- hash = ComputeHash((uint8_t *)pName, len);
- if (FAILED(m_pEffect->m_pStringPool->FindValueWithHash(pName, hash, &iter)))
- {
- assert( m_pEffect->m_pPooledHeap != 0 );
- _Analysis_assume_( m_pEffect->m_pPooledHeap != 0 );
- VN( (*ppString) = new(*m_pEffect->m_pPooledHeap) char[len + 1] );
- memcpy(*ppString, pName, len + 1);
- VHD( m_pEffect->m_pStringPool->AddValueWithHash(*ppString, hash), "Internal loading error: failed to add string to pool." );
- }
- else
- {
- *ppString = const_cast<LPSTR>(iter.GetData());
- }
-
- m_msUnstructured.Seek(oldPos);
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT CEffectLoader::LoadTypeAndAddToPool(SType **ppType, uint32_t dwOffset)
-{
- HRESULT hr = S_OK;
- SBinaryType *psType;
- SBinaryNumericType *pNumericType;
- EObjectType *pObjectType;
- uint32_t cMembers, iMember, cInterfaces;
- uint32_t oBaseClassType;
- SType temporaryType;
- CEffect::CTypeHashTable::CIterator iter;
- uint8_t *pHashBuffer;
- uint32_t hash;
- SVariable *pTempMembers = nullptr;
-
- m_HashBuffer.Empty();
-
- VHD( m_msUnstructured.ReadAtOffset(dwOffset, sizeof(SBinaryType), (void**) &psType), "Invalid pEffectBuffer: cannot read type." );
- VHD( LoadStringAndAddToPool(&temporaryType.pTypeName, psType->oTypeName), "Invalid pEffectBuffer: cannot read type name." );
- temporaryType.VarType = psType->VarType;
- temporaryType.Elements = psType->Elements;
- temporaryType.TotalSize = psType->TotalSize;
- temporaryType.Stride = psType->Stride;
- temporaryType.PackedSize = psType->PackedSize;
-
- // sanity check elements, size, stride, etc.
- uint32_t cElements = std::max<uint32_t>(1, temporaryType.Elements);
- VBD( cElements * temporaryType.Stride == AlignToPowerOf2(temporaryType.TotalSize, SType::c_RegisterSize), "Invalid pEffectBuffer: invalid type size." );
- VBD( temporaryType.Stride % SType::c_RegisterSize == 0, "Invalid pEffectBuffer: invalid type stride." );
- VBD( temporaryType.PackedSize <= temporaryType.TotalSize && temporaryType.PackedSize % cElements == 0, "Invalid pEffectBuffer: invalid type packed size." );
-
- switch(temporaryType.VarType)
- {
- case EVT_Object:
- VHD( m_msUnstructured.Read((void**) &pObjectType, sizeof(uint32_t)), "Invalid pEffectBuffer: cannot read object type." );
- temporaryType.ObjectType = *pObjectType;
- VBD( temporaryType.VarType > EOT_Invalid && temporaryType.VarType < EOT_Count, "Invalid pEffectBuffer: invalid object type." );
-
- VN( pHashBuffer = m_HashBuffer.AddRange(sizeof(temporaryType.VarType) + sizeof(temporaryType.Elements) +
- sizeof(temporaryType.pTypeName) + sizeof(temporaryType.ObjectType)) );
- memcpy(pHashBuffer, &temporaryType.VarType, sizeof(temporaryType.VarType));
- pHashBuffer += sizeof(temporaryType.VarType);
- memcpy(pHashBuffer, &temporaryType.Elements, sizeof(temporaryType.Elements));
- pHashBuffer += sizeof(temporaryType.Elements);
- memcpy(pHashBuffer, &temporaryType.pTypeName, sizeof(temporaryType.pTypeName));
- pHashBuffer += sizeof(temporaryType.pTypeName);
- memcpy(pHashBuffer, &temporaryType.ObjectType, sizeof(temporaryType.ObjectType));
- break;
-
- case EVT_Interface:
- temporaryType.InterfaceType = nullptr;
-
- VN( pHashBuffer = m_HashBuffer.AddRange(sizeof(temporaryType.VarType) + sizeof(temporaryType.Elements) +
- sizeof(temporaryType.pTypeName) + sizeof(temporaryType.ObjectType)) );
- memcpy(pHashBuffer, &temporaryType.VarType, sizeof(temporaryType.VarType));
- pHashBuffer += sizeof(temporaryType.VarType);
- memcpy(pHashBuffer, &temporaryType.Elements, sizeof(temporaryType.Elements));
- pHashBuffer += sizeof(temporaryType.Elements);
- memcpy(pHashBuffer, &temporaryType.pTypeName, sizeof(temporaryType.pTypeName));
- pHashBuffer += sizeof(temporaryType.pTypeName);
- memcpy(pHashBuffer, &temporaryType.ObjectType, sizeof(temporaryType.ObjectType));
- break;
-
- case EVT_Numeric:
- VHD( m_msUnstructured.Read((void**) &pNumericType, sizeof(SBinaryNumericType)), "Invalid pEffectBuffer: cannot read numeric type." );
- temporaryType.NumericType = *pNumericType;
- VBD( temporaryType.NumericType.Rows >= 1 && temporaryType.NumericType.Rows <= 4 &&
- temporaryType.NumericType.Columns >= 1 && temporaryType.NumericType.Columns <= 4 &&
- temporaryType.NumericType.NumericLayout != ENL_Invalid && temporaryType.NumericType.NumericLayout < ENL_Count &&
- temporaryType.NumericType.ScalarType > EST_Invalid && temporaryType.NumericType.ScalarType < EST_Count,
- "Invalid pEffectBuffer: invalid numeric type.");
-
- if (temporaryType.NumericType.NumericLayout != ENL_Matrix)
- {
- VBD( temporaryType.NumericType.IsColumnMajor == false, "Invalid pEffectBuffer: only matricies can be column major." );
- }
-
- VN( pHashBuffer = m_HashBuffer.AddRange(sizeof(temporaryType.VarType) + sizeof(temporaryType.Elements) +
- sizeof(temporaryType.pTypeName) + sizeof(temporaryType.NumericType)) );
- memcpy(pHashBuffer, &temporaryType.VarType, sizeof(temporaryType.VarType));
- pHashBuffer += sizeof(temporaryType.VarType);
- memcpy(pHashBuffer, &temporaryType.Elements, sizeof(temporaryType.Elements));
- pHashBuffer += sizeof(temporaryType.Elements);
- memcpy(pHashBuffer, &temporaryType.pTypeName, sizeof(temporaryType.pTypeName));
- pHashBuffer += sizeof(temporaryType.pTypeName);
- memcpy(pHashBuffer, &temporaryType.NumericType, sizeof(temporaryType.NumericType));
- break;
-
- case EVT_Struct:
- VHD( m_msUnstructured.Read(&cMembers), "Invalid pEffectBuffer: cannot read struct." );
-
- temporaryType.StructType.Members = cMembers;
-
- VN( pTempMembers = new SVariable[cMembers] );
- temporaryType.StructType.pMembers = pTempMembers;
-
- // read up all of the member descriptors at once
- SBinaryType::SBinaryMember *psMember;
- VHD( m_msUnstructured.Read((void**) &psMember, cMembers * sizeof(*psMember)), "Invalid pEffectBuffer: cannot read struct members." );
-
- {
- // Determine if this type implements an interface
- VHD( m_msUnstructured.Read(&oBaseClassType), "Invalid pEffectBuffer: cannot read base class type." );
- VHD( m_msUnstructured.Read(&cInterfaces), "Invalid pEffectBuffer: cannot read interfaces." );
- if( cInterfaces > 0 )
- {
- temporaryType.StructType.ImplementsInterface = 1;
- temporaryType.StructType.HasSuperClass = ( oBaseClassType > 0 ) ? 1 : 0;
- }
- else if( oBaseClassType > 0 )
- {
- // Get parent type and copy its ImplementsInterface
- SType* pBaseClassType;
- VH( LoadTypeAndAddToPool(&pBaseClassType, oBaseClassType) );
- temporaryType.StructType.ImplementsInterface = pBaseClassType->StructType.ImplementsInterface;
- temporaryType.StructType.HasSuperClass = 1;
- }
- // Read (and ignore) the interface types
- uint32_t *poInterface;
- VHD( m_msUnstructured.Read((void**) &poInterface, cInterfaces * sizeof(poInterface)), "Invalid pEffectBuffer: cannot read interface types." );
- }
-
- uint32_t totalSize;
- totalSize = 0;
- for (iMember=0; iMember<cMembers; iMember++)
- {
- SVariable *pMember;
-
- pMember = temporaryType.StructType.pMembers + iMember;
-
- VBD( psMember[iMember].Offset == totalSize ||
- psMember[iMember].Offset == AlignToPowerOf2(totalSize, SType::c_RegisterSize),
- "Internal loading error: invalid member offset." );
-
- pMember->Data.Offset = psMember[iMember].Offset;
-
- VH( LoadTypeAndAddToPool(&pMember->pType, psMember[iMember].oType) );
- VH( LoadStringAndAddToPool(&pMember->pName, psMember[iMember].oName) );
- VH( LoadStringAndAddToPool(&pMember->pSemantic, psMember[iMember].oSemantic) );
-
- totalSize = psMember[iMember].Offset + pMember->pType->TotalSize;
- }
- VBD( AlignToPowerOf2(totalSize, SType::c_RegisterSize) == temporaryType.Stride, "Internal loading error: invlid type size." );
-
- VN( pHashBuffer = m_HashBuffer.AddRange(sizeof(temporaryType.VarType) + sizeof(temporaryType.Elements) +
- sizeof(temporaryType.pTypeName) + sizeof(temporaryType.StructType.Members) + cMembers * sizeof(SVariable)) );
-
- memcpy(pHashBuffer, &temporaryType.VarType, sizeof(temporaryType.VarType));
- pHashBuffer += sizeof(temporaryType.VarType);
- memcpy(pHashBuffer, &temporaryType.Elements, sizeof(temporaryType.Elements));
- pHashBuffer += sizeof(temporaryType.Elements);
- memcpy(pHashBuffer, &temporaryType.pTypeName, sizeof(temporaryType.pTypeName));
- pHashBuffer += sizeof(temporaryType.pTypeName);
- memcpy(pHashBuffer, &temporaryType.StructType.Members, sizeof(temporaryType.StructType.Members));
- pHashBuffer += sizeof(temporaryType.StructType.Members);
- memcpy(pHashBuffer, temporaryType.StructType.pMembers, cMembers * sizeof(SVariable));
- break;
-
- default:
- assert(0);
- VHD( E_FAIL, "Internal loading error: invalid variable type." );
- }
-
- hash = ComputeHash(&m_HashBuffer[0], m_HashBuffer.GetSize());
- if (FAILED(m_pEffect->m_pTypePool->FindValueWithHash(&temporaryType, hash, &iter)))
- {
- assert( m_pEffect->m_pPooledHeap != nullptr );
-
- // allocate real member array, if necessary
- if (temporaryType.VarType == EVT_Struct)
- {
- VN( temporaryType.StructType.pMembers = new(*m_pEffect->m_pPooledHeap) SVariable[temporaryType.StructType.Members] );
- memcpy(temporaryType.StructType.pMembers, pTempMembers, temporaryType.StructType.Members * sizeof(SVariable));
- }
-
- // allocate real type
- VN( (*ppType) = new(*m_pEffect->m_pPooledHeap) SType );
- memcpy(*ppType, &temporaryType, sizeof(temporaryType));
- ZeroMemory(&temporaryType, sizeof(temporaryType));
- VH( m_pEffect->m_pTypePool->AddValueWithHash(*ppType, hash) );
- }
- else
- {
- *ppType = iter.GetData();
- }
-
-lExit:
- SAFE_DELETE_ARRAY(pTempMembers);
- return hr;
-}
-
-// Numeric data in annotations are tightly packed (unlike in CBs which follow D3D11 packing rules). This unpacks them.
-uint32_t CEffectLoader::UnpackData(uint8_t *pDestData, uint8_t *pSrcData, uint32_t PackedDataSize, SType *pType, uint32_t *pBytesRead)
-{
- uint32_t bytesRead = 0;
- HRESULT hr = S_OK;
- uint32_t elementsToCopy = std::max<uint32_t>(pType->Elements, 1);
-
- switch (pType->VarType)
- {
- case EVT_Struct:
- for (size_t i = 0; i < elementsToCopy; ++ i)
- {
- for (size_t j = 0; j < pType->StructType.Members; ++ j)
- {
- uint32_t br;
- assert(PackedDataSize > bytesRead);
-
- VH( UnpackData(pDestData + pType->StructType.pMembers[j].Data.Offset,
- pSrcData + bytesRead, PackedDataSize - bytesRead,
- pType->StructType.pMembers[j].pType, &br) );
-
- bytesRead += br;
- }
- pDestData += pType->Stride;
- }
- break;
-
- case EVT_Numeric:
- if (pType->NumericType.IsPackedArray)
- {
- // No support for packed arrays
- assert(0);
- VHD(E_FAIL, "Internal loading error: packed arrays are not supported." );
- }
- else
- {
- uint32_t bytesToCopy;
-
- if (pType->NumericType.IsColumnMajor)
- {
- uint32_t registers = pType->NumericType.Columns;
- uint32_t entries = pType->NumericType.Rows;
- bytesToCopy = entries * registers * SType::c_ScalarSize;
-
- for (size_t i = 0; i < elementsToCopy; ++ i)
- {
- for (size_t j = 0; j < registers; ++ j)
- {
- for (size_t k = 0; k < entries; ++ k)
- {
- // type cast to an arbitrary scalar
- ((uint32_t*)pDestData)[k] = ((uint32_t*)pSrcData)[k * registers + j];
- }
- pDestData += SType::c_RegisterSize; // advance to next register
- }
- pSrcData += bytesToCopy;
- bytesRead += bytesToCopy;
- }
- }
- else
- {
- uint32_t registers = pType->NumericType.Rows;
- uint32_t entries = pType->NumericType.Columns;
- bytesToCopy = entries * SType::c_ScalarSize;
-
- for (size_t i = 0; i < elementsToCopy; ++ i)
- {
- for (size_t j = 0; j < registers; ++ j)
- {
- memcpy(pDestData, pSrcData, bytesToCopy);
-
- pDestData += SType::c_RegisterSize; // advance to next register
- pSrcData += bytesToCopy;
- bytesRead += bytesToCopy;
- }
- }
- }
- }
- break;
-
- default:
- // shouldn't be called on non-struct/numeric types
- assert(0);
- VHD(E_FAIL, "Internal loading error: UnpackData should not be called on non-struct, non-numeric types." );
- }
-
-lExit:
- *pBytesRead = bytesRead;
- return hr;
-}
-
-// Read info from the compiled blob and initialize a numeric variable
-HRESULT CEffectLoader::LoadNumericVariable(_In_ SConstantBuffer *pParentCB)
-{
- HRESULT hr = S_OK;
- SBinaryNumericVariable *psVar;
- SGlobalVariable *pVar;
- SType *pType;
- void *pDefaultValue;
-
- // Read variable info
- VHD( m_msStructured.Read((void**) &psVar, sizeof(*psVar)), "Invalid pEffectBuffer: cannot read numeric variable." );
- VBD( m_pEffect->m_VariableCount < (m_pHeader->Effect.cObjectVariables + m_pHeader->Effect.cNumericVariables + m_pHeader->cInterfaceVariables),
- "Internal loading error: invalid variable counts.");
- pVar = &m_pEffect->m_pVariables[m_pEffect->m_VariableCount];
-
- // Get type
- VH( LoadTypeAndAddToPool(&pType, psVar->oType) );
-
- // Make sure the right polymorphic type is created
- VH( PlacementNewVariable(pVar, pType, false) );
-
- if (psVar->Flags & D3DX11_EFFECT_VARIABLE_EXPLICIT_BIND_POINT)
- {
- pVar->ExplicitBindPoint = psVar->Offset;
- }
- else
- {
- pVar->ExplicitBindPoint = uint32_t(-1);
- }
-
- pVar->pEffect = m_pEffect;
- pVar->pType = pType;
- pVar->pCB = pParentCB;
- pVar->Data.pGeneric = pParentCB->pBackingStore + psVar->Offset;
- VBD( psVar->Offset + pVar->pType->TotalSize <= pVar->pCB->Size, "Invalid pEffectBuffer: invalid variable offset." );
-
- if (pType->VarType == EVT_Struct && pType->StructType.ImplementsInterface && !pParentCB->IsTBuffer)
- {
- pVar->MemberDataOffsetPlus4 = m_pEffect->m_MemberDataCount * sizeof(SMemberDataPointer) + 4;
- m_pEffect->m_MemberDataCount += std::max<uint32_t>(pType->Elements,1);
- }
-
- // Get name & semantic
- VHD( GetStringAndAddToReflection(psVar->oName, &pVar->pName), "Invalid pEffectBuffer: cannot read variable name." );
- VHD( GetStringAndAddToReflection(psVar->oSemantic, &pVar->pSemantic), "Invalid pEffectBuffer: cannot read variable semantic." );
-
- // Ensure the variable fits in the CBuffer and doesn't overflow
- VBD( pType->TotalSize + psVar->Offset <= pParentCB->Size &&
- pType->TotalSize + psVar->Offset >= pType->TotalSize, "Invalid pEffectBuffer: variable does not fit in CB." );
-
- ZeroMemory(pVar->Data.pGeneric, pType->TotalSize);
-
- // Get default value
- if (0 != psVar->oDefaultValue)
- {
- uint32_t bytesUnpacked;
- VHD( m_msUnstructured.ReadAtOffset(psVar->oDefaultValue, pType->PackedSize, &pDefaultValue), "Invalid pEffectBuffer: cannot read default value." );
- VH( UnpackData((uint8_t*) pVar->Data.pGeneric, (uint8_t*) pDefaultValue, pType->PackedSize, pType, &bytesUnpacked) );
- VBD( bytesUnpacked == pType->PackedSize, "Invalid pEffectBuffer: invalid type packed size.");
- }
-
- // We need to use offsets until we fixup
- pVar->Data.Offset = psVar->Offset;
-
- // Read annotations
- VH( LoadAnnotations(&pVar->AnnotationCount, &pVar->pAnnotations) );
-
- m_pEffect->m_VariableCount++;
-
-lExit:
- return hr;
-}
-
-// Read info from the compiled blob and initialize a constant buffer
-HRESULT CEffectLoader::LoadCBs()
-{
- HRESULT hr = S_OK;
- uint32_t iCB, iVar;
-
- for (iCB=0; iCB<m_pHeader->Effect.cCBs; iCB++)
- {
- SBinaryConstantBuffer *psCB;
- SConstantBuffer *pCB;
-
- VHD( m_msStructured.Read((void**) &psCB, sizeof(*psCB)), "Invalid pEffectBuffer: cannot read CB." );
- pCB = &m_pEffect->m_pCBs[iCB];
-
- VHD( GetStringAndAddToReflection(psCB->oName, &pCB->pName), "Invalid pEffectBuffer: cannot read CB name." );
-
- pCB->IsTBuffer = (psCB->Flags & SBinaryConstantBuffer::c_IsTBuffer) != 0 ? true : false;
- pCB->IsSingle = (psCB->Flags & SBinaryConstantBuffer::c_IsSingle) != 0 ? true : false;
- pCB->Size = psCB->Size;
- pCB->ExplicitBindPoint = psCB->ExplicitBindPoint;
- VBD( pCB->Size == AlignToPowerOf2(pCB->Size, SType::c_RegisterSize), "Invalid pEffectBuffer: CB size not a power of 2." );
- VN( pCB->pBackingStore = PRIVATENEW uint8_t[pCB->Size] );
-
- pCB->MemberDataOffsetPlus4 = m_pEffect->m_MemberDataCount * sizeof(SMemberDataPointer) + 4;
- m_pEffect->m_MemberDataCount += 2;
-
- // point this CB to variables that it owns
- pCB->VariableCount = psCB->cVariables;
- if (pCB->VariableCount > 0)
- {
- pCB->pVariables = &m_pEffect->m_pVariables[m_pEffect->m_VariableCount];
- }
- else
- {
- pCB->pVariables = nullptr;
- }
-
- // Read annotations
- VH( LoadAnnotations(&pCB->AnnotationCount, &pCB->pAnnotations) );
-
- for (iVar=0; iVar<psCB->cVariables; iVar++)
- {
- VH( LoadNumericVariable(pCB) );
- }
- }
-
- m_pEffect->m_CBCount = m_pHeader->Effect.cCBs;
-
-lExit:
- return hr;
-}
-
-// Used by LoadAssignment to initialize members on load
-_Use_decl_annotations_
-HRESULT CEffectLoader::ExecuteConstantAssignment(const SBinaryConstant *pConstant, void *pLHS, D3D_SHADER_VARIABLE_TYPE lhsType)
-{
- HRESULT hr = S_OK;
-
- switch(pConstant->Type)
- {
- case EST_UInt:
- case EST_Int:
- case EST_Bool:
- switch(lhsType)
- {
- case D3D_SVT_BOOL:
- case D3D_SVT_INT:
- case D3D_SVT_UINT:
- *(uint32_t*) pLHS = pConstant->iValue;
- break;
-
- case D3D_SVT_UINT8:
- *(uint8_t*) pLHS = (uint8_t) pConstant->iValue;
- break;
-
- case D3D_SVT_FLOAT:
- *(float*) pLHS = (float) pConstant->iValue;
- break;
-
- default:
- VHD( E_FAIL, "Internal loading error: invalid left-hand assignment type." );
- }
- break;
-
- case EST_Float:
- switch(lhsType)
- {
- case D3D_SVT_BOOL:
- case D3D_SVT_INT:
- case D3D_SVT_UINT:
- *(uint32_t*) pLHS = (uint32_t) pConstant->fValue;
- break;
-
- case D3D_SVT_UINT8:
- *(uint8_t*) pLHS = (uint8_t) pConstant->fValue;
- break;
-
- case D3D_SVT_FLOAT:
- *(float*) pLHS = pConstant->fValue;
- break;
-
- default:
- VHD( E_FAIL, "Internal loading error: invalid left-hand assignment type." );
- }
- break;
-
- default:
- VHD( E_FAIL, "Internal loading error: invalid left-hand assignment type." );
- }
-
-lExit:
- return hr;
-}
-
-
-// Read info from the compiled blob and initialize a set of assignments
-_Use_decl_annotations_
-HRESULT CEffectLoader::LoadAssignments( uint32_t Assignments, SAssignment **ppAssignments,
- uint8_t *pBackingStore, uint32_t *pRTVAssignments, uint32_t *pFinalAssignments )
-{
- HRESULT hr = S_OK;
- uint32_t i, j;
-
- SBinaryAssignment *psAssignments;
- uint32_t finalAssignments = 0; // the number of assignments worth keeping
- uint32_t renderTargetViewAssns = 0; // Number of render target view assns, used by passes since SetRTV is a vararg call
-
- *pFinalAssignments = 0;
- if (pRTVAssignments)
- *pRTVAssignments = 0;
-
- VHD( m_msStructured.Read((void**) &psAssignments, sizeof(*psAssignments) * Assignments), "Invalid pEffectBuffer: cannot read assignments." );
-
- // allocate enough room to store all of the assignments (even though some may go unused)
- VN( (*ppAssignments) = PRIVATENEW SAssignment[Assignments] )
-
- //
- // In this loop, we read assignments 1-by-1, keeping some and discarding others.
- // We write to the "next" assignment which is given by &(*ppAssignments)[finalAssignments];
- // if an assignment is worth keeping, we increment finalAssignments.
- // This means that if you want to keep an assignment, you must be careful to initialize
- // all members of SAssignment because old values from preceding discarded assignments might remain.
- //
- for (i = 0; i < Assignments; ++ i)
- {
- SGlobalVariable *pVarArray, *pVarIndex, *pVar;
- const char *pGlobalVarName;
- SAssignment *pAssignment = &(*ppAssignments)[finalAssignments];
- uint8_t *pLHS;
-
- VBD( psAssignments[i].iState < NUM_STATES, "Invalid pEffectBuffer: invalid assignment state." );
- VBD( psAssignments[i].Index < g_lvGeneral[psAssignments[i].iState].m_Indices, "Invalid pEffectBuffer: invalid assignment index." );
-
- pAssignment->LhsType = g_lvGeneral[psAssignments[i].iState].m_LhsType;
-
- // Count RenderTargetView assignments
- if (pAssignment->LhsType == ELHS_RenderTargetView)
- renderTargetViewAssns++;
-
- switch (g_lvGeneral[psAssignments[i].iState].m_Type)
- {
- case D3D_SVT_UINT8:
- assert(g_lvGeneral[psAssignments[i].iState].m_Cols == 1); // uint8_t arrays not supported
- pAssignment->DataSize = sizeof(uint8_t);
- // Store an offset for destination instead of a pointer so that it's easy to relocate it later
-
- break;
-
- case D3D_SVT_BOOL:
- case D3D_SVT_INT:
- case D3D_SVT_UINT:
- case D3D_SVT_FLOAT:
- pAssignment->DataSize = SType::c_ScalarSize * g_lvGeneral[psAssignments[i].iState].m_Cols;
- break;
-
- case D3D_SVT_RASTERIZER:
- pAssignment->DataSize = sizeof(SRasterizerBlock);
- break;
-
- case D3D_SVT_DEPTHSTENCIL:
- pAssignment->DataSize = sizeof(SDepthStencilBlock);
- break;
-
- case D3D_SVT_BLEND:
- pAssignment->DataSize = sizeof(SBlendBlock);
- break;
-
- case D3D_SVT_VERTEXSHADER:
- case D3D_SVT_GEOMETRYSHADER:
- case D3D_SVT_PIXELSHADER:
- case D3D_SVT_HULLSHADER:
- case D3D_SVT_DOMAINSHADER:
- case D3D_SVT_COMPUTESHADER:
- pAssignment->DataSize = sizeof(SShaderBlock);
- break;
-
- case D3D_SVT_TEXTURE:
- case D3D_SVT_TEXTURE1D:
- case D3D_SVT_TEXTURE2D:
- case D3D_SVT_TEXTURE2DMS:
- case D3D_SVT_TEXTURE3D:
- case D3D_SVT_TEXTURECUBE:
- case D3D_SVT_TEXTURECUBEARRAY:
- case D3D_SVT_BYTEADDRESS_BUFFER:
- case D3D_SVT_STRUCTURED_BUFFER:
- pAssignment->DataSize = sizeof(SShaderResource);
- break;
-
- case D3D_SVT_RENDERTARGETVIEW:
- pAssignment->DataSize = sizeof(SRenderTargetView);
- break;
-
- case D3D_SVT_DEPTHSTENCILVIEW:
- pAssignment->DataSize = sizeof(SDepthStencilView);
- break;
-
- case D3D_SVT_RWTEXTURE1D:
- case D3D_SVT_RWTEXTURE1DARRAY:
- case D3D_SVT_RWTEXTURE2D:
- case D3D_SVT_RWTEXTURE2DARRAY:
- case D3D_SVT_RWTEXTURE3D:
- case D3D_SVT_RWBUFFER:
- case D3D_SVT_RWBYTEADDRESS_BUFFER:
- case D3D_SVT_RWSTRUCTURED_BUFFER:
- case D3D_SVT_APPEND_STRUCTURED_BUFFER:
- case D3D_SVT_CONSUME_STRUCTURED_BUFFER:
- pAssignment->DataSize = sizeof(SUnorderedAccessView);
- break;
-
- case D3D_SVT_INTERFACE_POINTER:
- pAssignment->DataSize = sizeof(SInterface);
- break;
-
- default:
- assert(0);
- VHD( E_FAIL, "Internal loading error: invalid assignment type.");
- }
-
- uint32_t lhsStride;
- if( g_lvGeneral[psAssignments[i].iState].m_Stride > 0 )
- lhsStride = g_lvGeneral[psAssignments[i].iState].m_Stride;
- else
- lhsStride = pAssignment->DataSize;
-
- // Store only the destination offset so that the backing store pointers can be easily fixed up later
- pAssignment->Destination.Offset = g_lvGeneral[psAssignments[i].iState].m_Offset + lhsStride * psAssignments[i].Index;
-
- // As a result, you should use pLHS in this function instead of the destination pointer
- pLHS = pBackingStore + pAssignment->Destination.Offset;
-
- switch (psAssignments[i].AssignmentType)
- {
- case ECAT_Constant: // e.g. LHS = 1; or LHS = nullptr;
- uint32_t *pNumConstants;
- SBinaryConstant *pConstants;
-
- VHD( m_msUnstructured.ReadAtOffset(psAssignments[i].oInitializer, sizeof(uint32_t), (void**) &pNumConstants), "Invalid pEffectBuffer: cannot read NumConstants." );
- VHD( m_msUnstructured.Read((void **)&pConstants, sizeof(SBinaryConstant) * (*pNumConstants)), "Invalid pEffectBuffer: cannot read constants." );
-
- if(pAssignment->IsObjectAssignment())
- {
- // make sure this is a nullptr assignment
- VBD( *pNumConstants == 1 && (pConstants[0].Type == EST_Int || pConstants[0].Type == EST_UInt) && pConstants[0].iValue == 0,
- "Invalid pEffectBuffer: non-nullptr constant assignment to object.");
-
- switch (pAssignment->LhsType)
- {
- case ELHS_DepthStencilBlock:
- *((void **)pLHS) = &g_NullDepthStencil;
- break;
- case ELHS_BlendBlock:
- *((void **)pLHS) = &g_NullBlend;
- break;
- case ELHS_RasterizerBlock:
- *((void **)pLHS) = &g_NullRasterizer;
- break;
- case ELHS_VertexShaderBlock:
- *((void **)pLHS) = &g_NullVS;
- break;
- case ELHS_PixelShaderBlock:
- *((void **)pLHS) = &g_NullPS;
- break;
- case ELHS_GeometryShaderBlock:
- *((void **)pLHS) = &g_NullGS;
- break;
- case ELHS_HullShaderBlock:
- *((void **)pLHS) = &g_NullHS;
- break;
- case ELHS_DomainShaderBlock:
- *((void **)pLHS) = &g_NullDS;
- break;
- case ELHS_ComputeShaderBlock:
- *((void **)pLHS) = &g_NullCS;
- break;
- case ELHS_Texture:
- *((void **)pLHS) = &g_NullTexture;
- break;
- case ELHS_DepthStencilView:
- *((void **)pLHS) = &g_NullDepthStencilView;
- break;
- case ELHS_RenderTargetView:
- *((void **)pLHS) = &g_NullRenderTargetView;
- break;
- default:
- assert(0);
- }
- }
- else
- {
- VBD( *pNumConstants == g_lvGeneral[psAssignments[i].iState].m_Cols, "Internal loading error: mismatch constant count." );
- for (j = 0; j < *pNumConstants; ++ j)
- {
- VH( ExecuteConstantAssignment(pConstants + j, pLHS, g_lvGeneral[psAssignments[i].iState].m_Type) );
- pLHS += SType::c_ScalarSize; // arrays of constants will always be regular scalar sized, never byte-sized
- }
- }
-
- // Can get rid of this assignment
- break;
-
- case ECAT_Variable: // e.g. LHS = myVar;
- VHD( m_msUnstructured.ReadAtOffset(psAssignments[i].oInitializer, &pGlobalVarName), "Invalid pEffectBuffer: cannot read variable name." );
-
- VBD( pVar = m_pEffect->FindVariableByName(pGlobalVarName), "Loading error: cannot find variable name." );
-
- if (pAssignment->IsObjectAssignment())
- {
- VBD( pVar->pType->VarType == EVT_Object &&
- GetSimpleParameterTypeFromObjectType(pVar->pType->ObjectType) == g_lvGeneral[psAssignments[i].iState].m_Type,
- "Loading error: invalid variable type or object type." );
-
- // Write directly into the state block's backing store
- *((void **)pLHS) = pVar->Data.pGeneric;
-
- // Now we can get rid of this assignment
- }
- else
- {
- VBD( pVar->pType->BelongsInConstantBuffer(), "Invalid pEffectBuffer: assignment type mismatch." );
-
- pAssignment->DependencyCount = 1;
- VN( pAssignment->pDependencies = PRIVATENEW SAssignment::SDependency[pAssignment->DependencyCount] );
- pAssignment->pDependencies->pVariable = pVar;
-
- // Store an offset for numeric values instead of a pointer so that it's easy to relocate it later
- pAssignment->Source.Offset = pVar->Data.Offset;
- pAssignment->AssignmentType = ERAT_NumericVariable;
-
- // Can't get rid of this assignment
- ++ finalAssignments;
- }
- break;
-
- case ECAT_ConstIndex: // e.g. LHS = myGS[1]
- SBinaryAssignment::SConstantIndex *psConstIndex;
-
- VHD( m_msUnstructured.ReadAtOffset(psAssignments[i].oInitializer, sizeof(*psConstIndex), (void**) &psConstIndex),
- "Invalid pEffectBuffer: cannot read assignment initializer." );
- VHD( m_msUnstructured.ReadAtOffset(psConstIndex->oArrayName, &pGlobalVarName), "Invalid pEffectBuffer: cannot read array name." );
-
- VBD( pVarArray = m_pEffect->FindVariableByName(pGlobalVarName), "Loading error: cannot find array name." );
-
- if (pAssignment->IsObjectAssignment())
- {
- VBD( psConstIndex->Index < pVarArray->pType->Elements, "Invalid pEffectBuffer: out of bounds array index." );
- VBD( pVarArray->pType->VarType == EVT_Object &&
- GetSimpleParameterTypeFromObjectType(pVarArray->pType->ObjectType) == g_lvGeneral[psAssignments[i].iState].m_Type,
- "Loading error: invalid variable type or object type." );
-
- // Write directly into the state block's backing store
- *((void **)pLHS) = GetBlockByIndex(pVarArray->pType->VarType, pVarArray->pType->ObjectType, pVarArray->Data.pGeneric, psConstIndex->Index);
- VBD( nullptr != *((void **)pLHS), "Internal loading error: invalid block." );
-
- // Now we can get rid of this assignment
- }
- else
- {
- VBD( pVarArray->pType->BelongsInConstantBuffer(), "Invalid pEffectBuffer: assignment type mismatch." );
-
- pAssignment->DependencyCount = 1;
- VN( pAssignment->pDependencies = PRIVATENEW SAssignment::SDependency[pAssignment->DependencyCount] );
- pAssignment->pDependencies->pVariable = pVarArray;
-
- CCheckedDword chkDataLen = psConstIndex->Index;
- uint32_t dataLen;
- chkDataLen *= SType::c_ScalarSize;
- chkDataLen += pAssignment->DataSize;
- VHD( chkDataLen.GetValue(&dataLen), "Overflow: assignment size." );
- VBD( dataLen <= pVarArray->pType->TotalSize, "Internal loading error: assignment size mismatch" );
-
- pAssignment->Source.Offset = pVarArray->Data.Offset + psConstIndex->Index * SType::c_ScalarSize;
-
- // _NumericConstIndex is not used here because _NumericVariable
- // does the same stuff in a more general fashion with no perf hit.
- pAssignment->AssignmentType = ERAT_NumericVariable;
-
- // Can't get rid of this assignment
- ++ finalAssignments;
- }
- break;
-
- case ECAT_VariableIndex: // e.g. LHS = myVar[numLights];
- SBinaryAssignment::SVariableIndex *psVarIndex;
-
- VHD( m_msUnstructured.ReadAtOffset(psAssignments[i].oInitializer, sizeof(*psVarIndex), (void**) &psVarIndex),
- "Invalid pEffectBuffer: cannot read assignment initializer." );
- VHD( m_msUnstructured.ReadAtOffset(psVarIndex->oArrayName, &pGlobalVarName), "Invalid pEffectBuffer: cannot read variable name." );
- VBD( pVarArray = m_pEffect->FindVariableByName(pGlobalVarName), "Loading error: cannot find variable name." );
-
- VHD( m_msUnstructured.ReadAtOffset(psVarIndex->oIndexVarName, &pGlobalVarName), "Invalid pEffectBuffer: cannot read index variable name." );
- VBD( pVarIndex = m_pEffect->FindVariableByName(pGlobalVarName), "Loading error: cannot find index variable name." );
-
- // Only support integer indices
- VBD( pVarIndex->pType->VarType == EVT_Numeric && (pVarIndex->pType->NumericType.ScalarType == EST_Int || pVarIndex->pType->NumericType.ScalarType == EST_UInt),
- "Invalid pEffectBuffer: invalid index variable type.");
- VBD( pVarArray->pType->Elements > 0, "Invalid pEffectBuffer: array variable is not an array." );
-
- pVarIndex->pCB->IsUsedByExpression = true;
-
- if (pAssignment->IsObjectAssignment())
- {
- VBD( pVarArray->pType->VarType == EVT_Object &&
- GetSimpleParameterTypeFromObjectType(pVarArray->pType->ObjectType) == g_lvGeneral[psAssignments[i].iState].m_Type,
- "Loading error: invalid variable type or object type." );
-
- // MaxElements is only 16-bits wide
- VBD( pVarArray->pType->Elements <= 0xFFFF, "Internal error: array size is too large." );
- pAssignment->MaxElements = pVarArray->pType->Elements;
-
- pAssignment->DependencyCount = 1;
- VN( pAssignment->pDependencies = PRIVATENEW SAssignment::SDependency[pAssignment->DependencyCount] );
- pAssignment->pDependencies[0].pVariable = pVarIndex;
-
- // Point this assignment to the start of the variable's object array.
- // When this assignment is dirty, we write the value of this pointer plus
- // the index given by its one dependency directly into the destination
- pAssignment->Source = pVarArray->Data;
- pAssignment->AssignmentType = ERAT_ObjectVariableIndex;
- }
- else
- {
- VBD( pVarArray->pType->BelongsInConstantBuffer(), "Invalid pEffectBuffer: assignment type mismatch." );
-
- pAssignment->DependencyCount = 2;
- VN( pAssignment->pDependencies = PRIVATENEW SAssignment::SDependency[pAssignment->DependencyCount] );
- pAssignment->pDependencies[0].pVariable = pVarIndex;
- pAssignment->pDependencies[1].pVariable = pVarArray;
-
- // When pVarIndex is updated, we update the source pointer.
- // When pVarArray is updated, we copy data from the source to the destination.
- pAssignment->Source.pGeneric = nullptr;
- pAssignment->AssignmentType = ERAT_NumericVariableIndex;
- }
-
- // Can't get rid of this assignment
- ++ finalAssignments;
-
- break;
-
- case ECAT_ExpressionIndex:// e.g. LHS = myVar[a + b * c];
- case ECAT_Expression: // e.g. LHS = a + b * c;
- // we do not support FXLVM
- VHD( E_NOTIMPL, "FXLVM Expressions (complex assignments like myVar[i*2]) are not supported in Effects11." );
- break;
-
- case ECAT_InlineShader:
- case ECAT_InlineShader5:
- uint32_t cbShaderBin;
- uint8_t *pShaderBin;
- SShaderBlock *pShaderBlock;
- SAnonymousShader *pAnonShader;
- union
- {
- SBinaryAssignment::SInlineShader *psInlineShader;
- SBinaryShaderData5 *psInlineShader5;
- };
-
- // Inline shader assignments must be object types
- assert(pAssignment->IsObjectAssignment());
-
- static_assert(offsetof(SBinaryAssignment::SInlineShader, oShader) == offsetof(SBinaryShaderData5, oShader), "ECAT_InlineShader issue");
- static_assert(offsetof(SBinaryAssignment::SInlineShader, oSODecl) == offsetof(SBinaryShaderData5, oSODecls), "ECAT_InlineShader5 issue");
- if( psAssignments[i].AssignmentType == ECAT_InlineShader )
- {
- VHD( m_msUnstructured.ReadAtOffset(psAssignments[i].oInitializer, sizeof(*psInlineShader), (void**) &psInlineShader),
- "Invalid pEffectBuffer: cannot read inline shader." );
- }
- else
- {
- VHD( m_msUnstructured.ReadAtOffset(psAssignments[i].oInitializer, sizeof(*psInlineShader5), (void**) &psInlineShader5),
- "Invalid pEffectBuffer: cannot read inline shader." );
- }
-
- VBD( m_pEffect->m_ShaderBlockCount < m_pHeader->cTotalShaders, "Internal loading error: shader count is out incorrect." );
- VBD( m_pEffect->m_AnonymousShaderCount < m_pHeader->cInlineShaders, "Internal loading error: anonymous shader count is out incorrect." );
-
- pShaderBlock = &m_pEffect->m_pShaderBlocks[m_pEffect->m_ShaderBlockCount];
- pAnonShader = &m_pEffect->m_pAnonymousShaders[m_pEffect->m_AnonymousShaderCount];
- pAnonShader->pShaderBlock = pShaderBlock;
-
- ++ m_pEffect->m_ShaderBlockCount;
- ++ m_pEffect->m_AnonymousShaderCount;
-
- // Write directly into the state block's backing store
- *((void **)pLHS) = pShaderBlock;
-
- VHD( GetUnstructuredDataBlock(psInlineShader->oShader, &cbShaderBin, (void **) &pShaderBin), "Invalid pEffectBuffer: cannot read inline shader block." );
-
- if (cbShaderBin > 0)
- {
- VN( pShaderBlock->pReflectionData = PRIVATENEW SShaderBlock::SReflectionData );
-
- pShaderBlock->pReflectionData->BytecodeLength = cbShaderBin;
- pShaderBlock->pReflectionData->pBytecode = (uint8_t*) pShaderBin;
- pShaderBlock->pReflectionData->pStreamOutDecls[0] =
- pShaderBlock->pReflectionData->pStreamOutDecls[1] =
- pShaderBlock->pReflectionData->pStreamOutDecls[2] =
- pShaderBlock->pReflectionData->pStreamOutDecls[3] = nullptr;
- pShaderBlock->pReflectionData->RasterizedStream = 0;
- pShaderBlock->pReflectionData->IsNullGS = FALSE;
- pShaderBlock->pReflectionData->pReflection = nullptr;
- pShaderBlock->pReflectionData->InterfaceParameterCount = 0;
- pShaderBlock->pReflectionData->pInterfaceParameters = nullptr;
- }
-
- switch (pAssignment->LhsType)
- {
- case ELHS_PixelShaderBlock:
- pShaderBlock->pVT = &g_vtPS;
- VBD( psInlineShader->oSODecl == 0, "Internal loading error: pixel shaders cannot have stream out decls." );
- break;
-
- case ELHS_GeometryShaderBlock:
- pShaderBlock->pVT = &g_vtGS;
- if( psAssignments[i].AssignmentType == ECAT_InlineShader )
- {
- if (psInlineShader->oSODecl)
- {
- // This is a GS with SO
- VHD( GetStringAndAddToReflection(psInlineShader->oSODecl, &pShaderBlock->pReflectionData->pStreamOutDecls[0]),
- "Invalid pEffectBuffer: cannot read SO decl." );
- }
- }
- else
- {
- // This is a GS with addressable stream out
- for( size_t iDecl=0; iDecl < psInlineShader5->cSODecls; ++iDecl )
- {
- if (psInlineShader5->oSODecls[iDecl])
- {
- VHD( GetStringAndAddToReflection(psInlineShader5->oSODecls[iDecl], &pShaderBlock->pReflectionData->pStreamOutDecls[iDecl]),
- "Invalid pEffectBuffer: cannot read SO decl." );
- }
- }
- pShaderBlock->pReflectionData->RasterizedStream = psInlineShader5->RasterizedStream;
- }
- break;
-
- case ELHS_VertexShaderBlock:
- pShaderBlock->pVT = &g_vtVS;
- VBD( psInlineShader->oSODecl == 0, "Internal loading error: vertex shaders cannot have stream out decls." );
- break;
-
- case ELHS_HullShaderBlock:
- pShaderBlock->pVT = &g_vtHS;
- VBD( psInlineShader->oSODecl == 0, "Internal loading error: hull shaders cannot have stream out decls." );
- break;
-
- case ELHS_DomainShaderBlock:
- pShaderBlock->pVT = &g_vtDS;
- VBD( psInlineShader->oSODecl == 0, "Internal loading error: domain shaders cannot have stream out decls." );
- break;
-
- case ELHS_ComputeShaderBlock:
- pShaderBlock->pVT = &g_vtCS;
- VBD( psInlineShader->oSODecl == 0, "Internal loading error: compute shaders cannot have stream out decls." );
- break;
-
- case ELHS_GeometryShaderSO:
- assert(0); // Should never happen
-
- default:
- VHD( E_FAIL, "Internal loading error: invalid shader type." );
- }
-
- if( psAssignments[i].AssignmentType == ECAT_InlineShader5 )
- {
- pShaderBlock->pReflectionData->InterfaceParameterCount = psInlineShader5->cInterfaceBindings;
- VH( GetInterfaceParametersAndAddToReflection( psInlineShader5->cInterfaceBindings, psInlineShader5->oInterfaceBindings, &pShaderBlock->pReflectionData->pInterfaceParameters ) );
- }
-
- // Now we can get rid of this assignment
- break;
-
- default:
- assert(0);
-
- }
- }
-
- *pFinalAssignments = finalAssignments;
- if (pRTVAssignments)
- *pRTVAssignments = renderTargetViewAssns;
-
-lExit:
- return hr;
-}
-
-
-// Read info from the compiled blob and initialize an object variable
-HRESULT CEffectLoader::LoadObjectVariables()
-{
- HRESULT hr = S_OK;
-
- size_t cBlocks = m_pHeader->Effect.cObjectVariables;
-
- for (size_t iBlock=0; iBlock<cBlocks; iBlock++)
- {
- SBinaryObjectVariable *psBlock;
- SGlobalVariable *pVar;
- SType *pType;
- uint32_t elementsToRead;
- CCheckedDword chkElementsTotal;
- uint32_t elementsTotal;
-
- // Read variable info
- VHD( m_msStructured.Read((void**) &psBlock, sizeof(*psBlock)), "Invalid pEffectBuffer: cannot read object variable." );
- VBD( m_pEffect->m_VariableCount < (m_pHeader->Effect.cObjectVariables + m_pHeader->Effect.cNumericVariables + m_pHeader->cInterfaceVariables),
- "Internal loading error: variable count mismatch." );
- pVar = &m_pEffect->m_pVariables[m_pEffect->m_VariableCount];
-
- // Get type
- VH( LoadTypeAndAddToPool(&pType, psBlock->oType) );
-
- // Make sure the right polymorphic type is created
- VH( PlacementNewVariable(pVar, pType, false) );
-
- pVar->pEffect = m_pEffect;
- pVar->pType = pType;
- pVar->pCB = nullptr;
- pVar->ExplicitBindPoint = psBlock->ExplicitBindPoint;
-
- if( pType->IsStateBlockObject() )
- {
- pVar->MemberDataOffsetPlus4 = m_pEffect->m_MemberDataCount * sizeof(SMemberDataPointer) + 4;
- m_pEffect->m_MemberDataCount += std::max<uint32_t>(pType->Elements,1);
- }
-
- // Get name
- VHD( GetStringAndAddToReflection(psBlock->oName, &pVar->pName), "Invalid pEffectBuffer: cannot read object variable name." );
- VHD( GetStringAndAddToReflection(psBlock->oSemantic, &pVar->pSemantic), "Invalid pEffectBuffer: cannot read object variable semantic." );
-
- m_pEffect->m_VariableCount++;
- elementsToRead = std::max<uint32_t>(1, pType->Elements);
- chkElementsTotal = elementsToRead;
-
- if (pType->IsStateBlockObject())
- {
- // State blocks
- EBlockType blockType;
- uint32_t *maxBlockCount;
- uint32_t *currentBlockCount;
-
- switch (pType->ObjectType)
- {
- case EOT_Blend:
- pVar->Data.pBlock = &m_pEffect->m_pBlendBlocks[m_pEffect->m_BlendBlockCount];
- maxBlockCount = &m_pHeader->cBlendStateBlocks;
- currentBlockCount = &m_pEffect->m_BlendBlockCount;
- blockType = EBT_Blend;
- break;
-
- case EOT_DepthStencil:
- pVar->Data.pBlock = &m_pEffect->m_pDepthStencilBlocks[m_pEffect->m_DepthStencilBlockCount];
- maxBlockCount = &m_pHeader->cDepthStencilBlocks;
- currentBlockCount = &m_pEffect->m_DepthStencilBlockCount;
- blockType = EBT_DepthStencil;
- break;
-
- case EOT_Rasterizer:
- pVar->Data.pBlock = &m_pEffect->m_pRasterizerBlocks[m_pEffect->m_RasterizerBlockCount];
- maxBlockCount = &m_pHeader->cRasterizerStateBlocks;
- currentBlockCount = &m_pEffect->m_RasterizerBlockCount;
- blockType = EBT_Rasterizer;
- break;
-
- default:
- VB(pType->IsSampler());
- pVar->Data.pBlock = &m_pEffect->m_pSamplerBlocks[m_pEffect->m_SamplerBlockCount];
- maxBlockCount = &m_pHeader->cSamplers;
- currentBlockCount = &m_pEffect->m_SamplerBlockCount;
- blockType = EBT_Sampler;
- }
-
- chkElementsTotal += *currentBlockCount;
- VHD( chkElementsTotal.GetValue(&elementsTotal), "Overflow: vaiable elements." );
- VBD( elementsTotal <= *maxBlockCount, "Internal loading error: element count overflow." );
-
- *currentBlockCount += elementsToRead;
-
- for (uint32_t iElement = 0; iElement < elementsToRead; ++ iElement)
- {
- SBaseBlock *pCurrentBlock;
- uint32_t cAssignments;
-
- pCurrentBlock = (SBaseBlock *) GetBlockByIndex(pVar->pType->VarType, pVar->pType->ObjectType, pVar->Data.pGeneric, iElement);
- VBD( nullptr != pCurrentBlock, "Internal loading error: find state block." );
-
- pCurrentBlock->BlockType = blockType;
-
- VHD( m_msStructured.Read(&cAssignments), "Invalid pEffectBuffer: cannot read state block assignments." );
-
- VH( LoadAssignments( cAssignments, &pCurrentBlock->pAssignments, (uint8_t*)pCurrentBlock, nullptr, &pCurrentBlock->AssignmentCount ) );
- }
- }
- else if (pType->IsShader())
- {
- // Shaders
-
- chkElementsTotal += m_pEffect->m_ShaderBlockCount;
- VHD( chkElementsTotal.GetValue(&elementsTotal), "Overflow: shader block count." );
- VBD( elementsTotal <= m_pHeader->cTotalShaders, "Invalid pEffectBuffer: shader count mismatch." );
-
- pVar->Data.pShader = &m_pEffect->m_pShaderBlocks[m_pEffect->m_ShaderBlockCount];
-
- for (size_t iElement=0; iElement<elementsToRead; iElement++)
- {
- uint32_t cbShaderBin;
- void *pShaderBin;
- SShaderBlock *pShaderBlock;
-
- union
- {
- uint32_t *pOffset;
- SBinaryGSSOInitializer *psInlineGSSO4;
- SBinaryShaderData5 *psInlineShader5;
- };
-
- static_assert(offsetof(SBinaryGSSOInitializer, oShader) == 0, "Union issue");
- static_assert(offsetof(SBinaryShaderData5, oShader) == 0, "Union issue");
-
-
- pShaderBlock = &m_pEffect->m_pShaderBlocks[m_pEffect->m_ShaderBlockCount];
- m_pEffect->m_ShaderBlockCount++;
-
- // Get shader binary
- switch (pType->ObjectType)
- {
- case EOT_VertexShader:
- case EOT_GeometryShader:
- case EOT_PixelShader:
- VHD( m_msStructured.Read((void**)&pOffset, sizeof(*pOffset)), "Invalid pEffectBuffer: cannot read shader block." );
- break;
-
- case EOT_GeometryShaderSO:
- VHD( m_msStructured.Read((void**)&psInlineGSSO4, sizeof(*psInlineGSSO4)), "Invalid pEffectBuffer: cannot read inline GS with SO." );
- break;
-
- case EOT_VertexShader5:
- case EOT_GeometryShader5:
- case EOT_HullShader5:
- case EOT_DomainShader5:
- case EOT_PixelShader5:
- case EOT_ComputeShader5:
- VHD( m_msStructured.Read((void**)&psInlineShader5, sizeof(*psInlineShader5)), "Invalid pEffectBuffer: cannot read inline shader." );
- break;
-
- default:
- VH( E_FAIL );
- }
-
- VHD( GetUnstructuredDataBlock(*pOffset, &cbShaderBin, &pShaderBin), "Invalid pEffectBuffer: cannot read shader byte code." );
-
- if (cbShaderBin > 0)
- {
- VN( pShaderBlock->pReflectionData = PRIVATENEW SShaderBlock::SReflectionData );
-
- pShaderBlock->pReflectionData->BytecodeLength = cbShaderBin;
- pShaderBlock->pReflectionData->pBytecode = (uint8_t*) pShaderBin;
- pShaderBlock->pReflectionData->pStreamOutDecls[0] =
- pShaderBlock->pReflectionData->pStreamOutDecls[1] =
- pShaderBlock->pReflectionData->pStreamOutDecls[2] =
- pShaderBlock->pReflectionData->pStreamOutDecls[3] = nullptr;
- pShaderBlock->pReflectionData->RasterizedStream = 0;
- pShaderBlock->pReflectionData->IsNullGS = FALSE;
- pShaderBlock->pReflectionData->pReflection = nullptr;
- pShaderBlock->pReflectionData->InterfaceParameterCount = 0;
- pShaderBlock->pReflectionData->pInterfaceParameters = nullptr;
- }
-
- switch (pType->ObjectType)
- {
- case EOT_PixelShader:
- pShaderBlock->pVT = &g_vtPS;
- break;
-
- case EOT_GeometryShaderSO:
- // Get StreamOut decl
- //VH( m_msStructured.Read(&dwOffset) );
- if (cbShaderBin > 0)
- {
- VHD( GetStringAndAddToReflection(psInlineGSSO4->oSODecl, &pShaderBlock->pReflectionData->pStreamOutDecls[0]),
- "Invalid pEffectBuffer: cannot read stream out decl." );
- }
- pShaderBlock->pVT = &g_vtGS;
- break;
-
- case EOT_VertexShader5:
- case EOT_GeometryShader5:
- case EOT_HullShader5:
- case EOT_DomainShader5:
- case EOT_PixelShader5:
- case EOT_ComputeShader5:
- // Get StreamOut decls
- if (cbShaderBin > 0)
- {
- for( size_t iDecl=0; iDecl < psInlineShader5->cSODecls; ++iDecl )
- {
- VHD( GetStringAndAddToReflection(psInlineShader5->oSODecls[iDecl], &pShaderBlock->pReflectionData->pStreamOutDecls[iDecl]),
- "Invalid pEffectBuffer: cannot read stream out decls." );
- }
- pShaderBlock->pReflectionData->RasterizedStream = psInlineShader5->RasterizedStream;
- pShaderBlock->pReflectionData->InterfaceParameterCount = psInlineShader5->cInterfaceBindings;
- VH( GetInterfaceParametersAndAddToReflection( psInlineShader5->cInterfaceBindings, psInlineShader5->oInterfaceBindings, &pShaderBlock->pReflectionData->pInterfaceParameters ) );
- }
- switch (pType->ObjectType)
- {
- case EOT_VertexShader5:
- pShaderBlock->pVT = &g_vtVS;
- break;
- case EOT_GeometryShader5:
- pShaderBlock->pVT = &g_vtGS;
- break;
- case EOT_HullShader5:
- pShaderBlock->pVT = &g_vtHS;
- break;
- case EOT_DomainShader5:
- pShaderBlock->pVT = &g_vtDS;
- break;
- case EOT_PixelShader5:
- pShaderBlock->pVT = &g_vtPS;
- break;
- case EOT_ComputeShader5:
- pShaderBlock->pVT = &g_vtCS;
- break;
- default:
- VH( E_FAIL );
- }
- break;
-
- case EOT_GeometryShader:
- pShaderBlock->pVT = &g_vtGS;
- break;
-
- case EOT_VertexShader:
- pShaderBlock->pVT = &g_vtVS;
- break;
-
- default:
- VHD( E_FAIL, "Invalid pEffectBuffer: invalid shader type." );
- }
- }
- }
- else if (pType->IsObjectType(EOT_String))
- {
- // Strings
-
- chkElementsTotal += m_pEffect->m_StringCount;
- VHD( chkElementsTotal.GetValue(&elementsTotal), "Overflow: string object count." );
- VBD( elementsTotal <= m_pHeader->cStrings, "Invalid pEffectBuffer: string count mismatch." );
-
- pVar->Data.pString = &m_pEffect->m_pStrings[m_pEffect->m_StringCount];
-
- for (size_t iElement=0; iElement<elementsToRead; iElement++)
- {
- uint32_t dwOffset;
- SString *pString;
-
- pString = &m_pEffect->m_pStrings[m_pEffect->m_StringCount];
- m_pEffect->m_StringCount++;
-
- // Get string
- VHD( m_msStructured.Read(&dwOffset), "Invalid pEffectBuffer: cannot read string offset." );
- VHD( GetStringAndAddToReflection(dwOffset, &pString->pString), "Invalid pEffectBuffer: cannot read string." );
- }
- }
- else if (pType->IsShaderResource())
- {
- // Textures/buffers
-
- chkElementsTotal += m_pEffect->m_ShaderResourceCount;
- VHD( chkElementsTotal.GetValue(&elementsTotal), "Overflow: SRV object count." );
- VBD( elementsTotal <= m_pHeader->cShaderResources, "Invalid pEffectBuffer: SRV count mismatch." );
-
- pVar->Data.pShaderResource = &m_pEffect->m_pShaderResources[m_pEffect->m_ShaderResourceCount];
- m_pEffect->m_ShaderResourceCount += elementsToRead;
- }
- else if (pType->IsUnorderedAccessView())
- {
- // UnorderedAccessViews
-
- chkElementsTotal += m_pEffect->m_UnorderedAccessViewCount;
- VHD( chkElementsTotal.GetValue(&elementsTotal), "Overflow: UAV object count." );
- VBD( elementsTotal <= m_pHeader->cUnorderedAccessViews, "Invalid pEffectBuffer: UAV count mismatch." );
-
- pVar->Data.pUnorderedAccessView = &m_pEffect->m_pUnorderedAccessViews[m_pEffect->m_UnorderedAccessViewCount];
- m_pEffect->m_UnorderedAccessViewCount += elementsToRead;
- }
- else if (pType->IsRenderTargetView())
- {
- // RenderTargets
-
- chkElementsTotal += m_pEffect->m_RenderTargetViewCount;
- VHD( chkElementsTotal.GetValue(&elementsTotal), "Overflow: RTV object count." );
- VBD( elementsTotal <= m_pHeader->cRenderTargetViews, "Invalid pEffectBuffer: RTV count mismatch." );
-
- pVar->Data.pRenderTargetView = &m_pEffect->m_pRenderTargetViews[m_pEffect->m_RenderTargetViewCount];
- m_pEffect->m_RenderTargetViewCount += elementsToRead;
- }
- else if (pType->IsDepthStencilView())
- {
- // DepthStencilViews
-
- chkElementsTotal += m_pEffect->m_DepthStencilViewCount;
- VHD( chkElementsTotal.GetValue(&elementsTotal), "Overflow: DSV object count." );
- VBD( elementsTotal <= m_pHeader->cDepthStencilViews, "Invalid pEffectBuffer: DSV count mismatch." );
-
- pVar->Data.pDepthStencilView = &m_pEffect->m_pDepthStencilViews[m_pEffect->m_DepthStencilViewCount];
- m_pEffect->m_DepthStencilViewCount += elementsToRead;
- }
- else
- {
- VHD( E_FAIL, "Invalid pEffectBuffer: DSV count mismatch." );
- }
-
- // Read annotations
- VH( LoadAnnotations(&pVar->AnnotationCount, &pVar->pAnnotations) );
- }
-lExit:
- return hr;
-}
-
-
-// Read info from the compiled blob and initialize an interface variable
-HRESULT CEffectLoader::LoadInterfaceVariables()
-{
- HRESULT hr = S_OK;
- uint32_t iBlock;
- uint32_t cBlocks;
-
- cBlocks = m_pHeader->cInterfaceVariables;
-
- for (iBlock=0; iBlock<cBlocks; iBlock++)
- {
- SBinaryInterfaceVariable *psBlock;
- SGlobalVariable *pVar;
- SType *pType;
- uint32_t elementsToRead;
- CCheckedDword chkElementsTotal;
- uint32_t elementsTotal;
- void *pDefaultValue;
-
- // Read variable info
- VHD( m_msStructured.Read((void**) &psBlock, sizeof(*psBlock)), "Invalid pEffectBuffer: cannot read interface block." );
- VBD( m_pEffect->m_VariableCount < (m_pHeader->Effect.cObjectVariables + m_pHeader->Effect.cNumericVariables + m_pHeader->cInterfaceVariables),
- "Internal loading error: variable count mismatch." );
- pVar = &m_pEffect->m_pVariables[m_pEffect->m_VariableCount];
-
- // Get type
- VH( LoadTypeAndAddToPool(&pType, psBlock->oType) );
-
- // Make sure the right polymorphic type is created
- VH( PlacementNewVariable(pVar, pType, false) );
-
- pVar->pEffect = m_pEffect;
- pVar->pType = pType;
- pVar->pCB = nullptr;
- pVar->ExplicitBindPoint = (uint32_t)-1;
- pVar->pSemantic = nullptr;
-
- // Get name
- VHD( GetStringAndAddToReflection(psBlock->oName, &pVar->pName), "Invalid pEffectBuffer: cannot read interface name." );
-
- m_pEffect->m_VariableCount++;
- elementsToRead = std::max<uint32_t>(1, pType->Elements);
- chkElementsTotal = elementsToRead;
-
- VBD( pType->IsInterface(), "Internal loading error: invlaid type for interface." );
-
- chkElementsTotal += m_pEffect->m_InterfaceCount;
- VHD( chkElementsTotal.GetValue(&elementsTotal), "Overflow: interface count." );
- VBD( elementsTotal <= m_pHeader->cInterfaceVariableElements, "Invalid pEffectBuffer: interface count mismatch." );
-
- pVar->Data.pInterface = &m_pEffect->m_pInterfaces[m_pEffect->m_InterfaceCount];
- m_pEffect->m_InterfaceCount += elementsToRead;
-
- // Get default value
- if (0 != psBlock->oDefaultValue)
- {
- VHD( m_msUnstructured.ReadAtOffset(psBlock->oDefaultValue, elementsToRead * sizeof(SBinaryInterfaceInitializer), &pDefaultValue),
- "Invalid pEffectBuffer: cannot read interface initializer offset." );
- for( size_t i=0; i < elementsToRead; i++ )
- {
- SBinaryInterfaceInitializer* pInterfaceInit = &((SBinaryInterfaceInitializer*)pDefaultValue)[i];
- LPCSTR pClassInstanceName;
- VHD( m_msUnstructured.ReadAtOffset(pInterfaceInit->oInstanceName, &pClassInstanceName), "Invalid pEffectBuffer: cannot read interface initializer." );
-
- SGlobalVariable *pCIVariable = m_pEffect->FindVariableByName(pClassInstanceName);
- VBD( pCIVariable != nullptr, "Loading error: cannot find class instance for interface initializer." );
- VBD( pCIVariable->pType->IsClassInstance(), "Loading error: variable type mismatch for interface initializer." );
- if( pInterfaceInit->ArrayIndex == (uint32_t)-1 )
- {
- VBD( pCIVariable->pType->Elements == 0, "Loading error: array mismatch for interface initializer." );
- pVar->Data.pInterface[i].pClassInstance = (SClassInstanceGlobalVariable*)pCIVariable;
- }
- else
- {
- VBD( pCIVariable->pType->Elements > 0, "Loading error: array mismatch for interface initializer." );
- VBD( pInterfaceInit->ArrayIndex < pCIVariable->pType->Elements, "Loading error: array index out of range." );
-
- SMember* pMember = (SMember*)pCIVariable->GetElement( pInterfaceInit->ArrayIndex );
- VBD( pMember->IsValid(), "Loading error: cannot find member by name." );
- VBD( pMember->pType->IsClassInstance(), "Loading error: member type mismatch for interface initializer." );
- pVar->Data.pInterface[i].pClassInstance = (SClassInstanceGlobalVariable*)pMember;
- }
- }
- }
-
-
- // Read annotations
- VH( LoadAnnotations(&pVar->AnnotationCount, &pVar->pAnnotations) );
- }
-lExit:
- return hr;
-}
-
-
-// Read info from the compiled blob and initialize a group (and contained techniques and passes)
-HRESULT CEffectLoader::LoadGroups()
-{
- HRESULT hr = S_OK;
- uint32_t TechniquesInEffect = 0;
-
- for( size_t iGroup=0; iGroup<m_pHeader->cGroups; iGroup++ )
- {
- SGroup *pGroup = &m_pEffect->m_pGroups[iGroup];
- SBinaryGroup *psGroup;
-
- // Read group info
- VHD( m_msStructured.Read((void**) &psGroup, sizeof(*psGroup)), "Invalid pEffectBuffer: cannot read group." );
- pGroup->TechniqueCount = psGroup->cTechniques;
- VN( pGroup->pTechniques = PRIVATENEW STechnique[pGroup->TechniqueCount] );
- VHD( GetStringAndAddToReflection(psGroup->oName, &pGroup->pName), "Invalid pEffectBuffer: cannot read group name." );
-
- if( pGroup->pName == nullptr )
- {
- VBD( m_pEffect->m_pNullGroup == nullptr, "Internal loading error: multiple nullptr groups." );
- m_pEffect->m_pNullGroup = pGroup;
- }
-
- // Read annotations
- VH( LoadAnnotations(&pGroup->AnnotationCount, &pGroup->pAnnotations) );
-
- for( size_t iTechnique=0; iTechnique < psGroup->cTechniques; iTechnique++ )
- {
- VH( LoadTechnique( &pGroup->pTechniques[iTechnique] ) );
- }
- TechniquesInEffect += psGroup->cTechniques;
- }
-
- VBD( TechniquesInEffect == m_pHeader->cTechniques, "Loading error: technique count mismatch." );
- m_pEffect->m_TechniqueCount = m_pHeader->cTechniques;
- m_pEffect->m_GroupCount = m_pHeader->cGroups;
-
-lExit:
- return hr;
-}
-
-
-// Read info from the compiled blob and initialize a technique (and contained passes)
-HRESULT CEffectLoader::LoadTechnique( STechnique* pTech )
-{
- HRESULT hr = S_OK;
- uint32_t iPass;
-
- SBinaryTechnique *psTech;
-
- // Read technique info
- VHD( m_msStructured.Read((void**) &psTech, sizeof(*psTech)), "Invalid pEffectBuffer: cannot read technique." );
- pTech->PassCount = psTech->cPasses;
- VN( pTech->pPasses = PRIVATENEW SPassBlock[pTech->PassCount] );
- VHD( GetStringAndAddToReflection(psTech->oName, &pTech->pName), "Invalid pEffectBuffer: cannot read technique name." );
-
- // Read annotations
- VH( LoadAnnotations(&pTech->AnnotationCount, &pTech->pAnnotations) );
-
- for (iPass=0; iPass<psTech->cPasses; iPass++)
- {
- SBinaryPass *psPass;
- SPassBlock *pPass = &pTech->pPasses[iPass];
-
- // Read pass info
- VHD( m_msStructured.Read((void**) &psPass, sizeof(SBinaryPass)), "Invalid pEffectBuffer: cannot read pass." );
- VHD( GetStringAndAddToReflection(psPass->oName, &pPass->pName), "Invalid pEffectBuffer: cannot read pass name." );
-
- // Read annotations
- VH( LoadAnnotations(&pPass->AnnotationCount, &pPass->pAnnotations) );
-
- VH( LoadAssignments( psPass->cAssignments, &pPass->pAssignments, (uint8_t*)pPass, &pPass->BackingStore.RenderTargetViewCount, &pPass->AssignmentCount ) );
- VBD( pPass->BackingStore.RenderTargetViewCount <= D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, "Invalid pEffectBuffer: too many RTVs in pass." );
-
- // Initialize other pass information
- pPass->pEffect = m_pEffect;
- pPass->BlockType = EBT_Pass;
- }
-
-lExit:
- return hr;
-}
-
-
-// Read info from the compiled blob and initialize a set of annotations
-HRESULT CEffectLoader::LoadAnnotations(uint32_t *pcAnnotations, SAnnotation **ppAnnotations)
-{
- HRESULT hr = S_OK;
- uint32_t cAnnotations, i, oData;
- SAnnotation *pAnnotations = nullptr;
-
- VHD( m_msStructured.Read(&cAnnotations), "Invalid pEffectBuffer: cannot read anootation count." );
-
- if (cAnnotations)
- {
- uint32_t annotationsSize;
- CCheckedDword chkAnnotationsSize;
-
- chkAnnotationsSize = cAnnotations;
- chkAnnotationsSize *= sizeof(SAnnotation);
- VHD( chkAnnotationsSize.GetValue(&annotationsSize), "Overflow in annotations." );
-
- // we allocate raw bytes for annotations because they are polymorphic types that need to be placement new'ed
- VN( pAnnotations = (SAnnotation *) PRIVATENEW uint8_t[annotationsSize] );
-
- for (i=0; i<cAnnotations; i++)
- {
- SBinaryAnnotation *psAnnotation;
- SAnnotation *pAn = &pAnnotations[i];
- SType *pType;
-
- VHD( m_msStructured.Read((void**) &psAnnotation, sizeof(SBinaryAnnotation)), "Invalid pEffectBuffer: cannot read annotation." );
-
- VH( LoadTypeAndAddToPool(&pType, psAnnotation->oType) );
-
- // Make sure the right polymorphic type is created
- VH( PlacementNewVariable(pAn, pType, true) );
-
- pAn->pEffect = m_pEffect;
- pAn->pType = pType;
-
- VHD( GetStringAndAddToReflection(psAnnotation->oName, &pAn->pName), "Invalid pEffectBuffer: cannot read annotation name." );
-
- if (pType->IsObjectType(EOT_String))
- {
- uint32_t cElements = std::max<uint32_t>(1, pType->Elements);
- uint32_t j;
- VN( pAn->Data.pString = PRIVATENEW SString[cElements] );
- for (j = 0; j < cElements; ++ j)
- {
- // Read initializer offset
- VHD( m_msStructured.Read(&oData), "Invalid pEffectBuffer: cannot read string." );
-#pragma warning( disable : 6011 )
- VHD( GetStringAndAddToReflection(oData, &pAn->Data.pString[j].pString), "Invalid pEffectBuffer: cannot read string initializer." );
- }
- }
- else if (pType->BelongsInConstantBuffer())
- {
- void *pDefaultValue;
- uint32_t bytesUnpacked;
-
- // Read initializer offset
- VHD( m_msStructured.Read(&oData), "Invalid pEffectBuffer: cannot read annotation." );
-
- VBD( oData != 0, "Invalid pEffectBuffer: invalid anotation offset." );
-
- VN( pAn->Data.pGeneric = PRIVATENEW uint8_t[pType->TotalSize] );
- ZeroMemory(pAn->Data.pGeneric, pType->TotalSize);
- VHD( m_msUnstructured.ReadAtOffset(oData, pType->PackedSize, &pDefaultValue), "Invalid pEffectBuffer: cannot read variable default value." );
- VH( UnpackData((uint8_t*) pAn->Data.pGeneric, (uint8_t*) pDefaultValue, pType->PackedSize, pType, &bytesUnpacked) );
- VBD( bytesUnpacked == pType->PackedSize, "Invalid pEffectBuffer: packed sizes to not match." );
- }
- else
- {
- VHD( E_FAIL, "Invalid pEffectBuffer: invalid annotation type." );
- }
- }
- }
-
- *pcAnnotations = cAnnotations;
- *ppAnnotations = pAnnotations;
-lExit:
-
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// Build shader block dependencies from shader metadata
-//////////////////////////////////////////////////////////////////////////
-
-//
-// Grabs shader resource dependency information from the bytecode of the shader
-// (cbuffer, tbuffer, texture, buffer, sampler, and UAV dependencies),
-// and sets up the given SShaderBlock to point to the dependencies within the effect
-//
-HRESULT CEffectLoader::GrabShaderData(SShaderBlock *pShaderBlock)
-{
- HRESULT hr = S_OK;
- CEffectVector<SRange> vRanges[ER_Count], *pvRange;
-
- SRange *pRange = nullptr;
- CEffectVector<SConstantBuffer*> vTBuffers;
-
- //////////////////////////////////////////////////////////////////////////
- // Step 1: iterate through the resource binding structures and build
- // an "optimized" list of all of the dependencies
-
- D3D11_SHADER_DESC ShaderDesc;
- hr = pShaderBlock->pReflectionData->pReflection->GetDesc( &ShaderDesc );
- if ( FAILED(hr) )
- return hr;
-
- // Since we have the shader desc, let's find out if this is a nullptr GS
- if( D3D11_SHVER_GET_TYPE( ShaderDesc.Version ) == D3D11_SHVER_VERTEX_SHADER && pShaderBlock->GetShaderType() == EOT_GeometryShader )
- {
- pShaderBlock->pReflectionData->IsNullGS = true;
- }
-
- pShaderBlock->CBDepCount = pShaderBlock->ResourceDepCount = pShaderBlock->TBufferDepCount = pShaderBlock->SampDepCount = 0;
- pShaderBlock->UAVDepCount = pShaderBlock->InterfaceDepCount = 0;
-
- for(uint32_t i = 0; i < ShaderDesc.BoundResources; i++)
- {
- LPCSTR pName;
- uint32_t bindPoint, size;
- ERanges eRange = ER_CBuffer;
- SShaderResource *pShaderResource = nullptr;
- SUnorderedAccessView *pUnorderedAccessView = nullptr;
- SSamplerBlock *pSampler = nullptr;
- SConstantBuffer *pCB = nullptr;
- SVariable *pVariable = nullptr;
- bool isFX9TextureLoad = false;
- D3D11_SHADER_INPUT_BIND_DESC ResourceDesc;
-
- pShaderBlock->pReflectionData->pReflection->GetResourceBindingDesc( i, &ResourceDesc );
-
- // HUGE ASSUMPTION: the bindpoints we read in the shader metadata are sorted;
- // i.e. bindpoints are steadily increasing
- // If this assumption is not met, then we will hit an assert below
-
- pName = ResourceDesc.Name;
- bindPoint = ResourceDesc.BindPoint;
- size = ResourceDesc.BindCount;
-
- switch( ResourceDesc.Type )
- {
- case D3D_SIT_CBUFFER:
- eRange = ER_CBuffer;
-
- pCB = m_pEffect->FindCB(pName);
- VBD( nullptr != pCB, "Loading error: cannot find cbuffer." );
- VBD( size == 1, "Loading error: cbuffer arrays are not supported." );
- break;
-
- case D3D_SIT_TBUFFER:
- eRange = ER_Texture;
-
- pCB = m_pEffect->FindCB(pName);
- VBD( nullptr != pCB, "Loading error: cannot find tbuffer." );
- VBD( false != pCB->IsTBuffer, "Loading error: cbuffer found where tbuffer is expected." );
- VBD( size == 1, "Loading error: tbuffer arrays are not supported." );
- pShaderResource = &pCB->TBuffer;
- break;
-
- case D3D_SIT_TEXTURE:
- case D3D_SIT_STRUCTURED:
- case D3D_SIT_BYTEADDRESS:
- {
- eRange = ER_Texture;
-
- pVariable = m_pEffect->FindVariableByNameWithParsing(pName);
- VBD( pVariable != nullptr, "Loading error: cannot find SRV variable." );
- uint32_t elements = std::max<uint32_t>(1, pVariable->pType->Elements);
- VBD( size <= elements, "Loading error: SRV array size mismatch." );
-
- if (pVariable->pType->IsShaderResource())
- {
- // this is just a straight texture assignment
- pShaderResource = pVariable->Data.pShaderResource;
- }
- else
- {
- // This is a FX9/HLSL9-style texture load instruction that specifies only a sampler
- VBD( pVariable->pType->IsSampler(), "Loading error: shader dependency is neither an SRV nor sampler.");
- isFX9TextureLoad = true;
- pSampler = pVariable->Data.pSampler;
- // validate that all samplers actually used (i.e. based on size, not elements) in this variable have a valid TEXTURE assignment
- for (size_t j = 0; j < size; ++ j)
- {
- if (nullptr == pSampler[j].BackingStore.pTexture)
- {
- // print spew appropriately for samplers vs sampler arrays
- if (0 == pVariable->pType->Elements)
- {
- DPF(0, "%s: Sampler %s does not have a texture bound to it, even though the sampler is used in a DX9-style texture load instruction", g_szEffectLoadArea, pName);
- }
- else
- {
- DPF(0, "%s: Sampler %s[%zu] does not have a texture bound to it, even though the sampler array is used in a DX9-style texture load instruction", g_szEffectLoadArea, pName, j);
- }
-
- VH( E_FAIL );
- }
- }
- }
- }
- break;
-
- case D3D_SIT_UAV_RWTYPED:
- case D3D_SIT_UAV_RWSTRUCTURED:
- case D3D_SIT_UAV_RWBYTEADDRESS:
- case D3D_SIT_UAV_APPEND_STRUCTURED:
- case D3D_SIT_UAV_CONSUME_STRUCTURED:
- case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
- eRange = ER_UnorderedAccessView;
-
- pVariable = m_pEffect->FindVariableByNameWithParsing(pName);
- VBD( pVariable != nullptr, "Loading error: cannot find UAV variable." );
- VBD( size <= std::max<uint32_t>(1, pVariable->pType->Elements), "Loading error: UAV array index out of range." );
- VBD( pVariable->pType->IsUnorderedAccessView(), "Loading error: UAV variable expected." );
- pUnorderedAccessView = pVariable->Data.pUnorderedAccessView;
- break;
-
- case D3D_SIT_SAMPLER:
- eRange = ER_Sampler;
-
- pVariable = m_pEffect->FindVariableByNameWithParsing(pName);
- VBD( pVariable != nullptr, "Loading error: cannot find sampler variable." );
- VBD( size <= std::max<uint32_t>(1, pVariable->pType->Elements), "Loading error: sampler array index out of range." );
- VBD( pVariable->pType->IsSampler(), "Loading error: sampler variable expected." );
- pSampler = pVariable->Data.pSampler;
- break;
-
- default:
- VHD( E_FAIL, "Internal loading error: unexpected shader dependency type." );
- };
-
- //
- // Here's where the "optimized" part comes in; whenever there's
- // a resource dependency, see if it's located contiguous to
- // an existing resource dependency and merge them together
- // if possible
- //
- uint32_t rangeCount;
- pvRange = &vRanges[eRange];
- rangeCount = pvRange->GetSize();
-
- if ( rangeCount > 0 )
- {
- // Can we continue an existing range?
- pRange = &( (*pvRange)[rangeCount - 1] );
-
- // Make sure that bind points are strictly increasing,
- // otherwise this algorithm breaks and we'd get worse runtime performance
- assert(pRange->last <= bindPoint);
-
- if ( pRange->last != bindPoint )
- {
- if( eRange != ER_UnorderedAccessView )
- {
- // No we can't. Begin a new range by setting rangeCount to 0 and triggering the next IF
- rangeCount = 0;
- }
- else
- {
- // UAVs will always be located in one range, as they are more expensive to set
- while(pRange->last < bindPoint)
- {
- VHD( pRange->vResources.Add(&g_NullUnorderedAccessView), "Internal loading error: cannot add UAV to range." );
- pRange->last++;
- }
- }
- }
- }
-
- if ( rangeCount == 0 )
- {
- VN( pRange = pvRange->Add() );
- pRange->start = bindPoint;
- }
-
- pRange->last = bindPoint + size;
-
- switch( ResourceDesc.Type )
- {
- case D3D_SIT_CBUFFER:
- VHD( pRange->vResources.Add(pCB), "Internal loading error: cannot add cbuffer to range." );
- break;
- case D3D_SIT_TBUFFER:
- VHD( pRange->vResources.Add(pShaderResource), "Internal loading error: cannot add tbuffer to range." );
- VHD( vTBuffers.Add( (SConstantBuffer*)pCB ), "Internal loading error: cannot add tbuffer to vector." );
- break;
- case D3D_SIT_TEXTURE:
- case D3D_SIT_STRUCTURED:
- case D3D_SIT_BYTEADDRESS:
- if (isFX9TextureLoad)
- {
- // grab all of the textures from each sampler
- for (size_t j = 0; j < size; ++ j)
- {
- VHD( pRange->vResources.Add(pSampler[j].BackingStore.pTexture), "Internal loading error: cannot add SRV to range." );
- }
- }
- else
- {
- // add the whole array
- for (size_t j = 0; j < size; ++ j)
- {
- VHD( pRange->vResources.Add(pShaderResource + j), "Internal loading error: cannot add SRV to range." );
- }
- }
- break;
- case D3D_SIT_UAV_RWTYPED:
- case D3D_SIT_UAV_RWSTRUCTURED:
- case D3D_SIT_UAV_RWBYTEADDRESS:
- case D3D_SIT_UAV_APPEND_STRUCTURED:
- case D3D_SIT_UAV_CONSUME_STRUCTURED:
- case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
- // add the whole array
- for (size_t j = 0; j < size; ++ j)
- {
- VHD( pRange->vResources.Add(pUnorderedAccessView + j), "Internal loading error: cannot add UAV to range." );
- }
- break;
- case D3D_SIT_SAMPLER:
- // add the whole array
- for (size_t j = 0; j < size; ++ j)
- {
- VHD( pRange->vResources.Add(pSampler + j), "Internal loading error: cannot add sampler to range." );
- }
- break;
- default:
- VHD( E_FAIL, "Internal loading error: unexpected shader dependency type." );
- }
- }
-
-
- //////////////////////////////////////////////////////////////////////////
- // Step 2: iterate through the interfaces and build
- // an "optimized" list of all of the dependencies
-
- uint32_t NumInterfaces = pShaderBlock->pReflectionData->pReflection->GetNumInterfaceSlots();
- uint32_t CurInterfaceParameter = 0;
- if( NumInterfaces > 0 )
- {
- assert( ShaderDesc.ConstantBuffers > 0 );
-
- for( uint32_t i=0; i < ShaderDesc.ConstantBuffers; i++ )
- {
- ID3D11ShaderReflectionConstantBuffer* pCB = pShaderBlock->pReflectionData->pReflection->GetConstantBufferByIndex(i);
- VN( pCB );
- D3D11_SHADER_BUFFER_DESC CBDesc;
- VHD( pCB->GetDesc( &CBDesc ), "Internal loading error: cannot get CB desc." );
- if( CBDesc.Type != D3D11_CT_INTERFACE_POINTERS )
- {
- continue;
- }
-
- for( uint32_t iVar=0; iVar < CBDesc.Variables; iVar++ )
- {
- ID3D11ShaderReflectionVariable* pInterfaceVar = pCB->GetVariableByIndex( iVar );
- VN( pInterfaceVar );
- D3D11_SHADER_VARIABLE_DESC InterfaceDesc;
- VHD( pInterfaceVar->GetDesc(&InterfaceDesc), "Internal load error: cannot get IV desc.");
-
- LPCSTR pName;
- uint32_t bindPoint, size;
- SGlobalVariable *pVariable = nullptr;
- SInterface *pInterface = nullptr;
- uint32_t VariableElements;
-
- pName = InterfaceDesc.Name;
- bindPoint = InterfaceDesc.StartOffset;
- size = InterfaceDesc.Size;
-
- if( bindPoint == (uint32_t)-1 )
- {
- continue;
- }
-
- assert( InterfaceDesc.uFlags & D3D11_SVF_INTERFACE_POINTER );
- if( InterfaceDesc.uFlags & D3D11_SVF_INTERFACE_PARAMETER )
- {
- // This interface pointer is a parameter to the shader
- if( pShaderBlock->pReflectionData->InterfaceParameterCount == 0 )
- {
- // There may be no interface parameters in this shader if it was compiled but had no interfaced bound to it.
- // The shader cannot be set (correctly) in any pass.
- continue;
- }
- else
- {
- VBD( CurInterfaceParameter < pShaderBlock->pReflectionData->InterfaceParameterCount,
- "Internal loading error: interface count mismatch.");
- SShaderBlock::SInterfaceParameter* pInterfaceInfo;
- pInterfaceInfo = &pShaderBlock->pReflectionData->pInterfaceParameters[CurInterfaceParameter];
- ++CurInterfaceParameter;
- SGlobalVariable *pParent = m_pEffect->FindVariableByName(pInterfaceInfo->pName);
- VBD( pParent != nullptr, "Loading error: cannot find parent type." );
- if( pInterfaceInfo->Index == (uint32_t)-1 )
- {
- pVariable = pParent;
- VariableElements = pVariable->pType->Elements;
- }
- else
- {
- // We want a specific index of the variable (ex. "MyVar[2]")
- VBD( size == 1, "Loading error: interface array type mismatch." );
- pVariable = (SGlobalVariable*)pParent->GetElement( pInterfaceInfo->Index );
- VBD( pVariable->IsValid(), "Loading error: interface array index out of range." );
- VariableElements = 0;
- }
- }
- }
- else
- {
- // This interface pointer is a global interface used in the shader
- pVariable = m_pEffect->FindVariableByName(pName);
- VBD( pVariable != nullptr, "Loading error: cannot find interface variable." );
- VariableElements = pVariable->pType->Elements;
- }
- VBD( size <= std::max<uint32_t>(1, VariableElements), "Loading error: interface array size mismatch." );
- if( pVariable->pType->IsInterface() )
- {
- pInterface = pVariable->Data.pInterface;
- }
- else if( pVariable->pType->IsClassInstance() )
- {
- // For class instances, we create background interfaces which point to the class instance. This is done so
- // the shader can always expect SInterface dependencies, rather than a mix of SInterfaces and class instances
- VN( pInterface = PRIVATENEW SInterface[size] );
- if( VariableElements == 0 )
- {
- assert( size == 1 );
- pInterface[0].pClassInstance = (SClassInstanceGlobalVariable*)pVariable;
- m_BackgroundInterfaces.Add( &pInterface[0] );
- }
- else
- {
- // Fill each element of the SInstance array individually
- VBD( size == VariableElements, "Loading error: class instance array size mismatch." );
- for( uint32_t iElement=0; iElement < size; iElement++ )
- {
- SGlobalVariable *pElement = (SGlobalVariable*)pVariable->GetElement( iElement );
- VBD( pElement->IsValid(), "Internal loading error: class instance array index out of range." );
- pInterface[iElement].pClassInstance = (SClassInstanceGlobalVariable*)pElement;
- m_BackgroundInterfaces.Add( &pInterface[iElement] );
- }
- }
- }
- else
- {
- VHD( E_FAIL, "Loading error: invalid interface initializer variable type.");
- }
-
- //
- // Here's where the "optimized" part comes in; whenever there's
- // a resource dependency, see if it's located contiguous to
- // an existing resource dependency and merge them together
- // if possible
- //
- uint32_t rangeCount;
- pvRange = &vRanges[ER_Interfaces];
- rangeCount = pvRange->GetSize();
-
- VBD( rangeCount <= 1, "Internal loading error: invalid range count." );
-
- if ( rangeCount == 0 )
- {
- VN( pRange = pvRange->Add() );
- pRange->start = pRange->last = 0;
- }
- else
- {
- pRange = &( (*pvRange)[0] );
- }
-
- if( bindPoint < pRange->last )
- {
- // add interfaces into the range that already exists
- VBD( bindPoint + size < pRange->last, "Internal loading error: range overlap." );
- for( uint32_t j = 0; j < size; ++ j )
- {
- pRange->vResources[j + bindPoint] = pInterface + j;
- }
- }
- else
- {
- // add interfaces to the end of the range
-
- // add missing interface slots, if necessary
- while(pRange->last < bindPoint)
- {
- VHD( pRange->vResources.Add(&g_NullInterface), "Internal loading error: cannot add nullptr interface to range." );
- pRange->last++;
- }
-
- assert( bindPoint == pRange->last );
- for( size_t j=0; j < size; ++ j )
- {
- VHD( pRange->vResources.Add(pInterface + j), "Internal loading error: cannot at interface to range." );
- }
- pRange->last = bindPoint + size;
- }
- }
-
- // There is only one interface cbuffer
- break;
- }
- }
-
- //////////////////////////////////////////////////////////////////////////
- // Step 3: allocate room in pShaderBlock for all of the dependency
- // pointers and then hook them up
-
- pShaderBlock->SampDepCount = vRanges[ ER_Sampler ].GetSize();
- pShaderBlock->CBDepCount = vRanges[ ER_CBuffer ].GetSize();
- pShaderBlock->InterfaceDepCount = vRanges[ ER_Interfaces ].GetSize();
- pShaderBlock->ResourceDepCount = vRanges[ ER_Texture ].GetSize();
- pShaderBlock->UAVDepCount = vRanges[ ER_UnorderedAccessView ].GetSize();
- pShaderBlock->TBufferDepCount = vTBuffers.GetSize();
-
- VN( pShaderBlock->pSampDeps = PRIVATENEW SShaderSamplerDependency[pShaderBlock->SampDepCount] );
- VN( pShaderBlock->pCBDeps = PRIVATENEW SShaderCBDependency[pShaderBlock->CBDepCount] );
- VN( pShaderBlock->pInterfaceDeps = PRIVATENEW SInterfaceDependency[pShaderBlock->InterfaceDepCount] );
- VN( pShaderBlock->pResourceDeps = PRIVATENEW SShaderResourceDependency[pShaderBlock->ResourceDepCount] );
- VN( pShaderBlock->pUAVDeps = PRIVATENEW SUnorderedAccessViewDependency[pShaderBlock->UAVDepCount] );
- VN( pShaderBlock->ppTbufDeps = PRIVATENEW SConstantBuffer*[pShaderBlock->TBufferDepCount] );
-
- for (size_t i=0; i<pShaderBlock->CBDepCount; ++i)
- {
- SShaderCBDependency *pDep = &pShaderBlock->pCBDeps[i];
-
- pRange = &vRanges[ER_CBuffer][i];
-
- pDep->StartIndex = pRange->start;
- pDep->Count = pRange->last - pDep->StartIndex;
- pDep->ppFXPointers = PRIVATENEW SConstantBuffer*[ pDep->Count ];
- pDep->ppD3DObjects = PRIVATENEW ID3D11Buffer*[ pDep->Count ];
-
- assert(pDep->Count == pRange->vResources.GetSize());
- for (size_t j=0; j<pDep->Count; ++j)
- {
- pDep->ppFXPointers[j] = (SConstantBuffer *)pRange->vResources[j];
- pDep->ppD3DObjects[j] = nullptr;
- }
- }
-
- for (size_t i=0; i<pShaderBlock->SampDepCount; ++i)
- {
- SShaderSamplerDependency *pDep = &pShaderBlock->pSampDeps[i];
-
- pRange = &vRanges[ER_Sampler][i];
-
- pDep->StartIndex = pRange->start;
- pDep->Count = pRange->last - pDep->StartIndex;
- pDep->ppFXPointers = PRIVATENEW SSamplerBlock*[ pDep->Count ];
- pDep->ppD3DObjects = PRIVATENEW ID3D11SamplerState*[ pDep->Count ];
-
- assert(pDep->Count == pRange->vResources.GetSize());
- for (size_t j=0; j<pDep->Count; ++j)
- {
- pDep->ppFXPointers[j] = (SSamplerBlock *) pRange->vResources[j];
- pDep->ppD3DObjects[j] = nullptr;
- }
- }
-
- for (size_t i=0; i<pShaderBlock->InterfaceDepCount; ++i)
- {
- SInterfaceDependency *pDep = &pShaderBlock->pInterfaceDeps[i];
-
- pRange = &vRanges[ER_Interfaces][i];
-
- pDep->StartIndex = pRange->start;
- pDep->Count = pRange->last - pDep->StartIndex;
- pDep->ppFXPointers = PRIVATENEW SInterface*[ pDep->Count ];
- pDep->ppD3DObjects = PRIVATENEW ID3D11ClassInstance*[ pDep->Count ];
-
- assert(pDep->Count == pRange->vResources.GetSize());
- for (size_t j=0; j<pDep->Count; ++j)
- {
- pDep->ppFXPointers[j] = (SInterface *) pRange->vResources[j];
- pDep->ppD3DObjects[j] = nullptr;
- }
- }
-
- for (size_t i=0; i<pShaderBlock->ResourceDepCount; ++i)
- {
- SShaderResourceDependency *pDep = &pShaderBlock->pResourceDeps[i];
-
- pRange = &vRanges[ER_Texture][i];
-
- pDep->StartIndex = pRange->start;
- pDep->Count = pRange->last - pDep->StartIndex;
- pDep->ppFXPointers = PRIVATENEW SShaderResource*[ pDep->Count ];
- pDep->ppD3DObjects = PRIVATENEW ID3D11ShaderResourceView*[ pDep->Count ];
-
- assert(pDep->Count == pRange->vResources.GetSize());
- for (size_t j=0; j<pDep->Count; ++j)
- {
- pDep->ppFXPointers[j] = (SShaderResource *) pRange->vResources[j];
- pDep->ppD3DObjects[j] = nullptr;
- }
- }
-
- for (size_t i=0; i<pShaderBlock->UAVDepCount; ++i)
- {
- SUnorderedAccessViewDependency *pDep = &pShaderBlock->pUAVDeps[i];
-
- pRange = &vRanges[ER_UnorderedAccessView][i];
-
- pDep->StartIndex = pRange->start;
- pDep->Count = pRange->last - pDep->StartIndex;
- pDep->ppFXPointers = PRIVATENEW SUnorderedAccessView*[ pDep->Count ];
- pDep->ppD3DObjects = PRIVATENEW ID3D11UnorderedAccessView*[ pDep->Count ];
-
- assert(pDep->Count == pRange->vResources.GetSize());
- for (size_t j=0; j<pDep->Count; ++j)
- {
- pDep->ppFXPointers[j] = (SUnorderedAccessView *) pRange->vResources[j];
- pDep->ppD3DObjects[j] = nullptr;
- }
- }
-
- if (pShaderBlock->TBufferDepCount > 0)
- {
- memcpy(pShaderBlock->ppTbufDeps, &vTBuffers[0], pShaderBlock->TBufferDepCount * sizeof(SConstantBuffer*));
- }
-
-lExit:
- return hr;
-}
-
-// Create shader reflection interface and grab dependency info
-HRESULT CEffectLoader::BuildShaderBlock(SShaderBlock *pShaderBlock)
-{
- HRESULT hr = S_OK;
-
- // unused shader block? that's not right
- VBD( pShaderBlock->pVT != nullptr, "Internal loading error: nullptr shader vtable." );
-
- assert(pShaderBlock->pD3DObject == nullptr);
-
- if (nullptr == pShaderBlock->pReflectionData)
- {
- // File contains a shader variable without an assigned shader, or this is a null assignment.
- // Usually, this is called by one of these guys:
- // SetVertexShader( nullptr );
- // or
- // vertexshader g_VS = nullptr;
- return S_OK;
- }
-
- // Initialize the reflection interface
- VHD( D3DReflect( pShaderBlock->pReflectionData->pBytecode, pShaderBlock->pReflectionData->BytecodeLength, IID_ID3D11ShaderReflection, (void**)&pShaderBlock->pReflectionData->pReflection ),
- "Internal loading error: cannot create shader reflection object." );
-
- // Get dependencies
- VH( GrabShaderData( pShaderBlock ) );
-
- // Grab input signatures for VS
- if( EOT_VertexShader == pShaderBlock->GetShaderType() )
- {
- assert( pShaderBlock->pInputSignatureBlob == nullptr );
- VHD( D3DGetBlobPart( pShaderBlock->pReflectionData->pBytecode, pShaderBlock->pReflectionData->BytecodeLength,
- D3D_BLOB_INPUT_SIGNATURE_BLOB, 0,
- &pShaderBlock->pInputSignatureBlob ),
- "Internal loading error: cannot get input signature." );
- }
-
-lExit:
- return hr;
-}
-
-#undef PRIVATENEW
-
-
-//////////////////////////////////////////////////////////////////////////
-// Code to relocate data to private heaps (reflection & runtime effect)
-//
-// Important note about alignment: all reasonable chunks of data are
-// machine word aligned (that is, any piece of data moved as a whole is
-// aligned as a whole. This means that when computing m_ReflectionMemory
-// or m_EffectMemory, each addition is aligned. This also means
-// that, when later relocating that same memory, you must call MoveData
-// or MoveString on the same chunks that were aligned. This is
-// because: Align(a * b) != a * Align(b).
-//////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////
-// Reflection reallocation code
-//////////////////////////////////////////////////////////////////////////
-
-HRESULT CEffectLoader::CalculateAnnotationSize(uint32_t cAnnotations, SAnnotation *pAnnotations)
-{
- HRESULT hr = S_OK;
- uint32_t i;
-
- m_ReflectionMemory += AlignToPowerOf2(cAnnotations * sizeof(SAnnotation), c_DataAlignment);
- for (i=0; i<cAnnotations; i++)
- {
- if (pAnnotations[i].pType->BelongsInConstantBuffer())
- {
- m_ReflectionMemory += AlignToPowerOf2(pAnnotations[i].pType->TotalSize, c_DataAlignment);
- }
- else
- {
- VBD( pAnnotations[i].pType->IsObjectType(EOT_String), "Invalid pEffectBuffer: invalid annotation type." );
-
- uint32_t cElements = std::max<uint32_t>(1, pAnnotations[i].pType->Elements);
-
- m_ReflectionMemory += AlignToPowerOf2(cElements * sizeof(SString), c_DataAlignment);
-
- }
- }
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::ReallocateAnnotationData(uint32_t cAnnotations, SAnnotation **ppAnnotations)
-{
- HRESULT hr = S_OK;
- uint32_t i;
- SAnnotation *pAnnotations;
-
- VHD( m_pReflection->m_Heap.MoveData((void**) ppAnnotations, cAnnotations * sizeof(SAnnotation)),
- "Internal loading error: cannot move annotation data." );
- pAnnotations = *ppAnnotations;
-
- for (i=0; i<cAnnotations; i++)
- {
- SAnnotation *pAn = &pAnnotations[i];
- pAn->pEffect = m_pEffect;
-
- VHD( m_pReflection->m_Heap.MoveString(&pAn->pName), "Internal loading error: cannot move annotation name." );
-
- // Reallocate type later
- if (pAn->pType->BelongsInConstantBuffer())
- {
- VHD( m_pReflection->m_Heap.MoveData( &pAn->Data.pGeneric, pAn->pType->TotalSize ), "Internal loading error: cannot move annotation data." );
- }
- else if (pAnnotations[i].pType->IsObjectType(EOT_String))
- {
- uint32_t cElements = std::max<uint32_t>(1, pAn->pType->Elements);
-
- VHD( m_pReflection->m_Heap.MoveData((void**) &pAn->Data.pString, cElements * sizeof(SString)), "Internal loading error: cannot move annotation string." );
- for (size_t j = 0; j < cElements; ++ j)
- {
- VHD( m_pReflection->m_Heap.MoveString(&pAn->Data.pString[j].pString), "Internal loading error: cannot move annotation string element." );
- }
- }
- else
- {
- VHD( E_FAIL, "Invalid pEffectBuffer: invalid annotation type." );
- }
- }
-
-lExit:
- return hr;
-}
-
-HRESULT CEffectLoader::InitializeReflectionDataAndMoveStrings( uint32_t KnownSize )
-{
- HRESULT hr = S_OK;
- uint32_t cbStrings;
- CEffectHeap *pHeap = &m_pReflection->m_Heap;
-
- // Get byte counts
- cbStrings = m_pEffect->m_StringCount * sizeof( SString );
-
- if( KnownSize )
- {
- m_ReflectionMemory = KnownSize;
- }
- else
- {
- m_ReflectionMemory += AlignToPowerOf2(cbStrings, c_DataAlignment);
-
- for (size_t i=0; i<m_pEffect->m_CBCount; i++)
- {
- VH( CalculateAnnotationSize(m_pEffect->m_pCBs[i].AnnotationCount, m_pEffect->m_pCBs[i].pAnnotations) );
- }
-
- for (size_t i=0; i<m_pEffect->m_VariableCount; i++)
- {
- VH( CalculateAnnotationSize(m_pEffect->m_pVariables[i].AnnotationCount, m_pEffect->m_pVariables[i].pAnnotations) );
- }
-
- for (size_t i=0; i<m_pEffect->m_GroupCount; i++)
- {
- VH( CalculateAnnotationSize(m_pEffect->m_pGroups[i].AnnotationCount, m_pEffect->m_pGroups[i].pAnnotations) );
-
- for (size_t j=0; j<m_pEffect->m_pGroups[i].TechniqueCount; j++)
- {
- VH( CalculateAnnotationSize(m_pEffect->m_pGroups[i].pTechniques[j].AnnotationCount, m_pEffect->m_pGroups[i].pTechniques[j].pAnnotations) );
-
- for (size_t k=0; k<m_pEffect->m_pGroups[i].pTechniques[j].PassCount; k++)
- {
- VH( CalculateAnnotationSize(m_pEffect->m_pGroups[i].pTechniques[j].pPasses[k].AnnotationCount, m_pEffect->m_pGroups[i].pTechniques[j].pPasses[k].pAnnotations) );
- }
- }
- }
-
- // Calculate shader reflection data size
- for (size_t i=0; i<m_pEffect->m_ShaderBlockCount; i++)
- {
- if (nullptr != m_pEffect->m_pShaderBlocks[i].pReflectionData)
- {
- m_ReflectionMemory += AlignToPowerOf2(sizeof(SShaderBlock::SReflectionData), c_DataAlignment);
- m_ReflectionMemory += AlignToPowerOf2(m_pEffect->m_pShaderBlocks[i].pReflectionData->BytecodeLength, c_DataAlignment);
- // stream out decl is handled as a string, and thus its size is already factored because of GetStringAndAddToReflection
- }
- }
- }
-
- VHD( pHeap->ReserveMemory(m_ReflectionMemory), "Internal loading error: failed to reserve reflection memory." );
-
- // Strings are handled separately because we are moving them to reflection
- m_pOldStrings = m_pEffect->m_pStrings;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pStrings, cbStrings), "Internal loading error: cannot move string data." );
- for(size_t i=0; i<m_pEffect->m_StringCount; i++)
- {
- VHD( pHeap->MoveString( &m_pEffect->m_pStrings[i].pString), "Internal loading error: cannot move string pointer." );
- }
-
-lExit:
- return hr;
-}
-
-// Move all reflection data to private heap
-HRESULT CEffectLoader::ReallocateReflectionData( bool Cloning )
-{
- HRESULT hr = S_OK;
- CEffectHeap *pHeap = &m_pReflection->m_Heap;
-
- for(size_t i=0; i<m_pEffect->m_CBCount; i++)
- {
- VHD( pHeap->MoveString( &m_pEffect->m_pCBs[i].pName ), "Internal loading error: cannot move CB name." );
- VH( ReallocateAnnotationData(m_pEffect->m_pCBs[i].AnnotationCount, &m_pEffect->m_pCBs[i].pAnnotations) );
- }
-
- for(size_t i=0; i<m_pEffect->m_VariableCount; i++)
- {
- VHD( pHeap->MoveString( &m_pEffect->m_pVariables[i].pName ), "Internal loading error: cannot move variable name." );
- VHD( pHeap->MoveString( &m_pEffect->m_pVariables[i].pSemantic ), "Internal loading error: cannot move variable semantic." );
- VH( ReallocateAnnotationData(m_pEffect->m_pVariables[i].AnnotationCount, &m_pEffect->m_pVariables[i].pAnnotations) );
- }
-
- for(size_t i=0; i<m_pEffect->m_GroupCount; i++)
- {
- VHD( pHeap->MoveString( &m_pEffect->m_pGroups[i].pName ), "Internal loading error: cannot move group name." );
- VH( ReallocateAnnotationData(m_pEffect->m_pGroups[i].AnnotationCount, &m_pEffect->m_pGroups[i].pAnnotations) );
-
- for(size_t j=0; j<m_pEffect->m_pGroups[i].TechniqueCount; j++)
- {
- VHD( pHeap->MoveString( &m_pEffect->m_pGroups[i].pTechniques[j].pName ), "Internal loading error: cannot move technique name." );
- VH( ReallocateAnnotationData(m_pEffect->m_pGroups[i].pTechniques[j].AnnotationCount, &m_pEffect->m_pGroups[i].pTechniques[j].pAnnotations) );
-
- for(size_t k=0; k<m_pEffect->m_pGroups[i].pTechniques[j].PassCount; k++)
- {
- VHD( pHeap->MoveString( &m_pEffect->m_pGroups[i].pTechniques[j].pPasses[k].pName ), "Internal loading error: cannot move pass name." );
- VH( ReallocateAnnotationData(m_pEffect->m_pGroups[i].pTechniques[j].pPasses[k].AnnotationCount, &m_pEffect->m_pGroups[i].pTechniques[j].pPasses[k].pAnnotations) );
- }
- }
- }
-
- if( !Cloning )
- {
- // When not cloning, every member in m_pMemberInterfaces is from a global variable, so we can take pName and pSemantic
- // from the parent variable, which were updated above
- for (size_t i = 0; i < m_pEffect->m_pMemberInterfaces.GetSize(); ++ i)
- {
- SMember* pMember = m_pEffect->m_pMemberInterfaces[i];
- SGlobalVariable* pTopLevelEntity = (SGlobalVariable*)pMember->pTopLevelEntity;
- VH( FixupVariablePointer( &pTopLevelEntity ) );
- pMember->pName = pTopLevelEntity->pName;
- pMember->pSemantic = pTopLevelEntity->pSemantic;
- }
- }
-
- // Move shader bytecode
- for (size_t i=0; i<m_pEffect->m_ShaderBlockCount; i++)
- {
- if (nullptr != m_pEffect->m_pShaderBlocks[i].pReflectionData)
- {
- VHD( pHeap->MoveData((void**)&m_pEffect->m_pShaderBlocks[i].pReflectionData, sizeof(SShaderBlock::SReflectionData)),
- "Internal loading error: cannot move shader reflection block." );
- VHD( pHeap->MoveData((void**)&m_pEffect->m_pShaderBlocks[i].pReflectionData->pBytecode, m_pEffect->m_pShaderBlocks[i].pReflectionData->BytecodeLength),
- "Internal loading error: cannot move shader bytecode.");
- for( size_t iDecl=0; iDecl < D3D11_SO_STREAM_COUNT; ++iDecl )
- {
- VHD( pHeap->MoveString(&m_pEffect->m_pShaderBlocks[i].pReflectionData->pStreamOutDecls[iDecl]), "Internal loading error: cannot move SO decl." );
- }
- VH( pHeap->MoveInterfaceParameters(m_pEffect->m_pShaderBlocks[i].pReflectionData->InterfaceParameterCount, &m_pEffect->m_pShaderBlocks[i].pReflectionData->pInterfaceParameters ) );
- }
-
- }
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// Runtime effect reallocation code
-//////////////////////////////////////////////////////////////////////////
-
-template<class T> HRESULT CEffectLoader::ReallocateBlockAssignments(T* &pBlocks, uint32_t cBlocks, T* pOldBlocks)
-{
- HRESULT hr = S_OK;
- CEffectHeap *pHeap = &m_pEffect->m_Heap;
-
- for(size_t i=0; i<cBlocks; i++)
- {
- T *pBlock = &pBlocks[i];
- VHD( pHeap->MoveData((void**) &pBlock->pAssignments, sizeof(SAssignment)*pBlock->AssignmentCount), "Internal loading error: cannot move assignment count." );
-
- for (size_t j=0; j<pBlock->AssignmentCount; j++)
- {
- SAssignment *pAssignment = &pBlock->pAssignments[j];
- uint32_t cbDeps;
-
- // When cloning, convert pointers back into offsets
- if( pOldBlocks )
- {
- T *pOldBlock = &pOldBlocks[i];
- pAssignment->Destination.Offset = (uint32_t)( (UINT_PTR)pAssignment->Destination.pGeneric - (UINT_PTR)pOldBlock ) ;
- }
-
- // Convert destination pointers from offset to real pointer
- pAssignment->Destination.pGeneric = (uint8_t*) pBlock + pAssignment->Destination.Offset;
-
- // Make sure the data pointer points into the backing store
- VBD( pAssignment->Destination.pGeneric >= &pBlock->BackingStore &&
- pAssignment->Destination.pGeneric < (uint8_t*) &pBlock->BackingStore + sizeof(pBlock->BackingStore),
- "Internal loading error: assignment destination out of range." );
-
- // Fixup dependencies
- cbDeps = pAssignment->DependencyCount * sizeof(SAssignment::SDependency);
- VHD( pHeap->MoveData((void**) &pAssignment->pDependencies, cbDeps), "Internal loading error: cannot move assignment dependencies." );
-
- SGlobalVariable *pOldVariable = nullptr;
- for(size_t iDep=0; iDep<pAssignment->DependencyCount; iDep++)
- {
- SAssignment::SDependency *pDep = &pAssignment->pDependencies[iDep];
- // We ignore all but the last variable because below, we only use the last dependency
- pOldVariable = pDep->pVariable;
- VH( FixupVariablePointer(&pDep->pVariable) );
- }
-
- // Fixup source pointers
- switch(pAssignment->LhsType)
- {
- case ELHS_VertexShaderBlock:
- case ELHS_PixelShaderBlock:
- case ELHS_GeometryShaderBlock:
- case ELHS_HullShaderBlock:
- case ELHS_DomainShaderBlock:
- case ELHS_ComputeShaderBlock:
- VH( FixupShaderPointer(&pAssignment->Source.pShader) );
- break;
-
- case ELHS_DepthStencilBlock:
- VH( FixupDSPointer((SDepthStencilBlock**)&pAssignment->Source.pBlock) );
- break;
- case ELHS_BlendBlock:
- VH( FixupABPointer((SBlendBlock**) &pAssignment->Source.pBlock) );
- break;
- case ELHS_RasterizerBlock:
- VH( FixupRSPointer((SRasterizerBlock**) &pAssignment->Source.pBlock) );
- break;
-
- case ELHS_Texture:
- VH( FixupShaderResourcePointer((SShaderResource**) &pAssignment->Source.pShaderResource) );
- break;
-
- default:
- // Non-object assignment (must have at least one dependency or it would have been pruned by now)
- assert( !pAssignment->IsObjectAssignment() && pAssignment->DependencyCount > 0 );
-
- // Numeric variables must be relocated before this function is called
-
- switch (pAssignment->AssignmentType)
- {
- case ERAT_NumericVariable:
- case ERAT_NumericVariableIndex:
- // the variable or variable array is always the last dependency in the chain
- SGlobalVariable *pVariable;
- pVariable = pAssignment->pDependencies[pAssignment->DependencyCount - 1].pVariable;
- assert( pVariable->pType->BelongsInConstantBuffer() && nullptr != pVariable->pCB );
-
- // When cloning, convert pointers back into offsets
- if( pOldBlocks )
- {
- VBD( pOldVariable != nullptr, "Internal loading error: pOldVariable is nullptr." );
- pAssignment->Source.Offset = pAssignment->Source.pNumeric - pOldVariable->pCB->pBackingStore;
- }
-
- // Convert from offset to pointer
- pAssignment->Source.pNumeric = pVariable->pCB->pBackingStore + pAssignment->Source.Offset;
- break;
-
- default:
- // Shouldn't be able to get here
- assert(0);
- VHD( E_FAIL, "Loading error: invalid assignment type." );
- }
- break;
-
- case ELHS_Invalid:
- VHD( E_FAIL, "Loading error: invalid assignment type." );
- }
-
- assert(m_pEffect->m_LocalTimer > 0);
- m_pEffect->EvaluateAssignment(pAssignment);
- }
- }
-
-lExit:
- return hr;
-}
-
-template<class T> uint32_t CEffectLoader::CalculateBlockAssignmentSize(T* &pBlocks, uint32_t cBlocks)
-{
- uint32_t dwSize = 0;
-
- for(size_t i=0; i<cBlocks; i++)
- {
- SBaseBlock *pBlock = &pBlocks[i];
- dwSize += AlignToPowerOf2(pBlock->AssignmentCount * sizeof(SAssignment), c_DataAlignment);
-
- for (size_t j=0; j<pBlock->AssignmentCount; j++)
- {
- SAssignment *pAssignment = &pBlock->pAssignments[j];
-
- dwSize += AlignToPowerOf2(pAssignment->DependencyCount * sizeof(SAssignment::SDependency), c_DataAlignment);
- }
- }
-
- return dwSize;
-}
-
-HRESULT CEffectLoader::ReallocateShaderBlocks()
-{
- HRESULT hr = S_OK;
- CEffectHeap *pHeap = &m_pEffect->m_Heap;
- const char* pError = "Internal loading error: cannot move shader data.";
-
- for (size_t i=0; i<m_pEffect->m_ShaderBlockCount; i++)
- {
- SShaderBlock *pShader = &m_pEffect->m_pShaderBlocks[i];
-
- // pShader->pReflection data and all of its members (bytecode, SO decl, etc.) are handled by ReallocateReflectionData()
- VHD( pHeap->MoveData((void**) &pShader->pCBDeps, pShader->CBDepCount * sizeof(SShaderCBDependency)), pError );
- VHD( pHeap->MoveData((void**) &pShader->pSampDeps, pShader->SampDepCount * sizeof(SShaderSamplerDependency)), pError );
- VHD( pHeap->MoveData((void**) &pShader->pInterfaceDeps, pShader->InterfaceDepCount * sizeof(SInterfaceDependency)), pError );
- VHD( pHeap->MoveData((void**) &pShader->pResourceDeps, pShader->ResourceDepCount * sizeof(SShaderResourceDependency)), pError );
- VHD( pHeap->MoveData((void**) &pShader->pUAVDeps, pShader->UAVDepCount * sizeof(SUnorderedAccessViewDependency)), pError );
- VHD( pHeap->MoveData((void**) &pShader->ppTbufDeps, pShader->TBufferDepCount * sizeof(SConstantBuffer*)), pError );
-
- for (size_t j=0; j<pShader->CBDepCount; j++)
- {
- SShaderCBDependency *pCBDeps = &pShader->pCBDeps[j];
- VHD( pHeap->MoveData((void**) &pCBDeps->ppD3DObjects, pCBDeps->Count * sizeof(ID3D11Buffer*)), pError );
- VHD( pHeap->MoveData((void**) &pCBDeps->ppFXPointers, pCBDeps->Count * sizeof(SConstantBuffer*)), pError );
-
- for (size_t k=0; k<pCBDeps->Count; k++)
- {
- VH( FixupCBPointer( &pCBDeps->ppFXPointers[k] ) );
- }
- }
-
- for (size_t j=0; j<pShader->SampDepCount; j++)
- {
- SShaderSamplerDependency *pSampDeps = &pShader->pSampDeps[j];
- VHD( pHeap->MoveData((void**) &pSampDeps->ppD3DObjects, pSampDeps->Count * sizeof(ID3D11SamplerState*)), pError );
- VHD( pHeap->MoveData((void**) &pSampDeps->ppFXPointers, pSampDeps->Count * sizeof(SSamplerBlock*)), pError );
-
- for (size_t k=0; k<pSampDeps->Count; k++)
- {
- VH( FixupSamplerPointer(&pSampDeps->ppFXPointers[k]) );
- }
- }
-
- for (size_t j=0; j<pShader->InterfaceDepCount; j++)
- {
- SInterfaceDependency *pInterfaceDeps = &pShader->pInterfaceDeps[j];
- VHD( pHeap->MoveData((void**) &pInterfaceDeps->ppD3DObjects, pInterfaceDeps->Count * sizeof(ID3D11ClassInstance*)), pError );
- VHD( pHeap->MoveData((void**) &pInterfaceDeps->ppFXPointers, pInterfaceDeps->Count * sizeof(SInterface*)), pError );
-
- for (size_t k=0; k<pInterfaceDeps->Count; k++)
- {
- VH( FixupInterfacePointer(&pInterfaceDeps->ppFXPointers[k], true) );
- }
- }
-
- for (size_t j=0; j<pShader->ResourceDepCount; j++)
- {
- SShaderResourceDependency *pResourceDeps = &pShader->pResourceDeps[j];
- VHD( pHeap->MoveData((void**) &pResourceDeps->ppD3DObjects, pResourceDeps->Count * sizeof(ID3D11ShaderResourceView*)), pError );
- VHD( pHeap->MoveData((void**) &pResourceDeps->ppFXPointers, pResourceDeps->Count * sizeof(SShaderResource*)), pError );
-
- for (size_t k=0; k<pResourceDeps->Count; k++)
- {
- VH( FixupShaderResourcePointer(&pResourceDeps->ppFXPointers[k]) );
- }
- }
-
- for (size_t j=0; j<pShader->UAVDepCount; j++)
- {
- SUnorderedAccessViewDependency *pUAVDeps = &pShader->pUAVDeps[j];
- VHD( pHeap->MoveData((void**) &pUAVDeps->ppD3DObjects, pUAVDeps->Count * sizeof(ID3D11UnorderedAccessView*)), pError );
- VHD( pHeap->MoveData((void**) &pUAVDeps->ppFXPointers, pUAVDeps->Count * sizeof(SUnorderedAccessView*)), pError );
-
- for (size_t k=0; k<pUAVDeps->Count; k++)
- {
- VH( FixupUnorderedAccessViewPointer(&pUAVDeps->ppFXPointers[k]) );
- }
- }
-
- for (size_t j=0; j<pShader->TBufferDepCount; j++)
- {
- VH( FixupCBPointer( &pShader->ppTbufDeps[j] ) );
- }
- }
-
-lExit:
- return hr;
-}
-
-
-uint32_t CEffectLoader::CalculateShaderBlockSize()
-{
- uint32_t dwSize = 0;
-
- for (size_t i=0; i<m_pEffect->m_ShaderBlockCount; i++)
- {
- SShaderBlock *pShader = &m_pEffect->m_pShaderBlocks[i];
-
- dwSize += AlignToPowerOf2(pShader->CBDepCount * sizeof(SShaderCBDependency), c_DataAlignment);
- dwSize += AlignToPowerOf2(pShader->SampDepCount * sizeof(SShaderSamplerDependency), c_DataAlignment);
- dwSize += AlignToPowerOf2(pShader->InterfaceDepCount * sizeof(SInterfaceDependency), c_DataAlignment);
- dwSize += AlignToPowerOf2(pShader->ResourceDepCount * sizeof(SShaderResourceDependency), c_DataAlignment);
- dwSize += AlignToPowerOf2(pShader->UAVDepCount * sizeof(SUnorderedAccessViewDependency), c_DataAlignment);
- dwSize += AlignToPowerOf2(pShader->TBufferDepCount * sizeof(SConstantBuffer*), c_DataAlignment);
-
- for (size_t j=0; j<pShader->CBDepCount; j++)
- {
- SShaderCBDependency *pCBDeps = &pShader->pCBDeps[j];
- dwSize += AlignToPowerOf2(pCBDeps->Count * sizeof(ID3D11Buffer*), c_DataAlignment);
- dwSize += AlignToPowerOf2(pCBDeps->Count * sizeof(SConstantBuffer*), c_DataAlignment);
- }
-
- for (size_t j=0; j<pShader->SampDepCount; j++)
- {
- SShaderSamplerDependency *pSampDeps = &pShader->pSampDeps[j];
- dwSize += AlignToPowerOf2(pSampDeps->Count * sizeof(ID3D11SamplerState*), c_DataAlignment);
- dwSize += AlignToPowerOf2(pSampDeps->Count * sizeof(SSamplerBlock*), c_DataAlignment);
- }
-
- for (size_t j=0; j<pShader->InterfaceDepCount; j++)
- {
- SInterfaceDependency *pInterfaceDeps = &pShader->pInterfaceDeps[j];
- dwSize += AlignToPowerOf2(pInterfaceDeps->Count * sizeof(ID3D11ClassInstance*), c_DataAlignment);
- dwSize += AlignToPowerOf2(pInterfaceDeps->Count * sizeof(SInterface*), c_DataAlignment);
- }
-
- for (size_t j=0; j<pShader->ResourceDepCount; j++)
- {
- SShaderResourceDependency *pResourceDeps = &pShader->pResourceDeps[j];
- dwSize += AlignToPowerOf2(pResourceDeps->Count * sizeof(ID3D11ShaderResourceView*), c_DataAlignment);
- dwSize += AlignToPowerOf2(pResourceDeps->Count * sizeof(SShaderResource*), c_DataAlignment);
- }
-
- for (size_t j=0; j<pShader->UAVDepCount; j++)
- {
- SUnorderedAccessViewDependency *pUAVDeps = &pShader->pUAVDeps[j];
- dwSize += AlignToPowerOf2(pUAVDeps->Count * sizeof(ID3D11UnorderedAccessView*), c_DataAlignment);
- dwSize += AlignToPowerOf2(pUAVDeps->Count * sizeof(SUnorderedAccessView*), c_DataAlignment);
- }
- }
-
- return dwSize;
-}
-
-// Move all (non-reflection) effect data to private heap
-#pragma warning(push)
-#pragma warning(disable: 4616 6239 )
-HRESULT CEffectLoader::ReallocateEffectData( bool Cloning )
-{
- HRESULT hr = S_OK;
- CEffectHeap *pHeap = &m_pEffect->m_Heap;
- uint32_t cbCBs = sizeof(SConstantBuffer) * m_pEffect->m_CBCount;
- uint32_t cbVariables = sizeof(SGlobalVariable) * m_pEffect->m_VariableCount;
- uint32_t cbGroups = sizeof(STechnique) * m_pEffect->m_GroupCount;
- uint32_t cbShaders = sizeof(SShaderBlock) * m_pEffect->m_ShaderBlockCount;
- uint32_t cbDS = sizeof(SDepthStencilBlock) * m_pEffect->m_DepthStencilBlockCount;
- uint32_t cbAB = sizeof(SBlendBlock) * m_pEffect->m_BlendBlockCount;
- uint32_t cbRS = sizeof(SRasterizerBlock) * m_pEffect->m_RasterizerBlockCount;
- uint32_t cbSamplers = sizeof(SSamplerBlock) * m_pEffect->m_SamplerBlockCount;
- uint32_t cbMemberDatas = sizeof(SMemberDataPointer) * m_pEffect->m_MemberDataCount;
- uint32_t cbInterfaces = sizeof(SInterface) * m_pEffect->m_InterfaceCount;
- uint32_t cbBackgroundInterfaces = sizeof(SInterface) * m_BackgroundInterfaces.GetSize();
- uint32_t cbShaderResources = sizeof(SShaderResource) * m_pEffect->m_ShaderResourceCount;
- uint32_t cbUnorderedAccessViews = sizeof(SUnorderedAccessView) * m_pEffect->m_UnorderedAccessViewCount;
- uint32_t cbRenderTargetViews = sizeof(SRenderTargetView) * m_pEffect->m_RenderTargetViewCount;
- uint32_t cbDepthStencilViews = sizeof(SDepthStencilView) * m_pEffect->m_DepthStencilViewCount;
- uint32_t cbAnonymousShaders = sizeof(SAnonymousShader) * m_pEffect->m_AnonymousShaderCount;
-
- // Calculate memory needed
- m_EffectMemory += AlignToPowerOf2(cbCBs, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbVariables, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbGroups, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbShaders, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbMemberDatas, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbInterfaces + cbBackgroundInterfaces, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbShaderResources, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbUnorderedAccessViews, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbRenderTargetViews, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbDepthStencilViews, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbDS, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbAB, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbRS, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbSamplers, c_DataAlignment);
- m_EffectMemory += AlignToPowerOf2(cbAnonymousShaders, c_DataAlignment);
-
- m_EffectMemory += CalculateShaderBlockSize();
-
- for (size_t i=0; i<m_pEffect->m_CBCount; i++)
- {
- SConstantBuffer *pCB = &m_pEffect->m_pCBs[i];
-
- m_EffectMemory += AlignToPowerOf2(pCB->Size, c_DataAlignment);
- }
-
- for (size_t i=0; i<m_pEffect->m_GroupCount; i++)
- {
- SGroup *pGroup = &m_pEffect->m_pGroups[i];
-
- m_EffectMemory += AlignToPowerOf2(pGroup->TechniqueCount * sizeof(STechnique), c_DataAlignment);
-
- for (size_t j=0; j<pGroup->TechniqueCount; j++)
- {
- STechnique *pTech = &pGroup->pTechniques[j];
-
- m_EffectMemory += AlignToPowerOf2(pTech->PassCount * sizeof(SPassBlock), c_DataAlignment);
- m_EffectMemory += CalculateBlockAssignmentSize(pTech->pPasses, pTech->PassCount);
- }
- };
-
- m_EffectMemory += CalculateBlockAssignmentSize(m_pEffect->m_pBlendBlocks, m_pEffect->m_BlendBlockCount);
- m_EffectMemory += CalculateBlockAssignmentSize(m_pEffect->m_pDepthStencilBlocks, m_pEffect->m_DepthStencilBlockCount);
- m_EffectMemory += CalculateBlockAssignmentSize(m_pEffect->m_pRasterizerBlocks, m_pEffect->m_RasterizerBlockCount);
- m_EffectMemory += CalculateBlockAssignmentSize(m_pEffect->m_pSamplerBlocks, m_pEffect->m_SamplerBlockCount);
-
- // Reserve memory
- VHD( pHeap->ReserveMemory(m_EffectMemory), "Internal loading error: cannot reserve effect memory." );
-
- // Move DataMemberPointer blocks
- m_pOldMemberDataBlocks = m_pEffect->m_pMemberDataBlocks;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pMemberDataBlocks, cbMemberDatas), "Internal loading error: cannot move member data blocks." );
-
- // Move CBs
- m_pOldCBs = m_pEffect->m_pCBs;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pCBs, cbCBs), "Internal loading error: cannot move CB count." );
- for (size_t i=0; i<m_pEffect->m_CBCount; i++)
- {
- SConstantBuffer *pCB = &m_pEffect->m_pCBs[i];
-
- VHD( pHeap->MoveData((void**) &pCB->pBackingStore, pCB->Size), "Internal loading error: cannot move CB backing store." );
-
- if( !Cloning )
- {
- // When creating the effect, MemberDataOffsetPlus4 is used, not pMemberData
- if( pCB->MemberDataOffsetPlus4 )
- {
- pCB->pMemberData = (SMemberDataPointer*)( (uint8_t*)m_pEffect->m_pMemberDataBlocks + ( pCB->MemberDataOffsetPlus4 - 4 ) );
- }
- }
- else if (pCB->pMemberData)
- {
- // When cloning an effect, pMemberData points to valid data in the original effect
- VH( FixupMemberDataPointer( &pCB->pMemberData ) );
- }
- }
-
- // Move numeric variables; move all variable types
- m_pOldVars = m_pEffect->m_pVariables;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pVariables, cbVariables), "Internal loading error: cannot move variable count." );
- for (size_t i=0; i<m_pEffect->m_VariableCount; i++)
- {
- SGlobalVariable *pVar = &m_pEffect->m_pVariables[i];
- pVar->pEffect = m_pEffect;
-
- if( Cloning && pVar->pType->BelongsInConstantBuffer())
- {
- // Convert pointer back to offset
- // pVar->pCB refers to the old CB
- pVar->Data.Offset = (UINT_PTR)pVar->Data.pGeneric - (UINT_PTR)pVar->pCB->pBackingStore;
- }
-
- if (pVar->pCB)
- {
- VH( FixupCBPointer( &pVar->pCB ) );
- }
-
- if( !Cloning )
- {
- // When creating the effect, MemberDataOffsetPlus4 is used, not pMemberData
- if( pVar->MemberDataOffsetPlus4 )
- {
- pVar->pMemberData = (SMemberDataPointer*)( (uint8_t*)m_pEffect->m_pMemberDataBlocks + ( pVar->MemberDataOffsetPlus4 - 4 ) );
- }
- }
- else if (pVar->pMemberData)
- {
- // When cloning an effect, pMemberData points to valid data in the original effect
- VH( FixupMemberDataPointer( &pVar->pMemberData ) );
- }
-
- if (pVar->pType->BelongsInConstantBuffer())
- {
- // Convert from offsets to pointers
- pVar->Data.pGeneric = pVar->pCB->pBackingStore + pVar->Data.Offset;
- }
- }
-
- // Fixup each CB's array of child variable pointers
- for (size_t i=0; i<m_pEffect->m_CBCount; i++)
- {
- SConstantBuffer *pCB = &m_pEffect->m_pCBs[i];
- pCB->pEffect = m_pEffect;
-
- if (pCB->pVariables != nullptr)
- {
- VH( FixupVariablePointer(&pCB->pVariables) );
- }
- }
-
- // Move shaders
- m_pOldShaders = m_pEffect->m_pShaderBlocks;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pShaderBlocks, cbShaders), "Internal loading error: cannot move shader count." );
-
- // Move interfaces, combining global interfaces and those that were created during shader initialization
- m_pOldInterfaces = m_pEffect->m_pInterfaces;
- m_OldInterfaceCount = m_pEffect->m_InterfaceCount;
- VHD( pHeap->MoveEmptyDataBlock((void**) &m_pEffect->m_pInterfaces, cbInterfaces + cbBackgroundInterfaces), "Internal loading error: cannot move shader." );
- memcpy( m_pEffect->m_pInterfaces, m_pOldInterfaces, cbInterfaces );
- for( size_t i=0; i < m_BackgroundInterfaces.GetSize(); i++ )
- {
- assert( m_BackgroundInterfaces[i] != nullptr );
- uint8_t* pDst = (uint8_t*)m_pEffect->m_pInterfaces + ( m_pEffect->m_InterfaceCount * sizeof(SInterface) );
- memcpy( pDst, m_BackgroundInterfaces[i], sizeof(SInterface) );
- m_pEffect->m_InterfaceCount++;
- }
-
- m_pOldShaderResources = m_pEffect->m_pShaderResources;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pShaderResources, cbShaderResources), "Internal loading error: cannot move SRVs." );
-
- m_pOldUnorderedAccessViews = m_pEffect->m_pUnorderedAccessViews;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pUnorderedAccessViews, cbUnorderedAccessViews), "Internal loading error: cannot move UAVS." );
-
- m_pOldRenderTargetViews = m_pEffect->m_pRenderTargetViews;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pRenderTargetViews, cbRenderTargetViews), "Internal loading error: cannot move RTVs." );
-
- m_pOldDepthStencilViews = m_pEffect->m_pDepthStencilViews;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pDepthStencilViews, cbDepthStencilViews), "Internal loading error: cannot move DSVs." );
-
- m_pOldDS = m_pEffect->m_pDepthStencilBlocks;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pDepthStencilBlocks, cbDS), "Internal loading error: cannot move depth-stencil state blocks." );
- VH( ReallocateBlockAssignments(m_pEffect->m_pDepthStencilBlocks, m_pEffect->m_DepthStencilBlockCount, Cloning ? m_pOldDS : nullptr) );
-
- m_pOldAB = m_pEffect->m_pBlendBlocks;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pBlendBlocks, cbAB), "Internal loading error: cannot move blend state blocks." );
- VH( ReallocateBlockAssignments(m_pEffect->m_pBlendBlocks, m_pEffect->m_BlendBlockCount, Cloning ? m_pOldAB : nullptr) );
-
- m_pOldRS = m_pEffect->m_pRasterizerBlocks;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pRasterizerBlocks, cbRS), "Internal loading error: cannot move rasterizer state blocks." );
- VH( ReallocateBlockAssignments(m_pEffect->m_pRasterizerBlocks, m_pEffect->m_RasterizerBlockCount, Cloning ? m_pOldRS : nullptr) );
-
- m_pOldSamplers = m_pEffect->m_pSamplerBlocks;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pSamplerBlocks, cbSamplers), "Internal loading error: cannot move samplers." );
- VH( ReallocateBlockAssignments(m_pEffect->m_pSamplerBlocks, m_pEffect->m_SamplerBlockCount, Cloning ? m_pOldSamplers : nullptr) );
-
- // Fixup sampler backing stores
- for (size_t i=0; i<m_pEffect->m_SamplerBlockCount; ++i)
- {
- VH( FixupShaderResourcePointer(&m_pEffect->m_pSamplerBlocks[i].BackingStore.pTexture) );
- }
-
- // Fixup each interface's class instance variable pointer
- for (size_t i=0; i<m_pEffect->m_InterfaceCount; i++)
- {
- SInterface *pInterface = &m_pEffect->m_pInterfaces[i];
-
- if (pInterface->pClassInstance != nullptr)
- {
- VH( FixupVariablePointer( (SGlobalVariable**)&pInterface->pClassInstance ) );
- }
- }
-
- // Fixup pointers for non-numeric variables
- for (size_t i=0; i<m_pEffect->m_VariableCount; i++)
- {
- SGlobalVariable *pVar = &m_pEffect->m_pVariables[i];
-
- if (pVar->pType->IsShader())
- {
- VH( FixupShaderPointer(&pVar->Data.pShader) );
- }
- else if (pVar->pType->IsShaderResource())
- {
- VH( FixupShaderResourcePointer(&pVar->Data.pShaderResource) );
- }
- else if (pVar->pType->IsUnorderedAccessView())
- {
- VH( FixupUnorderedAccessViewPointer(&pVar->Data.pUnorderedAccessView) );
- }
- else if (pVar->pType->IsInterface())
- {
- VH( FixupInterfacePointer(&pVar->Data.pInterface, false) );
- }
- else if (pVar->pType->IsObjectType(EOT_String))
- {
- if( !m_pEffect->IsOptimized() )
- {
- VH( FixupStringPointer(&pVar->Data.pString) );
- }
- }
- else if (pVar->pType->IsStateBlockObject())
- {
- switch(pVar->pType->ObjectType)
- {
- case EOT_DepthStencil:
- VH( FixupDSPointer((SDepthStencilBlock**) &pVar->Data.pBlock) );
- break;
- case EOT_Blend:
- VH( FixupABPointer((SBlendBlock**) &pVar->Data.pBlock) );
- break;
- case EOT_Rasterizer:
- VH( FixupRSPointer((SRasterizerBlock**) &pVar->Data.pBlock) );
- break;
- case EOT_Sampler:
- VB(pVar->pType->IsSampler());
- VH( FixupSamplerPointer((SSamplerBlock**) &pVar->Data.pBlock) );
- break;
- default:
- VH( E_FAIL );
- }
- }
- else if (pVar->pType->VarType == EVT_Struct || pVar->pType->VarType == EVT_Numeric)
- {
- if( pVar->pType->IsClassInstance() )
- {
- // do nothing
- }
- else
- {
- // do nothing
- }
- }
- else if (pVar->pType->IsRenderTargetView())
- {
- VH( FixupRenderTargetViewPointer(&pVar->Data.pRenderTargetView) );
- }
- else if (pVar->pType->IsDepthStencilView())
- {
- VH( FixupDepthStencilViewPointer(&pVar->Data.pDepthStencilView) );
- }
- else
- {
- VHD( E_FAIL, "Internal loading error: Invalid variable type." );
- }
- }
-
- // Fixup created members
- for (size_t i = 0; i < m_pEffect->m_pMemberInterfaces.GetSize(); ++ i)
- {
- SMember* pMember = m_pEffect->m_pMemberInterfaces[i];
- SGlobalVariable** ppTopLevelEntity = (SGlobalVariable**)&pMember->pTopLevelEntity;
- VN( *ppTopLevelEntity );
-
- // This might be set to false later, for supporting textures inside classes
- const bool bGlobalMemberDataBlock = true;
-
- if( Cloning )
- {
- if( pMember->pType->BelongsInConstantBuffer() )
- {
- assert( pMember->Data.pGeneric == nullptr || (*ppTopLevelEntity)->pEffect->m_Heap.IsInHeap(pMember->Data.pGeneric) );
- pMember->Data.Offset = (uint32_t)( (uint8_t*)pMember->Data.pGeneric - (uint8_t*)(*ppTopLevelEntity)->pCB->pBackingStore );
- }
- if( bGlobalMemberDataBlock && pMember->pMemberData )
- {
- pMember->MemberDataOffsetPlus4 = (uint32_t)( (uint8_t*)pMember->pMemberData - (uint8_t*)(*ppTopLevelEntity)->pEffect->m_pMemberDataBlocks ) + 4;
- }
- }
-
- VH( FixupVariablePointer( ppTopLevelEntity ) );
-
- if (pMember->pType->BelongsInConstantBuffer())
- {
- // Convert from offsets to pointers
- pMember->Data.pGeneric = (*ppTopLevelEntity)->pCB->pBackingStore + pMember->Data.Offset;
- }
- if( bGlobalMemberDataBlock && pMember->MemberDataOffsetPlus4 )
- {
- pMember->pMemberData = (SMemberDataPointer*)( (uint8_t*)m_pEffect->m_pMemberDataBlocks + ( pMember->MemberDataOffsetPlus4 - 4 ) );
- }
- }
-
- // Fixup shader data
- VH( ReallocateShaderBlocks() );
-
- // Move groups, techniques, and passes
- m_pOldGroups = m_pEffect->m_pGroups;
- VHD( pHeap->MoveData((void**) &m_pEffect->m_pGroups, cbGroups), "Internal loading error: cannot move groups." );
- for (size_t i=0; i<m_pEffect->m_GroupCount; i++)
- {
- SGroup *pGroup = &m_pEffect->m_pGroups[i];
- uint32_t cbTechniques;
-
- cbTechniques = pGroup->TechniqueCount * sizeof(STechnique);
- VHD( pHeap->MoveData((void**) &pGroup->pTechniques, cbTechniques), "Internal loading error: cannot move techniques." );
-
- for (size_t j=0; j<pGroup->TechniqueCount; j++)
- {
- STechnique *pTech = &pGroup->pTechniques[j];
- uint32_t cbPass;
-
- cbPass = pTech->PassCount * sizeof(SPassBlock);
- SPassBlock* pOldPasses = Cloning ? pTech->pPasses : nullptr;
- VHD( pHeap->MoveData((void**) &pTech->pPasses, cbPass), "Internal loading error: cannot move passes." );
-
- for (size_t iPass = 0; iPass < pTech->PassCount; ++ iPass)
- {
- pTech->pPasses[iPass].pEffect = m_pEffect;
-
- // Fixup backing store pointers in passes
- VH( FixupABPointer((SBlendBlock**) &pTech->pPasses[iPass].BackingStore.pBlendBlock) );
- VH( FixupDSPointer((SDepthStencilBlock**) &pTech->pPasses[iPass].BackingStore.pDepthStencilBlock) );
- VH( FixupRSPointer((SRasterizerBlock**) &pTech->pPasses[iPass].BackingStore.pRasterizerBlock) );
- VH( FixupShaderPointer((SShaderBlock**) &pTech->pPasses[iPass].BackingStore.pVertexShaderBlock) );
- VH( FixupShaderPointer((SShaderBlock**) &pTech->pPasses[iPass].BackingStore.pPixelShaderBlock) );
- VH( FixupShaderPointer((SShaderBlock**) &pTech->pPasses[iPass].BackingStore.pGeometryShaderBlock) );
- VH( FixupShaderPointer((SShaderBlock**) &pTech->pPasses[iPass].BackingStore.pHullShaderBlock) );
- VH( FixupShaderPointer((SShaderBlock**) &pTech->pPasses[iPass].BackingStore.pDomainShaderBlock) );
- VH( FixupShaderPointer((SShaderBlock**) &pTech->pPasses[iPass].BackingStore.pComputeShaderBlock) );
- VH( FixupDepthStencilViewPointer( &pTech->pPasses[iPass].BackingStore.pDepthStencilView) );
- for (size_t iRT = 0; iRT < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; iRT++)
- {
- VH( FixupRenderTargetViewPointer( &pTech->pPasses[iPass].BackingStore.pRenderTargetViews[iRT] ) );
- }
- }
-
- VH( ReallocateBlockAssignments( pTech->pPasses, pTech->PassCount, pOldPasses ) );
- }
- }
- VH( FixupGroupPointer( &m_pEffect->m_pNullGroup ) );
-
- // Move anonymous shader variables
- VHD( pHeap->MoveData((void **) &m_pEffect->m_pAnonymousShaders, cbAnonymousShaders), "Internal loading error: cannot move anonymous shaders." );
- for (size_t i=0; i<m_pEffect->m_AnonymousShaderCount; ++i)
- {
- SAnonymousShader *pAnonymousShader = m_pEffect->m_pAnonymousShaders + i;
- VH( FixupShaderPointer((SShaderBlock**) &pAnonymousShader->pShaderBlock) );
- }
-
- VBD( pHeap->GetSize() == m_EffectMemory, "Loading error: effect size mismatch." );
-
-lExit:
- return hr;
-}
-#pragma warning(pop)
-
-}
-
-#endif
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: EffectLoad.h
-//
-// Direct3D 11 Effects header for the FX file loader
-// A CEffectLoader is created at load time to facilitate loading
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-namespace D3DX11Effects
-{
-
-// Ranges are used for dependency checking during load
-
-enum ERanges
-{
- ER_CBuffer = 0,
- ER_Texture, // Includes TBuffers
- ER_Sampler,
- ER_UnorderedAccessView,
- ER_Interfaces,
- ER_Count // This should be the size of the enum
-};
-
-struct SRange
-{
- uint32_t start;
- uint32_t last;
- CEffectVector<void *> vResources; // should be (last - start) in length, resource type depends on the range type
-
- SRange() noexcept :
- start(0),
- last(0)
- {
- }
-};
-
-// Used during load to validate assignments
-D3D_SHADER_VARIABLE_TYPE GetSimpleParameterTypeFromObjectType(EObjectType ObjectType);
-
-
-// A class to facilitate loading an Effect. This class is a friend of CEffect.
-class CEffectLoader
-{
- friend HRESULT CEffect::CloneEffect(_In_ uint32_t Flags, _Outptr_ ID3DX11Effect** ppClonedEffect );
-
-protected:
- // Load-time allocations that eventually get moved happen out of the TempHeap. This heap will grow as needed
- CDataBlockStore m_BulkHeap;
-
- uint8_t *m_pData;
- SBinaryHeader5 *m_pHeader;
- DWORD m_Version;
-
- CEffect *m_pEffect;
- CEffectReflection *m_pReflection;
-
- D3DX11Core::CMemoryStream m_msStructured;
- D3DX11Core::CMemoryStream m_msUnstructured;
-
- // used to avoid repeated hash buffer allocations in LoadTypeAndAddToPool
- CEffectVector<uint8_t> m_HashBuffer;
-
- uint32_t m_dwBufferSize; // Size of data buffer in bytes
-
- // List of SInterface blocks created to back class instances bound to shaders
- CEffectVector<SInterface*> m_BackgroundInterfaces;
-
- // Pointers to pre-reallocation data
- SGlobalVariable *m_pOldVars;
- SShaderBlock *m_pOldShaders;
- SDepthStencilBlock *m_pOldDS;
- SBlendBlock *m_pOldAB;
- SRasterizerBlock *m_pOldRS;
- SConstantBuffer *m_pOldCBs;
- SSamplerBlock *m_pOldSamplers;
- uint32_t m_OldInterfaceCount;
- SInterface *m_pOldInterfaces;
- SShaderResource *m_pOldShaderResources;
- SUnorderedAccessView *m_pOldUnorderedAccessViews;
- SRenderTargetView *m_pOldRenderTargetViews;
- SDepthStencilView *m_pOldDepthStencilViews;
- SString *m_pOldStrings;
- SMemberDataPointer *m_pOldMemberDataBlocks;
- CEffectVectorOwner<SMember> *m_pvOldMemberInterfaces;
- SGroup *m_pOldGroups;
-
- uint32_t m_EffectMemory; // Effect private heap
- uint32_t m_ReflectionMemory; // Reflection private heap
-
- // Loader helpers
- HRESULT LoadCBs();
- HRESULT LoadNumericVariable(_In_ SConstantBuffer *pParentCB);
- HRESULT LoadObjectVariables();
- HRESULT LoadInterfaceVariables();
-
- HRESULT LoadTypeAndAddToPool(_Outptr_ SType **ppType, _In_ uint32_t dwOffset);
- HRESULT LoadStringAndAddToPool(_Outptr_result_maybenull_z_ char **ppString, _In_ uint32_t dwOffset);
- HRESULT LoadAssignments( _In_ uint32_t Assignments, _Out_writes_(Assignments) SAssignment **pAssignments,
- _In_ uint8_t *pBackingStore, _Out_opt_ uint32_t *pRTVAssignments, _Out_opt_ uint32_t *pFinalAssignments );
- HRESULT LoadGroups();
- HRESULT LoadTechnique( STechnique* pTech );
- HRESULT LoadAnnotations(uint32_t *pcAnnotations, SAnnotation **ppAnnotations);
-
- HRESULT ExecuteConstantAssignment(_In_ const SBinaryConstant *pConstant, _Out_writes_bytes_(4) void *pLHS, _In_ D3D_SHADER_VARIABLE_TYPE lhsType);
- uint32_t UnpackData(uint8_t *pDestData, uint8_t *pSrcData, uint32_t PackedDataSize, SType *pType, uint32_t *pBytesRead);
-
- // Build shader blocks
- HRESULT ConvertRangesToBindings(SShaderBlock *pShaderBlock, CEffectVector<SRange> *pvRanges );
- HRESULT GrabShaderData(SShaderBlock *pShaderBlock);
- HRESULT BuildShaderBlock(SShaderBlock *pShaderBlock);
-
- // Memory compactors
- HRESULT InitializeReflectionDataAndMoveStrings( uint32_t KnownSize = 0 );
- HRESULT ReallocateReflectionData( bool Cloning = false );
- HRESULT ReallocateEffectData( bool Cloning = false );
- HRESULT ReallocateShaderBlocks();
- template<class T> HRESULT ReallocateBlockAssignments(T* &pBlocks, uint32_t cBlocks, T* pOldBlocks = nullptr);
- HRESULT ReallocateAnnotationData(uint32_t cAnnotations, SAnnotation **ppAnnotations);
-
- HRESULT CalculateAnnotationSize(uint32_t cAnnotations, SAnnotation *pAnnotations);
- uint32_t CalculateShaderBlockSize();
- template<class T> uint32_t CalculateBlockAssignmentSize(T* &pBlocks, uint32_t cBlocks);
-
- HRESULT FixupCBPointer(_Inout_ SConstantBuffer **ppCB);
- HRESULT FixupShaderPointer(_Inout_ SShaderBlock **ppShaderBlock);
- HRESULT FixupDSPointer(_Inout_ SDepthStencilBlock **ppDSBlock);
- HRESULT FixupABPointer(_Inout_ SBlendBlock **ppABBlock);
- HRESULT FixupRSPointer(_Inout_ SRasterizerBlock **ppRSBlock);
- HRESULT FixupInterfacePointer(_Inout_ SInterface **ppInterface, _In_ bool CheckBackgroundInterfaces);
- HRESULT FixupShaderResourcePointer(_Inout_ SShaderResource **ppResource);
- HRESULT FixupUnorderedAccessViewPointer(_Inout_ SUnorderedAccessView **ppResource);
- HRESULT FixupRenderTargetViewPointer(_Inout_ SRenderTargetView **ppRenderTargetView);
- HRESULT FixupDepthStencilViewPointer(_Inout_ SDepthStencilView **ppDepthStencilView);
- HRESULT FixupSamplerPointer(_Inout_ SSamplerBlock **ppSampler);
- HRESULT FixupVariablePointer(_Inout_ SGlobalVariable **ppVar);
- HRESULT FixupStringPointer(_Inout_ SString **ppString);
- HRESULT FixupMemberDataPointer(_Inout_ SMemberDataPointer **ppMemberData);
- HRESULT FixupGroupPointer(_Inout_ SGroup **ppGroup);
-
- // Methods to retrieve data from the unstructured block
- // (these do not make copies; they simply return pointers into the block)
- HRESULT GetStringAndAddToReflection(_In_ uint32_t offset, _Outptr_result_maybenull_z_ char **ppPointer); // Returns a string from the file string block, updates m_EffectMemory
- HRESULT GetUnstructuredDataBlock(_In_ uint32_t offset, _Out_ uint32_t *pdwSize, _Outptr_result_buffer_(*pdwSize) void **ppData);
- // This function makes a copy of the array of SInterfaceParameters, but not a copy of the strings
- HRESULT GetInterfaceParametersAndAddToReflection( _In_ uint32_t InterfaceCount, _In_ uint32_t offset, _Outptr_result_buffer_all_maybenull_(InterfaceCount) SShaderBlock::SInterfaceParameter **ppInterfaces );
-
-public:
- CEffectLoader() noexcept;
-
- HRESULT LoadEffect(_In_ CEffect *pEffect, _In_reads_bytes_(cbEffectBuffer) const void *pEffectBuffer, _In_ uint32_t cbEffectBuffer);
-};
-
-}
+++ /dev/null
-#ifdef FX11
-
-//--------------------------------------------------------------------------------------
-// File: EffectNonRuntime.cpp
-//
-// D3DX11 Effect low-frequency utility functions
-// These functions are not intended to be called regularly. They
-// are typically called when creating, cloning, or optimizing an
-// Effect, or reflecting a variable.
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#include "pchfx.h"
-#include "SOParser.h"
-
-namespace D3DX11Effects
-{
-
-extern SUnorderedAccessView g_NullUnorderedAccessView;
-
-SBaseBlock::SBaseBlock() noexcept :
- BlockType(EBT_Invalid),
- IsUserManaged(false),
- AssignmentCount(0),
- pAssignments(nullptr)
-{
-}
-
-SPassBlock::SPassBlock() noexcept :
- BackingStore{},
- pName(nullptr),
- AnnotationCount(0),
- pAnnotations(nullptr),
- pEffect(nullptr),
- InitiallyValid(true),
- HasDependencies(false)
-{
-}
-
-STechnique::STechnique() noexcept :
- pName(nullptr),
- PassCount(0),
- pPasses(nullptr),
- AnnotationCount(0),
- pAnnotations(nullptr),
- InitiallyValid( true ),
- HasDependencies( false )
-{
-}
-
-SGroup::SGroup() noexcept :
- pName(nullptr),
- TechniqueCount(0),
- pTechniques(nullptr),
- AnnotationCount(0),
- pAnnotations(nullptr),
- InitiallyValid( true ),
- HasDependencies( false )
-{
-}
-
-SDepthStencilBlock::SDepthStencilBlock() noexcept :
- pDSObject(nullptr),
- BackingStore{},
- IsValid(true)
-{
- BackingStore.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
- BackingStore.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
- BackingStore.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
- BackingStore.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
- BackingStore.DepthEnable = true;
- BackingStore.DepthFunc = D3D11_COMPARISON_LESS;
- BackingStore.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
- BackingStore.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
- BackingStore.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
- BackingStore.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
- BackingStore.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
- BackingStore.StencilEnable = false;
- BackingStore.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
- BackingStore.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
-}
-
-SBlendBlock::SBlendBlock() noexcept :
- pBlendObject(nullptr),
- BackingStore{},
- IsValid(true)
-{
- BackingStore.AlphaToCoverageEnable = false;
- BackingStore.IndependentBlendEnable = true;
- for( size_t i=0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++ )
- {
- BackingStore.RenderTarget[i].SrcBlend = D3D11_BLEND_ONE;
- BackingStore.RenderTarget[i].DestBlend = D3D11_BLEND_ZERO;
- BackingStore.RenderTarget[i].BlendOp = D3D11_BLEND_OP_ADD;
- BackingStore.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ONE;
- BackingStore.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ZERO;
- BackingStore.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_ADD;
- memset(&BackingStore.RenderTarget[i].RenderTargetWriteMask, 0x0F, sizeof(BackingStore.RenderTarget[i].RenderTargetWriteMask));
- }
-}
-
-SRasterizerBlock::SRasterizerBlock() noexcept :
- pRasterizerObject(nullptr),
- BackingStore{},
- IsValid(true)
-{
- BackingStore.AntialiasedLineEnable = false;
- BackingStore.CullMode = D3D11_CULL_BACK;
- BackingStore.DepthBias = D3D11_DEFAULT_DEPTH_BIAS;
- BackingStore.DepthBiasClamp = D3D11_DEFAULT_DEPTH_BIAS_CLAMP;
- BackingStore.FillMode = D3D11_FILL_SOLID;
- BackingStore.FrontCounterClockwise = false;
- BackingStore.MultisampleEnable = false;
- BackingStore.ScissorEnable = false;
- BackingStore.SlopeScaledDepthBias = D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
- BackingStore.DepthClipEnable = true;
-}
-
-SSamplerBlock::SSamplerBlock() noexcept :
- pD3DObject(nullptr),
- BackingStore{}
-{
- BackingStore.SamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
- BackingStore.SamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
- BackingStore.SamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
- BackingStore.SamplerDesc.BorderColor[3] = D3D11_DEFAULT_BORDER_COLOR_COMPONENT;
- BackingStore.SamplerDesc.BorderColor[2] = D3D11_DEFAULT_BORDER_COLOR_COMPONENT;
- BackingStore.SamplerDesc.BorderColor[1] = D3D11_DEFAULT_BORDER_COLOR_COMPONENT;
- BackingStore.SamplerDesc.BorderColor[0] = D3D11_DEFAULT_BORDER_COLOR_COMPONENT;
- BackingStore.SamplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
- BackingStore.SamplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
- BackingStore.SamplerDesc.MaxAnisotropy = (UINT32) D3D11_DEFAULT_MAX_ANISOTROPY;
- BackingStore.SamplerDesc.MipLODBias = D3D11_DEFAULT_MIP_LOD_BIAS;
- BackingStore.SamplerDesc.MinLOD = -FLT_MAX;
- BackingStore.SamplerDesc.MaxLOD = FLT_MAX;
-}
-
-SShaderBlock::SShaderBlock(SD3DShaderVTable *pVirtualTable) noexcept :
- IsValid(true),
- pVT(pVirtualTable),
- pReflectionData(nullptr),
- pD3DObject(nullptr),
- CBDepCount(0),
- pCBDeps(nullptr),
- SampDepCount(0),
- pSampDeps(nullptr),
- InterfaceDepCount(0),
- pInterfaceDeps(nullptr),
- ResourceDepCount(0),
- pResourceDeps(nullptr),
- UAVDepCount(0),
- pUAVDeps(nullptr),
- TBufferDepCount(0),
- ppTbufDeps(nullptr),
- pInputSignatureBlob(nullptr)
-{
-}
-
-HRESULT SShaderBlock::OnDeviceBind()
-{
- HRESULT hr = S_OK;
- uint32_t i, j;
-
- // Update all CB deps
- for (i=0; i<CBDepCount; i++)
- {
- assert(pCBDeps[i].Count);
-
- for (j=0; j<pCBDeps[i].Count; j++)
- {
- pCBDeps[i].ppD3DObjects[j] = pCBDeps[i].ppFXPointers[j]->pD3DObject;
-
- if ( !pCBDeps[i].ppD3DObjects[j] )
- VH( E_FAIL );
- }
- }
-
- // Update all sampler deps
- for (i=0; i<SampDepCount; i++)
- {
- assert(pSampDeps[i].Count);
-
- for (j=0; j<pSampDeps[i].Count; j++)
- {
- pSampDeps[i].ppD3DObjects[j] = pSampDeps[i].ppFXPointers[j]->pD3DObject;
-
- if ( !pSampDeps[i].ppD3DObjects[j] )
- VH( E_FAIL );
- }
- }
-
- // Texture deps will be set automatically on use since they are initially marked dirty.
-
-lExit:
- return hr;
-}
-
-extern SD3DShaderVTable g_vtVS;
-extern SD3DShaderVTable g_vtGS;
-extern SD3DShaderVTable g_vtPS;
-extern SD3DShaderVTable g_vtHS;
-extern SD3DShaderVTable g_vtDS;
-extern SD3DShaderVTable g_vtCS;
-
-EObjectType SShaderBlock::GetShaderType()
-{
- if (&g_vtVS == pVT)
- return EOT_VertexShader;
- else if (&g_vtGS == pVT)
- return EOT_GeometryShader;
- else if (&g_vtPS == pVT)
- return EOT_PixelShader;
- else if (&g_vtHS == pVT)
- return EOT_HullShader5;
- else if (&g_vtDS == pVT)
- return EOT_DomainShader5;
- else if (&g_vtCS == pVT)
- return EOT_ComputeShader5;
-
- return EOT_Invalid;
-}
-
-#define _SET_BIT(bytes, x) (bytes[x / 8] |= (1 << (x % 8)))
-
-HRESULT SShaderBlock::ComputeStateBlockMask(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask)
-{
- HRESULT hr = S_OK;
- uint32_t i, j;
- uint8_t *pSamplerMask = nullptr, *pShaderResourceMask = nullptr, *pConstantBufferMask = nullptr, *pUnorderedAccessViewMask = nullptr, *pInterfaceMask = nullptr;
-
- switch (GetShaderType())
- {
- case EOT_VertexShader:
- case EOT_VertexShader5:
- pStateBlockMask->VS = 1;
- pSamplerMask = pStateBlockMask->VSSamplers;
- pShaderResourceMask = pStateBlockMask->VSShaderResources;
- pConstantBufferMask = pStateBlockMask->VSConstantBuffers;
- pInterfaceMask = pStateBlockMask->VSInterfaces;
- pUnorderedAccessViewMask = nullptr;
- break;
-
- case EOT_GeometryShader:
- case EOT_GeometryShader5:
- pStateBlockMask->GS = 1;
- pSamplerMask = pStateBlockMask->GSSamplers;
- pShaderResourceMask = pStateBlockMask->GSShaderResources;
- pConstantBufferMask = pStateBlockMask->GSConstantBuffers;
- pInterfaceMask = pStateBlockMask->GSInterfaces;
- pUnorderedAccessViewMask = nullptr;
- break;
-
- case EOT_PixelShader:
- case EOT_PixelShader5:
- pStateBlockMask->PS = 1;
- pSamplerMask = pStateBlockMask->PSSamplers;
- pShaderResourceMask = pStateBlockMask->PSShaderResources;
- pConstantBufferMask = pStateBlockMask->PSConstantBuffers;
- pInterfaceMask = pStateBlockMask->PSInterfaces;
- pUnorderedAccessViewMask = &pStateBlockMask->PSUnorderedAccessViews;
- break;
-
- case EOT_HullShader5:
- pStateBlockMask->HS = 1;
- pSamplerMask = pStateBlockMask->HSSamplers;
- pShaderResourceMask = pStateBlockMask->HSShaderResources;
- pConstantBufferMask = pStateBlockMask->HSConstantBuffers;
- pInterfaceMask = pStateBlockMask->HSInterfaces;
- pUnorderedAccessViewMask = nullptr;
- break;
-
- case EOT_DomainShader5:
- pStateBlockMask->DS = 1;
- pSamplerMask = pStateBlockMask->DSSamplers;
- pShaderResourceMask = pStateBlockMask->DSShaderResources;
- pConstantBufferMask = pStateBlockMask->DSConstantBuffers;
- pInterfaceMask = pStateBlockMask->DSInterfaces;
- pUnorderedAccessViewMask = nullptr;
- break;
-
- case EOT_ComputeShader5:
- pStateBlockMask->CS = 1;
- pSamplerMask = pStateBlockMask->CSSamplers;
- pShaderResourceMask = pStateBlockMask->CSShaderResources;
- pConstantBufferMask = pStateBlockMask->CSConstantBuffers;
- pInterfaceMask = pStateBlockMask->CSInterfaces;
- pUnorderedAccessViewMask = &pStateBlockMask->CSUnorderedAccessViews;
- break;
-
- default:
- assert(0);
- VH(E_FAIL);
- }
-
- for (i = 0; i < SampDepCount; ++ i)
- {
- for (j = 0; j < pSampDeps[i].Count; ++ j)
- {
- _SET_BIT(pSamplerMask, (pSampDeps[i].StartIndex + j));
- }
- }
-
- for (i = 0; i < InterfaceDepCount; ++ i)
- {
- for (j = 0; j < pInterfaceDeps[i].Count; ++ j)
- {
- _SET_BIT(pInterfaceMask, (pInterfaceDeps[i].StartIndex + j));
- }
- }
-
- for (i = 0; i < ResourceDepCount; ++ i)
- {
- for (j = 0; j < pResourceDeps[i].Count; ++ j)
- {
- _SET_BIT(pShaderResourceMask, (pResourceDeps[i].StartIndex + j));
- }
- }
-
- for (i = 0; i < CBDepCount; ++ i)
- {
- for (j = 0; j < pCBDeps[i].Count; ++ j)
- {
- _SET_BIT(pConstantBufferMask, (pCBDeps[i].StartIndex + j));
- }
- }
-
- for (i = 0; i < UAVDepCount; ++ i)
- {
- assert( pUnorderedAccessViewMask != 0 );
- _Analysis_assume_( pUnorderedAccessViewMask != 0 );
- for (j = 0; j < pUAVDeps[i].Count; ++ j)
- {
- if( pUAVDeps[i].ppFXPointers[j] != &g_NullUnorderedAccessView )
- _SET_BIT(pUnorderedAccessViewMask, (pUAVDeps[i].StartIndex + j));
- }
- }
-
-lExit:
- return hr;
-}
-
-#undef _SET_BIT
-
-HRESULT SShaderBlock::GetShaderDesc(_Out_ D3DX11_EFFECT_SHADER_DESC *pDesc, _In_ bool IsInline)
-{
- HRESULT hr = S_OK;
-
- ZeroMemory(pDesc, sizeof(*pDesc));
-
- pDesc->pInputSignature = pInputSignatureBlob ? (const uint8_t*)pInputSignatureBlob->GetBufferPointer() : nullptr;
- pDesc->IsInline = IsInline;
-
- if (nullptr != pReflectionData)
- {
- // initialize these only if present; otherwise leave them nullptr or 0
- pDesc->pBytecode = pReflectionData->pBytecode;
- pDesc->BytecodeLength = pReflectionData->BytecodeLength;
- for( size_t iDecl=0; iDecl < D3D11_SO_STREAM_COUNT; ++iDecl )
- {
- pDesc->SODecls[iDecl] = pReflectionData->pStreamOutDecls[iDecl];
- }
- pDesc->RasterizedStream = pReflectionData->RasterizedStream;
-
- // get # of input & output signature entries
- assert( pReflectionData->pReflection != 0 );
- _Analysis_assume_( pReflectionData->pReflection != 0 );
-
- D3D11_SHADER_DESC ShaderDesc;
- hr = pReflectionData->pReflection->GetDesc( &ShaderDesc );
- if ( SUCCEEDED(hr) )
- {
- pDesc->NumInputSignatureEntries = ShaderDesc.InputParameters;
- pDesc->NumOutputSignatureEntries = ShaderDesc.OutputParameters;
- pDesc->NumPatchConstantSignatureEntries = ShaderDesc.PatchConstantParameters;
- }
- }
-lExit:
- return hr;
-}
-
-HRESULT SShaderBlock::GetVertexShader(_Outptr_ ID3D11VertexShader **ppVS)
-{
- if (EOT_VertexShader == GetShaderType() ||
- EOT_VertexShader5 == GetShaderType())
- {
- assert( pD3DObject != 0 );
- _Analysis_assume_( pD3DObject != 0 );
- *ppVS = static_cast<ID3D11VertexShader *>( pD3DObject );
- SAFE_ADDREF(*ppVS);
- return S_OK;
- }
- else
- {
- *ppVS = nullptr;
- DPF(0, "ID3DX11EffectShaderVariable::GetVertexShader: This shader variable is not a vertex shader");
- return D3DERR_INVALIDCALL;
- }
-}
-
-HRESULT SShaderBlock::GetGeometryShader(_Outptr_ ID3D11GeometryShader **ppGS)
-{
- if (EOT_GeometryShader == GetShaderType() ||
- EOT_GeometryShaderSO == GetShaderType() ||
- EOT_GeometryShader5 == GetShaderType())
- {
- assert( pD3DObject != 0 );
- _Analysis_assume_( pD3DObject != 0 );
- *ppGS = static_cast<ID3D11GeometryShader *>( pD3DObject );
- SAFE_ADDREF(*ppGS);
- return S_OK;
- }
- else
- {
- *ppGS = nullptr;
- DPF(0, "ID3DX11EffectShaderVariable::GetGeometryShader: This shader variable is not a geometry shader");
- return D3DERR_INVALIDCALL;
- }
-}
-
-HRESULT SShaderBlock::GetPixelShader(_Outptr_ ID3D11PixelShader **ppPS)
-{
- if (EOT_PixelShader == GetShaderType() ||
- EOT_PixelShader5 == GetShaderType())
- {
- assert( pD3DObject != 0 );
- _Analysis_assume_( pD3DObject != 0 );
- *ppPS = static_cast<ID3D11PixelShader *>( pD3DObject );
- SAFE_ADDREF(*ppPS);
- return S_OK;
- }
- else
- {
- *ppPS = nullptr;
- DPF(0, "ID3DX11EffectShaderVariable::GetPixelShader: This shader variable is not a pixel shader");
- return D3DERR_INVALIDCALL;
- }
-}
-
-HRESULT SShaderBlock::GetHullShader(_Outptr_ ID3D11HullShader **ppHS)
-{
- if (EOT_HullShader5 == GetShaderType())
- {
- assert( pD3DObject != 0 );
- _Analysis_assume_( pD3DObject != 0 );
- *ppHS = static_cast<ID3D11HullShader *>( pD3DObject );
- SAFE_ADDREF(*ppHS);
- return S_OK;
- }
- else
- {
- *ppHS = nullptr;
- DPF(0, "ID3DX11EffectShaderVariable::GetHullShader: This shader variable is not a hull shader");
- return D3DERR_INVALIDCALL;
- }
-}
-
-HRESULT SShaderBlock::GetDomainShader(_Outptr_ ID3D11DomainShader **ppDS)
-{
- if (EOT_DomainShader5 == GetShaderType())
- {
- assert( pD3DObject != 0 );
- _Analysis_assume_( pD3DObject != 0 );
- *ppDS = static_cast<ID3D11DomainShader *>( pD3DObject );
- SAFE_ADDREF(*ppDS);
- return S_OK;
- }
- else
- {
- *ppDS = nullptr;
- DPF(0, "ID3DX11EffectShaderVariable::GetDomainShader: This shader variable is not a domain shader");
- return D3DERR_INVALIDCALL;
- }
-}
-
-HRESULT SShaderBlock::GetComputeShader(_Outptr_ ID3D11ComputeShader **ppCS)
-{
- if (EOT_ComputeShader5 == GetShaderType())
- {
- assert( pD3DObject != 0 );
- _Analysis_assume_( pD3DObject != 0 );
- *ppCS = static_cast<ID3D11ComputeShader *>( pD3DObject );
- SAFE_ADDREF(*ppCS);
- return S_OK;
- }
- else
- {
- *ppCS = nullptr;
- DPF(0, "ID3DX11EffectShaderVariable::GetComputeShader: This shader variable is not a compute shader");
- return D3DERR_INVALIDCALL;
- }
-}
-
-_Use_decl_annotations_
-HRESULT SShaderBlock::GetSignatureElementDesc(ESigType SigType, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
-{
- HRESULT hr = S_OK;
- LPCSTR pFuncName = nullptr;
- switch( SigType )
- {
- case ST_Input:
- pFuncName = "ID3DX11EffectShaderVariable::GetInputSignatureElementDesc";
- break;
- case ST_Output:
- pFuncName = "ID3DX11EffectShaderVariable::GetOutputSignatureElementDesc";
- break;
- case ST_PatchConstant:
- pFuncName = "ID3DX11EffectShaderVariable::GetPatchConstantSignatureElementDesc";
- break;
- default:
- assert( false );
- return E_FAIL;
- };
-
- if (nullptr != pReflectionData)
- {
- // get # of signature entries
- assert( pReflectionData->pReflection != 0 );
- _Analysis_assume_( pReflectionData->pReflection != 0 );
-
- D3D11_SHADER_DESC ShaderDesc;
- VH( pReflectionData->pReflection->GetDesc( &ShaderDesc ) );
-
- D3D11_SIGNATURE_PARAMETER_DESC ParamDesc ={};
- if( pReflectionData->IsNullGS )
- {
- switch( SigType )
- {
- case ST_Input:
- // The input signature for a null-GS is the output signature of the previous VS
- SigType = ST_Output;
- break;
- case ST_PatchConstant:
- // GeometryShaders cannot have patch constant signatures
- return E_INVALIDARG;
- };
- }
-
- switch( SigType )
- {
- case ST_Input:
- if( Element >= ShaderDesc.InputParameters )
- {
- DPF( 0, "%s: Invalid Element index (%u) specified", pFuncName, Element );
- VH( E_INVALIDARG );
- }
- VH( pReflectionData->pReflection->GetInputParameterDesc( Element, &ParamDesc ) );
- break;
- case ST_Output:
- if( Element >= ShaderDesc.OutputParameters )
- {
- DPF( 0, "%s: Invalid Element index (%u) specified", pFuncName, Element );
- VH( E_INVALIDARG );
- }
- VH( pReflectionData->pReflection->GetOutputParameterDesc( Element, &ParamDesc ) );
- break;
- case ST_PatchConstant:
- if( Element >= ShaderDesc.PatchConstantParameters )
- {
- DPF( 0, "%s: Invalid Element index (%u) specified", pFuncName, Element );
- VH( E_INVALIDARG );
- }
- VH( pReflectionData->pReflection->GetPatchConstantParameterDesc( Element, &ParamDesc ) );
- break;
- };
-
- pDesc->SemanticName = ParamDesc.SemanticName;
- pDesc->SystemValueType = ParamDesc.SystemValueType;
-
- // Pixel shaders need to be special-cased as they don't technically output SVs
- if( pDesc->SystemValueType == D3D_NAME_UNDEFINED && GetShaderType() == EOT_PixelShader && pDesc->SemanticName != 0 )
- {
- if( _stricmp(pDesc->SemanticName, "SV_TARGET") == 0 )
- {
- pDesc->SystemValueType = D3D_NAME_TARGET;
- }
- else if( _stricmp(pDesc->SemanticName, "SV_DEPTH") == 0 )
- {
- pDesc->SystemValueType = D3D_NAME_DEPTH;
- }
- else if( _stricmp(pDesc->SemanticName, "SV_COVERAGE") == 0 )
- {
- pDesc->SystemValueType = D3D_NAME_COVERAGE;
- }
- }
-
- pDesc->SemanticIndex = ParamDesc.SemanticIndex;
- pDesc->Register = ParamDesc.Register;
- pDesc->Mask = ParamDesc.Mask;
- pDesc->ComponentType = ParamDesc.ComponentType;
- pDesc->ReadWriteMask = ParamDesc.ReadWriteMask;
- }
- else
- {
- DPF(0, "%s: Cannot get signatures; shader bytecode is not present", pFuncName);
- VH( D3DERR_INVALIDCALL );
- }
-
-lExit:
- return hr;
-}
-
-void * GetBlockByIndex(EVarType VarType, EObjectType ObjectType, void *pBaseBlock, uint32_t Index)
-{
- switch( VarType )
- {
- case EVT_Interface:
- return (SInterface *)pBaseBlock + Index;
- case EVT_Object:
- switch (ObjectType)
- {
- case EOT_Blend:
- return (SBlendBlock *)pBaseBlock + Index;
- case EOT_DepthStencil:
- return (SDepthStencilBlock *)pBaseBlock + Index;
- case EOT_Rasterizer:
- return (SRasterizerBlock *)pBaseBlock + Index;
- case EOT_PixelShader:
- case EOT_PixelShader5:
- case EOT_GeometryShader:
- case EOT_GeometryShaderSO:
- case EOT_GeometryShader5:
- case EOT_VertexShader:
- case EOT_VertexShader5:
- case EOT_HullShader5:
- case EOT_DomainShader5:
- case EOT_ComputeShader5:
- return (SShaderBlock *)pBaseBlock + Index;
- case EOT_String:
- return (SString *)pBaseBlock + Index;
- case EOT_Sampler:
- return (SSamplerBlock *)pBaseBlock + Index;
- case EOT_Buffer:
- case EOT_Texture:
- case EOT_Texture1D:
- case EOT_Texture1DArray:
- case EOT_Texture2D:
- case EOT_Texture2DArray:
- case EOT_Texture2DMS:
- case EOT_Texture2DMSArray:
- case EOT_Texture3D:
- case EOT_TextureCube:
- case EOT_TextureCubeArray:
- case EOT_ByteAddressBuffer:
- case EOT_StructuredBuffer:
- return (SShaderResource *)pBaseBlock + Index;
- case EOT_DepthStencilView:
- return (SDepthStencilView *)pBaseBlock + Index;
- case EOT_RenderTargetView:
- return (SRenderTargetView *)pBaseBlock + Index;
- case EOT_RWTexture1D:
- case EOT_RWTexture1DArray:
- case EOT_RWTexture2D:
- case EOT_RWTexture2DArray:
- case EOT_RWTexture3D:
- case EOT_RWBuffer:
- case EOT_RWByteAddressBuffer:
- case EOT_RWStructuredBuffer:
- case EOT_RWStructuredBufferAlloc:
- case EOT_RWStructuredBufferConsume:
- case EOT_AppendStructuredBuffer:
- case EOT_ConsumeStructuredBuffer:
- return (SUnorderedAccessView *)pBaseBlock + Index;
- default:
- assert(0);
- return nullptr;
- }
- default:
- assert(0);
- return nullptr;
- }
-}
-
-//--------------------------------------------------------------------------------------
-// CEffect
-//--------------------------------------------------------------------------------------
-
-CEffect::CEffect( uint32_t Flags ) noexcept :
- m_RefCount(1),
- m_Flags(Flags),
- m_pReflection(nullptr),
- m_VariableCount(0),
- m_pVariables(nullptr),
- m_AnonymousShaderCount(0),
- m_pAnonymousShaders(nullptr),
- m_TechniqueCount(0),
- m_GroupCount(0),
- m_pGroups(nullptr),
- m_pNullGroup(nullptr),
- m_ShaderBlockCount(0),
- m_pShaderBlocks(nullptr),
- m_DepthStencilBlockCount(0),
- m_pDepthStencilBlocks(nullptr),
- m_BlendBlockCount(0),
- m_pBlendBlocks(nullptr),
- m_RasterizerBlockCount(0),
- m_pRasterizerBlocks(nullptr),
- m_SamplerBlockCount(0),
- m_pSamplerBlocks(nullptr),
- m_MemberDataCount(0),
- m_pMemberDataBlocks(nullptr),
- m_InterfaceCount(0),
- m_pInterfaces(nullptr),
- m_CBCount(0),
- m_pCBs(nullptr),
- m_StringCount(0),
- m_pStrings(nullptr),
- m_ShaderResourceCount(0),
- m_pShaderResources(nullptr),
- m_UnorderedAccessViewCount(0),
- m_pUnorderedAccessViews(nullptr),
- m_RenderTargetViewCount(0),
- m_pRenderTargetViews(nullptr),
- m_DepthStencilViewCount(0),
- m_pDepthStencilViews(nullptr),
- m_LocalTimer(1),
- m_FXLIndex(0),
- m_pDevice(nullptr),
- m_pContext(nullptr),
- m_pClassLinkage(nullptr),
- m_pTypePool(nullptr),
- m_pStringPool(nullptr),
- m_pPooledHeap(nullptr),
- m_pOptimizedTypeHeap(nullptr)
-{
-}
-
-void CEffect::ReleaseShaderRefection()
-{
- for( size_t i = 0; i < m_ShaderBlockCount; ++ i )
- {
- SAFE_RELEASE( m_pShaderBlocks[i].pInputSignatureBlob );
- if( m_pShaderBlocks[i].pReflectionData )
- {
- SAFE_RELEASE( m_pShaderBlocks[i].pReflectionData->pReflection );
- }
- }
-}
-
-CEffect::~CEffect()
-{
- ID3D11InfoQueue *pInfoQueue = nullptr;
-
- // Mute debug spew
- if (m_pDevice)
- {
- HRESULT hr = m_pDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void**) &pInfoQueue);
- if ( FAILED(hr) )
- pInfoQueue = nullptr;
- }
-
- if (pInfoQueue)
- {
- D3D11_INFO_QUEUE_FILTER filter = {};
- D3D11_MESSAGE_CATEGORY messageCategory = D3D11_MESSAGE_CATEGORY_STATE_SETTING;
-
- filter.DenyList.NumCategories = 1;
- filter.DenyList.pCategoryList = &messageCategory;
- pInfoQueue->PushStorageFilter(&filter);
- }
-
- if( nullptr != m_pDevice )
- {
- // if m_pDevice == nullptr, then we failed LoadEffect(), which means ReleaseShaderReflection was already called.
-
- // Release the shader reflection info, as it was not created on the private heap
- // This must be called before we delete m_pReflection
- ReleaseShaderRefection();
- }
-
- SAFE_DELETE( m_pReflection );
- SAFE_DELETE( m_pTypePool );
- SAFE_DELETE( m_pStringPool );
- SAFE_DELETE( m_pPooledHeap );
- SAFE_DELETE( m_pOptimizedTypeHeap );
-
- // this code assumes the effect has been loaded & relocated,
- // so check for that before freeing the resources
-
- if (nullptr != m_pDevice)
- {
- // Keep the following in line with AddRefAllForCloning
-
- assert(nullptr == m_pRasterizerBlocks || m_Heap.IsInHeap(m_pRasterizerBlocks));
- for (size_t i = 0; i < m_RasterizerBlockCount; ++ i)
- {
- SAFE_RELEASE(m_pRasterizerBlocks[i].pRasterizerObject);
- }
-
- assert(nullptr == m_pBlendBlocks || m_Heap.IsInHeap(m_pBlendBlocks));
- for (size_t i = 0; i < m_BlendBlockCount; ++ i)
- {
- SAFE_RELEASE(m_pBlendBlocks[i].pBlendObject);
- }
-
- assert(nullptr == m_pDepthStencilBlocks || m_Heap.IsInHeap(m_pDepthStencilBlocks));
- for (size_t i = 0; i < m_DepthStencilBlockCount; ++ i)
- {
- SAFE_RELEASE(m_pDepthStencilBlocks[i].pDSObject);
- }
-
- assert(nullptr == m_pSamplerBlocks || m_Heap.IsInHeap(m_pSamplerBlocks));
- for (size_t i = 0; i < m_SamplerBlockCount; ++ i)
- {
- SAFE_RELEASE(m_pSamplerBlocks[i].pD3DObject);
- }
-
- assert(nullptr == m_pShaderResources || m_Heap.IsInHeap(m_pShaderResources));
- for (size_t i = 0; i < m_ShaderResourceCount; ++ i)
- {
- SAFE_RELEASE(m_pShaderResources[i].pShaderResource);
- }
-
- assert(nullptr == m_pUnorderedAccessViews || m_Heap.IsInHeap(m_pUnorderedAccessViews));
- for (size_t i = 0; i < m_UnorderedAccessViewCount; ++ i)
- {
- SAFE_RELEASE(m_pUnorderedAccessViews[i].pUnorderedAccessView);
- }
-
- assert(nullptr == m_pRenderTargetViews || m_Heap.IsInHeap(m_pRenderTargetViews));
- for (size_t i = 0; i < m_RenderTargetViewCount; ++ i)
- {
- SAFE_RELEASE(m_pRenderTargetViews[i].pRenderTargetView);
- }
-
- assert(nullptr == m_pDepthStencilViews || m_Heap.IsInHeap(m_pDepthStencilViews));
- for (size_t i = 0; i < m_DepthStencilViewCount; ++ i)
- {
- SAFE_RELEASE(m_pDepthStencilViews[i].pDepthStencilView);
- }
-
- assert(nullptr == m_pMemberDataBlocks || m_Heap.IsInHeap(m_pMemberDataBlocks));
- for (size_t i = 0; i < m_MemberDataCount; ++ i)
- {
- switch( m_pMemberDataBlocks[i].Type )
- {
- case MDT_ClassInstance:
- SAFE_RELEASE(m_pMemberDataBlocks[i].Data.pD3DClassInstance);
- break;
- case MDT_BlendState:
- SAFE_RELEASE(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedBlendState);
- break;
- case MDT_DepthStencilState:
- SAFE_RELEASE(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedDepthStencilState);
- break;
- case MDT_RasterizerState:
- SAFE_RELEASE(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedRasterizerState);
- break;
- case MDT_SamplerState:
- SAFE_RELEASE(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedSamplerState);
- break;
- case MDT_Buffer:
- SAFE_RELEASE(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedConstantBuffer);
- break;
- case MDT_ShaderResourceView:
- SAFE_RELEASE(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedTextureBuffer);
- break;
- default:
- assert( false );
- }
- }
-
- assert(nullptr == m_pCBs || m_Heap.IsInHeap(m_pCBs));
- for (size_t i = 0; i < m_CBCount; ++ i)
- {
- SAFE_RELEASE(m_pCBs[i].TBuffer.pShaderResource);
- SAFE_RELEASE(m_pCBs[i].pD3DObject);
- }
-
- assert(nullptr == m_pShaderBlocks || m_Heap.IsInHeap(m_pShaderBlocks));
- _Analysis_assume_( m_ShaderBlockCount == 0 || m_pShaderBlocks != 0 );
- for (size_t i = 0; i < m_ShaderBlockCount; ++ i)
- {
- SAFE_RELEASE(m_pShaderBlocks[i].pD3DObject);
- }
-
- SAFE_RELEASE( m_pDevice );
- }
- SAFE_RELEASE( m_pClassLinkage );
- assert( m_pContext == nullptr );
-
- // Restore debug spew
- if (pInfoQueue)
- {
- pInfoQueue->PopStorageFilter();
- SAFE_RELEASE(pInfoQueue);
- }
-}
-
-// AddRef all D3D object when cloning
-void CEffect::AddRefAllForCloning( _In_ CEffect* pEffectSource )
-{
-#ifdef NDEBUG
- UNREFERENCED_PARAMETER(pEffectSource);
-#endif
- // Keep the following in line with ~CEffect
-
- assert( m_pDevice != nullptr );
-
- for( size_t i = 0; i < m_ShaderBlockCount; ++ i )
- {
- SAFE_ADDREF( m_pShaderBlocks[i].pInputSignatureBlob );
- if( m_pShaderBlocks[i].pReflectionData )
- {
- SAFE_ADDREF( m_pShaderBlocks[i].pReflectionData->pReflection );
- }
- }
-
- assert(nullptr == m_pRasterizerBlocks || pEffectSource->m_Heap.IsInHeap(m_pRasterizerBlocks));
- for ( size_t i = 0; i < m_RasterizerBlockCount; ++ i)
- {
- SAFE_ADDREF(m_pRasterizerBlocks[i].pRasterizerObject);
- }
-
- assert(nullptr == m_pBlendBlocks || pEffectSource->m_Heap.IsInHeap(m_pBlendBlocks));
- for ( size_t i = 0; i < m_BlendBlockCount; ++ i)
- {
- SAFE_ADDREF(m_pBlendBlocks[i].pBlendObject);
- }
-
- assert(nullptr == m_pDepthStencilBlocks || pEffectSource->m_Heap.IsInHeap(m_pDepthStencilBlocks));
- for ( size_t i = 0; i < m_DepthStencilBlockCount; ++ i)
- {
- SAFE_ADDREF(m_pDepthStencilBlocks[i].pDSObject);
- }
-
- assert(nullptr == m_pSamplerBlocks || pEffectSource->m_Heap.IsInHeap(m_pSamplerBlocks));
- for ( size_t i = 0; i < m_SamplerBlockCount; ++ i)
- {
- SAFE_ADDREF(m_pSamplerBlocks[i].pD3DObject);
- }
-
- assert(nullptr == m_pShaderResources || pEffectSource->m_Heap.IsInHeap(m_pShaderResources));
- for ( size_t i = 0; i < m_ShaderResourceCount; ++ i)
- {
- SAFE_ADDREF(m_pShaderResources[i].pShaderResource);
- }
-
- assert(nullptr == m_pUnorderedAccessViews || pEffectSource->m_Heap.IsInHeap(m_pUnorderedAccessViews));
- for ( size_t i = 0; i < m_UnorderedAccessViewCount; ++ i)
- {
- SAFE_ADDREF(m_pUnorderedAccessViews[i].pUnorderedAccessView);
- }
-
- assert(nullptr == m_pRenderTargetViews || pEffectSource->m_Heap.IsInHeap(m_pRenderTargetViews));
- for ( size_t i = 0; i < m_RenderTargetViewCount; ++ i)
- {
- SAFE_ADDREF(m_pRenderTargetViews[i].pRenderTargetView);
- }
-
- assert(nullptr == m_pDepthStencilViews || pEffectSource->m_Heap.IsInHeap(m_pDepthStencilViews));
- for ( size_t i = 0; i < m_DepthStencilViewCount; ++ i)
- {
- SAFE_ADDREF(m_pDepthStencilViews[i].pDepthStencilView);
- }
-
- assert(nullptr == m_pMemberDataBlocks || pEffectSource->m_Heap.IsInHeap(m_pMemberDataBlocks));
- for ( size_t i = 0; i < m_MemberDataCount; ++ i)
- {
- switch( m_pMemberDataBlocks[i].Type )
- {
- case MDT_ClassInstance:
- SAFE_ADDREF(m_pMemberDataBlocks[i].Data.pD3DClassInstance);
- break;
- case MDT_BlendState:
- SAFE_ADDREF(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedBlendState);
- break;
- case MDT_DepthStencilState:
- SAFE_ADDREF(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedDepthStencilState);
- break;
- case MDT_RasterizerState:
- SAFE_ADDREF(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedRasterizerState);
- break;
- case MDT_SamplerState:
- SAFE_ADDREF(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedSamplerState);
- break;
- case MDT_Buffer:
- SAFE_ADDREF(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedConstantBuffer);
- break;
- case MDT_ShaderResourceView:
- SAFE_ADDREF(m_pMemberDataBlocks[i].Data.pD3DEffectsManagedTextureBuffer);
- break;
- default:
- assert( false );
- }
- }
-
- // There's no need to AddRef CBs, since they are recreated
- if (m_pCBs)
- {
- assert(pEffectSource->m_Heap.IsInHeap(m_pCBs));
- for (size_t i = 0; i < m_CBCount; ++i)
- {
- SAFE_ADDREF(m_pCBs[i].TBuffer.pShaderResource);
- SAFE_ADDREF(m_pCBs[i].pD3DObject);
- }
- }
-
- assert(nullptr == m_pShaderBlocks || pEffectSource->m_Heap.IsInHeap(m_pShaderBlocks));
- for ( size_t i = 0; i < m_ShaderBlockCount; ++ i)
- {
- SAFE_ADDREF(m_pShaderBlocks[i].pD3DObject);
- }
-
- SAFE_ADDREF( m_pDevice );
-
- SAFE_ADDREF( m_pClassLinkage );
- assert( m_pContext == nullptr );
-}
-
-_Use_decl_annotations_
-HRESULT CEffect::QueryInterface(REFIID iid, LPVOID *ppv)
-{
- HRESULT hr = S_OK;
-
- if(nullptr == ppv)
- {
- DPF(0, "ID3DX11Effect::QueryInterface: nullptr parameter");
- hr = E_INVALIDARG;
- goto EXIT;
- }
-
- *ppv = nullptr;
- if(IsEqualIID(iid, IID_IUnknown))
- {
- *ppv = (IUnknown *) this;
- }
- else if(IsEqualIID(iid, IID_ID3DX11Effect))
- {
- *ppv = (ID3DX11Effect *) this;
- }
- else
- {
- return E_NOINTERFACE;
- }
-
- AddRef();
-
-EXIT:
- return hr;
-}
-
-ULONG CEffect::AddRef()
-{
- return ++ m_RefCount;
-}
-
-ULONG CEffect::Release()
-{
- if (-- m_RefCount > 0)
- {
- return m_RefCount;
- }
- else
- {
- delete this;
- }
-
- return 0;
-}
-
-// In all shaders, replace pOldBufferBlock with pNewBuffer, if pOldBufferBlock is a dependency
-_Use_decl_annotations_
-void CEffect::ReplaceCBReference(SConstantBuffer *pOldBufferBlock, ID3D11Buffer *pNewBuffer)
-{
- for (size_t iShaderBlock=0; iShaderBlock<m_ShaderBlockCount; iShaderBlock++)
- {
- for (size_t iCBDep = 0; iCBDep < m_pShaderBlocks[iShaderBlock].CBDepCount; iCBDep++)
- {
- for (size_t iCB = 0; iCB < m_pShaderBlocks[iShaderBlock].pCBDeps[iCBDep].Count; iCB++)
- {
- if (m_pShaderBlocks[iShaderBlock].pCBDeps[iCBDep].ppFXPointers[iCB] == pOldBufferBlock)
- m_pShaderBlocks[iShaderBlock].pCBDeps[iCBDep].ppD3DObjects[iCB] = pNewBuffer;
- }
- }
- }
-}
-
-// In all shaders, replace pOldSamplerBlock with pNewSampler, if pOldSamplerBlock is a dependency
-_Use_decl_annotations_
-void CEffect::ReplaceSamplerReference(SSamplerBlock *pOldSamplerBlock, ID3D11SamplerState *pNewSampler)
-{
- for (size_t iShaderBlock=0; iShaderBlock<m_ShaderBlockCount; iShaderBlock++)
- {
- for (size_t iSamplerDep = 0; iSamplerDep < m_pShaderBlocks[iShaderBlock].SampDepCount; iSamplerDep++)
- {
- for (size_t iSampler = 0; iSampler < m_pShaderBlocks[iShaderBlock].pSampDeps[iSamplerDep].Count; iSampler++)
- {
- if (m_pShaderBlocks[iShaderBlock].pSampDeps[iSamplerDep].ppFXPointers[iSampler] == pOldSamplerBlock)
- m_pShaderBlocks[iShaderBlock].pSampDeps[iSamplerDep].ppD3DObjects[iSampler] = pNewSampler;
- }
- }
- }
-}
-
-// Call BindToDevice after the effect has been fully loaded.
-// BindToDevice will release all D3D11 objects and create new ones on the new device
-_Use_decl_annotations_
-HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
-{
- HRESULT hr = S_OK;
-
- // Set new device
- if (pDevice == nullptr)
- {
- DPF(0, "ID3DX11Effect: pDevice must point to a valid D3D11 device");
- return D3DERR_INVALIDCALL;
- }
-
- if (m_pDevice != nullptr)
- {
- DPF(0, "ID3DX11Effect: Internal error, rebinding effects to a new device is not supported");
- return D3DERR_INVALIDCALL;
- }
-
- bool featureLevelGE11 = ( pDevice->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0 );
-
- pDevice->AddRef();
- SAFE_RELEASE(m_pDevice);
- m_pDevice = pDevice;
- VH( m_pDevice->CreateClassLinkage( &m_pClassLinkage ) );
- SetDebugObjectName(m_pClassLinkage,srcName);
-
- // Create all constant buffers
- SConstantBuffer *pCB = m_pCBs;
- SConstantBuffer *pCBLast = m_pCBs + m_CBCount;
- for(; pCB != pCBLast; pCB++)
- {
- SAFE_RELEASE(pCB->pD3DObject);
- SAFE_RELEASE(pCB->TBuffer.pShaderResource);
-
- // This is a CBuffer
- if (pCB->Size > 0)
- {
- if (pCB->IsTBuffer)
- {
- D3D11_BUFFER_DESC bufDesc;
- // size is always register aligned
- bufDesc.ByteWidth = pCB->Size;
- bufDesc.Usage = D3D11_USAGE_DEFAULT;
- bufDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
- bufDesc.CPUAccessFlags = 0;
- bufDesc.MiscFlags = 0;
-
- VH( pDevice->CreateBuffer( &bufDesc, nullptr, &pCB->pD3DObject) );
- SetDebugObjectName(pCB->pD3DObject, srcName );
-
- D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc;
- viewDesc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
- viewDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
- viewDesc.Buffer.ElementOffset = 0;
- viewDesc.Buffer.ElementWidth = pCB->Size / SType::c_RegisterSize;
-
- VH( pDevice->CreateShaderResourceView( pCB->pD3DObject, &viewDesc, &pCB->TBuffer.pShaderResource) );
- SetDebugObjectName(pCB->TBuffer.pShaderResource, srcName );
- }
- else
- {
- D3D11_BUFFER_DESC bufDesc;
- // size is always register aligned
- bufDesc.ByteWidth = pCB->Size;
- bufDesc.Usage = D3D11_USAGE_DEFAULT;
- bufDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
- bufDesc.CPUAccessFlags = 0;
- bufDesc.MiscFlags = 0;
-
- VH( pDevice->CreateBuffer( &bufDesc, nullptr, &pCB->pD3DObject) );
- SetDebugObjectName( pCB->pD3DObject, srcName );
- pCB->TBuffer.pShaderResource = nullptr;
- }
-
- pCB->IsDirty = true;
- }
- else
- {
- pCB->IsDirty = false;
- }
- }
-
- // Create all RasterizerStates
- SRasterizerBlock *pRB = m_pRasterizerBlocks;
- SRasterizerBlock *pRBLast = m_pRasterizerBlocks + m_RasterizerBlockCount;
- for(; pRB != pRBLast; pRB++)
- {
- SAFE_RELEASE(pRB->pRasterizerObject);
- if( SUCCEEDED( m_pDevice->CreateRasterizerState( &pRB->BackingStore, &pRB->pRasterizerObject) ) )
- {
- pRB->IsValid = true;
- SetDebugObjectName( pRB->pRasterizerObject, srcName );
- }
- else
- pRB->IsValid = false;
- }
-
- // Create all DepthStencils
- SDepthStencilBlock *pDS = m_pDepthStencilBlocks;
- SDepthStencilBlock *pDSLast = m_pDepthStencilBlocks + m_DepthStencilBlockCount;
- for(; pDS != pDSLast; pDS++)
- {
- SAFE_RELEASE(pDS->pDSObject);
- if( SUCCEEDED( m_pDevice->CreateDepthStencilState( &pDS->BackingStore, &pDS->pDSObject) ) )
- {
- pDS->IsValid = true;
- SetDebugObjectName( pDS->pDSObject, srcName );
- }
- else
- pDS->IsValid = false;
- }
-
- // Create all BlendStates
- SBlendBlock *pBlend = m_pBlendBlocks;
- SBlendBlock *pBlendLast = m_pBlendBlocks + m_BlendBlockCount;
- for(; pBlend != pBlendLast; pBlend++)
- {
- SAFE_RELEASE(pBlend->pBlendObject);
- if( SUCCEEDED( m_pDevice->CreateBlendState( &pBlend->BackingStore, &pBlend->pBlendObject ) ) )
- {
- pBlend->IsValid = true;
- SetDebugObjectName( pBlend->pBlendObject, srcName );
- }
- else
- pBlend->IsValid = false;
- }
-
- // Create all Samplers
- SSamplerBlock *pSampler = m_pSamplerBlocks;
- SSamplerBlock *pSamplerLast = m_pSamplerBlocks + m_SamplerBlockCount;
- for(; pSampler != pSamplerLast; pSampler++)
- {
- SAFE_RELEASE(pSampler->pD3DObject);
-
- VH( m_pDevice->CreateSamplerState( &pSampler->BackingStore.SamplerDesc, &pSampler->pD3DObject) );
- SetDebugObjectName( pSampler->pD3DObject, srcName );
- }
-
- // Create all shaders
- ID3D11ClassLinkage* neededClassLinkage = featureLevelGE11 ? m_pClassLinkage : nullptr;
- SShaderBlock *pShader = m_pShaderBlocks;
- SShaderBlock *pShaderLast = m_pShaderBlocks + m_ShaderBlockCount;
- for(; pShader != pShaderLast; pShader++)
- {
- SAFE_RELEASE(pShader->pD3DObject);
-
- if (nullptr == pShader->pReflectionData)
- {
- // nullptr shader. It's one of these:
- // PixelShader ps;
- // or
- // SetPixelShader( nullptr );
- continue;
- }
-
- if (pShader->pReflectionData->pStreamOutDecls[0] || pShader->pReflectionData->pStreamOutDecls[1] ||
- pShader->pReflectionData->pStreamOutDecls[2] || pShader->pReflectionData->pStreamOutDecls[3] )
- {
- // This is a geometry shader, process it's data
- CSOParser soParser;
- VH( soParser.Parse(pShader->pReflectionData->pStreamOutDecls) );
- uint32_t strides[4];
- soParser.GetStrides( strides );
- hr = m_pDevice->CreateGeometryShaderWithStreamOutput(pShader->pReflectionData->pBytecode,
- pShader->pReflectionData->BytecodeLength,
- soParser.GetDeclArray(),
- soParser.GetDeclCount(),
- strides,
- featureLevelGE11 ? 4 : 1,
- pShader->pReflectionData->RasterizedStream,
- neededClassLinkage,
- reinterpret_cast<ID3D11GeometryShader**>(&pShader->pD3DObject) );
- if (FAILED(hr))
- {
- DPF(1, "ID3DX11Effect::Load - failed to create GeometryShader with StreamOutput decl: \"%s\"", soParser.GetErrorString() );
- pShader->IsValid = false;
- hr = S_OK;
- }
- else
- {
- SetDebugObjectName( pShader->pD3DObject, srcName );
- }
- }
- else
- {
- // This is a regular shader
- if( pShader->pReflectionData->RasterizedStream == D3D11_SO_NO_RASTERIZED_STREAM )
- pShader->IsValid = false;
- else
- {
- if( FAILED( (m_pDevice->*(pShader->pVT->pCreateShader))( (uint32_t *) pShader->pReflectionData->pBytecode, pShader->pReflectionData->BytecodeLength, neededClassLinkage, &pShader->pD3DObject) ) )
- {
- DPF(1, "ID3DX11Effect::Load - failed to create shader" );
- pShader->IsValid = false;
- }
- else
- {
- SetDebugObjectName( pShader->pD3DObject, srcName );
- }
- }
- }
-
- // Update all dependency pointers
- VH( pShader->OnDeviceBind() );
- }
-
- // Initialize the member data pointers for all variables
- uint32_t CurMemberData = 0;
- for (uint32_t i = 0; i < m_VariableCount; ++ i)
- {
- if( m_pVariables[i].pMemberData )
- {
- if( m_pVariables[i].pType->IsClassInstance() )
- {
- for (uint32_t j = 0; j < std::max<size_t>(m_pVariables[i].pType->Elements,1); ++j)
- {
- assert( CurMemberData < m_MemberDataCount );
- ID3D11ClassInstance** ppCI = &(m_pVariables[i].pMemberData + j)->Data.pD3DClassInstance;
- (m_pVariables[i].pMemberData + j)->Type = MDT_ClassInstance;
- (m_pVariables[i].pMemberData + j)->Data.pD3DClassInstance = nullptr;
- if( m_pVariables[i].pType->TotalSize > 0 )
- {
- // ignore failures in GetClassInstance;
- m_pClassLinkage->GetClassInstance( m_pVariables[i].pName, j, ppCI );
- }
- else
- {
- // The HLSL compiler optimizes out zero-sized classes, so we have to create class instances from scratch
- if( FAILED( m_pClassLinkage->CreateClassInstance( m_pVariables[i].pType->pTypeName, 0, 0, 0, 0, ppCI ) ) )
- {
- DPF(0, "ID3DX11Effect: Out of memory while trying to create new class instance interface");
- }
- else
- {
- SetDebugObjectName( *ppCI, srcName );
- }
- }
- CurMemberData++;
- }
- }
- else if( m_pVariables[i].pType->IsStateBlockObject() )
- {
- for (size_t j = 0; j < std::max<size_t>(m_pVariables[i].pType->Elements,1); ++j)
- {
- switch( m_pVariables[i].pType->ObjectType )
- {
- case EOT_Blend:
- (m_pVariables[i].pMemberData + j)->Type = MDT_BlendState;
- (m_pVariables[i].pMemberData + j)->Data.pD3DEffectsManagedBlendState = nullptr;
- break;
- case EOT_Rasterizer:
- (m_pVariables[i].pMemberData + j)->Type = MDT_RasterizerState;
- (m_pVariables[i].pMemberData + j)->Data.pD3DEffectsManagedRasterizerState = nullptr;
- break;
- case EOT_DepthStencil:
- (m_pVariables[i].pMemberData + j)->Type = MDT_DepthStencilState;
- (m_pVariables[i].pMemberData + j)->Data.pD3DEffectsManagedDepthStencilState = nullptr;
- break;
- case EOT_Sampler:
- (m_pVariables[i].pMemberData + j)->Type = MDT_SamplerState;
- (m_pVariables[i].pMemberData + j)->Data.pD3DEffectsManagedSamplerState = nullptr;
- break;
- default:
- VB( false );
- }
- CurMemberData++;
- }
- }
- else
- {
- VB( false );
- }
- }
- }
- for(pCB = m_pCBs; pCB != pCBLast; pCB++)
- {
- (pCB->pMemberData + 0)->Type = MDT_Buffer;
- (pCB->pMemberData + 0)->Data.pD3DEffectsManagedConstantBuffer = nullptr;
- CurMemberData++;
- (pCB->pMemberData + 1)->Type = MDT_ShaderResourceView;
- (pCB->pMemberData + 1)->Data.pD3DEffectsManagedTextureBuffer = nullptr;
- CurMemberData++;
- }
-
-
- // Determine which techniques and passes are known to be invalid
- for( size_t iGroup=0; iGroup < m_GroupCount; iGroup++ )
- {
- SGroup* pGroup = &m_pGroups[iGroup];
- pGroup->InitiallyValid = true;
-
- for( size_t iTech=0; iTech < pGroup->TechniqueCount; iTech++ )
- {
- STechnique* pTechnique = &pGroup->pTechniques[iTech];
- pTechnique->InitiallyValid = true;
-
- for( size_t iPass = 0; iPass < pTechnique->PassCount; iPass++ )
- {
- SPassBlock* pPass = &pTechnique->pPasses[iPass];
- pPass->InitiallyValid = true;
-
- if( pPass->BackingStore.pBlendBlock != nullptr && !pPass->BackingStore.pBlendBlock->IsValid )
- pPass->InitiallyValid = false;
- if( pPass->BackingStore.pDepthStencilBlock != nullptr && !pPass->BackingStore.pDepthStencilBlock->IsValid )
- pPass->InitiallyValid = false;
- if( pPass->BackingStore.pRasterizerBlock != nullptr && !pPass->BackingStore.pRasterizerBlock->IsValid )
- pPass->InitiallyValid = false;
- if( pPass->BackingStore.pVertexShaderBlock != nullptr && !pPass->BackingStore.pVertexShaderBlock->IsValid )
- pPass->InitiallyValid = false;
- if( pPass->BackingStore.pPixelShaderBlock != nullptr && !pPass->BackingStore.pPixelShaderBlock->IsValid )
- pPass->InitiallyValid = false;
- if( pPass->BackingStore.pGeometryShaderBlock != nullptr && !pPass->BackingStore.pGeometryShaderBlock->IsValid )
- pPass->InitiallyValid = false;
- if( pPass->BackingStore.pHullShaderBlock != nullptr && !pPass->BackingStore.pHullShaderBlock->IsValid )
- pPass->InitiallyValid = false;
- if( pPass->BackingStore.pDomainShaderBlock != nullptr && !pPass->BackingStore.pDomainShaderBlock->IsValid )
- pPass->InitiallyValid = false;
- if( pPass->BackingStore.pComputeShaderBlock != nullptr && !pPass->BackingStore.pComputeShaderBlock->IsValid )
- pPass->InitiallyValid = false;
-
- pTechnique->InitiallyValid &= pPass->InitiallyValid;
- }
- pGroup->InitiallyValid &= pTechnique->InitiallyValid;
- }
- }
-
-lExit:
- return hr;
-}
-
-// FindVariableByName, plus an understanding of literal indices
-// This code handles A[i].
-// It does not handle anything else, like A.B, A[B[i]], A[B]
-SVariable * CEffect::FindVariableByNameWithParsing(_In_z_ LPCSTR pName)
-{
- SGlobalVariable *pVariable;
- const uint32_t MAX_PARSABLE_NAME_LENGTH = 256;
- char pScratchString[MAX_PARSABLE_NAME_LENGTH];
-
- const char* pSource = pName;
- char* pDest = pScratchString;
- char* pEnd = pScratchString + MAX_PARSABLE_NAME_LENGTH;
-
- pVariable = nullptr;
-
- while( *pSource != 0 )
- {
- if( pDest == pEnd )
- {
- pVariable = FindLocalVariableByName(pName);
- if( pVariable == nullptr )
- {
- DPF( 0, "Name %s is too long to parse", pName );
- }
- return pVariable;
- }
-
- if( *pSource == '[' )
- {
- // parse previous variable name
- *pDest = 0;
- assert( pVariable == nullptr );
- pVariable = FindLocalVariableByName(pScratchString);
- if( pVariable == nullptr )
- {
- return nullptr;
- }
- pDest = pScratchString;
- }
- else if( *pSource == ']' )
- {
- // parse integer
- *pDest = 0;
- uint32_t index = atoi(pScratchString);
- assert( pVariable != 0 );
- _Analysis_assume_( pVariable != 0 );
- pVariable = (SGlobalVariable*)pVariable->GetElement(index);
- if( pVariable && !pVariable->IsValid() )
- {
- pVariable = nullptr;
- }
- return pVariable;
- }
- else
- {
- // add character
- *pDest = *pSource;
- pDest++;
- }
- pSource++;
- }
-
- if( pDest != pScratchString )
- {
- // parse the variable name (there was no [i])
- *pDest = 0;
- assert( pVariable == nullptr );
- pVariable = FindLocalVariableByName(pScratchString);
- }
-
- return pVariable;
-}
-
-SGlobalVariable * CEffect::FindVariableByName(_In_z_ LPCSTR pName)
-{
- SGlobalVariable *pVariable;
-
- pVariable = FindLocalVariableByName(pName);
-
- return pVariable;
-}
-
-SGlobalVariable * CEffect::FindLocalVariableByName(_In_z_ LPCSTR pName)
-{
- SGlobalVariable *pVariable, *pVariableEnd;
-
- pVariableEnd = m_pVariables + m_VariableCount;
- for (pVariable = m_pVariables; pVariable != pVariableEnd; pVariable++)
- {
- if (strcmp( pVariable->pName, pName) == 0)
- {
- return pVariable;
- }
- }
-
- return nullptr;
-}
-
-
-//
-// Checks to see if two types are equivalent (either at runtime
-// or during the type-pooling load process)
-//
-// Major assumption: if both types are structures, then their
-// member types & names should already have been added to the pool,
-// in which case their member type & name pointers should be equal.
-//
-// This is true because complex data types (structures) have all
-// sub-types translated before the containing type is translated,
-// which means that simple sub-types (numeric types) have already
-// been pooled.
-//
-bool SType::IsEqual(SType *pOtherType) const
-{
- if (VarType != pOtherType->VarType || Elements != pOtherType->Elements
- || strcmp(pTypeName, pOtherType->pTypeName) != 0)
- {
- return false;
- }
-
- switch (VarType)
- {
- case EVT_Struct:
- {
- if (StructType.Members != pOtherType->StructType.Members)
- {
- return false;
- }
- assert(StructType.pMembers != nullptr && pOtherType->StructType.pMembers != nullptr);
-
- uint32_t i;
- for (i = 0; i < StructType.Members; ++ i)
- {
- // names for types must exist (not true for semantics)
- assert(StructType.pMembers[i].pName != nullptr && pOtherType->StructType.pMembers[i].pName != nullptr);
-
- if (StructType.pMembers[i].pType != pOtherType->StructType.pMembers[i].pType ||
- StructType.pMembers[i].Data.Offset != pOtherType->StructType.pMembers[i].Data.Offset ||
- StructType.pMembers[i].pName != pOtherType->StructType.pMembers[i].pName ||
- StructType.pMembers[i].pSemantic != pOtherType->StructType.pMembers[i].pSemantic)
- {
- return false;
- }
- }
- }
- break;
-
- case EVT_Object:
- {
- if (ObjectType != pOtherType->ObjectType)
- {
- return false;
- }
- }
- break;
-
- case EVT_Numeric:
- {
- if (NumericType.Rows != pOtherType->NumericType.Rows ||
- NumericType.Columns != pOtherType->NumericType.Columns ||
- NumericType.ScalarType != pOtherType->NumericType.ScalarType ||
- NumericType.NumericLayout != pOtherType->NumericType.NumericLayout ||
- NumericType.IsColumnMajor != pOtherType->NumericType.IsColumnMajor ||
- NumericType.IsPackedArray != pOtherType->NumericType.IsPackedArray)
- {
- return false;
- }
- }
- break;
-
- case EVT_Interface:
- {
- // VarType and pTypeName handled above
- }
- break;
-
- default:
- {
- assert(0);
- return false;
- }
- break;
- }
-
- assert(TotalSize == pOtherType->TotalSize && Stride == pOtherType->Stride && PackedSize == pOtherType->PackedSize);
-
- return true;
-}
-
-uint32_t SType::GetTotalUnpackedSize(_In_ bool IsSingleElement) const
-{
- if (VarType == EVT_Object)
- {
- return 0;
- }
- else if (VarType == EVT_Interface)
- {
- return 0;
- }
- else if (Elements > 0 && IsSingleElement)
- {
- assert( ( TotalSize == 0 && Stride == 0 ) ||
- ( (TotalSize > (Stride * (Elements - 1))) && (TotalSize <= (Stride * Elements)) ) );
- return TotalSize - Stride * (Elements - 1);
- }
- else
- {
- return TotalSize;
- }
-}
-
-uint32_t SType::GetTotalPackedSize(_In_ bool IsSingleElement) const
-{
- if (Elements > 0 && IsSingleElement)
- {
- assert(PackedSize % Elements == 0);
- return PackedSize / Elements;
- }
- else
- {
- return PackedSize;
- }
-}
-
-SConstantBuffer *CEffect::FindCB(_In_z_ LPCSTR pName)
-{
- uint32_t i;
-
- for (i=0; i<m_CBCount; i++)
- {
- if (!strcmp(m_pCBs[i].pName, pName))
- {
- return &m_pCBs[i];
- }
- }
-
- return nullptr;
-}
-
-bool CEffect::IsOptimized()
-{
- if ((m_Flags & D3DX11_EFFECT_OPTIMIZED) != 0)
- {
- assert(nullptr == m_pReflection);
- return true;
- }
- else
- {
- assert(nullptr != m_pReflection);
- return false;
- }
-}
-
-// Replace *ppType with the corresponding value in pMappingTable
-// pMappingTable table describes how to map old type pointers to new type pointers
-static HRESULT RemapType(_Inout_ SType **ppType, _Inout_ CPointerMappingTable *pMappingTable)
-{
- HRESULT hr = S_OK;
-
- SPointerMapping ptrMapping;
- CPointerMappingTable::CIterator iter;
- ptrMapping.pOld = *ppType;
- VH( pMappingTable->FindValueWithHash(ptrMapping, ptrMapping.Hash(), &iter) );
- *ppType = (SType *) iter.GetData().pNew;
-
-lExit:
- return hr;
-}
-
-// Replace *ppString with the corresponding value in pMappingTable
-// pMappingTable table describes how to map old string pointers to new string pointers
-static HRESULT RemapString(_In_ char **ppString, _Inout_ CPointerMappingTable *pMappingTable)
-{
- HRESULT hr = S_OK;
-
- SPointerMapping ptrMapping;
- CPointerMappingTable::CIterator iter;
- ptrMapping.pOld = *ppString;
- VH( pMappingTable->FindValueWithHash(ptrMapping, ptrMapping.Hash(), &iter) );
- *ppString = (char *) iter.GetData().pNew;
-
-lExit:
- return hr;
-}
-
-// Used in cloning, copy m_pMemberInterfaces from pEffectSource to this
-HRESULT CEffect::CopyMemberInterfaces( _In_ CEffect* pEffectSource )
-{
- HRESULT hr = S_OK;
-
- uint32_t Members = pEffectSource->m_pMemberInterfaces.GetSize();
- m_pMemberInterfaces.AddRange(Members);
- uint32_t i=0; // after a failure, this holds the failing index
- for(; i < Members; i++ )
- {
- SMember* pOldMember = pEffectSource->m_pMemberInterfaces[i];
- if( pOldMember == nullptr )
- {
- // During Optimization, m_pMemberInterfaces[i] was set to nullptr because it was an annotation
- m_pMemberInterfaces[i] = nullptr;
- continue;
- }
-
- SMember *pNewMember;
- assert( pOldMember->pTopLevelEntity != nullptr );
-
- if (nullptr == (pNewMember = CreateNewMember((SType*)pOldMember->pType, false)))
- {
- DPF(0, "ID3DX11Effect: Out of memory while trying to create new member variable interface");
- VN( pNewMember );
- }
-
- pNewMember->pType = pOldMember->pType;
- pNewMember->pName = pOldMember->pName;
- pNewMember->pSemantic = pOldMember->pSemantic;
- pNewMember->Data.pGeneric = pOldMember->Data.pGeneric;
- pNewMember->IsSingleElement = pOldMember->IsSingleElement;
- pNewMember->pTopLevelEntity = pOldMember->pTopLevelEntity;
- pNewMember->pMemberData = pOldMember->pMemberData;
-
- m_pMemberInterfaces[i] = pNewMember;
- }
-
-lExit:
- if( FAILED(hr) )
- {
- assert( i < Members );
- ZeroMemory( &m_pMemberInterfaces[i], sizeof(SMember) * ( Members - i ) );
- }
- return hr;
-}
-
-// Used in cloning, copy the string pool from pEffectSource to this and build mappingTable
-// for use in RemapString
-_Use_decl_annotations_
-HRESULT CEffect::CopyStringPool( CEffect* pEffectSource, CPointerMappingTable& mappingTable )
-{
- HRESULT hr = S_OK;
- assert( m_pPooledHeap != 0 );
- _Analysis_assume_( m_pPooledHeap != 0 );
- VN( m_pStringPool = new CEffect::CStringHashTable );
- m_pStringPool->SetPrivateHeap(m_pPooledHeap);
- VH( m_pStringPool->AutoGrow() );
-
- CStringHashTable::CIterator stringIter;
-
- // move strings over, build mapping table
- for (pEffectSource->m_pStringPool->GetFirstEntry(&stringIter); !pEffectSource->m_pStringPool->PastEnd(&stringIter); pEffectSource->m_pStringPool->GetNextEntry(&stringIter))
- {
- SPointerMapping ptrMapping;
- char *pString;
-
- const char* pOldString = stringIter.GetData();
- ptrMapping.pOld = (void*)pOldString;
- uint32_t len = (uint32_t)strlen(pOldString);
- uint32_t hash = ptrMapping.Hash();
- VN( pString = new(*m_pPooledHeap) char[len + 1] );
- ptrMapping.pNew = (void*)pString;
- memcpy(ptrMapping.pNew, ptrMapping.pOld, len + 1);
- VH( m_pStringPool->AddValueWithHash(pString, hash) );
-
- VH( mappingTable.AddValueWithHash(ptrMapping, hash) );
- }
-
- // Uncomment to print string mapping
- /*
- CPointerMappingTable::CIterator mapIter;
- for (mappingTable.GetFirstEntry(&mapIter); !mappingTable.PastEnd(&mapIter); mappingTable.GetNextEntry(&mapIter))
- {
- SPointerMapping ptrMapping = mapIter.GetData();
- DPF(0, "string: 0x%x : 0x%x %s", (UINT_PTR)ptrMapping.pOld, (UINT_PTR)ptrMapping.pNew, (char*)ptrMapping.pNew );
- }*/
-
-lExit:
- return hr;
-}
-
-// Used in cloning, copy the unoptimized type pool from pEffectSource to this and build mappingTableTypes
-// for use in RemapType. mappingTableStrings is the mapping table previously filled when copying strings.
-_Use_decl_annotations_
-HRESULT CEffect::CopyTypePool( CEffect* pEffectSource, CPointerMappingTable& mappingTableTypes, CPointerMappingTable& mappingTableStrings )
-{
- HRESULT hr = S_OK;
- assert( m_pPooledHeap != 0 );
- _Analysis_assume_( m_pPooledHeap != 0 );
- VN( m_pTypePool = new CEffect::CTypeHashTable );
- m_pTypePool->SetPrivateHeap(m_pPooledHeap);
- VH( m_pTypePool->AutoGrow() );
-
- CTypeHashTable::CIterator typeIter;
- CPointerMappingTable::CIterator mapIter;
-
- // first pass: move types over, build mapping table
- for (pEffectSource->m_pTypePool->GetFirstEntry(&typeIter); !pEffectSource->m_pTypePool->PastEnd(&typeIter); pEffectSource->m_pTypePool->GetNextEntry(&typeIter))
- {
- SPointerMapping ptrMapping;
- SType *pType;
-
- ptrMapping.pOld = typeIter.GetData();
- uint32_t hash = ptrMapping.Hash();
- VN( (ptrMapping.pNew) = new(*m_pPooledHeap) SType );
- memcpy(ptrMapping.pNew, ptrMapping.pOld, sizeof(SType));
-
- pType = (SType *) ptrMapping.pNew;
-
- // if this is a struct, move its members to the newly allocated space
- if (EVT_Struct == pType->VarType)
- {
- SVariable* pOldMembers = pType->StructType.pMembers;
- VN( pType->StructType.pMembers = new(*m_pPooledHeap) SVariable[pType->StructType.Members] );
- memcpy(pType->StructType.pMembers, pOldMembers, pType->StructType.Members * sizeof(SVariable));
- }
-
- VH( m_pTypePool->AddValueWithHash(pType, hash) );
- VH( mappingTableTypes.AddValueWithHash(ptrMapping, hash) );
- }
-
- // second pass: fixup structure member & name pointers
- for (mappingTableTypes.GetFirstEntry(&mapIter); !mappingTableTypes.PastEnd(&mapIter); mappingTableTypes.GetNextEntry(&mapIter))
- {
- SPointerMapping ptrMapping = mapIter.GetData();
-
- // Uncomment to print type mapping
- //DPF(0, "type: 0x%x : 0x%x", (UINT_PTR)ptrMapping.pOld, (UINT_PTR)ptrMapping.pNew );
-
- SType *pType = (SType *) ptrMapping.pNew;
-
- if( pType->pTypeName )
- {
- VH( RemapString(&pType->pTypeName, &mappingTableStrings) );
- }
-
- // if this is a struct, fix up its members' pointers
- if (EVT_Struct == pType->VarType)
- {
- for (uint32_t i = 0; i < pType->StructType.Members; ++ i)
- {
- VH( RemapType((SType**)&pType->StructType.pMembers[i].pType, &mappingTableTypes) );
- if( pType->StructType.pMembers[i].pName )
- {
- VH( RemapString(&pType->StructType.pMembers[i].pName, &mappingTableStrings) );
- }
- if( pType->StructType.pMembers[i].pSemantic )
- {
- VH( RemapString(&pType->StructType.pMembers[i].pSemantic, &mappingTableStrings) );
- }
- }
- }
- }
-
-lExit:
- return hr;
-}
-
-// Used in cloning, copy the unoptimized type pool from pEffectSource to this and build mappingTableTypes
-// for use in RemapType. mappingTableStrings is the mapping table previously filled when copying strings.
-_Use_decl_annotations_
-HRESULT CEffect::CopyOptimizedTypePool( CEffect* pEffectSource, CPointerMappingTable& mappingTableTypes )
-{
- HRESULT hr = S_OK;
- CEffectHeap* pOptimizedTypeHeap = nullptr;
-
- assert( pEffectSource->m_pOptimizedTypeHeap != 0 );
- _Analysis_assume_( pEffectSource->m_pOptimizedTypeHeap != 0 );
- assert( m_pTypePool == 0 );
- assert( m_pStringPool == 0 );
- assert( m_pPooledHeap == 0 );
-
- VN( pOptimizedTypeHeap = new CEffectHeap );
- VH( pOptimizedTypeHeap->ReserveMemory( pEffectSource->m_pOptimizedTypeHeap->GetSize() ) );
- CPointerMappingTable::CIterator mapIter;
-
- // first pass: move types over, build mapping table
- uint8_t* pReadTypes = pEffectSource->m_pOptimizedTypeHeap->GetDataStart();
- while( pEffectSource->m_pOptimizedTypeHeap->IsInHeap( pReadTypes ) )
- {
- SPointerMapping ptrMapping;
- SType *pType;
- uint32_t moveSize;
-
- ptrMapping.pOld = ptrMapping.pNew = pReadTypes;
- moveSize = sizeof(SType);
- VH( pOptimizedTypeHeap->MoveData(&ptrMapping.pNew, moveSize) );
- pReadTypes += moveSize;
-
- pType = (SType *) ptrMapping.pNew;
-
- // if this is a struct, move its members to the newly allocated space
- if (EVT_Struct == pType->VarType)
- {
- moveSize = pType->StructType.Members * sizeof(SVariable);
- VH( pOptimizedTypeHeap->MoveData((void **)&pType->StructType.pMembers, moveSize) );
- pReadTypes += moveSize;
- }
-
- VH( mappingTableTypes.AddValueWithHash(ptrMapping, ptrMapping.Hash()) );
- }
-
- // second pass: fixup structure member & name pointers
- for (mappingTableTypes.GetFirstEntry(&mapIter); !mappingTableTypes.PastEnd(&mapIter); mappingTableTypes.GetNextEntry(&mapIter))
- {
- SPointerMapping ptrMapping = mapIter.GetData();
-
- // Uncomment to print type mapping
- //DPF(0, "type: 0x%x : 0x%x", (UINT_PTR)ptrMapping.pOld, (UINT_PTR)ptrMapping.pNew );
-
- SType *pType = (SType *) ptrMapping.pNew;
-
- // if this is a struct, fix up its members' pointers
- if (EVT_Struct == pType->VarType)
- {
- for (uint32_t i = 0; i < pType->StructType.Members; ++ i)
- {
- VH( RemapType((SType**)&pType->StructType.pMembers[i].pType, &mappingTableTypes) );
- }
- }
- }
-
-lExit:
- return hr;
-}
-
-// Used in cloning, create new ID3D11ConstantBuffers for each non-single CB
-HRESULT CEffect::RecreateCBs()
-{
- HRESULT hr = S_OK;
- uint32_t i; // after a failure, this holds the failing index
-
- for (i = 0; i < m_CBCount; ++ i)
- {
- SConstantBuffer* pCB = &m_pCBs[i];
-
- pCB->IsNonUpdatable = pCB->IsUserManaged || pCB->ClonedSingle();
-
- if( pCB->Size > 0 && !pCB->ClonedSingle() )
- {
- ID3D11Buffer** ppOriginalBuffer;
- ID3D11ShaderResourceView** ppOriginalTBufferView;
-
- if( pCB->IsUserManaged )
- {
- ppOriginalBuffer = &pCB->pMemberData[0].Data.pD3DEffectsManagedConstantBuffer;
- ppOriginalTBufferView = &pCB->pMemberData[1].Data.pD3DEffectsManagedTextureBuffer;
- }
- else
- {
- ppOriginalBuffer = &pCB->pD3DObject;
- ppOriginalTBufferView = &pCB->TBuffer.pShaderResource;
- }
-
- VN( *ppOriginalBuffer );
- D3D11_BUFFER_DESC bufDesc;
- (*ppOriginalBuffer)->GetDesc( &bufDesc );
- ID3D11Buffer* pNewBuffer = nullptr;
- VH( m_pDevice->CreateBuffer( &bufDesc, nullptr, &pNewBuffer ) );
- SetDebugObjectName( pNewBuffer, "D3DX11Effect" );
- (*ppOriginalBuffer)->Release();
- (*ppOriginalBuffer) = pNewBuffer;
- pNewBuffer = nullptr;
-
- if( pCB->IsTBuffer )
- {
- VN( *ppOriginalTBufferView );
- D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc;
- (*ppOriginalTBufferView)->GetDesc( &viewDesc );
- ID3D11ShaderResourceView* pNewView = nullptr;
- VH( m_pDevice->CreateShaderResourceView( (*ppOriginalBuffer), &viewDesc, &pNewView) );
- SetDebugObjectName( pNewView, "D3DX11Effect" );
- (*ppOriginalTBufferView)->Release();
- (*ppOriginalTBufferView) = pNewView;
- pNewView = nullptr;
- }
- else
- {
- assert( *ppOriginalTBufferView == nullptr );
- ReplaceCBReference( pCB, (*ppOriginalBuffer) );
- }
-
- pCB->IsDirty = true;
- }
- }
-
-lExit:
- return hr;
-}
-
-// Move Name and Semantic strings using mappingTableStrings
-_Use_decl_annotations_
-HRESULT CEffect::FixupMemberInterface( SMember* pMember, CEffect* pEffectSource, CPointerMappingTable& mappingTableStrings )
-{
- HRESULT hr = S_OK;
-
- if( pMember->pName )
- {
- if( pEffectSource->m_pReflection && pEffectSource->m_pReflection->m_Heap.IsInHeap(pMember->pName) )
- {
- pMember->pName = (char*)((UINT_PTR)pMember->pName - (UINT_PTR)pEffectSource->m_pReflection->m_Heap.GetDataStart() + (UINT_PTR)m_pReflection->m_Heap.GetDataStart());
- }
- else
- {
- VH( RemapString(&pMember->pName, &mappingTableStrings) );
- }
- }
- if( pMember->pSemantic )
- {
- if( pEffectSource->m_pReflection && pEffectSource->m_pReflection->m_Heap.IsInHeap(pMember->pSemantic) )
- {
- pMember->pSemantic = (char*)((UINT_PTR)pMember->pSemantic - (UINT_PTR)pEffectSource->m_pReflection->m_Heap.GetDataStart() + (UINT_PTR)m_pReflection->m_Heap.GetDataStart());
- }
- else
- {
- VH( RemapString(&pMember->pSemantic, &mappingTableStrings) );
- }
- }
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// Public API to create a copy of this effect
-HRESULT CEffect::CloneEffect(_In_ uint32_t Flags, _Outptr_ ID3DX11Effect** ppClonedEffect )
-{
- HRESULT hr = S_OK;
- CPointerMappingTable mappingTableTypes;
- CPointerMappingTable mappingTableStrings;
-
- CEffectLoader loader;
- CEffect* pNewEffect = nullptr;
- CDataBlockStore* pTempHeap = nullptr;
-
-
- VN( pNewEffect = new CEffect( m_Flags ) );
- if( Flags & D3DX11_EFFECT_CLONE_FORCE_NONSINGLE )
- {
- // The effect is cloned as if there was no original, so don't mark it as cloned
- pNewEffect->m_Flags &= ~(uint32_t)D3DX11_EFFECT_CLONE;
- }
- else
- {
- pNewEffect->m_Flags |= D3DX11_EFFECT_CLONE;
- }
-
- pNewEffect->m_VariableCount = m_VariableCount;
- pNewEffect->m_pVariables = m_pVariables;
- pNewEffect->m_AnonymousShaderCount = m_AnonymousShaderCount;
- pNewEffect->m_pAnonymousShaders = m_pAnonymousShaders;
- pNewEffect->m_TechniqueCount = m_TechniqueCount;
- pNewEffect->m_GroupCount = m_GroupCount;
- pNewEffect->m_pGroups = m_pGroups;
- pNewEffect->m_pNullGroup = m_pNullGroup;
- pNewEffect->m_ShaderBlockCount = m_ShaderBlockCount;
- pNewEffect->m_pShaderBlocks = m_pShaderBlocks;
- pNewEffect->m_DepthStencilBlockCount = m_DepthStencilBlockCount;
- pNewEffect->m_pDepthStencilBlocks = m_pDepthStencilBlocks;
- pNewEffect->m_BlendBlockCount = m_BlendBlockCount;
- pNewEffect->m_pBlendBlocks = m_pBlendBlocks;
- pNewEffect->m_RasterizerBlockCount = m_RasterizerBlockCount;
- pNewEffect->m_pRasterizerBlocks = m_pRasterizerBlocks;
- pNewEffect->m_SamplerBlockCount = m_SamplerBlockCount;
- pNewEffect->m_pSamplerBlocks = m_pSamplerBlocks;
- pNewEffect->m_MemberDataCount = m_MemberDataCount;
- pNewEffect->m_pMemberDataBlocks = m_pMemberDataBlocks;
- pNewEffect->m_InterfaceCount = m_InterfaceCount;
- pNewEffect->m_pInterfaces = m_pInterfaces;
- pNewEffect->m_CBCount = m_CBCount;
- pNewEffect->m_pCBs = m_pCBs;
- pNewEffect->m_StringCount = m_StringCount;
- pNewEffect->m_pStrings = m_pStrings;
- pNewEffect->m_ShaderResourceCount = m_ShaderResourceCount;
- pNewEffect->m_pShaderResources = m_pShaderResources;
- pNewEffect->m_UnorderedAccessViewCount = m_UnorderedAccessViewCount;
- pNewEffect->m_pUnorderedAccessViews = m_pUnorderedAccessViews;
- pNewEffect->m_RenderTargetViewCount = m_RenderTargetViewCount;
- pNewEffect->m_pRenderTargetViews = m_pRenderTargetViews;
- pNewEffect->m_DepthStencilViewCount = m_DepthStencilViewCount;
- pNewEffect->m_pDepthStencilViews = m_pDepthStencilViews;
- pNewEffect->m_LocalTimer = m_LocalTimer;
- pNewEffect->m_FXLIndex = m_FXLIndex;
- pNewEffect->m_pDevice = m_pDevice;
- pNewEffect->m_pClassLinkage = m_pClassLinkage;
-
- pNewEffect->AddRefAllForCloning( this );
-
-
- // m_pMemberInterfaces is a vector of cbuffer members that were created when the user called GetMemberBy* or GetElement
- // or during Effect loading when an interface is initialized to a global class variable elment.
- VH( pNewEffect->CopyMemberInterfaces( this ) );
-
- loader.m_pvOldMemberInterfaces = &m_pMemberInterfaces;
- loader.m_pEffect = pNewEffect;
- loader.m_EffectMemory = loader.m_ReflectionMemory = 0;
-
-
- // Move data from current effect to new effect
- if( !IsOptimized() )
- {
- VN( pNewEffect->m_pReflection = new CEffectReflection() );
- loader.m_pReflection = pNewEffect->m_pReflection;
-
- // make sure strings are moved before ReallocateEffectData
- VH( loader.InitializeReflectionDataAndMoveStrings( m_pReflection->m_Heap.GetSize() ) );
- }
- VH( loader.ReallocateEffectData( true ) );
- if( !IsOptimized() )
- {
- VH( loader.ReallocateReflectionData( true ) );
- }
-
-
- // Data structures for remapping type pointers and string pointers
- VN( pTempHeap = new CDataBlockStore );
- pTempHeap->EnableAlignment();
- mappingTableTypes.SetPrivateHeap(pTempHeap);
- mappingTableStrings.SetPrivateHeap(pTempHeap);
- VH( mappingTableTypes.AutoGrow() );
- VH( mappingTableStrings.AutoGrow() );
-
- if( !IsOptimized() )
- {
- // Let's re-create the type pool and string pool
- VN( pNewEffect->m_pPooledHeap = new CDataBlockStore );
- pNewEffect->m_pPooledHeap->EnableAlignment();
-
- VH( pNewEffect->CopyStringPool( this, mappingTableStrings ) );
- VH( pNewEffect->CopyTypePool( this, mappingTableTypes, mappingTableStrings ) );
- }
- else
- {
- // There's no string pool after optimizing. Let's re-create the type pool
- VH( pNewEffect->CopyOptimizedTypePool( this, mappingTableTypes ) );
- }
-
- // fixup this effect's variable's types
- VH( pNewEffect->OptimizeTypes(&mappingTableTypes, true) );
- VH( pNewEffect->RecreateCBs() );
-
-
- for (uint32_t i = 0; i < pNewEffect->m_pMemberInterfaces.GetSize(); ++ i)
- {
- SMember* pMember = pNewEffect->m_pMemberInterfaces[i];
- VH( pNewEffect->FixupMemberInterface( pMember, this, mappingTableStrings ) );
- }
-
-
-lExit:
- SAFE_DELETE( pTempHeap );
- if( FAILED( hr ) )
- {
- SAFE_DELETE( pNewEffect );
- }
- *ppClonedEffect = pNewEffect;
- return hr;
-}
-
-// Move all type pointers using pMappingTable.
-// This is called after creating the optimized type pool or during cloning.
-HRESULT CEffect::OptimizeTypes(_Inout_ CPointerMappingTable *pMappingTable, _In_ bool Cloning)
-{
- HRESULT hr = S_OK;
-
- // find all child types, point them to the new location
- for (size_t i = 0; i < m_VariableCount; ++ i)
- {
- VH( RemapType((SType**)&m_pVariables[i].pType, pMappingTable) );
- }
-
- uint32_t Members = m_pMemberInterfaces.GetSize();
- for( size_t i=0; i < Members; i++ )
- {
- if( m_pMemberInterfaces[i] != nullptr )
- {
- VH( RemapType((SType**)&m_pMemberInterfaces[i]->pType, pMappingTable) );
- }
- }
-
- // when cloning, there may be annotations
- if( Cloning )
- {
- for (size_t iVar = 0; iVar < m_VariableCount; ++ iVar)
- {
- for(size_t i = 0; i < m_pVariables[iVar].AnnotationCount; ++ i )
- {
- VH( RemapType((SType**)&m_pVariables[iVar].pAnnotations[i].pType, pMappingTable) );
- }
- }
- for (size_t iCB = 0; iCB < m_CBCount; ++ iCB)
- {
- for(size_t i = 0; i < m_pCBs[iCB].AnnotationCount; ++ i )
- {
- VH( RemapType((SType**)&m_pCBs[iCB].pAnnotations[i].pType, pMappingTable) );
- }
- }
- for (size_t iGroup = 0; iGroup < m_GroupCount; ++ iGroup)
- {
- for(size_t i = 0; i < m_pGroups[iGroup].AnnotationCount; ++ i )
- {
- VH( RemapType((SType**)&m_pGroups[iGroup].pAnnotations[i].pType, pMappingTable) );
- }
- for(size_t iTech = 0; iTech < m_pGroups[iGroup].TechniqueCount; ++ iTech )
- {
- for(size_t i = 0; i < m_pGroups[iGroup].pTechniques[iTech].AnnotationCount; ++ i )
- {
- VH( RemapType((SType**)&m_pGroups[iGroup].pTechniques[iTech].pAnnotations[i].pType, pMappingTable) );
- }
- for(size_t iPass = 0; iPass < m_pGroups[iGroup].pTechniques[iTech].PassCount; ++ iPass )
- {
- for(size_t i = 0; i < m_pGroups[iGroup].pTechniques[iTech].pPasses[iPass].AnnotationCount; ++ i )
- {
- VH( RemapType((SType**)&m_pGroups[iGroup].pTechniques[iTech].pPasses[iPass].pAnnotations[i].pType, pMappingTable) );
- }
- }
- }
- }
- }
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// Public API to shed this effect of its reflection data
-
-HRESULT CEffect::Optimize()
-{
- HRESULT hr = S_OK;
- CEffectHeap *pOptimizedTypeHeap = nullptr;
-
- if (IsOptimized())
- {
- DPF(0, "ID3DX11Effect::Optimize: Effect has already been Optimize()'ed");
- return S_OK;
- }
-
- // Delete annotations, names, semantics, and string data on variables
-
- for (size_t i = 0; i < m_VariableCount; ++ i)
- {
- m_pVariables[i].AnnotationCount = 0;
- m_pVariables[i].pAnnotations = nullptr;
- m_pVariables[i].pName = nullptr;
- m_pVariables[i].pSemantic = nullptr;
-
- // 2) Point string variables to nullptr
- if (m_pVariables[i].pType->IsObjectType(EOT_String))
- {
- assert(nullptr != m_pVariables[i].Data.pString);
- m_pVariables[i].Data.pString = nullptr;
- }
- }
-
- // Delete annotations and names on CBs
-
- for (size_t i = 0; i < m_CBCount; ++ i)
- {
- m_pCBs[i].AnnotationCount = 0;
- m_pCBs[i].pAnnotations = nullptr;
- m_pCBs[i].pName = nullptr;
- m_pCBs[i].IsEffectOptimized = true;
- }
-
- // Delete annotations and names on techniques and passes
-
- for (size_t i = 0; i < m_GroupCount; ++ i)
- {
- m_pGroups[i].AnnotationCount = 0;
- m_pGroups[i].pAnnotations = nullptr;
- m_pGroups[i].pName = nullptr;
-
- for (size_t j = 0; j < m_pGroups[i].TechniqueCount; ++ j)
- {
- m_pGroups[i].pTechniques[j].AnnotationCount = 0;
- m_pGroups[i].pTechniques[j].pAnnotations = nullptr;
- m_pGroups[i].pTechniques[j].pName = nullptr;
-
- for (size_t k = 0; k < m_pGroups[i].pTechniques[j].PassCount; ++ k)
- {
- m_pGroups[i].pTechniques[j].pPasses[k].AnnotationCount = 0;
- m_pGroups[i].pTechniques[j].pPasses[k].pAnnotations = nullptr;
- m_pGroups[i].pTechniques[j].pPasses[k].pName = nullptr;
- }
- }
- };
-
- // 2) Remove shader bytecode & stream out decls
- // (all are contained within pReflectionData)
-
- for (size_t i = 0; i < m_ShaderBlockCount; ++ i)
- {
- if( m_pShaderBlocks[i].pReflectionData )
- {
- // pReflection was not created with PRIVATENEW
- SAFE_RELEASE( m_pShaderBlocks[i].pReflectionData->pReflection );
-
- m_pShaderBlocks[i].pReflectionData = nullptr;
- }
- }
-
- uint32_t Members = m_pMemberInterfaces.GetSize();
- for( size_t i=0; i < Members; i++ )
- {
- assert( m_pMemberInterfaces[i] != nullptr );
- if( IsReflectionData(m_pMemberInterfaces[i]->pTopLevelEntity) )
- {
- assert( IsReflectionData(m_pMemberInterfaces[i]->Data.pGeneric) );
-
- // This is checked when cloning (so we don't clone Optimized-out member variables)
- m_pMemberInterfaces[i] = nullptr;
- }
- else
- {
- m_pMemberInterfaces[i]->pName = nullptr;
- m_pMemberInterfaces[i]->pSemantic = nullptr;
- }
- }
-
-
-
- // get rid of the name/type hash tables and string data,
- // then reallocate the type data and fix up this effect
- CPointerMappingTable mappingTable;
- CTypeHashTable::CIterator typeIter;
- CPointerMappingTable::CIterator mapIter;
- CCheckedDword chkSpaceNeeded = 0;
- uint32_t spaceNeeded;
-
- // first pass: compute needed space
- for (m_pTypePool->GetFirstEntry(&typeIter); !m_pTypePool->PastEnd(&typeIter); m_pTypePool->GetNextEntry(&typeIter))
- {
- SType *pType = typeIter.GetData();
-
- chkSpaceNeeded += AlignToPowerOf2(sizeof(SType), c_DataAlignment);
-
- // if this is a struct, allocate room for its members
- if (EVT_Struct == pType->VarType)
- {
- chkSpaceNeeded += AlignToPowerOf2(pType->StructType.Members * sizeof(SVariable), c_DataAlignment);
- }
- }
-
- VH( chkSpaceNeeded.GetValue(&spaceNeeded) );
-
- assert(nullptr == m_pOptimizedTypeHeap);
- VN( pOptimizedTypeHeap = new CEffectHeap );
- VH( pOptimizedTypeHeap->ReserveMemory(spaceNeeded));
-
- // use the private heap that we're about to destroy as scratch space for the mapping table
- mappingTable.SetPrivateHeap(m_pPooledHeap);
- VH( mappingTable.AutoGrow() );
-
- // second pass: move types over, build mapping table
- for (m_pTypePool->GetFirstEntry(&typeIter); !m_pTypePool->PastEnd(&typeIter); m_pTypePool->GetNextEntry(&typeIter))
- {
- SPointerMapping ptrMapping;
- SType *pType;
-
- ptrMapping.pOld = ptrMapping.pNew = typeIter.GetData();
- VH( pOptimizedTypeHeap->MoveData(&ptrMapping.pNew, sizeof(SType)) );
-
- pType = (SType *) ptrMapping.pNew;
-
- // if this is a struct, move its members to the newly allocated space
- if (EVT_Struct == pType->VarType)
- {
- VH( pOptimizedTypeHeap->MoveData((void **)&pType->StructType.pMembers, pType->StructType.Members * sizeof(SVariable)) );
- }
-
- VH( mappingTable.AddValueWithHash(ptrMapping, ptrMapping.Hash()) );
- }
-
- // third pass: fixup structure member & name pointers
- for (mappingTable.GetFirstEntry(&mapIter); !mappingTable.PastEnd(&mapIter); mappingTable.GetNextEntry(&mapIter))
- {
- SPointerMapping ptrMapping = mapIter.GetData();
- SType *pType = (SType *) ptrMapping.pNew;
-
- pType->pTypeName = nullptr;
-
- // if this is a struct, fix up its members' pointers
- if (EVT_Struct == pType->VarType)
- {
- for (size_t i = 0; i < pType->StructType.Members; ++ i)
- {
- VH( RemapType((SType**)&pType->StructType.pMembers[i].pType, &mappingTable) );
- pType->StructType.pMembers[i].pName = nullptr;
- pType->StructType.pMembers[i].pSemantic = nullptr;
- }
- }
- }
-
- // fixup this effect's variable's types
- VH( OptimizeTypes(&mappingTable) );
-
- m_pOptimizedTypeHeap = pOptimizedTypeHeap;
- pOptimizedTypeHeap = nullptr;
-
-#ifdef D3DX11_FX_PRINT_HASH_STATS
- DPF(0, "Compiler string pool hash table statistics:");
- m_pTypePool->PrintHashTableStats();
- DPF(0, "Compiler type pool hash table statistics:");
- m_pStringPool->PrintHashTableStats();
-#endif // D3DX11_FX_PRINT_HASH_STATS
-
- SAFE_DELETE(m_pTypePool);
- SAFE_DELETE(m_pStringPool);
- SAFE_DELETE(m_pPooledHeap);
-
- DPF(0, "ID3DX11Effect::Optimize: %u bytes of reflection data freed.", m_pReflection->m_Heap.GetSize());
- SAFE_DELETE(m_pReflection);
- m_Flags |= D3DX11_EFFECT_OPTIMIZED;
-
-lExit:
- SAFE_DELETE(pOptimizedTypeHeap);
- return hr;
-}
-
-SMember * CreateNewMember(_In_ SType *pType, _In_ bool IsAnnotation)
-{
- switch (pType->VarType)
- {
- case EVT_Struct:
- if (IsAnnotation)
- {
- assert(sizeof(SNumericAnnotationMember) == sizeof(SMember));
- return (SMember*) new SNumericAnnotationMember;
- }
- else if (pType->StructType.ImplementsInterface)
- {
- assert(sizeof(SClassInstanceGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SClassInstanceGlobalVariableMember;
- }
- else
- {
- assert(sizeof(SNumericGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SNumericGlobalVariableMember;
- }
- break;
- case EVT_Interface:
- assert(sizeof(SInterfaceGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SInterfaceGlobalVariableMember;
- break;
- case EVT_Object:
- switch (pType->ObjectType)
- {
- case EOT_String:
- if (IsAnnotation)
- {
- assert(sizeof(SStringAnnotationMember) == sizeof(SMember));
- return (SMember*) new SStringAnnotationMember;
- }
- else
- {
- assert(sizeof(SStringGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SStringGlobalVariableMember;
- }
-
- break;
- case EOT_Texture:
- case EOT_Texture1D:
- case EOT_Texture1DArray:
- case EOT_Texture2D:
- case EOT_Texture2DArray:
- case EOT_Texture2DMS:
- case EOT_Texture2DMSArray:
- case EOT_Texture3D:
- case EOT_TextureCube:
- case EOT_TextureCubeArray:
- case EOT_Buffer:
- case EOT_ByteAddressBuffer:
- case EOT_StructuredBuffer:
- assert(!IsAnnotation);
- assert(sizeof(SShaderResourceGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SShaderResourceGlobalVariableMember;
- break;
- case EOT_RWTexture1D:
- case EOT_RWTexture1DArray:
- case EOT_RWTexture2D:
- case EOT_RWTexture2DArray:
- case EOT_RWTexture3D:
- case EOT_RWBuffer:
- case EOT_RWByteAddressBuffer:
- case EOT_RWStructuredBuffer:
- case EOT_RWStructuredBufferAlloc:
- case EOT_RWStructuredBufferConsume:
- case EOT_AppendStructuredBuffer:
- case EOT_ConsumeStructuredBuffer:
- assert(!IsAnnotation);
- assert(sizeof(SUnorderedAccessViewGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SUnorderedAccessViewGlobalVariableMember;
- break;
- case EOT_VertexShader:
- case EOT_VertexShader5:
- case EOT_GeometryShader:
- case EOT_GeometryShaderSO:
- case EOT_GeometryShader5:
- case EOT_PixelShader:
- case EOT_PixelShader5:
- case EOT_HullShader5:
- case EOT_DomainShader5:
- case EOT_ComputeShader5:
- assert(!IsAnnotation);
- assert(sizeof(SShaderGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SShaderGlobalVariableMember;
- break;
- case EOT_Blend:
- assert(!IsAnnotation);
- assert(sizeof(SBlendGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SBlendGlobalVariableMember;
- break;
- case EOT_Rasterizer:
- assert(!IsAnnotation);
- assert(sizeof(SRasterizerGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SRasterizerGlobalVariableMember;
- break;
- case EOT_DepthStencil:
- assert(!IsAnnotation);
- assert(sizeof(SDepthStencilGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SDepthStencilGlobalVariableMember;
- break;
- case EOT_Sampler:
- assert(!IsAnnotation);
- assert(sizeof(SSamplerGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SSamplerGlobalVariableMember;
- break;
- case EOT_DepthStencilView:
- assert(!IsAnnotation);
- assert(sizeof(SDepthStencilViewGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SDepthStencilViewGlobalVariableMember;
- break;
- case EOT_RenderTargetView:
- assert(!IsAnnotation);
- assert(sizeof(SRenderTargetViewGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SRenderTargetViewGlobalVariableMember;
- break;
- default:
- assert(0);
- DPF( 0, "Internal error: invalid object type." );
- return nullptr;
- break;
- }
- break;
- case EVT_Numeric:
- switch (pType->NumericType.NumericLayout)
- {
- case ENL_Matrix:
- if (IsAnnotation)
- {
- assert(sizeof(SMatrixAnnotationMember) == sizeof(SMember));
- return (SMember*) new SMatrixAnnotationMember;
- }
- else
- {
- assert(sizeof(SMatrixGlobalVariableMember) == sizeof(SMember));
- assert(sizeof(SMatrix4x4ColumnMajorGlobalVariableMember) == sizeof(SMember));
- assert(sizeof(SMatrix4x4RowMajorGlobalVariableMember) == sizeof(SMember));
-
- if (pType->NumericType.Rows == 4 && pType->NumericType.Columns == 4)
- {
- if (pType->NumericType.IsColumnMajor)
- {
- return (SMember*) new SMatrix4x4ColumnMajorGlobalVariableMember;
- }
- else
- {
- return (SMember*) new SMatrix4x4RowMajorGlobalVariableMember;
- }
- }
- else
- {
- return (SMember*) new SMatrixGlobalVariableMember;
- }
- }
- break;
- case ENL_Vector:
- switch (pType->NumericType.ScalarType)
- {
- case EST_Float:
- if (IsAnnotation)
- {
- assert(sizeof(SFloatVectorAnnotationMember) == sizeof(SMember));
- return (SMember*) new SFloatVectorAnnotationMember;
- }
- else
- {
- assert(sizeof(SFloatVectorGlobalVariableMember) == sizeof(SMember));
- assert(sizeof(SFloatVector4GlobalVariableMember) == sizeof(SMember));
-
- if (pType->NumericType.Columns == 4)
- {
- return (SMember*) new SFloatVector4GlobalVariableMember;
- }
- else
- {
- return (SMember*) new SFloatVectorGlobalVariableMember;
- }
- }
- break;
- case EST_Bool:
- if (IsAnnotation)
- {
- assert(sizeof(SBoolVectorAnnotationMember) == sizeof(SMember));
- return (SMember*) new SBoolVectorAnnotationMember;
- }
- else
- {
- assert(sizeof(SBoolVectorGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SBoolVectorGlobalVariableMember;
- }
- break;
- case EST_UInt:
- case EST_Int:
- if (IsAnnotation)
- {
- assert(sizeof(SIntVectorAnnotationMember) == sizeof(SMember));
- return (SMember*) new SIntVectorAnnotationMember;
- }
- else
- {
- assert(sizeof(SIntVectorGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SIntVectorGlobalVariableMember;
- }
- break;
- default:
- assert(0);
- DPF( 0, "Internal loading error: invalid vector type." );
- break;
- }
- break;
- case ENL_Scalar:
- switch (pType->NumericType.ScalarType)
- {
- case EST_Float:
- if (IsAnnotation)
- {
- assert(sizeof(SFloatScalarAnnotationMember) == sizeof(SMember));
- return (SMember*) new SFloatScalarAnnotationMember;
- }
- else
- {
- assert(sizeof(SFloatScalarGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SFloatScalarGlobalVariableMember;
- }
- break;
- case EST_UInt:
- case EST_Int:
- if (IsAnnotation)
- {
- assert(sizeof(SIntScalarAnnotationMember) == sizeof(SMember));
- return (SMember*) new SIntScalarAnnotationMember;
- }
- else
- {
- assert(sizeof(SIntScalarGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SIntScalarGlobalVariableMember;
- }
- break;
- case EST_Bool:
- if (IsAnnotation)
- {
- assert(sizeof(SBoolScalarAnnotationMember) == sizeof(SMember));
- return (SMember*) new SBoolScalarAnnotationMember;
- }
- else
- {
- assert(sizeof(SBoolScalarGlobalVariableMember) == sizeof(SMember));
- return (SMember*) new SBoolScalarGlobalVariableMember;
- }
- break;
- default:
- DPF( 0, "Internal loading error: invalid scalar type." );
- assert(0);
- break;
- }
- break;
- default:
- assert(0);
- DPF( 0, "Internal loading error: invalid numeric type." );
- break;
- }
- break;
- default:
- assert(0);
- DPF( 0, "Internal loading error: invalid variable type." );
- break;
- }
- return nullptr;
-}
-
-// Global variables are created in place because storage for them was allocated during LoadEffect
-HRESULT PlacementNewVariable(_In_ void *pVar, _In_ SType *pType, _In_ bool IsAnnotation)
-{
- switch (pType->VarType)
- {
- case EVT_Struct:
- if (IsAnnotation)
- {
- assert(sizeof(SNumericAnnotation) == sizeof(SAnnotation));
- new(pVar) SNumericAnnotation();
- }
- else if (pType->StructType.ImplementsInterface)
- {
- assert(sizeof(SClassInstanceGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SClassInstanceGlobalVariable;
- }
- else
- {
- assert(sizeof(SNumericGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SNumericGlobalVariable;
- }
- break;
- case EVT_Interface:
- assert(sizeof(SInterfaceGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SInterfaceGlobalVariable;
- break;
- case EVT_Object:
- switch (pType->ObjectType)
- {
- case EOT_String:
- if (IsAnnotation)
- {
- assert(sizeof(SStringAnnotation) == sizeof(SAnnotation));
- new(pVar) SStringAnnotation;
- }
- else
- {
- assert(sizeof(SStringGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SStringGlobalVariable;
- }
-
- break;
- case EOT_Texture:
- case EOT_Texture1D:
- case EOT_Texture1DArray:
- case EOT_Texture2D:
- case EOT_Texture2DArray:
- case EOT_Texture2DMS:
- case EOT_Texture2DMSArray:
- case EOT_Texture3D:
- case EOT_TextureCube:
- case EOT_TextureCubeArray:
- case EOT_Buffer:
- case EOT_ByteAddressBuffer:
- case EOT_StructuredBuffer:
- assert(!IsAnnotation);
- assert(sizeof(SShaderResourceGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SShaderResourceGlobalVariable;
- break;
- case EOT_RWTexture1D:
- case EOT_RWTexture1DArray:
- case EOT_RWTexture2D:
- case EOT_RWTexture2DArray:
- case EOT_RWTexture3D:
- case EOT_RWBuffer:
- case EOT_RWByteAddressBuffer:
- case EOT_RWStructuredBuffer:
- case EOT_RWStructuredBufferAlloc:
- case EOT_RWStructuredBufferConsume:
- case EOT_AppendStructuredBuffer:
- case EOT_ConsumeStructuredBuffer:
- assert(!IsAnnotation);
- assert(sizeof(SUnorderedAccessViewGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SUnorderedAccessViewGlobalVariable;
- break;
- case EOT_VertexShader:
- case EOT_VertexShader5:
- case EOT_GeometryShader:
- case EOT_GeometryShaderSO:
- case EOT_GeometryShader5:
- case EOT_PixelShader:
- case EOT_PixelShader5:
- case EOT_HullShader5:
- case EOT_DomainShader5:
- case EOT_ComputeShader5:
- assert(!IsAnnotation);
- assert(sizeof(SShaderGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SShaderGlobalVariable;
- break;
- case EOT_Blend:
- assert(!IsAnnotation);
- assert(sizeof(SBlendGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SBlendGlobalVariable;
- break;
- case EOT_Rasterizer:
- assert(!IsAnnotation);
- assert(sizeof(SRasterizerGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SRasterizerGlobalVariable;
- break;
- case EOT_DepthStencil:
- assert(!IsAnnotation);
- assert(sizeof(SDepthStencilGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SDepthStencilGlobalVariable;
- break;
- case EOT_Sampler:
- assert(!IsAnnotation);
- assert(sizeof(SSamplerGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SSamplerGlobalVariable;
- break;
- case EOT_RenderTargetView:
- assert(!IsAnnotation);
- assert(sizeof(SRenderTargetViewGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SRenderTargetViewGlobalVariable;
- break;
- case EOT_DepthStencilView:
- assert(!IsAnnotation);
- assert(sizeof(SDepthStencilViewGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SDepthStencilViewGlobalVariable;
- break;
- default:
- assert(0);
- DPF( 0, "Internal loading error: invalid object type." );
- return E_FAIL;
- break;
- }
- break;
- case EVT_Numeric:
- switch (pType->NumericType.NumericLayout)
- {
- case ENL_Matrix:
- if (IsAnnotation)
- {
- assert(sizeof(SMatrixAnnotation) == sizeof(SAnnotation));
- new(pVar) SMatrixAnnotation;
- }
- else
- {
- assert(sizeof(SMatrixGlobalVariable) == sizeof(SGlobalVariable));
- assert(sizeof(SMatrix4x4ColumnMajorGlobalVariable) == sizeof(SGlobalVariable));
- assert(sizeof(SMatrix4x4RowMajorGlobalVariable) == sizeof(SGlobalVariable));
-
- if (pType->NumericType.Rows == 4 && pType->NumericType.Columns == 4)
- {
- if (pType->NumericType.IsColumnMajor)
- {
- new(pVar) SMatrix4x4ColumnMajorGlobalVariable;
- }
- else
- {
- new(pVar) SMatrix4x4RowMajorGlobalVariable;
- }
- }
- else
- {
- new(pVar) SMatrixGlobalVariable;
- }
- }
- break;
- case ENL_Vector:
- switch (pType->NumericType.ScalarType)
- {
- case EST_Float:
- if (IsAnnotation)
- {
- assert(sizeof(SFloatVectorAnnotation) == sizeof(SAnnotation));
- new(pVar) SFloatVectorAnnotation;
- }
- else
- {
- assert(sizeof(SFloatVectorGlobalVariable) == sizeof(SGlobalVariable));
- assert(sizeof(SFloatVector4GlobalVariable) == sizeof(SGlobalVariable));
-
- if (pType->NumericType.Columns == 4)
- {
- new(pVar) SFloatVector4GlobalVariable;
- }
- else
- {
- new(pVar) SFloatVectorGlobalVariable;
- }
- }
- break;
- case EST_Bool:
- if (IsAnnotation)
- {
- assert(sizeof(SBoolVectorAnnotation) == sizeof(SAnnotation));
- new(pVar) SBoolVectorAnnotation;
- }
- else
- {
- assert(sizeof(SBoolVectorGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SBoolVectorGlobalVariable;
- }
- break;
- case EST_UInt:
- case EST_Int:
- if (IsAnnotation)
- {
- assert(sizeof(SIntVectorAnnotation) == sizeof(SAnnotation));
- new(pVar) SIntVectorAnnotation;
- }
- else
- {
- assert(sizeof(SIntVectorGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SIntVectorGlobalVariable;
- }
- break;
- }
- break;
- case ENL_Scalar:
- switch (pType->NumericType.ScalarType)
- {
- case EST_Float:
- if (IsAnnotation)
- {
- assert(sizeof(SFloatScalarAnnotation) == sizeof(SAnnotation));
- new(pVar) SFloatScalarAnnotation;
- }
- else
- {
- assert(sizeof(SFloatScalarGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SFloatScalarGlobalVariable;
- }
- break;
- case EST_UInt:
- case EST_Int:
- if (IsAnnotation)
- {
- assert(sizeof(SIntScalarAnnotation) == sizeof(SAnnotation));
- new(pVar) SIntScalarAnnotation;
- }
- else
- {
- assert(sizeof(SIntScalarGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SIntScalarGlobalVariable;
- }
- break;
- case EST_Bool:
- if (IsAnnotation)
- {
- assert(sizeof(SBoolScalarAnnotation) == sizeof(SAnnotation));
- new(pVar) SBoolScalarAnnotation;
- }
- else
- {
- assert(sizeof(SBoolScalarGlobalVariable) == sizeof(SGlobalVariable));
- new(pVar) SBoolScalarGlobalVariable;
- }
- break;
- default:
- assert(0);
- DPF( 0, "Internal loading error: invalid scalar type." );
- return E_FAIL;
- break;
- }
- break;
- default:
- assert(0);
- DPF( 0, "Internal loading error: invalid numeric type." );
- return E_FAIL;
- break;
- }
- break;
- default:
- assert(0);
- DPF( 0, "Internal loading error: invalid variable type." );
- return E_FAIL;
- break;
- }
- return S_OK;
-}
-
-}
-
-#endif
+++ /dev/null
-#ifdef FX11
-
-//--------------------------------------------------------------------------------------
-// File: EffectReflection.cpp
-//
-// Direct3D 11 Effects public reflection APIs
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#include "pchfx.h"
-
-namespace D3DX11Effects
-{
-
-SEffectInvalidType g_InvalidType;
-
-SEffectInvalidScalarVariable g_InvalidScalarVariable;
-SEffectInvalidVectorVariable g_InvalidVectorVariable;
-SEffectInvalidMatrixVariable g_InvalidMatrixVariable;
-SEffectInvalidStringVariable g_InvalidStringVariable;
-SEffectInvalidClassInstanceVariable g_InvalidClassInstanceVariable;
-SEffectInvalidInterfaceVariable g_InvalidInterfaceVariable;
-SEffectInvalidShaderResourceVariable g_InvalidShaderResourceVariable;
-SEffectInvalidUnorderedAccessViewVariable g_InvalidUnorderedAccessViewVariable;
-SEffectInvalidRenderTargetViewVariable g_InvalidRenderTargetViewVariable;
-SEffectInvalidDepthStencilViewVariable g_InvalidDepthStencilViewVariable;
-SEffectInvalidConstantBuffer g_InvalidConstantBuffer;
-SEffectInvalidShaderVariable g_InvalidShaderVariable;
-SEffectInvalidBlendVariable g_InvalidBlendVariable;
-SEffectInvalidDepthStencilVariable g_InvalidDepthStencilVariable;
-SEffectInvalidRasterizerVariable g_InvalidRasterizerVariable;
-SEffectInvalidSamplerVariable g_InvalidSamplerVariable;
-
-SEffectInvalidPass g_InvalidPass;
-SEffectInvalidTechnique g_InvalidTechnique;
-SEffectInvalidGroup g_InvalidGroup;
-
-
-//////////////////////////////////////////////////////////////////////////
-// Helper routine implementations
-//////////////////////////////////////////////////////////////////////////
-
-ID3DX11EffectConstantBuffer * NoParentCB()
-{
- DPF(0, "ID3DX11EffectVariable::GetParentConstantBuffer: Variable does not have a parent constant buffer");
- // have to typecast because the type of g_InvalidScalarVariable has not been declared yet
- return &g_InvalidConstantBuffer;
-}
-
-_Use_decl_annotations_
-ID3DX11EffectVariable * GetAnnotationByIndexHelper(const char *pClassName, uint32_t Index, uint32_t AnnotationCount, SAnnotation *pAnnotations)
-{
- if (Index >= AnnotationCount)
- {
- DPF(0, "%s::GetAnnotationByIndex: Invalid index (%u, total: %u)", pClassName, Index, AnnotationCount);
- return &g_InvalidScalarVariable;
- }
-
- return pAnnotations + Index;
-}
-
-_Use_decl_annotations_
-ID3DX11EffectVariable * GetAnnotationByNameHelper(const char *pClassName, LPCSTR Name, uint32_t AnnotationCount, SAnnotation *pAnnotations)
-{
- uint32_t i;
- for (i = 0; i < AnnotationCount; ++ i)
- {
- if (strcmp(pAnnotations[i].pName, Name) == 0)
- {
- return pAnnotations + i;
- }
- }
-
- DPF(0, "%s::GetAnnotationByName: Annotation [%s] not found", pClassName, Name);
- return &g_InvalidScalarVariable;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// Effect routines to pool interfaces
-//////////////////////////////////////////////////////////////////////////
-
-ID3DX11EffectType * CEffect::CreatePooledSingleElementTypeInterface(_In_ SType *pType)
-{
- if (IsOptimized())
- {
- DPF(0, "ID3DX11Effect: Cannot create new type interfaces since the effect has been Optimize()'ed");
- return &g_InvalidType;
- }
-
- for (size_t i = 0; i < m_pTypeInterfaces.GetSize(); ++ i)
- {
- if (m_pTypeInterfaces[i]->pType == pType)
- {
- return (SSingleElementType*)m_pTypeInterfaces[i];
- }
- }
- SSingleElementType *pNewType;
- if (nullptr == (pNewType = new SSingleElementType))
- {
- DPF(0, "ID3DX11Effect: Out of memory while trying to create new type interface");
- return &g_InvalidType;
- }
-
- pNewType->pType = pType;
- m_pTypeInterfaces.Add(pNewType);
-
- return pNewType;
-}
-
-// Create a member variable (via GetMemberBy* or GetElement)
-_Use_decl_annotations_
-ID3DX11EffectVariable * CEffect::CreatePooledVariableMemberInterface(TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity,
- const SVariable *pMember,
- const UDataPointer Data, bool IsSingleElement, uint32_t Index)
-{
- bool IsAnnotation;
-
- if (IsOptimized())
- {
- DPF(0, "ID3DX11Effect: Cannot create new variable interfaces since the effect has been Optimize()'ed");
- return &g_InvalidScalarVariable;
- }
-
- for (size_t i = 0; i < m_pMemberInterfaces.GetSize(); ++ i)
- {
- if (m_pMemberInterfaces[i]->pType == pMember->pType &&
- m_pMemberInterfaces[i]->pName == pMember->pName &&
- m_pMemberInterfaces[i]->pSemantic == pMember->pSemantic &&
- m_pMemberInterfaces[i]->Data.pGeneric == Data.pGeneric &&
- m_pMemberInterfaces[i]->IsSingleElement == (uint32_t)IsSingleElement &&
- ((SMember*)m_pMemberInterfaces[i])->pTopLevelEntity == pTopLevelEntity)
- {
- return (ID3DX11EffectVariable *) m_pMemberInterfaces[i];
- }
- }
-
- // is this annotation or runtime data?
- if( pTopLevelEntity->pEffect->IsReflectionData(pTopLevelEntity) )
- {
- assert( pTopLevelEntity->pEffect->IsReflectionData(Data.pGeneric) );
- IsAnnotation = true;
- }
- else
- {
- // if the heap is empty, we are still loading the Effect, and thus creating a member for a variable initializer
- // ex. Interface myInt = myClassArray[2];
- if( pTopLevelEntity->pEffect->m_Heap.GetSize() > 0 )
- {
- assert( pTopLevelEntity->pEffect->IsRuntimeData(pTopLevelEntity) );
- if (!pTopLevelEntity->pType->IsObjectType(EOT_String))
- {
- // strings are funny; their data is reflection data, so ignore those
- assert( pTopLevelEntity->pEffect->IsRuntimeData(Data.pGeneric) );
- }
- }
- IsAnnotation = false;
- }
-
- SMember *pNewMember;
-
- if (nullptr == (pNewMember = CreateNewMember((SType*)pMember->pType, IsAnnotation)))
- {
- DPF(0, "ID3DX11Effect: Out of memory while trying to create new member variable interface");
- return &g_InvalidScalarVariable;
- }
-
- pNewMember->pType = pMember->pType;
- pNewMember->pName = pMember->pName;
- pNewMember->pSemantic = pMember->pSemantic;
- pNewMember->Data.pGeneric = Data.pGeneric;
- pNewMember->IsSingleElement = IsSingleElement;
- pNewMember->pTopLevelEntity = pTopLevelEntity;
-
- if( IsSingleElement && pMember->pMemberData )
- {
- assert( !IsAnnotation );
- // This is an element of a global variable array
- pNewMember->pMemberData = pMember->pMemberData + Index;
- }
-
- if (FAILED(m_pMemberInterfaces.Add(pNewMember)))
- {
- SAFE_DELETE(pNewMember);
- DPF(0, "ID3DX11Effect: Out of memory while trying to create new member variable interface");
- return &g_InvalidScalarVariable;
- }
-
- return (ID3DX11EffectVariable *) pNewMember;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectType (SType, SSingleElementType implementations)
-//////////////////////////////////////////////////////////////////////////
-
-static ID3DX11EffectType * GetTypeByIndexHelper(uint32_t Index, uint32_t VariableCount,
- SVariable *pVariables, uint32_t SizeOfVariableType)
-{
- static LPCSTR pFuncName = "ID3DX11EffectType::GetMemberTypeByIndex";
-
- if (Index >= VariableCount)
- {
- DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, VariableCount);
- return &g_InvalidType;
- }
-
- SVariable *pVariable = (SVariable *)((uint8_t *)pVariables + Index * SizeOfVariableType);
- if (nullptr == pVariable->pName)
- {
- DPF(0, "%s: Cannot get member types; Effect has been Optimize()'ed", pFuncName);
- return &g_InvalidType;
- }
-
- return (ID3DX11EffectType *) pVariable->pType;
-}
-
-static ID3DX11EffectType * GetTypeByNameHelper(LPCSTR Name, uint32_t VariableCount,
- SVariable *pVariables, uint32_t SizeOfVariableType)
-{
- static LPCSTR pFuncName = "ID3DX11EffectType::GetMemberTypeByName";
-
- if (nullptr == Name)
- {
- DPF(0, "%s: Parameter Name was nullptr.", pFuncName);
- return &g_InvalidType;
- }
-
- uint32_t i;
- SVariable *pVariable;
-
- for (i = 0; i < VariableCount; ++ i)
- {
- pVariable = (SVariable *)((uint8_t *)pVariables + i * SizeOfVariableType);
- if (nullptr == pVariable->pName)
- {
- DPF(0, "%s: Cannot get member types; Effect has been Optimize()'ed", pFuncName);
- return &g_InvalidType;
- }
- if (strcmp(pVariable->pName, Name) == 0)
- {
- return (ID3DX11EffectType *) pVariable->pType;
- }
- }
-
- DPF(0, "%s: Member type [%s] not found", pFuncName, Name);
- return &g_InvalidType;
-}
-
-
-static ID3DX11EffectType * GetTypeBySemanticHelper(LPCSTR Semantic, uint32_t VariableCount,
- SVariable *pVariables, uint32_t SizeOfVariableType)
-{
- static LPCSTR pFuncName = "ID3DX11EffectType::GetMemberTypeBySemantic";
-
- if (nullptr == Semantic)
- {
- DPF(0, "%s: Parameter Semantic was nullptr.", pFuncName);
- return &g_InvalidType;
- }
-
- uint32_t i;
- SVariable *pVariable;
-
- for (i = 0; i < VariableCount; ++ i)
- {
- pVariable = (SVariable *)((uint8_t *)pVariables + i * SizeOfVariableType);
- if (nullptr == pVariable->pName)
- {
- DPF(0, "%s: Cannot get member types; Effect has been Optimize()'ed", pFuncName);
- return &g_InvalidType;
- }
- if (nullptr != pVariable->pSemantic &&
- _stricmp(pVariable->pSemantic, Semantic) == 0)
- {
- return (ID3DX11EffectType *) pVariable->pType;
- }
- }
-
- DPF(0, "%s: Member type with semantic [%s] not found", pFuncName, Semantic);
- return &g_InvalidType;
-}
-
-ID3DX11EffectType * SType::GetMemberTypeByIndex(_In_ uint32_t Index)
-{
- if (VarType != EVT_Struct)
- {
- DPF(0, "ID3DX11EffectType::GetMemberTypeByIndex: This interface does not refer to a structure");
- return &g_InvalidType;
- }
-
- return GetTypeByIndexHelper(Index, StructType.Members, StructType.pMembers, sizeof(SVariable));
-}
-
-ID3DX11EffectType * SType::GetMemberTypeByName(_In_z_ LPCSTR Name)
-{
- if (VarType != EVT_Struct)
- {
- DPF(0, "ID3DX11EffectType::GetMemberTypeByName: This interface does not refer to a structure");
- return &g_InvalidType;
- }
-
- return GetTypeByNameHelper(Name, StructType.Members, StructType.pMembers, sizeof(SVariable));
-}
-
-ID3DX11EffectType * SType::GetMemberTypeBySemantic(_In_z_ LPCSTR Semantic)
-{
- if (VarType != EVT_Struct)
- {
- DPF(0, "ID3DX11EffectType::GetMemberTypeBySemantic: This interface does not refer to a structure");
- return &g_InvalidType;
- }
-
- return GetTypeBySemanticHelper(Semantic, StructType.Members, StructType.pMembers, sizeof(SVariable));
-}
-
-LPCSTR SType::GetMemberName(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectType::GetMemberName";
-
- if (VarType != EVT_Struct)
- {
- DPF(0, "%s: This interface does not refer to a structure", pFuncName);
- return nullptr;
- }
-
- if (Index >= StructType.Members)
- {
- DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, StructType.Members);
- return nullptr;
- }
-
- SVariable *pVariable = StructType.pMembers + Index;
-
- if (nullptr == pVariable->pName)
- {
- DPF(0, "%s: Cannot get member names; Effect has been Optimize()'ed", pFuncName);
- return nullptr;
- }
-
- return pVariable->pName;
-}
-
-LPCSTR SType::GetMemberSemantic(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectType::GetMemberSemantic";
-
- if (VarType != EVT_Struct)
- {
- DPF(0, "%s: This interface does not refer to a structure", pFuncName);
- return nullptr;
- }
-
- if (Index >= StructType.Members)
- {
- DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, StructType.Members);
- return nullptr;
- }
-
- SVariable *pVariable = StructType.pMembers + Index;
-
- if (nullptr == pVariable->pName)
- {
- DPF(0, "%s: Cannot get member semantics; Effect has been Optimize()'ed", pFuncName);
- return nullptr;
- }
-
- return pVariable->pSemantic;
-}
-
-HRESULT SType::GetDescHelper(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc, _In_ bool IsSingleElement) const
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectType::GetDesc";
-
- VERIFYPARAMETER(pDesc);
-
- pDesc->TypeName = pTypeName;
-
- // intentionally return 0 so they know it's not a single element array
- pDesc->Elements = IsSingleElement ? 0 : Elements;
- pDesc->PackedSize = GetTotalPackedSize(IsSingleElement);
- pDesc->UnpackedSize = GetTotalUnpackedSize(IsSingleElement);
- pDesc->Stride = Stride;
-
- switch (VarType)
- {
- case EVT_Numeric:
- switch (NumericType.NumericLayout)
- {
- case ENL_Matrix:
- if (NumericType.IsColumnMajor)
- {
- pDesc->Class = D3D_SVC_MATRIX_COLUMNS;
- }
- else
- {
- pDesc->Class = D3D_SVC_MATRIX_ROWS;
- }
- break;
- case ENL_Vector:
- pDesc->Class = D3D_SVC_VECTOR;
- break;
- case ENL_Scalar:
- pDesc->Class = D3D_SVC_SCALAR;
- break;
- default:
- assert(0);
- }
-
- switch (NumericType.ScalarType)
- {
- case EST_Bool:
- pDesc->Type = D3D_SVT_BOOL;
- break;
- case EST_Int:
- pDesc->Type = D3D_SVT_INT;
- break;
- case EST_UInt:
- pDesc->Type = D3D_SVT_UINT;
- break;
- case EST_Float:
- pDesc->Type = D3D_SVT_FLOAT;
- break;
- default:
- assert(0);
- }
-
- pDesc->Rows = NumericType.Rows;
- pDesc->Columns = NumericType.Columns;
- pDesc->Members = 0;
-
- break;
-
- case EVT_Struct:
- pDesc->Rows = 0;
- pDesc->Columns = 0;
- pDesc->Members = StructType.Members;
- if( StructType.ImplementsInterface )
- {
- pDesc->Class = D3D_SVC_INTERFACE_CLASS;
- }
- else
- {
- pDesc->Class = D3D_SVC_STRUCT;
- }
- pDesc->Type = D3D_SVT_VOID;
- break;
-
- case EVT_Interface:
- pDesc->Rows = 0;
- pDesc->Columns = 0;
- pDesc->Members = 0;
- pDesc->Class = D3D_SVC_INTERFACE_POINTER;
- pDesc->Type = D3D_SVT_INTERFACE_POINTER;
- break;
-
- case EVT_Object:
- pDesc->Rows = 0;
- pDesc->Columns = 0;
- pDesc->Members = 0;
- pDesc->Class = D3D_SVC_OBJECT;
-
- switch (ObjectType)
- {
- case EOT_String:
- pDesc->Type = D3D_SVT_STRING;
- break;
- case EOT_Blend:
- pDesc->Type = D3D_SVT_BLEND;
- break;
- case EOT_DepthStencil:
- pDesc->Type = D3D_SVT_DEPTHSTENCIL;
- break;
- case EOT_Rasterizer:
- pDesc->Type = D3D_SVT_RASTERIZER;
- break;
- case EOT_PixelShader:
- case EOT_PixelShader5:
- pDesc->Type = D3D_SVT_PIXELSHADER;
- break;
- case EOT_VertexShader:
- case EOT_VertexShader5:
- pDesc->Type = D3D_SVT_VERTEXSHADER;
- break;
- case EOT_GeometryShader:
- case EOT_GeometryShaderSO:
- case EOT_GeometryShader5:
- pDesc->Type = D3D_SVT_GEOMETRYSHADER;
- break;
- case EOT_HullShader5:
- pDesc->Type = D3D_SVT_HULLSHADER;
- break;
- case EOT_DomainShader5:
- pDesc->Type = D3D_SVT_DOMAINSHADER;
- break;
- case EOT_ComputeShader5:
- pDesc->Type = D3D_SVT_COMPUTESHADER;
- break;
- case EOT_Texture:
- pDesc->Type = D3D_SVT_TEXTURE;
- break;
- case EOT_Texture1D:
- pDesc->Type = D3D_SVT_TEXTURE1D;
- break;
- case EOT_Texture1DArray:
- pDesc->Type = D3D_SVT_TEXTURE1DARRAY;
- break;
- case EOT_Texture2D:
- pDesc->Type = D3D_SVT_TEXTURE2D;
- break;
- case EOT_Texture2DArray:
- pDesc->Type = D3D_SVT_TEXTURE2DARRAY;
- break;
- case EOT_Texture2DMS:
- pDesc->Type = D3D_SVT_TEXTURE2DMS;
- break;
- case EOT_Texture2DMSArray:
- pDesc->Type = D3D_SVT_TEXTURE2DMSARRAY;
- break;
- case EOT_Texture3D:
- pDesc->Type = D3D_SVT_TEXTURE3D;
- break;
- case EOT_TextureCube:
- pDesc->Type = D3D_SVT_TEXTURECUBE;
- break;
- case EOT_TextureCubeArray:
- pDesc->Type = D3D_SVT_TEXTURECUBEARRAY;
- break;
- case EOT_Buffer:
- pDesc->Type = D3D_SVT_BUFFER;
- break;
- case EOT_Sampler:
- pDesc->Type = D3D_SVT_SAMPLER;
- break;
- case EOT_RenderTargetView:
- pDesc->Type = D3D_SVT_RENDERTARGETVIEW;
- break;
- case EOT_DepthStencilView:
- pDesc->Type = D3D_SVT_DEPTHSTENCILVIEW;
- break;
- case EOT_RWTexture1D:
- pDesc->Type = D3D_SVT_RWTEXTURE1D;
- break;
- case EOT_RWTexture1DArray:
- pDesc->Type = D3D_SVT_RWTEXTURE1DARRAY;
- break;
- case EOT_RWTexture2D:
- pDesc->Type = D3D_SVT_RWTEXTURE2D;
- break;
- case EOT_RWTexture2DArray:
- pDesc->Type = D3D_SVT_RWTEXTURE2DARRAY;
- break;
- case EOT_RWTexture3D:
- pDesc->Type = D3D_SVT_RWTEXTURE3D;
- break;
- case EOT_RWBuffer:
- pDesc->Type = D3D_SVT_RWBUFFER;
- break;
- case EOT_ByteAddressBuffer:
- pDesc->Type = D3D_SVT_BYTEADDRESS_BUFFER;
- break;
- case EOT_RWByteAddressBuffer:
- pDesc->Type = D3D_SVT_RWBYTEADDRESS_BUFFER;
- break;
- case EOT_StructuredBuffer:
- pDesc->Type = D3D_SVT_STRUCTURED_BUFFER;
- break;
- case EOT_RWStructuredBuffer:
- case EOT_RWStructuredBufferAlloc:
- case EOT_RWStructuredBufferConsume:
- pDesc->Type = D3D_SVT_RWSTRUCTURED_BUFFER;
- break;
- case EOT_AppendStructuredBuffer:
- pDesc->Type = D3D_SVT_APPEND_STRUCTURED_BUFFER;
- break;
- case EOT_ConsumeStructuredBuffer:
- pDesc->Type = D3D_SVT_CONSUME_STRUCTURED_BUFFER;
- break;
-
- default:
- assert(0);
- }
- break;
-
- default:
- assert(0);
- }
-
-lExit:
- return hr;
-
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectShaderVariable (SAnonymousShader implementation)
-////////////////////////////////////////////////////////////////////////////////
-
-SAnonymousShader::SAnonymousShader(_In_opt_ SShaderBlock *pBlock) noexcept :
- pShaderBlock(pBlock)
-{
-}
-
-bool SAnonymousShader::IsValid()
-{
- return pShaderBlock && pShaderBlock->IsValid;
-}
-
-ID3DX11EffectType * SAnonymousShader::GetType()
-{
- return (ID3DX11EffectType *) this;
-}
-
-HRESULT SAnonymousShader::GetDesc(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc)
-{
- pDesc->Annotations = 0;
- pDesc->Flags = 0;
-
- pDesc->Name = "$Anonymous";
- pDesc->Semantic = nullptr;
- pDesc->BufferOffset = 0;
-
- return S_OK;
-}
-
-ID3DX11EffectVariable * SAnonymousShader::GetAnnotationByIndex(_In_ uint32_t Index)
-{
- UNREFERENCED_PARAMETER(Index);
- DPF(0, "ID3DX11EffectVariable::GetAnnotationByIndex: Anonymous shaders cannot have annotations");
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectVariable * SAnonymousShader::GetAnnotationByName(_In_z_ LPCSTR Name)
-{
- UNREFERENCED_PARAMETER(Name);
- DPF(0, "ID3DX11EffectVariable::GetAnnotationByName: Anonymous shaders cannot have annotations");
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectVariable * SAnonymousShader::GetMemberByIndex(_In_ uint32_t Index)
-{
- UNREFERENCED_PARAMETER(Index);
- DPF(0, "ID3DX11EffectVariable::GetMemberByIndex: Variable is not a structure");
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectVariable * SAnonymousShader::GetMemberByName(_In_z_ LPCSTR Name)
-{
- UNREFERENCED_PARAMETER(Name);
- DPF(0, "ID3DX11EffectVariable::GetMemberByName: Variable is not a structure");
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectVariable * SAnonymousShader::GetMemberBySemantic(_In_z_ LPCSTR Semantic)
-{
- UNREFERENCED_PARAMETER(Semantic);
- DPF(0, "ID3DX11EffectVariable::GetMemberBySemantic: Variable is not a structure");
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectVariable * SAnonymousShader::GetElement(_In_ uint32_t Index)
-{
- UNREFERENCED_PARAMETER(Index);
- DPF(0, "ID3DX11EffectVariable::GetElement: Anonymous shaders cannot have elements");
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectConstantBuffer * SAnonymousShader::GetParentConstantBuffer()
-{
- return NoParentCB();
-}
-
-ID3DX11EffectShaderVariable * SAnonymousShader::AsShader()
-{
- return (ID3DX11EffectShaderVariable *) this;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::SetRawValue(const void *pData, uint32_t Offset, uint32_t Count)
-{
- UNREFERENCED_PARAMETER(pData);
- UNREFERENCED_PARAMETER(Offset);
- UNREFERENCED_PARAMETER(Count);
- return ObjectSetRawValue();
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetRawValue(void *pData, uint32_t Offset, uint32_t Count)
-{
- UNREFERENCED_PARAMETER(pData);
- UNREFERENCED_PARAMETER(Offset);
- UNREFERENCED_PARAMETER(Count);
- return ObjectGetRawValue();
-}
-
-#define ANONYMOUS_SHADER_INDEX_CHECK() \
- HRESULT hr = S_OK; \
- if (0 != ShaderIndex) \
- { \
- DPF(0, "%s: Invalid index specified", pFuncName); \
- VH(E_INVALIDARG); \
- } \
-
-HRESULT SAnonymousShader::GetShaderDesc(_In_ uint32_t ShaderIndex, _Out_ D3DX11_EFFECT_SHADER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetShaderDesc";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- hr = pShaderBlock->GetShaderDesc(pDesc, true);
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetVertexShader(uint32_t ShaderIndex, ID3D11VertexShader **ppVS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetVertexShader";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetVertexShader(ppVS) );
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetGeometryShader(uint32_t ShaderIndex, ID3D11GeometryShader **ppGS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetGeometryShader";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetGeometryShader(ppGS) );
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetPixelShader(uint32_t ShaderIndex, ID3D11PixelShader **ppPS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetPixelShader";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetPixelShader(ppPS) );
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetHullShader(uint32_t ShaderIndex, ID3D11HullShader **ppHS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetHullShader";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetHullShader(ppHS) );
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetDomainShader(uint32_t ShaderIndex, ID3D11DomainShader **ppDS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetDomainShader";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetDomainShader(ppDS) );
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetComputeShader(uint32_t ShaderIndex, ID3D11ComputeShader **ppCS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetComputeShader";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetComputeShader(ppCS) );
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetInputSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetInputSignatureElementDesc";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetSignatureElementDesc(SShaderBlock::ST_Input, Element, pDesc) );
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetOutputSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetOutputSignatureElementDesc";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetSignatureElementDesc(SShaderBlock::ST_Output, Element, pDesc) );
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SAnonymousShader::GetPatchConstantSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetPatchConstantSignatureElementDesc";
-
- ANONYMOUS_SHADER_INDEX_CHECK();
-
- VH( pShaderBlock->GetSignatureElementDesc(SShaderBlock::ST_PatchConstant, Element, pDesc) );
-
-lExit:
- return hr;
-}
-
-HRESULT SAnonymousShader::GetDesc(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc)
-{
- pDesc->Class = D3D_SVC_OBJECT;
-
- switch (pShaderBlock->GetShaderType())
- {
- case EOT_VertexShader:
- case EOT_VertexShader5:
- pDesc->TypeName = "vertexshader";
- pDesc->Type = D3D_SVT_VERTEXSHADER;
- break;
- case EOT_GeometryShader:
- case EOT_GeometryShader5:
- pDesc->TypeName = "geometryshader";
- pDesc->Type = D3D_SVT_GEOMETRYSHADER;
- break;
- case EOT_PixelShader:
- case EOT_PixelShader5:
- pDesc->TypeName = "pixelshader";
- pDesc->Type = D3D_SVT_PIXELSHADER;
- break;
- case EOT_HullShader5:
- pDesc->TypeName = "Hullshader";
- pDesc->Type = D3D_SVT_HULLSHADER;
- break;
- case EOT_DomainShader5:
- pDesc->TypeName = "Domainshader";
- pDesc->Type = D3D_SVT_DOMAINSHADER;
- break;
- case EOT_ComputeShader5:
- pDesc->TypeName = "Computeshader";
- pDesc->Type = D3D_SVT_COMPUTESHADER;
- break;
- }
-
- pDesc->Elements = 0;
- pDesc->Members = 0;
- pDesc->Rows = 0;
- pDesc->Columns = 0;
- pDesc->PackedSize = 0;
- pDesc->UnpackedSize = 0;
- pDesc->Stride = 0;
-
- return S_OK;
-}
-
-ID3DX11EffectType * SAnonymousShader::GetMemberTypeByIndex(_In_ uint32_t Index)
-{
- UNREFERENCED_PARAMETER(Index);
- DPF(0, "ID3DX11EffectType::GetMemberTypeByIndex: This interface does not refer to a structure");
- return &g_InvalidType;
-}
-
-ID3DX11EffectType * SAnonymousShader::GetMemberTypeByName(_In_z_ LPCSTR Name)
-{
- UNREFERENCED_PARAMETER(Name);
- DPF(0, "ID3DX11EffectType::GetMemberTypeByName: This interface does not refer to a structure");
- return &g_InvalidType;
-}
-
-ID3DX11EffectType * SAnonymousShader::GetMemberTypeBySemantic(_In_z_ LPCSTR Semantic)
-{
- UNREFERENCED_PARAMETER(Semantic);
- DPF(0, "ID3DX11EffectType::GetMemberTypeBySemantic: This interface does not refer to a structure");
- return &g_InvalidType;
-}
-
-LPCSTR SAnonymousShader::GetMemberName(_In_ uint32_t Index)
-{
- UNREFERENCED_PARAMETER(Index);
- DPF(0, "ID3DX11EffectType::GetMemberName: This interface does not refer to a structure");
- return nullptr;
-}
-
-LPCSTR SAnonymousShader::GetMemberSemantic(_In_ uint32_t Index)
-{
- UNREFERENCED_PARAMETER(Index);
- DPF(0, "ID3DX11EffectType::GetMemberSemantic: This interface does not refer to a structure");
- return nullptr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectConstantBuffer (SConstantBuffer implementation)
-//////////////////////////////////////////////////////////////////////////
-
-bool SConstantBuffer::IsValid()
-{
- return true;
-}
-
-ID3DX11EffectType * SConstantBuffer::GetType()
-{
- return (ID3DX11EffectType *) this;
-}
-
-HRESULT SConstantBuffer::GetDesc(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc)
-{
- pDesc->Annotations = AnnotationCount;
- pDesc->Flags = 0;
-
- pDesc->Name = pName;
- pDesc->Semantic = nullptr;
- pDesc->BufferOffset = 0;
-
- if (ExplicitBindPoint != -1)
- {
- pDesc->ExplicitBindPoint = ExplicitBindPoint;
- pDesc->Flags |= D3DX11_EFFECT_VARIABLE_EXPLICIT_BIND_POINT;
- }
- else
- {
- pDesc->ExplicitBindPoint = 0;
- }
-
- return S_OK;
-}
-
-ID3DX11EffectVariable * SConstantBuffer::GetAnnotationByIndex(_In_ uint32_t Index)
-{
- return GetAnnotationByIndexHelper("ID3DX11EffectVariable", Index, AnnotationCount, pAnnotations);
-}
-
-ID3DX11EffectVariable * SConstantBuffer::GetAnnotationByName(_In_z_ LPCSTR Name)
-{
- return GetAnnotationByNameHelper("ID3DX11EffectVariable", Name, AnnotationCount, pAnnotations);
-}
-
-ID3DX11EffectVariable * SConstantBuffer::GetMemberByIndex(_In_ uint32_t Index)
-{
- SGlobalVariable *pMember;
- UDataPointer dataPtr;
-
- if (IsEffectOptimized)
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberByIndex: Cannot get members; effect has been Optimize()'ed");
- return &g_InvalidScalarVariable;
- }
-
- if (!GetVariableByIndexHelper<SGlobalVariable>(Index, VariableCount, (SGlobalVariable*)pVariables,
- nullptr, &pMember, &dataPtr.pGeneric))
- {
- return &g_InvalidScalarVariable;
- }
-
- return (ID3DX11EffectVariable *) pMember;
-}
-
-ID3DX11EffectVariable * SConstantBuffer::GetMemberByName(_In_z_ LPCSTR Name)
-{
- SGlobalVariable *pMember;
- UDataPointer dataPtr;
- uint32_t index;
-
- if (IsEffectOptimized)
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberByName: Cannot get members; effect has been Optimize()'ed");
- return &g_InvalidScalarVariable;
- }
-
- if (!GetVariableByNameHelper<SGlobalVariable>(Name, VariableCount, (SGlobalVariable*)pVariables,
- nullptr, &pMember, &dataPtr.pGeneric, &index))
- {
- return &g_InvalidScalarVariable;
- }
-
- return (ID3DX11EffectVariable *) pMember;
-}
-
-ID3DX11EffectVariable * SConstantBuffer::GetMemberBySemantic(_In_z_ LPCSTR Semantic)
-{
- SGlobalVariable *pMember;
- UDataPointer dataPtr;
- uint32_t index;
-
- if (IsEffectOptimized)
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberBySemantic: Cannot get members; effect has been Optimize()'ed");
- return &g_InvalidScalarVariable;
- }
-
- if (!GetVariableBySemanticHelper<SGlobalVariable>(Semantic, VariableCount, (SGlobalVariable*)pVariables,
- nullptr, &pMember, &dataPtr.pGeneric, &index))
- {
- return &g_InvalidScalarVariable;
- }
-
- return (ID3DX11EffectVariable *) pMember;
-}
-
-ID3DX11EffectVariable * SConstantBuffer::GetElement(_In_ uint32_t Index)
-{
- UNREFERENCED_PARAMETER(Index);
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetElement";
- DPF(0, "%s: This interface does not refer to an array", pFuncName);
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectConstantBuffer * SConstantBuffer::GetParentConstantBuffer()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetParentConstantBuffer";
- DPF(0, "%s: Constant buffers do not have parent constant buffers", pFuncName);
- return &g_InvalidConstantBuffer;
-}
-
-ID3DX11EffectConstantBuffer * SConstantBuffer::AsConstantBuffer()
-{
- return (ID3DX11EffectConstantBuffer *) this;
-}
-
-HRESULT SConstantBuffer::GetDesc(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc)
-{
- pDesc->TypeName = IsTBuffer ? "tbuffer" : "cbuffer";
- pDesc->Class = D3D_SVC_OBJECT;
- pDesc->Type = IsTBuffer ? D3D_SVT_TBUFFER : D3D_SVT_CBUFFER;
-
- pDesc->Elements = 0;
- pDesc->Members = VariableCount;
- pDesc->Rows = 0;
- pDesc->Columns = 0;
-
- uint32_t i;
- pDesc->PackedSize = 0;
- for (i = 0; i < VariableCount; ++ i)
- {
- pDesc->PackedSize += pVariables[i].pType->PackedSize;
- }
-
- pDesc->UnpackedSize = Size;
- assert(pDesc->UnpackedSize >= pDesc->PackedSize);
-
- pDesc->Stride = AlignToPowerOf2(pDesc->UnpackedSize, SType::c_RegisterSize);
-
- return S_OK;
-}
-
-ID3DX11EffectType * SConstantBuffer::GetMemberTypeByIndex(_In_ uint32_t Index)
-{
- return GetTypeByIndexHelper(Index, VariableCount, pVariables, sizeof (SGlobalVariable));
-}
-
-ID3DX11EffectType * SConstantBuffer::GetMemberTypeByName(_In_z_ LPCSTR Name)
-{
- return GetTypeByNameHelper(Name, VariableCount, pVariables, sizeof (SGlobalVariable));
-}
-
-ID3DX11EffectType * SConstantBuffer::GetMemberTypeBySemantic(_In_z_ LPCSTR Semantic)
-{
- return GetTypeBySemanticHelper(Semantic, VariableCount, pVariables, sizeof (SGlobalVariable));
-}
-
-LPCSTR SConstantBuffer::GetMemberName(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectType::GetMemberName";
-
- if (IsEffectOptimized)
- {
- DPF(0, "%s: Cannot get member names; Effect has been Optimize()'ed", pFuncName);
- return nullptr;
- }
-
- if (Index >= VariableCount)
- {
- DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, VariableCount);
- return nullptr;
- }
-
- return pVariables[Index].pName;
-}
-
-LPCSTR SConstantBuffer::GetMemberSemantic(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectType::GetMemberSemantic";
-
- if (IsEffectOptimized)
- {
- DPF(0, "%s: Cannot get member semantics; Effect has been Optimize()'ed", pFuncName);
- return nullptr;
- }
-
- if (Index >= VariableCount)
- {
- DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, VariableCount);
- return nullptr;
- }
-
- return pVariables[Index].pSemantic;
-}
-
-_Use_decl_annotations_
-HRESULT SConstantBuffer::SetRawValue(const void *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectVariable::SetRawValue";
-
- VERIFYPARAMETER(pData);
-
- if ((Offset + Count < Offset) ||
- (Count + (uint8_t*)pData < (uint8_t*)pData) ||
- ((Offset + Count) > Size))
- {
- // overflow of some kind
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- if (IsUsedByExpression)
- {
- uint32_t i;
- for (i = 0; i < VariableCount; ++ i)
- {
- ((SGlobalVariable*)pVariables)[i].DirtyVariable();
- }
- }
- else
- {
- IsDirty = true;
- }
-
- memcpy(pBackingStore + Offset, pData, Count);
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-HRESULT SConstantBuffer::GetRawValue(void *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetRawValue";
-
- VERIFYPARAMETER(pData);
-
- if ((Offset + Count < Offset) ||
- (Count + (uint8_t*)pData < (uint8_t*)pData) ||
- ((Offset + Count) > Size))
- {
- // overflow of some kind
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- memcpy(pData, pBackingStore + Offset, Count);
-
-lExit:
- return hr;
-}
-
-bool SConstantBuffer::ClonedSingle() const
-{
- return IsSingle && ( pEffect->m_Flags & D3DX11_EFFECT_CLONE );
-}
-
-HRESULT SConstantBuffer::SetConstantBuffer(_In_ ID3D11Buffer *pConstantBuffer)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::SetConstantBuffer";
-
- if (IsTBuffer)
- {
- DPF(0, "%s: This is a texture buffer; use SetTextureBuffer instead", pFuncName);
- VH(D3DERR_INVALIDCALL);
- }
-
- // Replace all references to the old shader block with this one
- pEffect->ReplaceCBReference(this, pConstantBuffer);
-
- if( !IsUserManaged )
- {
- // Save original cbuffer in case we UndoSet
- assert( pMemberData[0].Type == MDT_Buffer );
- VB( pMemberData[0].Data.pD3DEffectsManagedConstantBuffer == nullptr );
- pMemberData[0].Data.pD3DEffectsManagedConstantBuffer = pD3DObject;
- pD3DObject = nullptr;
- IsUserManaged = true;
- IsNonUpdatable = true;
- }
-
- SAFE_ADDREF( pConstantBuffer );
- SAFE_RELEASE( pD3DObject );
- pD3DObject = pConstantBuffer;
-
-lExit:
- return hr;
-}
-
-HRESULT SConstantBuffer::GetConstantBuffer(_Outptr_ ID3D11Buffer **ppConstantBuffer)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::GetConstantBuffer";
-
- VERIFYPARAMETER(ppConstantBuffer);
-
- if (IsTBuffer)
- {
- DPF(0, "%s: This is a texture buffer; use GetTextureBuffer instead", pFuncName);
- VH(D3DERR_INVALIDCALL);
- }
-
- assert( pD3DObject );
- _Analysis_assume_( pD3DObject );
- *ppConstantBuffer = pD3DObject;
- SAFE_ADDREF(*ppConstantBuffer);
-
-lExit:
- return hr;
-}
-
-HRESULT SConstantBuffer::UndoSetConstantBuffer()
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::UndoSetConstantBuffer";
-
- if (IsTBuffer)
- {
- DPF(0, "%s: This is a texture buffer; use UndoSetTextureBuffer instead", pFuncName);
- VH(D3DERR_INVALIDCALL);
- }
-
- if( !IsUserManaged )
- {
- return S_FALSE;
- }
-
- // Replace all references to the old shader block with this one
- pEffect->ReplaceCBReference(this, pMemberData[0].Data.pD3DEffectsManagedConstantBuffer);
-
- // Revert to original cbuffer
- SAFE_RELEASE( pD3DObject );
- pD3DObject = pMemberData[0].Data.pD3DEffectsManagedConstantBuffer;
- pMemberData[0].Data.pD3DEffectsManagedConstantBuffer = nullptr;
- IsUserManaged = false;
- IsNonUpdatable = ClonedSingle();
-
-lExit:
- return hr;
-}
-
-HRESULT SConstantBuffer::SetTextureBuffer(_In_ ID3D11ShaderResourceView *pTextureBuffer)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::SetTextureBuffer";
-
- if (!IsTBuffer)
- {
- DPF(0, "%s: This is a constant buffer; use SetConstantBuffer instead", pFuncName);
- VH(D3DERR_INVALIDCALL);
- }
-
- if( !IsUserManaged )
- {
- // Save original cbuffer and tbuffer in case we UndoSet
- assert( pMemberData[0].Type == MDT_Buffer );
- VB( pMemberData[0].Data.pD3DEffectsManagedConstantBuffer == nullptr );
- pMemberData[0].Data.pD3DEffectsManagedConstantBuffer = pD3DObject;
- pD3DObject = nullptr;
- assert( pMemberData[1].Type == MDT_ShaderResourceView );
- VB( pMemberData[1].Data.pD3DEffectsManagedTextureBuffer == nullptr );
- pMemberData[1].Data.pD3DEffectsManagedTextureBuffer = TBuffer.pShaderResource;
- TBuffer.pShaderResource = nullptr;
- IsUserManaged = true;
- IsNonUpdatable = true;
- }
-
- SAFE_ADDREF( pTextureBuffer );
- SAFE_RELEASE(pD3DObject); // won't be needing this anymore...
- SAFE_RELEASE( TBuffer.pShaderResource );
- TBuffer.pShaderResource = pTextureBuffer;
-
-lExit:
- return hr;
-}
-
-HRESULT SConstantBuffer::GetTextureBuffer(_Outptr_ ID3D11ShaderResourceView **ppTextureBuffer)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::GetTextureBuffer";
-
- VERIFYPARAMETER(ppTextureBuffer);
-
- if (!IsTBuffer)
- {
- DPF(0, "%s: This is a constant buffer; use GetConstantBuffer instead", pFuncName);
- VH(D3DERR_INVALIDCALL);
- }
-
- assert( TBuffer.pShaderResource );
- _Analysis_assume_( TBuffer.pShaderResource );
- *ppTextureBuffer = TBuffer.pShaderResource;
- SAFE_ADDREF(*ppTextureBuffer);
-
-lExit:
- return hr;
-}
-
-HRESULT SConstantBuffer::UndoSetTextureBuffer()
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectConstantBuffer::UndoSetTextureBuffer";
-
- if (!IsTBuffer)
- {
- DPF(0, "%s: This is a texture buffer; use UndoSetConstantBuffer instead", pFuncName);
- VH(D3DERR_INVALIDCALL);
- }
-
- if( !IsUserManaged )
- {
- return S_FALSE;
- }
-
- // Revert to original cbuffer
- SAFE_RELEASE( pD3DObject );
- pD3DObject = pMemberData[0].Data.pD3DEffectsManagedConstantBuffer;
- pMemberData[0].Data.pD3DEffectsManagedConstantBuffer = nullptr;
- SAFE_RELEASE( TBuffer.pShaderResource );
- TBuffer.pShaderResource = pMemberData[1].Data.pD3DEffectsManagedTextureBuffer;
- pMemberData[1].Data.pD3DEffectsManagedTextureBuffer = nullptr;
- IsUserManaged = false;
- IsNonUpdatable = ClonedSingle();
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectPass (CEffectPass implementation)
-//////////////////////////////////////////////////////////////////////////
-
-bool SPassBlock::IsValid()
-{
- if( HasDependencies )
- return pEffect->ValidatePassBlock( this );
- return InitiallyValid;
-}
-
-HRESULT SPassBlock::GetDesc(_Out_ D3DX11_PASS_DESC *pDesc)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectPass::GetDesc";
-
- VERIFYPARAMETER(pDesc);
-
- ZeroMemory(pDesc, sizeof(*pDesc));
-
- pDesc->Name = pName;
- pDesc->Annotations = AnnotationCount;
-
- SAssignment *pAssignment;
- SAssignment *pLastAssn;
-
- pEffect->IncrementTimer();
-
- pAssignment = pAssignments;
- pLastAssn = pAssignments + AssignmentCount;
-
- for(; pAssignment < pLastAssn; pAssignment++)
- {
- pEffect->EvaluateAssignment(pAssignment);
- }
-
- if( BackingStore.pVertexShaderBlock && BackingStore.pVertexShaderBlock->pInputSignatureBlob )
- {
- // pInputSignatureBlob can be null if we're setting a nullptr VS "SetVertexShader( nullptr )"
- pDesc->pIAInputSignature = (uint8_t*)BackingStore.pVertexShaderBlock->pInputSignatureBlob->GetBufferPointer();
- pDesc->IAInputSignatureSize = BackingStore.pVertexShaderBlock->pInputSignatureBlob->GetBufferSize();
- }
-
- pDesc->StencilRef = BackingStore.StencilRef;
- pDesc->SampleMask = BackingStore.SampleMask;
- pDesc->BlendFactor[0] = BackingStore.BlendFactor[0];
- pDesc->BlendFactor[1] = BackingStore.BlendFactor[1];
- pDesc->BlendFactor[2] = BackingStore.BlendFactor[2];
- pDesc->BlendFactor[3] = BackingStore.BlendFactor[3];
-
-lExit:
- return hr;
-}
-
-extern SShaderBlock g_NullVS;
-extern SShaderBlock g_NullGS;
-extern SShaderBlock g_NullPS;
-extern SShaderBlock g_NullHS;
-extern SShaderBlock g_NullDS;
-extern SShaderBlock g_NullCS;
-
-SAnonymousShader g_AnonymousNullVS(&g_NullVS);
-SAnonymousShader g_AnonymousNullGS(&g_NullGS);
-SAnonymousShader g_AnonymousNullPS(&g_NullPS);
-SAnonymousShader g_AnonymousNullHS(&g_NullHS);
-SAnonymousShader g_AnonymousNullDS(&g_NullDS);
-SAnonymousShader g_AnonymousNullCS(&g_NullCS);
-
-template<EObjectType EShaderType>
-HRESULT SPassBlock::GetShaderDescHelper(D3DX11_PASS_SHADER_DESC *pDesc)
-{
- HRESULT hr = S_OK;
- uint32_t i;
- LPCSTR pFuncName = nullptr;
- SShaderBlock *pShaderBlock = nullptr;
-
- ApplyPassAssignments();
-
- switch (EShaderType)
- {
- case EOT_VertexShader:
- case EOT_VertexShader5:
- pFuncName = "ID3DX11EffectPass::GetVertexShaderDesc";
- pShaderBlock = BackingStore.pVertexShaderBlock;
- break;
- case EOT_PixelShader:
- case EOT_PixelShader5:
- pFuncName = "ID3DX11EffectPass::GetPixelShaderDesc";
- pShaderBlock = BackingStore.pPixelShaderBlock;
- break;
- case EOT_GeometryShader:
- case EOT_GeometryShader5:
- pFuncName = "ID3DX11EffectPass::GetGeometryShaderDesc";
- pShaderBlock = BackingStore.pGeometryShaderBlock;
- break;
- case EOT_HullShader5:
-#pragma prefast(suppress:__WARNING_UNUSED_POINTER_ASSIGNMENT, "pFuncName used in DPF")
- pFuncName = "ID3DX11EffectPass::GetHullShaderDesc";
- pShaderBlock = BackingStore.pHullShaderBlock;
- break;
- case EOT_DomainShader5:
-#pragma prefast(suppress:__WARNING_UNUSED_POINTER_ASSIGNMENT, "pFuncName used in DPF")
- pFuncName = "ID3DX11EffectPass::GetDomainShaderDesc";
- pShaderBlock = BackingStore.pDomainShaderBlock;
- break;
- case EOT_ComputeShader5:
-#pragma prefast(suppress:__WARNING_UNUSED_POINTER_ASSIGNMENT, "pFuncName used in DPF")
- pFuncName = "ID3DX11EffectPass::GetComputeShaderDesc";
- pShaderBlock = BackingStore.pComputeShaderBlock;
- break;
- default:
- assert(0);
- }
-
- VERIFYPARAMETER(pDesc);
-
- // in case of error (or in case the assignment doesn't exist), return something reasonable
- pDesc->pShaderVariable = &g_InvalidShaderVariable;
- pDesc->ShaderIndex = 0;
-
- if (nullptr != pShaderBlock)
- {
- uint32_t elements, varCount, anonymousShaderCount;
- SGlobalVariable *pVariables;
- SAnonymousShader *pAnonymousShaders;
-
- if (pShaderBlock == &g_NullVS)
- {
- pDesc->pShaderVariable = &g_AnonymousNullVS;
- pDesc->ShaderIndex = 0;
- // we're done
- goto lExit;
- }
- else if (pShaderBlock == &g_NullGS)
- {
- pDesc->pShaderVariable = &g_AnonymousNullGS;
- pDesc->ShaderIndex = 0;
- // we're done
- goto lExit;
- }
- else if (pShaderBlock == &g_NullPS)
- {
- pDesc->pShaderVariable = &g_AnonymousNullPS;
- pDesc->ShaderIndex = 0;
- // we're done
- goto lExit;
- }
- else if (pShaderBlock == &g_NullHS)
- {
- pDesc->pShaderVariable = &g_AnonymousNullHS;
- pDesc->ShaderIndex = 0;
- // we're done
- goto lExit;
- }
- else if (pShaderBlock == &g_NullDS)
- {
- pDesc->pShaderVariable = &g_AnonymousNullDS;
- pDesc->ShaderIndex = 0;
- // we're done
- goto lExit;
- }
- else if (pShaderBlock == &g_NullCS)
- {
- pDesc->pShaderVariable = &g_AnonymousNullCS;
- pDesc->ShaderIndex = 0;
- // we're done
- goto lExit;
- }
- else
- {
- VB( pEffect->IsRuntimeData(pShaderBlock) );
- varCount = pEffect->m_VariableCount;
- pVariables = pEffect->m_pVariables;
- anonymousShaderCount = pEffect->m_AnonymousShaderCount;
- pAnonymousShaders = pEffect->m_pAnonymousShaders;
- }
-
- for (i = 0; i < varCount; ++ i)
- {
- elements = std::max<uint32_t>(1, pVariables[i].pType->Elements);
- // make sure the variable type matches, and don't forget about GeometryShaderSO's
- if (pVariables[i].pType->IsShader())
- {
- if (pShaderBlock >= pVariables[i].Data.pShader && pShaderBlock < pVariables[i].Data.pShader + elements)
- {
- pDesc->pShaderVariable = (ID3DX11EffectShaderVariable *)(pVariables + i);
- pDesc->ShaderIndex = (uint32_t)(UINT_PTR)(pShaderBlock - pVariables[i].Data.pShader);
- // we're done
- goto lExit;
- }
- }
- }
-
- for (i = 0; i < anonymousShaderCount; ++ i)
- {
- if (pShaderBlock == pAnonymousShaders[i].pShaderBlock)
- {
- VB(EShaderType == pAnonymousShaders[i].pShaderBlock->GetShaderType())
- pDesc->pShaderVariable = (pAnonymousShaders + i);
- pDesc->ShaderIndex = 0;
- // we're done
- goto lExit;
- }
- }
-
- DPF(0, "%s: Internal error; shader not found", pFuncName);
- VH( E_FAIL );
- }
-
-lExit:
- return hr;
-}
-
-HRESULT SPassBlock::GetVertexShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC *pDesc)
-{
- return GetShaderDescHelper<EOT_VertexShader>(pDesc);
-}
-
-HRESULT SPassBlock::GetPixelShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC *pDesc)
-{
- return GetShaderDescHelper<EOT_PixelShader>(pDesc);
-}
-
-HRESULT SPassBlock::GetGeometryShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC *pDesc)
-{
- return GetShaderDescHelper<EOT_GeometryShader>(pDesc);
-}
-
-HRESULT SPassBlock::GetHullShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC *pDesc)
-{
- return GetShaderDescHelper<EOT_HullShader5>(pDesc);
-}
-
-HRESULT SPassBlock::GetDomainShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC *pDesc)
-{
- return GetShaderDescHelper<EOT_DomainShader5>(pDesc);
-}
-
-HRESULT SPassBlock::GetComputeShaderDesc(_Out_ D3DX11_PASS_SHADER_DESC *pDesc)
-{
- return GetShaderDescHelper<EOT_ComputeShader5>(pDesc);
-}
-
-ID3DX11EffectVariable * SPassBlock::GetAnnotationByIndex(_In_ uint32_t Index)
-{
- return GetAnnotationByIndexHelper("ID3DX11EffectPass", Index, AnnotationCount, pAnnotations);
-}
-
-ID3DX11EffectVariable * SPassBlock::GetAnnotationByName(_In_z_ LPCSTR Name)
-{
- return GetAnnotationByNameHelper("ID3DX11EffectPass", Name, AnnotationCount, pAnnotations);
-}
-
-HRESULT SPassBlock::Apply(_In_ uint32_t Flags, _In_ ID3D11DeviceContext* pContext)
-
-{
- UNREFERENCED_PARAMETER(Flags);
- HRESULT hr = S_OK;
-
- // Flags are unused, so should be 0
-
-
- assert( pEffect->m_pContext == nullptr );
- pEffect->m_pContext = pContext;
- pEffect->ApplyPassBlock(this);
- pEffect->m_pContext = nullptr;
-
-lExit:
- return hr;
-}
-
-HRESULT SPassBlock::ComputeStateBlockMask(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask)
-{
- HRESULT hr = S_OK;
-
- // flags indicating whether the following shader types were caught by assignment checks or not
- bool bVS = false, bGS = false, bPS = false, bHS = false, bDS = false, bCS = false;
-
- for (size_t i = 0; i < AssignmentCount; ++ i)
- {
- bool bShader = false;
-
- switch (pAssignments[i].LhsType)
- {
- case ELHS_VertexShaderBlock:
- bVS = true;
- bShader = true;
- break;
- case ELHS_GeometryShaderBlock:
- bGS = true;
- bShader = true;
- break;
- case ELHS_PixelShaderBlock:
- bPS = true;
- bShader = true;
- break;
- case ELHS_HullShaderBlock:
- bHS = true;
- bShader = true;
- break;
- case ELHS_DomainShaderBlock:
- bDS = true;
- bShader = true;
- break;
- case ELHS_ComputeShaderBlock:
- bCS = true;
- bShader = true;
- break;
-
- case ELHS_RasterizerBlock:
- pStateBlockMask->RSRasterizerState = 1;
- break;
- case ELHS_BlendBlock:
- pStateBlockMask->OMBlendState = 1;
- break;
- case ELHS_DepthStencilBlock:
- pStateBlockMask->OMDepthStencilState = 1;
- break;
-
- default:
- // ignore this assignment (must be a scalar/vector assignment associated with a state object)
- break;
- }
-
- if (bShader)
- {
- for (size_t j = 0; j < pAssignments[i].MaxElements; ++ j)
- {
- // compute state block mask for the union of ALL shaders
- VH( pAssignments[i].Source.pShader[j].ComputeStateBlockMask(pStateBlockMask) );
- }
- }
- }
-
- // go over the state block objects in case there was no corresponding assignment
- if (nullptr != BackingStore.pRasterizerBlock)
- {
- pStateBlockMask->RSRasterizerState = 1;
- }
- if (nullptr != BackingStore.pBlendBlock)
- {
- pStateBlockMask->OMBlendState = 1;
- }
- if (nullptr != BackingStore.pDepthStencilBlock)
- {
- pStateBlockMask->OMDepthStencilState = 1;
- }
-
- // go over the shaders only if an assignment didn't already catch them
- if (false == bVS && nullptr != BackingStore.pVertexShaderBlock)
- {
- VH( BackingStore.pVertexShaderBlock->ComputeStateBlockMask(pStateBlockMask) );
- }
- if (false == bGS && nullptr != BackingStore.pGeometryShaderBlock)
- {
- VH( BackingStore.pGeometryShaderBlock->ComputeStateBlockMask(pStateBlockMask) );
- }
- if (false == bPS && nullptr != BackingStore.pPixelShaderBlock)
- {
- VH( BackingStore.pPixelShaderBlock->ComputeStateBlockMask(pStateBlockMask) );
- }
- if (false == bHS && nullptr != BackingStore.pHullShaderBlock)
- {
- VH( BackingStore.pHullShaderBlock->ComputeStateBlockMask(pStateBlockMask) );
- }
- if (false == bDS && nullptr != BackingStore.pDomainShaderBlock)
- {
- VH( BackingStore.pDomainShaderBlock->ComputeStateBlockMask(pStateBlockMask) );
- }
- if (false == bCS && nullptr != BackingStore.pComputeShaderBlock)
- {
- VH( BackingStore.pComputeShaderBlock->ComputeStateBlockMask(pStateBlockMask) );
- }
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectTechnique (STechnique implementation)
-//////////////////////////////////////////////////////////////////////////
-
-bool STechnique::IsValid()
-{
- if( HasDependencies )
- {
- for( size_t i = 0; i < PassCount; i++ )
- {
- if( !((SPassBlock*)pPasses)[i].IsValid() )
- return false;
- }
- return true;
- }
- return InitiallyValid;
-}
-
-HRESULT STechnique::GetDesc(_Out_ D3DX11_TECHNIQUE_DESC *pDesc)
-{
- HRESULT hr = S_OK;
-
- static LPCSTR pFuncName = "ID3DX11EffectTechnique::GetDesc";
-
- VERIFYPARAMETER(pDesc);
-
- pDesc->Name = pName;
- pDesc->Annotations = AnnotationCount;
- pDesc->Passes = PassCount;
-
-lExit:
- return hr;
-}
-
-ID3DX11EffectVariable * STechnique::GetAnnotationByIndex(_In_ uint32_t Index)
-{
- return GetAnnotationByIndexHelper("ID3DX11EffectTechnique", Index, AnnotationCount, pAnnotations);
-}
-
-ID3DX11EffectVariable * STechnique::GetAnnotationByName(_In_z_ LPCSTR Name)
-{
- return GetAnnotationByNameHelper("ID3DX11EffectTechnique", Name, AnnotationCount, pAnnotations);
-}
-
-ID3DX11EffectPass * STechnique::GetPassByIndex(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectTechnique::GetPassByIndex";
-
- if (Index >= PassCount)
- {
- DPF(0, "%s: Invalid pass index (%u, total: %u)", pFuncName, Index, PassCount);
- return &g_InvalidPass;
- }
-
- return (ID3DX11EffectPass *)(pPasses + Index);
-}
-
-ID3DX11EffectPass * STechnique::GetPassByName(_In_z_ LPCSTR Name)
-{
- static LPCSTR pFuncName = "ID3DX11EffectTechnique::GetPassByName";
-
- uint32_t i;
-
- for (i = 0; i < PassCount; ++ i)
- {
- if (nullptr != pPasses[i].pName &&
- strcmp(pPasses[i].pName, Name) == 0)
- {
- break;
- }
- }
-
- if (i == PassCount)
- {
- DPF(0, "%s: Pass [%s] not found", pFuncName, Name);
- return &g_InvalidPass;
- }
-
- return (ID3DX11EffectPass *)(pPasses + i);
-}
-
-HRESULT STechnique::ComputeStateBlockMask(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask)
-{
- HRESULT hr = S_OK;
- uint32_t i;
-
- _Analysis_assume_( PassCount == 0 || pPasses != 0 );
- for (i = 0; i < PassCount; ++ i)
- {
- VH( ((SPassBlock*)pPasses)[i].ComputeStateBlockMask(pStateBlockMask) );
- }
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectGroup (SGroup implementation)
-//////////////////////////////////////////////////////////////////////////
-
-bool SGroup::IsValid()
-{
- if( HasDependencies )
- {
- for( size_t i = 0; i < TechniqueCount; i++ )
- {
- if( !((STechnique*)pTechniques)[i].IsValid() )
- return false;
- }
- return true;
- }
- return InitiallyValid;
-}
-
-HRESULT SGroup::GetDesc(_Out_ D3DX11_GROUP_DESC *pDesc)
-{
- HRESULT hr = S_OK;
-
- static LPCSTR pFuncName = "ID3DX11EffectGroup::GetDesc";
-
- VERIFYPARAMETER(pDesc);
-
- pDesc->Name = pName;
- pDesc->Annotations = AnnotationCount;
- pDesc->Techniques = TechniqueCount;
-
-lExit:
- return hr;
-}
-
-ID3DX11EffectVariable * SGroup::GetAnnotationByIndex(_In_ uint32_t Index)
-{
- return GetAnnotationByIndexHelper("ID3DX11EffectGroup", Index, AnnotationCount, pAnnotations);
-}
-
-ID3DX11EffectVariable * SGroup::GetAnnotationByName(_In_z_ LPCSTR Name)
-{
- return GetAnnotationByNameHelper("ID3DX11EffectGroup", Name, AnnotationCount, pAnnotations);
-}
-
-ID3DX11EffectTechnique * SGroup::GetTechniqueByIndex(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectGroup::GetTechniqueByIndex";
-
- if (Index >= TechniqueCount)
- {
- DPF(0, "%s: Invalid pass index (%u, total: %u)", pFuncName, Index, TechniqueCount);
- return &g_InvalidTechnique;
- }
-
- return (ID3DX11EffectTechnique *)(pTechniques + Index);
-}
-
-ID3DX11EffectTechnique * SGroup::GetTechniqueByName(_In_z_ LPCSTR Name)
-{
- static LPCSTR pFuncName = "ID3DX11EffectGroup::GetTechniqueByName";
-
- uint32_t i;
-
- for (i = 0; i < TechniqueCount; ++ i)
- {
- if (nullptr != pTechniques[i].pName &&
- strcmp(pTechniques[i].pName, Name) == 0)
- {
- break;
- }
- }
-
- if (i == TechniqueCount)
- {
- DPF(0, "%s: Technique [%s] not found", pFuncName, Name);
- return &g_InvalidTechnique;
- }
-
- return (ID3DX11EffectTechnique *)(pTechniques + i);
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11Effect Public Reflection APIs (CEffect)
-//////////////////////////////////////////////////////////////////////////
-
-HRESULT CEffect::GetDevice(_Outptr_ ID3D11Device **ppDevice)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11Effect::GetDevice";
- VERIFYPARAMETER(ppDevice);
-
- m_pDevice->AddRef();
- *ppDevice = m_pDevice;
-
-lExit:
- return hr;
-}
-
-HRESULT CEffect::GetDesc(_Out_ D3DX11_EFFECT_DESC *pDesc)
-{
- HRESULT hr = S_OK;
-
- static LPCSTR pFuncName = "ID3DX11Effect::GetDesc";
-
- VERIFYPARAMETER(pDesc);
-
- pDesc->ConstantBuffers = m_CBCount;
- pDesc->GlobalVariables = m_VariableCount;
- pDesc->Techniques = m_TechniqueCount;
- pDesc->Groups = m_GroupCount;
- pDesc->InterfaceVariables = m_InterfaceCount;
-
-lExit:
- return hr;
-}
-
-ID3DX11EffectConstantBuffer * CEffect::GetConstantBufferByIndex(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetConstantBufferByIndex";
-
- if (Index < m_CBCount)
- {
- return m_pCBs + Index;
- }
-
- DPF(0, "%s: Invalid constant buffer index", pFuncName);
- return &g_InvalidConstantBuffer;
-}
-
-ID3DX11EffectConstantBuffer * CEffect::GetConstantBufferByName(_In_z_ LPCSTR Name)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetConstantBufferByName";
-
- if (IsOptimized())
- {
- DPF(0, "%s: Cannot get constant buffer interfaces by name since the effect has been Optimize()'ed", pFuncName);
- return &g_InvalidConstantBuffer;
- }
-
- if (nullptr == Name)
- {
- DPF(0, "%s: Parameter Name was nullptr.", pFuncName);
- return &g_InvalidConstantBuffer;
- }
-
- for (uint32_t i = 0; i < m_CBCount; ++ i)
- {
- if (strcmp(m_pCBs[i].pName, Name) == 0)
- {
- return m_pCBs + i;
- }
- }
-
- DPF(0, "%s: Constant Buffer [%s] not found", pFuncName, Name);
- return &g_InvalidConstantBuffer;
-}
-
-ID3DX11EffectVariable * CEffect::GetVariableByIndex(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetVariableByIndex";
-
- if (Index < m_VariableCount)
- {
- return m_pVariables + Index;
- }
-
- DPF(0, "%s: Invalid variable index", pFuncName);
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectVariable * CEffect::GetVariableByName(_In_z_ LPCSTR Name)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetVariableByName";
-
- if (IsOptimized())
- {
- DPF(0, "%s: Cannot get variable interfaces by name since the effect has been Optimize()'ed", pFuncName);
- return &g_InvalidScalarVariable;
- }
-
- if (nullptr == Name)
- {
- DPF(0, "%s: Parameter Name was nullptr.", pFuncName);
- return &g_InvalidScalarVariable;
- }
-
- for (uint32_t i = 0; i < m_VariableCount; ++ i)
- {
- if (strcmp(m_pVariables[i].pName, Name) == 0)
- {
- return m_pVariables + i;
- }
- }
-
- DPF(0, "%s: Variable [%s] not found", pFuncName, Name);
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectVariable * CEffect::GetVariableBySemantic(_In_z_ LPCSTR Semantic)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetVariableBySemantic";
-
- if (IsOptimized())
- {
- DPF(0, "%s: Cannot get variable interfaces by semantic since the effect has been Optimize()'ed", pFuncName);
- return &g_InvalidScalarVariable;
- }
-
- if (nullptr == Semantic)
- {
- DPF(0, "%s: Parameter Semantic was nullptr.", pFuncName);
- return &g_InvalidScalarVariable;
- }
-
- uint32_t i;
-
- for (i = 0; i < m_VariableCount; ++ i)
- {
- if (nullptr != m_pVariables[i].pSemantic &&
- _stricmp(m_pVariables[i].pSemantic, Semantic) == 0)
- {
- return (ID3DX11EffectVariable *)(m_pVariables + i);
- }
- }
-
- DPF(0, "%s: Variable with semantic [%s] not found", pFuncName, Semantic);
- return &g_InvalidScalarVariable;
-}
-
-ID3DX11EffectTechnique * CEffect::GetTechniqueByIndex(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetTechniqueByIndex";
-
- if( Index < m_TechniqueCount )
- {
- for( size_t i=0; i < m_GroupCount; i++ )
- {
- if( Index < m_pGroups[i].TechniqueCount )
- {
- return (ID3DX11EffectTechnique *)(m_pGroups[i].pTechniques + Index);
- }
- Index -= m_pGroups[i].TechniqueCount;
- }
- assert( false );
- }
- DPF(0, "%s: Invalid technique index (%u)", pFuncName, Index);
- return &g_InvalidTechnique;
-}
-
-ID3DX11EffectTechnique * CEffect::GetTechniqueByName(_In_z_ LPCSTR Name)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetTechniqueByName";
- const size_t MAX_GROUP_TECHNIQUE_SIZE = 256;
- char NameCopy[MAX_GROUP_TECHNIQUE_SIZE];
-
- if (IsOptimized())
- {
- DPF(0, "ID3DX11Effect::GetTechniqueByName: Cannot get technique interfaces by name since the effect has been Optimize()'ed");
- return &g_InvalidTechnique;
- }
-
- if (nullptr == Name)
- {
- DPF(0, "%s: Parameter Name was nullptr.", pFuncName);
- return &g_InvalidTechnique;
- }
-
- if( FAILED( strcpy_s( NameCopy, MAX_GROUP_TECHNIQUE_SIZE, Name ) ) )
- {
- DPF( 0, "Group|Technique name has a length greater than %zu.", MAX_GROUP_TECHNIQUE_SIZE );
- return &g_InvalidTechnique;
- }
-
- char* pDelimiter = strchr( NameCopy, '|' );
- if( pDelimiter == nullptr )
- {
- if ( m_pNullGroup == nullptr )
- {
- DPF( 0, "The effect contains no default group." );
- return &g_InvalidTechnique;
- }
-
- return m_pNullGroup->GetTechniqueByName( Name );
- }
-
- // separate group name and technique name
- *pDelimiter = 0;
-
- return GetGroupByName( NameCopy )->GetTechniqueByName( pDelimiter + 1 );
-}
-
-ID3D11ClassLinkage * CEffect::GetClassLinkage()
-{
- SAFE_ADDREF( m_pClassLinkage );
- return m_pClassLinkage;
-}
-
-ID3DX11EffectGroup * CEffect::GetGroupByIndex(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetGroupByIndex";
-
- if( Index < m_GroupCount )
- {
- return (ID3DX11EffectGroup *)(m_pGroups + Index);
- }
- DPF(0, "%s: Invalid group index (%u)", pFuncName, Index);
- return &g_InvalidGroup;
-}
-
-ID3DX11EffectGroup * CEffect::GetGroupByName(_In_z_ LPCSTR Name)
-{
- static LPCSTR pFuncName = "ID3DX11Effect::GetGroupByName";
-
- if (IsOptimized())
- {
- DPF(0, "ID3DX11Effect::GetGroupByName: Cannot get group interfaces by name since the effect has been Optimize()'ed");
- return &g_InvalidGroup;
- }
-
- if (nullptr == Name || Name[0] == 0 )
- {
- return m_pNullGroup ? (ID3DX11EffectGroup *)m_pNullGroup : &g_InvalidGroup;
- }
-
- uint32_t i = 0;
- for (; i < m_GroupCount; ++ i)
- {
- if (nullptr != m_pGroups[i].pName &&
- strcmp(m_pGroups[i].pName, Name) == 0)
- {
- break;
- }
- }
-
- if (i == m_GroupCount)
- {
- DPF(0, "%s: Group [%s] not found", pFuncName, Name);
- return &g_InvalidGroup;
- }
-
- return (ID3DX11EffectGroup *)(m_pGroups + i);
-}
-
-}
-
-#endif
+++ /dev/null
-#ifdef FX11
-
-//--------------------------------------------------------------------------------------
-// File: EffectRuntime.cpp
-//
-// Direct3D 11 Effect runtime routines (performance critical)
-// These functions are expected to be called at high frequency
-// (when applying a pass).
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#include "pchfx.h"
-
-namespace D3DX11Effects
-{
- // D3D11_KEEP_UNORDERED_ACCESS_VIEWS == (uint32_t)-1
- uint32_t g_pNegativeOnes[8] = { D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS,
- D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS,
- D3D11_KEEP_UNORDERED_ACCESS_VIEWS, D3D11_KEEP_UNORDERED_ACCESS_VIEWS };
-
-bool SBaseBlock::ApplyAssignments(CEffect *pEffect)
-{
- SAssignment *pAssignment = pAssignments;
- SAssignment *pLastAssn = pAssignments + AssignmentCount;
- bool bRecreate = false;
-
- for(; pAssignment < pLastAssn; pAssignment++)
- {
- bRecreate |= pEffect->EvaluateAssignment(pAssignment);
- }
-
- return bRecreate;
-}
-
-void SPassBlock::ApplyPassAssignments()
-{
- SAssignment *pAssignment = pAssignments;
- SAssignment *pLastAssn = pAssignments + AssignmentCount;
-
- pEffect->IncrementTimer();
-
- for(; pAssignment < pLastAssn; pAssignment++)
- {
- pEffect->EvaluateAssignment(pAssignment);
- }
-}
-
-// Returns true if the shader uses global interfaces (since these interfaces can be updated through SetClassInstance)
-bool SPassBlock::CheckShaderDependencies( _In_ const SShaderBlock* pBlock )
-{
- if( pBlock->InterfaceDepCount > 0 )
- {
- assert( pBlock->InterfaceDepCount == 1 );
- for( size_t i=0; i < pBlock->pInterfaceDeps[0].Count; i++ )
- {
- SInterface* pInterfaceDep = pBlock->pInterfaceDeps[0].ppFXPointers[i];
- if( pInterfaceDep > pEffect->m_pInterfaces && pInterfaceDep < (pEffect->m_pInterfaces + pEffect->m_InterfaceCount) )
- {
- // This is a global interface pointer (as opposed to an SInterface created in a BindInterface call
- return true;
- }
- }
- }
- return false;
-}
-
-// Returns true if the pass (and sets HasDependencies) if the pass sets objects whose backing stores can be updated
-#pragma warning(push)
-#pragma warning(disable: 4616 6282)
-bool SPassBlock::CheckDependencies()
-{
- if( HasDependencies )
- return true;
-
- for( size_t i=0; i < AssignmentCount; i++ )
- {
- if( pAssignments[i].DependencyCount > 0 )
- return HasDependencies = true;
- }
- if( BackingStore.pBlendBlock && BackingStore.pBlendBlock->AssignmentCount > 0 )
- {
- for( size_t i=0; i < BackingStore.pBlendBlock->AssignmentCount; i++ )
- {
- if( BackingStore.pBlendBlock->pAssignments[i].DependencyCount > 0 )
- return HasDependencies = true;
- }
- }
- if( BackingStore.pDepthStencilBlock && BackingStore.pDepthStencilBlock->AssignmentCount > 0 )
- {
- for( size_t i=0; i < BackingStore.pDepthStencilBlock->AssignmentCount; i++ )
- {
- if( BackingStore.pDepthStencilBlock->pAssignments[i].DependencyCount > 0 )
- return HasDependencies = true;
- }
- }
- if( BackingStore.pRasterizerBlock && BackingStore.pRasterizerBlock->AssignmentCount > 0 )
- {
- for( size_t i=0; i < BackingStore.pRasterizerBlock->AssignmentCount; i++ )
- {
- if( BackingStore.pRasterizerBlock->pAssignments[i].DependencyCount > 0 )
- return HasDependencies = true;
- }
- }
- if( BackingStore.pVertexShaderBlock && CheckShaderDependencies( BackingStore.pVertexShaderBlock ) )
- {
- return HasDependencies = true;
- }
- if( BackingStore.pGeometryShaderBlock && CheckShaderDependencies( BackingStore.pGeometryShaderBlock ) )
- {
- return HasDependencies = true;
- }
- if( BackingStore.pPixelShaderBlock && CheckShaderDependencies( BackingStore.pPixelShaderBlock ) )
- {
- return HasDependencies = true;
- }
- if( BackingStore.pHullShaderBlock && CheckShaderDependencies( BackingStore.pHullShaderBlock ) )
- {
- return HasDependencies = true;
- }
- if( BackingStore.pDomainShaderBlock && CheckShaderDependencies( BackingStore.pDomainShaderBlock ) )
- {
- return HasDependencies = true;
- }
- if( BackingStore.pComputeShaderBlock && CheckShaderDependencies( BackingStore.pComputeShaderBlock ) )
- {
- return HasDependencies = true;
- }
-
- return HasDependencies;
-}
-#pragma warning(pop)
-
-// Update constant buffer contents if necessary
-inline void CheckAndUpdateCB_FX(ID3D11DeviceContext *pContext, SConstantBuffer *pCB)
-{
- if (pCB->IsDirty && !pCB->IsNonUpdatable)
- {
- // CB out of date; rebuild it
- pContext->UpdateSubresource(pCB->pD3DObject, 0, nullptr, pCB->pBackingStore, pCB->Size, pCB->Size);
- pCB->IsDirty = false;
- }
-}
-
-
-//--------------------------------------------------------------------------------------
-//--------------------------------------------------------------------------------------
-
-// Set the shader and dependent state (SRVs, samplers, UAVs, interfaces)
-void CEffect::ApplyShaderBlock(_In_ SShaderBlock *pBlock)
-{
- SD3DShaderVTable *pVT = pBlock->pVT;
-
- // Apply constant buffers first (tbuffers are done later)
- SShaderCBDependency *pCBDep = pBlock->pCBDeps;
- SShaderCBDependency *pLastCBDep = pBlock->pCBDeps + pBlock->CBDepCount;
-
- for (; pCBDep<pLastCBDep; pCBDep++)
- {
- assert(pCBDep->ppFXPointers);
-
- for (size_t i = 0; i < pCBDep->Count; ++ i)
- {
- CheckAndUpdateCB_FX(m_pContext, (SConstantBuffer*)pCBDep->ppFXPointers[i]);
- }
-
- (m_pContext->*(pVT->pSetConstantBuffers))(pCBDep->StartIndex, pCBDep->Count, pCBDep->ppD3DObjects);
- }
-
- // Next, apply samplers
- SShaderSamplerDependency *pSampDep = pBlock->pSampDeps;
- SShaderSamplerDependency *pLastSampDep = pBlock->pSampDeps + pBlock->SampDepCount;
-
- for (; pSampDep<pLastSampDep; pSampDep++)
- {
- assert(pSampDep->ppFXPointers);
-
- for (size_t i=0; i<pSampDep->Count; i++)
- {
- if ( ApplyRenderStateBlock(pSampDep->ppFXPointers[i]) )
- {
- // If the sampler was updated, its pointer will have changed
- pSampDep->ppD3DObjects[i] = pSampDep->ppFXPointers[i]->pD3DObject;
- }
- }
- (m_pContext->*(pVT->pSetSamplers))(pSampDep->StartIndex, pSampDep->Count, pSampDep->ppD3DObjects);
- }
-
- // Set the UAVs
- // UAV ranges were combined in EffectLoad. This code remains unchanged, however, so that ranges can be easily split
- assert( pBlock->UAVDepCount < 2 );
- if( pBlock->UAVDepCount > 0 )
- {
- SUnorderedAccessViewDependency *pUAVDep = pBlock->pUAVDeps;
- assert(pUAVDep->ppFXPointers != 0);
- _Analysis_assume_(pUAVDep->ppFXPointers != 0);
-
- for (size_t i=0; i<pUAVDep->Count; i++)
- {
- pUAVDep->ppD3DObjects[i] = pUAVDep->ppFXPointers[i]->pUnorderedAccessView;
- }
-
- if( EOT_ComputeShader5 == pBlock->GetShaderType() )
- {
- m_pContext->CSSetUnorderedAccessViews( pUAVDep->StartIndex, pUAVDep->Count, pUAVDep->ppD3DObjects, g_pNegativeOnes );
- }
- else
- {
- // This call could be combined with the call to set render targets if both exist in the pass
- m_pContext->OMSetRenderTargetsAndUnorderedAccessViews( D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, pUAVDep->StartIndex, pUAVDep->Count, pUAVDep->ppD3DObjects, g_pNegativeOnes );
- }
- }
-
- // TBuffers are funny:
- // We keep two references to them. One is in as a standard texture dep, and that gets used for all sets
- // The other is as a part of the TBufferDeps array, which tells us to rebuild the matching CBs.
- // These two refs could be rolled into one, but then we would have to predicate on each CB or each texture.
- SConstantBuffer **ppTB = pBlock->ppTbufDeps;
- SConstantBuffer **ppLastTB = ppTB + pBlock->TBufferDepCount;
-
- for (; ppTB<ppLastTB; ppTB++)
- {
- CheckAndUpdateCB_FX(m_pContext, (SConstantBuffer*)*ppTB);
- }
-
- // Set the textures
- SShaderResourceDependency *pResourceDep = pBlock->pResourceDeps;
- SShaderResourceDependency *pLastResourceDep = pBlock->pResourceDeps + pBlock->ResourceDepCount;
-
- for (; pResourceDep<pLastResourceDep; pResourceDep++)
- {
- assert(pResourceDep->ppFXPointers != 0);
- _Analysis_assume_(pResourceDep->ppFXPointers != 0);
-
- for (size_t i=0; i<pResourceDep->Count; i++)
- {
- pResourceDep->ppD3DObjects[i] = pResourceDep->ppFXPointers[i]->pShaderResource;
- }
-
- (m_pContext->*(pVT->pSetShaderResources))(pResourceDep->StartIndex, pResourceDep->Count, pResourceDep->ppD3DObjects);
- }
-
- // Update Interface dependencies
- uint32_t Interfaces = 0;
- ID3D11ClassInstance** ppClassInstances = nullptr;
- assert( pBlock->InterfaceDepCount < 2 );
- if( pBlock->InterfaceDepCount > 0 )
- {
- SInterfaceDependency *pInterfaceDep = pBlock->pInterfaceDeps;
- assert(pInterfaceDep->ppFXPointers);
-
- ppClassInstances = pInterfaceDep->ppD3DObjects;
- Interfaces = pInterfaceDep->Count;
- for (size_t i=0; i<pInterfaceDep->Count; i++)
- {
- assert(pInterfaceDep->ppFXPointers != 0);
- _Analysis_assume_(pInterfaceDep->ppFXPointers != 0);
- SClassInstanceGlobalVariable* pCI = pInterfaceDep->ppFXPointers[i]->pClassInstance;
- if( pCI )
- {
- assert( pCI->pMemberData != 0 );
- _Analysis_assume_( pCI->pMemberData != 0 );
- pInterfaceDep->ppD3DObjects[i] = pCI->pMemberData->Data.pD3DClassInstance;
- }
- else
- {
- pInterfaceDep->ppD3DObjects[i] = nullptr;
- }
- }
- }
-
- // Now set the shader
- (m_pContext->*(pVT->pSetShader))(pBlock->pD3DObject, ppClassInstances, Interfaces);
-}
-
-// Returns true if the block D3D data was recreated
-bool CEffect::ApplyRenderStateBlock(_In_ SBaseBlock *pBlock)
-{
- if( pBlock->IsUserManaged )
- {
- return false;
- }
-
- bool bRecreate = pBlock->ApplyAssignments(this);
-
- if (bRecreate)
- {
- switch (pBlock->BlockType)
- {
- case EBT_Sampler:
- {
- SSamplerBlock *pSBlock = pBlock->AsSampler();
-
- assert(pSBlock->pD3DObject != 0);
- _Analysis_assume_(pSBlock->pD3DObject != 0);
- pSBlock->pD3DObject->Release();
-
- HRESULT hr = m_pDevice->CreateSamplerState( &pSBlock->BackingStore.SamplerDesc, &pSBlock->pD3DObject );
- if ( SUCCEEDED(hr) )
- {
- SetDebugObjectName(pSBlock->pD3DObject, "D3DX11Effect");
- }
- }
- break;
-
- case EBT_DepthStencil:
- {
- SDepthStencilBlock *pDSBlock = pBlock->AsDepthStencil();
-
- assert(nullptr != pDSBlock->pDSObject);
- SAFE_RELEASE( pDSBlock->pDSObject );
- if( SUCCEEDED( m_pDevice->CreateDepthStencilState( &pDSBlock->BackingStore, &pDSBlock->pDSObject ) ) )
- {
- pDSBlock->IsValid = true;
- SetDebugObjectName( pDSBlock->pDSObject, "D3DX11Effect" );
- }
- else
- pDSBlock->IsValid = false;
- }
- break;
-
- case EBT_Blend:
- {
- SBlendBlock *pBBlock = pBlock->AsBlend();
-
- assert(nullptr != pBBlock->pBlendObject);
- SAFE_RELEASE( pBBlock->pBlendObject );
- if( SUCCEEDED( m_pDevice->CreateBlendState( &pBBlock->BackingStore, &pBBlock->pBlendObject ) ) )
- {
- pBBlock->IsValid = true;
- SetDebugObjectName( pBBlock->pBlendObject, "D3DX11Effect" );
- }
- else
- pBBlock->IsValid = false;
- }
- break;
-
- case EBT_Rasterizer:
- {
- SRasterizerBlock *pRBlock = pBlock->AsRasterizer();
-
- assert(nullptr != pRBlock->pRasterizerObject);
-
- SAFE_RELEASE( pRBlock->pRasterizerObject );
- if( SUCCEEDED( m_pDevice->CreateRasterizerState( &pRBlock->BackingStore, &pRBlock->pRasterizerObject ) ) )
- {
- pRBlock->IsValid = true;
- SetDebugObjectName( pRBlock->pRasterizerObject, "D3DX11Effect" );
- }
- else
- pRBlock->IsValid = false;
- }
- break;
-
- default:
- assert(0);
- }
- }
-
- return bRecreate;
-}
-
-void CEffect::ValidateIndex(_In_ uint32_t Elements)
-{
- if (m_FXLIndex >= Elements)
- {
- DPF(0, "ID3DX11Effect: Overindexing variable array (size: %u, index: %u), using index = 0 instead", Elements, m_FXLIndex);
- m_FXLIndex = 0;
- }
-}
-
-// Returns true if the assignment was changed
-bool CEffect::EvaluateAssignment(_Inout_ SAssignment *pAssignment)
-{
- bool bNeedUpdate = false;
- SGlobalVariable *pVarDep0, *pVarDep1;
-
- switch (pAssignment->AssignmentType)
- {
- case ERAT_NumericVariable:
- assert(pAssignment->DependencyCount == 1);
- if (pAssignment->pDependencies[0].pVariable->LastModifiedTime >= pAssignment->LastRecomputedTime)
- {
- memcpy(pAssignment->Destination.pNumeric, pAssignment->Source.pNumeric, pAssignment->DataSize);
- bNeedUpdate = true;
- }
- break;
-
- case ERAT_NumericVariableIndex:
- assert(pAssignment->DependencyCount == 2);
- pVarDep0 = pAssignment->pDependencies[0].pVariable;
- pVarDep1 = pAssignment->pDependencies[1].pVariable;
-
- if (pVarDep0->LastModifiedTime >= pAssignment->LastRecomputedTime)
- {
- m_FXLIndex = *pVarDep0->Data.pNumericDword;
-
- ValidateIndex(pVarDep1->pType->Elements);
-
- // Array index variable is dirty, update the pointer
- pAssignment->Source.pNumeric = pVarDep1->Data.pNumeric + pVarDep1->pType->Stride * m_FXLIndex;
-
- // Copy the new data
- memcpy(pAssignment->Destination.pNumeric, pAssignment->Source.pNumeric, pAssignment->DataSize);
- bNeedUpdate = true;
- }
- else if (pVarDep1->LastModifiedTime >= pAssignment->LastRecomputedTime)
- {
- // Only the array variable is dirty, copy the new data
- memcpy(pAssignment->Destination.pNumeric, pAssignment->Source.pNumeric, pAssignment->DataSize);
- bNeedUpdate = true;
- }
- break;
-
- case ERAT_ObjectVariableIndex:
- assert(pAssignment->DependencyCount == 1);
- pVarDep0 = pAssignment->pDependencies[0].pVariable;
- if (pVarDep0->LastModifiedTime >= pAssignment->LastRecomputedTime)
- {
- m_FXLIndex = *pVarDep0->Data.pNumericDword;
- ValidateIndex(pAssignment->MaxElements);
-
- // Array index variable is dirty, update the destination pointer
- *((void **)pAssignment->Destination.pGeneric) = pAssignment->Source.pNumeric +
- pAssignment->DataSize * m_FXLIndex;
- bNeedUpdate = true;
- }
- break;
-
- default:
- //case ERAT_Constant: -- These are consumed and discarded
- //case ERAT_ObjectVariable: -- These are consumed and discarded
- //case ERAT_ObjectConstIndex: -- These are consumed and discarded
- //case ERAT_ObjectInlineShader: -- These are consumed and discarded
- //case ERAT_NumericConstIndex: -- ERAT_NumericVariable should be generated instead
- assert(0);
- break;
- }
-
- // Mark the assignment as not dirty
- pAssignment->LastRecomputedTime = m_LocalTimer;
-
- return bNeedUpdate;
-}
-
-// Returns false if this shader has interface dependencies which are nullptr (SetShader will fail).
-bool CEffect::ValidateShaderBlock( _Inout_ SShaderBlock* pBlock )
-{
- if( !pBlock->IsValid )
- return false;
- if( pBlock->InterfaceDepCount > 0 )
- {
- assert( pBlock->InterfaceDepCount == 1 );
- for( size_t i=0; i < pBlock->pInterfaceDeps[0].Count; i++ )
- {
- SInterface* pInterfaceDep = pBlock->pInterfaceDeps[0].ppFXPointers[i];
- assert( pInterfaceDep != 0 );
- _Analysis_assume_( pInterfaceDep != 0 );
- if( pInterfaceDep->pClassInstance == nullptr )
- {
- return false;
- }
- }
- }
- return true;
-}
-
-// Returns false if any state in the pass is invalid
-bool CEffect::ValidatePassBlock( _Inout_ SPassBlock* pBlock )
-{
- pBlock->ApplyPassAssignments();
-
- if (nullptr != pBlock->BackingStore.pBlendBlock)
- {
- ApplyRenderStateBlock(pBlock->BackingStore.pBlendBlock);
- pBlock->BackingStore.pBlendState = pBlock->BackingStore.pBlendBlock->pBlendObject;
- if( !pBlock->BackingStore.pBlendBlock->IsValid )
- return false;
- }
-
- if( nullptr != pBlock->BackingStore.pDepthStencilBlock )
- {
- ApplyRenderStateBlock( pBlock->BackingStore.pDepthStencilBlock );
- pBlock->BackingStore.pDepthStencilState = pBlock->BackingStore.pDepthStencilBlock->pDSObject;
- if( !pBlock->BackingStore.pDepthStencilBlock->IsValid )
- return false;
- }
-
- if( nullptr != pBlock->BackingStore.pRasterizerBlock )
- {
- ApplyRenderStateBlock( pBlock->BackingStore.pRasterizerBlock );
- if( !pBlock->BackingStore.pRasterizerBlock->IsValid )
- return false;
- }
-
- if( nullptr != pBlock->BackingStore.pVertexShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pVertexShaderBlock) )
- return false;
-
- if( nullptr != pBlock->BackingStore.pGeometryShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pGeometryShaderBlock) )
- return false;
-
- if( nullptr != pBlock->BackingStore.pPixelShaderBlock )
- {
- if( !ValidateShaderBlock(pBlock->BackingStore.pPixelShaderBlock) )
- return false;
- else if( pBlock->BackingStore.pPixelShaderBlock->UAVDepCount > 0 &&
- pBlock->BackingStore.RenderTargetViewCount > pBlock->BackingStore.pPixelShaderBlock->pUAVDeps[0].StartIndex )
- {
- return false;
- }
- }
-
- if( nullptr != pBlock->BackingStore.pHullShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pHullShaderBlock) )
- return false;
-
- if( nullptr != pBlock->BackingStore.pDomainShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pDomainShaderBlock) )
- return false;
-
- if( nullptr != pBlock->BackingStore.pComputeShaderBlock && !ValidateShaderBlock(pBlock->BackingStore.pComputeShaderBlock) )
- return false;
-
- return true;
-}
-
-// Set all state defined in the pass
-void CEffect::ApplyPassBlock(_Inout_ SPassBlock *pBlock)
-{
- pBlock->ApplyPassAssignments();
-
- if (nullptr != pBlock->BackingStore.pBlendBlock)
- {
- ApplyRenderStateBlock(pBlock->BackingStore.pBlendBlock);
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pBlendBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid BlendState." );
-#endif
- pBlock->BackingStore.pBlendState = pBlock->BackingStore.pBlendBlock->pBlendObject;
- m_pContext->OMSetBlendState(pBlock->BackingStore.pBlendState,
- pBlock->BackingStore.BlendFactor,
- pBlock->BackingStore.SampleMask);
- }
-
- if (nullptr != pBlock->BackingStore.pDepthStencilBlock)
- {
- ApplyRenderStateBlock(pBlock->BackingStore.pDepthStencilBlock);
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pDepthStencilBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid DepthStencilState." );
-#endif
- pBlock->BackingStore.pDepthStencilState = pBlock->BackingStore.pDepthStencilBlock->pDSObject;
- m_pContext->OMSetDepthStencilState(pBlock->BackingStore.pDepthStencilState,
- pBlock->BackingStore.StencilRef);
- }
-
- if (nullptr != pBlock->BackingStore.pRasterizerBlock)
- {
- ApplyRenderStateBlock(pBlock->BackingStore.pRasterizerBlock);
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pRasterizerBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid RasterizerState." );
-#endif
- m_pContext->RSSetState(pBlock->BackingStore.pRasterizerBlock->pRasterizerObject);
- }
-
- if (nullptr != pBlock->BackingStore.pRenderTargetViews[0])
- {
- // Grab all render targets
- ID3D11RenderTargetView *pRTV[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
-
- assert(pBlock->BackingStore.RenderTargetViewCount <= D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT);
- _Analysis_assume_(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT >= pBlock->BackingStore.RenderTargetViewCount);
-
- for (uint32_t i=0; i<pBlock->BackingStore.RenderTargetViewCount; i++)
- {
- pRTV[i] = pBlock->BackingStore.pRenderTargetViews[i]->pRenderTargetView;
- }
-
- // This call could be combined with the call to set PS UAVs if both exist in the pass
- m_pContext->OMSetRenderTargetsAndUnorderedAccessViews( pBlock->BackingStore.RenderTargetViewCount, pRTV, pBlock->BackingStore.pDepthStencilView->pDepthStencilView, 7, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, nullptr, nullptr );
- }
-
- if (nullptr != pBlock->BackingStore.pVertexShaderBlock)
- {
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pVertexShaderBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid vertex shader." );
-#endif
- ApplyShaderBlock(pBlock->BackingStore.pVertexShaderBlock);
- }
-
- if (nullptr != pBlock->BackingStore.pPixelShaderBlock)
- {
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pPixelShaderBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid pixel shader." );
-#endif
- ApplyShaderBlock(pBlock->BackingStore.pPixelShaderBlock);
- }
-
- if (nullptr != pBlock->BackingStore.pGeometryShaderBlock)
- {
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pGeometryShaderBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid geometry shader." );
-#endif
- ApplyShaderBlock(pBlock->BackingStore.pGeometryShaderBlock);
- }
-
- if (nullptr != pBlock->BackingStore.pHullShaderBlock)
- {
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pHullShaderBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid hull shader." );
-#endif
- ApplyShaderBlock(pBlock->BackingStore.pHullShaderBlock);
- }
-
- if (nullptr != pBlock->BackingStore.pDomainShaderBlock)
- {
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pDomainShaderBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid domain shader." );
-#endif
- ApplyShaderBlock(pBlock->BackingStore.pDomainShaderBlock);
- }
-
- if (nullptr != pBlock->BackingStore.pComputeShaderBlock)
- {
-#ifdef FXDEBUG
- if( !pBlock->BackingStore.pComputeShaderBlock->IsValid )
- DPF( 0, "Pass::Apply - warning: applying invalid compute shader." );
-#endif
- ApplyShaderBlock(pBlock->BackingStore.pComputeShaderBlock);
- }
-}
-
-void CEffect::IncrementTimer()
-{
- m_LocalTimer++;
-
-#if !defined(_M_X64) && !defined(_M_ARM64)
-#if _DEBUG
- if (m_LocalTimer > g_TimerRolloverCount)
- {
- DPF(0, "Rolling over timer (current time: %zu, rollover cap: %u).", m_LocalTimer, g_TimerRolloverCount);
-#else
- if (m_LocalTimer >= 0x80000000) // check to see if we've exceeded ~2 billion
- {
-#endif
- HandleLocalTimerRollover();
-
- m_LocalTimer = 1;
- }
-#endif // _M_X64
-}
-
-// This function resets all timers, rendering all assignments dirty
-// This is clearly bad for performance, but should only happen every few billion ticks
-void CEffect::HandleLocalTimerRollover()
-{
- uint32_t i, j, k;
-
- // step 1: update variables
- for (i = 0; i < m_VariableCount; ++ i)
- {
- m_pVariables[i].LastModifiedTime = 0;
- }
-
- // step 2: update assignments on all blocks (pass, depth stencil, rasterizer, blend, sampler)
- for (uint32_t iGroup = 0; iGroup < m_GroupCount; ++ iGroup)
- {
- for (i = 0; i < m_pGroups[iGroup].TechniqueCount; ++ i)
- {
- for (j = 0; j < m_pGroups[iGroup].pTechniques[i].PassCount; ++ j)
- {
- for (k = 0; k < m_pGroups[iGroup].pTechniques[i].pPasses[j].AssignmentCount; ++ k)
- {
- m_pGroups[iGroup].pTechniques[i].pPasses[j].pAssignments[k].LastRecomputedTime = 0;
- }
- }
- }
- }
-
- for (i = 0; i < m_DepthStencilBlockCount; ++ i)
- {
- for (j = 0; j < m_pDepthStencilBlocks[i].AssignmentCount; ++ j)
- {
- m_pDepthStencilBlocks[i].pAssignments[j].LastRecomputedTime = 0;
- }
- }
-
- for (i = 0; i < m_RasterizerBlockCount; ++ i)
- {
- for (j = 0; j < m_pRasterizerBlocks[i].AssignmentCount; ++ j)
- {
- m_pRasterizerBlocks[i].pAssignments[j].LastRecomputedTime = 0;
- }
- }
-
- for (i = 0; i < m_BlendBlockCount; ++ i)
- {
- for (j = 0; j < m_pBlendBlocks[i].AssignmentCount; ++ j)
- {
- m_pBlendBlocks[i].pAssignments[j].LastRecomputedTime = 0;
- }
- }
-
- for (i = 0; i < m_SamplerBlockCount; ++ i)
- {
- for (j = 0; j < m_pSamplerBlocks[i].AssignmentCount; ++ j)
- {
- m_pSamplerBlocks[i].pAssignments[j].LastRecomputedTime = 0;
- }
- }
-}
-
-}
-
-#endif
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: EffectStateBase11.h
-//
-// Direct3D 11 Effects States Header
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-namespace D3DX11Effects
-{
-
-//////////////////////////////////////////////////////////////////////////
-// Effect HLSL states and late resolve lists
-//////////////////////////////////////////////////////////////////////////
-
-struct RValue
-{
- const char *m_pName;
- uint32_t m_Value;
-};
-
-#define RVALUE_END() { nullptr, 0U }
-#define RVALUE_ENTRY(prefix, x) { #x, (uint32_t)prefix##x }
-
-enum ELhsType : int;
-
-struct LValue
-{
- const char *m_pName; // name of the LHS side of expression
- EBlockType m_BlockType; // type of block it can appear in
- D3D_SHADER_VARIABLE_TYPE m_Type; // data type allows
- uint32_t m_Cols; // number of [m_Type]'s required (1 for a scalar, 4 for a vector)
- uint32_t m_Indices; // max index allowable (if LHS is an array; otherwise this is 1)
- bool m_VectorScalar; // can be both vector and scalar (setting as a scalar sets all m_Indices values simultaneously)
- const RValue *m_pRValue; // pointer to table of allowable RHS "late resolve" values
- ELhsType m_LhsType; // ELHS_* enum value that corresponds to this entry
- uint32_t m_Offset; // offset into the given block type where this value should be written
- uint32_t m_Stride; // for vectors, byte stride between two consecutive values. if 0, m_Type's size is used
-};
-
-#define LVALUE_END() { nullptr, D3D_SVT_UINT, 0, 0, 0, nullptr }
-
-extern const LValue g_lvGeneral[];
-extern const uint32_t g_lvGeneralCount;
-
-} // end namespace D3DX11Effects
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: EffectStates11.h
-//
-// Direct3D 11 Effects States Header
-// This file defines properties of states which can appear in
-// state blocks and pass blocks.
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-#include "EffectStateBase11.h"
-
-namespace D3DX11Effects
-{
-
-//////////////////////////////////////////////////////////////////////////
-// Effect HLSL late resolve lists (state values)
-//////////////////////////////////////////////////////////////////////////
-
-static const RValue g_rvNULL[] =
-{
- { "nullptr", 0 },
- RVALUE_END()
-};
-
-
-static const RValue g_rvBOOL[] =
-{
- { "false", 0 },
- { "true", 1 },
- RVALUE_END()
-};
-
-static const RValue g_rvDEPTH_WRITE_MASK[] =
-{
- { "ZERO", D3D11_DEPTH_WRITE_MASK_ZERO },
- { "ALL", D3D11_DEPTH_WRITE_MASK_ALL },
- RVALUE_END()
-};
-
-static const RValue g_rvFILL[] =
-{
- { "WIREFRAME", D3D11_FILL_WIREFRAME },
- { "SOLID", D3D11_FILL_SOLID },
- RVALUE_END()
-};
-
-static const RValue g_rvFILTER[] =
-{
- RVALUE_ENTRY(D3D11_FILTER_, MIN_MAG_MIP_POINT ),
- RVALUE_ENTRY(D3D11_FILTER_, MIN_MAG_POINT_MIP_LINEAR ),
- RVALUE_ENTRY(D3D11_FILTER_, MIN_POINT_MAG_LINEAR_MIP_POINT ),
- RVALUE_ENTRY(D3D11_FILTER_, MIN_POINT_MAG_MIP_LINEAR ),
- RVALUE_ENTRY(D3D11_FILTER_, MIN_LINEAR_MAG_MIP_POINT ),
- RVALUE_ENTRY(D3D11_FILTER_, MIN_LINEAR_MAG_POINT_MIP_LINEAR ),
- RVALUE_ENTRY(D3D11_FILTER_, MIN_MAG_LINEAR_MIP_POINT ),
- RVALUE_ENTRY(D3D11_FILTER_, MIN_MAG_MIP_LINEAR ),
- RVALUE_ENTRY(D3D11_FILTER_, ANISOTROPIC ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_MIN_MAG_MIP_POINT ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_MIN_MAG_POINT_MIP_LINEAR ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_MIN_POINT_MAG_MIP_LINEAR ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_MIN_LINEAR_MAG_MIP_POINT ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_MIN_MAG_LINEAR_MIP_POINT ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_MIN_MAG_MIP_LINEAR ),
- RVALUE_ENTRY(D3D11_FILTER_, COMPARISON_ANISOTROPIC ),
- RVALUE_END()
-};
-
-static const RValue g_rvBLEND[] =
-{
- { "ZERO", D3D11_BLEND_ZERO },
- { "ONE", D3D11_BLEND_ONE },
- { "SRC_COLOR", D3D11_BLEND_SRC_COLOR },
- { "INV_SRC_COLOR", D3D11_BLEND_INV_SRC_COLOR },
- { "SRC_ALPHA", D3D11_BLEND_SRC_ALPHA },
- { "INV_SRC_ALPHA", D3D11_BLEND_INV_SRC_ALPHA },
- { "DEST_ALPHA", D3D11_BLEND_DEST_ALPHA },
- { "INV_DEST_ALPHA", D3D11_BLEND_INV_DEST_ALPHA },
- { "DEST_COLOR", D3D11_BLEND_DEST_COLOR },
- { "INV_DEST_COLOR", D3D11_BLEND_INV_DEST_COLOR },
- { "SRC_ALPHA_SAT", D3D11_BLEND_SRC_ALPHA_SAT },
- { "BLEND_FACTOR", D3D11_BLEND_BLEND_FACTOR },
- { "INV_BLEND_FACTOR", D3D11_BLEND_INV_BLEND_FACTOR },
- { "SRC1_COLOR", D3D11_BLEND_SRC1_COLOR },
- { "INV_SRC1_COLOR", D3D11_BLEND_INV_SRC1_COLOR },
- { "SRC1_ALPHA", D3D11_BLEND_SRC1_ALPHA },
- { "INV_SRC1_ALPHA", D3D11_BLEND_INV_SRC1_ALPHA },
-
- RVALUE_END()
-};
-
-static const RValue g_rvTADDRESS[] =
-{
- { "CLAMP", D3D11_TEXTURE_ADDRESS_CLAMP },
- { "WRAP", D3D11_TEXTURE_ADDRESS_WRAP },
- { "MIRROR", D3D11_TEXTURE_ADDRESS_MIRROR },
- { "BORDER", D3D11_TEXTURE_ADDRESS_BORDER },
- { "MIRROR_ONCE", D3D11_TEXTURE_ADDRESS_MIRROR_ONCE },
- RVALUE_END()
-};
-
-static const RValue g_rvCULL[] =
-{
- { "NONE", D3D11_CULL_NONE },
- { "FRONT", D3D11_CULL_FRONT },
- { "BACK", D3D11_CULL_BACK },
- RVALUE_END()
-};
-
-static const RValue g_rvCMP[] =
-{
- { "NEVER", D3D11_COMPARISON_NEVER },
- { "LESS", D3D11_COMPARISON_LESS },
- { "EQUAL", D3D11_COMPARISON_EQUAL },
- { "LESS_EQUAL", D3D11_COMPARISON_LESS_EQUAL },
- { "GREATER", D3D11_COMPARISON_GREATER },
- { "NOT_EQUAL", D3D11_COMPARISON_NOT_EQUAL },
- { "GREATER_EQUAL", D3D11_COMPARISON_GREATER_EQUAL },
- { "ALWAYS", D3D11_COMPARISON_ALWAYS },
- RVALUE_END()
-};
-
-static const RValue g_rvSTENCILOP[] =
-{
- { "KEEP", D3D11_STENCIL_OP_KEEP },
- { "ZERO", D3D11_STENCIL_OP_ZERO },
- { "REPLACE", D3D11_STENCIL_OP_REPLACE },
- { "INCR_SAT", D3D11_STENCIL_OP_INCR_SAT },
- { "DECR_SAT", D3D11_STENCIL_OP_DECR_SAT },
- { "INVERT", D3D11_STENCIL_OP_INVERT },
- { "INCR", D3D11_STENCIL_OP_INCR },
- { "DECR", D3D11_STENCIL_OP_DECR },
- RVALUE_END()
-};
-
-static const RValue g_rvBLENDOP[] =
-{
- { "ADD", D3D11_BLEND_OP_ADD },
- { "SUBTRACT", D3D11_BLEND_OP_SUBTRACT },
- { "REV_SUBTRACT", D3D11_BLEND_OP_REV_SUBTRACT },
- { "MIN", D3D11_BLEND_OP_MIN },
- { "MAX", D3D11_BLEND_OP_MAX },
- RVALUE_END()
-};
-
-
-//////////////////////////////////////////////////////////////////////////
-// Effect HLSL states
-//////////////////////////////////////////////////////////////////////////
-
-#define strideof( s, m ) offsetof_fx(s,m[1]) - offsetof_fx(s,m[0])
-
-const LValue g_lvGeneral[] =
-{
- // RObjects
- { "RasterizerState", EBT_Pass, D3D_SVT_RASTERIZER, 1, 1, false, nullptr, ELHS_RasterizerBlock, offsetof_fx(SPassBlock, BackingStore.pRasterizerBlock), 0 },
- { "DepthStencilState", EBT_Pass, D3D_SVT_DEPTHSTENCIL, 1, 1, false, nullptr, ELHS_DepthStencilBlock, offsetof_fx(SPassBlock, BackingStore.pDepthStencilBlock), 0 },
- { "BlendState", EBT_Pass, D3D_SVT_BLEND, 1, 1, false, nullptr, ELHS_BlendBlock, offsetof_fx(SPassBlock, BackingStore.pBlendBlock), 0 },
- { "RenderTargetView", EBT_Pass, D3D_SVT_RENDERTARGETVIEW, 1, 8, false, nullptr, ELHS_RenderTargetView, offsetof_fx(SPassBlock, BackingStore.pRenderTargetViews), 0 },
- { "DepthStencilView", EBT_Pass, D3D_SVT_DEPTHSTENCILVIEW, 1, 8, false, nullptr, ELHS_DepthStencilView, offsetof_fx(SPassBlock, BackingStore.pDepthStencilView), 0 },
- { "GenerateMips", EBT_Pass, D3D_SVT_TEXTURE, 1, 1, false, nullptr, ELHS_GenerateMips, 0, 0 },
- // Shaders
- { "VertexShader", EBT_Pass, D3D_SVT_VERTEXSHADER, 1, 1, false, g_rvNULL, ELHS_VertexShaderBlock, offsetof_fx(SPassBlock, BackingStore.pVertexShaderBlock), 0 },
- { "PixelShader", EBT_Pass, D3D_SVT_PIXELSHADER, 1, 1, false, g_rvNULL, ELHS_PixelShaderBlock, offsetof_fx(SPassBlock, BackingStore.pPixelShaderBlock), 0 },
- { "GeometryShader", EBT_Pass, D3D_SVT_GEOMETRYSHADER, 1, 1, false, g_rvNULL, ELHS_GeometryShaderBlock, offsetof_fx(SPassBlock, BackingStore.pGeometryShaderBlock), 0 },
- // RObject config assignments
- { "DS_StencilRef", EBT_Pass, D3D_SVT_UINT, 1, 1, false, nullptr, ELHS_DS_StencilRef, offsetof_fx(SPassBlock, BackingStore.StencilRef), 0 },
- { "AB_BlendFactor", EBT_Pass, D3D_SVT_FLOAT, 4, 1, false, nullptr, ELHS_B_BlendFactor, offsetof_fx(SPassBlock, BackingStore.BlendFactor), 0 },
- { "AB_SampleMask", EBT_Pass, D3D_SVT_UINT, 1, 1, false, nullptr, ELHS_B_SampleMask, offsetof_fx(SPassBlock, BackingStore.SampleMask), 0 },
-
- { "FillMode", EBT_Rasterizer, D3D_SVT_UINT, 1, 1, false, g_rvFILL, ELHS_FillMode, offsetof_fx(SRasterizerBlock, BackingStore.FillMode), 0 },
- { "CullMode", EBT_Rasterizer, D3D_SVT_UINT, 1, 1, false, g_rvCULL, ELHS_CullMode, offsetof_fx(SRasterizerBlock, BackingStore.CullMode), 0 },
- { "FrontCounterClockwise", EBT_Rasterizer, D3D_SVT_BOOL, 1, 1, false, g_rvBOOL, ELHS_FrontCC, offsetof_fx(SRasterizerBlock, BackingStore.FrontCounterClockwise), 0 },
- { "DepthBias", EBT_Rasterizer, D3D_SVT_UINT, 1, 1, false, nullptr, ELHS_DepthBias, offsetof_fx(SRasterizerBlock, BackingStore.DepthBias), 0 },
- { "DepthBiasClamp", EBT_Rasterizer, D3D_SVT_FLOAT, 1, 1, false, nullptr, ELHS_DepthBiasClamp, offsetof_fx(SRasterizerBlock, BackingStore.DepthBiasClamp), 0 },
- { "SlopeScaledDepthBias", EBT_Rasterizer, D3D_SVT_FLOAT, 1, 1, false, nullptr, ELHS_SlopeScaledDepthBias, offsetof_fx(SRasterizerBlock, BackingStore.SlopeScaledDepthBias), 0 },
- { "DepthClipEnable", EBT_Rasterizer, D3D_SVT_BOOL, 1, 1, false, g_rvBOOL, ELHS_DepthClipEnable, offsetof_fx(SRasterizerBlock, BackingStore.DepthClipEnable), 0 },
- { "ScissorEnable", EBT_Rasterizer, D3D_SVT_BOOL, 1, 1, false, g_rvBOOL, ELHS_ScissorEnable, offsetof_fx(SRasterizerBlock, BackingStore.ScissorEnable), 0 },
- { "MultisampleEnable", EBT_Rasterizer, D3D_SVT_BOOL, 1, 1, false, g_rvBOOL, ELHS_MultisampleEnable, offsetof_fx(SRasterizerBlock, BackingStore.MultisampleEnable), 0 },
- { "AntialiasedLineEnable", EBT_Rasterizer, D3D_SVT_BOOL, 1, 1, false, g_rvBOOL, ELHS_AntialiasedLineEnable, offsetof_fx(SRasterizerBlock, BackingStore.AntialiasedLineEnable), 0 },
-
- { "DepthEnable", EBT_DepthStencil, D3D_SVT_BOOL, 1, 1, false, g_rvBOOL, ELHS_DepthEnable, offsetof_fx(SDepthStencilBlock, BackingStore.DepthEnable), 0 },
- { "DepthWriteMask", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvDEPTH_WRITE_MASK, ELHS_DepthWriteMask, offsetof_fx(SDepthStencilBlock, BackingStore.DepthWriteMask), 0 },
- { "DepthFunc", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvCMP, ELHS_DepthFunc, offsetof_fx(SDepthStencilBlock, BackingStore.DepthFunc), 0 },
- { "StencilEnable", EBT_DepthStencil, D3D_SVT_BOOL, 1, 1, false, g_rvBOOL, ELHS_StencilEnable, offsetof_fx(SDepthStencilBlock, BackingStore.StencilEnable), 0 },
- { "StencilReadMask", EBT_DepthStencil, D3D_SVT_UINT8, 1, 1, false, nullptr, ELHS_StencilReadMask, offsetof_fx(SDepthStencilBlock, BackingStore.StencilReadMask), 0 },
- { "StencilWriteMask", EBT_DepthStencil, D3D_SVT_UINT8, 1, 1, false, nullptr, ELHS_StencilWriteMask, offsetof_fx(SDepthStencilBlock, BackingStore.StencilWriteMask), 0 },
- { "FrontFaceStencilFail", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvSTENCILOP, ELHS_FrontFaceStencilFailOp, offsetof_fx(SDepthStencilBlock, BackingStore.FrontFace.StencilFailOp), 0 },
- { "FrontFaceStencilDepthFail", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvSTENCILOP, ELHS_FrontFaceStencilDepthFailOp,offsetof_fx(SDepthStencilBlock, BackingStore.FrontFace.StencilDepthFailOp), 0 },
- { "FrontFaceStencilPass", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvSTENCILOP, ELHS_FrontFaceStencilPassOp, offsetof_fx(SDepthStencilBlock, BackingStore.FrontFace.StencilPassOp), 0 },
- { "FrontFaceStencilFunc", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvCMP, ELHS_FrontFaceStencilFunc, offsetof_fx(SDepthStencilBlock, BackingStore.FrontFace.StencilFunc), 0 },
- { "BackFaceStencilFail", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvSTENCILOP, ELHS_BackFaceStencilFailOp, offsetof_fx(SDepthStencilBlock, BackingStore.BackFace.StencilFailOp), 0 },
- { "BackFaceStencilDepthFail", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvSTENCILOP, ELHS_BackFaceStencilDepthFailOp,offsetof_fx(SDepthStencilBlock, BackingStore.BackFace.StencilDepthFailOp), 0 },
- { "BackFaceStencilPass", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvSTENCILOP, ELHS_BackFaceStencilPassOp, offsetof_fx(SDepthStencilBlock, BackingStore.BackFace.StencilPassOp), 0 },
- { "BackFaceStencilFunc", EBT_DepthStencil, D3D_SVT_UINT, 1, 1, false, g_rvCMP, ELHS_BackFaceStencilFunc, offsetof_fx(SDepthStencilBlock, BackingStore.BackFace.StencilFunc), 0 },
-
- { "AlphaToCoverageEnable", EBT_Blend, D3D_SVT_BOOL, 1, 1, false, g_rvBOOL, ELHS_AlphaToCoverage, offsetof_fx(SBlendBlock, BackingStore.AlphaToCoverageEnable), 0 },
- { "BlendEnable", EBT_Blend, D3D_SVT_BOOL, 1, 8, false, g_rvBOOL, ELHS_BlendEnable, offsetof_fx(SBlendBlock, BackingStore.RenderTarget[0].BlendEnable), strideof(SBlendBlock, BackingStore.RenderTarget) },
- { "SrcBlend", EBT_Blend, D3D_SVT_UINT, 1, 8, true, g_rvBLEND, ELHS_SrcBlend, offsetof_fx(SBlendBlock, BackingStore.RenderTarget[0].SrcBlend), strideof(SBlendBlock, BackingStore.RenderTarget) },
- { "DestBlend", EBT_Blend, D3D_SVT_UINT, 1, 8, true, g_rvBLEND, ELHS_DestBlend, offsetof_fx(SBlendBlock, BackingStore.RenderTarget[0].DestBlend), strideof(SBlendBlock, BackingStore.RenderTarget) },
- { "BlendOp", EBT_Blend, D3D_SVT_UINT, 1, 8, true, g_rvBLENDOP, ELHS_BlendOp, offsetof_fx(SBlendBlock, BackingStore.RenderTarget[0].BlendOp), strideof(SBlendBlock, BackingStore.RenderTarget) },
- { "SrcBlendAlpha", EBT_Blend, D3D_SVT_UINT, 1, 8, true, g_rvBLEND, ELHS_SrcBlendAlpha, offsetof_fx(SBlendBlock, BackingStore.RenderTarget[0].SrcBlendAlpha), strideof(SBlendBlock, BackingStore.RenderTarget) },
- { "DestBlendAlpha", EBT_Blend, D3D_SVT_UINT, 1, 8, true, g_rvBLEND, ELHS_DestBlendAlpha, offsetof_fx(SBlendBlock, BackingStore.RenderTarget[0].DestBlendAlpha), strideof(SBlendBlock, BackingStore.RenderTarget) },
- { "BlendOpAlpha", EBT_Blend, D3D_SVT_UINT, 1, 8, true, g_rvBLENDOP, ELHS_BlendOpAlpha, offsetof_fx(SBlendBlock, BackingStore.RenderTarget[0].BlendOpAlpha), strideof(SBlendBlock, BackingStore.RenderTarget) },
- { "RenderTargetWriteMask", EBT_Blend, D3D_SVT_UINT8, 1, 8, false, nullptr, ELHS_RenderTargetWriteMask, offsetof_fx(SBlendBlock, BackingStore.RenderTarget[0].RenderTargetWriteMask), strideof(SBlendBlock, BackingStore.RenderTarget) },
-
- { "Filter", EBT_Sampler, D3D_SVT_UINT, 1, 1, false, g_rvFILTER, ELHS_Filter, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.Filter), 0 },
- { "AddressU", EBT_Sampler, D3D_SVT_UINT, 1, 1, false, g_rvTADDRESS, ELHS_AddressU, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.AddressU), 0 },
- { "AddressV", EBT_Sampler, D3D_SVT_UINT, 1, 1, false, g_rvTADDRESS, ELHS_AddressV, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.AddressV), 0 },
- { "AddressW", EBT_Sampler, D3D_SVT_UINT, 1, 1, false, g_rvTADDRESS, ELHS_AddressW, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.AddressW), 0 },
- { "MipLODBias", EBT_Sampler, D3D_SVT_FLOAT, 1, 1, false, nullptr, ELHS_MipLODBias, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.MipLODBias), 0 },
- { "MaxAnisotropy", EBT_Sampler, D3D_SVT_UINT, 1, 1, false, nullptr, ELHS_MaxAnisotropy, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.MaxAnisotropy), 0 },
- { "ComparisonFunc", EBT_Sampler, D3D_SVT_UINT, 1, 1, false, g_rvCMP, ELHS_ComparisonFunc, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.ComparisonFunc), 0 },
- { "BorderColor", EBT_Sampler, D3D_SVT_FLOAT, 4, 1, false, nullptr, ELHS_BorderColor, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.BorderColor), 0 },
- { "MinLOD", EBT_Sampler, D3D_SVT_FLOAT, 1, 1, false, nullptr, ELHS_MinLOD, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.MinLOD), 0 },
- { "MaxLOD", EBT_Sampler, D3D_SVT_FLOAT, 1, 1, false, nullptr, ELHS_MaxLOD, offsetof_fx(SSamplerBlock, BackingStore.SamplerDesc.MaxLOD), 0 },
- { "Texture", EBT_Sampler, D3D_SVT_TEXTURE, 1, 1, false, g_rvNULL, ELHS_Texture, offsetof_fx(SSamplerBlock, BackingStore.pTexture), 0 },
-
- // D3D11
- { "HullShader", EBT_Pass, D3D11_SVT_HULLSHADER, 1, 1, false, g_rvNULL, ELHS_HullShaderBlock, offsetof_fx(SPassBlock, BackingStore.pHullShaderBlock), 0 },
- { "DomainShader", EBT_Pass, D3D11_SVT_DOMAINSHADER, 1, 1, false, g_rvNULL, ELHS_DomainShaderBlock, offsetof_fx(SPassBlock, BackingStore.pDomainShaderBlock), 0 },
- { "ComputeShader", EBT_Pass, D3D11_SVT_COMPUTESHADER, 1, 1, false, g_rvNULL, ELHS_ComputeShaderBlock, offsetof_fx(SPassBlock, BackingStore.pComputeShaderBlock), 0 },
-};
-
-#define NUM_STATES (sizeof(g_lvGeneral) / sizeof(LValue))
-#define MAX_VECTOR_SCALAR_INDEX 8
-
-const uint32_t g_lvGeneralCount = NUM_STATES;
-
-} // end namespace D3DX11Effects
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: EffectVariable.inl
-//
-// Direct3D 11 Effects Variable reflection template
-// These templates define the many Effect variable types.
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma warning(push)
-#pragma warning(disable : 4127)
-
-//////////////////////////////////////////////////////////////////////////
-// Invalid variable forward defines
-//////////////////////////////////////////////////////////////////////////
-
-struct SEffectInvalidScalarVariable;
-struct SEffectInvalidVectorVariable;
-struct SEffectInvalidMatrixVariable;
-struct SEffectInvalidStringVariable;
-struct SEffectInvalidClassInstanceVariable;
-struct SEffectInvalidInterfaceVariable;
-struct SEffectInvalidShaderResourceVariable;
-struct SEffectInvalidUnorderedAccessViewVariable;
-struct SEffectInvalidRenderTargetViewVariable;
-struct SEffectInvalidDepthStencilViewVariable;
-struct SEffectInvalidConstantBuffer;
-struct SEffectInvalidShaderVariable;
-struct SEffectInvalidBlendVariable;
-struct SEffectInvalidDepthStencilVariable;
-struct SEffectInvalidRasterizerVariable;
-struct SEffectInvalidSamplerVariable;
-struct SEffectInvalidTechnique;
-struct SEffectInvalidPass;
-struct SEffectInvalidType;
-
-extern SEffectInvalidScalarVariable g_InvalidScalarVariable;
-extern SEffectInvalidVectorVariable g_InvalidVectorVariable;
-extern SEffectInvalidMatrixVariable g_InvalidMatrixVariable;
-extern SEffectInvalidStringVariable g_InvalidStringVariable;
-extern SEffectInvalidClassInstanceVariable g_InvalidClassInstanceVariable;
-extern SEffectInvalidInterfaceVariable g_InvalidInterfaceVariable;
-extern SEffectInvalidShaderResourceVariable g_InvalidShaderResourceVariable;
-extern SEffectInvalidUnorderedAccessViewVariable g_InvalidUnorderedAccessViewVariable;
-extern SEffectInvalidRenderTargetViewVariable g_InvalidRenderTargetViewVariable;
-extern SEffectInvalidDepthStencilViewVariable g_InvalidDepthStencilViewVariable;
-extern SEffectInvalidConstantBuffer g_InvalidConstantBuffer;
-extern SEffectInvalidShaderVariable g_InvalidShaderVariable;
-extern SEffectInvalidBlendVariable g_InvalidBlendVariable;
-extern SEffectInvalidDepthStencilVariable g_InvalidDepthStencilVariable;
-extern SEffectInvalidRasterizerVariable g_InvalidRasterizerVariable;
-extern SEffectInvalidSamplerVariable g_InvalidSamplerVariable;
-extern SEffectInvalidTechnique g_InvalidTechnique;
-extern SEffectInvalidPass g_InvalidPass;
-extern SEffectInvalidType g_InvalidType;
-
-enum ETemplateVarType
-{
- ETVT_Bool,
- ETVT_Int,
- ETVT_Float,
- ETVT_bool
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Invalid effect variable struct definitions
-//////////////////////////////////////////////////////////////////////////
-
-struct SEffectInvalidType : public ID3DX11EffectType
-{
- STDMETHOD_(bool, IsValid)() override { return false; }
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidType; }
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidType; }
- STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(_In_z_ LPCSTR Semantic) override { UNREFERENCED_PARAMETER(Semantic); return &g_InvalidType; }
- STDMETHOD_(LPCSTR, GetMemberName)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return nullptr; }
- STDMETHOD_(LPCSTR, GetMemberSemantic)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return nullptr; }
- IUNKNOWN_IMP(SEffectInvalidType, ID3DX11EffectType, IUnknown);
-};
-
-template<typename IBaseInterface>
-struct TEffectInvalidVariable : public IBaseInterface
-{
-public:
- STDMETHOD_(bool, IsValid)() override { return false; }
- STDMETHOD_(ID3DX11EffectType*, GetType)() override { return &g_InvalidType; }
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberBySemantic)(_In_z_ LPCSTR Semantic) override { UNREFERENCED_PARAMETER(Semantic); return &g_InvalidScalarVariable; }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetElement)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
-
- STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override { return &g_InvalidConstantBuffer; }
-
- STDMETHOD_(ID3DX11EffectScalarVariable*, AsScalar)() override { return &g_InvalidScalarVariable; }
- STDMETHOD_(ID3DX11EffectVectorVariable*, AsVector)() override { return &g_InvalidVectorVariable; }
- STDMETHOD_(ID3DX11EffectMatrixVariable*, AsMatrix)() override { return &g_InvalidMatrixVariable; }
- STDMETHOD_(ID3DX11EffectStringVariable*, AsString)() override { return &g_InvalidStringVariable; }
- STDMETHOD_(ID3DX11EffectClassInstanceVariable*, AsClassInstance)() override { return &g_InvalidClassInstanceVariable; }
- STDMETHOD_(ID3DX11EffectInterfaceVariable*, AsInterface)() override { return &g_InvalidInterfaceVariable; }
- STDMETHOD_(ID3DX11EffectShaderResourceVariable*, AsShaderResource)() override { return &g_InvalidShaderResourceVariable; }
- STDMETHOD_(ID3DX11EffectUnorderedAccessViewVariable*, AsUnorderedAccessView)() override { return &g_InvalidUnorderedAccessViewVariable; }
- STDMETHOD_(ID3DX11EffectRenderTargetViewVariable*, AsRenderTargetView)() override { return &g_InvalidRenderTargetViewVariable; }
- STDMETHOD_(ID3DX11EffectDepthStencilViewVariable*, AsDepthStencilView)() override { return &g_InvalidDepthStencilViewVariable; }
- STDMETHOD_(ID3DX11EffectConstantBuffer*, AsConstantBuffer)() override { return &g_InvalidConstantBuffer; }
- STDMETHOD_(ID3DX11EffectShaderVariable*, AsShader)() override { return &g_InvalidShaderVariable; }
- STDMETHOD_(ID3DX11EffectBlendVariable*, AsBlend)() override { return &g_InvalidBlendVariable; }
- STDMETHOD_(ID3DX11EffectDepthStencilVariable*, AsDepthStencil)() override { return &g_InvalidDepthStencilVariable; }
- STDMETHOD_(ID3DX11EffectRasterizerVariable*, AsRasterizer)() override { return &g_InvalidRasterizerVariable; }
- STDMETHOD_(ID3DX11EffectSamplerVariable*, AsSampler)() override { return &g_InvalidSamplerVariable; }
-
- STDMETHOD(SetRawValue)(_In_reads_bytes_(Count) const void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetRawValue)(_Out_writes_bytes_(Count) void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-};
-
-struct SEffectInvalidScalarVariable : public TEffectInvalidVariable<ID3DX11EffectScalarVariable>
-{
-public:
-
- STDMETHOD(SetFloat)(_In_ const float Value) override { UNREFERENCED_PARAMETER(Value); return E_FAIL; }
- STDMETHOD(GetFloat)(_Out_ float *pValue) override { UNREFERENCED_PARAMETER(pValue); return E_FAIL; }
-
- STDMETHOD(SetFloatArray)(_In_reads_(Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetFloatArray)(_Out_writes_(Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- STDMETHOD(SetInt)(_In_ const int Value) override { UNREFERENCED_PARAMETER(Value); return E_FAIL; }
- STDMETHOD(GetInt)(_Out_ int *pValue) override { UNREFERENCED_PARAMETER(pValue); return E_FAIL; }
-
- STDMETHOD(SetIntArray)(_In_reads_(Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetIntArray)(_Out_writes_(Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- STDMETHOD(SetBool)(_In_ const bool Value) override { UNREFERENCED_PARAMETER(Value); return E_FAIL; }
- STDMETHOD(GetBool)(_Out_ bool *pValue) override { UNREFERENCED_PARAMETER(pValue); return E_FAIL; }
-
- STDMETHOD(SetBoolArray)(_In_reads_(Count) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetBoolArray)(_Out_writes_(Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidScalarVariable, ID3DX11EffectScalarVariable, ID3DX11EffectVariable);
-};
-
-
-struct SEffectInvalidVectorVariable : public TEffectInvalidVariable<ID3DX11EffectVectorVariable>
-{
-public:
- STDMETHOD(SetFloatVector)(_In_reads_(4) const float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
- STDMETHOD(SetIntVector)(_In_reads_(4) const int *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
- STDMETHOD(SetBoolVector)(_In_reads_(4) const bool *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
-
- STDMETHOD(GetFloatVector)(_Out_writes_(4) float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
- STDMETHOD(GetIntVector)(_Out_writes_(4) int *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
- STDMETHOD(GetBoolVector)(_Out_writes_(4) bool *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
-
- STDMETHOD(SetBoolVectorArray) (_In_reads_(4*Count) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
- STDMETHOD(SetIntVectorArray) (_In_reads_(4*Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
- STDMETHOD(SetFloatVectorArray)(_In_reads_(4*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
-
- STDMETHOD(GetBoolVectorArray) (_Out_writes_(4*Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
- STDMETHOD(GetIntVectorArray) (_Out_writes_(4*Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
- STDMETHOD(GetFloatVectorArray)(_Out_writes_(4*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
-
- IUNKNOWN_IMP(SEffectInvalidVectorVariable, ID3DX11EffectVectorVariable, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidMatrixVariable : public TEffectInvalidVariable<ID3DX11EffectMatrixVariable>
-{
-public:
-
- STDMETHOD(SetMatrix)(_In_reads_(16) const float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; }
- STDMETHOD(GetMatrix)(_Out_writes_(16) float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; }
-
- STDMETHOD(SetMatrixArray)(_In_reads_(16*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetMatrixArray)(_Out_writes_(16*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- STDMETHOD(SetMatrixPointerArray)(_In_reads_(16*Count) const float **ppData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetMatrixPointerArray)(_Out_writes_(16*Count) float **ppData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- STDMETHOD(SetMatrixTranspose)(_In_reads_(16) const float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; }
- STDMETHOD(GetMatrixTranspose)(_Out_writes_(16) float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; }
-
- STDMETHOD(SetMatrixTransposeArray)(_In_reads_(16*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetMatrixTransposeArray)(_Out_writes_(16*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- STDMETHOD(SetMatrixTransposePointerArray)(_In_reads_(16*Count) const float **ppData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetMatrixTransposePointerArray)(_Out_writes_(16*Count) float **ppData, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidMatrixVariable, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidStringVariable : public TEffectInvalidVariable<ID3DX11EffectStringVariable>
-{
-public:
-
- STDMETHOD(GetString)(_Outptr_result_z_ LPCSTR *ppString) override { UNREFERENCED_PARAMETER(ppString); return E_FAIL; }
- STDMETHOD(GetStringArray)(_Out_writes_(Count) LPCSTR *ppStrings, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppStrings); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidStringVariable, ID3DX11EffectStringVariable, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidClassInstanceVariable : public TEffectInvalidVariable<ID3DX11EffectClassInstanceVariable>
-{
-public:
-
- STDMETHOD(GetClassInstance)(_Outptr_ ID3D11ClassInstance **ppClassInstance) override { UNREFERENCED_PARAMETER(ppClassInstance); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidClassInstanceVariable, ID3DX11EffectClassInstanceVariable, ID3DX11EffectVariable);
-};
-
-
-struct SEffectInvalidInterfaceVariable : public TEffectInvalidVariable<ID3DX11EffectInterfaceVariable>
-{
-public:
-
- STDMETHOD(SetClassInstance)(_In_ ID3DX11EffectClassInstanceVariable *pEffectClassInstance) override
- { UNREFERENCED_PARAMETER(pEffectClassInstance); return E_FAIL; }
- STDMETHOD(GetClassInstance)(_Outptr_ ID3DX11EffectClassInstanceVariable **ppEffectClassInstance) override
- { UNREFERENCED_PARAMETER(ppEffectClassInstance); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidInterfaceVariable, ID3DX11EffectInterfaceVariable, ID3DX11EffectVariable);
-};
-
-
-struct SEffectInvalidShaderResourceVariable : public TEffectInvalidVariable<ID3DX11EffectShaderResourceVariable>
-{
-public:
-
- STDMETHOD(SetResource)(_In_ ID3D11ShaderResourceView *pResource) override { UNREFERENCED_PARAMETER(pResource); return E_FAIL; }
- STDMETHOD(GetResource)(_Outptr_ ID3D11ShaderResourceView **ppResource) override { UNREFERENCED_PARAMETER(ppResource); return E_FAIL; }
-
- STDMETHOD(SetResourceArray)(_In_reads_(Count) ID3D11ShaderResourceView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetResourceArray)(_Out_writes_(Count) ID3D11ShaderResourceView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidShaderResourceVariable, ID3DX11EffectShaderResourceVariable, ID3DX11EffectVariable);
-};
-
-
-struct SEffectInvalidUnorderedAccessViewVariable : public TEffectInvalidVariable<ID3DX11EffectUnorderedAccessViewVariable>
-{
-public:
-
- STDMETHOD(SetUnorderedAccessView)(_In_ ID3D11UnorderedAccessView *pResource) override { UNREFERENCED_PARAMETER(pResource); return E_FAIL; }
- STDMETHOD(GetUnorderedAccessView)(_Outptr_ ID3D11UnorderedAccessView **ppResource) override { UNREFERENCED_PARAMETER(ppResource); return E_FAIL; }
-
- STDMETHOD(SetUnorderedAccessViewArray)(_In_reads_(Count) ID3D11UnorderedAccessView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetUnorderedAccessViewArray)(_Out_writes_(Count) ID3D11UnorderedAccessView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidUnorderedAccessViewVariable, ID3DX11EffectUnorderedAccessViewVariable, ID3DX11EffectVariable);
-};
-
-
-struct SEffectInvalidRenderTargetViewVariable : public TEffectInvalidVariable<ID3DX11EffectRenderTargetViewVariable>
-{
-public:
-
- STDMETHOD(SetRenderTarget)(_In_ ID3D11RenderTargetView *pResource) override { UNREFERENCED_PARAMETER(pResource); return E_FAIL; }
- STDMETHOD(GetRenderTarget)(_Outptr_ ID3D11RenderTargetView **ppResource) override { UNREFERENCED_PARAMETER(ppResource); return E_FAIL; }
-
- STDMETHOD(SetRenderTargetArray)(_In_reads_(Count) ID3D11RenderTargetView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetRenderTargetArray)(_Out_writes_(Count) ID3D11RenderTargetView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidRenderTargetViewVariable, ID3DX11EffectRenderTargetViewVariable, ID3DX11EffectVariable);
-};
-
-
-struct SEffectInvalidDepthStencilViewVariable : public TEffectInvalidVariable<ID3DX11EffectDepthStencilViewVariable>
-{
-public:
-
- STDMETHOD(SetDepthStencil)(_In_ ID3D11DepthStencilView *pResource) override { UNREFERENCED_PARAMETER(pResource); return E_FAIL; }
- STDMETHOD(GetDepthStencil)(_Outptr_ ID3D11DepthStencilView **ppResource) override { UNREFERENCED_PARAMETER(ppResource); return E_FAIL; }
-
- STDMETHOD(SetDepthStencilArray)(_In_reads_(Count) ID3D11DepthStencilView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
- STDMETHOD(GetDepthStencilArray)(_Out_writes_(Count) ID3D11DepthStencilView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
- { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidDepthStencilViewVariable, ID3DX11EffectDepthStencilViewVariable, ID3DX11EffectVariable);
-};
-
-
-struct SEffectInvalidConstantBuffer : public TEffectInvalidVariable<ID3DX11EffectConstantBuffer>
-{
-public:
-
- STDMETHOD(SetConstantBuffer)(_In_ ID3D11Buffer *pConstantBuffer) override { UNREFERENCED_PARAMETER(pConstantBuffer); return E_FAIL; }
- STDMETHOD(GetConstantBuffer)(_Outptr_ ID3D11Buffer **ppConstantBuffer) override { UNREFERENCED_PARAMETER(ppConstantBuffer); return E_FAIL; }
- STDMETHOD(UndoSetConstantBuffer)() override { return E_FAIL; }
-
- STDMETHOD(SetTextureBuffer)(_In_ ID3D11ShaderResourceView *pTextureBuffer) override { UNREFERENCED_PARAMETER(pTextureBuffer); return E_FAIL; }
- STDMETHOD(GetTextureBuffer)(_Outptr_ ID3D11ShaderResourceView **ppTextureBuffer) override { UNREFERENCED_PARAMETER(ppTextureBuffer); return E_FAIL; }
- STDMETHOD(UndoSetTextureBuffer)() override { return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidConstantBuffer, ID3DX11EffectConstantBuffer, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidShaderVariable : public TEffectInvalidVariable<ID3DX11EffectShaderVariable>
-{
-public:
-
- STDMETHOD(GetShaderDesc)(_In_ uint32_t ShaderIndex, _Out_ D3DX11_EFFECT_SHADER_DESC *pDesc) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- STDMETHOD(GetVertexShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11VertexShader **ppVS) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppVS); return E_FAIL; }
- STDMETHOD(GetGeometryShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11GeometryShader **ppGS) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppGS); return E_FAIL; }
- STDMETHOD(GetPixelShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11PixelShader **ppPS) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppPS); return E_FAIL; }
- STDMETHOD(GetHullShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11HullShader **ppHS) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppHS); return E_FAIL; }
- STDMETHOD(GetDomainShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11DomainShader **ppDS) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppDS); return E_FAIL; }
- STDMETHOD(GetComputeShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11ComputeShader **ppCS) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppCS); return E_FAIL; }
-
- STDMETHOD(GetInputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(Element); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
- STDMETHOD(GetOutputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(Element); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
- STDMETHOD(GetPatchConstantSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override
- { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(Element); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidShaderVariable, ID3DX11EffectShaderVariable, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidBlendVariable : public TEffectInvalidVariable<ID3DX11EffectBlendVariable>
-{
-public:
-
- STDMETHOD(GetBlendState)(_In_ uint32_t Index, _Outptr_ ID3D11BlendState **ppState) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(ppState); return E_FAIL; }
- STDMETHOD(SetBlendState)(_In_ uint32_t Index, _In_ ID3D11BlendState *pState) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pState); return E_FAIL; }
- STDMETHOD(UndoSetBlendState)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return E_FAIL; }
- STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_BLEND_DESC *pDesc) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidBlendVariable, ID3DX11EffectBlendVariable, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidDepthStencilVariable : public TEffectInvalidVariable<ID3DX11EffectDepthStencilVariable>
-{
-public:
-
- STDMETHOD(GetDepthStencilState)(_In_ uint32_t Index, _Outptr_ ID3D11DepthStencilState **ppState) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(ppState); return E_FAIL; }
- STDMETHOD(SetDepthStencilState)(_In_ uint32_t Index, _In_ ID3D11DepthStencilState *pState) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pState); return E_FAIL; }
- STDMETHOD(UndoSetDepthStencilState)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return E_FAIL; }
- STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_DEPTH_STENCIL_DESC *pDesc) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidDepthStencilVariable, ID3DX11EffectDepthStencilVariable, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidRasterizerVariable : public TEffectInvalidVariable<ID3DX11EffectRasterizerVariable>
-{
-public:
-
- STDMETHOD(GetRasterizerState)(_In_ uint32_t Index, _Outptr_ ID3D11RasterizerState **ppState) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(ppState); return E_FAIL; }
- STDMETHOD(SetRasterizerState)(_In_ uint32_t Index, _In_ ID3D11RasterizerState *pState) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pState); return E_FAIL; }
- STDMETHOD(UndoSetRasterizerState)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return E_FAIL; }
- STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_RASTERIZER_DESC *pDesc) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidRasterizerVariable, ID3DX11EffectRasterizerVariable, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidSamplerVariable : public TEffectInvalidVariable<ID3DX11EffectSamplerVariable>
-{
-public:
-
- STDMETHOD(GetSampler)(_In_ uint32_t Index, _Outptr_ ID3D11SamplerState **ppSampler) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(ppSampler); return E_FAIL; }
- STDMETHOD(SetSampler)(_In_ uint32_t Index, _In_ ID3D11SamplerState *pSampler) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pSampler); return E_FAIL; }
- STDMETHOD(UndoSetSampler)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return E_FAIL; }
- STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_SAMPLER_DESC *pDesc) override
- { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidSamplerVariable, ID3DX11EffectSamplerVariable, ID3DX11EffectVariable);
-};
-
-struct SEffectInvalidPass : public ID3DX11EffectPass
-{
-public:
- STDMETHOD_(bool, IsValid)() override { return false; }
- STDMETHOD(GetDesc)(_Out_ D3DX11_PASS_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- STDMETHOD(GetVertexShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
- STDMETHOD(GetGeometryShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
- STDMETHOD(GetPixelShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
- STDMETHOD(GetHullShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
- STDMETHOD(GetDomainShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
- STDMETHOD(GetComputeShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
-
- STDMETHOD(Apply)(_In_ uint32_t Flags, _In_ ID3D11DeviceContext* pContext) override
- { UNREFERENCED_PARAMETER(Flags); UNREFERENCED_PARAMETER(pContext); return E_FAIL; }
- STDMETHOD(ComputeStateBlockMask)(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask) override { UNREFERENCED_PARAMETER(pStateBlockMask); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidPass, ID3DX11EffectPass, IUnknown);
-};
-
-struct SEffectInvalidTechnique : public ID3DX11EffectTechnique
-{
-public:
- STDMETHOD_(bool, IsValid)() override { return false; }
- STDMETHOD(GetDesc)(_Out_ D3DX11_TECHNIQUE_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
-
- STDMETHOD_(ID3DX11EffectPass*, GetPassByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidPass; }
- STDMETHOD_(ID3DX11EffectPass*, GetPassByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidPass; }
-
- STDMETHOD(ComputeStateBlockMask)(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask) override { UNREFERENCED_PARAMETER(pStateBlockMask); return E_FAIL; }
-
- IUNKNOWN_IMP(SEffectInvalidTechnique, ID3DX11EffectTechnique, IUnknown);
-};
-
-struct SEffectInvalidGroup : public ID3DX11EffectGroup
-{
-public:
- STDMETHOD_(bool, IsValid)() override { return false; }
- STDMETHOD(GetDesc)(_Out_ D3DX11_GROUP_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
-
- STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidTechnique; }
- STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidTechnique; }
-
- IUNKNOWN_IMP(SEffectInvalidGroup, ID3DX11EffectGroup, IUnknown);
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Helper routines
-//////////////////////////////////////////////////////////////////////////
-
-// This is an annoying warning that pops up in retail builds because
-// the code that jumps to "lExit" is conditionally not compiled.
-// The only alternative is more #ifdefs in every function
-#pragma warning( disable : 4102 ) // 'label' : unreferenced label
-
-#define VERIFYPARAMETER(x) \
-{ if (!(x)) { DPF(0, "%s: Parameter " #x " was nullptr.", pFuncName); \
- __BREAK_ON_FAIL; hr = E_INVALIDARG; goto lExit; } }
-
-static HRESULT AnnotationInvalidSetCall(LPCSTR pFuncName)
-{
- DPF(0, "%s: Annotations are readonly", pFuncName);
- return D3DERR_INVALIDCALL;
-}
-
-static HRESULT ObjectSetRawValue()
-{
- DPF(0, "ID3DX11EffectVariable::SetRawValue: Objects do not support ths call; please use the specific object accessors instead.");
- return D3DERR_INVALIDCALL;
-}
-
-static HRESULT ObjectGetRawValue()
-{
- DPF(0, "ID3DX11EffectVariable::GetRawValue: Objects do not support ths call; please use the specific object accessors instead.");
- return D3DERR_INVALIDCALL;
-}
-
-ID3DX11EffectConstantBuffer * NoParentCB();
-
-ID3DX11EffectVariable * GetAnnotationByIndexHelper(_In_z_ const char *pClassName, _In_ uint32_t Index,
- _In_ uint32_t AnnotationCount, _In_reads_(AnnotationCount) SAnnotation *pAnnotations);
-
-ID3DX11EffectVariable * GetAnnotationByNameHelper(_In_z_ const char *pClassName, _In_z_ LPCSTR Name,
- _In_ uint32_t AnnotationCount, _In_reads_(AnnotationCount) SAnnotation *pAnnotations);
-
-template<typename SVarType>
-_Success_(return)
-bool GetVariableByIndexHelper(_In_ uint32_t Index, _In_ uint32_t VariableCount, _In_reads_(VariableCount) SVarType *pVariables,
- _In_opt_ uint8_t *pBaseAddress, _Outptr_ SVarType **ppMember, _Outptr_ void **ppDataPtr)
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetMemberByIndex";
-
- if (Index >= VariableCount)
- {
- DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, VariableCount);
- return false;
- }
-
- *ppMember = pVariables + Index;
- *ppDataPtr = pBaseAddress + (*ppMember)->Data.Offset;
- return true;
-}
-
-template<typename SVarType>
-_Success_(return)
-bool GetVariableByNameHelper(_In_z_ LPCSTR Name, _In_ uint32_t VariableCount, _In_reads_(VariableCount) SVarType *pVariables,
- _In_opt_ uint8_t *pBaseAddress, _Outptr_ SVarType **ppMember, _Outptr_ void **ppDataPtr, _Out_ uint32_t* pIndex)
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetMemberByName";
-
- if (nullptr == Name)
- {
- DPF(0, "%s: Parameter Name was nullptr.", pFuncName);
- return false;
- }
-
- bool bHasSuper = false;
-
- for (uint32_t i = 0; i < VariableCount; ++ i)
- {
- *ppMember = pVariables + i;
- assert((*ppMember)->pName != 0);
- _Analysis_assume_((*ppMember)->pName != 0);
- if (strcmp((*ppMember)->pName, Name) == 0)
- {
- *ppDataPtr = pBaseAddress + (*ppMember)->Data.Offset;
- *pIndex = i;
- return true;
- }
- else if (i == 0 &&
- (*ppMember)->pName[0] == '$' &&
- strcmp((*ppMember)->pName, "$super") == 0)
- {
- bHasSuper = true;
- }
- }
-
- if (bHasSuper)
- {
- SVarType* pSuper = pVariables;
-
- return GetVariableByNameHelper<SVarType>(Name,
- pSuper->pType->StructType.Members,
- (SVarType*)pSuper->pType->StructType.pMembers,
- pBaseAddress + pSuper->Data.Offset,
- ppMember,
- ppDataPtr,
- pIndex);
- }
-
- DPF(0, "%s: Variable [%s] not found", pFuncName, Name);
- return false;
-}
-
-template<typename SVarType>
-_Success_(return)
-bool GetVariableBySemanticHelper(_In_z_ LPCSTR Semantic, _In_ uint32_t VariableCount, _In_reads_(VariableCount) SVarType *pVariables,
- _In_opt_ uint8_t *pBaseAddress, _Outptr_ SVarType **ppMember, _Outptr_ void **ppDataPtr, _Out_ uint32_t* pIndex)
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetMemberBySemantic";
-
- if (nullptr == Semantic)
- {
- DPF(0, "%s: Parameter Semantic was nullptr.", pFuncName);
- return false;
- }
-
- for (uint32_t i = 0; i < VariableCount; ++ i)
- {
- *ppMember = pVariables + i;
- if (nullptr != (*ppMember)->pSemantic &&
- _stricmp((*ppMember)->pSemantic, Semantic) == 0)
- {
- *ppDataPtr = pBaseAddress + (*ppMember)->Data.Offset;
- *pIndex = i;
- return true;
- }
- }
-
- DPF(0, "%s: Variable with semantic [%s] not found", pFuncName, Semantic);
- return false;
-}
-
-inline bool AreBoundsValid(_In_ uint32_t Offset, _In_ uint32_t Count, _In_ const void *pData, _In_ const SType *pType, _In_ uint32_t TotalUnpackedSize)
-{
- if (Count == 0) return true;
- uint32_t singleElementSize = pType->GetTotalUnpackedSize(true);
- assert(singleElementSize <= pType->Stride);
-
- return ((Offset + Count >= Offset) &&
- ((Offset + Count) < ((uint32_t)-1) / pType->Stride) &&
- (Count * pType->Stride + (uint8_t*)pData >= (uint8_t*)pData) &&
- ((Offset + Count - 1) * pType->Stride + singleElementSize <= TotalUnpackedSize));
-}
-
-// Note that the branches in this code is based on template parameters and will be compiled out
-template<ETemplateVarType SourceType, ETemplateVarType DestType, typename SRC_TYPE, bool ValidatePtr>
-__forceinline HRESULT CopyScalarValue(_In_ SRC_TYPE SrcValue, _Out_ void *pDest, _In_z_ const char *pFuncName)
-{
- HRESULT hr = S_OK;
-#ifdef _DEBUG
- if (ValidatePtr)
- VERIFYPARAMETER(pDest);
-#else
- UNREFERENCED_PARAMETER(pFuncName);
-#endif
-
- switch (SourceType)
- {
- case ETVT_Bool:
- switch (DestType)
- {
- case ETVT_Bool:
- *(int*)pDest = (SrcValue != 0) ? -1 : 0;
- break;
-
- case ETVT_Int:
- *(int*)pDest = SrcValue ? 1 : 0;
- break;
-
- case ETVT_Float:
- *(float*)pDest = SrcValue ? 1.0f : 0.0f;
- break;
-
- case ETVT_bool:
- *(bool*)pDest = (SrcValue != 0) ? true : false;
- break;
-
- default:
- assert(0);
- }
- break;
-
- case ETVT_Int:
- switch (DestType)
- {
- case ETVT_Bool:
- *(int*)pDest = (SrcValue != 0) ? -1 : 0;
- break;
-
- case ETVT_Int:
- *(int*)pDest = (int) SrcValue;
- break;
-
- case ETVT_Float:
- *(float*)pDest = (float)(SrcValue);
- break;
-
- case ETVT_bool:
- *(bool*)pDest = (SrcValue != 0) ? true : false;
- break;
-
- default:
- assert(0);
- }
- break;
-
- case ETVT_Float:
- switch (DestType)
- {
- case ETVT_Bool:
- *(int*)pDest = (SrcValue != 0.0f) ? -1 : 0;
- break;
-
- case ETVT_Int:
- *(int*)pDest = (int) (SrcValue);
- break;
-
- case ETVT_Float:
- *(float*)pDest = (float) SrcValue;
- break;
-
- case ETVT_bool:
- *(bool*)pDest = (SrcValue != 0.0f) ? true : false;
- break;
-
- default:
- assert(0);
- }
- break;
-
- case ETVT_bool:
- switch (DestType)
- {
- case ETVT_Bool:
- *(int*)pDest = SrcValue ? -1 : 0;
- break;
-
- case ETVT_Int:
- *(int*)pDest = SrcValue ? 1 : 0;
- break;
-
- case ETVT_Float:
- *(float*)pDest = SrcValue ? 1.0f : 0.0f;
- break;
-
- case ETVT_bool:
- *(bool*)pDest = (SrcValue != 0) ? true : false;
- break;
-
- default:
- assert(0);
- }
- break;
-
- default:
- assert(0);
- }
-
-lExit:
- return hr;
-}
-
-#pragma warning(push)
-#pragma warning( disable : 6103 )
-template<ETemplateVarType SourceType, ETemplateVarType DestType, typename SRC_TYPE, typename DEST_TYPE>
-inline HRESULT SetScalarArray(_In_reads_(Count) const SRC_TYPE *pSrcValues, _Out_writes_(Count) DEST_TYPE *pDestValues,
- _In_ uint32_t Offset, _In_ uint32_t Count,
- _In_ const SType *pType, _In_ uint32_t TotalUnpackedSize, _In_z_ const char *pFuncName)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- VERIFYPARAMETER(pSrcValues);
-
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pSrcValues, pType, TotalUnpackedSize))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#else
- UNREFERENCED_PARAMETER(TotalUnpackedSize);
- UNREFERENCED_PARAMETER(pFuncName);
-#endif
-
- uint32_t i, j, delta = pType->NumericType.IsPackedArray ? 1 : SType::c_ScalarsPerRegister;
- pDestValues += Offset * delta;
- for (i = 0, j = 0; j < Count; i += delta, ++ j)
- {
- // pDestValues[i] = (DEST_TYPE)pSrcValues[j];
- CopyScalarValue<SourceType, DestType, SRC_TYPE, false>(pSrcValues[j], &pDestValues[i], "SetScalarArray");
- }
-
-lExit:
- return hr;
-}
-#pragma warning(pop)
-
-#pragma warning( disable : 6103 )
-template<ETemplateVarType SourceType, ETemplateVarType DestType, typename SRC_TYPE, typename DEST_TYPE>
-inline HRESULT GetScalarArray(_In_reads_(Count) SRC_TYPE *pSrcValues, _Out_writes_(Count) DEST_TYPE *pDestValues,
- _In_ uint32_t Offset, _In_ uint32_t Count,
- _In_ const SType *pType, _In_ uint32_t TotalUnpackedSize, _In_z_ const char *pFuncName)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- VERIFYPARAMETER(pDestValues);
-
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pDestValues, pType, TotalUnpackedSize))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#else
- UNREFERENCED_PARAMETER(TotalUnpackedSize);
- UNREFERENCED_PARAMETER(pFuncName);
-#endif
-
- uint32_t i, j, delta = pType->NumericType.IsPackedArray ? 1 : SType::c_ScalarsPerRegister;
- pSrcValues += Offset * delta;
- for (i = 0, j = 0; j < Count; i += delta, ++ j)
- {
- // pDestValues[j] = (DEST_TYPE)pSrcValues[i];
- CopyScalarValue<SourceType, DestType, SRC_TYPE, false>(pSrcValues[i], &pDestValues[j], "GetScalarArray");
- }
-
-lExit:
- return hr;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-// TVariable - implements type casting and member/element retrieval
-//////////////////////////////////////////////////////////////////////////
-
-// requires that IBaseInterface contain SVariable's fields and support ID3DX11EffectVariable
-template<typename IBaseInterface>
-struct TVariable : public IBaseInterface
-{
- STDMETHOD_(bool, IsValid)() override { return true; }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index)
- {
- SVariable *pMember;
- UDataPointer dataPtr;
- TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity2 = GetTopLevelEntity();
-
- if (((ID3DX11Effect*)pTopLevelEntity2->pEffect)->IsOptimized())
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberByIndex: Cannot get members; effect has been Optimize()'ed");
- return &g_InvalidScalarVariable;
- }
-
- if (pType->VarType != EVT_Struct)
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberByIndex: Variable is not a structure");
- return &g_InvalidScalarVariable;
- }
-
- if (!GetVariableByIndexHelper<SVariable>(Index, pType->StructType.Members, pType->StructType.pMembers,
- Data.pNumeric, &pMember, &dataPtr.pGeneric))
- {
- return &g_InvalidScalarVariable;
- }
-
- return pTopLevelEntity2->pEffect->CreatePooledVariableMemberInterface(pTopLevelEntity2, pMember, dataPtr, false, Index);
- }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberByName)(_In_z_ LPCSTR Name)
- {
- SVariable *pMember;
- UDataPointer dataPtr;
- uint32_t index;
- TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity2 = GetTopLevelEntity();
-
- if (pTopLevelEntity2->pEffect->IsOptimized())
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberByName: Cannot get members; effect has been Optimize()'ed");
- return &g_InvalidScalarVariable;
- }
-
- if (pType->VarType != EVT_Struct)
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberByName: Variable is not a structure");
- return &g_InvalidScalarVariable;
- }
-
- if (!GetVariableByNameHelper<SVariable>(Name, pType->StructType.Members, pType->StructType.pMembers,
- Data.pNumeric, &pMember, &dataPtr.pGeneric, &index))
- {
- return &g_InvalidScalarVariable;
-
- }
-
- return pTopLevelEntity2->pEffect->CreatePooledVariableMemberInterface(pTopLevelEntity2, pMember, dataPtr, false, index);
- }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetMemberBySemantic)(_In_z_ LPCSTR Semantic)
- {
- SVariable *pMember;
- UDataPointer dataPtr;
- uint32_t index;
- TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity2 = GetTopLevelEntity();
-
- if (pTopLevelEntity2->pEffect->IsOptimized())
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberBySemantic: Cannot get members; effect has been Optimize()'ed");
- return &g_InvalidScalarVariable;
- }
-
- if (pType->VarType != EVT_Struct)
- {
- DPF(0, "ID3DX11EffectVariable::GetMemberBySemantic: Variable is not a structure");
- return &g_InvalidScalarVariable;
- }
-
- if (!GetVariableBySemanticHelper<SVariable>(Semantic, pType->StructType.Members, pType->StructType.pMembers,
- Data.pNumeric, &pMember, &dataPtr.pGeneric, &index))
- {
- return &g_InvalidScalarVariable;
-
- }
-
- return pTopLevelEntity2->pEffect->CreatePooledVariableMemberInterface(pTopLevelEntity2, pMember, dataPtr, false, index);
- }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetElement)(_In_ uint32_t Index)
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetElement";
- TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity2 = GetTopLevelEntity();
- UDataPointer dataPtr;
-
- if (pTopLevelEntity2->pEffect->IsOptimized())
- {
- DPF(0, "ID3DX11EffectVariable::GetElement: Cannot get element; effect has been Optimize()'ed");
- return &g_InvalidScalarVariable;
- }
-
- if (!IsArray())
- {
- DPF(0, "%s: This interface does not refer to an array", pFuncName);
- return &g_InvalidScalarVariable;
- }
-
- if (Index >= pType->Elements)
- {
- DPF(0, "%s: Invalid element index (%u, total: %u)", pFuncName, Index, pType->Elements);
- return &g_InvalidScalarVariable;
- }
-
- if (pType->BelongsInConstantBuffer())
- {
- dataPtr.pGeneric = Data.pNumeric + pType->Stride * Index;
- }
- else
- {
- dataPtr.pGeneric = GetBlockByIndex(pType->VarType, pType->ObjectType, Data.pGeneric, Index);
- if (nullptr == dataPtr.pGeneric)
- {
- DPF(0, "%s: Internal error", pFuncName);
- return &g_InvalidScalarVariable;
- }
- }
-
- return pTopLevelEntity2->pEffect->CreatePooledVariableMemberInterface(pTopLevelEntity2, (SVariable *) this, dataPtr, true, Index);
- }
-
- STDMETHOD_(ID3DX11EffectScalarVariable*, AsScalar)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsScalar";
-
- if (pType->VarType != EVT_Numeric ||
- pType->NumericType.NumericLayout != ENL_Scalar)
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidScalarVariable;
- }
-
- return (ID3DX11EffectScalarVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectVectorVariable*, AsVector)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsVector";
-
- if (pType->VarType != EVT_Numeric ||
- pType->NumericType.NumericLayout != ENL_Vector)
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidVectorVariable;
- }
-
- return (ID3DX11EffectVectorVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectMatrixVariable*, AsMatrix)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsMatrix";
-
- if (pType->VarType != EVT_Numeric ||
- pType->NumericType.NumericLayout != ENL_Matrix)
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidMatrixVariable;
- }
-
- return (ID3DX11EffectMatrixVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectStringVariable*, AsString)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsString";
-
- if (!pType->IsObjectType(EOT_String))
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidStringVariable;
- }
-
- return (ID3DX11EffectStringVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectClassInstanceVariable*, AsClassInstance)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsClassInstance";
-
- if (!pType->IsClassInstance() )
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidClassInstanceVariable;
- }
- else if( pMemberData == nullptr )
- {
- DPF(0, "%s: Non-global class instance variables (members of structs or classes) and class instances "
- "inside tbuffers are not supported.", pFuncName );
- return &g_InvalidClassInstanceVariable;
- }
-
- return (ID3DX11EffectClassInstanceVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectInterfaceVariable*, AsInterface)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsInterface";
-
- if (!pType->IsInterface())
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidInterfaceVariable;
- }
-
- return (ID3DX11EffectInterfaceVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectShaderResourceVariable*, AsShaderResource)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShaderResource";
-
- if (!pType->IsShaderResource())
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidShaderResourceVariable;
- }
-
- return (ID3DX11EffectShaderResourceVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectUnorderedAccessViewVariable*, AsUnorderedAccessView)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsUnorderedAccessView";
-
- if (!pType->IsUnorderedAccessView())
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidUnorderedAccessViewVariable;
- }
-
- return (ID3DX11EffectUnorderedAccessViewVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectRenderTargetViewVariable*, AsRenderTargetView)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRenderTargetView";
-
- if (!pType->IsRenderTargetView())
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidRenderTargetViewVariable;
- }
-
- return (ID3DX11EffectRenderTargetViewVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectDepthStencilViewVariable*, AsDepthStencilView)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencilView";
-
- if (!pType->IsDepthStencilView())
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidDepthStencilViewVariable;
- }
-
- return (ID3DX11EffectDepthStencilViewVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectConstantBuffer*, AsConstantBuffer)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsConstantBuffer";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidConstantBuffer;
- }
-
- STDMETHOD_(ID3DX11EffectShaderVariable*, AsShader)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShader";
-
- if (!pType->IsShader())
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidShaderVariable;
- }
-
- return (ID3DX11EffectShaderVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectBlendVariable*, AsBlend)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsBlend";
-
- if (!pType->IsObjectType(EOT_Blend))
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidBlendVariable;
- }
-
- return (ID3DX11EffectBlendVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectDepthStencilVariable*, AsDepthStencil)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencil";
-
- if (!pType->IsObjectType(EOT_DepthStencil))
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidDepthStencilVariable;
- }
-
- return (ID3DX11EffectDepthStencilVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectRasterizerVariable*, AsRasterizer)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRasterizer";
-
- if (!pType->IsObjectType(EOT_Rasterizer))
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidRasterizerVariable;
- }
-
- return (ID3DX11EffectRasterizerVariable *) this;
- }
-
- STDMETHOD_(ID3DX11EffectSamplerVariable*, AsSampler)()
- {
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsSampler";
-
- if (!pType->IsSampler())
- {
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidSamplerVariable;
- }
-
- return (ID3DX11EffectSamplerVariable *) this;
- }
-
- // Numeric variables should override this
- STDMETHOD(SetRawValue)(_In_reads_bytes_(Count) const void *pData, _In_ uint32_t Offset, _In_ uint32_t Count)
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return ObjectSetRawValue(); }
- STDMETHOD(GetRawValue)(_Out_writes_(Count) void *pData, _In_ uint32_t Offset, _In_ uint32_t Count)
- { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return ObjectGetRawValue(); }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// TTopLevelVariable - functionality for annotations and global variables
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TTopLevelVariable : public SVariable, public IBaseInterface
-{
- // Required to create member/element variable interfaces
- CEffect *pEffect;
-
- CEffect* GetEffect()
- {
- return pEffect;
- }
-
- TTopLevelVariable() noexcept :
- pEffect(nullptr)
- {
- }
-
- uint32_t GetTotalUnpackedSize()
- {
- return ((SType*)pType)->GetTotalUnpackedSize(false);
- }
-
- STDMETHOD_(ID3DX11EffectType*, GetType)()
- {
- return (ID3DX11EffectType*)(SType*)pType;
- }
-
- TTopLevelVariable<ID3DX11EffectVariable> * GetTopLevelEntity()
- {
- return (TTopLevelVariable<ID3DX11EffectVariable> *)this;
- }
-
- bool IsArray()
- {
- return (pType->Elements > 0);
- }
-
-};
-
-//////////////////////////////////////////////////////////////////////////
-// TMember - functionality for structure/array members of other variables
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TMember : public SVariable, public IBaseInterface
-{
- // Indicates that this is a single element of a containing array
- uint32_t IsSingleElement : 1;
-
- // Required to create member/element variable interfaces
- TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity;
-
- TMember() noexcept :
- IsSingleElement(false),
- pTopLevelEntity(nullptr)
- {
- }
-
- CEffect* GetEffect()
- {
- return pTopLevelEntity->pEffect;
- }
-
- uint32_t GetTotalUnpackedSize()
- {
- return pType->GetTotalUnpackedSize(IsSingleElement);
- }
-
- STDMETHOD_(ID3DX11EffectType*, GetType)() override
- {
- if (IsSingleElement)
- {
- return pTopLevelEntity->pEffect->CreatePooledSingleElementTypeInterface( pType );
- }
- else
- {
- return (ID3DX11EffectType*) pType;
- }
- }
-
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override
- {
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetDesc";
-
- VERIFYPARAMETER(pDesc != nullptr);
-
- pDesc->Name = pName;
- pDesc->Semantic = pSemantic;
- pDesc->Flags = 0;
-
- if (pTopLevelEntity->pEffect->IsReflectionData(pTopLevelEntity))
- {
- // Is part of an annotation
- assert(pTopLevelEntity->pEffect->IsReflectionData(Data.pGeneric));
- pDesc->Annotations = 0;
- pDesc->BufferOffset = 0;
- pDesc->Flags |= D3DX11_EFFECT_VARIABLE_ANNOTATION;
- }
- else
- {
- // Is part of a global variable
- assert(pTopLevelEntity->pEffect->IsRuntimeData(pTopLevelEntity));
- if (!pTopLevelEntity->pType->IsObjectType(EOT_String))
- {
- // strings are funny; their data is reflection data, so ignore those
- assert(pTopLevelEntity->pEffect->IsRuntimeData(Data.pGeneric));
- }
-
- pDesc->Annotations = ((TGlobalVariable<ID3DX11Effect>*)pTopLevelEntity)->AnnotationCount;
-
- SConstantBuffer *pCB = ((TGlobalVariable<ID3DX11Effect>*)pTopLevelEntity)->pCB;
-
- if (pType->BelongsInConstantBuffer())
- {
- assert(pCB != 0);
- _Analysis_assume_(pCB != 0);
- UINT_PTR offset = Data.pNumeric - pCB->pBackingStore;
- assert(offset == (uint32_t)offset);
- pDesc->BufferOffset = (uint32_t)offset;
- assert(pDesc->BufferOffset >= 0 && pDesc->BufferOffset + GetTotalUnpackedSize() <= pCB->Size);
- }
- else
- {
- assert(pCB == nullptr);
- pDesc->BufferOffset = 0;
- }
- }
-
-lExit:
- return hr;
- }
-
- TTopLevelVariable<ID3DX11EffectVariable> * GetTopLevelEntity()
- {
- return pTopLevelEntity;
- }
-
- bool IsArray()
- {
- return (pType->Elements > 0 && !IsSingleElement);
- }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override
- { return pTopLevelEntity->GetAnnotationByIndex(Index); }
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override
- { return pTopLevelEntity->GetAnnotationByName(Name); }
-
- STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override
- { return pTopLevelEntity->GetParentConstantBuffer(); }
-
- // Annotations should never be able to go down this codepath
- void DirtyVariable()
- {
- // make sure to call the global variable's version of dirty variable
- ((TGlobalVariable<ID3DX11EffectVariable>*)pTopLevelEntity)->DirtyVariable();
- }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// TAnnotation - functionality for top level annotations
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TAnnotation : public TVariable<TTopLevelVariable<IBaseInterface> >
-{
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override
- {
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetDesc";
-
- VERIFYPARAMETER(pDesc != nullptr);
-
- pDesc->Name = pName;
- pDesc->Semantic = pSemantic;
- pDesc->Flags = D3DX11_EFFECT_VARIABLE_ANNOTATION;
- pDesc->Annotations = 0;
- pDesc->BufferOffset = 0;
- pDesc->ExplicitBindPoint = 0;
-
-lExit:
- return hr;
-
- }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override
- {
- UNREFERENCED_PARAMETER(Index);
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetAnnotationByIndex";
- DPF(0, "%s: Only variables may have annotations", pFuncName);
- return &g_InvalidScalarVariable;
- }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override
- {
- UNREFERENCED_PARAMETER(Name);
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetAnnotationByName";
- DPF(0, "%s: Only variables may have annotations", pFuncName);
- return &g_InvalidScalarVariable;
- }
-
- STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override
- { return NoParentCB(); }
-
- void DirtyVariable()
- {
- assert(0);
- }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// TGlobalVariable - functionality for top level global variables
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TGlobalVariable : public TVariable<TTopLevelVariable<IBaseInterface> >
-{
- Timer LastModifiedTime;
-
- // if numeric, pointer to the constant buffer where this variable lives
- SConstantBuffer *pCB;
-
- uint32_t AnnotationCount;
- SAnnotation *pAnnotations;
-
- TGlobalVariable() noexcept :
- LastModifiedTime(0),
- pCB(nullptr),
- AnnotationCount(0),
- pAnnotations(nullptr)
- {
- }
-
- STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc)
- {
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetDesc";
-
- VERIFYPARAMETER(pDesc != nullptr);
-
- pDesc->Name = pName;
- pDesc->Semantic = pSemantic;
- pDesc->Flags = 0;
- pDesc->Annotations = AnnotationCount;
-
- if (pType->BelongsInConstantBuffer())
- {
- assert(pCB != 0);
- _Analysis_assume_(pCB != 0);
- UINT_PTR offset = Data.pNumeric - pCB->pBackingStore;
- assert(offset == (uint32_t)offset);
- pDesc->BufferOffset = (uint32_t)offset;
- assert(pDesc->BufferOffset >= 0 && pDesc->BufferOffset + GetTotalUnpackedSize() <= pCB->Size );
- }
- else
- {
- assert(pCB == nullptr);
- pDesc->BufferOffset = 0;
- }
-
- if (ExplicitBindPoint != -1)
- {
- pDesc->ExplicitBindPoint = ExplicitBindPoint;
- pDesc->Flags |= D3DX11_EFFECT_VARIABLE_EXPLICIT_BIND_POINT;
- }
- else
- {
- pDesc->ExplicitBindPoint = 0;
- }
-
-lExit:
- return hr;
- }
-
- // these are all well defined for global vars
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index)
- {
- return GetAnnotationByIndexHelper("ID3DX11EffectVariable", Index, AnnotationCount, pAnnotations);
- }
-
- STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name)
- {
- return GetAnnotationByNameHelper("ID3DX11EffectVariable", Name, AnnotationCount, pAnnotations);
- }
-
- STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)()
- {
- if (nullptr != pCB)
- {
- assert(pType->BelongsInConstantBuffer());
- return (ID3DX11EffectConstantBuffer*)pCB;
- }
- else
- {
- assert(!pType->BelongsInConstantBuffer());
- return &g_InvalidConstantBuffer;
- }
- }
-
- inline void DirtyVariable()
- {
- assert(pCB != 0);
- _Analysis_assume_(pCB != 0);
- pCB->IsDirty = true;
- LastModifiedTime = pEffect->GetCurrentTime();
- }
-
-};
-
-//////////////////////////////////////////////////////////////////////////
-// TNumericVariable - implements raw set/get functionality
-//////////////////////////////////////////////////////////////////////////
-
-// IMPORTANT NOTE: All of these numeric & object aspect classes MUST NOT
-// add data members to the base variable classes. Otherwise type sizes
-// will disagree between object & numeric variables and we cannot eaily
-// create arrays of global variables using SGlobalVariable
-
-// Requires that IBaseInterface have SVariable's members, GetTotalUnpackedSize() and DirtyVariable()
-template<typename IBaseInterface, bool IsAnnotation>
-struct TNumericVariable : public IBaseInterface
-{
- STDMETHOD(SetRawValue)(_In_reads_bytes_(ByteCount) const void *pData, _In_ uint32_t ByteOffset, _In_ uint32_t ByteCount) override
- {
- if (IsAnnotation)
- {
- return AnnotationInvalidSetCall("ID3DX11EffectVariable::SetRawValue");
- }
- else
- {
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectVariable::SetRawValue";
-
- VERIFYPARAMETER(pData);
-
- if ((ByteOffset + ByteCount < ByteOffset) ||
- (ByteCount + (uint8_t*)pData < (uint8_t*)pData) ||
- ((ByteOffset + ByteCount) > GetTotalUnpackedSize()))
- {
- // overflow of some kind
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- DirtyVariable();
- memcpy(Data.pNumeric + ByteOffset, pData, ByteCount);
-
-lExit:
- return hr;
- }
- }
-
- STDMETHOD(GetRawValue)(_Out_writes_bytes_(ByteCount) void *pData, _In_ uint32_t ByteOffset, _In_ uint32_t ByteCount) override
- {
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectVariable::GetRawValue";
-
- VERIFYPARAMETER(pData);
-
- if ((ByteOffset + ByteCount < ByteOffset) ||
- (ByteCount + (uint8_t*)pData < (uint8_t*)pData) ||
- ((ByteOffset + ByteCount) > GetTotalUnpackedSize()))
- {
- // overflow of some kind
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- memcpy(pData, Data.pNumeric + ByteOffset, ByteCount);
-
-lExit:
- return hr;
- }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectScalarVariable (TFloatScalarVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface, bool IsAnnotation>
-struct TFloatScalarVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
-{
- STDMETHOD(SetFloat)(_In_ const float Value) override;
- STDMETHOD(GetFloat)(_Out_ float *pValue) override;
-
- STDMETHOD(SetFloatArray)(_In_reads_(Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetFloatArray)(_Out_writes_(Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(SetInt)(_In_ const int Value) override;
- STDMETHOD(GetInt)(_Out_ int *pValue) override;
-
- STDMETHOD(SetIntArray)(_In_reads_(Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetIntArray)(_Out_writes_(Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(SetBool)(_In_ const bool Value) override;
- STDMETHOD(GetBool)(_Out_ bool *pValue) override;
-
- STDMETHOD(SetBoolArray)(_In_reads_(Count) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetBoolArray)(_Out_writes_(Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_Float, ETVT_Float, float, false>(Value, Data.pNumericFloat, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetFloat(float *pValue)
-{
- return CopyScalarValue<ETVT_Float, ETVT_Float, float, true>(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetFloat");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_Float, ETVT_Float, float, float>(pData, Data.pNumericFloat, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Float, ETVT_Float, float, float>(Data.pNumericFloat, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetInt(const int Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_Int, ETVT_Float, int, false>(Value, Data.pNumericFloat, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetInt(int *pValue)
-{
- return CopyScalarValue<ETVT_Float, ETVT_Int, float, true>(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetInt");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_Int, ETVT_Float, int, float>(pData, Data.pNumericFloat, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetIntArray(int *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Float, ETVT_Int, float, int>(Data.pNumericFloat, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetBool(const bool Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_bool, ETVT_Float, bool, false>(Value, Data.pNumericFloat, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetBool(bool *pValue)
-{
- return CopyScalarValue<ETVT_Float, ETVT_bool, float, true>(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetBool");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_bool, ETVT_Float, bool, float>(pData, Data.pNumericFloat, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Float, ETVT_bool, float, bool>(Data.pNumericFloat, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray");
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectScalarVariable (TIntScalarVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface, bool IsAnnotation>
-struct TIntScalarVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
-{
- STDMETHOD(SetFloat)(_In_ const float Value) override;
- STDMETHOD(GetFloat)(_Out_ float *pValue) override;
-
- STDMETHOD(SetFloatArray)(_In_reads_(Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetFloatArray)(_Out_writes_(Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(SetInt)(_In_ const int Value) override;
- STDMETHOD(GetInt)(_Out_ int *pValue) override;
-
- STDMETHOD(SetIntArray)(_In_reads_(Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetIntArray)(_Out_writes_(Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(SetBool)(_In_ const bool Value) override;
- STDMETHOD(GetBool)(_Out_ bool *pValue) override;
-
- STDMETHOD(SetBoolArray)(_In_reads_(Count) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetBoolArray)(_Out_writes_(Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_Float, ETVT_Int, float, false>(Value, Data.pNumericInt, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetFloat(float *pValue)
-{
- return CopyScalarValue<ETVT_Int, ETVT_Float, int, true>(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetFloat");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_Float, ETVT_Int, float, int>(pData, Data.pNumericInt, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Int, ETVT_Float, int, float>(Data.pNumericInt, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetInt(const int Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_Int, ETVT_Int, int, false>(Value, Data.pNumericInt, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetInt(int *pValue)
-{
- return CopyScalarValue<ETVT_Int, ETVT_Int, int, true>(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetInt");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_Int, ETVT_Int, int, int>(pData, Data.pNumericInt, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetIntArray(int *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Int, ETVT_Int, int, int>(Data.pNumericInt, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetBool(const bool Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_bool, ETVT_Int, bool, false>(Value, Data.pNumericInt, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetBool(bool *pValue)
-{
- return CopyScalarValue<ETVT_Int, ETVT_bool, int, true>(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetBool");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_bool, ETVT_Int, bool, int>(pData, Data.pNumericInt, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Int, ETVT_bool, int, bool>(Data.pNumericInt, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray");
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectScalarVariable (TBoolScalarVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface, bool IsAnnotation>
-struct TBoolScalarVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
-{
- STDMETHOD(SetFloat)(_In_ const float Value) override;
- STDMETHOD(GetFloat)(_Out_ float *pValue) override;
-
- STDMETHOD(SetFloatArray)(_In_reads_(Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetFloatArray)(_Out_writes_(Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(SetInt)(_In_ const int Value) override;
- STDMETHOD(GetInt)(_Out_ int *pValue) override;
-
- STDMETHOD(SetIntArray)(_In_reads_(Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetIntArray)(_Out_writes_(Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(SetBool)(_In_ const bool Value) override;
- STDMETHOD(GetBool)(_Out_ bool *pValue) override;
-
- STDMETHOD(SetBoolArray)(_In_reads_(Count) const bool *pData, uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetBoolArray)(_Out_writes_(Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_Float, ETVT_Bool, float, false>(Value, Data.pNumericBool, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetFloat(float *pValue)
-{
- return CopyScalarValue<ETVT_Bool, ETVT_Float, BOOL, true>(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetFloat");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_Float, ETVT_Bool, float, BOOL>(pData, Data.pNumericBool, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Bool, ETVT_Float, BOOL, float>(Data.pNumericBool, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetInt(const int Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_Int, ETVT_Bool, int, false>(Value, Data.pNumericBool, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetInt(int *pValue)
-{
- return CopyScalarValue<ETVT_Bool, ETVT_Int, BOOL, true>(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetInt");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_Int, ETVT_Bool, int, BOOL>(pData, Data.pNumericBool, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetIntArray(int *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Bool, ETVT_Int, BOOL, int>(Data.pNumericBool, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetBool(const bool Value)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return CopyScalarValue<ETVT_bool, ETVT_Bool, bool, false>(Value, Data.pNumericBool, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetBool(bool *pValue)
-{
- return CopyScalarValue<ETVT_Bool, ETVT_bool, BOOL, true>(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetBool");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return SetScalarArray<ETVT_bool, ETVT_Bool, bool, BOOL>(pData, Data.pNumericBool, Offset, Count,
- pType, GetTotalUnpackedSize(), pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count)
-{
- return GetScalarArray<ETVT_Bool, ETVT_bool, BOOL, bool>(Data.pNumericBool, pData, Offset, Count,
- pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray");
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectVectorVariable (TVectorVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType >
-struct TVectorVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
-{
- STDMETHOD(SetBoolVector) (_In_reads_(4) const bool *pData) override;
- STDMETHOD(SetIntVector) (_In_reads_(4) const int *pData) override;
- STDMETHOD(SetFloatVector)(_In_reads_(4) const float *pData) override;
-
- STDMETHOD(GetBoolVector) (_Out_writes_(4) bool *pData) override;
- STDMETHOD(GetIntVector) (_Out_writes_(4) int *pData) override;
- STDMETHOD(GetFloatVector)(_Out_writes_(4) float *pData) override;
-
-
- STDMETHOD(SetBoolVectorArray) (_In_reads_(Count*4) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(SetIntVectorArray) (_In_reads_(Count*4) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(SetFloatVectorArray)(_In_reads_(Count*4) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(GetBoolVectorArray) (_Out_writes_(Count*4) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetIntVectorArray) (_Out_writes_(Count*4) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetFloatVectorArray)(_Out_writes_(Count*4) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-// Note that branches in this code is based on template parameters and will be compiled out
-#pragma warning (push)
-#pragma warning (disable : 6101)
-template <ETemplateVarType DestType, ETemplateVarType SourceType>
-void __forceinline CopyDataWithTypeConversion(_Out_ void *pDest,
- _In_ const void *pSource,
- _In_ size_t dstVecSize, _In_ size_t srcVecSize,
- _In_ size_t elementCount, _In_ size_t vecCount)
-{
- switch (SourceType)
- {
- case ETVT_Bool:
- switch (DestType)
- {
- case ETVT_Bool:
- for (size_t j=0; j<vecCount; j++)
- {
- memcpy(pDest, pSource, elementCount * SType::c_ScalarSize);
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_Int:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((int*)pDest)[i] = ((bool*)pSource)[i] ? -1 : 0;
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_Float:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((float*)pDest)[i] = ((bool*)pSource)[i] ? -1.0f : 0.0f;
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_bool:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((bool*)pDest)[i] = (((int*)pSource)[i] != 0) ? true : false;
-
- pDest = ((bool*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- default:
- assert(0);
- }
- break;
-
- case ETVT_Int:
- switch (DestType)
- {
- case ETVT_Bool:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((int*)pDest)[i] = (((int*)pSource)[i] != 0) ? -1 : 0;
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_Int:
- for (size_t j=0; j<vecCount; j++)
- {
- memcpy(pDest, pSource, elementCount * SType::c_ScalarSize);
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_Float:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((float*)pDest)[i] = (float)(((int*)pSource)[i]);
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_bool:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((bool*)pDest)[i] = (((int*)pSource)[i] != 0) ? true : false;
-
- pDest = ((bool*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- default:
- assert(0);
- }
- break;
-
- case ETVT_Float:
- switch (DestType)
- {
- case ETVT_Bool:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((int*)pDest)[i] = (((float*)pSource)[i] != 0.0f) ? -1 : 0;
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_Int:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((int*)pDest)[i] = (int)((float*)pSource)[i];
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_Float:
- for (size_t i=0; i<vecCount; i++)
- {
- memcpy( pDest, pSource, elementCount * SType::c_ScalarSize);
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_bool:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- ((bool*)pDest)[i] = (((float*)pSource)[i] != 0.0f) ? true : false;
-
- pDest = ((bool*) pDest) + dstVecSize;
- pSource = ((float*) pSource) + srcVecSize;
- }
- break;
-
- default:
- assert(0);
- }
- break;
-
- case ETVT_bool:
- switch (DestType)
- {
- case ETVT_Bool:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- reinterpret_cast<int*>(pDest)[i] = reinterpret_cast<const bool*>(pSource)[i] ? -1 : 0;
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((bool*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_Int:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- reinterpret_cast<int*>(pDest)[i] = reinterpret_cast<const bool*>(pSource)[i] ? -1 : 0;
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((bool*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_Float:
- for (size_t j=0; j<vecCount; j++)
- {
- for (size_t i=0; i<elementCount; i++)
- reinterpret_cast<float*>(pDest)[i] = reinterpret_cast<const bool*>(pSource)[i] ? -1.0f : 0.0f;
-
- pDest = ((float*) pDest) + dstVecSize;
- pSource = ((bool*) pSource) + srcVecSize;
- }
- break;
-
- case ETVT_bool:
- for (size_t j=0; j<vecCount; j++)
- {
- memcpy(pDest, pSource, elementCount);
-
- pDest = ((bool*) pDest) + dstVecSize;
- pSource = ((bool*) pSource) + srcVecSize;
- }
- break;
-
- default:
- assert(0);
- }
- break;
-
- default:
- assert(0);
- }
-}
-#pragma warning (pop)
-
-// Float Vector
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType >::SetFloatVector(const float *pData)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetFloatVector";
-
-#ifdef _DEBUG
- VERIFYPARAMETER(pData);
-#endif
-
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- CopyDataWithTypeConversion<BaseType, ETVT_Float>(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetFloatVector(float *pData)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVector";
-
-#ifdef _DEBUG
- VERIFYPARAMETER(pData);
-#endif
-
- CopyDataWithTypeConversion<ETVT_Float, BaseType>(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1);
-
-lExit:
- return hr;
-}
-
-// Int Vector
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType >::SetIntVector(const int *pData)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetIntVector";
-
-#ifdef _DEBUG
- VERIFYPARAMETER(pData);
-#endif
-
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- CopyDataWithTypeConversion<BaseType, ETVT_Int>(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetIntVector(int *pData)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetIntVector";
- VERIFYPARAMETER(pData);
-#endif
-
- CopyDataWithTypeConversion<ETVT_Int, BaseType>(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1);
-
-lExit:
- return hr;
-}
-
-// Bool Vector
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType >::SetBoolVector(const bool *pData)
-{
- HRESULT hr = S_OK;
-
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetBoolVector";
-
-#ifdef _DEBUG
- VERIFYPARAMETER(pData);
-#endif
-
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- CopyDataWithTypeConversion<BaseType, ETVT_bool>(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetBoolVector(bool *pData)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetBoolVector";
- VERIFYPARAMETER(pData);
-#endif
-
- CopyDataWithTypeConversion<ETVT_bool, BaseType>(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1);
-
-lExit:
- return hr;
-}
-
-// Vector Arrays /////////////////////////////////////////////////////////
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::SetFloatVectorArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetFloatVectorArray";
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- // ensure we don't write over the padding at the end of the vector array
- CopyDataWithTypeConversion<BaseType, ETVT_Float>(Data.pVector + Offset, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetFloatVectorArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVectorArray";
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- // ensure we don't read past the end of the vector array
- CopyDataWithTypeConversion<ETVT_Float, BaseType>(pData, Data.pVector + Offset, pType->NumericType.Columns, 4, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
-
-lExit:
- return hr;
-}
-
-// int
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::SetIntVectorArray(const int *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetIntVectorArray";
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- // ensure we don't write over the padding at the end of the vector array
- CopyDataWithTypeConversion<BaseType, ETVT_Int>(Data.pVector + Offset, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetIntVectorArray(int *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetIntVectorArray";
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- // ensure we don't read past the end of the vector array
- CopyDataWithTypeConversion<ETVT_Int, BaseType>(pData, Data.pVector + Offset, pType->NumericType.Columns, 4, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
-
-lExit:
- return hr;
-}
-
-// bool
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::SetBoolVectorArray(const bool *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetBoolVectorArray";
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- // ensure we don't write over the padding at the end of the vector array
- CopyDataWithTypeConversion<BaseType, ETVT_bool>(Data.pVector + Offset, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
-_Use_decl_annotations_
-HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetBoolVectorArray(bool *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetBoolVectorArray";
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- // ensure we don't read past the end of the vector array
- CopyDataWithTypeConversion<ETVT_bool, BaseType>(pData, Data.pVector + Offset, pType->NumericType.Columns, 4, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectVector4Variable (TVectorVariable implementation) [OPTIMIZED]
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TVector4Variable : public TVectorVariable<IBaseInterface, false, ETVT_Float>
-{
- STDMETHOD(SetFloatVector)(_In_reads_(4) const float *pData) override;
- STDMETHOD(GetFloatVector)(_Out_writes_(4) float *pData) override;
-
- STDMETHOD(SetFloatVectorArray)(_In_reads_(Count*4) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetFloatVectorArray)(_Out_writes_(Count*4) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TVector4Variable<IBaseInterface>::SetFloatVector(const float *pData)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetFloatVector";
-
-#ifdef _DEBUG
- VERIFYPARAMETER(pData);
-#endif
-
- DirtyVariable();
- Data.pVector[0] = ((CEffectVector4*) pData)[0];
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TVector4Variable<IBaseInterface>::GetFloatVector(float *pData)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVector";
-
-#ifdef _DEBUG
- VERIFYPARAMETER(pData);
-#endif
-
- memcpy(pData, Data.pVector, pType->NumericType.Columns * SType::c_ScalarSize);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TVector4Variable<IBaseInterface>::SetFloatVectorArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetFloatVectorArray";
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- DirtyVariable();
- // ensure we don't write over the padding at the end of the vector array
- memcpy(Data.pVector + Offset, pData,
- std::min<size_t>(Count * sizeof(CEffectVector4), pType->TotalSize - (Offset * sizeof(CEffectVector4))));
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TVector4Variable<IBaseInterface>::GetFloatVectorArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVectorArray";
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#endif
-
- // ensure we don't read past the end of the vector array
- memcpy(pData, Data.pVector + Offset,
- std::min<size_t>(Count * sizeof(CEffectVector4), pType->TotalSize - (Offset * sizeof(CEffectVector4))));
-
-lExit:
- return hr;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectMatrixVariable (TMatrixVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface, bool IsAnnotation>
-struct TMatrixVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
-{
- STDMETHOD(SetMatrix)(_In_reads_(16) const float *pData) override;
- STDMETHOD(GetMatrix)(_Out_writes_(16) float *pData) override;
-
- STDMETHOD(SetMatrixArray)(_In_reads_(Count*16) const float *pData, uint32_t Offset, uint32_t Count) override;
- STDMETHOD(GetMatrixArray)(_Out_writes_(Count*16) float *pData, uint32_t Offset, uint32_t Count) override;
-
- STDMETHOD(SetMatrixPointerArray)(_In_reads_(Count*16) const float **ppData, uint32_t Offset, uint32_t Count) override;
- STDMETHOD(GetMatrixPointerArray)(_Out_writes_(Count*16) float **ppData, uint32_t Offset, uint32_t Count) override;
-
- STDMETHOD(SetMatrixTranspose)(_In_reads_(16) const float *pData) override;
- STDMETHOD(GetMatrixTranspose)(_Out_writes_(16) float *pData) override;
-
- STDMETHOD(SetMatrixTransposeArray)(_In_reads_(Count*16) const float *pData, uint32_t Offset, uint32_t Count) override;
- STDMETHOD(GetMatrixTransposeArray)(_Out_writes_(Count*16) float *pData, uint32_t Offset, uint32_t Count) override;
-
- STDMETHOD(SetMatrixTransposePointerArray)(_In_reads_(Count*16) const float **ppData, uint32_t Offset, uint32_t Count) override;
- STDMETHOD(GetMatrixTransposePointerArray)(_Out_writes_(Count*16) float **ppData, uint32_t Offset, uint32_t Count) override;
-};
-
-#pragma warning (push)
-#pragma warning (disable : 6101)
-template<bool Transpose>
-static void SetMatrixTransposeHelper(_In_ const SType *pType, _Out_writes_bytes_(64) uint8_t *pDestData, _In_reads_(16) const float* pMatrix)
-{
- uint32_t registers, entries;
-
- if (Transpose)
- {
- // row major
- registers = pType->NumericType.Rows;
- entries = pType->NumericType.Columns;
- }
- else
- {
- // column major
- registers = pType->NumericType.Columns;
- entries = pType->NumericType.Rows;
- }
- _Analysis_assume_( registers <= 4 );
- _Analysis_assume_( entries <= 4 );
-
- for (size_t i = 0; i < registers; ++ i)
- {
- for (size_t j = 0; j < entries; ++ j)
- {
-#pragma prefast(suppress:__WARNING_UNRELATED_LOOP_TERMINATION, "regs / entries <= 4")
- ((float*)pDestData)[j] = ((float*)pMatrix)[j * 4 + i];
- }
- pDestData += SType::c_RegisterSize;
- }
-}
-
-template<bool Transpose>
-static void GetMatrixTransposeHelper(_In_ const SType *pType, _In_reads_bytes_(64) uint8_t *pSrcData, _Out_writes_(16) float* pMatrix)
-{
- uint32_t registers, entries;
-
- if (Transpose)
- {
- // row major
- registers = pType->NumericType.Rows;
- entries = pType->NumericType.Columns;
- }
- else
- {
- // column major
- registers = pType->NumericType.Columns;
- entries = pType->NumericType.Rows;
- }
- _Analysis_assume_( registers <= 4 );
- _Analysis_assume_( entries <= 4 );
-
- for (size_t i = 0; i < registers; ++ i)
- {
- for (size_t j = 0; j < entries; ++ j)
- {
- ((float*)pMatrix)[j * 4 + i] = ((float*)pSrcData)[j];
- }
- pSrcData += SType::c_RegisterSize;
- }
-}
-
-template<bool Transpose, bool IsSetting, bool ExtraIndirection>
-HRESULT DoMatrixArrayInternal(_In_ const SType *pType, _In_ uint32_t TotalUnpackedSize,
- _Out_ uint8_t *pEffectData,
- void *pMatrixData,
- _In_ uint32_t Offset, _In_ uint32_t Count, _In_z_ LPCSTR pFuncName)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pMatrixData, pType, TotalUnpackedSize))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-#else
- UNREFERENCED_PARAMETER(TotalUnpackedSize);
- UNREFERENCED_PARAMETER(pFuncName);
-#endif
-
- if ((pType->NumericType.IsColumnMajor && Transpose) || (!pType->NumericType.IsColumnMajor && !Transpose))
- {
- // fast path
- uint32_t dataSize;
- if (Transpose)
- {
- dataSize = ((pType->NumericType.Columns - 1) * 4 + pType->NumericType.Rows) * SType::c_ScalarSize;
- }
- else
- {
- dataSize = ((pType->NumericType.Rows - 1) * 4 + pType->NumericType.Columns) * SType::c_ScalarSize;
- }
-
- for (size_t i = 0; i < Count; ++ i)
- {
- CEffectMatrix *pMatrix;
- if (ExtraIndirection)
- {
- pMatrix = ((CEffectMatrix **)pMatrixData)[i];
- if (!pMatrix)
- {
- continue;
- }
- }
- else
- {
- pMatrix = ((CEffectMatrix *)pMatrixData) + i;
- }
-
- if (IsSetting)
- {
- memcpy(pEffectData + pType->Stride * (i + Offset), pMatrix, dataSize);
- }
- else
- {
- memcpy(pMatrix, pEffectData + pType->Stride * (i + Offset), dataSize);
- }
- }
- }
- else
- {
- // slow path
- for (size_t i = 0; i < Count; ++ i)
- {
- CEffectMatrix *pMatrix;
- if (ExtraIndirection)
- {
- pMatrix = ((CEffectMatrix **)pMatrixData)[i];
- if (!pMatrix)
- {
- continue;
- }
- }
- else
- {
- pMatrix = ((CEffectMatrix *)pMatrixData) + i;
- }
-
- if (IsSetting)
- {
- SetMatrixTransposeHelper<Transpose>(pType, pEffectData + pType->Stride * (i + Offset), (float*) pMatrix);
- }
- else
- {
- GetMatrixTransposeHelper<Transpose>(pType, pEffectData + pType->Stride * (i + Offset), (float*) pMatrix);
- }
- }
- }
-
-lExit:
- return hr;
-}
-#pragma warning (pop)
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrix(const float *pData)
-{
- static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrix";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return DoMatrixArrayInternal<false, true, false>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, const_cast<float*>(pData), 0, 1, pFuncName);
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrix(float *pData)
-{
- return DoMatrixArrayInternal<false, false, false>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, pData, 0, 1, "ID3DX11EffectMatrixVariable::GetMatrix");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return DoMatrixArrayInternal<false, true, false>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, const_cast<float*>(pData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- return DoMatrixArrayInternal<false, false, false>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, pData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixPointerArray(const float **ppData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixPointerArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return DoMatrixArrayInternal<false, true, true>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, const_cast<float**>(ppData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixPointerArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixPointerArray(float **ppData, uint32_t Offset, uint32_t Count)
-{
- return DoMatrixArrayInternal<false, false, true>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, ppData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixPointerArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixTranspose(const float *pData)
-{
- static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTranspose";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return DoMatrixArrayInternal<true, true, false>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, const_cast<float*>(pData), 0, 1, "ID3DX11EffectMatrixVariable::SetMatrixTranspose");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixTranspose(float *pData)
-{
- return DoMatrixArrayInternal<true, false, false>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, pData, 0, 1, "ID3DX11EffectMatrixVariable::GetMatrixTranspose");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixTransposeArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return DoMatrixArrayInternal<true, true, false>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, const_cast<float*>(pData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixTransposeArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- return DoMatrixArrayInternal<true, false, false>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, pData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixTransposeArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixTransposePointerArray(const float **ppData, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTransposePointerArray";
- if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
- DirtyVariable();
- return DoMatrixArrayInternal<true, true, true>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, const_cast<float**>(ppData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixTransposePointerArray");
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixTransposePointerArray(float **ppData, uint32_t Offset, uint32_t Count)
-{
- return DoMatrixArrayInternal<true, false, true>(pType, GetTotalUnpackedSize(),
- Data.pNumeric, ppData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixTransposePointerArray");
-}
-
-// Optimize commonly used fast paths
-// (non-annotations only!)
-template<typename IBaseInterface, bool IsColumnMajor>
-struct TMatrix4x4Variable : public TMatrixVariable<IBaseInterface, false>
-{
- STDMETHOD(SetMatrix)(_In_reads_(16) const float *pData) override;
- STDMETHOD(GetMatrix)(_Out_writes_(16) float *pData) override;
-
- STDMETHOD(SetMatrixArray)(_In_reads_(16*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetMatrixArray)(_Out_writes_(16*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-
- STDMETHOD(SetMatrixTranspose)(_In_reads_(16) const float *pData) override;
- STDMETHOD(GetMatrixTranspose)(_Out_writes_(16) float *pData) override;
-
- STDMETHOD(SetMatrixTransposeArray)(_In_reads_(16*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetMatrixTransposeArray)(_Out_writes_(16*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-inline static void Matrix4x4TransposeHelper(_In_reads_bytes_(64) const void *pSrc, _Out_writes_bytes_(64) void *pDst)
-{
- uint8_t *pDestData = (uint8_t*)pDst;
- uint32_t *pMatrix = (uint32_t*)pSrc;
-
- ((uint32_t*)pDestData)[0 * 4 + 0] = pMatrix[0 * 4 + 0];
- ((uint32_t*)pDestData)[0 * 4 + 1] = pMatrix[1 * 4 + 0];
- ((uint32_t*)pDestData)[0 * 4 + 2] = pMatrix[2 * 4 + 0];
- ((uint32_t*)pDestData)[0 * 4 + 3] = pMatrix[3 * 4 + 0];
-
- ((uint32_t*)pDestData)[1 * 4 + 0] = pMatrix[0 * 4 + 1];
- ((uint32_t*)pDestData)[1 * 4 + 1] = pMatrix[1 * 4 + 1];
- ((uint32_t*)pDestData)[1 * 4 + 2] = pMatrix[2 * 4 + 1];
- ((uint32_t*)pDestData)[1 * 4 + 3] = pMatrix[3 * 4 + 1];
-
- ((uint32_t*)pDestData)[2 * 4 + 0] = pMatrix[0 * 4 + 2];
- ((uint32_t*)pDestData)[2 * 4 + 1] = pMatrix[1 * 4 + 2];
- ((uint32_t*)pDestData)[2 * 4 + 2] = pMatrix[2 * 4 + 2];
- ((uint32_t*)pDestData)[2 * 4 + 3] = pMatrix[3 * 4 + 2];
-
- ((uint32_t*)pDestData)[3 * 4 + 0] = pMatrix[0 * 4 + 3];
- ((uint32_t*)pDestData)[3 * 4 + 1] = pMatrix[1 * 4 + 3];
- ((uint32_t*)pDestData)[3 * 4 + 2] = pMatrix[2 * 4 + 3];
- ((uint32_t*)pDestData)[3 * 4 + 3] = pMatrix[3 * 4 + 3];
-}
-
-inline static void Matrix4x4Copy(_In_reads_bytes_(64) const void *pSrc, _Out_writes_bytes_(64) void *pDst)
-{
-#if 1
- // In tests, this path ended up generating faster code both on x86 and x64
- // T1 - Matrix4x4Copy - this path
- // T2 - Matrix4x4Transpose
- // T1: 1.88 T2: 1.92 - with 32 bit copies
- // T1: 1.85 T2: 1.80 - with 64 bit copies
-
- uint64_t *pDestData = (uint64_t*)pDst;
- uint64_t *pMatrix = (uint64_t*)pSrc;
-
- pDestData[0 * 4 + 0] = pMatrix[0 * 4 + 0];
- pDestData[0 * 4 + 1] = pMatrix[0 * 4 + 1];
- pDestData[0 * 4 + 2] = pMatrix[0 * 4 + 2];
- pDestData[0 * 4 + 3] = pMatrix[0 * 4 + 3];
-
- pDestData[1 * 4 + 0] = pMatrix[1 * 4 + 0];
- pDestData[1 * 4 + 1] = pMatrix[1 * 4 + 1];
- pDestData[1 * 4 + 2] = pMatrix[1 * 4 + 2];
- pDestData[1 * 4 + 3] = pMatrix[1 * 4 + 3];
-#else
- uint32_t *pDestData = (uint32_t*)pDst;
- uint32_t *pMatrix = (uint32_t*)pSrc;
-
- pDestData[0 * 4 + 0] = pMatrix[0 * 4 + 0];
- pDestData[0 * 4 + 1] = pMatrix[0 * 4 + 1];
- pDestData[0 * 4 + 2] = pMatrix[0 * 4 + 2];
- pDestData[0 * 4 + 3] = pMatrix[0 * 4 + 3];
-
- pDestData[1 * 4 + 0] = pMatrix[1 * 4 + 0];
- pDestData[1 * 4 + 1] = pMatrix[1 * 4 + 1];
- pDestData[1 * 4 + 2] = pMatrix[1 * 4 + 2];
- pDestData[1 * 4 + 3] = pMatrix[1 * 4 + 3];
-
- pDestData[2 * 4 + 0] = pMatrix[2 * 4 + 0];
- pDestData[2 * 4 + 1] = pMatrix[2 * 4 + 1];
- pDestData[2 * 4 + 2] = pMatrix[2 * 4 + 2];
- pDestData[2 * 4 + 3] = pMatrix[2 * 4 + 3];
-
- pDestData[3 * 4 + 0] = pMatrix[3 * 4 + 0];
- pDestData[3 * 4 + 1] = pMatrix[3 * 4 + 1];
- pDestData[3 * 4 + 2] = pMatrix[3 * 4 + 2];
- pDestData[3 * 4 + 3] = pMatrix[3 * 4 + 3];
-#endif
-}
-
-
-// Note that branches in this code is based on template parameters and will be compiled out
-#pragma warning (push)
-#pragma warning (disable : 6101)
-template<bool IsColumnMajor, bool Transpose, bool IsSetting>
-inline HRESULT DoMatrix4x4ArrayInternal(_In_ uint8_t *pEffectData,
- _When_(IsSetting, _In_reads_bytes_(64 * Count))
- _When_(!IsSetting, _Out_writes_bytes_(64 * Count))
- void *pMatrixData,
- _In_ uint32_t Offset, _In_ uint32_t Count
-#ifdef _DEBUG
- , _In_ const SType *pType, _In_ uint32_t TotalUnpackedSize, _In_z_ LPCSTR pFuncName
-#endif
-
- )
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
-#pragma warning( suppress : 6001 )
- if (!AreBoundsValid(Offset, Count, pMatrixData, pType, TotalUnpackedSize))
- {
- DPF(0, "%s: Invalid range specified", pFuncName);
- VH(E_INVALIDARG);
- }
-
- assert(pType->NumericType.IsColumnMajor == IsColumnMajor && pType->Stride == (4 * SType::c_RegisterSize));
-#endif
-
- if ((IsColumnMajor && Transpose) || (!IsColumnMajor && !Transpose))
- {
- // fast path
- for (size_t i = 0; i < Count; ++ i)
- {
- CEffectMatrix *pMatrix = ((CEffectMatrix *)pMatrixData) + i;
-
- if (IsSetting)
- {
- Matrix4x4Copy(pMatrix, pEffectData + 4 * SType::c_RegisterSize * (i + Offset));
- }
- else
- {
- Matrix4x4Copy(pEffectData + 4 * SType::c_RegisterSize * (i + Offset), pMatrix);
- }
- }
- }
- else
- {
- // slow path
- for (size_t i = 0; i < Count; ++ i)
- {
- CEffectMatrix *pMatrix = ((CEffectMatrix *)pMatrixData) + i;
-
- if (IsSetting)
- {
- Matrix4x4TransposeHelper((float*) pMatrix, pEffectData + 4 * SType::c_RegisterSize * (i + Offset));
- }
- else
- {
- Matrix4x4TransposeHelper(pEffectData + 4 * SType::c_RegisterSize * (i + Offset), (float*) pMatrix);
- }
- }
- }
-
-lExit:
- return hr;
-}
-#pragma warning (pop)
-
-template<typename IBaseInterface, bool IsColumnMajor>
-_Use_decl_annotations_
-HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::SetMatrix(const float *pData)
-{
- DirtyVariable();
- return DoMatrix4x4ArrayInternal<IsColumnMajor, false, true>(Data.pNumeric, const_cast<float*>(pData), 0, 1
-#ifdef _DEBUG
- , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrix");
-#else
- );
-#endif
-}
-
-template<typename IBaseInterface, bool IsColumnMajor>
-_Use_decl_annotations_
-HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::GetMatrix(float *pData)
-{
- return DoMatrix4x4ArrayInternal<IsColumnMajor, false, false>(Data.pNumeric, pData, 0, 1
-#ifdef _DEBUG
- , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrix");
-#else
- );
-#endif
-}
-
-template<typename IBaseInterface, bool IsColumnMajor>
-_Use_decl_annotations_
-HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::SetMatrixArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- DirtyVariable();
- return DoMatrix4x4ArrayInternal<IsColumnMajor, false, true>(Data.pNumeric, const_cast<float*>(pData), Offset, Count
-#ifdef _DEBUG
- , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixArray");
-#else
- );
-#endif
-}
-
-template<typename IBaseInterface, bool IsColumnMajor>
-_Use_decl_annotations_
-HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::GetMatrixArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- return DoMatrix4x4ArrayInternal<IsColumnMajor, false, false>(Data.pNumeric, pData, Offset, Count
-#ifdef _DEBUG
- , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrixArray");
-#else
- );
-#endif
-}
-
-template<typename IBaseInterface, bool IsColumnMajor>
-_Use_decl_annotations_
-HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::SetMatrixTranspose(const float *pData)
-{
- DirtyVariable();
- return DoMatrix4x4ArrayInternal<IsColumnMajor, true, true>(Data.pNumeric, const_cast<float*>(pData), 0, 1
-#ifdef _DEBUG
- , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixTranspose");
-#else
- );
-#endif
-}
-
-template<typename IBaseInterface, bool IsColumnMajor>
-_Use_decl_annotations_
-HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::GetMatrixTranspose(float *pData)
-{
- return DoMatrix4x4ArrayInternal<IsColumnMajor, true, false>(Data.pNumeric, pData, 0, 1
-#ifdef _DEBUG
- , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrixTranspose");
-#else
- );
-#endif
-}
-
-template<typename IBaseInterface, bool IsColumnMajor>
-_Use_decl_annotations_
-HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::SetMatrixTransposeArray(const float *pData, uint32_t Offset, uint32_t Count)
-{
- DirtyVariable();
- return DoMatrix4x4ArrayInternal<IsColumnMajor, true, true>(Data.pNumeric, const_cast<float*>(pData), Offset, Count
-#ifdef _DEBUG
- , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray");
-#else
- );
-#endif
-}
-
-template<typename IBaseInterface, bool IsColumnMajor>
-_Use_decl_annotations_
-HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::GetMatrixTransposeArray(float *pData, uint32_t Offset, uint32_t Count)
-{
- return DoMatrix4x4ArrayInternal<IsColumnMajor, true, false>(Data.pNumeric, pData, Offset, Count
-#ifdef _DEBUG
- , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrixTransposeArray");
-#else
- );
-#endif
-}
-
-#ifdef _DEBUG
-
-// Useful object macro to check bounds and parameters
-#define CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, Pointer) \
- HRESULT hr = S_OK; \
- VERIFYPARAMETER(Pointer) \
- uint32_t elements = IsArray() ? pType->Elements : 1; \
- \
- if ((Offset + Count < Offset) || (elements < Offset + Count)) \
- { \
- DPF(0, "%s: Invalid range specified", pFuncName); \
- VH(E_INVALIDARG); \
- } \
-
-#define CHECK_OBJECT_SCALAR_BOUNDS(Index, Pointer) \
- HRESULT hr = S_OK; \
- VERIFYPARAMETER(Pointer) \
- uint32_t elements = IsArray() ? pType->Elements : 1; \
- \
- if (Index >= elements) \
- { \
- DPF(0, "%s: Invalid index specified", pFuncName); \
- VH(E_INVALIDARG); \
- } \
-
-#define CHECK_SCALAR_BOUNDS(Index) \
- HRESULT hr = S_OK; \
- uint32_t elements = IsArray() ? pType->Elements : 1; \
- \
- if (Index >= elements) \
-{ \
- DPF(0, "%s: Invalid index specified", pFuncName); \
- VH(E_INVALIDARG); \
-} \
-
-#else // _DEBUG
-
-#define CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, Pointer) \
- HRESULT hr = S_OK; \
-
-#define CHECK_OBJECT_SCALAR_BOUNDS(Index, Pointer) \
- HRESULT hr = S_OK; \
-
-#define CHECK_SCALAR_BOUNDS(Index) \
- HRESULT hr = S_OK; \
-
-#endif // _DEBUG
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectStringVariable (TStringVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface, bool IsAnnotation>
-struct TStringVariable : public IBaseInterface
-{
- STDMETHOD(GetString)(_Outptr_result_z_ LPCSTR *ppString) override;
- STDMETHOD(GetStringArray)( _Out_writes_(Count) LPCSTR *ppStrings, _In_ uint32_t Offset, _In_ uint32_t Count ) override;
-};
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-HRESULT TStringVariable<IBaseInterface, IsAnnotation>::GetString(LPCSTR *ppString)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectStringVariable::GetString";
-
- VERIFYPARAMETER(ppString);
-
- if (GetTopLevelEntity()->pEffect->IsOptimized())
- {
- DPF(0, "%s: Effect has been Optimize()'ed; all string/reflection data has been deleted", pFuncName);
- return D3DERR_INVALIDCALL;
- }
-
- assert(Data.pString != 0);
- _Analysis_assume_(Data.pString != 0);
-
- *ppString = Data.pString->pString;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface, bool IsAnnotation>
-_Use_decl_annotations_
-#pragma warning(suppress : 6054)
-HRESULT TStringVariable<IBaseInterface, IsAnnotation>::GetStringArray( LPCSTR *ppStrings, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectStringVariable::GetStringArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppStrings);
-
- if (GetTopLevelEntity()->pEffect->IsOptimized())
- {
- DPF(0, "%s: Effect has been Optimize()'ed; all string/reflection data has been deleted", pFuncName);
- return D3DERR_INVALIDCALL;
- }
-
- assert(Data.pString != 0);
- _Analysis_assume_(Data.pString != 0);
-
- for (size_t i = 0; i < Count; ++ i)
- {
- ppStrings[i] = (Data.pString + Offset + i)->pString;
- }
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectClassInstanceVariable (TClassInstanceVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TClassInstanceVariable : public IBaseInterface
-{
- STDMETHOD(GetClassInstance)(_Outptr_ ID3D11ClassInstance **ppClassInstance) override;
-};
-
-template<typename IBaseClassInstance>
-HRESULT TClassInstanceVariable<IBaseClassInstance>::GetClassInstance(_Outptr_ ID3D11ClassInstance** ppClassInstance)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectClassInstanceVariable::GetClassInstance";
-
- assert( pMemberData != 0 && pMemberData->Data.pD3DClassInstance != 0);
- _Analysis_assume_( pMemberData != 0 && pMemberData->Data.pD3DClassInstance != 0);
- *ppClassInstance = pMemberData->Data.pD3DClassInstance;
- SAFE_ADDREF(*ppClassInstance);
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectInterfaceeVariable (TInterfaceVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TInterfaceVariable : public IBaseInterface
-{
- STDMETHOD(SetClassInstance)(_In_ ID3DX11EffectClassInstanceVariable *pEffectClassInstance) override;
- STDMETHOD(GetClassInstance)(_Outptr_ ID3DX11EffectClassInstanceVariable **ppEffectClassInstance) override;
-};
-
-template<typename IBaseInterface>
-HRESULT TInterfaceVariable<IBaseInterface>::SetClassInstance(_In_ ID3DX11EffectClassInstanceVariable *pEffectClassInstance)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectInterfaceVariable::SetClassInstance";
-
- // Note that we don't check if the types are compatible. The debug layer will complain if it is.
- // IsValid() will not catch type mismatches.
- SClassInstanceGlobalVariable* pCI = (SClassInstanceGlobalVariable*)pEffectClassInstance;
- Data.pInterface->pClassInstance = pCI;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-HRESULT TInterfaceVariable<IBaseInterface>::GetClassInstance(_Outptr_ ID3DX11EffectClassInstanceVariable **ppEffectClassInstance)
-{
- HRESULT hr = S_OK;
- static LPCSTR pFuncName = "ID3DX11EffectInterfaceVariable::GetClassInstance";
-
-#ifdef _DEBUG
- VERIFYPARAMETER(ppEffectClassInstance);
-#endif
-
- *ppEffectClassInstance = Data.pInterface->pClassInstance;
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectShaderResourceVariable (TShaderResourceVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TShaderResourceVariable : public IBaseInterface
-{
- STDMETHOD(SetResource)(_In_ ID3D11ShaderResourceView *pResource) override;
- STDMETHOD(GetResource)(_Outptr_ ID3D11ShaderResourceView **ppResource) override;
-
- STDMETHOD(SetResourceArray)(_In_reads_(Count) ID3D11ShaderResourceView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetResourceArray)(_Out_writes_(Count) ID3D11ShaderResourceView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-static LPCSTR GetTextureTypeNameFromEnum(_In_ EObjectType ObjectType)
-{
- switch (ObjectType)
- {
- case EOT_Buffer:
- return "Buffer";
- case EOT_Texture:
- return "texture";
- case EOT_Texture1D:
- case EOT_Texture1DArray:
- return "Texture1D";
- case EOT_Texture2DMS:
- case EOT_Texture2DMSArray:
- return "Texture2DMS";
- case EOT_Texture2D:
- case EOT_Texture2DArray:
- return "Texture2D";
- case EOT_Texture3D:
- return "Texture3D";
- case EOT_TextureCube:
- return "TextureCube";
- case EOT_TextureCubeArray:
- return "TextureCubeArray";
- case EOT_RWTexture1D:
- case EOT_RWTexture1DArray:
- return "RWTexture1D";
- case EOT_RWTexture2D:
- case EOT_RWTexture2DArray:
- return "RWTexture2D";
- case EOT_RWTexture3D:
- return "RWTexture3D";
- case EOT_RWBuffer:
- return "RWBuffer";
- case EOT_ByteAddressBuffer:
- return "ByteAddressBuffer";
- case EOT_RWByteAddressBuffer:
- return "RWByteAddressBuffer";
- case EOT_StructuredBuffer:
- return "StructuredBuffe";
- case EOT_RWStructuredBuffer:
- return "RWStructuredBuffer";
- case EOT_RWStructuredBufferAlloc:
- return "RWStructuredBufferAlloc";
- case EOT_RWStructuredBufferConsume:
- return "RWStructuredBufferConsume";
- case EOT_AppendStructuredBuffer:
- return "AppendStructuredBuffer";
- case EOT_ConsumeStructuredBuffer:
- return "ConsumeStructuredBuffer";
- }
- return "<unknown texture format>";
-}
-
-static LPCSTR GetResourceDimensionNameFromEnum(_In_ D3D11_RESOURCE_DIMENSION ResourceDimension)
-{
- switch (ResourceDimension)
- {
- case D3D11_RESOURCE_DIMENSION_BUFFER:
- return "Buffer";
- case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
- return "Texture1D";
- case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
- return "Texture2D";
- case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
- return "Texture3D";
- }
- return "<unknown texture format>";
-}
-
-static LPCSTR GetSRVDimensionNameFromEnum(_In_ D3D11_SRV_DIMENSION ViewDimension)
-{
- switch (ViewDimension)
- {
- case D3D11_SRV_DIMENSION_BUFFER:
- case D3D11_SRV_DIMENSION_BUFFEREX:
- return "Buffer";
- case D3D11_SRV_DIMENSION_TEXTURE1D:
- return "Texture1D";
- case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
- return "Texture1DArray";
- case D3D11_SRV_DIMENSION_TEXTURE2D:
- return "Texture2D";
- case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
- return "Texture2DArray";
- case D3D11_SRV_DIMENSION_TEXTURE2DMS:
- return "Texture2DMS";
- case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
- return "Texture2DMSArray";
- case D3D11_SRV_DIMENSION_TEXTURE3D:
- return "Texture3D";
- case D3D11_SRV_DIMENSION_TEXTURECUBE:
- return "TextureCube";
- }
- return "<unknown texture format>";
-}
-
-static LPCSTR GetUAVDimensionNameFromEnum(_In_ D3D11_UAV_DIMENSION ViewDimension)
-{
- switch (ViewDimension)
- {
- case D3D11_UAV_DIMENSION_BUFFER:
- return "Buffer";
- case D3D11_UAV_DIMENSION_TEXTURE1D:
- return "RWTexture1D";
- case D3D11_UAV_DIMENSION_TEXTURE1DARRAY:
- return "RWTexture1DArray";
- case D3D11_UAV_DIMENSION_TEXTURE2D:
- return "RWTexture2D";
- case D3D11_UAV_DIMENSION_TEXTURE2DARRAY:
- return "RWTexture2DArray";
- case D3D11_UAV_DIMENSION_TEXTURE3D:
- return "RWTexture3D";
- }
- return "<unknown texture format>";
-}
-
-static LPCSTR GetRTVDimensionNameFromEnum(_In_ D3D11_RTV_DIMENSION ViewDimension)
-{
- switch (ViewDimension)
- {
- case D3D11_RTV_DIMENSION_BUFFER:
- return "Buffer";
- case D3D11_RTV_DIMENSION_TEXTURE1D:
- return "Texture1D";
- case D3D11_RTV_DIMENSION_TEXTURE1DARRAY:
- return "Texture1DArray";
- case D3D11_RTV_DIMENSION_TEXTURE2D:
- return "Texture2D";
- case D3D11_RTV_DIMENSION_TEXTURE2DARRAY:
- return "Texture2DArray";
- case D3D11_RTV_DIMENSION_TEXTURE2DMS:
- return "Texture2DMS";
- case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY:
- return "Texture2DMSArray";
- case D3D11_RTV_DIMENSION_TEXTURE3D:
- return "Texture3D";
- }
- return "<unknown texture format>";
-}
-
-static LPCSTR GetDSVDimensionNameFromEnum(_In_ D3D11_DSV_DIMENSION ViewDimension)
-{
- switch (ViewDimension)
- {
- case D3D11_DSV_DIMENSION_TEXTURE1D:
- return "Texture1D";
- case D3D11_DSV_DIMENSION_TEXTURE1DARRAY:
- return "Texture1DArray";
- case D3D11_DSV_DIMENSION_TEXTURE2D:
- return "Texture2D";
- case D3D11_DSV_DIMENSION_TEXTURE2DARRAY:
- return "Texture2DArray";
- case D3D11_DSV_DIMENSION_TEXTURE2DMS:
- return "Texture2DMS";
- case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY:
- return "Texture2DMSArray";
- }
- return "<unknown texture format>";
-}
-
-static HRESULT ValidateTextureType(_In_ ID3D11ShaderResourceView *pView, _In_ EObjectType ObjectType, _In_z_ LPCSTR pFuncName)
-{
- if (nullptr != pView)
- {
- D3D11_SHADER_RESOURCE_VIEW_DESC desc;
- pView->GetDesc(&desc);
- switch (ObjectType)
- {
- case EOT_Texture:
- if (desc.ViewDimension != D3D11_SRV_DIMENSION_BUFFER && desc.ViewDimension != D3D11_SRV_DIMENSION_BUFFEREX)
- return S_OK;
- break;
- case EOT_Buffer:
- if (desc.ViewDimension != D3D11_SRV_DIMENSION_BUFFER && desc.ViewDimension != D3D11_SRV_DIMENSION_BUFFEREX)
- break;
- if (desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFEREX && (desc.BufferEx.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW))
- {
- DPF(0, "%s: Resource type mismatch; %s expected, ByteAddressBuffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
- return E_INVALIDARG;
- }
- else
- {
- ID3D11Buffer* pBuffer = nullptr;
- pView->GetResource( (ID3D11Resource**)&pBuffer );
- assert( pBuffer != nullptr );
- D3D11_BUFFER_DESC BufDesc;
- pBuffer->GetDesc( &BufDesc );
- SAFE_RELEASE( pBuffer );
- if( BufDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED )
- {
- DPF(0, "%s: Resource type mismatch; %s expected, StructuredBuffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
- return E_INVALIDARG;
- }
- else
- {
- return S_OK;
- }
- }
- break;
- case EOT_Texture1D:
- case EOT_Texture1DArray:
- if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE1D ||
- desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
- return S_OK;
- break;
- case EOT_Texture2D:
- case EOT_Texture2DArray:
- if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D ||
- desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
- return S_OK;
- break;
- case EOT_Texture2DMS:
- case EOT_Texture2DMSArray:
- if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMS ||
- desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
- return S_OK;
- break;
- case EOT_Texture3D:
- if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
- return S_OK;
- break;
- case EOT_TextureCube:
- case EOT_TextureCubeArray:
- if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE ||
- desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
- return S_OK;
- break;
- case EOT_ByteAddressBuffer:
- if (desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFEREX && (desc.BufferEx.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW))
- return S_OK;
- break;
- case EOT_StructuredBuffer:
- if (desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFEREX || desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER)
- {
- ID3D11Buffer* pBuffer = nullptr;
- pView->GetResource( (ID3D11Resource**)&pBuffer );
- assert( pBuffer != nullptr );
- D3D11_BUFFER_DESC BufDesc;
- pBuffer->GetDesc( &BufDesc );
- SAFE_RELEASE( pBuffer );
- if( BufDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED )
- {
- return S_OK;
- }
- else
- {
- DPF(0, "%s: Resource type mismatch; %s expected, non-structured Buffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
- return E_INVALIDARG;
- }
- }
- break;
- default:
- assert(0); // internal error, should never get here
- return E_FAIL;
- }
-
-
- DPF(0, "%s: Resource type mismatch; %s expected, %s provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType), GetSRVDimensionNameFromEnum(desc.ViewDimension));
- return E_INVALIDARG;
- }
- return S_OK;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderResourceVariable<IBaseInterface>::SetResource(ID3D11ShaderResourceView *pResource)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectShaderResourceVariable::SetResource";
-
- VH(ValidateTextureType(pResource, pType->ObjectType, pFuncName));
-#endif
-
- // Texture variables don't need to be dirtied.
- SAFE_ADDREF(pResource);
- SAFE_RELEASE(Data.pShaderResource->pShaderResource);
- Data.pShaderResource->pShaderResource = pResource;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderResourceVariable<IBaseInterface>::GetResource(ID3D11ShaderResourceView **ppResource)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectShaderResourceVariable::GetResource";
-
- VERIFYPARAMETER(ppResource);
-#endif
-
- assert(Data.pShaderResource != 0 && Data.pShaderResource->pShaderResource != 0);
- _Analysis_assume_(Data.pShaderResource != 0 && Data.pShaderResource->pShaderResource != 0);
- *ppResource = Data.pShaderResource->pShaderResource;
- SAFE_ADDREF(*ppResource);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderResourceVariable<IBaseInterface>::SetResourceArray(ID3D11ShaderResourceView **ppResources, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderResourceVariable::SetResourceArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
-
-#ifdef _DEBUG
- for (size_t i = 0; i < Count; ++ i)
- {
- VH(ValidateTextureType(ppResources[i], pType->ObjectType, pFuncName));
- }
-#endif
-
- // Texture variables don't need to be dirtied.
- for (size_t i = 0; i < Count; ++ i)
- {
- SShaderResource *pResourceBlock = Data.pShaderResource + Offset + i;
- SAFE_ADDREF(ppResources[i]);
- SAFE_RELEASE(pResourceBlock->pShaderResource);
- pResourceBlock->pShaderResource = ppResources[i];
- }
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderResourceVariable<IBaseInterface>::GetResourceArray(ID3D11ShaderResourceView **ppResources, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderResourceVariable::GetResourceArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
-
- for (size_t i = 0; i < Count; ++ i)
- {
- ppResources[i] = (Data.pShaderResource + Offset + i)->pShaderResource;
- SAFE_ADDREF(ppResources[i]);
- }
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectUnorderedAccessViewVariable (TUnorderedAccessViewVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TUnorderedAccessViewVariable : public IBaseInterface
-{
- STDMETHOD(SetUnorderedAccessView)(_In_ ID3D11UnorderedAccessView *pResource) override;
- STDMETHOD(GetUnorderedAccessView)(_Outptr_ ID3D11UnorderedAccessView **ppResource) override;
-
- STDMETHOD(SetUnorderedAccessViewArray)(_In_reads_(Count) ID3D11UnorderedAccessView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetUnorderedAccessViewArray)(_Out_writes_(Count) ID3D11UnorderedAccessView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-static HRESULT ValidateTextureType(_In_ ID3D11UnorderedAccessView *pView, _In_ EObjectType ObjectType, _In_z_ LPCSTR pFuncName)
-{
- if (nullptr != pView)
- {
- D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
- pView->GetDesc(&desc);
- switch (ObjectType)
- {
- case EOT_RWBuffer:
- if (desc.ViewDimension != D3D11_UAV_DIMENSION_BUFFER)
- break;
- if (desc.Buffer.Flags & D3D11_BUFFER_UAV_FLAG_RAW)
- {
- DPF(0, "%s: Resource type mismatch; %s expected, RWByteAddressBuffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
- return E_INVALIDARG;
- }
- else
- {
- ID3D11Buffer* pBuffer = nullptr;
- pView->GetResource( (ID3D11Resource**)&pBuffer );
- assert( pBuffer != nullptr );
- D3D11_BUFFER_DESC BufDesc;
- pBuffer->GetDesc( &BufDesc );
- SAFE_RELEASE( pBuffer );
- if( BufDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED )
- {
- DPF(0, "%s: Resource type mismatch; %s expected, an RWStructuredBuffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
- return E_INVALIDARG;
- }
- else
- {
- return S_OK;
- }
- }
- break;
- case EOT_RWTexture1D:
- case EOT_RWTexture1DArray:
- if (desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE1D ||
- desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
- return S_OK;
- break;
- case EOT_RWTexture2D:
- case EOT_RWTexture2DArray:
- if (desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D ||
- desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
- return S_OK;
- break;
- case EOT_RWTexture3D:
- if (desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
- return S_OK;
- break;
- case EOT_RWByteAddressBuffer:
- if (desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER && (desc.Buffer.Flags & D3D11_BUFFER_UAV_FLAG_RAW))
- return S_OK;
- break;
- case EOT_RWStructuredBuffer:
- if (desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER)
- {
- ID3D11Buffer* pBuffer = nullptr;
- pView->GetResource( (ID3D11Resource**)&pBuffer );
- assert( pBuffer != nullptr );
- D3D11_BUFFER_DESC BufDesc;
- pBuffer->GetDesc( &BufDesc );
- SAFE_RELEASE( pBuffer );
- if( BufDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED )
- {
- return S_OK;
- }
- else
- {
- DPF(0, "%s: Resource type mismatch; %s expected, non-structured Buffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
- return E_INVALIDARG;
- }
- }
- break;
- case EOT_RWStructuredBufferAlloc:
- case EOT_RWStructuredBufferConsume:
- if (desc.ViewDimension != D3D11_UAV_DIMENSION_BUFFER)
- break;
- if (desc.Buffer.Flags & D3D11_BUFFER_UAV_FLAG_COUNTER)
- {
- return S_OK;
- }
- else
- {
- DPF(0, "%s: Resource type mismatch; %s expected, non-Counter buffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
- return E_INVALIDARG;
- }
- break;
- case EOT_AppendStructuredBuffer:
- case EOT_ConsumeStructuredBuffer:
- if (desc.ViewDimension != D3D11_UAV_DIMENSION_BUFFER)
- break;
- if (desc.Buffer.Flags & D3D11_BUFFER_UAV_FLAG_APPEND)
- {
- return S_OK;
- }
- else
- {
- DPF(0, "%s: Resource type mismatch; %s expected, non-Append buffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
- return E_INVALIDARG;
- }
- break;
- default:
- assert(0); // internal error, should never get here
- return E_FAIL;
- }
-
-
- DPF(0, "%s: Resource type mismatch; %s expected, %s provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType), GetUAVDimensionNameFromEnum(desc.ViewDimension));
- return E_INVALIDARG;
- }
- return S_OK;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TUnorderedAccessViewVariable<IBaseInterface>::SetUnorderedAccessView(ID3D11UnorderedAccessView *pResource)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectUnorderedAccessViewVariable::SetUnorderedAccessView";
-
- VH(ValidateTextureType(pResource, pType->ObjectType, pFuncName));
-#endif
-
- // UAV variables don't need to be dirtied.
- SAFE_ADDREF(pResource);
- SAFE_RELEASE(Data.pUnorderedAccessView->pUnorderedAccessView);
- Data.pUnorderedAccessView->pUnorderedAccessView = pResource;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TUnorderedAccessViewVariable<IBaseInterface>::GetUnorderedAccessView(ID3D11UnorderedAccessView **ppResource)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectUnorderedAccessViewVariable::GetUnorderedAccessView";
-
- VERIFYPARAMETER(ppResource);
-#endif
-
- assert(Data.pUnorderedAccessView != 0 && Data.pUnorderedAccessView->pUnorderedAccessView != 0);
- _Analysis_assume_(Data.pUnorderedAccessView != 0 && Data.pUnorderedAccessView->pUnorderedAccessView != 0);
- *ppResource = Data.pUnorderedAccessView->pUnorderedAccessView;
- SAFE_ADDREF(*ppResource);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TUnorderedAccessViewVariable<IBaseInterface>::SetUnorderedAccessViewArray(ID3D11UnorderedAccessView **ppResources, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectUnorderedAccessViewVariable::SetUnorderedAccessViewArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
-
-#ifdef _DEBUG
- for (size_t i = 0; i < Count; ++ i)
- {
- VH(ValidateTextureType(ppResources[i], pType->ObjectType, pFuncName));
- }
-#endif
-
- // Texture variables don't need to be dirtied.
- for (size_t i = 0; i < Count; ++ i)
- {
- SUnorderedAccessView *pResourceBlock = Data.pUnorderedAccessView + Offset + i;
- SAFE_ADDREF(ppResources[i]);
- SAFE_RELEASE(pResourceBlock->pUnorderedAccessView);
- pResourceBlock->pUnorderedAccessView = ppResources[i];
- }
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TUnorderedAccessViewVariable<IBaseInterface>::GetUnorderedAccessViewArray(ID3D11UnorderedAccessView **ppResources, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectUnorderedAccessViewVariable::GetUnorderedAccessViewArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
-
- for (size_t i = 0; i < Count; ++ i)
- {
- ppResources[i] = (Data.pUnorderedAccessView + Offset + i)->pUnorderedAccessView;
- SAFE_ADDREF(ppResources[i]);
- }
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectRenderTargetViewVariable (TRenderTargetViewVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TRenderTargetViewVariable : public IBaseInterface
-{
- STDMETHOD(SetRenderTarget)(_In_ ID3D11RenderTargetView *pResource) override;
- STDMETHOD(GetRenderTarget)(_Outptr_ ID3D11RenderTargetView **ppResource) override;
-
- STDMETHOD(SetRenderTargetArray)(_In_reads_(Count) ID3D11RenderTargetView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetRenderTargetArray)(_Out_writes_(Count) ID3D11RenderTargetView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TRenderTargetViewVariable<IBaseInterface>::SetRenderTarget(ID3D11RenderTargetView *pResource)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3DX11EffectRenderTargetVariable::SetRenderTarget";
-#endif
-
- // Texture variables don't need to be dirtied.
- SAFE_ADDREF(pResource);
- SAFE_RELEASE(Data.pRenderTargetView->pRenderTargetView);
- Data.pRenderTargetView->pRenderTargetView = pResource;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TRenderTargetViewVariable<IBaseInterface>::GetRenderTarget(ID3D11RenderTargetView **ppResource)
-{
- HRESULT hr = S_OK;
-
- assert(Data.pRenderTargetView->pRenderTargetView != 0);
- _Analysis_assume_(Data.pRenderTargetView->pRenderTargetView != 0);
- *ppResource = Data.pRenderTargetView->pRenderTargetView;
- SAFE_ADDREF(*ppResource);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TRenderTargetViewVariable<IBaseInterface>::SetRenderTargetArray(ID3D11RenderTargetView **ppResources, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectRenderTargetVariable::SetRenderTargetArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
-
- // Texture variables don't need to be dirtied.
- for (size_t i = 0; i < Count; ++ i)
- {
- SRenderTargetView *pResourceBlock = Data.pRenderTargetView + Offset + i;
- SAFE_ADDREF(ppResources[i]);
- SAFE_RELEASE(pResourceBlock->pRenderTargetView);
- pResourceBlock->pRenderTargetView = ppResources[i];
- }
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TRenderTargetViewVariable<IBaseInterface>::GetRenderTargetArray(ID3D11RenderTargetView **ppResources, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3DX11EffectRenderTargetVariable::GetRenderTargetArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
-
- for (size_t i = 0; i < Count; ++ i)
- {
- ppResources[i] = (Data.pRenderTargetView + Offset + i)->pRenderTargetView;
- SAFE_ADDREF(ppResources[i]);
- }
-
-lExit:
- return hr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectDepthStencilViewVariable (TDepthStencilViewVariable implementation)
-//////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TDepthStencilViewVariable : public IBaseInterface
-{
- STDMETHOD(SetDepthStencil)(_In_ ID3D11DepthStencilView *pResource) override;
- STDMETHOD(GetDepthStencil)(_Outptr_ ID3D11DepthStencilView **ppResource) override;
-
- STDMETHOD(SetDepthStencilArray)(_In_reads_(Count) ID3D11DepthStencilView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
- STDMETHOD(GetDepthStencilArray)(_Out_writes_(Count) ID3D11DepthStencilView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
-};
-
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TDepthStencilViewVariable<IBaseInterface>::SetDepthStencil(ID3D11DepthStencilView *pResource)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3D11DepthStencilViewVariable::SetDepthStencil";
-
-#endif
-
- // Texture variables don't need to be dirtied.
- SAFE_ADDREF(pResource);
- SAFE_RELEASE(Data.pDepthStencilView->pDepthStencilView);
- Data.pDepthStencilView->pDepthStencilView = pResource;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TDepthStencilViewVariable<IBaseInterface>::GetDepthStencil(ID3D11DepthStencilView **ppResource)
-{
- HRESULT hr = S_OK;
-
-#ifdef _DEBUG
- static LPCSTR pFuncName = "ID3D11DepthStencilViewVariable::GetDepthStencil";
-
- VERIFYPARAMETER(ppResource);
-#endif
-
- assert(Data.pDepthStencilView->pDepthStencilView != 0);
- _Analysis_assume_(Data.pDepthStencilView->pDepthStencilView != 0);
- *ppResource = Data.pDepthStencilView->pDepthStencilView;
- SAFE_ADDREF(*ppResource);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TDepthStencilViewVariable<IBaseInterface>::SetDepthStencilArray(ID3D11DepthStencilView **ppResources, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3D11DepthStencilViewVariable::SetDepthStencilArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
-
- // Texture variables don't need to be dirtied.
- for (size_t i = 0; i < Count; ++ i)
- {
- SDepthStencilView *pResourceBlock = Data.pDepthStencilView + Offset + i;
- SAFE_ADDREF(ppResources[i]);
- SAFE_RELEASE(pResourceBlock->pDepthStencilView);
- pResourceBlock->pDepthStencilView = ppResources[i];
- }
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TDepthStencilViewVariable<IBaseInterface>::GetDepthStencilArray(ID3D11DepthStencilView **ppResources, uint32_t Offset, uint32_t Count)
-{
- static LPCSTR pFuncName = "ID3D11DepthStencilViewVariable::GetDepthStencilArray";
-
- CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
-
- for (size_t i = 0; i < Count; ++ i)
- {
- ppResources[i] = (Data.pDepthStencilView + Offset + i)->pDepthStencilView;
- SAFE_ADDREF(ppResources[i]);
- }
-
-lExit:
- return hr;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectShaderVariable (TShaderVariable implementation)
-////////////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TShaderVariable : public IBaseInterface
-{
- STDMETHOD(GetShaderDesc)(_In_ uint32_t ShaderIndex, _Out_ D3DX11_EFFECT_SHADER_DESC *pDesc) override;
-
- STDMETHOD(GetVertexShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11VertexShader **ppVS) override;
- STDMETHOD(GetGeometryShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11GeometryShader **ppGS) override;
- STDMETHOD(GetPixelShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11PixelShader **ppPS) override;
- STDMETHOD(GetHullShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11HullShader **ppHS) override;
- STDMETHOD(GetDomainShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11DomainShader **ppDS) override;
- STDMETHOD(GetComputeShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11ComputeShader **ppCS) override;
-
- STDMETHOD(GetInputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
- STDMETHOD(GetOutputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
- STDMETHOD(GetPatchConstantSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
-
- STDMETHOD_(bool, IsValid)();
-};
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetShaderDesc(uint32_t ShaderIndex, D3DX11_EFFECT_SHADER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetShaderDesc";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, pDesc);
-
- hr = Data.pShader[ShaderIndex].GetShaderDesc(pDesc, false);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetVertexShader(uint32_t ShaderIndex, ID3D11VertexShader **ppVS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetVertexShader";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppVS);
-
- VH( Data.pShader[ShaderIndex].GetVertexShader(ppVS) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetGeometryShader(uint32_t ShaderIndex, ID3D11GeometryShader **ppGS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetGeometryShader";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppGS);
-
- VH( Data.pShader[ShaderIndex].GetGeometryShader(ppGS) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetPixelShader(uint32_t ShaderIndex, ID3D11PixelShader **ppPS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetPixelShader";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppPS);
-
- VH( Data.pShader[ShaderIndex].GetPixelShader(ppPS) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetHullShader(uint32_t ShaderIndex, ID3D11HullShader **ppHS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetHullShader";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppHS);
-
- VH( Data.pShader[ShaderIndex].GetHullShader(ppHS) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetDomainShader(uint32_t ShaderIndex, ID3D11DomainShader **ppDS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetDomainShader";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppDS);
-
- VH( Data.pShader[ShaderIndex].GetDomainShader(ppDS) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetComputeShader(uint32_t ShaderIndex, ID3D11ComputeShader **ppCS)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetComputeShader";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppCS);
-
- VH( Data.pShader[ShaderIndex].GetComputeShader(ppCS) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetInputSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetInputSignatureElementDesc";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, pDesc);
-
- VH( Data.pShader[ShaderIndex].GetSignatureElementDesc(SShaderBlock::ST_Input, Element, pDesc) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetOutputSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetOutputSignatureElementDesc";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, pDesc);
-
- VH( Data.pShader[ShaderIndex].GetSignatureElementDesc(SShaderBlock::ST_Output, Element, pDesc) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TShaderVariable<IBaseInterface>::GetPatchConstantSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetPatchConstantSignatureElementDesc";
-
- CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, pDesc);
-
- VH( Data.pShader[ShaderIndex].GetSignatureElementDesc(SShaderBlock::ST_PatchConstant, Element, pDesc) );
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-bool TShaderVariable<IBaseInterface>::IsValid()
-{
- uint32_t numElements = IsArray()? pType->Elements : 1;
- bool valid = true;
- while( numElements > 0 && ( valid = Data.pShader[ numElements-1 ].IsValid ) )
- numElements--;
- return valid;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectBlendVariable (TBlendVariable implementation)
-////////////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TBlendVariable : public IBaseInterface
-{
-public:
- STDMETHOD(GetBlendState)(_In_ uint32_t Index, _Outptr_ ID3D11BlendState **ppState) override;
- STDMETHOD(SetBlendState)(_In_ uint32_t Index, _In_ ID3D11BlendState *pState) override;
- STDMETHOD(UndoSetBlendState)(_In_ uint32_t Index) override;
- STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_BLEND_DESC *pDesc) override;
- STDMETHOD_(bool, IsValid)() override;
-};
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TBlendVariable<IBaseInterface>::GetBlendState(uint32_t Index, ID3D11BlendState **ppState)
-{
- static LPCSTR pFuncName = "ID3DX11EffectBlendVariable::GetBlendState";
-
- CHECK_OBJECT_SCALAR_BOUNDS(Index, ppState);
-
- assert(Data.pBlend[Index].pBlendObject != 0);
- _Analysis_assume_(Data.pBlend[Index].pBlendObject != 0);
- *ppState = Data.pBlend[Index].pBlendObject;
- SAFE_ADDREF(*ppState);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TBlendVariable<IBaseInterface>::SetBlendState(uint32_t Index, ID3D11BlendState *pState)
-{
- static LPCSTR pFuncName = "ID3DX11EffectBlendState::SetBlendState";
-
- CHECK_SCALAR_BOUNDS(Index);
-
- if( !Data.pBlend[Index].IsUserManaged )
- {
- // Save original state object in case we UndoSet
- assert( pMemberData[Index].Type == MDT_BlendState );
- VB( pMemberData[Index].Data.pD3DEffectsManagedBlendState == nullptr );
- pMemberData[Index].Data.pD3DEffectsManagedBlendState = Data.pBlend[Index].pBlendObject;
- Data.pBlend[Index].pBlendObject = nullptr;
- Data.pBlend[Index].IsUserManaged = true;
- }
-
- SAFE_ADDREF( pState );
- SAFE_RELEASE( Data.pBlend[Index].pBlendObject );
- Data.pBlend[Index].pBlendObject = pState;
- Data.pBlend[Index].IsValid = true;
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TBlendVariable<IBaseInterface>::UndoSetBlendState(uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectBlendState::UndoSetBlendState";
-
- CHECK_SCALAR_BOUNDS(Index);
-
- if( !Data.pBlend[Index].IsUserManaged )
- {
- return S_FALSE;
- }
-
- // Revert to original state object
- SAFE_RELEASE( Data.pBlend[Index].pBlendObject );
- Data.pBlend[Index].pBlendObject = pMemberData[Index].Data.pD3DEffectsManagedBlendState;
- pMemberData[Index].Data.pD3DEffectsManagedBlendState = nullptr;
- Data.pBlend[Index].IsUserManaged = false;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TBlendVariable<IBaseInterface>::GetBackingStore(uint32_t Index, D3D11_BLEND_DESC *pBlendDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectBlendVariable::GetBackingStore";
-
- CHECK_OBJECT_SCALAR_BOUNDS(Index, pBlendDesc);
-
- if( Data.pBlend[Index].IsUserManaged )
- {
- if( Data.pBlend[Index].pBlendObject )
- {
- Data.pBlend[Index].pBlendObject->GetDesc( pBlendDesc );
- }
- else
- {
- *pBlendDesc = CD3D11_BLEND_DESC( D3D11_DEFAULT );
- }
- }
- else
- {
- SBlendBlock *pBlock = Data.pBlend + Index;
- if (pBlock->ApplyAssignments(GetTopLevelEntity()->pEffect))
- {
- pBlock->pAssignments[0].LastRecomputedTime = 0; // Force a recreate of this block the next time ApplyRenderStateBlock is called
- }
-
- memcpy( pBlendDesc, &pBlock->BackingStore, sizeof(D3D11_BLEND_DESC) );
- }
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-bool TBlendVariable<IBaseInterface>::IsValid()
-{
- uint32_t numElements = IsArray()? pType->Elements : 1;
- bool valid = true;
- while( numElements > 0 && ( valid = Data.pBlend[ numElements-1 ].IsValid ) )
- numElements--;
- return valid;
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectDepthStencilVariable (TDepthStencilVariable implementation)
-////////////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TDepthStencilVariable : public IBaseInterface
-{
-public:
- STDMETHOD(GetDepthStencilState)(_In_ uint32_t Index, _Outptr_ ID3D11DepthStencilState **ppState) override;
- STDMETHOD(SetDepthStencilState)(_In_ uint32_t Index, _In_ ID3D11DepthStencilState *pState) override;
- STDMETHOD(UndoSetDepthStencilState)(_In_ uint32_t Index) override;
- STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_DEPTH_STENCIL_DESC *pDesc) override;
- STDMETHOD_(bool, IsValid)() override;
-};
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TDepthStencilVariable<IBaseInterface>::GetDepthStencilState(uint32_t Index, ID3D11DepthStencilState **ppState)
-{
- static LPCSTR pFuncName = "ID3DX11EffectDepthStencilVariable::GetDepthStencilState";
-
- CHECK_OBJECT_SCALAR_BOUNDS(Index, ppState);
-
- assert(Data.pDepthStencil[Index].pDSObject != 0);
- _Analysis_assume_(Data.pDepthStencil[Index].pDSObject != 0);
- *ppState = Data.pDepthStencil[Index].pDSObject;
- SAFE_ADDREF(*ppState);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TDepthStencilVariable<IBaseInterface>::SetDepthStencilState(uint32_t Index, ID3D11DepthStencilState *pState)
-{
- static LPCSTR pFuncName = "ID3DX11EffectDepthStencilState::SetDepthStencilState";
-
- CHECK_SCALAR_BOUNDS(Index);
-
- if( !Data.pDepthStencil[Index].IsUserManaged )
- {
- // Save original state object in case we UndoSet
- assert( pMemberData[Index].Type == MDT_DepthStencilState );
- VB( pMemberData[Index].Data.pD3DEffectsManagedDepthStencilState == nullptr );
- pMemberData[Index].Data.pD3DEffectsManagedDepthStencilState = Data.pDepthStencil[Index].pDSObject;
- Data.pDepthStencil[Index].pDSObject = nullptr;
- Data.pDepthStencil[Index].IsUserManaged = true;
- }
-
- SAFE_ADDREF( pState );
- SAFE_RELEASE( Data.pDepthStencil[Index].pDSObject );
- Data.pDepthStencil[Index].pDSObject = pState;
- Data.pDepthStencil[Index].IsValid = true;
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-HRESULT TDepthStencilVariable<IBaseInterface>::UndoSetDepthStencilState(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectDepthStencilState::UndoSetDepthStencilState";
-
- CHECK_SCALAR_BOUNDS(Index);
-
- if( !Data.pDepthStencil[Index].IsUserManaged )
- {
- return S_FALSE;
- }
-
- // Revert to original state object
- SAFE_RELEASE( Data.pDepthStencil[Index].pDSObject );
- Data.pDepthStencil[Index].pDSObject = pMemberData[Index].Data.pD3DEffectsManagedDepthStencilState;
- pMemberData[Index].Data.pD3DEffectsManagedDepthStencilState = nullptr;
- Data.pDepthStencil[Index].IsUserManaged = false;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TDepthStencilVariable<IBaseInterface>::GetBackingStore(uint32_t Index, D3D11_DEPTH_STENCIL_DESC *pDepthStencilDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectDepthStencilVariable::GetBackingStore";
-
- CHECK_OBJECT_SCALAR_BOUNDS(Index, pDepthStencilDesc);
-
- if( Data.pDepthStencil[Index].IsUserManaged )
- {
- if( Data.pDepthStencil[Index].pDSObject )
- {
- Data.pDepthStencil[Index].pDSObject->GetDesc( pDepthStencilDesc );
- }
- else
- {
- *pDepthStencilDesc = CD3D11_DEPTH_STENCIL_DESC( D3D11_DEFAULT );
- }
- }
- else
- {
- SDepthStencilBlock *pBlock = Data.pDepthStencil + Index;
- if (pBlock->ApplyAssignments(GetTopLevelEntity()->pEffect))
- {
- pBlock->pAssignments[0].LastRecomputedTime = 0; // Force a recreate of this block the next time ApplyRenderStateBlock is called
- }
-
- memcpy(pDepthStencilDesc, &pBlock->BackingStore, sizeof(D3D11_DEPTH_STENCIL_DESC));
- }
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-bool TDepthStencilVariable<IBaseInterface>::IsValid()
-{
- uint32_t numElements = IsArray()? pType->Elements : 1;
- bool valid = true;
- while( numElements > 0 && ( valid = Data.pDepthStencil[ numElements-1 ].IsValid ) )
- numElements--;
- return valid;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectRasterizerVariable (TRasterizerVariable implementation)
-////////////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TRasterizerVariable : public IBaseInterface
-{
-public:
-
- STDMETHOD(GetRasterizerState)(_In_ uint32_t Index, _Outptr_ ID3D11RasterizerState **ppState) override;
- STDMETHOD(SetRasterizerState)(_In_ uint32_t Index, _In_ ID3D11RasterizerState *pState) override;
- STDMETHOD(UndoSetRasterizerState)(_In_ uint32_t Index) override;
- STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_RASTERIZER_DESC *pDesc) override;
- STDMETHOD_(bool, IsValid)() override;
-};
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TRasterizerVariable<IBaseInterface>::GetRasterizerState(uint32_t Index, ID3D11RasterizerState **ppState)
-{
- static LPCSTR pFuncName = "ID3DX11EffectRasterizerVariable::GetRasterizerState";
-
- CHECK_OBJECT_SCALAR_BOUNDS(Index, ppState);
-
- assert(Data.pRasterizer[Index].pRasterizerObject != 0);
- _Analysis_assume_(Data.pRasterizer[Index].pRasterizerObject != 0);
- *ppState = Data.pRasterizer[Index].pRasterizerObject;
- SAFE_ADDREF(*ppState);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TRasterizerVariable<IBaseInterface>::SetRasterizerState(uint32_t Index, ID3D11RasterizerState *pState)
-{
- static LPCSTR pFuncName = "ID3DX11EffectRasterizerState::SetRasterizerState";
-
- CHECK_SCALAR_BOUNDS(Index);
-
- if( !Data.pRasterizer[Index].IsUserManaged )
- {
- // Save original state object in case we UndoSet
- assert( pMemberData[Index].Type == MDT_RasterizerState );
- VB( pMemberData[Index].Data.pD3DEffectsManagedRasterizerState == nullptr );
- pMemberData[Index].Data.pD3DEffectsManagedRasterizerState = Data.pRasterizer[Index].pRasterizerObject;
- Data.pRasterizer[Index].pRasterizerObject = nullptr;
- Data.pRasterizer[Index].IsUserManaged = true;
- }
-
- SAFE_ADDREF( pState );
- SAFE_RELEASE( Data.pRasterizer[Index].pRasterizerObject );
- Data.pRasterizer[Index].pRasterizerObject = pState;
- Data.pRasterizer[Index].IsValid = true;
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TRasterizerVariable<IBaseInterface>::UndoSetRasterizerState(uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectRasterizerState::UndoSetRasterizerState";
-
- CHECK_SCALAR_BOUNDS(Index);
-
- if( !Data.pRasterizer[Index].IsUserManaged )
- {
- return S_FALSE;
- }
-
- // Revert to original state object
- SAFE_RELEASE( Data.pRasterizer[Index].pRasterizerObject );
- Data.pRasterizer[Index].pRasterizerObject = pMemberData[Index].Data.pD3DEffectsManagedRasterizerState;
- pMemberData[Index].Data.pD3DEffectsManagedRasterizerState = nullptr;
- Data.pRasterizer[Index].IsUserManaged = false;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TRasterizerVariable<IBaseInterface>::GetBackingStore(uint32_t Index, D3D11_RASTERIZER_DESC *pRasterizerDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectRasterizerVariable::GetBackingStore";
-
- CHECK_OBJECT_SCALAR_BOUNDS(Index, pRasterizerDesc);
-
- if( Data.pRasterizer[Index].IsUserManaged )
- {
- if( Data.pRasterizer[Index].pRasterizerObject )
- {
- Data.pRasterizer[Index].pRasterizerObject->GetDesc( pRasterizerDesc );
- }
- else
- {
- *pRasterizerDesc = CD3D11_RASTERIZER_DESC( D3D11_DEFAULT );
- }
- }
- else
- {
- SRasterizerBlock *pBlock = Data.pRasterizer + Index;
- if (pBlock->ApplyAssignments(GetTopLevelEntity()->pEffect))
- {
- pBlock->pAssignments[0].LastRecomputedTime = 0; // Force a recreate of this block the next time ApplyRenderStateBlock is called
- }
-
- memcpy(pRasterizerDesc, &pBlock->BackingStore, sizeof(D3D11_RASTERIZER_DESC));
- }
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-bool TRasterizerVariable<IBaseInterface>::IsValid()
-{
- uint32_t numElements = IsArray()? pType->Elements : 1;
- bool valid = true;
- while( numElements > 0 && ( valid = Data.pRasterizer[ numElements-1 ].IsValid ) )
- numElements--;
- return valid;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ID3DX11EffectSamplerVariable (TSamplerVariable implementation)
-////////////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TSamplerVariable : public IBaseInterface
-{
-public:
-
- STDMETHOD(GetSampler)(_In_ uint32_t Index, _Outptr_ ID3D11SamplerState **ppSampler) override;
- STDMETHOD(SetSampler)(_In_ uint32_t Index, _In_ ID3D11SamplerState *pSampler) override;
- STDMETHOD(UndoSetSampler)(_In_ uint32_t Index) override;
- STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_SAMPLER_DESC *pDesc) override;
-};
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TSamplerVariable<IBaseInterface>::GetSampler(uint32_t Index, ID3D11SamplerState **ppSampler)
-{
- static LPCSTR pFuncName = "ID3DX11EffectSamplerVariable::GetSampler";
-
- CHECK_OBJECT_SCALAR_BOUNDS(Index, ppSampler);
-
- _Analysis_assume_( Data.pSampler[Index].pD3DObject != 0 );
- *ppSampler = Data.pSampler[Index].pD3DObject;
- SAFE_ADDREF(*ppSampler);
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TSamplerVariable<IBaseInterface>::SetSampler(uint32_t Index, ID3D11SamplerState *pSampler)
-{
- static LPCSTR pFuncName = "ID3DX11EffectSamplerState::SetSampler";
-
- CHECK_SCALAR_BOUNDS(Index);
-
- // Replace all references to the old shader block with this one
- GetEffect()->ReplaceSamplerReference(&Data.pSampler[Index], pSampler);
-
- if( !Data.pSampler[Index].IsUserManaged )
- {
- // Save original state object in case we UndoSet
- assert( pMemberData[Index].Type == MDT_SamplerState );
- VB( pMemberData[Index].Data.pD3DEffectsManagedSamplerState == nullptr );
- pMemberData[Index].Data.pD3DEffectsManagedSamplerState = Data.pSampler[Index].pD3DObject;
- Data.pSampler[Index].pD3DObject = nullptr;
- Data.pSampler[Index].IsUserManaged = true;
- }
-
- SAFE_ADDREF( pSampler );
- SAFE_RELEASE( Data.pSampler[Index].pD3DObject );
- Data.pSampler[Index].pD3DObject = pSampler;
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-HRESULT TSamplerVariable<IBaseInterface>::UndoSetSampler(_In_ uint32_t Index)
-{
- static LPCSTR pFuncName = "ID3DX11EffectSamplerState::UndoSetSampler";
-
- CHECK_SCALAR_BOUNDS(Index);
-
- if( !Data.pSampler[Index].IsUserManaged )
- {
- return S_FALSE;
- }
-
- // Replace all references to the old shader block with this one
- GetEffect()->ReplaceSamplerReference(&Data.pSampler[Index], pMemberData[Index].Data.pD3DEffectsManagedSamplerState);
-
- // Revert to original state object
- SAFE_RELEASE( Data.pSampler[Index].pD3DObject );
- Data.pSampler[Index].pD3DObject = pMemberData[Index].Data.pD3DEffectsManagedSamplerState;
- pMemberData[Index].Data.pD3DEffectsManagedSamplerState = nullptr;
- Data.pSampler[Index].IsUserManaged = false;
-
-lExit:
- return hr;
-}
-
-template<typename IBaseInterface>
-_Use_decl_annotations_
-HRESULT TSamplerVariable<IBaseInterface>::GetBackingStore(uint32_t Index, D3D11_SAMPLER_DESC *pDesc)
-{
- static LPCSTR pFuncName = "ID3DX11EffectSamplerVariable::GetBackingStore";
-
- CHECK_OBJECT_SCALAR_BOUNDS(Index, pDesc);
-
- if( Data.pSampler[Index].IsUserManaged )
- {
- if( Data.pSampler[Index].pD3DObject )
- {
- Data.pSampler[Index].pD3DObject->GetDesc( pDesc );
- }
- else
- {
- *pDesc = CD3D11_SAMPLER_DESC( D3D11_DEFAULT );
- }
- }
- else
- {
- SSamplerBlock *pBlock = Data.pSampler + Index;
- if (pBlock->ApplyAssignments(GetTopLevelEntity()->pEffect))
- {
- pBlock->pAssignments[0].LastRecomputedTime = 0; // Force a recreate of this block the next time ApplyRenderStateBlock is called
- }
-
- memcpy(pDesc, &pBlock->BackingStore.SamplerDesc, sizeof(D3D11_SAMPLER_DESC));
- }
-
-lExit:
- return hr;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// TUncastableVariable
-////////////////////////////////////////////////////////////////////////////////
-
-template<typename IBaseInterface>
-struct TUncastableVariable : public IBaseInterface
-{
- STDMETHOD_(ID3DX11EffectScalarVariable*, AsScalar)() override;
- STDMETHOD_(ID3DX11EffectVectorVariable*, AsVector)() override;
- STDMETHOD_(ID3DX11EffectMatrixVariable*, AsMatrix)() override;
- STDMETHOD_(ID3DX11EffectStringVariable*, AsString)() override;
- STDMETHOD_(ID3DX11EffectClassInstanceVariable*, AsClassInstance)() override;
- STDMETHOD_(ID3DX11EffectInterfaceVariable*, AsInterface)() override;
- STDMETHOD_(ID3DX11EffectShaderResourceVariable*, AsShaderResource)() override;
- STDMETHOD_(ID3DX11EffectUnorderedAccessViewVariable*, AsUnorderedAccessView)() override;
- STDMETHOD_(ID3DX11EffectRenderTargetViewVariable*, AsRenderTargetView)() override;
- STDMETHOD_(ID3DX11EffectDepthStencilViewVariable*, AsDepthStencilView)() override;
- STDMETHOD_(ID3DX11EffectConstantBuffer*, AsConstantBuffer)() override;
- STDMETHOD_(ID3DX11EffectShaderVariable*, AsShader)() override;
- STDMETHOD_(ID3DX11EffectBlendVariable*, AsBlend)() override;
- STDMETHOD_(ID3DX11EffectDepthStencilVariable*, AsDepthStencil)() override;
- STDMETHOD_(ID3DX11EffectRasterizerVariable*, AsRasterizer)() override;
- STDMETHOD_(ID3DX11EffectSamplerVariable*, AsSampler)() override;
-};
-
-template<typename IBaseInterface>
-ID3DX11EffectScalarVariable * TUncastableVariable<IBaseInterface>::AsScalar()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsScalar";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidScalarVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectVectorVariable * TUncastableVariable<IBaseInterface>::AsVector()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsVector";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidVectorVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectMatrixVariable * TUncastableVariable<IBaseInterface>::AsMatrix()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsMatrix";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidMatrixVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectStringVariable * TUncastableVariable<IBaseInterface>::AsString()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsString";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidStringVariable;
-}
-
-template<typename IBaseClassInstance>
-ID3DX11EffectClassInstanceVariable * TUncastableVariable<IBaseClassInstance>::AsClassInstance()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsClassInstance";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidClassInstanceVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectInterfaceVariable * TUncastableVariable<IBaseInterface>::AsInterface()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsInterface";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidInterfaceVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectShaderResourceVariable * TUncastableVariable<IBaseInterface>::AsShaderResource()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShaderResource";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidShaderResourceVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectUnorderedAccessViewVariable * TUncastableVariable<IBaseInterface>::AsUnorderedAccessView()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsUnorderedAccessView";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidUnorderedAccessViewVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectRenderTargetViewVariable * TUncastableVariable<IBaseInterface>::AsRenderTargetView()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRenderTargetView";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidRenderTargetViewVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectDepthStencilViewVariable * TUncastableVariable<IBaseInterface>::AsDepthStencilView()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencilView";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidDepthStencilViewVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectConstantBuffer * TUncastableVariable<IBaseInterface>::AsConstantBuffer()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsConstantBuffer";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidConstantBuffer;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectShaderVariable * TUncastableVariable<IBaseInterface>::AsShader()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShader";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidShaderVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectBlendVariable * TUncastableVariable<IBaseInterface>::AsBlend()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsBlend";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidBlendVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectDepthStencilVariable * TUncastableVariable<IBaseInterface>::AsDepthStencil()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencil";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidDepthStencilVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectRasterizerVariable * TUncastableVariable<IBaseInterface>::AsRasterizer()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRasterizer";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidRasterizerVariable;
-}
-
-template<typename IBaseInterface>
-ID3DX11EffectSamplerVariable * TUncastableVariable<IBaseInterface>::AsSampler()
-{
- static LPCSTR pFuncName = "ID3DX11EffectVariable::AsSampler";
- DPF(0, "%s: Invalid typecast", pFuncName);
- return &g_InvalidSamplerVariable;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Macros to instantiate the myriad templates
-////////////////////////////////////////////////////////////////////////////////
-
-// generates a global variable, annotation, global variable member, and annotation member of each struct type
-#define GenerateReflectionClasses(Type, BaseInterface) \
-struct S##Type##GlobalVariable : public T##Type##Variable<TGlobalVariable<BaseInterface>, false> { IUNKNOWN_IMP(S##Type##GlobalVariable, BaseInterface, ID3DX11EffectVariable); }; \
-struct S##Type##Annotation : public T##Type##Variable<TAnnotation<BaseInterface>, true> { IUNKNOWN_IMP(S##Type##Annotation, BaseInterface, ID3DX11EffectVariable);}; \
-struct S##Type##GlobalVariableMember : public T##Type##Variable<TVariable<TMember<BaseInterface> >, false> { IUNKNOWN_IMP(S##Type##GlobalVariableMember, BaseInterface, ID3DX11EffectVariable); }; \
-struct S##Type##AnnotationMember : public T##Type##Variable<TVariable<TMember<BaseInterface> >, true> { IUNKNOWN_IMP(S##Type##AnnotationMember, BaseInterface, ID3DX11EffectVariable); };
-
-#define GenerateVectorReflectionClasses(Type, BaseType, BaseInterface) \
-struct S##Type##GlobalVariable : public TVectorVariable<TGlobalVariable<BaseInterface>, false, BaseType> { IUNKNOWN_IMP(S##Type##GlobalVariable, BaseInterface, ID3DX11EffectVariable); }; \
-struct S##Type##Annotation : public TVectorVariable<TAnnotation<BaseInterface>, true, BaseType> { IUNKNOWN_IMP(S##Type##Annotation, BaseInterface, ID3DX11EffectVariable);}; \
-struct S##Type##GlobalVariableMember : public TVectorVariable<TVariable<TMember<BaseInterface> >, false, BaseType> { IUNKNOWN_IMP(S##Type##GlobalVariableMember, BaseInterface, ID3DX11EffectVariable);}; \
-struct S##Type##AnnotationMember : public TVectorVariable<TVariable<TMember<BaseInterface> >, true, BaseType> { IUNKNOWN_IMP(S##Type##AnnotationMember, BaseInterface, ID3DX11EffectVariable);};
-
-#define GenerateReflectionGlobalOnlyClasses(Type) \
-struct S##Type##GlobalVariable : public T##Type##Variable<TGlobalVariable<ID3DX11Effect##Type##Variable> > { IUNKNOWN_IMP(S##Type##GlobalVariable, ID3DX11Effect##Type##Variable, ID3DX11EffectVariable); }; \
-struct S##Type##GlobalVariableMember : public T##Type##Variable<TVariable<TMember<ID3DX11Effect##Type##Variable> > > { IUNKNOWN_IMP(S##Type##GlobalVariableMember, ID3DX11Effect##Type##Variable, ID3DX11EffectVariable); }; \
-
-GenerateReflectionClasses(Numeric, ID3DX11EffectVariable);
-GenerateReflectionClasses(FloatScalar, ID3DX11EffectScalarVariable);
-GenerateReflectionClasses(IntScalar, ID3DX11EffectScalarVariable);
-GenerateReflectionClasses(BoolScalar, ID3DX11EffectScalarVariable);
-GenerateVectorReflectionClasses(FloatVector, ETVT_Float, ID3DX11EffectVectorVariable);
-GenerateVectorReflectionClasses(BoolVector, ETVT_Bool, ID3DX11EffectVectorVariable);
-GenerateVectorReflectionClasses(IntVector, ETVT_Int, ID3DX11EffectVectorVariable);
-GenerateReflectionClasses(Matrix, ID3DX11EffectMatrixVariable);
-GenerateReflectionClasses(String, ID3DX11EffectStringVariable);
-GenerateReflectionGlobalOnlyClasses(ClassInstance);
-GenerateReflectionGlobalOnlyClasses(Interface);
-GenerateReflectionGlobalOnlyClasses(ShaderResource);
-GenerateReflectionGlobalOnlyClasses(UnorderedAccessView);
-GenerateReflectionGlobalOnlyClasses(RenderTargetView);
-GenerateReflectionGlobalOnlyClasses(DepthStencilView);
-GenerateReflectionGlobalOnlyClasses(Shader);
-GenerateReflectionGlobalOnlyClasses(Blend);
-GenerateReflectionGlobalOnlyClasses(DepthStencil);
-GenerateReflectionGlobalOnlyClasses(Rasterizer);
-GenerateReflectionGlobalOnlyClasses(Sampler);
-
-// Optimized matrix classes
-struct SMatrix4x4ColumnMajorGlobalVariable : public TMatrix4x4Variable<TGlobalVariable<ID3DX11EffectMatrixVariable>, true> { IUNKNOWN_IMP(SMatrix4x4ColumnMajorGlobalVariable, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); };
-struct SMatrix4x4RowMajorGlobalVariable : public TMatrix4x4Variable<TGlobalVariable<ID3DX11EffectMatrixVariable>, false> { IUNKNOWN_IMP(SMatrix4x4RowMajorGlobalVariable, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); };
-
-struct SMatrix4x4ColumnMajorGlobalVariableMember : public TMatrix4x4Variable<TVariable<TMember<ID3DX11EffectMatrixVariable> >, true> { IUNKNOWN_IMP(SMatrix4x4ColumnMajorGlobalVariableMember, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); };
-struct SMatrix4x4RowMajorGlobalVariableMember : public TMatrix4x4Variable<TVariable<TMember<ID3DX11EffectMatrixVariable> >, false> { IUNKNOWN_IMP(SMatrix4x4RowMajorGlobalVariableMember, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); };
-
-// Optimized vector classes
-struct SFloatVector4GlobalVariable : public TVector4Variable<TGlobalVariable<ID3DX11EffectVectorVariable> > { IUNKNOWN_IMP(SFloatVector4GlobalVariable, ID3DX11EffectVectorVariable, ID3DX11EffectVariable); };
-struct SFloatVector4GlobalVariableMember : public TVector4Variable<TVariable<TMember<ID3DX11EffectVectorVariable> > > { IUNKNOWN_IMP(SFloatVector4GlobalVariableMember, ID3DX11EffectVectorVariable, ID3DX11EffectVariable); };
-
-// These 3 classes should never be used directly
-
-// The "base" global variable struct (all global variables should be the same size in bytes,
-// but we pick this as the default).
-struct SGlobalVariable : public TGlobalVariable<ID3DX11EffectVariable>
-{
-
-};
-
-// The "base" annotation struct (all annotations should be the same size in bytes,
-// but we pick this as the default).
-struct SAnnotation : public TAnnotation<ID3DX11EffectVariable>
-{
-
-};
-
-// The "base" variable member struct (all annotation/global variable members should be the
-// same size in bytes, but we pick this as the default).
-struct SMember : public TVariable<TMember<ID3DX11EffectVariable> >
-{
-
-};
-
-// creates a new variable of the appropriate polymorphic type where pVar was
-HRESULT PlacementNewVariable(_In_ void *pVar, _In_ SType *pType, _In_ bool IsAnnotation);
-SMember * CreateNewMember(_In_ SType *pType, _In_ bool IsAnnotation);
-
-#pragma warning(pop)
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: IUnknownImp.h
-//
-// Direct3D 11 Effects Helper for COM interop
-//
-// Lifetime for most Effects objects is based on the the lifetime of the master
-// effect, so the reference count is not used.
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-#define IUNKNOWN_IMP(Class, Interface, BaseInterface) \
- \
-HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, _COM_Outptr_ LPVOID *ppv) override \
-{ \
- if( !ppv ) \
- return E_INVALIDARG; \
- \
- *ppv = nullptr; \
- if(IsEqualIID(iid, IID_IUnknown)) \
- { \
- *ppv = (IUnknown*)((Interface*)this); \
- } \
- else if(IsEqualIID(iid, IID_##Interface)) \
- { \
- *ppv = (Interface *)this; \
- } \
- else if(IsEqualIID(iid, IID_##BaseInterface)) \
- { \
- *ppv = (BaseInterface *)this; \
- } \
- else \
- { \
- return E_NOINTERFACE; \
- } \
- \
- return S_OK; \
-} \
- \
-ULONG STDMETHODCALLTYPE AddRef() override \
-{ \
- return 1; \
-} \
- \
-ULONG STDMETHODCALLTYPE Release() override \
-{ \
- return 0; \
-}
+++ /dev/null
- The MIT License (MIT)
-
-Copyright (c) 2009-2020 Microsoft Corp
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this
-software and associated documentation files (the "Software"), to deal in the Software
-without restriction, including without limitation the rights to use, copy, modify,
-merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be included in all copies
-or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
-INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
-PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
-CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
-OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: SOParser.h
-//
-// Direct3D 11 Effects Stream Out Decl Parser
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-#include <stdio.h>
-#include <string.h>
-
-namespace D3DX11Effects
-{
-
-//////////////////////////////////////////////////////////////////////////
-// CSOParser
-//////////////////////////////////////////////////////////////////////////
-
-class CSOParser
-{
-
- CEffectVector<D3D11_SO_DECLARATION_ENTRY> m_vDecls; // Set of parsed decl entries
- D3D11_SO_DECLARATION_ENTRY m_newEntry; // Currently parsing entry
- LPSTR m_SemanticString[D3D11_SO_BUFFER_SLOT_COUNT]; // Copy of strings
-
- static const size_t MAX_ERROR_SIZE = 254;
- char m_pError[ MAX_ERROR_SIZE + 1 ]; // Error buffer
-
-public:
- CSOParser() noexcept :
- m_newEntry{},
- m_SemanticString{},
- m_pError{}
- {
- }
-
- ~CSOParser()
- {
- for( size_t Stream = 0; Stream < D3D11_SO_STREAM_COUNT; ++Stream )
- {
- SAFE_DELETE_ARRAY( m_SemanticString[Stream] );
- }
- }
-
- // Parse a single string, assuming stream 0
- HRESULT Parse( _In_z_ LPCSTR pString )
- {
- m_vDecls.Clear();
- return Parse( 0, pString );
- }
-
- // Parse all 4 streams
- HRESULT Parse( _In_z_ LPSTR pStreams[D3D11_SO_STREAM_COUNT] )
- {
- HRESULT hr = S_OK;
- m_vDecls.Clear();
- for( uint32_t iDecl=0; iDecl < D3D11_SO_STREAM_COUNT; ++iDecl )
- {
- hr = Parse( iDecl, pStreams[iDecl] );
- if( FAILED(hr) )
- {
- char str[16];
- sprintf_s( str, 16, " in stream %u.", iDecl );
- str[15] = 0;
- strcat_s( m_pError, MAX_ERROR_SIZE, str );
- return hr;
- }
- }
- return hr;
- }
-
- // Return resulting declarations
- D3D11_SO_DECLARATION_ENTRY *GetDeclArray()
- {
- return &m_vDecls[0];
- }
-
- char* GetErrorString()
- {
- return m_pError;
- }
-
- uint32_t GetDeclCount() const
- {
- return m_vDecls.GetSize();
- }
-
- // Return resulting buffer strides
- void GetStrides( uint32_t strides[4] )
- {
- size_t len = GetDeclCount();
- strides[0] = strides[1] = strides[2] = strides[3] = 0;
-
- for( size_t i=0; i < len; i++ )
- {
- strides[m_vDecls[i].OutputSlot] += m_vDecls[i].ComponentCount * sizeof(float);
- }
- }
-
-protected:
-
- // Parse a single string "[<slot> :] <semantic>[<index>][.<mask>]; [[<slot> :] <semantic>[<index>][.<mask>][;]]"
- HRESULT Parse( _In_ uint32_t Stream, _In_z_ LPCSTR pString )
- {
- HRESULT hr = S_OK;
-
- m_pError[0] = 0;
-
- if( pString == nullptr )
- return S_OK;
-
- uint32_t len = (uint32_t)strlen( pString );
- if( len == 0 )
- return S_OK;
-
- SAFE_DELETE_ARRAY( m_SemanticString[Stream] );
- VN( m_SemanticString[Stream] = new char[len + 1] );
- strcpy_s( m_SemanticString[Stream], len + 1, pString );
-
- LPSTR pSemantic = m_SemanticString[Stream];
-
- while( true )
- {
- // Each decl entry is delimited by a semi-colon
- LPSTR pSemi = strchr( pSemantic, ';' );
-
- // strip leading and trailing spaces
- LPSTR pEnd;
- if( pSemi != nullptr )
- {
- *pSemi = '\0';
- pEnd = pSemi - 1;
- }
- else
- {
- pEnd = pSemantic + strlen( pSemantic );
- }
- while( isspace( (unsigned char)*pSemantic ) )
- pSemantic++;
- while( pEnd > pSemantic && isspace( (unsigned char)*pEnd ) )
- {
- *pEnd = '\0';
- pEnd--;
- }
-
- if( *pSemantic != '\0' )
- {
- VH( AddSemantic( pSemantic ) );
- m_newEntry.Stream = Stream;
-
- VH( m_vDecls.Add( m_newEntry ) );
- }
- if( pSemi == nullptr )
- break;
- pSemantic = pSemi + 1;
- }
-
-lExit:
- return hr;
- }
-
- // Parse a single decl "[<slot> :] <semantic>[<index>][.<mask>]"
- HRESULT AddSemantic( _Inout_z_ LPSTR pSemantic )
- {
- HRESULT hr = S_OK;
-
- assert( pSemantic );
-
- ZeroMemory( &m_newEntry, sizeof(m_newEntry) );
- VH( ConsumeOutputSlot( &pSemantic ) );
- VH( ConsumeRegisterMask( pSemantic ) );
- VH( ConsumeSemanticIndex( pSemantic ) );
-
- // pSenantic now contains only the SemanticName (all other fields were consumed)
- if( strcmp( "$SKIP", pSemantic ) != 0 )
- {
- m_newEntry.SemanticName = pSemantic;
- }
-
-lExit:
- return hr;
- }
-
- // Parse optional mask "[.<mask>]"
- HRESULT ConsumeRegisterMask( _Inout_z_ LPSTR pSemantic )
- {
- HRESULT hr = S_OK;
- const char *pFullMask1 = "xyzw";
- const char *pFullMask2 = "rgba";
- size_t stringLength;
- size_t startComponent = 0;
- LPCSTR p;
-
- assert( pSemantic );
-
- pSemantic = strchr( pSemantic, '.' );
-
- if( pSemantic == nullptr )
- {
- m_newEntry.ComponentCount = 4;
- return S_OK;
- }
-
- *pSemantic = '\0';
- pSemantic++;
-
- stringLength = strlen( pSemantic );
- p = strstr(pFullMask1, pSemantic );
- if( p )
- {
- startComponent = (uint32_t)( p - pFullMask1 );
- }
- else
- {
- p = strstr( pFullMask2, pSemantic );
- if( p )
- startComponent = (uint32_t)( p - pFullMask2 );
- else
- {
- sprintf_s( m_pError, MAX_ERROR_SIZE, "ID3D11Effect::ParseSODecl - invalid mask declaration '%s'", pSemantic );
- VH( E_FAIL );
- }
-
- }
-
- if( stringLength == 0 )
- stringLength = 4;
-
- m_newEntry.StartComponent = (uint8_t)startComponent;
- m_newEntry.ComponentCount = (uint8_t)stringLength;
-
-lExit:
- return hr;
- }
-
- // Parse optional output slot "[<slot> :]"
- HRESULT ConsumeOutputSlot( _Inout_z_ LPSTR* ppSemantic )
- {
- assert( ppSemantic && *ppSemantic );
- _Analysis_assume_( ppSemantic && *ppSemantic );
-
- HRESULT hr = S_OK;
- LPSTR pColon = strchr( *ppSemantic, ':' );
-
- if( pColon == nullptr )
- return S_OK;
-
- if( pColon == *ppSemantic )
- {
- strcpy_s( m_pError, MAX_ERROR_SIZE,
- "ID3D11Effect::ParseSODecl - Invalid output slot" );
- VH( E_FAIL );
- }
-
- *pColon = '\0';
- int outputSlot = atoi( *ppSemantic );
- if( outputSlot < 0 || outputSlot > 255 )
- {
- strcpy_s( m_pError, MAX_ERROR_SIZE,
- "ID3D11Effect::ParseSODecl - Invalid output slot" );
- VH( E_FAIL );
- }
- m_newEntry.OutputSlot = (uint8_t)outputSlot;
-
- while( *ppSemantic < pColon )
- {
- if( !isdigit( (unsigned char)**ppSemantic ) )
- {
- sprintf_s( m_pError, MAX_ERROR_SIZE, "ID3D11Effect::ParseSODecl - Non-digit '%c' in output slot", **ppSemantic );
- VH( E_FAIL );
- }
- (*ppSemantic)++;
- }
-
- // skip the colon (which is now '\0')
- (*ppSemantic)++;
-
- while( isspace( (unsigned char)**ppSemantic ) )
- (*ppSemantic)++;
-
-lExit:
- return hr;
- }
-
- // Parse optional index "[<index>]"
- HRESULT ConsumeSemanticIndex( _Inout_z_ LPSTR pSemantic )
- {
- assert( pSemantic );
-
- uint32_t uLen = (uint32_t)strlen( pSemantic );
-
- // Grab semantic index
- while( uLen > 0 && isdigit( (unsigned char)pSemantic[uLen - 1] ) )
- uLen--;
-
- if( isdigit( (unsigned char)pSemantic[uLen] ) )
- {
- m_newEntry.SemanticIndex = atoi( pSemantic + uLen );
- pSemantic[uLen] = '\0';
- }
- else
- {
- m_newEntry.SemanticIndex = 0;
- }
-
- return S_OK;
- }
-};
-
-} // end namespace D3DX11Effects
+++ /dev/null
-#ifdef FX11
-
-//--------------------------------------------------------------------------------------
-// File: d3dxGlobal.cpp
-//
-// Direct3D 11 Effects implementation for helper data structures
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#include "pchfx.h"
-
-#include <intsafe.h>
-
-#include <stdio.h>
-#include <stdarg.h>
-
-namespace D3DX11Core
-{
-
- //////////////////////////////////////////////////////////////////////////
- // CMemoryStream - A class to simplify reading binary data
- //////////////////////////////////////////////////////////////////////////
-
- CMemoryStream::CMemoryStream() noexcept :
- m_pData(nullptr),
- m_cbData(0),
- m_readPtr(0)
- {
- }
-
- CMemoryStream::~CMemoryStream()
- {
- }
-
- _Use_decl_annotations_
- HRESULT CMemoryStream::SetData(const void* pData, size_t size)
- {
- m_pData = (uint8_t*)pData;
- m_cbData = size;
- m_readPtr = 0;
-
- return S_OK;
- }
-
- _Use_decl_annotations_
- HRESULT CMemoryStream::ReadAtOffset(size_t offset, size_t size, void** ppData)
- {
- if (offset >= m_cbData)
- return E_FAIL;
-
- m_readPtr = offset;
- return Read(ppData, size);
- }
-
- _Use_decl_annotations_
- HRESULT CMemoryStream::ReadAtOffset(size_t offset, LPCSTR* ppString)
- {
- if (offset >= m_cbData)
- return E_FAIL;
-
- m_readPtr = offset;
- return Read(ppString);
- }
-
- _Use_decl_annotations_
- HRESULT CMemoryStream::Read(void** ppData, size_t size)
- {
- size_t temp = m_readPtr + size;
-
- if (temp < m_readPtr || temp > m_cbData)
- return E_FAIL;
-
- *ppData = m_pData + m_readPtr;
- m_readPtr = temp;
- return S_OK;
- }
-
- _Use_decl_annotations_
- HRESULT CMemoryStream::Read(uint32_t* pDword)
- {
- uint32_t* pTempDword;
- HRESULT hr;
-
- hr = Read((void**)&pTempDword, sizeof(uint32_t));
- if (FAILED(hr))
- return E_FAIL;
-
- *pDword = *pTempDword;
- return S_OK;
- }
-
- _Use_decl_annotations_
- HRESULT CMemoryStream::Read(LPCSTR* ppString)
- {
- size_t iChar = m_readPtr;
- for (; m_pData[iChar]; iChar++)
- {
- if (iChar > m_cbData)
- return E_FAIL;
- }
-
- *ppString = (LPCSTR)(m_pData + m_readPtr);
- m_readPtr = iChar;
-
- return S_OK;
- }
-
- size_t CMemoryStream::GetPosition()
- {
- return m_readPtr;
- }
-
- HRESULT CMemoryStream::Seek(_In_ size_t offset)
- {
- if (offset > m_cbData)
- return E_FAIL;
-
- m_readPtr = offset;
- return S_OK;
- }
-
-}
-
-//////////////////////////////////////////////////////////////////////////
-// CDataBlock - used to dynamically build up the effect file in memory
-//////////////////////////////////////////////////////////////////////////
-
-CDataBlock::CDataBlock() noexcept :
- m_size(0),
- m_maxSize(0),
- m_pData(nullptr),
- m_pNext(nullptr),
- m_IsAligned(false)
-{
-}
-
-CDataBlock::~CDataBlock()
-{
- SAFE_DELETE_ARRAY(m_pData);
- SAFE_DELETE(m_pNext);
-}
-
-void CDataBlock::EnableAlignment()
-{
- m_IsAligned = true;
-}
-
-_Use_decl_annotations_
-HRESULT CDataBlock::AddData(const void* pvNewData, uint32_t bufferSize, CDataBlock** ppBlock)
-{
- HRESULT hr = S_OK;
- uint32_t bytesToCopy;
- const uint8_t* pNewData = (const uint8_t*)pvNewData;
-
- if (m_maxSize == 0)
- {
- // This is a brand new DataBlock, fill it up
- m_maxSize = std::max<uint32_t>(8192, bufferSize);
-
- VN(m_pData = new uint8_t[m_maxSize]);
- }
-
- assert(m_pData == AlignToPowerOf2(m_pData, c_DataAlignment));
-
- bytesToCopy = std::min(m_maxSize - m_size, bufferSize);
- memcpy(m_pData + m_size, pNewData, bytesToCopy);
- pNewData += bytesToCopy;
-
- if (m_IsAligned)
- {
- assert(m_size == AlignToPowerOf2(m_size, c_DataAlignment));
- m_size += AlignToPowerOf2(bytesToCopy, c_DataAlignment);
- }
- else
- {
- m_size += bytesToCopy;
- }
-
- bufferSize -= bytesToCopy;
- *ppBlock = this;
-
- if (bufferSize != 0)
- {
- assert(nullptr == m_pNext); // make sure we're not overwriting anything
-
- // Couldn't fit all data into this block, spill over into next
- VN(m_pNext = new CDataBlock());
- if (m_IsAligned)
- {
- m_pNext->EnableAlignment();
- }
- VH(m_pNext->AddData(pNewData, bufferSize, ppBlock));
- }
-
-lExit:
- return hr;
-}
-
-_Use_decl_annotations_
-void* CDataBlock::Allocate(uint32_t bufferSize, CDataBlock** ppBlock)
-{
- void* pRetValue;
- uint32_t temp = m_size + bufferSize;
-
- if (temp < m_size)
- return nullptr;
-
- *ppBlock = this;
-
- if (m_maxSize == 0)
- {
- // This is a brand new DataBlock, fill it up
- m_maxSize = std::max<uint32_t>(8192, bufferSize);
-
- m_pData = new uint8_t[m_maxSize];
- if (!m_pData)
- return nullptr;
- memset(m_pData, 0xDD, m_maxSize);
- }
- else if (temp > m_maxSize)
- {
- assert(nullptr == m_pNext); // make sure we're not overwriting anything
-
- // Couldn't fit data into this block, spill over into next
- m_pNext = new CDataBlock();
- if (!m_pNext)
- return nullptr;
- if (m_IsAligned)
- {
- m_pNext->EnableAlignment();
- }
-
- return m_pNext->Allocate(bufferSize, ppBlock);
- }
-
- assert(m_pData == AlignToPowerOf2(m_pData, c_DataAlignment));
-
- pRetValue = m_pData + m_size;
- if (m_IsAligned)
- {
- assert(m_size == AlignToPowerOf2(m_size, c_DataAlignment));
- m_size = AlignToPowerOf2(temp, c_DataAlignment);
- }
- else
- {
- m_size = temp;
- }
-
- return pRetValue;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-
-CDataBlockStore::CDataBlockStore() noexcept :
- m_pFirst(nullptr),
- m_pLast(nullptr),
- m_Size(0),
- m_Offset(0),
- m_IsAligned(false)
-{
-#if _DEBUG
- m_cAllocations = 0;
-#endif
-}
-
-CDataBlockStore::~CDataBlockStore()
-{
- // Can't just do SAFE_DELETE(m_pFirst) since it blows the stack when deleting long chains of data
- CDataBlock* pData = m_pFirst;
- while (pData)
- {
- CDataBlock* pCurrent = pData;
- pData = pData->m_pNext;
- pCurrent->m_pNext = nullptr;
- delete pCurrent;
- }
-
- // m_pLast will be deleted automatically
-}
-
-void CDataBlockStore::EnableAlignment()
-{
- m_IsAligned = true;
-}
-
-_Use_decl_annotations_
-HRESULT CDataBlockStore::AddString(LPCSTR pString, uint32_t* pOffset)
-{
- size_t strSize = strlen(pString) + 1;
- assert(strSize <= 0xffffffff);
- return AddData(pString, (uint32_t)strSize, pOffset);
-}
-
-_Use_decl_annotations_
-HRESULT CDataBlockStore::AddData(const void* pNewData, uint32_t bufferSize, uint32_t* pCurOffset)
-{
- HRESULT hr = S_OK;
-
- if (bufferSize == 0)
- {
- if (pCurOffset)
- {
- *pCurOffset = 0;
- }
- goto lExit;
- }
-
- if (!m_pFirst)
- {
- VN(m_pFirst = new CDataBlock());
- if (m_IsAligned)
- {
- m_pFirst->EnableAlignment();
- }
- m_pLast = m_pFirst;
- }
-
- if (pCurOffset)
- *pCurOffset = m_Size + m_Offset;
-
- VH(m_pLast->AddData(pNewData, bufferSize, &m_pLast));
- m_Size += bufferSize;
-
-lExit:
- return hr;
-}
-
-void* CDataBlockStore::Allocate(_In_ uint32_t bufferSize)
-{
- void* pRetValue = nullptr;
-
-#if _DEBUG
- m_cAllocations++;
-#endif
-
- if (!m_pFirst)
- {
- m_pFirst = new CDataBlock();
- if (!m_pFirst)
- return nullptr;
-
- if (m_IsAligned)
- {
- m_pFirst->EnableAlignment();
- }
- m_pLast = m_pFirst;
- }
-
- if (FAILED(UIntAdd(m_Size, bufferSize, &m_Size)))
- return nullptr;
-
- pRetValue = m_pLast->Allocate(bufferSize, &m_pLast);
- if (!pRetValue)
- return nullptr;
-
- return pRetValue;
-}
-
-uint32_t CDataBlockStore::GetSize()
-{
- return m_Size;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-
-static bool s_mute = false;
-
-bool D3DX11DebugMute(bool mute)
-{
- bool previous = s_mute;
- s_mute = mute;
- return previous;
-}
-
-#ifdef _DEBUG
-_Use_decl_annotations_
-void __cdecl D3DXDebugPrintf(UINT lvl, LPCSTR szFormat, ...)
-{
- if (s_mute)
- return;
-
- UNREFERENCED_PARAMETER(lvl);
-
- char strA[4096] = {};
- char strB[4096] = {};
-
- va_list ap;
- va_start(ap, szFormat);
- vsprintf_s(strA, sizeof(strA), szFormat, ap);
- strA[4095] = '\0';
- va_end(ap);
-
- sprintf_s(strB, sizeof(strB), "Effects11: %s\r\n", strA);
-
- strB[4095] = '\0';
-
- OutputDebugStringA(strB);
-}
-#endif // _DEBUG
-
-#endif
\ No newline at end of file
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: D3DXGlobal.h
-//
-// Direct3D 11 Effects helper defines and data structures
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-#include <assert.h>
-#include <string.h>
-
-namespace D3DX11Debug
-{
- // Helper sets a D3D resource name string (used by PIX and debug layer leak reporting).
- inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char *name )
- {
- #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
- resource->SetPrivateData( WKPDID_D3DDebugObjectName, static_cast<UINT>(strlen(name)), name );
- #else
- UNREFERENCED_PARAMETER(resource);
- UNREFERENCED_PARAMETER(name);
- #endif
- }
-
- template<UINT TNameLength>
- inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength])
- {
- #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
- resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
- #else
- UNREFERENCED_PARAMETER(resource);
- UNREFERENCED_PARAMETER(name);
- #endif
- }
-}
-
-using namespace D3DX11Debug;
-
-#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = nullptr; } }
-#define SAFE_ADDREF(p) { if (p) { (p)->AddRef(); } }
-
-#define SAFE_DELETE_ARRAY(p) { delete [](p); p = nullptr; }
-#define SAFE_DELETE(p) { delete (p); p = nullptr; }
-
-#if FXDEBUG
-#define __BREAK_ON_FAIL { __debugbreak(); }
-#else
-#define __BREAK_ON_FAIL
-#endif
-
-#define VA(x, action) { hr = (x); if (FAILED(hr)) { action; __BREAK_ON_FAIL; return hr; } }
-#define VNA(x,action) { if (!(x)) { action; __BREAK_ON_FAIL; hr = E_OUTOFMEMORY; goto lExit; } }
-#define VBA(x,action) { if (!(x)) { action; __BREAK_ON_FAIL; hr = E_FAIL; goto lExit; } }
-#define VHA(x,action) { hr = (x); if (FAILED(hr)) { action; __BREAK_ON_FAIL; goto lExit; } }
-
-#define V(x) { VA (x, 0) }
-#define VN(x) { VNA(x, 0) }
-#define VB(x) { VBA(x, 0) }
-#define VH(x) { VHA(x, 0) }
-
-#define VBD(x,str) { VBA(x, DPF(1,str)) }
-#define VHD(x,str) { VHA(x, DPF(1,str)) }
-
-#define VEASSERT(x) { hr = (x); if (FAILED(hr)) { __BREAK_ON_FAIL; assert(!#x); goto lExit; } }
-#define VNASSERT(x) { if (!(x)) { __BREAK_ON_FAIL; assert(!#x); hr = E_OUTOFMEMORY; goto lExit; } }
-
-#define D3DX11FLTASSIGN(a,b) { *reinterpret_cast< UINT32* >(&(a)) = *reinterpret_cast< UINT32* >(&(b)); }
-
-// Preferred data alignment -- must be a power of 2!
-static const uint32_t c_DataAlignment = sizeof(UINT_PTR);
-
-inline uint32_t AlignToPowerOf2(uint32_t Value, uint32_t Alignment)
-{
- assert((Alignment & (Alignment - 1)) == 0);
- // to align to 2^N, add 2^N - 1 and AND with all but lowest N bits set
- _Analysis_assume_(Alignment > 0 && Value < MAXDWORD - Alignment);
- return (Value + Alignment - 1) & (~(Alignment - 1));
-}
-
-inline void * AlignToPowerOf2(void *pValue, UINT_PTR Alignment)
-{
- assert((Alignment & (Alignment - 1)) == 0);
- // to align to 2^N, add 2^N - 1 and AND with all but lowest N bits set
- return (void *)(((UINT_PTR)pValue + Alignment - 1) & (~((UINT_PTR)Alignment - 1)));
-}
-
-namespace D3DX11Core
-{
-
-//////////////////////////////////////////////////////////////////////////
-// CMemoryStream - A class to simplify reading binary data
-//////////////////////////////////////////////////////////////////////////
-class CMemoryStream
-{
- uint8_t *m_pData;
- size_t m_cbData;
- size_t m_readPtr;
-
-public:
- HRESULT SetData(_In_reads_bytes_(size) const void *pData, _In_ size_t size);
-
- HRESULT Read(_Out_ uint32_t *pUint);
- HRESULT Read(_Outptr_result_buffer_(size) void **ppData, _In_ size_t size);
- HRESULT Read(_Outptr_ LPCSTR *ppString);
-
- HRESULT ReadAtOffset(_In_ size_t offset, _In_ size_t size, _Outptr_result_buffer_(size) void **ppData);
- HRESULT ReadAtOffset(_In_ size_t offset, _Outptr_result_z_ LPCSTR *ppString);
-
- size_t GetPosition();
- HRESULT Seek(_In_ size_t offset);
-
- CMemoryStream() noexcept;
- ~CMemoryStream();
-};
-
-}
-
-#if defined(_DEBUG) && !defined(_M_X64) && !defined(_M_ARM64)
-
-namespace D3DX11Debug
-{
-
-// This variable indicates how many ticks to go before rolling over
-// all of the timer variables in the FX system.
-// It is read from the system registry in debug builds; in retail the high bit is simply tested.
-
-_declspec(selectany) unsigned int g_TimerRolloverCount = 0x80000000;
-}
-
-#endif // _DEBUG && !_M_X64
-
-
-//////////////////////////////////////////////////////////////////////////
-// CEffectVector - A vector implementation
-//////////////////////////////////////////////////////////////////////////
-
-template<class T> class CEffectVector
-{
-protected:
-#if _DEBUG
- T *m_pCastData; // makes debugging easier to have a casted version of the data
-#endif // _DEBUG
-
- uint8_t *m_pData;
- uint32_t m_MaxSize;
- uint32_t m_CurSize;
-
- HRESULT Grow()
- {
- return Reserve(m_CurSize + 1);
- }
-
- HRESULT Reserve(_In_ uint32_t DesiredSize)
- {
- if (DesiredSize > m_MaxSize)
- {
- uint8_t *pNewData;
- uint32_t newSize = std::max(m_MaxSize * 2, DesiredSize);
-
- if (newSize < 16)
- newSize = 16;
-
- if ((newSize < m_MaxSize) || (newSize < m_CurSize) || (newSize >= UINT_MAX / sizeof(T)))
- {
- m_hLastError = E_OUTOFMEMORY;
- return m_hLastError;
- }
-
- pNewData = new uint8_t[newSize * sizeof(T)];
- if (pNewData == nullptr)
- {
- m_hLastError = E_OUTOFMEMORY;
- return m_hLastError;
- }
-
- if (m_pData)
- {
- memcpy(pNewData, m_pData, m_CurSize * sizeof(T));
- delete []m_pData;
- }
-
- m_pData = pNewData;
- m_MaxSize = newSize;
- }
-#if _DEBUG
- m_pCastData = (T*) m_pData;
-#endif // _DEBUG
- return S_OK;
- }
-
-public:
- HRESULT m_hLastError;
-
- CEffectVector<T>() noexcept :
- m_hLastError(S_OK),
- m_pData(nullptr),
- m_CurSize(0),
- m_MaxSize(0)
- {
-#if _DEBUG
- m_pCastData = nullptr;
-#endif // _DEBUG
- }
-
- ~CEffectVector<T>()
- {
- Clear();
- }
-
- // cleanly swaps two vectors -- useful for when you want
- // to reallocate a vector and copy data over, then swap them back
- void SwapVector(_Out_ CEffectVector<T> &vOther)
- {
- uint8_t tempData[sizeof(*this)];
-
- memcpy(tempData, this, sizeof(*this));
- memcpy(this, &vOther, sizeof(*this));
- memcpy(&vOther, tempData, sizeof(*this));
- }
-
- HRESULT CopyFrom(_In_ const CEffectVector<T> &vOther)
- {
- HRESULT hr = S_OK;
- Clear();
- VN( m_pData = new uint8_t[vOther.m_MaxSize * sizeof(T)] );
-
- m_CurSize = vOther.m_CurSize;
- m_MaxSize = vOther.m_MaxSize;
- m_hLastError = vOther.m_hLastError;
-
- for (size_t i = 0; i < m_CurSize; ++ i)
- {
- ((T*)m_pData)[i] = ((T*)vOther.m_pData)[i];
- }
-
-lExit:
-
-#if _DEBUG
- m_pCastData = (T*) m_pData;
-#endif // _DEBUG
-
- return hr;
- }
-
- void Clear()
- {
- Empty();
- SAFE_DELETE_ARRAY(m_pData);
- m_MaxSize = 0;
-#if _DEBUG
- m_pCastData = nullptr;
-#endif // _DEBUG
- }
-
- void ClearWithoutDestructor()
- {
- m_CurSize = 0;
- m_hLastError = S_OK;
- SAFE_DELETE_ARRAY(m_pData);
- m_MaxSize = 0;
-
-#if _DEBUG
- m_pCastData = nullptr;
-#endif // _DEBUG
- }
-
- void Empty()
- {
-
- // manually invoke destructor on all elements
- for (size_t i = 0; i < m_CurSize; ++ i)
- {
- ((T*)m_pData + i)->~T();
- }
- m_CurSize = 0;
- m_hLastError = S_OK;
- }
-
- T* Add()
- {
- if (FAILED(Grow()))
- return nullptr;
-
- // placement new
- return new((T*)m_pData + (m_CurSize ++)) T;
- }
-
- T* AddRange(_In_ uint32_t count)
- {
- if (m_CurSize + count < m_CurSize)
- {
- m_hLastError = E_OUTOFMEMORY;
- return nullptr;
- }
-
- if (FAILED(Reserve(m_CurSize + count)))
- return nullptr;
-
- T *pData = (T*)m_pData + m_CurSize;
- for (size_t i = 0; i < count; ++ i)
- {
- new(pData + i) T;
- }
- m_CurSize += count;
- return pData;
- }
-
- HRESULT Add(_In_ const T& var)
- {
- if (FAILED(Grow()))
- return m_hLastError;
-
- memcpy((T*)m_pData + m_CurSize, &var, sizeof(T));
- m_CurSize++;
-
- return S_OK;
- }
-
- HRESULT AddRange(_In_reads_(count) const T *pVar, _In_ uint32_t count)
- {
- if (m_CurSize + count < m_CurSize)
- {
- m_hLastError = E_OUTOFMEMORY;
- return m_hLastError;
- }
-
- if (FAILED(Reserve(m_CurSize + count)))
- return m_hLastError;
-
- memcpy((T*)m_pData + m_CurSize, pVar, count * sizeof(T));
- m_CurSize += count;
-
- return S_OK;
- }
-
- HRESULT Insert(_In_ const T& var, _In_ uint32_t index)
- {
- assert(index < m_CurSize);
-
- if (FAILED(Grow()))
- return m_hLastError;
-
- memmove((T*)m_pData + index + 1, (T*)m_pData + index, (m_CurSize - index) * sizeof(T));
- memcpy((T*)m_pData + index, &var, sizeof(T));
- m_CurSize++;
-
- return S_OK;
- }
-
- HRESULT InsertRange(_In_reads_(count) const T *pVar, _In_ uint32_t index, _In_ uint32_t count)
- {
- assert(index < m_CurSize);
-
- if (m_CurSize + count < m_CurSize)
- {
- m_hLastError = E_OUTOFMEMORY;
- return m_hLastError;
- }
-
- if (FAILED(Reserve(m_CurSize + count)))
- return m_hLastError;
-
- memmove((T*)m_pData + index + count, (T*)m_pData + index, (m_CurSize - index) * sizeof(T));
- memcpy((T*)m_pData + index, pVar, count * sizeof(T));
- m_CurSize += count;
-
- return S_OK;
- }
-
- inline T& operator[](_In_ size_t index)
- {
- assert(index < m_CurSize);
- return ((T*)m_pData)[index];
- }
-
- // Deletes element at index and shifts all other values down
- void Delete(_In_ uint32_t index)
- {
- assert(index < m_CurSize);
-
- -- m_CurSize;
- memmove((T*)m_pData + index, (T*)m_pData + index + 1, (m_CurSize - index) * sizeof(T));
- }
-
- // Deletes element at index and moves the last element into its place
- void QuickDelete(_In_ uint32_t index)
- {
- assert(index < m_CurSize);
-
- -- m_CurSize;
- memcpy((T*)m_pData + index, (T*)m_pData + m_CurSize, sizeof(T));
- }
-
- inline uint32_t GetSize() const
- {
- return m_CurSize;
- }
-
- inline T* GetData() const
- {
- return (T*)m_pData;
- }
-
- uint32_t FindIndexOf(_In_ const void *pEntry) const
- {
- for (size_t i = 0; i < m_CurSize; ++ i)
- {
- if (((T*)m_pData + i) == pEntry)
- return i;
- }
-
- return -1;
- }
-
- void Sort(int (__cdecl *pfnCompare)(const void *pElem1, const void *pElem2))
- {
- qsort(m_pData, m_CurSize, sizeof(T), pfnCompare);
- }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// CEffectVectorOwner - implements a vector of ptrs to objects. The vector owns the objects.
-//////////////////////////////////////////////////////////////////////////
-template<class T> class CEffectVectorOwner : public CEffectVector<T*>
-{
-public:
- ~CEffectVectorOwner<T>()
- {
- Clear();
-
- for (size_t i=0; i<m_CurSize; i++)
- SAFE_DELETE(((T**)m_pData)[i]);
-
- SAFE_DELETE_ARRAY(m_pData);
- }
-
- void Clear()
- {
- Empty();
- SAFE_DELETE_ARRAY(m_pData);
- m_MaxSize = 0;
- }
-
- void Empty()
- {
- // manually invoke destructor on all elements
- for (size_t i = 0; i < m_CurSize; ++ i)
- {
- SAFE_DELETE(((T**)m_pData)[i]);
- }
- m_CurSize = 0;
- m_hLastError = S_OK;
- }
-
- void Delete(_In_ uint32_t index)
- {
- assert(index < m_CurSize);
-
- SAFE_DELETE(((T**)m_pData)[index]);
-
- CEffectVector<T*>::Delete(index);
- }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Checked uint32_t, uint64_t
-// Use CheckedNumber only with uint32_t and uint64_t
-//////////////////////////////////////////////////////////////////////////
-template <class T, T MaxValue> class CheckedNumber
-{
- T m_Value;
- bool m_bValid;
-
-public:
- CheckedNumber<T, MaxValue>() noexcept :
- m_Value(0),
- m_bValid(true)
- {
- }
-
- CheckedNumber<T, MaxValue>(const T &value) : m_Value(value), m_bValid(true)
- {
- }
-
- CheckedNumber<T, MaxValue>(const CheckedNumber<T, MaxValue> &value) : m_bValid(value.m_bValid), m_Value(value.m_Value)
- {
- }
-
- CheckedNumber<T, MaxValue> &operator+(const CheckedNumber<T, MaxValue> &other)
- {
- CheckedNumber<T, MaxValue> Res(*this);
- return Res+=other;
- }
-
- CheckedNumber<T, MaxValue> &operator+=(const CheckedNumber<T, MaxValue> &other)
- {
- if (!other.m_bValid)
- {
- m_bValid = false;
- }
- else
- {
- m_Value += other.m_Value;
-
- if (m_Value < other.m_Value)
- m_bValid = false;
- }
-
- return *this;
- }
-
- CheckedNumber<T, MaxValue> &operator*(const CheckedNumber<T, MaxValue> &other)
- {
- CheckedNumber<T, MaxValue> Res(*this);
- return Res*=other;
- }
-
- CheckedNumber<T, MaxValue> &operator*=(const CheckedNumber<T, MaxValue> &other)
- {
- if (!other.m_bValid)
- {
- m_bValid = false;
- }
- else
- {
- if (other.m_Value != 0)
- {
- if (m_Value > MaxValue / other.m_Value)
- {
- m_bValid = false;
- }
- }
- m_Value *= other.m_Value;
- }
-
- return *this;
- }
-
- HRESULT GetValue(_Out_ T *pValue)
- {
- if (!m_bValid)
- {
- *pValue = uint32_t(-1);
- return E_FAIL;
- }
-
- *pValue = m_Value;
- return S_OK;
- }
-};
-
-typedef CheckedNumber<uint32_t, _UI32_MAX> CCheckedDword;
-typedef CheckedNumber<uint64_t, _UI64_MAX> CCheckedDword64;
-
-
-//////////////////////////////////////////////////////////////////////////
-// Data Block Store - A linked list of allocations
-//////////////////////////////////////////////////////////////////////////
-
-class CDataBlock
-{
-protected:
- uint32_t m_size;
- uint32_t m_maxSize;
- uint8_t *m_pData;
- CDataBlock *m_pNext;
-
- bool m_IsAligned; // Whether or not to align the data to c_DataAlignment
-
-public:
- // AddData appends an existing use buffer to the data block
- HRESULT AddData(_In_reads_bytes_(bufferSize) const void *pNewData, _In_ uint32_t bufferSize, _Outptr_ CDataBlock **ppBlock);
-
- // Allocate reserves bufferSize bytes of contiguous memory and returns a pointer to the user
- _Success_(return != nullptr)
- void* Allocate(_In_ uint32_t bufferSize, _Outptr_ CDataBlock **ppBlock);
-
- void EnableAlignment();
-
- CDataBlock() noexcept;
- ~CDataBlock();
-
- friend class CDataBlockStore;
-};
-
-
-class CDataBlockStore
-{
-protected:
- CDataBlock *m_pFirst;
- CDataBlock *m_pLast;
- uint32_t m_Size;
- uint32_t m_Offset; // m_Offset gets added to offsets returned from AddData & AddString. Use this to set a global for the entire string block
- bool m_IsAligned; // Whether or not to align the data to c_DataAlignment
-
-public:
-#if _DEBUG
- uint32_t m_cAllocations;
-#endif
-
-public:
- HRESULT AddString(_In_z_ LPCSTR pString, _Inout_ uint32_t *pOffset);
- // Writes a null-terminated string to buffer
-
- HRESULT AddData(_In_reads_bytes_(bufferSize) const void *pNewData, _In_ uint32_t bufferSize, _Inout_ uint32_t *pOffset);
- // Writes data block to buffer
-
- // Memory allocator support
- void* Allocate(_In_ uint32_t bufferSize);
- uint32_t GetSize();
- void EnableAlignment();
-
- CDataBlockStore() noexcept;
- ~CDataBlockStore();
-};
-
-// Custom allocator that uses CDataBlockStore
-// The trick is that we never free, so we don't have to keep as much state around
-// Use PRIVATENEW in CEffectLoader
-
-inline void* __cdecl operator new(_In_ size_t s, _In_ CDataBlockStore &pAllocator)
-{
-#ifdef _M_X64
- assert( s <= 0xffffffff );
-#endif
- return pAllocator.Allocate( (uint32_t)s );
-}
-
-inline void __cdecl operator delete(_In_opt_ void* p, _In_ CDataBlockStore &pAllocator)
-{
- UNREFERENCED_PARAMETER(p);
- UNREFERENCED_PARAMETER(pAllocator);
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-// Hash table
-//////////////////////////////////////////////////////////////////////////
-
-#define HASH_MIX(a,b,c) \
-{ \
- a -= b; a -= c; a ^= (c>>13); \
- b -= c; b -= a; b ^= (a<<8); \
- c -= a; c -= b; c ^= (b>>13); \
- a -= b; a -= c; a ^= (c>>12); \
- b -= c; b -= a; b ^= (a<<16); \
- c -= a; c -= b; c ^= (b>>5); \
- a -= b; a -= c; a ^= (c>>3); \
- b -= c; b -= a; b ^= (a<<10); \
- c -= a; c -= b; c ^= (b>>15); \
-}
-
-static uint32_t ComputeHash(_In_reads_bytes_(cbToHash) const uint8_t *pb, _In_ uint32_t cbToHash)
-{
- uint32_t cbLeft = cbToHash;
-
- uint32_t a;
- uint32_t b;
- a = b = 0x9e3779b9; // the golden ratio; an arbitrary value
-
- uint32_t c = 0;
-
- while (cbLeft >= 12)
- {
- const uint32_t *pdw = reinterpret_cast<const uint32_t *>(pb);
-
- a += pdw[0];
- b += pdw[1];
- c += pdw[2];
-
- HASH_MIX(a,b,c);
- pb += 12;
- cbLeft -= 12;
- }
-
- c += cbToHash;
-
- switch(cbLeft) // all the case statements fall through
- {
- case 11: c+=((uint32_t) pb[10] << 24);
- case 10: c+=((uint32_t) pb[9] << 16);
- case 9 : c+=((uint32_t) pb[8] << 8);
- // the first byte of c is reserved for the length
- case 8 : b+=((uint32_t) pb[7] << 24);
- case 7 : b+=((uint32_t) pb[6] << 16);
- case 6 : b+=((uint32_t) pb[5] << 8);
- case 5 : b+=pb[4];
- case 4 : a+=((uint32_t) pb[3] << 24);
- case 3 : a+=((uint32_t) pb[2] << 16);
- case 2 : a+=((uint32_t) pb[1] << 8);
- case 1 : a+=pb[0];
- }
-
- HASH_MIX(a,b,c);
-
- return c;
-}
-
-static uint32_t ComputeHashLower(_In_reads_bytes_(cbToHash) const uint8_t *pb, _In_ uint32_t cbToHash)
-{
- uint32_t cbLeft = cbToHash;
-
- uint32_t a;
- uint32_t b;
- a = b = 0x9e3779b9; // the golden ratio; an arbitrary value
- uint32_t c = 0;
-
- while (cbLeft >= 12)
- {
- uint8_t pbT[12];
- for( size_t i = 0; i < 12; i++ )
- pbT[i] = (uint8_t)tolower(pb[i]);
-
- uint32_t *pdw = reinterpret_cast<uint32_t *>(pbT);
-
- a += pdw[0];
- b += pdw[1];
- c += pdw[2];
-
- HASH_MIX(a,b,c);
- pb += 12;
- cbLeft -= 12;
- }
-
- c += cbToHash;
-
- uint8_t pbT[12];
- for( size_t i = 0; i < cbLeft; i++ )
- pbT[i] = (uint8_t)tolower(pb[i]);
-
- switch(cbLeft) // all the case statements fall through
- {
- case 11: c+=((uint32_t) pbT[10] << 24);
- case 10: c+=((uint32_t) pbT[9] << 16);
- case 9 : c+=((uint32_t) pbT[8] << 8);
- // the first byte of c is reserved for the length
- case 8 : b+=((uint32_t) pbT[7] << 24);
- case 7 : b+=((uint32_t) pbT[6] << 16);
- case 6 : b+=((uint32_t) pbT[5] << 8);
- case 5 : b+=pbT[4];
- case 4 : a+=((uint32_t) pbT[3] << 24);
- case 3 : a+=((uint32_t) pbT[2] << 16);
- case 2 : a+=((uint32_t) pbT[1] << 8);
- case 1 : a+=pbT[0];
- }
-
- HASH_MIX(a,b,c);
-
- return c;
-}
-
-static uint32_t ComputeHash(_In_z_ LPCSTR pString)
-{
- return ComputeHash(reinterpret_cast<const uint8_t*>(pString), (uint32_t)strlen(pString));
-}
-
-
-// 1) these numbers are prime
-// 2) each is slightly less than double the last
-// 4) each is roughly in between two powers of 2;
-// (2^n hash table sizes are VERY BAD; they effectively truncate your
-// precision down to the n least significant bits of the hash)
-static const uint32_t c_PrimeSizes[] =
-{
- 11,
- 23,
- 53,
- 97,
- 193,
- 389,
- 769,
- 1543,
- 3079,
- 6151,
- 12289,
- 24593,
- 49157,
- 98317,
- 196613,
- 393241,
- 786433,
- 1572869,
- 3145739,
- 6291469,
- 12582917,
- 25165843,
- 50331653,
- 100663319,
- 201326611,
- 402653189,
- 805306457,
- 1610612741,
-};
-
-template<typename T, bool (*pfnIsEqual)(const T &Data1, const T &Data2)>
-class CEffectHashTable
-{
-protected:
-
- struct SHashEntry
- {
- uint32_t Hash;
- T Data;
- SHashEntry *pNext;
- };
-
- // Array of hash entries
- SHashEntry **m_rgpHashEntries;
- uint32_t m_NumHashSlots;
- uint32_t m_NumEntries;
- bool m_bOwnHashEntryArray;
-
-public:
- class CIterator
- {
- friend class CEffectHashTable;
-
- protected:
- SHashEntry **ppHashSlot;
- SHashEntry *pHashEntry;
-
- public:
- T GetData()
- {
- assert(pHashEntry != 0);
- _Analysis_assume_(pHashEntry != 0);
- return pHashEntry->Data;
- }
-
- uint32_t GetHash()
- {
- assert(pHashEntry != 0);
- _Analysis_assume_(pHashEntry != 0);
- return pHashEntry->Hash;
- }
- };
-
- CEffectHashTable() noexcept :
- m_rgpHashEntries(nullptr),
- m_NumHashSlots(0),
- m_NumEntries(0),
- m_bOwnHashEntryArray(false)
- {
- }
-
- HRESULT Initialize(_In_ const CEffectHashTable *pOther)
- {
- HRESULT hr = S_OK;
- SHashEntry **rgpNewHashEntries = nullptr;
- uint32_t valuesMigrated = 0;
- uint32_t actualSize;
-
- Cleanup();
-
- actualSize = pOther->m_NumHashSlots;
- VN( rgpNewHashEntries = new SHashEntry*[actualSize] );
-
- ZeroMemory(rgpNewHashEntries, sizeof(SHashEntry*) * actualSize);
-
- // Expensive operation: rebuild the hash table
- CIterator iter, nextIter;
- pOther->GetFirstEntry(&iter);
- while (!pOther->PastEnd(&iter))
- {
- uint32_t index = iter.GetHash() % actualSize;
-
- // we need to advance to the next element
- // before we seize control of this element and move
- // it to the new table
- nextIter = iter;
- pOther->GetNextEntry(&nextIter);
-
- // seize this hash entry, migrate it to the new table
- SHashEntry *pNewEntry;
- VN( pNewEntry = new SHashEntry );
-
- pNewEntry->pNext = rgpNewHashEntries[index];
- pNewEntry->Data = iter.pHashEntry->Data;
- pNewEntry->Hash = iter.pHashEntry->Hash;
- rgpNewHashEntries[index] = pNewEntry;
-
- iter = nextIter;
- ++ valuesMigrated;
- }
-
- assert(valuesMigrated == pOther->m_NumEntries);
-
- m_rgpHashEntries = rgpNewHashEntries;
- m_NumHashSlots = actualSize;
- m_NumEntries = pOther->m_NumEntries;
- m_bOwnHashEntryArray = true;
- rgpNewHashEntries = nullptr;
-
-lExit:
- SAFE_DELETE_ARRAY( rgpNewHashEntries );
- return hr;
- }
-
-protected:
- void CleanArray()
- {
- if (m_bOwnHashEntryArray)
- {
- SAFE_DELETE_ARRAY(m_rgpHashEntries);
- m_bOwnHashEntryArray = false;
- }
- }
-
-public:
- void Cleanup()
- {
- for (size_t i = 0; i < m_NumHashSlots; ++ i)
- {
- SHashEntry *pCurrentEntry = m_rgpHashEntries[i];
- SHashEntry *pTempEntry;
- while (nullptr != pCurrentEntry)
- {
- pTempEntry = pCurrentEntry->pNext;
- SAFE_DELETE(pCurrentEntry);
- pCurrentEntry = pTempEntry;
- -- m_NumEntries;
- }
- }
- CleanArray();
- m_NumHashSlots = 0;
- assert(m_NumEntries == 0);
- }
-
- ~CEffectHashTable()
- {
- Cleanup();
- }
-
- static uint32_t GetNextHashTableSize(_In_ uint32_t DesiredSize)
- {
- // figure out the next logical size to use
- for (size_t i = 0; i < _countof(c_PrimeSizes); ++i )
- {
- if (c_PrimeSizes[i] >= DesiredSize)
- {
- return c_PrimeSizes[i];
- }
- }
-
- return DesiredSize;
- }
-
- // O(n) function
- // Grows to the next suitable size (based off of the prime number table)
- // DesiredSize is merely a suggestion
- HRESULT Grow(_In_ uint32_t DesiredSize,
- _In_ uint32_t ProvidedArraySize = 0,
- _In_reads_opt_(ProvidedArraySize) void** ProvidedArray = nullptr,
- _In_ bool OwnProvidedArray = false)
- {
- HRESULT hr = S_OK;
- SHashEntry **rgpNewHashEntries = nullptr;
- uint32_t valuesMigrated = 0;
- uint32_t actualSize;
-
- VB( DesiredSize > m_NumHashSlots );
-
- actualSize = GetNextHashTableSize(DesiredSize);
-
- if (ProvidedArray &&
- ProvidedArraySize >= actualSize)
- {
- rgpNewHashEntries = reinterpret_cast<SHashEntry**>(ProvidedArray);
- }
- else
- {
- OwnProvidedArray = true;
-
- VN( rgpNewHashEntries = new SHashEntry*[actualSize] );
- }
-
- ZeroMemory(rgpNewHashEntries, sizeof(SHashEntry*) * actualSize);
-
- // Expensive operation: rebuild the hash table
- CIterator iter, nextIter;
- GetFirstEntry(&iter);
- while (!PastEnd(&iter))
- {
- uint32_t index = iter.GetHash() % actualSize;
-
- // we need to advance to the next element
- // before we seize control of this element and move
- // it to the new table
- nextIter = iter;
- GetNextEntry(&nextIter);
-
- // seize this hash entry, migrate it to the new table
- iter.pHashEntry->pNext = rgpNewHashEntries[index];
- rgpNewHashEntries[index] = iter.pHashEntry;
-
- iter = nextIter;
- ++ valuesMigrated;
- }
-
- assert(valuesMigrated == m_NumEntries);
-
- CleanArray();
- m_rgpHashEntries = rgpNewHashEntries;
- m_NumHashSlots = actualSize;
- m_bOwnHashEntryArray = OwnProvidedArray;
-
-lExit:
- return hr;
- }
-
- HRESULT AutoGrow()
- {
- // arbitrary heuristic -- grow if 1:1
- if (m_NumEntries >= m_NumHashSlots)
- {
- // grows this hash table so that it is roughly 50% full
- return Grow(m_NumEntries * 2 + 1);
- }
- return S_OK;
- }
-
-#if _DEBUG
- void PrintHashTableStats()
- {
- if (m_NumHashSlots == 0)
- {
- DPF(0, "Uninitialized hash table!");
- return;
- }
-
- float variance = 0.0f;
- float mean = (float)m_NumEntries / (float)m_NumHashSlots;
- uint32_t unusedSlots = 0;
-
- DPF(0, "Hash table slots: %d, Entries in table: %d", m_NumHashSlots, m_NumEntries);
-
- for (size_t i = 0; i < m_NumHashSlots; ++ i)
- {
- uint32_t entries = 0;
- SHashEntry *pCurrentEntry = m_rgpHashEntries[i];
-
- while (nullptr != pCurrentEntry)
- {
- SHashEntry *pCurrentEntry2 = m_rgpHashEntries[i];
-
- // check other hash entries in this slot for hash collisions or duplications
- while (pCurrentEntry2 != pCurrentEntry)
- {
- if (pCurrentEntry->Hash == pCurrentEntry2->Hash)
- {
- if (pfnIsEqual(pCurrentEntry->Data, pCurrentEntry2->Data))
- {
- assert(0);
- DPF(0, "Duplicate entry (identical hash, identical data) found!");
- }
- else
- {
- DPF(0, "Hash collision (hash: %d)", pCurrentEntry->Hash);
- }
- }
- pCurrentEntry2 = pCurrentEntry2->pNext;
- }
-
- pCurrentEntry = pCurrentEntry->pNext;
- ++ entries;
- }
-
- if (0 == entries)
- {
- ++ unusedSlots;
- }
-
- // mean must be greater than 0 at this point
- variance += (float)entries * (float)entries / mean;
- }
-
- variance /= std::max(1.0f, (m_NumHashSlots - 1));
- variance -= (mean * mean);
-
- DPF(0, "Mean number of entries per slot: %f, Standard deviation: %f, Unused slots; %d", mean, variance, unusedSlots);
- }
-#endif // _DEBUG
-
- // S_OK if element is found, E_FAIL otherwise
- HRESULT FindValueWithHash(_In_ T Data, _In_ uint32_t Hash, _Out_ CIterator *pIterator)
- {
- assert(m_NumHashSlots > 0);
-
- uint32_t index = Hash % m_NumHashSlots;
- SHashEntry *pEntry = m_rgpHashEntries[index];
- while (nullptr != pEntry)
- {
- if (Hash == pEntry->Hash && pfnIsEqual(pEntry->Data, Data))
- {
- pIterator->ppHashSlot = m_rgpHashEntries + index;
- pIterator->pHashEntry = pEntry;
- return S_OK;
- }
- pEntry = pEntry->pNext;
- }
- return E_FAIL;
- }
-
- // S_OK if element is found, E_FAIL otherwise
- HRESULT FindFirstMatchingValue(_In_ uint32_t Hash, _Out_ CIterator *pIterator)
- {
- assert(m_NumHashSlots > 0);
-
- uint32_t index = Hash % m_NumHashSlots;
- SHashEntry *pEntry = m_rgpHashEntries[index];
- while (nullptr != pEntry)
- {
- if (Hash == pEntry->Hash)
- {
- pIterator->ppHashSlot = m_rgpHashEntries + index;
- pIterator->pHashEntry = pEntry;
- return S_OK;
- }
- pEntry = pEntry->pNext;
- }
- return E_FAIL;
- }
-
- // Adds data at the specified hash slot without checking for existence
- HRESULT AddValueWithHash(_In_ T Data, _In_ uint32_t Hash)
- {
- HRESULT hr = S_OK;
-
- assert(m_NumHashSlots > 0);
-
- SHashEntry *pHashEntry;
- uint32_t index = Hash % m_NumHashSlots;
-
- VN( pHashEntry = new SHashEntry );
- pHashEntry->pNext = m_rgpHashEntries[index];
- pHashEntry->Data = Data;
- pHashEntry->Hash = Hash;
- m_rgpHashEntries[index] = pHashEntry;
-
- ++ m_NumEntries;
-
-lExit:
- return hr;
- }
-
- // Iterator code:
- //
- // CMyHashTable::CIterator myIt;
- // for (myTable.GetFirstEntry(&myIt); !myTable.PastEnd(&myIt); myTable.GetNextEntry(&myIt)
- // { myTable.GetData(&myIt); }
- void GetFirstEntry(_Out_ CIterator *pIterator)
- {
- SHashEntry **ppEnd = m_rgpHashEntries + m_NumHashSlots;
- pIterator->ppHashSlot = m_rgpHashEntries;
- while (pIterator->ppHashSlot < ppEnd)
- {
- if (nullptr != *(pIterator->ppHashSlot))
- {
- pIterator->pHashEntry = *(pIterator->ppHashSlot);
- return;
- }
- ++ pIterator->ppHashSlot;
- }
- }
-
- bool PastEnd(_Inout_ CIterator *pIterator)
- {
- SHashEntry **ppEnd = m_rgpHashEntries + m_NumHashSlots;
- assert(pIterator->ppHashSlot >= m_rgpHashEntries && pIterator->ppHashSlot <= ppEnd);
- return (pIterator->ppHashSlot == ppEnd);
- }
-
- void GetNextEntry(_Inout_ CIterator *pIterator)
- {
- SHashEntry **ppEnd = m_rgpHashEntries + m_NumHashSlots;
- assert(pIterator->ppHashSlot >= m_rgpHashEntries && pIterator->ppHashSlot <= ppEnd);
- assert(pIterator->pHashEntry != 0);
- _Analysis_assume_(pIterator->pHashEntry != 0);
-
- pIterator->pHashEntry = pIterator->pHashEntry->pNext;
- if (nullptr != pIterator->pHashEntry)
- {
- return;
- }
-
- ++ pIterator->ppHashSlot;
- while (pIterator->ppHashSlot < ppEnd)
- {
- pIterator->pHashEntry = *(pIterator->ppHashSlot);
- if (nullptr != pIterator->pHashEntry)
- {
- return;
- }
- ++ pIterator->ppHashSlot;
- }
- // hit the end of the list, ppHashSlot == ppEnd
- }
-
- void RemoveEntry(_Inout_ CIterator *pIterator)
- {
- SHashEntry *pTemp;
- SHashEntry **ppPrev;
- SHashEntry **ppEnd = m_rgpHashEntries + m_NumHashSlots;
-
- assert(pIterator && !PastEnd(pIterator));
- ppPrev = pIterator->ppHashSlot;
- pTemp = *ppPrev;
- while (pTemp)
- {
- if (pTemp == pIterator->pHashEntry)
- {
- *ppPrev = pTemp->pNext;
- pIterator->ppHashSlot = ppEnd;
- delete pTemp;
- return;
- }
- ppPrev = &pTemp->pNext;
- pTemp = pTemp->pNext;
- }
-
- // Should never get here
- assert(0);
- }
-
-};
-
-// Allocates the hash slots on the regular heap (since the
-// hash table can grow), but all hash entries are allocated on
-// a private heap
-
-template<typename T, bool (*pfnIsEqual)(const T &Data1, const T &Data2)>
-class CEffectHashTableWithPrivateHeap : public CEffectHashTable<T, pfnIsEqual>
-{
-protected:
- CDataBlockStore *m_pPrivateHeap;
-
-public:
- CEffectHashTableWithPrivateHeap() noexcept :
- m_pPrivateHeap(nullptr)
- {
- }
-
- void Cleanup()
- {
- CleanArray();
- m_NumHashSlots = 0;
- m_NumEntries = 0;
- }
-
- ~CEffectHashTableWithPrivateHeap()
- {
- Cleanup();
- }
-
- // Call this only once
- void SetPrivateHeap(_In_ CDataBlockStore *pPrivateHeap)
- {
- assert(nullptr == m_pPrivateHeap);
- m_pPrivateHeap = pPrivateHeap;
- }
-
- // Adds data at the specified hash slot without checking for existence
- HRESULT AddValueWithHash(_In_ T Data, _In_ uint32_t Hash)
- {
- HRESULT hr = S_OK;
-
- assert(m_pPrivateHeap);
- _Analysis_assume_(m_pPrivateHeap);
- assert(m_NumHashSlots > 0);
-
- SHashEntry *pHashEntry;
- uint32_t index = Hash % m_NumHashSlots;
-
- VN( pHashEntry = new(*m_pPrivateHeap) SHashEntry );
- pHashEntry->pNext = m_rgpHashEntries[index];
- pHashEntry->Data = Data;
- pHashEntry->Hash = Hash;
- m_rgpHashEntries[index] = pHashEntry;
-
- ++ m_NumEntries;
-
-lExit:
- return hr;
- }
-};
+++ /dev/null
-//--------------------------------------------------------------------------------------
-// File: pchfx.h
-//
-// Direct3D 11 shader effects precompiled header
-//
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-//
-// http://go.microsoft.com/fwlink/p/?LinkId=271568
-//--------------------------------------------------------------------------------------
-
-#pragma once
-
-#pragma warning(disable : 4102 4127 4201 4505 4616 4706 6326)
-
-#ifndef NOMINMAX
-#define NOMINMAX
-#endif
-
-#include <algorithm>
-
-#if defined(_XBOX_ONE) && defined(_TITLE)
-#include <d3d11_x.h>
-#include <D3DCompiler_x.h>
-#define DCOMMON_H_INCLUDED
-#define NO_D3D11_DEBUG_NAME
-#elif (_WIN32_WINNT >= 0x0602) || defined(_WIN7_PLATFORM_UPDATE)
-#include <d3d11_1.h>
-#include <D3DCompiler.h>
-#else
-#include <d3d11.h>
-#include <D3DCompiler.h>
-#endif
-
-#ifndef _WIN32_WINNT_WIN8
-#define _WIN32_WINNT_WIN8 0x0602
-#endif
-
-#undef DEFINE_GUID
-#include "INITGUID.h"
-
-#include "d3dx11effect.h"
-
-#define UNUSED -1
-
-//////////////////////////////////////////////////////////////////////////
-
-#define offsetof_fx( a, b ) (uint32_t)offsetof( a, b )
-
-#include "d3dxGlobal.h"
-
-#include <stddef.h>
-#include <stdlib.h>
-
-#include "Effect.h"
-#include "EffectStateBase11.h"
-#include "EffectLoad.h"
-
*d = 0;
}
-#ifdef FX11
+#if 1
static bool psEffect_LoadEffect(struct d3d11struct *d3d, const TCHAR *shaderfile, struct shaderdata11 *s, int num)
{
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories);$(SolutionDir)\..\lib\</AdditionalLibraryDirectories>
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories);$(SolutionDir)\..\lib\</AdditionalLibraryDirectories>
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories);$(SolutionDir)\..\lib\</AdditionalLibraryDirectories>
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>NotSet</ShowProgress>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>NotSet</ShowProgress>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>NotSet</ShowProgress>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;prowizard.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories);$(SolutionDir)\..\lib\</AdditionalLibraryDirectories>
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>NotSet</ShowProgress>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<ClCompile Include="..\fpp_native_msvc_80bit.cpp" />
<ClCompile Include="..\fsdb_mywin32.cpp" />
<ClCompile Include="..\fsdb_win32.cpp" />
- <ClCompile Include="..\FX11\d3dxGlobal.cpp" />
- <ClCompile Include="..\FX11\EffectAPI.cpp" />
- <ClCompile Include="..\FX11\EffectLoad.cpp" />
- <ClCompile Include="..\FX11\EffectNonRuntime.cpp" />
- <ClCompile Include="..\FX11\EffectReflection.cpp" />
- <ClCompile Include="..\FX11\EffectRuntime.cpp" />
<ClCompile Include="..\hardfile_win32.cpp" />
<ClCompile Include="..\hq2x_d3d.cpp" />
<ClCompile Include="..\ioport.cpp" />
<Filter Include="win32\Shaders">
<UniqueIdentifier>{34d75786-02bd-43a5-b45d-934eef34e96e}</UniqueIdentifier>
</Filter>
- <Filter Include="win32\FX11">
- <UniqueIdentifier>{aacd260d-3fd9-43a0-9cac-463ddd009704}</UniqueIdentifier>
- </Filter>
<Filter Include="nasm">
<UniqueIdentifier>{9d6d0e7b-76b0-4b28-a9ef-0b69a02528c7}</UniqueIdentifier>
</Filter>
<ClCompile Include="..\..\pcem\vid_cl5429.cpp">
<Filter>pcem</Filter>
</ClCompile>
- <ClCompile Include="..\FX11\d3dxGlobal.cpp">
- <Filter>win32\FX11</Filter>
- </ClCompile>
- <ClCompile Include="..\FX11\EffectAPI.cpp">
- <Filter>win32\FX11</Filter>
- </ClCompile>
- <ClCompile Include="..\FX11\EffectLoad.cpp">
- <Filter>win32\FX11</Filter>
- </ClCompile>
- <ClCompile Include="..\FX11\EffectNonRuntime.cpp">
- <Filter>win32\FX11</Filter>
- </ClCompile>
- <ClCompile Include="..\FX11\EffectReflection.cpp">
- <Filter>win32\FX11</Filter>
- </ClCompile>
- <ClCompile Include="..\FX11\EffectRuntime.cpp">
- <Filter>win32\FX11</Filter>
- </ClCompile>
<ClCompile Include="..\..\pcem\vid_voodoo_banshee.cpp">
<Filter>pcem</Filter>
</ClCompile>