@@ -858,16 +858,19 @@ void RendererBackend::Begin(const std::shared_ptr<RendererFrame>& frame, bool cl
858858// projection * glm::lookAt(lightPos, lightPos + glm::vec3( 0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))
859859// };
860860// }
861- static std::vector<glm::mat4> GenerateLightViewTransforms (const glm::vec3 & lightPos) {
862- return std::vector<glm::mat4> {
861+ static std::vector<glm::mat4, StackBasedPoolAllocator<glm::mat4>> GenerateLightViewTransforms (const glm::vec3 & lightPos, const UnsafePtr<StackAllocator>& allocator ) {
862+ return std::vector<glm::mat4, StackBasedPoolAllocator<glm::mat4>>( {
863863 // pos pos + dir up
864- glm::lookAt (lightPos, lightPos + glm::vec3 ( 1 .0f , 0 .0f , 0 .0f ), glm::vec3 (0 .0f , -1 .0f , 0 .0f )),
864+ glm::lookAt (lightPos, lightPos + glm::vec3 (1 .0f , 0 .0f , 0 .0f ), glm::vec3 (0 .0f , -1 .0f , 0 .0f )),
865865 glm::lookAt (lightPos, lightPos + glm::vec3 (-1 .0f , 0 .0f , 0 .0f ), glm::vec3 (0 .0f , -1 .0f , 0 .0f )),
866- glm::lookAt (lightPos, lightPos + glm::vec3 ( 0 .0f , 1 .0f , 0 .0f ), glm::vec3 (0 .0f , 0 .0f , 1 .0f )),
867- glm::lookAt (lightPos, lightPos + glm::vec3 ( 0 .0f , -1 .0f , 0 .0f ), glm::vec3 (0 .0f , 0 .0f , -1 .0f )),
868- glm::lookAt (lightPos, lightPos + glm::vec3 ( 0 .0f , 0 .0f , 1 .0f ), glm::vec3 (0 .0f , -1 .0f , 0 .0f )),
869- glm::lookAt (lightPos, lightPos + glm::vec3 ( 0 .0f , 0 .0f , -1 .0f ), glm::vec3 (0 .0f , -1 .0f , 0 .0f ))
870- };
866+ glm::lookAt (lightPos, lightPos + glm::vec3 (0 .0f , 1 .0f , 0 .0f ), glm::vec3 (0 .0f , 0 .0f , 1 .0f )),
867+ glm::lookAt (lightPos, lightPos + glm::vec3 (0 .0f , -1 .0f , 0 .0f ), glm::vec3 (0 .0f , 0 .0f , -1 .0f )),
868+ glm::lookAt (lightPos, lightPos + glm::vec3 (0 .0f , 0 .0f , 1 .0f ), glm::vec3 (0 .0f , -1 .0f , 0 .0f )),
869+ glm::lookAt (lightPos, lightPos + glm::vec3 (0 .0f , 0 .0f , -1 .0f ), glm::vec3 (0 .0f , -1 .0f , 0 .0f ))
870+ },
871+
872+ StackBasedPoolAllocator<glm::mat4>(allocator)
873+ );
871874}
872875
873876void RendererBackend::BindShader_ (Pipeline * s) {
@@ -1266,7 +1269,7 @@ void RendererBackend::RenderAtmosphericShadowing_() {
12661269 glEnable (GL_DEPTH_TEST);
12671270}
12681271
1269- void RendererBackend::InitVplFrameData_ (const std::vector<std::pair<LightPtr, double >>& perVPLDistToViewer) {
1272+ void RendererBackend::InitVplFrameData_ (const std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator >& perVPLDistToViewer) {
12701273 std::vector<GpuVplData> vplData (perVPLDistToViewer.size ());
12711274 for (size_t i = 0 ; i < perVPLDistToViewer.size (); ++i) {
12721275 VirtualPointLight * point = (VirtualPointLight *)perVPLDistToViewer[i].first .get ();
@@ -1279,10 +1282,10 @@ void RendererBackend::InitVplFrameData_(const std::vector<std::pair<LightPtr, do
12791282 state_.vpls .vplData .CopyDataToBuffer (0 , sizeof (GpuVplData) * vplData.size (), (const void *)vplData.data ());
12801283}
12811284
1282- void RendererBackend::UpdatePointLights_ (std::vector<std::pair<LightPtr, double >>& perLightDistToViewer,
1283- std::vector<std::pair<LightPtr, double >>& perLightShadowCastingDistToViewer,
1284- std::vector<std::pair<LightPtr, double >>& perVPLDistToViewer,
1285- std::vector<int >& visibleVplIndices) {
1285+ void RendererBackend::UpdatePointLights_ (std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator >& perLightDistToViewer,
1286+ std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator >& perLightShadowCastingDistToViewer,
1287+ std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator >& perVPLDistToViewer,
1288+ std::vector<int , StackBasedPoolAllocator< int > >& visibleVplIndices) {
12861289 const Camera& c = *frame_->camera ;
12871290
12881291 const bool worldLightEnabled = frame_->csc .worldLight ->GetEnabled ();
@@ -1400,7 +1403,7 @@ void RendererBackend::UpdatePointLights_(std::vector<std::pair<LightPtr, double>
14001403 // glClear(GL_DEPTH_BUFFER_BIT);
14011404
14021405 Pipeline * shader = light->IsVirtualLight () ? state_.vplShadows .get () : state_.shadows .get ();
1403- auto transforms = GenerateLightViewTransforms (point->GetPosition ());
1406+ auto transforms = GenerateLightViewTransforms (point->GetPosition (), frame_-> perFrameScratchMemory );
14041407
14051408 for (size_t i = 0 ; i < transforms.size (); ++i) {
14061409 const glm::mat4 projectionView = lightPerspective * transforms[i];
@@ -1455,8 +1458,8 @@ void RendererBackend::UpdatePointLights_(std::vector<std::pair<LightPtr, double>
14551458}
14561459
14571460void RendererBackend::PerformVirtualPointLightCullingStage1_ (
1458- std::vector<std::pair<LightPtr, double >>& perVPLDistToViewer,
1459- std::vector<int >& visibleVplIndices) {
1461+ std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator >& perVPLDistToViewer,
1462+ std::vector<int , StackBasedPoolAllocator< int > >& visibleVplIndices) {
14601463
14611464 if (perVPLDistToViewer.size () == 0 ) return ;
14621465
@@ -1538,7 +1541,7 @@ void RendererBackend::PerformVirtualPointLightCullingStage1_(
15381541// const std::vector<std::pair<LightPtr, double>>& perVPLDistToViewer,
15391542// const std::vector<int>& visibleVplIndices) {
15401543void RendererBackend::PerformVirtualPointLightCullingStage2_ (
1541- const std::vector<std::pair<LightPtr, double >>& perVPLDistToViewer) {
1544+ const std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator >& perVPLDistToViewer) {
15421545
15431546 // int totalVisible = *(int *)state_.vpls.vplNumVisible.MapMemory();
15441547 // state_.vpls.vplNumVisible.UnmapMemory();
@@ -1556,9 +1559,9 @@ void RendererBackend::PerformVirtualPointLightCullingStage2_(
15561559 }
15571560
15581561 // Pack data into system memory
1559- std::vector<GpuTextureHandle> diffuseHandles;
1562+ std::vector<GpuTextureHandle, StackBasedPoolAllocator<GpuTextureHandle>> diffuseHandles (StackBasedPoolAllocator<GpuTextureHandle>(frame_-> perFrameScratchMemory )) ;
15601563 diffuseHandles.reserve (totalVisible);
1561- std::vector<GpuAtlasEntry> shadowDiffuseIndices;
1564+ std::vector<GpuAtlasEntry, StackBasedPoolAllocator<GpuAtlasEntry>> shadowDiffuseIndices (StackBasedPoolAllocator<GpuAtlasEntry>(frame_-> perFrameScratchMemory )) ;
15621565 shadowDiffuseIndices.reserve (totalVisible);
15631566 for (size_t i = 0 ; i < totalVisible; ++i) {
15641567 const int index = visibleVplIndices[i];
@@ -1683,7 +1686,7 @@ void RendererBackend::PerformVirtualPointLightCullingStage2_(
16831686 // _state.vpls.vplNumVisible.UnmapMemory();
16841687}
16851688
1686- void RendererBackend::ComputeVirtualPointLightGlobalIllumination_ (const std::vector<std::pair<LightPtr, double >>& perVPLDistToViewer, const double deltaSeconds) {
1689+ void RendererBackend::ComputeVirtualPointLightGlobalIllumination_ (const std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator >& perVPLDistToViewer, const double deltaSeconds) {
16871690 if (perVPLDistToViewer.size () == 0 ) return ;
16881691
16891692 // auto space = LogSpace<float>(1, 512, 30);
@@ -1745,10 +1748,13 @@ void RendererBackend::ComputeVirtualPointLightGlobalIllumination_(const std::vec
17451748 UnbindShader_ ();
17461749 state_.vpls .vplGIFbo .Unbind ();
17471750
1748- std::vector<FrameBuffer *> buffers = {
1751+ std::vector<FrameBuffer*, StackBasedPoolAllocator<FrameBuffer*>> buffers ( {
17491752 &state_.vpls .vplGIDenoisedFbo1 ,
17501753 &state_.vpls .vplGIDenoisedFbo2
1751- };
1754+ },
1755+
1756+ StackBasedPoolAllocator<FrameBuffer*>(frame_->perFrameScratchMemory )
1757+ );
17521758
17531759 Texture indirectIllum = state_.vpls .vplGIFbo .GetColorAttachments ()[0 ];
17541760 Texture indirectShadows = state_.vpls .vplGIFbo .GetColorAttachments ()[1 ];
@@ -1829,11 +1835,11 @@ void RendererBackend::RenderScene(const double deltaSeconds) {
18291835 RenderCSMDepth_ ();
18301836 }
18311837
1832- std::vector<std::pair<LightPtr, double >>& perLightDistToViewer = perLightDistToViewer_ ;
1838+ std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator> perLightDistToViewer ( LightDistancePairAllocator (frame_-> perFrameScratchMemory )) ;
18331839 // // This one is just for shadow-casting lights
1834- std::vector<std::pair<LightPtr, double >>& perLightShadowCastingDistToViewer = perLightShadowCastingDistToViewer_ ;
1835- std::vector<std::pair<LightPtr, double >>& perVPLDistToViewer = perVPLDistToViewer_ ;
1836- std::vector<int >& visibleVplIndices = visibleVplIndices_ ;
1840+ std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator> perLightShadowCastingDistToViewer ( LightDistancePairAllocator (frame_-> perFrameScratchMemory )) ;
1841+ std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator> perVPLDistToViewer ( LightDistancePairAllocator (frame_-> perFrameScratchMemory )) ;
1842+ std::vector<int , StackBasedPoolAllocator< int >> visibleVplIndices (StackBasedPoolAllocator< int >(frame_-> perFrameScratchMemory )) ;
18371843
18381844 // Perform point light pass
18391845 UpdatePointLights_ (perLightDistToViewer, perLightShadowCastingDistToViewer, perVPLDistToViewer, visibleVplIndices);
@@ -2008,7 +2014,10 @@ void RendererBackend::PerformBloomPostFx_() {
20082014 if (!frame_->settings .bloomEnabled ) return ;
20092015
20102016 // We use this so that we can avoid a final copy between the downsample and blurring stages
2011- std::vector<PostFXBuffer> finalizedPostFxFrames (state_.numDownsampleIterations + state_.numUpsampleIterations );
2017+ std::vector<PostFXBuffer, StackBasedPoolAllocator<PostFXBuffer>> finalizedPostFxFrames (
2018+ state_.numDownsampleIterations + state_.numUpsampleIterations ,
2019+ StackBasedPoolAllocator<PostFXBuffer>(frame_->perFrameScratchMemory )
2020+ );
20122021
20132022 Pipeline* bloom = state_.bloom .get ();
20142023 BindShader_ (bloom);
@@ -2322,7 +2331,7 @@ void RendererBackend::InitCoreCSMData_(Pipeline * s) {
23222331 }
23232332}
23242333
2325- void RendererBackend::InitLights_ (Pipeline * s, const std::vector<std::pair<LightPtr, double >> & lights, const size_t maxShadowLights) {
2334+ void RendererBackend::InitLights_ (Pipeline * s, const std::vector<std::pair<LightPtr, double >, LightDistancePairAllocator > & lights, const size_t maxShadowLights) {
23262335 // Set up point lights
23272336
23282337 // Make sure everything is set to some sort of default to prevent shader crashes or huge performance drops
@@ -2368,9 +2377,10 @@ void RendererBackend::InitLights_(Pipeline * s, const std::vector<std::pair<Ligh
23682377 // ++lightIndex;
23692378 // }
23702379
2371- std::vector<GpuPointLight> gpuLights;
2372- std::vector<GpuAtlasEntry> gpuShadowCubeMaps;
2373- std::vector<GpuPointLight> gpuShadowLights;
2380+ auto allocator = frame_->perFrameScratchMemory ;
2381+ auto gpuLights = std::vector<GpuPointLight, StackBasedPoolAllocator<GpuPointLight>>(StackBasedPoolAllocator<GpuPointLight>(allocator));
2382+ auto gpuShadowCubeMaps = std::vector<GpuAtlasEntry, StackBasedPoolAllocator<GpuAtlasEntry>>(StackBasedPoolAllocator<GpuAtlasEntry>(allocator));
2383+ auto gpuShadowLights = std::vector<GpuPointLight, StackBasedPoolAllocator<GpuPointLight>>(StackBasedPoolAllocator<GpuPointLight>(allocator));
23742384 gpuLights.reserve (lights.size ());
23752385 gpuShadowCubeMaps.reserve (maxShadowLights);
23762386 gpuShadowLights.reserve (maxShadowLights);
0 commit comments