OgreShaderProgramProcessor.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef _ShaderProgramProcessor_
#define _ShaderProgramProcessor_
#include "OgreShaderPrerequisites.h"
#include "OgreShaderParameter.h"
#include "OgreShaderFunctionAtom.h"
namespace Ogre {
namespace RTShader {
class _OgreRTSSExport ProgramProcessor : public RTShaderSystemAlloc
{
// Interface.
public:
ProgramProcessor();
virtual ~ProgramProcessor();
virtual const String& getTargetLanguage() const = 0;
virtual bool preCreateGpuPrograms(ProgramSet* programSet) = 0;
virtual bool postCreateGpuPrograms(ProgramSet* programSet) = 0;
// Protected types.
protected:
//-----------------------------------------------------------------------------
// Class that holds merge parameter information.
class _OgreRTSSExport MergeParameter
{
// Interface.
public:
MergeParameter();
void clear();
void addSourceParameter(ParameterPtr srcParam, int mask);
size_t getSourceParameterCount() const { return mSrcParameterCount; }
ParameterPtr getSourceParameter(unsigned int index) { return mSrcParameter[index]; }
int getSourceParameterMask(unsigned int index) const { return mSrcParameterMask[index]; }
int getDestinationParameterMask(unsigned int index) const { return mDstParameterMask[index]; }
int getUsedFloatCount();
ParameterPtr getDestinationParameter(int usage, int index);
protected:
void createDestinationParameter(int usage, int index);
protected:
// Destination merged parameter.
ParameterPtr mDstParameter;
// Source parameters - 4 source at max 1,1,1,1 -> 4.
ParameterPtr mSrcParameter[4];
// Source parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
int mSrcParameterMask[4];
// Destination parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
int mDstParameterMask[4];
// The actual source parameters count.
size_t mSrcParameterCount;
// The number of used floats.
int mUsedFloatCount;
};
typedef vector<MergeParameter>::type MergeParameterList;
//-----------------------------------------------------------------------------
// A struct that defines merge parameters combination.
struct _OgreRTSSExport MergeCombination
{
// The count of each source type. I.E (1 FLOAT1, 0 FLOAT2, 1 FLOAT3, 0 FLOAT4).
size_t srcParameterTypeCount[4];
// Source parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
int srcParameterMask[4];
MergeCombination(
int float1Count, int float1Mask,
int float2Count, int float2Mask,
int float3Count, int float3Mask,
int float4Count, int float4Mask)
{
srcParameterTypeCount[0] = float1Count;
srcParameterTypeCount[1] = float2Count;
srcParameterTypeCount[2] = float3Count;
srcParameterTypeCount[3] = float4Count;
srcParameterMask[0] = float1Mask;
srcParameterMask[1] = float2Mask;
srcParameterMask[2] = float3Mask;
srcParameterMask[3] = float4Mask;
}
};
typedef vector<MergeCombination>::type MergeCombinationList;
//-----------------------------------------------------------------------------
typedef vector<Operand*>::type OperandPtrVector;
typedef map<Parameter*, OperandPtrVector>::type ParameterOperandMap;
typedef map<Parameter*, ParameterPtr>::type LocalParameterMap;
protected:
void buildMergeCombinations();
virtual bool compactVsOutputs(Function* vsMain, Function* fsMain);
void countVsTexcoordOutputs(Function* vsMain, int& outTexCoordSlots, int& outTexCoordFloats);
void buildTexcoordTable(const ShaderParameterList& paramList, ShaderParameterList outParamsTable[4]);
void mergeParameters(ShaderParameterList paramsTable[4], MergeParameterList& mergedParams, ShaderParameterList& splitParams);
void mergeParametersByPredefinedCombinations(ShaderParameterList paramsTable[4], MergeParameterList& mergedParams);
bool mergeParametersByCombination(const MergeCombination& combination, ShaderParameterList paramsTable[4],
MergeParameter* mergedParameter);
void mergeParametersReminders(ShaderParameterList paramsTable[4], MergeParameterList& mergedParams, ShaderParameterList& splitParams);
void generateLocalSplitParameters(Function* func, GpuProgramType progType, MergeParameterList& mergedParams, ShaderParameterList& splitParams, LocalParameterMap& localParamsMap);
void rebuildParameterList(Function* func, int paramsUsage, MergeParameterList& mergedParams);
void rebuildFunctionInvocations(FunctionAtomInstanceList& funcAtomList, MergeParameterList& mergedParams, LocalParameterMap& localParamsMap);
void buildParameterReferenceMap(FunctionAtomInstanceList& funcAtomList, ParameterOperandMap& paramsRefMap);
void replaceParametersReferences(MergeParameterList& mergedParams, ParameterOperandMap& paramsRefMap);
void replaceSplitParametersReferences(LocalParameterMap& localParamsMap, ParameterOperandMap& paramsRefMap);
static int getParameterFloatCount(GpuConstantType type);
static int getParameterMaskByType(GpuConstantType type);
static int getParameterMaskByFloatCount(int floatCount);
void bindAutoParameters(Program* pCpuProgram, GpuProgramPtr pGpuProgram);
protected:
// Merging combinations defs.
MergeCombinationList mParamMergeCombinations;
// Maximum texcoord slots.
int mMaxTexCoordSlots;
// Maximum texcoord floats count.
int mMaxTexCoordFloats;
map<Function *, String *>::type mFunctionMap; // Map between function signatures and source code
};
}
}
#endif
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
Ogre::RTShader::ProgramProcessor::mParamMergeCombinations
MergeCombinationList mParamMergeCombinations
Definition: OgreShaderProgramProcessor.h:259
Ogre::RTShader::ProgramProcessor::MergeCombinationList
vector< MergeCombination >::type MergeCombinationList
Definition: OgreShaderProgramProcessor.h:164
Ogre::RTShader::ProgramProcessor::MergeParameter::mUsedFloatCount
int mUsedFloatCount
Definition: OgreShaderProgramProcessor.h:133
Ogre::RTShader::ProgramProcessor::MergeParameterList
vector< MergeParameter >::type MergeParameterList
Definition: OgreShaderProgramProcessor.h:135
Ogre::RTShader::ProgramProcessor::mMaxTexCoordSlots
int mMaxTexCoordSlots
Definition: OgreShaderProgramProcessor.h:261
Ogre::RTShader::ProgramProcessor::MergeParameter::getSourceParameterCount
size_t getSourceParameterCount() const
Return the source parameter count.
Definition: OgreShaderProgramProcessor.h:98
OgreShaderParameter.h
Ogre::RTShader::ProgramProcessor::MergeParameter::mDstParameter
ParameterPtr mDstParameter
Definition: OgreShaderProgramProcessor.h:123
OgreShaderPrerequisites.h
Ogre::RTShader::ProgramProcessor::mMaxTexCoordFloats
int mMaxTexCoordFloats
Definition: OgreShaderProgramProcessor.h:263
Ogre::RTShader::ShaderParameterList
vector< ParameterPtr >::type ShaderParameterList
Definition: OgreShaderParameter.h:370
Ogre::RTShader::ProgramSet
Container class for shader based programs.
Definition: OgreShaderProgramSet.h:46
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
Ogre::RTShader::ProgramProcessor::ParameterOperandMap
map< Parameter *, OperandPtrVector >::type ParameterOperandMap
Definition: OgreShaderProgramProcessor.h:168
Ogre::RTShader::ProgramProcessor::MergeParameter::getSourceParameterMask
int getSourceParameterMask(unsigned int index) const
Return source parameter mask by index.
Definition: OgreShaderProgramProcessor.h:104
Ogre::RTShader::ProgramProcessor::MergeParameter::mSrcParameterCount
size_t mSrcParameterCount
Definition: OgreShaderProgramProcessor.h:131
Ogre::RTShader::Program
A class that represents a shader based program.
Definition: OgreShaderProgram.h:50
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::GpuProgramType
GpuProgramType
Enumerates the types of programs which can run on the GPU.
Definition: OgreGpuProgram.h:50
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
_OgreRTSSExport
#define _OgreRTSSExport
Definition: OgreShaderPrerequisites.h:108
Ogre::RTShader::ProgramProcessor
A class that provides extra processing services on CPU based programs.
Definition: OgreShaderProgramProcessor.h:49
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::RTShader::Function
A class that represents a shader based program function.
Definition: OgreShaderFunction.h:46
Ogre::RTShader::ProgramProcessor::OperandPtrVector
vector< Operand * >::type OperandPtrVector
Definition: OgreShaderProgramProcessor.h:167
Ogre::SharedPtr< Parameter >
Ogre::GpuConstantType
GpuConstantType
Enumeration of the types of constant we may encounter in programs.
Definition: OgreGpuProgramParams.h:54
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::RTShader::ProgramProcessor::LocalParameterMap
map< Parameter *, ParameterPtr >::type LocalParameterMap
Definition: OgreShaderProgramProcessor.h:169
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::MergeParameter
Definition: OgreShaderProgramProcessor.h:83
Ogre::RTShader::ProgramProcessor::MergeCombination
Definition: OgreShaderProgramProcessor.h:140
Ogre::RTShader::FunctionAtomInstanceList
vector< FunctionAtom * >::type FunctionAtomInstanceList
Definition: OgreShaderFunctionAtom.h:257
OgreShaderFunctionAtom.h
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::RTShader::ProgramProcessor::MergeParameter::getDestinationParameterMask
int getDestinationParameterMask(unsigned int index) const
Return destination parameter mask by index.
Definition: OgreShaderProgramProcessor.h:107

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