From e371fdbf311e450ac0cc7f4d3fdacc938b489d92 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 29 Apr 2021 08:41:50 -0700 Subject: SL-14113: Remove magic numbers. Take advantage of existing shader #defines injection by extending shader loading to make use of addConstant() instead of hard-coding magic number constants in each GLSL file. --- indra/llrender/llglslshader.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 74cfa60b27..458f83aabe 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -62,6 +62,23 @@ U32 LLGLSLShader::sTotalDrawCalls = 0; LLGLSLShader gUIProgram; LLGLSLShader gSolidColorProgram; +// NOTE:Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! +const std::string gShaderConstsKey[ LLGLSLShader::NUM_SHADER_CONSTS ] = +{ + "LL_SHADER_CONST_CLOUD_DEPTH" + , "LL_SHADER_CONST_MOON_DEPTH" + , "LL_SHADER_CONST_STAR_DEPTH" +}; + +// NOTE:Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! +const std::string gShaderConstsVal[ LLGLSLShader::NUM_SHADER_CONSTS ] = +{ + "0.999985" // SHADER_CONST_CLOUD_DEPTH // SL-14113 + , "0.999985" // SHADER_CONST_MOON_DEPTH // SL-14113 + , "0.999995" // SHADER_CONST_STAR_DEPTH // SL-14113 +}; + + BOOL shouldChange(const LLVector4& v1, const LLVector4& v2) { return v1 != v2; @@ -755,6 +772,11 @@ void LLGLSLShader::addPermutation(std::string name, std::string value) mDefines[name] = value; } +void LLGLSLShader::addConstant( const LLGLSLShader::eShaderConsts shader_const ) +{ + addPermutation( gShaderConstsKey[ shader_const ], gShaderConstsVal[ shader_const ] ); +} + void LLGLSLShader::removePermutation(std::string name) { mDefines[name].erase(); -- cgit v1.2.3 From 3f4b8423a46bae4736ebcc28082ee1a9d5b71d6b Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 29 Apr 2021 10:27:09 -0700 Subject: SL-14113: Merge duplicate shader constant for clarity. --- indra/llrender/llglslshader.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 458f83aabe..74c8b2e448 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -62,20 +62,18 @@ U32 LLGLSLShader::sTotalDrawCalls = 0; LLGLSLShader gUIProgram; LLGLSLShader gSolidColorProgram; -// NOTE:Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! +// NOTE: Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! const std::string gShaderConstsKey[ LLGLSLShader::NUM_SHADER_CONSTS ] = { - "LL_SHADER_CONST_CLOUD_DEPTH" - , "LL_SHADER_CONST_MOON_DEPTH" + "LL_SHADER_CONST_CLOUD_MOON_DEPTH" , "LL_SHADER_CONST_STAR_DEPTH" }; -// NOTE:Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! +// NOTE: Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! const std::string gShaderConstsVal[ LLGLSLShader::NUM_SHADER_CONSTS ] = { - "0.999985" // SHADER_CONST_CLOUD_DEPTH // SL-14113 - , "0.999985" // SHADER_CONST_MOON_DEPTH // SL-14113 - , "0.999995" // SHADER_CONST_STAR_DEPTH // SL-14113 + "0.999985" // SHADER_CONST_CLOUD_MOON_DEPTH // SL-14113 + , "0.999995" // SHADER_CONST_STAR_DEPTH // SL-14113 }; -- cgit v1.2.3 From d3c439b3743490ee22d5356ec3b61cb13c86f487 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 29 Apr 2021 14:06:37 -0700 Subject: SL-14113: Remove useless last digit in constant to help readability based on Euclid's feedback --- indra/llrender/llglslshader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 74c8b2e448..d669e7134c 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -72,8 +72,8 @@ const std::string gShaderConstsKey[ LLGLSLShader::NUM_SHADER_CONSTS ] = // NOTE: Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! const std::string gShaderConstsVal[ LLGLSLShader::NUM_SHADER_CONSTS ] = { - "0.999985" // SHADER_CONST_CLOUD_MOON_DEPTH // SL-14113 - , "0.999995" // SHADER_CONST_STAR_DEPTH // SL-14113 + "0.99998" // SHADER_CONST_CLOUD_MOON_DEPTH // SL-14113 + , "0.99999" // SHADER_CONST_STAR_DEPTH // SL-14113 }; -- cgit v1.2.3 From b854eceee3a867d64b20de18d6b7ce91b33abed0 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 11 Jun 2021 21:16:08 +0300 Subject: SL-15391 Crash at getUniformLocation --- indra/llrender/llglslshader.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 42b8c35442..d3942c7552 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1427,7 +1427,11 @@ GLint LLGLSLShader::getUniformLocation(U32 index) GLint ret = -1; if (mProgramObject) { - llassert(index < mUniform.size()); + if (index >= mUniform.size()) + { + LL_WARNS_ONCE("Shader") << "Uniform index " << index << " out of bounds " << (S32)mUniform.size() << LL_ENDL; + return ret; + } return mUniform[index]; } -- cgit v1.2.3 From 7ce17542d46ff7cb6b88d33d4cad5ba4808c6c58 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 12 Nov 2021 17:34:13 +0200 Subject: DRTVWR-528 Reverting multiple commits due to moving them into D546 branch This reverts commits 9b5b2eac82b1f423daec463b3d55d0f3d3979bbc SL-15933 53c0144dd272470172591b967a84beaa4019b728 SL-11687 492ea7c3a03d5ef0d3679b873a44c08baaced0f1 SL-16056 b854eceee3a867d64b20de18d6b7ce91b33abed0 SL-15391 921c3f5f69c90b5924d2f4bbbd32455f8c9c8173 SL-13561 639acb6ff7495a6840d437dd8473172ec03e200a SL-15333 --- indra/llrender/llglslshader.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index d3942c7552..42b8c35442 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1427,11 +1427,7 @@ GLint LLGLSLShader::getUniformLocation(U32 index) GLint ret = -1; if (mProgramObject) { - if (index >= mUniform.size()) - { - LL_WARNS_ONCE("Shader") << "Uniform index " << index << " out of bounds " << (S32)mUniform.size() << LL_ENDL; - return ret; - } + llassert(index < mUniform.size()); return mUniform[index]; } -- cgit v1.2.3 From 93a025966649e281ceff8d1471bc983cc036bc17 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 29 Apr 2022 13:51:11 +0000 Subject: SL-17282 prototype mixing of reflection map into legacy materials --- indra/llrender/llglslshader.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 185c1450c8..3001375c60 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -832,6 +832,9 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) As example where this situation appear see: "Deferred Material Shader 28/29/30/31" And tickets: MAINT-4165, MAINT-4839, MAINT-3568, MAINT-6437 + + --- davep TODO -- pretty sure the entire block here is superstitious and that the uniform index has nothing to do with the texture channel + texture channel should follow the uniform VALUE */ @@ -840,6 +843,7 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) S32 bumpMap = glGetUniformLocationARB(mProgramObject, "bumpMap"); S32 altDiffuseMap = glGetUniformLocationARB(mProgramObject, "altDiffuseMap"); S32 environmentMap = glGetUniformLocationARB(mProgramObject, "environmentMap"); + S32 reflectionMap = glGetUniformLocationARB(mProgramObject, "reflectionMap"); std::set skip_index; @@ -882,6 +886,12 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) continue; } + if (-1 == reflectionMap && std::string(name) == "reflectionMap") + { + reflectionMap = i; + continue; + } + if (-1 == altDiffuseMap && std::string(name) == "altDiffuseMap") { altDiffuseMap = i; @@ -892,8 +902,9 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) bool specularDiff = specularMap < diffuseMap && -1 != specularMap; bool bumpLessDiff = bumpMap < diffuseMap && -1 != bumpMap; bool envLessDiff = environmentMap < diffuseMap && -1 != environmentMap; + bool refLessDiff = reflectionMap < diffuseMap && -1 != reflectionMap; - if (specularDiff || bumpLessDiff || envLessDiff) + if (specularDiff || bumpLessDiff || envLessDiff || refLessDiff) { mapUniform(diffuseMap, uniforms); skip_index.insert(diffuseMap); @@ -912,6 +923,11 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) mapUniform(environmentMap, uniforms); skip_index.insert(environmentMap); } + + if (-1 != reflectionMap) { + mapUniform(reflectionMap, uniforms); + skip_index.insert(reflectionMap); + } } } -- cgit v1.2.3 From 93260cfeff2382dd1ffeecaef208d37bf21c2a01 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 4 May 2022 16:07:50 +0000 Subject: SL-17283 LLReflectionMapManager prototype. Remove snapshot code related overhead from reflection map renders. Add parallax correction and support for multiple reflection maps. --- indra/llrender/llglslshader.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 3001375c60..a52dcd5aa1 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -738,7 +738,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector * { //found it mUniform[i] = location; - mTexture[i] = mapUniformTextureChannel(location, type); + mTexture[i] = mapUniformTextureChannel(location, type, size); return; } } @@ -752,7 +752,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector * { //found it mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location; - mTexture[i+LLShaderMgr::instance()->mReservedUniforms.size()] = mapUniformTextureChannel(location, type); + mTexture[i+LLShaderMgr::instance()->mReservedUniforms.size()] = mapUniformTextureChannel(location, type, size); return; } } @@ -775,16 +775,37 @@ void LLGLSLShader::removePermutation(std::string name) mDefines[name].erase(); } -GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type) +GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type, GLint size) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if ((type >= GL_SAMPLER_1D_ARB && type <= GL_SAMPLER_2D_RECT_SHADOW_ARB) || type == GL_SAMPLER_2D_MULTISAMPLE) { //this here is a texture - glUniform1iARB(location, mActiveTextureChannels); - LL_DEBUGS("ShaderUniform") << "Assigned to texture channel " << mActiveTextureChannels << LL_ENDL; - return mActiveTextureChannels++; + GLint ret = mActiveTextureChannels; + if (size == 1) + { + glUniform1iARB(location, mActiveTextureChannels); + LL_DEBUGS("ShaderUniform") << "Assigned to texture channel " << mActiveTextureChannels << LL_ENDL; + mActiveTextureChannels++; + } + else + { + //is array of textures, make sequential after this texture + GLint channel[32]; // <=== only support up to 32 texture channels + llassert(size <= 32); + size = llmin(size, 32); + for (int i = 0; i < size; ++i) + { + channel[i] = mActiveTextureChannels++; + } + glUniform1ivARB(location, size, channel); + LL_DEBUGS("ShaderUniform") << "Assigned to texture channel " << + (mActiveTextureChannels-size) << " through " << (mActiveTextureChannels-1) << LL_ENDL; + } + + llassert(mActiveTextureChannels <= 32); // too many textures (probably) + return ret; } return -1; } -- cgit v1.2.3 From 3400e5fd302c0d9dea6386c4d5bf38876f2cc287 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 16 May 2022 17:21:08 +0000 Subject: SL-17284 Reflection probe tuning and optimization take 1 --- indra/llrender/llglslshader.cpp | 61 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index a52dcd5aa1..0212c605c3 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -780,7 +780,8 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type, GLint LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if ((type >= GL_SAMPLER_1D_ARB && type <= GL_SAMPLER_2D_RECT_SHADOW_ARB) || - type == GL_SAMPLER_2D_MULTISAMPLE) + type == GL_SAMPLER_2D_MULTISAMPLE || + type == GL_SAMPLER_CUBE_MAP_ARRAY_ARB) { //this here is a texture GLint ret = mActiveTextureChannels; if (size == 1) @@ -1289,6 +1290,30 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) } } +void LLGLSLShader::uniform4iv(U32 index, U32 count, const GLint* v) +{ + if (mProgramObject) + { + if (mUniform.size() <= index) + { + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; + return; + } + + if (mUniform[index] >= 0) + { + const auto& iter = mValue.find(mUniform[index]); + LLVector4 vec(v[0], v[1], v[2], v[3]); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) + { + glUniform1ivARB(mUniform[index], count, v); + mValue[mUniform[index]] = vec; + } + } + } +} + + void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) { if (mProgramObject) @@ -1526,6 +1551,40 @@ void LLGLSLShader::uniform1i(const LLStaticHashedString& uniform, GLint v) } } +void LLGLSLShader::uniform1iv(const LLStaticHashedString& uniform, U32 count, const GLint* v) +{ + GLint location = getUniformLocation(uniform); + + if (location >= 0) + { + LLVector4 vec(v[0], 0, 0, 0); + const auto& iter = mValue.find(location); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) + { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + glUniform1ivARB(location, count, v); + mValue[location] = vec; + } + } +} + +void LLGLSLShader::uniform4iv(const LLStaticHashedString& uniform, U32 count, const GLint* v) +{ + GLint location = getUniformLocation(uniform); + + if (location >= 0) + { + LLVector4 vec(v[0], v[1], v[2], v[3]); + const auto& iter = mValue.find(location); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) + { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + glUniform4ivARB(location, count, v); + mValue[location] = vec; + } + } +} + void LLGLSLShader::uniform2i(const LLStaticHashedString& uniform, GLint i, GLint j) { GLint location = getUniformLocation(uniform); -- cgit v1.2.3 From 6b857059516be849e60570445a03f58647656c53 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Thu, 23 Jun 2022 17:33:03 -0700 Subject: fixing DRTVWR-559 glext usage on mac by upgrading to use khronos distributed glext.h --- indra/llrender/llglslshader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 0212c605c3..67f82c9c5e 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -452,7 +452,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, #ifdef GL_INTERLEAVED_ATTRIBS if (varying_count > 0 && varyings) { - glTransformFeedbackVaryings(mProgramObject, varying_count, varyings, GL_INTERLEAVED_ATTRIBS); + glTransformFeedbackVaryings((GLuint64) mProgramObject, varying_count, varyings, GL_INTERLEAVED_ATTRIBS); } #endif -- cgit v1.2.3 From 2082443220fe344bb027c3acbf50fea0a99159c3 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 1 Sep 2022 10:58:27 -0700 Subject: SL-17967 - Git rid of ARB that is in core --- indra/llrender/llglslshader.cpp | 154 ++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 77 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 67f82c9c5e..db70ba0c60 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -37,7 +37,7 @@ #include "OpenGL/OpenGL.h" #endif -// Print-print list of shader included source files that are linked together via glAttachObjectARB() +// Print-print list of shader included source files that are linked together via glAttachShader() // i.e. On macOS / OSX the AMD GLSL linker will display an error if a varying is left in an undefined state. #define DEBUG_SHADER_INCLUDES 0 @@ -47,7 +47,7 @@ using std::pair; using std::make_pair; using std::string; -GLhandleARB LLGLSLShader::sCurBoundShader = 0; +GLuint LLGLSLShader::sCurBoundShader = 0; LLGLSLShader* LLGLSLShader::sCurBoundShaderPtr = NULL; S32 LLGLSLShader::sIndexedTextureChannels = 0; bool LLGLSLShader::sProfileEnabled = false; @@ -227,11 +227,11 @@ void LLGLSLShader::stopProfile(U32 count, U32 mode) void LLGLSLShader::placeProfileQuery() { -#if !LL_DARWIN +#if 1 || !LL_DARWIN if (mTimerQuery == 0) { - glGenQueriesARB(1, &mSamplesQuery); - glGenQueriesARB(1, &mTimerQuery); + glGenQueries(1, &mSamplesQuery); + glGenQueries(1, &mTimerQuery); } if (!mTextureStateFetched) @@ -267,16 +267,16 @@ void LLGLSLShader::placeProfileQuery() } - glBeginQueryARB(GL_SAMPLES_PASSED, mSamplesQuery); - glBeginQueryARB(GL_TIME_ELAPSED, mTimerQuery); + glBeginQuery(GL_SAMPLES_PASSED, mSamplesQuery); + glBeginQuery(GL_TIME_ELAPSED, mTimerQuery); #endif } void LLGLSLShader::readProfileQuery(U32 count, U32 mode) { #if !LL_DARWIN - glEndQueryARB(GL_TIME_ELAPSED); - glEndQueryARB(GL_SAMPLES_PASSED); + glEndQuery(GL_TIME_ELAPSED); + glEndQuery(GL_SAMPLES_PASSED); U64 time_elapsed = 0; glGetQueryObjectui64v(mTimerQuery, GL_QUERY_RESULT, &time_elapsed); @@ -347,30 +347,30 @@ void LLGLSLShader::unloadInternal() if (mProgramObject) { - GLhandleARB obj[1024]; + GLuint obj[1024]; GLsizei count; - glGetAttachedObjectsARB(mProgramObject, 1024, &count, obj); + glGetAttachedShaders(mProgramObject, 1024, &count, obj); for (GLsizei i = 0; i < count; i++) { - glDetachObjectARB(mProgramObject, obj[i]); - glDeleteObjectARB(obj[i]); + glDetachShader(mProgramObject, obj[i]); + glDeleteShader(obj[i]); } - glDeleteObjectARB(mProgramObject); + glDeleteProgram(mProgramObject); mProgramObject = 0; } if (mTimerQuery) { - glDeleteQueriesARB(1, &mTimerQuery); + glDeleteQueries(1, &mTimerQuery); mTimerQuery = 0; } if (mSamplesQuery) { - glDeleteQueriesARB(1, &mSamplesQuery); + glDeleteQueries(1, &mSamplesQuery); mSamplesQuery = 0; } @@ -401,7 +401,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, llassert_always(!mShaderFiles.empty()); // Create program - mProgramObject = glCreateProgramObjectARB(); + mProgramObject = glCreateProgram(); if (mProgramObject == 0) { // Shouldn't happen if shader related extensions, like ARB_vertex_shader, exist. @@ -425,7 +425,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, vector< pair >::iterator fileIter = mShaderFiles.begin(); for ( ; fileIter != mShaderFiles.end(); fileIter++ ) { - GLhandleARB shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels); + GLuint shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels); LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL; if (shaderhandle) { @@ -505,20 +505,20 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, } #if DEBUG_SHADER_INCLUDES -void dumpAttachObject( const char *func_name, GLhandleARB program_object, const std::string &object_path ) +void dumpAttachObject( const char *func_name, GLuint program_object, const std::string &object_path ) { - GLcharARB* info_log; + GLchar* info_log; GLint info_len_expect = 0; GLint info_len_actual = 0; - glGetObjectParameterivARB(program_object, GL_OBJECT_INFO_LOG_LENGTH_ARB, &info_len_expect); + glGetShaderiv(program_object, GL_INFO_LOG_LENGTH,, &info_len_expect); fprintf(stderr, " * %-20s(), log size: %d, %s\n", func_name, info_len_expect, object_path.c_str()); if (info_len_expect > 0) { fprintf(stderr, " ========== %s() ========== \n", func_name); - info_log = new GLcharARB [ info_len_expect ]; - glGetInfoLogARB(program_object, info_len_expect, &info_len_actual, info_log); + info_log = new GLchar [ info_len_expect ]; + glGetProgramInfoLog(program_object, info_len_expect, &info_len_actual, info_log); fprintf(stderr, "%s\n", info_log); delete [] info_log; } @@ -530,7 +530,7 @@ BOOL LLGLSLShader::attachVertexObject(std::string object_path) if (LLShaderMgr::instance()->mVertexShaderObjects.count(object_path) > 0) { stop_glerror(); - glAttachObjectARB(mProgramObject, LLShaderMgr::instance()->mVertexShaderObjects[object_path]); + glAttachShader(mProgramObject, LLShaderMgr::instance()->mVertexShaderObjects[object_path]); #if DEBUG_SHADER_INCLUDES dumpAttachObject("attachVertexObject", mProgramObject, object_path); #endif // DEBUG_SHADER_INCLUDES @@ -549,7 +549,7 @@ BOOL LLGLSLShader::attachFragmentObject(std::string object_path) if (LLShaderMgr::instance()->mFragmentShaderObjects.count(object_path) > 0) { stop_glerror(); - glAttachObjectARB(mProgramObject, LLShaderMgr::instance()->mFragmentShaderObjects[object_path]); + glAttachShader(mProgramObject, LLShaderMgr::instance()->mFragmentShaderObjects[object_path]); #if DEBUG_SHADER_INCLUDES dumpAttachObject("attachFragmentObject", mProgramObject, object_path); #endif // DEBUG_SHADER_INCLUDES @@ -563,12 +563,12 @@ BOOL LLGLSLShader::attachFragmentObject(std::string object_path) } } -void LLGLSLShader::attachObject(GLhandleARB object) +void LLGLSLShader::attachObject(GLuint object) { if (object != 0) { stop_glerror(); - glAttachObjectARB(mProgramObject, object); + glAttachShader(mProgramObject, object); #if DEBUG_SHADER_INCLUDES std::string object_path("???"); dumpAttachObject("attachObject", mProgramObject, object_path); @@ -581,7 +581,7 @@ void LLGLSLShader::attachObject(GLhandleARB object) } } -void LLGLSLShader::attachObjects(GLhandleARB* objects, S32 count) +void LLGLSLShader::attachObjects(GLuint* objects, S32 count) { for (S32 i = 0; i < count; i++) { @@ -597,7 +597,7 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++) { const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str(); - glBindAttribLocationARB(mProgramObject, i, (const GLcharARB *) name); + glBindAttribLocation(mProgramObject, i, (const GLchar *) name); } //link the program @@ -620,7 +620,7 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++) { const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str(); - S32 index = glGetAttribLocationARB(mProgramObject, (const GLcharARB *)name); + S32 index = glGetAttribLocation(mProgramObject, (const GLchar *)name); if (index != -1) { #if LL_RELEASE_WITH_DEBUG_INFO @@ -637,7 +637,7 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri for (U32 i = 0; i < numAttributes; i++) { const char* name = (*attributes)[i].String().c_str(); - S32 index = glGetAttribLocationARB(mProgramObject, name); + S32 index = glGetAttribLocation(mProgramObject, name); if (index != -1) { mAttribute[LLShaderMgr::instance()->mReservedAttribs.size() + i] = index; @@ -668,7 +668,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector * name[0] = 0; - glGetActiveUniformARB(mProgramObject, index, 1024, &length, &size, &type, (GLcharARB *)name); + glGetActiveUniform(mProgramObject, index, 1024, &length, &size, &type, (GLchar *)name); #if !LL_DARWIN if (size > 0) { @@ -713,7 +713,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector * } #endif - S32 location = glGetUniformLocationARB(mProgramObject, name); + S32 location = glGetUniformLocation(mProgramObject, name); if (location != -1) { //chop off "[0]" so we can always access the first element @@ -779,14 +779,14 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type, GLint { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - if ((type >= GL_SAMPLER_1D_ARB && type <= GL_SAMPLER_2D_RECT_SHADOW_ARB) || + if ((type >= GL_SAMPLER_1D && type <= GL_SAMPLER_2D_RECT_SHADOW) || type == GL_SAMPLER_2D_MULTISAMPLE || - type == GL_SAMPLER_CUBE_MAP_ARRAY_ARB) + type == GL_SAMPLER_CUBE_MAP_ARRAY) { //this here is a texture GLint ret = mActiveTextureChannels; if (size == 1) { - glUniform1iARB(location, mActiveTextureChannels); + glUniform1i(location, mActiveTextureChannels); LL_DEBUGS("ShaderUniform") << "Assigned to texture channel " << mActiveTextureChannels << LL_ENDL; mActiveTextureChannels++; } @@ -800,7 +800,7 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type, GLint { channel[i] = mActiveTextureChannels++; } - glUniform1ivARB(location, size, channel); + glUniform1iv(location, size, channel); LL_DEBUGS("ShaderUniform") << "Assigned to texture channel " << (mActiveTextureChannels-size) << " through " << (mActiveTextureChannels-1) << LL_ENDL; } @@ -833,7 +833,7 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) //get the number of active uniforms GLint activeCount; - glGetObjectParameterivARB(mProgramObject, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); + glGetProgramiv(mProgramObject, GL_ACTIVE_UNIFORMS, &activeCount); //........................................................................................................................................ //........................................................................................ @@ -860,12 +860,12 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) */ - S32 diffuseMap = glGetUniformLocationARB(mProgramObject, "diffuseMap"); - S32 specularMap = glGetUniformLocationARB(mProgramObject, "specularMap"); - S32 bumpMap = glGetUniformLocationARB(mProgramObject, "bumpMap"); - S32 altDiffuseMap = glGetUniformLocationARB(mProgramObject, "altDiffuseMap"); - S32 environmentMap = glGetUniformLocationARB(mProgramObject, "environmentMap"); - S32 reflectionMap = glGetUniformLocationARB(mProgramObject, "reflectionMap"); + S32 diffuseMap = glGetUniformLocation(mProgramObject, "diffuseMap"); + S32 specularMap = glGetUniformLocation(mProgramObject, "specularMap"); + S32 bumpMap = glGetUniformLocation(mProgramObject, "bumpMap"); + S32 altDiffuseMap = glGetUniformLocation(mProgramObject, "altDiffuseMap"); + S32 environmentMap = glGetUniformLocation(mProgramObject, "environmentMap"); + S32 reflectionMap = glGetUniformLocation(mProgramObject, "reflectionMap"); std::set skip_index; @@ -882,7 +882,7 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) { name[0] = '\0'; - glGetActiveUniformARB(mProgramObject, i, 1024, &length, &size, &type, (GLcharARB *)name); + glGetActiveUniform(mProgramObject, i, 1024, &length, &size, &type, (GLchar *)name); if (-1 == diffuseMap && std::string(name) == "diffuseMap") { @@ -995,7 +995,7 @@ void LLGLSLShader::bind() if (sCurBoundShader != mProgramObject) // Don't re-bind current shader { LLVertexBuffer::unbind(); - glUseProgramObjectARB(mProgramObject); + glUseProgram(mProgramObject); sCurBoundShader = mProgramObject; sCurBoundShaderPtr = this; } @@ -1027,7 +1027,7 @@ void LLGLSLShader::unbind() gGL.flush(); stop_glerror(); LLVertexBuffer::unbind(); - glUseProgramObjectARB(0); + glUseProgram(0); sCurBoundShader = 0; sCurBoundShaderPtr = NULL; stop_glerror(); @@ -1038,7 +1038,7 @@ void LLGLSLShader::bindNoShader(void) LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; LLVertexBuffer::unbind(); - glUseProgramObjectARB(0); + glUseProgram(0); sCurBoundShader = 0; sCurBoundShaderPtr = NULL; } @@ -1168,7 +1168,7 @@ void LLGLSLShader::uniform1i(U32 index, GLint x) const auto& iter = mValue.find(mUniform[index]); if (iter == mValue.end() || iter->second.mV[0] != x) { - glUniform1iARB(mUniform[index], x); + glUniform1i(mUniform[index], x); mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); } } @@ -1191,7 +1191,7 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x) const auto& iter = mValue.find(mUniform[index]); if (iter == mValue.end() || iter->second.mV[0] != x) { - glUniform1fARB(mUniform[index], x); + glUniform1f(mUniform[index], x); mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); } } @@ -1214,7 +1214,7 @@ void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) LLVector4 vec(x,y,0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform2fARB(mUniform[index], x, y); + glUniform2f(mUniform[index], x, y); mValue[mUniform[index]] = vec; } } @@ -1237,7 +1237,7 @@ void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) LLVector4 vec(x,y,z,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform3fARB(mUniform[index], x, y, z); + glUniform3f(mUniform[index], x, y, z); mValue[mUniform[index]] = vec; } } @@ -1260,7 +1260,7 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat LLVector4 vec(x,y,z,w); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform4fARB(mUniform[index], x, y, z, w); + glUniform4f(mUniform[index], x, y, z, w); mValue[mUniform[index]] = vec; } } @@ -1283,7 +1283,7 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) LLVector4 vec(v[0],0.f,0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { - glUniform1ivARB(mUniform[index], count, v); + glUniform1iv(mUniform[index], count, v); mValue[mUniform[index]] = vec; } } @@ -1306,7 +1306,7 @@ void LLGLSLShader::uniform4iv(U32 index, U32 count, const GLint* v) LLVector4 vec(v[0], v[1], v[2], v[3]); if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { - glUniform1ivARB(mUniform[index], count, v); + glUniform1iv(mUniform[index], count, v); mValue[mUniform[index]] = vec; } } @@ -1330,7 +1330,7 @@ void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) LLVector4 vec(v[0],0.f,0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { - glUniform1fvARB(mUniform[index], count, v); + glUniform1fv(mUniform[index], count, v); mValue[mUniform[index]] = vec; } } @@ -1353,7 +1353,7 @@ void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) LLVector4 vec(v[0],v[1],0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { - glUniform2fvARB(mUniform[index], count, v); + glUniform2fv(mUniform[index], count, v); mValue[mUniform[index]] = vec; } } @@ -1376,7 +1376,7 @@ void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) LLVector4 vec(v[0],v[1],v[2],0.f); if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { - glUniform3fvARB(mUniform[index], count, v); + glUniform3fv(mUniform[index], count, v); mValue[mUniform[index]] = vec; } } @@ -1400,7 +1400,7 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - glUniform4fvARB(mUniform[index], count, v); + glUniform4fv(mUniform[index], count, v); mValue[mUniform[index]] = vec; } } @@ -1419,7 +1419,7 @@ void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, c if (mUniform[index] >= 0) { - glUniformMatrix2fvARB(mUniform[index], count, transpose, v); + glUniformMatrix2fv(mUniform[index], count, transpose, v); } } } @@ -1436,7 +1436,7 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c if (mUniform[index] >= 0) { - glUniformMatrix3fvARB(mUniform[index], count, transpose, v); + glUniformMatrix3fv(mUniform[index], count, transpose, v); } } } @@ -1472,7 +1472,7 @@ void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, c if (mUniform[index] >= 0) { - glUniformMatrix4fvARB(mUniform[index], count, transpose, v); + glUniformMatrix4fv(mUniform[index], count, transpose, v); } } } @@ -1490,7 +1490,7 @@ GLint LLGLSLShader::getUniformLocation(const LLStaticHashedString& uniform) if (gDebugGL) { stop_glerror(); - if (iter->second != glGetUniformLocationARB(mProgramObject, uniform.String().c_str())) + if (iter->second != glGetUniformLocation(mProgramObject, uniform.String().c_str())) { LL_ERRS() << "Uniform does not match." << LL_ENDL; } @@ -1545,7 +1545,7 @@ void LLGLSLShader::uniform1i(const LLStaticHashedString& uniform, GLint v) LLVector4 vec(v,0.f,0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform1iARB(location, v); + glUniform1i(location, v); mValue[location] = vec; } } @@ -1562,7 +1562,7 @@ void LLGLSLShader::uniform1iv(const LLStaticHashedString& uniform, U32 count, co if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - glUniform1ivARB(location, count, v); + glUniform1iv(location, count, v); mValue[location] = vec; } } @@ -1579,7 +1579,7 @@ void LLGLSLShader::uniform4iv(const LLStaticHashedString& uniform, U32 count, co if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - glUniform4ivARB(location, count, v); + glUniform4iv(location, count, v); mValue[location] = vec; } } @@ -1595,7 +1595,7 @@ void LLGLSLShader::uniform2i(const LLStaticHashedString& uniform, GLint i, GLint LLVector4 vec(i,j,0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform2iARB(location, i, j); + glUniform2i(location, i, j); mValue[location] = vec; } } @@ -1612,7 +1612,7 @@ void LLGLSLShader::uniform1f(const LLStaticHashedString& uniform, GLfloat v) LLVector4 vec(v,0.f,0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform1fARB(location, v); + glUniform1f(location, v); mValue[location] = vec; } } @@ -1628,7 +1628,7 @@ void LLGLSLShader::uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLf LLVector4 vec(x,y,0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform2fARB(location, x,y); + glUniform2f(location, x,y); mValue[location] = vec; } } @@ -1645,7 +1645,7 @@ void LLGLSLShader::uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLf LLVector4 vec(x,y,z,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform3fARB(location, x,y,z); + glUniform3f(location, x,y,z); mValue[location] = vec; } } @@ -1661,7 +1661,7 @@ void LLGLSLShader::uniform1fv(const LLStaticHashedString& uniform, U32 count, co LLVector4 vec(v[0],0.f,0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { - glUniform1fvARB(location, count, v); + glUniform1fv(location, count, v); mValue[location] = vec; } } @@ -1677,7 +1677,7 @@ void LLGLSLShader::uniform2fv(const LLStaticHashedString& uniform, U32 count, co LLVector4 vec(v[0],v[1],0.f,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { - glUniform2fvARB(location, count, v); + glUniform2fv(location, count, v); mValue[location] = vec; } } @@ -1693,7 +1693,7 @@ void LLGLSLShader::uniform3fv(const LLStaticHashedString& uniform, U32 count, co LLVector4 vec(v[0],v[1],v[2],0.f); if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { - glUniform3fvARB(location, count, v); + glUniform3fv(location, count, v); mValue[location] = vec; } } @@ -1710,7 +1710,7 @@ void LLGLSLShader::uniform4fv(const LLStaticHashedString& uniform, U32 count, co if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - glUniform4fvARB(location, count, v); + glUniform4fv(location, count, v); mValue[location] = vec; } } @@ -1723,7 +1723,7 @@ void LLGLSLShader::uniformMatrix4fv(const LLStaticHashedString& uniform, U32 cou if (location >= 0) { stop_glerror(); - glUniformMatrix4fvARB(location, count, transpose, v); + glUniformMatrix4fv(location, count, transpose, v); stop_glerror(); } } @@ -1733,7 +1733,7 @@ void LLGLSLShader::vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GL { if (mAttribute[index] > 0) { - glVertexAttrib4fARB(mAttribute[index], x, y, z, w); + glVertexAttrib4f(mAttribute[index], x, y, z, w); } } @@ -1741,7 +1741,7 @@ void LLGLSLShader::vertexAttrib4fv(U32 index, GLfloat* v) { if (mAttribute[index] > 0) { - glVertexAttrib4fvARB(mAttribute[index], v); + glVertexAttrib4fv(mAttribute[index], v); } } -- cgit v1.2.3 From 88e1740d205bdfaa57d1d5dec4e6e9e755eae075 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 1 Sep 2022 16:18:14 -0700 Subject: SL-17967 - block layout binding acceptable to apple --- indra/llrender/llglslshader.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index db70ba0c60..7be1fd0702 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -965,6 +965,14 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) } //........................................................................................................................................ + if (mFeatures.hasReflectionProbes) // Set up block binding, in a way supported by Apple (rather than binding = 1 in .glsl). + { // See slide 35 and more of https://docs.huihoo.com/apple/wwdc/2011/session_420__advances_in_opengl_for_mac_os_x_lion.pdf + static const GLuint BLOCKBINDING = 1; //picked by us + //Get the index, similar to a uniform location + GLuint UBOBlockIndex = glGetUniformBlockIndex(mProgramObject, "UBO"); + //Set this index to a binding index + glUniformBlockBinding(mProgramObject, UBOBlockIndex, BLOCKBINDING); + } unbind(); LL_DEBUGS("ShaderUniform") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; -- cgit v1.2.3 From 00b1fec9601c3618f12cebce551e4ce2b38d7e00 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 2 Sep 2022 19:53:56 -0500 Subject: SL-17967 Purge OpenGL extensions (use core API only) --- indra/llrender/llglslshader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 7be1fd0702..91d756c0d1 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -969,7 +969,7 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) { // See slide 35 and more of https://docs.huihoo.com/apple/wwdc/2011/session_420__advances_in_opengl_for_mac_os_x_lion.pdf static const GLuint BLOCKBINDING = 1; //picked by us //Get the index, similar to a uniform location - GLuint UBOBlockIndex = glGetUniformBlockIndex(mProgramObject, "UBO"); + GLuint UBOBlockIndex = glGetUniformBlockIndex(mProgramObject, "ReflectionProbes"); //Set this index to a binding index glUniformBlockBinding(mProgramObject, UBOBlockIndex, BLOCKBINDING); } -- cgit v1.2.3 From 60cc58fbfc23efe133dca3797188462d1b2ae5ab Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 2 Sep 2022 21:05:53 -0500 Subject: SL-17967 Fix for confounding program and shader objects when fetching logs and fix for gl errors on AMD windows --- indra/llrender/llglslshader.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 91d756c0d1..bc349c2015 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -348,13 +348,20 @@ void LLGLSLShader::unloadInternal() if (mProgramObject) { GLuint obj[1024]; - GLsizei count; + GLsizei count = 0; glGetAttachedShaders(mProgramObject, 1024, &count, obj); for (GLsizei i = 0; i < count; i++) { glDetachShader(mProgramObject, obj[i]); - glDeleteShader(obj[i]); + } + + for (GLsizei i = 0; i < count; i++) + { + if (glIsShader(obj[i])) + { + glDeleteShader(obj[i]); + } } glDeleteProgram(mProgramObject); -- cgit v1.2.3 From e61b6570b15e5d7843712ea65e11c3df42bf4f81 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 14 Sep 2022 18:53:16 -0500 Subject: SL-17701 Fix for crash on AMD WHQL drivers. --- indra/llrender/llglslshader.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index bc349c2015..7cc5d33c49 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -977,8 +977,11 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) static const GLuint BLOCKBINDING = 1; //picked by us //Get the index, similar to a uniform location GLuint UBOBlockIndex = glGetUniformBlockIndex(mProgramObject, "ReflectionProbes"); - //Set this index to a binding index - glUniformBlockBinding(mProgramObject, UBOBlockIndex, BLOCKBINDING); + if (UBOBlockIndex != GL_INVALID_INDEX) + { + //Set this index to a binding index + glUniformBlockBinding(mProgramObject, UBOBlockIndex, BLOCKBINDING); + } } unbind(); -- cgit v1.2.3 From 718073717c70b1f7e7284a02641c0a0a7bf50367 Mon Sep 17 00:00:00 2001 From: "Howard (Aech Linden) Stearns" Date: Mon, 19 Sep 2022 12:16:49 -0700 Subject: SL-18128, SL-18128 - No glerror on Mac! --- indra/llrender/llglslshader.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 7cc5d33c49..55713eea80 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -227,7 +227,6 @@ void LLGLSLShader::stopProfile(U32 count, U32 mode) void LLGLSLShader::placeProfileQuery() { -#if 1 || !LL_DARWIN if (mTimerQuery == 0) { glGenQueries(1, &mSamplesQuery); @@ -269,12 +268,10 @@ void LLGLSLShader::placeProfileQuery() glBeginQuery(GL_SAMPLES_PASSED, mSamplesQuery); glBeginQuery(GL_TIME_ELAPSED, mTimerQuery); -#endif } void LLGLSLShader::readProfileQuery(U32 count, U32 mode) { -#if !LL_DARWIN glEndQuery(GL_TIME_ELAPSED); glEndQuery(GL_SAMPLES_PASSED); @@ -304,7 +301,6 @@ void LLGLSLShader::readProfileQuery(U32 count, U32 mode) sTotalDrawCalls++; mDrawCalls++; -#endif } @@ -676,7 +672,6 @@ void LLGLSLShader::mapUniform(GLint index, const vector * glGetActiveUniform(mProgramObject, index, 1024, &length, &size, &type, (GLchar *)name); -#if !LL_DARWIN if (size > 0) { switch(type) @@ -718,7 +713,6 @@ void LLGLSLShader::mapUniform(GLint index, const vector * } mTotalUniformSize += size; } -#endif S32 location = glGetUniformLocation(mProgramObject, name); if (location != -1) -- cgit v1.2.3 From be1cdc1aaa67eca71fee8cbbc16b4c85bcbdb258 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 5 Oct 2022 09:48:18 -0700 Subject: Initial pass at adding KHR_debug support This still needs some work - I'm not super satisfied with the overall structure of the code. Will continue to iterate as I add in proper RenderDoc support. --- indra/llrender/llglslshader.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 55713eea80..f424a01541 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -504,6 +504,10 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, unbind(); } +#ifdef LL_PROFILER_ENABLE_TRACY_OPENGL + setLabel(mName); +#endif + return success; } @@ -1786,3 +1790,10 @@ void LLShaderUniforms::apply(LLGLSLShader* shader) shader->uniform3fv(uniform.mUniform, 1, uniform.mValue.mV); } } + +#ifdef LL_PROFILER_ENABLE_TRACY_OPENGL +void LLGLSLShader::setLabel(std::string label) { + LL_LABEL_OBJECT_GL(GL_PROGRAM, mProgramObject, label.length(), label.c_str()); +} + +#endif -- cgit v1.2.3 From db92f9564992b9910b21f3de57a584ccfa199e75 Mon Sep 17 00:00:00 2001 From: Geenz Linden Date: Thu, 6 Oct 2022 15:18:17 -0400 Subject: Switch away from std::string API expects const char* anyways. --- indra/llrender/llglslshader.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index f424a01541..27de7070ff 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -505,7 +505,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, } #ifdef LL_PROFILER_ENABLE_TRACY_OPENGL - setLabel(mName); + setLabel(mName.c_str()); #endif return success; @@ -1792,8 +1792,8 @@ void LLShaderUniforms::apply(LLGLSLShader* shader) } #ifdef LL_PROFILER_ENABLE_TRACY_OPENGL -void LLGLSLShader::setLabel(std::string label) { - LL_LABEL_OBJECT_GL(GL_PROGRAM, mProgramObject, label.length(), label.c_str()); +void LLGLSLShader::setLabel(const char* label) { + LL_LABEL_OBJECT_GL(GL_PROGRAM, mProgramObject, strlen(label), label); } #endif -- cgit v1.2.3 From 97277e74a9d966ed441e51f844f9012f55cca3dc Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Mon, 14 Nov 2022 18:12:22 +0000 Subject: Merged in SL-18332 (pull request #1194) First pass of Screen Space Reflections Approved-by: Dave Parks --- indra/llrender/llglslshader.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 27de7070ff..0a834b28e3 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -84,6 +84,7 @@ LLShaderFeatures::LLShaderFeatures() , hasSrgb(false) , encodesNormal(false) , isDeferred(false) + , hasScreenSpaceReflections(false) , hasIndirect(false) , hasShadows(false) , hasAmbientOcclusion(false) -- cgit v1.2.3 From 8d2ac419b22c8c9475f2efb312dd198ac8eb9fb7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 16 Nov 2022 14:49:17 -0600 Subject: SL-18154 Profile guided optimizations vs release viewer. Trim some unused abilities and remove some more fast timers. --- indra/llrender/llglslshader.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 0a834b28e3..661ea6c4fa 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -505,7 +505,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, unbind(); } -#ifdef LL_PROFILER_ENABLE_TRACY_OPENGL +#ifdef LL_PROFILER_ENABLE_RENDER_DOC setLabel(mName.c_str()); #endif @@ -1792,9 +1792,8 @@ void LLShaderUniforms::apply(LLGLSLShader* shader) } } -#ifdef LL_PROFILER_ENABLE_TRACY_OPENGL +#ifdef LL_PROFILER_ENABLE_RENDER_DOC void LLGLSLShader::setLabel(const char* label) { LL_LABEL_OBJECT_GL(GL_PROGRAM, mProgramObject, strlen(label), label); } - #endif -- cgit v1.2.3 From e2d1af5c4f7bdc04becb4a4fd56b7e9057bdfedc Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 17 Nov 2022 13:35:39 -0600 Subject: SL-18154 Profile guided optimizations -- remove some unneeded operations and make LLDrawPoolMaterials less branchy. --- indra/llrender/llglslshader.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 661ea6c4fa..55b6f5e2a6 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1215,8 +1215,18 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x) } } +void LLGLSLShader::fastUniform1f(U32 index, GLfloat x) +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(mProgramObject); + llassert(mUniform.size() <= index); + llassert(mUniform[index] >= 0); + glUniform1f(mUniform[index], x); +} + void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1240,6 +1250,7 @@ void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1263,6 +1274,7 @@ void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1286,6 +1298,7 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1309,6 +1322,7 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) void LLGLSLShader::uniform4iv(U32 index, U32 count, const GLint* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1333,6 +1347,7 @@ void LLGLSLShader::uniform4iv(U32 index, U32 count, const GLint* v) void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1356,6 +1371,7 @@ void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1379,6 +1395,7 @@ void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1402,6 +1419,7 @@ void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1426,6 +1444,7 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1443,6 +1462,7 @@ void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, c void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1479,6 +1499,7 @@ void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; if (mProgramObject) { if (mUniform.size() <= index) @@ -1554,6 +1575,7 @@ GLint LLGLSLShader::getAttribLocation(U32 attrib) void LLGLSLShader::uniform1i(const LLStaticHashedString& uniform, GLint v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1570,6 +1592,7 @@ void LLGLSLShader::uniform1i(const LLStaticHashedString& uniform, GLint v) void LLGLSLShader::uniform1iv(const LLStaticHashedString& uniform, U32 count, const GLint* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1587,6 +1610,7 @@ void LLGLSLShader::uniform1iv(const LLStaticHashedString& uniform, U32 count, co void LLGLSLShader::uniform4iv(const LLStaticHashedString& uniform, U32 count, const GLint* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1604,6 +1628,7 @@ void LLGLSLShader::uniform4iv(const LLStaticHashedString& uniform, U32 count, co void LLGLSLShader::uniform2i(const LLStaticHashedString& uniform, GLint i, GLint j) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1621,6 +1646,7 @@ void LLGLSLShader::uniform2i(const LLStaticHashedString& uniform, GLint i, GLint void LLGLSLShader::uniform1f(const LLStaticHashedString& uniform, GLfloat v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1637,6 +1663,7 @@ void LLGLSLShader::uniform1f(const LLStaticHashedString& uniform, GLfloat v) void LLGLSLShader::uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1654,6 +1681,7 @@ void LLGLSLShader::uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLf void LLGLSLShader::uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y, GLfloat z) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1670,6 +1698,7 @@ void LLGLSLShader::uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLf void LLGLSLShader::uniform1fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1686,6 +1715,7 @@ void LLGLSLShader::uniform1fv(const LLStaticHashedString& uniform, U32 count, co void LLGLSLShader::uniform2fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1702,6 +1732,7 @@ void LLGLSLShader::uniform2fv(const LLStaticHashedString& uniform, U32 count, co void LLGLSLShader::uniform3fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1718,6 +1749,7 @@ void LLGLSLShader::uniform3fv(const LLStaticHashedString& uniform, U32 count, co void LLGLSLShader::uniform4fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1735,6 +1767,7 @@ void LLGLSLShader::uniform4fv(const LLStaticHashedString& uniform, U32 count, co void LLGLSLShader::uniformMatrix4fv(const LLStaticHashedString& uniform, U32 count, GLboolean transpose, const GLfloat* v) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); if (location >= 0) @@ -1764,6 +1797,7 @@ void LLGLSLShader::vertexAttrib4fv(U32 index, GLfloat* v) void LLGLSLShader::setMinimumAlpha(F32 minimum) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; gGL.flush(); uniform1f(LLShaderMgr::MINIMUM_ALPHA, minimum); } -- cgit v1.2.3 From b1dabc0f008bf0e6558a93bca2a2d818073a03c1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 18 Nov 2022 11:45:04 -0600 Subject: SL-18669 Fix for broken lighting on transparent faces. Optimize handling of "bindDeferredShader" and shadow map setup. --- indra/llrender/llglslshader.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 55b6f5e2a6..d634945632 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1171,7 +1171,8 @@ S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTe void LLGLSLShader::uniform1i(U32 index, GLint x) { - LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); if (mProgramObject) { if (mUniform.size() <= index) @@ -1194,7 +1195,9 @@ void LLGLSLShader::uniform1i(U32 index, GLint x) void LLGLSLShader::uniform1f(U32 index, GLfloat x) { - LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1218,6 +1221,7 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x) void LLGLSLShader::fastUniform1f(U32 index, GLfloat x) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); llassert(mProgramObject); llassert(mUniform.size() <= index); llassert(mUniform[index] >= 0); @@ -1227,6 +1231,8 @@ void LLGLSLShader::fastUniform1f(U32 index, GLfloat x) void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1251,6 +1257,8 @@ void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1275,6 +1283,8 @@ void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1299,6 +1309,8 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1323,6 +1335,8 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) void LLGLSLShader::uniform4iv(U32 index, U32 count, const GLint* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1348,6 +1362,8 @@ void LLGLSLShader::uniform4iv(U32 index, U32 count, const GLint* v) void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1372,6 +1388,8 @@ void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1396,6 +1414,8 @@ void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1420,6 +1440,8 @@ void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1445,6 +1467,8 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1463,6 +1487,8 @@ void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, c void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) @@ -1481,6 +1507,7 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); if (mProgramObject) { @@ -1500,6 +1527,8 @@ void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(sCurBoundShaderPtr == this); + if (mProgramObject) { if (mUniform.size() <= index) -- cgit v1.2.3 From 493d501cde13abf1ac4164cd77286f068da3a62c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 10 Jan 2023 19:49:18 -0600 Subject: SL-18869 Optimizations -- Revive "Frame Profile" and GL_DEPTH_CLAMP. Remove usage of gl_FragDepth from shadow shaders. --- indra/llrender/llglslshader.cpp | 753 +++++++++++++++++++--------------------- 1 file changed, 363 insertions(+), 390 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index e3b29dc812..b5da3d08e2 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llglslshader.cpp * @brief GLSL helper functions and state. * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2010, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -37,8 +37,8 @@ #include "OpenGL/OpenGL.h" #endif -// Print-print list of shader included source files that are linked together via glAttachShader() -// i.e. On macOS / OSX the AMD GLSL linker will display an error if a varying is left in an undefined state. + // Print-print list of shader included source files that are linked together via glAttachShader() + // i.e. On macOS / OSX the AMD GLSL linker will display an error if a varying is left in an undefined state. #define DEBUG_SHADER_INCLUDES 0 // Lots of STL stuff in here, using namespace std to keep things more readable @@ -55,24 +55,24 @@ std::set LLGLSLShader::sInstances; U64 LLGLSLShader::sTotalTimeElapsed = 0; U32 LLGLSLShader::sTotalTrianglesDrawn = 0; U64 LLGLSLShader::sTotalSamplesDrawn = 0; -U32 LLGLSLShader::sTotalDrawCalls = 0; +U32 LLGLSLShader::sTotalBinds = 0; //UI shader -- declared here so llui_libtest will link properly LLGLSLShader gUIProgram; LLGLSLShader gSolidColorProgram; // NOTE: Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! -const std::string gShaderConstsKey[ LLGLSLShader::NUM_SHADER_CONSTS ] = +const std::string gShaderConstsKey[LLGLSLShader::NUM_SHADER_CONSTS] = { - "LL_SHADER_CONST_CLOUD_MOON_DEPTH" - , "LL_SHADER_CONST_STAR_DEPTH" + "LL_SHADER_CONST_CLOUD_MOON_DEPTH" + , "LL_SHADER_CONST_STAR_DEPTH" }; // NOTE: Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! -const std::string gShaderConstsVal[ LLGLSLShader::NUM_SHADER_CONSTS ] = +const std::string gShaderConstsVal[LLGLSLShader::NUM_SHADER_CONSTS] = { - "0.99998" // SHADER_CONST_CLOUD_MOON_DEPTH // SL-14113 - , "0.99999" // SHADER_CONST_STAR_DEPTH // SL-14113 + "0.99998" // SHADER_CONST_CLOUD_MOON_DEPTH // SL-14113 + , "0.99999" // SHADER_CONST_STAR_DEPTH // SL-14113 }; @@ -121,7 +121,7 @@ void LLGLSLShader::initProfile() sTotalTimeElapsed = 0; sTotalTrianglesDrawn = 0; sTotalSamplesDrawn = 0; - sTotalDrawCalls = 0; + sTotalBinds = 0; for (std::set::iterator iter = sInstances.begin(); iter != sInstances.end(); ++iter) { @@ -132,10 +132,10 @@ void LLGLSLShader::initProfile() struct LLGLSLShaderCompareTimeElapsed { - bool operator()(const LLGLSLShader* const& lhs, const LLGLSLShader* const& rhs) - { - return lhs->mTimeElapsed < rhs->mTimeElapsed; - } + bool operator()(const LLGLSLShader* const& lhs, const LLGLSLShader* const& rhs) + { + return lhs->mTimeElapsed < rhs->mTimeElapsed; + } }; //static @@ -158,11 +158,11 @@ void LLGLSLShader::finishProfile(bool emit_report) { (*iter)->dumpStats(); } - - LL_INFOS() << "-----------------------------------" << LL_ENDL; - LL_INFOS() << "Total rendering time: " << llformat("%.4f ms", sTotalTimeElapsed/1000000.f) << LL_ENDL; - LL_INFOS() << "Total samples drawn: " << llformat("%.4f million", sTotalSamplesDrawn/1000000.f) << LL_ENDL; - LL_INFOS() << "Total triangles drawn: " << llformat("%.3f million", sTotalTrianglesDrawn/1000000.f) << LL_ENDL; + + LL_INFOS() << "-----------------------------------" << LL_ENDL; + LL_INFOS() << "Total rendering time: " << llformat("%.4f ms", sTotalTimeElapsed / 1000000.f) << LL_ENDL; + LL_INFOS() << "Total samples drawn: " << llformat("%.4f million", sTotalSamplesDrawn / 1000000.f) << LL_ENDL; + LL_INFOS() << "Total triangles drawn: " << llformat("%.3f million", sTotalTrianglesDrawn / 1000000.f) << LL_ENDL; } } @@ -171,15 +171,12 @@ void LLGLSLShader::clearStats() mTrianglesDrawn = 0; mTimeElapsed = 0; mSamplesDrawn = 0; - mDrawCalls = 0; - mTextureStateFetched = false; - mTextureMagFilter.clear(); - mTextureMinFilter.clear(); + mBinds = 0; } void LLGLSLShader::dumpStats() { - if (mDrawCalls > 0) + if (mBinds > 0) { LL_INFOS() << "=============================================" << LL_ENDL; LL_INFOS() << mName << LL_ENDL; @@ -187,36 +184,25 @@ void LLGLSLShader::dumpStats() { LL_INFOS() << mShaderFiles[i].first << LL_ENDL; } - for (U32 i = 0; i < mTexture.size(); ++i) - { - GLint idx = mTexture[i]; - - if (idx >= 0) - { - GLint uniform_idx = getUniformLocation(i); - LL_INFOS() << mUniformNameMap[uniform_idx] << " - " << std::hex << mTextureMagFilter[i] << "/" << mTextureMinFilter[i] << std::dec << LL_ENDL; - } - } LL_INFOS() << "=============================================" << LL_ENDL; - - F32 ms = mTimeElapsed/1000000.f; - F32 seconds = ms/1000.f; - F32 pct_tris = (F32) mTrianglesDrawn/(F32)sTotalTrianglesDrawn*100.f; - F32 tris_sec = (F32) (mTrianglesDrawn/1000000.0); + F32 ms = mTimeElapsed / 1000000.f; + F32 seconds = ms / 1000.f; + + F32 pct_tris = (F32)mTrianglesDrawn / (F32)sTotalTrianglesDrawn * 100.f; + F32 tris_sec = (F32)(mTrianglesDrawn / 1000000.0); tris_sec /= seconds; - F32 pct_samples = (F32) ((F64)mSamplesDrawn/(F64)sTotalSamplesDrawn)*100.f; - F32 samples_sec = (F32) mSamplesDrawn/1000000000.0; + F32 pct_samples = (F32)((F64)mSamplesDrawn / (F64)sTotalSamplesDrawn) * 100.f; + F32 samples_sec = (F32)mSamplesDrawn / 1000000000.0; samples_sec /= seconds; - F32 pct_calls = (F32) mDrawCalls/(F32)sTotalDrawCalls*100.f; - U32 avg_batch = mTrianglesDrawn/mDrawCalls; + F32 pct_binds = (F32)mBinds / (F32)sTotalBinds * 100.f; - LL_INFOS() << "Triangles Drawn: " << mTrianglesDrawn << " " << llformat("(%.2f pct of total, %.3f million/sec)", pct_tris, tris_sec ) << LL_ENDL; - LL_INFOS() << "Draw Calls: " << mDrawCalls << " " << llformat("(%.2f pct of total, avg %d tris/call)", pct_calls, avg_batch) << LL_ENDL; + LL_INFOS() << "Triangles Drawn: " << mTrianglesDrawn << " " << llformat("(%.2f pct of total, %.3f million/sec)", pct_tris, tris_sec) << LL_ENDL; + LL_INFOS() << "Binds: " << mBinds << " " << llformat("(%.2f pct of total)", pct_binds) << LL_ENDL; LL_INFOS() << "SamplesDrawn: " << mSamplesDrawn << " " << llformat("(%.2f pct of total, %.3f billion/sec)", pct_samples, samples_sec) << LL_ENDL; - LL_INFOS() << "Time Elapsed: " << mTimeElapsed << " " << llformat("(%.2f pct of total, %.5f ms)\n", (F32) ((F64)mTimeElapsed/(F64)sTotalTimeElapsed)*100.f, ms) << LL_ENDL; + LL_INFOS() << "Time Elapsed: " << mTimeElapsed << " " << llformat("(%.2f pct of total, %.5f ms)\n", (F32)((F64)mTimeElapsed / (F64)sTotalTimeElapsed) * 100.f, ms) << LL_ENDL; } } @@ -232,108 +218,80 @@ void LLGLSLShader::startProfile() } //static -void LLGLSLShader::stopProfile(U32 count, U32 mode) +void LLGLSLShader::stopProfile() { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + if (sProfileEnabled && sCurBoundShaderPtr) { - sCurBoundShaderPtr->readProfileQuery(count, mode); + sCurBoundShaderPtr->unbind(); } } void LLGLSLShader::placeProfileQuery() { - if (mTimerQuery == 0) + if (sProfileEnabled) { - glGenQueries(1, &mSamplesQuery); - glGenQueries(1, &mTimerQuery); - } - - if (!mTextureStateFetched) - { - mTextureStateFetched = true; - mTextureMagFilter.resize(mTexture.size()); - mTextureMinFilter.resize(mTexture.size()); - - U32 cur_active = gGL.getCurrentTexUnitIndex(); - - for (U32 i = 0; i < mTexture.size(); ++i) + if (mTimerQuery == 0) { - GLint idx = mTexture[i]; - - if (idx >= 0) - { - gGL.getTexUnit(idx)->activate(); - - U32 mag = 0xFFFFFFFF; - U32 min = 0xFFFFFFFF; - - U32 type = LLTexUnit::getInternalType(gGL.getTexUnit(idx)->getCurrType()); - - glGetTexParameteriv(type, GL_TEXTURE_MAG_FILTER, (GLint*) &mag); - glGetTexParameteriv(type, GL_TEXTURE_MIN_FILTER, (GLint*) &min); - - mTextureMagFilter[i] = mag; - mTextureMinFilter[i] = min; - } + glGenQueries(1, &mSamplesQuery); + glGenQueries(1, &mTimerQuery); + glGenQueries(1, &mPrimitivesQuery); } - gGL.getTexUnit(cur_active)->activate(); + glBeginQuery(GL_SAMPLES_PASSED, mSamplesQuery); + glBeginQuery(GL_TIME_ELAPSED, mTimerQuery); + glBeginQuery(GL_PRIMITIVES_GENERATED, mPrimitivesQuery); } - - - glBeginQuery(GL_SAMPLES_PASSED, mSamplesQuery); - glBeginQuery(GL_TIME_ELAPSED, mTimerQuery); } -void LLGLSLShader::readProfileQuery(U32 count, U32 mode) +void LLGLSLShader::readProfileQuery() { - glEndQuery(GL_TIME_ELAPSED); - glEndQuery(GL_SAMPLES_PASSED); - - U64 time_elapsed = 0; - glGetQueryObjectui64v(mTimerQuery, GL_QUERY_RESULT, &time_elapsed); + if (sProfileEnabled) + { + glEndQuery(GL_TIME_ELAPSED); + glEndQuery(GL_SAMPLES_PASSED); + glEndQuery(GL_PRIMITIVES_GENERATED); - U64 samples_passed = 0; - glGetQueryObjectui64v(mSamplesQuery, GL_QUERY_RESULT, &samples_passed); + U64 time_elapsed = 0; + glGetQueryObjectui64v(mTimerQuery, GL_QUERY_RESULT, &time_elapsed); - sTotalTimeElapsed += time_elapsed; - mTimeElapsed += time_elapsed; + U64 samples_passed = 0; + glGetQueryObjectui64v(mSamplesQuery, GL_QUERY_RESULT, &samples_passed); - sTotalSamplesDrawn += samples_passed; - mSamplesDrawn += samples_passed; + U64 primitives_generated = 0; + glGetQueryObjectui64v(mPrimitivesQuery, GL_QUERY_RESULT, &primitives_generated); + sTotalTimeElapsed += time_elapsed; + mTimeElapsed += time_elapsed; - U32 tri_count = 0; - switch (mode) - { - case LLRender::TRIANGLES: tri_count = count/3; break; - case LLRender::TRIANGLE_FAN: tri_count = count-2; break; - case LLRender::TRIANGLE_STRIP: tri_count = count-2; break; - default: tri_count = count; break; //points lines etc just use primitive count - } + sTotalSamplesDrawn += samples_passed; + mSamplesDrawn += samples_passed; + + U32 tri_count = (U32)primitives_generated / 3; - mTrianglesDrawn += tri_count; - sTotalTrianglesDrawn += tri_count; + mTrianglesDrawn += tri_count; + sTotalTrianglesDrawn += tri_count; - sTotalDrawCalls++; - mDrawCalls++; + sTotalBinds++; + mBinds++; + } } LLGLSLShader::LLGLSLShader() - : mProgramObject(0), - mAttributeMask(0), - mTotalUniformSize(0), - mActiveTextureChannels(0), - mShaderLevel(0), - mShaderGroup(SG_DEFAULT), - mUniformsDirty(FALSE), - mTimerQuery(0), - mSamplesQuery(0) - + : mProgramObject(0), + mAttributeMask(0), + mTotalUniformSize(0), + mActiveTextureChannels(0), + mShaderLevel(0), + mShaderGroup(SG_DEFAULT), + mUniformsDirty(FALSE), + mTimerQuery(0), + mSamplesQuery(0), + mPrimitivesQuery(0) { - + } LLGLSLShader::~LLGLSLShader() @@ -399,10 +357,10 @@ void LLGLSLShader::unloadInternal() stop_glerror(); } -BOOL LLGLSLShader::createShader(std::vector * attributes, - std::vector * uniforms, - U32 varying_count, - const char** varyings) +BOOL LLGLSLShader::createShader(std::vector* attributes, + std::vector* uniforms, + U32 varying_count, + const char** varyings) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; @@ -430,19 +388,19 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, } BOOL success = TRUE; - + #if LL_DARWIN // work-around missing mix(vec3,vec3,bvec3) mDefines["OLD_SELECT"] = "1"; #endif - + #if DEBUG_SHADER_INCLUDES fprintf(stderr, "--- %s ---\n", mName.c_str()); #endif // DEBUG_SHADER_INCLUDES //compile new source - vector< pair >::iterator fileIter = mShaderFiles.begin(); - for ( ; fileIter != mShaderFiles.end(); fileIter++ ) + vector< pair >::iterator fileIter = mShaderFiles.begin(); + for (; fileIter != mShaderFiles.end(); fileIter++) { GLuint shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels); LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL; @@ -471,7 +429,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, #ifdef GL_INTERLEAVED_ATTRIBS if (varying_count > 0 && varyings) { - glTransformFeedbackVaryings((GLuint64) mProgramObject, varying_count, varyings, GL_INTERLEAVED_ATTRIBS); + glTransformFeedbackVaryings((GLuint64)mProgramObject, varying_count, varyings, GL_INTERLEAVED_ATTRIBS); } #endif @@ -484,7 +442,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, { success = mapUniforms(uniforms); } - if( !success ) + if (!success) { LL_SHADER_LOADING_WARNS() << "Failed to link shader: " << mName << LL_ENDL; @@ -493,7 +451,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, { LL_SHADER_LOADING_WARNS() << "Failed to link using shader level " << mShaderLevel << " trying again using shader level " << (mShaderLevel - 1) << LL_ENDL; mShaderLevel--; - return createShader(attributes,uniforms); + return createShader(attributes, uniforms); } } else if (mFeatures.mIndexedTextureChannels > 0) @@ -528,22 +486,22 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, } #if DEBUG_SHADER_INCLUDES -void dumpAttachObject( const char *func_name, GLuint program_object, const std::string &object_path ) +void dumpAttachObject(const char* func_name, GLuint program_object, const std::string& object_path) { GLchar* info_log; GLint info_len_expect = 0; GLint info_len_actual = 0; - glGetShaderiv(program_object, GL_INFO_LOG_LENGTH,, &info_len_expect); + glGetShaderiv(program_object, GL_INFO_LOG_LENGTH, , &info_len_expect); fprintf(stderr, " * %-20s(), log size: %d, %s\n", func_name, info_len_expect, object_path.c_str()); if (info_len_expect > 0) { fprintf(stderr, " ========== %s() ========== \n", func_name); - info_log = new GLchar [ info_len_expect ]; - glGetProgramInfoLog(program_object, info_len_expect, &info_len_actual, info_log); - fprintf(stderr, "%s\n", info_log); - delete [] info_log; + info_log = new GLchar[info_len_expect]; + glGetProgramInfoLog(program_object, info_len_expect, &info_len_actual, info_log); + fprintf(stderr, "%s\n", info_log); + delete[] info_log; } } #endif // DEBUG_SHADER_INCLUDES @@ -612,7 +570,7 @@ void LLGLSLShader::attachObjects(GLuint* objects, S32 count) } } -BOOL LLGLSLShader::mapAttributes(const std::vector * attributes) +BOOL LLGLSLShader::mapAttributes(const std::vector* attributes) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; @@ -620,9 +578,9 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++) { const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str(); - glBindAttribLocation(mProgramObject, i, (const GLchar *) name); + glBindAttribLocation(mProgramObject, i, (const GLchar*)name); } - + //link the program BOOL res = link(); @@ -633,7 +591,7 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri #else mAttribute.resize(LLShaderMgr::instance()->mReservedAttribs.size() + numAttributes, -1); #endif - + if (res) { //read back channel locations @@ -643,7 +601,7 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++) { const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str(); - S32 index = glGetAttribLocation(mProgramObject, (const GLchar *)name); + S32 index = glGetAttribLocation(mProgramObject, (const GLchar*)name); if (index != -1) { #if LL_RELEASE_WITH_DEBUG_INFO @@ -671,11 +629,11 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri return TRUE; } - + return FALSE; } -void LLGLSLShader::mapUniform(GLint index, const vector * uniforms) +void LLGLSLShader::mapUniform(GLint index, const vector* uniforms) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; @@ -691,45 +649,45 @@ void LLGLSLShader::mapUniform(GLint index, const vector * name[0] = 0; - glGetActiveUniform(mProgramObject, index, 1024, &length, &size, &type, (GLchar *)name); + glGetActiveUniform(mProgramObject, index, 1024, &length, &size, &type, (GLchar*)name); if (size > 0) { - switch(type) - { - case GL_FLOAT_VEC2: size *= 2; break; - case GL_FLOAT_VEC3: size *= 3; break; - case GL_FLOAT_VEC4: size *= 4; break; - case GL_DOUBLE: size *= 2; break; - case GL_DOUBLE_VEC2: size *= 2; break; - case GL_DOUBLE_VEC3: size *= 6; break; - case GL_DOUBLE_VEC4: size *= 8; break; - case GL_INT_VEC2: size *= 2; break; - case GL_INT_VEC3: size *= 3; break; - case GL_INT_VEC4: size *= 4; break; - case GL_UNSIGNED_INT_VEC2: size *= 2; break; - case GL_UNSIGNED_INT_VEC3: size *= 3; break; - case GL_UNSIGNED_INT_VEC4: size *= 4; break; - case GL_BOOL_VEC2: size *= 2; break; - case GL_BOOL_VEC3: size *= 3; break; - case GL_BOOL_VEC4: size *= 4; break; - case GL_FLOAT_MAT2: size *= 4; break; - case GL_FLOAT_MAT3: size *= 9; break; - case GL_FLOAT_MAT4: size *= 16; break; - case GL_FLOAT_MAT2x3: size *= 6; break; - case GL_FLOAT_MAT2x4: size *= 8; break; - case GL_FLOAT_MAT3x2: size *= 6; break; - case GL_FLOAT_MAT3x4: size *= 12; break; - case GL_FLOAT_MAT4x2: size *= 8; break; - case GL_FLOAT_MAT4x3: size *= 12; break; - case GL_DOUBLE_MAT2: size *= 8; break; - case GL_DOUBLE_MAT3: size *= 18; break; - case GL_DOUBLE_MAT4: size *= 32; break; - case GL_DOUBLE_MAT2x3: size *= 12; break; - case GL_DOUBLE_MAT2x4: size *= 16; break; - case GL_DOUBLE_MAT3x2: size *= 12; break; - case GL_DOUBLE_MAT3x4: size *= 24; break; - case GL_DOUBLE_MAT4x2: size *= 16; break; - case GL_DOUBLE_MAT4x3: size *= 24; break; + switch (type) + { + case GL_FLOAT_VEC2: size *= 2; break; + case GL_FLOAT_VEC3: size *= 3; break; + case GL_FLOAT_VEC4: size *= 4; break; + case GL_DOUBLE: size *= 2; break; + case GL_DOUBLE_VEC2: size *= 2; break; + case GL_DOUBLE_VEC3: size *= 6; break; + case GL_DOUBLE_VEC4: size *= 8; break; + case GL_INT_VEC2: size *= 2; break; + case GL_INT_VEC3: size *= 3; break; + case GL_INT_VEC4: size *= 4; break; + case GL_UNSIGNED_INT_VEC2: size *= 2; break; + case GL_UNSIGNED_INT_VEC3: size *= 3; break; + case GL_UNSIGNED_INT_VEC4: size *= 4; break; + case GL_BOOL_VEC2: size *= 2; break; + case GL_BOOL_VEC3: size *= 3; break; + case GL_BOOL_VEC4: size *= 4; break; + case GL_FLOAT_MAT2: size *= 4; break; + case GL_FLOAT_MAT3: size *= 9; break; + case GL_FLOAT_MAT4: size *= 16; break; + case GL_FLOAT_MAT2x3: size *= 6; break; + case GL_FLOAT_MAT2x4: size *= 8; break; + case GL_FLOAT_MAT3x2: size *= 6; break; + case GL_FLOAT_MAT3x4: size *= 12; break; + case GL_FLOAT_MAT4x2: size *= 8; break; + case GL_FLOAT_MAT4x3: size *= 12; break; + case GL_DOUBLE_MAT2: size *= 8; break; + case GL_DOUBLE_MAT3: size *= 18; break; + case GL_DOUBLE_MAT4: size *= 32; break; + case GL_DOUBLE_MAT2x3: size *= 12; break; + case GL_DOUBLE_MAT2x4: size *= 16; break; + case GL_DOUBLE_MAT3x2: size *= 12; break; + case GL_DOUBLE_MAT3x4: size *= 24; break; + case GL_DOUBLE_MAT4x2: size *= 16; break; + case GL_DOUBLE_MAT4x3: size *= 24; break; } mTotalUniformSize += size; } @@ -750,11 +708,11 @@ void LLGLSLShader::mapUniform(GLint index, const vector * mUniformMap[hashedName] = location; LL_DEBUGS("ShaderUniform") << "Uniform " << name << " is at location " << location << LL_ENDL; - + //find the index of this uniform - for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++) + for (S32 i = 0; i < (S32)LLShaderMgr::instance()->mReservedUniforms.size(); i++) { - if ( (mUniform[i] == -1) + if ((mUniform[i] == -1) && (LLShaderMgr::instance()->mReservedUniforms[i] == name)) { //found it @@ -768,12 +726,12 @@ void LLGLSLShader::mapUniform(GLint index, const vector * { for (U32 i = 0; i < uniforms->size(); i++) { - if ( (mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] == -1) + if ((mUniform[i + LLShaderMgr::instance()->mReservedUniforms.size()] == -1) && ((*uniforms)[i].String() == name)) { //found it - mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location; - mTexture[i+LLShaderMgr::instance()->mReservedUniforms.size()] = mapUniformTextureChannel(location, type, size); + mUniform[i + LLShaderMgr::instance()->mReservedUniforms.size()] = location; + mTexture[i + LLShaderMgr::instance()->mReservedUniforms.size()] = mapUniformTextureChannel(location, type, size); return; } } @@ -791,9 +749,9 @@ void LLGLSLShader::addPermutation(std::string name, std::string value) mDefines[name] = value; } -void LLGLSLShader::addConstant( const LLGLSLShader::eShaderConsts shader_const ) +void LLGLSLShader::addConstant(const LLGLSLShader::eShaderConsts shader_const) { - addPermutation( gShaderConstsKey[ shader_const ], gShaderConstsVal[ shader_const ] ); + addPermutation(gShaderConstsKey[shader_const], gShaderConstsVal[shader_const]); } void LLGLSLShader::removePermutation(std::string name) @@ -805,7 +763,7 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type, GLint { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - if ((type >= GL_SAMPLER_1D && type <= GL_SAMPLER_2D_RECT_SHADOW) || + if ((type >= GL_SAMPLER_1D && type <= GL_SAMPLER_2D_RECT_SHADOW) || type == GL_SAMPLER_2D_MULTISAMPLE || type == GL_SAMPLER_CUBE_MAP_ARRAY) { //this here is a texture @@ -827,8 +785,8 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type, GLint channel[i] = mActiveTextureChannels++; } glUniform1iv(location, size, channel); - LL_DEBUGS("ShaderUniform") << "Assigned to texture channel " << - (mActiveTextureChannels-size) << " through " << (mActiveTextureChannels-1) << LL_ENDL; + LL_DEBUGS("ShaderUniform") << "Assigned to texture channel " << + (mActiveTextureChannels - size) << " through " << (mActiveTextureChannels - 1) << LL_ENDL; } llassert(mActiveTextureChannels <= 32); // too many textures (probably) @@ -837,102 +795,102 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type, GLint return -1; } -BOOL LLGLSLShader::mapUniforms(const vector * uniforms) +BOOL LLGLSLShader::mapUniforms(const vector* uniforms) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; BOOL res = TRUE; - mTotalUniformSize = 0; - mActiveTextureChannels = 0; - mUniform.clear(); - mUniformMap.clear(); - mUniformNameMap.clear(); - mTexture.clear(); - mValue.clear(); - //initialize arrays - U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); - mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); - mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); - - bind(); - - //get the number of active uniforms - GLint activeCount; + mTotalUniformSize = 0; + mActiveTextureChannels = 0; + mUniform.clear(); + mUniformMap.clear(); + mUniformNameMap.clear(); + mTexture.clear(); + mValue.clear(); + //initialize arrays + U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); + mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); + mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); + + bind(); + + //get the number of active uniforms + GLint activeCount; glGetProgramiv(mProgramObject, GL_ACTIVE_UNIFORMS, &activeCount); - //........................................................................................................................................ - //........................................................................................ + //........................................................................................................................................ + //........................................................................................ - /* - EXPLANATION: - This is part of code is temporary because as the final result the mapUniform() should be rewrited. - But it's a huge a volume of work which is need to be a more carefully performed for avoid possible - regression's (i.e. it should be formalized a separate ticket in JIRA). + /* + EXPLANATION: + This is part of code is temporary because as the final result the mapUniform() should be rewrited. + But it's a huge a volume of work which is need to be a more carefully performed for avoid possible + regression's (i.e. it should be formalized a separate ticket in JIRA). - RESON: - The reason of this code is that SL engine is very sensitive to fact that "diffuseMap" should be appear - first as uniform parameter which is should get 0-"texture channel" index (see mapUniformTextureChannel() and mActiveTextureChannels) - it influence to which is texture matrix will be updated during rendering. + RESON: + The reason of this code is that SL engine is very sensitive to fact that "diffuseMap" should be appear + first as uniform parameter which is should get 0-"texture channel" index (see mapUniformTextureChannel() and mActiveTextureChannels) + it influence to which is texture matrix will be updated during rendering. - But, order of indexe's of uniform variables is not defined and GLSL compiler can change it as want - , even if the "diffuseMap" will be appear and use first in shader code. + But, order of indexe's of uniform variables is not defined and GLSL compiler can change it as want + , even if the "diffuseMap" will be appear and use first in shader code. - As example where this situation appear see: "Deferred Material Shader 28/29/30/31" - And tickets: MAINT-4165, MAINT-4839, MAINT-3568, MAINT-6437 + As example where this situation appear see: "Deferred Material Shader 28/29/30/31" + And tickets: MAINT-4165, MAINT-4839, MAINT-3568, MAINT-6437 --- davep TODO -- pretty sure the entire block here is superstitious and that the uniform index has nothing to do with the texture channel texture channel should follow the uniform VALUE - */ + */ - S32 diffuseMap = glGetUniformLocation(mProgramObject, "diffuseMap"); - S32 specularMap = glGetUniformLocation(mProgramObject, "specularMap"); - S32 bumpMap = glGetUniformLocation(mProgramObject, "bumpMap"); + S32 diffuseMap = glGetUniformLocation(mProgramObject, "diffuseMap"); + S32 specularMap = glGetUniformLocation(mProgramObject, "specularMap"); + S32 bumpMap = glGetUniformLocation(mProgramObject, "bumpMap"); S32 altDiffuseMap = glGetUniformLocation(mProgramObject, "altDiffuseMap"); - S32 environmentMap = glGetUniformLocation(mProgramObject, "environmentMap"); + S32 environmentMap = glGetUniformLocation(mProgramObject, "environmentMap"); S32 reflectionMap = glGetUniformLocation(mProgramObject, "reflectionMap"); - std::set skip_index; + std::set skip_index; - if (-1 != diffuseMap && (-1 != specularMap || -1 != bumpMap || -1 != environmentMap || -1 != altDiffuseMap)) - { - GLenum type; - GLsizei length; - GLint size = -1; - char name[1024]; + if (-1 != diffuseMap && (-1 != specularMap || -1 != bumpMap || -1 != environmentMap || -1 != altDiffuseMap)) + { + GLenum type; + GLsizei length; + GLint size = -1; + char name[1024]; - diffuseMap = altDiffuseMap = specularMap = bumpMap = environmentMap = -1; + diffuseMap = altDiffuseMap = specularMap = bumpMap = environmentMap = -1; - for (S32 i = 0; i < activeCount; i++) - { - name[0] = '\0'; + for (S32 i = 0; i < activeCount; i++) + { + name[0] = '\0'; - glGetActiveUniform(mProgramObject, i, 1024, &length, &size, &type, (GLchar *)name); + glGetActiveUniform(mProgramObject, i, 1024, &length, &size, &type, (GLchar*)name); - if (-1 == diffuseMap && std::string(name) == "diffuseMap") - { - diffuseMap = i; - continue; - } + if (-1 == diffuseMap && std::string(name) == "diffuseMap") + { + diffuseMap = i; + continue; + } - if (-1 == specularMap && std::string(name) == "specularMap") - { - specularMap = i; - continue; - } + if (-1 == specularMap && std::string(name) == "specularMap") + { + specularMap = i; + continue; + } - if (-1 == bumpMap && std::string(name) == "bumpMap") - { - bumpMap = i; - continue; - } + if (-1 == bumpMap && std::string(name) == "bumpMap") + { + bumpMap = i; + continue; + } - if (-1 == environmentMap && std::string(name) == "environmentMap") - { - environmentMap = i; - continue; - } + if (-1 == environmentMap && std::string(name) == "environmentMap") + { + environmentMap = i; + continue; + } if (-1 == reflectionMap && std::string(name) == "reflectionMap") { @@ -941,55 +899,55 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) } if (-1 == altDiffuseMap && std::string(name) == "altDiffuseMap") - { - altDiffuseMap = i; - continue; - } - } - - bool specularDiff = specularMap < diffuseMap && -1 != specularMap; - bool bumpLessDiff = bumpMap < diffuseMap && -1 != bumpMap; - bool envLessDiff = environmentMap < diffuseMap && -1 != environmentMap; + { + altDiffuseMap = i; + continue; + } + } + + bool specularDiff = specularMap < diffuseMap && -1 != specularMap; + bool bumpLessDiff = bumpMap < diffuseMap && -1 != bumpMap; + bool envLessDiff = environmentMap < diffuseMap && -1 != environmentMap; bool refLessDiff = reflectionMap < diffuseMap && -1 != reflectionMap; - if (specularDiff || bumpLessDiff || envLessDiff || refLessDiff) - { - mapUniform(diffuseMap, uniforms); - skip_index.insert(diffuseMap); + if (specularDiff || bumpLessDiff || envLessDiff || refLessDiff) + { + mapUniform(diffuseMap, uniforms); + skip_index.insert(diffuseMap); - if (-1 != specularMap) { - mapUniform(specularMap, uniforms); - skip_index.insert(specularMap); - } + if (-1 != specularMap) { + mapUniform(specularMap, uniforms); + skip_index.insert(specularMap); + } - if (-1 != bumpMap) { - mapUniform(bumpMap, uniforms); - skip_index.insert(bumpMap); - } + if (-1 != bumpMap) { + mapUniform(bumpMap, uniforms); + skip_index.insert(bumpMap); + } - if (-1 != environmentMap) { - mapUniform(environmentMap, uniforms); - skip_index.insert(environmentMap); - } + if (-1 != environmentMap) { + mapUniform(environmentMap, uniforms); + skip_index.insert(environmentMap); + } if (-1 != reflectionMap) { mapUniform(reflectionMap, uniforms); skip_index.insert(reflectionMap); } - } - } + } + } - //........................................................................................ + //........................................................................................ - for (S32 i = 0; i < activeCount; i++) - { - //........................................................................................ - if (skip_index.end() != skip_index.find(i)) continue; - //........................................................................................ + for (S32 i = 0; i < activeCount; i++) + { + //........................................................................................ + if (skip_index.end() != skip_index.find(i)) continue; + //........................................................................................ - mapUniform(i, uniforms); - } - //........................................................................................................................................ + mapUniform(i, uniforms); + } + //........................................................................................................................................ if (mFeatures.hasReflectionProbes) // Set up block binding, in a way supported by Apple (rather than binding = 1 in .glsl). { // See slide 35 and more of https://docs.huihoo.com/apple/wwdc/2011/session_420__advances_in_opengl_for_mac_os_x_lion.pdf @@ -1002,10 +960,10 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) glUniformBlockBinding(mProgramObject, UBOBlockIndex, BLOCKBINDING); } } - unbind(); + unbind(); - LL_DEBUGS("ShaderUniform") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; - return res; + LL_DEBUGS("ShaderUniform") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; + return res; } @@ -1031,10 +989,16 @@ void LLGLSLShader::bind() if (sCurBoundShader != mProgramObject) // Don't re-bind current shader { + if (sCurBoundShaderPtr) + { + sCurBoundShaderPtr->readProfileQuery(); + } LLVertexBuffer::unbind(); glUseProgram(mProgramObject); sCurBoundShader = mProgramObject; sCurBoundShaderPtr = this; + placeProfileQuery(); + LLVertexBuffer::setupClientArrays(mAttributeMask); } if (mUniformsDirty) @@ -1060,8 +1024,11 @@ void LLGLSLShader::bind(bool rigged) void LLGLSLShader::unbind() { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - gGL.flush(); + if (sCurBoundShaderPtr) + { + sCurBoundShaderPtr->readProfileQuery(); + } stop_glerror(); LLVertexBuffer::unbind(); glUseProgram(0); @@ -1075,22 +1042,28 @@ void LLGLSLShader::bindNoShader(void) LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; LLVertexBuffer::unbind(); + + if (sCurBoundShaderPtr) + { + sCurBoundShaderPtr->readProfileQuery(); + } + glUseProgram(0); sCurBoundShader = 0; sCurBoundShaderPtr = NULL; } -S32 LLGLSLShader::bindTexture(const std::string &uniform, LLTexture *texture, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace colorspace) +S32 LLGLSLShader::bindTexture(const std::string& uniform, LLTexture* texture, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace colorspace) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; S32 channel = 0; channel = getUniformLocation(uniform); - + return bindTexture(channel, texture, mode, colorspace); } -S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace colorspace) +S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture* texture, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace colorspace) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; @@ -1099,25 +1072,25 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextu LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; return -1; } - + uniform = mTexture[uniform]; - + if (uniform > -1) { gGL.getTexUnit(uniform)->bindFast(texture); gGL.getTexUnit(uniform)->setTextureColorSpace(colorspace); } - + return uniform; } -S32 LLGLSLShader::unbindTexture(const std::string &uniform, LLTexUnit::eTextureType mode) +S32 LLGLSLShader::unbindTexture(const std::string& uniform, LLTexUnit::eTextureType mode) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; S32 channel = 0; channel = getUniformLocation(uniform); - + return unbindTexture(channel); } @@ -1130,14 +1103,14 @@ S32 LLGLSLShader::unbindTexture(S32 uniform, LLTexUnit::eTextureType mode) LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; return -1; } - + uniform = mTexture[uniform]; - + if (uniform > -1) { gGL.getTexUnit(uniform)->unbindFast(mode); } - + return uniform; } @@ -1194,7 +1167,7 @@ void LLGLSLShader::uniform1i(U32 index, GLint x) LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1207,7 +1180,7 @@ void LLGLSLShader::uniform1i(U32 index, GLint x) if (iter == mValue.end() || iter->second.mV[0] != x) { glUniform1i(mUniform[index], x); - mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); + mValue[mUniform[index]] = LLVector4(x, 0.f, 0.f, 0.f); } } } @@ -1219,7 +1192,7 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x) llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1232,7 +1205,7 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x) if (iter == mValue.end() || iter->second.mV[0] != x) { glUniform1f(mUniform[index], x); - mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); + mValue[mUniform[index]] = LLVector4(x, 0.f, 0.f, 0.f); } } } @@ -1254,7 +1227,7 @@ void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1264,8 +1237,8 @@ void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) if (mUniform[index] >= 0) { const auto& iter = mValue.find(mUniform[index]); - LLVector4 vec(x,y,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) + LLVector4 vec(x, y, 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec)) { glUniform2f(mUniform[index], x, y); mValue[mUniform[index]] = vec; @@ -1280,7 +1253,7 @@ void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1290,8 +1263,8 @@ void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) if (mUniform[index] >= 0) { const auto& iter = mValue.find(mUniform[index]); - LLVector4 vec(x,y,z,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) + LLVector4 vec(x, y, z, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec)) { glUniform3f(mUniform[index], x, y, z); mValue[mUniform[index]] = vec; @@ -1306,7 +1279,7 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1316,8 +1289,8 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat if (mUniform[index] >= 0) { const auto& iter = mValue.find(mUniform[index]); - LLVector4 vec(x,y,z,w); - if (iter == mValue.end() || shouldChange(iter->second,vec)) + LLVector4 vec(x, y, z, w); + if (iter == mValue.end() || shouldChange(iter->second, vec)) { glUniform4f(mUniform[index], x, y, z, w); mValue[mUniform[index]] = vec; @@ -1332,7 +1305,7 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1342,8 +1315,8 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) if (mUniform[index] >= 0) { const auto& iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + LLVector4 vec(v[0], 0.f, 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { glUniform1iv(mUniform[index], count, v); mValue[mUniform[index]] = vec; @@ -1385,7 +1358,7 @@ void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1395,8 +1368,8 @@ void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) if (mUniform[index] >= 0) { const auto& iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + LLVector4 vec(v[0], 0.f, 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { glUniform1fv(mUniform[index], count, v); mValue[mUniform[index]] = vec; @@ -1411,7 +1384,7 @@ void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1421,8 +1394,8 @@ void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) if (mUniform[index] >= 0) { const auto& iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],v[1],0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + LLVector4 vec(v[0], v[1], 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { glUniform2fv(mUniform[index], count, v); mValue[mUniform[index]] = vec; @@ -1437,7 +1410,7 @@ void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1447,8 +1420,8 @@ void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) if (mUniform[index] >= 0) { const auto& iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],v[1],v[2],0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + LLVector4 vec(v[0], v[1], v[2], 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { glUniform3fv(mUniform[index], count, v); mValue[mUniform[index]] = vec; @@ -1463,7 +1436,7 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1473,8 +1446,8 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) if (mUniform[index] >= 0) { const auto& iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],v[1],v[2],v[3]); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + LLVector4 vec(v[0], v[1], v[2], v[3]); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; glUniform4fv(mUniform[index], count, v); @@ -1484,13 +1457,13 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) } } -void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) +void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1504,13 +1477,13 @@ void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, c } } -void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) +void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1524,33 +1497,33 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c } } -void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) +void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; llassert(sCurBoundShaderPtr == this); - if (mProgramObject) - { - if (mUniform.size() <= index) - { - LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; - return; - } + if (mProgramObject) + { + if (mUniform.size() <= index) + { + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (mUniform[index] >= 0) - { - glUniformMatrix3x4fv(mUniform[index], count, transpose, v); - } - } + if (mUniform[index] >= 0) + { + glUniformMatrix3x4fv(mUniform[index], count, transpose, v); + } + } } -void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) +void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat* v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; llassert(sCurBoundShaderPtr == this); if (mProgramObject) - { + { if (mUniform.size() <= index) { LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; @@ -1626,12 +1599,12 @@ void LLGLSLShader::uniform1i(const LLStaticHashedString& uniform, GLint v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); - + if (location >= 0) { const auto& iter = mValue.find(location); - LLVector4 vec(v,0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) + LLVector4 vec(v, 0.f, 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec)) { glUniform1i(location, v); mValue[location] = vec; @@ -1679,12 +1652,12 @@ void LLGLSLShader::uniform2i(const LLStaticHashedString& uniform, GLint i, GLint { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); - + if (location >= 0) { const auto& iter = mValue.find(location); - LLVector4 vec(i,j,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) + LLVector4 vec(i, j, 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec)) { glUniform2i(location, i, j); mValue[location] = vec; @@ -1697,12 +1670,12 @@ void LLGLSLShader::uniform1f(const LLStaticHashedString& uniform, GLfloat v) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); - + if (location >= 0) { const auto& iter = mValue.find(location); - LLVector4 vec(v,0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) + LLVector4 vec(v, 0.f, 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec)) { glUniform1f(location, v); mValue[location] = vec; @@ -1714,14 +1687,14 @@ void LLGLSLShader::uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLf { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); - + if (location >= 0) { const auto& iter = mValue.find(location); - LLVector4 vec(x,y,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) + LLVector4 vec(x, y, 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec)) { - glUniform2f(location, x,y); + glUniform2f(location, x, y); mValue[location] = vec; } } @@ -1732,14 +1705,14 @@ void LLGLSLShader::uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLf { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); - + if (location >= 0) { const auto& iter = mValue.find(location); - LLVector4 vec(x,y,z,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) + LLVector4 vec(x, y, z, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec)) { - glUniform3f(location, x,y,z); + glUniform3f(location, x, y, z); mValue[location] = vec; } } @@ -1753,8 +1726,8 @@ void LLGLSLShader::uniform1fv(const LLStaticHashedString& uniform, U32 count, co if (location >= 0) { const auto& iter = mValue.find(location); - LLVector4 vec(v[0],0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + LLVector4 vec(v[0], 0.f, 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { glUniform1fv(location, count, v); mValue[location] = vec; @@ -1766,12 +1739,12 @@ void LLGLSLShader::uniform2fv(const LLStaticHashedString& uniform, U32 count, co { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); - + if (location >= 0) { const auto& iter = mValue.find(location); - LLVector4 vec(v[0],v[1],0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + LLVector4 vec(v[0], v[1], 0.f, 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { glUniform2fv(location, count, v); mValue[location] = vec; @@ -1783,12 +1756,12 @@ void LLGLSLShader::uniform3fv(const LLStaticHashedString& uniform, U32 count, co { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); - + if (location >= 0) { const auto& iter = mValue.find(location); - LLVector4 vec(v[0],v[1],v[2],0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + LLVector4 vec(v[0], v[1], v[2], 0.f); + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { glUniform3fv(location, count, v); mValue[location] = vec; @@ -1805,7 +1778,7 @@ void LLGLSLShader::uniform4fv(const LLStaticHashedString& uniform, U32 count, co { LLVector4 vec(v); const auto& iter = mValue.find(location); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) + if (iter == mValue.end() || shouldChange(iter->second, vec) || count != 1) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; glUniform4fv(location, count, v); @@ -1818,7 +1791,7 @@ void LLGLSLShader::uniformMatrix4fv(const LLStaticHashedString& uniform, U32 cou { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; GLint location = getUniformLocation(uniform); - + if (location >= 0) { stop_glerror(); -- cgit v1.2.3 From 3ac990e6ce962c2530a902d14a711d1ee996375c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 11 Jan 2023 00:04:41 -0600 Subject: SL-18869 Touch up -- fix some Debug GL assertions and restore shadows. --- indra/llrender/llglslshader.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index b5da3d08e2..c5f4efd2c0 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -998,7 +998,6 @@ void LLGLSLShader::bind() sCurBoundShader = mProgramObject; sCurBoundShaderPtr = this; placeProfileQuery(); - LLVertexBuffer::setupClientArrays(mAttributeMask); } if (mUniformsDirty) -- cgit v1.2.3 From 7bd9d21e19b923096ba2b5ea3cbc8be3e13d7aa0 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 19 Jan 2023 09:13:45 -0600 Subject: Optimizations, decruft, and intel compatibility pass (#53) SL-18869, SL-18772 Overhaul VBO management, restore occlusion culling, intel compatibility pass, etc --- indra/llrender/llglslshader.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index c5f4efd2c0..982b2a847a 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -154,15 +154,33 @@ void LLGLSLShader::finishProfile(bool emit_report) std::sort(sorted.begin(), sorted.end(), LLGLSLShaderCompareTimeElapsed()); + bool unbound = false; for (std::vector::iterator iter = sorted.begin(); iter != sorted.end(); ++iter) { (*iter)->dumpStats(); + if ((*iter)->mBinds == 0) + { + unbound = true; + } } LL_INFOS() << "-----------------------------------" << LL_ENDL; LL_INFOS() << "Total rendering time: " << llformat("%.4f ms", sTotalTimeElapsed / 1000000.f) << LL_ENDL; LL_INFOS() << "Total samples drawn: " << llformat("%.4f million", sTotalSamplesDrawn / 1000000.f) << LL_ENDL; LL_INFOS() << "Total triangles drawn: " << llformat("%.3f million", sTotalTrianglesDrawn / 1000000.f) << LL_ENDL; + LL_INFOS() << "-----------------------------------" << LL_ENDL; + + if (unbound) + { + LL_INFOS() << "The following shaders were unused: " << LL_ENDL; + for (std::vector::iterator iter = sorted.begin(); iter != sorted.end(); ++iter) + { + if ((*iter)->mBinds == 0) + { + LL_INFOS() << (*iter)->mName << LL_ENDL; + } + } + } } } @@ -985,6 +1003,8 @@ void LLGLSLShader::bind() { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + llassert(mProgramObject != 0); + gGL.flush(); if (sCurBoundShader != mProgramObject) // Don't re-bind current shader @@ -998,6 +1018,7 @@ void LLGLSLShader::bind() sCurBoundShader = mProgramObject; sCurBoundShaderPtr = this; placeProfileQuery(); + LLVertexBuffer::setupClientArrays(mAttributeMask); } if (mUniformsDirty) -- cgit v1.2.3 From a851aa83e705fa4a1c78919cfcac6709cfb1a875 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 24 Jan 2023 12:50:17 -0600 Subject: SL-18958 Fix for broken water distortion map and depth buffer. Incidental decruft. --- indra/llrender/llglslshader.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 982b2a847a..42b7cc46b3 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1134,6 +1134,11 @@ S32 LLGLSLShader::unbindTexture(S32 uniform, LLTexUnit::eTextureType mode) return uniform; } +S32 LLGLSLShader::getTextureChannel(S32 uniform) const +{ + return mTexture[uniform]; +} + S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace space) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; -- cgit v1.2.3 From c9d56e212aa0117661f9c76545ca84b39412bae7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 31 Jan 2023 15:01:05 -0600 Subject: SL-19015 Balance sun/sky ambiance with punctual light ambiance. Prevent irradiance maps from being brighter than the environment. --- indra/llrender/llglslshader.cpp | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 42b7cc46b3..faa45d59b9 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1041,26 +1041,10 @@ void LLGLSLShader::bind(bool rigged) } } -void LLGLSLShader::unbind() +void LLGLSLShader::unbind(void) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; gGL.flush(); - if (sCurBoundShaderPtr) - { - sCurBoundShaderPtr->readProfileQuery(); - } - stop_glerror(); - LLVertexBuffer::unbind(); - glUseProgram(0); - sCurBoundShader = 0; - sCurBoundShaderPtr = NULL; - stop_glerror(); -} - -void LLGLSLShader::bindNoShader(void) -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - LLVertexBuffer::unbind(); if (sCurBoundShaderPtr) -- cgit v1.2.3 From 830cb6b66551025285120fb628f0b5ebf3841756 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Feb 2023 17:18:39 -0600 Subject: SL-19148 Decruft some forward shaders and drawpools. Fix HUDs being in wrong color space. --- indra/llrender/llglslshader.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index faa45d59b9..1e3f539c81 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -87,7 +87,6 @@ LLShaderFeatures::LLShaderFeatures() , calculatesAtmospherics(false) , hasLighting(false) , isAlphaLighting(false) - , isShiny(false) , isFullbright(false) , isSpecular(false) , hasWaterFog(false) -- cgit v1.2.3 From 1c2410b8af62254e96d60b2ae2e411d4756215e4 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Feb 2023 19:45:31 -0600 Subject: SL-19148 Decruft followthrough -- decruft shader tree and some remaining forward rendering code. --- indra/llrender/llglslshader.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 1e3f539c81..6b56c23fcd 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -99,7 +99,6 @@ LLShaderFeatures::LLShaderFeatures() , encodesNormal(false) , isDeferred(false) , hasScreenSpaceReflections(false) - , hasIndirect(false) , hasShadows(false) , hasAmbientOcclusion(false) , mIndexedTextureChannels(0) -- cgit v1.2.3 From c8fb3ad4de0575a0538b9532e819319f655613d1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 6 Feb 2023 10:28:26 -0600 Subject: SL-19148 Decruft followthrough -- fix for crash when running from installer. Feed fresnel component into PBR alpha. Remove obsolete "shader_hierarchy.txt", remove redundant LL_PROFILE_ZONE_SCOPED, remove unused shader feature flag. --- indra/llrender/llglslshader.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 6b56c23fcd..4e32e2bd25 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -82,8 +82,7 @@ BOOL shouldChange(const LLVector4& v1, const LLVector4& v2) } LLShaderFeatures::LLShaderFeatures() - : atmosphericHelpers(false) - , calculatesLighting(false) + : calculatesLighting(false) , calculatesAtmospherics(false) , hasLighting(false) , isAlphaLighting(false) -- cgit v1.2.3 From a2647e953aeee26ef99e62e0146adcd37c8afca1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 7 Feb 2023 18:25:22 -0600 Subject: SL-18229 Fix for PBR materials on HUDs misbehaving. Incidental decruft. --- indra/llrender/llglslshader.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 4e32e2bd25..59e8e86fbb 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -86,7 +86,6 @@ LLShaderFeatures::LLShaderFeatures() , calculatesAtmospherics(false) , hasLighting(false) , isAlphaLighting(false) - , isFullbright(false) , isSpecular(false) , hasWaterFog(false) , hasTransport(false) -- cgit v1.2.3 From b44ad50f75724a5d9e53bd52d2724111568caf24 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Fri, 31 Mar 2023 10:54:19 -0700 Subject: Move glow extract to be after tonemapping. SL-19513 --- indra/llrender/llglslshader.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 59e8e86fbb..151597e724 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -32,6 +32,7 @@ #include "llfile.h" #include "llrender.h" #include "llvertexbuffer.h" +#include "llrendertarget.h" #if LL_DARWIN #include "OpenGL/OpenGL.h" @@ -1084,6 +1085,39 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture* texture, LLTexUnit::eTextu return uniform; } +S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, LLTexUnit::eTextureFilterOptions mode) +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + + if (uniform < 0 || uniform >= (S32)mTexture.size()) + { + LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; + return -1; + } + + uniform = getTextureChannel(uniform); + + if (uniform > -1) + { + gGL.getTexUnit(uniform)->bindManual(texture->getUsage(), texture->getTexture(0)); + + + gGL.getTexUnit(uniform)->setTextureFilteringOption(mode); + } + + return uniform; +} + +S32 LLGLSLShader::bindTexture(const std::string& uniform, LLRenderTarget* texture, bool depth, LLTexUnit::eTextureFilterOptions mode) +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; + + S32 channel = 0; + channel = getUniformLocation(uniform); + + return bindTexture(channel, texture, depth, mode); +} + S32 LLGLSLShader::unbindTexture(const std::string& uniform, LLTexUnit::eTextureType mode) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; -- cgit v1.2.3 From 56b21054eb974c21c31aed0b6239f5d1a24b467f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Mon, 10 Apr 2023 11:29:50 -0700 Subject: Get DoF working Need to fix up bloom. DRTVWR-559 SL-19524 SL-19513 --- indra/llrender/llglslshader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 61a17e5f52..8f06ef4a42 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1091,7 +1091,7 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, if (uniform < 0 || uniform >= (S32)mTexture.size()) { - LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; + //LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; return -1; } @@ -1099,7 +1099,7 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, if (uniform > -1) { - gGL.getTexUnit(uniform)->bindManual(texture->getUsage(), texture->getTexture(0)); + gGL.getTexUnit(uniform)->bind(texture, depth); gGL.getTexUnit(uniform)->setTextureFilteringOption(mode); -- cgit v1.2.3 From 2b2154f0217758b27b544d066024d922ba234d51 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 11 Apr 2023 15:09:58 -0500 Subject: SL-19564 Rebalance exposure and sky. Hack legacy diffuse map saturation and brightness to allow ACES Hill all the time. --- indra/llrender/llglslshader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 61a17e5f52..d27528296f 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1099,7 +1099,8 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, if (uniform > -1) { - gGL.getTexUnit(uniform)->bindManual(texture->getUsage(), texture->getTexture(0)); + bool has_mips = mode == LLTexUnit::TFO_TRILINEAR || mode == LLTexUnit::TFO_ANISOTROPIC; + gGL.getTexUnit(uniform)->bindManual(texture->getUsage(), texture->getTexture(0), has_mips); gGL.getTexUnit(uniform)->setTextureFilteringOption(mode); -- cgit v1.2.3 From 58df456675f37146d9a6cdaaf75c0f2b93f234c6 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Wed, 12 Apr 2023 14:50:14 -0700 Subject: Fixed DoF --- indra/llrender/llglslshader.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 8f06ef4a42..d213aa05ed 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1091,7 +1091,6 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, if (uniform < 0 || uniform >= (S32)mTexture.size()) { - //LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; return -1; } -- cgit v1.2.3 From f4274ba64e40b487dea2e7c0bfaee47232b55736 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Fri, 14 Apr 2023 03:08:28 -0700 Subject: Move mipmap generation into LLRenderTarget. DRTVWR-583 --- indra/llrender/llglslshader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index b12de563e4..04ac2476a7 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -1085,7 +1085,7 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture* texture, LLTexUnit::eTextu return uniform; } -S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, LLTexUnit::eTextureFilterOptions mode) +S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, LLTexUnit::eTextureFilterOptions mode, U32 index) { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; @@ -1103,7 +1103,7 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, } else { bool has_mips = mode == LLTexUnit::TFO_TRILINEAR || mode == LLTexUnit::TFO_ANISOTROPIC; - gGL.getTexUnit(uniform)->bindManual(texture->getUsage(), texture->getTexture(0), has_mips); + gGL.getTexUnit(uniform)->bindManual(texture->getUsage(), texture->getTexture(index), has_mips); } gGL.getTexUnit(uniform)->setTextureFilteringOption(mode); -- cgit v1.2.3 From e09475713b7abe6fcb916f4a770081a1696b57ab Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 2 May 2023 18:47:21 -0500 Subject: DRTVWR-559 Optimization pass, make it so profileAvatar can read back GPU timer without a frame stall. --- indra/llrender/llglslshader.cpp | 72 ++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 04ac2476a7..b7f08aa9af 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -243,9 +243,9 @@ void LLGLSLShader::stopProfile() } } -void LLGLSLShader::placeProfileQuery() +void LLGLSLShader::placeProfileQuery(bool for_runtime) { - if (sProfileEnabled) + if (sProfileEnabled || for_runtime) { if (mTimerQuery == 0) { @@ -254,42 +254,70 @@ void LLGLSLShader::placeProfileQuery() glGenQueries(1, &mPrimitivesQuery); } - glBeginQuery(GL_SAMPLES_PASSED, mSamplesQuery); glBeginQuery(GL_TIME_ELAPSED, mTimerQuery); - glBeginQuery(GL_PRIMITIVES_GENERATED, mPrimitivesQuery); + + if (!for_runtime) + { + glBeginQuery(GL_SAMPLES_PASSED, mSamplesQuery); + glBeginQuery(GL_PRIMITIVES_GENERATED, mPrimitivesQuery); + } } } -void LLGLSLShader::readProfileQuery() +bool LLGLSLShader::readProfileQuery(bool for_runtime, bool force_read) { - if (sProfileEnabled) + if (sProfileEnabled || for_runtime) { - glEndQuery(GL_TIME_ELAPSED); - glEndQuery(GL_SAMPLES_PASSED); - glEndQuery(GL_PRIMITIVES_GENERATED); + if (!mProfilePending) + { + glEndQuery(GL_TIME_ELAPSED); + if (!for_runtime) + { + glEndQuery(GL_SAMPLES_PASSED); + glEndQuery(GL_PRIMITIVES_GENERATED); + } + mProfilePending = for_runtime; + } + + if (mProfilePending && for_runtime && !force_read) + { + GLuint64 result = 0; + glGetQueryObjectui64v(mTimerQuery, GL_QUERY_RESULT_AVAILABLE, &result); + + if (result != GL_TRUE) + { + return false; + } + } GLuint64 time_elapsed = 0; glGetQueryObjectui64v(mTimerQuery, GL_QUERY_RESULT, &time_elapsed); + mTimeElapsed += time_elapsed; + mProfilePending = false; - GLuint64 samples_passed = 0; - glGetQueryObjectui64v(mSamplesQuery, GL_QUERY_RESULT, &samples_passed); + if (!for_runtime) + { + GLuint64 samples_passed = 0; + glGetQueryObjectui64v(mSamplesQuery, GL_QUERY_RESULT, &samples_passed); - U64 primitives_generated = 0; - glGetQueryObjectui64v(mPrimitivesQuery, GL_QUERY_RESULT, &primitives_generated); - sTotalTimeElapsed += time_elapsed; - mTimeElapsed += time_elapsed; + U64 primitives_generated = 0; + glGetQueryObjectui64v(mPrimitivesQuery, GL_QUERY_RESULT, &primitives_generated); + sTotalTimeElapsed += time_elapsed; - sTotalSamplesDrawn += samples_passed; - mSamplesDrawn += samples_passed; + sTotalSamplesDrawn += samples_passed; + mSamplesDrawn += samples_passed; - U32 tri_count = (U32)primitives_generated / 3; + U32 tri_count = (U32)primitives_generated / 3; - mTrianglesDrawn += tri_count; - sTotalTrianglesDrawn += tri_count; + mTrianglesDrawn += tri_count; + sTotalTrianglesDrawn += tri_count; - sTotalBinds++; - mBinds++; + sTotalBinds++; + mBinds++; + } } + + return true; } -- cgit v1.2.3 From cdc9852f052d804f8b25564ab7d90eb2b79cddd4 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 15 May 2023 11:01:24 -0500 Subject: SL-19709 Fix for fullbright shiny not factoring out exposure and flickering fullbright alpha. Incidental decruft. --- indra/llrender/llglslshader.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index b7f08aa9af..017634a2b9 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -89,7 +89,6 @@ LLShaderFeatures::LLShaderFeatures() , isAlphaLighting(false) , isSpecular(false) , hasWaterFog(false) - , hasTransport(false) , hasSkinning(false) , hasObjectSkinning(false) , hasAtmospherics(false) -- cgit v1.2.3 From 87bda552688bb38fe255cc7e6069c1be6ac20834 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Wed, 17 May 2023 19:30:27 -0400 Subject: Add a binary cache for compiled shaders using glProgramBinary (#216) * Add a binary cache for compiled shaders using glProgramBinary * Add additional sanity checking to shader binary save and load, hook up cache clear and menu option * Fix default init of shader cache data struct and clear gl errors before glGetError calls --------- Co-authored-by: RunitaiLinden --- indra/llrender/llglslshader.cpp | 163 +++++++++++++++++++++++----------------- 1 file changed, 95 insertions(+), 68 deletions(-) (limited to 'indra/llrender/llglslshader.cpp') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 017634a2b9..ccfb8f69be 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -34,6 +34,9 @@ #include "llvertexbuffer.h" #include "llrendertarget.h" +#include "hbxxh.h" +#include "llsdserialize.h" + #if LL_DARWIN #include "OpenGL/OpenGL.h" #endif @@ -53,6 +56,7 @@ LLGLSLShader* LLGLSLShader::sCurBoundShaderPtr = NULL; S32 LLGLSLShader::sIndexedTextureChannels = 0; bool LLGLSLShader::sProfileEnabled = false; std::set LLGLSLShader::sInstances; +LLGLSLShader::defines_map_t LLGLSLShader::sGlobalDefines; U64 LLGLSLShader::sTotalTimeElapsed = 0; U32 LLGLSLShader::sTotalTrianglesDrawn = 0; U64 LLGLSLShader::sTotalSamplesDrawn = 0; @@ -82,30 +86,6 @@ BOOL shouldChange(const LLVector4& v1, const LLVector4& v2) return v1 != v2; } -LLShaderFeatures::LLShaderFeatures() - : calculatesLighting(false) - , calculatesAtmospherics(false) - , hasLighting(false) - , isAlphaLighting(false) - , isSpecular(false) - , hasWaterFog(false) - , hasSkinning(false) - , hasObjectSkinning(false) - , hasAtmospherics(false) - , hasGamma(false) - , hasSrgb(false) - , encodesNormal(false) - , isDeferred(false) - , hasScreenSpaceReflections(false) - , hasShadows(false) - , hasAmbientOcclusion(false) - , mIndexedTextureChannels(0) - , disableTextureIndex(false) - , hasAlphaMask(false) - , attachNothing(false) -{ -} - //=============================== // LLGLSL Shader implementation //=============================== @@ -328,6 +308,7 @@ LLGLSLShader::LLGLSLShader() mActiveTextureChannels(0), mShaderLevel(0), mShaderGroup(SG_DEFAULT), + mFeatures(), mUniformsDirty(FALSE), mTimerQuery(0), mSamplesQuery(0), @@ -344,6 +325,7 @@ void LLGLSLShader::unload() { mShaderFiles.clear(); mDefines.clear(); + mFeatures = LLShaderFeatures(); unloadInternal(); } @@ -419,6 +401,13 @@ BOOL LLGLSLShader::createShader(std::vector* attributes, llassert_always(!mShaderFiles.empty()); +#if LL_DARWIN + // work-around missing mix(vec3,vec3,bvec3) + mDefines["OLD_SELECT"] = "1"; +#endif + + mShaderHash = hash(); + // Create program mProgramObject = glCreateProgram(); if (mProgramObject == 0) @@ -431,50 +420,37 @@ BOOL LLGLSLShader::createShader(std::vector* attributes, BOOL success = TRUE; -#if LL_DARWIN - // work-around missing mix(vec3,vec3,bvec3) - mDefines["OLD_SELECT"] = "1"; -#endif + mUsingBinaryProgram = LLShaderMgr::instance()->loadCachedProgramBinary(this); + if (!mUsingBinaryProgram) + { #if DEBUG_SHADER_INCLUDES - fprintf(stderr, "--- %s ---\n", mName.c_str()); + fprintf(stderr, "--- %s ---\n", mName.c_str()); #endif // DEBUG_SHADER_INCLUDES - //compile new source - vector< pair >::iterator fileIter = mShaderFiles.begin(); - for (; fileIter != mShaderFiles.end(); fileIter++) - { - GLuint shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels); - LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL; - if (shaderhandle) - { - attachObject(shaderhandle); - } - else - { - success = FALSE; - } + //compile new source + vector< pair >::iterator fileIter = mShaderFiles.begin(); + for (; fileIter != mShaderFiles.end(); fileIter++) + { + GLuint shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels); + LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL; + if (shaderhandle) + { + attachObject(shaderhandle); + } + else + { + success = FALSE; + } + } } // Attach existing objects if (!LLShaderMgr::instance()->attachShaderFeatures(this)) { + unloadInternal(); return FALSE; } - - if (gGLManager.mGLSLVersionMajor < 2 && gGLManager.mGLSLVersionMinor < 3) - { //indexed texture rendering requires GLSL 1.3 or later - //attachShaderFeatures may have set the number of indexed texture channels, so set to 1 again - mFeatures.mIndexedTextureChannels = llmin(mFeatures.mIndexedTextureChannels, 1); - } - -#ifdef GL_INTERLEAVED_ATTRIBS - if (varying_count > 0 && varyings) - { - glTransformFeedbackVaryings((GLuint64)mProgramObject, varying_count, varyings, GL_INTERLEAVED_ATTRIBS); - } -#endif - // Map attributes and uniforms if (success) { @@ -495,6 +471,11 @@ BOOL LLGLSLShader::createShader(std::vector* attributes, mShaderLevel--; return createShader(attributes, uniforms); } + else + { + // Give up and unload shader. + unloadInternal(); + } } else if (mFeatures.mIndexedTextureChannels > 0) { //override texture channels for indexed texture rendering @@ -569,6 +550,9 @@ BOOL LLGLSLShader::attachVertexObject(std::string object_path) BOOL LLGLSLShader::attachFragmentObject(std::string object_path) { + if(mUsingBinaryProgram) + return TRUE; + if (LLShaderMgr::instance()->mFragmentShaderObjects.count(object_path) > 0) { stop_glerror(); @@ -588,6 +572,9 @@ BOOL LLGLSLShader::attachFragmentObject(std::string object_path) void LLGLSLShader::attachObject(GLuint object) { + if(mUsingBinaryProgram) + return; + if (object != 0) { stop_glerror(); @@ -606,6 +593,9 @@ void LLGLSLShader::attachObject(GLuint object) void LLGLSLShader::attachObjects(GLuint* objects, S32 count) { + if(mUsingBinaryProgram) + return; + for (S32 i = 0; i < count; i++) { attachObject(objects[i]); @@ -616,15 +606,19 @@ BOOL LLGLSLShader::mapAttributes(const std::vector* attrib { LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER; - //before linking, make sure reserved attributes always have consistent locations - for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++) - { - const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str(); - glBindAttribLocation(mProgramObject, i, (const GLchar*)name); - } + BOOL res = TRUE; + if (!mUsingBinaryProgram) + { + //before linking, make sure reserved attributes always have consistent locations + for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++) + { + const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str(); + glBindAttribLocation(mProgramObject, i, (const GLchar*)name); + } - //link the program - BOOL res = link(); + //link the program + res = link(); + } mAttribute.clear(); U32 numAttributes = (attributes == NULL) ? 0 : attributes->size(); @@ -746,7 +740,6 @@ void LLGLSLShader::mapUniform(GLint index, const vector* u } LLStaticHashedString hashedName(name); - mUniformNameMap[location] = name; mUniformMap[hashedName] = location; LL_DEBUGS("ShaderUniform") << "Uniform " << name << " is at location " << location << LL_ENDL; @@ -798,7 +791,7 @@ void LLGLSLShader::addConstant(const LLGLSLShader::eShaderConsts shader_const) void LLGLSLShader::removePermutation(std::string name) { - mDefines[name].erase(); + mDefines.erase(name); } GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type, GLint size) @@ -847,7 +840,6 @@ BOOL LLGLSLShader::mapUniforms(const vector* uniforms) mActiveTextureChannels = 0; mUniform.clear(); mUniformMap.clear(); - mUniformNameMap.clear(); mTexture.clear(); mValue.clear(); //initialize arrays @@ -1020,6 +1012,11 @@ BOOL LLGLSLShader::link(BOOL suppress_errors) LLShaderMgr::instance()->dumpObjectLog(mProgramObject, !success, mName); } + if (success) + { + LLShaderMgr::instance()->saveCachedProgramBinary(this); + } + return success; } @@ -1918,6 +1915,36 @@ void LLShaderUniforms::apply(LLGLSLShader* shader) } } +LLUUID LLGLSLShader::hash() +{ + HBXXH128 hash_obj; + hash_obj.update(mName); + hash_obj.update(&mShaderGroup, sizeof(mShaderGroup)); + hash_obj.update(&mShaderLevel, sizeof(mShaderLevel)); + for (const auto& shdr_pair : mShaderFiles) + { + hash_obj.update(shdr_pair.first); + hash_obj.update(&shdr_pair.second, sizeof(GLenum)); + } + for (const auto& define_pair : mDefines) + { + hash_obj.update(define_pair.first); + hash_obj.update(define_pair.second); + + } + for (const auto& define_pair : LLGLSLShader::sGlobalDefines) + { + hash_obj.update(define_pair.first); + hash_obj.update(define_pair.second); + + } + hash_obj.update(&mFeatures, sizeof(LLShaderFeatures)); + hash_obj.update(gGLManager.mGLVendor); + hash_obj.update(gGLManager.mGLRenderer); + hash_obj.update(gGLManager.mGLVersionString); + return hash_obj.digest(); +} + #ifdef LL_PROFILER_ENABLE_RENDER_DOC void LLGLSLShader::setLabel(const char* label) { LL_LABEL_OBJECT_GL(GL_PROGRAM, mProgramObject, strlen(label), label); -- cgit v1.2.3