Skip to content

Commit efabef6

Browse files
committed
Modified ex 24 to test separable samplers and added conditional compilation for deifferent tests as defines in push_constants.hlsl
1 parent f91ccdc commit efabef6

File tree

4 files changed

+83
-10
lines changed

4 files changed

+83
-10
lines changed

07_StagingAndMultipleQueues/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
272272
const nbl::video::IGPUDescriptorSetLayout::SBinding bindings[2] = {
273273
{
274274
.binding = 0,
275-
.type = nbl::asset::IDescriptor::E_TYPE::ET_SAMPLED_IMAGE, // 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,
@@ -379,10 +379,10 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
379379
m_histogramBufferMemPtrs[2] = m_histogramBufferMemPtrs[1] + HISTOGRAM_SIZE;
380380
}
381381

382-
// TODO: Remove commented stuff below
383-
/*IGPUSampler::SParams samplerParams;
382+
// TODO: Remove stuff below
383+
IGPUSampler::SParams samplerParams;
384384
samplerParams.AnisotropicFilter = false;
385-
core::smart_refctd_ptr<IGPUSampler> sampler = m_device->createSampler(samplerParams);*/
385+
core::smart_refctd_ptr<IGPUSampler> sampler = m_device->createSampler(samplerParams);
386386

387387
IGPUDescriptorSet::SDescriptorInfo bufInfo;
388388
bufInfo.desc = smart_refctd_ptr(histogramBuffer);
@@ -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 = nullptr, .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: 62 additions & 2 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,
137+
#if defined(COMBINED_IMMUTABLE)
135138
.samplers = &defaultSampler
136-
}};
139+
#else
140+
.samplers = 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+
.samplers = 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+
.samplers = &defaultSampler
161+
#else
162+
.samplers = 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

0 commit comments

Comments
 (0)