Skip to content

Commit 832f47e

Browse files
committed
Merge with shader_pipeline_irrlichtbaw
2 parents 2b49c4e + 377aa10 commit 832f47e

File tree

27 files changed

+2275
-996
lines changed

27 files changed

+2275
-996
lines changed

examples_tests/22.RaytracedAO/common.glsl

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,4 @@
2323
#define mat4x3 nbl::core::matrix3x4SIMD
2424
#endif
2525

26-
27-
struct RaytraceShaderCommonData_t
28-
{
29-
uvec2 imageDimensions;
30-
uint samplesPerPixelPerDispatch;
31-
uint samplesPerRowPerDispatch;
32-
};
33-
34-
35-
struct SLight
36-
{
37-
#ifdef __cplusplus
38-
SLight() : obb() {}
39-
SLight(const SLight& other) : obb(other.obb) {}
40-
SLight(const nbl::core::aabbox3df& bbox, const nbl::core::matrix3x4SIMD& tform) : SLight()
41-
{
42-
auto extent = bbox.getExtent();
43-
obb.setScale(nbl::core::vectorSIMDf(extent.X,extent.Y,extent.Z));
44-
obb.setTranslation(nbl::core::vectorSIMDf(bbox.MinEdge.X,bbox.MinEdge.Y,bbox.MinEdge.Z));
45-
46-
obb = nbl::core::concatenateBFollowedByA(tform,obb);
47-
}
48-
49-
inline SLight& operator=(SLight&& other) noexcept
50-
{
51-
std::swap(obb, other.obb);
52-
53-
return *this;
54-
}
55-
56-
// also known as an upper bound on lumens put into the scene
57-
inline float computeFluxBound(const nbl::core::vectorSIMDf& radiance) const
58-
{
59-
const nbl::core::vectorSIMDf rec709LumaCoeffs(0.2126f, 0.7152f, 0.0722f, 0.f);
60-
const auto unitHemisphereArea = 2.f*nbl::core::PI<float>();
61-
62-
const auto unitBoxScale = obb.getScale();
63-
const float obbArea = 2.f*(unitBoxScale.x*unitBoxScale.y+unitBoxScale.x*unitBoxScale.z+unitBoxScale.y*unitBoxScale.z);
64-
65-
return nbl::core::dot(radiance,rec709LumaCoeffs).x*unitHemisphereArea*obbArea;
66-
}
67-
#endif
68-
69-
mat4x3 obb; // needs row_major qualifier
70-
};
71-
72-
7326
#endif

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.cpp

Lines changed: 533 additions & 641 deletions
Large diffs are not rendered by default.

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.h

Lines changed: 50 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _EXTRA_CRAP_INCLUDED_
2-
#define _EXTRA_CRAP_INCLUDED_
1+
#ifndef _RENDERER_INCLUDED_
2+
#define _RENDERER_INCLUDED_
33

44
#include "nabla.h"
55

