Skip to content

Commit 8b659d4

Browse files
authored
Merge pull request #123 from Devsh-Graphics-Programming/07_fix
Fixed 07 and 24
2 parents dd466f6 + 78b345d commit 8b659d4

File tree

4 files changed

+18
-77
lines changed

4 files changed

+18
-77
lines changed

07_StagingAndMultipleQueues/main.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,6 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
379379
m_histogramBufferMemPtrs[2] = m_histogramBufferMemPtrs[1] + HISTOGRAM_SIZE;
380380
}
381381

382-
// TODO: Remove stuff below
383-
IGPUSampler::SParams samplerParams;
384-
samplerParams.AnisotropicFilter = false;
385-
core::smart_refctd_ptr<IGPUSampler> sampler = m_device->createSampler(samplerParams);
386-
387382
IGPUDescriptorSet::SDescriptorInfo bufInfo;
388383
bufInfo.desc = smart_refctd_ptr(histogramBuffer);
389384
bufInfo.info.buffer = { .offset = 0u, .size = histogramBuffer->getSize() };

24_ColorSpaceTest/app_resources/present.frag.hlsl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ using namespace nbl::hlsl::ext::FullScreenTriangle;
1010

1111
#include "push_constants.hlsl"
1212

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
13+
14+
[[vk::combinedImageSampler]][[vk::binding(0,3)]] Texture2DArray texture;
15+
[[vk::combinedImageSampler]][[vk::binding(0,3)]] SamplerState samplerState;
16+
2017

2118
[[vk::push_constant]] push_constants_t pc;
2219

24_ColorSpaceTest/app_resources/push_constants.hlsl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +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-
// 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-
115
struct push_constants_t
126
{
137
uint16_t2 grid;

24_ColorSpaceTest/main.cpp

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -120,50 +120,28 @@ class ColorSpaceTestSampleApp final : public examples::SimpleWindowedApplication
120120
if (!m_semaphore)
121121
return logFail("Failed to Create a Semaphore!");
122122

123-
// create the descriptor sets layout
123+
/*
124+
* We'll be using a combined image sampler for this example, which lets us assign both a sampled image and a sampler to the same binding.
125+
* In this example we provide a sampler at descriptor set creation time, via the SBinding struct below. This specifies that the sampler for this binding is immutable,
126+
* as evidenced by the name of the field in the SBinding.
127+
* Samplers for combined image samplers can also be mutable, which for a binding of a descriptor set is specified also at creation time by leaving the immutableSamplers
128+
* field set to its default (nullptr).
129+
*/
124130
smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout;
125131
{
126132
auto defaultSampler = m_device->createSampler({
127133
.AnisotropicFilter = 0
128134
});
129135

130-
#if defined(COMBINED_IMMUTABLE) || defined(COMBINED_MUTABLE)
131136
const IGPUDescriptorSetLayout::SBinding bindings[1] = { {
132137
.binding = 0,
133138
.type = IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER,
134139
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
135140
.stageFlags = IShader::ESS_FRAGMENT,
136141
.count = 1,
137-
#if defined(COMBINED_IMMUTABLE)
138142
.immutableSamplers = &defaultSampler
139-
#else
140-
.immutableSamplers = nullptr
141-
#endif
142143
}
143144
};
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
167145
dsLayout = m_device->createDescriptorSetLayout(bindings);
168146
if (!dsLayout)
169147
return logFail("Failed to Create Descriptor Layout");
@@ -288,12 +266,6 @@ class ColorSpaceTestSampleApp final : public examples::SimpleWindowedApplication
288266
// We do a very simple thing, display an image and wait `DisplayImageMs` to show it
289267
inline void workLoopBody() override
290268
{
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
297269
// load the image view
298270
system::path filename, extension;
299271
smart_refctd_ptr<ICPUImageView> cpuImgView;
@@ -377,6 +349,13 @@ class ColorSpaceTestSampleApp final : public examples::SimpleWindowedApplication
377349
smart_refctd_ptr<IGPUImage> gpuImg;
378350
auto ds = m_descriptorSets[resourceIx].get();
379351
{
352+
/*
353+
* Since we're using a combined image sampler with an immutable sampler, we only need to update the sampled image at the binding. Do note however that had we chosen
354+
* to use a mutable sampler instead, we'd need to write to it at least once, via the SDescriptorInfo info.info.combinedImageSampler.sampler field
355+
* WARNING: With an immutable sampler on a combined image sampler, trying to write to it is valid according to Vulkan spec, although the sampler is ignored and only
356+
* the image is updated. Please note that this is NOT the case in Nabla: if you try to write to a combined image sampler, then
357+
* info.info.combinedImageSampler.sampler MUST be nullptr
358+
*/
380359
IGPUDescriptorSet::SDescriptorInfo info = {};
381360
info.info.image.imageLayout = IImage::LAYOUT::READ_ONLY_OPTIMAL;
382361
{
@@ -426,37 +405,13 @@ class ColorSpaceTestSampleApp final : public examples::SimpleWindowedApplication
426405
};
427406
info.desc = m_device->createImageView(std::move(viewParams));
428407
}
429-
430-
#if defined(COMBINED_IMMUTABLE) || defined(COMBINED_MUTABLE) || defined(SEPARATED_IMMUTABLE)
431-
#if defined(COMBINED_MUTABLE)
432-
info.info.image.sampler = defaultSampler;
433-
#endif
434408
const IGPUDescriptorSet::SWriteDescriptorSet writes[] = {{
435409
.dstSet = ds,
436410
.binding = 0,
437411
.arrayElement = 0,
438412
.count = 1,
439413
.info = &info
440414
}};
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
460415
m_device->updateDescriptorSets(writes,{});
461416
}
462417

0 commit comments

Comments
 (0)