OgreD3D11HLSLProgram.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __D3D11HLSLProgram_H__
    00029 #define __D3D11HLSLProgram_H__
    00030
    00031 #include "OgreD3D11Prerequisites.h"
    00032 #include "OgreHighLevelGpuProgram.h"
    00033 #include "OgreD3D11VertexDeclaration.h"
    00034
    00035
    00036 namespace Ogre {
    00037     typedef vector<byte>::type MicroCode;
    00038
    00047     class D3D11HLSLProgram : public HighLevelGpuProgram
    00048     {
    00049     public:
    00051         class CmdEntryPoint : public ParamCommand
    00052         {
    00053         public:
    00054             String doGet(const void* target) const;
    00055             void doSet(void* target, const String& val);
    00056         };
    00058         class CmdTarget : public ParamCommand
    00059         {
    00060         public:
    00061             String doGet(const void* target) const;
    00062             void doSet(void* target, const String& val);
    00063         };
    00065         class CmdPreprocessorDefines : public ParamCommand
    00066         {
    00067         public:
    00068             String doGet(const void* target) const;
    00069             void doSet(void* target, const String& val);
    00070         };
    00072         class CmdColumnMajorMatrices : public ParamCommand
    00073         {
    00074         public:
    00075             String doGet(const void* target) const;
    00076             void doSet(void* target, const String& val);
    00077         };
    00079         class CmdEnableBackwardsCompatibility : public ParamCommand
    00080         {
    00081         public:
    00082             String doGet(const void* target) const;
    00083             void doSet(void* target, const String& val);
    00084         };
    00085
    00086     protected:
    00087
    00088         static CmdEntryPoint msCmdEntryPoint;
    00089         static CmdTarget msCmdTarget;
    00090         static CmdPreprocessorDefines msCmdPreprocessorDefines;
    00091         static CmdColumnMajorMatrices msCmdColumnMajorMatrices;
    00092         static CmdEnableBackwardsCompatibility msCmdEnableBackwardsCompatibility;
    00093
    00094
    00097         void createLowLevelImpl(void);
    00099         void unloadHighLevelImpl(void);
    00101         //void populateParameterNames(GpuProgramParametersSharedPtr params);
    00102
    00103         // Recursive utility method for populateParameterNames
    00104         void processParamElement(String prefix, LPCSTR pName, size_t paramIndex, ID3D11ShaderReflectionType* varRefType) const;
    00105
    00106         void populateDef(D3D11_SHADER_TYPE_DESC& d3dDesc, GpuConstantDefinition& def) const;
    00107
    00108         String mTarget;
    00109         String mEntryPoint;
    00110         String mPreprocessorDefines;
    00111         bool mColumnMajorMatrices;
    00112         bool mEnableBackwardsCompatibility;
    00113
    00114         bool mErrorsInCompile;
    00115         MicroCode mMicroCode;
    00116         ID3D11Buffer* mConstantBuffer;
    00117
    00118         D3D11Device & mDevice;
    00119
    00120         ID3D11ShaderReflectionConstantBuffer* mShaderReflectionConstantBuffer;
    00121         D3D11_SHADER_BUFFER_DESC mConstantBufferDesc ;
    00122         D3D11_SHADER_DESC mShaderDesc;
    00123
    00124         D3D11VertexDeclaration mInputVertexDeclaration;
    00125
    00126         ID3D11ShaderReflection* mIShaderReflection;
    00127
    00128         ID3D11VertexShader* mVertexShader;
    00129         ID3D11PixelShader* mPixelShader;
    00130         ID3D11GeometryShader* mGeometryShader;
    00131
    00132         struct ShaderVarWithPosInBuf
    00133         {
    00134             bool wasInit;
    00135             bool isFloat;
    00136             size_t physicalIndex;
    00137             void * src;
    00138             String name;
    00139
    00140             D3D11_SHADER_VARIABLE_DESC var;
    00141         };
    00142         typedef vector<ShaderVarWithPosInBuf>::type ShaderVars;
    00143         typedef ShaderVars::iterator ShaderVarsIter;
    00144
    00145         ShaderVars mShaderVars;
    00146
    00147         void createConstantBuffer(const UINT ByteWidth);
    00148         void analizeMicrocode();
    00149         void getMicrocodeFromCache(void);
    00150         void compileMicrocode(void);
    00151     public:
    00152         D3D11HLSLProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
    00153             const String& group, bool isManual, ManualResourceLoader* loader, D3D11Device & device);
    00154         ~D3D11HLSLProgram();
    00155
    00157         void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
    00159         const String& getEntryPoint(void) const { return mEntryPoint; }
    00161         void setTarget(const String& target);
    00163         const String& getTarget(void) const { return mTarget; }
    00164
    00166         void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
    00168         const String& getPreprocessorDefines(void) const { return mPreprocessorDefines; }
    00170         void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
    00172         bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; }
    00174         void setEnableBackwardsCompatibility(bool enableBackwardsCompatibility) { mEnableBackwardsCompatibility = enableBackwardsCompatibility; }
    00176         bool getEnableBackwardsCompatibility(void) const { return mEnableBackwardsCompatibility; }
    00178         bool isSupported(void) const;
    00180         GpuProgramParametersSharedPtr createParameters(void);
    00182         const String& getLanguage(void) const;
    00183
    00184         virtual void buildConstantDefinitions() const;
    00185         ID3D11VertexShader* getVertexShader(void) const;
    00186         ID3D11PixelShader* getPixelShader(void) const;
    00187         ID3D11GeometryShader* getGeometryShader(void) const;
    00188         const MicroCode &  getMicroCode(void) const;
    00189
    00190         ID3D11Buffer* getConstantBuffer(GpuProgramParametersSharedPtr params, uint16 variabilityMask);
    00191
    00192         void CreateVertexShader();
    00193         void CreatePixelShader();
    00194         void CreateGeometryShader();
    00195
    00198         void loadFromSource(void);
    00199
    00200         D3D11VertexDeclaration & getInputVertexDeclaration() { return mInputVertexDeclaration; }
    00201
    00202         void reinterpretGSForStreamOut(void);
    00203         bool mReinterpretingGS;
    00204
    00205         unsigned int getNumInputs(void)const {return mShaderDesc.InputParameters;}
    00206         unsigned int getNumOutputs(void)const {return mShaderDesc.OutputParameters;}
    00207
    00208         D3D11_SIGNATURE_PARAMETER_DESC getInputParamDesc(unsigned int index) const;
    00209         D3D11_SIGNATURE_PARAMETER_DESC getOutputParamDesc(unsigned int index) const;
    00210     };
    00211 }
    00212
    00213 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21