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)
#define ANGLE_TRACE_ENABLED
#endif
#define ANGLE_EMPTY_STATEMENT for (;;) break
#if !defined(NDEBUG) || defined(ANGLE_ENABLE_RELEASE_ASSERTS)
#define ANGLE_ENABLE_ASSERTS
#endif
......@@ -281,34 +280,34 @@ std::ostream &FmtHex(std::ostream &os, T value)
#if defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS)
#define UNIMPLEMENTED() \
do \
{ \
WARN() << "\t! Unimplemented: " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ \
<< ")"; \
ASSERT(NOASSERT_UNIMPLEMENTED); \
} \
ANGLE_EMPTY_STATEMENT
} while (0)
// A macro for code which is not expected to be reached under valid assumptions
#define UNREACHABLE() \
do \
{ \
ERR() << "\t! Unreachable reached: " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ \
<< ")"; \
ASSERT(false); \
} \
ANGLE_EMPTY_STATEMENT
} while (0)
#else
#define UNIMPLEMENTED() \
do \
{ \
ASSERT(NOASSERT_UNIMPLEMENTED); \
} \
ANGLE_EMPTY_STATEMENT
} while (0)
// A macro for code which is not expected to be reached under valid assumptions
#define UNREACHABLE() \
do \
{ \
ASSERT(false); \
} \
ANGLE_EMPTY_STATEMENT
} while (0)
#endif // defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS)
#if defined(ANGLE_PLATFORM_WINDOWS)
......
......@@ -191,20 +191,21 @@ inline Error NoError()
#define ANGLE_LOCAL_VAR ANGLE_CONCAT2(_localVar, __LINE__)
#define ANGLE_TRY_TEMPLATE(EXPR, FUNC) \
do \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
{ \
FUNC(ANGLE_LOCAL_VAR); \
} \
} \
ANGLE_EMPTY_STATEMENT
} while (0)
#define ANGLE_RETURN(X) return X;
#define ANGLE_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_RETURN);
// TODO(jmadill): Remove this once refactor is complete. http://anglebug.com/2491
#define ANGLE_TRY_HANDLE(CONTEXT, EXPR) \
do \
{ \
auto ANGLE_LOCAL_VAR = (EXPR); \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
......@@ -212,19 +213,18 @@ inline Error NoError()
CONTEXT->handleError(ANGLE_LOCAL_VAR); \
return angle::Result::Stop(); \
} \
} \
ANGLE_EMPTY_STATEMENT
} while (0)
// TODO(jmadill): Introduce way to store errors to a const Context. http://anglebug.com/2491
#define ANGLE_SWALLOW_ERR(EXPR) \
do \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
{ \
ERR() << "Unhandled internal error: " << ANGLE_LOCAL_VAR; \
} \
} \
ANGLE_EMPTY_STATEMENT
} while (0)
#undef ANGLE_LOCAL_VAR
#undef ANGLE_CONCAT2
......
......@@ -860,6 +860,7 @@ VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bo
} // namespace rx
#define ANGLE_VK_TRY(context, command) \
do \
{ \
auto ANGLE_LOCAL_VAR = command; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR != VK_SUCCESS)) \
......@@ -867,10 +868,27 @@ VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bo
context->handleError(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \
return angle::Result::Stop(); \
} \
} \
ANGLE_EMPTY_STATEMENT
} while (0)
#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; \
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
context->handleError(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \
return angle::Result::Stop(); \
} \
result = ANGLE_LOCAL_VAR == VK_SUCCESS ? angle::Result::Continue() \
: angle::Result::Incomplete(); \
} \
ANGLE_EMPTY_STATEMENT
return ANGLE_LOCAL_VAR == VK_SUCCESS ? angle::Result::Continue() \
: angle::Result::Incomplete(); \
} while (0)
#define ANGLE_VK_TRY_ALLOW_INCOMPLETE(context, command, result) \
ANGLE_VK_TRY_ALLOW_OTHER(context, command, VK_INCOMPLETE, result)
#define ANGLE_VK_TRY_RETURN_ALLOW_INCOMPLETE(context, command) \
ANGLE_VK_TRY_RETURN_ALLOW_OTHER(context, command, VK_INCOMPLETE)
#define ANGLE_VK_TRY_ALLOW_NOT_READY(context, command, result) \
ANGLE_VK_TRY_ALLOW_OTHER(context, command, VK_NOT_READY, 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)
#define ANGLE_VK_TRY_RETURN_ALLOW_NOT_READY(context, command) \
ANGLE_VK_TRY_RETURN_ALLOW_OTHER(context, command, VK_NOT_READY)
#endif // LIBANGLE_RENDERER_VULKAN_VK_UTILS_H_
......@@ -470,14 +470,15 @@ bool IsDebug();
bool IsRelease();
// Note: git cl format messes up this formatting.
#define ANGLE_SKIP_TEST_IF(COND) \
\
if (COND) \
\
{ \
std::cout << "Test skipped: " #COND "." << std::endl; \
return; \
} \
ANGLE_EMPTY_STATEMENT
#define ANGLE_SKIP_TEST_IF(COND) \
do \
{ \
if (COND) \
\
{ \
std::cout << "Test skipped: " #COND "." << std::endl; \
return; \
} \
} while (0)
#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