Skip to content

Commit

Permalink
IGL: Rename REPORT_ERROR to SOFT_ERROR/SOFT_ASSERT
Browse files Browse the repository at this point in the history
Reviewed By: ChristianK275, AmesingFlank

Differential Revision: D64044393

fbshipit-source-id: e8f3334efb628fadc078ef3f7b23e5d1f72312ba
  • Loading branch information
Eric Griffith authored and facebook-github-bot committed Oct 9, 2024
1 parent b01c815 commit e62aa19
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 72 deletions.
6 changes: 3 additions & 3 deletions shell/android/jni/TinyRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void TinyRenderer::init(AAssetManager* mgr,

IGL_DEBUG_ASSERT(d != nullptr);
// We want to catch failed device creation instead of letting implicitly fail
IGL_REPORT_ERROR(result.isOk());
IGL_SOFT_ASSERT(result.isOk());
if (d) {
platform_ = std::make_shared<igl::shell::PlatformAndroid>(std::move(d));
IGL_DEBUG_ASSERT(platform_ != nullptr);
Expand Down Expand Up @@ -211,7 +211,7 @@ void TinyRenderer::render(float displayScale) {
break;
}
IGL_DEBUG_ASSERT(result.isOk());
IGL_REPORT_ERROR(result.isOk());
IGL_SOFT_ASSERT(result.isOk());

const ContextGuard guard(platform_->getDevice()); // wrap 'session_' operations

Expand All @@ -232,7 +232,7 @@ void TinyRenderer::onSurfacesChanged(ANativeWindow* /*surface*/, int width, int
platform_->getDevice().getPlatformDevice<opengl::egl::PlatformDevice>()->updateSurfaces(
readSurface, drawSurface, &result);
IGL_DEBUG_ASSERT(result.isOk());
IGL_REPORT_ERROR(result.isOk());
IGL_SOFT_ASSERT(result.isOk());
}
#endif

Expand Down
12 changes: 6 additions & 6 deletions src/igl/Assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void _IGLDebugBreak() {

// ----------------------------------------------------------------------------

#if IGL_REPORT_ERROR_ENABLED
#if IGL_SOFT_ERROR_ENABLED

// Default handler is no-op.
// If there's an error, IGL_DEBUG_VERIFY will trap in dev builds
Expand All @@ -69,20 +69,20 @@ static void _IGLReportErrorDefault(const char* file,
const char* format,
...) {}

static IGLReportErrorFunc& GetErrorHandler() {
static IGLReportErrorFunc sHandler = _IGLReportErrorDefault;
static IGLSoftErrorFunc& GetErrorHandler() {
static IGLSoftErrorFunc sHandler = _IGLReportErrorDefault;
return sHandler;
}

IGL_API void IGLReportErrorSetHandler(IGLReportErrorFunc handler) {
IGL_API void IGLSetSoftErrorHandler(IGLSoftErrorFunc handler) {
if (!handler) {
handler = _IGLReportErrorDefault; // prevent null handler
}
GetErrorHandler() = handler;
}

IGL_API IGLReportErrorFunc IGLReportErrorGetHandler(void) {
IGL_API IGLSoftErrorFunc IGLGetSoftErrorHandler(void) {
return GetErrorHandler();
}

#endif // IGL_REPORT_ERROR_ENABLED
#endif // IGL_SOFT_ERROR_ENABLED
40 changes: 20 additions & 20 deletions src/igl/Assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,39 +156,39 @@ template<typename T>
///--------------------------------------
/// MARK: - Custom

#if IGL_REPORT_ERROR_ENABLED
#if IGL_SOFT_ERROR_ENABLED

#define IGL_ERROR_CATEGORY "IGL"

using IGLReportErrorFunc = void (*)(const char* file,
const char* func,
int line,
const char* category,
const char* format,
...);
IGL_API void IGLReportErrorSetHandler(IGLReportErrorFunc handler);
IGL_API IGLReportErrorFunc IGLReportErrorGetHandler(void);

#define IGL_REPORT_ERROR(cond) \
do { \
if (!IGL_DEBUG_VERIFY(cond)) { \
IGLReportErrorGetHandler()(__FILE__, IGL_FUNCTION, __LINE__, IGL_ERROR_CATEGORY, #cond); \
} \
using IGLSoftErrorFunc = void (*)(const char* file,
const char* func,
int line,
const char* category,
const char* format,
...);
IGL_API void IGLSetSoftErrorHandler(IGLSoftErrorFunc handler);
IGL_API IGLSoftErrorFunc IGLGetSoftErrorHandler(void);

#define IGL_SOFT_ASSERT(cond) \
do { \
if (!IGL_DEBUG_VERIFY(cond)) { \
IGLGetSoftErrorHandler()(__FILE__, IGL_FUNCTION, __LINE__, IGL_ERROR_CATEGORY, #cond); \
} \
} while (0)

#define IGL_REPORT_ERROR_MSG(cond, format, ...) \
#define IGL_SOFT_ASSERT_MSG(cond, format, ...) \
do { \
bool cachedCond = (cond); \
IGL_DEBUG_ASSERT(cachedCond, format, ##__VA_ARGS__); \
if (!cachedCond) { \
IGLReportErrorGetHandler()( \
IGLGetSoftErrorHandler()( \
__FILE__, IGL_FUNCTION, __LINE__, IGL_ERROR_CATEGORY, (format), ##__VA_ARGS__); \
} \
} while (0)

#else

#define IGL_REPORT_ERROR(condition) static_cast<void>(0)
#define IGL_REPORT_ERROR_MSG(condition, format, ...) static_cast<void>(0)
#define IGL_SOFT_ASSERT(condition) static_cast<void>(0)
#define IGL_SOFT_ASSERT_MSG(condition, format, ...) static_cast<void>(0)

#endif // IGL_REPORT_ERROR_ENABLED
#endif // IGL_SOFT_ERROR_ENABLED
8 changes: 4 additions & 4 deletions src/igl/IGLSafeC.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ inline void* checked_memcpy(void* destination,
const void* source,
size_t count) {
if (destination_size < count) {
IGL_REPORT_ERROR_MSG(false, "Aborting due to potential buffer overflow");
IGL_SOFT_ASSERT_MSG(false, "Aborting due to potential buffer overflow");
exit(EXIT_FAILURE);
}
return memcpy(destination, source, count);
Expand All @@ -46,7 +46,7 @@ inline void* checked_memcpy_robust(void* destination,
size_t source_size,
size_t count) {
if (destination_size < count || source_size < count) {
IGL_REPORT_ERROR_MSG(false, "Aborting due to potential buffer overflow");
IGL_SOFT_ASSERT_MSG(false, "Aborting due to potential buffer overflow");
exit(EXIT_FAILURE);
}
return memcpy(destination, source, count);
Expand All @@ -66,7 +66,7 @@ inline void* checked_memcpy_offset(void* destination,
const size_t available_size = offset > destination_size ? 0 : destination_size - offset;

if (count > available_size) {
IGL_REPORT_ERROR_MSG(false, "Aborting due to potential buffer overflow");
IGL_SOFT_ASSERT_MSG(false, "Aborting due to potential buffer overflow");
exit(EXIT_FAILURE);
}

Expand All @@ -80,7 +80,7 @@ inline int checked_strncmp(const char* str1,
size_t str2_size,
size_t count) {
if (str1_size < count || str2_size < count) {
IGL_REPORT_ERROR_MSG(false, "Aborting due to potential buffer overflow");
IGL_SOFT_ASSERT_MSG(false, "Aborting due to potential buffer overflow");
exit(EXIT_FAILURE);
}

Expand Down
6 changes: 3 additions & 3 deletions src/igl/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@
// clang-format on

// clang-format off
#if !defined(IGL_REPORT_ERROR_ENABLED)
#if !defined(IGL_SOFT_ERROR_ENABLED)
// Either we have IGL_DEBUG, or Windows/Linux/etc, since we don't have good detection mechanism there.
#if IGL_DEBUG || (!IGL_PLATFORM_APPLE && !IGL_PLATFORM_ANDROID)
#define IGL_REPORT_ERROR_ENABLED 1
#define IGL_SOFT_ERROR_ENABLED 1
#else
#define IGL_REPORT_ERROR_ENABLED 0
#define IGL_SOFT_ERROR_ENABLED 0
#endif
#endif
// clang-format on
Expand Down
10 changes: 5 additions & 5 deletions src/igl/opengl/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void ArrayBuffer::unbind() {
void ArrayBuffer::bindBase(IGL_MAYBE_UNUSED size_t index, Result* outResult) {
if (target_ != GL_SHADER_STORAGE_BUFFER) {
static const char* kErrorMsg = "Buffer should be GL_SHADER_STORAGE_BUFFER";
IGL_REPORT_ERROR_MSG(1, kErrorMsg);
IGL_SOFT_ASSERT_MSG(1, kErrorMsg);
Result::setResult(outResult, Result::Code::InvalidOperation, kErrorMsg);
return;
}
Expand All @@ -192,15 +192,15 @@ void UniformBlockBuffer::bindBase(size_t index, Result* outResult) {
if (getContext().deviceFeatures().hasFeature(DeviceFeatures::UniformBlocks)) {
if (target_ != GL_UNIFORM_BUFFER) {
static const char* kErrorMsg = "Buffer should be GL_UNIFORM_BUFFER";
IGL_REPORT_ERROR_MSG(1, kErrorMsg);
IGL_SOFT_ASSERT_MSG(1, kErrorMsg);
Result::setResult(outResult, Result::Code::InvalidOperation, kErrorMsg);
return;
}
getContext().bindBufferBase(target_, (GLuint)index, iD_);
Result::setOk(outResult);
} else {
static const char* kErrorMsg = "Uniform Blocks are not supported";
IGL_REPORT_ERROR_MSG(1, kErrorMsg);
IGL_SOFT_ASSERT_MSG(1, kErrorMsg);
Result::setResult(outResult, Result::Code::Unimplemented, kErrorMsg);
}
}
Expand All @@ -209,7 +209,7 @@ void UniformBlockBuffer::bindRange(size_t index, size_t offset, Result* outResul
if (getContext().deviceFeatures().hasFeature(DeviceFeatures::UniformBlocks)) {
if (target_ != GL_UNIFORM_BUFFER) {
static const char* kErrorMsg = "Buffer should be GL_UNIFORM_BUFFER";
IGL_REPORT_ERROR_MSG(1, kErrorMsg);
IGL_SOFT_ASSERT_MSG(1, kErrorMsg);
Result::setResult(outResult, Result::Code::InvalidOperation, kErrorMsg);
return;
}
Expand All @@ -221,7 +221,7 @@ void UniformBlockBuffer::bindRange(size_t index, size_t offset, Result* outResul
Result::setOk(outResult);
} else {
static const char* kErrorMsg = "Uniform Blocks are not supported";
IGL_REPORT_ERROR_MSG(1, kErrorMsg);
IGL_SOFT_ASSERT_MSG(1, kErrorMsg);
Result::setResult(outResult, Result::Code::Unimplemented, kErrorMsg);
}
}
Expand Down
42 changes: 21 additions & 21 deletions src/igl/opengl/IContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,35 @@ void logSource(const int count, const char** string, const int* length) {
#define APILOG_SOURCE(count, string, length) static_cast<void>(0)
#endif // defined(IGL_API_LOG) && (IGL_DEBUG || defined(IGL_FORCE_ENABLE_LOGS))

#define GLCALL(funcName) \
IGL_REPORT_ERROR(isCurrentContext() || isCurrentSharegroup()); \
callCounter_++; \
#define GLCALL(funcName) \
IGL_SOFT_ASSERT(isCurrentContext() || isCurrentSharegroup()); \
callCounter_++; \
gl##funcName

#define IGLCALL(funcName) \
IGL_REPORT_ERROR(isCurrentContext() || isCurrentSharegroup()); \
callCounter_++; \
#define IGLCALL(funcName) \
IGL_SOFT_ASSERT(isCurrentContext() || isCurrentSharegroup()); \
callCounter_++; \
igl##funcName

#define GLCALL_WITH_RETURN(ret, funcName) \
IGL_REPORT_ERROR(isCurrentContext() || isCurrentSharegroup()); \
callCounter_++; \
#define GLCALL_WITH_RETURN(ret, funcName) \
IGL_SOFT_ASSERT(isCurrentContext() || isCurrentSharegroup()); \
callCounter_++; \
ret = gl##funcName

#define IGLCALL_WITH_RETURN(ret, funcName) \
IGL_REPORT_ERROR(isCurrentContext() || isCurrentSharegroup()); \
callCounter_++; \
#define IGLCALL_WITH_RETURN(ret, funcName) \
IGL_SOFT_ASSERT(isCurrentContext() || isCurrentSharegroup()); \
callCounter_++; \
ret = igl##funcName

#define GLCALL_PROC(funcPtr, ...) \
IGL_REPORT_ERROR(isCurrentContext() || isCurrentSharegroup()); \
if (IGL_DEBUG_VERIFY(funcPtr)) { \
callCounter_++; \
(*funcPtr)(__VA_ARGS__); \
#define GLCALL_PROC(funcPtr, ...) \
IGL_SOFT_ASSERT(isCurrentContext() || isCurrentSharegroup()); \
if (IGL_DEBUG_VERIFY(funcPtr)) { \
callCounter_++; \
(*funcPtr)(__VA_ARGS__); \
}

#define GLCALL_PROC_WITH_RETURN(ret, funcPtr, returnOnError, ...) \
IGL_REPORT_ERROR(isCurrentContext() || isCurrentSharegroup()); \
IGL_SOFT_ASSERT(isCurrentContext() || isCurrentSharegroup()); \
if (IGL_DEBUG_VERIFY(funcPtr)) { \
callCounter_++; \
ret = (*funcPtr)(__VA_ARGS__); \
Expand Down Expand Up @@ -711,9 +711,9 @@ IContext::IContext() : deviceFeatureSet_(*this) {
}

IContext::~IContext() {
IGL_REPORT_ERROR_MSG(refCount_ == 0,
"Dangling IContext reference left behind."
// @fb-only
IGL_SOFT_ASSERT_MSG(refCount_ == 0,
"Dangling IContext reference left behind."
// @fb-only
);
// Clear the zombie guard explicitly so our "secret" stays secret.
zombieGuard_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/igl/opengl/egl/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ EGLImageKHR Context::createImageFromAndroidHardwareBuffer(AHardwareBuffer* hwb)

this->checkForErrors(__FUNCTION__, __LINE__);

IGL_REPORT_ERROR(this->isCurrentContext() || this->isCurrentSharegroup());
IGL_SOFT_ASSERT(this->isCurrentContext() || this->isCurrentSharegroup());

return eglImage;
}
Expand Down
2 changes: 1 addition & 1 deletion src/igl/opengl/egl/android/NativeHWBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Result NativeHWTextureBuffer::createTextureInternal(const TextureDesc& desc,
}
getContext().checkForErrors(__FUNCTION__, __LINE__);

IGL_REPORT_ERROR(getContext().isCurrentContext() || getContext().isCurrentSharegroup());
IGL_SOFT_ASSERT(getContext().isCurrentContext() || getContext().isCurrentSharegroup());

GLuint tid = 0;
getContext().genTextures(1, &tid);
Expand Down
12 changes: 6 additions & 6 deletions src/igl/tests/util/TestErrorGuard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
#include <string>

igl::tests::util::TestErrorGuard::TestErrorGuard() {
#if IGL_REPORT_ERROR_ENABLED
savedErrorHandler_ = IGLReportErrorGetHandler();
IGLReportErrorSetHandler(ReportErrorHandler);
#if IGL_SOFT_ERROR_ENABLED
savedErrorHandler_ = IGLGetSoftErrorHandler();
IGLSetSoftErrorHandler(ReportErrorHandler);
#endif
}

igl::tests::util::TestErrorGuard::~TestErrorGuard() {
#if IGL_REPORT_ERROR_ENABLED
IGLReportErrorSetHandler(savedErrorHandler_);
#if IGL_SOFT_ERROR_ENABLED
IGLSetSoftErrorHandler(savedErrorHandler_);
#endif
}

Expand All @@ -32,7 +32,7 @@ void igl::tests::util::TestErrorGuard::ReportErrorHandler(const char* file,
const char* category,
const char* format,
...) {
#if IGL_REPORT_ERROR_ENABLED
#if IGL_SOFT_ERROR_ENABLED
va_list ap;
va_start(ap, format);

Expand Down
4 changes: 2 additions & 2 deletions src/igl/tests/util/TestErrorGuard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class TestErrorGuard final {
...);

private:
#if IGL_REPORT_ERROR_ENABLED
IGLReportErrorFunc savedErrorHandler_;
#if IGL_SOFT_ERROR_ENABLED
IGLSoftErrorFunc savedErrorHandler_;
#endif
};
} // namespace igl::tests::util

0 comments on commit e62aa19

Please sign in to comment.