//-------------------------------------------------------------------------------------- // File: EffectVariable.inl // // Direct3D 11 Effects Variable reflection template // These templates define the many Effect variable types. // // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // Copyright (c) Microsoft Corporation. All rights reserved. // // 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 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 { 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 { 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 { 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 { 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 { public: STDMETHOD(GetClassInstance)(_Outptr_ ID3D11ClassInstance **ppClassInstance) override { UNREFERENCED_PARAMETER(ppClassInstance); return E_FAIL; } IUNKNOWN_IMP(SEffectInvalidClassInstanceVariable, ID3DX11EffectClassInstanceVariable, ID3DX11EffectVariable); }; struct SEffectInvalidInterfaceVariable : public TEffectInvalidVariable { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 _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 _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(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 _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 __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 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(pSrcValues[j], &pDestValues[i], "SetScalarArray"); } lExit: return hr; } #pragma warning(pop) #pragma warning( disable : 6103 ) template 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(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 struct TVariable : public IBaseInterface { STDMETHOD_(bool, IsValid)() override { return true; } STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index) { SVariable *pMember; UDataPointer dataPtr; TTopLevelVariable *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(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 *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(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 *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(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 *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 struct TTopLevelVariable : public SVariable, public IBaseInterface { // Required to create member/element variable interfaces CEffect *pEffect; CEffect* GetEffect() { return pEffect; } TTopLevelVariable() : pEffect (nullptr) { } uint32_t GetTotalUnpackedSize() { return ((SType*)pType)->GetTotalUnpackedSize(false); } STDMETHOD_(ID3DX11EffectType*, GetType)() { return (ID3DX11EffectType*)(SType*)pType; } TTopLevelVariable * GetTopLevelEntity() { return (TTopLevelVariable *)this; } bool IsArray() { return (pType->Elements > 0); } }; ////////////////////////////////////////////////////////////////////////// // TMember - functionality for structure/array members of other variables ////////////////////////////////////////////////////////////////////////// template 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 *pTopLevelEntity; TMember() { 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*)pTopLevelEntity)->AnnotationCount; SConstantBuffer *pCB = ((TGlobalVariable*)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 * 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*)pTopLevelEntity)->DirtyVariable(); } }; ////////////////////////////////////////////////////////////////////////// // TAnnotation - functionality for top level annotations ////////////////////////////////////////////////////////////////////////// template struct TAnnotation : public TVariable > { 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 struct TGlobalVariable : public TVariable > { Timer LastModifiedTime; // if numeric, pointer to the constant buffer where this variable lives SConstantBuffer *pCB; uint32_t AnnotationCount; SAnnotation *pAnnotations; TGlobalVariable() : 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 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 struct TFloatScalarVariable : public TNumericVariable { 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 _Use_decl_annotations_ HRESULT TFloatScalarVariable::SetFloat(float Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericFloat, pFuncName); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::GetFloat(float *pValue) { return CopyScalarValue(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetFloat"); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericFloat, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericFloat, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray"); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::SetInt(const int Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericFloat, pFuncName); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::GetInt(int *pValue) { return CopyScalarValue(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetInt"); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericFloat, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::GetIntArray(int *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericFloat, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray"); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::SetBool(const bool Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericFloat, pFuncName); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::GetBool(bool *pValue) { return CopyScalarValue(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetBool"); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericFloat, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TFloatScalarVariable::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericFloat, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray"); } ////////////////////////////////////////////////////////////////////////// // ID3DX11EffectScalarVariable (TIntScalarVariable implementation) ////////////////////////////////////////////////////////////////////////// template struct TIntScalarVariable : public TNumericVariable { 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 _Use_decl_annotations_ HRESULT TIntScalarVariable::SetFloat(float Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericInt, pFuncName); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::GetFloat(float *pValue) { return CopyScalarValue(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetFloat"); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericInt, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericInt, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray"); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::SetInt(const int Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericInt, pFuncName); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::GetInt(int *pValue) { return CopyScalarValue(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetInt"); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericInt, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::GetIntArray(int *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericInt, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray"); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::SetBool(const bool Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericInt, pFuncName); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::GetBool(bool *pValue) { return CopyScalarValue(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetBool"); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericInt, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TIntScalarVariable::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericInt, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray"); } ////////////////////////////////////////////////////////////////////////// // ID3DX11EffectScalarVariable (TBoolScalarVariable implementation) ////////////////////////////////////////////////////////////////////////// template struct TBoolScalarVariable : public TNumericVariable { 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 _Use_decl_annotations_ HRESULT TBoolScalarVariable::SetFloat(float Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericBool, pFuncName); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::GetFloat(float *pValue) { return CopyScalarValue(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetFloat"); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericBool, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericBool, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray"); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::SetInt(const int Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericBool, pFuncName); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::GetInt(int *pValue) { return CopyScalarValue(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetInt"); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericBool, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::GetIntArray(int *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericBool, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray"); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::SetBool(const bool Value) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return CopyScalarValue(Value, Data.pNumericBool, pFuncName); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::GetBool(bool *pValue) { return CopyScalarValue(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetBool"); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return SetScalarArray(pData, Data.pNumericBool, Offset, Count, pType, GetTotalUnpackedSize(), pFuncName); } template _Use_decl_annotations_ HRESULT TBoolScalarVariable::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count) { return GetScalarArray(Data.pNumericBool, pData, Offset, Count, pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray"); } ////////////////////////////////////////////////////////////////////////// // ID3DX11EffectVectorVariable (TVectorVariable implementation) ////////////////////////////////////////////////////////////////////////// template struct TVectorVariable : public TNumericVariable { 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 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(pDest)[i] = reinterpret_cast(pSource)[i] ? -1 : 0; pDest = ((float*) pDest) + dstVecSize; pSource = ((bool*) pSource) + srcVecSize; } break; case ETVT_Int: for (size_t j=0; j(pDest)[i] = reinterpret_cast(pSource)[i] ? -1 : 0; pDest = ((float*) pDest) + dstVecSize; pSource = ((bool*) pSource) + srcVecSize; } break; case ETVT_Float: for (size_t j=0; j(pDest)[i] = reinterpret_cast(pSource)[i] ? -1.0f : 0.0f; pDest = ((float*) pDest) + dstVecSize; pSource = ((bool*) pSource) + srcVecSize; } break; case ETVT_bool: for (size_t j=0; j _Use_decl_annotations_ HRESULT TVectorVariable::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(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1); lExit: return hr; } template _Use_decl_annotations_ HRESULT TVectorVariable::GetFloatVector(float *pData) { HRESULT hr = S_OK; static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVector"; #ifdef _DEBUG VERIFYPARAMETER(pData); #endif CopyDataWithTypeConversion(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1); lExit: return hr; } // Int Vector template _Use_decl_annotations_ HRESULT TVectorVariable::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(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1); lExit: return hr; } template _Use_decl_annotations_ HRESULT TVectorVariable::GetIntVector(int *pData) { HRESULT hr = S_OK; #ifdef _DEBUG static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetIntVector"; VERIFYPARAMETER(pData); #endif CopyDataWithTypeConversion(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1); lExit: return hr; } // Bool Vector template _Use_decl_annotations_ HRESULT TVectorVariable::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(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1); lExit: return hr; } template _Use_decl_annotations_ HRESULT TVectorVariable::GetBoolVector(bool *pData) { HRESULT hr = S_OK; #ifdef _DEBUG static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetBoolVector"; VERIFYPARAMETER(pData); #endif CopyDataWithTypeConversion(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1); lExit: return hr; } // Vector Arrays ///////////////////////////////////////////////////////// template _Use_decl_annotations_ HRESULT TVectorVariable::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(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 _Use_decl_annotations_ HRESULT TVectorVariable::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(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 _Use_decl_annotations_ HRESULT TVectorVariable::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(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 _Use_decl_annotations_ HRESULT TVectorVariable::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(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 _Use_decl_annotations_ HRESULT TVectorVariable::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(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 _Use_decl_annotations_ HRESULT TVectorVariable::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(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 struct TVector4Variable : public TVectorVariable { 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 _Use_decl_annotations_ HRESULT TVector4Variable::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 _Use_decl_annotations_ HRESULT TVector4Variable::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 _Use_decl_annotations_ HRESULT TVector4Variable::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(Count * sizeof(CEffectVector4), pType->TotalSize - (Offset * sizeof(CEffectVector4)))); lExit: return hr; } template _Use_decl_annotations_ HRESULT TVector4Variable::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(Count * sizeof(CEffectVector4), pType->TotalSize - (Offset * sizeof(CEffectVector4)))); lExit: return hr; } ////////////////////////////////////////////////////////////////////////// // ID3DX11EffectMatrixVariable (TMatrixVariable implementation) ////////////////////////////////////////////////////////////////////////// template struct TMatrixVariable : public TNumericVariable { 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 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 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 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(pType, pEffectData + pType->Stride * (i + Offset), (float*) pMatrix); } else { GetMatrixTransposeHelper(pType, pEffectData + pType->Stride * (i + Offset), (float*) pMatrix); } } } lExit: return hr; } #pragma warning (pop) template _Use_decl_annotations_ HRESULT TMatrixVariable::SetMatrix(const float *pData) { static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrix"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, const_cast(pData), 0, 1, pFuncName); } template _Use_decl_annotations_ HRESULT TMatrixVariable::GetMatrix(float *pData) { return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, pData, 0, 1, "ID3DX11EffectMatrixVariable::GetMatrix"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::SetMatrixArray(const float *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, const_cast(pData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixArray"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::GetMatrixArray(float *pData, uint32_t Offset, uint32_t Count) { return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, pData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixArray"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::SetMatrixPointerArray(const float **ppData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixPointerArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, const_cast(ppData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixPointerArray"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::GetMatrixPointerArray(float **ppData, uint32_t Offset, uint32_t Count) { return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, ppData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixPointerArray"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::SetMatrixTranspose(const float *pData) { static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTranspose"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, const_cast(pData), 0, 1, "ID3DX11EffectMatrixVariable::SetMatrixTranspose"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::GetMatrixTranspose(float *pData) { return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, pData, 0, 1, "ID3DX11EffectMatrixVariable::GetMatrixTranspose"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::SetMatrixTransposeArray(const float *pData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, const_cast(pData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::GetMatrixTransposeArray(float *pData, uint32_t Offset, uint32_t Count) { return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, pData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixTransposeArray"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::SetMatrixTransposePointerArray(const float **ppData, uint32_t Offset, uint32_t Count) { static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTransposePointerArray"; if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName); DirtyVariable(); return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, const_cast(ppData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixTransposePointerArray"); } template _Use_decl_annotations_ HRESULT TMatrixVariable::GetMatrixTransposePointerArray(float **ppData, uint32_t Offset, uint32_t Count) { return DoMatrixArrayInternal(pType, GetTotalUnpackedSize(), Data.pNumeric, ppData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixTransposePointerArray"); } // Optimize commonly used fast paths // (non-annotations only!) template struct TMatrix4x4Variable : public TMatrixVariable { 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 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 _Use_decl_annotations_ HRESULT TMatrix4x4Variable::SetMatrix(const float *pData) { DirtyVariable(); return DoMatrix4x4ArrayInternal(Data.pNumeric, const_cast(pData), 0, 1 #ifdef _DEBUG , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrix"); #else ); #endif } template _Use_decl_annotations_ HRESULT TMatrix4x4Variable::GetMatrix(float *pData) { return DoMatrix4x4ArrayInternal(Data.pNumeric, pData, 0, 1 #ifdef _DEBUG , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrix"); #else ); #endif } template _Use_decl_annotations_ HRESULT TMatrix4x4Variable::SetMatrixArray(const float *pData, uint32_t Offset, uint32_t Count) { DirtyVariable(); return DoMatrix4x4ArrayInternal(Data.pNumeric, const_cast(pData), Offset, Count #ifdef _DEBUG , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixArray"); #else ); #endif } template _Use_decl_annotations_ HRESULT TMatrix4x4Variable::GetMatrixArray(float *pData, uint32_t Offset, uint32_t Count) { return DoMatrix4x4ArrayInternal(Data.pNumeric, pData, Offset, Count #ifdef _DEBUG , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrixArray"); #else ); #endif } template _Use_decl_annotations_ HRESULT TMatrix4x4Variable::SetMatrixTranspose(const float *pData) { DirtyVariable(); return DoMatrix4x4ArrayInternal(Data.pNumeric, const_cast(pData), 0, 1 #ifdef _DEBUG , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixTranspose"); #else ); #endif } template _Use_decl_annotations_ HRESULT TMatrix4x4Variable::GetMatrixTranspose(float *pData) { return DoMatrix4x4ArrayInternal(Data.pNumeric, pData, 0, 1 #ifdef _DEBUG , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrixTranspose"); #else ); #endif } template _Use_decl_annotations_ HRESULT TMatrix4x4Variable::SetMatrixTransposeArray(const float *pData, uint32_t Offset, uint32_t Count) { DirtyVariable(); return DoMatrix4x4ArrayInternal(Data.pNumeric, const_cast(pData), Offset, Count #ifdef _DEBUG , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray"); #else ); #endif } template _Use_decl_annotations_ HRESULT TMatrix4x4Variable::GetMatrixTransposeArray(float *pData, uint32_t Offset, uint32_t Count) { return DoMatrix4x4ArrayInternal(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 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 _Use_decl_annotations_ HRESULT TStringVariable::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 _Use_decl_annotations_ #pragma warning(suppress : 6054) HRESULT TStringVariable::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 struct TClassInstanceVariable : public IBaseInterface { STDMETHOD(GetClassInstance)(_Outptr_ ID3D11ClassInstance **ppClassInstance) override; }; template HRESULT TClassInstanceVariable::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 struct TInterfaceVariable : public IBaseInterface { STDMETHOD(SetClassInstance)(_In_ ID3DX11EffectClassInstanceVariable *pEffectClassInstance) override; STDMETHOD(GetClassInstance)(_Outptr_ ID3DX11EffectClassInstanceVariable **ppEffectClassInstance) override; }; template HRESULT TInterfaceVariable::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 HRESULT TInterfaceVariable::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 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 ""; } 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 ""; } 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 ""; } 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 ""; } 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 ""; } 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 ""; } 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 _Use_decl_annotations_ HRESULT TShaderResourceVariable::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 _Use_decl_annotations_ HRESULT TShaderResourceVariable::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 _Use_decl_annotations_ HRESULT TShaderResourceVariable::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 _Use_decl_annotations_ HRESULT TShaderResourceVariable::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 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 _Use_decl_annotations_ HRESULT TUnorderedAccessViewVariable::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 _Use_decl_annotations_ HRESULT TUnorderedAccessViewVariable::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 _Use_decl_annotations_ HRESULT TUnorderedAccessViewVariable::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 _Use_decl_annotations_ HRESULT TUnorderedAccessViewVariable::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 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 _Use_decl_annotations_ HRESULT TRenderTargetViewVariable::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 _Use_decl_annotations_ HRESULT TRenderTargetViewVariable::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 _Use_decl_annotations_ HRESULT TRenderTargetViewVariable::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 _Use_decl_annotations_ HRESULT TRenderTargetViewVariable::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 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 _Use_decl_annotations_ HRESULT TDepthStencilViewVariable::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 _Use_decl_annotations_ HRESULT TDepthStencilViewVariable::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 _Use_decl_annotations_ HRESULT TDepthStencilViewVariable::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 _Use_decl_annotations_ HRESULT TDepthStencilViewVariable::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 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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 _Use_decl_annotations_ HRESULT TShaderVariable::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 bool TShaderVariable::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 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 _Use_decl_annotations_ HRESULT TBlendVariable::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 _Use_decl_annotations_ HRESULT TBlendVariable::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 _Use_decl_annotations_ HRESULT TBlendVariable::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 _Use_decl_annotations_ HRESULT TBlendVariable::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 bool TBlendVariable::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 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 _Use_decl_annotations_ HRESULT TDepthStencilVariable::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 _Use_decl_annotations_ HRESULT TDepthStencilVariable::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 HRESULT TDepthStencilVariable::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 _Use_decl_annotations_ HRESULT TDepthStencilVariable::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 bool TDepthStencilVariable::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 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 _Use_decl_annotations_ HRESULT TRasterizerVariable::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 _Use_decl_annotations_ HRESULT TRasterizerVariable::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 _Use_decl_annotations_ HRESULT TRasterizerVariable::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 _Use_decl_annotations_ HRESULT TRasterizerVariable::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 bool TRasterizerVariable::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 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 _Use_decl_annotations_ HRESULT TSamplerVariable::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 _Use_decl_annotations_ HRESULT TSamplerVariable::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 HRESULT TSamplerVariable::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 _Use_decl_annotations_ HRESULT TSamplerVariable::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 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 ID3DX11EffectScalarVariable * TUncastableVariable::AsScalar() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsScalar"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidScalarVariable; } template ID3DX11EffectVectorVariable * TUncastableVariable::AsVector() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsVector"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidVectorVariable; } template ID3DX11EffectMatrixVariable * TUncastableVariable::AsMatrix() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsMatrix"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidMatrixVariable; } template ID3DX11EffectStringVariable * TUncastableVariable::AsString() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsString"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidStringVariable; } template ID3DX11EffectClassInstanceVariable * TUncastableVariable::AsClassInstance() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsClassInstance"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidClassInstanceVariable; } template ID3DX11EffectInterfaceVariable * TUncastableVariable::AsInterface() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsInterface"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidInterfaceVariable; } template ID3DX11EffectShaderResourceVariable * TUncastableVariable::AsShaderResource() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShaderResource"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidShaderResourceVariable; } template ID3DX11EffectUnorderedAccessViewVariable * TUncastableVariable::AsUnorderedAccessView() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsUnorderedAccessView"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidUnorderedAccessViewVariable; } template ID3DX11EffectRenderTargetViewVariable * TUncastableVariable::AsRenderTargetView() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRenderTargetView"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidRenderTargetViewVariable; } template ID3DX11EffectDepthStencilViewVariable * TUncastableVariable::AsDepthStencilView() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencilView"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidDepthStencilViewVariable; } template ID3DX11EffectConstantBuffer * TUncastableVariable::AsConstantBuffer() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsConstantBuffer"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidConstantBuffer; } template ID3DX11EffectShaderVariable * TUncastableVariable::AsShader() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShader"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidShaderVariable; } template ID3DX11EffectBlendVariable * TUncastableVariable::AsBlend() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsBlend"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidBlendVariable; } template ID3DX11EffectDepthStencilVariable * TUncastableVariable::AsDepthStencil() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencil"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidDepthStencilVariable; } template ID3DX11EffectRasterizerVariable * TUncastableVariable::AsRasterizer() { static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRasterizer"; DPF(0, "%s: Invalid typecast", pFuncName); return &g_InvalidRasterizerVariable; } template ID3DX11EffectSamplerVariable * TUncastableVariable::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, false> { IUNKNOWN_IMP(S##Type##GlobalVariable, BaseInterface, ID3DX11EffectVariable); }; \ struct S##Type##Annotation : public T##Type##Variable, true> { IUNKNOWN_IMP(S##Type##Annotation, BaseInterface, ID3DX11EffectVariable);}; \ struct S##Type##GlobalVariableMember : public T##Type##Variable >, false> { IUNKNOWN_IMP(S##Type##GlobalVariableMember, BaseInterface, ID3DX11EffectVariable); }; \ struct S##Type##AnnotationMember : public T##Type##Variable >, true> { IUNKNOWN_IMP(S##Type##AnnotationMember, BaseInterface, ID3DX11EffectVariable); }; #define GenerateVectorReflectionClasses(Type, BaseType, BaseInterface) \ struct S##Type##GlobalVariable : public TVectorVariable, false, BaseType> { IUNKNOWN_IMP(S##Type##GlobalVariable, BaseInterface, ID3DX11EffectVariable); }; \ struct S##Type##Annotation : public TVectorVariable, true, BaseType> { IUNKNOWN_IMP(S##Type##Annotation, BaseInterface, ID3DX11EffectVariable);}; \ struct S##Type##GlobalVariableMember : public TVectorVariable >, false, BaseType> { IUNKNOWN_IMP(S##Type##GlobalVariableMember, BaseInterface, ID3DX11EffectVariable);}; \ struct S##Type##AnnotationMember : public TVectorVariable >, true, BaseType> { IUNKNOWN_IMP(S##Type##AnnotationMember, BaseInterface, ID3DX11EffectVariable);}; #define GenerateReflectionGlobalOnlyClasses(Type) \ struct S##Type##GlobalVariable : public T##Type##Variable > { IUNKNOWN_IMP(S##Type##GlobalVariable, ID3DX11Effect##Type##Variable, ID3DX11EffectVariable); }; \ struct S##Type##GlobalVariableMember : public T##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, true> { IUNKNOWN_IMP(SMatrix4x4ColumnMajorGlobalVariable, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); }; struct SMatrix4x4RowMajorGlobalVariable : public TMatrix4x4Variable, false> { IUNKNOWN_IMP(SMatrix4x4RowMajorGlobalVariable, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); }; struct SMatrix4x4ColumnMajorGlobalVariableMember : public TMatrix4x4Variable >, true> { IUNKNOWN_IMP(SMatrix4x4ColumnMajorGlobalVariableMember, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); }; struct SMatrix4x4RowMajorGlobalVariableMember : public TMatrix4x4Variable >, false> { IUNKNOWN_IMP(SMatrix4x4RowMajorGlobalVariableMember, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); }; // Optimized vector classes struct SFloatVector4GlobalVariable : public TVector4Variable > { IUNKNOWN_IMP(SFloatVector4GlobalVariable, ID3DX11EffectVectorVariable, ID3DX11EffectVariable); }; struct SFloatVector4GlobalVariableMember : public TVector4Variable > > { 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 { }; // The "base" annotation struct (all annotations should be the same size in bytes, // but we pick this as the default). struct SAnnotation : public TAnnotation { }; // 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 > { }; // 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)