Skip to content

Commit dd466f6

Browse files
authored
Merge pull request #112 from Devsh-Graphics-Programming/separable_image_sampler
Changed examples to follow separable sampler changes
2 parents daea3f9 + ca6f6f2 commit dd466f6

File tree

7 files changed

+90
-18
lines changed

7 files changed

+90
-18
lines changed

02_HelloCompute/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ class HelloComputeApp final : public nbl::application_templates::MonoSystemMonoL
151151
.createFlags=IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE, // not is not the time for descriptor indexing
152152
.stageFlags=IGPUShader::ESS_COMPUTE,
153153
.count=1,
154-
.samplers=nullptr // irrelevant for a buffer
155154
}
156155
};
157156
smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout = device->createDescriptorSetLayout(bindings);

03_DeviceSelectionAndSharedSources/Testers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class PredefinedLayoutTester final : public IntrospectionTesterBase
203203
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
204204
.stageFlags = ICPUShader::ESS_COMPUTE,
205205
.count = 1,
206-
.samplers = nullptr
206+
.immutableSamplers = nullptr
207207
}
208208
};
209209

@@ -215,15 +215,15 @@ class PredefinedLayoutTester final : public IntrospectionTesterBase
215215
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
216216
.stageFlags = ICPUShader::ESS_COMPUTE,
217217
.count = 1,
218-
.samplers = nullptr
218+
.immutableSamplers = nullptr
219219
},
220220
{
221221
.binding = 1,
222222
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
223223
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
224224
.stageFlags = ICPUShader::ESS_COMPUTE,
225225
.count = 2,
226-
.samplers = nullptr
226+
.immutableSamplers = nullptr
227227
}
228228
};
229229

07_StagingAndMultipleQueues/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,22 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
269269
smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout;
270270
core::smart_refctd_ptr<IGPUDescriptorSet> descSets[FRAMES_IN_FLIGHT];
271271
{
272-
nbl::video::IGPUDescriptorSetLayout::SBinding bindings[2] = {
272+
const nbl::video::IGPUDescriptorSetLayout::SBinding bindings[2] = {
273273
{
274274
.binding = 0,
275-
.type = nbl::asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER, // TODO: just an image descriptor type when separable samplers arrive
275+
.type = nbl::asset::IDescriptor::E_TYPE::ET_SAMPLED_IMAGE,
276276
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
277277
.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
278278
.count = 1,
279-
.samplers = nullptr
279+
.immutableSamplers = nullptr
280280
},
281281
{
282282
.binding = 1,
283283
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
284284
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
285285
.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
286286
.count = 1,
287-
.samplers = nullptr
287+
.immutableSamplers = nullptr
288288
}
289289
};
290290

@@ -379,7 +379,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
379379
m_histogramBufferMemPtrs[2] = m_histogramBufferMemPtrs[1] + HISTOGRAM_SIZE;
380380
}
381381

382-
// TODO: will no longer be necessary after separable samplers and images
382+
// TODO: Remove stuff below
383383
IGPUSampler::SParams samplerParams;
384384
samplerParams.AnisotropicFilter = false;
385385
core::smart_refctd_ptr<IGPUSampler> sampler = m_device->createSampler(samplerParams);
@@ -425,7 +425,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
425425
logFailAndTerminate("Couldn't create descriptor.");
426426
view->setObjectDebugName(("Image View #"+std::to_string(imageToProcessId)).c_str());
427427
imgInfo.desc = std::move(view);
428-
imgInfo.info.image = { .sampler = sampler, .imageLayout = IImage::LAYOUT::READ_ONLY_OPTIMAL };
428+
imgInfo.info.image = { .imageLayout = IImage::LAYOUT::READ_ONLY_OPTIMAL };
429429

430430
IGPUDescriptorSet::SWriteDescriptorSet write[1] = {
431431
{.dstSet = descSets[resourceIdx].get(), .binding = 0, .arrayElement = 0, .count = 1, .info = &imgInfo }

24_ColorSpaceTest/app_resources/present.frag.hlsl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
// Copyright (C) 2024-2024 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4+
45
#pragma wave shader_stage(fragment)
56

67
// vertex shader is provided by the fullScreenTriangle extension
78
#include <nbl/builtin/hlsl/ext/FullScreenTriangle/SVertexAttributes.hlsl>
89
using namespace nbl::hlsl::ext::FullScreenTriangle;
910

10-
[[vk::combinedImageSampler]][[vk::binding(0,3)]] Texture2DArray texture;
11-
[[vk::combinedImageSampler]][[vk::binding(0,3)]] SamplerState samplerState;
12-
1311
#include "push_constants.hlsl"
12+
13+
#if defined(SEPARATED_IMMUTABLE) || defined(SEPARATED_MUTABLE)
14+
[[vk::binding(0,3)]] Texture2DArray texture;
15+
[[vk::binding(1,3)]] SamplerState samplerState;
16+
#else
17+
[[vk::combinedImageSampler]][[vk::binding(0,3)]] Texture2DArray texture;
18+
[[vk::combinedImageSampler]][[vk::binding(0,3)]] SamplerState samplerState;
19+
#endif
20+
1421
[[vk::push_constant]] push_constants_t pc;
1522

1623
[[vk::location(0)]] float32_t4 main(SVertexAttributes vxAttr) : SV_Target0

24_ColorSpaceTest/app_resources/push_constants.hlsl

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

5+
// Tests for combined and separable image samplers. Make sure exactly one is defined
6+
#define COMBINED_IMMUTABLE
7+
//#define COMBINED_MUTABLE
8+
//#define SEPARATED_IMMUTABLE
9+
//#define SEPARATED_MUTABLE
10+
511
struct push_constants_t
612
{
713
uint16_t2 grid;

24_ColorSpaceTest/main.cpp

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using namespace asset;
1717
using namespace ui;
1818
using namespace video;
1919

20+
// defines for sampler tests can be found in the file below
2021
#include "app_resources/push_constants.hlsl"
2122

2223

@@ -126,17 +127,47 @@ class ColorSpaceTestSampleApp final : public examples::SimpleWindowedApplication
126127
.AnisotropicFilter = 0
127128
});
128129

129-
const IGPUDescriptorSetLayout::SBinding bindings[1] = {{
130+
#if defined(COMBINED_IMMUTABLE) || defined(COMBINED_MUTABLE)
131+
const IGPUDescriptorSetLayout::SBinding bindings[1] = { {
130132
.binding = 0,
131133
.type = IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER,
132134
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
133135
.stageFlags = IShader::ESS_FRAGMENT,
134136
.count = 1,
135-
.samplers = &defaultSampler
136-
}};
137+
#if defined(COMBINED_IMMUTABLE)
138+
.immutableSamplers = &defaultSampler
139+
#else
140+
.immutableSamplers = nullptr
141+
#endif
142+
}
143+
};
144+
#else
145+
const IGPUDescriptorSetLayout::SBinding bindings[2] = { {
146+
.binding = 0,
147+
.type = IDescriptor::E_TYPE::ET_SAMPLED_IMAGE,
148+
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
149+
.stageFlags = IShader::ESS_FRAGMENT,
150+
.count = 1,
151+
.immutableSamplers = nullptr
152+
},
153+
{
154+
.binding = 1,
155+
.type = IDescriptor::E_TYPE::ET_SAMPLER,
156+
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
157+
.stageFlags = IShader::ESS_FRAGMENT,
158+
.count = 1,
159+
#if defined(SEPARATED_IMMUTABLE)
160+
.immutableSamplers = &defaultSampler
161+
#else
162+
.immutableSamplers = nullptr
163+
#endif
164+
}
165+
};
166+
#endif
137167
dsLayout = m_device->createDescriptorSetLayout(bindings);
138168
if (!dsLayout)
139169
return logFail("Failed to Create Descriptor Layout");
170+
140171
}
141172

