more Engine configuration cleanup

- move all froxel configuration constants out of Engine.h, unlike
  the previous todo/comment, these shouldn't be part of Engine::Config.

- same for irradiance map
This commit is contained in:
Mathias Agopian
2022-07-12 16:00:11 -07:00
committed by Mathias Agopian
parent 0ba0591e19
commit efc88fbc6f
6 changed files with 37 additions and 39 deletions

View File

@@ -227,6 +227,7 @@ public:
*/
uint32_t minCommandBufferSizeMB = FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB;
/**
* Size in MiB of the per-frame high level command buffer.
*

View File

@@ -44,6 +44,11 @@ namespace filament {
using namespace backend;
// TODO: these should come from a configuration object on View or Camera
static constexpr size_t FROXEL_SLICE_COUNT = 16;
static constexpr float FROXEL_FIRST_SLICE_DEPTH = 5;
static constexpr float FROXEL_LAST_SLICE_DISTANCE = 100;
// The Froxel buffer is set to FROXEL_BUFFER_WIDTH x n
// With n limited by the supported texture dimension, which is guaranteed to be at least 2048
// in all version of GLES.
@@ -63,7 +68,7 @@ constexpr size_t RECORD_BUFFER_ENTRY_COUNT = RECORD_BUFFER_WIDTH * RECORD_BUFFE
constexpr size_t PER_FROXELDATA_ARENA_SIZE = sizeof(float4) *
(FROXEL_BUFFER_ENTRY_COUNT_MAX +
FROXEL_BUFFER_ENTRY_COUNT_MAX + 3 +
FEngine::CONFIG_FROXEL_SLICE_COUNT / 4 + 1);
FROXEL_SLICE_COUNT / 4 + 1);
// number of lights processed by one group (e.g. 32)
@@ -80,8 +85,10 @@ static_assert(RECORD_BUFFER_ENTRY_COUNT <= 65536,
"RecordBuffer cannot be larger than 65536 entries");
Froxelizer::Froxelizer(FEngine& engine)
: mArena("froxel", PER_FROXELDATA_ARENA_SIZE) {
: mArena("froxel", PER_FROXELDATA_ARENA_SIZE),
mZLightNear(FROXEL_FIRST_SLICE_DEPTH),
mZLightFar(FROXEL_LAST_SLICE_DISTANCE)
{
DriverApi& driverApi = engine.getDriverApi();
static_assert(std::is_same_v<RecordBufferType, uint8_t>,
@@ -200,7 +207,7 @@ void Froxelizer::computeFroxelLayout(
// calculate froxel dimension from FROXEL_BUFFER_ENTRY_COUNT_MAX and viewport
// - Start from the maximum number of froxels we can use in the x-y plane
size_t froxelSliceCount = FEngine::CONFIG_FROXEL_SLICE_COUNT;
size_t froxelSliceCount = FROXEL_SLICE_COUNT;
size_t froxelPlaneCount = FROXEL_BUFFER_ENTRY_COUNT_MAX / froxelSliceCount;
// - compute the number of square froxels we need in width and height, rounded down
// solving: | froxelCountX * froxelCountY == froxelPlaneCount

View File

@@ -248,8 +248,8 @@ private:
math::float4 mParamsZ = {};
math::uint3 mParamsF = {};
float mNear = 0.0f; // camera near
float mZLightFar = FEngine::CONFIG_Z_LIGHT_FAR;
float mZLightNear = FEngine::CONFIG_Z_LIGHT_NEAR; // light near (first slice)
float mZLightNear;
float mZLightFar;
// track if we need to update our internal state before froxelizing
uint8_t mDirtyFlags = 0;

View File

@@ -62,12 +62,13 @@ namespace filament {
using namespace backend;
using namespace filaflat;
FEngine* FEngine::create(Backend backend, Platform* platform, void* sharedGLContext, const Config *config) {
FEngine* FEngine::create(Backend backend, Platform* platform,
void* sharedGLContext, const Config *pConfig) {
SYSTRACE_ENABLE();
SYSTRACE_CALL();
Config validConfig = validateConfig(config);
FEngine* instance = new FEngine(backend, platform, validConfig, sharedGLContext);
const Config config{ validateConfig(pConfig) };
FEngine* instance = new FEngine(backend, platform, config, sharedGLContext);
// initialize all fields that need an instance of FEngine
// (this cannot be done safely in the ctor)
@@ -224,25 +225,19 @@ FEngine::FEngine(Backend backend, Platform* platform, const Config& config, void
mTransformManager(),
mLightManager(*this),
mCameraManager(*this),
mCommandBufferQueue(config.minCommandBufferSizeMB * 1024 * 1024, config.commandBufferSizeMB * 1024 * 1024),
mPerRenderPassAllocator("FEngine::mPerRenderPassAllocator", config.perRenderPassArenaSizeMB * 1024 * 1024),
mCommandBufferQueue(config.minCommandBufferSizeMB * MiB, config.commandBufferSizeMB * MiB),
mPerRenderPassAllocator("FEngine::mPerRenderPassAllocator", config.perRenderPassArenaSizeMB * MiB),
mHeapAllocator("FEngine::mHeapAllocator", AreaPolicy::NullArea{}),
mJobSystem(getJobSystemThreadPoolSize()),
mEngineEpoch(std::chrono::steady_clock::now()),
mDriverBarrier(1),
mMainThreadId(ThreadUtils::getThreadId())
mMainThreadId(ThreadUtils::getThreadId()),
mConfig(config)
{
// we're assuming we're on the main thread here.
// (it may not be the case)
mJobSystem.adopt();
constexpr size_t MiB = 1024U * 1024U;
mMinCommandBufferSize = config.minCommandBufferSizeMB * MiB;
mCommandBufferSize = config.commandBufferSizeMB * MiB;
mPerFrameCommandsSize = config.perFrameCommandsSizeMB * MiB;
mPerRenderPassArenaSize = config.perRenderPassArenaSizeMB * MiB;
mRequestedDriverHandleArenaSize = config.driverHandleArenaSizeMB * MiB;
slog.i << "FEngine (" << sizeof(void*) * 8 << " bits) created at " << this << " "
<< "(threading is " << (UTILS_HAS_THREADING ? "enabled)" : "disabled)") << io::endl;
}
@@ -411,7 +406,7 @@ void FEngine::shutdown() {
#ifndef NDEBUG
// print out some statistics about this run
size_t wm = mCommandBufferQueue.getHighWatermark();
size_t wmpct = wm / (mCommandBufferSize / 100);
size_t wmpct = wm / (getCommandBufferSize() / 100);
slog.d << "CircularBuffer: High watermark "
<< wm / 1024 << " KiB (" << wmpct << "%)" << io::endl;
#endif

View File

@@ -118,16 +118,10 @@ public:
using Epoch = clock::time_point;
using duration = clock::duration;
// TODO: these should come from a configuration object
static constexpr float CONFIG_Z_LIGHT_NEAR = 5;
static constexpr float CONFIG_Z_LIGHT_FAR = 100;
static constexpr size_t CONFIG_FROXEL_SLICE_COUNT = 16;
static constexpr bool CONFIG_IBL_USE_IRRADIANCE_MAP = false;
public:
static FEngine* create(Backend backend = Backend::DEFAULT,
Platform* platform = nullptr, void* sharedGLContext = nullptr,
const Config* config = nullptr);
const Config* pConfig = nullptr);
#if UTILS_HAS_THREADING
static void createAsync(CreateCallback callback, void* user,
@@ -361,11 +355,13 @@ public:
backend::Handle<backend::HwTexture> getZeroTextureArray() const { return mDummyZeroTextureArray; }
backend::Handle<backend::HwTexture> getOneIntegerTextureArray() const { return mDummyOneIntegerTextureArray; }
size_t getMinCommandBufferSize() const noexcept { return mMinCommandBufferSize; }
size_t getCommandBufferSize() const noexcept { return mCommandBufferSize; }
size_t getPerFrameCommandsSize() const noexcept { return mPerFrameCommandsSize; }
size_t getPerRenderPassArenaSize() const noexcept { return mPerRenderPassArenaSize; }
size_t getRequestedDriverHandleArenaSize() const noexcept { return mRequestedDriverHandleArenaSize; }
static constexpr const size_t MiB = 1024u * 1024u;
size_t getMinCommandBufferSize() const noexcept { return mConfig.minCommandBufferSizeMB * MiB; }
size_t getCommandBufferSize() const noexcept { return mConfig.commandBufferSizeMB * MiB; }
size_t getPerFrameCommandsSize() const noexcept { return mConfig.perFrameCommandsSizeMB * MiB; }
size_t getPerRenderPassArenaSize() const noexcept { return mConfig.perRenderPassArenaSizeMB * MiB; }
size_t getRequestedDriverHandleArenaSize() const noexcept { return mConfig.driverHandleArenaSizeMB * MiB; }
Config const& getConfig() const noexcept { return mConfig; }
private:
static Config validateConfig(const Config* pConfig) noexcept;
@@ -480,11 +476,7 @@ private:
std::thread::id mMainThreadId{};
// Creation parameters
size_t mMinCommandBufferSize; // minimum size of command buffer (in bytes)
size_t mCommandBufferSize; // size of command buffer (in bytes)
size_t mPerFrameCommandsSize; // size of the high-level draw commands buffer (in bytes)
size_t mPerRenderPassArenaSize; // size of the per-pass arena buffer (in bytes)
size_t mRequestedDriverHandleArenaSize; // requested size of driver handle arena (in bytes). Driver will validate and clam
Config mConfig;
public:
// these are the debug properties used by FDebug. They're accessed directly by modules who need them.

View File

@@ -36,6 +36,9 @@ using namespace filament::math;
namespace filament {
// TODO: This should be a quality setting on View or LightManager
static constexpr bool CONFIG_IBL_USE_IRRADIANCE_MAP = false;
// ------------------------------------------------------------------------------------------------
struct IndirectLight::BuilderDetails {
@@ -188,13 +191,13 @@ FIndirectLight::FIndirectLight(FEngine& engine, const Builder& builder) noexcept
mIrradianceTexture = upcast(builder->mIrradianceMap);
} else {
// TODO: if needed, generate the irradiance map, this is an engine config
if (FEngine::CONFIG_IBL_USE_IRRADIANCE_MAP) {
if (CONFIG_IBL_USE_IRRADIANCE_MAP) {
}
}
}
void FIndirectLight::terminate(FEngine& engine) {
if (FEngine::CONFIG_IBL_USE_IRRADIANCE_MAP) {
if (CONFIG_IBL_USE_IRRADIANCE_MAP) {
FEngine::DriverApi& driver = engine.getDriverApi();
driver.destroyTexture(getIrradianceHwHandle());
}