@@ -20,7 +20,9 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
2020
{
2121
public:
2222
#include "../drawCommon.glsl"
23+
#include "../raytraceCommon.glsl"
2324
#ifdef __cplusplus
25+
#undef uint
2426
#undef mat4
2527
#undef mat4x3
2628
#endif
@@ -29,24 +31,25 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
2931
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxResolution[2] = {7680/2,4320/2};
3032

3133

32-
Renderer(nbl::video::IVideoDriver* _driver, nbl::asset::IAssetManager* _assetManager, nbl::scene::ISceneManager* _smgr, nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet>&& globalBackendDataDS, bool useDenoiser = true);
34+
Renderer(nbl::video::IVideoDriver* _driver, nbl::asset::IAssetManager* _assetManager, nbl::scene::ISceneManager* _smgr, bool useDenoiser = true);
3335

34-
void init( const nbl::asset::SAssetBundle& meshes,
35-
bool isCameraRightHanded,
36-
nbl::core::smart_refctd_ptr<nbl::asset::ICPUBuffer>&& sampleSequence,
37-
uint32_t rayBufferSize=(sizeof(::RadeonRays::ray)*2u+sizeof(uint32_t)*2u)*MaxResolution[0]*MaxResolution[1]); // 2 samples for MIS, TODO: compute default buffer size
36+
void init( const nbl::asset::SAssetBundle& meshes, nbl::core::smart_refctd_ptr<nbl::asset::ICPUBuffer>&& sampleSequence,
37+
uint32_t rayBufferSize=(sizeof(::RadeonRays::ray)+sizeof(::RadeonRays::Intersection))*2u*MaxResolution[0]*MaxResolution[1]); // 2 samples for MIS, TODO: compute default buffer size
3838

3939
void deinit();
4040

4141
void render(nbl::ITimer* timer);
4242

43-
bool isRightHanded() { return m_rightHanded; }
44-
4543
auto* getColorBuffer() { return m_colorBuffer; }
4644

4745
const auto& getSceneBound() const { return m_sceneBound; }
4846

49-
uint64_t getTotalSamplesComputed() const { return static_cast<uint64_t>(m_samplesComputedPerPixel)*static_cast<uint64_t>(m_rayCountPerDispatch)/m_samplesPerPixelPerDispatch; }
47+
uint64_t getTotalSamplesComputed() const
48+
{
49+
const auto samplesPerDispatch = static_cast<uint64_t>(m_staticViewData.samplesPerRowPerDispatch*m_staticViewData.imageDimensions.y);
50+
const auto framesDispatched = static_cast<uint64_t>(m_raytraceCommonData.framesDispatched);
51+
return framesDispatched*samplesPerDispatch;
52+
}
5053

5154

5255
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxDimensions = 6u;
@@ -87,108 +90,81 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
8790

8891
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> createScreenSizedTexture(nbl::asset::E_FORMAT format);
8992

90-
#if TODO
91-
core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> createDS2layoutCompost(bool useDenoiser, core::smart_refctd_ptr<video::IGPUSampler>& nearstSampler);
92-
core::smart_refctd_ptr<video::IGPUDescriptorSet> createDS2Compost(bool useDenoiser,
93-
core::smart_refctd_ptr<video::IGPUSampler>& nearestSampler
94-
);
95-
core::smart_refctd_ptr<video::IGPUPipelineLayout> createLayoutCompost();
9693

97-
core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> createDS2layoutRaygen(core::smart_refctd_ptr<video::IGPUSampler>& nearstSampler);
98-
core::smart_refctd_ptr<video::IGPUDescriptorSet> createDS2Raygen(core::smart_refctd_ptr<video::IGPUSampler>& nearstSampler);
99-
core::smart_refctd_ptr<video::IGPUPipelineLayout> createLayoutRaygen();
100-
#endif
101-
102-
const bool m_useDenoiser;
94+
// "constants"
95+
bool m_useDenoiser;
10396

97+
// managers
10498
nbl::video::IVideoDriver* m_driver;
10599

106100
nbl::asset::IAssetManager* m_assetManager;
107101
nbl::scene::ISceneManager* m_smgr;
108102

109103
nbl::core::smart_refctd_ptr<nbl::ext::RadeonRays::Manager> m_rrManager;
104+
#ifdef _IRR_BUILD_OPTIX_
105+
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::Manager> m_optixManager;
106+
CUstream m_cudaStream;
107+
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::IContext> m_optixContext;
108+
#endif
110109

111-
nbl::core::smart_refctd_ptr<nbl::asset::ICPUSpecializedShader> m_visibilityBufferFillShaders[2];
112-
nbl::core::smart_refctd_ptr<nbl::asset::ICPUPipelineLayout> m_visibilityBufferFillPipelineLayoutCPU;
113-
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_visibilityBufferFillPipelineLayoutGPU;
114-
nbl::core::smart_refctd_ptr<const nbl::video::IGPUDescriptorSetLayout> m_perCameraRasterDSLayout;
115110

111+
// persistent (intialized in constructor
116112
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_cullDSLayout;
117113
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_cullPipelineLayout;
118114
nbl::core::smart_refctd_ptr<nbl::video::IGPUComputePipeline> m_cullPipeline;
119-
120-
nbl::core::smart_refctd_ptr<nbl::video::IGPUComputePipeline> m_raygenPipeline,m_resolvePipeline;
121115

116+
nbl::core::smart_refctd_ptr<nbl::asset::ICPUSpecializedShader> m_visibilityBufferFillShaders[2];
117+
nbl::core::smart_refctd_ptr<nbl::asset::ICPUPipelineLayout> m_visibilityBufferFillPipelineLayoutCPU;
118+
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_visibilityBufferFillPipelineLayoutGPU;
119+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_perCameraRasterDSLayout;
120+
121+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_commonRaytracingDSLayout, m_raygenDSLayout, m_resolveDSLayout;
122+
123+
124+
// scene specific data
125+
nbl::ext::RadeonRays::MockSceneManager m_mock_smgr;
126+
nbl::ext::RadeonRays::Manager::MeshBufferRRShapeCache rrShapeCache;
127+
nbl::ext::RadeonRays::Manager::NblInstanceRRInstanceCache rrInstances;
122128

123-
nbl::core::vectorSIMDf baseEnvColor;
124129
nbl::core::aabbox3df m_sceneBound;
125-
uint32_t m_renderSize[2u];
126-
bool m_rightHanded;
130+
uint32_t m_maxRaysPerDispatch;
131+
StaticViewData_t m_staticViewData;
132+
RaytraceShaderCommonData_t m_raytraceCommonData;
127133

128134
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> m_indirectDrawBuffers[2];
129135
struct MDICall
130136
{
131137
nbl::asset::SBufferBinding<nbl::video::IGPUBuffer> vertexBindings[nbl::video::IGPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT];
132138
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> indexBuffer;
133139
nbl::core::smart_refctd_ptr<nbl::video::IGPURenderpassIndependentPipeline> pipeline;
134-
uint32_t mdiOffset,mdiCount;
140+
uint32_t mdiOffset, mdiCount;
135141
};
136142
nbl::core::vector<MDICall> m_mdiDrawCalls;
143+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_cullDS;
137144
CullShaderData_t m_cullPushConstants;
145+
uint32_t m_cullWorkGroups;
138146

139-
uint32_t m_lightCount;
140-
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> m_lightCDFBuffer;
141-
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> m_lightBuffer;
142-
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> m_lightRadianceBuffer;
143-
144-
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_globalBackendDataDS,m_cullDS,m_perCameraRasterDS; // TODO: do we need to keep track of this?
145-
146-
147-
nbl::ext::RadeonRays::Manager::MeshBufferRRShapeCache rrShapeCache;
148-
#if TODO
149-
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_compostDS2;
150-
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_compostLayout;
151-
nbl::core::smart_refctd_ptr<nbl::video::IGPUComputePipeline> m_compostPipeline;
152-
147+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_perCameraRasterDS;
148+
149+
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_raygenPipelineLayout, m_resolvePipelineLayout;
150+
nbl::core::smart_refctd_ptr<nbl::video::IGPUComputePipeline> m_raygenPipeline, m_resolvePipeline;
151+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_globalBackendDataDS,m_commonRaytracingDS,m_raygenDS;
153152
uint32_t m_raygenWorkGroups[2];
154-
uint32_t m_resolveWorkGroups[2];
155-
156-
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_raygenDS2;
157-
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_raygenLayout;
158153

159-
nbl::ext::RadeonRays::Manager::MeshNodeRRInstanceCache rrInstances;
160-
#endif
161154
struct InteropBuffer
162155
{
163156
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> buffer;
164-
std::pair<::RadeonRays::Buffer*,cl_mem> asRRBuffer;
157+
std::pair<::RadeonRays::Buffer*, cl_mem> asRRBuffer = { nullptr,0u };
165158
};
166159
InteropBuffer m_rayCountBuffer,m_rayBuffer,m_intersectionBuffer;
167160

161+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_resolveDS;
162+
uint32_t m_resolveWorkGroups[2];
168163

169-
enum E_VISIBILITY_BUFFER_ATTACHMENT
170-
{
171-
EVBA_DEPTH,
172-
EVBA_OBJECTID_AND_TRIANGLEID_AND_FRONTFACING,
173-
// TODO: Once we get geometry packer V2 (virtual geometry) no need for these buffers actually (might want/need a barycentric buffer)
174-
EVBA_NORMALS,
175-
EVBA_UV_COORDINATES,
176-
EVBA_COUNT
177-
};
178-
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> m_visibilityBufferAttachments[EVBA_COUNT];
179-
180-
uint32_t m_maxSamples, m_samplesPerPixelPerDispatch, m_rayCountPerDispatch;
181-
uint32_t m_framesDone, m_samplesComputedPerPixel;
182-
nbl::core::smart_refctd_ptr<nbl::video::IGPUBufferView> m_sampleSequence;
183-
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> m_scrambleTexture;
184-
185-
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> m_accumulation, m_tonemapOutput;
164+
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> m_accumulation,m_tonemapOutput;
186165
nbl::video::IFrameBuffer* m_visibilityBuffer,* m_colorBuffer,* tmpTonemapBuffer;
187166

188-
#ifdef _NBL_BUILD_OPTIX_
189-
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::Manager> m_optixManager;
190-
CUstream m_cudaStream;
191-
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::IContext> m_optixContext;
167+
#ifdef _IRR_BUILD_OPTIX_
192168
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::IDenoiser> m_denoiser;
193169
OptixDenoiserSizes m_denoiserMemReqs;
194170
nbl::cuda::CCUDAHandler::GraphicsAPIObjLink<nbl::video::IGPUBuffer> m_denoiserInputBuffer,m_denoiserStateBuffer,m_denoisedBuffer,m_denoiserScratchBuffer;

examples_tests/22.RaytracedAO/fillVisBuffer.frag

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ layout(location = 0) flat in uint ObjectID;
1111
layout(location = 1) in vec3 Normal;
1212
layout(location = 2) in vec2 UV;
1313

14-
layout(location = 0) out uvec2 objectTriangleFrontFacing;
14+
layout(location = 0) out uvec2 frontFacing_Object_Triangle;
1515
layout(location = 1) out vec2 encodedNormal;
1616
layout(location = 2) out vec2 uv;
1717

1818
void main()
1919
{
20-
objectTriangleFrontFacing = uvec2(ObjectID^(gl_FrontFacing ? 0x0u:0x80000000u),gl_PrimitiveID);
20+
frontFacing_Object_Triangle = uvec2(ObjectID^(gl_FrontFacing ? 0x0u:0x80000000u),gl_PrimitiveID);
21+
// these will disappear once we finally have MeshPackerV2 and settle on a way to obtain barycentrics
2122
encodedNormal = nbl_glsl_NormalEncode_signedSpherical(normalize(Normal));
2223
uv = UV;
2324
}

examples_tests/22.RaytracedAO/main.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ int main()
116116

117117
auto smgr = device->getSceneManager();
118118

119+
// TODO: Move into renderer?
119120
bool rightHandedCamera = true;
120121
auto camera = smgr->addCameraSceneNode(nullptr);
121122
auto isOkSensorType = [](const ext::MitsubaLoader::CElementSensor& sensor) -> bool {
@@ -216,17 +217,8 @@ int main()
216217

217218
auto driver = device->getVideoDriver();
218219

219-
asset::ICPUDescriptorSet* glslMaterialBackendGlobalDS = nullptr;
220-
{
221-
// a bit roundabout but oh well what can we do
222-
auto& _1stmesh = meshes.getContents().begin()[0];
223-
auto* meta_ = static_cast<asset::ICPUMesh*>(_1stmesh.get())->getMeshBuffer(0)->getPipeline()->getMetadata();
224-
auto* pipelinemeta = static_cast<ext::MitsubaLoader::CMitsubaPipelineMetadata*>(meta_);
225-
glslMaterialBackendGlobalDS = pipelinemeta->getDescriptorSet();
226-
}
227-
auto gpuds0 = driver->getGPUObjectsFromAssets(&glslMaterialBackendGlobalDS,&glslMaterialBackendGlobalDS+1)->front();
228220

229-
core::smart_refctd_ptr<Renderer> renderer = core::make_smart_refctd_ptr<Renderer>(driver, device->getAssetManager(), smgr, std::move(gpuds0));
221+
core::smart_refctd_ptr<Renderer> renderer = core::make_smart_refctd_ptr<Renderer>(driver, device->getAssetManager(), smgr);
230222
constexpr uint32_t MaxSamples = 1024u*1024u;
231223
auto sampleSequence = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof(uint32_t)*MaxSamples*Renderer::MaxDimensions);
232224
{
@@ -264,7 +256,7 @@ int main()
264256
}
265257
}
266258

267-
renderer->init(meshes, rightHandedCamera, std::move(sampleSequence));
259+
renderer->init(meshes, std::move(sampleSequence));
268260
meshes = {}; // free memory
269261

270262

0 commit comments

Comments
 (0)