cleanup and missing includes
This commit is contained in:
committed by
Mathias Agopian
parent
660bb5f8fe
commit
2c60740edd
@@ -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;
|
||||
|
||||
@@ -16,15 +16,31 @@
|
||||
|
||||
#include "details/InstanceBuffer.h"
|
||||
|
||||
#include <details/Engine.h>
|
||||
#include <private/filament/UibStructs.h>
|
||||
#include "details/Engine.h"
|
||||
|
||||
#include "FilamentAPI-impl.h"
|
||||
|
||||
#include <private/filament/UibStructs.h>
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/InstanceBuffer.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/Handle.h>
|
||||
|
||||
#include <utils/Panic.h>
|
||||
#include <utils/StaticString.h>
|
||||
|
||||
#include <math/mat3.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/mat4.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstddef>
|
||||
|
||||
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<HwBufferObject> 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<PerRenderableData*>(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
|
||||
|
||||
@@ -28,8 +28,11 @@
|
||||
#include <utils/CString.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
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<backend::HwBufferObject> handle);
|
||||
|
||||
utils::CString const& getName() const noexcept { return mName; }
|
||||
|
||||
@@ -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 <private/filament/UibStructs.h>
|
||||
#include "components/TransformManager.h"
|
||||
|
||||
#include "details/Engine.h"
|
||||
#include "details/IndirectLight.h"
|
||||
#include "details/InstanceBuffer.h"
|
||||
#include "details/Skybox.h"
|
||||
|
||||
#include "BufferPoolAllocator.h"
|
||||
|
||||
#include <private/filament/UibStructs.h>
|
||||
#include <private/utils/Tracing.h>
|
||||
|
||||
#include <filament/Box.h>
|
||||
#include <filament/TransformManager.h>
|
||||
#include <filament/RenderableManager.h>
|
||||
#include <filament/LightManager.h>
|
||||
|
||||
#include <math/mat3.h>
|
||||
#include <math/mat4.h>
|
||||
#include <math/vec2.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
#include <utils/Allocator.h>
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/debug.h>
|
||||
#include <utils/EntityManager.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/Invocable.h>
|
||||
#include <utils/JobSystem.h>
|
||||
#include <utils/Range.h>
|
||||
|
||||
#include <math/quat.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <new>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
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<RootArenaScope::Arena> 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<size_t>(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<LAYERS>()[i] = 0;
|
||||
sceneData.data<VISIBLE_MASK>()[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<PerRenderableData*>(bufferPoolAllocator.get(count * sizeof(PerRenderableData)));
|
||||
} else {
|
||||
// allocate space into the command stream directly
|
||||
return driver.allocatePod<PerRenderableData>(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<SharedState>* const weakShared = new std::weak_ptr<SharedState>(mSharedState);
|
||||
std::weak_ptr<SharedState>* const weakShared = new(std::nothrow) std::weak_ptr(mSharedState);
|
||||
|
||||
// update the UBO
|
||||
driver.resetBufferObject(renderableUbh);
|
||||
|
||||
Reference in New Issue
Block a user