Commit 6f1dc51b by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Use a specialized macro for wrapped vulkan calls

Vulkan wrapper functions are fairly straightforward. They call the Vulkan function and return immediately. The specialized macros introduced in this commit take care of the final return for brevity of the warpper. Additionally, this commit gets rid of ANGLE_EMPTY_STATEMENT in favor of the more robust macro definition using do {} while (0). Bug: none Change-Id: Ia7c68962d1aeee2c06ef210122b345b1a2e54f08 Reviewed-on: https://chromium-review.googlesource.com/c/1262020 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 957e9b82
...@@ -214,7 +214,6 @@ std::ostream &FmtHex(std::ostream &os, T value) ...@@ -214,7 +214,6 @@ std::ostream &FmtHex(std::ostream &os, T value)
#define ANGLE_TRACE_ENABLED #define ANGLE_TRACE_ENABLED
#endif #endif
#define ANGLE_EMPTY_STATEMENT for (;;) break
#if !defined(NDEBUG) || defined(ANGLE_ENABLE_RELEASE_ASSERTS) #if !defined(NDEBUG) || defined(ANGLE_ENABLE_RELEASE_ASSERTS)
#define ANGLE_ENABLE_ASSERTS #define ANGLE_ENABLE_ASSERTS
#endif #endif
...@@ -281,34 +280,34 @@ std::ostream &FmtHex(std::ostream &os, T value) ...@@ -281,34 +280,34 @@ std::ostream &FmtHex(std::ostream &os, T value)
#if defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS) #if defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS)
#define UNIMPLEMENTED() \ #define UNIMPLEMENTED() \
do \
{ \ { \
WARN() << "\t! Unimplemented: " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ \ WARN() << "\t! Unimplemented: " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ \
<< ")"; \ << ")"; \
ASSERT(NOASSERT_UNIMPLEMENTED); \ ASSERT(NOASSERT_UNIMPLEMENTED); \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
// A macro for code which is not expected to be reached under valid assumptions // A macro for code which is not expected to be reached under valid assumptions
#define UNREACHABLE() \ #define UNREACHABLE() \
do \
{ \ { \
ERR() << "\t! Unreachable reached: " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ \ ERR() << "\t! Unreachable reached: " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ \
<< ")"; \ << ")"; \
ASSERT(false); \ ASSERT(false); \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
#else #else
#define UNIMPLEMENTED() \ #define UNIMPLEMENTED() \
do \
{ \ { \
ASSERT(NOASSERT_UNIMPLEMENTED); \ ASSERT(NOASSERT_UNIMPLEMENTED); \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
// A macro for code which is not expected to be reached under valid assumptions // A macro for code which is not expected to be reached under valid assumptions
#define UNREACHABLE() \ #define UNREACHABLE() \
do \
{ \ { \
ASSERT(false); \ ASSERT(false); \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
#endif // defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS) #endif // defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS)
#if defined(ANGLE_PLATFORM_WINDOWS) #if defined(ANGLE_PLATFORM_WINDOWS)
......
...@@ -191,20 +191,21 @@ inline Error NoError() ...@@ -191,20 +191,21 @@ inline Error NoError()
#define ANGLE_LOCAL_VAR ANGLE_CONCAT2(_localVar, __LINE__) #define ANGLE_LOCAL_VAR ANGLE_CONCAT2(_localVar, __LINE__)
#define ANGLE_TRY_TEMPLATE(EXPR, FUNC) \ #define ANGLE_TRY_TEMPLATE(EXPR, FUNC) \
do \
{ \ { \
auto ANGLE_LOCAL_VAR = EXPR; \ auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \ if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
{ \ { \
FUNC(ANGLE_LOCAL_VAR); \ FUNC(ANGLE_LOCAL_VAR); \
} \ } \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
#define ANGLE_RETURN(X) return X; #define ANGLE_RETURN(X) return X;
#define ANGLE_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_RETURN); #define ANGLE_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_RETURN);
// TODO(jmadill): Remove this once refactor is complete. http://anglebug.com/2491 // TODO(jmadill): Remove this once refactor is complete. http://anglebug.com/2491
#define ANGLE_TRY_HANDLE(CONTEXT, EXPR) \ #define ANGLE_TRY_HANDLE(CONTEXT, EXPR) \
do \
{ \ { \
auto ANGLE_LOCAL_VAR = (EXPR); \ auto ANGLE_LOCAL_VAR = (EXPR); \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \ if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
...@@ -212,19 +213,18 @@ inline Error NoError() ...@@ -212,19 +213,18 @@ inline Error NoError()
CONTEXT->handleError(ANGLE_LOCAL_VAR); \ CONTEXT->handleError(ANGLE_LOCAL_VAR); \
return angle::Result::Stop(); \ return angle::Result::Stop(); \
} \ } \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
// TODO(jmadill): Introduce way to store errors to a const Context. http://anglebug.com/2491 // TODO(jmadill): Introduce way to store errors to a const Context. http://anglebug.com/2491
#define ANGLE_SWALLOW_ERR(EXPR) \ #define ANGLE_SWALLOW_ERR(EXPR) \
do \
{ \ { \
auto ANGLE_LOCAL_VAR = EXPR; \ auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \ if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
{ \ { \
ERR() << "Unhandled internal error: " << ANGLE_LOCAL_VAR; \ ERR() << "Unhandled internal error: " << ANGLE_LOCAL_VAR; \
} \ } \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
#undef ANGLE_LOCAL_VAR #undef ANGLE_LOCAL_VAR
#undef ANGLE_CONCAT2 #undef ANGLE_CONCAT2
......
...@@ -860,6 +860,7 @@ VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bo ...@@ -860,6 +860,7 @@ VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bo
} // namespace rx } // namespace rx
#define ANGLE_VK_TRY(context, command) \ #define ANGLE_VK_TRY(context, command) \
do \
{ \ { \
auto ANGLE_LOCAL_VAR = command; \ auto ANGLE_LOCAL_VAR = command; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR != VK_SUCCESS)) \ if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR != VK_SUCCESS)) \
...@@ -867,10 +868,27 @@ VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bo ...@@ -867,10 +868,27 @@ VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bo
context->handleError(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \ context->handleError(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \
return angle::Result::Stop(); \ return angle::Result::Stop(); \
} \ } \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
#define ANGLE_VK_TRY_ALLOW_OTHER(context, command, acceptable, result) \ #define ANGLE_VK_CHECK(context, test, error) ANGLE_VK_TRY(context, test ? VK_SUCCESS : error)
#define ANGLE_VK_CHECK_MATH(context, result) \
ANGLE_VK_CHECK(context, result, VK_ERROR_VALIDATION_FAILED_EXT)
#define ANGLE_VK_CHECK_ALLOC(context, result) \
ANGLE_VK_CHECK(context, result, VK_ERROR_OUT_OF_HOST_MEMORY)
// Macros specifically made for vulkan wrappers (in vk_utils.h) that execute the call and return
// appropriately.
#define ANGLE_VK_TRY_RETURN(context, command) \
do \
{ \
ANGLE_VK_TRY(context, command); \
return angle::Result::Continue(); \
} while (0)
#define ANGLE_VK_TRY_RETURN_ALLOW_OTHER(context, command, acceptable) \
do \
{ \ { \
auto ANGLE_LOCAL_VAR = command; \ auto ANGLE_LOCAL_VAR = command; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR != VK_SUCCESS && ANGLE_LOCAL_VAR != acceptable)) \ if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR != VK_SUCCESS && ANGLE_LOCAL_VAR != acceptable)) \
...@@ -878,23 +896,14 @@ VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bo ...@@ -878,23 +896,14 @@ VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bo
context->handleError(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \ context->handleError(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \
return angle::Result::Stop(); \ return angle::Result::Stop(); \
} \ } \
result = ANGLE_LOCAL_VAR == VK_SUCCESS ? angle::Result::Continue() \ return ANGLE_LOCAL_VAR == VK_SUCCESS ? angle::Result::Continue() \
: angle::Result::Incomplete(); \ : angle::Result::Incomplete(); \
} \ } while (0)
ANGLE_EMPTY_STATEMENT
#define ANGLE_VK_TRY_ALLOW_INCOMPLETE(context, command, result) \ #define ANGLE_VK_TRY_RETURN_ALLOW_INCOMPLETE(context, command) \
ANGLE_VK_TRY_ALLOW_OTHER(context, command, VK_INCOMPLETE, result) ANGLE_VK_TRY_RETURN_ALLOW_OTHER(context, command, VK_INCOMPLETE)
#define ANGLE_VK_TRY_ALLOW_NOT_READY(context, command, result) \ #define ANGLE_VK_TRY_RETURN_ALLOW_NOT_READY(context, command) \
ANGLE_VK_TRY_ALLOW_OTHER(context, command, VK_NOT_READY, result) ANGLE_VK_TRY_RETURN_ALLOW_OTHER(context, command, VK_NOT_READY)
#define ANGLE_VK_CHECK(context, test, error) ANGLE_VK_TRY(context, test ? VK_SUCCESS : error)
#define ANGLE_VK_CHECK_MATH(context, result) \
ANGLE_VK_CHECK(context, result, VK_ERROR_VALIDATION_FAILED_EXT)
#define ANGLE_VK_CHECK_ALLOC(context, result) \
ANGLE_VK_CHECK(context, result, VK_ERROR_OUT_OF_HOST_MEMORY)
#endif // LIBANGLE_RENDERER_VULKAN_VK_UTILS_H_ #endif // LIBANGLE_RENDERER_VULKAN_VK_UTILS_H_
...@@ -470,14 +470,15 @@ bool IsDebug(); ...@@ -470,14 +470,15 @@ bool IsDebug();
bool IsRelease(); bool IsRelease();
// Note: git cl format messes up this formatting. // Note: git cl format messes up this formatting.
#define ANGLE_SKIP_TEST_IF(COND) \ #define ANGLE_SKIP_TEST_IF(COND) \
\ do \
if (COND) \ { \
\ if (COND) \
{ \ \
std::cout << "Test skipped: " #COND "." << std::endl; \ { \
return; \ std::cout << "Test skipped: " #COND "." << std::endl; \
} \ return; \
ANGLE_EMPTY_STATEMENT } \
} while (0)
#endif // ANGLE_TESTS_ANGLE_TEST_H_ #endif // ANGLE_TESTS_ANGLE_TEST_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