diff --git a/filament/include/filament/InstanceBuffer.h b/filament/include/filament/InstanceBuffer.h index 09e2acee8d..4493dab61c 100644 --- a/filament/include/filament/InstanceBuffer.h +++ b/filament/include/filament/InstanceBuffer.h @@ -101,7 +101,7 @@ public: /** * Creates the InstanceBuffer object and returns a pointer to it. */ - InstanceBuffer* UTILS_NONNULL build(Engine& engine); + InstanceBuffer* UTILS_NONNULL build(Engine& engine) const; private: friend class FInstanceBuffer; diff --git a/filament/src/details/InstanceBuffer.cpp b/filament/src/details/InstanceBuffer.cpp index cbc9b1bdf6..d4f2157e48 100644 --- a/filament/src/details/InstanceBuffer.cpp +++ b/filament/src/details/InstanceBuffer.cpp @@ -16,15 +16,31 @@ #include "details/InstanceBuffer.h" -#include
-#include +#include "details/Engine.h" #include "FilamentAPI-impl.h" +#include + +#include +#include +#include + +#include +#include + +#include #include #include -#include +#include + +#include + +#include +#include +#include +#include namespace filament { @@ -60,7 +76,7 @@ InstanceBuffer::Builder& InstanceBuffer::Builder::name(utils::StaticString const return BuilderNameMixin::name(name); } -InstanceBuffer* InstanceBuffer::Builder::build(Engine& engine) { +InstanceBuffer* InstanceBuffer::Builder::build(Engine& engine) const { FILAMENT_CHECK_PRECONDITION(mImpl->mInstanceCount >= 1) << "instanceCount must be >= 1."; FILAMENT_CHECK_PRECONDITION(mImpl->mInstanceCount <= engine.getMaxAutomaticInstances()) << "instanceCount is " << mImpl->mInstanceCount @@ -71,7 +87,7 @@ InstanceBuffer* InstanceBuffer::Builder::build(Engine& engine) { // ------------------------------------------------------------------------------------------------ -FInstanceBuffer::FInstanceBuffer(FEngine& engine, const Builder& builder) +FInstanceBuffer::FInstanceBuffer(FEngine&, const Builder& builder) : mName(builder.getName()) { mInstanceCount = builder->mInstanceCount; @@ -93,20 +109,20 @@ void FInstanceBuffer::setLocalTransforms( memcpy(mLocalTransforms.data() + offset, localTransforms, sizeof(math::mat4f) * count); } -void FInstanceBuffer::prepare(FEngine& engine, math::mat4f rootTransform, +void FInstanceBuffer::prepare(FEngine& engine, math::mat4f const& rootTransform, const PerRenderableData& ubo, Handle handle) { DriverApi& driver = engine.getDriverApi(); // TODO: allocate this staging buffer from a pool. - uint32_t stagingBufferSize = sizeof(PerRenderableUib); - PerRenderableData* stagingBuffer = (PerRenderableData*)malloc(stagingBufferSize); + constexpr uint32_t stagingBufferSize = sizeof(PerRenderableUib); + PerRenderableData* stagingBuffer = static_cast(malloc(stagingBufferSize)); // TODO: consider using JobSystem to parallelize this. for (size_t i = 0, c = mInstanceCount; i < c; i++) { stagingBuffer[i] = ubo; - math::mat4f model = rootTransform * mLocalTransforms[i]; + math::mat4f const model = rootTransform * mLocalTransforms[i]; stagingBuffer[i].worldFromModelMatrix = model; - math::mat3f m = math::mat3f::getTransformForNormals(model.upperLeft()); + math::mat3f const m = math::mat3f::getTransformForNormals(model.upperLeft()); stagingBuffer[i].worldFromModelNormalMatrix = math::prescaleForNormals(m); } driver.updateBufferObject(handle, { @@ -117,7 +133,7 @@ void FInstanceBuffer::prepare(FEngine& engine, math::mat4f rootTransform, }, 0); } -void FInstanceBuffer::terminate(FEngine& engine) { +void FInstanceBuffer::terminate(FEngine&) { } } // namespace filament diff --git a/filament/src/details/InstanceBuffer.h b/filament/src/details/InstanceBuffer.h index 56bac500c2..131235ead2 100644 --- a/filament/src/details/InstanceBuffer.h +++ b/filament/src/details/InstanceBuffer.h @@ -28,8 +28,11 @@ #include #include +#include + namespace filament { +class RenderableManager; class FEngine; struct PerRenderableData; @@ -44,7 +47,7 @@ public: void setLocalTransforms(math::mat4f const* localTransforms, size_t count, size_t offset); - void prepare(FEngine& engine, math::mat4f rootTransform, const PerRenderableData& ubo, + void prepare(FEngine& engine, math::mat4f const& rootTransform, const PerRenderableData& ubo, backend::Handle handle); utils::CString const& getName() const noexcept { return mName; } diff --git a/filament/src/details/Scene.cpp b/filament/src/details/Scene.cpp index b055bd804b..4a7b82e63b 100644 --- a/filament/src/details/Scene.cpp +++ b/filament/src/details/Scene.cpp @@ -16,27 +16,50 @@ #include "details/Scene.h" +#include "Allocators.h" +#include "BufferPoolAllocator.h" + +#include "backend/Handle.h" #include "components/LightManager.h" #include "components/RenderableManager.h" - -#include +#include "components/TransformManager.h" #include "details/Engine.h" -#include "details/IndirectLight.h" #include "details/InstanceBuffer.h" #include "details/Skybox.h" -#include "BufferPoolAllocator.h" - +#include #include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include #include +#include #include +#include +#include +#include #include -#include - #include +#include +#include +#include +#include +#include +#include + +#include using namespace filament::backend; using namespace filament::math; @@ -65,7 +88,7 @@ void FScene::prepare(JobSystem& js, FILAMENT_TRACING_CONTEXT(FILAMENT_TRACING_CATEGORY_FILAMENT); // This will reset the allocator upon exiting - ArenaScope localArenaScope(rootArenaScope.getArena()); + ArenaScope localArenaScope(rootArenaScope.getArena()); FEngine& engine = mEngine; EntityManager const& em = engine.getEntityManager(); @@ -139,7 +162,7 @@ void FScene::prepare(JobSystem& js, // The light data list will always contain at least one entry for the // dominating directional light, even if there are no entities. - // we need the capacity to be multiple of 16 for SIMD loops + // We need the capacity to be multiple of 16 for SIMD loops size_t lightDataCapacity = std::max(DIRECTIONAL_LIGHTS_COUNT, entities.size()); lightDataCapacity = (lightDataCapacity + 0xFu) & ~0xFu; @@ -314,7 +337,7 @@ void FScene::prepare(JobSystem& js, // Purely for the benefit of MSAN, we can avoid uninitialized reads by zeroing out the // unused scene elements between the end of the array and the rounded-up count. - if (UTILS_HAS_SANITIZE_MEMORY) { + if constexpr (UTILS_HAS_SANITIZE_MEMORY) { for (size_t i = sceneData.size(), e = sceneData.capacity(); i < e; i++) { sceneData.data()[i] = 0; sceneData.data()[i] = 0; @@ -396,7 +419,7 @@ void FScene::updateUBOs( if (count >= MAX_STREAM_ALLOCATION_COUNT) { // use the heap allocator auto& bufferPoolAllocator = mSharedState->mBufferPoolAllocator; - return (PerRenderableData*)bufferPoolAllocator.get(count * sizeof(PerRenderableData)); + return static_cast(bufferPoolAllocator.get(count * sizeof(PerRenderableData))); } else { // allocate space into the command stream directly return driver.allocatePod(count); @@ -423,7 +446,7 @@ void FScene::updateUBOs( // We capture state shared between Scene and the update buffer callback, because the Scene could // be destroyed before the callback executes. - std::weak_ptr* const weakShared = new std::weak_ptr(mSharedState); + std::weak_ptr* const weakShared = new(std::nothrow) std::weak_ptr(mSharedState); // update the UBO driver.resetBufferObject(renderableUbh);