Follow up fixes for Apple Silicon (#4662)

* Remove GLM sse flag from cmake that was moved to llpreprocessor.h

* Further reduce performance loss of HDR and Sharpening on bandwith-constrained gpu by combining gamma correction into tonemap/sharpening shader passes

* Update SSE2NEON to 1.8.0 to fix random render nans

* Fix occasional startup crash from LLCachedControl being declared in global scope
master
Rye 2025-09-11 20:54:32 -04:00 committed by GitHub
parent 3ab18e8545
commit 452c8e0ea4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 217 additions and 38 deletions

View File

@ -2343,11 +2343,11 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<key>archive</key> <key>archive</key>
<map> <map>
<key>hash</key> <key>hash</key>
<string>c578c2a7f4355197d0ce8544310bc5e785531018</string> <string>e51fb1d24836d897ce90b8a72010635915b959d6</string>
<key>hash_algorithm</key> <key>hash_algorithm</key>
<string>sha1</string> <string>sha1</string>
<key>url</key> <key>url</key>
<string>https://github.com/secondlife/3p-sse2neon/releases/download/v1.7.0-r2/sse2neon-1.7.0-dev0.gc8ad5f1.d20241212-common-12287325635.tar.zst</string> <string>https://github.com/secondlife/3p-sse2neon/releases/download/v1.8.0/sse2neon-1.8.0-common-17657389472.tar.zst</string>
</map> </map>
<key>name</key> <key>name</key>
<string>common</string> <string>common</string>
@ -2360,7 +2360,7 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors</string>
<key>copyright</key> <key>copyright</key>
<string>Copyright (c) 2015-2024 SSE2NEON Contributors.</string> <string>Copyright (c) 2015-2024 SSE2NEON Contributors.</string>
<key>version</key> <key>version</key>
<string>1.7.0-dev0.gc8ad5f1.d20241212</string> <string>1.8.0</string>
<key>name</key> <key>name</key>
<string>sse2neon</string> <string>sse2neon</string>
<key>canonical_repo</key> <key>canonical_repo</key>

View File

@ -34,7 +34,10 @@ add_compile_definitions(BOOST_BIND_GLOBAL_PLACEHOLDERS)
# Force enable SSE2 instructions in GLM per the manual # Force enable SSE2 instructions in GLM per the manual
# https://github.com/g-truc/glm/blob/master/manual.md#section2_10 # https://github.com/g-truc/glm/blob/master/manual.md#section2_10
add_compile_definitions(GLM_FORCE_DEFAULT_ALIGNED_GENTYPES=1 GLM_FORCE_SSE2=1 GLM_ENABLE_EXPERIMENTAL=1) add_compile_definitions(GLM_FORCE_DEFAULT_ALIGNED_GENTYPES=1 GLM_ENABLE_EXPERIMENTAL=1)
# SSE2NEON throws a pointless warning when compiler optimizations are enabled
add_compile_definitions(SSE2NEON_SUPPRESS_WARNINGS=1)
# Configure crash reporting # Configure crash reporting
set(RELEASE_CRASH_REPORTING OFF CACHE BOOL "Enable use of crash reporting in release builds") set(RELEASE_CRASH_REPORTING OFF CACHE BOOL "Enable use of crash reporting in release builds")

View File

@ -2545,12 +2545,31 @@ A_STATIC void CasSetup(
#endif #endif
#ifdef A_GPU #ifdef A_GPU
#ifdef LEGACY_GAMMA
uniform float gamma;
vec3 legacyGamma(vec3 color)
{
vec3 c = 1. - clamp(color, vec3(0.), vec3(1.));
c = 1. - pow(c, vec3(gamma)); // s/b inverted already CPU-side
return c;
}
#endif
void main() void main()
{ {
vec4 diff = vec4(0.f); vec4 diff = vec4(0.f);
uvec2 point = uvec2(vary_fragcoord * out_screen_res.xy); uvec2 point = uvec2(vary_fragcoord * out_screen_res.xy);
CasFilter(diff.r, diff.g, diff.b, point, cas_param_0, cas_param_1, true); CasFilter(diff.r, diff.g, diff.b, point, cas_param_0, cas_param_1, true);
diff.a = texture(diffuseRect, vary_fragcoord).a; diff.a = texture(diffuseRect, vary_fragcoord).a;
diff.rgb = linear_to_srgb(diff.rgb);
#ifdef LEGACY_GAMMA
diff.rgb = legacyGamma(diff.rgb);
#endif
frag_color = diff; frag_color = diff;
} }
#endif #endif

View File

@ -43,8 +43,6 @@ vec3 legacyGamma(vec3 color)
return c; return c;
} }
vec3 clampHDRRange(vec3 color);
void main() void main()
{ {
//this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB)
@ -55,7 +53,7 @@ void main()
diff.rgb = legacyGamma(diff.rgb); diff.rgb = legacyGamma(diff.rgb);
#endif #endif
diff.rgb = clampHDRRange(diff.rgb); diff.rgb = clamp(diff.rgb, vec3(0.0), vec3(1.0));
frag_color = diff; frag_color = diff;
} }

