From 8b9a63a88b3edec0e00ea1846457bbf92beb6c15 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Fri, 20 Oct 2023 14:33:20 +0200 Subject: [PATCH] RTSS: switch to a unified program processor --- .../src/OgreShaderGLSLProgramProcessor.cpp | 95 ------------------- .../src/OgreShaderGLSLProgramProcessor.h | 83 ---------------- .../src/OgreShaderHLSLProgramProcessor.cpp | 75 --------------- .../src/OgreShaderHLSLProgramProcessor.h | 83 ---------------- .../src/OgreShaderPrecompiledHeaders.h | 3 - .../src/OgreShaderProgramManager.cpp | 48 +--------- .../src/OgreShaderProgramProcessor.cpp | 47 +++++++++ .../src/OgreShaderProgramProcessor.h | 5 +- 8 files changed, 54 insertions(+), 385 deletions(-) delete mode 100644 Components/RTShaderSystem/src/OgreShaderGLSLProgramProcessor.cpp delete mode 100644 Components/RTShaderSystem/src/OgreShaderGLSLProgramProcessor.h delete mode 100644 Components/RTShaderSystem/src/OgreShaderHLSLProgramProcessor.cpp delete mode 100644 Components/RTShaderSystem/src/OgreShaderHLSLProgramProcessor.h diff --git a/Components/RTShaderSystem/src/OgreShaderGLSLProgramProcessor.cpp b/Components/RTShaderSystem/src/OgreShaderGLSLProgramProcessor.cpp deleted file mode 100644 index 32ffe66efc0..00000000000 --- a/Components/RTShaderSystem/src/OgreShaderGLSLProgramProcessor.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* ------------------------------------------------------------------------------ -This source file is part of OGRE -(Object-oriented Graphics Rendering Engine) -For the latest info, see http://www.ogre3d.org/ - -Copyright (c) 2000-2014 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. ------------------------------------------------------------------------------ -*/ - -#include "OgreShaderPrecompiledHeaders.h" - -namespace Ogre { -namespace RTShader { - -//----------------------------------------------------------------------------- -GLSLProgramProcessor::GLSLProgramProcessor() -{ -} - -//----------------------------------------------------------------------------- -GLSLProgramProcessor::~GLSLProgramProcessor() -{ -} - -//----------------------------------------------------------------------------- -bool GLSLProgramProcessor::preCreateGpuPrograms(ProgramSet* programSet) -{ - Program* vsProgram = programSet->getCpuProgram(GPT_VERTEX_PROGRAM); - Program* fsProgram = programSet->getCpuProgram(GPT_FRAGMENT_PROGRAM); - Function* vsMain = vsProgram->getEntryPointFunction(); - Function* fsMain = fsProgram->getEntryPointFunction(); - bool success; - - // Compact vertex shader outputs. - success = ProgramProcessor::compactVsOutputs(vsMain, fsMain); - if (success == false) - return false; - - return true; -} - -//----------------------------------------------------------------------------- -bool GLSLProgramProcessor::postCreateGpuPrograms(ProgramSet* programSet) -{ - // Bind vertex auto parameters. - for(auto type : {GPT_VERTEX_PROGRAM, GPT_FRAGMENT_PROGRAM}) - { - Program* cpuProgram = programSet->getCpuProgram(type); - const GpuProgramPtr& gpuProgram = programSet->getGpuProgram(type); - bindAutoParameters(cpuProgram, gpuProgram); - bindTextureSamplers(cpuProgram, gpuProgram); - } - - return true; -} -//----------------------------------------------------------------------------- -void GLSLProgramProcessor::bindTextureSamplers(Program* pCpuProgram, GpuProgramPtr pGpuProgram) -{ - if (StringConverter::parseBool(pGpuProgram->getParameter("has_sampler_binding"))) - return; - - GpuProgramParametersSharedPtr pGpuParams = pGpuProgram->getDefaultParameters(); - - // Bind the samplers. - for (const auto& pCurParam : pCpuProgram->getParameters()) - { - if (pCurParam->isSampler() && pCurParam->isUsed()) - { - // The optimizer may remove some unnecessary parameters, so we should ignore them - pGpuParams->setIgnoreMissingParams(true); - pGpuParams->setNamedConstant(pCurParam->getName(), pCurParam->getIndex()); - } - } -} - -} -} diff --git a/Components/RTShaderSystem/src/OgreShaderGLSLProgramProcessor.h b/Components/RTShaderSystem/src/OgreShaderGLSLProgramProcessor.h deleted file mode 100644 index 8dcc65f07c3..00000000000 --- a/Components/RTShaderSystem/src/OgreShaderGLSLProgramProcessor.h +++ /dev/null @@ -1,83 +0,0 @@ -/* ------------------------------------------------------------------------------ -This source file is part of OGRE -(Object-oriented Graphics Rendering Engine) -For the latest info, see http://www.ogre3d.org - -Copyright (c) 2000-2014 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 _ShaderGLSLProgramProcessor_ -#define _ShaderGLSLProgramProcessor_ - -#include "OgreShaderPrerequisites.h" -#include "OgreShaderProgramProcessor.h" -#include "OgreStringVector.h" - -namespace Ogre { -namespace RTShader { - -/** \addtogroup Optional -* @{ -*/ -/** \addtogroup RTShader -* @{ -*/ - -/** GLSL Language program processor class. -*/ -class GLSLProgramProcessor : public ProgramProcessor -{ - -// Interface. -public: - - /** Class constructor. - */ - GLSLProgramProcessor(); - - /** Class destructor */ - virtual ~GLSLProgramProcessor(); - - /** - @see ProgramProcessor::preCreateGpuPrograms - */ - bool preCreateGpuPrograms(ProgramSet* programSet) override; - - /** - @see ProgramProcessor::postCreateGpuPrograms - */ - bool postCreateGpuPrograms(ProgramSet* programSet) override; - - -private: - - /** Bind texture samplers. */ - void bindTextureSamplers(Program* pCpuProgram, GpuProgramPtr pGpuProgram); -}; - -/** @} */ -/** @} */ - -} -} - -#endif - diff --git a/Components/RTShaderSystem/src/OgreShaderHLSLProgramProcessor.cpp b/Components/RTShaderSystem/src/OgreShaderHLSLProgramProcessor.cpp deleted file mode 100644 index bfe436b0f27..00000000000 --- a/Components/RTShaderSystem/src/OgreShaderHLSLProgramProcessor.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* ------------------------------------------------------------------------------ -This source file is part of OGRE -(Object-oriented Graphics Rendering Engine) -For the latest info, see http://www.ogre3d.org/ - -Copyright (c) 2000-2014 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. ------------------------------------------------------------------------------ -*/ - -#include "OgreShaderPrecompiledHeaders.h" - -namespace Ogre { -namespace RTShader { - -String HLSLProgramProcessor::TargetLanguage = "hlsl"; - -//----------------------------------------------------------------------------- -HLSLProgramProcessor::HLSLProgramProcessor() -{ - -} - -//----------------------------------------------------------------------------- -HLSLProgramProcessor::~HLSLProgramProcessor() -{ - -} - -//----------------------------------------------------------------------------- -bool HLSLProgramProcessor::preCreateGpuPrograms( ProgramSet* programSet ) -{ - Program* vsProgram = programSet->getCpuProgram(GPT_VERTEX_PROGRAM); - Program* psProgram = programSet->getCpuProgram(GPT_FRAGMENT_PROGRAM); - Function* vsMain = vsProgram->getEntryPointFunction(); - Function* fsMain = psProgram->getEntryPointFunction(); - bool success; - - // Compact vertex shader outputs. - success = ProgramProcessor::compactVsOutputs(vsMain, fsMain); - if (success == false) - return false; - - return true; -} - -//----------------------------------------------------------------------------- -bool HLSLProgramProcessor::postCreateGpuPrograms( ProgramSet* programSet ) -{ - // Bind vertex auto parameters. - for(auto type : {GPT_VERTEX_PROGRAM, GPT_FRAGMENT_PROGRAM}) - bindAutoParameters(programSet->getCpuProgram(type), programSet->getGpuProgram(type)); - - return true; -} - -} -} diff --git a/Components/RTShaderSystem/src/OgreShaderHLSLProgramProcessor.h b/Components/RTShaderSystem/src/OgreShaderHLSLProgramProcessor.h deleted file mode 100644 index be5ad00491a..00000000000 --- a/Components/RTShaderSystem/src/OgreShaderHLSLProgramProcessor.h +++ /dev/null @@ -1,83 +0,0 @@ -/* ------------------------------------------------------------------------------ -This source file is part of OGRE -(Object-oriented Graphics Rendering Engine) -For the latest info, see http://www.ogre3d.org - -Copyright (c) 2000-2014 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 _ShaderHLSLProgramProcessor_ -#define _ShaderHLSLProgramProcessor_ - -#include "OgreShaderPrerequisites.h" -#include "OgreShaderProgramProcessor.h" - - -namespace Ogre { -namespace RTShader { - -/** \addtogroup Optional -* @{ -*/ -/** \addtogroup RTShader -* @{ -*/ - -/** CG Language program processor class. -*/ -class HLSLProgramProcessor : public ProgramProcessor -{ - - // Interface. -public: - - /** Class constructor. - */ - HLSLProgramProcessor(); - - /** Class destructor */ - virtual ~HLSLProgramProcessor(); - - /** Return the target language of this processor. */ - virtual const String& getTargetLanguage() const { return TargetLanguage; } - - /** - @see ProgramProcessor::preCreateGpuPrograms - */ - bool preCreateGpuPrograms(ProgramSet* programSet) override; - /** - @see ProgramProcessor::postCreateGpuPrograms - */ - bool postCreateGpuPrograms(ProgramSet* programSet) override; - - static String TargetLanguage; - -}; - - -/** @} */ -/** @} */ - -} -} - -#endif - diff --git a/Components/RTShaderSystem/src/OgreShaderPrecompiledHeaders.h b/Components/RTShaderSystem/src/OgreShaderPrecompiledHeaders.h index 85c801dab93..0e33e2632a1 100644 --- a/Components/RTShaderSystem/src/OgreShaderPrecompiledHeaders.h +++ b/Components/RTShaderSystem/src/OgreShaderPrecompiledHeaders.h @@ -82,9 +82,6 @@ THE SOFTWARE. #include "OgreShaderCookTorranceLighting.h" #include "OgreShaderImageBasedLighting.h" -#include "OgreShaderHLSLProgramProcessor.h" -#include "OgreShaderGLSLProgramProcessor.h" - #include "OgreShaderProgramWriter.h" #include "OgreShaderProgramWriterManager.h" #include "OgreShaderCGProgramWriter.h" diff --git a/Components/RTShaderSystem/src/OgreShaderProgramManager.cpp b/Components/RTShaderSystem/src/OgreShaderProgramManager.cpp index 5850f0561c1..ee55424a20f 100644 --- a/Components/RTShaderSystem/src/OgreShaderProgramManager.cpp +++ b/Components/RTShaderSystem/src/OgreShaderProgramManager.cpp @@ -101,22 +101,12 @@ void ProgramManager::flushGpuProgramsCache() void ProgramManager::createDefaultProgramProcessors() { // Add standard shader processors - mDefaultProgramProcessors.push_back(OGRE_NEW GLSLProgramProcessor); - addProgramProcessor("glsles", mDefaultProgramProcessors.back()); - addProgramProcessor("glslang", mDefaultProgramProcessors.back()); -#if OGRE_PLATFORM != OGRE_PLATFORM_ANDROID - addProgramProcessor("glsl", mDefaultProgramProcessors.back()); - mDefaultProgramProcessors.push_back(OGRE_NEW HLSLProgramProcessor); - addProgramProcessor("hlsl", mDefaultProgramProcessors.back()); -#endif + mDefaultProgramProcessors.push_back(OGRE_NEW ProgramProcessor); } //----------------------------------------------------------------------------- void ProgramManager::destroyDefaultProgramProcessors() { - // removing unknown is not an error - for(auto lang : {"glsl", "glsles", "glslang", "hlsl"}) - removeProgramProcessor(lang); for (auto processor : mDefaultProgramProcessors) { OGRE_DELETE processor; } @@ -136,17 +126,7 @@ void ProgramManager::createGpuPrograms(ProgramSet* programSet) auto programWriter = ProgramWriterManager::getSingleton().getProgramWriter(language); - ProgramProcessorIterator itProcessor = mProgramProcessorsMap.find(language); - ProgramProcessor* programProcessor = NULL; - - if (itProcessor == mProgramProcessorsMap.end()) - { - OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, - "Could not find processor for language '" + language, - "ProgramManager::createGpuPrograms"); - } - - programProcessor = itProcessor->second; + ProgramProcessor* programProcessor = mDefaultProgramProcessors.front(); // Call the pre creation of GPU programs method. if (!programProcessor->preCreateGpuPrograms(programSet)) @@ -279,28 +259,8 @@ String ProgramManager::generateHash(const String& programString, const String& d //----------------------------------------------------------------------------- -void ProgramManager::addProgramProcessor(const String& lang, ProgramProcessor* processor) -{ - - ProgramProcessorIterator itFind = mProgramProcessorsMap.find(lang); - - if (itFind != mProgramProcessorsMap.end()) - { - OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "A processor for language '" + lang + "' already exists."); - } - - mProgramProcessorsMap[lang] = processor; -} - -//----------------------------------------------------------------------------- -void ProgramManager::removeProgramProcessor(const String& lang) -{ - ProgramProcessorIterator itFind = mProgramProcessorsMap.find(lang); - - if (itFind != mProgramProcessorsMap.end()) - mProgramProcessorsMap.erase(itFind); - -} +void ProgramManager::addProgramProcessor(const String& lang, ProgramProcessor* processor) {} +void ProgramManager::removeProgramProcessor(const String& lang) {} //----------------------------------------------------------------------- void ProgramManager::matchVStoPSInterface( ProgramSet* programSet ) diff --git a/Components/RTShaderSystem/src/OgreShaderProgramProcessor.cpp b/Components/RTShaderSystem/src/OgreShaderProgramProcessor.cpp index 564c5d1382b..64d79fcd14e 100644 --- a/Components/RTShaderSystem/src/OgreShaderProgramProcessor.cpp +++ b/Components/RTShaderSystem/src/OgreShaderProgramProcessor.cpp @@ -44,6 +44,34 @@ ProgramProcessor::~ProgramProcessor() } +//----------------------------------------------------------------------------- +bool ProgramProcessor::preCreateGpuPrograms(ProgramSet* programSet) +{ + Program* vsProgram = programSet->getCpuProgram(GPT_VERTEX_PROGRAM); + Program* fsProgram = programSet->getCpuProgram(GPT_FRAGMENT_PROGRAM); + Function* vsMain = vsProgram->getEntryPointFunction(); + Function* fsMain = fsProgram->getEntryPointFunction(); + + // Compact vertex shader outputs. + return compactVsOutputs(vsMain, fsMain); +} + + +bool ProgramProcessor::postCreateGpuPrograms(ProgramSet* programSet) +{ + // Bind vertex auto parameters. + for(auto type : {GPT_VERTEX_PROGRAM, GPT_FRAGMENT_PROGRAM}) + bindAutoParameters(programSet->getCpuProgram(type), programSet->getGpuProgram(type)); + + if(ShaderGenerator::getSingleton().getTargetLanguage().find("glsl") == String::npos) + return true; + + for(auto type : {GPT_VERTEX_PROGRAM, GPT_FRAGMENT_PROGRAM}) + bindTextureSamplers(programSet->getCpuProgram(type), programSet->getGpuProgram(type)); + + return true; +} + //----------------------------------------------------------------------------- void ProgramProcessor::bindAutoParameters(Program* pCpuProgram, GpuProgramPtr pGpuProgram) { @@ -99,6 +127,25 @@ void ProgramProcessor::bindAutoParameters(Program* pCpuProgram, GpuProgramPtr pG } } +void ProgramProcessor::bindTextureSamplers(Program* pCpuProgram, GpuProgramPtr pGpuProgram) +{ + if (StringConverter::parseBool(pGpuProgram->getParameter("has_sampler_binding"))) + return; + + GpuProgramParametersSharedPtr pGpuParams = pGpuProgram->getDefaultParameters(); + + // Bind the samplers. + for (const auto& pCurParam : pCpuProgram->getParameters()) + { + if (pCurParam->isSampler() && pCurParam->isUsed()) + { + // The optimizer may remove some unnecessary parameters, so we should ignore them + pGpuParams->setIgnoreMissingParams(true); + pGpuParams->setNamedConstant(pCurParam->getName(), pCurParam->getIndex()); + } + } +} + //----------------------------------------------------------------------------- bool ProgramProcessor::compactVsOutputs(Function* vsMain, Function* fsMain) { diff --git a/Components/RTShaderSystem/src/OgreShaderProgramProcessor.h b/Components/RTShaderSystem/src/OgreShaderProgramProcessor.h index f3fae078ec0..0c93eb66d00 100644 --- a/Components/RTShaderSystem/src/OgreShaderProgramProcessor.h +++ b/Components/RTShaderSystem/src/OgreShaderProgramProcessor.h @@ -63,13 +63,13 @@ class ProgramProcessor : public RTShaderSystemAlloc @param programSet The program set container. Return true on success. */ - virtual bool preCreateGpuPrograms(ProgramSet* programSet) = 0; + bool preCreateGpuPrograms(ProgramSet* programSet); /** Called after creation of the GPU programs. @param programSet The program set container. Return true on success. */ - virtual bool postCreateGpuPrograms(ProgramSet* programSet) = 0; + bool postCreateGpuPrograms(ProgramSet* programSet); // Protected types. protected: @@ -250,6 +250,7 @@ class ProgramProcessor : public RTShaderSystemAlloc /** Bind the auto parameters for a given CPU and GPU program set. */ void bindAutoParameters(Program* pCpuProgram, GpuProgramPtr pGpuProgram); + void bindTextureSamplers(Program* pCpuProgram, GpuProgramPtr pGpuProgram); protected: // Merging combinations defs. MergeCombinationList mParamMergeCombinations;