Skip to content

Commit

Permalink
Merge branch 'main' into igl_nanovg
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsentli committed Dec 3, 2024
2 parents 4795e13 + b18d5a4 commit 67ab188
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 113 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to igl
# Contributing to IGL
We want to make contributing to this project as easy and transparent as
possible.

Expand All @@ -11,7 +11,7 @@ We actively welcome your pull requests.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").
7. Please respect // @fb-only comments and do not delete them!
7. Please respect `// @fb-only` comments and do not delete them!

## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
Expand Down
3 changes: 3 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ https://github.com/corporateshark/lightweightvk/blob/main/LICENSE.md
Meshoptimizer
https://github.com/zeux/meshoptimizer/blob/master/LICENSE.md

NanoVG
https://github.com/memononen/nanovg/blob/master/LICENSE.txt

Spark SL
https://github.com/facebook/igl/releases/download/SparkSL/SparkSL.LICENSE

Expand Down
2 changes: 1 addition & 1 deletion samples/android/vulkan/jni/Tiny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void render() {

// VK_EXT_debug_utils support doesn't exist yet
// commands->pushDebugGroupLabel("Render Triangle", igl::Color(1, 0, 0));
commands->draw(PrimitiveType::Triangle, 0, 3);
commands->draw(3, 0, 3);
// commands->popDebugGroupLabel();
commands->endEncoding();

Expand Down
1 change: 0 additions & 1 deletion shell/ios/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ - (void)loadView {
kEAGLDrawablePropertyColorFormat,
nil];
self.view = openGLView;
self.view.layer.contentsScale = [UIScreen mainScreen].scale;
#endif
break;
}
Expand Down
2 changes: 0 additions & 2 deletions shell/shared/fileLoader/win/FileLoaderWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

// @fb-only

#include <shell/shared/fileLoader/win/FileLoaderWin.h>

#include <filesystem>
Expand Down
40 changes: 21 additions & 19 deletions src/igl/Assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@

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

namespace {
IGLErrorHandlerFunc& GetDebugAbortListener() {
static IGLErrorHandlerFunc sListener = nullptr;
return sListener;
}
} // namespace

IGL_API void IGLSetDebugAbortListener(IGLErrorHandlerFunc listener) {
GetDebugAbortListener() = listener;
}

IGL_API IGLErrorHandlerFunc IGLGetDebugAbortListener(void) {
return GetDebugAbortListener();
}

