Skip to content

Commit f81d33b

Browse files
committed
Update
1 parent 8d41254 commit f81d33b

File tree

4 files changed

+47
-116
lines changed

4 files changed

+47
-116
lines changed

03_DeviceSelectionAndSharedSources/Testers.h

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,6 @@ class IntrospectionTesterBase
114114
logger->log(msg, system::ILogger::ELL_ERROR, std::forward<Args>(args)...);
115115
return false;
116116
}
117-
118-
// requires two compute shaders for simplicity of the example
119-
//core::smart_refctd_ptr<ICPUComputePipeline> createComputePipelinesWithCompatibleLayout(std::span<core::smart_refctd_ptr<ICPUShader>> spirvShaders)
120-
//{
121-
// CSPIRVIntrospector introspector;
122-
// auto pplnIntroData = CSPIRVIntrospector::CPipelineIntrospectionData();
123-
124-
// for (auto it = spirvShaders.begin(); it != spirvShaders.end(); ++it)
125-
// {
126-
// CSPIRVIntrospector::CStageIntrospectionData::SParams params;
127-
// params.entryPoint = "main"; //whatever
128-
// params.shader = *it;
129-
130-
// auto stageIntroData = introspector.introspect(params);
131-
// const bool hasMerged = pplnIntroData.merge(stageIntroData.get());
132-
133-
// if (!hasMerged)
134-
// {
135-
// m_logger->log("Unable to create a compatible layout.", ILogger::ELL_PERFORMANCE);
136-
// return nullptr;
137-
// }
138-
// }
139-
140-
// // TODO: create ppln from `pplnIntroData`..
141-
// //return core::make_smart_refctd_ptr<ICPUComputePipeline>();
142-
// return nullptr;
143-
//}
144-
145117
};
146118

147119
class MergeTester final : public IntrospectionTesterBase
@@ -316,6 +288,8 @@ class SandboxTester final : public IntrospectionTesterBase
316288
auto pplnIntroData = core::make_smart_refctd_ptr<CSPIRVIntrospector::CPipelineIntrospectionData>();
317289
confirmExpectedOutput(logger, pplnIntroData->merge(sourceIntrospectionPair.second.get()), true);
318290

