Commit 14126505 by Jamie Madill Committed by Commit Bot

Revert "Use a constexpr array for es3 copy conversion table."

This reverts commit f30808db. Reason for revert: build/android/gyp/assert_static_initializers.py thinks this adds a static initializer. See https://ci.chromium.org/p/chromium/builders/try/android-marshmallow-arm64-rel/208664 Need to revert since this is blocking the roll. Original change's description: > Use a constexpr array for es3 copy conversion table. > > With the relaxed C++14 constexpr rules allowed in Chromium, we can > use a constexpr sorted array to store our table data. This can lead > to very fast lookups while being more maintanable than using auto- > generator scripts for every lookup table. > > Note that to be sure this syntax is permitted, we should land this > through the bots and let it sit for a little while. > > Bug: angleproject:1389 > Change-Id: I9395c40276470108ce3e5786d8f1b8d85462c517 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/777544 > Commit-Queue: Jamie Madill <jmadill@google.com> > Reviewed-by: Yuly Novikov <ynovikov@chromium.org> TBR=ynovikov@chromium.org,jmadill@google.com,syoussefi@chromium.org,jmadill@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: angleproject:1389 Change-Id: I482729b6f16975896b0e5c29999f9a081056e800 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1506238Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 105bc9d7
...@@ -93,6 +93,12 @@ generators = { ...@@ -93,6 +93,12 @@ generators = {
auto_script('scripts/generate_loader.py'), auto_script('scripts/generate_loader.py'),
'GL/EGL entry points': 'GL/EGL entry points':
auto_script('scripts/generate_entry_points.py'), auto_script('scripts/generate_entry_points.py'),
'GL copy conversion table': {
'inputs': [
'src/libANGLE/es3_copy_conversion_formats.json',
],
'script': 'src/libANGLE/gen_copy_conversion_table.py',
},
'GL format map': { 'GL format map': {
'inputs': [ 'inputs': [
'src/libANGLE/es3_format_type_combinations.json', 'src/libANGLE/es3_format_type_combinations.json',
......
...@@ -45,6 +45,10 @@ ...@@ -45,6 +45,10 @@
"002ad46d144c51fe98d73478aa554ba7", "002ad46d144c51fe98d73478aa554ba7",
"Emulated HLSL functions:src/compiler/translator/gen_emulated_builtin_function_tables.py": "Emulated HLSL functions:src/compiler/translator/gen_emulated_builtin_function_tables.py":
"6a00c1ba22c35a9b700a154efda6f861", "6a00c1ba22c35a9b700a154efda6f861",
"GL copy conversion table:src/libANGLE/es3_copy_conversion_formats.json":
"54608f6f7d9aa7c59a8458ccf3ab9935",
"GL copy conversion table:src/libANGLE/gen_copy_conversion_table.py":
"ac1afe23d9578bd1d2ef74f4a7aa927a",
"GL format map:src/libANGLE/es3_format_type_combinations.json": "GL format map:src/libANGLE/es3_format_type_combinations.json":
"a232823cd6430f14e28793ccabb968ee", "a232823cd6430f14e28793ccabb968ee",
"GL format map:src/libANGLE/format_map_data.json": "GL format map:src/libANGLE/format_map_data.json":
......
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// constexpr_array:
// C++14 relaxes constexpr requirements enough that we can support sorting
// a constexpr std::array at compile-time. This is useful for defining fast
// lookup tables and other data at compile-time.
// The code is adapted from https://stackoverflow.com/a/40030044.
#ifndef COMMON_CONSTEXPR_ARRAY_H_
#define COMMON_CONSTEXPR_ARRAY_H_
#include <algorithm>
namespace angle
{
template <class T>
constexpr void constexpr_swap(T &l, T &r)
{
T tmp = std::move(l);
l = std::move(r);
r = std::move(tmp);
}
template <typename T, size_t N>
struct constexpr_array
{
constexpr T &operator[](size_t i) { return arr[i]; }
constexpr const T &operator[](size_t i) const { return arr[i]; }
constexpr const T *begin() const { return arr; }
constexpr const T *end() const { return arr + N; }
T arr[N];
};
namespace priv
{
template <typename T, size_t N>
size_t hoare_partition(constexpr_array<T, N> &arr, size_t left, size_t right)
{
const T pivot = arr[(left + right) >> 1];
size_t i = left - 1;
size_t j = right + 1;
for (;;)
{
do
{
i++;
} while (arr[i] < pivot);
do
{
j--;
} while (arr[j] > pivot);
if (i >= j)
{
return j;
}
constexpr_swap(arr[i], arr[j]);
}
return 0;
}
template <typename T, size_t N>
void constexpr_sort_impl(constexpr_array<T, N> &arr, size_t left, size_t right)
{
if (left < right)
{
size_t p = priv::hoare_partition(arr, left, right);
constexpr_sort_impl(arr, left, p);
constexpr_sort_impl(arr, p + 1, right);
}
}
} // namespace priv
// Note that std::sort in constexpr in c++20. So this implementation can be
// removed given sufficient STL support.
template <typename T, size_t N>
constexpr_array<T, N> constexpr_sort(constexpr_array<T, N> arr)
{
auto sorted = arr;
priv::constexpr_sort_impl(sorted, 0, N - 1);
return sorted;
}
template <typename T, size_t N>
bool constexpr_array_contains(const constexpr_array<T, N> &haystack, const T &needle)
{
const T *found = std::lower_bound(haystack.begin(), haystack.end(), needle);
return (found && *found == needle);
}
} // namespace angle
#endif // COMMON_CONSTEXPR_ARRAY_H_
{
"From ES 3.0.1 spec, table 3.15":
[
[ "GL_ALPHA", "GL_RGBA" ],
[ "GL_LUMINANCE", "GL_RED" ],
[ "GL_LUMINANCE", "GL_RG" ],
[ "GL_LUMINANCE", "GL_RGB" ],
[ "GL_LUMINANCE", "GL_RGBA" ],
[ "GL_LUMINANCE_ALPHA", "GL_RGBA" ],
[ "GL_RED", "GL_RED" ],
[ "GL_RED", "GL_RG" ],
[ "GL_RED", "GL_RGB" ],
[ "GL_RED", "GL_RGBA" ],
[ "GL_RG", "GL_RG" ],
[ "GL_RG", "GL_RGB" ],
[ "GL_RG", "GL_RGBA" ],
[ "GL_RGB", "GL_RGB" ],
[ "GL_RGB", "GL_RGBA" ],
[ "GL_RGBA", "GL_RGBA" ]
],
"Necessary for ANGLE back-buffers":
[
[ "GL_ALPHA", "GL_BGRA_EXT" ],
[ "GL_LUMINANCE", "GL_BGRA_EXT" ],
[ "GL_LUMINANCE_ALPHA", "GL_BGRA_EXT" ],
[ "GL_RED", "GL_BGRA_EXT" ],
[ "GL_RG", "GL_BGRA_EXT" ],
[ "GL_RGB", "GL_BGRA_EXT" ],
[ "GL_RGBA", "GL_BGRA_EXT" ],
[ "GL_BGRA_EXT", "GL_BGRA_EXT" ],
[ "GL_RED_INTEGER", "GL_RED_INTEGER" ],
[ "GL_RED_INTEGER", "GL_RG_INTEGER" ],
[ "GL_RED_INTEGER", "GL_RGB_INTEGER" ],
[ "GL_RED_INTEGER", "GL_RGBA_INTEGER" ],
[ "GL_RG_INTEGER", "GL_RG_INTEGER" ],
[ "GL_RG_INTEGER", "GL_RGB_INTEGER" ],
[ "GL_RG_INTEGER", "GL_RGBA_INTEGER" ],
[ "GL_RGB_INTEGER", "GL_RGB_INTEGER" ],
[ "GL_RGB_INTEGER", "GL_RGBA_INTEGER" ],
[ "GL_RGBA_INTEGER", "GL_RGBA_INTEGER" ]
]
}
// GENERATED FILE - DO NOT EDIT.
// Generated by gen_copy_conversion_table.py using data from es3_copy_conversion_formats.json.
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// format_map:
// Determining the sized internal format from a (format,type) pair.
// Also check es3 format combinations for validity.
#include "angle_gl.h"
#include "common/debug.h"
namespace gl
{
bool ValidES3CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
{
switch (textureFormat)
{
case GL_ALPHA:
switch (framebufferFormat)
{
case GL_BGRA_EXT:
case GL_RGBA:
return true;
default:
break;
}
break;
case GL_BGRA_EXT:
switch (framebufferFormat)
{
case GL_BGRA_EXT:
return true;
default:
break;
}
break;
case GL_LUMINANCE:
switch (framebufferFormat)
{
case GL_BGRA_EXT:
case GL_RED:
case GL_RG:
case GL_RGB:
case GL_RGBA:
return true;
default:
break;
}
break;
case GL_LUMINANCE_ALPHA:
switch (framebufferFormat)
{
case GL_BGRA_EXT:
case GL_RGBA:
return true;
default:
break;
}
break;
case GL_RED:
switch (framebufferFormat)
{
case GL_BGRA_EXT:
case GL_RED:
case GL_RG:
case GL_RGB:
case GL_RGBA:
return true;
default:
break;
}
break;
case GL_RED_INTEGER:
switch (framebufferFormat)
{
case GL_RED_INTEGER:
case GL_RGBA_INTEGER:
case GL_RGB_INTEGER:
case GL_RG_INTEGER:
return true;
default:
break;
}
break;
case GL_RG:
switch (framebufferFormat)
{
case GL_BGRA_EXT:
case GL_RG:
case GL_RGB:
case GL_RGBA:
return true;
default:
break;
}
break;
case GL_RGB:
switch (framebufferFormat)
{
case GL_BGRA_EXT:
case GL_RGB:
case GL_RGBA:
return true;
default:
break;
}
break;
case GL_RGBA:
switch (framebufferFormat)
{
case GL_BGRA_EXT:
case GL_RGBA:
return true;
default:
break;
}
break;
case GL_RGBA_INTEGER:
switch (framebufferFormat)
{
case GL_RGBA_INTEGER:
return true;
default:
break;
}
break;
case GL_RGB_INTEGER:
switch (framebufferFormat)
{
case GL_RGBA_INTEGER:
case GL_RGB_INTEGER:
return true;
default:
break;
}
break;
case GL_RG_INTEGER:
switch (framebufferFormat)
{
case GL_RGBA_INTEGER:
case GL_RGB_INTEGER:
case GL_RG_INTEGER:
return true;
default:
break;
}
break;
default:
break;
}
return false;
}
} // namespace gl
...@@ -269,6 +269,10 @@ bool ValidES3InternalFormat(GLenum internalFormat); ...@@ -269,6 +269,10 @@ bool ValidES3InternalFormat(GLenum internalFormat);
bool ValidES3Format(GLenum format); bool ValidES3Format(GLenum format);
bool ValidES3Type(GLenum type); bool ValidES3Type(GLenum type);
bool ValidES3FormatCombination(GLenum format, GLenum type, GLenum internalFormat); bool ValidES3FormatCombination(GLenum format, GLenum type, GLenum internalFormat);
// Implemented in es3_copy_conversion_table_autogen.cpp
bool ValidES3CopyConversion(GLenum textureFormat, GLenum framebufferFormat);
} // namespace gl } // namespace gl
#endif // LIBANGLE_FORMATUTILS_H_ #endif // LIBANGLE_FORMATUTILS_H_
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "libANGLE/validationES3_autogen.h" #include "libANGLE/validationES3_autogen.h"
#include "anglebase/numerics/safe_conversions.h" #include "anglebase/numerics/safe_conversions.h"
#include "common/constexpr_array.h"
#include "common/mathutil.h" #include "common/mathutil.h"
#include "common/utilities.h" #include "common/utilities.h"
#include "libANGLE/Context.h" #include "libANGLE/Context.h"
...@@ -257,55 +256,6 @@ bool ValidateCopyTexture3DCommon(Context *context, ...@@ -257,55 +256,6 @@ bool ValidateCopyTexture3DCommon(Context *context,
return true; return true;
} }
// Since the unsorted array is only referenced in construction, it should be optimized out.
using CopyDesc = std::pair<GLenum, GLenum>;
constexpr angle::constexpr_array<CopyDesc, 34> kUnsortedCopyConversionTable{
{// From ES 3.0.1 spec, table 3.15
{GL_ALPHA, GL_RGBA},
{GL_LUMINANCE, GL_RED},
{GL_LUMINANCE, GL_RG},
{GL_LUMINANCE, GL_RGB},
{GL_LUMINANCE, GL_RGBA},
{GL_LUMINANCE_ALPHA, GL_RGBA},
{GL_RED, GL_RED},
{GL_RED, GL_RG},
{GL_RED, GL_RGB},
{GL_RED, GL_RGBA},
{GL_RG, GL_RG},
{GL_RG, GL_RGB},
{GL_RG, GL_RGBA},
{GL_RGB, GL_RGB},
{GL_RGB, GL_RGBA},
{GL_RGBA, GL_RGBA},
// Necessary for ANGLE back-buffers
{GL_ALPHA, GL_BGRA_EXT},
{GL_LUMINANCE, GL_BGRA_EXT},
{GL_LUMINANCE_ALPHA, GL_BGRA_EXT},
{GL_RED, GL_BGRA_EXT},
{GL_RG, GL_BGRA_EXT},
{GL_RGB, GL_BGRA_EXT},
{GL_RGBA, GL_BGRA_EXT},
{GL_BGRA_EXT, GL_BGRA_EXT},
{GL_RED_INTEGER, GL_RED_INTEGER},
{GL_RED_INTEGER, GL_RG_INTEGER},
{GL_RED_INTEGER, GL_RGB_INTEGER},
{GL_RED_INTEGER, GL_RGBA_INTEGER},
{GL_RG_INTEGER, GL_RG_INTEGER},
{GL_RG_INTEGER, GL_RGB_INTEGER},
{GL_RG_INTEGER, GL_RGBA_INTEGER},
{GL_RGB_INTEGER, GL_RGB_INTEGER},
{GL_RGB_INTEGER, GL_RGBA_INTEGER},
{GL_RGBA_INTEGER, GL_RGBA_INTEGER}}};
auto kSortedCopyConversionTable = angle::constexpr_sort(kUnsortedCopyConversionTable);
bool ValidES3CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
{
return constexpr_array_contains(kSortedCopyConversionTable, {textureFormat, framebufferFormat});
}
} // anonymous namespace } // anonymous namespace
static bool ValidateTexImageFormatCombination(gl::Context *context, static bool ValidateTexImageFormatCombination(gl::Context *context,
......
...@@ -24,7 +24,6 @@ libangle_common_sources = [ ...@@ -24,7 +24,6 @@ libangle_common_sources = [
"src/common/angleutils.cpp", "src/common/angleutils.cpp",
"src/common/angleutils.h", "src/common/angleutils.h",
"src/common/bitset_utils.h", "src/common/bitset_utils.h",
"src/common/constexpr_array.h",
"src/common/debug.cpp", "src/common/debug.cpp",
"src/common/debug.h", "src/common/debug.h",
"src/common/hash_utils.h", "src/common/hash_utils.h",
...@@ -269,6 +268,7 @@ libangle_sources = [ ...@@ -269,6 +268,7 @@ libangle_sources = [
"src/libANGLE/angletypes.cpp", "src/libANGLE/angletypes.cpp",
"src/libANGLE/angletypes.h", "src/libANGLE/angletypes.h",
"src/libANGLE/angletypes.inl", "src/libANGLE/angletypes.inl",
"src/libANGLE/es3_copy_conversion_table_autogen.cpp",
"src/libANGLE/features.h", "src/libANGLE/features.h",
"src/libANGLE/format_map_autogen.cpp", "src/libANGLE/format_map_autogen.cpp",
"src/libANGLE/formatutils.cpp", "src/libANGLE/formatutils.cpp",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment