summaryrefslogtreecommitdiff
path: root/libs/shaders/shaders.cpp
diff options
context:
space:
mode:
author Alec Mouri <alecmouri@google.com> 2022-03-04 23:41:38 +0000
committer Alec Mouri <alecmouri@google.com> 2022-03-18 23:54:08 +0000
commit7a577450e536aa1e99f229a0cb3d3531c82e8a8d (patch)
tree324da642f325123cf62f9c688f481614942a9d1e /libs/shaders/shaders.cpp
parent1a3c5456dd9e05642c3d0f388102c511e80b5108 (diff)
Push HLG OOTF down to libtonemap.
Usage of current display brightness may be vendor-configured when the display brightness is very low, so keep the OOTF in libtonemap as part of the reference implementation. Concretely, this means that: * The BT2100 recommended OOTF for HLG->output format is moved from ScaleLuminance in libshaders to be the first part of the tonemapping operator in libtonemap * The inverse OOTF for input format->HLG is moved from NormalizeLuminance in libshaders to the end of the tonemapping operator in libtonemp * Current display brightness is only taken into account in the default tonemapping for Android T. The historic tonemapper does not take into account current display brightness, as it treats the "nominal peak brightness" of the display as 1000 nits instead of the current brightness. Also add a default lower-bound for using the current display brightness, because not having a bound looks really terrible on existing shipping devices Bug: 208933319 Test: builds Test: HLG test video looks okay Test: HDR10 test video didn't break Change-Id: I4f489c68f635a8ecc4d497b98c32e91c297d0765
Diffstat (limited to 'libs/shaders/shaders.cpp')
-rw-r--r--libs/shaders/shaders.cpp21
1 files changed, 5 insertions, 16 deletions
diff --git a/libs/shaders/shaders.cpp b/libs/shaders/shaders.cpp
index 0d77519ab7..5935589fdf 100644
--- a/libs/shaders/shaders.cpp
+++ b/libs/shaders/shaders.cpp
@@ -185,9 +185,8 @@ void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace, ui::Dataspace
break;
case HAL_DATASPACE_TRANSFER_HLG:
shader.append(R"(
- uniform float in_hlgGamma;
float3 ScaleLuminance(float3 xyz) {
- return xyz * 1000.0 * pow(xyz.y, in_hlgGamma - 1);
+ return xyz * 1000.0;
}
)");
break;
@@ -228,10 +227,8 @@ static void generateLuminanceNormalizationForOOTF(ui::Dataspace outputDataspace,
break;
case HAL_DATASPACE_TRANSFER_HLG:
shader.append(R"(
- uniform float in_hlgGamma;
float3 NormalizeLuminance(float3 xyz) {
- return xyz / 1000.0 *
- pow(xyz.y / 1000.0, (1 - in_hlgGamma) / (in_hlgGamma));
+ return xyz / 1000.0;
}
)");
break;
@@ -451,11 +448,6 @@ std::vector<uint8_t> buildUniformValue(T value) {
return result;
}
-// Refer to BT2100-2
-float computeHlgGamma(float currentDisplayBrightnessNits) {
- return 1.2 + 0.42 * std::log10(currentDisplayBrightnessNits / 1000);
-}
-
} // namespace
std::string buildLinearEffectSkSL(const LinearEffect& linearEffect) {
@@ -493,12 +485,6 @@ std::vector<tonemap::ShaderUniform> buildLinearEffectUniforms(const LinearEffect
colorTransform * mat4(outputColorSpace.getXYZtoRGB()))});
}
- if ((linearEffect.inputDataspace & HAL_DATASPACE_TRANSFER_MASK) == HAL_DATASPACE_TRANSFER_HLG) {
- uniforms.push_back(
- {.name = "in_hlgGamma",
- .value = buildUniformValue<float>(computeHlgGamma(currentDisplayLuminanceNits))});
- }
-
tonemap::Metadata metadata{.displayMaxLuminance = maxDisplayLuminance,
// If the input luminance is unknown, use display luminance (aka,
// no-op any luminance changes)
@@ -506,6 +492,9 @@ std::vector<tonemap::ShaderUniform> buildLinearEffectUniforms(const LinearEffect
// uncalibrated displays
.contentMaxLuminance =
maxLuminance > 0 ? maxLuminance : maxDisplayLuminance,
+ .currentDisplayLuminance = currentDisplayLuminanceNits > 0
+ ? currentDisplayLuminanceNits
+ : maxDisplayLuminance,
.buffer = buffer};
for (const auto uniform : tonemap::getToneMapper()->generateShaderSkSLUniforms(metadata)) {