OgreShaderProgramProcessor.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 -----------------------------------------------------------------------------
26 */
27 #ifndef _ShaderProgramProcessor_
28 #define _ShaderProgramProcessor_
29 
31 #include "OgreShaderParameter.h"
32 #include "OgreShaderFunctionAtom.h"
33 
34 
35 namespace Ogre {
36 namespace RTShader {
37 
50 {
51 
52 // Interface.
53 public:
54 
58 
60  virtual ~ProgramProcessor();
61 
63  virtual const String& getTargetLanguage() const = 0;
64 
70  virtual bool preCreateGpuPrograms(ProgramSet* programSet) = 0;
71 
76  virtual bool postCreateGpuPrograms(ProgramSet* programSet) = 0;
77 
78 // Protected types.
79 protected:
80 
81  //-----------------------------------------------------------------------------
82  // Class that holds merge parameter information.
84  {
85  // Interface.
86  public:
89 
90 
92  void clear();
93 
95  void addSourceParameter(ParameterPtr srcParam, int mask);
96 
98  size_t getSourceParameterCount() const { return mSrcParameterCount; }
99 
101  ParameterPtr getSourceParameter(unsigned int index) { return mSrcParameter[index]; }
102 
104  int getSourceParameterMask(unsigned int index) const { return mSrcParameterMask[index]; }
105 
107  int getDestinationParameterMask(unsigned int index) const { return mDstParameterMask[index]; }
108 
111 
113  ParameterPtr getDestinationParameter(int usage, int index);
114 
115  protected:
116 
118  void createDestinationParameter(int usage, int index);
119 
120 
121  protected:
122  // Destination merged parameter.
124  // Source parameters - 4 source at max 1,1,1,1 -> 4.
125  ParameterPtr mSrcParameter[4];
126  // Source parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
127  int mSrcParameterMask[4];
128  // Destination parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
129  int mDstParameterMask[4];
130  // The actual source parameters count.
132  // The number of used floats.
134  };
136 
137 
138  //-----------------------------------------------------------------------------
139  // A struct that defines merge parameters combination.
141  {
142  // The count of each source type. I.E (1 FLOAT1, 0 FLOAT2, 1 FLOAT3, 0 FLOAT4).
143  size_t srcParameterTypeCount[4];
144  // Source parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
145  int srcParameterMask[4];
146 
148  int float1Count, int float1Mask,
149  int float2Count, int float2Mask,
150  int float3Count, int float3Mask,
151  int float4Count, int float4Mask)
152  {
153  srcParameterTypeCount[0] = float1Count;
154  srcParameterTypeCount[1] = float2Count;
155  srcParameterTypeCount[2] = float3Count;
156  srcParameterTypeCount[3] = float4Count;
157  srcParameterMask[0] = float1Mask;
158  srcParameterMask[1] = float2Mask;
159  srcParameterMask[2] = float3Mask;
160  srcParameterMask[3] = float4Mask;
161 
162  }
163  };
165 
166  //-----------------------------------------------------------------------------
170 
171 protected:
172 
175 
181  virtual bool compactVsOutputs(Function* vsMain, Function* fsMain);
182 
188  void countVsTexcoordOutputs(Function* vsMain, int& outTexCoordSlots, int& outTexCoordFloats);
189 
194  void buildTexcoordTable(const ShaderParameterList& paramList, ShaderParameterList outParamsTable[4]);
195 
196 
201  void mergeParameters(ShaderParameterList paramsTable[4], MergeParameterList& mergedParams, ShaderParameterList& splitParams);
202 
203 
209 
215  bool mergeParametersByCombination(const MergeCombination& combination, ShaderParameterList paramsTable[4],
216  MergeParameter* mergedParameter);
217 
223  void mergeParametersReminders(ShaderParameterList paramsTable[4], MergeParameterList& mergedParams, ShaderParameterList& splitParams);
224 
225 
227  void generateLocalSplitParameters(Function* func, GpuProgramType progType, MergeParameterList& mergedParams, ShaderParameterList& splitParams, LocalParameterMap& localParamsMap);
228 
231  void rebuildParameterList(Function* func, int paramsUsage, MergeParameterList& mergedParams);
232 
235 
238 
241 
244 
247 
250 
252  static int getParameterMaskByFloatCount(int floatCount);
253 
255  void bindAutoParameters(Program* pCpuProgram, GpuProgramPtr pGpuProgram);
256 
257 protected:
258  // Merging combinations defs.
260  // Maximum texcoord slots.
262  // Maximum texcoord floats count.
264  map<Function *, String *>::type mFunctionMap; // Map between function signatures and source code
265 
266 };
267 
268 
272 }
273 }
274 
275 #endif
276 
Ogre::RTShader::ProgramProcessor::generateLocalSplitParameters
void generateLocalSplitParameters(Function *func, GpuProgramType progType, MergeParameterList &mergedParams, ShaderParameterList &splitParams, LocalParameterMap &localParamsMap)
Generates local parameters for the split parameters and perform packing/unpacking operation using the...
Ogre::RTShader::ProgramProcessor::MergeParameter::mSrcParameterCount
size_t mSrcParameterCount
Definition: OgreShaderProgramProcessor.h:131
Ogre::RTShader::ProgramProcessor::mergeParametersByPredefinedCombinations
void mergeParametersByPredefinedCombinations(ShaderParameterList paramsTable[4], MergeParameterList &mergedParams)
Internal function that creates merged parameter using pre defined combinations.
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:59
Ogre
Definition: OgreAndroidLogListener.h:35
OgreShaderFunctionAtom.h
Ogre::RTShader::ProgramSet
Container class for shader based programs.
Definition: OgreShaderProgramSet.h:47
Ogre::RTShader::ProgramProcessor::LocalParameterMap
map< Parameter *, ParameterPtr >::type LocalParameterMap
Definition: OgreShaderProgramProcessor.h:169
Ogre::RTShader::ProgramProcessor::MergeParameter::getDestinationParameterMask
int getDestinationParameterMask(unsigned int index) const
Return destination parameter mask by index.
Definition: OgreShaderProgramProcessor.h:107
Ogre::RTShader::ProgramProcessor::buildTexcoordTable
void buildTexcoordTable(const ShaderParameterList &paramList, ShaderParameterList outParamsTable[4])
Internal function that builds parameters table.
Ogre::RTShader::ProgramProcessor::getParameterMaskByFloatCount
static int getParameterMaskByFloatCount(int floatCount)
Return the parameter mask of by the float count type (I.E: X|Y for 2 etc..)
Ogre::RTShader::ProgramProcessor::countVsTexcoordOutputs
void countVsTexcoordOutputs(Function *vsMain, int &outTexCoordSlots, int &outTexCoordFloats)
Internal method that counts vertex shader texcoord output slots and output floats.
Ogre::RTShader::ProgramProcessor::OperandPtrVector
vector< Operand * >::type OperandPtrVector
Definition: OgreShaderProgramProcessor.h:167
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::RTShader::ProgramProcessor::mergeParametersReminders
void mergeParametersReminders(ShaderParameterList paramsTable[4], MergeParameterList &mergedParams, ShaderParameterList &splitParams)
Merge reminders parameters that could not be merged into one slot using the predefined combinations.
Ogre::RTShader::ProgramProcessor::ProgramProcessor
ProgramProcessor()
Class constructor.
Ogre::RTShader::ProgramProcessor::ParameterOperandMap
map< Parameter *, OperandPtrVector >::type ParameterOperandMap
Definition: OgreShaderProgramProcessor.h:168
OgreShaderPrerequisites.h
Ogre::RTShader::ProgramProcessor::mMaxTexCoordSlots
int mMaxTexCoordSlots
Definition: OgreShaderProgramProcessor.h:261
Ogre::GpuProgramType
GpuProgramType
Enumerates the types of programs which can run on the GPU.
Definition: OgreGpuProgram.h:51
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
Ogre::RTShader::ShaderParameterList
vector< ParameterPtr >::type ShaderParameterList
Definition: OgreShaderParameter.h:370
Ogre::RTShader::ProgramProcessor::replaceSplitParametersReferences
void replaceSplitParametersReferences(LocalParameterMap &localParamsMap, ParameterOperandMap &paramsRefMap)
Replace references to old parameters that have been split with the new local parameters that represen...
Ogre::RTShader::ProgramProcessor::MergeCombination::MergeCombination
MergeCombination(int float1Count, int float1Mask, int float2Count, int float2Mask, int float3Count, int float3Mask, int float4Count, int float4Mask)
Definition: OgreShaderProgramProcessor.h:147
Ogre::RTShader::Program
A class that represents a shader based program.
Definition: OgreShaderProgram.h:51
Ogre::RTShader::ProgramProcessor::MergeCombination
Definition: OgreShaderProgramProcessor.h:141
Ogre::RTShader::ProgramProcessor::MergeParameter::MergeParameter
MergeParameter()
Class constructor.
Ogre::RTShader::ProgramProcessor::compactVsOutputs
virtual bool compactVsOutputs(Function *vsMain, Function *fsMain)
Compact the vertex shader output registers.
Ogre::RTShader::ProgramProcessor::MergeCombinationList
vector< MergeCombination >::type MergeCombinationList
Definition: OgreShaderProgramProcessor.h:164
Ogre::RTShader::ProgramProcessor::buildMergeCombinations
void buildMergeCombinations()
Build parameter merging combinations.
Ogre::RTShader::ProgramProcessor::MergeParameter::getUsedFloatCount
int getUsedFloatCount()
Return the number of used floats.
Ogre::RTShader::ProgramProcessor::MergeParameter::mUsedFloatCount
int mUsedFloatCount
Definition: OgreShaderProgramProcessor.h:133
Ogre::RTShader::ProgramProcessor::rebuildFunctionInvocations
void rebuildFunctionInvocations(FunctionAtomInstanceList &funcAtomList, MergeParameterList &mergedParams, LocalParameterMap &localParamsMap)
Rebuild function invocations by replacing references to old source parameters with the matching merge...
Ogre::RTShader::ProgramProcessor::MergeParameterList
vector< MergeParameter >::type MergeParameterList
Definition: OgreShaderProgramProcessor.h:135
Ogre::SharedPtr< Parameter >
Ogre::RTShader::ProgramProcessor::MergeParameter::getSourceParameterMask
int getSourceParameterMask(unsigned int index) const
Return source parameter mask by index.
Definition: OgreShaderProgramProcessor.h:104
Ogre::RTShader::ProgramProcessor
A class that provides extra processing services on CPU based programs.
Definition: OgreShaderProgramProcessor.h:50
Ogre::GpuConstantType
GpuConstantType
Enumeration of the types of constant we may encounter in programs.
Definition: OgreGpuProgramParams.h:55
Ogre::RTShader::ProgramProcessor::bindAutoParameters
void bindAutoParameters(Program *pCpuProgram, GpuProgramPtr pGpuProgram)
Bind the auto parameters for a given CPU and GPU program set.
Ogre::RTShader::ProgramProcessor::rebuildParameterList
void rebuildParameterList(Function *func, int paramsUsage, MergeParameterList &mergedParams)
Rebuild the given parameters list using the merged parameters.
Ogre::RTShader::ProgramProcessor::MergeParameter::getDestinationParameter
ParameterPtr getDestinationParameter(int usage, int index)
Return the destination parameter.
Ogre::RTShader::ProgramProcessor::MergeParameter::mDstParameter
ParameterPtr mDstParameter
Definition: OgreShaderProgramProcessor.h:123
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
Ogre::RTShader::ProgramProcessor::preCreateGpuPrograms
virtual bool preCreateGpuPrograms(ProgramSet *programSet)=0
Called before creation of the GPU programs.
Ogre::RTShader::ProgramProcessor::MergeParameter::getSourceParameterCount
size_t getSourceParameterCount() const
Return the source parameter count.
Definition: OgreShaderProgramProcessor.h:98
Ogre::RTShader::ProgramProcessor::MergeParameter
Definition: OgreShaderProgramProcessor.h:84
Ogre::RTShader::ProgramProcessor::postCreateGpuPrograms
virtual bool postCreateGpuPrograms(ProgramSet *programSet)=0
Called after creation of the GPU programs.
OgreShaderParameter.h
Ogre::RTShader::ProgramProcessor::getTargetLanguage
virtual const String & getTargetLanguage() const =0
Return the target language of this processor.
Ogre::RTShader::ProgramProcessor::buildParameterReferenceMap
void buildParameterReferenceMap(FunctionAtomInstanceList &funcAtomList, ParameterOperandMap &paramsRefMap)
Builds a map between parameter and all the references to it.
Ogre::RTShader::ProgramProcessor::mergeParametersByCombination
bool mergeParametersByCombination(const MergeCombination &combination, ShaderParameterList paramsTable[4], MergeParameter *mergedParameter)
Internal function that creates merged parameter from given combination.
Ogre::RTShader::ProgramProcessor::MergeParameter::addSourceParameter
void addSourceParameter(ParameterPtr srcParam, int mask)
Add source parameter to this merged.
Ogre::RTShader::ProgramProcessor::mMaxTexCoordFloats
int mMaxTexCoordFloats
Definition: OgreShaderProgramProcessor.h:263
Ogre::vector
Definition: OgrePrerequisites.h:492
Ogre::RTShader::FunctionAtomInstanceList
vector< FunctionAtom * >::type FunctionAtomInstanceList
Definition: OgreShaderFunctionAtom.h:257
Ogre::RTShader::ProgramProcessor::~ProgramProcessor
virtual ~ProgramProcessor()
Class destructor.
Ogre::RTShader::ProgramProcessor::MergeParameter::createDestinationParameter
void createDestinationParameter(int usage, int index)
Creates the destination parameter by a given class and index.
Ogre::RTShader::Function
A class that represents a shader based program function.
Definition: OgreShaderFunction.h:47
Ogre::RTShader::ProgramProcessor::replaceParametersReferences
void replaceParametersReferences(MergeParameterList &mergedParams, ParameterOperandMap &paramsRefMap)
Replace references to old parameters with the new merged parameters.
Ogre::RTShader::ProgramProcessor::MergeParameter::clear
void clear()
Clear the state of this merge parameter.
Ogre::RTShader::ProgramProcessor::mFunctionMap
map< Function *, String * >::type mFunctionMap
Definition: OgreShaderProgramProcessor.h:264
Ogre::RTShader::ProgramProcessor::MergeParameter::getSourceParameter
ParameterPtr getSourceParameter(unsigned int index)
Return source parameter by index.
Definition: OgreShaderProgramProcessor.h:101
Ogre::RTShader::ProgramProcessor::getParameterMaskByType
static int getParameterMaskByType(GpuConstantType type)
Return the parameter mask of by the given parameter type (I.E: X|Y for FLOAT2 etc....
Ogre::RTShader::ProgramProcessor::mergeParameters
void mergeParameters(ShaderParameterList paramsTable[4], MergeParameterList &mergedParams, ShaderParameterList &splitParams)
Merge the parameters from the given table.
Ogre::RTShader::ProgramProcessor::getParameterFloatCount
static int getParameterFloatCount(GpuConstantType type)
Return number of floats needed by the given type.
_OgreRTSSExport
#define _OgreRTSSExport
Definition: OgreShaderPrerequisites.h:108
Ogre::RTShader::ProgramProcessor::mParamMergeCombinations
MergeCombinationList mParamMergeCombinations
Definition: OgreShaderProgramProcessor.h:259

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.