Skip to content

Commit 39cb993

Browse files
Merge pull request #109 from Devsh-Graphics-Programming/pathtracing
Path Tracer without MIS or RR
2 parents 4ba1fb2 + 9ca3821 commit 39cb993

File tree

79 files changed

+3264
-2018
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3264
-2018
lines changed

3rdparty/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ if (NBL_BUILD_RADEON_RAYS)
416416
option(RR_NO_TESTS "RADEON_RAYS: don't do tests" ON)
417417
option(RR_ENABLE_STATIC "RADEON_RAYS: compile into a static library" ON)
418418
option(RR_EMBED_KERNELS "RADEON_RAYS: so we don't have to go looking for OpenCL kernel code" ON)
419-
option(RR_USE_VULKAN "RADEON_RAYS: use Vulkan (only if you have RR 3.0)" OFF)
419+
set(RR_USE_VULKAN OFF CACHE BOOL "RADEON_RAYS: Cannot use Vulkan for RR 2.0 the backend is broken" FORCE)
420+
set(RR_ENABLE_BACKFACE_CULL OFF CACHE BOOL "RADEON_RAYS: Don't enable backface culling (we use the memory of the ray struct for something else there)." FORCE)
420421
set(MSVC_USE_STATIC_CRT ON CACHE BOOL "Use /MT flag (static CRT) when compiling in MSVC")
421422
add_subdirectory(radeonrays EXCLUDE_FROM_ALL)
422423

@@ -470,7 +471,7 @@ set(NBL_3RDPARTY_TARGETS
470471
SPIRV
471472
Iex
472473
IexMath
473-
SPIRV-Tools
474+
SPIRV-Tools-static
474475
SPIRV-Tools-opt )
475476
#TODO insert more targets that are conditionally built
476477
if (NBL_BUILD_MITSUBA_LOADER)

3rdparty/SPIRV-Tools

Submodule SPIRV-Tools updated 866 files

3rdparty/glslang

3rdparty/shaderc

Submodule shaderc updated 79 files

3rdparty/spirv_cross

examples_tests/18.MitsubaLoader/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void main()
105105
mat2 dUV = mat2(dFdx(UV),dFdy(UV));
106106
107107
// "The sign of this computation is negated when the value of GL_CLIP_ORIGIN (the clip volume origin, set with glClipControl) is GL_UPPER_LEFT."
108-
const bool front = (!gl_FrontFacing) != (PC.camTformDeterminant*InstData.data[InstanceIndex].determinant < 0.0);
108+
const bool front = bool((InstData.data[InstanceIndex].determinantSignBit^mix(~0u,0u,gl_FrontFacing!=PC.camTformDeterminant<0.0))&0x80000000u);
109109
precomp = nbl_glsl_MC_precomputeData(front);
110110
material = nbl_glsl_MC_material_data_t_getOriented(InstData.data[InstanceIndex].material,precomp.frontface);
111111
#ifdef TEX_PREFETCH_STREAM

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 791 additions & 599 deletions
Large diffs are not rendered by default.

examples_tests/22.RaytracedAO/Renderer.h

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@
1919
class Renderer : public nbl::core::IReferenceCounted, public nbl::core::InterfaceUnmovable
2020
{
2121
public:
22-
#include "drawCommon.glsl"
23-
#include "raytraceCommon.glsl"
22+
#include "rasterizationCommon.h"
23+
#include "raytraceCommon.h"
2424
#ifdef __cplusplus
2525
#undef uint
26+
#undef vec4
2627
#undef mat4
2728
#undef mat4x3
2829
#endif
2930

30-
// No 8k yet, too many rays to store
31-
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxResolution[2] = {7680/2,4320/2};
32-
33-
3431
Renderer(nbl::video::IVideoDriver* _driver, nbl::asset::IAssetManager* _assetManager, nbl::scene::ISceneManager* _smgr, bool useDenoiser = true);
3532

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
33+
void init(const nbl::asset::SAssetBundle& meshes, nbl::core::smart_refctd_ptr<nbl::asset::ICPUBuffer>&& sampleSequence);
3834

3935
void deinit();
4036

@@ -46,20 +42,32 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
4642

4743
uint64_t getTotalSamplesComputed() const
4844
{
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);
45+
const auto samplesPerDispatch = static_cast<uint64_t>(m_staticViewData.samplesPerPixelPerDispatch*m_staticViewData.imageDimensions.x*m_staticViewData.imageDimensions.y);
46+
const auto framesDispatched = static_cast<uint64_t>(m_framesDispatched);
5147
return framesDispatched*samplesPerDispatch;
5248
}
49+
uint64_t getTotalRaysCast() const
50+
{
51+
return m_totalRaysCast;
52+
}
5353

