Skip to content

Commit 5a64236

Browse files
committed
Ported Example 29 and 33 and fixed them (29 still needs fix)
1 parent a6f5787 commit 5a64236

File tree

2 files changed

+108
-29
lines changed

2 files changed

+108
-29
lines changed

examples_tests/29.SpecializationConstants/main.cpp

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// #include "CFileSystem.h"
1010
using namespace nbl;
1111
using namespace core;
12+
using namespace ui;
1213

1314
struct UBOCompute
1415
{
@@ -25,15 +26,16 @@ class SpecializationConstantsSampleApp : public ApplicationBase
2526
static constexpr uint64_t MAX_TIMEOUT = 99999999999999ull;
2627
static_assert(FRAMES_IN_FLIGHT > SC_IMG_COUNT);
2728

28-
core::smart_refctd_ptr<nbl::ui::IWindow> win;
29+
core::smart_refctd_ptr<nbl::ui::IWindow> window;
30+
core::smart_refctd_ptr<nbl::system::ISystem> system;
2931
core::smart_refctd_ptr<CommonAPI::CommonAPIEventCallback> windowCb;
3032
core::smart_refctd_ptr<nbl::video::IAPIConnection> api;
3133
core::smart_refctd_ptr<nbl::video::ISurface> surface;
3234
core::smart_refctd_ptr<nbl::video::IUtilities> utils;
3335
core::smart_refctd_ptr<nbl::video::ILogicalDevice> device;
3436
video::IPhysicalDevice* gpu;
3537
std::array<video::IGPUQueue*, CommonAPI::InitOutput::MaxQueuesCount> queues;
36-
core::smart_refctd_ptr<nbl::video::ISwapchain> sc;
38+
core::smart_refctd_ptr<nbl::video::ISwapchain> swapchain;
3739
core::smart_refctd_ptr<nbl::video::IGPURenderpass> renderpass;
3840
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, CommonAPI::InitOutput::MaxSwapChainImageCount> fbo;
3941
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, CommonAPI::InitOutput::MaxQueuesCount> commandPools;
@@ -77,17 +79,53 @@ class SpecializationConstantsSampleApp : public ApplicationBase
7779
core::smart_refctd_ptr<video::IGPURenderpassIndependentPipeline> m_rpIndependentPipeline;
7880

7981
public:
82+
8083
void setWindow(core::smart_refctd_ptr<nbl::ui::IWindow>&& wnd) override
8184
{
82-
win = std::move(wnd);
85+
window = std::move(wnd);
86+
}
87+
void setSystem(core::smart_refctd_ptr<nbl::system::ISystem>&& s) override
88+
{
89+
system = std::move(s);
8390
}
8491
nbl::ui::IWindow* getWindow() override
8592
{
86-
return win.get();
93+
return window.get();
94+
}
95+
video::IAPIConnection* getAPIConnection() override
96+
{
97+
return api.get();
98+
}
99+
video::ILogicalDevice* getLogicalDevice() override
100+
{
101+
return device.get();
102+
}
103+
video::IGPURenderpass* getRenderpass() override
104+
{
105+
return renderpass.get();
106+
}
107+
void setSurface(core::smart_refctd_ptr<video::ISurface>&& s) override
108+
{
109+
surface = std::move(s);
110+
}
111+
void setFBOs(std::vector<core::smart_refctd_ptr<video::IGPUFramebuffer>>& f) override
112+
{
113+
for (int i = 0; i < f.size(); i++)
114+
{
115+
fbo[i] = core::smart_refctd_ptr(f[i]);
116+
}
117+
}
118+
void setSwapchain(core::smart_refctd_ptr<video::ISwapchain>&& s) override
119+
{
120+
swapchain = std::move(s);
121+
}
122+
uint32_t getSwapchainImageCount() override
123+
{
124+
return SC_IMG_COUNT;
87125
}
88-
void setSystem(core::smart_refctd_ptr<nbl::system::ISystem>&& system) override
126+
virtual nbl::asset::E_FORMAT getDepthFormat() override
89127
{
90-
system = std::move(system);
128+
return nbl::asset::EF_UNKNOWN;
91129
}
92130

93131
APP_CONSTRUCTOR(SpecializationConstantsSampleApp);
@@ -113,7 +151,8 @@ class SpecializationConstantsSampleApp : public ApplicationBase
113151
const asset::E_FORMAT depthFormat = asset::EF_UNKNOWN;
114152

115153
CommonAPI::InitOutput initOutp;
116-
initOutp.window = core::smart_refctd_ptr(win);
154+
initOutp.window = window;
155+
initOutp.system = system;
117156
CommonAPI::Init(
118157
initOutp,
119158
video::EAT_VULKAN,
@@ -127,14 +166,15 @@ class SpecializationConstantsSampleApp : public ApplicationBase
127166
surfaceFormat,
128167
depthFormat);
129168

130-
win = std::move(initOutp.window);
169+
window = std::move(initOutp.window);
170+
system = std::move(initOutp.system);
131171
windowCb = std::move(initOutp.windowCb);
132172
api = std::move(initOutp.apiConnection);
133173
surface = std::move(initOutp.surface);
134174
device = std::move(initOutp.logicalDevice);
135175
gpu = std::move(initOutp.physicalDevice);
136176
queues = std::move(initOutp.queues);
137-
sc = std::move(initOutp.swapchain);
177+
swapchain = std::move(initOutp.swapchain);
138178
renderpass = std::move(initOutp.renderpass);
139179
fbo = std::move(initOutp.fbo);
140180
commandPools = std::move(initOutp.commandPools);
@@ -153,7 +193,7 @@ class SpecializationConstantsSampleApp : public ApplicationBase
153193

154194
video::IGPUObjectFromAssetConverter CPU2GPU;
155195
m_cameraPosition = core::vectorSIMDf(0, 0, -10);
156-
matrix4SIMD proj = matrix4SIMD::buildProjectionMatrixPerspectiveFovRH(core::radians(90), float(WIN_W) / WIN_H, 0.01, 100);
196+
matrix4SIMD proj = matrix4SIMD::buildProjectionMatrixPerspectiveFovRH(core::radians(90.0f), float(WIN_W) / WIN_H, 0.01, 100);
157197
matrix3x4SIMD view = matrix3x4SIMD::buildCameraLookAtMatrixRH(m_cameraPosition, core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 1, 0));
158198
m_viewProj = matrix4SIMD::concatenateBFollowedByA(proj, matrix4SIMD(view));
159199
m_camFront = view[2];
@@ -191,7 +231,7 @@ class SpecializationConstantsSampleApp : public ApplicationBase
191231
int32_t vel_buf_ix;
192232
int32_t buf_count;
193233
};
194-
SpecConstants sc{ WORKGROUP_SIZE, PARTICLE_COUNT, POS_BUF_IX, VEL_BUF_IX, BUF_COUNT };
234+
SpecConstants swapchain{ WORKGROUP_SIZE, PARTICLE_COUNT, POS_BUF_IX, VEL_BUF_IX, BUF_COUNT };
195235