142173
ISwapchain::SCreationParams swapchainParams = {.surface=m_surface->getSurface()};
@@ -257,6 +288,12 @@ class ColorSpaceTestSampleApp final : public examples::SimpleWindowedApplication
257288
// We do a very simple thing, display an image and wait `DisplayImageMs` to show it
258289
inline void workLoopBody() override
259290
{
291+
// Make the sampler persist in the workloopbody
292+
#if defined(COMBINED_MUTABLE) || defined(SEPARATED_MUTABLE)
293+
static auto defaultSampler = m_device->createSampler({
294+
.AnisotropicFilter = 0
295+
});
296+
#endif
260297
// load the image view
261298
system::path filename, extension;
262299
smart_refctd_ptr<ICPUImageView> cpuImgView;
@@ -390,13 +427,36 @@ class ColorSpaceTestSampleApp final : public examples::SimpleWindowedApplication
390427
info.desc = m_device->createImageView(std::move(viewParams));
391428
}
392429

430+
#if defined(COMBINED_IMMUTABLE) || defined(COMBINED_MUTABLE) || defined(SEPARATED_IMMUTABLE)
431+
#if defined(COMBINED_MUTABLE)
432+
info.info.image.sampler = defaultSampler;
433+
#endif
393434
const IGPUDescriptorSet::SWriteDescriptorSet writes[] = {{
394435
.dstSet = ds,
395436
.binding = 0,
396437
.arrayElement = 0,
397438
.count = 1,
398439
.info = &info
399440
}};
441+
#else
442+
IGPUDescriptorSet::SDescriptorInfo samplerInfo = {};
443+
samplerInfo.desc = defaultSampler;
444+
samplerInfo.info.image.sampler = defaultSampler;
445+
const IGPUDescriptorSet::SWriteDescriptorSet writes[] = { {
446+
.dstSet = ds,
447+
.binding = 0,
448+
.arrayElement = 0,
449+
.count = 1,
450+
.info = &info
451+
},
452+
{
453+
.dstSet = ds,
454+
.binding = 1,
455+
.arrayElement = 0,
456+
.count = 1,
457+
.info = &samplerInfo
458+
}};
459+
#endif
400460
m_device->updateDescriptorSets(writes,{});
401461
}
402462

62_CAD/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,14 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
589589
descriptorInfosSet0[3u].desc = drawResourcesFiller.gpuDrawBuffers.lineStylesBuffer;
590590

591591
descriptorInfosSet0[4u].info.image.imageLayout = IImage::LAYOUT::READ_ONLY_OPTIMAL;
592-
descriptorInfosSet0[4u].info.image.sampler = msdfTextureSampler;
592+
descriptorInfosSet0[4u].info.combinedImageSampler.sampler = msdfTextureSampler;
593593
descriptorInfosSet0[4u].desc = drawResourcesFiller.getMSDFsTextureArray();
594594

595595
// Descriptors For Set 1:
596596
constexpr uint32_t DescriptorCountSet1 = 1u;
597597
video::IGPUDescriptorSet::SDescriptorInfo descriptorInfosSet1[DescriptorCountSet0] = {};
598598
descriptorInfosSet1[0u].info.image.imageLayout = IImage::LAYOUT::GENERAL;
599-
descriptorInfosSet1[0u].info.image.sampler = nullptr;
599+
descriptorInfosSet1[0u].info.combinedImageSampler.sampler = nullptr;
600600
descriptorInfosSet1[0u].desc = pseudoStencilImageView;
601601

602602
constexpr uint32_t DescriptorUpdatesCount = DescriptorCountSet0 + DescriptorCountSet1;

0 commit comments

Comments
 (0)