Skip to content

Commit 4549c25

Browse files
committed
createGPUDescriptorSetLayout_impl use vector instead of stack fixed-length arrays
+ Test ImmutableSamplers on Example-09
1 parent a379e94 commit 4549c25

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

examples_tests/09.ColorSpaceTest/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ class ColorSpaceTestSampleApp : public ApplicationBase
114114
}
115115
};
116116

117-
video::IGPUDescriptorSetLayout::SBinding binding{ 0u, nbl::asset::EDT_COMBINED_IMAGE_SAMPLER, 1u, nbl::video::IGPUShader::ESS_FRAGMENT, nullptr };
117+
nbl::asset::ISampler::SParams samplerParams = { nbl::asset::ISampler::ETC_CLAMP_TO_EDGE, nbl::asset::ISampler::ETC_CLAMP_TO_EDGE, nbl::asset::ISampler::ETC_CLAMP_TO_EDGE, nbl::asset::ISampler::ETBC_FLOAT_OPAQUE_BLACK, nbl::asset::ISampler::ETF_LINEAR, nbl::asset::ISampler::ETF_LINEAR, nbl::asset::ISampler::ESMM_LINEAR, 0u, false, nbl::asset::ECO_ALWAYS };
118+
auto immutableSampler = logicalDevice->createGPUSampler(samplerParams);
119+
120+
video::IGPUDescriptorSetLayout::SBinding binding{ 0u, nbl::asset::EDT_COMBINED_IMAGE_SAMPLER, 1u, nbl::video::IGPUShader::ESS_FRAGMENT, &immutableSampler };
118121
auto gpuDescriptorSetLayout3 = logicalDevice->createGPUDescriptorSetLayout(&binding, &binding + 1u);
119122
auto gpuDescriptorPool = createDescriptorPool(1u); // per single texture
120123
auto fstProtoPipeline = nbl::ext::FullScreenTriangle::createProtoPipeline(cpu2gpuParams);
@@ -299,8 +302,7 @@ class ColorSpaceTestSampleApp : public ApplicationBase
299302
nbl::video::IGPUDescriptorSet::SDescriptorInfo info;
300303
{
301304
info.desc = gpuImageView;
302-
nbl::asset::ISampler::SParams samplerParams = { nbl::asset::ISampler::ETC_CLAMP_TO_EDGE, nbl::asset::ISampler::ETC_CLAMP_TO_EDGE, nbl::asset::ISampler::ETC_CLAMP_TO_EDGE, nbl::asset::ISampler::ETBC_FLOAT_OPAQUE_BLACK, nbl::asset::ISampler::ETF_LINEAR, nbl::asset::ISampler::ETF_LINEAR, nbl::asset::ISampler::ESMM_LINEAR, 0u, false, nbl::asset::ECO_ALWAYS };
303-
info.image.sampler = logicalDevice->createGPUSampler(samplerParams);
305+
info.image.sampler = nullptr;
304306
info.image.imageLayout = nbl::asset::EIL_SHADER_READ_ONLY_OPTIMAL;
305307
}
306308

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,42 +1249,51 @@ class CVulkanLogicalDevice final : public ILogicalDevice
12491249
uint32_t bindingCount = std::distance(_begin, _end);
12501250
assert(bindingCount <= MAX_BINDING_COUNT);
12511251

1252-
uint32_t samplerOffset = 0u;
1253-
VkSampler vk_samplers[MAX_SAMPLER_COUNT_PER_BINDING * MAX_BINDING_COUNT];
1254-
VkDescriptorSetLayoutBinding vk_dsLayoutBindings[MAX_BINDING_COUNT];
1252+
std::vector<VkSampler> vk_samplers;
1253+
std::vector<VkDescriptorSetLayoutBinding> vk_dsLayoutBindings;
12551254

