22// This file is part of the "Nabla Engine".
33// For conditions of distribution and use, see copyright notice in nabla.h
44
5+
56#include " nbl/examples/examples.hpp"
7+ #include " nbl/examples/common/CCachedOwenScrambledSequence.hpp"
68#include " nbl/this_example/transform.hpp"
9+
710#include " nbl/ext/FullScreenTriangle/FullScreenTriangle.h"
11+
812#include " nbl/builtin/hlsl/math/thin_lens_projection.hlsl"
9- #include " nbl/this_example/common.hpp"
1013#include " nbl/builtin/hlsl/colorspace/encodeCIEXYZ.hlsl"
1114#include " nbl/builtin/hlsl/sampling/quantized_sequence.hlsl"
12- #include " nbl/examples/common/ScrambleSequence.hpp"
15+
16+ #include " nbl/this_example/common.hpp"
1317#include " app_resources/hlsl/render_common.hlsl"
1418#include " app_resources/hlsl/render_rwmc_common.hlsl"
1519#include " app_resources/hlsl/resolve_common.hlsl"
1620
21+ #include < future>
22+
23+
1724using namespace nbl ;
1825using namespace core ;
1926using namespace hlsl ;
@@ -42,7 +49,6 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
4249 constexpr static inline uint32_t2 WindowDimensions = { 1280 , 720 };
4350 constexpr static inline uint32_t MaxFramesInFlight = 5 ;
4451 static inline std::string DefaultImagePathsFile = " envmap/envmap_0.exr" ;
45- static inline std::string OwenSamplerFilePath = " owen_sampler_buffer.bin" ;
4652 static inline std::string PTHLSLShaderPath = " app_resources/hlsl/render.comp.hlsl" ;
4753 static inline std::array<std::string, E_LIGHT_GEOMETRY::ELG_COUNT> PTHLSLShaderVariants = {
4854 " SPHERE_LIGHT" ,
@@ -123,6 +129,16 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
123129 if (!m_semaphore)
124130 return logFail (" Failed to create semaphore!" );
125131 }
132+
133+ auto sequenceFuture = std::async (std::launch::async,[this ]()->auto
134+ {
135+ return CCachedOwenScrambledSequence::create ({
136+ .cachePath = (sharedOutputCWD/CCachedOwenScrambledSequence::SCreationParams::DefaultFilename).string (),
137+ .assMan = m_assetMgr.get (),
138+ .header = {.maxSamplesLog2 = MaxSamplesLog2,.maxDimensions = MaxBufferDimensions}
139+ });
140+ }
141+ );
126142
127143 // Create renderpass and init surface
128144 nbl::video::IGPURenderpass* renderpass;
@@ -739,21 +755,6 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
739755 m_cascadeView->setObjectDebugName (" Cascade View" );
740756 }
741757
742- // create sequence buffer
743- {
744- ScrambleSequence::SCreationParams params = {
745- .queue = getGraphicsQueue (),
746- .utilities = smart_refctd_ptr (m_utils),
747- .system = smart_refctd_ptr (m_system),
748- .localOutputCWD = localOutputCWD,
749- .sharedOutputCWD = sharedOutputCWD,
750- .owenSamplerCachePath = OwenSamplerFilePath,
751- .MaxBufferDimensions = MaxBufferDimensions,
752- .MaxSamplesBuffer = MaxSamplesBuffer,
753- };
754- m_scrambleSequence = ScrambleSequence::create (params);
755- }
756-
757758 // Update Descriptors
758759 {
759760 ISampler::SParams samplerParams0 = {
@@ -1009,6 +1010,15 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
10091010 guiControlled.rwmcParams .base = 8 .0f ;
10101011 guiControlled.rwmcParams .minReliableLuma = 1 .0f ;
10111012 guiControlled.rwmcParams .kappa = 5 .0f ;
1013+
1014+ // do this as late as possible
1015+ {
1016+ auto sequence = sequenceFuture.get ();
1017+ auto * const seqBufferCPU = sequence->getBuffer ();
1018+ m_utils->createFilledDeviceLocalBufferOnDedMem (SIntendedSubmitInfo{.queue =getGraphicsQueue ()},IGPUBuffer::SCreationParams{seqBufferCPU->getCreationParams ()},seqBufferCPU->getPointer ()).move_into (m_sequenceBuffer);
1019+ m_sequenceBuffer->setObjectDebugName (" Low Discrepancy Sequence" );
1020+ }
1021+
10121022 return true ;
10131023 }
10141024
@@ -1087,7 +1097,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
10871097 rwmcPushConstants.renderPushConstants .generalPurposeLightMatrix = hlsl::float32_t3x4 (transpose (m_lightModelMatrix));
10881098 rwmcPushConstants.renderPushConstants .depth = guiControlled.depth ;
10891099 rwmcPushConstants.renderPushConstants .sampleCount = guiControlled.rwmcParams .sampleCount = guiControlled.spp ;
1090- rwmcPushConstants.renderPushConstants .pSampleSequence = m_scrambleSequence-> buffer ->getDeviceAddress ();
1100+ rwmcPushConstants.renderPushConstants .pSampleSequence = m_sequenceBuffer ->getDeviceAddress ();
10911101 rwmcPushConstants.splattingParameters = rwmc::SPackedSplattingParameters::create (guiControlled.rwmcParams .base , guiControlled.rwmcParams .start , CascadeCount);
10921102 }
10931103 else
@@ -1096,7 +1106,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
10961106 pc.generalPurposeLightMatrix = hlsl::float32_t3x4 (transpose (m_lightModelMatrix));
10971107 pc.sampleCount = guiControlled.spp ;
10981108 pc.depth = guiControlled.depth ;
1099- pc.pSampleSequence = m_scrambleSequence-> buffer ->getDeviceAddress ();
1109+ pc.pSampleSequence = m_sequenceBuffer ->getDeviceAddress ();
11001110 }
11011111 };
11021112 updatePathtracerPushConstants ();
@@ -1485,8 +1495,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
14851495
14861496 // pathtracer resources
14871497 smart_refctd_ptr<IGPUImageView> m_envMapView, m_scrambleView;
1488- // smart_refctd_ptr<IGPUBuffer> m_sequenceBuffer;
1489- smart_refctd_ptr<ScrambleSequence> m_scrambleSequence;
1498+ smart_refctd_ptr<IGPUBuffer> m_sequenceBuffer;
14901499 smart_refctd_ptr<IGPUImageView> m_outImgView;
14911500 smart_refctd_ptr<IGPUImageView> m_cascadeView;
14921501
0 commit comments