196236
auto it_particleBufDescIntro = std::find_if(introspection->descriptorSetBindings[COMPUTE_SET].begin(), introspection->descriptorSetBindings[COMPUTE_SET].end(),
197237
[=](auto b) { return b.binding == PARTICLE_BUF_BINDING; }
@@ -202,8 +242,8 @@ class SpecializationConstantsSampleApp : public ApplicationBase
202242
assert(particleDataArrayIntro.countIsSpecConstant);
203243
const uint32_t particle_count_specID = particleDataArrayIntro.count_specID;
204244

205-
auto backbuf = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof(sc));
206-
memcpy(backbuf->getPointer(), &sc, sizeof(sc));
245+
auto backbuf = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof(swapchain));
246+
memcpy(backbuf->getPointer(), &swapchain, sizeof(swapchain));
207247
auto entries = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<asset::ISpecializedShader::SInfo::SMapEntry>>(5u);
208248
(*entries)[0] = { 0u,offsetof(SpecConstants,wg_size),sizeof(int32_t) };//currently local_size_{x|y|z}_id is not queryable via introspection API
209249
(*entries)[1] = { particle_count_specID,offsetof(SpecConstants,particle_count),sizeof(int32_t) };
@@ -314,8 +354,6 @@ class SpecializationConstantsSampleApp : public ApplicationBase
314354
auto& blendParams = pipeline->getBlendParams();
315355
blendParams.logicOpEnable = false;
316356
blendParams.logicOp = nbl::asset::ELO_NO_OP;
317-
for (size_t i = 0ull; i < nbl::asset::SBlendParams::MAX_COLOR_ATTACHMENT_COUNT; i++)
318-
blendParams.blendParams[i].attachmentEnabled = (i == 0ull);
319357
}
320358
auto gfxLayout = core::make_smart_refctd_ptr<asset::ICPUPipelineLayout>(nullptr, nullptr, core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout>(pipeline->getLayout()->getDescriptorSetLayout(0)));
321359
pipeline->setLayout(core::smart_refctd_ptr(gfxLayout));
@@ -410,7 +448,7 @@ class SpecializationConstantsSampleApp : public ApplicationBase
410448
COMPUTE_SET,
411449
1u,
412450
&m_gpuds0Compute.get(),
413-
nullptr);
451+
0u);
414452
cb->dispatch(PARTICLE_COUNT / WORKGROUP_SIZE, 1u, 1u);
415453

