Replace static inline with constexpr where possible.
This commit is contained in:
parent
2f87f85278
commit
eabede8cdf
@ -109,7 +109,7 @@ id<MTLComputePipelineState> MVKCommandEncodingPool::getCmdFillBufferMTLComputePi
|
|||||||
MVK_ENC_REZ_ACCESS(_mtlFillBufferComputePipelineState, newCmdFillBufferMTLComputePipelineState(_commandPool));
|
MVK_ENC_REZ_ACCESS(_mtlFillBufferComputePipelineState, newCmdFillBufferMTLComputePipelineState(_commandPool));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t getRenderpassLoadStoreStateIndex(MVKFormatType type) {
|
constexpr uint32_t getRenderpassLoadStoreStateIndex(MVKFormatType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case kMVKFormatColorHalf:
|
case kMVKFormatColorHalf:
|
||||||
case kMVKFormatColorFloat:
|
case kMVKFormatColorFloat:
|
||||||
|
@ -314,7 +314,7 @@ uint32_t mvkGetAttachments(const VkRenderingInfo* pRenderingInfo,
|
|||||||
VkClearValue clearValues[]);
|
VkClearValue clearValues[]);
|
||||||
|
|
||||||
/** Returns whether the view mask uses multiview. */
|
/** Returns whether the view mask uses multiview. */
|
||||||
static inline bool mvkIsMultiview(uint32_t viewMask) { return viewMask != 0; }
|
constexpr bool mvkIsMultiview(uint32_t viewMask) { return viewMask != 0; }
|
||||||
|
|
||||||
/** Returns whether the attachment is being used. */
|
/** Returns whether the attachment is being used. */
|
||||||
bool mvkIsColorAttachmentUsed(const VkPipelineRenderingCreateInfo* pRendInfo, uint32_t colorAttIdx);
|
bool mvkIsColorAttachmentUsed(const VkPipelineRenderingCreateInfo* pRendInfo, uint32_t colorAttIdx);
|
||||||
|
@ -176,7 +176,7 @@ struct CIE1931XY {
|
|||||||
// According to D.3.28:
|
// According to D.3.28:
|
||||||
// "[x and y] specify the normalized x and y chromaticity coordinates, respectively...
|
// "[x and y] specify the normalized x and y chromaticity coordinates, respectively...
|
||||||
// in normalized increments of 0.00002."
|
// in normalized increments of 0.00002."
|
||||||
static inline uint16_t FloatToCIE1931Unorm(float x) { return OSSwapHostToBigInt16((uint16_t)(x * 100000 / 2)); }
|
constexpr uint16_t FloatToCIE1931Unorm(float x) { return OSSwapHostToBigInt16((uint16_t)(x * 100000 / 2)); }
|
||||||
static inline CIE1931XY VkXYColorEXTToCIE1931XY(VkXYColorEXT xy) {
|
static inline CIE1931XY VkXYColorEXTToCIE1931XY(VkXYColorEXT xy) {
|
||||||
return { FloatToCIE1931Unorm(xy.x), FloatToCIE1931Unorm(xy.y) };
|
return { FloatToCIE1931Unorm(xy.x), FloatToCIE1931Unorm(xy.y) };
|
||||||
}
|
}
|
||||||
|
@ -137,8 +137,7 @@ static inline std::string mvkGetMoltenVKVersionString(uint32_t mvkVersion) {
|
|||||||
|
|
||||||
/** Returns whether the specified positive value is a power-of-two. */
|
/** Returns whether the specified positive value is a power-of-two. */
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline bool mvkIsPowerOfTwo(T value) {
|
constexpr bool mvkIsPowerOfTwo(T value) {
|
||||||
// Test POT: (x != 0) && ((x & (x - 1)) == 0)
|
|
||||||
return value && ((value & (value - 1)) == 0);
|
return value && ((value & (value - 1)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +147,7 @@ static inline bool mvkIsPowerOfTwo(T value) {
|
|||||||
* that is larger than the specified value is returned.
|
* that is larger than the specified value is returned.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline T mvkEnsurePowerOfTwo(T value) {
|
constexpr T mvkEnsurePowerOfTwo(T value) {
|
||||||
if (mvkIsPowerOfTwo(value)) { return value; }
|
if (mvkIsPowerOfTwo(value)) { return value; }
|
||||||
|
|
||||||
T pot = 1;
|
T pot = 1;
|
||||||
@ -163,7 +162,7 @@ static inline T mvkEnsurePowerOfTwo(T value) {
|
|||||||
* This implementation returns zero for both zero and one as inputs.
|
* This implementation returns zero for both zero and one as inputs.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline T mvkPowerOfTwoExponent(T value) {
|
constexpr T mvkPowerOfTwoExponent(T value) {
|
||||||
T p2Value = mvkEnsurePowerOfTwo(value);
|
T p2Value = mvkEnsurePowerOfTwo(value);
|
||||||
|
|
||||||
// Count the trailing zeros
|
// Count the trailing zeros
|
||||||
@ -184,7 +183,7 @@ static inline T mvkPowerOfTwoExponent(T value) {
|
|||||||
* This is a low level utility method. Usually you will use the convenience functions
|
* This is a low level utility method. Usually you will use the convenience functions
|
||||||
* mvkAlignAddress() and mvkAlignByteCount() to align addresses and offsets respectively.
|
* mvkAlignAddress() and mvkAlignByteCount() to align addresses and offsets respectively.
|
||||||
*/
|
*/
|
||||||
static inline uintptr_t mvkAlignByteRef(uintptr_t byteRef, uintptr_t byteAlignment, bool alignDown = false) {
|
constexpr uintptr_t mvkAlignByteRef(uintptr_t byteRef, uintptr_t byteAlignment, bool alignDown = false) {
|
||||||
if (byteAlignment == 0) { return byteRef; }
|
if (byteAlignment == 0) { return byteRef; }
|
||||||
|
|
||||||
assert(mvkIsPowerOfTwo(byteAlignment));
|
assert(mvkIsPowerOfTwo(byteAlignment));
|
||||||
@ -213,7 +212,7 @@ static inline void* mvkAlignAddress(void* address, uintptr_t byteAlignment, bool
|
|||||||
* which will be greater than or equal to the original offset if alignDown is false, or less
|
* which will be greater than or equal to the original offset if alignDown is false, or less
|
||||||
* than or equal to the original offset if alignDown is true.
|
* than or equal to the original offset if alignDown is true.
|
||||||
*/
|
*/
|
||||||
static inline uintptr_t mvkAlignByteCount(uintptr_t byteCount, uintptr_t byteAlignment, bool alignDown = false) {
|
constexpr uint64_t mvkAlignByteCount(uint64_t byteCount, uint64_t byteAlignment, bool alignDown = false) {
|
||||||
return mvkAlignByteRef(byteCount, byteAlignment, alignDown);
|
return mvkAlignByteRef(byteCount, byteAlignment, alignDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,22 +253,22 @@ static inline VkExtent2D mvkVkExtent2DFromVkExtent3D(VkExtent3D e) { return {e.w
|
|||||||
static inline VkExtent3D mvkVkExtent3DFromVkExtent2D(VkExtent2D e) { return {e.width, e.height, 1U }; }
|
static inline VkExtent3D mvkVkExtent3DFromVkExtent2D(VkExtent2D e) { return {e.width, e.height, 1U }; }
|
||||||
|
|
||||||
/** Returns whether the two Vulkan extents are equal by comparing their respective components. */
|
/** Returns whether the two Vulkan extents are equal by comparing their respective components. */
|
||||||
static inline bool mvkVkExtent2DsAreEqual(VkExtent2D e1, VkExtent2D e2) {
|
constexpr bool mvkVkExtent2DsAreEqual(VkExtent2D e1, VkExtent2D e2) {
|
||||||
return (e1.width == e2.width) && (e1.height == e2.height);
|
return (e1.width == e2.width) && (e1.height == e2.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns whether the two Vulkan extents are equal by comparing their respective components. */
|
/** Returns whether the two Vulkan extents are equal by comparing their respective components. */
|
||||||
static inline bool mvkVkExtent3DsAreEqual(VkExtent3D e1, VkExtent3D e2) {
|
constexpr bool mvkVkExtent3DsAreEqual(VkExtent3D e1, VkExtent3D e2) {
|
||||||
return (e1.width == e2.width) && (e1.height == e2.height) && (e1.depth == e2.depth);
|
return (e1.width == e2.width) && (e1.height == e2.height) && (e1.depth == e2.depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns whether the two Vulkan offsets are equal by comparing their respective components. */
|
/** Returns whether the two Vulkan offsets are equal by comparing their respective components. */
|
||||||
static inline bool mvkVkOffset2DsAreEqual(VkOffset2D os1, VkOffset2D os2) {
|
constexpr bool mvkVkOffset2DsAreEqual(VkOffset2D os1, VkOffset2D os2) {
|
||||||
return (os1.x == os2.x) && (os1.y == os2.y);
|
return (os1.x == os2.x) && (os1.y == os2.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns whether the two Vulkan offsets are equal by comparing their respective components. */
|
/** Returns whether the two Vulkan offsets are equal by comparing their respective components. */
|
||||||
static inline bool mvkVkOffset3DsAreEqual(VkOffset3D os1, VkOffset3D os2) {
|
constexpr bool mvkVkOffset3DsAreEqual(VkOffset3D os1, VkOffset3D os2) {
|
||||||
return (os1.x == os2.x) && (os1.y == os2.y) && (os1.z == os2.z);
|
return (os1.x == os2.x) && (os1.y == os2.y) && (os1.z == os2.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,9 +285,9 @@ static inline VkOffset3D mvkVkOffset3DDifference(VkOffset3D minuend, VkOffset3D
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Packs the four swizzle components into a single 32-bit word. */
|
/** Packs the four swizzle components into a single 32-bit word. */
|
||||||
static inline uint32_t mvkPackSwizzle(VkComponentMapping components) {
|
constexpr uint32_t mvkPackSwizzle(VkComponentMapping components) {
|
||||||
return ((components.r & 0xFF) << 0) | ((components.g & 0xFF) << 8) |
|
return (((components.r & 0xFF) << 0) | ((components.g & 0xFF) << 8) |
|
||||||
((components.b & 0xFF) << 16) | ((components.a & 0xFF) << 24);
|
((components.b & 0xFF) << 16) | ((components.a & 0xFF) << 24));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Unpacks a single 32-bit word containing four swizzle components. */
|
/** Unpacks a single 32-bit word containing four swizzle components. */
|
||||||
@ -311,9 +310,9 @@ static inline VkComponentMapping mvkUnpackSwizzle(uint32_t packed) {
|
|||||||
* 3) Either cs1 or cs2 is VK_COMPONENT_SWIZZLE_MAX_ENUM, which is considered a wildcard,
|
* 3) Either cs1 or cs2 is VK_COMPONENT_SWIZZLE_MAX_ENUM, which is considered a wildcard,
|
||||||
* and matches any value.
|
* and matches any value.
|
||||||
*/
|
*/
|
||||||
static inline bool mvkVKComponentSwizzlesMatch(VkComponentSwizzle cs1,
|
constexpr bool mvkVKComponentSwizzlesMatch(VkComponentSwizzle cs1,
|
||||||
VkComponentSwizzle cs2,
|
VkComponentSwizzle cs2,
|
||||||
VkComponentSwizzle csPos) {
|
VkComponentSwizzle csPos) {
|
||||||
return ((cs1 == cs2) ||
|
return ((cs1 == cs2) ||
|
||||||
((cs1 == VK_COMPONENT_SWIZZLE_IDENTITY) && (cs2 == csPos)) ||
|
((cs1 == VK_COMPONENT_SWIZZLE_IDENTITY) && (cs2 == csPos)) ||
|
||||||
((cs2 == VK_COMPONENT_SWIZZLE_IDENTITY) && (cs1 == csPos)) ||
|
((cs2 == VK_COMPONENT_SWIZZLE_IDENTITY) && (cs1 == csPos)) ||
|
||||||
@ -328,7 +327,7 @@ static inline bool mvkVKComponentSwizzlesMatch(VkComponentSwizzle cs1,
|
|||||||
* A component value of VK_COMPONENT_SWIZZLE_MAX_ENUM is considered a wildcard and matches
|
* A component value of VK_COMPONENT_SWIZZLE_MAX_ENUM is considered a wildcard and matches
|
||||||
* any value in the corresponding component in the other mapping.
|
* any value in the corresponding component in the other mapping.
|
||||||
*/
|
*/
|
||||||
static inline bool mvkVkComponentMappingsMatch(VkComponentMapping cm1, VkComponentMapping cm2) {
|
constexpr bool mvkVkComponentMappingsMatch(VkComponentMapping cm1, VkComponentMapping cm2) {
|
||||||
return (mvkVKComponentSwizzlesMatch(cm1.r, cm2.r, VK_COMPONENT_SWIZZLE_R) &&
|
return (mvkVKComponentSwizzlesMatch(cm1.r, cm2.r, VK_COMPONENT_SWIZZLE_R) &&
|
||||||
mvkVKComponentSwizzlesMatch(cm1.g, cm2.g, VK_COMPONENT_SWIZZLE_G) &&
|
mvkVKComponentSwizzlesMatch(cm1.g, cm2.g, VK_COMPONENT_SWIZZLE_G) &&
|
||||||
mvkVKComponentSwizzlesMatch(cm1.b, cm2.b, VK_COMPONENT_SWIZZLE_B) &&
|
mvkVKComponentSwizzlesMatch(cm1.b, cm2.b, VK_COMPONENT_SWIZZLE_B) &&
|
||||||
@ -342,7 +341,7 @@ static inline bool mvkVkComponentMappingsMatch(VkComponentMapping cm1, VkCompone
|
|||||||
#pragma mark Math
|
#pragma mark Math
|
||||||
|
|
||||||
/** Rounds the value to nearest integer using half-to-even rounding. */
|
/** Rounds the value to nearest integer using half-to-even rounding. */
|
||||||
static inline double mvkRoundHalfToEven(const double val) {
|
constexpr double mvkRoundHalfToEven(const double val) {
|
||||||
return val - std::remainder(val, 1.0); // remainder() uses half-to-even rounding
|
return val - std::remainder(val, 1.0); // remainder() uses half-to-even rounding
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,7 +555,7 @@ bool mvkAreEqual(const T* pV1, const T* pV2, size_t count = 1) {
|
|||||||
* otherwise returns false. This functionality is different than the char version of mvkAreEqual(),
|
* otherwise returns false. This functionality is different than the char version of mvkAreEqual(),
|
||||||
* which works on individual chars or char arrays, not strings.
|
* which works on individual chars or char arrays, not strings.
|
||||||
*/
|
*/
|
||||||
static inline bool mvkStringsAreEqual(const char* pV1, const char* pV2, size_t count = 1) {
|
constexpr bool mvkStringsAreEqual(const char* pV1, const char* pV2, size_t count = 1) {
|
||||||
return (pV1 && pV2) ? (strcmp(pV1, pV2) == 0) : false;
|
return (pV1 && pV2) ? (strcmp(pV1, pV2) == 0) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,7 +572,7 @@ static inline bool mvkStringsAreEqual(const char* pV1, const char* pV2, size_t c
|
|||||||
* If the destination pointer is NULL, does nothing, and returns false.
|
* If the destination pointer is NULL, does nothing, and returns false.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool mvkSetOrClear(T* pDest, const T* pSrc) {
|
constexpr bool mvkSetOrClear(T* pDest, const T* pSrc) {
|
||||||
if (pDest && pSrc) {
|
if (pDest && pSrc) {
|
||||||
*pDest = *pSrc;
|
*pDest = *pSrc;
|
||||||
return true;
|
return true;
|
||||||
@ -595,17 +594,17 @@ void mvkDisableFlags(Tv& value, const Tm bitMask) { value = (Tv)(value & ~(Tv)bi
|
|||||||
|
|
||||||
/** Returns whether the specified value has ANY of the flags specified in bitMask enabled (set to 1). */
|
/** Returns whether the specified value has ANY of the flags specified in bitMask enabled (set to 1). */
|
||||||
template<typename Tv, typename Tm>
|
template<typename Tv, typename Tm>
|
||||||
bool mvkIsAnyFlagEnabled(Tv value, const Tm bitMask) { return ((value & bitMask) != 0); }
|
constexpr bool mvkIsAnyFlagEnabled(Tv value, const Tm bitMask) { return ((value & bitMask) != 0); }
|
||||||
|
|
||||||
/** Returns whether the specified value has ALL of the flags specified in bitMask enabled (set to 1). */
|
/** Returns whether the specified value has ALL of the flags specified in bitMask enabled (set to 1). */
|
||||||
template<typename Tv, typename Tm>
|
template<typename Tv, typename Tm>
|
||||||
bool mvkAreAllFlagsEnabled(Tv value, const Tm bitMask) { return ((value & bitMask) == bitMask); }
|
constexpr bool mvkAreAllFlagsEnabled(Tv value, const Tm bitMask) { return ((value & bitMask) == bitMask); }
|
||||||
|
|
||||||
/** Returns whether the specified value has ONLY one or more of the flags specified in bitMask enabled (set to 1), and none others. */
|
/** Returns whether the specified value has ONLY one or more of the flags specified in bitMask enabled (set to 1), and none others. */
|
||||||
template<typename Tv, typename Tm>
|
template<typename Tv, typename Tm>
|
||||||
bool mvkIsOnlyAnyFlagEnabled(Tv value, const Tm bitMask) { return (mvkIsAnyFlagEnabled(value, bitMask) && ((value | bitMask) == bitMask)); }
|
constexpr bool mvkIsOnlyAnyFlagEnabled(Tv value, const Tm bitMask) { return (mvkIsAnyFlagEnabled(value, bitMask) && ((value | bitMask) == bitMask)); }
|
||||||
|
|
||||||
/** Returns whether the specified value has ONLY ALL of the flags specified in bitMask enabled (set to 1), and none others. */
|
/** Returns whether the specified value has ONLY ALL of the flags specified in bitMask enabled (set to 1), and none others. */
|
||||||
template<typename Tv, typename Tm>
|
template<typename Tv, typename Tm>
|
||||||
bool mvkAreOnlyAllFlagsEnabled(Tv value, const Tm bitMask) { return (value == bitMask); }
|
constexpr bool mvkAreOnlyAllFlagsEnabled(Tv value, const Tm bitMask) { return (value == bitMask); }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user