Skip to content

Commit e7a536b

Browse files
VisibilityBufferPipeline almost ready to run
1 parent c55b97d commit e7a536b

File tree

5 files changed

+135
-33
lines changed

5 files changed

+135
-33
lines changed

examples_tests/22.RaytracedAO/common.glsl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,4 @@ struct SLight
4848
};
4949

5050

51-
#ifdef __cplusplus
52-
#undef mat4
53-
#undef mat4x3
54-
#endif
55-
56-
5751
#endif

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.cpp

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ constexpr uint32_t kOptiXPixelSize = sizeof(uint16_t)*3u;
2020

2121
Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, irr::scene::ISceneManager* _smgr, core::smart_refctd_ptr<video::IGPUDescriptorSet>&& globalBackendDataDS, bool useDenoiser) :
2222
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(),
2526
#if TODO
26-
m_raygenProgram(0u), m_compostProgram(0u),
2727
m_raygenWorkGroups{0u,0u}, m_resolveWorkGroups{0u,0u},
2828
m_rayBuffer(), m_intersectionBuffer(), m_rayCountBuffer(),
2929
m_rayBufferAsRR(nullptr,nullptr), m_intersectionBufferAsRR(nullptr,nullptr), m_rayCountBufferAsRR(nullptr,nullptr),
30-
nodes(), rrInstances(),
30+
rrInstances(),
3131
#endif
3232
m_lightCount(0u),
3333
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
3636
,m_cudaStream(nullptr)
3737
#endif
3838
{
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+
3950
#ifdef _IRR_BUILD_OPTIX_
4051
while (useDenoiser)
4152
{
@@ -295,6 +306,7 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
295306
InitializationData retval;
296307

297308
auto contents = meshes.getContents();
309+
uint32_t instanceCount = 0u;
298310
for (auto& cpumesh_ : contents)
299311
{
300312
auto cpumesh = static_cast<asset::ICPUMesh*>(cpumesh_.get());
@@ -315,6 +327,35 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
315327
{
316328
// TODO: get rid of `getMeshBuffer` and `getMeshBufferCount`, just return a range as `getMeshBuffers`
317329
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
318359
m_rrManager->makeRRShapes(rrShapeCache, &cpumb, (&cpumb)+1);
319360
}
320361

@@ -335,6 +376,23 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
335376
retval.lightPDF.push_back(weight);
336377
}
337378
}
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+
338396
return retval;
339397
}
340398

@@ -371,7 +429,7 @@ void Renderer::initSceneNonAreaLights(Renderer::InitializationData& initData)
371429
}
372430
}
373431

