Add FILAMENT_DEBUG_COMMANDS_HISTOGRAM compile flag
This commit is contained in:
@@ -221,6 +221,7 @@ public:
|
||||
|
||||
CircularBuffer const& getCircularBuffer() const noexcept { return mCurrentBuffer; }
|
||||
|
||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
||||
using Execute = Dispatcher::Execute;
|
||||
struct CommandInfo {
|
||||
size_t size;
|
||||
@@ -248,6 +249,7 @@ public:
|
||||
// NoopCommands have variable size. We will handle them specially using their mNext pointer.
|
||||
mCommands[NoopCommand::execute] = { 0, "NoopCommand", currentIndex++ };
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#define DECL_DRIVER_API(methodName, paramsDecl, params) \
|
||||
@@ -293,10 +295,12 @@ public:
|
||||
|
||||
void execute(void* buffer);
|
||||
|
||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
||||
void debugIterateCommands(void* head, void* tail,
|
||||
std::function<void(CommandInfo const& info)> const& callback);
|
||||
|
||||
void debugPrintHistogram(void* head, void* tail);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* queueCommand() allows to queue a lambda function as a command.
|
||||
|
||||
@@ -48,6 +48,11 @@
|
||||
|
||||
#define FILAMENT_DEBUG_COMMANDS FILAMENT_DEBUG_COMMANDS_NONE
|
||||
|
||||
// Upon command stream overflow, print a histogram of commands
|
||||
#ifndef FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
||||
#define FILAMENT_DEBUG_COMMANDS_HISTOGRAM 0
|
||||
#endif
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class BufferDescriptor;
|
||||
|
||||
@@ -106,11 +106,13 @@ void CommandBufferQueue::flush(std::function<void(void*, void*)> const& debugPri
|
||||
std::unique_lock lock(mLock);
|
||||
|
||||
// circular buffer is too small, we corrupted the stream
|
||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
||||
if (UTILS_VERY_UNLIKELY(used > mFreeSpace)) {
|
||||
if (debugPrintHistogram) {
|
||||
debugPrintHistogram(begin, end);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
FILAMENT_CHECK_POSTCONDITION(used <= mFreeSpace) <<
|
||||
"Backend CommandStream overflow. Commands are corrupted and unrecoverable.\n"
|
||||
"Please increase minCommandBufferSizeMB inside the Config passed to Engine::create.\n"
|
||||
|
||||
@@ -30,12 +30,15 @@
|
||||
#include <utils/ostream.h>
|
||||
#include <utils/sstream.h>
|
||||
|
||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <sys/system_properties.h>
|
||||
@@ -86,7 +89,9 @@ CommandStream::CommandStream(Driver& driver, CircularBuffer& buffer) noexcept
|
||||
mUsePerformanceCounter = bool(atoi(property));
|
||||
#endif
|
||||
|
||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
||||
initializeLookup();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CommandStream::execute(void* buffer) {
|
||||
@@ -130,6 +135,7 @@ void CommandStream::execute(void* buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
||||
void CommandStream::debugIterateCommands(void* head, void* tail,
|
||||
std::function<void(CommandInfo const& info)> const& callback) {
|
||||
CommandBase* UTILS_RESTRICT base = static_cast<CommandBase*>(head);
|
||||
@@ -192,6 +198,7 @@ void CommandStream::debugPrintHistogram(void* head, void* tail) {
|
||||
LOG(INFO) << "CS hist: " << short_histogram;
|
||||
LOG(INFO) << "";
|
||||
}
|
||||
#endif
|
||||
|
||||
void CommandStream::queueCommand(std::function<void()> command) {
|
||||
new(allocateCommand(CustomCommand::align(sizeof(CustomCommand)))) CustomCommand(std::move(command));
|
||||
|
||||
@@ -921,7 +921,10 @@ int FEngine::loop() {
|
||||
void FEngine::flushCommandBuffer(CommandBufferQueue& commandBufferQueue) const {
|
||||
getDriver().purge();
|
||||
commandBufferQueue.flush([this](void* begin, void* end) {
|
||||
const_cast<FEngine*>(this)->getDriverApi().debugPrintHistogram(begin, end);
|
||||
UTILS_UNUSED FEngine* engine = const_cast<FEngine*>(this);
|
||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
||||
engine->getDriverApi().debugPrintHistogram(begin, end);
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user