Skip to content

Commit

Permalink
Inline common cases of PackParam<BufferBinding>
Browse files Browse the repository at this point in the history
This appears to improve frame time by ~0.8% in some of my
driver_overhead_2 tests on a mobile device.
Default implementation is FromGLenum<BufferBinding>
https://crsrc.org/c/third_party/angle/src/common/PackedGLEnums_autogen.cpp;drc=0bb109aa3311f35bf0b51bcda3d7e095048168c8;l=106
and has 15 cases. This CL avoids the call for 3 of those cases,
most common ones according to frequency of glBindBuffer arg
in our trace cpp files.

This mapping adds compare/branch instructions for each case, hence
inlining increases the caller a little. In this case the increase is
about 60 bytes. With the total of 23 callers (GL_*Buffer* exports), this
increase the .so size by ~1.3KB. Just inlining the function would yield
higher bloat and wouldn't prioritize the common cases.

Bug: b/383305597
Change-Id: Icc205fd46fb8ef195c8ffaf67f9cd5194d1d1a5d
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6148838
Reviewed-by: Shahbaz Youssefi <[email protected]>
Reviewed-by: Geoff Lang <[email protected]>
Commit-Queue: Roman Lavrov <[email protected]>
  • Loading branch information
romanl-g authored and Angle LUCI CQ committed Jan 6, 2025
1 parent 2c025cb commit 1a8d771
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/common/PackedEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,27 @@ PackParam(FromT from)
"Data types are different");
return reinterpret_cast<EnumT>(from);
}

// Optimized specialization to avoid function call in common cases
template <>
ANGLE_INLINE typename gl::BufferBinding PackParam<gl::BufferBinding>(GLenum from)
{
if (ANGLE_LIKELY(from == GL_ARRAY_BUFFER))
{
return gl::BufferBinding::Array;
}
if (ANGLE_LIKELY(from == GL_ELEMENT_ARRAY_BUFFER))
{
return gl::BufferBinding::ElementArray;
}
if (ANGLE_LIKELY(from == GL_UNIFORM_BUFFER))
{
return gl::BufferBinding::Uniform;
}

// Fall back to the default implementation
return FromGLenum<gl::BufferBinding>(from);
}
} // namespace gl

#endif // COMMON_PACKEDGLENUMS_H_

0 comments on commit 1a8d771

Please sign in to comment.