416454
asset::SMemoryBarrier memBarrier;
@@ -445,7 +483,7 @@ class SpecializationConstantsSampleApp : public ApplicationBase
445483
}
446484
// renderpass
447485
uint32_t imgnum = 0u;
448-
sc->acquireNextImage(MAX_TIMEOUT, m_imageAcquire[m_resourceIx].get(), nullptr, &imgnum);
486+
swapchain->acquireNextImage(MAX_TIMEOUT, m_imageAcquire[m_resourceIx].get(), nullptr, &imgnum);
449487
{
450488
video::IGPUCommandBuffer::SRenderpassBeginInfo info;
451489
asset::SClearValue clear;
@@ -466,15 +504,15 @@ class SpecializationConstantsSampleApp : public ApplicationBase
466504
cb->bindGraphicsPipeline(m_graphicsPipeline.get());
467505
size_t vbOffset = 0;
468506
cb->bindVertexBuffers(0, 1, &m_gpuParticleBuf.get(), &vbOffset);
469-
cb->bindDescriptorSets(asset::EPBP_GRAPHICS, m_rpIndependentPipeline->getLayout(), GRAPHICS_SET, 1u, &m_gpuds0Graphics.get(), nullptr);
507+
cb->bindDescriptorSets(asset::EPBP_GRAPHICS, m_rpIndependentPipeline->getLayout(), GRAPHICS_SET, 1u, &m_gpuds0Graphics.get(), 0u);
470508
cb->draw(PARTICLE_COUNT, 1, 0, 0);
471509
}
472510
cb->endRenderPass();
473511
cb->end();
474512

