Commit c33c55f5 authored by Geoff Lang's avatar Geoff Lang Committed by Commit Bot

Optimize GLES2Util::ComputeDataSize using templates.

Use templates to determine the size of each element and the elements per
unit allowing ComputeDataSize to only use a single inlined CheckedNumeric
multiply with a compile-time constant.

The data size validation of glUniform calls was up to 12% of the GPU
process' CPU time on some WebGL applications, this lowers it to be less
than 0.1%.

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ic6e5f975087308da9473918a9ef081c0b591fbb4
Reviewed-on: https://chromium-review.googlesource.com/559104Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485297}
parent d3dadb5e
...@@ -7094,7 +7094,7 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { ...@@ -7094,7 +7094,7 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
def WriteGetDataSizeCode(self, func, f): def WriteGetDataSizeCode(self, func, f):
"""Overrriden from TypeHandler.""" """Overrriden from TypeHandler."""
code = """ uint32_t data_size; code = """ uint32_t data_size;
if (!GLES2Util::ComputeDataSize(1, sizeof(%s), %d, &data_size)) { if (!GLES2Util::ComputeDataSize<%s, %d>(1, &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
""" """
...@@ -7392,7 +7392,7 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { ...@@ -7392,7 +7392,7 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
"""Overrriden from TypeHandler.""" """Overrriden from TypeHandler."""
code = """ uint32_t data_size = 0; code = """ uint32_t data_size = 0;
if (count >= 0 && if (count >= 0 &&
!GLES2Util::ComputeDataSize(count, sizeof(%s), %d, &data_size)) { !GLES2Util::ComputeDataSize<%s, %d>(count, &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
""" """
......
...@@ -1820,22 +1820,6 @@ uint32_t GLES2Util::ConvertToSizedFormat(uint32_t format, uint32_t type) { ...@@ -1820,22 +1820,6 @@ uint32_t GLES2Util::ConvertToSizedFormat(uint32_t format, uint32_t type) {
return format; return format;
} }
// static
bool GLES2Util::ComputeDataSize(uint32_t count,
size_t size,
unsigned int elements_per_unit,
uint32_t* dst) {
uint32_t value;
if (!SafeMultiplyUint32(count, static_cast<uint32_t>(size), &value)) {
return false;
}
if (!SafeMultiplyUint32(value, elements_per_unit, &value)) {
return false;
}
*dst = value;
return true;
}
namespace { namespace {
// GL context configuration attributes. Those in the 16-bit range are the same // GL context configuration attributes. Those in the 16-bit range are the same
......
...@@ -252,10 +252,12 @@ class GLES2_UTILS_EXPORT GLES2Util { ...@@ -252,10 +252,12 @@ class GLES2_UTILS_EXPORT GLES2Util {
uint32_t internal_format, uint32_t type, int* r, int* g, int* b, int* a); uint32_t internal_format, uint32_t type, int* r, int* g, int* b, int* a);
// Computes the data size for certain gl commands like glUniform. // Computes the data size for certain gl commands like glUniform.
static bool ComputeDataSize(uint32_t count, template <typename VALUE_TYPE, unsigned int ELEMENTS_PER_UNIT>
size_t size, static bool ComputeDataSize(uint32_t count, uint32_t* dst) {
unsigned int elements_per_unit, constexpr uint32_t element_size = sizeof(VALUE_TYPE) * ELEMENTS_PER_UNIT;
uint32_t* dst); return base::CheckMul(count, element_size)
.template AssignIfValid<uint32_t>(dst);
}
#include "gpu/command_buffer/common/gles2_cmd_utils_autogen.h" #include "gpu/command_buffer/common/gles2_cmd_utils_autogen.h"
......
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