Skip to content

Commit 53bc372

Browse files
authored
Log Filament command buffer statistics (#9709)
1 parent 58f6d77 commit 53bc372

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

filament/backend/include/backend/Platform.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,18 @@ class UTILS_PUBLIC Platform {
561561

562562
/**
563563
* Sets the callback function that the backend can use to update backend-specific statistics
564-
* to aid with debugging. This callback is guaranteed to be called on the Filament driver
565-
* thread.
564+
* to aid with debugging. This callback can be called on either the Filament main thread or
565+
* the Filament driver thread.
566566
*
567567
* The callback signature is (key, intValue, stringValue). Note that for any given call,
568568
* only one of the value parameters (intValue or stringValue) will be meaningful, depending on
569569
* the specific key.
570570
*
571-
* IMPORTANT_NOTE: because the callback is called on the driver thread, only quick, non-blocking
572-
* work should be done inside it. Furthermore, no graphics API calls (such as GL calls) should
573-
* be made, which could interfere with Filament's driver state.
571+
* IMPORTANT_NOTE: because the callback can be called on the driver thread, only quick,
572+
* non-blocking work should be done inside it. Furthermore, no graphics API calls (such as GL
573+
* calls) should be made, which could interfere with Filament's driver state. Lastly, the
574+
* callback implementation must be synchronized (thread-safe) since it can be called from
575+
* either thread.
574576
*
575577
* @param debugUpdateStat an Invocable that updates debug statistics
576578
*/
@@ -587,8 +589,7 @@ class UTILS_PUBLIC Platform {
587589
* with a given key. It is possible for this function to be called multiple times with the
588590
* same key, in which case newer values should overwrite older values.
589591
*
590-
* This function is guaranteed to be called only on a single thread, the Filament driver
591-
* thread.
592+
* This function can be called on either the Filament main thread or the Filament driver thread.
592593
*
593594
* @param key a null-terminated C-string with the key of the debug statistic
594595
* @param intValue the updated integer value of key (the string value passed to the
@@ -602,8 +603,7 @@ class UTILS_PUBLIC Platform {
602603
* with a given key. It is possible for this function to be called multiple times with the
603604
* same key, in which case newer values should overwrite older values.
604605
*
605-
* This function is guaranteed to be called only on a single thread, the Filament driver
606-
* thread.
606+
* This function can be called on either the Filament main thread or the Filament driver thread.
607607
*
608608
* @param key a null-terminated C-string with the key of the debug statistic
609609
* @param stringValue the updated string value of key (the integer value passed to the

filament/src/RenderPass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,12 @@ void RenderPass::Executor::execute(FEngine const& engine, DriverApi& driver,
901901
size_t const capacity = engine.getMinCommandBufferSize();
902902
CircularBuffer const& circularBuffer = driver.getCircularBuffer();
903903

904+
// b/479079631: Log the number of commands in this render pass.
905+
size_t const commandCount = last - first;
906+
if (Platform* platform = engine.getPlatform(); platform->hasDebugUpdateStatFunc()) {
907+
platform->debugUpdateStat("filament.renderer.render_pass.command_count", commandCount);
908+
}
909+
904910
if (first != last) {
905911
FILAMENT_TRACING_VALUE(FILAMENT_TRACING_CATEGORY_FILAMENT, "commandCount", last - first);
906912

filament/src/RendererUtils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,21 @@ RendererUtils::ColorPassOutput RendererUtils::colorPass(
258258
}
259259

260260
driver.beginRenderPass(out.target, out.params);
261+
Platform* platform = engine.getPlatform();
262+
CircularBuffer const& circularBuffer = driver.getCircularBuffer();
263+
// b/479079631: Log the current command buffer size before and after executing the
264+
// render pass.
265+
if (platform->hasDebugUpdateStatFunc()) {
266+
platform->debugUpdateStat(
267+
"filament.renderer.color_pass.command_buffer_used_start",
268+
circularBuffer.getUsed());
269+
}
261270
passExecutor.execute(engine, driver);
271+
if (platform->hasDebugUpdateStatFunc()) {
272+
platform->debugUpdateStat(
273+
"filament.renderer.color_pass.command_buffer_used_end",
274+
circularBuffer.getUsed());
275+
}
262276
driver.endRenderPass();
263277

264278
// unbind all descriptor sets to avoid false dependencies with the next pass

0 commit comments

Comments
 (0)