diff --git a/src/App.cpp b/src/App.cpp index cf7958e9..72df61e3 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -92,9 +92,9 @@ void App::init(ScopedScratch scopeAlloc) vk::BufferUsageFlagBits::eStorageBuffer, asserted_cast(kilobytes(16)), "ConstantsRing"); - m_cam->init(scopeAlloc.child_scope(), &m_constantsRing); + m_cam->init(scopeAlloc.child_scope(), m_constantsRing); - m_world->init(scopeAlloc.child_scope(), &m_constantsRing, m_scenePath); + m_world->init(scopeAlloc.child_scope(), m_constantsRing, m_scenePath); m_renderer->init( scopeAlloc.child_scope(), m_swapchain->config(), @@ -506,7 +506,7 @@ void App::drawFrame(ScopedScratch scopeAlloc, uint32_t scopeHighWatermark) SceneStats &sceneStats = m_sceneStats[nextFrame]; sceneStats = {}; m_world->updateScene( - scopeAlloc.child_scope(), &m_sceneCameraTransform, &sceneStats); + scopeAlloc.child_scope(), m_sceneCameraTransform, sceneStats); m_world->uploadMeshDatas(scopeAlloc.child_scope(), nextFrame); diff --git a/src/gfx/Device.cpp b/src/gfx/Device.cpp index 657f8fc5..6ed148f6 100644 --- a/src/gfx/Device.cpp +++ b/src/gfx/Device.cpp @@ -1706,7 +1706,7 @@ std::filesystem::path Device::updateShaderCache( try { expandIncludes( - alloc, sourcePath, topLevelSource, &fullSource, &uniqueIncludes, 0); + alloc, sourcePath, topLevelSource, fullSource, uniqueIncludes, 0); } catch (const std::exception &e) { diff --git a/src/gfx/ShaderIncludes.cpp b/src/gfx/ShaderIncludes.cpp index c422d0de..e9c881f1 100644 --- a/src/gfx/ShaderIncludes.cpp +++ b/src/gfx/ShaderIncludes.cpp @@ -24,10 +24,8 @@ const StrSpan sLinePrefix{sLinePrefixCStr}; Pair getInclude( Allocator &alloc, const std::filesystem::path &requestingSource, StrSpan requestedSourceRelative, - HashSet *uniqueIncludes) + HashSet &uniqueIncludes) { - WHEELS_ASSERT(uniqueIncludes != nullptr); - const std::filesystem::path requestingDir = requestingSource.parent_path(); const std::filesystem::path requestedSource = (requestingDir / @@ -39,7 +37,7 @@ Pair getInclude( std::string{"Could not find '"} + requestedSource.generic_string() + '\''); - uniqueIncludes->insert(requestedSource); + uniqueIncludes.insert(requestedSource); String content = readFileString(alloc, requestedSource); @@ -142,38 +140,33 @@ uint32_t parseLineNumber(StrSpan span) } StrSpan parseIncludePath( - StrSpan span, size_t *includePathStart, size_t *includePathLength) + StrSpan span, size_t &includePathStart, size_t &includePathLength) { WHEELS_ASSERT(span.starts_with(sIncludePrefix)); - WHEELS_ASSERT(includePathStart != nullptr); - WHEELS_ASSERT(includePathLength != nullptr); // Parse the include path const Optional includePathFrontQuatation = span.find_first('"'); if (!includePathFrontQuatation.has_value()) throw std::runtime_error("Parser expects relative paths."); - *includePathStart = *includePathFrontQuatation + 1; + includePathStart = *includePathFrontQuatation + 1; const Optional includePathNextQuotation = - StrSpan{&span[*includePathStart + 1], span.size() - *includePathStart} + StrSpan{&span[includePathStart + 1], span.size() - includePathStart} .find_first('"'); if (!includePathNextQuotation.has_value()) throw std::runtime_error("Parser expects relative paths."); - *includePathLength = *includePathNextQuotation + 1; + includePathLength = *includePathNextQuotation + 1; - return StrSpan{&span[*includePathStart], *includePathLength}; + return StrSpan{&span[includePathStart], includePathLength}; } } // namespace void expandIncludes( Allocator &alloc, const std::filesystem::path ¤tPath, - StrSpan currentSource, String *fullSource, - HashSet *uniqueIncludes, size_t includeDepth) + StrSpan currentSource, String &fullSource, + HashSet &uniqueIncludes, size_t includeDepth) { - WHEELS_ASSERT(fullSource != nullptr); - WHEELS_ASSERT(uniqueIncludes != nullptr); - if (includeDepth > 100) throw std::runtime_error( currentPath.generic_string() + @@ -236,7 +229,7 @@ void expandIncludes( // Reached the end so copy the remaning span const StrSpan frontSpan{ ¤tSource[frontCursor], backCursor - frontCursor}; - fullSource->extend(frontSpan); + fullSource.extend(frontSpan); frontCursor = backCursor; break; } @@ -271,15 +264,15 @@ void expandIncludes( // Let's copy what's between the cursors before the include const StrSpan frontSpan{ ¤tSource[frontCursor], backCursor - frontCursor}; - fullSource->extend(frontSpan); + fullSource.extend(frontSpan); size_t includePathStart = 0; size_t includePathLength = 0; Optional> include; try { - const StrSpan includeRelPath = parseIncludePath( - tailSpan, &includePathStart, &includePathLength); + const StrSpan includeRelPath = + parseIncludePath(tailSpan, includePathStart, includePathLength); include = getInclude(alloc, currentPath, includeRelPath, uniqueIncludes); @@ -297,10 +290,10 @@ void expandIncludes( genericIncludePath.data(), genericIncludePath.size()}; // Tag include source for error reporting - fullSource->extend("\n#line 1 \""); - fullSource->extend(genericIncludeSpan); - fullSource->push_back('"'); - fullSource->push_back('\n'); + fullSource.extend("\n#line 1 \""); + fullSource.extend(genericIncludeSpan); + fullSource.push_back('"'); + fullSource.push_back('\n'); expandIncludes( alloc, include->first.string().c_str(), include->second, fullSource, @@ -311,12 +304,12 @@ void expandIncludes( snprintf(lineNumberStr.data(), 7, "%u", lineNumber + 1); // Tag current source for error reporting - fullSource->extend("\n#line "); - fullSource->extend(lineNumberStr.data()); - fullSource->push_back(' '); - fullSource->push_back('"'); - fullSource->extend(genericCurrentSpan); - fullSource->push_back('"'); + fullSource.extend("\n#line "); + fullSource.extend(lineNumberStr.data()); + fullSource.push_back(' '); + fullSource.push_back('"'); + fullSource.extend(genericCurrentSpan); + fullSource.push_back('"'); // No newline as we don't skip the one after the include directive // Move cursors past the include path diff --git a/src/gfx/ShaderIncludes.hpp b/src/gfx/ShaderIncludes.hpp index 20f9a4f7..43126fb8 100644 --- a/src/gfx/ShaderIncludes.hpp +++ b/src/gfx/ShaderIncludes.hpp @@ -8,8 +8,8 @@ void expandIncludes( wheels::Allocator &alloc, const std::filesystem::path ¤tPath, - wheels::StrSpan currentSource, wheels::String *fullSource, - wheels::HashSet *uniqueIncludes, + wheels::StrSpan currentSource, wheels::String &fullSource, + wheels::HashSet &uniqueIncludes, size_t includeDepth); #endif // PROSPER_GFX_SHADER_INCLUDES_HPP diff --git a/src/gfx/ShaderReflection.cpp b/src/gfx/ShaderReflection.cpp index ee7c201f..21685dbd 100644 --- a/src/gfx/ShaderReflection.cpp +++ b/src/gfx/ShaderReflection.cpp @@ -144,12 +144,12 @@ struct SpvResult const size_t firstOpOffset = 5; void firstPass( - Allocator &alloc, const uint32_t *words, size_t wordCount, - Span results, uint32_t &pushConstantMetadataId) + Allocator &alloc, Span words, Span results, + uint32_t &pushConstantMetadataId) { // Collect names and types size_t opFirstWord = firstOpOffset; - while (opFirstWord < wordCount) + while (opFirstWord < words.size()) { const uint16_t opWordCount = static_cast(words[opFirstWord] >> 16); @@ -368,12 +368,11 @@ void firstPass( } } -void secondPass( - const uint32_t *words, size_t wordCount, Span results) +void secondPass(Span words, Span results) { // Collect decorations size_t opFirstWord = firstOpOffset; - while (opFirstWord < wordCount) + while (opFirstWord < words.size()) { const uint16_t opWordCount = static_cast(words[opFirstWord] >> 16); @@ -814,19 +813,16 @@ void ShaderReflection::init( for (const std::filesystem::path &include : sourceFiles) m_sourceFiles.insert(include); - const uint32_t *words = spvWords.data(); - const size_t wordCount = spvWords.size(); - const uint32_t spvMagic = 0x0723'0203; - if (words[0] != spvMagic) + if (spvWords[0] != spvMagic) throw std::runtime_error( "Tried to read reflection from invalid SPIR-V words"); // bytes 0 | major | minor | 0, 0x0001'0300 is 1.3 // const uint32_t version = words[1]; - // const uint32_t generatorMagic = words[2]; - const uint32_t idBound = words[3]; - // const uint32_t schema = words[4]; + // const uint32_t generatorMagic = spvWords[2]; + const uint32_t idBound = spvWords[3]; + // const uint32_t schema = spvWords[4]; Array results{scopeAlloc}; results.resize(idBound); @@ -835,10 +831,8 @@ void ShaderReflection::init( // Run in two passes because type definitons come after decorations. // Data relations are simpler this way. - firstPass( - scopeAlloc, words, wordCount, results.mut_span(), - pushConstantMetadataId); - secondPass(words, wordCount, results.mut_span()); + firstPass(scopeAlloc, spvWords, results.mut_span(), pushConstantMetadataId); + secondPass(spvWords, results.mut_span()); if (pushConstantMetadataId != sUninitialized) m_pushConstantsBytesize = diff --git a/src/render/ForwardRenderer.cpp b/src/render/ForwardRenderer.cpp index 6ee8c315..d0d24a7a 100644 --- a/src/render/ForwardRenderer.cpp +++ b/src/render/ForwardRenderer.cpp @@ -69,12 +69,10 @@ ForwardRenderer::~ForwardRenderer() void ForwardRenderer::init( ScopedScratch scopeAlloc, const InputDSLayouts &dsLayouts, - MeshletCuller *meshletCuller, - HierarchicalDepthDownsampler *hierarchicalDepthDownsampler) + MeshletCuller &meshletCuller, + HierarchicalDepthDownsampler &hierarchicalDepthDownsampler) { WHEELS_ASSERT(!m_initialized); - WHEELS_ASSERT(meshletCuller != nullptr); - WHEELS_ASSERT(hierarchicalDepthDownsampler != nullptr); LOG_INFO("Creating ForwardRenderer"); @@ -84,8 +82,8 @@ void ForwardRenderer::init( createDescriptorSets(scopeAlloc.child_scope()); createGraphicsPipelines(dsLayouts); - m_meshletCuller = meshletCuller; - m_hierarchicalDepthDownsampler = hierarchicalDepthDownsampler; + m_meshletCuller = &meshletCuller; + m_hierarchicalDepthDownsampler = &hierarchicalDepthDownsampler; m_initialized = true; } @@ -116,7 +114,7 @@ ForwardRenderer::OpaqueOutput ForwardRenderer::recordOpaque( ScopedScratch scopeAlloc, vk::CommandBuffer cb, const World &world, const Camera &cam, const vk::Rect2D &renderArea, const LightClusteringOutput &lightClusters, BufferHandle inOutDrawStats, - uint32_t nextFrame, bool applyIbl, DrawType drawType, DrawStats *drawStats) + uint32_t nextFrame, bool applyIbl, DrawType drawType, DrawStats &drawStats) { WHEELS_ASSERT(m_initialized); @@ -161,7 +159,7 @@ ForwardRenderer::OpaqueOutput ForwardRenderer::recordOpaque( .ibl = applyIbl, .drawType = drawType, }, - drawStats, " FirstPhase"); + " FirstPhase"); gRenderResources.buffers->release(firstPhaseCullingOutput.dataBuffer); gRenderResources.buffers->release(firstPhaseCullingOutput.argumentBuffer); @@ -204,7 +202,7 @@ ForwardRenderer::OpaqueOutput ForwardRenderer::recordOpaque( .secondPhase = true, .drawType = drawType, }, - drawStats, " SecondPhase"); + " SecondPhase"); gRenderResources.buffers->release(secondPhaseCullingOutput.dataBuffer); gRenderResources.buffers->release( @@ -220,18 +218,17 @@ ForwardRenderer::OpaqueOutput ForwardRenderer::recordOpaque( } void ForwardRenderer::recordTransparent( - ScopedScratch scopeAlloc, vk::CommandBuffer cb, - MeshletCuller *meshletCuller, const World &world, const Camera &cam, - const TransparentInOut &inOutTargets, + ScopedScratch scopeAlloc, vk::CommandBuffer cb, const World &world, + const Camera &cam, const TransparentInOut &inOutTargets, const LightClusteringOutput &lightClusters, BufferHandle inOutDrawStats, - uint32_t nextFrame, DrawType drawType, DrawStats *drawStats) + uint32_t nextFrame, DrawType drawType, DrawStats &drawStats) { WHEELS_ASSERT(m_initialized); PROFILER_CPU_GPU_SCOPE(cb, "Transparent"); const MeshletCullerFirstPhaseOutput cullerOutput = - meshletCuller->recordFirstPhase( + m_meshletCuller->recordFirstPhase( scopeAlloc.child_scope(), cb, MeshletCuller::Mode::Transparent, world, cam, nextFrame, {}, "Transparent", drawStats); WHEELS_ASSERT(!cullerOutput.secondPhaseInput.has_value()); @@ -250,7 +247,7 @@ void ForwardRenderer::recordTransparent( .transparents = true, .drawType = drawType, }, - drawStats, " Geometry"); + " Geometry"); gRenderResources.buffers->release(cullerOutput.dataBuffer); gRenderResources.buffers->release(cullerOutput.argumentBuffer); @@ -488,10 +485,8 @@ void ForwardRenderer::recordDraw( ScopedScratch scopeAlloc, vk::CommandBuffer cb, const World &world, const Camera &cam, uint32_t nextFrame, const RecordInOut &inputsOutputs, const LightClusteringOutput &lightClusters, const Options &options, - DrawStats *drawStats, const char *debugName) + const char *debugName) { - WHEELS_ASSERT(drawStats != nullptr); - PROFILER_CPU_SCOPE(debugName); const vk::Rect2D renderArea = getRect2D(inputsOutputs.inOutIllumination); diff --git a/src/render/ForwardRenderer.hpp b/src/render/ForwardRenderer.hpp index edfbfa8a..1aed0097 100644 --- a/src/render/ForwardRenderer.hpp +++ b/src/render/ForwardRenderer.hpp @@ -32,8 +32,8 @@ class ForwardRenderer }; void init( wheels::ScopedScratch scopeAlloc, const InputDSLayouts &dsLayouts, - MeshletCuller *meshletCuller, - HierarchicalDepthDownsampler *hierarchicalDepthDownsampler); + MeshletCuller &meshletCuller, + HierarchicalDepthDownsampler &hierarchicalDepthDownsampler); void recompileShaders( wheels::ScopedScratch scopeAlloc, @@ -53,7 +53,7 @@ class ForwardRenderer const World &world, const Camera &cam, const vk::Rect2D &renderArea, const LightClusteringOutput &lightClusters, BufferHandle inOutDrawStats, uint32_t nextFrame, bool applyIbl, DrawType drawType, - DrawStats *drawStats); + DrawStats &drawStats); struct TransparentInOut { @@ -62,10 +62,10 @@ class ForwardRenderer }; void recordTransparent( wheels::ScopedScratch scopeAlloc, vk::CommandBuffer cb, - MeshletCuller *meshletCuller, const World &world, const Camera &cam, + const World &world, const Camera &cam, const TransparentInOut &inOutTargets, const LightClusteringOutput &lightClusters, BufferHandle inOutDrawStats, - uint32_t nextFrame, DrawType drawType, DrawStats *drawStats); + uint32_t nextFrame, DrawType drawType, DrawStats &drawStats); void releasePreserved(); @@ -108,7 +108,7 @@ class ForwardRenderer const World &world, const Camera &cam, uint32_t nextFrame, const RecordInOut &inputsOutputs, const LightClusteringOutput &lightClusters, const Options &options, - DrawStats *drawStats, const char *debugName); + const char *debugName); bool m_initialized{false}; diff --git a/src/render/GBufferRenderer.cpp b/src/render/GBufferRenderer.cpp index 2f50bd1a..86e5defe 100644 --- a/src/render/GBufferRenderer.cpp +++ b/src/render/GBufferRenderer.cpp @@ -53,12 +53,10 @@ struct Attachments void GBufferRenderer::init( ScopedScratch scopeAlloc, const vk::DescriptorSetLayout camDSLayout, - const WorldDSLayouts &worldDSLayouts, MeshletCuller *meshletCuller, - HierarchicalDepthDownsampler *hierarchicalDepthDownsampler) + const WorldDSLayouts &worldDSLayouts, MeshletCuller &meshletCuller, + HierarchicalDepthDownsampler &hierarchicalDepthDownsampler) { WHEELS_ASSERT(!m_initialized); - WHEELS_ASSERT(meshletCuller != nullptr); - WHEELS_ASSERT(hierarchicalDepthDownsampler != nullptr); LOG_INFO("Creating GBufferRenderer"); @@ -68,8 +66,8 @@ void GBufferRenderer::init( createDescriptorSets(scopeAlloc.child_scope()); createGraphicsPipelines(camDSLayout, worldDSLayouts); - m_meshletCuller = meshletCuller; - m_hierarchicalDepthDownsampler = hierarchicalDepthDownsampler; + m_meshletCuller = &meshletCuller; + m_hierarchicalDepthDownsampler = &hierarchicalDepthDownsampler; m_initialized = true; } @@ -111,10 +109,9 @@ GBufferRendererOutput GBufferRenderer::record( ScopedScratch scopeAlloc, vk::CommandBuffer cb, const World &world, const Camera &cam, const vk::Rect2D &renderArea, BufferHandle inOutDrawStats, DrawType drawType, const uint32_t nextFrame, - DrawStats *drawStats) + DrawStats &drawStats) { WHEELS_ASSERT(m_initialized); - WHEELS_ASSERT(drawStats != nullptr); PROFILER_CPU_GPU_SCOPE(cb, "GBuffer"); @@ -179,7 +176,7 @@ GBufferRendererOutput GBufferRenderer::record( .outVelocity = ret.velocity, .outDepth = ret.depth, }, - drawType, false, drawStats); + drawType, false); gRenderResources.buffers->release( firstPhaseCullingOutput.dataBuffer); @@ -220,7 +217,7 @@ GBufferRendererOutput GBufferRenderer::record( .outVelocity = ret.velocity, .outDepth = ret.depth, }, - drawType, true, drawStats); + drawType, true); gRenderResources.buffers->release( secondPhaseCullingOutput.dataBuffer); @@ -438,11 +435,8 @@ void GBufferRenderer::createGraphicsPipelines( void GBufferRenderer::recordDraw( ScopedScratch scopeAlloc, vk::CommandBuffer cb, const World &world, const Camera &cam, const vk::Rect2D &renderArea, uint32_t nextFrame, - const RecordInOut &inputsOutputs, DrawType drawType, bool isSecondPhase, - DrawStats *drawStats) + const RecordInOut &inputsOutputs, DrawType drawType, bool isSecondPhase) { - WHEELS_ASSERT(drawStats != nullptr); - const vk::DescriptorSet ds = m_meshSets[nextFrame * 2 + (isSecondPhase ? 1u : 0u)]; diff --git a/src/render/GBufferRenderer.hpp b/src/render/GBufferRenderer.hpp index 471fe9bc..4c3e3de5 100644 --- a/src/render/GBufferRenderer.hpp +++ b/src/render/GBufferRenderer.hpp @@ -33,8 +33,8 @@ class GBufferRenderer void init( wheels::ScopedScratch scopeAlloc, vk::DescriptorSetLayout camDSLayout, - const WorldDSLayouts &worldDSLayouts, MeshletCuller *meshletCuller, - HierarchicalDepthDownsampler *hierarchicalDepthDownsampler); + const WorldDSLayouts &worldDSLayouts, MeshletCuller &meshletCuller, + HierarchicalDepthDownsampler &hierarchicalDepthDownsampler); void recompileShaders( wheels::ScopedScratch scopeAlloc, @@ -46,7 +46,7 @@ class GBufferRenderer wheels::ScopedScratch scopeAlloc, vk::CommandBuffer cb, const World &world, const Camera &cam, const vk::Rect2D &renderArea, BufferHandle inOutDrawStats, DrawType drawType, uint32_t nextFrame, - DrawStats *drawStats); + DrawStats &drawStats); void releasePreserved(); private: @@ -83,7 +83,7 @@ class GBufferRenderer wheels::ScopedScratch scopeAlloc, vk::CommandBuffer cb, const World &world, const Camera &cam, const vk::Rect2D &renderArea, uint32_t nextFrame, const RecordInOut &inputsOutputs, DrawType drawType, - bool isSecondPhase, DrawStats *drawStats); + bool isSecondPhase); bool m_initialized{false}; diff --git a/src/render/MeshletCuller.cpp b/src/render/MeshletCuller.cpp index b4d80bd8..fc31d603 100644 --- a/src/render/MeshletCuller.cpp +++ b/src/render/MeshletCuller.cpp @@ -217,7 +217,7 @@ MeshletCullerFirstPhaseOutput MeshletCuller::recordFirstPhase( ScopedScratch scopeAlloc, vk::CommandBuffer cb, Mode mode, const World &world, const Camera &cam, uint32_t nextFrame, const Optional &inHierarchicalDepth, StrSpan debugPrefix, - DrawStats *drawStats) + DrawStats &drawStats) { WHEELS_ASSERT(m_initialized); @@ -290,7 +290,7 @@ MeshletCullerSecondPhaseOutput MeshletCuller::recordSecondPhase( BufferHandle MeshletCuller::recordGenerateList( ScopedScratch scopeAlloc, vk::CommandBuffer cb, Mode mode, const World &world, uint32_t nextFrame, StrSpan debugPrefix, - DrawStats *drawStats) + DrawStats &drawStats) { uint32_t meshletCountUpperBound = 0; { @@ -317,13 +317,13 @@ BufferHandle MeshletCuller::recordGenerateList( if (shouldDraw) { - drawStats->totalMeshCount++; - drawStats->totalTriangleCount += info.indexCount / 3; - drawStats->totalMeshletCount += info.meshletCount; + drawStats.totalMeshCount++; + drawStats.totalTriangleCount += info.indexCount / 3; + drawStats.totalMeshletCount += info.meshletCount; meshletCountUpperBound += info.meshletCount; if (!modelDrawn) { - drawStats->totalModelCount++; + drawStats.totalModelCount++; modelDrawn = true; } } diff --git a/src/render/MeshletCuller.hpp b/src/render/MeshletCuller.hpp index 27bf329b..0aaac14b 100644 --- a/src/render/MeshletCuller.hpp +++ b/src/render/MeshletCuller.hpp @@ -59,7 +59,7 @@ class MeshletCuller wheels::ScopedScratch scopeAlloc, vk::CommandBuffer cb, Mode mode, const World &world, const Camera &cam, uint32_t nextFrame, const wheels::Optional &inHierarchicalDepth, - wheels::StrSpan debugPrefix, DrawStats *drawStats); + wheels::StrSpan debugPrefix, DrawStats &drawStats); // Culls the input draw lists. Intended to use with depth drawn with the // first pass outputs @@ -73,7 +73,7 @@ class MeshletCuller [[nodiscard]] BufferHandle recordGenerateList( wheels::ScopedScratch scopeAlloc, vk::CommandBuffer cb, Mode mode, const World &world, uint32_t nextFrame, wheels::StrSpan debugPrefix, - DrawStats *drawStats); + DrawStats &drawStats); [[nodiscard]] BufferHandle recordWriteCullerArgs( wheels::ScopedScratch scopeAlloc, vk::CommandBuffer cb, diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 589e4342..cd2b80cb 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -171,10 +171,10 @@ void Renderer::init( .lightClusters = m_lightClustering->descriptorSetLayout(), .world = worldDsLayouts, }, - m_meshletCuller.get(), m_hierarchicalDepthDownsampler.get()); + *m_meshletCuller, *m_hierarchicalDepthDownsampler); m_gbufferRenderer->init( - scopeAlloc.child_scope(), camDsLayout, worldDsLayouts, - m_meshletCuller.get(), m_hierarchicalDepthDownsampler.get()); + scopeAlloc.child_scope(), camDsLayout, worldDsLayouts, *m_meshletCuller, + *m_hierarchicalDepthDownsampler); m_deferredShading->init( scopeAlloc.child_scope(), DeferredShading::InputDSLayouts{ @@ -411,7 +411,7 @@ void Renderer::render( const GBufferRendererOutput gbuffer = m_gbufferRenderer->record( scopeAlloc.child_scope(), cb, world, cam, renderArea, - gpuDrawStats, m_drawType, nextFrame, &drawStats); + gpuDrawStats, m_drawType, nextFrame, drawStats); if (m_deferredRt) illumination = @@ -450,7 +450,7 @@ void Renderer::render( m_forwardRenderer->recordOpaque( scopeAlloc.child_scope(), cb, world, cam, renderArea, lightClusters, gpuDrawStats, nextFrame, m_applyIbl, - m_drawType, &drawStats); + m_drawType, drawStats); illumination = output.illumination; velocity = output.velocity; @@ -467,12 +467,12 @@ void Renderer::render( // Transparent m_forwardRenderer->recordTransparent( - scopeAlloc.child_scope(), cb, m_meshletCuller.get(), world, cam, + scopeAlloc.child_scope(), cb, world, cam, ForwardRenderer::TransparentInOut{ .illumination = illumination, .depth = depth, }, - lightClusters, gpuDrawStats, nextFrame, m_drawType, &drawStats); + lightClusters, gpuDrawStats, nextFrame, m_drawType, drawStats); m_debugRenderer->record( scopeAlloc.child_scope(), cb, cam, diff --git a/src/scene/Camera.cpp b/src/scene/Camera.cpp index f0881448..06d357fa 100644 --- a/src/scene/Camera.cpp +++ b/src/scene/Camera.cpp @@ -50,12 +50,11 @@ Camera::~Camera() gDevice.logical().destroy(m_descriptorSetLayout); } -void Camera::init(wheels::ScopedScratch scopeAlloc, RingBuffer *constantsRing) +void Camera::init(wheels::ScopedScratch scopeAlloc, RingBuffer &constantsRing) { WHEELS_ASSERT(!m_initialized); - WHEELS_ASSERT(constantsRing != nullptr); - m_constantsRing = constantsRing; + m_constantsRing = &constantsRing; LOG_INFO("Creating Camera"); diff --git a/src/scene/Camera.hpp b/src/scene/Camera.hpp index 5b27eb19..cb28223a 100644 --- a/src/scene/Camera.hpp +++ b/src/scene/Camera.hpp @@ -91,7 +91,7 @@ class Camera Camera &operator=(const Camera &other) = delete; Camera &operator=(Camera &&other) = delete; - void init(wheels::ScopedScratch scopeAlloc, RingBuffer *constantsRing); + void init(wheels::ScopedScratch scopeAlloc, RingBuffer &constantsRing); void endFrame(); void lookAt(const CameraTransform &transform); diff --git a/src/scene/DeferredLoadingContext.cpp b/src/scene/DeferredLoadingContext.cpp index e574fbd8..e3180a77 100644 --- a/src/scene/DeferredLoadingContext.cpp +++ b/src/scene/DeferredLoadingContext.cpp @@ -260,22 +260,21 @@ void flattenAttribute(Array &attribute, const Array &indices) attribute = WHEELS_MOV(flattened); } -void generateTangents(MeshData *meshData) +void generateTangents(MeshData &meshData) { - WHEELS_ASSERT(meshData != nullptr); - WHEELS_ASSERT(meshData->tangents.empty()); - WHEELS_ASSERT(meshData->positions.size() == meshData->normals.size()); - WHEELS_ASSERT(meshData->positions.size() == meshData->texCoord0s.size()); + WHEELS_ASSERT(meshData.tangents.empty()); + WHEELS_ASSERT(meshData.positions.size() == meshData.normals.size()); + WHEELS_ASSERT(meshData.positions.size() == meshData.texCoord0s.size()); // Flatten data first as instructed in the mikktspace header // TODO: tmp buffers here - const size_t flattenedVertexCount = meshData->indices.size(); - flattenAttribute(meshData->positions, meshData->indices); - flattenAttribute(meshData->normals, meshData->indices); - flattenAttribute(meshData->texCoord0s, meshData->indices); - meshData->indices.clear(); + const size_t flattenedVertexCount = meshData.indices.size(); + flattenAttribute(meshData.positions, meshData.indices); + flattenAttribute(meshData.normals, meshData.indices); + flattenAttribute(meshData.texCoord0s, meshData.indices); + meshData.indices.clear(); - meshData->tangents.resize(flattenedVertexCount); + meshData.tangents.resize(flattenedVertexCount); // Now we can generate the tangents SMikkTSpaceInterface sMikkTInterface{ @@ -289,7 +288,7 @@ void generateTangents(MeshData *meshData) const SMikkTSpaceContext mikkCtx{ .m_pInterface = &sMikkTInterface, - .m_pUserData = meshData, + .m_pUserData = &meshData, }; genTangSpaceDefault(&mikkCtx); @@ -297,22 +296,22 @@ void generateTangents(MeshData *meshData) // And now that we have tangents, we can re-generate indices const StaticArray vertexStreams{{ meshopt_Stream{ - .data = meshData->positions.data(), + .data = meshData.positions.data(), .size = sizeof(vec3), .stride = sizeof(vec3), }, meshopt_Stream{ - .data = meshData->normals.data(), + .data = meshData.normals.data(), .size = sizeof(vec3), .stride = sizeof(vec3), }, meshopt_Stream{ - .data = meshData->tangents.data(), + .data = meshData.tangents.data(), .size = sizeof(vec4), .stride = sizeof(vec4), }, meshopt_Stream{ - .data = meshData->texCoord0s.data(), + .data = meshData.texCoord0s.data(), .size = sizeof(vec2), .stride = sizeof(vec2), }, @@ -324,103 +323,100 @@ void generateTangents(MeshData *meshData) remapTable.data(), nullptr, flattenedVertexCount, flattenedVertexCount, vertexStreams.data(), vertexStreams.size()); - meshData->indices.resize(flattenedVertexCount); + meshData.indices.resize(flattenedVertexCount); meshopt_remapIndexBuffer( - meshData->indices.data(), nullptr, flattenedVertexCount, + meshData.indices.data(), nullptr, flattenedVertexCount, remapTable.data()); - remapVertexAttribute(meshData->positions, remapTable, uniqueVertexCount); - remapVertexAttribute(meshData->normals, remapTable, uniqueVertexCount); - remapVertexAttribute(meshData->tangents, remapTable, uniqueVertexCount); - remapVertexAttribute(meshData->texCoord0s, remapTable, uniqueVertexCount); + remapVertexAttribute(meshData.positions, remapTable, uniqueVertexCount); + remapVertexAttribute(meshData.normals, remapTable, uniqueVertexCount); + remapVertexAttribute(meshData.tangents, remapTable, uniqueVertexCount); + remapVertexAttribute(meshData.texCoord0s, remapTable, uniqueVertexCount); } void optimizeMeshData( - MeshData *meshData, MeshInfo *meshInfo, const char *meshName) + MeshData &meshData, MeshInfo &meshInfo, const char *meshName) { - WHEELS_ASSERT(meshData != nullptr); - - const size_t indexCount = meshData->indices.size(); - const size_t vertexCount = meshData->positions.size(); + const size_t indexCount = meshData.indices.size(); + const size_t vertexCount = meshData.positions.size(); Array tmpIndices{gAllocators.loadingWorker}; - tmpIndices.resize(meshData->indices.size()); + tmpIndices.resize(meshData.indices.size()); meshopt_optimizeVertexCache( - tmpIndices.data(), meshData->indices.data(), indexCount, vertexCount); + tmpIndices.data(), meshData.indices.data(), indexCount, vertexCount); const float vertexCacheDegradationThreshod = 1.00f; meshopt_optimizeOverdraw( - meshData->indices.data(), tmpIndices.data(), tmpIndices.size(), - &meshData->positions.data()[0].x, vertexCount, sizeof(vec3), + meshData.indices.data(), tmpIndices.data(), tmpIndices.size(), + &meshData.positions.data()[0].x, vertexCount, sizeof(vec3), vertexCacheDegradationThreshod); Array remapIndices{gAllocators.loadingWorker}; remapIndices.resize(vertexCount); const size_t uniqueVertexCount = meshopt_optimizeVertexFetchRemap( - remapIndices.data(), meshData->indices.data(), indexCount, vertexCount); + remapIndices.data(), meshData.indices.data(), indexCount, vertexCount); if (uniqueVertexCount < vertexCount) LOG_WARN("Mesh '%s' has unused vertices", meshName); // Reuse tmpIndices as it's not required after optimizeOverdraw meshopt_remapIndexBuffer( - tmpIndices.data(), meshData->indices.data(), indexCount, + tmpIndices.data(), meshData.indices.data(), indexCount, remapIndices.data()); - meshData->indices = WHEELS_MOV(tmpIndices); + meshData.indices = WHEELS_MOV(tmpIndices); - remapVertexAttribute(meshData->positions, remapIndices, uniqueVertexCount); - remapVertexAttribute(meshData->normals, remapIndices, uniqueVertexCount); - remapVertexAttribute(meshData->tangents, remapIndices, uniqueVertexCount); - remapVertexAttribute(meshData->texCoord0s, remapIndices, uniqueVertexCount); + remapVertexAttribute(meshData.positions, remapIndices, uniqueVertexCount); + remapVertexAttribute(meshData.normals, remapIndices, uniqueVertexCount); + remapVertexAttribute(meshData.tangents, remapIndices, uniqueVertexCount); + remapVertexAttribute(meshData.texCoord0s, remapIndices, uniqueVertexCount); - meshInfo->vertexCount = asserted_cast(uniqueVertexCount); + meshInfo.vertexCount = asserted_cast(uniqueVertexCount); } -void generateMeshlets(MeshData *meshData) +void generateMeshlets(MeshData &meshData) { - WHEELS_ASSERT(meshData != nullptr); - WHEELS_ASSERT(meshData->meshlets.empty()); - WHEELS_ASSERT(meshData->meshletVertices.empty()); - WHEELS_ASSERT(meshData->meshletTriangles.empty()); + WHEELS_ASSERT(meshData.meshlets.empty()); + WHEELS_ASSERT(meshData.meshletVertices.empty()); + WHEELS_ASSERT(meshData.meshletTriangles.empty()); const size_t maxMeshlets = meshopt_buildMeshletsBound( - meshData->indices.size(), sMaxMsVertices, sMaxMsTriangles); + meshData.indices.size(), sMaxMsVertices, sMaxMsTriangles); WHEELS_ASSERT(maxMeshlets > 0); - meshData->meshlets.resize(maxMeshlets); - meshData->meshletVertices.resize(maxMeshlets * sMaxMsVertices); - meshData->meshletTriangles.resize(maxMeshlets * sMaxMsTriangles * 3); + meshData.meshlets.resize(maxMeshlets); + meshData.meshletVertices.resize(maxMeshlets * sMaxMsVertices); + meshData.meshletTriangles.resize(maxMeshlets * sMaxMsTriangles * 3); const size_t meshletCount = meshopt_buildMeshlets( - meshData->meshlets.data(), meshData->meshletVertices.data(), - meshData->meshletTriangles.data(), meshData->indices.data(), - meshData->indices.size(), &meshData->positions[0].x, - meshData->positions.size(), sizeof(vec3), sMaxMsVertices, + meshData.meshlets.data(), meshData.meshletVertices.data(), + meshData.meshletTriangles.data(), meshData.indices.data(), + meshData.indices.size(), &meshData.positions[0].x, + meshData.positions.size(), sizeof(vec3), sMaxMsVertices, sMaxMsTriangles, sConeWeight); WHEELS_ASSERT(meshletCount > 0); // Need to trim the buffers now that we know the tight sizes - meshData->meshlets.resize(meshletCount); + meshData.meshlets.resize(meshletCount); - const meshopt_Meshlet &lastMeshlet = meshData->meshlets.back(); + const meshopt_Meshlet &lastMeshlet = meshData.meshlets.back(); - meshData->meshletVertices.resize( + meshData.meshletVertices.resize( lastMeshlet.vertex_offset + lastMeshlet.vertex_count); // Pad up to a u32 boundary const uint32_t trianglesSize = asserted_cast(wheels::aligned_offset( lastMeshlet.triangle_offset + lastMeshlet.triangle_count, sizeof(uint32_t))); - meshData->meshletTriangles.resize(asserted_cast(trianglesSize) * 3); + meshData.meshletTriangles.resize(asserted_cast(trianglesSize) * 3); - meshData->meshletBounds.reserve(meshData->meshlets.size()); - for (const meshopt_Meshlet &meshlet : meshData->meshlets) + meshData.meshletBounds.reserve(meshData.meshlets.size()); + for (const meshopt_Meshlet &meshlet : meshData.meshlets) { const meshopt_Bounds bounds = meshopt_computeMeshletBounds( - &meshData->meshletVertices[meshlet.vertex_offset], - &meshData->meshletTriangles[meshlet.triangle_offset], - meshlet.triangle_count, &meshData->positions[0].x, - meshData->positions.size(), sizeof(vec3)); - meshData->meshletBounds.push_back(MeshletBounds{ + &meshData.meshletVertices[meshlet.vertex_offset], + &meshData.meshletTriangles[meshlet.triangle_offset], + meshlet.triangle_count, &meshData.positions[0].x, + meshData.positions.size(), sizeof(vec3)); + meshData.meshletBounds.push_back(MeshletBounds{ .center = vec3{ bounds.center[0], @@ -799,10 +795,8 @@ void writeCache( std::filesystem::rename(cacheTmpPath, cachePath); } -void loadNextMesh(DeferredLoadingContext *ctx) +void loadNextMesh(DeferredLoadingContext &ctx) { - WHEELS_ASSERT(ctx != nullptr); - // Set up a custom allocator for meshopt, let's keep track of allocations // there too sMeshoptAllocator = &gAllocators.loadingWorker; @@ -812,12 +806,12 @@ void loadNextMesh(DeferredLoadingContext *ctx) { sMeshoptAllocator->deallocate(ptr); }; meshopt_setAllocator(meshoptAllocate, meshoptDeallocate); - const uint32_t meshIndex = ctx->workerLoadedMeshCount; - WHEELS_ASSERT(meshIndex < ctx->meshes.size()); + const uint32_t meshIndex = ctx.workerLoadedMeshCount; + WHEELS_ASSERT(meshIndex < ctx.meshes.size()); // Ctx member functions will use the command buffer - ctx->cb.reset(); - ctx->cb.begin(vk::CommandBufferBeginInfo{ + ctx.cb.reset(); + ctx.cb.begin(vk::CommandBufferBeginInfo{ .flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit, }); @@ -826,34 +820,34 @@ void loadNextMesh(DeferredLoadingContext *ctx) WHEELS_ASSERT(families.transferFamily.has_value()); const Pair &nextMesh = - ctx->meshes[meshIndex]; + ctx.meshes[meshIndex]; const InputGeometryMetadata &metadata = nextMesh.first; MeshInfo info = nextMesh.second; - const char *meshName = ctx->gltfData->meshes[metadata.sourceMeshIndex].name; - ctx->meshNames.emplace_back(gAllocators.loadingWorker, meshName); + const char *meshName = ctx.gltfData->meshes[metadata.sourceMeshIndex].name; + ctx.meshNames.emplace_back(gAllocators.loadingWorker, meshName); const std::filesystem::path cachePath = - getCachePath(ctx->sceneDir, meshIndex); - if (!cacheValid(cachePath, ctx->sceneWriteTime)) + getCachePath(ctx.sceneDir, meshIndex); + if (!cacheValid(cachePath, ctx.sceneWriteTime)) { MeshData meshData = getMeshData(metadata, info); if (meshData.tangents.empty() && !meshData.texCoord0s.empty()) { - generateTangents(&meshData); + generateTangents(meshData); info.vertexCount = asserted_cast(meshData.positions.size()); } - optimizeMeshData(&meshData, &info, meshName); + optimizeMeshData(meshData, info, meshName); - generateMeshlets(&meshData); + generateMeshlets(meshData); PackedMeshData packedMeshData = packMeshData(WHEELS_MOV(meshData)); writeCache( - ctx->sceneDir, ctx->sceneWriteTime, meshIndex, + ctx.sceneDir, ctx.sceneWriteTime, meshIndex, WHEELS_MOV(packedMeshData), info); } @@ -867,13 +861,13 @@ void loadNextMesh(DeferredLoadingContext *ctx) info.vertexCount = cacheHeader->vertexCount; info.meshletCount = cacheHeader->meshletCount; - const UploadedGeometryData uploadData = ctx->uploadGeometryData( - *cacheHeader, dataBlob, ctx->meshNames[meshIndex]); + const UploadedGeometryData uploadData = ctx.uploadGeometryData( + *cacheHeader, dataBlob, ctx.meshNames[meshIndex]); if (*families.graphicsFamily != *families.transferFamily) { const Buffer &buffer = - ctx->geometryBuffers[uploadData.metadata.bufferIndex]; + ctx.geometryBuffers[uploadData.metadata.bufferIndex]; // Transfer ownership of the newly pushed buffer range. // NOTE: This expects the subsequent ranges to be packed tightly. @@ -890,18 +884,18 @@ void loadNextMesh(DeferredLoadingContext *ctx) .offset = uploadData.byteOffset, .size = uploadData.byteCount, }; - ctx->cb.pipelineBarrier2(vk::DependencyInfo{ + ctx.cb.pipelineBarrier2(vk::DependencyInfo{ .bufferMemoryBarrierCount = 1, .pBufferMemoryBarriers = &releaseBarrier, }); } - ctx->cb.end(); + ctx.cb.end(); const vk::Queue transferQueue = gDevice.transferQueue(); const vk::SubmitInfo submitInfo{ .commandBufferCount = 1, - .pCommandBuffers = &ctx->cb, + .pCommandBuffers = &ctx.cb, }; checkSuccess( transferQueue.submit(1, &submitInfo, vk::Fence{}), @@ -909,41 +903,39 @@ void loadNextMesh(DeferredLoadingContext *ctx) // We could have multiple uploads in flight, but let's be simple for now transferQueue.waitIdle(); - ctx->workerLoadedMeshCount++; + ctx.workerLoadedMeshCount++; { - const std::lock_guard lock{ctx->loadedMeshesMutex}; + const std::lock_guard lock{ctx.loadedMeshesMutex}; - ctx->loadedMeshes.emplace_back(uploadData, info); + ctx.loadedMeshes.emplace_back(uploadData, info); } - if (ctx->workerLoadedMeshCount == ctx->meshes.size()) + if (ctx.workerLoadedMeshCount == ctx.meshes.size()) { - LOG_INFO("Mesh loading took %.2fs", ctx->meshTimer.getSeconds()); - ctx->textureTimer.reset(); + LOG_INFO("Mesh loading took %.2fs", ctx.meshTimer.getSeconds()); + ctx.textureTimer.reset(); } } -void loadNextTexture(DeferredLoadingContext *ctx) +void loadNextTexture(DeferredLoadingContext &ctx) { - WHEELS_ASSERT(ctx != nullptr); - - const uint32_t imageIndex = ctx->workerLoadedImageCount; - if (imageIndex == ctx->gltfData->images_count) + const uint32_t imageIndex = ctx.workerLoadedImageCount; + if (imageIndex == ctx.gltfData->images_count) { - LOG_INFO("Texture loading took %.2fs", ctx->textureTimer.getSeconds()); - ctx->interruptLoading = true; + LOG_INFO("Texture loading took %.2fs", ctx.textureTimer.getSeconds()); + ctx.interruptLoading = true; return; } - WHEELS_ASSERT(ctx->gltfData->images_count > imageIndex); - const cgltf_image &image = ctx->gltfData->images[imageIndex]; + WHEELS_ASSERT(ctx.gltfData->images_count > imageIndex); + const cgltf_image &image = ctx.gltfData->images[imageIndex]; if (image.uri == nullptr) throw std::runtime_error("Embedded glTF textures aren't supported. " "Scene should be glTF + bin + textures."); - ctx->cb.reset(); - ctx->cb.begin(vk::CommandBufferBeginInfo{ + ctx.cb.reset(); + ctx.cb.begin(vk::CommandBufferBeginInfo{ .flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit, }); @@ -951,22 +943,22 @@ void loadNextTexture(DeferredLoadingContext *ctx) gAllocators.loadingWorker, Allocators::sLoadingScratchSize}; TextureColorSpace colorSpace = TextureColorSpace::sRgb; - if (ctx->linearColorImages.contains(imageIndex)) + if (ctx.linearColorImages.contains(imageIndex)) { WHEELS_ASSERT( - !ctx->sRgbColorImages.contains(imageIndex) && + !ctx.sRgbColorImages.contains(imageIndex) && "Image should belong to exactly one colorspace set"); colorSpace = TextureColorSpace::Linear; } else WHEELS_ASSERT( - ctx->sRgbColorImages.contains(imageIndex) && + ctx.sRgbColorImages.contains(imageIndex) && "Image should belong to exactly one colorspace set"); Texture2D tex; tex.init( - ScopedScratch{scopeBacking}, ctx->sceneDir / image.uri, ctx->cb, - ctx->stagingBuffer, + ScopedScratch{scopeBacking}, ctx.sceneDir / image.uri, ctx.cb, + ctx.stagingBuffer, Texture2DOptions{ .generateMipMaps = true, .colorSpace = colorSpace, @@ -997,18 +989,18 @@ void loadNextTexture(DeferredLoadingContext *ctx) .layerCount = VK_REMAINING_ARRAY_LAYERS, }, }; - ctx->cb.pipelineBarrier2(vk::DependencyInfo{ + ctx.cb.pipelineBarrier2(vk::DependencyInfo{ .imageMemoryBarrierCount = 1, .pImageMemoryBarriers = &releaseBarrier, }); } - ctx->cb.end(); + ctx.cb.end(); const vk::Queue transferQueue = gDevice.transferQueue(); const vk::SubmitInfo submitInfo{ .commandBufferCount = 1, - .pCommandBuffers = &ctx->cb, + .pCommandBuffers = &ctx.cb, }; checkSuccess( transferQueue.submit(1, &submitInfo, vk::Fence{}), @@ -1016,12 +1008,12 @@ void loadNextTexture(DeferredLoadingContext *ctx) // We could have multiple uploads in flight, but let's be simple for now transferQueue.waitIdle(); - ctx->workerLoadedImageCount++; + ctx.workerLoadedImageCount++; { - const std::lock_guard lock{ctx->loadedTexturesMutex}; + const std::lock_guard lock{ctx.loadedTexturesMutex}; - ctx->loadedTextures.emplace_back(WHEELS_MOV(tex)); + ctx.loadedTextures.emplace_back(WHEELS_MOV(tex)); } } @@ -1037,7 +1029,7 @@ void loadingWorker(DeferredLoadingContext *ctx) { if (ctx->workerLoadedMeshCount < ctx->meshes.size()) { - loadNextMesh(ctx); + loadNextMesh(*ctx); // Only update for meshes as textures will always allocate a big // worst case tmp chunk for linear allocation @@ -1046,7 +1038,7 @@ void loadingWorker(DeferredLoadingContext *ctx) .allocated_byte_count_high_watermark; } else - loadNextTexture(ctx); + loadNextTexture(*ctx); } } @@ -1087,14 +1079,13 @@ DeferredLoadingContext::~DeferredLoadingContext() void DeferredLoadingContext::init( std::filesystem::path inSceneDir, - std::filesystem::file_time_type inSceneWriteTime, cgltf_data *inGltfData) + std::filesystem::file_time_type inSceneWriteTime, cgltf_data &inGltfData) { WHEELS_ASSERT(!initialized); - WHEELS_ASSERT(inGltfData != nullptr); sceneDir = WHEELS_MOV(inSceneDir); sceneWriteTime = inSceneWriteTime; - gltfData = inGltfData; + gltfData = &inGltfData; cb = gDevice.logical().allocateCommandBuffers(vk::CommandBufferAllocateInfo{ .commandPool = gDevice.transferPool(), .level = vk::CommandBufferLevel::ePrimary, diff --git a/src/scene/DeferredLoadingContext.hpp b/src/scene/DeferredLoadingContext.hpp index cbecd1d7..4cea47df 100644 --- a/src/scene/DeferredLoadingContext.hpp +++ b/src/scene/DeferredLoadingContext.hpp @@ -89,7 +89,7 @@ class DeferredLoadingContext void init( std::filesystem::path inSceneDir, std::filesystem::file_time_type inSceneWriteTime, - cgltf_data *inGltfData); + cgltf_data &inGltfData); void launch(); void kill(); diff --git a/src/scene/World.cpp b/src/scene/World.cpp index b45d0522..e5bed5ad 100644 --- a/src/scene/World.cpp +++ b/src/scene/World.cpp @@ -115,7 +115,7 @@ class World::Impl Impl &operator=(Impl &&other) = delete; void init( - ScopedScratch scopeAlloc, RingBuffer *constantsRing, + ScopedScratch scopeAlloc, RingBuffer &constantsRing, const std::filesystem::path &scene); void startFrame(); @@ -134,8 +134,8 @@ class World::Impl void updateAnimations(float timeS); // Has to be called after updateAnimations() void updateScene( - ScopedScratch scopeAlloc, CameraTransform *cameraTransform, - SceneStats *sceneStats); + ScopedScratch scopeAlloc, CameraTransform &cameraTransform, + SceneStats &sceneStats); void updateBuffers(ScopedScratch scopeAlloc); // Has to be called after updateBuffers(). Returns true if new BLASes were // added. @@ -190,12 +190,10 @@ World::Impl::~Impl() } void World::Impl::init( - ScopedScratch scopeAlloc, RingBuffer *constantsRing, + ScopedScratch scopeAlloc, RingBuffer &constantsRing, const std::filesystem::path &scene) { - WHEELS_ASSERT(constantsRing != nullptr); - - m_constantsRing = constantsRing; + m_constantsRing = &constantsRing; const uint32_t lightDataBufferSize = (DirectionalLight::sBufferByteSize + RingBuffer::sAlignment + @@ -209,7 +207,7 @@ void World::Impl::init( m_data.init( WHEELS_MOV(scopeAlloc), WorldData::RingBuffers{ - .constantsRing = constantsRing, + .constantsRing = &constantsRing, .lightDataRing = &m_lightDataRing, }, scene); @@ -352,12 +350,9 @@ void World::Impl::updateAnimations(float timeS) } void World::Impl::updateScene( - ScopedScratch scopeAlloc, CameraTransform *cameraTransform, - SceneStats *sceneStats) + ScopedScratch scopeAlloc, CameraTransform &cameraTransform, + SceneStats &sceneStats) { - WHEELS_ASSERT(cameraTransform != nullptr); - WHEELS_ASSERT(sceneStats != nullptr); - PROFILER_CPU_SCOPE("World::updateScene"); Scene &scene = currentScene(); @@ -413,13 +408,13 @@ void World::Impl::updateScene( if (node.camera.has_value() && *node.camera == m_currentCamera) { - cameraTransform->eye = + cameraTransform.eye = vec3{modelToWorld4x4 * vec4{0.f, 0.f, 0.f, 1.f}}; // TODO: Halfway from camera to scene bb end if inside // bb / halfway of bb if outside of bb? - cameraTransform->target = + cameraTransform.target = vec3{modelToWorld4x4 * vec4{0.f, 0.f, -1.f, 1.f}}; - cameraTransform->up = + cameraTransform.up = mat3{modelToWorld4x4} * vec3{0.f, 1.f, 0.f}; } @@ -455,9 +450,9 @@ void World::Impl::updateScene( } parentTransforms.emplace_back(modelToWorld4x4); - sceneStats->totalNodeCount++; + sceneStats.totalNodeCount++; if (node.dynamicTransform) - sceneStats->animatedNodeCount++; + sceneStats.animatedNodeCount++; } } } @@ -952,7 +947,7 @@ World::World() noexcept World::~World() = default; void World::init( - wheels::ScopedScratch scopeAlloc, RingBuffer *constantsRing, + wheels::ScopedScratch scopeAlloc, RingBuffer &constantsRing, const std::filesystem::path &scene) { WHEELS_ASSERT(!m_initialized); @@ -1055,8 +1050,8 @@ void World::updateAnimations(float timeS) } void World::updateScene( - ScopedScratch scopeAlloc, CameraTransform *cameraTransform, - SceneStats *sceneStats) + ScopedScratch scopeAlloc, CameraTransform &cameraTransform, + SceneStats &sceneStats) { WHEELS_ASSERT(m_initialized); m_impl->updateScene(WHEELS_MOV(scopeAlloc), cameraTransform, sceneStats); diff --git a/src/scene/World.hpp b/src/scene/World.hpp index 4354e93a..b8ca4084 100644 --- a/src/scene/World.hpp +++ b/src/scene/World.hpp @@ -23,7 +23,7 @@ class World World &operator=(World &&other) = delete; void init( - wheels::ScopedScratch scopeAlloc, RingBuffer *constantsRing, + wheels::ScopedScratch scopeAlloc, RingBuffer &constantsRing, const std::filesystem::path &scene); void startFrame(); @@ -52,8 +52,8 @@ class World void updateAnimations(float timeS); // Has to be called after updateAnimations() void updateScene( - wheels::ScopedScratch scopeAlloc, CameraTransform *cameraTransform, - SceneStats *sceneStats); + wheels::ScopedScratch scopeAlloc, CameraTransform &cameraTransform, + SceneStats &sceneStats); void updateBuffers(wheels::ScopedScratch scopeAlloc); // Has to be called after updateBuffers(). Returns true if new BLASes were // added. diff --git a/src/scene/WorldData.cpp b/src/scene/WorldData.cpp index 44df7149..86fb0da4 100644 --- a/src/scene/WorldData.cpp +++ b/src/scene/WorldData.cpp @@ -431,7 +431,7 @@ void WorldData::init( // Deferred context is responsible for freeing gltfData. Dispatch happens // after other loading finishes and WorldData will then always go through // the deferred context when it needs gltfData. - m_deferredLoadingContext->init(m_sceneDir, sourceWriteTime, gltfData); + m_deferredLoadingContext->init(m_sceneDir, sourceWriteTime, *gltfData); const auto &tl = [&](const char *stage, std::function const &fn) { diff --git a/src/utils/Profiler.cpp b/src/utils/Profiler.cpp index afd01a3b..1bd5a003 100644 --- a/src/utils/Profiler.cpp +++ b/src/utils/Profiler.cpp @@ -226,9 +226,9 @@ Array GpuFrameProfiler::getData(Allocator &alloc) return ret; } -CpuFrameProfiler::Scope::Scope(std::chrono::nanoseconds *output) +CpuFrameProfiler::Scope::Scope(std::chrono::nanoseconds &output) : m_start{std::chrono::high_resolution_clock::now()} -, m_output{output} +, m_output{&output} { } @@ -282,7 +282,7 @@ void CpuFrameProfiler::startFrame() m_queryScopeIndices.push_back(index); m_nanos.emplace_back(); - return Scope{&m_nanos.back()}; + return Scope{m_nanos.back()}; } Array CpuFrameProfiler::getTimes(Allocator &alloc) diff --git a/src/utils/Profiler.hpp b/src/utils/Profiler.hpp index 7a02aba7..d79f3759 100644 --- a/src/utils/Profiler.hpp +++ b/src/utils/Profiler.hpp @@ -112,7 +112,7 @@ class CpuFrameProfiler Scope &operator=(Scope &&) = delete; protected: - Scope(std::chrono::nanoseconds *output); + Scope(std::chrono::nanoseconds &output); private: std::chrono::time_point m_start;