Skip to content

Commit 310be40

Browse files
committed
Improvenets
1 parent 9d0022b commit 310be40

File tree

1 file changed

+33
-68
lines changed
  • 03_DeviceSelectionAndSharedSources

1 file changed

+33
-68
lines changed

03_DeviceSelectionAndSharedSources/main.cpp

Lines changed: 33 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
4242
//if (!introspection->canSpecializationlesslyCreateDescSetFrom())
4343
//return logFail("Someone changed the shader and some descriptor binding depends on a specialization constant!");
4444

45-
#if 0
4645
// flexible test
46+
#if 0
4747
{
4848
m_logger->log("------- test.hlsl INTROSPECTION -------", ILogger::E_LOG_LEVEL::ELL_WARNING);
4949
CSPIRVIntrospector introspector;
@@ -66,8 +66,9 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
6666
}
6767
};
6868

69-
// TODO: if these are to stay, then i should avoid code multiplication
7069
// testing creation of compute pipeline layouts compatible for multiple shaders
70+
#if 0
71+
// TODO: if these are to stay, then i should avoid code multiplication
7172
{
7273
constexpr std::array mergeTestShadersPaths = {
7374
"app_resources/pplnLayoutMergeTest/shader_0.comp.hlsl",
@@ -112,14 +113,14 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
112113
// TODO: idk what should happen when last binding in introspection is fixed-length sized array and last binding in introspection to merge is run-time sized array
113114
confirmExpectedOutput(pplnIntroData->merge(introspections[5].get()), false);
114115
}
115-
116+
#endif
116117
// testing pre-defined layout compatibility
117118
{
118119
constexpr std::array mergeTestShadersPaths = {
119-
"app_resources/pplnLayoutCreationWithPredefinedLayoutTest/shader_0.comp.hlsl",
120-
"app_resources/pplnLayoutCreationWithPredefinedLayoutTest/shader_1.comp.hlsl",
121-
"app_resources/pplnLayoutCreationWithPredefinedLayoutTest/shader_2.comp.hlsl",
122-
"app_resources/pplnLayoutCreationWithPredefinedLayoutTest/shader_3.comp.hlsl"
120+
"app_resources/pplnLayoutCreationWithPredefinedLayoutTest/shader_0.comp.hlsl"
121+
//"app_resources/pplnLayoutCreationWithPredefinedLayoutTest/shader_1.comp.hlsl",
122+
//"app_resources/pplnLayoutCreationWithPredefinedLayoutTest/shader_2.comp.hlsl",
123+
//"app_resources/pplnLayoutCreationWithPredefinedLayoutTest/shader_3.comp.hlsl"
123124
};
124125
constexpr uint32_t MERGE_TEST_SHADERS_CNT = mergeTestShadersPaths.size();
125126

@@ -139,31 +140,39 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
139140
{
140141
.binding = 0,
141142
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
142-
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE, // not is not the time for descriptor indexing
143+
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
143144
.stageFlags = ICPUShader::ESS_COMPUTE,
144145
.count = 1,
145-
.samplers = nullptr // irrelevant for a buffer
146+
.samplers = nullptr
146147
},
147148
{
148149
.binding = 1,
149150
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
150-
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE, // not is not the time for descriptor indexing
151+
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
151152
.stageFlags = IGPUShader::ESS_COMPUTE,
152-
.count = 2,
153-
.samplers = nullptr // irrelevant for a buffer
153+
.count = 3,
154+
.samplers = nullptr
154155
}
155156
};
156157

157-
constexpr uint32_t BINDINGS_DS_1_CNT = 1u;
158+
constexpr uint32_t BINDINGS_DS_1_CNT = 2u;
158159
const ICPUDescriptorSetLayout::SBinding bindingsDS1[BINDINGS_DS_1_CNT] = {
159160
{
160-
.binding = 6,
161+
.binding = 0,
161162
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
162163
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
163164
.stageFlags = ICPUShader::ESS_COMPUTE,
164165
.count = 1,
165-
.samplers = nullptr // irrelevant for a buffer
166+
.samplers = nullptr
166167
},
168+
{
169+
.binding = 1,
170+
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
171+
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
172+
.stageFlags = ICPUShader::ESS_COMPUTE,
173+
.count = 5,
174+
.samplers = nullptr
175+
}
167176
};
168177

169178
core::smart_refctd_ptr<ICPUDescriptorSetLayout> dsLayout0 = core::make_smart_refctd_ptr<ICPUDescriptorSetLayout>(bindingsDS0, bindingsDS0 + BINDINGS_DS_0_CNT);
@@ -185,76 +194,32 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
185194
pplnCreationSuccess[i] = static_cast<bool>(introspector[i].createApproximateComputePipelineFromIntrospection(specInfo, core::smart_refctd_ptr<ICPUPipelineLayout>(predefinedPplnLayout)));
186195
}
187196