View File

@ -31,11 +31,25 @@ uniform sampler2D diffuseRect;
in vec2 vary_fragcoord; in vec2 vary_fragcoord;
#ifdef GAMMA_CORRECT
uniform float gamma;
#endif
vec3 linear_to_srgb(vec3 cl); vec3 linear_to_srgb(vec3 cl);
vec3 toneMap(vec3 color); vec3 toneMap(vec3 color);
vec3 clampHDRRange(vec3 color); vec3 clampHDRRange(vec3 color);
#ifdef GAMMA_CORRECT
vec3 legacyGamma(vec3 color)
{
vec3 c = 1. - clamp(color, vec3(0.), vec3(1.));
c = 1. - pow(c, vec3(gamma)); // s/b inverted already CPU-side
return c;
}
#endif
void main() void main()
{ {
//this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB)
@ -47,8 +61,18 @@ void main()
diff.rgb = clamp(diff.rgb, vec3(0.0), vec3(1.0)); diff.rgb = clamp(diff.rgb, vec3(0.0), vec3(1.0));
#endif #endif
diff.rgb = clampHDRRange(diff.rgb); #ifdef GAMMA_CORRECT
diff.rgb = linear_to_srgb(diff.rgb);
#ifdef LEGACY_GAMMA
diff.rgb = legacyGamma(diff.rgb);
#endif
#endif
diff.rgb = clamp(diff.rgb, vec3(0.0), vec3(1.0)); // We should always be 0-1 past this point
//debugExposure(diff.rgb); //debugExposure(diff.rgb);
frag_color = max(diff, vec4(0)); frag_color = diff;
} }

View File

