2
2
// This file is part of the "Nabla Engine".
3
3
// For conditions of distribution and use, see copyright notice in nabla.h
4
4
5
- // I've moved out a tiny part of this example into a shared header for reuse, please open and read it.
6
-
7
5
#include " nbl/application_templates/MonoDeviceApplication.hpp"
8
6
#include " nbl/application_templates/MonoAssetManagerAndBuiltinResourceApplication.hpp"
9
7
@@ -69,39 +67,45 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
69
67
specInfo.entryPoint = " main" ;
70
68
specInfo.shader = source.get ();
71
69
70
+ // TODO: cast to IGPUComputePipeline
72
71
smart_refctd_ptr<nbl::asset::ICPUComputePipeline> cpuPipeline = introspector.createApproximateComputePipelineFromIntrospection (specInfo);
73
72
74
73
smart_refctd_ptr<IGPUShader> shader = m_device->createShader (source.get ());
75
74
76
- nbl::video::IGPUDescriptorSetLayout::SBinding bindingsDS1[1 ] = {
77
- {
78
- .binding = 2 ,
79
- .type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
80
- .createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE, // not is not the time for descriptor indexing
81
- .stageFlags = IGPUShader::ESS_COMPUTE,
82
- .count = 4 , // TODO: check what will happen with: .count = 5
83
- .samplers = nullptr // irrelevant for a buffer
84
- },
85
- };
75
+ std::array<std::vector<IGPUDescriptorSetLayout::SBinding>, IGPUPipelineLayout::DESCRIPTOR_SET_COUNT> bindings;
76
+ for (uint32_t i = 0u ; i < IGPUPipelineLayout::DESCRIPTOR_SET_COUNT; ++i)
77
+ {
78
+ const auto & introspectionBindings = shaderIntrospection->getDescriptorSetInfo (i);
79
+ bindings[i].resize (introspectionBindings.size ());
86
80
87
- nbl::video::IGPUDescriptorSetLayout::SBinding bindingsDS3[1 ] = {
88
- {
89
- .binding = 6 ,
90
- .type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
91
- .createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
92
- .stageFlags = IGPUShader::ESS_COMPUTE,
93
- .count = 1 ,
94
- .samplers = nullptr // irrelevant for a buffer
95
- },
81
+ for (const auto & introspectionBinding : introspectionBindings)
82
+ {
83
+ auto & binding = bindings[i].emplace_back ();
84
+
85
+ binding.binding = introspectionBinding.binding ;
86
+ binding.type = introspectionBinding.type ;
87
+ binding.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE;
88
+ binding.stageFlags = IGPUShader::ESS_COMPUTE;
89
+ assert (introspectionBinding.count .countMode == CSPIRVIntrospector::CIntrospectionData::SDescriptorArrayInfo::DESCRIPTOR_COUNT::STATIC);
90
+ binding.count = introspectionBinding.count .count ;
91
+ }
92
+ }
93
+
94
+ const std::array<core::smart_refctd_ptr<IGPUDescriptorSetLayout>, ICPUPipelineLayout::DESCRIPTOR_SET_COUNT> dsLayouts = {
95
+ bindings[0 ].empty () ? nullptr : m_device->createDescriptorSetLayout (bindings[0 ]),
96
+ bindings[1 ].empty () ? nullptr : m_device->createDescriptorSetLayout (bindings[1 ]),
97
+ bindings[2 ].empty () ? nullptr : m_device->createDescriptorSetLayout (bindings[2 ]),
98
+ bindings[3 ].empty () ? nullptr : m_device->createDescriptorSetLayout (bindings[3 ])
96
99
};
97
-
98
- smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout1 = m_device->createDescriptorSetLayout (bindingsDS1);
99
- smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout3 = m_device->createDescriptorSetLayout (bindingsDS3);
100
- if (!dsLayout1 || !dsLayout3)
101
- return logFail (" Failed to create a Descriptor Layout!\n " );
102
100
103
101
// Nabla actually has facilities for SPIR-V Reflection and "guessing" pipeline layouts for a given SPIR-V which we'll cover in a different example
104
- smart_refctd_ptr<nbl::video::IGPUPipelineLayout> pplnLayout = m_device->createPipelineLayout ({}, nullptr , smart_refctd_ptr (dsLayout1), nullptr , smart_refctd_ptr (dsLayout3));
102
+ smart_refctd_ptr<nbl::video::IGPUPipelineLayout> pplnLayout = m_device->createPipelineLayout (
103
+ {},
104
+ core::smart_refctd_ptr (dsLayouts[0 ]),
105
+ core::smart_refctd_ptr (dsLayouts[1 ]),
106
+ core::smart_refctd_ptr (dsLayouts[2 ]),
107
+ core::smart_refctd_ptr (dsLayouts[3 ])
108
+ );
105
109
if (!pplnLayout)
106
110
return logFail (" Failed to create a Pipeline Layout!\n " );
107
111
@@ -120,7 +124,12 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
120
124
121
125
// Nabla hardcodes the maximum descriptor set count to 4
122
126
constexpr uint32_t MaxDescriptorSets = ICPUPipelineLayout::DESCRIPTOR_SET_COUNT;
123
- const std::array<IGPUDescriptorSetLayout*, MaxDescriptorSets> dscLayoutPtrs = { nullptr , dsLayout1.get (), nullptr , dsLayout3.get () };
127
+ const std::array<IGPUDescriptorSetLayout*, MaxDescriptorSets> dscLayoutPtrs = {
128
+ !dsLayouts[0 ] ? nullptr : dsLayouts[0 ].get (),
129
+ !dsLayouts[1 ] ? nullptr : dsLayouts[1 ].get (),
130
+ !dsLayouts[2 ] ? nullptr : dsLayouts[2 ].get (),
131
+ !dsLayouts[3 ] ? nullptr : dsLayouts[3 ].get ()
132
+ };
124
133
std::array<smart_refctd_ptr<IGPUDescriptorSet>, MaxDescriptorSets> ds;
125
134
auto pool = m_device->createDescriptorPoolForDSLayouts (IDescriptorPool::ECF_NONE, std::span (dscLayoutPtrs.begin (), dscLayoutPtrs.end ()));
126
135
pool->createDescriptorSets (dscLayoutPtrs.size (), dscLayoutPtrs.data (), ds.data ());
@@ -190,7 +199,6 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
190
199
}
191
200
}
192
201
193
- #ifndef USE_INTROSPECTOR
194
202
{
195
203
IGPUDescriptorSet::SDescriptorInfo inputBuffersInfo[2 ];
196
204
inputBuffersInfo[0 ].desc = smart_refctd_ptr (inputBuff[0 ].first );
@@ -209,7 +217,6 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
209
217
210
218
m_device->updateDescriptorSets (std::span (writes, 2 ), {});
211
219
}
212
- #endif
213
220
214
221
// create, record, submit and await commandbuffers
215
222
constexpr auto StartedValue = 0 ;
@@ -340,33 +347,6 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
340
347
341
348
return std::pair (source, introspection);
342
349
}
343
-
344
- // requires two compute shaders for simplicity of the example
345
- core::smart_refctd_ptr<ICPUComputePipeline> createComputePipelinesWithCompatibleLayout (std::span<core::smart_refctd_ptr<ICPUShader>> spirvShaders)
346
- {
347
- CSPIRVIntrospector introspector;
348
- auto pplnIntroData = CSPIRVIntrospector::CPipelineIntrospectionData ();
349
-
350
- for (auto it = spirvShaders.begin (); it != spirvShaders.end (); ++it)
351
- {
352
- CSPIRVIntrospector::CStageIntrospectionData::SParams params;
353
- params.entryPoint = " main" ; // whatever
354
- params.shader = *it;
355
-
356
- auto stageIntroData = introspector.introspect (params);
357
- const bool hasMerged = pplnIntroData.merge (stageIntroData.get ());
358
-
359
- if (!hasMerged)
360
- {
361
- m_logger->log (" Unable to create a compatible layout." , ILogger::ELL_PERFORMANCE);
362
- return nullptr ;
363
- }
364
- }
365
-
366
- // TODO: create ppln from `pplnIntroData`..
367
- // return core::make_smart_refctd_ptr<ICPUComputePipeline>();
368
- return nullptr ;
369
- }
370
350
};
371
351
372
352
NBL_MAIN_FUNC (DeviceSelectionAndSharedSourcesApp)
0 commit comments