Skip to content

Commit

Permalink
* tzsl: tz::debug::assert no longer internally prints to the vulkan c…
Browse files Browse the repository at this point in the history
…allback unless the condition is false. This means that the overhead of asserting within a shader is now very small if the assert succeeds, whereas previously it was massive because it was internally printing every single time, now it just does an if
  • Loading branch information
harrand committed Feb 19, 2023
1 parent 71fe248 commit 934b788
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions test/gl/shaders/shader_test.compute.tzsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ void math_tests()
tz::debug::assert(tz::math::clamp(2.5f, 1.0f, 2.0f) == 2.0f);

tz::debug::assert(tz::math::distance(vec2(0.0f, 0.0f), vec2(0.0f, 0.0f)) == 0.0f);
tz::debug::assert(tz::math::dot(vec2(2.0f, 0.0f), vec2(2.0f, 0.0f)) == 2.0f);
tz::debug::assert(tz::math::dot(vec2(2.0f, 0.0f), vec2(2.0f, 0.0f)) == 4.0f);

tz::debug::assert(tz::math::ln(tz::math::exp(2.0f)) == 2.0f);
tz::debug::assert(tz::math::log(tz::math::exp2(2.0f)) == 2.0f);

tz::debug::assert(tz::math::sqrt(3.0f) == (1.0f / tz::math::inverse_sqrt(3.0f)));
tz::debug::assert(tz::math::inverse_sqrt(3.0f) == (1.0f / tz::math::sqrt(3.0f)));

tz::debug::assert(!tz::math::is_infinity(1.0f));
tz::debug::assert(!tz::math::is_nan(1.0f));
Expand Down
2 changes: 1 addition & 1 deletion tools/tzslc/shaders/debug.tzsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#if TZ_VULKAN && TZ_DEBUG
// tz::debug::printf(...) implemented via compiler magic. Assume it's here.
#define tz::debug::assert(expr) debugPrintfEXT("TZ_GPUASSERT(%d,%d): Assert failure on line %d.", expr, TZ_SHADER_STAGE, __LINE__ + 1)
#define tz::debug::assert(expr) if(!(expr)){debugPrintfEXT("TZ_GPUASSERT(0,%d): Assert failure on line %d.", TZ_SHADER_STAGE, __LINE__ + 1);}
#else
#define debugPrintfEXT //
#define tz::debug::assert //
Expand Down

0 comments on commit 934b788

Please sign in to comment.