Hello Johannes, On 2017-05-11 01:23, Johannes wrote:
> - For OSGComputeShaderAlgorithm is it possible to combine the > useMemoryBarrier and memoryBarrier fields, i.e. if memoryBarrier > is GL_NONE that means no memory barrier? That would allow > controlling the barrier with a single field instead of requiring > the setting of two. Hmm, I don't think so. GL_NONE is not a valid (better listed of allowed) parameters to the glMemoryBarrier API. I wouldn't try this.
sorry, I did not explain this in enough detail. I meant to use GL_NONE as a special value that guards the call to glMemoryBarrier, i.e.
if(_sfMemoryBarrier.getValue() != GL_NONE) glMemoryBarrier(_sfMemoryBarrier.getValue()); Please see the attached patch for details.This also matches what we do for the face culling mode where GL requires a glEnable(GL_CULL_FACE) call and glCullFace(GL_BACK) call, but there is only a single field. If it has a value that is valid for glCullFace() we issue the glEnable and glCullFace calls otherwise we call glDisable (see PolygonChunk).
Cheers, Carsten
>From e6ed2ea8b451a68d650189fe553fb4a72b7e40e7 Mon Sep 17 00:00:00 2001 From: Carsten Neumann <carsten_neum...@gmx.net> Date: Tue, 16 May 2017 14:48:04 -0500 Subject: [PATCH] Use GL_NONE to indicate no memory barrier, remove useMemoryBarrier field --- Examples/Advanced/computeshader3.cpp | 1 - Examples/Advanced/computeshader4.cpp | 1 - Examples/Advanced/computeshader5.cpp | 1 - Examples/Advanced/computeshader6.cpp | 1 - .../ComputeShader/OSGComputeShaderAlgorithm.cpp | 4 +- .../ComputeShader/OSGComputeShaderAlgorithm.fcd | 18 +--- .../OSGComputeShaderAlgorithmBase.cpp | 99 ++-------------------- .../ComputeShader/OSGComputeShaderAlgorithmBase.h | 18 +--- .../OSGComputeShaderAlgorithmBase.inl | 28 ------ 9 files changed, 15 insertions(+), 156 deletions(-) diff --git a/Examples/Advanced/computeshader3.cpp b/Examples/Advanced/computeshader3.cpp index 871d310..b602dfe 100644 --- a/Examples/Advanced/computeshader3.cpp +++ b/Examples/Advanced/computeshader3.cpp @@ -366,7 +366,6 @@ OSG::NodeTransitPtr createScene() compShaderChunk->addComputeShader(compShader); compShaderChunk->setVariables(compShader->getVariables()); - compShaderAlgo->setUseMemoryBarrier(true); compShaderAlgo->setUseVariableWorkGroupSize(true); compShaderAlgo->setMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); compShaderAlgo->setComputeShader(compShaderChunk); diff --git a/Examples/Advanced/computeshader4.cpp b/Examples/Advanced/computeshader4.cpp index c24f5d4..88d352c 100644 --- a/Examples/Advanced/computeshader4.cpp +++ b/Examples/Advanced/computeshader4.cpp @@ -426,7 +426,6 @@ OSG::AlgorithmComputeElementTransitPtr createComputation() compShaderChunk->setVariables(compShader->getVariables()); OSG::ComputeShaderAlgorithmRefPtr compShaderAlgo = OSG::ComputeShaderAlgorithm::create(); - compShaderAlgo->setUseMemoryBarrier(true); compShaderAlgo->setMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); compShaderAlgo->setComputeShader(compShaderChunk); compShaderAlgo->setDispatchConfig(work_group_count); diff --git a/Examples/Advanced/computeshader5.cpp b/Examples/Advanced/computeshader5.cpp index ef68085..0d1b71a 100644 --- a/Examples/Advanced/computeshader5.cpp +++ b/Examples/Advanced/computeshader5.cpp @@ -407,7 +407,6 @@ OSG::AlgorithmComputeElementTransitPtr createComputation() compShaderChunk->setVariables(compShader->getVariables()); OSG::ComputeShaderAlgorithmRefPtr compShaderAlgo = OSG::ComputeShaderAlgorithm::create(); - compShaderAlgo->setUseMemoryBarrier(true); compShaderAlgo->setMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); compShaderAlgo->setComputeShader(compShaderChunk); compShaderAlgo->setDispatchConfig(work_group_count); diff --git a/Examples/Advanced/computeshader6.cpp b/Examples/Advanced/computeshader6.cpp index b096fa6..aef3055 100644 --- a/Examples/Advanced/computeshader6.cpp +++ b/Examples/Advanced/computeshader6.cpp @@ -373,7 +373,6 @@ OSG::AlgorithmComputeElementTransitPtr createComputation() compShaderChunk->setVariables(compShader->getVariables()); OSG::ComputeShaderAlgorithmRefPtr compShaderAlgo = OSG::ComputeShaderAlgorithm::create(); - compShaderAlgo->setUseMemoryBarrier(true); compShaderAlgo->setMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); compShaderAlgo->setComputeShader(compShaderChunk); compShaderAlgo->setDispatchConfig(work_group_count); diff --git a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithm.cpp b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithm.cpp index 6b2bd43..d267de5 100644 --- a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithm.cpp +++ b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithm.cpp @@ -167,7 +167,7 @@ void ComputeShaderAlgorithm::execute(HardwareContext *pContext, return; } - if(_sfUseMemoryBarrier.getValue() == true && + if(_sfMemoryBarrier.getValue() != GL_NONE && !pWin->hasExtOrVersion(_arbShaderImageLoadStore, 0x0402)) { FWARNING(("OpenGL memory barrier is not supported, couldn't find " @@ -252,7 +252,7 @@ void ComputeShaderAlgorithm::execute(HardwareContext *pContext, _sfDispatchConfig.getValue()[2]); } - if (_sfUseMemoryBarrier.getValue() == true) + if (_sfMemoryBarrier.getValue() != GL_NONE) { OSGGETGLFUNCBYID_GL4(glMemoryBarrier, osgGlMemoryBarrier, diff --git a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithm.fcd b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithm.fcd index 8d3c6ab..38a87c2 100644 --- a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithm.fcd +++ b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithm.fcd @@ -76,18 +76,6 @@ </Field> <Field - name="useMemoryBarrier" - type="bool" - cardinality="single" - visibility="external" - access="public" - defaultValue="false" - > - This flag toggles the usage of the memory barrier call after the operation of - the compute shader. - </Field> - - <Field name="useVariableWorkGroupSize" type="bool" cardinality="single" @@ -105,10 +93,10 @@ cardinality="single" visibility="external" access="public" - defaultValue="GL_SHADER_STORAGE_BARRIER_BIT" + defaultValue="GL_NONE" > - This bitmask determines the behavior of the memory barrier that is issued after the - operation of the compute shader. + This bitmask determines the behavior of the memory barrier that is issued after the operation of the compute shader. + Set to GL_NONE (the default) to not issue any memory barrier. </Field> </FieldContainer> diff --git a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.cpp b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.cpp index 242c4d3..2c33000 100644 --- a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.cpp +++ b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.cpp @@ -115,19 +115,14 @@ OSG_BEGIN_NAMESPACE This does need the ARB_compute_variable_group_size GL extension to work. */ -/*! \var bool ComputeShaderAlgorithmBase::_sfUseMemoryBarrier - This flag toggles the usage of the memory barrier call after the operation of - the compute shader. -*/ - /*! \var bool ComputeShaderAlgorithmBase::_sfUseVariableWorkGroupSize This flag enables the useage of the variable work group size dispatch API that is specified in the ARB_compute_variable_group_size extension. */ /*! \var GLenum ComputeShaderAlgorithmBase::_sfMemoryBarrier - This bitmask determines the behavior of the memory barrier that is issued after the - operation of the compute shader. + This bitmask determines the behavior of the memory barrier that is issued after the operation of the compute shader. + Set to GL_NONE (the default) to not issue any memory barrier. */ @@ -232,19 +227,6 @@ void ComputeShaderAlgorithmBase::classDescInserter(TypeObject &oType) pDesc = new SFBool::Description( SFBool::getClassType(), - "useMemoryBarrier", - "This flag toggles the usage of the memory barrier call after the operation of\n" - "the compute shader.\n", - UseMemoryBarrierFieldId, UseMemoryBarrierFieldMask, - false, - (Field::SFDefaultFlags | Field::FStdAccess), - static_cast<FieldEditMethodSig>(&ComputeShaderAlgorithm::editHandleUseMemoryBarrier), - static_cast<FieldGetMethodSig >(&ComputeShaderAlgorithm::getHandleUseMemoryBarrier)); - - oType.addInitialDesc(pDesc); - - pDesc = new SFBool::Description( - SFBool::getClassType(), "useVariableWorkGroupSize", "This flag enables the useage of the variable work group size dispatch API that\n" "is specified in the ARB_compute_variable_group_size extension.\n", @@ -259,8 +241,8 @@ void ComputeShaderAlgorithmBase::classDescInserter(TypeObject &oType) pDesc = new SFGLenum::Description( SFGLenum::getClassType(), "memoryBarrier", - "This bitmask determines the behavior of the memory barrier that is issued after the\n" - "operation of the compute shader.\n", + "This bitmask determines the behavior of the memory barrier that is issued after the operation of the compute shader.\n" + "Set to GL_NONE (the default) to not issue any memory barrier.\n", MemoryBarrierFieldId, MemoryBarrierFieldMask, false, (Field::SFDefaultFlags | Field::FStdAccess), @@ -360,18 +342,6 @@ ComputeShaderAlgorithmBase::TypeObject ComputeShaderAlgorithmBase::_type( " </Field>\n" "\n" " <Field\n" - " name=\"useMemoryBarrier\"\n" - " type=\"bool\"\n" - " cardinality=\"single\"\n" - " visibility=\"external\"\n" - " access=\"public\"\n" - " defaultValue=\"false\"\n" - " >\n" - " This flag toggles the usage of the memory barrier call after the operation of\n" - " the compute shader.\n" - " </Field>\n" - "\n" - " <Field\n" " name=\"useVariableWorkGroupSize\"\n" " type=\"bool\"\n" " cardinality=\"single\"\n" @@ -389,10 +359,10 @@ ComputeShaderAlgorithmBase::TypeObject ComputeShaderAlgorithmBase::_type( " cardinality=\"single\"\n" " visibility=\"external\"\n" " access=\"public\"\n" - " defaultValue=\"GL_SHADER_STORAGE_BARRIER_BIT\"\n" + " defaultValue=\"GL_NONE\"\n" " >\n" - " This bitmask determines the behavior of the memory barrier that is issued after the\n" - " operation of the compute shader.\n" + " This bitmask determines the behavior of the memory barrier that is issued after the operation of the compute shader.\n" + " Set to GL_NONE (the default) to not issue any memory barrier.\n" " </Field>\n" "\n" "</FieldContainer>\n", @@ -520,19 +490,6 @@ const SFVec3i *ComputeShaderAlgorithmBase::getSFWorkGroupSize(void) const } -SFBool *ComputeShaderAlgorithmBase::editSFUseMemoryBarrier(void) -{ - editSField(UseMemoryBarrierFieldMask); - - return &_sfUseMemoryBarrier; -} - -const SFBool *ComputeShaderAlgorithmBase::getSFUseMemoryBarrier(void) const -{ - return &_sfUseMemoryBarrier; -} - - SFBool *ComputeShaderAlgorithmBase::editSFUseVariableWorkGroupSize(void) { editSField(UseVariableWorkGroupSizeFieldMask); @@ -642,10 +599,6 @@ SizeT ComputeShaderAlgorithmBase::getBinSize(ConstFieldMaskArg whichField) { returnValue += _sfWorkGroupSize.getBinSize(); } - if(FieldBits::NoField != (UseMemoryBarrierFieldMask & whichField)) - { - returnValue += _sfUseMemoryBarrier.getBinSize(); - } if(FieldBits::NoField != (UseVariableWorkGroupSizeFieldMask & whichField)) { returnValue += _sfUseVariableWorkGroupSize.getBinSize(); @@ -683,10 +636,6 @@ void ComputeShaderAlgorithmBase::copyToBin(BinaryDataHandler &pMem, { _sfWorkGroupSize.copyToBin(pMem); } - if(FieldBits::NoField != (UseMemoryBarrierFieldMask & whichField)) - { - _sfUseMemoryBarrier.copyToBin(pMem); - } if(FieldBits::NoField != (UseVariableWorkGroupSizeFieldMask & whichField)) { _sfUseVariableWorkGroupSize.copyToBin(pMem); @@ -727,11 +676,6 @@ void ComputeShaderAlgorithmBase::copyFromBin(BinaryDataHandler &pMem, editSField(WorkGroupSizeFieldMask); _sfWorkGroupSize.copyFromBin(pMem); } - if(FieldBits::NoField != (UseMemoryBarrierFieldMask & whichField)) - { - editSField(UseMemoryBarrierFieldMask); - _sfUseMemoryBarrier.copyFromBin(pMem); - } if(FieldBits::NoField != (UseVariableWorkGroupSizeFieldMask & whichField)) { editSField(UseVariableWorkGroupSizeFieldMask); @@ -872,9 +816,8 @@ ComputeShaderAlgorithmBase::ComputeShaderAlgorithmBase(void) : _sfComputeShader (NULL), _sfDispatchConfig (Vec3i(1, 0, 0)), _sfWorkGroupSize (Vec3i(1, 1, 1)), - _sfUseMemoryBarrier (bool(false)), _sfUseVariableWorkGroupSize(bool(false)), - _sfMemoryBarrier (GLenum(GL_SHADER_STORAGE_BARRIER_BIT)) + _sfMemoryBarrier (GLenum(GL_NONE)) { } @@ -885,7 +828,6 @@ ComputeShaderAlgorithmBase::ComputeShaderAlgorithmBase(const ComputeShaderAlgori _sfComputeShader (NULL), _sfDispatchConfig (source._sfDispatchConfig ), _sfWorkGroupSize (source._sfWorkGroupSize ), - _sfUseMemoryBarrier (source._sfUseMemoryBarrier ), _sfUseVariableWorkGroupSize(source._sfUseVariableWorkGroupSize), _sfMemoryBarrier (source._sfMemoryBarrier ) { @@ -1067,31 +1009,6 @@ EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleWorkGroupSize (void) return returnValue; } -GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleUseMemoryBarrier (void) const -{ - SFBool::GetHandlePtr returnValue( - new SFBool::GetHandle( - &_sfUseMemoryBarrier, - this->getType().getFieldDesc(UseMemoryBarrierFieldId), - const_cast<ComputeShaderAlgorithmBase *>(this))); - - return returnValue; -} - -EditFieldHandlePtr ComputeShaderAlgorithmBase::editHandleUseMemoryBarrier(void) -{ - SFBool::EditHandlePtr returnValue( - new SFBool::EditHandle( - &_sfUseMemoryBarrier, - this->getType().getFieldDesc(UseMemoryBarrierFieldId), - this)); - - - editSField(UseMemoryBarrierFieldMask); - - return returnValue; -} - GetFieldHandlePtr ComputeShaderAlgorithmBase::getHandleUseVariableWorkGroupSize (void) const { SFBool::GetHandlePtr returnValue( diff --git a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.h b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.h index ef895dd..98cdd38 100644 --- a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.h +++ b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.h @@ -69,7 +69,7 @@ #include "OSGChunkMaterialFields.h" // ChunkMaterial type #include "OSGComputeShaderChunkFields.h" // ComputeShader type #include "OSGVecFields.h" // DispatchConfig type -#include "OSGSysFields.h" // UseMemoryBarrier type +#include "OSGSysFields.h" // UseVariableWorkGroupSize type #include "OSGBaseFields.h" // MemoryBarrier type #include "OSGComputeShaderAlgorithmFields.h" @@ -104,8 +104,7 @@ class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderAlgorithmBase : public Comp ComputeShaderFieldId = ChunkMaterialFieldId + 1, DispatchConfigFieldId = ComputeShaderFieldId + 1, WorkGroupSizeFieldId = DispatchConfigFieldId + 1, - UseMemoryBarrierFieldId = WorkGroupSizeFieldId + 1, - UseVariableWorkGroupSizeFieldId = UseMemoryBarrierFieldId + 1, + UseVariableWorkGroupSizeFieldId = WorkGroupSizeFieldId + 1, MemoryBarrierFieldId = UseVariableWorkGroupSizeFieldId + 1, NextFieldId = MemoryBarrierFieldId + 1 }; @@ -120,8 +119,6 @@ class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderAlgorithmBase : public Comp (TypeTraits<BitVector>::One << DispatchConfigFieldId); static const OSG::BitVector WorkGroupSizeFieldMask = (TypeTraits<BitVector>::One << WorkGroupSizeFieldId); - static const OSG::BitVector UseMemoryBarrierFieldMask = - (TypeTraits<BitVector>::One << UseMemoryBarrierFieldId); static const OSG::BitVector UseVariableWorkGroupSizeFieldMask = (TypeTraits<BitVector>::One << UseVariableWorkGroupSizeFieldId); static const OSG::BitVector MemoryBarrierFieldMask = @@ -134,7 +131,6 @@ class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderAlgorithmBase : public Comp typedef SFUnrecComputeShaderChunkPtr SFComputeShaderType; typedef SFVec3i SFDispatchConfigType; typedef SFVec3i SFWorkGroupSizeType; - typedef SFBool SFUseMemoryBarrierType; typedef SFBool SFUseVariableWorkGroupSizeType; typedef SFGLenum SFMemoryBarrierType; @@ -174,9 +170,6 @@ class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderAlgorithmBase : public Comp SFVec3i *editSFWorkGroupSize (void); const SFVec3i *getSFWorkGroupSize (void) const; - SFBool *editSFUseMemoryBarrier(void); - const SFBool *getSFUseMemoryBarrier (void) const; - SFBool *editSFUseVariableWorkGroupSize(void); const SFBool *getSFUseVariableWorkGroupSize (void) const; @@ -196,9 +189,6 @@ class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderAlgorithmBase : public Comp Vec3i &editWorkGroupSize (void); const Vec3i &getWorkGroupSize (void) const; - bool &editUseMemoryBarrier(void); - bool getUseMemoryBarrier (void) const; - bool &editUseVariableWorkGroupSize(void); bool getUseVariableWorkGroupSize (void) const; @@ -214,7 +204,6 @@ class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderAlgorithmBase : public Comp void setComputeShader (ComputeShaderChunk * const value); void setDispatchConfig (const Vec3i &value); void setWorkGroupSize (const Vec3i &value); - void setUseMemoryBarrier(const bool value); void setUseVariableWorkGroupSize(const bool value); void setMemoryBarrier (const GLenum &value); @@ -292,7 +281,6 @@ class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderAlgorithmBase : public Comp SFUnrecComputeShaderChunkPtr _sfComputeShader; SFVec3i _sfDispatchConfig; SFVec3i _sfWorkGroupSize; - SFBool _sfUseMemoryBarrier; SFBool _sfUseVariableWorkGroupSize; SFGLenum _sfMemoryBarrier; @@ -333,8 +321,6 @@ class OSG_CONTRIBCOMPUTEBASE_DLLMAPPING ComputeShaderAlgorithmBase : public Comp EditFieldHandlePtr editHandleDispatchConfig (void); GetFieldHandlePtr getHandleWorkGroupSize (void) const; EditFieldHandlePtr editHandleWorkGroupSize (void); - GetFieldHandlePtr getHandleUseMemoryBarrier (void) const; - EditFieldHandlePtr editHandleUseMemoryBarrier(void); GetFieldHandlePtr getHandleUseVariableWorkGroupSize (void) const; EditFieldHandlePtr editHandleUseVariableWorkGroupSize(void); GetFieldHandlePtr getHandleMemoryBarrier (void) const; diff --git a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.inl b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.inl index 2aaaa9e..e8174cf 100644 --- a/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.inl +++ b/Source/Contrib/ComputeBase/ComputeShader/OSGComputeShaderAlgorithmBase.inl @@ -124,31 +124,6 @@ void ComputeShaderAlgorithmBase::setWorkGroupSize(const Vec3i &value) _sfWorkGroupSize.setValue(value); } -//! Get the value of the ComputeShaderAlgorithm::_sfUseMemoryBarrier field. - -inline -bool &ComputeShaderAlgorithmBase::editUseMemoryBarrier(void) -{ - editSField(UseMemoryBarrierFieldMask); - - return _sfUseMemoryBarrier.getValue(); -} - -//! Get the value of the ComputeShaderAlgorithm::_sfUseMemoryBarrier field. -inline - bool ComputeShaderAlgorithmBase::getUseMemoryBarrier(void) const -{ - return _sfUseMemoryBarrier.getValue(); -} - -//! Set the value of the ComputeShaderAlgorithm::_sfUseMemoryBarrier field. -inline -void ComputeShaderAlgorithmBase::setUseMemoryBarrier(const bool value) -{ - editSField(UseMemoryBarrierFieldMask); - - _sfUseMemoryBarrier.setValue(value); -} //! Get the value of the ComputeShaderAlgorithm::_sfUseVariableWorkGroupSize field. inline @@ -230,9 +205,6 @@ void ComputeShaderAlgorithmBase::execSync ( ComputeShaderAlgorithmBase *pFr if(FieldBits::NoField != (WorkGroupSizeFieldMask & whichField)) _sfWorkGroupSize.syncWith(pFrom->_sfWorkGroupSize); - if(FieldBits::NoField != (UseMemoryBarrierFieldMask & whichField)) - _sfUseMemoryBarrier.syncWith(pFrom->_sfUseMemoryBarrier); - if(FieldBits::NoField != (UseVariableWorkGroupSizeFieldMask & whichField)) _sfUseVariableWorkGroupSize.syncWith(pFrom->_sfUseVariableWorkGroupSize); -- 2.5.5
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users