Skip to content

Commit 7031e60

Browse files
doesn't crash anymore
1 parent b11e947 commit 7031e60

File tree

5 files changed

+32
-29
lines changed

5 files changed

+32
-29
lines changed

examples_tests/22.RaytracedAO/common.glsl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
};
2222
#define mat4 nbl::core::matrix4SIMD
2323
#define mat4x3 nbl::core::matrix3x4SIMD
24-
#else
25-
#include <nbl/builtin/glsl/ext/MitsubaLoader/instance_data_descriptor.glsl>
2624
#endif
2725

2826
#endif

examples_tests/22.RaytracedAO/cull.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "drawCommon.glsl"
55
layout(local_size_x = WORKGROUP_SIZE) in;
66

7+
#include <nbl/builtin/glsl/ext/MitsubaLoader/instance_data_descriptor.glsl>
78

89
#include <nbl/builtin/glsl/utils/indirect_commands.glsl>
910
layout(set=1, binding=0, row_major) writeonly restrict buffer PerInstancePerCamera

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,21 @@ Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, scene::I
8080
break;
8181
}
8282

83-
constexpr auto cullingOutputDescriptorCount = 1u;
8483
{
85-
constexpr auto cullingDescriptorCount = cullingOutputDescriptorCount+2u;
84+
constexpr auto cullingDescriptorCount = 3u;
8685
IGPUDescriptorSetLayout::SBinding bindings[cullingDescriptorCount];
8786
fillIotaDescriptorBindingDeclarations(bindings,ISpecializedShader::ESS_COMPUTE,cullingDescriptorCount,asset::EDT_STORAGE_BUFFER);
8887
bindings[2u].count = 2u;
8988
m_cullDSLayout = m_driver->createGPUDescriptorSetLayout(bindings,bindings+3u);
90-
SPushConstantRange range{ISpecializedShader::ESS_COMPUTE,0u,sizeof(CullShaderData_t)};
91-
m_cullPipelineLayout = m_driver->createGPUPipelineLayout(&range,&range+1u,nullptr,core::smart_refctd_ptr(m_cullDSLayout),nullptr,nullptr);
92-
m_cullPipeline = m_driver->createGPUComputePipeline(nullptr,core::smart_refctd_ptr(m_cullPipelineLayout),gpuSpecializedShaderFromFile(m_assetManager,m_driver,"../cull.comp"));
9389
}
9490

