Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Unified Diff: cc/output/color_lut_cache.cc

Issue 2648043002: Create FP16 LUTs when needed (Closed)
Patch Set: upload floats, let gl convert Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/output/color_lut_cache.h ('k') | cc/output/gl_renderer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/color_lut_cache.cc
diff --git a/cc/output/color_lut_cache.cc b/cc/output/color_lut_cache.cc
index d591f39fbcb898079c644ec714d42df21a365f64..aa083a7a4a4f22a0d919491be1b0440d47492c05 100644
--- a/cc/output/color_lut_cache.cc
+++ b/cc/output/color_lut_cache.cc
@@ -9,19 +9,23 @@
#include <vector>
#include "gpu/command_buffer/client/gles2_interface.h"
+#include "third_party/khronos/GLES2/gl2ext.h"
#include "ui/gfx/color_transform.h"
// After a LUT has not been used for this many frames, we release it.
const uint32_t kMaxFramesUnused = 10;
-ColorLUTCache::ColorLUTCache(gpu::gles2::GLES2Interface* gl)
- : lut_cache_(0), gl_(gl) {}
+ColorLUTCache::ColorLUTCache(gpu::gles2::GLES2Interface* gl,
+ bool texture_half_float_linear)
+ : lut_cache_(0),
+ gl_(gl),
+ texture_half_float_linear_(texture_half_float_linear) {}
ColorLUTCache::~ColorLUTCache() {
GLuint textures[10];
size_t n = 0;
for (const auto& cache_entry : lut_cache_) {
- textures[n++] = cache_entry.second.texture;
+ textures[n++] = cache_entry.second.lut.texture;
if (n == arraysize(textures)) {
gl_->DeleteTextures(n, textures);
n = 0;
@@ -31,16 +35,10 @@ ColorLUTCache::~ColorLUTCache() {
gl_->DeleteTextures(n, textures);
}
-namespace {
-
-unsigned char FloatToLUT(float f) {
- return std::min<int>(255, std::max<int>(0, floorf(f * 255.0f + 0.5f)));
-}
-};
-
unsigned int ColorLUTCache::MakeLUT(const gfx::ColorSpace& from,
gfx::ColorSpace to,
- int lut_samples) {
+ int lut_samples,
+ int data_type) {
ccameron 2017/01/23 18:30:25 Small nit: should be "GLenum type" instead of "int
hubbe 2017/01/24 18:32:17 Acknowledged.
if (to == gfx::ColorSpace()) {
to = gfx::ColorSpace::CreateSRGB();
}
@@ -50,9 +48,9 @@ unsigned int ColorLUTCache::MakeLUT(const gfx::ColorSpace& from,
int lut_entries = lut_samples * lut_samples * lut_samples;
float inverse = 1.0f / (lut_samples - 1);
- std::vector<unsigned char> lut(lut_entries * 4);
+ std::vector<float> lut(lut_entries * 4);
std::vector<gfx::ColorTransform::TriStim> samples(lut_samples);
- unsigned char* lutp = lut.data();
+ float* lutp = lut.data();
for (int v = 0; v < lut_samples; v++) {
for (int u = 0; u < lut_samples; u++) {
for (int y = 0; y < lut_samples; y++) {
@@ -62,10 +60,10 @@ unsigned int ColorLUTCache::MakeLUT(const gfx::ColorSpace& from,
}
transform->transform(samples.data(), samples.size());
for (int y = 0; y < lut_samples; y++) {
- *(lutp++) = FloatToLUT(samples[y].x());
- *(lutp++) = FloatToLUT(samples[y].y());
- *(lutp++) = FloatToLUT(samples[y].z());
- *(lutp++) = 255; // alpha
+ *(lutp++) = samples[y].x();
+ *(lutp++) = samples[y].y();
+ *(lutp++) = samples[y].z();
+ *(lutp++) = 1.0; // alpha
}
}
}
@@ -78,22 +76,34 @@ unsigned int ColorLUTCache::MakeLUT(const gfx::ColorSpace& from,
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, lut_samples,
- lut_samples * lut_samples, 0, GL_RGBA, GL_UNSIGNED_BYTE,
- lut.data());
+ lut_samples * lut_samples, 0, GL_RGBA, data_type, nullptr);
ccameron 2017/01/23 18:30:25 So I'm not 100% sure what exactly triggers use of
hubbe 2017/01/24 18:32:17 Seems clear enough to me that it's the data type t
+ gl_->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, lut_samples,
+ lut_samples * lut_samples, GL_RGBA, GL_FLOAT, lut.data());
return lut_texture;
}
-unsigned int ColorLUTCache::GetLUT(const gfx::ColorSpace& from,
- const gfx::ColorSpace& to,
- int lut_samples) {
- CacheKey key(from, std::make_pair(to, lut_samples));
+ColorLUTCache::LUT ColorLUTCache::GetLUT(const gfx::ColorSpace& from,
+ const gfx::ColorSpace& to) {
+ CacheKey key(from, to);
auto iter = lut_cache_.Get(key);
if (iter != lut_cache_.end()) {
iter->second.last_used_frame = current_frame_;
- return iter->second.texture;
+ return iter->second.lut;
}
- unsigned int lut = MakeLUT(from, to, lut_samples);
+ LUT lut;
+ // If input is HDR, and the output is scRGB, we're going to need
+ // to produce values outside of 0-1, so we'll need to make a half-float
+ // LUT. Also, we'll need to build a larger lut to maintain accuracy.
+ // All LUT sizes should be odd a some transforms hav a knee at 0.5.
+ if (to == gfx::ColorSpace::CreateSCRGBLinear() && from.IsHDR() &&
+ texture_half_float_linear_) {
+ lut.size = 37;
+ lut.texture = MakeLUT(from, to, lut.size, GL_HALF_FLOAT_OES);
+ } else {
+ lut.size = 17;
+ lut.texture = MakeLUT(from, to, lut.size, GL_UNSIGNED_BYTE);
+ }
lut_cache_.Put(key, CacheVal(lut, current_frame_));
return lut;
}
@@ -103,7 +113,7 @@ void ColorLUTCache::Swap() {
while (!lut_cache_.empty() &&
current_frame_ - lut_cache_.rbegin()->second.last_used_frame >
kMaxFramesUnused) {
- gl_->DeleteTextures(1, &lut_cache_.rbegin()->second.texture);
+ gl_->DeleteTextures(1, &lut_cache_.rbegin()->second.lut.texture);
lut_cache_.ShrinkToSize(lut_cache_.size() - 1);
}
}
« no previous file with comments | « cc/output/color_lut_cache.h ('k') | cc/output/gl_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698