374-
void Renderer::finalizeSceneLights(Renderer::InitializationData& initData)
432+
void Renderer::finalizeScene(Renderer::InitializationData& initData)
375433
{
376434
if (initData.lights.empty())
377435
return;
@@ -476,7 +534,7 @@ void Renderer::init(const SAssetBundle& meshes,
476534
assert(globalMeta);
477535

478536
initSceneNonAreaLights(initData);
479-
finalizeSceneLights(initData);
537+
finalizeScene(initData);
480538
{
481539
#if TODO
482540
auto gpumeshes = m_driver->getGPUObjectsFromAssets<ICPUMesh>(contents.first, contents.second);
@@ -581,7 +639,6 @@ void Renderer::init(const SAssetBundle& meshes,
581639
m_raygenLayout = createLayoutRaygen();
582640
m_compostLayout = createLayoutCompost();
583641

584-
auto rr_includes = m_rrManager->getRadeonRaysGLSLIncludes();
585642
{
586643
std::string glsl = "raygen.comp" +
587644
globalMeta->materialCompilerGLSL_declarations +
@@ -740,9 +797,6 @@ void Renderer::deinit()
740797
m_raygenWorkGroups[0] = m_raygenWorkGroups[1] = 0u;
741798
m_resolveWorkGroups[0] = m_resolveWorkGroups[1] = 0u;
742799

743-
for (auto& node : nodes)
744-
node->remove();
745-
nodes.clear();
746800
m_rrManager->detachInstances(rrInstances.begin(),rrInstances.end());
747801
m_rrManager->deleteInstances(rrInstances.begin(),rrInstances.end());
748802
rrInstances.clear();
@@ -783,6 +837,8 @@ void Renderer::deinit()
783837
m_rrManager->deleteShapes(rrShapeCache.begin(), rrShapeCache.end());
784838
rrShapeCache.clear();
785839

840+
m_perCameraRasterDS = nullptr;
841+
786842
m_globalBackendDataDS = nullptr;
787843
m_rightHanded = false;
788844
m_renderSize[0u] = m_renderSize[1u] = 0u;

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.h

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
class Renderer : public irr::core::IReferenceCounted, public irr::core::InterfaceUnmovable
2020
{
2121
public:
22-
#include "../common.glsl"
22+
#include "../InstanceDataPerCamera.glsl"
23+
#ifdef __cplusplus
24+
#undef mat4
25+
#undef mat4x3
26+
#endif
2327

2428
// No 8k yet, too many rays to store
2529
_IRR_STATIC_INLINE_CONSTEXPR uint32_t MaxResolution[2] = {7680/2,4320/2};
@@ -66,6 +70,27 @@ class Renderer : public irr::core::IReferenceCounted, public irr::core::Interfac
6670
globalMeta = other.globalMeta;
6771
return *this;
6872
}
73+
74+
75+
struct VisibilityBufferPipelineKey
76+
{
77+
inline bool operator==(const VisibilityBufferPipelineKey& other) const
78+
{
79+
return vertexParams==other.vertexParams&&frontFaceIsCCW==other.frontFaceIsCCW;
80+
}
81+
82+
irr::asset::SVertexInputParams vertexParams;
83+
uint8_t frontFaceIsCCW;
84+
};
85+
struct VisibilityBufferPipelineKeyHash
86+
{
87+
inline std::size_t operator()(const VisibilityBufferPipelineKey& key) const
88+
{
89+
std::basic_string_view view(reinterpret_cast<const char*>(&key),sizeof(key));
90+
return std::hash<decltype(view)>()(view);
91+
}
92+
};
93+
irr::core::unordered_map<VisibilityBufferPipelineKey,irr::core::smart_refctd_ptr<irr::video::IGPURenderpassIndependentPipeline>,VisibilityBufferPipelineKeyHash> m_visibilityBufferFillPipelines;
6994

7095
irr::core::vector<SLight> lights;
7196
irr::core::vector<irr::core::vectorSIMDf> lightRadiances;
@@ -78,7 +103,7 @@ class Renderer : public irr::core::IReferenceCounted, public irr::core::Interfac
78103
};
79104
InitializationData initSceneObjects(const irr::asset::SAssetBundle& meshes);
80105
void initSceneNonAreaLights(InitializationData& initData);
81-
void finalizeSceneLights(InitializationData& initData);
106+
void finalizeScene(InitializationData& initData);
82107

83108
irr::core::smart_refctd_ptr<irr::video::IGPUImageView> createScreenSizedTexture(irr::asset::E_FORMAT format);
84109

@@ -103,13 +128,25 @@ class Renderer : public irr::core::IReferenceCounted, public irr::core::Interfac
103128

104129
irr::core::smart_refctd_ptr<irr::ext::RadeonRays::Manager> m_rrManager;
105130

131+
irr::core::smart_refctd_ptr<irr::video::IGPUSpecializedShader> m_visibilityBufferFillShaders[2];
132+
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSetLayout> m_perCameraRasterDSLayout;
133+
irr::core::smart_refctd_ptr<irr::video::IGPUPipelineLayout> m_visibilityBufferFillPipelineLayout;
134+
135+
irr::core::smart_refctd_ptr<irr::video::IGPUComputePipeline> m_raygenPipeline,m_resolvePipeline;
136+
106137

107138
irr::core::vectorSIMDf baseEnvColor;
108139
irr::core::aabbox3df m_sceneBound;
109140
uint32_t m_renderSize[2u];
110141
bool m_rightHanded;
111142

112-
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSet> m_globalBackendDataDS;
143+
uint32_t m_lightCount;
144+
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_lightCDFBuffer;
145+
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_lightBuffer;
146+
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_lightRadianceBuffer;
147+
148+
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSet> m_globalBackendDataDS,m_perCameraRasterDS; // TODO: do we need to keep track of this?
149+
113150

114151
irr::ext::RadeonRays::Manager::MeshBufferRRShapeCache rrShapeCache;
115152
#if TODO
@@ -119,24 +156,19 @@ class Renderer : public irr::core::IReferenceCounted, public irr::core::Interfac
119156

120157
uint32_t m_raygenWorkGroups[2];
121158
uint32_t m_resolveWorkGroups[2];
122-
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_rayBuffer;
123-
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_intersectionBuffer;
124-
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_rayCountBuffer;
125-
std::pair<::RadeonRays::Buffer*,cl_mem> m_rayBufferAsRR;
126-
std::pair<::RadeonRays::Buffer*,cl_mem> m_intersectionBufferAsRR;
127-
std::pair<::RadeonRays::Buffer*,cl_mem> m_rayCountBufferAsRR;
128159

129160
irr::core::smart_refctd_ptr<irr::video::IGPUDescriptorSet> m_raygenDS2;
130161
irr::core::smart_refctd_ptr<irr::video::IGPUPipelineLayout> m_raygenLayout;
131-
irr::core::smart_refctd_ptr<irr::video::IGPUComputePipeline> m_raygenPipeline;
132162

133-
irr::core::vector<irr::core::smart_refctd_ptr<irr::scene::IMeshSceneNode> > nodes;
134163
irr::ext::RadeonRays::Manager::MeshNodeRRInstanceCache rrInstances;
135164
#endif
136-
uint32_t m_lightCount;
137-
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_lightCDFBuffer;
138-
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_lightBuffer;
139-
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> m_lightRadianceBuffer;
165+
struct InteropBuffer
166+
{
167+
irr::core::smart_refctd_ptr<irr::video::IGPUBuffer> buffer;
168+
std::pair<::RadeonRays::Buffer*,cl_mem> asRRBuffer;
169+
};
170+
InteropBuffer m_rayCountBuffer,m_rayBuffer,m_intersectionBuffer;
171+
140172

141173
enum E_VISIBILITY_BUFFER_ATTACHMENT
142174
{

examples_tests/22.RaytracedAO/mesh.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 430 core
22

33
#include "InstanceDataPerCamera.glsl"
4-
layout(set=3, binding=0, row_major) readonly restrict buffer SSBO
4+
layout(set=2, binding=0, row_major) readonly restrict buffer SSBO
55
{
66
InstanceDataPerCamera data[];
77
} instanceDataPerCamera;

include/irr/asset/IRenderpassIndependentPipeline.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,25 @@ struct SVertexInputAttribParams
4747
SVertexInputAttribParams(uint32_t _binding, uint32_t _format, uint32_t _relativeOffset) :
4848
binding(_binding), format(_format), relativeOffset(_relativeOffset) {}
4949

50+
inline bool operator==(const SVertexInputAttribParams& rhs) const
51+
{
52+
return binding==rhs.binding&&format==rhs.format&&relativeOffset==rhs.relativeOffset;
53+
}
54+
5055
uint32_t binding : 4;
5156
uint32_t format : 8;//asset::E_FORMAT
5257
uint32_t relativeOffset : 13;//assuming max=2048
5358
} PACK_STRUCT;
5459
static_assert(sizeof(SVertexInputAttribParams)==(4u), "Unexpected size!");
5560
struct SVertexInputBindingParams
5661
{
57-
uint32_t stride = 0u;
62+
63+
inline bool operator==(const SVertexInputBindingParams& rhs) const
64+
{
65+
return stride==rhs.stride&&inputRate==rhs.inputRate;
66+
}
67+
68+
uint32_t stride = 0u; // could have packed the stride and input rate together since there are limits on those
5869
E_VERTEX_INPUT_RATE inputRate = EVIR_PER_VERTEX;
5970
} PACK_STRUCT;
6071
static_assert(sizeof(SVertexInputBindingParams)==5u, "Unexpected size!");
@@ -63,6 +74,15 @@ struct SVertexInputParams
6374
_IRR_STATIC_INLINE_CONSTEXPR size_t MAX_VERTEX_ATTRIB_COUNT = 16u;
6475
_IRR_STATIC_INLINE_CONSTEXPR size_t MAX_ATTR_BUF_BINDING_COUNT = 16u;
6576

77+
inline bool operator==(const SVertexInputParams& rhs) const
78+
{
79+
if (enabledAttribFlags!=rhs.enabledAttribFlags||enabledBindingFlags!=rhs.enabledBindingFlags)
80+
return false;
81+
82+
return std::equal(attributes,attributes+MAX_VERTEX_ATTRIB_COUNT,rhs.attributes)&&std::equal(bindings,bindings+MAX_ATTR_BUF_BINDING_COUNT,rhs.bindings);
83+
}
84+
85+
6686
uint16_t enabledAttribFlags = 0u;
6787
uint16_t enabledBindingFlags = 0u;
6888
//! index in array denotes location (attribute ID)

0 commit comments

Comments
 (0)