291+
sourceIntrospectionPair.second->debugPrint(logger);
292+
319293
// TODO
320294
/*CSPIRVIntrospector introspector_test1;
321295
auto vtx_test1 = compileHLSLShaderAndTestIntrospection(physicalDevice, device, logger, assetMgr, "app_resources/vtx_test1.hlsl", introspector_test1);
Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,12 @@
1-
#pragma wave shader_stage(compute)
21
#include "common.hlsl"
32

4-
struct SomeType
5-
{
6-
uint16_t asdf[6][9][45];
7-
};
8-
9-
[[vk::constant_id(3)]] const int TEST_INT_1 = 2;
10-
11-
[[vk::binding(0,0)]] RWStructuredBuffer<SomeType> asdf;
3+
// intentionally making my live difficult here, to showcase the power of reflection
124
[[vk::binding(2,1)]] ByteAddressBuffer inputs[2];
135
[[vk::binding(6,3)]] RWByteAddressBuffer output;
146

15-
struct PushConstants
16-
{
17-
uint2 a;
18-
uint b;
19-
};
20-
21-
[[vk::push_constant]]
22-
PushConstants u_pushConstants;
23-
247
[numthreads(WorkgroupSize, 1, 1)]
258
void main(uint32_t3 ID : SV_DispatchThreadID)
269
{
27-
const uint32_t byteOffset = sizeof(uint32_t)*ID.x+TEST_INT_1+uint32_t(asdf[69].asdf[4][5][0]);
28-
29-
output.Store<uint32_t>(byteOffset,inputs[0].Load<uint32_t>(byteOffset)+inputs[1].Load<uint32_t>(byteOffset)
30-
+ uint32_t(u_pushConstants.a.x) + uint32_t(u_pushConstants.a.y) + uint32_t(u_pushConstants.b));
31-
32-
// testing push constants
33-
//const uint32_t byteOffset = sizeof(uint32_t)*ID.x;
34-
//output.Store<uint32_t>(byteOffset, uint32_t(u_pushConstants.a.x) + uint32_t(u_pushConstants.a.y) + uint32_t(u_pushConstants.b));
10+
const uint32_t byteOffset = sizeof(uint32_t)*ID.x;
11+
output.Store<uint32_t>(byteOffset,inputs[0].Load<uint32_t>(byteOffset)+inputs[1].Load<uint32_t>(byteOffset));
3512
}

03_DeviceSelectionAndSharedSources/app_resources/test.hlsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
struct SomeType
77
{
8-
uint32_t a;
8+
float4x4 a;
99
uint32_t b[5];
1010
uint32_t c[10];
1111
};
@@ -20,8 +20,8 @@ void main(uint32_t3 ID : SV_DispatchThreadID)
2020
const uint32_t index = ID.x;
2121
const uint32_t byteOffset = sizeof(uint32_t)*index;
2222

23-
output[0].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3] * SPEC_CONSTANT_VALUE);
24-
output[1].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3]);
25-
output[2].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] + asdf[index].c[3]);
26-
output2[1].Store<uint32_t>(byteOffset, asdf[index].a + asdf[index].b[2] - asdf[index].c[3]);
23+
output[0].Store<uint32_t>(byteOffset, asdf[index].a[0][0] + asdf[index].b[2] + asdf[index].c[3] * SPEC_CONSTANT_VALUE);
24+
output[1].Store<uint32_t>(byteOffset, asdf[index].a[0][0] + asdf[index].b[2] + asdf[index].c[3]);
25+
output[2].Store<uint32_t>(byteOffset, asdf[index].a[0][0] + asdf[index].b[2] + asdf[index].c[3]);
26+
output2[1].Store<uint32_t>(byteOffset, asdf[index].a[0][0] + asdf[index].b[2] - asdf[index].c[3]);
2727
}

03_DeviceSelectionAndSharedSources/main.cpp

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

5-
// I've moved out a tiny part of this example into a shared header for reuse, please open and read it.
6-
75
#include "nbl/application_templates/MonoDeviceApplication.hpp"
86
#include "nbl/application_templates/MonoAssetManagerAndBuiltinResourceApplication.hpp"
97

@@ -69,39 +67,45 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
6967
specInfo.entryPoint = "main";
7068
specInfo.shader = source.get();
7169

70+
// TODO: cast to IGPUComputePipeline
7271
smart_refctd_ptr<nbl::asset::ICPUComputePipeline> cpuPipeline = introspector.createApproximateComputePipelineFromIntrospection(specInfo);
7372

7473
smart_refctd_ptr<IGPUShader> shader = m_device->createShader(source.get());
7574

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());
8680

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])
9699
};
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");
102100

103101
// 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+
);
105109
if (!pplnLayout)
106110
return logFail("Failed to create a Pipeline Layout!\n");
107111

@@ -120,7 +124,12 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
120124

121125
// Nabla hardcodes the maximum descriptor set count to 4
122126
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+
};
124133
std::array<smart_refctd_ptr<IGPUDescriptorSet>, MaxDescriptorSets> ds;
125134
auto pool = m_device->createDescriptorPoolForDSLayouts(IDescriptorPool::ECF_NONE, std::span(dscLayoutPtrs.begin(), dscLayoutPtrs.end()));
126135
pool->createDescriptorSets(dscLayoutPtrs.size(), dscLayoutPtrs.data(), ds.data());
@@ -190,7 +199,6 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
190199
}
191200
}
192201

193-
#ifndef USE_INTROSPECTOR
194202
{
195203
IGPUDescriptorSet::SDescriptorInfo inputBuffersInfo[2];
196204
inputBuffersInfo[0].desc = smart_refctd_ptr(inputBuff[0].first);
@@ -209,7 +217,6 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
209217

210218
m_device->updateDescriptorSets(std::span(writes, 2), {});
211219
}
212-
#endif
213220

214221
// create, record, submit and await commandbuffers
215222
constexpr auto StartedValue = 0;
@@ -340,33 +347,6 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
340347

341348
return std::pair(source, introspection);
342349
}
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-
}
370350
};
371351

372352
NBL_MAIN_FUNC(DeviceSelectionAndSharedSourcesApp)

0 commit comments

Comments
 (0)