@@ -20,14 +20,14 @@ constexpr uint32_t kOptiXPixelSize = sizeof(uint16_t)*3u;
20
20
21
21
Renderer::Renderer (IVideoDriver* _driver, IAssetManager* _assetManager, irr::scene::ISceneManager* _smgr, core::smart_refctd_ptr<video::IGPUDescriptorSet>&& globalBackendDataDS, bool useDenoiser) :
22
22
m_useDenoiser(useDenoiser), m_driver(_driver), m_smgr(_smgr), m_assetManager(_assetManager), m_rrManager(ext::RadeonRays::Manager::create(m_driver)),
23
- m_sceneBound(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX), baseEnvColor(), /* m_renderSize{0u,0u}, */ m_rightHanded(false ),
24
- m_globalBackendDataDS(std::move(globalBackendDataDS)), rrShapeCache(),
23
+ m_sceneBound(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX), /* m_renderSize{0u,0u}, */ m_rightHanded(false ),
24
+ m_globalBackendDataDS(std::move(globalBackendDataDS)), // TODO: review this member
25
+ rrShapeCache(),
25
26
#if TODO
26
- m_raygenProgram (0u ), m_compostProgram(0u ),
27
27
m_raygenWorkGroups{0u ,0u }, m_resolveWorkGroups{0u ,0u },
28
28
m_rayBuffer (), m_intersectionBuffer(), m_rayCountBuffer(),
29
29
m_rayBufferAsRR(nullptr ,nullptr ), m_intersectionBufferAsRR(nullptr ,nullptr ), m_rayCountBufferAsRR(nullptr ,nullptr ),
30
- nodes(), rrInstances(),
30
+ rrInstances(),
31
31
#endif
32
32
m_lightCount (0u ),
33
33
m_visibilityBufferAttachments{nullptr }, m_maxSamples(0u ), m_samplesPerPixelPerDispatch(0u ), m_rayCountPerDispatch(0u ), m_framesDone(0u ), m_samplesComputedPerPixel(0u ),
@@ -36,6 +36,17 @@ Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, irr::sce
36
36
,m_cudaStream(nullptr )
37
37
#endif
38
38
{
39
+ {
40
+ video::IGPUDescriptorSetLayout::SBinding binding;
41
+ binding.binding = 0u ;
42
+ binding.type = asset::EDT_STORAGE_BUFFER;
43
+ binding.count = 1u ;
44
+ binding.stageFlags = ISpecializedShader::ESS_VERTEX;
45
+ binding.samplers = nullptr ;
46
+ m_perCameraRasterDSLayout = m_driver->createGPUDescriptorSetLayout (&binding,&binding+1u );
47
+ m_visibilityBufferFillPipelineLayout = m_driver->createGPUPipelineLayout (nullptr ,nullptr ,nullptr ,nullptr ,core::smart_refctd_ptr (m_perCameraRasterDSLayout),nullptr );
48
+ }
49
+
39
50
#ifdef _IRR_BUILD_OPTIX_
40
51
while (useDenoiser)
41
52
{
@@ -295,6 +306,7 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
295
306
InitializationData retval;
296
307
297
308
auto contents = meshes.getContents ();
309
+ uint32_t instanceCount = 0u ;
298
310
for (auto & cpumesh_ : contents)
299
311
{
300
312
auto cpumesh = static_cast <asset::ICPUMesh*>(cpumesh_.get ());
@@ -315,6 +327,35 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
315
327
{
316
328
// TODO: get rid of `getMeshBuffer` and `getMeshBufferCount`, just return a range as `getMeshBuffers`
317
329
auto cpumb = cpumesh->getMeshBuffer (i);
330
+
331
+ // set up Visibility Buffer pipelines
332
+ {
333
+ auto oldPipeline = cpumb->getPipeline ();
334
+ auto vertexInputParams = oldPipeline->getVertexInputParams ();
335
+ const bool frontFaceIsCCW = oldPipeline->getRasterizationParams ().frontFaceIsCCW ;
336
+ auto found = retval.m_visibilityBufferFillPipelines .find (InitializationData::VisibilityBufferPipelineKey{vertexInputParams,frontFaceIsCCW});
337
+
338
+ core::smart_refctd_ptr<video::IGPURenderpassIndependentPipeline> newPipeline;
339
+ if (found!=retval.m_visibilityBufferFillPipelines .end ())
340
+ newPipeline = core::smart_refctd_ptr (found->second );
341
+ else
342
+ {
343
+ video::IGPUSpecializedShader* shaders[] = {m_visibilityBufferFillShaders[0 ].get (),m_visibilityBufferFillShaders[1 ].get ()};
344
+ vertexInputParams.enabledAttribFlags &= 0b1101u ;
345
+ asset::SRasterizationParams rasterParams;
346
+ rasterParams.frontFaceIsCCW = frontFaceIsCCW;
347
+ newPipeline = m_driver->createGPURenderpassIndependentPipeline (
348
+ nullptr ,core::smart_refctd_ptr (m_visibilityBufferFillPipelineLayout),shaders,shaders+2u ,
349
+ vertexInputParams,asset::SBlendParams{},asset::SPrimitiveAssemblyParams{},rasterParams
350
+ );
351
+ retval.m_visibilityBufferFillPipelines .emplace (InitializationData::VisibilityBufferPipelineKey{vertexInputParams,frontFaceIsCCW},std::move (newPipeline));
352
+ }
353
+ // cpumb->setPipeline(std::move(newPipeline));
354
+ }
355
+ cpumb->setBaseInstance (instanceCount);
356
+ instanceCount += 1u ;
357
+
358
+ // set up BVH
318
359
m_rrManager->makeRRShapes (rrShapeCache, &cpumb, (&cpumb)+1 );
319
360
}
320
361
@@ -335,6 +376,23 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
335
376
retval.lightPDF .push_back (weight);
336
377
}
337
378
}
379
+
380
+ m_perCameraRasterDS = m_driver->createGPUDescriptorSet (core::smart_refctd_ptr (m_perCameraRasterDSLayout));
381
+ {
382
+ IGPUDescriptorSet::SDescriptorInfo info;
383
+ info.buffer .size = instanceCount*sizeof (InstanceDataPerCamera);
384
+ info.buffer .offset = 0u ;
385
+ info.desc = m_driver->createDeviceLocalGPUBufferOnDedMem (info.buffer .size );
386
+ IGPUDescriptorSet::SWriteDescriptorSet write;
387
+ write.dstSet = m_perCameraRasterDS.get ();
388
+ write.binding = 0u ;
389
+ write.arrayElement = 0u ;
390
+ write.count = 1u ;
391
+ write.descriptorType = EDT_STORAGE_BUFFER;
392
+ write.info = &info;
393
+ m_driver->updateDescriptorSets (1u ,&write,0u ,nullptr );
394
+ }
395
+
338
396
return retval;
339
397
}
340
398
@@ -371,7 +429,7 @@ void Renderer::initSceneNonAreaLights(Renderer::InitializationData& initData)
371
429
}
372
430
}
373
431
374
- void Renderer::finalizeSceneLights (Renderer::InitializationData& initData)
432
+ void Renderer::finalizeScene (Renderer::InitializationData& initData)
375
433
{
376
434
if (initData.lights .empty ())
377
435
return ;
@@ -476,7 +534,7 @@ void Renderer::init(const SAssetBundle& meshes,
476
534
assert (globalMeta);
477
535
478
536
initSceneNonAreaLights (initData);
479
- finalizeSceneLights (initData);
537
+ finalizeScene (initData);
480
538
{
481
539
#if TODO
482
540
auto gpumeshes = m_driver->getGPUObjectsFromAssets <ICPUMesh>(contents.first , contents.second );
@@ -581,7 +639,6 @@ void Renderer::init(const SAssetBundle& meshes,
581
639
m_raygenLayout = createLayoutRaygen ();
582
640
m_compostLayout = createLayoutCompost ();
583
641
584
- auto rr_includes = m_rrManager->getRadeonRaysGLSLIncludes ();
585
642
{
586
643
std::string glsl = " raygen.comp" +
587
644
globalMeta->materialCompilerGLSL_declarations +
@@ -740,9 +797,6 @@ void Renderer::deinit()
740
797
m_raygenWorkGroups[0 ] = m_raygenWorkGroups[1 ] = 0u ;
741
798
m_resolveWorkGroups[0 ] = m_resolveWorkGroups[1 ] = 0u ;
742
799
743
- for (auto & node : nodes)
744
- node->remove ();
745
- nodes.clear ();
746
800
m_rrManager->detachInstances (rrInstances.begin (),rrInstances.end ());
747
801
m_rrManager->deleteInstances (rrInstances.begin (),rrInstances.end ());
748
802
rrInstances.clear ();
@@ -783,6 +837,8 @@ void Renderer::deinit()
783
837
m_rrManager->deleteShapes (rrShapeCache.begin (), rrShapeCache.end ());
784
838
rrShapeCache.clear ();
785
839
840
+ m_perCameraRasterDS = nullptr ;
841
+
786
842
m_globalBackendDataDS = nullptr ;
787
843
m_rightHanded = false ;
788
844
m_renderSize[0u ] = m_renderSize[1u ] = 0u ;
0 commit comments