Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdfb92e14a | ||
|
|
55c16e6e7a | ||
|
|
65e3c3bfb9 |
@@ -27,8 +27,6 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -66,7 +64,7 @@ public:
|
|||||||
|
|
||||||
// all commands buffers (Slices) written to this point are returned by waitForCommand(). This
|
// all commands buffers (Slices) written to this point are returned by waitForCommand(). This
|
||||||
// call blocks until the CircularBuffer has at least mRequiredSize bytes available.
|
// call blocks until the CircularBuffer has at least mRequiredSize bytes available.
|
||||||
void flush(std::function<void(void*, void*)> const& debugPrintHistogram = nullptr);
|
void flush();
|
||||||
|
|
||||||
// returns from waitForCommands() immediately.
|
// returns from waitForCommands() immediately.
|
||||||
void requestExit();
|
void requestExit();
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ namespace filament::backend {
|
|||||||
|
|
||||||
class CommandBase {
|
class CommandBase {
|
||||||
static constexpr size_t FILAMENT_OBJECT_ALIGNMENT = alignof(std::max_align_t);
|
static constexpr size_t FILAMENT_OBJECT_ALIGNMENT = alignof(std::max_align_t);
|
||||||
friend class CommandStream;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
using Execute = Dispatcher::Execute;
|
using Execute = Dispatcher::Execute;
|
||||||
@@ -169,8 +168,8 @@ struct CommandType<void (Driver::*)(ARGS...)> {
|
|||||||
|
|
||||||
class CustomCommand : public CommandBase {
|
class CustomCommand : public CommandBase {
|
||||||
std::function<void()> mCommand;
|
std::function<void()> mCommand;
|
||||||
public:
|
|
||||||
static void execute(Driver&, CommandBase* base, intptr_t* next);
|
static void execute(Driver&, CommandBase* base, intptr_t* next);
|
||||||
|
public:
|
||||||
CustomCommand(CustomCommand&& rhs) = default;
|
CustomCommand(CustomCommand&& rhs) = default;
|
||||||
|
|
||||||
explicit CustomCommand(std::function<void()> cmd)
|
explicit CustomCommand(std::function<void()> cmd)
|
||||||
@@ -180,12 +179,11 @@ public:
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class NoopCommand : public CommandBase {
|
class NoopCommand : public CommandBase {
|
||||||
public:
|
|
||||||
intptr_t mNext;
|
intptr_t mNext;
|
||||||
static void execute(Driver&, CommandBase* self, intptr_t* next) noexcept {
|
static void execute(Driver&, CommandBase* self, intptr_t* next) noexcept {
|
||||||
*next = static_cast<NoopCommand*>(self)->mNext;
|
*next = static_cast<NoopCommand*>(self)->mNext;
|
||||||
}
|
}
|
||||||
|
public:
|
||||||
constexpr explicit NoopCommand(void* next) noexcept
|
constexpr explicit NoopCommand(void* next) noexcept
|
||||||
: CommandBase(execute), mNext(intptr_t((char *)next - (char *)this)) { }
|
: CommandBase(execute), mNext(intptr_t((char *)next - (char *)this)) { }
|
||||||
};
|
};
|
||||||
@@ -221,36 +219,6 @@ public:
|
|||||||
|
|
||||||
CircularBuffer const& getCircularBuffer() const noexcept { return mCurrentBuffer; }
|
CircularBuffer const& getCircularBuffer() const noexcept { return mCurrentBuffer; }
|
||||||
|
|
||||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
|
||||||
using Execute = Dispatcher::Execute;
|
|
||||||
struct CommandInfo {
|
|
||||||
size_t size;
|
|
||||||
const char* name;
|
|
||||||
int index;
|
|
||||||
};
|
|
||||||
std::unordered_map<Execute, CommandInfo> mCommands;
|
|
||||||
|
|
||||||
void initializeLookup() {
|
|
||||||
int currentIndex = 0;
|
|
||||||
#define DECL_DRIVER_API_SYNCHRONOUS(RetType, methodName, paramsDecl, params)
|
|
||||||
#define DECL_DRIVER_API(methodName, paramsDecl, params) \
|
|
||||||
mCommands[mDispatcher.methodName##_] = { CommandBase::align(sizeof(COMMAND_TYPE(methodName))), \
|
|
||||||
#methodName, currentIndex++ };
|
|
||||||
#define DECL_DRIVER_API_RETURN(RetType, methodName, paramsDecl, params) \
|
|
||||||
mCommands[mDispatcher.methodName##_] = { \
|
|
||||||
CommandBase::align(sizeof(COMMAND_TYPE(methodName##R))), #methodName, currentIndex++ \
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "private/backend/DriverAPI.inc"
|
|
||||||
|
|
||||||
mCommands[CustomCommand::execute] = { CommandBase::align(sizeof(CustomCommand)),
|
|
||||||
"CustomCommand", currentIndex++ };
|
|
||||||
|
|
||||||
// NoopCommands have variable size. We will handle them specially using their mNext pointer.
|
|
||||||
mCommands[NoopCommand::execute] = { 0, "NoopCommand", currentIndex++ };
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#define DECL_DRIVER_API(methodName, paramsDecl, params) \
|
#define DECL_DRIVER_API(methodName, paramsDecl, params) \
|
||||||
inline void methodName(paramsDecl) noexcept { \
|
inline void methodName(paramsDecl) noexcept { \
|
||||||
@@ -295,13 +263,6 @@ public:
|
|||||||
|
|
||||||
void execute(void* buffer);
|
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.
|
* queueCommand() allows to queue a lambda function as a command.
|
||||||
* This is much less efficient than using the Driver* API.
|
* This is much less efficient than using the Driver* API.
|
||||||
|
|||||||
@@ -48,11 +48,6 @@
|
|||||||
|
|
||||||
#define FILAMENT_DEBUG_COMMANDS FILAMENT_DEBUG_COMMANDS_NONE
|
#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 {
|
namespace filament::backend {
|
||||||
|
|
||||||
class BufferDescriptor;
|
class BufferDescriptor;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ bool CommandBufferQueue::isExitRequested() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CommandBufferQueue::flush(std::function<void(void*, void*)> const& debugPrintHistogram) {
|
void CommandBufferQueue::flush() {
|
||||||
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
|
||||||
|
|
||||||
CircularBuffer& circularBuffer = mCircularBuffer;
|
CircularBuffer& circularBuffer = mCircularBuffer;
|
||||||
@@ -106,13 +106,6 @@ void CommandBufferQueue::flush(std::function<void(void*, void*)> const& debugPri
|
|||||||
std::unique_lock lock(mLock);
|
std::unique_lock lock(mLock);
|
||||||
|
|
||||||
// circular buffer is too small, we corrupted the stream
|
// 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) <<
|
FILAMENT_CHECK_POSTCONDITION(used <= mFreeSpace) <<
|
||||||
"Backend CommandStream overflow. Commands are corrupted and unrecoverable.\n"
|
"Backend CommandStream overflow. Commands are corrupted and unrecoverable.\n"
|
||||||
"Please increase minCommandBufferSizeMB inside the Config passed to Engine::create.\n"
|
"Please increase minCommandBufferSizeMB inside the Config passed to Engine::create.\n"
|
||||||
|
|||||||
@@ -30,11 +30,6 @@
|
|||||||
#include <utils/ostream.h>
|
#include <utils/ostream.h>
|
||||||
#include <utils/sstream.h>
|
#include <utils/sstream.h>
|
||||||
|
|
||||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
|
||||||
#include <algorithm>
|
|
||||||
#include <vector>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -88,10 +83,6 @@ CommandStream::CommandStream(Driver& driver, CircularBuffer& buffer) noexcept
|
|||||||
__system_property_get("debug.filament.perfcounters", property);
|
__system_property_get("debug.filament.perfcounters", property);
|
||||||
mUsePerformanceCounter = bool(atoi(property));
|
mUsePerformanceCounter = bool(atoi(property));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
|
||||||
initializeLookup();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandStream::execute(void* buffer) {
|
void CommandStream::execute(void* buffer) {
|
||||||
@@ -135,71 +126,6 @@ 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);
|
|
||||||
auto p = base;
|
|
||||||
while (UTILS_LIKELY(p)) {
|
|
||||||
if (p >= tail) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Execute e = p->mExecute;
|
|
||||||
|
|
||||||
if (e == NoopCommand::execute) {
|
|
||||||
NoopCommand* noop = static_cast<NoopCommand*>(p);
|
|
||||||
size_t size = noop->mNext;
|
|
||||||
int noopIndex = mCommands[NoopCommand::execute].index;
|
|
||||||
callback({ size, "NoopCommand", noopIndex });
|
|
||||||
p = reinterpret_cast<CommandBase*>(reinterpret_cast<char*>(p) + size);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto it = mCommands.find(e); it != mCommands.end()) {
|
|
||||||
size_t size = it->second.size;
|
|
||||||
callback(it->second);
|
|
||||||
p = reinterpret_cast<CommandBase*>(reinterpret_cast<char*>(p) + size);
|
|
||||||
} else {
|
|
||||||
LOG(ERROR) << "Cannot find command in lookup table";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandStream::debugPrintHistogram(void* head, void* tail) {
|
|
||||||
std::unordered_map<std::string_view, int> histogram;
|
|
||||||
std::unordered_map<int, int> index_histogram;
|
|
||||||
debugIterateCommands(head, tail, [&](CommandInfo const& info) {
|
|
||||||
histogram[std::string_view(info.name)]++;
|
|
||||||
index_histogram[info.index]++;
|
|
||||||
});
|
|
||||||
|
|
||||||
std::vector<std::pair<std::string_view, int>> sorted_histogram(histogram.begin(),
|
|
||||||
histogram.end());
|
|
||||||
std::sort(sorted_histogram.begin(), sorted_histogram.end(),
|
|
||||||
[](auto const& a, auto const& b) { return a.second > b.second; });
|
|
||||||
|
|
||||||
LOG(INFO) << "Command stream histogram:";
|
|
||||||
for (auto const& [name, count]: sorted_histogram) {
|
|
||||||
LOG(INFO) << name << ": " << count;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::pair<int, int>> sorted_index_histogram(index_histogram.begin(),
|
|
||||||
index_histogram.end());
|
|
||||||
std::sort(sorted_index_histogram.begin(), sorted_index_histogram.end(),
|
|
||||||
[](auto const& a, auto const& b) { return a.second > b.second; });
|
|
||||||
|
|
||||||
std::string short_histogram = "";
|
|
||||||
for (size_t i = 0, n = sorted_index_histogram.size(); i < n; ++i) {
|
|
||||||
short_histogram += std::to_string(sorted_index_histogram[i].first) + ":" +
|
|
||||||
std::to_string(sorted_index_histogram[i].second);
|
|
||||||
short_histogram += (i < n - 1) ? ";" : ".";
|
|
||||||
}
|
|
||||||
LOG(INFO) << "CS hist: " << short_histogram;
|
|
||||||
LOG(INFO) << "";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void CommandStream::queueCommand(std::function<void()> command) {
|
void CommandStream::queueCommand(std::function<void()> command) {
|
||||||
new(allocateCommand(CustomCommand::align(sizeof(CustomCommand)))) CustomCommand(std::move(command));
|
new(allocateCommand(CustomCommand::align(sizeof(CustomCommand)))) CustomCommand(std::move(command));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "SharedShaders.h"
|
#include "SharedShaders.h"
|
||||||
|
#include "Skip.h"
|
||||||
#include "TrianglePrimitive.h"
|
#include "TrianglePrimitive.h"
|
||||||
|
|
||||||
#include <backend/PixelBufferDescriptor.h>
|
#include <backend/PixelBufferDescriptor.h>
|
||||||
@@ -31,6 +32,9 @@ using namespace filament::backend;
|
|||||||
using namespace filament::math;
|
using namespace filament::math;
|
||||||
|
|
||||||
TEST_F(BackendTest, AutoresolveDifferingSampleCounts) {
|
TEST_F(BackendTest, AutoresolveDifferingSampleCounts) {
|
||||||
|
SKIP_IF(SkipEnvironment(OperatingSystem::CI, Backend::OPENGL), "see b/486954356");
|
||||||
|
SKIP_IF(SkipEnvironment(OperatingSystem::CI, Backend::VULKAN), "see b/486954356");
|
||||||
|
|
||||||
auto& api = getDriverApi();
|
auto& api = getDriverApi();
|
||||||
constexpr int kRenderTargetSize = 512;
|
constexpr int kRenderTargetSize = 512;
|
||||||
|
|
||||||
|
|||||||
@@ -798,6 +798,12 @@ void FEngine::submitFrame() {
|
|||||||
void FEngine::flush() {
|
void FEngine::flush() {
|
||||||
// flush the command buffer
|
// flush the command buffer
|
||||||
flushCommandBuffer(mCommandBufferQueue);
|
flushCommandBuffer(mCommandBufferQueue);
|
||||||
|
|
||||||
|
// In single-threaded mode, we have to call execute() to drain the command
|
||||||
|
// buffer to really free up space
|
||||||
|
if constexpr (!UTILS_HAS_THREADING) {
|
||||||
|
execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FEngine::flushAndWait() {
|
void FEngine::flushAndWait() {
|
||||||
@@ -920,12 +926,7 @@ int FEngine::loop() {
|
|||||||
|
|
||||||
void FEngine::flushCommandBuffer(CommandBufferQueue& commandBufferQueue) const {
|
void FEngine::flushCommandBuffer(CommandBufferQueue& commandBufferQueue) const {
|
||||||
getDriver().purge();
|
getDriver().purge();
|
||||||
commandBufferQueue.flush([this](void* begin, void* end) {
|
commandBufferQueue.flush();
|
||||||
UTILS_UNUSED FEngine* engine = const_cast<FEngine*>(this);
|
|
||||||
#if FILAMENT_DEBUG_COMMANDS_HISTOGRAM
|
|
||||||
engine->getDriverApi().debugPrintHistogram(begin, end);
|
|
||||||
#endif
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const FMaterial* FEngine::getSkyboxMaterial() const noexcept {
|
const FMaterial* FEngine::getSkyboxMaterial() const noexcept {
|
||||||
|
|||||||
@@ -60,11 +60,13 @@
|
|||||||
#define GLTFIO_WARN(msg) slog.w << msg << io::endl
|
#define GLTFIO_WARN(msg) slog.w << msg << io::endl
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef GLTFIO_USE_FILESYSTEM
|
||||||
#if defined(__EMSCRIPTEN__) || defined(__ANDROID__) || defined(FILAMENT_IOS)
|
#if defined(__EMSCRIPTEN__) || defined(__ANDROID__) || defined(FILAMENT_IOS)
|
||||||
#define GLTFIO_USE_FILESYSTEM 0
|
#define GLTFIO_USE_FILESYSTEM 0
|
||||||
#else
|
#else
|
||||||
#define GLTFIO_USE_FILESYSTEM 1
|
#define GLTFIO_USE_FILESYSTEM 1
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
class NameComponentManager;
|
class NameComponentManager;
|
||||||
|
|||||||
Reference in New Issue
Block a user