@ -196,6 +196,10 @@ LLGLSLShader gDeferredCoFProgram;
LLGLSLShader gDeferredDoFCombineProgram; LLGLSLShader gDeferredDoFCombineProgram;
LLGLSLShader gDeferredPostTonemapProgram; LLGLSLShader gDeferredPostTonemapProgram;
LLGLSLShader gNoPostTonemapProgram; LLGLSLShader gNoPostTonemapProgram;
LLGLSLShader gDeferredPostTonemapGammaCorrectProgram;
LLGLSLShader gNoPostTonemapGammaCorrectProgram;
LLGLSLShader gDeferredPostTonemapLegacyGammaCorrectProgram;
LLGLSLShader gNoPostTonemapLegacyGammaCorrectProgram;
LLGLSLShader gDeferredPostGammaCorrectProgram; LLGLSLShader gDeferredPostGammaCorrectProgram;
LLGLSLShader gLegacyPostGammaCorrectProgram; LLGLSLShader gLegacyPostGammaCorrectProgram;
LLGLSLShader gExposureProgram; LLGLSLShader gExposureProgram;
@ -206,6 +210,7 @@ LLGLSLShader gSMAAEdgeDetectProgram[4];
LLGLSLShader gSMAABlendWeightsProgram[4]; LLGLSLShader gSMAABlendWeightsProgram[4];
LLGLSLShader gSMAANeighborhoodBlendProgram[4]; LLGLSLShader gSMAANeighborhoodBlendProgram[4];
LLGLSLShader gCASProgram; LLGLSLShader gCASProgram;
LLGLSLShader gCASLegacyGammaProgram;
LLGLSLShader gDeferredPostNoDoFProgram; LLGLSLShader gDeferredPostNoDoFProgram;
LLGLSLShader gDeferredPostNoDoFNoiseProgram; LLGLSLShader gDeferredPostNoDoFNoiseProgram;
LLGLSLShader gDeferredWLSkyProgram; LLGLSLShader gDeferredWLSkyProgram;
@ -443,6 +448,11 @@ void LLViewerShaderMgr::finalizeShaderList()
mShaderList.push_back(&gHUDPBRAlphaProgram); mShaderList.push_back(&gHUDPBRAlphaProgram);
mShaderList.push_back(&gDeferredPostTonemapProgram); mShaderList.push_back(&gDeferredPostTonemapProgram);
mShaderList.push_back(&gNoPostTonemapProgram); mShaderList.push_back(&gNoPostTonemapProgram);
mShaderList.push_back(&gDeferredPostTonemapGammaCorrectProgram);
mShaderList.push_back(&gNoPostTonemapGammaCorrectProgram);
mShaderList.push_back(&gDeferredPostTonemapLegacyGammaCorrectProgram);
mShaderList.push_back(&gNoPostTonemapLegacyGammaCorrectProgram);
mShaderList.push_back(&gCASLegacyGammaProgram);
mShaderList.push_back(&gDeferredPostGammaCorrectProgram); // for gamma mShaderList.push_back(&gDeferredPostGammaCorrectProgram); // for gamma
mShaderList.push_back(&gLegacyPostGammaCorrectProgram); mShaderList.push_back(&gLegacyPostGammaCorrectProgram);
mShaderList.push_back(&gDeferredDiffuseProgram); mShaderList.push_back(&gDeferredDiffuseProgram);
@ -1116,6 +1126,11 @@ bool LLViewerShaderMgr::loadShadersDeferred()
gLegacyPostGammaCorrectProgram.unload(); gLegacyPostGammaCorrectProgram.unload();
gDeferredPostTonemapProgram.unload(); gDeferredPostTonemapProgram.unload();
gNoPostTonemapProgram.unload(); gNoPostTonemapProgram.unload();
gDeferredPostTonemapGammaCorrectProgram.unload();
gNoPostTonemapGammaCorrectProgram.unload();
gDeferredPostTonemapLegacyGammaCorrectProgram.unload();
gNoPostTonemapLegacyGammaCorrectProgram.unload();
for (auto i = 0; i < 4; ++i) for (auto i = 0; i < 4; ++i)
{ {
gFXAAProgram[i].unload(); gFXAAProgram[i].unload();
@ -1124,6 +1139,7 @@ bool LLViewerShaderMgr::loadShadersDeferred()
gSMAANeighborhoodBlendProgram[i].unload(); gSMAANeighborhoodBlendProgram[i].unload();
} }
gCASProgram.unload(); gCASProgram.unload();
gCASLegacyGammaProgram.unload();
gEnvironmentMapProgram.unload(); gEnvironmentMapProgram.unload();
gDeferredWLSkyProgram.unload(); gDeferredWLSkyProgram.unload();
gDeferredWLCloudProgram.unload(); gDeferredWLCloudProgram.unload();
@ -2486,6 +2502,74 @@ bool LLViewerShaderMgr::loadShadersDeferred()
llassert(success); llassert(success);
} }
if (success)
{
gDeferredPostTonemapGammaCorrectProgram.mName = "Deferred Tonemap Gamma Post Process";
gDeferredPostTonemapGammaCorrectProgram.mFeatures.hasSrgb = true;
gDeferredPostTonemapGammaCorrectProgram.mFeatures.isDeferred = true;
gDeferredPostTonemapGammaCorrectProgram.mFeatures.hasTonemap = true;
gDeferredPostTonemapGammaCorrectProgram.mShaderFiles.clear();
gDeferredPostTonemapGammaCorrectProgram.clearPermutations();
gDeferredPostTonemapGammaCorrectProgram.addPermutation("GAMMA_CORRECT", "1");
gDeferredPostTonemapGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
gDeferredPostTonemapGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredTonemap.glsl", GL_FRAGMENT_SHADER));
gDeferredPostTonemapGammaCorrectProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
success = gDeferredPostTonemapGammaCorrectProgram.createShader();
llassert(success);
}
if (success)
{
gNoPostTonemapGammaCorrectProgram.mName = "No Post Tonemap Gamma Post Process";
gNoPostTonemapGammaCorrectProgram.mFeatures.hasSrgb = true;
gNoPostTonemapGammaCorrectProgram.mFeatures.isDeferred = true;
gNoPostTonemapGammaCorrectProgram.mFeatures.hasTonemap = true;
gNoPostTonemapGammaCorrectProgram.mShaderFiles.clear();
gNoPostTonemapGammaCorrectProgram.clearPermutations();
gNoPostTonemapGammaCorrectProgram.addPermutation("GAMMA_CORRECT", "1");
gNoPostTonemapGammaCorrectProgram.addPermutation("NO_POST", "1");
gNoPostTonemapGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
gNoPostTonemapGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredTonemap.glsl", GL_FRAGMENT_SHADER));
gNoPostTonemapGammaCorrectProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
success = gNoPostTonemapGammaCorrectProgram.createShader();
llassert(success);
}
if (success)
{
gDeferredPostTonemapLegacyGammaCorrectProgram.mName = "Deferred Tonemap Legacy Gamma Post Process";
gDeferredPostTonemapLegacyGammaCorrectProgram.mFeatures.hasSrgb = true;
gDeferredPostTonemapProgram.mFeatures.isDeferred = true;
gDeferredPostTonemapLegacyGammaCorrectProgram.mFeatures.hasTonemap = true;
gDeferredPostTonemapLegacyGammaCorrectProgram.mShaderFiles.clear();
gDeferredPostTonemapLegacyGammaCorrectProgram.clearPermutations();
gDeferredPostTonemapLegacyGammaCorrectProgram.addPermutation("GAMMA_CORRECT", "1");
gDeferredPostTonemapLegacyGammaCorrectProgram.addPermutation("LEGACY_GAMMA", "1");
gDeferredPostTonemapLegacyGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
gDeferredPostTonemapLegacyGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredTonemap.glsl", GL_FRAGMENT_SHADER));
gDeferredPostTonemapLegacyGammaCorrectProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
success = gDeferredPostTonemapLegacyGammaCorrectProgram.createShader();
llassert(success);
}
if (success)
{
gNoPostTonemapLegacyGammaCorrectProgram.mName = "No Post Tonemap Legacy Gamma Post Process";
gNoPostTonemapLegacyGammaCorrectProgram.mFeatures.hasSrgb = true;
gNoPostTonemapLegacyGammaCorrectProgram.mFeatures.isDeferred = true;
gNoPostTonemapLegacyGammaCorrectProgram.mFeatures.hasTonemap = true;
gNoPostTonemapLegacyGammaCorrectProgram.mShaderFiles.clear();
gNoPostTonemapLegacyGammaCorrectProgram.clearPermutations();
gNoPostTonemapLegacyGammaCorrectProgram.addPermutation("NO_POST", "1");
gNoPostTonemapLegacyGammaCorrectProgram.addPermutation("GAMMA_CORRECT", "1");
gNoPostTonemapLegacyGammaCorrectProgram.addPermutation("LEGACY_GAMMA", "1");
gNoPostTonemapLegacyGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
gNoPostTonemapLegacyGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredTonemap.glsl", GL_FRAGMENT_SHADER));
gNoPostTonemapLegacyGammaCorrectProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
success = gNoPostTonemapLegacyGammaCorrectProgram.createShader();
llassert(success);
}
if (success && gGLManager.mGLVersion > 3.9f) if (success && gGLManager.mGLVersion > 3.9f)
{ {
std::vector<std::pair<std::string, std::string>> quality_levels = { {"12", "Low"}, std::vector<std::pair<std::string, std::string>> quality_levels = { {"12", "Low"},
@ -2669,6 +2753,27 @@ bool LLViewerShaderMgr::loadShadersDeferred()
} }
} }
if (success && gGLManager.mGLVersion > 4.05f)
{
gCASLegacyGammaProgram.mName = "Contrast Adaptive Sharpening Legacy Gamma Shader";
gCASLegacyGammaProgram.mFeatures.hasSrgb = true;
gCASLegacyGammaProgram.mShaderFiles.clear();
gCASLegacyGammaProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
gCASLegacyGammaProgram.mShaderFiles.push_back(make_pair("deferred/CASF.glsl", GL_FRAGMENT_SHADER));
gCASLegacyGammaProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
gCASLegacyGammaProgram.clearPermutations();
gCASLegacyGammaProgram.addPermutation("GAMMA_CORRECT", "1");
gCASLegacyGammaProgram.addPermutation("LEGACY_GAMMA", "1");
success = gCASLegacyGammaProgram.createShader();
// llassert(success);
if (!success)
{
LL_WARNS() << "Failed to create shader '" << gCASProgram.mName << "', disabling!" << LL_ENDL;
// continue as if this shader never happened
success = true;
}
}
if (success) if (success)
{ {
gDeferredPostProgram.mName = "Deferred Post Shader"; gDeferredPostProgram.mName = "Deferred Post Shader";

View File

@ -250,12 +250,17 @@ extern LLGLSLShader gSMAAEdgeDetectProgram[4];
extern LLGLSLShader gSMAABlendWeightsProgram[4]; extern LLGLSLShader gSMAABlendWeightsProgram[4];
extern LLGLSLShader gSMAANeighborhoodBlendProgram[4]; extern LLGLSLShader gSMAANeighborhoodBlendProgram[4];
extern LLGLSLShader gCASProgram; extern LLGLSLShader gCASProgram;
extern LLGLSLShader gCASLegacyGammaProgram;
extern LLGLSLShader gDeferredPostNoDoFProgram; extern LLGLSLShader gDeferredPostNoDoFProgram;
extern LLGLSLShader gDeferredPostNoDoFNoiseProgram; extern LLGLSLShader gDeferredPostNoDoFNoiseProgram;
extern LLGLSLShader gDeferredPostGammaCorrectProgram; extern LLGLSLShader gDeferredPostGammaCorrectProgram;
extern LLGLSLShader gLegacyPostGammaCorrectProgram; extern LLGLSLShader gLegacyPostGammaCorrectProgram;
extern LLGLSLShader gDeferredPostTonemapProgram; extern LLGLSLShader gDeferredPostTonemapProgram;
extern LLGLSLShader gNoPostTonemapProgram; extern LLGLSLShader gNoPostTonemapProgram;
extern LLGLSLShader gDeferredPostTonemapGammaCorrectProgram;
extern LLGLSLShader gNoPostTonemapGammaCorrectProgram;
extern LLGLSLShader gDeferredPostTonemapLegacyGammaCorrectProgram;
extern LLGLSLShader gNoPostTonemapLegacyGammaCorrectProgram;
extern LLGLSLShader gExposureProgram; extern LLGLSLShader gExposureProgram;
extern LLGLSLShader gExposureProgramNoFade; extern LLGLSLShader gExposureProgramNoFade;
extern LLGLSLShader gLuminanceProgram; extern LLGLSLShader gLuminanceProgram;

View File

@ -261,9 +261,6 @@ static const F32 MIN_DISPLAY_SCALE = 0.75f;
static const char KEY_MOUSELOOK = 'M'; static const char KEY_MOUSELOOK = 'M';
static LLCachedControl<std::string> sSnapshotBaseName(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseName", "Snapshot"));
static LLCachedControl<std::string> sSnapshotDir(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseDir", ""));
LLTrace::SampleStatHandle<> LLViewerWindow::sMouseVelocityStat("Mouse Velocity"); LLTrace::SampleStatHandle<> LLViewerWindow::sMouseVelocityStat("Mouse Velocity");
@ -2042,6 +2039,7 @@ LLViewerWindow::LLViewerWindow(const Params& p)
std::string LLViewerWindow::getLastSnapshotDir() std::string LLViewerWindow::getLastSnapshotDir()
{ {
static LLCachedControl<std::string> sSnapshotDir(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseDir", ""));
return sSnapshotDir; return sSnapshotDir;
} }
@ -4752,6 +4750,7 @@ void LLViewerWindow::saveImageNumbered(LLImageFormatted *image, bool force_picke
// Get a base file location if needed. // Get a base file location if needed.
if (force_picker || !isSnapshotLocSet()) if (force_picker || !isSnapshotLocSet())
{ {
static LLCachedControl<std::string> sSnapshotBaseName(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseName", "Snapshot"));
std::string proposed_name(sSnapshotBaseName); std::string proposed_name(sSnapshotBaseName);
// getSaveFile will append an appropriate extension to the proposed name, based on the ESaveFilter constant passed in. // getSaveFile will append an appropriate extension to the proposed name, based on the ESaveFilter constant passed in.
@ -4850,6 +4849,9 @@ void LLViewerWindow::saveImageLocal(LLImageFormatted *image, const snapshot_save
// Shouldn't there be a return here? // Shouldn't there be a return here?
} }
static LLCachedControl<std::string> sSnapshotBaseName(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseName", "Snapshot"));
static LLCachedControl<std::string> sSnapshotDir(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseDir", ""));
// Look for an unused file name // Look for an unused file name
auto is_snapshot_name_loc_set = isSnapshotLocSet(); auto is_snapshot_name_loc_set = isSnapshotLocSet();
std::string filepath; std::string filepath;
@ -4957,8 +4959,8 @@ void LLViewerWindow::playSnapshotAnimAndSound()
bool LLViewerWindow::isSnapshotLocSet() const bool LLViewerWindow::isSnapshotLocSet() const
{ {
std::string snapshot_dir = sSnapshotDir; static LLCachedControl<std::string> sSnapshotDir(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseDir", ""));
return !snapshot_dir.empty(); return !sSnapshotDir().empty();
} }
void LLViewerWindow::resetSnapshotLoc() const void LLViewerWindow::resetSnapshotLoc() const

View File

@ -7200,7 +7200,7 @@ void LLPipeline::generateExposure(LLRenderTarget* src, LLRenderTarget* dst, bool
extern LLPointer<LLImageGL> gEXRImage; extern LLPointer<LLImageGL> gEXRImage;
void LLPipeline::tonemap(LLRenderTarget* src, LLRenderTarget* dst) void LLPipeline::tonemap(LLRenderTarget* src, LLRenderTarget* dst, bool gamma_correct)
{ {
LL_PROFILE_GPU_ZONE("tonemap"); LL_PROFILE_GPU_ZONE("tonemap");
@ -7218,17 +7218,33 @@ void LLPipeline::tonemap(LLRenderTarget* src, LLRenderTarget* dst)
LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
bool no_post = gSnapshotNoPost || psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f || (buildNoPost && gFloaterTools && gFloaterTools->isAvailable()); bool no_post = gSnapshotNoPost || psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f || (buildNoPost && gFloaterTools && gFloaterTools->isAvailable());
LLGLSLShader& shader = no_post ? gNoPostTonemapProgram : gDeferredPostTonemapProgram; LLGLSLShader* shader = nullptr;
if(gamma_correct)
{
bool legacy_gamma = psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f;
if(legacy_gamma)
{
shader = no_post ? &gNoPostTonemapLegacyGammaCorrectProgram : &gDeferredPostTonemapLegacyGammaCorrectProgram;
}
else
{
shader = no_post ? &gNoPostTonemapGammaCorrectProgram : &gDeferredPostTonemapGammaCorrectProgram;
}
}
else
{
shader = no_post ? &gNoPostTonemapProgram : &gDeferredPostTonemapProgram;
}
shader.bind(); shader->bind();
S32 channel = 0; S32 channel = 0;
shader.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT); shader->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
shader.bindTexture(LLShaderMgr::EXPOSURE_MAP, &mExposureMap); shader->bindTexture(LLShaderMgr::EXPOSURE_MAP, &mExposureMap);
shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, (GLfloat)src->getWidth(), (GLfloat)src->getHeight()); shader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, (GLfloat)src->getWidth(), (GLfloat)src->getHeight());
static LLCachedControl<F32> exposure(gSavedSettings, "RenderExposure", 1.f); static LLCachedControl<F32> exposure(gSavedSettings, "RenderExposure", 1.f);
@ -7238,17 +7254,17 @@ void LLPipeline::tonemap(LLRenderTarget* src, LLRenderTarget* dst)
static LLStaticHashedString tonemap_mix("tonemap_mix"); static LLStaticHashedString tonemap_mix("tonemap_mix");
static LLStaticHashedString tonemap_type("tonemap_type"); static LLStaticHashedString tonemap_type("tonemap_type");
shader.uniform1f(s_exposure, e); shader->uniform1f(s_exposure, e);
static LLCachedControl<U32> tonemap_type_setting(gSavedSettings, "RenderTonemapType", 0U); static LLCachedControl<U32> tonemap_type_setting(gSavedSettings, "RenderTonemapType", 0U);
shader.uniform1i(tonemap_type, tonemap_type_setting); shader->uniform1i(tonemap_type, tonemap_type_setting);
shader.uniform1f(tonemap_mix, psky->getTonemapMix(should_auto_adjust())); shader->uniform1f(tonemap_mix, psky->getTonemapMix(should_auto_adjust()));
mScreenTriangleVB->setBuffer(); mScreenTriangleVB->setBuffer();
mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3); mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
gGL.getTexUnit(channel)->unbind(src->getUsage()); gGL.getTexUnit(channel)->unbind(src->getUsage());
shader.unbind(); shader->unbind();
} }
dst->flush(); dst->flush();
} }
@ -7422,13 +7438,21 @@ void LLPipeline::applyCAS(LLRenderTarget* src, LLRenderTarget* dst)
{ {
static LLCachedControl<F32> cas_sharpness(gSavedSettings, "RenderCASSharpness", 0.4f); static LLCachedControl<F32> cas_sharpness(gSavedSettings, "RenderCASSharpness", 0.4f);
LL_PROFILE_GPU_ZONE("cas"); LL_PROFILE_GPU_ZONE("cas");
if (cas_sharpness == 0.0f || !gCASProgram.isComplete()) if (cas_sharpness == 0.0f || !gCASProgram.isComplete() || !gCASLegacyGammaProgram.isComplete())
{ {
gPipeline.copyRenderTarget(src, dst); gPipeline.copyRenderTarget(src, dst);
return; return;
} }
LLGLSLShader* sharpen_shader = &gCASProgram; LLGLSLShader* sharpen_shader = &gCASProgram;
static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", false);
LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
bool legacy_gamma = psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f;
if(legacy_gamma)
{
sharpen_shader = &gCASLegacyGammaProgram;
}
// Bind setup: // Bind setup:
dst->bindTarget(); dst->bindTarget();
@ -7990,7 +8014,6 @@ void LLPipeline::renderFinalize()
static LLCachedControl<bool> has_hdr(gSavedSettings, "RenderHDREnabled", true); static LLCachedControl<bool> has_hdr(gSavedSettings, "RenderHDREnabled", true);
bool hdr = gGLManager.mGLVersion > 4.05f && has_hdr(); bool hdr = gGLManager.mGLVersion > 4.05f && has_hdr();
LLRenderTarget* postHDRBuffer = &mRT->screen;
if (hdr) if (hdr)
{ {
copyScreenSpaceReflections(&mRT->screen, &mSceneMap); copyScreenSpaceReflections(&mRT->screen, &mSceneMap);
@ -7999,21 +8022,21 @@ void LLPipeline::renderFinalize()
generateExposure(&mLuminanceMap, &mExposureMap); generateExposure(&mLuminanceMap, &mExposureMap);
tonemap(&mRT->screen, &mRT->deferredLight);
static LLCachedControl<F32> cas_sharpness(gSavedSettings, "RenderCASSharpness", 0.4f); static LLCachedControl<F32> cas_sharpness(gSavedSettings, "RenderCASSharpness", 0.4f);
if (cas_sharpness != 0.0f && gCASProgram.isComplete()) bool apply_cas = cas_sharpness != 0.0f && gCASProgram.isComplete() && gCASLegacyGammaProgram.isComplete();
tonemap(&mRT->screen, apply_cas ? &mRT->deferredLight : &mPostPingMap, !apply_cas);
if (apply_cas)
{ {
applyCAS(&mRT->deferredLight, &mRT->screen); // Gamma Corrects
postHDRBuffer = &mRT->screen; applyCAS(&mRT->deferredLight, &mPostPingMap);
}
else
{
postHDRBuffer = &mRT->deferredLight;
} }
} }
else
gammaCorrect(postHDRBuffer, &mPostPingMap); {
gammaCorrect(&mRT->screen, &mPostPingMap);
}
LLVertexBuffer::unbind(); LLVertexBuffer::unbind();

View File

@ -155,7 +155,7 @@ public:
void copyScreenSpaceReflections(LLRenderTarget* src, LLRenderTarget* dst); void copyScreenSpaceReflections(LLRenderTarget* src, LLRenderTarget* dst);
void generateLuminance(LLRenderTarget* src, LLRenderTarget* dst); void generateLuminance(LLRenderTarget* src, LLRenderTarget* dst);
void generateExposure(LLRenderTarget* src, LLRenderTarget* dst, bool use_history = true); void generateExposure(LLRenderTarget* src, LLRenderTarget* dst, bool use_history = true);
void tonemap(LLRenderTarget* src, LLRenderTarget* dst); void tonemap(LLRenderTarget* src, LLRenderTarget* dst, bool gamma_correct);
void gammaCorrect(LLRenderTarget* src, LLRenderTarget* dst); void gammaCorrect(LLRenderTarget* src, LLRenderTarget* dst);
void generateGlow(LLRenderTarget* src); void generateGlow(LLRenderTarget* src);
void applyCAS(LLRenderTarget* src, LLRenderTarget* dst); void applyCAS(LLRenderTarget* src, LLRenderTarget* dst);