12561255
for (uint32_t b = 0u; b < bindingCount; ++b)
12571256
{
12581257
auto binding = _begin + b;
12591258

1260-
vk_dsLayoutBindings[b].binding = binding->binding;
1261-
vk_dsLayoutBindings[b].descriptorType = static_cast<VkDescriptorType>(binding->type);
1262-
vk_dsLayoutBindings[b].descriptorCount = binding->count;
1263-
vk_dsLayoutBindings[b].stageFlags = static_cast<VkShaderStageFlags>(binding->stageFlags);
1264-
vk_dsLayoutBindings[b].pImmutableSamplers = nullptr;
1259+
VkDescriptorSetLayoutBinding vkDescSetLayoutBinding = {};
1260+
vkDescSetLayoutBinding.binding = binding->binding;
1261+
vkDescSetLayoutBinding.descriptorType = static_cast<VkDescriptorType>(binding->type);
1262+
vkDescSetLayoutBinding.descriptorCount = binding->count;
1263+
vkDescSetLayoutBinding.stageFlags = static_cast<VkShaderStageFlags>(binding->stageFlags);
1264+
vkDescSetLayoutBinding.pImmutableSamplers = nullptr;
12651265

1266-
if (binding->samplers)
1266+
if (binding->samplers && binding->count > 0u)
12671267
{
1268+
// If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount is not 0 and pImmutableSamplers is not NULL:
1269+
// pImmutableSamplers must be a valid pointer to an array of descriptorCount valid VkSampler handles.
1270+
12681271
assert(binding->count <= MAX_SAMPLER_COUNT_PER_BINDING);
1272+
const uint32_t samplerOffset = vk_samplers.size();
12691273

12701274
for (uint32_t i = 0u; i < binding->count; ++i)
12711275
{
1272-
if (binding->samplers[i]->getAPIType() != EAT_VULKAN)
1276+
if (binding->samplers[i]->getAPIType() != EAT_VULKAN) {
1277+
assert(false);
1278+
vk_samplers.push_back(VK_NULL_HANDLE); // To get validation errors on Release Builds
12731279
continue;
1280+
}
12741281

1275-
vk_samplers[samplerOffset + i] = static_cast<const CVulkanSampler*>(binding->samplers[i].get())->getInternalObject();
1282+
VkSampler vkSampler = static_cast<const CVulkanSampler*>(binding->samplers[i].get())->getInternalObject();
1283+
vk_samplers.push_back(vkSampler);
12761284
}
12771285

1278-
vk_dsLayoutBindings[b].pImmutableSamplers = vk_samplers + samplerOffset;
1279-
samplerOffset += binding->count;
1286+
vkDescSetLayoutBinding.pImmutableSamplers = vk_samplers.data() + samplerOffset;
12801287
}
1288+
1289+
vk_dsLayoutBindings.push_back(vkDescSetLayoutBinding);
12811290
}
12821291

12831292
VkDescriptorSetLayoutCreateInfo vk_createInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO };
12841293
vk_createInfo.pNext = nullptr; // Each pNext member of any structure (including this one) in the pNext chain must be either NULL or a pointer to a valid instance of VkDescriptorSetLayoutBindingFlagsCreateInfo or VkMutableDescriptorTypeCreateInfoVALVE
12851294
vk_createInfo.flags = 0; // Todo(achal): I would need to create a IDescriptorSetLayout::SCreationParams for this
1286-
vk_createInfo.bindingCount = bindingCount;
1287-
vk_createInfo.pBindings = vk_dsLayoutBindings;
1295+
vk_createInfo.bindingCount = vk_dsLayoutBindings.size();
1296+
vk_createInfo.pBindings = vk_dsLayoutBindings.data();
12881297

12891298
VkDescriptorSetLayout vk_dsLayout;
12901299
if (m_devf.vk.vkCreateDescriptorSetLayout(m_vkdev, &vk_createInfo, nullptr, &vk_dsLayout) == VK_SUCCESS)

0 commit comments

Comments
 (0)