From 559bc4eb96deb50268c243ebcd72b13558978613 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 7 Feb 2025 14:48:37 -0800 Subject: [PATCH] fix some missing includes and trivial warnings (#8414) --- filament/backend/src/opengl/OpenGLDriver.cpp | 84 ++++++------ filament/backend/src/opengl/OpenGLDriver.h | 6 +- filament/src/details/Engine.cpp | 127 ++++++++++--------- filament/src/details/Engine.h | 4 +- 4 files changed, 118 insertions(+), 103 deletions(-) diff --git a/filament/backend/src/opengl/OpenGLDriver.cpp b/filament/backend/src/opengl/OpenGLDriver.cpp index 3390b7f81e0..78637aeefcf 100644 --- a/filament/backend/src/opengl/OpenGLDriver.cpp +++ b/filament/backend/src/opengl/OpenGLDriver.cpp @@ -39,6 +39,7 @@ #include #include +#include "private/backend/CommandStream.h" #include "private/backend/Dispatcher.h" #include "private/backend/DriverApi.h" @@ -46,9 +47,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -155,7 +158,7 @@ using namespace GLUtils; UTILS_NOINLINE OpenGLDriver* OpenGLDriver::create(OpenGLPlatform* const platform, - void* const sharedGLContext, const Platform::DriverConfig& driverConfig) noexcept { + void* const /*sharedGLContext*/, const Platform::DriverConfig& driverConfig) noexcept { assert_invariant(platform); OpenGLPlatform* const ec = platform; @@ -222,7 +225,7 @@ OpenGLDriver* OpenGLDriver::create(OpenGLPlatform* const platform, } #endif - size_t const defaultSize = FILAMENT_OPENGL_HANDLE_ARENA_SIZE_IN_MB * 1024U * 1024U; + constexpr size_t defaultSize = FILAMENT_OPENGL_HANDLE_ARENA_SIZE_IN_MB * 1024U * 1024U; Platform::DriverConfig validConfig{ driverConfig }; validConfig.handleArenaSize = std::max(driverConfig.handleArenaSize, defaultSize); OpenGLDriver* const driver = new(std::nothrow) OpenGLDriver(ec, validConfig); @@ -277,7 +280,6 @@ OpenGLDriver::OpenGLDriver(OpenGLPlatform* platform, const Platform::DriverConfi driverConfig.disableHandleUseAfterFreeCheck), mDriverConfig(driverConfig), mCurrentPushConstants(new(std::nothrow) PushConstantBundle{}) { - // set a reasonable default value for our stream array mTexturesWithStreamsAttached.reserve(8); mStreamsWithPendingAcquiredImage.reserve(8); @@ -366,8 +368,8 @@ void OpenGLDriver::bindSampler(GLuint unit, GLuint sampler) noexcept { mContext.bindSampler(unit, sampler); } -void OpenGLDriver::setPushConstant(backend::ShaderStage stage, uint8_t index, - backend::PushConstantVariant value) { +void OpenGLDriver::setPushConstant(ShaderStage stage, uint8_t index, + PushConstantVariant value) { assert_invariant(stage == ShaderStage::VERTEX || stage == ShaderStage::FRAGMENT); #if FILAMENT_ENABLE_MATDBG @@ -376,7 +378,7 @@ void OpenGLDriver::setPushConstant(backend::ShaderStage stage, uint8_t index, } #endif - utils::Slice> constants; + Slice> constants; if (stage == ShaderStage::VERTEX) { constants = mCurrentPushConstants->vertexConstants; } else if (stage == ShaderStage::FRAGMENT) { @@ -681,7 +683,7 @@ void OpenGLDriver::createBufferObjectR(Handle boh, bo->gl.buffer = malloc(byteCount); memset(bo->gl.buffer, 0, byteCount); } else { - bo->gl.binding = GLUtils::getBufferBindingType(bindingType); + bo->gl.binding = getBufferBindingType(bindingType); glGenBuffers(1, &bo->gl.id); gl.bindBuffer(bo->gl.binding, bo->gl.id); glBufferData(bo->gl.binding, byteCount, nullptr, getBufferUsage(usage)); @@ -758,7 +760,7 @@ void OpenGLDriver::createProgramR(Handle ph, Program&& program) { } UTILS_NOINLINE -void OpenGLDriver::textureStorage(OpenGLDriver::GLTexture* t, +void OpenGLDriver::textureStorage(GLTexture* t, uint32_t width, uint32_t height, uint32_t depth, bool useProtectedMemory) noexcept { auto& gl = mContext; @@ -1144,7 +1146,7 @@ void OpenGLDriver::createTextureExternalImageR(Handle th, SamplerType } void OpenGLDriver::createTextureExternalImagePlaneR(Handle th, - backend::TextureFormat format, uint32_t width, uint32_t height, backend::TextureUsage usage, + TextureFormat format, uint32_t width, uint32_t height, TextureUsage usage, void* image, uint32_t plane) { // not relevant for the OpenGL backend } @@ -1460,7 +1462,7 @@ void OpenGLDriver::framebufferTexture(TargetBufferInfo const& binfo, && ((gl.ext.EXT_multisampled_render_to_texture && attachment == GL_COLOR_ATTACHMENT0) || gl.ext.EXT_multisampled_render_to_texture2)) { assert_invariant(rt->gl.samples > 1); - // We have a multi-sample rendertarget and we have EXT_multisampled_render_to_texture, + // We have a multi-sample rendertarget, and we have EXT_multisampled_render_to_texture, // so, we can directly use a 1-sample texture as attachment, multi-sample resolve, // will happen automagically and efficiently in the driver. // This extension only exists on OpenGL ES. @@ -1660,9 +1662,9 @@ void OpenGLDriver::createRenderTargetR(Handle rth, rt->gl.samples = samples; rt->targets = targets; - UTILS_UNUSED_IN_RELEASE math::vec2 tmin = { std::numeric_limits::max() }; - UTILS_UNUSED_IN_RELEASE math::vec2 tmax = { 0 }; - auto checkDimensions = [&tmin, &tmax](GLTexture* t, uint8_t level) { + UTILS_UNUSED_IN_RELEASE vec2 tmin = { std::numeric_limits::max() }; + UTILS_UNUSED_IN_RELEASE vec2 tmax = { 0 }; + auto checkDimensions = [&tmin, &tmax](GLTexture const* t, uint8_t level) { const auto twidth = std::max(1u, t->width >> level); const auto theight = std::max(1u, t->height >> level); tmin = { std::min(tmin.x, twidth), std::min(tmin.y, theight) }; @@ -2364,11 +2366,11 @@ bool OpenGLDriver::isStereoSupported() { return false; } switch (mDriverConfig.stereoscopicType) { - case backend::StereoscopicType::INSTANCED: + case StereoscopicType::INSTANCED: return mContext.ext.EXT_clip_cull_distance; - case backend::StereoscopicType::MULTIVIEW: + case StereoscopicType::MULTIVIEW: return mContext.ext.OVR_multiview2; - case backend::StereoscopicType::NONE: + case StereoscopicType::NONE: return false; } } @@ -2381,7 +2383,7 @@ bool OpenGLDriver::isDepthStencilResolveSupported() { return true; } -bool OpenGLDriver::isDepthStencilBlitSupported(TextureFormat format) { +bool OpenGLDriver::isDepthStencilBlitSupported(TextureFormat) { return true; } @@ -2415,12 +2417,12 @@ FeatureLevel OpenGLDriver::getFeatureLevel() { return mContext.getFeatureLevel(); } -math::float2 OpenGLDriver::getClipSpaceParams() { +float2 OpenGLDriver::getClipSpaceParams() { return mContext.ext.EXT_clip_control ? // z-coordinate of virtual and physical clip-space is in [-w, 0] - math::float2{ 1.0f, 0.0f } : + float2{ 1.0f, 0.0f } : // z-coordinate of virtual clip-space is in [-w,0], physical is in [-w, w] - math::float2{ 2.0f, -1.0f }; + float2{ 2.0f, -1.0f }; } uint8_t OpenGLDriver::getMaxDrawBuffers() { @@ -2484,7 +2486,7 @@ void OpenGLDriver::makeCurrent(Handle schDraw, Handle // Updating driver objects // ------------------------------------------------------------------------------------------------ -void OpenGLDriver::setDebugTag(HandleBase::HandleId handleId, utils::CString tag) { +void OpenGLDriver::setDebugTag(HandleBase::HandleId handleId, CString tag) { mHandleAllocator.associateTagToHandle(handleId, std::move(tag)); } @@ -2660,7 +2662,7 @@ void OpenGLDriver::generateMipmaps(Handle th) { CHECK_GL_ERROR(utils::slog.e) } -void OpenGLDriver::setTextureData(GLTexture* t, uint32_t level, +void OpenGLDriver::setTextureData(GLTexture const* t, uint32_t level, uint32_t xoffset, uint32_t yoffset, uint32_t zoffset, uint32_t width, uint32_t height, uint32_t depth, PixelBufferDescriptor&& p) { @@ -2769,7 +2771,7 @@ void OpenGLDriver::setTextureData(GLTexture* t, uint32_t level, CHECK_GL_ERROR(utils::slog.e) } -void OpenGLDriver::setCompressedTextureData(GLTexture* t, uint32_t level, +void OpenGLDriver::setCompressedTextureData(GLTexture const* t, uint32_t level, uint32_t xoffset, uint32_t yoffset, uint32_t zoffset, uint32_t width, uint32_t height, uint32_t depth, PixelBufferDescriptor&& p) { @@ -3410,8 +3412,8 @@ void OpenGLDriver::readPixels(Handle src, #endif } -void OpenGLDriver::readBufferSubData(backend::BufferObjectHandle boh, - uint32_t offset, uint32_t size, backend::BufferDescriptor&& p) { +void OpenGLDriver::readBufferSubData(BufferObjectHandle boh, + uint32_t offset, uint32_t size, BufferDescriptor&& p) { UTILS_UNUSED_IN_RELEASE auto& gl = mContext; assert_invariant(!gl.isES2()); @@ -3558,13 +3560,13 @@ void OpenGLDriver::beginFrame( } } -void OpenGLDriver::setFrameScheduledCallback(Handle sch, CallbackHandler* handler, - FrameScheduledCallback&& callback, uint64_t flags) { +void OpenGLDriver::setFrameScheduledCallback(Handle, CallbackHandler*, + FrameScheduledCallback&& /*callback*/, uint64_t /*flags*/) { DEBUG_MARKER() } -void OpenGLDriver::setFrameCompletedCallback(Handle sch, - CallbackHandler* handler, utils::Invocable&& callback) { +void OpenGLDriver::setFrameCompletedCallback(Handle, + CallbackHandler*, Invocable&& /*callback*/) { DEBUG_MARKER() } @@ -3595,9 +3597,9 @@ void OpenGLDriver::endFrame(UTILS_UNUSED uint32_t frameId) { } void OpenGLDriver::updateDescriptorSetBuffer( - backend::DescriptorSetHandle dsh, - backend::descriptor_binding_t binding, - backend::BufferObjectHandle boh, + DescriptorSetHandle dsh, + descriptor_binding_t binding, + BufferObjectHandle boh, uint32_t offset, uint32_t size) { GLDescriptorSet* ds = handle_cast(dsh); GLBufferObject* bo = boh ? handle_cast(boh) : nullptr; @@ -3605,9 +3607,9 @@ void OpenGLDriver::updateDescriptorSetBuffer( } void OpenGLDriver::updateDescriptorSetTexture( - backend::DescriptorSetHandle dsh, - backend::descriptor_binding_t binding, - backend::TextureHandle th, + DescriptorSetHandle dsh, + descriptor_binding_t binding, + TextureHandle th, SamplerParams params) { GLDescriptorSet* ds = handle_cast(dsh); GLTexture* t = th ? handle_cast(th) : nullptr; @@ -3640,7 +3642,7 @@ void OpenGLDriver::finish(int) { UTILS_NOINLINE void OpenGLDriver::clearWithRasterPipe(TargetBufferFlags clearFlags, - math::float4 const& linearColor, GLfloat depth, GLint stencil) noexcept { + float4 const& linearColor, GLfloat depth, GLint stencil) noexcept { if (any(clearFlags & TargetBufferFlags::COLOR_ALL)) { mContext.colorMask(GL_TRUE); @@ -3963,9 +3965,9 @@ void OpenGLDriver::bindRenderPrimitive(Handle rph) { } void OpenGLDriver::bindDescriptorSet( - backend::DescriptorSetHandle dsh, - backend::descriptor_set_t set, - backend::DescriptorSetOffsetArray&& offsets) { + DescriptorSetHandle dsh, + descriptor_set_t set, + DescriptorSetOffsetArray&& offsets) { if (UTILS_UNLIKELY(!dsh)) { mBoundDescriptorSets[set].dsh = dsh; @@ -3997,7 +3999,7 @@ void OpenGLDriver::bindDescriptorSet( } } -void OpenGLDriver::updateDescriptors(utils::bitset8 invalidDescriptorSets) noexcept { +void OpenGLDriver::updateDescriptors(bitset8 invalidDescriptorSets) noexcept { assert_invariant(mBoundProgram); auto const offsetOnly = mInvalidDescriptorSetBindingOffsets & ~mInvalidDescriptorSetBindings; invalidDescriptorSets.forEachSetBit([this, offsetOnly, @@ -4109,7 +4111,7 @@ void OpenGLDriver::draw(PipelineState state, Handle rph, } } -void OpenGLDriver::dispatchCompute(Handle program, math::uint3 workGroupCount) { +void OpenGLDriver::dispatchCompute(Handle program, uint3 workGroupCount) { DEBUG_MARKER() getShaderCompilerService().tick(); diff --git a/filament/backend/src/opengl/OpenGLDriver.h b/filament/backend/src/opengl/OpenGLDriver.h index 8fc79651627..879c6ce27bb 100644 --- a/filament/backend/src/opengl/OpenGLDriver.h +++ b/filament/backend/src/opengl/OpenGLDriver.h @@ -298,13 +298,13 @@ class OpenGLDriver final : public OpenGLDriverBase { void setStencilState(StencilState ss) noexcept; - void setTextureData(GLTexture* t, + void setTextureData(GLTexture const* t, uint32_t level, uint32_t xoffset, uint32_t yoffset, uint32_t zoffset, uint32_t width, uint32_t height, uint32_t depth, PixelBufferDescriptor&& p); - void setCompressedTextureData(GLTexture* t, + void setCompressedTextureData(GLTexture const* t, uint32_t level, uint32_t xoffset, uint32_t yoffset, uint32_t zoffset, uint32_t width, uint32_t height, uint32_t depth, @@ -347,7 +347,7 @@ class OpenGLDriver final : public OpenGLDriverBase { struct { DescriptorSetHandle dsh; std::array offsets; - } mBoundDescriptorSets[MAX_DESCRIPTOR_SET_COUNT]; + } mBoundDescriptorSets[MAX_DESCRIPTOR_SET_COUNT] = {}; void clearWithRasterPipe(TargetBufferFlags clearFlags, math::float4 const& linearColor, GLfloat depth, GLint stencil) noexcept; diff --git a/filament/src/details/Engine.cpp b/filament/src/details/Engine.cpp index 3982f9235c8..108f741b299 100644 --- a/filament/src/details/Engine.cpp +++ b/filament/src/details/Engine.cpp @@ -25,7 +25,9 @@ #include "details/Fence.h" #include "details/IndexBuffer.h" #include "details/IndirectLight.h" +#include "details/InstanceBuffer.h" #include "details/Material.h" +#include "details/MorphTargetBuffer.h" #include "details/Renderer.h" #include "details/Scene.h" #include "details/SkinningBuffer.h" @@ -36,28 +38,39 @@ #include "details/VertexBuffer.h" #include "details/View.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 #include #include @@ -66,6 +79,7 @@ #include #include +#include #include #include "generated/resources/materials.h" @@ -101,7 +115,7 @@ Engine* FEngine::create(Builder const& builder) { // Normally we launch a thread and create the context and Driver from there (see FEngine::loop). // In the single-threaded case, we do so in the here and now. - if (!UTILS_HAS_THREADING) { + if constexpr (!UTILS_HAS_THREADING) { Platform* platform = builder->mPlatform; void* const sharedContext = builder->mSharedContext; @@ -144,7 +158,7 @@ Engine* FEngine::create(Builder const& builder) { // now we can initialize the largest part of the engine instance->init(); - if (!UTILS_HAS_THREADING) { + if constexpr (!UTILS_HAS_THREADING) { instance->execute(); } @@ -163,7 +177,7 @@ void FEngine::create(Builder const& builder, Invocable&& callback) instance->mDriverThread = std::thread(&FEngine::loop, instance); // launch a thread to call the callback -- so it can't do any damage. - std::thread callbackThread = std::thread([instance, callback = std::move(callback)]() { + std::thread callbackThread = std::thread([instance, callback = std::move(callback)] { instance->mDriverBarrier.await(); callback(instance); }); @@ -196,7 +210,7 @@ FEngine* FEngine::getEngine(void* token) { #endif -// these must be static because only a pointer is copied to the render stream +// These must be static because only a pointer is copied to the render stream // Note that these coordinates are specified in OpenGL clip space. Other backends can transform // these in the vertex shader as needed. static constexpr float4 sFullScreenTriangleVertices[3] = { @@ -206,7 +220,7 @@ static constexpr float4 sFullScreenTriangleVertices[3] = { }; // these must be static because only a pointer is copied to the render stream -static const uint16_t sFullScreenTriangleIndices[3] = { 0, 1, 2 }; +static constexpr uint16_t sFullScreenTriangleIndices[3] = { 0, 1, 2 }; FEngine::FEngine(Builder const& builder) : mBackend(builder->mBackend), @@ -216,7 +230,6 @@ FEngine::FEngine(Builder const& builder) : mPostProcessManager(*this), mEntityManager(EntityManager::get()), mRenderableManager(*this), - mTransformManager(), mLightManager(*this), mCameraManager(*this), mCommandBufferQueue( @@ -274,7 +287,7 @@ uint32_t FEngine::getJobSystemThreadPoolSize(Config const& config) noexcept { } // 1 thread for the user, 1 thread for the backend - int threadCount = (int)std::thread::hardware_concurrency() - 2; + int threadCount = int(std::thread::hardware_concurrency()) - 2; // make sure we have at least 1 thread though threadCount = std::max(1, threadCount); return threadCount; @@ -347,8 +360,8 @@ void FEngine::init() { } // initialize the dummy textures so that their contents are not undefined - static const uint32_t zeroes[6] = {0}; - static const uint32_t ones = 0xffffffff; + static constexpr uint32_t zeroes[6] = {}; + static constexpr uint32_t ones = 0xffffffff; mDefaultIblTexture = downcast(Texture::Builder() .width(1).height(1).levels(1) @@ -360,7 +373,7 @@ void FEngine::init() { { zeroes, sizeof(zeroes), Texture::Format::RGBA, Texture::Type::UBYTE }); // 3 bands = 9 float3 - const float sh[9 * 3] = { 0.0f }; + constexpr float sh[9 * 3] = { 0.0f }; mDefaultIbl = downcast(IndirectLight::Builder() .irradiance(3, reinterpret_cast(sh)) .build(*this)); @@ -427,10 +440,10 @@ void FEngine::init() { #endif break; } - mDefaultMaterial = downcast(defaultMaterialBuilder.build(*const_cast(this))); + mDefaultMaterial = downcast(defaultMaterialBuilder.build(*this)); - float3 dummyPositions[1] = {}; - short4 dummyTangents[1] = {}; + constexpr float3 dummyPositions[1] = {}; + constexpr short4 dummyTangents[1] = {}; mDummyMorphTargetBuffer->setPositionsAt(*this, 0, dummyPositions, 1, 0); mDummyMorphTargetBuffer->setTangentsAt(*this, 0, dummyTangents, 1, 0); @@ -453,7 +466,7 @@ void FEngine::init() { mPostProcessManager.init(); mDebugRegistry.registerProperty("d.shadowmap.debug_directional_shadowmap", - &debug.shadowmap.debug_directional_shadowmap, [this]() { + &debug.shadowmap.debug_directional_shadowmap, [this] { mMaterials.forEach([this](FMaterial* material) { if (material->getMaterialDomain() == MaterialDomain::SURFACE) { @@ -469,7 +482,7 @@ void FEngine::init() { }); mDebugRegistry.registerProperty("d.lighting.debug_froxel_visualization", - &debug.lighting.debug_froxel_visualization, [this]() { + &debug.lighting.debug_froxel_visualization, [this] { mMaterials.forEach([this](FMaterial* material) { if (material->getMaterialDomain() == MaterialDomain::SURFACE) { @@ -607,7 +620,7 @@ void FEngine::shutdown() { // now wait for all pending commands to be executed and the thread to exit mCommandBufferQueue.requestExit(); - if (!UTILS_HAS_THREADING) { + if constexpr (!UTILS_HAS_THREADING) { execute(); getDriverApi().terminate(); } else { @@ -638,13 +651,13 @@ void FEngine::prepare() { DriverApi& driver = getDriverApi(); for (auto& materialInstanceList: mMaterialInstances) { - materialInstanceList.second.forEach([&driver](FMaterialInstance* item) { + materialInstanceList.second.forEach([&driver](FMaterialInstance const* item) { item->commit(driver); }); } mMaterials.forEach([](FMaterial* material) { -#if FILAMENT_ENABLE_MATDBG +#if FILAMENT_ENABLE_MATDBG // NOLINT(*-include-cleaner) material->checkProgramEdits(); #endif }); @@ -668,7 +681,7 @@ void FEngine::flushAndWait() { flushAndWait(FENCE_WAIT_FOR_EVER); } -bool FEngine::flushAndWait(uint64_t timeout) { +bool FEngine::flushAndWait(uint64_t const timeout) { FILAMENT_CHECK_PRECONDITION(!mCommandBufferQueue.isPaused()) << "Cannot call Engine::flushAndWait() when rendering thread is paused!"; @@ -749,7 +762,7 @@ int FEngine::loop() { } #endif -#if FILAMENT_ENABLE_FGVIEWER +#if FILAMENT_ENABLE_FGVIEWER // NOLINT(*-include-cleaner) #ifdef __ANDROID__ const char* fgviewerPortString = "8085"; #else @@ -779,9 +792,9 @@ int FEngine::loop() { return 0; } -void FEngine::flushCommandBuffer(CommandBufferQueue& commandQueue) { +void FEngine::flushCommandBuffer(CommandBufferQueue& commandBufferQueue) const { getDriver().purge(); - commandQueue.flush(); + commandBufferQueue.flush(); } const FMaterial* FEngine::getSkyboxMaterial() const noexcept { @@ -802,7 +815,7 @@ const FMaterial* FEngine::getSkyboxMaterial() const noexcept { */ template -inline T* FEngine::create(ResourceList& list, +T* FEngine::create(ResourceList& list, typename T::Builder const& builder, ARGS&& ... args) noexcept { T* p = mHeapAllocator.make(*this, builder, std::forward(args)...); if (UTILS_LIKELY(p)) { @@ -880,7 +893,7 @@ FMaterialInstance* FEngine::createMaterialInstance(const FMaterial* material, const FMaterialInstance* other, const char* name) noexcept { FMaterialInstance* p = mHeapAllocator.make(*this, other, name); if (UTILS_LIKELY(p)) { - auto pos = mMaterialInstances.emplace(material, "MaterialInstance"); + auto const pos = mMaterialInstances.emplace(material, "MaterialInstance"); pos.first->second.insert(p); } return p; @@ -958,7 +971,7 @@ FCamera* FEngine::createCamera(Entity const entity) noexcept { } FCamera* FEngine::getCameraComponent(Entity const entity) noexcept { - auto ci = mCameraManager.getInstance(entity); + auto const ci = mCameraManager.getInstance(entity); return ci ? mCameraManager.getCamera(ci) : nullptr; } @@ -1011,16 +1024,16 @@ void FEngine::cleanupResourceListLocked(Lock& lock, ResourceList&& list) { template UTILS_ALWAYS_INLINE -inline bool FEngine::isValid(const T* ptr, ResourceList const& list) const { +bool FEngine::isValid(const T* ptr, ResourceList const& list) const { auto& l = const_cast&>(list); return l.find(ptr) != l.end(); } template UTILS_ALWAYS_INLINE -inline bool FEngine::terminateAndDestroy(const T* ptr, ResourceList& list) { - if (ptr == nullptr) return true; - bool const success = list.remove(ptr); +bool FEngine::terminateAndDestroy(const T* p, ResourceList& list) { + if (p == nullptr) return true; + bool const success = list.remove(p); #if UTILS_HAS_RTTI auto typeName = CallStack::typeName(); @@ -1030,19 +1043,19 @@ inline bool FEngine::terminateAndDestroy(const T* ptr, ResourceList& list) { #endif if (ASSERT_PRECONDITION_NON_FATAL(success, - "Object %s at %p doesn't exist (double free?)", typeNameCStr, ptr)) { - const_cast(ptr)->terminate(*this); - mHeapAllocator.destroy(const_cast(ptr)); + "Object %s at %p doesn't exist (double free?)", typeNameCStr, p)) { + const_cast(p)->terminate(*this); + mHeapAllocator.destroy(const_cast(p)); } return success; } template UTILS_ALWAYS_INLINE -inline bool FEngine::terminateAndDestroyLocked(Lock& lock, const T* ptr, ResourceList& list) { - if (ptr == nullptr) return true; +bool FEngine::terminateAndDestroyLocked(Lock& lock, const T* p, ResourceList& list) { + if (p == nullptr) return true; lock.lock(); - bool const success = list.remove(ptr); + bool const success = list.remove(p); lock.unlock(); #if UTILS_HAS_RTTI @@ -1053,9 +1066,9 @@ inline bool FEngine::terminateAndDestroyLocked(Lock& lock, const T* ptr, Resourc #endif if (ASSERT_PRECONDITION_NON_FATAL(success, - "Object %s at %p doesn't exist (double free?)", typeNameCStr, ptr)) { - const_cast(ptr)->terminate(*this); - mHeapAllocator.destroy(const_cast(ptr)); + "Object %s at %p doesn't exist (double free?)", typeNameCStr, p)) { + const_cast(p)->terminate(*this); + mHeapAllocator.destroy(const_cast(p)); } return success; } @@ -1148,11 +1161,11 @@ bool FEngine::destroy(const FInstanceBuffer* p){ } UTILS_NOINLINE -bool FEngine::destroy(const FMaterial* ptr) { - if (ptr == nullptr) return true; - bool const success = terminateAndDestroy(ptr, mMaterials); +bool FEngine::destroy(const FMaterial* p) { + if (p == nullptr) return true; + bool const success = terminateAndDestroy(p, mMaterials); if (UTILS_LIKELY(success)) { - auto pos = mMaterialInstances.find(ptr); + auto const pos = mMaterialInstances.find(p); if (UTILS_LIKELY(pos != mMaterialInstances.cend())) { mMaterialInstances.erase(pos); } @@ -1161,8 +1174,8 @@ bool FEngine::destroy(const FMaterial* ptr) { } UTILS_NOINLINE -bool FEngine::destroy(const FMaterialInstance* ptr) { - if (ptr == nullptr) return true; +bool FEngine::destroy(const FMaterialInstance* p) { + if (p == nullptr) return true; // Check that the material instance we're destroying is not in use in the RenderableManager // To do this, we currently need to inspect all render primitives in the RenderableManager @@ -1178,13 +1191,13 @@ bool FEngine::destroy(const FMaterialInstance* ptr) { for (size_t j = 0; j < primitiveCount; j++) { auto const* const mi = rcm.getMaterialInstanceAt(ri, 0, j); if (features.engine.debug.assert_material_instance_in_use) { - FILAMENT_CHECK_PRECONDITION(mi != ptr) + FILAMENT_CHECK_PRECONDITION(mi != p) << "destroying MaterialInstance \"" << mi->getName() << "\" which is still in use by Renderable (entity=" << entity.getId() << ", instance=" << ri.asValue() << ", index=" << j << ")"; } else { - if (UTILS_UNLIKELY(mi == ptr)) { + if (UTILS_UNLIKELY(mi == p)) { slog.e << "destroying MaterialInstance \"" << mi->getName() << "\" which is still in use by Renderable (entity=" << entity.getId() << ", instance=" @@ -1196,11 +1209,11 @@ bool FEngine::destroy(const FMaterialInstance* ptr) { } } - if (ptr->isDefaultInstance()) return false; - auto pos = mMaterialInstances.find(ptr->getMaterial()); + if (p->isDefaultInstance()) return false; + auto const pos = mMaterialInstances.find(p->getMaterial()); assert_invariant(pos != mMaterialInstances.cend()); if (pos != mMaterialInstances.cend()) { - return terminateAndDestroy(ptr, pos->second); + return terminateAndDestroy(p, pos->second); } // this shouldn't happen, this would be double-free return false; @@ -1253,7 +1266,7 @@ bool FEngine::isValid(const FMaterial* m, const FMaterialInstance* p) const { } // then find the material instance list for that material - auto it = mMaterialInstances.find(m); + auto const it = mMaterialInstances.find(m); if (it == mMaterialInstances.end()) { // this could happen if this material has no material instances at all return false; @@ -1342,7 +1355,7 @@ void* FEngine::streamAlloc(size_t const size, size_t const alignment) noexcept { bool FEngine::execute() { // wait until we get command buffers to be executed (or thread exit requested) - auto buffers = mCommandBufferQueue.waitForCommands(); + auto const buffers = mCommandBufferQueue.waitForCommands(); if (UTILS_UNLIKELY(buffers.empty())) { return false; } @@ -1381,7 +1394,7 @@ Engine::FeatureLevel FEngine::getSupportedFeatureLevel() const noexcept { Engine::FeatureLevel FEngine::setActiveFeatureLevel(FeatureLevel featureLevel) { FILAMENT_CHECK_PRECONDITION(featureLevel <= getSupportedFeatureLevel()) - << "Feature level " << (unsigned)featureLevel << " not supported"; + << "Feature level " << unsigned(featureLevel) << " not supported"; FILAMENT_CHECK_PRECONDITION(mActiveFeatureLevel >= FeatureLevel::FEATURE_LEVEL_1) << "Cannot adjust feature level beyond 0 at runtime"; return (mActiveFeatureLevel = std::max(mActiveFeatureLevel, featureLevel)); @@ -1400,7 +1413,7 @@ void FEngine::unprotected() noexcept { mUnprotectedDummySwapchain->makeCurrent(getDriverApi()); } -bool FEngine::setFeatureFlag(char const* name, bool const value) noexcept { +bool FEngine::setFeatureFlag(char const* name, bool const value) const noexcept { auto* const p = getFeatureFlagPtr(name); if (p) { *p = value; @@ -1471,7 +1484,7 @@ Engine::Builder& Engine::Builder::feature(char const* name, bool const value) no } Engine::Builder& Engine::Builder::features(std::initializer_list const list) noexcept { - for (auto name : list) { + for (auto const name : list) { if (name) { feature(name, true); } @@ -1500,15 +1513,15 @@ Engine::Config Engine::BuilderDetails::validateConfig(Config config) noexcept { // Use at least the defaults set by the build system config.minCommandBufferSizeMB = std::max( config.minCommandBufferSizeMB, - (uint32_t)FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB); + uint32_t(FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB)); // NOLINT(*-include-cleaner) config.perFrameCommandsSizeMB = std::max( config.perFrameCommandsSizeMB, - (uint32_t)FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB); + uint32_t(FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB)); // NOLINT(*-include-cleaner) config.perRenderPassArenaSizeMB = std::max( config.perRenderPassArenaSizeMB, - (uint32_t)FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB); + uint32_t(FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB)); // NOLINT(*-include-cleaner) config.commandBufferSizeMB = std::max( config.commandBufferSizeMB, diff --git a/filament/src/details/Engine.h b/filament/src/details/Engine.h index eec73eba953..9a78ab2c16f 100644 --- a/filament/src/details/Engine.h +++ b/filament/src/details/Engine.h @@ -519,7 +519,7 @@ class FEngine : public Engine { void shutdown(); int loop(); - void flushCommandBuffer(backend::CommandBufferQueue& commandBufferQueue); + void flushCommandBuffer(backend::CommandBufferQueue& commandBufferQueue) const; template bool isValid(const T* ptr, ResourceList const& list) const; @@ -730,7 +730,7 @@ class FEngine : public Engine { return { mFeatures.data(), mFeatures.size() }; } - bool setFeatureFlag(char const* name, bool value) noexcept; + bool setFeatureFlag(char const* name, bool value) const noexcept; std::optional getFeatureFlag(char const* name) const noexcept; bool* getFeatureFlagPtr(std::string_view name, bool allowConstant = false) const noexcept; };