namespace igl {

// Toggle debug break on/off at runtime
Expand Down Expand Up @@ -58,29 +73,16 @@ void _IGLDebugBreak() {
// ----------------------------------------------------------------------------

namespace {
// Default handler is no-op.
// If there's an error, IGL_DEBUG_VERIFY will trap in dev builds
void IGLReportErrorDefault(const char* /* file */,
const char* /* func */,
int /* line */,
const char* /* category */,
const char* /* format */,
...) {}

IGLSoftErrorFunc& GetErrorHandler() {
static IGLSoftErrorFunc sHandler = IGLReportErrorDefault;
IGLErrorHandlerFunc& GetSoftErrorHandler() {
static IGLErrorHandlerFunc sHandler = nullptr;
return sHandler;
}

} // namespace

IGL_API void IGLSetSoftErrorHandler(IGLSoftErrorFunc handler) {
if (!handler) {
handler = IGLReportErrorDefault; // prevent null handler
}
GetErrorHandler() = handler;
IGL_API void IGLSetSoftErrorHandler(IGLErrorHandlerFunc handler) {
GetSoftErrorHandler() = handler;
}

IGL_API IGLSoftErrorFunc IGLGetSoftErrorHandler(void) {
return GetErrorHandler();
IGL_API IGLErrorHandlerFunc IGLGetSoftErrorHandler(void) {
return GetSoftErrorHandler();
}
172 changes: 100 additions & 72 deletions src/igl/Assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

#include <igl/Log.h>

#define IGL_ERROR_CATEGORY "IGL"

#if IGL_DEBUG || defined(IGL_FORCE_ENABLE_LOGS)
#define IGL_VERIFY_ENABLED 1
#else
Expand All @@ -68,61 +70,94 @@
#define IGL_DEBUG_BREAK_ENABLED 0
#endif

using IGLErrorHandlerFunc = void (*)(const char* category,
const char* reason,
const char* file,
const char* func,
int line,
const char* format,
va_list ap);

IGL_API void _IGLDebugBreak();

IGL_API void IGLSetDebugAbortListener(IGLErrorHandlerFunc listener);
IGL_API IGLErrorHandlerFunc IGLGetDebugAbortListener(void);

namespace igl {
bool isDebugBreakEnabled();
void setDebugBreakEnabled(bool enabled);

template<typename T>
[[nodiscard]] static inline const T& _IGLVerify(const T& cond,
[[maybe_unused]] const char* reason,
[[maybe_unused]] const char* func,
[[maybe_unused]] const char* file,
[[maybe_unused]] int line,
[[maybe_unused]] const char* format,
...) {
[[nodiscard]] inline bool _IGLAlwaysTrue() {
return true;
}

inline void _IGLDebugAbortV([[maybe_unused]] const char* category,
[[maybe_unused]] const char* reason,
[[maybe_unused]] const char* func,
[[maybe_unused]] const char* file,
[[maybe_unused]] int line,
[[maybe_unused]] const char* format,
[[maybe_unused]] va_list ap) {
#if IGL_VERIFY_ENABLED
if (!cond) {
IGLLog(IGLLogError, "[IGL] %s in '%s' (%s:%d): ", reason, func, file, line);
va_list ap;
va_start(ap, format);
IGLLogV(IGLLogError, format, ap);
va_end(ap);
IGLLog(IGLLogError, IGL_NEWLINE);
_IGLDebugBreak();
va_list apCopy;
va_copy(apCopy, ap);
auto listener = IGLGetDebugAbortListener();
if (listener) {
listener(category, reason, file, func, line, format, apCopy);
}
va_end(apCopy);

IGLLog(IGLLogError, "[%s] %s in '%s' (%s:%d): ", category, reason, func, file, line);
IGLLogV(IGLLogError, format, ap);
IGLLog(IGLLogError, IGL_NEWLINE);
_IGLDebugBreak();
#endif // IGL_VERIFY_ENABLED
return cond;
}

[[nodiscard]] inline bool _IGLDebugAbort(const char* category,
const char* reason,
const char* func,
const char* file,
int line,
const char* format,
...) {
va_list ap;
va_start(ap, format);
_IGLDebugAbortV(category, reason, func, file, line, format, ap);
va_end(ap);

return false;
}
} // namespace igl

#if IGL_VERIFY_ENABLED

#define _IGL_DEBUG_ABORT(cond, format, ...) \
(void)::igl::_IGLVerify( \
cond, "Abort requested", IGL_FUNCTION, __FILE__, __LINE__, (format), ##__VA_ARGS__)
#define _IGL_DEBUG_ABORT_IMPL(cond, reason, format, ...) \
(cond \
? ::igl::_IGLAlwaysTrue() \
: ::igl::_IGLDebugAbort( \
IGL_ERROR_CATEGORY, reason, IGL_FUNCTION, __FILE__, __LINE__, format, ##__VA_ARGS__))

#define _IGL_DEBUG_ABORT(format, ...) \
(void)_IGL_DEBUG_ABORT_IMPL(false, "Abort requested", (format), ##__VA_ARGS__)
#define _IGL_DEBUG_ASSERT(cond, format, ...) \
(void)::igl::_IGLVerify( \
cond, "Assert failed", IGL_FUNCTION, __FILE__, __LINE__, (format), ##__VA_ARGS__)
(void)_IGL_DEBUG_ABORT_IMPL(!!(cond), "Assert failed", (format), ##__VA_ARGS__)

#define _IGL_DEBUG_VERIFY(cond, format, ...) \
::igl::_IGLVerify( \
(cond), "Verify failed", IGL_FUNCTION, __FILE__, __LINE__, (format), ##__VA_ARGS__)
_IGL_DEBUG_ABORT_IMPL(!!(cond), "Verify failed", (format), ##__VA_ARGS__)
#define _IGL_DEBUG_VERIFY_NOT(cond, format, ...) \
(!::igl::_IGLVerify( \
0 == !!(cond), "Verify failed", IGL_FUNCTION, __FILE__, __LINE__, (format), ##__VA_ARGS__))
!_IGL_DEBUG_ABORT_IMPL(!(cond), "Verify failed", (format), ##__VA_ARGS__)

#else

#define _IGL_DEBUG_ABORT(cond, format, ...) static_cast<void>(0)
#define _IGL_DEBUG_ABORT(format, ...) static_cast<void>(0)
#define _IGL_DEBUG_ASSERT(cond, format, ...) static_cast<void>(0)
#define _IGL_DEBUG_VERIFY(cond, format, ...) (cond)
#define _IGL_DEBUG_VERIFY_NOT(cond, format, ...) (cond)

#endif // IGL_VERIFY_ENABLED

#define IGL_DEBUG_ABORT(format, ...) _IGL_DEBUG_ABORT(false, (format), ##__VA_ARGS__)
#define IGL_DEBUG_ABORT(format, ...) _IGL_DEBUG_ABORT((format), ##__VA_ARGS__)

#define _IGL_DEBUG_ASSERT_0(cond) _IGL_DEBUG_ASSERT(cond, #cond)
#define _IGL_DEBUG_ASSERT_1(cond, format, ...) _IGL_DEBUG_ASSERT(cond, (format), ##__VA_ARGS__)
Expand Down Expand Up @@ -156,78 +191,71 @@ template<typename T>
///--------------------------------------
/// MARK: - Custom

#define IGL_ERROR_CATEGORY "IGL"

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);
IGL_API void IGLSoftError(const char* file,
IGL_API void IGLSetSoftErrorHandler(IGLErrorHandlerFunc handler);
IGL_API IGLErrorHandlerFunc IGLGetSoftErrorHandler(void);
IGL_API void IGLSoftError(const char* category,
const char* reason,
const char* file,
const char* func,
int line,
const char* category,
const char* format,
...);
namespace igl {
template<typename T, typename... Args>
[[nodiscard]] static inline const T& _IGLSoftError(const T& cond,
[[maybe_unused]] const char* reason,
[[maybe_unused]] const char* func,
[[maybe_unused]] const char* file,
[[maybe_unused]] int line,
[[maybe_unused]] const char* format,
[[maybe_unused]] const Args&... args) {
#if IGL_VERIFY_ENABLED
const auto& verifiedCond = _IGLVerify(cond, reason, func, file, line, format, args...);
#else
const auto& verifiedCond = cond;
#endif // IGL_VERIFY_ENABLED
[[nodiscard]] inline bool _IGLSoftError(const char* category,
const char* reason,
const char* func,
const char* file,
int line,
const char* format,
...) {
va_list ap, apCopy;
va_start(ap, format);
va_copy(apCopy, ap);

_IGLDebugAbortV(category, reason, func, file, line, format, apCopy);
va_end(apCopy);

#if IGL_SOFT_ERROR_ENABLED
if (!verifiedCond) {
IGLGetSoftErrorHandler()(file, func, line, IGL_ERROR_CATEGORY, format, args...);
auto handler = IGLGetSoftErrorHandler();
if (handler) {
handler(category, reason, file, func, line, format, ap);
}
#endif // IGL_SOFT_ERROR_ENABLED

return verifiedCond;
va_end(ap);

return false; // Always return false
}
} // namespace igl

#if IGL_SOFT_ERROR_ENABLED

#define _IGL_SOFT_ERROR(cond, format, ...) \
(void)::igl::_IGLSoftError( \
cond, "Soft error", IGL_FUNCTION, __FILE__, __LINE__, (format), ##__VA_ARGS__)
#define _IGL_SOFT_ERROR_IMPL(cond, reason, format, ...) \
(cond \
? ::igl::_IGLAlwaysTrue() \
: ::igl::_IGLSoftError( \
IGL_ERROR_CATEGORY, reason, IGL_FUNCTION, __FILE__, __LINE__, format, ##__VA_ARGS__))

#define _IGL_SOFT_ERROR(format, ...) \
(void)_IGL_SOFT_ERROR_IMPL(false, "Soft error", (format), ##__VA_ARGS__)
#define _IGL_SOFT_ASSERT(cond, format, ...) \
(void)::igl::_IGLSoftError( \
cond, "Soft assert failed", IGL_FUNCTION, __FILE__, __LINE__, (format), ##__VA_ARGS__)
(void)_IGL_SOFT_ERROR_IMPL(!!(cond), "Soft assert failed", (format), ##__VA_ARGS__)

#define _IGL_SOFT_VERIFY(cond, format, ...) \
::igl::_IGLSoftError( \
(cond), "Soft verify failed", IGL_FUNCTION, __FILE__, __LINE__, (format), ##__VA_ARGS__)
_IGL_SOFT_ERROR_IMPL(!!(cond), "Soft verify failed", (format), ##__VA_ARGS__)
#define _IGL_SOFT_VERIFY_NOT(cond, format, ...) \
(!::igl::_IGLSoftError(0 == !!(cond), \
"Soft verify failed", \
IGL_FUNCTION, \
__FILE__, \
__LINE__, \
(format), \
##__VA_ARGS__))
!_IGL_SOFT_ERROR_IMPL(!(cond), "Soft verify failed", (format), ##__VA_ARGS__)

#else

#define _IGL_SOFT_ERROR(cond, format, ...) static_cast<void>(0)
#define _IGL_SOFT_ERROR(format, ...) static_cast<void>(0)
#define _IGL_SOFT_ASSERT(cond, format, ...) static_cast<void>(0)
#define _IGL_SOFT_VERIFY(cond, format, ...) (cond)
#define _IGL_SOFT_VERIFY_NOT(cond, format, ...) (cond)

#endif // IGL_SOFT_ERROR_ENABLED

#define IGL_SOFT_ERROR(format, ...) _IGL_SOFT_ERROR(false, (format), ##__VA_ARGS__)
#define IGL_SOFT_ERROR(format, ...) _IGL_SOFT_ERROR((format), ##__VA_ARGS__)

#define _IGL_SOFT_ASSERT_0(cond) _IGL_SOFT_ASSERT(cond, #cond)
#define _IGL_SOFT_ASSERT_1(cond, format, ...) _IGL_SOFT_ASSERT(cond, (format), ##__VA_ARGS__)
Expand Down
11 changes: 6 additions & 5 deletions src/igl/opengl/RenderCommandAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,11 @@ void RenderCommandAdapter::clearDependentResources(
clearFragmentTexture();
}

if (!newStateOpenGL || !curStateOpenGL->matchesVertexInputState(*newStateOpenGL)) {
// We do need to clear vertex attributes, when pipelinestate is modified.
// If we don't, subsequent draw calls might try to read from these locations
// and crashes might happen.
unbindVertexAttributes();
if (curStateOpenGL && newStateOpenGL) {
newStateOpenGL->savePrevPipelineStateAttributesLocations(*curStateOpenGL);
}

if (!newStateOpenGL || !curStateOpenGL->matchesVertexInputState(*newStateOpenGL)) {
// Don't reuse previously set vertex buffers.
clearVertexBuffers();
}
Expand Down Expand Up @@ -343,6 +342,7 @@ void RenderCommandAdapter::willDraw() {

// Vertex Buffers must be bound before pipelineState->bind()
if (pipelineState) {
pipelineState->clearActiveAttributesLocations();
for (size_t bufferIndex = 0; bufferIndex < IGL_VERTEX_BUFFER_MAX; ++bufferIndex) {
if (IS_DIRTY(vertexBuffersDirty_, bufferIndex)) {
auto& bufferState = vertexBuffers_[bufferIndex];
Expand All @@ -352,6 +352,7 @@ void RenderCommandAdapter::willDraw() {
CLEAR_DIRTY(vertexBuffersDirty_, bufferIndex);
}
}
pipelineState->unbindPrevPipelineVertexAttributes();
if (isDirty(StateMask::PIPELINE)) {
pipelineState->bind();
clearDirty(StateMask::PIPELINE);
Expand Down
Loading

0 comments on commit 67ab188

Please sign in to comment.