diff options
Diffstat (limited to 'indra/llrender')
| -rw-r--r-- | indra/llrender/llcubemap.cpp | 10 | ||||
| -rw-r--r-- | indra/llrender/llcubemaparray.cpp | 3 | ||||
| -rw-r--r-- | indra/llrender/llfontfreetype.cpp | 201 | ||||
| -rw-r--r-- | indra/llrender/llfontfreetype.h | 23 | ||||
| -rw-r--r-- | indra/llrender/llgl.cpp | 27 | ||||
| -rw-r--r-- | indra/llrender/llgl.h | 13 | ||||
| -rw-r--r-- | indra/llrender/llglslshader.cpp | 26 | ||||
| -rw-r--r-- | indra/llrender/llglslshader.h | 5 | ||||
| -rw-r--r-- | indra/llrender/llimagegl.cpp | 42 | ||||
| -rw-r--r-- | indra/llrender/llrender.cpp | 197 | ||||
| -rw-r--r-- | indra/llrender/llrender.h | 20 | ||||
| -rw-r--r-- | indra/llrender/llrender2dutils.cpp | 3 | ||||
| -rw-r--r-- | indra/llrender/llrendertarget.cpp | 199 | ||||
| -rw-r--r-- | indra/llrender/llrendertarget.h | 11 | ||||
| -rw-r--r-- | indra/llrender/llshadermgr.cpp | 80 | ||||
| -rw-r--r-- | indra/llrender/llshadermgr.h | 18 | ||||
| -rw-r--r-- | indra/llrender/llvertexbuffer.cpp | 211 | ||||
| -rw-r--r-- | indra/llrender/llvertexbuffer.h | 8 |
18 files changed, 713 insertions, 384 deletions
diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index 53691bafe2..c52f68d298 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -86,7 +86,10 @@ void LLCubeMap::initGL() #endif mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP); mRawImages[i] = new LLImageRaw(RESOLUTION, RESOLUTION, 4); - mImages[i]->createGLTexture(0, mRawImages[i], texname); + if (!mImages[i]->createGLTexture(0, mRawImages[i], texname)) + { + LL_WARNS() << "Failed to create GL texture for environment cubemap face " << i << LL_ENDL; + } gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname); mImages[i]->setAddressMode(LLTexUnit::TAM_CLAMP); @@ -203,7 +206,10 @@ void LLCubeMap::initEnvironmentMap(const std::vector<LLPointer<LLImageRaw> >& ra mImages[i] = new LLImageGL(resolution, resolution, components, true); mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP); mRawImages[i] = rawimages[i]; - mImages[i]->createGLTexture(0, mRawImages[i], texname); + if (!mImages[i]->createGLTexture(0, mRawImages[i], texname)) + { + LL_WARNS() << "Failed to create GL texture for environment cubemap face " << i << LL_ENDL; + } gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname); mImages[i]->setAddressMode(LLTexUnit::TAM_CLAMP); diff --git a/indra/llrender/llcubemaparray.cpp b/indra/llrender/llcubemaparray.cpp index fb35e002df..e0a8782c33 100644 --- a/indra/llrender/llcubemaparray.cpp +++ b/indra/llrender/llcubemaparray.cpp @@ -114,6 +114,8 @@ LLCubeMapArray::LLCubeMapArray(LLCubeMapArray& lhs, U32 width, U32 count) : mTex allocate(mWidth, lhs.mImage->getComponents(), count, lhs.mImage->getUseMipMaps(), lhs.mHDR); // Copy each cubemap from the incoming array to the new array + // The call to glTexSubImage3D causes an INVALID OPERATION OpenGL error. For now we comment this.. + /* U32 min_count = std::min(count, lhs.mCount); for (U32 i = 0; i < min_count * 6; ++i) { @@ -133,6 +135,7 @@ LLCubeMapArray::LLCubeMapArray(LLCubeMapArray& lhs, U32 width, U32 count) : mTex glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, 0, 0, i, mWidth, mWidth, 1, components, GL_UNSIGNED_BYTE, scaled_image->getData()); } } + */ } LLCubeMapArray::~LLCubeMapArray() diff --git a/indra/llrender/llfontfreetype.cpp b/indra/llrender/llfontfreetype.cpp index e93c98970b..9d6773ac5b 100644 --- a/indra/llrender/llfontfreetype.cpp +++ b/indra/llrender/llfontfreetype.cpp @@ -58,9 +58,9 @@ FT_Render_Mode gFontRenderMode = FT_RENDER_MODE_NORMAL; -LLFontManager *gFontManagerp = NULL; +LLFontManager *gFontManagerp = nullptr; -FT_Library gFTLibrary = NULL; +FT_Library gFTLibrary = nullptr; //static void LLFontManager::initClass() @@ -75,7 +75,7 @@ void LLFontManager::initClass() void LLFontManager::cleanupClass() { delete gFontManagerp; - gFontManagerp = NULL; + gFontManagerp = nullptr; } LLFontManager::LLFontManager() @@ -103,6 +103,7 @@ LLFontManager::LLFontManager() LLFontManager::~LLFontManager() { FT_Done_FreeType(gFTLibrary); + unloadAllFonts(); } @@ -141,12 +142,8 @@ LLFontFreetype::LLFontFreetype() mAscender(0.f), mDescender(0.f), mLineHeight(0.f), -#ifdef LL_WINDOWS - pFileStream(NULL), - pFtStream(NULL), -#endif mIsFallback(false), - mFTFace(NULL), + mFTFace(nullptr), mRenderGlyphCount(0), mStyle(0), mPointSize(0) @@ -159,35 +156,16 @@ LLFontFreetype::~LLFontFreetype() // Clean up freetype libs. if (mFTFace) FT_Done_Face(mFTFace); - mFTFace = NULL; + mFTFace = nullptr; // Delete glyph info std::for_each(mCharGlyphInfoMap.begin(), mCharGlyphInfoMap.end(), DeletePairedPointer()); mCharGlyphInfoMap.clear(); -#ifdef LL_WINDOWS - delete pFileStream; // closed by FT_Done_Face - delete pFtStream; -#endif delete mFontBitmapCachep; // mFallbackFonts cleaned up by LLPointer destructor } -#ifdef LL_WINDOWS -unsigned long ft_read_cb(FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count) { - if (count <= 0) return count; - llifstream *file_stream = static_cast<llifstream *>(stream->descriptor.pointer); - file_stream->seekg(offset, std::ios::beg); - file_stream->read((char*)buffer, count); - return (unsigned long)file_stream->gcount(); -} - -void ft_close_cb(FT_Stream stream) { - llifstream *file_stream = static_cast<llifstream *>(stream->descriptor.pointer); - file_stream->close(); -} -#endif - bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 vert_dpi, F32 horz_dpi, bool is_fallback, S32 face_n) { // Don't leak face objects. This is also needed to deal with @@ -195,26 +173,21 @@ bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 v if (mFTFace) { FT_Done_Face(mFTFace); - mFTFace = NULL; + mFTFace = nullptr; } - int error; -#ifdef LL_WINDOWS - error = ftOpenFace(filename, face_n); -#else - error = FT_New_Face( gFTLibrary, - filename.c_str(), - 0, - &mFTFace); -#endif + FT_Open_Args openArgs; + memset( &openArgs, 0, sizeof( openArgs ) ); + openArgs.memory_base = gFontManagerp->loadFont( filename, openArgs.memory_size ); + + if( !openArgs.memory_base ) + return false; + + openArgs.flags = FT_OPEN_MEMORY; + int error = FT_Open_Face( gFTLibrary, &openArgs, 0, &mFTFace ); if (error) - { -#ifdef LL_WINDOWS - clearFontStreams(); -#endif return false; - } mIsFallback = is_fallback; F32 pixels_per_em = (point_size / 72.f)*vert_dpi; // Size in inches * dpi @@ -229,10 +202,8 @@ bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 v { // Clean up freetype libs. FT_Done_Face(mFTFace); -#ifdef LL_WINDOWS - clearFontStreams(); -#endif - mFTFace = NULL; + + mFTFace = nullptr; return false; } @@ -288,73 +259,30 @@ S32 LLFontFreetype::getNumFaces(const std::string& filename) if (mFTFace) { FT_Done_Face(mFTFace); - mFTFace = NULL; + mFTFace = nullptr; } S32 num_faces = 1; -#ifdef LL_WINDOWS - int error = ftOpenFace(filename, 0); + FT_Open_Args openArgs; + memset( &openArgs, 0, sizeof( openArgs ) ); + openArgs.memory_base = gFontManagerp->loadFont( filename, openArgs.memory_size ); + if( !openArgs.memory_base ) + return 0; + openArgs.flags = FT_OPEN_MEMORY; + int error = FT_Open_Face( gFTLibrary, &openArgs, 0, &mFTFace ); if (error) - { return 0; - } else - { num_faces = mFTFace->num_faces; - } FT_Done_Face(mFTFace); - clearFontStreams(); - mFTFace = NULL; -#endif + mFTFace = nullptr; return num_faces; } -#ifdef LL_WINDOWS -S32 LLFontFreetype::ftOpenFace(const std::string& filename, S32 face_n) -{ - S32 error = -1; - pFileStream = new llifstream(filename, std::ios::binary); - if (pFileStream->is_open()) - { - std::streampos beg = pFileStream->tellg(); - pFileStream->seekg(0, std::ios::end); - std::streampos end = pFileStream->tellg(); - std::size_t file_size = end - beg; - pFileStream->seekg(0, std::ios::beg); - - pFtStream = new LLFT_Stream(); - pFtStream->base = 0; - pFtStream->pos = 0; - pFtStream->size = static_cast<unsigned long>(file_size); - pFtStream->descriptor.pointer = pFileStream; - pFtStream->read = ft_read_cb; - pFtStream->close = ft_close_cb; - - FT_Open_Args args; - args.flags = FT_OPEN_STREAM; - args.stream = (FT_StreamRec*)pFtStream; - error = FT_Open_Face(gFTLibrary, &args, face_n, &mFTFace); - } - return error; -} - -void LLFontFreetype::clearFontStreams() -{ - if (pFileStream) - { - pFileStream->close(); - } - delete pFileStream; - delete pFtStream; - pFileStream = NULL; - pFtStream = NULL; -} -#endif - void LLFontFreetype::addFallbackFont(const LLPointer<LLFontFreetype>& fallback_font, const char_functor_t& functor) { @@ -378,7 +306,7 @@ F32 LLFontFreetype::getDescenderHeight() const F32 LLFontFreetype::getXAdvance(llwchar wch) const { - if (mFTFace == NULL) + if (mFTFace == nullptr) return 0.0; // Return existing info only if it is current @@ -402,7 +330,7 @@ F32 LLFontFreetype::getXAdvance(llwchar wch) const F32 LLFontFreetype::getXAdvance(const LLFontGlyphInfo* glyph) const { - if (mFTFace == NULL) + if (mFTFace == nullptr) return 0.0; return glyph->mXAdvance; @@ -410,7 +338,7 @@ F32 LLFontFreetype::getXAdvance(const LLFontGlyphInfo* glyph) const F32 LLFontFreetype::getXKerning(llwchar char_left, llwchar char_right) const { - if (mFTFace == NULL) + if (mFTFace == nullptr) return 0.0; //llassert(!mIsFallback); @@ -429,7 +357,7 @@ F32 LLFontFreetype::getXKerning(llwchar char_left, llwchar char_right) const F32 LLFontFreetype::getXKerning(const LLFontGlyphInfo* left_glyph_info, const LLFontGlyphInfo* right_glyph_info) const { - if (mFTFace == NULL) + if (mFTFace == nullptr) return 0.0; U32 left_glyph = left_glyph_info ? left_glyph_info->mGlyphIndex : 0; @@ -452,7 +380,7 @@ LLFontGlyphInfo* LLFontFreetype::addGlyph(llwchar wch, EFontGlyphType glyph_type { if (!mFTFace) { - return NULL; + return nullptr; } llassert(!mIsFallback); @@ -543,14 +471,14 @@ LLFontGlyphInfo* LLFontFreetype::addGlyph(llwchar wch, EFontGlyphType glyph_type { return addGlyphFromFont(this, wch, glyph_index, glyph_type); } - return NULL; + return nullptr; } LLFontGlyphInfo* LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, llwchar wch, U32 glyph_index, EFontGlyphType requested_glyph_type) const { LL_PROFILE_ZONE_SCOPED; - if (mFTFace == NULL) - return NULL; + if (mFTFace == nullptr) + return nullptr; llassert(!mIsFallback); fontp->renderGlyph(requested_glyph_type, glyph_index, wch); @@ -602,7 +530,7 @@ LLFontGlyphInfo* LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, l { U8 *buffer_data = fontp->mFTFace->glyph->bitmap.buffer; S32 buffer_row_stride = fontp->mFTFace->glyph->bitmap.pitch; - U8 *tmp_graydata = NULL; + U8 *tmp_graydata = nullptr; if (fontp->mFTFace->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) @@ -706,7 +634,7 @@ void LLFontFreetype::insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const void LLFontFreetype::renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index, llwchar wch) const { - if (mFTFace == NULL) + if (mFTFace == nullptr) return; FT_Int32 load_flags = FT_LOAD_FORCE_AUTOHINT; @@ -920,3 +848,58 @@ void LLFontFreetype::setSubImageLuminanceAlpha(U32 x, U32 y, U32 bitmap_num, U32 } } + +namespace ll +{ + namespace fonts + { + class LoadedFont + { + public: + LoadedFont( std::string aName , std::string const &aAddress, std::size_t aSize ) + : mAddress( aAddress ) + { + mName = aName; + mSize = aSize; + mRefs = 1; + } + std::string mName; + std::string mAddress; + std::size_t mSize; + U32 mRefs; + }; + } +} + +U8 const* LLFontManager::loadFont( std::string const &aFilename, long &a_Size) +{ + a_Size = 0; + std::map< std::string, std::shared_ptr<ll::fonts::LoadedFont> >::iterator itr = m_LoadedFonts.find( aFilename ); + if( itr != m_LoadedFonts.end() ) + { + ++itr->second->mRefs; + // A possible overflow cannot happen here, as it is asserted that the size is less than std::numeric_limits<long>::max() a few lines below. + a_Size = static_cast<long>(itr->second->mSize); + return reinterpret_cast<U8 const*>(itr->second->mAddress.c_str()); + } + + auto strContent = LLFile::getContents(aFilename); + + if( strContent.empty() ) + return nullptr; + + // For fontconfig a type of long is required, std::string::size() returns size_t. I think it is safe to limit this to 2GiB and not support fonts that huge (can that even be a thing?) + llassert_always( strContent.size() < std::numeric_limits<long>::max() ); + + a_Size = static_cast<long>(strContent.size()); + + auto pCache = std::make_shared<ll::fonts::LoadedFont>( aFilename, strContent, a_Size ); + itr = m_LoadedFonts.insert( std::make_pair( aFilename, pCache ) ).first; + + return reinterpret_cast<U8 const*>(itr->second->mAddress.c_str()); +} + +void LLFontManager::unloadAllFonts() +{ + m_LoadedFonts.clear(); +} diff --git a/indra/llrender/llfontfreetype.h b/indra/llrender/llfontfreetype.h index 783bf4a4b3..a9b3a944ee 100644 --- a/indra/llrender/llfontfreetype.h +++ b/indra/llrender/llfontfreetype.h @@ -43,15 +43,28 @@ typedef struct FT_FaceRec_* LLFT_Face; struct FT_StreamRec_; typedef struct FT_StreamRec_ LLFT_Stream; +namespace ll +{ + namespace fonts + { + class LoadedFont; + } +} + class LLFontManager { public: static void initClass(); static void cleanupClass(); + U8 const *loadFont( std::string const &aFilename, long &a_Size ); + private: LLFontManager(); ~LLFontManager(); + + void unloadAllFonts(); + std::map< std::string, std::shared_ptr<ll::fonts::LoadedFont> > m_LoadedFonts; }; struct LLFontGlyphInfo @@ -90,11 +103,6 @@ public: S32 getNumFaces(const std::string& filename); -#ifdef LL_WINDOWS - S32 ftOpenFace(const std::string& filename, S32 face_n); - void clearFontStreams(); -#endif - typedef std::function<bool(llwchar)> char_functor_t; void addFallbackFont(const LLPointer<LLFontFreetype>& fallback_font, const char_functor_t& functor = nullptr); @@ -170,11 +178,6 @@ private: LLFT_Face mFTFace; -#ifdef LL_WINDOWS - llifstream *pFileStream; - LLFT_Stream *pFtStream; -#endif - bool mIsFallback; typedef std::pair<LLPointer<LLFontFreetype>, char_functor_t> fallback_font_t; typedef std::vector<fallback_font_t> fallback_font_vector_t; diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index ac66faaf5a..b002d183ef 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -1123,17 +1123,6 @@ bool LLGLManager::initGL() if (mGLVersion >= 2.f) { parse_glsl_version(mGLSLVersionMajor, mGLSLVersionMinor); - -#if 0 && LL_DARWIN - // TODO maybe switch to using a core profile for GL 3.2? - // https://stackoverflow.com/a/19868861 - //never use GLSL greater than 1.20 on OSX - if (mGLSLVersionMajor > 1 || mGLSLVersionMinor > 30) - { - mGLSLVersionMajor = 1; - mGLSLVersionMinor = 30; - } -#endif } #if GL_VERSION_1_3 @@ -2279,26 +2268,28 @@ void rotate_quat(LLQuaternion& rotation) void flush_glerror() { + if(!gDebugGL) return; glGetError(); } -//this function outputs gl error to the log file, does not crash the code. -void log_glerror() +void log_glerror(std::string comment) { + if(!gDebugGL) return; + if (LL_UNLIKELY(!gGLManager.mInited)) { return ; } - // Create or update texture to be used with this data + GLenum error; error = glGetError(); - while (LL_UNLIKELY(error)) + if (error != GL_NO_ERROR) { #if GLU_VERSION_1_1 GLubyte const * gl_error_msg = gluErrorString(error); if (NULL != gl_error_msg) { - LL_WARNS() << "GL Error: " << error << " GL Error String: " << gl_error_msg << LL_ENDL ; + LL_WARNS() << "GL Error (" << comment << ")" << error << ": " << gl_error_msg << LL_ENDL; } else #endif // GLU_VERSION_1_1 @@ -2307,7 +2298,6 @@ void log_glerror() // you'll probably have to grep for the number in glext.h. LL_WARNS() << "GL Error: UNKNOWN 0x" << std::hex << error << std::dec << LL_ENDL; } - error = glGetError(); } } @@ -2385,6 +2375,7 @@ void assert_glerror() void clear_glerror() { + if(!gDebugGL) return; glGetError(); glGetError(); } @@ -2746,7 +2737,7 @@ void LLGLUserClipPlane::setPlane(F32 a, F32 b, F32 c, F32 d) if(cplane[2] < 0) cplane *= -1; - glm::mat4 suffix; + glm::mat4 suffix = glm::identity<glm::mat4>(); suffix = glm::row(suffix, 2, cplane); glm::mat4 newP = suffix * P; gGL.matrixMode(LLRender::MM_PROJECTION); diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index bf8368a7b3..130b06f9df 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -154,17 +154,20 @@ void rotate_quat(LLQuaternion& rotation); void flush_glerror(); // Flush GL errors when we know we're handling them correctly. -void log_glerror(); +void log_glerror(std::string comment); void assert_glerror(); void clear_glerror(); -#if !LL_RELEASE_FOR_DOWNLOAD -# define stop_glerror() assert_glerror() -# define llglassertok() assert_glerror() -# define STOP_GLERROR stop_glerror() +//#if !LL_RELEASE_FOR_DOWNLOAD +#if 1 +# define LOG_GLERROR(COMMENT) log_glerror(COMMENT) +# define stop_glerror() log_glerror("stop") +# define llglassertok() log_glerror("ASSERTOK") +# define STOP_GLERROR log_glerror("STOP") #else +# define LOG_GLERROR(COMMENT) # define stop_glerror() # define llglassertok() # define STOP_GLERROR diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index aac5e3abc8..39bd9cbfed 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -57,6 +57,7 @@ S32 LLGLSLShader::sIndexedTextureChannels = 0; U32 LLGLSLShader::sMaxGLTFMaterials = 0; U32 LLGLSLShader::sMaxGLTFNodes = 0; bool LLGLSLShader::sProfileEnabled = false; +bool LLGLSLShader::sCanProfile = true; std::set<LLGLSLShader*> LLGLSLShader::sInstances; LLGLSLShader::defines_map_t LLGLSLShader::sGlobalDefines; U64 LLGLSLShader::sTotalTimeElapsed = 0; @@ -273,7 +274,7 @@ void LLGLSLShader::placeProfileQuery(bool for_runtime) bool LLGLSLShader::readProfileQuery(bool for_runtime, bool force_read) { - if (sProfileEnabled || for_runtime) + if ((sProfileEnabled || for_runtime) && sCanProfile) { if (!mProfilePending) { @@ -450,8 +451,11 @@ bool LLGLSLShader::createShader() llassert_always(!mShaderFiles.empty()); #if LL_DARWIN - // work-around missing mix(vec3,vec3,bvec3) - mDefines["OLD_SELECT"] = "1"; + if(!gGLManager.mIsApple) + { + // work-around missing mix(vec3,vec3,bvec3) + mDefines["OLD_SELECT"] = "1"; + } #endif mShaderHash = hash(); @@ -572,7 +576,7 @@ bool LLGLSLShader::createShader() } } -#ifdef LL_PROFILER_ENABLE_RENDER_DOC +#if LL_PROFILER_ENABLE_RENDER_DOC setLabel(mName.c_str()); #endif @@ -1190,22 +1194,22 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth, return -1; } - uniform = getTextureChannel(uniform); + S32 channel = getTextureChannel(uniform); - if (uniform > -1) + if (channel > -1) { if (depth) { - gGL.getTexUnit(uniform)->bind(texture, true); + gGL.getTexUnit(channel)->bind(texture, true); } else { bool has_mips = mode == LLTexUnit::TFO_TRILINEAR || mode == LLTexUnit::TFO_ANISOTROPIC; - gGL.getTexUnit(uniform)->bindManual(texture->getUsage(), texture->getTexture(index), has_mips); + gGL.getTexUnit(channel)->bindManual(texture->getUsage(), texture->getTexture(index), has_mips); } - gGL.getTexUnit(uniform)->setTextureFilteringOption(mode); + gGL.getTexUnit(channel)->setTextureFilteringOption(mode); } - return uniform; + return channel; } S32 LLGLSLShader::bindTexture(const std::string& uniform, LLRenderTarget* texture, bool depth, LLTexUnit::eTextureFilterOptions mode) @@ -2116,7 +2120,7 @@ LLUUID LLGLSLShader::hash() return hash_obj.digest(); } -#ifdef LL_PROFILER_ENABLE_RENDER_DOC +#if LL_PROFILER_ENABLE_RENDER_DOC void LLGLSLShader::setLabel(const char* label) { LL_LABEL_OBJECT_GL(GL_PROGRAM, mProgramObject, strlen(label), label); } diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 873ab0cff5..272a99aaa5 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -160,6 +160,7 @@ public: static std::set<LLGLSLShader*> sInstances; static bool sProfileEnabled; + static bool sCanProfile; LLGLSLShader(); ~LLGLSLShader(); @@ -361,7 +362,7 @@ public: // hacky flag used for optimization in LLDrawPoolAlpha bool mCanBindFast = false; -#ifdef LL_PROFILER_ENABLE_RENDER_DOC +#if LL_PROFILER_ENABLE_RENDER_DOC void setLabel(const char* label); #endif @@ -381,7 +382,7 @@ extern LLGLSLShader gSolidColorProgram; //Alpha mask shader (declared here so llappearance can access properly) extern LLGLSLShader gAlphaMaskProgram; -#ifdef LL_PROFILER_ENABLE_RENDER_DOC +#if LL_PROFILER_ENABLE_RENDER_DOC #define LL_SET_SHADER_LABEL(shader) shader.setLabel(#shader) #else #define LL_SET_SHADER_LABEL(shader, label) diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 0146ed3119..bc80bd9556 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -357,7 +357,10 @@ S32 LLImageGL::dataFormatBits(S32 dataformat) case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac #endif case GL_DEPTH_COMPONENT: return 24; + case GL_DEPTH_COMPONENT16: return 16; case GL_DEPTH_COMPONENT24: return 24; + case GL_DEPTH_COMPONENT32: return 32; + case GL_RGBA16: return 64; case GL_R16F: return 16; case GL_RG16F: return 32; case GL_RGB16F: return 48; @@ -1149,6 +1152,8 @@ void sub_image_lines(U32 target, S32 miplevel, S32 x_offset, S32 y_offset, S32 w // full width texture, do 32 lines at a time for (U32 y_pos = y_offset; y_pos < y_offset_end; y_pos += batch_size) { + // If this keeps crashing, pass down data_size, looks like it is using + // imageraw->getData(); for data, but goes way over allocated size limit glTexSubImage2D(target, miplevel, x_offset, y_pos, width, batch_size, pixformat, pixtype, src); src += line_width * batch_size; } @@ -1158,6 +1163,8 @@ void sub_image_lines(U32 target, S32 miplevel, S32 x_offset, S32 y_offset, S32 w // partial width or strange height for (U32 y_pos = y_offset; y_pos < y_offset_end; y_pos += 1) { + // If this keeps crashing, pass down data_size, looks like it is using + // imageraw->getData(); for data, but goes way over allocated size limit glTexSubImage2D(target, miplevel, x_offset, y_pos, width, 1, pixformat, pixtype, src); src += line_width; } @@ -1290,7 +1297,7 @@ bool LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_ { glCopyTexSubImage2D(GL_TEXTURE_2D, 0, fb_x, fb_y, x_pos, y_pos, width, height); mGLTextureCreated = true; - stop_glerror(); + LOG_GLERROR("LLImageGL::setSubImageFromFrameBuffer()"); return true; } else @@ -1632,6 +1639,7 @@ bool LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S llassert(mCurrentDiscardLevel >= 0); discard_level = mCurrentDiscardLevel; } + discard_level = llmin(discard_level, MAX_DISCARD_LEVEL); // Actual image width/height = raw image width/height * 2^discard_level S32 raw_w = imageraw->getWidth() ; @@ -1738,6 +1746,7 @@ bool LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, bool data_ discard_level = mCurrentDiscardLevel; } discard_level = llclamp(discard_level, 0, (S32)mMaxDiscardLevel); + discard_level = llmin(discard_level, MAX_DISCARD_LEVEL); if (main_thread // <--- always force creation of new_texname when not on main thread ... && !defer_copy // <--- ... or defer copy is set @@ -1966,8 +1975,17 @@ bool LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, (GLint*)&glbytes); if(!imageraw->allocateDataSize(width, height, ncomponents, glbytes)) { - LL_WARNS() << "Memory allocation failed for reading back texture. Size is: " << glbytes << LL_ENDL ; - LL_WARNS() << "width: " << width << "height: " << height << "components: " << ncomponents << LL_ENDL ; + constexpr S64 MAX_GL_BYTES = 2048 * 2048; + if (glbytes > 0 && glbytes <= MAX_GL_BYTES) + { + LLError::LLUserWarningMsg::showOutOfMemory(); + LL_ERRS() << "Memory allocation failed for reading back texture. Data size: " << glbytes << LL_ENDL; + } + else + { + LL_WARNS() << "Memory allocation failed for reading back texture. Data size is: " << glbytes << LL_ENDL; + LL_WARNS() << "width: " << width << "height: " << height << "components: " << ncomponents << LL_ENDL; + } return false ; } @@ -1978,8 +1996,18 @@ bool LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre { if(!imageraw->allocateDataSize(width, height, ncomponents)) { - LL_WARNS() << "Memory allocation failed for reading back texture." << LL_ENDL ; - LL_WARNS() << "width: " << width << "height: " << height << "components: " << ncomponents << LL_ENDL ; + constexpr F32 MAX_IMAGE_SIZE = 2048 * 2048; + F32 size = (F32)width * (F32)height * (F32)ncomponents; + if (size > 0 && size <= MAX_IMAGE_SIZE) + { + LLError::LLUserWarningMsg::showOutOfMemory(); + LL_ERRS() << "Memory allocation failed for reading back texture. Data size: " << size << LL_ENDL; + } + else + { + LL_WARNS() << "Memory allocation failed for reading back texture." << LL_ENDL; + LL_WARNS() << "width: " << width << "height: " << height << "components: " << ncomponents << LL_ENDL; + } return false ; } @@ -2564,6 +2592,8 @@ bool LLImageGL::scaleDown(S32 desired_discard) return false; } + //LL_WARNS() << "scaleDown" << LL_ENDL; + S32 mip = desired_discard - mCurrentDiscardLevel; S32 desired_width = getWidth(desired_discard); @@ -2581,6 +2611,7 @@ bool LLImageGL::scaleDown(S32 desired_discard) free_tex_image(mTexName); glTexImage2D(mTarget, 0, mFormatInternal, desired_width, desired_height, 0, mFormatPrimary, mFormatType, nullptr); glCopyTexSubImage2D(mTarget, 0, 0, 0, 0, 0, desired_width, desired_height); + LOG_GLERROR("LLImageGL::scaleDown() - glCopyTexSubImage2D"); alloc_tex_image(desired_width, desired_height, mFormatInternal, 1); mTexOptionsDirty = true; @@ -2590,6 +2621,7 @@ bool LLImageGL::scaleDown(S32 desired_discard) LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("scaleDown - glGenerateMipmap"); gGL.getTexUnit(0)->bind(this); glGenerateMipmap(mTarget); + LOG_GLERROR("LLImageGL::scaleDown() - glGenerateMipmap"); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); } } diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index cbb178b6f8..658947d531 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -124,7 +124,7 @@ static const GLenum sGLBlendFactor[] = LLTexUnit::LLTexUnit(S32 index) : mCurrTexType(TT_NONE), - mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0), + mCurrTexture(0), mHasMipMaps(false), mIndex(index) { @@ -203,6 +203,7 @@ void LLTexUnit::bindFast(LLTexture* texture) glActiveTexture(GL_TEXTURE0 + mIndex); gGL.mCurrTextureUnitIndex = mIndex; mCurrTexture = gl_tex->getTexName(); + mCurrTexType = gl_tex->getTarget(); if (!mCurrTexture) { LL_PROFILE_ZONE_NAMED("MISSING TEXTURE"); @@ -213,6 +214,14 @@ void LLTexUnit::bindFast(LLTexture* texture) } glBindTexture(sGLTextureType[gl_tex->getTarget()], mCurrTexture); mHasMipMaps = gl_tex->mHasMipMaps; +/* + if (gl_tex->mTexOptionsDirty) + { + gl_tex->mTexOptionsDirty = false; + setTextureAddressModeFast(gl_tex->mAddressMode, gl_tex->getTarget()); + setTextureFilteringOptionFast(gl_tex->mFilterOption, gl_tex->getTarget()); + } +*/ } bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind) @@ -467,11 +476,24 @@ void LLTexUnit::setTextureAddressMode(eTextureAddressMode mode) activate(); - glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_S, sGLAddressMode[mode]); - glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_T, sGLAddressMode[mode]); +/* + setTextureAddressModeFast(mode, mCurrTexType); +} + +void LLTexUnit::setTextureAddressModeFast(eTextureAddressMode mode, eTextureType tex_type) +{ + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_WRAP_S, sGLAddressMode[mode]); + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_WRAP_T, sGLAddressMode[mode]); + if (tex_type == TT_CUBE_MAP || tex_type == TT_CUBE_MAP_ARRAY || tex_type == TT_TEXTURE_3D) + { + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_WRAP_R, sGLAddressMode[mode]); + } +*/ + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_S, sGLAddressMode[mode]); + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_T, sGLAddressMode[mode]); if (mCurrTexType == TT_CUBE_MAP) { - glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, sGLAddressMode[mode]); + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_R, sGLAddressMode[mode]); } } @@ -479,41 +501,80 @@ void LLTexUnit::setTextureFilteringOption(LLTexUnit::eTextureFilterOptions optio { if (mIndex < 0 || mCurrTexture == 0 || mCurrTexType == LLTexUnit::TT_MULTISAMPLE_TEXTURE) return; + GLenum target = sGLTextureType[mCurrTexType]; + + if (mCurrTexType == LLTexUnit::TT_NONE) + { + LL_WARNS() << "setTextureFilteringOption() Error: mCurrTexType==TT_NONE texture: " << mCurrTexture << LL_ENDL; + gGL.debugTexUnits(); + } + gGL.flush(); +/* + setTextureFilteringOptionFast(option, mCurrTexType); +} + +void LLTexUnit::setTextureFilteringOptionFast(LLTexUnit::eTextureFilterOptions option, eTextureType tex_type) +{ +*/ if (option == TFO_POINT) { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MAG_FILTER, GL_NEAREST); +/* + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MAG_FILTER, GL_NEAREST); } else { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MAG_FILTER, GL_LINEAR); +*/ + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + else + { + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } if (option >= TFO_TRILINEAR && mHasMipMaps) { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); +/* + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); +*/ + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } else if (option >= TFO_BILINEAR) { if (mHasMipMaps) { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); +/* + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + } + else + { + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_LINEAR); +*/ + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } else { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } } else { if (mHasMipMaps) { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); +/* + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); } else { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_NEAREST); +*/ + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + } + else + { + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } } @@ -521,11 +582,20 @@ void LLTexUnit::setTextureFilteringOption(LLTexUnit::eTextureFilterOptions optio { if (LLImageGL::sGlobalUseAnisotropic && option == TFO_ANISOTROPIC) { - glTexParameterf(sGLTextureType[mCurrTexType], GL_TEXTURE_MAX_ANISOTROPY_EXT, gGLManager.mMaxAnisotropy); +/* + glTexParameterf(sGLTextureType[tex_type], GL_TEXTURE_MAX_ANISOTROPY, gGLManager.mMaxAnisotropy); } else { - glTexParameterf(sGLTextureType[mCurrTexType], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); + glTexParameterf(sGLTextureType[tex_type], GL_TEXTURE_MAX_ANISOTROPY, 1.f); +*/ + //glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, gGLManager.mMaxAnisotropy); + //We plan to add a setting. For now we stick to a low value. + glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0); + } + else + { + glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); } } } @@ -610,30 +680,6 @@ GLint LLTexUnit::getTextureSourceType(eTextureBlendSrc src, bool isAlpha) } } -void LLTexUnit::setColorScale(S32 scale) -{ - if (mCurrColorScale != scale || gGL.mDirty) - { - mCurrColorScale = scale; - gGL.flush(); -#if GL_VERSION_1_1 - glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE, scale ); -#endif - } -} - -void LLTexUnit::setAlphaScale(S32 scale) -{ - if (mCurrAlphaScale != scale || gGL.mDirty) - { - mCurrAlphaScale = scale; - gGL.flush(); -#if GL_VERSION_1_1 - glTexEnvi( GL_TEXTURE_ENV, GL_ALPHA_SCALE, scale ); -#endif - } -} - // Useful for debugging that you've manually assigned a texture operation to the correct // texture unit based on the currently set active texture in opengl. void LLTexUnit::debugTextureUnit(void) @@ -908,13 +954,12 @@ bool LLRender::init(bool needs_vertex_buffer) void LLRender::initVertexBuffer() { llassert_always(mBuffer.isNull()); - stop_glerror(); mBuffer = new LLVertexBuffer(immediate_mask); - mBuffer->allocateBuffer(4096, 0); + mBuffer->allocateBuffer(16384, 0); mBuffer->getVertexStrider(mVerticesp); mBuffer->getTexCoord0Strider(mTexcoordsp); mBuffer->getColorStrider(mColorsp); - stop_glerror(); + LOG_GLERROR("LLRender::initVertexBuffer()"); } void LLRender::resetVertexBuffer() @@ -1000,7 +1045,6 @@ void LLRender::syncLightState() void LLRender::syncMatrices() { - STOP_GLERROR; LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; static const U32 name[] = @@ -1145,7 +1189,7 @@ void LLRender::syncMatrices() syncLightState(); } } - STOP_GLERROR; + LOG_GLERROR("LLRender::syncMatrices()"); } void LLRender::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z) @@ -1299,9 +1343,7 @@ void LLRender::translateUI(F32 x, F32 y, F32 z) LL_ERRS() << "Need to push a UI translation frame before offsetting" << LL_ENDL; } - mUIOffset.back().mV[0] += x; - mUIOffset.back().mV[1] += y; - mUIOffset.back().mV[2] += z; + mUIOffset.back().add(LLVector4a(x, y, z)); } void LLRender::scaleUI(F32 x, F32 y, F32 z) @@ -1311,14 +1353,14 @@ void LLRender::scaleUI(F32 x, F32 y, F32 z) LL_ERRS() << "Need to push a UI transformation frame before scaling." << LL_ENDL; } - mUIScale.back().scaleVec(LLVector3(x,y,z)); + mUIScale.back().mul(LLVector4a(x, y, z)); } void LLRender::pushUIMatrix() { if (mUIOffset.empty()) { - mUIOffset.emplace_back(0.f,0.f,0.f); + mUIOffset.emplace_back(0.f); } else { @@ -1327,7 +1369,7 @@ void LLRender::pushUIMatrix() if (mUIScale.empty()) { - mUIScale.emplace_back(1.f,1.f,1.f); + mUIScale.emplace_back(1.f); } else { @@ -1349,18 +1391,20 @@ LLVector3 LLRender::getUITranslation() { if (mUIOffset.empty()) { - return LLVector3(0,0,0); + return LLVector3::zero; } - return mUIOffset.back(); + + return LLVector3(mUIOffset.back().getF32ptr()); } LLVector3 LLRender::getUIScale() { if (mUIScale.empty()) { - return LLVector3(1,1,1); + return LLVector3::all_one; } - return mUIScale.back(); + + return LLVector3(mUIScale.back().getF32ptr()); } @@ -1370,8 +1414,9 @@ void LLRender::loadUIIdentity() { LL_ERRS() << "Need to push UI translation frame before clearing offset." << LL_ENDL; } - mUIOffset.back().setVec(0,0,0); - mUIScale.back().setVec(1,1,1); + + mUIOffset.back().clear(); + mUIScale.back().splat(1); } void LLRender::setColorMask(bool writeColor, bool writeAlpha) @@ -1555,7 +1600,7 @@ void LLRender::begin(const GLuint& mode) mMode == LLRender::TRIANGLES || mMode == LLRender::POINTS) { - flush(); + flush("LLRender::begin"); } else if (mCount != 0) { @@ -1566,7 +1611,7 @@ void LLRender::begin(const GLuint& mode) } } -void LLRender::end() +void LLRender::end(std::string comment_) { if (mCount == 0) { @@ -1579,13 +1624,12 @@ void LLRender::end() mMode != LLRender::POINTS) || mCount > 2048) { - flush(); + flush("from end " + comment_); } } -void LLRender::flush() +void LLRender::flush(std::string comment_) { - STOP_GLERROR; if (mCount > 0) { LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; @@ -1654,9 +1698,16 @@ void LLRender::flush() } resetStriders(count); + + LOG_GLERROR("LLRender::flush() end " + comment_); } } +void LLRender::flush() +{ + flush(""); +} + LLVertexBuffer* LLRender::bufferfromCache(U32 attribute_mask, U32 count) { LLVertexBuffer *vb = nullptr; @@ -1751,9 +1802,11 @@ LLVertexBuffer* LLRender::genBuffer(U32 attribute_mask, S32 count) vb->setColorData(mColorsp.get()); } -#if LL_DARWIN + if(gGLManager.mIsApple && LLVertexBuffer::getVertexBufferMode() == 0) + { vb->unmapBuffer(); -#endif + } + vb->unbind(); return vb; @@ -1799,8 +1852,10 @@ void LLRender::vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat& z) } else { - LLVector3 vert = (LLVector3(x,y,z)+mUIOffset.back()).scaledVec(mUIScale.back()); - mVerticesp[mCount].set(vert.mV[VX], vert.mV[VY], vert.mV[VZ]); + LLVector4a vert(x, y, z); + vert.add(mUIOffset.back()); + vert.mul(mUIScale.back()); + mVerticesp[mCount] = vert; } mCount++; @@ -2026,7 +2081,8 @@ void LLRender::debugTexUnits(void) std::string active_enabled = "false"; for (U32 i = 0; i < mTexUnits.size(); i++) { - if (getTexUnit(i)->mCurrTexType != LLTexUnit::TT_NONE) + //if (getTexUnit(i)->mCurrTexType != LLTexUnit::TT_NONE) + if(1) { if (i == mCurrTextureUnitIndex) active_enabled = "true"; LL_INFOS("TextureUnit") << "TexUnit: " << i << " Enabled" << LL_ENDL; @@ -2044,8 +2100,19 @@ void LLRender::debugTexUnits(void) case LLTexUnit::TT_CUBE_MAP: LL_CONT << "Cube Map"; break; + case LLTexUnit::TT_CUBE_MAP_ARRAY: + LL_CONT << "Cube Map Array"; + break; + + case LLTexUnit::TT_MULTISAMPLE_TEXTURE: + LL_CONT << "Multisample Texture"; + break; + + case LLTexUnit::TT_TEXTURE_3D: + LL_CONT << "Texture 3D"; + break; default: - LL_CONT << "ARGH!!! NONE!"; + LL_CONT << "ARGH!!! NONE! -> type = " << getTexUnit(i)->mCurrTexType; break; } LL_CONT << ", Texture Bound: " << getTexUnit(i)->mCurrTexture << LL_ENDL; diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 97c47bcae9..e6ae3baac6 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -44,6 +44,7 @@ #include "llglheaders.h" #include "llmatrix4a.h" #include "glm/mat4x4.hpp" +#include <boost/align/aligned_allocator.hpp> #include <array> #include <list> @@ -214,11 +215,19 @@ public: // Warning: this stays set for the bound texture forever, // make sure you want to permanently change the address mode for the bound texture. void setTextureAddressMode(eTextureAddressMode mode); +/* + // MUST already be active and bound + void setTextureAddressModeFast(eTextureAddressMode mode, eTextureType tex_type); +*/ // Sets the filtering options used to sample the texture // Warning: this stays set for the bound texture forever, // make sure you want to permanently change the filtering for the bound texture. void setTextureFilteringOption(LLTexUnit::eTextureFilterOptions option); +/* + // MUST already be active and bound + void setTextureFilteringOptionFast(LLTexUnit::eTextureFilterOptions option, eTextureType tex_type); +*/ static U32 getInternalType(eTextureType type); @@ -234,13 +243,9 @@ protected: S32 mIndex; U32 mCurrTexture; eTextureType mCurrTexType; - S32 mCurrColorScale; - S32 mCurrAlphaScale; bool mHasMipMaps; void debugTextureUnit(void); - void setColorScale(S32 scale); - void setAlphaScale(S32 scale); GLint getTextureSource(eTextureBlendSrc src); GLint getTextureSourceType(eTextureBlendSrc src, bool isAlpha = false); }; @@ -421,6 +426,7 @@ public: LLVector3 getUITranslation(); LLVector3 getUIScale(); + void flush(std::string comment_); void flush(); // if list is set, will store buffers in list for later use, if list isn't set, will use cache @@ -428,7 +434,7 @@ public: void endList(); void begin(const GLuint& mode); - void end(); + void end(std::string comment_ = ""); U8 getMode() const { return mMode; } @@ -533,8 +539,8 @@ private: eBlendFactor mCurrBlendAlphaSFactor; eBlendFactor mCurrBlendAlphaDFactor; - std::vector<LLVector3> mUIOffset; - std::vector<LLVector3> mUIScale; + std::vector<LLVector4a, boost::alignment::aligned_allocator<LLVector4a, 16> > mUIOffset; + std::vector<LLVector4a, boost::alignment::aligned_allocator<LLVector4a, 16> > mUIScale; }; extern F32 gGLModelView[16]; diff --git a/indra/llrender/llrender2dutils.cpp b/indra/llrender/llrender2dutils.cpp index 9144ce6d62..714df863cd 100644 --- a/indra/llrender/llrender2dutils.cpp +++ b/indra/llrender/llrender2dutils.cpp @@ -833,8 +833,7 @@ void gl_line_3d( const LLVector3& start, const LLVector3& end, const LLColor4& c { gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], color.mV[VALPHA]); - gGL.flush(); - glLineWidth(2.5f); + LLRender2D::setLineWidth(2.5f); gGL.begin(LLRender::LINES); { diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 0e4aa2ee7a..ebdc609f94 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -158,6 +158,8 @@ void LLRenderTarget::setColorAttachment(LLImageGL* img, LLGLuint use_name) llassert(mTex.empty()); // mTex must be empty with this mode (binding target should be done via LLImageGL) llassert(!isBoundInStack()); + U32 target = getTarget(); + if (mFBO == 0) { glGenFramebuffers(1, (GLuint*)&mFBO); @@ -174,14 +176,14 @@ void LLRenderTarget::setColorAttachment(LLImageGL* img, LLGLuint use_name) mTex.push_back(use_name); - glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + glBindFramebuffer(target, mFBO); + glFramebufferTexture2D(target, GL_COLOR_ATTACHMENT0, LLTexUnit::getInternalType(mUsage), use_name, 0); stop_glerror(); check_framebuffer_status(); - glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); + glBindFramebuffer(target, sCurFBO); } void LLRenderTarget::releaseColorAttachment() @@ -194,6 +196,7 @@ void LLRenderTarget::releaseColorAttachment() glBindFramebuffer(GL_FRAMEBUFFER, mFBO); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, LLTexUnit::getInternalType(mUsage), 0, 0); glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); + LOG_GLERROR(mName + " releaseColorAttachment()"); mTex.clear(); } @@ -208,6 +211,8 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) return true; } + U32 target = getTarget(); + U32 offset = static_cast<U32>(mTex.size()); if( offset >= 4 ) @@ -226,12 +231,76 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) LLImageGL::generateTextures(1, &tex); gGL.getTexUnit(0)->bindManual(mUsage, tex); - stop_glerror(); - + U32 miplevel = mMipLevels; + U32 intformat = color_fmt; + U32 pixformat = GL_RGBA; + U32 pixtype = GL_UNSIGNED_BYTE; { - clear_glerror(); - LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false); + //clear_glerror(); + + if(color_fmt == GL_RGB10_A2) + { + pixformat = GL_RGBA; + pixtype = GL_UNSIGNED_BYTE; + } + else if(color_fmt == GL_R11F_G11F_B10F) + { + pixformat = GL_RGB; + pixtype = GL_HALF_FLOAT; + } + else if(color_fmt == GL_R8) + { + pixformat = GL_RED; + pixtype = GL_UNSIGNED_BYTE; + } + else if(color_fmt == GL_R16F) + { + pixformat = GL_RED; + pixtype = GL_HALF_FLOAT; + } + else if(color_fmt == GL_RG16F) + { + pixformat = GL_RG; + pixtype = GL_HALF_FLOAT; + } + else if(color_fmt == GL_RGBA16F) + { + pixformat = GL_RGBA; + pixtype = GL_HALF_FLOAT; + } + else if(color_fmt == GL_RGB16F) + { + pixformat = GL_RGB; + pixtype = GL_HALF_FLOAT; + } + else if(color_fmt == GL_RGB8) + { + pixformat = GL_RGB; + pixtype = GL_UNSIGNED_BYTE; + } + else if(color_fmt == GL_RGB) + { + pixformat = GL_RGB; + pixtype = GL_UNSIGNED_BYTE; + } + else if(color_fmt == GL_RGBA) + { + pixformat = GL_RGBA; + pixtype = GL_UNSIGNED_BYTE; + } + else if(color_fmt == GL_RGBA8) + { + pixformat = GL_RGBA; + pixtype = GL_UNSIGNED_BYTE; + } + else + { + pixformat = GL_RGBA; + pixtype = GL_UNSIGNED_BYTE; + } + + LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, pixformat, pixtype, NULL, false); if (glGetError() != GL_NO_ERROR) { LL_WARNS() << "Could not allocate color buffer for render target." << LL_ENDL; @@ -241,32 +310,29 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) sBytesAllocated += mResX*mResY*4; - stop_glerror(); - - if (offset == 0) { //use bilinear filtering on single texture render targets that aren't multisampled gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR); - stop_glerror(); + LOG_GLERROR(mName + " setting filtering to TFO_BILINEAR"); } else { //don't filter data attachments gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); - stop_glerror(); + LOG_GLERROR(mName + " setting filtering to TFO_POINT"); } #if GL_VERSION_3_1 if (mUsage != LLTexUnit::TT_RECT_TEXTURE) { gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_MIRROR); - stop_glerror(); + LOG_GLERROR(mName + " setting address mode to TAM_MIRROR"); } else #endif { // ATI doesn't support mirrored repeat for rectangular textures. gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); - stop_glerror(); + LOG_GLERROR(mName + " setting address mode to TAM_CLAMP"); } if (mFBO) @@ -285,7 +351,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) if (gDebugGL) { //bind and unbind to validate target - bindTarget(); + bindTarget(mName, mMode); flush(); } @@ -300,8 +366,6 @@ bool LLRenderTarget::allocateDepth() gGL.getTexUnit(0)->bindManual(mUsage, mDepth); U32 internal_type = LLTexUnit::getInternalType(mUsage); - stop_glerror(); - clear_glerror(); LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); @@ -309,7 +373,7 @@ bool LLRenderTarget::allocateDepth() if (glGetError() != GL_NO_ERROR) { - LL_WARNS() << "Unable to allocate depth buffer for render target." << LL_ENDL; + LL_WARNS() << "Unable to allocate depth buffer for render target " << mName << LL_ENDL; return false; } @@ -345,6 +409,8 @@ void LLRenderTarget::shareDepthBuffer(LLRenderTarget& target) glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); + LOG_GLERROR(mName + " shareDepthBuffer()"); + target.mUseDepth = true; } } @@ -408,19 +474,32 @@ void LLRenderTarget::release() LLImageGL::deleteTextures(1, &mTex[0]); } + LOG_GLERROR(mName + " release()"); + mTex.clear(); mInternalFormat.clear(); mResX = mResY = 0; } -void LLRenderTarget::bindTarget() +void LLRenderTarget::bindTarget(std::string name_, U32 mode_) { LL_PROFILE_GPU_ZONE("bindTarget"); llassert(mFBO); llassert(!isBoundInStack()); - glBindFramebuffer(GL_FRAMEBUFFER, mFBO); + //mode_ = 0; + + mMode = mode_; + mName = name_; + + U32 target = getTarget(); + + glBindFramebuffer(target, mFBO); + LOG_GLERROR(mName+" bindTarget()"); + + //attach(); + sCurFBO = mFBO; //setup multiple render targets @@ -431,16 +510,32 @@ void LLRenderTarget::bindTarget() if (mTex.empty()) { //no color buffer to draw to + if(!mUseDepth) LL_WARNS() << mName << " HAS NO COLOR BUFFER AND NO DEPTH!!" << LL_ENDL; GLenum buffers[] = {GL_NONE}; glDrawBuffers(0, buffers); glReadBuffer(GL_NONE); } - else + else if(mMode == 0) + { + glDrawBuffers(static_cast<GLsizei>(mTex.size()), drawbuffers); + glReadBuffer(GL_COLOR_ATTACHMENT0); + LOG_GLERROR(mName+" read and write buffers"); + } + else if(mMode == 1) { glDrawBuffers(static_cast<GLsizei>(mTex.size()), drawbuffers); + //glReadBuffer(GL_NONE); + LOG_GLERROR(mName+" draw buffer"); + } + else if(mMode == 2) + { + //glDrawBuffer(GL_NONE); glReadBuffer(GL_COLOR_ATTACHMENT0); + LOG_GLERROR(mName+" read buffer"); } + check_framebuffer_status(); + LOG_GLERROR(mName+" checked status"); glViewport(0, 0, mResX, mResY); sCurResX = mResX; @@ -454,7 +549,9 @@ void LLRenderTarget::clear(U32 mask_in) { LL_PROFILE_GPU_ZONE("clear"); llassert(mFBO); - U32 mask = GL_COLOR_BUFFER_BIT; + U32 mask = 0; + + if(!mTex.empty()) mask |= GL_COLOR_BUFFER_BIT; if (mUseDepth) { mask |= GL_DEPTH_BUFFER_BIT; @@ -463,15 +560,14 @@ void LLRenderTarget::clear(U32 mask_in) if (mFBO) { check_framebuffer_status(); - stop_glerror(); glClear(mask & mask_in); - stop_glerror(); + LOG_GLERROR(mName + "clear()"); } else { LLGLEnable scissor(GL_SCISSOR_TEST); glScissor(0, 0, mResX, mResY); - stop_glerror(); + LOG_GLERROR(""); glClear(mask & mask_in); } } @@ -495,48 +591,44 @@ U32 LLRenderTarget::getNumTextures() const void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options) { gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index), filter_options == LLTexUnit::TFO_TRILINEAR || filter_options == LLTexUnit::TFO_ANISOTROPIC); - - bool isSRGB = false; - llassert(mInternalFormat.size() > index); - switch (mInternalFormat[index]) - { - case GL_SRGB: - case GL_SRGB8: -#if GL_VERSION_2_1 - case GL_SRGB_ALPHA: -#endif - case GL_SRGB8_ALPHA8: - isSRGB = true; - break; - - default: - break; - } - gGL.getTexUnit(channel)->setTextureFilteringOption(filter_options); + + LOG_GLERROR(mName + " bindTexture()"); } void LLRenderTarget::flush() { LL_PROFILE_GPU_ZONE("rt flush"); + + LOG_GLERROR(mName+" rt flush() A"); + gGL.flush(); llassert(mFBO); llassert(sCurFBO == mFBO); llassert(sBoundTarget == this); - if (mGenerateMipMaps == LLTexUnit::TMG_AUTO) + if (mGenerateMipMaps == LLTexUnit::TMG_AUTO && mMode != 2) { LL_PROFILE_GPU_ZONE("rt generate mipmaps"); - bindTexture(0, 0, LLTexUnit::TFO_TRILINEAR); + //bindTexture(0, 0, LLTexUnit::TFO_TRILINEAR); + bindTexture(0, 0, LLTexUnit::TFO_ANISOTROPIC); glGenerateMipmap(GL_TEXTURE_2D); + LOG_GLERROR(mName + " glGenerateMipmap()"); } + LOG_GLERROR(mName + " rt flush() B"); + + unbind(); +} + +void LLRenderTarget::unbind() +{ if (mPreviousRT) { // a bit hacky -- pop the RT stack back two frames and push // the previous frame back on to play nice with the GL state machine sBoundTarget = mPreviousRT->mPreviousRT; - mPreviousRT->bindTarget(); + mPreviousRT->bindTarget(mPreviousRT->mName, mPreviousRT->mMode); } else { @@ -547,9 +639,10 @@ void LLRenderTarget::flush() sCurResX = gGLViewport[2]; sCurResY = gGLViewport[3]; glReadBuffer(GL_BACK); - GLenum drawbuffers[] = {GL_BACK}; - glDrawBuffers(1, drawbuffers); + glDrawBuffer(GL_BACK); } + + LOG_GLERROR(mName + " rt unbind()"); } bool LLRenderTarget::isComplete() const @@ -604,3 +697,13 @@ void LLRenderTarget::swapFBORefs(LLRenderTarget& other) std::swap(mFBO, other.mFBO); std::swap(mTex, other.mTex); } + +U32 LLRenderTarget::getTarget() +{ + U32 target = GL_FRAMEBUFFER; + + if(mMode == 1) target = GL_DRAW_FRAMEBUFFER; + else if(mMode == 2) target = GL_READ_FRAMEBUFFER; + + return target; +} diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h index cd3290cf66..ce3025f280 100644 --- a/indra/llrender/llrendertarget.h +++ b/indra/llrender/llrendertarget.h @@ -126,7 +126,7 @@ public: // If an LLRenderTarget is currently bound, stores a reference to that LLRenderTarget // and restores previous binding on flush() (maintains a stack of Render Targets) // Asserts that this target is not currently bound in the stack - void bindTarget(); + void bindTarget(std::string name_ = "nd", U32 mode_ = 0); //clear render targer, clears depth buffer if present, //uses scissor rect if in copy-to-texture mode @@ -158,6 +158,7 @@ public: // If an LLRenderTarget was bound when bindTarget was called, binds that RenderTarget for rendering (maintains RT stack) // asserts that this target is currently bound void flush(); + void unbind(); //Returns TRUE if target is ready to be rendered into. //That is, if the target has been allocated with at least @@ -174,11 +175,15 @@ public: static LLRenderTarget* sBoundTarget; + U32 mMode; + std::string mName; + protected: U32 mResX; U32 mResY; std::vector<U32> mTex; std::vector<U32> mInternalFormat; + std::vector<U32> mPixFormat; U32 mFBO; LLRenderTarget* mPreviousRT = nullptr; @@ -188,6 +193,10 @@ protected: U32 mMipLevels; LLTexUnit::eTextureType mUsage; + +private: + U32 getTarget(); + }; #endif diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 4807c12226..ea8530f282 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -263,6 +263,7 @@ bool LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } + /* if (features->hasGamma || features->isDeferred) { if (!shader->attachFragmentObject("windlight/gammaF.glsl")) @@ -270,6 +271,7 @@ bool LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) return false; } } + */ if (features->hasAtmospherics || features->isDeferred) { @@ -458,7 +460,7 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev // endsure work-around for missing GLSL funcs gets propogated to feature shader files (e.g. srgbF.glsl) #if LL_DARWIN - if (defines) + if (!gGLManager.mIsApple && defines) { (*defines)["OLD_SELECT"] = "1"; } @@ -571,7 +573,7 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev } else { - shader_code_text[shader_code_count++] = strdup("#version 400\n"); + shader_code_text[shader_code_count++] = strdup("#version 410\n"); } } else if (major_version == 3) @@ -989,16 +991,17 @@ bool LLShaderMgr::validateProgramObject(GLuint obj) return success; } -void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version) +void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version, bool second_instance) { - LL_INFOS() << "Initializing shader cache" << LL_ENDL; + LL_PROFILE_ZONE_SCOPED; + LL_INFOS("ShaderMgr") << "Initializing shader cache" << LL_ENDL; mShaderCacheEnabled = gGLManager.mGLVersion >= 4.09 && enabled; - if(!mShaderCacheEnabled || mShaderCacheInitialized) + if(!mShaderCacheEnabled || mShaderCacheVersion.notNull()) return; - mShaderCacheInitialized = true; + mShaderCacheVersion = current_cache_version; mShaderCacheDir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "shader_cache"); LLFile::mkdir(mShaderCacheDir); @@ -1007,16 +1010,19 @@ void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version, std::string meta_out_path = gDirUtilp->add(mShaderCacheDir, "shaderdata.llsd"); if (gDirUtilp->fileExists(meta_out_path)) { - LL_INFOS() << "Loading shader cache metadata" << LL_ENDL; + LL_PROFILE_ZONE_NAMED("shader_cache"); + LL_INFOS("ShaderMgr") << "Loading shader cache metadata" << LL_ENDL; - llifstream instream(meta_out_path); + llifstream instream(meta_out_path, std::ifstream::in | std::ifstream::binary); LLSD in_data; - LLSDSerialize::fromNotation(in_data, instream, LLSDSerialize::SIZE_UNLIMITED); + // todo: this is likely very expensive to parse, should use binary + LLSDSerialize::fromBinary(in_data, instream, LLSDSerialize::SIZE_UNLIMITED); instream.close(); - if (old_cache_version == current_cache_version) + if (old_cache_version == current_cache_version + && in_data["version"].asUUID() == current_cache_version) { - for (const auto& data_pair : llsd::inMap(in_data)) + for (const auto& data_pair : llsd::inMap(in_data["shaders"])) { ProgramBinaryData binary_info = ProgramBinaryData(); binary_info.mBinaryFormat = data_pair.second["binary_format"].asInteger(); @@ -1025,11 +1031,15 @@ void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version, mShaderBinaryCache.insert_or_assign(LLUUID(data_pair.first), binary_info); } } - else + else if (!second_instance) { - LL_INFOS() << "Shader cache version mismatch detected. Purging." << LL_ENDL; + LL_INFOS("ShaderMgr") << "Shader cache version mismatch detected. Purging." << LL_ENDL; clearShaderCache(); } + else + { + LL_INFOS("ShaderMgr") << "Shader cache version mismatch detected." << LL_ENDL; + } } } } @@ -1037,19 +1047,32 @@ void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version, void LLShaderMgr::clearShaderCache() { std::string shader_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "shader_cache"); - LL_INFOS() << "Removing shader cache at " << shader_cache << LL_ENDL; + LL_INFOS("ShaderMgr") << "Removing shader cache at " << shader_cache << LL_ENDL; const std::string mask = "*"; gDirUtilp->deleteFilesInDir(shader_cache, mask); + LLFile::rmdir(shader_cache); mShaderBinaryCache.clear(); } void LLShaderMgr::persistShaderCacheMetadata() { if(!mShaderCacheEnabled) return; + if (mShaderCacheVersion.isNull()) + { + LL_WARNS("ShaderMgr") << "Attempted to save shader cache with no version set" << LL_ENDL; + return; + } - LL_INFOS() << "Persisting shader cache metadata to disk" << LL_ENDL; + LL_INFOS("ShaderMgr") << "Persisting shader cache metadata to disk" << LL_ENDL; - LLSD out = LLSD::emptyMap(); + LLSD out; + // Settings and shader cache get saved at different time, thus making + // RenderShaderCacheVersion unreliable when running multiple viewer + // instances, or for cases where viewer crashes before saving settings. + // Dupplicate version to the cache itself. + out["version"] = mShaderCacheVersion; + out["shaders"] = LLSD::emptyMap(); + LLSD &shaders = out["shaders"]; static const F32 LRU_TIME = (60.f * 60.f) * 24.f * 7.f; // 14 days const F32 current_time = (F32)LLTimer::getTotalSeconds(); @@ -1068,14 +1091,19 @@ void LLShaderMgr::persistShaderCacheMetadata() data["binary_format"] = LLSD::Integer(shader_metadata.mBinaryFormat); data["binary_size"] = LLSD::Integer(shader_metadata.mBinaryLength); data["last_used"] = LLSD::Real(shader_metadata.mLastUsedTime); - out[it->first.asString()] = data; + shaders[it->first.asString()] = data; ++it; } } std::string meta_out_path = gDirUtilp->add(mShaderCacheDir, "shaderdata.llsd"); - llofstream outstream(meta_out_path); - LLSDSerialize::toNotation(out, outstream); + llofstream outstream(meta_out_path, std::ios_base::out | std::ios_base::binary); + if (!outstream.is_open()) + { + LL_WARNS("ShaderMgr") << "Failed to open file. Unable to save shader cache to: " << mShaderCacheDir << LL_ENDL; + return; + } + LLSDSerialize::toBinary(out, outstream); outstream.close(); } @@ -1501,6 +1529,20 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("searchTex"); mReservedUniforms.push_back("blendTex"); + mReservedUniforms.push_back("bloomEMap"); + mReservedUniforms.push_back("bloomBlurredMap"); + mReservedUniforms.push_back("bloomHorizontal"); + mReservedUniforms.push_back("bloomBlurRadius"); + mReservedUniforms.push_back("bloomExtractBrightness"); + mReservedUniforms.push_back("bloomStrength"); + mReservedUniforms.push_back("bloomExtractEmissive"); + mReservedUniforms.push_back("bloomExtractEmissive2"); + mReservedUniforms.push_back("bloomExtractORM"); + mReservedUniforms.push_back("bloomExtractMetal"); + mReservedUniforms.push_back("bloomExtractNonMetal"); + mReservedUniforms.push_back("bloomClampValue"); + mReservedUniforms.push_back("mpHDRBoost"); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); std::set<std::string> dupe_check; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 46788841a5..4cfa78632b 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -341,6 +341,20 @@ public: SMAA_SEARCH_TEX, // "searchTex" SMAA_BLEND_TEX, // "blendTex" + BLOOM_EMAP, // "bloomEMap" + BLOOM_BMAP, // "bloomBlurredMap" + BLOOM_BLURH, // "bloomHorizontal" + BLOOM_BLUR_RADIUS, // "bloomRadius" + BLOOM_EXTRACT_BRIGHTNESS, // "bloomExtractBrightness" + BLOOM_STRENGTH, // "bloomStrength" + BLOOM_EXTRACT_EMISSIVE, // "bloomExtractEmissive" + BLOOM_EXTRACT_EMISSIVE2, // "bloomExtractEmissive2" + BLOOM_EXTRACT_ORM, // "bloomExtractORM" + BLOOM_EXTRACT_METAL, // "bloomExtractMetal" + BLOOM_EXTRACT_NONMETAL, // "bloomExtractNonMetal" + BLOOM_CLAMP, // "bloomClampValue" + MP_HDR_BOOST, // "mpHDRBoost" + END_RESERVED_UNIFORMS } eGLSLReservedUniforms; // clang-format on @@ -363,7 +377,7 @@ public: // Implemented in the application to actually update out of date uniforms for a particular shader virtual void updateShaderUniforms(LLGLSLShader * shader) = 0; // Pure Virtual - void initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version); + void initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version, bool second_instance); void clearShaderCache(); void persistShaderCacheMetadata(); @@ -387,7 +401,7 @@ public: F32 mLastUsedTime = 0.0; }; std::map<LLUUID, ProgramBinaryData> mShaderBinaryCache; - bool mShaderCacheInitialized = false; + LLUUID mShaderCacheVersion; bool mShaderCacheEnabled = false; std::string mShaderCacheDir; diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index ac6db0b34f..4b62c3476f 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -29,7 +29,6 @@ #include "llfasttimer.h" #include "llsys.h" #include "llvertexbuffer.h" -// #include "llrender.h" #include "llglheaders.h" #include "llrender.h" #include "llvector4a.h" @@ -272,13 +271,13 @@ static GLuint gen_buffer() { LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen buffer"); sIndex = pool_size; -#if !LL_DARWIN +//#if !LL_DARWIN if (!gGLManager.mIsAMD) { glGenBuffers(pool_size, sNamePool); } else -#endif +//#endif { // work around for AMD driver bug for (U32 i = 0; i < pool_size; ++i) { @@ -345,7 +344,7 @@ public: void allocate(GLenum type, U32 size, GLuint& name, U8*& data) override { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - STOP_GLERROR; + llassert(type == GL_ARRAY_BUFFER || type == GL_ELEMENT_ARRAY_BUFFER); llassert(name == 0); // non zero name indicates a gl name that wasn't freed llassert(data == nullptr); // non null data indicates a buffer that wasn't freed @@ -355,10 +354,18 @@ public: { //allocate a new buffer LL_PROFILE_GPU_ZONE("vbo alloc"); - // ON OS X, we don't allocate a VBO until the last possible moment - // in unmapBuffer data = (U8*) ll_aligned_malloc_16(size); - STOP_GLERROR; + + if (type == GL_ARRAY_BUFFER) + { + glGenBuffers(1, &name); + LLVertexBuffer::sGLRenderBuffer = name; + } + else + { + glGenBuffers(1, &name); + LLVertexBuffer::sGLRenderIndices = name; + } } } @@ -374,12 +381,11 @@ public: } mAllocated -= size; - STOP_GLERROR; if (name) { delete_buffers(1, &name); } - STOP_GLERROR; + //LOG_GLERROR("LLAppleVBOPool::free()"); } }; @@ -606,6 +612,8 @@ public: static LLVBOPool* sVBOPool = nullptr; +static U32 sMPVertexBufferMode = 0; + void LLVertexBufferData::drawWithMatrix() { if (!mVB) @@ -783,16 +791,9 @@ void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVecto LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; llassert(LLGLSLShader::sCurBoundShaderPtr != NULL); - STOP_GLERROR; gGL.syncMatrices(); - U32 mask = LLVertexBuffer::MAP_VERTEX; - if (tc) - { - mask = mask | LLVertexBuffer::MAP_TEXCOORD0; - } - unbind(); gGL.begin(mode); @@ -885,7 +886,7 @@ bool LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of return true; } -#ifdef LL_PROFILER_ENABLE_RENDER_DOC +#if LL_PROFILER_ENABLE_RENDER_DOC void LLVertexBuffer::setLabel(const char* label) { LL_LABEL_OBJECT_GL(GL_BUFFER, mGLBuffer, strlen(label), label); } @@ -909,10 +910,8 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi llassert(mGLBuffer == sGLRenderBuffer); llassert(mGLIndices == sGLRenderIndices); gGL.syncMatrices(); - STOP_GLERROR; glDrawRangeElements(sGLMode[mode], start, end, count, mIndicesType, (GLvoid*) (indices_offset * (size_t) mIndicesStride)); - STOP_GLERROR; } void LLVertexBuffer::drawRangeFast(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const @@ -935,17 +934,18 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const llassert(mGLIndices == sGLRenderIndices); gGL.syncMatrices(); - STOP_GLERROR; glDrawArrays(sGLMode[mode], first, count); - STOP_GLERROR; + LOG_GLERROR("LLVertexBuffer::drawArrays()"); } //static -void LLVertexBuffer::initClass(LLWindow* window) +void LLVertexBuffer::initClass(LLWindow* window, U32 mode_) { llassert(sVBOPool == nullptr); - if (gGLManager.mIsApple) + sMPVertexBufferMode = mode_; + + if (mode_ == 0 && gGLManager.mIsApple) { LL_INFOS() << "VBO Pooling Disabled" << LL_ENDL; sVBOPool = new LLAppleVBOPool(); @@ -968,12 +968,16 @@ void LLVertexBuffer::initClass(LLWindow* window) } //static +U32 LLVertexBuffer::getVertexBufferMode() +{ + return sMPVertexBufferMode; +} + +//static void LLVertexBuffer::unbind() { - STOP_GLERROR; glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - STOP_GLERROR; sGLRenderBuffer = 0; sGLRenderIndices = 0; } @@ -1288,7 +1292,7 @@ U8* LLVertexBuffer::mapVertexBuffer(LLVertexBuffer::AttributeType type, U32 inde count = mNumVerts - index; } - if (!gGLManager.mIsApple) + if (!gGLManager.mIsApple || sMPVertexBufferMode == 1) { U32 start = mOffsets[type] + sTypeSize[type] * index; U32 end = start + sTypeSize[type] * count-1; @@ -1325,7 +1329,7 @@ U8* LLVertexBuffer::mapIndexBuffer(U32 index, S32 count) count = mNumIndices-index; } - if (!gGLManager.mIsApple) + if (!gGLManager.mIsApple || sMPVertexBufferMode == 1) { U32 start = sizeof(U16) * index; U32 end = start + sizeof(U16) * count-1; @@ -1362,13 +1366,35 @@ void LLVertexBuffer::flush_vbo(GLenum target, U32 start, U32 end, void* data, U8 { if (gGLManager.mIsApple) { + if(sMPVertexBufferMode == 1) + { + //LL_WARNS() << "flush_vbo mode 1" << LL_ENDL; + + U32 MapBits = GL_MAP_WRITE_BIT; + //U32 MapBits = GL_MAP_READ_BIT; + U32 buffer_size = end-start+1; + + U8 * mptr = NULL; + mptr = (U8*) glMapBufferRange( target, start, end-start+1, MapBits); + + if (mptr) + { + std::memcpy(mptr, (U8*) data, buffer_size); + if(!glUnmapBuffer(target)) LL_WARNS() << "glUnmapBuffer() failed" << LL_ENDL; + } + else LL_WARNS() << "glMapBufferRange() returned NULL" << LL_ENDL; + + } + else + { + //LL_WARNS() << "flush_vbo mode 0" << LL_ENDL; // on OS X, flush_vbo doesn't actually write to the GL buffer, so be sure to call // _mapBuffer to tag the buffer for flushing to GL _mapBuffer(); LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("vb memcpy"); - STOP_GLERROR; // copy into mapped buffer memcpy(dst+start, data, end-start+1); + } } else { @@ -1412,7 +1438,6 @@ void LLVertexBuffer::_mapBuffer() void LLVertexBuffer::_unmapBuffer() { - STOP_GLERROR; if (!mMapped) { return; @@ -1426,16 +1451,16 @@ void LLVertexBuffer::_unmapBuffer() } }; - if (gGLManager.mIsApple) + if (gGLManager.mIsApple && sMPVertexBufferMode == 0) { - STOP_GLERROR; + LOG_GLERROR("LLVertexBuffer::_unmapBuffer() - apple 1"); if (mMappedData) { - if (mGLBuffer) + if(mGLBuffer == 0) { - delete_buffers(1, &mGLBuffer); + LL_WARNS() << "mGLBuffer is ZERO in unmapbuffer" << LL_ENDL; + glGenBuffers(1, &mGLBuffer); } - mGLBuffer = gen_buffer(); glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); sGLRenderBuffer = mGLBuffer; glBufferData(GL_ARRAY_BUFFER, mSize, mMappedData, GL_STATIC_DRAW); @@ -1445,16 +1470,16 @@ void LLVertexBuffer::_unmapBuffer() glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); sGLRenderBuffer = mGLBuffer; } - STOP_GLERROR; + LOG_GLERROR("LLVertexBuffer::_unmapBuffer() - apple 2"); if (mMappedIndexData) { - if (mGLIndices) + if (mGLIndices == 0) { - delete_buffers(1, &mGLIndices); + LL_WARNS() << "mGLIndices is ZERO in unmapbuffer" << LL_ENDL; + glGenBuffers(1, &mGLIndices); } - mGLIndices = gen_buffer(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); sGLRenderIndices = mGLIndices; @@ -1465,7 +1490,7 @@ void LLVertexBuffer::_unmapBuffer() glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); sGLRenderIndices = mGLIndices; } - STOP_GLERROR; + LOG_GLERROR("LLVertexBuffer::_unmapBuffer() - apple 3"); } else { @@ -1656,11 +1681,10 @@ bool LLVertexBuffer::getClothWeightStrider(LLStrider<LLVector4>& strider, U32 in // Set for rendering void LLVertexBuffer::setBuffer() { - STOP_GLERROR; if (mMapped) { - LL_WARNS_ONCE() << "Missing call to unmapBuffer or flushBuffers" << LL_ENDL; + LL_WARNS() << "Missing call to unmapBuffer or flushBuffers" << LL_ENDL; _unmapBuffer(); } @@ -1680,6 +1704,11 @@ void LLVertexBuffer::setBuffer() if (sGLRenderBuffer != mGLBuffer) { + if(mGLBuffer == 0) + { + LL_WARNS() << "mGLBuffer is ZERO: sGLRenderBuffer=" << sGLRenderBuffer << LL_ENDL; + } + glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); sGLRenderBuffer = mGLBuffer; @@ -1697,113 +1726,141 @@ void LLVertexBuffer::setBuffer() sGLRenderIndices = mGLIndices; } - STOP_GLERROR; + LOG_GLERROR("LLVertexBuffer::setBuffer()"); } // virtual (default) void LLVertexBuffer::setupVertexBuffer() { - STOP_GLERROR; + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer()"); U8* base = nullptr; - AttributeType loc; - void* ptr = nullptr; - U32 data_mask = LLGLSLShader::sCurBoundShaderPtr->mAttributeMask; if (data_mask & MAP_NORMAL) { - loc = TYPE_NORMAL; - ptr = (void*)(base + mOffsets[TYPE_NORMAL]); + AttributeType loc = TYPE_NORMAL; + void* ptr = (void*)(base + mOffsets[TYPE_NORMAL]); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_NORMAL"); } if (data_mask & MAP_TEXCOORD3) { - loc = TYPE_TEXCOORD3; - ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]); + AttributeType loc = TYPE_TEXCOORD3; + void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_TEXCOORD3"); } if (data_mask & MAP_TEXCOORD2) { - loc = TYPE_TEXCOORD2; - ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]); + AttributeType loc = TYPE_TEXCOORD2; + void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_TEXCOORD2"); } if (data_mask & MAP_TEXCOORD1) { - loc = TYPE_TEXCOORD1; - ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]); + AttributeType loc = TYPE_TEXCOORD1; + void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_TEXCOORD1"); } if (data_mask & MAP_TANGENT) { - loc = TYPE_TANGENT; - ptr = (void*)(base + mOffsets[TYPE_TANGENT]); + AttributeType loc = TYPE_TANGENT; + void* ptr = (void*)(base + mOffsets[TYPE_TANGENT]); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TANGENT], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_TANGENT"); } if (data_mask & MAP_TEXCOORD0) { - loc = TYPE_TEXCOORD0; - ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]); + AttributeType loc = TYPE_TEXCOORD0; + //glEnableVertexAttribArray(loc); + void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_TEXCOORD0"); } if (data_mask & MAP_COLOR) { - loc = TYPE_COLOR; + AttributeType loc = TYPE_COLOR; //bind emissive instead of color pointer if emissive is present - ptr = (data_mask & MAP_EMISSIVE) ? (void*)(base + mOffsets[TYPE_EMISSIVE]) : (void*)(base + mOffsets[TYPE_COLOR]); + void* ptr = (data_mask & MAP_EMISSIVE) ? (void*)(base + mOffsets[TYPE_EMISSIVE]) : (void*)(base + mOffsets[TYPE_COLOR]); glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_COLOR"); } if (data_mask & MAP_EMISSIVE) { - loc = TYPE_EMISSIVE; - ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]); + AttributeType loc = TYPE_EMISSIVE; + void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]); glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_EMISSIVE"); + if (!(data_mask & MAP_COLOR)) { //map emissive to color channel when color is not also being bound to avoid unnecessary shader swaps loc = TYPE_COLOR; glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_COLOR"); } } if (data_mask & MAP_WEIGHT) { - loc = TYPE_WEIGHT; - ptr = (void*)(base + mOffsets[TYPE_WEIGHT]); + AttributeType loc = TYPE_WEIGHT; + void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT]); glVertexAttribPointer(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_WEIGHT"); } if (data_mask & MAP_WEIGHT4) { - loc = TYPE_WEIGHT4; - ptr = (void*)(base + mOffsets[TYPE_WEIGHT4]); + AttributeType loc = TYPE_WEIGHT4; + void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT4]); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_WEIGHT4"); } if (data_mask & MAP_JOINT) { - loc = TYPE_JOINT; - ptr = (void*)(base + mOffsets[TYPE_JOINT]); + AttributeType loc = TYPE_JOINT; + void* ptr = (void*)(base + mOffsets[TYPE_JOINT]); glVertexAttribIPointer(loc, 4, GL_UNSIGNED_SHORT, LLVertexBuffer::sTypeSize[TYPE_JOINT], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_JOINT"); } if (data_mask & MAP_CLOTHWEIGHT) { - loc = TYPE_CLOTHWEIGHT; - ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]); + AttributeType loc = TYPE_CLOTHWEIGHT; + void* ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_CLOTHWEIGHT"); } + if (data_mask & MAP_TEXTURE_INDEX) { - loc = TYPE_TEXTURE_INDEX; - ptr = (void*)(base + mOffsets[TYPE_VERTEX] + 12); + AttributeType loc = TYPE_TEXTURE_INDEX; + void* ptr = (void*)(base + mOffsets[TYPE_VERTEX] + 12); glVertexAttribIPointer(loc, 1, GL_UNSIGNED_INT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_TEXTURE_INDEX"); } if (data_mask & MAP_VERTEX) { - loc = TYPE_VERTEX; - ptr = (void*)(base + mOffsets[TYPE_VERTEX]); + AttributeType loc = TYPE_VERTEX; + void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); + + LOG_GLERROR("LLVertexBuffer::setupVertexBuffer TYPE_VERTEX"); } - STOP_GLERROR; } void LLVertexBuffer::setPositionData(const LLVector4a* data) @@ -1917,3 +1974,7 @@ void LLVertexBuffer::setIndexData(const U32* data, U32 offset, U32 count) } flush_vbo(GL_ELEMENT_ARRAY_BUFFER, offset * sizeof(U32), (offset + count) * sizeof(U32) - 1, (U8*)data, mMappedIndexData); } + + + + diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h index 375ad76fb8..b0f6ae7d8d 100644 --- a/indra/llrender/llvertexbuffer.h +++ b/indra/llrender/llvertexbuffer.h @@ -109,7 +109,7 @@ public: return *this; } - static void initClass(LLWindow* window); + static void initClass(LLWindow* window, U32 mode_ = 0); static void cleanupClass(); static void setupClientArrays(U32 data_mask); static void drawArrays(U32 mode, const std::vector<LLVector3>& pos); @@ -128,6 +128,8 @@ public: // flush any pending mapped buffers static void flushBuffers(); + static U32 getVertexBufferMode(); + //WARNING -- when updating these enums you MUST // 1 - update LLVertexBuffer::sTypeSize // 2 - update LLVertexBuffer::vb_type_name @@ -279,7 +281,7 @@ public: //for debugging, validate data in given range is valid bool validateRange(U32 start, U32 end, U32 count, U32 offset) const; - #ifdef LL_PROFILER_ENABLE_RENDER_DOC + #if LL_PROFILER_ENABLE_RENDER_DOC void setLabel(const char* label); #endif @@ -340,7 +342,7 @@ public: static U32 sVertexCount; }; -#ifdef LL_PROFILER_ENABLE_RENDER_DOC +#if LL_PROFILER_ENABLE_RENDER_DOC #define LL_LABEL_VERTEX_BUFFER(buf, name) buf->setLabel(name) #else #define LL_LABEL_VERTEX_BUFFER(buf, name) |
