Inline CommandAllocator/Iterator

Inlining these hot functions decreases CPU time in perf tests for
DrawCallPerf.Run/Vulkan by roughly 12% (55 to 47ns) and increases
binary size by about 0.16% (~4kB).

Bug: dawn:304
Change-Id: I84e5d011defe88d6f1492dcb54e421c3d1bf099f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14000
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng
2019-12-10 01:10:27 +00:00
committed by Commit Bot service account
parent 56b12422da
commit ff8b3f4397
5 changed files with 138 additions and 114 deletions

View File

@@ -61,6 +61,9 @@
# endif
# define DAWN_DECLARE_UNUSED __attribute__((unused))
# if defined(NDEBUG)
# define DAWN_FORCE_INLINE inline __attribute__((always_inline))
# endif
// MSVC
#elif defined(_MSC_VER)
@@ -77,6 +80,9 @@ extern void __cdecl __debugbreak(void);
# endif
# define DAWN_DECLARE_UNUSED
# if defined(NDEBUG)
# define DAWN_FORCE_INLINE __forceinline
# endif
#else
# error "Unsupported compiler"
@@ -97,5 +103,8 @@ extern void __cdecl __debugbreak(void);
#if !defined(DAWN_NO_DISCARD)
# define DAWN_NO_DISCARD
#endif
#if !defined(DAWN_FORCE_INLINE)
# define DAWN_FORCE_INLINE inline
#endif
#endif // COMMON_COMPILER_H_

View File

@@ -85,13 +85,6 @@ bool IsPtrAligned(const void* ptr, size_t alignment) {
return (reinterpret_cast<size_t>(ptr) & (alignment - 1)) == 0;
}
void* AlignVoidPtr(void* ptr, size_t alignment) {
ASSERT(IsPowerOfTwo(alignment));
ASSERT(alignment != 0);
return reinterpret_cast<void*>((reinterpret_cast<size_t>(ptr) + (alignment - 1)) &
~(alignment - 1));
}
bool IsAligned(uint32_t value, size_t alignment) {
ASSERT(alignment <= UINT32_MAX);
ASSERT(IsPowerOfTwo(alignment));

View File

@@ -15,6 +15,8 @@
#ifndef COMMON_MATH_H_
#define COMMON_MATH_H_
#include "common/Assert.h"
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -35,13 +37,19 @@ bool IsAligned(uint32_t value, size_t alignment);
uint32_t Align(uint32_t value, size_t alignment);
template <typename T>
T* AlignPtr(T* ptr, size_t alignment) {
return static_cast<T*>(AlignVoidPtr(ptr, alignment));
DAWN_FORCE_INLINE T* AlignPtr(T* ptr, size_t alignment) {
ASSERT(IsPowerOfTwo(alignment));
ASSERT(alignment != 0);
return reinterpret_cast<T*>((reinterpret_cast<size_t>(ptr) + (alignment - 1)) &
~(alignment - 1));
}
template <typename T>
const T* AlignPtr(const T* ptr, size_t alignment) {
return static_cast<const T*>(AlignVoidPtr(const_cast<T*>(ptr), alignment));
DAWN_FORCE_INLINE const T* AlignPtr(const T* ptr, size_t alignment) {
ASSERT(IsPowerOfTwo(alignment));
ASSERT(alignment != 0);
return reinterpret_cast<const T*>((reinterpret_cast<size_t>(ptr) + (alignment - 1)) &
~(alignment - 1));
}
template <typename destType, typename sourceType>