188-
assert(MERGE_TEST_SHADERS_CNT <= 4u);
197+
//assert(MERGE_TEST_SHADERS_CNT <= 4u);
189198
// DESCRIPTOR VALIDATION TESTS
190199
// layout from introspection is a subset of pre-defined layout, hence ppln creation should SUCCEED
191200
confirmExpectedOutput(pplnCreationSuccess[0], true);
192201
// layout from introspection is NOT a subset (too many bindings in descriptor set 0) of pre-defined layout, hence ppln creation should FAIL
193-
confirmExpectedOutput(pplnCreationSuccess[1], false);
202+
//confirmExpectedOutput(pplnCreationSuccess[1], false);
194203
// layout from introspection is NOT a subset (pre-defined layout doesn't have descriptor set 2) of pre-defined layout, hence ppln creation should FAIL
195-
confirmExpectedOutput(pplnCreationSuccess[2], false);
204+
//confirmExpectedOutput(pplnCreationSuccess[2], false);
196205
// layout from introspection is NOT a subset (same bindings, different type of one of the bindings) of pre-defined layout, hence ppln creation should FAIL
197-
confirmExpectedOutput(pplnCreationSuccess[3], false);
206+
//confirmExpectedOutput(pplnCreationSuccess[3], false);
198207
// PUSH CONSTANTS VALIDATION TESTS
199208
// layout from introspection is a subset of pre-defined layout (Push constant size declared in shader are compatible), hence ppln creation should SUCCEED
200209
// TODO
201210
// layout from introspection is NOT a subset of pre-defined layout (Push constant size declared in shader are NOT compatible), hence ppln creation should FAIL
202211
// TODO
203212
}
204213

205-
// testing what will happen when last binding in introspection is fixed-length sized array and last binding in introspection to merge is run-time sized array
206-
{
207-
CSPIRVIntrospector introspector;
208-
auto source = this->compileShaderAndTestIntrospection("app_resources/lastBindingCompatibilityTest.comp.hlsl", introspector).first;
209-
210-
ICPUShader::SSpecInfo specInfo;
211-
specInfo.entryPoint = "main";
212-
specInfo.shader = source.get();
213-
214-
m_logger->log("------- shader.comp.hlsl PIPELINE CREATION -------", ILogger::E_LOG_LEVEL::ELL_WARNING);
215-
smart_refctd_ptr<nbl::asset::ICPUComputePipeline> cpuPipeline = introspector.createApproximateComputePipelineFromIntrospection(specInfo);
216-
217-
smart_refctd_ptr<IGPUShader> shader = m_device->createShader(source.get());
218-
219-
nbl::video::IGPUDescriptorSetLayout::SBinding bindingsDS0[1] = {
220-
{
221-
.binding = 0,
222-
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
223-
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT,
224-
.stageFlags = IGPUShader::ESS_COMPUTE,
225-
.count = 0,
226-
.samplers = nullptr
227-
},
228-
};
229-
230-
smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout0 = m_device->createDescriptorSetLayout(bindingsDS0);
231-
if (!dsLayout0)
232-
return logFail("Failed to create a Descriptor Layout!\n");
233-
234-
// 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
235-
smart_refctd_ptr<nbl::video::IGPUPipelineLayout> pplnLayout = m_device->createPipelineLayout({}, smart_refctd_ptr(dsLayout0), nullptr, nullptr, nullptr);
236-
if (!pplnLayout)
237-
return logFail("Failed to create a Pipeline Layout!\n");
238-
239-
// We use strong typing on the pipelines (Compute, Graphics, Mesh, RT), since there's no reason to polymorphically switch between different pipelines
240-
smart_refctd_ptr<nbl::video::IGPUComputePipeline> pipeline;
241-
{
242-
IGPUComputePipeline::SCreationParams params = {};
243-
params.layout = pplnLayout.get();
244-
// Theoretically a blob of SPIR-V can contain multiple named entry points and one has to be chosen, in practice most compilers only support outputting one (and glslang used to require it be called "main")
245-
params.shader.entryPoint = "main";
246-
params.shader.shader = shader.get();
247-
// we'll cover the specialization constant API in another example
248-
if (!m_device->createComputePipelines(nullptr, { &params,1 }, &pipeline))
249-
return logFail("Failed to create pipelines (compile & link shaders)!\n");
250-
}
251-
}
252-
253214
m_logger->log("------- shader.comp.hlsl INTROSPECTION -------", ILogger::E_LOG_LEVEL::ELL_WARNING);
254215
CSPIRVIntrospector introspector;
255-
auto source = this->compileShaderAndTestIntrospection("app_resources/shader.comp.hlsl", introspector).first;
216+
auto mainShader = this->compileShaderAndTestIntrospection("app_resources/shader.comp.hlsl", introspector);
217+
auto source = mainShader.first;
218+
auto mainShaderIntrospection = mainShader.second;
219+
mainShaderIntrospection->debugPrint(m_logger.get());
256220
// auto source2 = this->compileShaderAndTestIntrospection("app_resources/shader.comp.hlsl", introspector); // to make sure caching works
257221

222+
258223
m_logger->log("------- vtx_test1.hlsl INTROSPECTION -------", ILogger::E_LOG_LEVEL::ELL_WARNING);
259224
CSPIRVIntrospector introspector_test1;
260225
auto vtx_test1 = this->compileShaderAndTestIntrospection("app_resources/vtx_test1.hlsl", introspector_test1);

0 commit comments

Comments
 (0)