Commit 44183cce by Jamie Madill Committed by Commit Bot

Micro-optimizations to draw call entry point.

Thanks to Markus from NVIDIA. This inlines some methods and optimizes the check if a uniform is a bool type. BUG=angleproject:2119 Change-Id: I6f2c2d22c577458b39de600d3c56ec8e1a456a7a Reviewed-on: https://chromium-review.googlesource.com/591699 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org>
parent 5788d24b
......@@ -60,22 +60,6 @@ bool MemoryBuffer::resize(size_t size)
return true;
}
size_t MemoryBuffer::size() const
{
return mSize;
}
const uint8_t *MemoryBuffer::data() const
{
return mData;
}
uint8_t *MemoryBuffer::data()
{
ASSERT(mData);
return mData;
}
void MemoryBuffer::fill(uint8_t datum)
{
if (!empty())
......
......@@ -9,6 +9,7 @@
#include "common/Optional.h"
#include "common/angleutils.h"
#include "common/debug.h"
#include <stdint.h>
#include <cstddef>
......@@ -26,11 +27,15 @@ class MemoryBuffer final : NonCopyable
MemoryBuffer &operator=(MemoryBuffer &&other);
bool resize(size_t size);
size_t size() const;
size_t size() const { return mSize; }
bool empty() const { return mSize == 0; }
const uint8_t *data() const;
uint8_t *data();
const uint8_t *data() const { return mData; }
uint8_t *data()
{
ASSERT(mData);
return mData;
}
void fill(uint8_t datum);
......
......@@ -254,4 +254,24 @@ std::string ToString(const T &value)
return gl::InternalError() << "Integer overflow."; \
}
// The below inlining code lifted from V8.
#if defined(__clang__) || defined(__GNUC__)
#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
#define ANGLE_HAS___FORCEINLINE 0
#elif defined(_MSC_VER)
#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE 0
#define ANGLE_HAS___FORCEINLINE 1
#else
#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE 0
#define ANGLE_HAS___FORCEINLINE 0
#endif
#if defined(NDEBUG) && ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE
#define ANGLE_INLINE inline __attribute__((always_inline))
#elif defined(NDEBUG) && ANGLE_HAS___FORCEINLINE
#define ANGLE_INLINE __forceinline
#else
#define ANGLE_INLINE inline
#endif
#endif // COMMON_ANGLEUTILS_H_
......@@ -23,6 +23,7 @@ namespace gl
int VariableComponentCount(GLenum type);
GLenum VariableComponentType(GLenum type);
bool IsVariableComponentTypeBool(GLenum type);
size_t VariableComponentSize(GLenum type);
size_t VariableInternalSize(GLenum type);
size_t VariableExternalSize(GLenum type);
......@@ -41,6 +42,17 @@ int MatrixRegisterCount(GLenum type, bool isRowMajorMatrix);
int MatrixComponentCount(GLenum type, bool isRowMajorMatrix);
int VariableSortOrder(GLenum type);
// Inlined for speed
ANGLE_INLINE bool IsVariableComponentTypeBool(GLenum type)
{
static_assert((GL_BOOL_VEC2 == GL_BOOL + 1) && (GL_BOOL_VEC3 == GL_BOOL + 2) &&
(GL_BOOL_VEC4 == GL_BOOL + 3),
"GL_BOOL and GL_BOOL_VEC2-4 are contiguous");
ASSERT((static_cast<uint32_t>(type - GL_BOOL) <= 3) ==
(VariableComponentType(type) == GL_BOOL));
return (static_cast<uint32_t>(type - GL_BOOL) <= 3);
}
int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize);
static const GLenum FirstCubeMapTextureTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
......
......@@ -934,7 +934,7 @@ class Context final : public ValidationContext
};
template <EntryPoint EP, typename... ArgsT>
void Context::gatherParams(ArgsT &&... args)
ANGLE_INLINE void Context::gatherParams(ArgsT &&... args)
{
static_assert(sizeof(EntryPointParamType<EP>) <= kParamsBufferSize,
"Params struct too large, please increase kParamsBufferSize.");
......
......@@ -2901,7 +2901,9 @@ GLsizei Program::setUniformInternal(GLint location, GLsizei countIn, int vectorS
count = maxElementCount / vectorSize;
}
if (VariableComponentType(linkedUniform->type) == GL_BOOL)
// VariableComponentType(linkedUniform->type) has a dozens of compares and thus is evil for
// inlining with regards to code size. This version is one subtract and one compare only.
if (IsVariableComponentTypeBool(linkedUniform->type))
{
// Do a cast conversion for boolean types. From the spec:
// "The uniform is set to FALSE if the input value is 0 or 0.0f, and set to TRUE otherwise."
......
......@@ -83,18 +83,6 @@ size_t LinkedUniform::dataSize() const
return mLazyData.size();
}
uint8_t *LinkedUniform::data()
{
if (mLazyData.empty())
{
// dataSize() will init the data store.
size_t size = dataSize();
memset(mLazyData.data(), 0, size);
}
return mLazyData.data();
}
const uint8_t *LinkedUniform::data() const
{
return const_cast<LinkedUniform *>(this)->data();
......
......@@ -38,7 +38,17 @@ struct LinkedUniform : public sh::Uniform
~LinkedUniform();
size_t dataSize() const;
uint8_t *data();
uint8_t *data()
{
if (mLazyData.empty())
{
// dataSize() will init the data store.
size_t size = dataSize();
memset(mLazyData.data(), 0, size);
}
return mLazyData.data();
}
const uint8_t *data() const;
bool isSampler() const;
bool isImage() const;
......
......@@ -20,15 +20,6 @@ namespace gl
constexpr ParamTypeInfo ParamsBase::TypeInfo;
constexpr ParamTypeInfo HasIndexRange::TypeInfo;
ParamsBase::ParamsBase(Context *context, ...)
{
}
HasIndexRange::HasIndexRange(Context *context, GLsizei count, GLenum type, const void *indices)
: ParamsBase(context), mContext(context), mCount(count), mType(type), mIndices(indices)
{
}
const Optional<IndexRange> &HasIndexRange::getIndexRange() const
{
if (mIndexRange.valid())
......
......@@ -53,7 +53,7 @@ class ParamTypeInfo
class ParamsBase : angle::NonCopyable
{
public:
ParamsBase(Context *context, ...);
ParamsBase(Context *context, ...){};
template <EntryPoint EP, typename... ArgsT>
static void Factory(EntryPointParamType<EP> *objBuffer, ArgsT... args);
......@@ -63,7 +63,7 @@ class ParamsBase : angle::NonCopyable
// static
template <EntryPoint EP, typename... ArgsT>
void ParamsBase::Factory(EntryPointParamType<EP> *objBuffer, ArgsT... args)
ANGLE_INLINE void ParamsBase::Factory(EntryPointParamType<EP> *objBuffer, ArgsT... args)
{
new (objBuffer) EntryPointParamType<EP>(args...);
}
......@@ -71,7 +71,10 @@ void ParamsBase::Factory(EntryPointParamType<EP> *objBuffer, ArgsT... args)
class HasIndexRange : public ParamsBase
{
public:
HasIndexRange(Context *context, GLsizei count, GLenum type, const void *indices);
HasIndexRange(Context *context, GLsizei count, GLenum type, const void *indices)
: ParamsBase(context), mContext(context), mCount(count), mType(type), mIndices(indices)
{
}
template <EntryPoint EP, typename... ArgsT>
static void Factory(HasIndexRange *objBuffer, ArgsT... args);
......
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