Results 1 to 3 of 3

Thread: Possible pImmutableSamplers Error(?)

  1. #1
    Junior Member Habor1's Avatar
    Join Date
    Jul 2017
    Posts
    5

    Possible pImmutableSamplers Error(?)

    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:
    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():\n Failed to create Vulkan descriptor Set layout.\n\n";
    	}
     
            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();
    	}
    };

    Code :
        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?
    Last edited by Habor1; 09-29-2017 at 12:12 PM.

  2. #2
    Senior Member
    Join Date
    Mar 2016
    Posts
    227
    You are not allowed to use NULL as an element of pImmutableSamplers.

    What is MAX_ENVIRONMENTS?
    Last edited by krOoze; 09-29-2017 at 02:30 PM.

  3. #3
    Junior Member Habor1's Avatar
    Join Date
    Jul 2017
    Posts
    5
    Yes, the NULL was just an experiment since MAX_ENVIRONMENTS is just 3 and NULL is the 4th element.
    It doesnt make any difference.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean