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

Unified Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 2076213002: Decompress ETC texture data when there is no native support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Decompress ETC texture data when there is no native support. Created 4 years, 5 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
Index: gpu/command_buffer/service/gles2_cmd_decoder.cc
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 944b3ccdc5dfc42ce3ad0ba5661d2d09133c3868..d7f77b945b5b711b5e8efcd90eb50f5a9089b738 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -64,6 +64,7 @@
#include "gpu/command_buffer/service/transform_feedback_manager.h"
#include "gpu/command_buffer/service/vertex_array_manager.h"
#include "gpu/command_buffer/service/vertex_attrib_manager.h"
+#include "third_party/angle/src/image_util/loadimage.h"
#include "third_party/smhasher/src/City.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/point.h"
@@ -11451,6 +11452,147 @@ const ASTCBlockArray kASTCBlockArray[] = {
{12, 10},
{12, 12}};
+bool CheckETCFormatSupport(const FeatureInfo& featureInfo) {
+ const gl::GLVersionInfo& versionInfo = featureInfo.gl_version_info();
+ return versionInfo.IsAtLeastGL(4, 3) || versionInfo.IsAtLeastGLES(3, 0) ||
+ featureInfo.feature_flags().arb_es3_compatability;
+}
+
+using CompressedFormatSupportCheck = bool (*)(const FeatureInfo&);
+using CompressedFormatDecompressionFunction = void (*)(size_t width,
+ size_t height,
+ size_t depth,
+ const uint8_t* input,
+ size_t inputRowPitch,
+ size_t inputDepthPitch,
+ uint8_t* output,
+ size_t outputRowPitch,
+ size_t outputDepthPitch);
+
+struct CompressedFormatInfo {
+ GLenum format;
+ uint32_t blockSize;
piman 2016/07/06 21:20:59 nit: use chromium style here and below (e.g. block
Geoff Lang 2016/07/08 18:49:16 Done.
+ uint32_t bytesPerBlock;
+ CompressedFormatSupportCheck supportCheck;
+ CompressedFormatDecompressionFunction decompressionFunction;
+ GLenum decompressedInternalFormat;
+ GLenum decompressedFormat;
+ GLenum decompressedType;
+};
+
+const CompressedFormatInfo kCompressedFormatInfoArray[]{
Zhenyao Mo 2016/07/06 19:45:39 nit: a space between [] and {
Geoff Lang 2016/07/08 18:49:16 Done.
+ {
+ GL_COMPRESSED_R11_EAC, 4, 8, CheckETCFormatSupport,
+ angle::LoadEACR11ToR8, GL_R8, GL_RED, GL_UNSIGNED_BYTE,
+ },
+ {
+ GL_COMPRESSED_SIGNED_R11_EAC, 4, 8, CheckETCFormatSupport,
+ angle::LoadEACR11SToR8, GL_R8_SNORM, GL_RED, GL_BYTE,
+ },
+ {
+ GL_COMPRESSED_RG11_EAC, 4, 16, CheckETCFormatSupport,
+ angle::LoadEACRG11ToRG8, GL_RG8, GL_RG, GL_UNSIGNED_BYTE,
+ },
+ {
+ GL_COMPRESSED_SIGNED_RG11_EAC, 4, 16, CheckETCFormatSupport,
+ angle::LoadEACRG11SToRG8, GL_RG8_SNORM, GL_RG, GL_BYTE,
+ },
+ {
+ GL_COMPRESSED_RGB8_ETC2, 4, 8, CheckETCFormatSupport,
+ angle::LoadETC2RGB8ToRGBA8, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE,
+ },
+ {
+ GL_COMPRESSED_SRGB8_ETC2, 4, 8, CheckETCFormatSupport,
+ angle::LoadETC2SRGB8ToRGBA8, GL_SRGB8_ALPHA8, GL_SRGB_ALPHA,
+ GL_UNSIGNED_BYTE,
+ },
+ {
+ GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 16, CheckETCFormatSupport,
+ angle::LoadETC2RGBA8ToRGBA8, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE,
+ },
+ {
+ GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 8,
+ CheckETCFormatSupport, angle::LoadETC2RGB8A1ToRGBA8, GL_RGBA8, GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ },
+ {
+ GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 16, CheckETCFormatSupport,
+ angle::LoadETC2SRGBA8ToSRGBA8, GL_SRGB8_ALPHA8, GL_SRGB_ALPHA,
+ GL_UNSIGNED_BYTE,
+ },
+ {
+ GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 8,
+ CheckETCFormatSupport, angle::LoadETC2SRGB8A1ToRGBA8, GL_SRGB8_ALPHA8,
+ GL_SRGB_ALPHA, GL_UNSIGNED_BYTE,
+ },
+};
+
+const CompressedFormatInfo* GetCompressedFormatInfo(GLenum format) {
+ for (size_t i = 0; i < arraysize(kCompressedFormatInfoArray); i++) {
+ if (kCompressedFormatInfoArray[i].format == format) {
+ return &kCompressedFormatInfoArray[i];
+ }
+ }
+ return nullptr;
+}
+
+uint32_t GetCompressedFormatRowPitch(const CompressedFormatInfo& info,
+ uint32_t width) {
+ uint32_t num_blocks_wide = (width + info.blockSize - 1) / info.blockSize;
+ return num_blocks_wide * info.bytesPerBlock;
+}
+
+uint32_t GetCompressedFormatDepthPitch(const CompressedFormatInfo& info,
+ uint32_t width,
+ uint32_t height) {
+ uint32_t num_blocks_high = ((height + info.blockSize - 1) / info.blockSize);
+ return num_blocks_high * GetCompressedFormatRowPitch(info, width);
+}
+
+std::unique_ptr<uint8_t[]> DecompressTextureData(
+ const CompressedFormatInfo& info,
+ uint32_t width,
+ uint32_t height,
+ uint32_t depth,
+ const void* data) {
+ uint32_t output_pixel_size = GLES2Util::ComputeImageGroupSize(
+ info.decompressedFormat, info.decompressedType);
+ std::unique_ptr<uint8_t[]> decompressed_data(
+ new uint8_t[output_pixel_size * width * height]);
+
+ info.decompressionFunction(width, height, 1,
+ reinterpret_cast<const uint8_t*>(data),
+ GetCompressedFormatRowPitch(info, width),
+ GetCompressedFormatDepthPitch(info, width, height),
+ decompressed_data.get(), output_pixel_size * width,
+ output_pixel_size * width * height);
+
+ return decompressed_data;
+}
+
+void PushDecompressedTextureUnpackState() {
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+ glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+ glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
+ glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0);
Zhenyao Mo 2016/07/06 19:45:39 No need for all the SKIP params as they are always
Geoff Lang 2016/07/08 18:49:16 Ah, thanks for pointing that out. I kept the Push
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+}
+
+void PopDecompressedTextureUnpackState(const ContextState& state) {
+ glPixelStorei(GL_UNPACK_ALIGNMENT, state.unpack_alignment);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, state.unpack_row_length);
+ glPixelStorei(GL_UNPACK_SKIP_ROWS, state.unpack_skip_rows);
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS, state.unpack_skip_images);
+ glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, state.unpack_image_height);
+ glPixelStorei(GL_UNPACK_SKIP_IMAGES, state.unpack_skip_images);
+ if (state.bound_pixel_unpack_buffer) {
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
+ state.bound_array_buffer->service_id());
+ }
+}
+
bool IsValidDXTSize(GLint level, GLsizei size) {
// TODO(zmo): Linux NVIDIA driver does allow size of 1 and 2 on level 0.
// However, the WebGL conformance test and blink side code forbid it.
@@ -11879,9 +12021,23 @@ error::Error GLES2DecoderImpl::DoCompressedTexImage2D(
memset(zero.get(), 0, image_size);
data = zero.get();
}
+
LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D");
- glCompressedTexImage2D(
- target, level, internal_format, width, height, border, image_size, data);
+
+ const CompressedFormatInfo* format_info =
+ GetCompressedFormatInfo(internal_format);
+ if (format_info != nullptr && !format_info->supportCheck(*feature_info_)) {
+ std::unique_ptr<uint8_t[]> decompressed_data =
+ DecompressTextureData(*format_info, width, height, 1, data);
piman 2016/07/06 21:20:59 What happens if there's a PIXEL_UNPACK_BUFFER boun
Geoff Lang 2016/07/08 18:49:16 Yea, I noticed that too. PBOs aren't handled at a
+ PushDecompressedTextureUnpackState();
+ glTexImage2D(target, level, format_info->decompressedInternalFormat, width,
+ height, border, format_info->decompressedFormat,
+ format_info->decompressedType, decompressed_data.get());
+ PopDecompressedTextureUnpackState(state_);
+ } else {
+ glCompressedTexImage2D(target, level, internal_format, width, height,
+ border, image_size, data);
+ }
GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D");
if (error == GL_NO_ERROR) {
texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format,
@@ -11952,8 +12108,20 @@ error::Error GLES2DecoderImpl::DoCompressedTexImage3D(
data = zero.get();
}
LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage3D");
- glCompressedTexImage3D(target, level, internal_format, width, height, depth,
- border, image_size, data);
+ const CompressedFormatInfo* format_info =
+ GetCompressedFormatInfo(internal_format);
+ if (format_info != nullptr && !format_info->supportCheck(*feature_info_)) {
+ std::unique_ptr<uint8_t[]> decompressed_data =
+ DecompressTextureData(*format_info, width, height, depth, data);
+ PushDecompressedTextureUnpackState();
+ glTexImage3D(target, level, format_info->decompressedInternalFormat, width,
+ height, depth, border, format_info->decompressedFormat,
+ format_info->decompressedType, decompressed_data.get());
+ PopDecompressedTextureUnpackState(state_);
+ } else {
+ glCompressedTexImage3D(target, level, internal_format, width, height, depth,
+ border, image_size, data);
+ }
GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage3D");
if (error == GL_NO_ERROR) {
texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format,
@@ -12018,9 +12186,21 @@ void GLES2DecoderImpl::DoCompressedTexSubImage3D(
// because the validation above means you can only get here if the level
// is already a matching compressed format and in that case
// CompressedTexImage3D already cleared the texture.
- glCompressedTexSubImage3D(
- target, level, xoffset, yoffset, zoffset, width, height, depth, format,
- image_size, data);
+
+ const CompressedFormatInfo* format_info =
+ GetCompressedFormatInfo(internal_format);
+ if (format_info != nullptr && !format_info->supportCheck(*feature_info_)) {
+ std::unique_ptr<uint8_t[]> decompressed_data =
+ DecompressTextureData(*format_info, width, height, depth, data);
+ PushDecompressedTextureUnpackState();
+ glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height,
+ depth, format_info->decompressedFormat,
+ format_info->decompressedType, decompressed_data.get());
+ PopDecompressedTextureUnpackState(state_);
+ } else {
+ glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width,
+ height, depth, format, image_size, data);
+ }
// This may be a slow command. Exit command processing to allow for
// context preemption and GPU watchdog checks.
@@ -12269,8 +12449,20 @@ void GLES2DecoderImpl::DoCompressedTexSubImage2D(
DCHECK(texture->IsLevelCleared(target, level));
}
- glCompressedTexSubImage2D(
- target, level, xoffset, yoffset, width, height, format, image_size, data);
+ const CompressedFormatInfo* format_info =
+ GetCompressedFormatInfo(internal_format);
+ if (format_info != nullptr && !format_info->supportCheck(*feature_info_)) {
+ std::unique_ptr<uint8_t[]> decompressed_data =
+ DecompressTextureData(*format_info, width, height, 1, data);
+ PushDecompressedTextureUnpackState();
+ glTexSubImage2D(target, level, xoffset, yoffset, width, height,
+ format_info->decompressedFormat,
+ format_info->decompressedType, decompressed_data.get());
+ PopDecompressedTextureUnpackState(state_);
+ } else {
+ glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height,
+ format, image_size, data);
+ }
// This may be a slow command. Exit command processing to allow for
// context preemption and GPU watchdog checks.
@@ -15063,13 +15255,22 @@ void GLES2DecoderImpl::TexStorageImpl(GLenum target,
}
}
+ GLenum compatability_iternal_format = internal_format;
piman 2016/07/06 21:20:59 nit: 2 typos: compatability_iternal_format -> comp
Geoff Lang 2016/07/08 18:49:16 Done.
+ const CompressedFormatInfo* format_info =
+ GetCompressedFormatInfo(internal_format);
+ if (format_info != nullptr && !format_info->supportCheck(*feature_info_)) {
+ compatability_iternal_format = format_info->decompressedInternalFormat;
+ }
+
// TODO(zmo): We might need to emulate TexStorage using TexImage or
// CompressedTexImage on Mac OSX where we expose ES3 APIs when the underlying
// driver is lower than 4.2 and ARB_texture_storage extension doesn't exist.
if (dimension == ContextState::k2D) {
- glTexStorage2DEXT(target, levels, internal_format, width, height);
+ glTexStorage2DEXT(target, levels, compatability_iternal_format, width,
+ height);
} else {
- glTexStorage3D(target, levels, internal_format, width, height, depth);
+ glTexStorage3D(target, levels, compatability_iternal_format, width, height,
+ depth);
}
{

Powered by Google App Engine
This is Rietveld 408576698