9591
m_visibilityBufferFillShaders[0] = specializedShaderFromFile(m_assetManager,"../fillVisBuffer.vert");
9692
m_visibilityBufferFillShaders[1] = specializedShaderFromFile(m_assetManager,"../fillVisBuffer.frag");
9793
{
98-
ICPUDescriptorSetLayout::SBinding bindings[cullingOutputDescriptorCount];
99-
fillIotaDescriptorBindingDeclarations(bindings,ISpecializedShader::ESS_VERTEX,cullingOutputDescriptorCount,asset::EDT_STORAGE_BUFFER);
94+
ICPUDescriptorSetLayout::SBinding binding;
95+
fillIotaDescriptorBindingDeclarations(&binding,ISpecializedShader::ESS_VERTEX,1u,asset::EDT_STORAGE_BUFFER);
10096

101-
auto dsLayout = core::make_smart_refctd_ptr<ICPUDescriptorSetLayout>(bindings,bindings+2u);
97+
auto dsLayout = core::make_smart_refctd_ptr<ICPUDescriptorSetLayout>(&binding,&binding+1u);
10298
m_visibilityBufferFillPipelineLayoutCPU = core::make_smart_refctd_ptr<ICPUPipelineLayout>(nullptr,nullptr,nullptr,core::smart_refctd_ptr(dsLayout),nullptr,nullptr);
10399

104100
// TODO: @Crisspl find a way to stop the user from such insanity as moving from the bundle's dynamic array
@@ -229,7 +225,7 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
229225
{
230226
// TODO: get rid of `getMeshBuffer` and `getMeshBufferCount`, just return a range as `getMeshBuffers`
231227
auto cpumb = cpumesh->getMeshBuffer(i);
232-
assert(cpumesh->getInstanceCount()==instances.size());
228+
assert(cpumb->getInstanceCount()==instances.size());
233229

234230
// set up Visibility Buffer pipelines
235231
{
@@ -439,7 +435,7 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
439435
infos[1].desc = m_driver->createFilledDeviceLocalGPUBufferOnDedMem(infos[1].buffer.size,cullData.data());
440436
cullData.clear();
441437

442-
for (auto offset=2u,i=offset; i<2u; i++)
438+
for (auto offset=2u,i=0u; i<2u; i++)
443439
{
444440
auto j = i+offset;
445441
infos[j].buffer.size = mdiData.size()*sizeof(DrawElementsIndirectCommand_t);
@@ -668,12 +664,21 @@ void Renderer::init(const SAssetBundle& meshes,
668664

669665
//
670666
{
671-
SPushConstantRange raytracingCommonPCRange{ISpecializedShader::ESS_COMPUTE,0u,sizeof(RaytraceShaderCommonData_t)};
672-
m_commonRaytracingDS = m_driver->createGPUDescriptorSet(core::smart_refctd_ptr(m_commonRaytracingDSLayout));
673-
674667
// i know what I'm doing
675668
auto globalBackendDataDSLayout = core::smart_refctd_ptr<IGPUDescriptorSetLayout>(const_cast<IGPUDescriptorSetLayout*>(m_globalBackendDataDS->getLayout()));
676669

670+
671+
// cull
672+
{
673+
SPushConstantRange range{ISpecializedShader::ESS_COMPUTE,0u,sizeof(CullShaderData_t)};
674+
m_cullPipelineLayout = m_driver->createGPUPipelineLayout(&range,&range+1u,core::smart_refctd_ptr(globalBackendDataDSLayout),core::smart_refctd_ptr(m_cullDSLayout),nullptr,nullptr);
675+
m_cullPipeline = m_driver->createGPUComputePipeline(nullptr,core::smart_refctd_ptr(m_cullPipelineLayout),gpuSpecializedShaderFromFile(m_assetManager,m_driver,"../cull.comp"));
676+
}
677+
678+
679+
SPushConstantRange raytracingCommonPCRange{ISpecializedShader::ESS_COMPUTE,0u,sizeof(RaytraceShaderCommonData_t)};
680+
m_commonRaytracingDS = m_driver->createGPUDescriptorSet(core::smart_refctd_ptr(m_commonRaytracingDSLayout));
681+
677682
// raygen
678683
{
679684
m_raygenPipelineLayout = m_driver->createGPUPipelineLayout(
@@ -969,8 +974,10 @@ void Renderer::deinit()
969974
m_commonRaytracingDS = nullptr;
970975
m_globalBackendDataDS = nullptr;
971976

977+
m_cullPipelineLayout = nullptr;
972978
m_raygenPipelineLayout = nullptr;
973979
m_resolvePipelineLayout = nullptr;
980+
m_cullPipeline = nullptr;
974981
m_raygenPipeline = nullptr;
975982
m_resolvePipeline = nullptr;
976983

@@ -1016,11 +1023,10 @@ void Renderer::render(nbl::ITimer* timer)
10161023
{
10171024
m_raytraceCommonData.framesDispatched = 0u;
10181025

1019-
IGPUDescriptorSet* descriptors[3] = { nullptr };
1020-
descriptors[1] = m_cullDS.get();
1026+
IGPUDescriptorSet* descriptors[3] = { m_globalBackendDataDS.get(),m_cullDS.get(),nullptr };
10211027

10221028
m_driver->bindComputePipeline(m_cullPipeline.get());
1023-
m_driver->bindDescriptorSets(EPBP_COMPUTE,m_cullPipelineLayout.get(),1u,1u,descriptors+1u,nullptr);
1029+
m_driver->bindDescriptorSets(EPBP_COMPUTE,m_cullPipelineLayout.get(),0u,2u,descriptors,nullptr);
10241030
{
10251031
m_cullPushConstants.viewProjMatrix = currentViewProj;
10261032
m_cullPushConstants.viewProjDeterminant = core::determinant(currentViewProj);
@@ -1029,6 +1035,7 @@ void Renderer::render(nbl::ITimer* timer)
10291035
m_driver->dispatch(m_cullWorkGroups, 1u, 1u);
10301036
COpenGLExtensionHandler::pGlMemoryBarrier(GL_COMMAND_BARRIER_BIT|GL_SHADER_STORAGE_BARRIER_BIT);
10311037

1038+
// in the future we'll clear it differently (esp with AA)
10321039
m_driver->setRenderTarget(tmpTonemapBuffer);
10331040
{
10341041
uint32_t clearAccumulation[4] = { 0,0,0,0 };
@@ -1043,7 +1050,7 @@ void Renderer::render(nbl::ITimer* timer)
10431050
m_driver->clearColorBuffer(EFAP_COLOR_ATTACHMENT1, zero);
10441051
m_driver->clearColorBuffer(EFAP_COLOR_ATTACHMENT2, zero);
10451052
}
1046-
m_driver->bindDescriptorSets(EPBP_GRAPHICS,m_visibilityBufferFillPipelineLayoutGPU.get(),0u,2u,descriptors,nullptr);
1053+
m_driver->bindDescriptorSets(EPBP_GRAPHICS,m_visibilityBufferFillPipelineLayoutGPU.get(),1u,1u,descriptors+1u,nullptr);
10471054
for (auto call : m_mdiDrawCalls)
10481055
{
10491056
m_driver->bindGraphicsPipeline(call.pipeline.get());
@@ -1074,13 +1081,13 @@ void Renderer::render(nbl::ITimer* timer)
10741081
}
10751082
}
10761083

1077-
// generate rays ( TODO: move the camera part)
1084+
// generate rays
10781085
{
10791086
m_raytraceCommonData.framesDispatched++;
10801087
m_raytraceCommonData.rcpFramesDispatched = 1.f/float(m_raytraceCommonData.framesDispatched);
10811088

1082-
IGPUDescriptorSet* descriptorSets[] = {m_globalBackendDataDS.get(),m_commonRaytracingDS.get(),m_raygenDS.get()};
1083-
m_driver->bindDescriptorSets(EPBP_COMPUTE, m_raygenPipelineLayout.get(), 0, 3, descriptorSets, nullptr);
1089+
IGPUDescriptorSet* descriptorSets[] = {m_commonRaytracingDS.get(),m_raygenDS.get()};
1090+
m_driver->bindDescriptorSets(EPBP_COMPUTE, m_raygenPipelineLayout.get(), 1, 2, descriptorSets, nullptr);
10841091
m_driver->bindComputePipeline(m_raygenPipeline.get());
10851092
m_driver->pushConstants(m_raygenPipelineLayout.get(),ISpecializedShader::ESS_COMPUTE,0u,sizeof(RaytraceShaderCommonData_t),&m_raytraceCommonData);
10861093
m_driver->dispatch(m_raygenWorkGroups[0], m_raygenWorkGroups[1], 1);

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
110110

111111
// persistent (intialized in constructor
112112
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSetLayout> m_cullDSLayout;
113-
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_cullPipelineLayout;
114-
nbl::core::smart_refctd_ptr<nbl::video::IGPUComputePipeline> m_cullPipeline;
115113

116114
nbl::core::smart_refctd_ptr<nbl::asset::ICPUSpecializedShader> m_visibilityBufferFillShaders[2];
117115
nbl::core::smart_refctd_ptr<nbl::asset::ICPUPipelineLayout> m_visibilityBufferFillPipelineLayoutCPU;
@@ -146,8 +144,8 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
146144

147145
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_perCameraRasterDS;
148146

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;
147+
nbl::core::smart_refctd_ptr<nbl::video::IGPUPipelineLayout> m_cullPipelineLayout, m_raygenPipelineLayout, m_resolvePipelineLayout;
148+
nbl::core::smart_refctd_ptr<nbl::video::IGPUComputePipeline> m_cullPipeline, m_raygenPipeline, m_resolvePipeline;
151149
nbl::core::smart_refctd_ptr<nbl::video::IGPUDescriptorSet> m_globalBackendDataDS,m_commonRaytracingDS,m_raygenDS;
152150
uint32_t m_raygenWorkGroups[2];
153151

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ layout(set = 2, binding = 5) uniform sampler2D uvCoords;
1717

1818

1919
#include "bin/material_declarations.glsl"
20+
#include <nbl/builtin/glsl/ext/MitsubaLoader/material_compiler_compatibility_impl.glsl>
2021
vec3 normalizedV;
2122
vec3 nbl_glsl_MC_getNormalizedWorldSpaceV()
2223
{
@@ -178,10 +179,8 @@ void main()
178179

179180
//
180181
emissive = nbl_glsl_MC_oriented_material_t_getEmissive(material);
181-
}
182182

183-
// normally we'd use MeshPackerV2's vertex attribute data for this, but now we read from temporary GBuffer
184-
{
183+
// normally we'd use MeshPackerV2's vertex attribute data for this, but now we read from temporary GBuffer
185184
const vec3 normal = nbl_glsl_NormalDecode_signedSpherical(normalBuffer);
186185
normalizedN.x = dot(InstData.data[objectID].normalMatrixRow0,normal);
187186
normalizedN.y = dot(InstData.data[objectID].normalMatrixRow1,normal);

0 commit comments

Comments
 (0)