475513
CommonAPI::Submit(
476514
device.get(),
477-
sc.get(),
515+
swapchain.get(),
478516
cb.get(),
479517
queues[CommonAPI::InitOutput::EQT_GRAPHICS],
480518
m_imageAcquire[m_resourceIx].get(),
@@ -483,7 +521,7 @@ class SpecializationConstantsSampleApp : public ApplicationBase
483521

484522
CommonAPI::Present(
485523
device.get(),
486-
sc.get(),
524+
swapchain.get(),
487525
queues[CommonAPI::InitOutput::EQT_GRAPHICS],
488526
m_renderFinished[m_resourceIx].get(),
489527
imgnum);

examples_tests/33.Draw3DLine/main.cpp

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
using namespace nbl;
1212
using namespace core;
13+
using namespace ui;
1314

1415
class Draw3DLineSampleApp : public ApplicationBase
1516
{
@@ -20,7 +21,8 @@ class Draw3DLineSampleApp : public ApplicationBase
2021
static constexpr uint64_t MAX_TIMEOUT = 99999999999999ull;
2122
static_assert(FRAMES_IN_FLIGHT > SC_IMG_COUNT);
2223

23-
core::smart_refctd_ptr<nbl::ui::IWindow> win;
24+
core::smart_refctd_ptr<nbl::ui::IWindow> window;
25+
core::smart_refctd_ptr<nbl::system::ISystem> system;
2426
core::smart_refctd_ptr<CommonAPI::CommonAPIEventCallback> windowCb;
2527
core::smart_refctd_ptr<nbl::video::IAPIConnection> api;
2628
core::smart_refctd_ptr<nbl::video::ISurface> surface;
@@ -47,17 +49,53 @@ class Draw3DLineSampleApp : public ApplicationBase
4749
core::smart_refctd_ptr<video::IGPUSemaphore> m_renderFinished[FRAMES_IN_FLIGHT] = { nullptr };
4850

4951
public:
52+
5053
void setWindow(core::smart_refctd_ptr<nbl::ui::IWindow>&& wnd) override
5154
{
52-
win = std::move(wnd);
55+
window = std::move(wnd);
56+
}
57+
void setSystem(core::smart_refctd_ptr<nbl::system::ISystem>&& s) override
58+
{
59+
system = std::move(s);
5360
}
5461
nbl::ui::IWindow* getWindow() override
5562
{
56-
return win.get();
63+
return window.get();
5764
}
58-
void setSystem(core::smart_refctd_ptr<nbl::system::ISystem>&& system) override
65+
video::IAPIConnection* getAPIConnection() override
5966
{
60-
system = std::move(system);
67+
return api.get();
68+
}
69+
video::ILogicalDevice* getLogicalDevice() override
70+
{
71+
return device.get();
72+
}
73+
video::IGPURenderpass* getRenderpass() override
74+
{
75+
return renderpass.get();
76+
}
77+
void setSurface(core::smart_refctd_ptr<video::ISurface>&& s) override
78+
{
79+
surface = std::move(s);
80+
}
81+
void setFBOs(std::vector<core::smart_refctd_ptr<video::IGPUFramebuffer>>& f) override
82+
{
83+
for (int i = 0; i < f.size(); i++)
84+
{
85+
fbo[i] = core::smart_refctd_ptr(f[i]);
86+
}
87+
}
88+
void setSwapchain(core::smart_refctd_ptr<video::ISwapchain>&& s) override
89+
{
90+
sc = std::move(s);
91+
}
92+
uint32_t getSwapchainImageCount() override
93+
{
94+
return SC_IMG_COUNT;
95+
}
96+
virtual nbl::asset::E_FORMAT getDepthFormat() override
97+
{
98+
return nbl::asset::EF_UNKNOWN;
6199
}
62100

63101
APP_CONSTRUCTOR(Draw3DLineSampleApp);
@@ -83,10 +121,13 @@ class Draw3DLineSampleApp : public ApplicationBase
83121
const asset::E_FORMAT depthFormat = asset::EF_UNKNOWN;
84122

85123
CommonAPI::InitOutput initOutp;
86-
initOutp.window = core::smart_refctd_ptr(win);
124+
125+
initOutp.window = window;
126+
initOutp.system = system;
127+
87128
CommonAPI::Init(
88129
initOutp,
89-
video::EAT_OPENGL,
130+
video::EAT_VULKAN,
90131
"33.Draw3DLine",
91132
requiredInstanceFeatures,
92133
optionalInstanceFeatures,
@@ -97,7 +138,7 @@ class Draw3DLineSampleApp : public ApplicationBase
97138
surfaceFormat,
98139
depthFormat);
99140

100-
win = std::move(initOutp.window);
141+
window = std::move(initOutp.window);
101142
windowCb = std::move(initOutp.windowCb);
102143
api = std::move(initOutp.apiConnection);
103144
surface = std::move(initOutp.surface);
@@ -130,7 +171,7 @@ class Draw3DLineSampleApp : public ApplicationBase
130171
});
131172
}
132173

133-
matrix4SIMD proj = matrix4SIMD::buildProjectionMatrixPerspectiveFovRH(core::radians(90), float(WIN_W) / WIN_H, 0.01, 100);
174+
matrix4SIMD proj = matrix4SIMD::buildProjectionMatrixPerspectiveFovRH(core::radians(90.0f), float(WIN_W) / WIN_H, 0.01, 100);
134175
matrix3x4SIMD view = matrix3x4SIMD::buildCameraLookAtMatrixRH(core::vectorSIMDf(0, 0, -10), core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 1, 0));
135176
auto viewProj = matrix4SIMD::concatenateBFollowedByA(proj, matrix4SIMD(view));
136177

0 commit comments

Comments
 (0)