Skip to content

Commit

Permalink
Switch ASSERT macros to new stream API (google#7881)
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado authored May 24, 2024
1 parent 3ec2249 commit cf91e42
Show file tree
Hide file tree
Showing 77 changed files with 855 additions and 800 deletions.
4 changes: 2 additions & 2 deletions filament/backend/src/Callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ PresentCallable::PresentCallable(PresentFn fn, void* user) noexcept
}

void PresentCallable::operator()(bool presentFrame) noexcept {
ASSERT_PRECONDITION(mPresentFn, "This PresentCallable was already called. " \
"PresentCallables should be called exactly once.");
FILAMENT_CHECK_PRECONDITION(mPresentFn) << "This PresentCallable was already called. "
"PresentCallables should be called exactly once.";
mPresentFn(presentFrame, mUser);
// Set mPresentFn to nullptr to denote that the callable has been called.
mPresentFn = nullptr;
Expand Down
11 changes: 6 additions & 5 deletions filament/backend/src/metal/MetalBlitter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ inline bool MTLSizeEqual(T a, T b) noexcept {
MetalBlitter::MetalBlitter(MetalContext& context) noexcept : mContext(context) { }

void MetalBlitter::blit(id<MTLCommandBuffer> cmdBuffer, const BlitArgs& args, const char* label) {

ASSERT_PRECONDITION(args.source.region.size.depth == args.destination.region.size.depth,
"Blitting requires the source and destination regions to have the same depth.");
FILAMENT_CHECK_PRECONDITION(args.source.region.size.depth == args.destination.region.size.depth)
<< "Blitting requires the source and destination regions to have the same depth.";

// Determine if the blit for color or depth are eligible to use a MTLBlitCommandEncoder.
// blitFastPath returns true upon success.
Expand Down Expand Up @@ -327,7 +326,8 @@ inline bool MTLSizeEqual(T a, T b) noexcept {
utils::slog.e << description << utils::io::endl;
}
}
ASSERT_POSTCONDITION(library && function, "Unable to compile fragment shader for MetalBlitter.");
FILAMENT_CHECK_POSTCONDITION(library && function)
<< "Unable to compile fragment shader for MetalBlitter.";

return function;
}
Expand All @@ -352,7 +352,8 @@ inline bool MTLSizeEqual(T a, T b) noexcept {
utils::slog.e << description << utils::io::endl;
}
}
ASSERT_POSTCONDITION(library && function, "Unable to compile vertex shader for MetalBlitter.");
FILAMENT_CHECK_POSTCONDITION(library && function)
<< "Unable to compile vertex shader for MetalBlitter.";

mVertexFunction = function;

Expand Down
11 changes: 6 additions & 5 deletions filament/backend/src/metal/MetalBuffer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
mBuffer = { [context.device newBufferWithLength:size options:MTLResourceStorageModePrivate],
TrackedMetalBuffer::Type::GENERIC };
}
ASSERT_POSTCONDITION(mBuffer, "Could not allocate Metal buffer of size %zu.", size);
FILAMENT_CHECK_POSTCONDITION(mBuffer)
<< "Could not allocate Metal buffer of size " << size << ".";
}

MetalBuffer::~MetalBuffer() {
Expand All @@ -57,9 +58,9 @@
if (size <= 0) {
return;
}
ASSERT_PRECONDITION(size + byteOffset <= mBufferSize,
"Attempting to copy %zu bytes into a buffer of size %zu at offset %zu",
size, mBufferSize, byteOffset);
FILAMENT_CHECK_PRECONDITION(size + byteOffset <= mBufferSize)
<< "Attempting to copy " << size << " bytes into a buffer of size " << mBufferSize
<< " at offset " << byteOffset;

// Either copy into the Metal buffer or into our cpu buffer.
if (mCpuBuffer) {
Expand All @@ -73,7 +74,7 @@
memcpy(staging->buffer.get().contents, src, size);

// The blit below requires that byteOffset be a multiple of 4.
ASSERT_PRECONDITION(!(byteOffset & 0x3u), "byteOffset must be a multiple of 4");
FILAMENT_CHECK_PRECONDITION(!(byteOffset & 0x3u)) << "byteOffset must be a multiple of 4";

// Encode a blit from the staging buffer into the private GPU buffer.
id<MTLCommandBuffer> cmdBuffer = getPendingCommandBuffer(&mContext);
Expand Down
3 changes: 2 additions & 1 deletion filament/backend/src/metal/MetalBufferPool.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
buffer = [mContext.device newBufferWithLength:numBytes
options:MTLResourceStorageModeShared];
}
ASSERT_POSTCONDITION(buffer, "Could not allocate Metal staging buffer of size %zu.", numBytes);
FILAMENT_CHECK_POSTCONDITION(buffer)
<< "Could not allocate Metal staging buffer of size " << numBytes << ".";
MetalBufferPoolEntry* stage = new MetalBufferPoolEntry {
.buffer = { buffer, TrackedMetalBuffer::Type::STAGING },
.capacity = numBytes,
Expand Down
3 changes: 2 additions & 1 deletion filament/backend/src/metal/MetalContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void initializeSupportedGpuFamilies(MetalContext* context) {
}
}
}];
ASSERT_POSTCONDITION(context->pendingCommandBuffer, "Could not obtain command buffer.");
FILAMENT_CHECK_POSTCONDITION(context->pendingCommandBuffer)
<< "Could not obtain command buffer.";
return context->pendingCommandBuffer;
}

Expand Down
Loading

0 comments on commit cf91e42

Please sign in to comment.