Hi,
until now I was not using VkDescriptorSetLayoutBinding.pImmutableSamplers and always took the way via DescriptorSets to set them.
Now using VkDescriptorSetLayoutBinding.pImmutableSamplers with a single VkSampler pointer creates no problem at all, but I have a TextureCube[3] in one of my shaders and setting pImmutableSamplers to an array of VkSampler’s seems to create havok within Vulkan and crashes my program in total random locations every time I execute it.
I assume an buffer overflow or another pointer problem, but I cant find the source.
The pointer to the first VkSampler-Array element is valid at all times. I even added a NULL element at the end.
Is there an open, known bug in that direction?
Code:
class Vulkan::DescriptorSetLayout {
/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
/*//////// Variables //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
private:
VkDescriptorSetLayout _vkDescriptorSetLayout = VK_NULL_HANDLE;
VkDescriptorSetLayoutCreateInfo vkDescriptorSetLayoutCreateInfo = {};
std::vector<VkDescriptorSetLayoutBinding> vkDescriptorSetLayoutBindings;
std::vector<VkSampler> _vkSamplers;
public:
const std::shared_ptr<Vulkan::LogicalDevice> logicalDevice;
const VkDescriptorSetLayout& vkDescriptorSetLayout = _vkDescriptorSetLayout;
const std::vector<VkSampler>& vkSamplers = _vkSamplers;
/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
/*//////// Functions //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
public:
DescriptorSetLayout(const std::shared_ptr<Vulkan::LogicalDevice>& logicaldevice, VkDescriptorSetLayoutCreateFlags flags = 0) : logicalDevice(logicaldevice) {
vkDescriptorSetLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
vkDescriptorSetLayoutCreateInfo.flags = flags;
}
~DescriptorSetLayout() {
if (vkDescriptorSetLayout != VK_NULL_HANDLE) vkDestroyDescriptorSetLayout(logicalDevice->vkLogicalDevice, vkDescriptorSetLayout, NULL);
}
/* Controller */
/*-------------------------------------------------------------------------------------------------------------------------------------------------*/
public:
void Initialize() {
if (vkDescriptorSetLayout != VK_NULL_HANDLE) vkDestroyDescriptorSetLayout(logicalDevice->vkLogicalDevice, vkDescriptorSetLayout, NULL);
if (vkCreateDescriptorSetLayout(logicalDevice->vkLogicalDevice, &vkDescriptorSetLayoutCreateInfo, NULL, &_vkDescriptorSetLayout) != VK_SUCCESS)
throw "Vulkan::DescriptorSetLayout.Initialize():
Failed to create Vulkan descriptor Set layout.
";
}
void SetImmutableSamplers(const std::vector<VkSampler>& vksamplers) { _vkSamplers = vksamplers; }
void SetBindings(const std::vector<VkDescriptorSetLayoutBinding> vkdescriptorsetlayoutbinding) {
vkDescriptorSetLayoutBindings = vkdescriptorsetlayoutbinding;
vkDescriptorSetLayoutCreateInfo.bindingCount = (uint32)vkDescriptorSetLayoutBindings.size();
vkDescriptorSetLayoutCreateInfo.pBindings = vkDescriptorSetLayoutBindings.data();
}
};
static std::shared_ptr<Utilities::Vulkan::DescriptorSetLayout> CreateDescriptorSetLayout(const std::shared_ptr<Utilities::Vulkan::LogicalDevice>& logicaldevice,
const std::shared_ptr<Utilities::Vulkan::Sampler>& sampler)
{
std::shared_ptr<Utilities::Vulkan::DescriptorSetLayout> descriptorsetlayout(new Utilities::Vulkan::DescriptorSetLayout(logicaldevice));
descriptorsetlayout->SetImmutableSamplers({ sampler->vkSampler, sampler->vkSampler, sampler->vkSampler, NULL });
descriptorsetlayout->SetBindings({
CreateTextureDescriptorSetLayoutBinding(BindingIndexes::uAlbedoTexture, &sampler->vkSampler),
CreateTextureDescriptorSetLayoutBinding(BindingIndexes::uSpecularEmissionTexture, &sampler->vkSampler),
CreateTextureDescriptorSetLayoutBinding(BindingIndexes::uNormalGlossTexture, &sampler->vkSampler),
CreateTextureDescriptorSetLayoutBinding(BindingIndexes::uDiffuseEnvironmentTextureCube, descriptorsetlayout->vkSamplers.data(), MAX_ENVIRONMENTS),//descriptorsetlayout->vkSamplers.data()
CreateTextureDescriptorSetLayoutBinding(BindingIndexes::uSpecularPrefilteredEnvironmentTextureCube, NULL, MAX_ENVIRONMENTS)
});
descriptorsetlayout->Initialize();
return descriptorsetlayout;
}
private:
static VkDescriptorSetLayoutBinding CreateTextureDescriptorSetLayoutBinding(uint32 bindingindex, const VkSampler* samplers, uint32 descriptorcount = 1) {
VkDescriptorSetLayoutBinding result = {};
result.binding = bindingindex;
result.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
result.descriptorCount = descriptorcount;
result.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
result.pImmutableSamplers = samplers;
return result;
}
sampler as well as descriptorsetlayout are saved in a higher context and are valid at all times after their creation.
Do you have any idea?