From 5ce0c5858c387346b7b8923ec55b4cee3f1c4d12 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Tue, 11 Mar 2025 00:40:36 -0400 Subject: #3409 Make maximum probe count adjustable. (#3709) * #3409 Make probe count adjustable to better accomodate low VRAM scenarios --- indra/newview/llreflectionmapmanager.cpp | 112 ++++++++++++------------------- 1 file changed, 43 insertions(+), 69 deletions(-) (limited to 'indra/newview/llreflectionmapmanager.cpp') diff --git a/indra/newview/llreflectionmapmanager.cpp b/indra/newview/llreflectionmapmanager.cpp index 9a20977652..48b73531ea 100644 --- a/indra/newview/llreflectionmapmanager.cpp +++ b/indra/newview/llreflectionmapmanager.cpp @@ -221,6 +221,14 @@ void LLReflectionMapManager::update() resume(); } + static LLCachedControl probe_count(gSavedSettings, "RenderReflectionProbeCount", 256U); + bool countReset = mReflectionProbeCount != probe_count; + + if (countReset) + { + mResetFade = -0.5f; + } + initReflectionMaps(); static LLCachedControl render_hdr(gSavedSettings, "RenderHDREnabled", true); @@ -335,6 +343,13 @@ void LLReflectionMapManager::update() } } + if (countReset) + { + mResetFade = -0.5f; + } + + mResetFade = llmin((F32)(mResetFade + gFrameIntervalSeconds), 1.f); + for (unsigned int i = 0; i < mProbes.size(); ++i) { LLReflectionMap* probe = mProbes[i]; @@ -1012,60 +1027,18 @@ void LLReflectionMapManager::updateUniforms() LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; - // structure for packing uniform buffer object - // see class3/deferred/reflectionProbeF.glsl - struct ReflectionProbeData - { - // for box probes, matrix that transforms from camera space to a [-1, 1] cube representing the bounding box of - // the box probe - LLMatrix4 refBox[LL_MAX_REFLECTION_PROBE_COUNT]; - - LLMatrix4 heroBox; - - // for sphere probes, origin (xyz) and radius (w) of refmaps in clip space - LLVector4 refSphere[LL_MAX_REFLECTION_PROBE_COUNT]; - - // extra parameters - // x - irradiance scale - // y - radiance scale - // z - fade in - // w - znear - LLVector4 refParams[LL_MAX_REFLECTION_PROBE_COUNT]; - - LLVector4 heroSphere; - - // indices used by probe: - // [i][0] - cubemap array index for this probe - // [i][1] - index into "refNeighbor" for probes that intersect this probe - // [i][2] - number of probes that intersect this probe, or -1 for no neighbors - // [i][3] - priority (probe type stored in sign bit - positive for spheres, negative for boxes) - GLint refIndex[LL_MAX_REFLECTION_PROBE_COUNT][4]; - - // list of neighbor indices - GLint refNeighbor[4096]; - - GLint refBucket[256][4]; //lookup table for which index to start with for the given Z depth - // numbrer of active refmaps - GLint refmapCount; - - GLint heroShape; - GLint heroMipCount; - GLint heroProbeCount; - }; mReflectionMaps.resize(mReflectionProbeCount); getReflectionMaps(mReflectionMaps); - ReflectionProbeData rpd; - F32 minDepth[256]; for (int i = 0; i < 256; ++i) { - rpd.refBucket[i][0] = mReflectionProbeCount; - rpd.refBucket[i][1] = mReflectionProbeCount; - rpd.refBucket[i][2] = mReflectionProbeCount; - rpd.refBucket[i][3] = mReflectionProbeCount; + mProbeData.refBucket[i][0] = mReflectionProbeCount; + mProbeData.refBucket[i][1] = mReflectionProbeCount; + mProbeData.refBucket[i][2] = mReflectionProbeCount; + mProbeData.refBucket[i][3] = mReflectionProbeCount; minDepth[i] = FLT_MAX; } @@ -1111,7 +1084,7 @@ void LLReflectionMapManager::updateUniforms() if (refmap->mMinDepth < minDepth[i]) { minDepth[i] = refmap->mMinDepth; - rpd.refBucket[i][0] = refmap->mProbeIndex; + mProbeData.refBucket[i][0] = refmap->mProbeIndex; } } } @@ -1139,25 +1112,25 @@ void LLReflectionMapManager::updateUniforms() } } modelview.affineTransform(refmap->mOrigin, oa); - rpd.refSphere[count].set(oa.getF32ptr()); - rpd.refSphere[count].mV[3] = refmap->mRadius; + mProbeData.refSphere[count].set(oa.getF32ptr()); + mProbeData.refSphere[count].mV[3] = refmap->mRadius; } - rpd.refIndex[count][0] = refmap->mCubeIndex; + mProbeData.refIndex[count][0] = refmap->mCubeIndex; llassert(nc % 4 == 0); - rpd.refIndex[count][1] = nc / 4; - rpd.refIndex[count][3] = refmap->mPriority; + mProbeData.refIndex[count][1] = nc / 4; + mProbeData.refIndex[count][3] = refmap->mPriority; // for objects that are reflection probes, use the volume as the influence volume of the probe // only possibile influence volumes are boxes and spheres, so detect boxes and treat everything else as spheres - if (refmap->getBox(rpd.refBox[count])) + if (refmap->getBox(mProbeData.refBox[count])) { // negate priority to indicate this probe has a box influence volume - rpd.refIndex[count][3] = -rpd.refIndex[count][3]; + mProbeData.refIndex[count][3] = -mProbeData.refIndex[count][3]; } - rpd.refParams[count].set( - llmax(minimum_ambiance, refmap->getAmbiance())*ambscale, // ambiance scale - radscale, // radiance scale + mProbeData.refParams[count].set( + llmax(minimum_ambiance, refmap->getAmbiance())*ambscale * llmax(mResetFade, 0.f), // ambiance scale + radscale * llmax(mResetFade, 0.f), // radiance scale refmap->mFadeIn, // fade in weight oa.getF32ptr()[2] - refmap->mRadius); // z near @@ -1182,7 +1155,7 @@ void LLReflectionMapManager::updateUniforms() } // this neighbor may be sampled - rpd.refNeighbor[ni++] = idx; + mProbeData.refNeighbor[ni++] = idx; neighbor_count++; if (neighbor_count >= max_neighbors) @@ -1195,11 +1168,11 @@ void LLReflectionMapManager::updateUniforms() if (nc == ni) { //no neighbors, tag as empty - rpd.refIndex[count][1] = -1; + mProbeData.refIndex[count][1] = -1; } else { - rpd.refIndex[count][2] = ni - nc; + mProbeData.refIndex[count][2] = ni - nc; // move the cursor forward nc = ni; @@ -1237,19 +1210,19 @@ void LLReflectionMapManager::updateUniforms() } #endif - rpd.refmapCount = count; + mProbeData.refmapCount = count; gPipeline.mHeroProbeManager.updateUniforms(); // Get the hero data. - rpd.heroBox = gPipeline.mHeroProbeManager.mHeroData.heroBox; - rpd.heroSphere = gPipeline.mHeroProbeManager.mHeroData.heroSphere; - rpd.heroShape = gPipeline.mHeroProbeManager.mHeroData.heroShape; - rpd.heroMipCount = gPipeline.mHeroProbeManager.mHeroData.heroMipCount; - rpd.heroProbeCount = gPipeline.mHeroProbeManager.mHeroData.heroProbeCount; + mProbeData.heroBox = gPipeline.mHeroProbeManager.mHeroData.heroBox; + mProbeData.heroSphere = gPipeline.mHeroProbeManager.mHeroData.heroSphere; + mProbeData.heroShape = gPipeline.mHeroProbeManager.mHeroData.heroShape; + mProbeData.heroMipCount = gPipeline.mHeroProbeManager.mHeroData.heroMipCount; + mProbeData.heroProbeCount = gPipeline.mHeroProbeManager.mHeroData.heroProbeCount; - //copy rpd into uniform buffer object + //copy mProbeData into uniform buffer object if (mUBO == 0) { glGenBuffers(1, &mUBO); @@ -1258,7 +1231,7 @@ void LLReflectionMapManager::updateUniforms() { LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("rmmsu - update buffer"); glBindBuffer(GL_UNIFORM_BUFFER, mUBO); - glBufferData(GL_UNIFORM_BUFFER, sizeof(ReflectionProbeData), &rpd, GL_STREAM_DRAW); + glBufferData(GL_UNIFORM_BUFFER, sizeof(ReflectionProbeData), &mProbeData, GL_STREAM_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); } @@ -1392,7 +1365,8 @@ void LLReflectionMapManager::renderDebug() void LLReflectionMapManager::initReflectionMaps() { - U32 count = LL_MAX_REFLECTION_PROBE_COUNT; + static LLCachedControl probe_count(gSavedSettings, "RenderReflectionProbeCount", 256U); + U32 count = probe_count(); static LLCachedControl ref_probe_res(gSavedSettings, "RenderReflectionProbeResolution", 128U); U32 probe_resolution = nhpo2(llclamp(ref_probe_res(), (U32)64, (U32)512)); -- cgit v1.2.3 From 32c7d3064f04899547ee4dea48969c6ceb8554e9 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Fri, 21 Mar 2025 09:33:23 -0400 Subject: Dynamic Probe Allocation (#3787) * #3788 Support dynamic probe allocation. * #3738 Mitigate probe flashing * #3735 Mitigate realtime probes flashing --- indra/newview/llreflectionmapmanager.cpp | 86 +++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 23 deletions(-) (limited to 'indra/newview/llreflectionmapmanager.cpp') diff --git a/indra/newview/llreflectionmapmanager.cpp b/indra/newview/llreflectionmapmanager.cpp index 48b73531ea..34c6034e9e 100644 --- a/indra/newview/llreflectionmapmanager.cpp +++ b/indra/newview/llreflectionmapmanager.cpp @@ -144,13 +144,14 @@ static void touch_default_probe(LLReflectionMap* probe) LLReflectionMapManager::LLReflectionMapManager() { + mDynamicProbeCount = LL_MAX_REFLECTION_PROBE_COUNT; initCubeFree(); } void LLReflectionMapManager::initCubeFree() { // start at 1 because index 0 is reserved for mDefaultProbe - for (int i = 1; i < LL_MAX_REFLECTION_PROBE_COUNT; ++i) + for (U32 i = 1; i < mDynamicProbeCount; ++i) { mCubeFree.push_back(i); } @@ -221,15 +222,50 @@ void LLReflectionMapManager::update() resume(); } - static LLCachedControl probe_count(gSavedSettings, "RenderReflectionProbeCount", 256U); - bool countReset = mReflectionProbeCount != probe_count; + static LLCachedControl sDetail(gSavedSettings, "RenderReflectionProbeDetail", -1); + static LLCachedControl sLevel(gSavedSettings, "RenderReflectionProbeLevel", 3); - if (countReset) + // Once every 20 frames, update the dynamic probe count. + if (gFrameCount % 20) { - mResetFade = -0.5f; + U32 probe_count_temp = mDynamicProbeCount; + if (sLevel == 0) + { + mDynamicProbeCount = 1; + } + else if (sLevel == 1) + { + mDynamicProbeCount = (U32)mProbes.size(); + + } + else if (sLevel == 2) + { + mDynamicProbeCount = llmax((U32)mProbes.size(), 128); + } + else + { + mDynamicProbeCount = 256; + } + + // Round mDynamicProbeCount to the nearest increment of 32 + mDynamicProbeCount = ((mDynamicProbeCount + 16) / 32) * 32; + mDynamicProbeCount = llclamp(mDynamicProbeCount, 1, LL_MAX_REFLECTION_PROBE_COUNT); + + if (mDynamicProbeCount < probe_count_temp * 1.1 && mDynamicProbeCount > probe_count_temp * 0.9) + mDynamicProbeCount = probe_count_temp; + else + mGlobalFadeTarget = 0.f; } - initReflectionMaps(); + if (mGlobalFadeTarget < mResetFade) + mResetFade = llmax(mGlobalFadeTarget, mResetFade - (F32)gFrameIntervalSeconds * 2); + else + mResetFade = llmin(mGlobalFadeTarget, mResetFade + (F32)gFrameIntervalSeconds * 2); + + if (mResetFade == mGlobalFadeTarget) + { + initReflectionMaps(); + } static LLCachedControl render_hdr(gSavedSettings, "RenderHDREnabled", true); @@ -286,9 +322,6 @@ void LLReflectionMapManager::update() bool did_update = false; - static LLCachedControl sDetail(gSavedSettings, "RenderReflectionProbeDetail", -1); - static LLCachedControl sLevel(gSavedSettings, "RenderReflectionProbeLevel", 3); - bool realtime = sDetail >= (S32)LLReflectionMapManager::DetailLevel::REALTIME; LLReflectionMap* closestDynamic = nullptr; @@ -343,12 +376,7 @@ void LLReflectionMapManager::update() } } - if (countReset) - { - mResetFade = -0.5f; - } - - mResetFade = llmin((F32)(mResetFade + gFrameIntervalSeconds), 1.f); + mResetFade = llmin((F32)(mResetFade + gFrameIntervalSeconds * 2.f), 1.f); for (unsigned int i = 0; i < mProbes.size(); ++i) { @@ -520,6 +548,16 @@ LLReflectionMap* LLReflectionMapManager::addProbe(LLSpatialGroup* group) return probe; } +U32 LLReflectionMapManager::probeCount() +{ + return mDynamicProbeCount; +} + +U32 LLReflectionMapManager::probeMemory() +{ + return (mDynamicProbeCount * 6 * (mProbeResolution * mProbeResolution) * 4) / 1024 / 1024 + (mDynamicProbeCount * 6 * (LL_IRRADIANCE_MAP_RESOLUTION * LL_IRRADIANCE_MAP_RESOLUTION) * 4) / 1024 / 1024; +} + struct CompareProbeDepth { bool operator()(const LLReflectionMap* lhs, const LLReflectionMap* rhs) @@ -1058,7 +1096,11 @@ void LLReflectionMapManager::updateUniforms() bool is_ambiance_pass = gCubeSnapshot && !isRadiancePass(); F32 ambscale = is_ambiance_pass ? 0.f : 1.f; + ambscale *= mResetFade; + ambscale = llmax(0, ambscale); F32 radscale = is_ambiance_pass ? 0.5f : 1.f; + radscale *= mResetFade; + radscale = llmax(0, radscale); for (auto* refmap : mReflectionMaps) { @@ -1129,8 +1171,8 @@ void LLReflectionMapManager::updateUniforms() } mProbeData.refParams[count].set( - llmax(minimum_ambiance, refmap->getAmbiance())*ambscale * llmax(mResetFade, 0.f), // ambiance scale - radscale * llmax(mResetFade, 0.f), // radiance scale + llmax(minimum_ambiance, refmap->getAmbiance())*ambscale, // ambiance scale + radscale, // radiance scale refmap->mFadeIn, // fade in weight oa.getF32ptr()[2] - refmap->mRadius); // z near @@ -1365,12 +1407,9 @@ void LLReflectionMapManager::renderDebug() void LLReflectionMapManager::initReflectionMaps() { - static LLCachedControl probe_count(gSavedSettings, "RenderReflectionProbeCount", 256U); - U32 count = probe_count(); - static LLCachedControl ref_probe_res(gSavedSettings, "RenderReflectionProbeResolution", 128U); U32 probe_resolution = nhpo2(llclamp(ref_probe_res(), (U32)64, (U32)512)); - if (mTexture.isNull() || mReflectionProbeCount != count || mProbeResolution != probe_resolution || mReset) + if (mTexture.isNull() || mReflectionProbeCount != mDynamicProbeCount || mProbeResolution != probe_resolution || mReset) { if(mProbeResolution != probe_resolution) { @@ -1379,9 +1418,10 @@ void LLReflectionMapManager::initReflectionMaps() } gEXRImage = nullptr; - + mGlobalFadeTarget = 1.f; + mResetFade = -0.125f; mReset = false; - mReflectionProbeCount = count; + mReflectionProbeCount = mDynamicProbeCount; mProbeResolution = probe_resolution; mMaxProbeLOD = log2f((F32)mProbeResolution) - 1.f; // number of mips - 1 -- cgit v1.2.3 From 5e5d466628f3576bb48b63f143502ea914f79bca Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Mon, 24 Mar 2025 17:59:13 -0400 Subject: Readd probe count setting (#3793) * Readd max probe count. Disable dynamic probe allocation by default (for now). --- indra/newview/llreflectionmapmanager.cpp | 90 +++++++++++++++++++------------- 1 file changed, 53 insertions(+), 37 deletions(-) (limited to 'indra/newview/llreflectionmapmanager.cpp') diff --git a/indra/newview/llreflectionmapmanager.cpp b/indra/newview/llreflectionmapmanager.cpp index 34c6034e9e..f2abc7b8b7 100644 --- a/indra/newview/llreflectionmapmanager.cpp +++ b/indra/newview/llreflectionmapmanager.cpp @@ -224,48 +224,54 @@ void LLReflectionMapManager::update() static LLCachedControl sDetail(gSavedSettings, "RenderReflectionProbeDetail", -1); static LLCachedControl sLevel(gSavedSettings, "RenderReflectionProbeLevel", 3); + static LLCachedControl sReflectionProbeCount(gSavedSettings, "RenderReflectionProbeCount", 256U); + static LLCachedControl sProbeDynamicAllocation(gSavedSettings, "RenderReflectionProbeDynamicAllocation", -1); + mResetFade = llmin((F32)(mResetFade + gFrameIntervalSeconds * 2.f), 1.f); - // Once every 20 frames, update the dynamic probe count. - if (gFrameCount % 20) { U32 probe_count_temp = mDynamicProbeCount; - if (sLevel == 0) - { - mDynamicProbeCount = 1; - } - else if (sLevel == 1) + if (sProbeDynamicAllocation > -1) { - mDynamicProbeCount = (U32)mProbes.size(); + if (sLevel == 0) + { + mDynamicProbeCount = 1; + } + else if (sLevel == 1) + { + mDynamicProbeCount = (U32)mProbes.size(); + } + else if (sLevel == 2) + { + mDynamicProbeCount = llmax((U32)mProbes.size(), 128); + } + else + { + mDynamicProbeCount = 256; + } - } - else if (sLevel == 2) - { - mDynamicProbeCount = llmax((U32)mProbes.size(), 128); + if (sProbeDynamicAllocation > 1) + { + // Round mDynamicProbeCount to the nearest increment of 16 + mDynamicProbeCount = ((mDynamicProbeCount + sProbeDynamicAllocation / 2) / sProbeDynamicAllocation) * 16; + mDynamicProbeCount = llclamp(mDynamicProbeCount, 1, sReflectionProbeCount); + } + else + { + mDynamicProbeCount = llclamp(mDynamicProbeCount + sProbeDynamicAllocation, 1, sReflectionProbeCount); + } } else { - mDynamicProbeCount = 256; + mDynamicProbeCount = sReflectionProbeCount; } - // Round mDynamicProbeCount to the nearest increment of 32 - mDynamicProbeCount = ((mDynamicProbeCount + 16) / 32) * 32; - mDynamicProbeCount = llclamp(mDynamicProbeCount, 1, LL_MAX_REFLECTION_PROBE_COUNT); + mDynamicProbeCount = llmin(mDynamicProbeCount, LL_MAX_REFLECTION_PROBE_COUNT); - if (mDynamicProbeCount < probe_count_temp * 1.1 && mDynamicProbeCount > probe_count_temp * 0.9) - mDynamicProbeCount = probe_count_temp; - else - mGlobalFadeTarget = 0.f; + if (mDynamicProbeCount != probe_count_temp) + mResetFade = 1.f; } - if (mGlobalFadeTarget < mResetFade) - mResetFade = llmax(mGlobalFadeTarget, mResetFade - (F32)gFrameIntervalSeconds * 2); - else - mResetFade = llmin(mGlobalFadeTarget, mResetFade + (F32)gFrameIntervalSeconds * 2); - - if (mResetFade == mGlobalFadeTarget) - { - initReflectionMaps(); - } + initReflectionMaps(); static LLCachedControl render_hdr(gSavedSettings, "RenderHDREnabled", true); @@ -356,6 +362,7 @@ void LLReflectionMapManager::update() probe->mCubeArray = nullptr; probe->mCubeIndex = -1; probe->mComplete = false; + probe->mFadeIn = 0; } } @@ -1418,8 +1425,6 @@ void LLReflectionMapManager::initReflectionMaps() } gEXRImage = nullptr; - mGlobalFadeTarget = 1.f; - mResetFade = -0.125f; mReset = false; mReflectionProbeCount = mDynamicProbeCount; mProbeResolution = probe_resolution; @@ -1429,15 +1434,25 @@ void LLReflectionMapManager::initReflectionMaps() mTexture->getWidth() != mProbeResolution || mReflectionProbeCount + 2 != mTexture->getCount()) { - mTexture = new LLCubeMapArray(); + if (mTexture) + { + mTexture = new LLCubeMapArray(*mTexture, mProbeResolution, mReflectionProbeCount + 2); - static LLCachedControl render_hdr(gSavedSettings, "RenderHDREnabled", true); + mIrradianceMaps = new LLCubeMapArray(*mIrradianceMaps, LL_IRRADIANCE_MAP_RESOLUTION, mReflectionProbeCount); + } + else + { + mTexture = new LLCubeMapArray(); + + static LLCachedControl render_hdr(gSavedSettings, "RenderHDREnabled", true); - // store mReflectionProbeCount+2 cube maps, final two cube maps are used for render target and radiance map generation source) - mTexture->allocate(mProbeResolution, 3, mReflectionProbeCount + 2, true, render_hdr); + // store mReflectionProbeCount+2 cube maps, final two cube maps are used for render target and radiance map generation + // source) + mTexture->allocate(mProbeResolution, 3, mReflectionProbeCount + 2, true, render_hdr); - mIrradianceMaps = new LLCubeMapArray(); - mIrradianceMaps->allocate(LL_IRRADIANCE_MAP_RESOLUTION, 3, mReflectionProbeCount, false, render_hdr); + mIrradianceMaps = new LLCubeMapArray(); + mIrradianceMaps->allocate(LL_IRRADIANCE_MAP_RESOLUTION, 3, mReflectionProbeCount, false, render_hdr); + } } // reset probe state @@ -1457,6 +1472,7 @@ void LLReflectionMapManager::initReflectionMaps() probe->mCubeArray = nullptr; probe->mCubeIndex = -1; probe->mNeighbors.clear(); + probe->mFadeIn = 0; } mCubeFree.clear(); -- cgit v1.2.3