54-
55-
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxDimensions = 6u;
54+
//! Brief guideline to good path depth limits
55+
// Want to see stuff with indirect lighting on the other side of a pane of glass
56+
// 5 = glass frontface->glass backface->diffuse surface->diffuse surface->light
57+
// Want to see through a glass box, vase, or office
58+
// 7 = glass frontface->glass backface->glass frontface->glass backface->diffuse surface->diffuse surface->light
59+
// pick higher numbers for better GI and less bias
60+
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxPathDepth = 8u;
61+
_NBL_STATIC_INLINE_CONSTEXPR uint32_t RandomDimsPerPathVertex = 3u;
62+
// one less because the first path vertex is rasterized
63+
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxDimensions = RandomDimsPerPathVertex*(MaxPathDepth-1u);
5664
static const float AntiAliasingSequence[4096][2];
5765
protected:
5866
~Renderer();
5967

6068
struct InitializationData
6169
{
62-
InitializationData() : lights(),lightRadiances(),lightCDF(),globalMeta(nullptr) {}
70+
InitializationData() : lights(),lightCDF(),globalMeta(nullptr) {}
6371
InitializationData(InitializationData&& other) : InitializationData()
6472
{
6573
operator=(std::move(other));
@@ -69,15 +77,12 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
6977
inline InitializationData& operator=(InitializationData&& other)
7078
{
7179
lights = std::move(other.lights);
72-
lightRadiances = std::move(other.lightRadiances);
7380
lightCDF = std::move(other.lightCDF);
7481
globalMeta = other.globalMeta;
7582
return *this;
7683
}
7784

78-
7985
nbl::core::vector<SLight> lights;
80-
nbl::core::vector<nbl::core::vectorSIMDf> lightRadiances;
8186
union
8287
{
8388
nbl::core::vector<float> lightPDF;
@@ -89,7 +94,11 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
8994
void initSceneNonAreaLights(InitializationData& initData);
9095
void finalizeScene(InitializationData& initData);
9196

92-
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> createScreenSizedTexture(nbl::asset::E_FORMAT format);
97+
//
98+
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> createScreenSizedTexture(nbl::asset::E_FORMAT format, uint32_t layers = 0u);
99+
100+
//
101+
uint32_t traceBounce(uint32_t raycount);
93102

94103

95104
// "constants"
@@ -110,34 +119,32 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
110119

111120

112121
// persistent (intialized in constructor
122+
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> m_rayCountBuffer,m_littleDownloadBuffer;
113123
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_cullDSLayout;
114-
115-
nbl::core::smart_refctd_ptr<nbl::asset::ICPUSpecializedShader> m_visibilityBufferFillShaders[2];
116-
nbl::core::smart_refctd_ptr<nbl::asset::ICPUPipelineLayout> m_visibilityBufferFillPipelineLayoutCPU;
117-
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_visibilityBufferFillPipelineLayoutGPU;
118-
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_perCameraRasterDSLayout;
119-
120-
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_commonRaytracingDSLayout, m_raygenDSLayout, m_resolveDSLayout;
124+
nbl::core::smart_refctd_ptr<const nbl::video::IGPUDescriptorSetLayout> m_perCameraRasterDSLayout;
125+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_rasterInstanceDataDSLayout,m_additionalGlobalDSLayout,m_commonRaytracingDSLayout;
126+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_raygenDSLayout,m_closestHitDSLayout,m_resolveDSLayout;
127+
nbl::core::smart_refctd_ptr<nbl::video::IGPURenderpassIndependentPipeline> m_visibilityBufferFillPipeline;
121128

122129

123130
// scene specific data
124-
nbl::ext::RadeonRays::MockSceneManager m_mock_smgr;
125-
nbl::ext::RadeonRays::Manager::MeshBufferRRShapeCache rrShapeCache;
126-
nbl::ext::RadeonRays::Manager::NblInstanceRRInstanceCache rrInstances;
131+
nbl::core::vector<::RadeonRays::Shape*> rrShapes;
132+
nbl::core::vector<::RadeonRays::Shape*> rrInstances;
127133

128134
nbl::core::matrix3x4SIMD m_prevView;
135+
nbl::core::matrix4x3 m_prevCamTform;
129136
nbl::core::aabbox3df m_sceneBound;
130-
uint32_t m_maxRaysPerDispatch;
137+
uint32_t m_framesDispatched;
138+
vec2 m_rcpPixelSize;
139+
uint64_t m_totalRaysCast;
131140
StaticViewData_t m_staticViewData;
132141
RaytraceShaderCommonData_t m_raytraceCommonData;
133142

143+
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> m_indexBuffer;
134144
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> m_indirectDrawBuffers[2];
135145
struct MDICall
136146
{
137-
nbl::asset::SBufferBinding<const nbl::video::IGPUBuffer> vertexBindings[nbl::video::IGPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT];
138-
nbl::core::smart_refctd_ptr<const nbl::video::IGPUBuffer> indexBuffer;
139-
nbl::core::smart_refctd_ptr<const nbl::video::IGPURenderpassIndependentPipeline> pipeline;
140-
uint32_t mdiOffset, mdiCount;
147+
uint32_t mdiOffset,mdiCount;
141148
};
142149
nbl::core::vector<MDICall> m_mdiDrawCalls;
143150
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_cullDS;
@@ -146,23 +153,23 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
146153

147154
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_perCameraRasterDS;
148155

149-
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_cullPipelineLayout, m_raygenPipelineLayout, m_resolvePipelineLayout;
150-
nbl::core::smart_refctd_ptr<nbl::video::IGPUComputePipeline> m_cullPipeline, m_raygenPipeline, m_resolvePipeline;
151-
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_globalBackendDataDS,m_commonRaytracingDS,m_raygenDS;
156+
nbl::core::smart_refctd_ptr<nbl::video::IGPUComputePipeline> m_cullPipeline,m_raygenPipeline,m_closestHitPipeline,m_resolvePipeline;
157+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_globalBackendDataDS,m_additionalGlobalDS;
158+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_commonRaytracingDS[2];
159+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_rasterInstanceDataDS,m_raygenDS,m_resolveDS;
160+
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_closestHitDS[2];
152161
uint32_t m_raygenWorkGroups[2];
153162

154163
struct InteropBuffer
155164
{
156165
nbl::core::smart_refctd_ptr<nbl::video::IGPUBuffer> buffer;
157166
std::pair<::RadeonRays::Buffer*, cl_mem> asRRBuffer = { nullptr,0u };
158167
};
159-
InteropBuffer m_rayCountBuffer,m_rayBuffer,m_intersectionBuffer;
160-
161-
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_resolveDS;
162-
uint32_t m_resolveWorkGroups[2];
168+
InteropBuffer m_rayBuffer[2];
169+
InteropBuffer m_intersectionBuffer[2];
163170

164171
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> m_accumulation,m_tonemapOutput;
165-
nbl::video::IFrameBuffer* m_visibilityBuffer,* m_colorBuffer,* tmpTonemapBuffer;
172+
nbl::video::IFrameBuffer* m_visibilityBuffer,* m_colorBuffer;
166173

167174
#ifdef _NBL_BUILD_OPTIX_
168175
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::IDenoiser> m_denoiser;

0 commit comments

Comments
 (0)