Device lost after descriptor recreation. (Driver bug ?)

Hi! the vkWaitForFence function after the vkSubmit, return the code error (-4), it happens after I recreate the descriptors when I try to add a new render component with my editor. (It doesn’t crash with the validation layers enabled when it runs slower so I guess the driver try to access to a wrong descriptor even when adding vkDeviceWaitIdle…

window::Device::QueueFamilyIndices indices = vkDevice.findQueueFamilies(vkDevice.getPhysicalDevice(), nullptr);
if (vkQueueSubmit(vkDevice.getQueue(indices.graphicsFamily.value(), queueIndex), 1, &submitInfo, (fenceToSubmit == nullptr) ? inFlightFences[currentFrame] : fenceToSubmit) != VK_SUCCESS) {
throw core::Erreur(0, “échec de l’envoi d’un command buffer!”, 1);
}
std::cout<<"wait on fence : "<<inFlightFences[currentFrame]<<std::endl;
VkResult r = vkWaitForFences(vkDevice.getDevice(), 1, (fenceToSubmit == nullptr) ? &inFlightFences[currentFrame] : &fenceToSubmit, VK_TRUE, UINT64_MAX);
printf(“wait for fence result : %d\n”, r);

In fact I need to recreate the descriptors of every renderers when I add new resources like shaders otherwise I’ve errors. I’ve ids for shader which point to a specific descriptor, and even sometimes a topology index because I use different buffers depending on the topology. I also have different pipelines that I also recreate when I add resources like shaders. Here is where I create/recreate the pipelines :

void RenderTarget::createGraphicPipeline(PrimitiveType type,
                      RenderStates states, unsigned int depthStencilId, unsigned int nbDepthStencil, unsigned int id) {
            Shader* shader = const_cast<Shader*>(states.shader);
            states.blendMode.updateIds();
            //system("PAUSE");

            unsigned int blendModeId = states.blendMode.id;
            unsigned int nbBlendMode = states.blendMode.nbBlendModes;
            if ((Batcher::nbPrimitiveTypes - 1) * shader->getNbShaders() > graphicsPipeline.size()) {
                graphicsPipeline.resize((Batcher::nbPrimitiveTypes - 1) * shader->getNbShaders());
                pipelineLayoutInfo.resize((Batcher::nbPrimitiveTypes - 1) * shader->getNbShaders());
                pipelineLayout.resize((Batcher::nbPrimitiveTypes - 1) * shader->getNbShaders());
                depthStencil.resize((Batcher::nbPrimitiveTypes - 1) * shader->getNbShaders());
            }
            for (unsigned int i = 0; i < (Batcher::nbPrimitiveTypes - 1) * shader->getNbShaders(); i++) {
                if ((id + 1) > graphicsPipeline[i].size()) {
                    graphicsPipeline[i].resize(id+1);
                    pipelineLayoutInfo[i].resize(id+1);
                    pipelineLayout[i].resize(id+1);
                    depthStencil[i].resize(id+1);
                }
            }
            for (unsigned int i = 0; i < (Batcher::nbPrimitiveTypes - 1) * shader->getNbShaders(); i++) {
                for (unsigned int j = 0; j < (id + 1); j++) {
                    if (nbDepthStencil * nbBlendMode > graphicsPipeline[i][j].size()) {
                        graphicsPipeline[i][j].resize(nbDepthStencil*nbBlendMode);
                        pipelineLayoutInfo[i][j].resize(nbDepthStencil*nbBlendMode);
                        pipelineLayout[i][j].resize(nbDepthStencil*nbBlendMode);
                        depthStencil[i][j].resize(nbDepthStencil*nbBlendMode);
                    }
                }
            }

            unsigned int descriptorId = shader->getId();
            //std::cout<<"descriptor set layout id : "<<descriptorId<<std::endl;


            ////////std::cout<<"rt dl size : "<<descriptorSetLayout.size()<<std::endl;
            /*//////std::cout<<"descriptor id : "<<descriptorId<<std::endl;*/
            ////////std::cout<<"pipeline id : "<<pipelineId<<std::endl;


            /*for (unsigned int i = 0; i < pipelinesId.size(); i++) {
                if (pipelinesId[i] == pipelineId) {
                    //////std::cout<<"Erreur"<<std::endl;
                    system("PAUSE");
                }
            }
            pipelinesId.push_back(pipelineId);*/

            VkShaderModule vertShaderModule;
            VkShaderModule fragShaderModule;
            VkShaderModule geomShaderModule=nullptr;

            if (states.shader == nullptr) {
                defaultShader.createShaderModules();
                vertShaderModule = defaultShader.getVertexShaderModule();
                fragShaderModule = defaultShader.getFragmentShaderModule();
                states.shader = &defaultShader;
            } else {
                shader->createShaderModules();
                vertShaderModule = shader->getVertexShaderModule();
                fragShaderModule = shader->getFragmentShaderModule();
                if (shader->getGeometryShaderModule() != nullptr) {
                    geomShaderModule = shader->getGeometryShaderModule();
                }
            }

            std::vector<VkPipelineShaderStageCreateInfo> shaderStages;

            if (geomShaderModule == nullptr) {
                VkPipelineShaderStageCreateInfo vertShaderStageInfo{};
                vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
                vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
                vertShaderStageInfo.module = vertShaderModule;
                vertShaderStageInfo.pName = "main";

                VkPipelineShaderStageCreateInfo fragShaderStageInfo{};
                fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
                fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
                fragShaderStageInfo.module = fragShaderModule;
                fragShaderStageInfo.pName = "main";

                shaderStages = {vertShaderStageInfo, fragShaderStageInfo};
            } else {
                VkPipelineShaderStageCreateInfo vertShaderStageInfo{};
                vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
                vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
                vertShaderStageInfo.module = vertShaderModule;
                vertShaderStageInfo.pName = "main";

                VkPipelineShaderStageCreateInfo fragShaderStageInfo{};
                fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
                fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
                fragShaderStageInfo.module = fragShaderModule;
                fragShaderStageInfo.pName = "main";

                VkPipelineShaderStageCreateInfo geomShaderStageInfo{};
                geomShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
                geomShaderStageInfo.stage = VK_SHADER_STAGE_GEOMETRY_BIT;
                geomShaderStageInfo.module = geomShaderModule;
                geomShaderStageInfo.pName = "main";

                shaderStages = {vertShaderStageInfo, fragShaderStageInfo, geomShaderStageInfo};
            }

            VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
            auto bindingDescription = Vertex::getBindingDescription();
            auto attributeDescriptions = Vertex::getAttributeDescriptions();
            vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
            vertexInputInfo.vertexBindingDescriptionCount = 1;
            vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size());
            vertexInputInfo.pVertexBindingDescriptions = &bindingDescription;
            vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();


            VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
            inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
            VkPrimitiveTopology modes[] = {VK_PRIMITIVE_TOPOLOGY_POINT_LIST, VK_PRIMITIVE_TOPOLOGY_LINE_LIST, VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN};

            inputAssembly.topology = modes[type];
            inputAssembly.primitiveRestartEnable =
            (inputAssembly.topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP ||
             inputAssembly.topology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ||
             inputAssembly.topology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN)
            ? VK_TRUE : VK_FALSE;



            VkPipelineViewportStateCreateInfo viewportState{};
            viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
            viewportState.viewportCount = viewports.size();
            //viewportState.pViewports = &viewport;
            viewportState.scissorCount = scissors.size();
            //viewportState.pScissors = &scissor;
            std::vector<VkDynamicState> dynamicStates = {
            VK_DYNAMIC_STATE_VIEWPORT,
            VK_DYNAMIC_STATE_SCISSOR
            };
            VkPipelineDynamicStateCreateInfo dynamicState{};
            dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
            dynamicState.dynamicStateCount = static_cast<uint32_t>(dynamicStates.size());
            dynamicState.pDynamicStates = dynamicStates.data();

            VkPipelineRasterizationStateCreateInfo rasterizer{};
            rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
            rasterizer.depthClampEnable = VK_FALSE;
            rasterizer.rasterizerDiscardEnable = VK_FALSE;
            rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
            rasterizer.lineWidth = 1.0f;
            if (cm == NONE)
                rasterizer.cullMode = VK_CULL_MODE_NONE;
            else if (cm == FRONT)
                rasterizer.cullMode = VK_CULL_MODE_FRONT_BIT;
            else if (cm == BACK)
                rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
            else
                rasterizer.cullMode = VK_CULL_MODE_FRONT_AND_BACK;
            rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;
            rasterizer.depthBiasEnable = VK_FALSE;

            VkPipelineMultisampleStateCreateInfo multisampling{};
            multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
            multisampling.sampleShadingEnable = VK_FALSE;
            multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;

            VkPipelineColorBlendAttachmentState colorBlendAttachment{};
            colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
            colorBlendAttachment.blendEnable = VK_TRUE;


            colorBlendAttachment.srcColorBlendFactor = factorToVkConstant(states.blendMode.colorSrcFactor);
            colorBlendAttachment.dstColorBlendFactor = factorToVkConstant(states.blendMode.colorDstFactor);
            colorBlendAttachment.colorBlendOp = equationToVkConstant(states.blendMode.colorEquation);


            colorBlendAttachment.srcAlphaBlendFactor = factorToVkConstant(states.blendMode.alphaSrcFactor);
            colorBlendAttachment.dstAlphaBlendFactor = factorToVkConstant(states.blendMode.alphaDstFactor);
            colorBlendAttachment.alphaBlendOp = equationToVkConstant(states.blendMode.alphaEquation);

            VkPipelineColorBlendStateCreateInfo colorBlending{};
            colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
            colorBlending.logicOpEnable = VK_FALSE;
            colorBlending.logicOp = VK_LOGIC_OP_COPY;
            colorBlending.attachmentCount = 1;
            colorBlending.pAttachments = &colorBlendAttachment;
            colorBlending.blendConstants[0] = 0.0f;
            colorBlending.blendConstants[1] = 0.0f;
            colorBlending.blendConstants[2] = 0.0f;
            colorBlending.blendConstants[3] = 0.0f;



            pipelineLayoutInfo[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
            pipelineLayoutInfo[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].setLayoutCount = descriptorSetLayout[descriptorId].size();
            pipelineLayoutInfo[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].pSetLayouts = descriptorSetLayout[descriptorId].data();

            //std::cout<<"ids : "<<shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type<<","<<id<<","<<depthStencilId*nbBlendMode+blendModeId<<std::endl;
            if (pipelineLayout[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId] != nullptr) {
                //std::cout<<"destroy pipeline layout ids : "<<shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type<<","<<id<<","<<depthStencilId*nbBlendMode+blendModeId<<std::endl;
                vkDestroyPipelineLayout(vkDevice.getDevice(), pipelineLayout[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId], nullptr);
            }
            /*std::cout<<"create pipeline layout ids : "<<shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type<<","<<id<<","<<depthStencilId*nbBlendMode+blendModeId<<std::endl;
            std::cout<<"sizes : "<<pipelineLayout.size()<<","<<pipelineLayout[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type].size()<<","<<pipelineLayout[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id].size()<<std::endl;*/
            if (vkCreatePipelineLayout(vkDevice.getDevice(), &pipelineLayoutInfo[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId], nullptr, &pipelineLayout[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId]) != VK_SUCCESS) {

                throw core::Erreur(0, "failed to create pipeline layout!", 1);
            }
            ////////std::cout<<"pipeline layout : "<<pipelineLayout[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId]<<std::endl;

            depthStencil[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
            depthStencil[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].depthTestEnable = (depthTestEnabled) ? VK_TRUE : VK_FALSE;
            depthStencil[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].depthBoundsTestEnable = VK_FALSE;
            depthStencil[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].minDepthBounds = 0.0f; // Optional
            depthStencil[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].maxDepthBounds = 1.0f; // Optional
            depthStencil[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].stencilTestEnable = (stencilTestEnabled) ? VK_TRUE : VK_FALSE;
            /*if (depthStencil[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId].depthTestEnable  == VK_TRUE)
                //std::cout<<"depth test enabled"<<std::endl;*/



            VkGraphicsPipelineCreateInfo pipelineInfo{};
            pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
            pipelineInfo.stageCount = shaderStages.size();
            pipelineInfo.pStages = shaderStages.data();
            pipelineInfo.pVertexInputState = &vertexInputInfo;
            pipelineInfo.pInputAssemblyState = &inputAssembly;
            pipelineInfo.pViewportState = &viewportState;
            pipelineInfo.pRasterizationState = &rasterizer;
            pipelineInfo.pMultisampleState = &multisampling;
            pipelineInfo.pColorBlendState = &colorBlending;
            pipelineInfo.pDynamicState = &dynamicState;
            pipelineInfo.layout = pipelineLayout[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId];
            /*if (getSurface() != VK_NULL_HANDLE)
                //////std::cout<<"render pass ppl rw : "<<getRenderPass()<<std::endl;
            else
                //////std::cout<<"render pass ppl rt : "<<getRenderPass()<<std::endl;*/
            pipelineInfo.renderPass = (depthTestEnabled || stencilTestEnabled) ? getRenderPass(1) : getRenderPass(0);
            pipelineInfo.subpass = 0;
            pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
            pipelineInfo.pDepthStencilState = &depthStencil[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId];
            if (graphicsPipeline[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId] != nullptr) {
                //std::cout<<"destroy pipeline"<<std::endl;
                vkDestroyPipeline(vkDevice.getDevice(), graphicsPipeline[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId], nullptr);

            }
            /*std::cout<<"create graphics pipeline ids : "<<(shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type)<<","<<id<<","<<(depthStencilId*nbBlendMode+blendModeId)<<std::endl;
            std::cout<<"sizes : "<<graphicsPipeline.size()<<","<<graphicsPipeline[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type].size()<<","<<graphicsPipeline[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id].size()<<std::endl;*/
            if (vkCreateGraphicsPipelines(vkDevice.getDevice(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline[shader->getId() * (Batcher::nbPrimitiveTypes - 1)+type][id][depthStencilId*nbBlendMode+blendModeId]) != VK_SUCCESS) {
                throw core::Erreur(0, "failed to create graphics pipeline!", 1);
            }
            shader->cleanupShaderModules();
        }

And in my other renderer which use the main renderer I update the descriptors like this :

void PerPixelLinkedListRenderComponent::createDescriptorPool(unsigned int p, RenderStates states) {
            std::vector<std::vector<VkDescriptorPool>>& descriptorPool = frameBuffer.getDescriptorPool();
            Shader* shader = const_cast<Shader*>(states.shader);
            if (shader == &indirectRenderingShader) {
                unsigned int descriptorId = p * shader->getNbShaders() + shader->getId();
                if (shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1) > descriptorPool.size())
                    descriptorPool.resize(shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1));
                descriptorPool[descriptorId].resize(1);
                std::array<VkDescriptorPoolSize, 6> poolSizes;
                poolSizes[0].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                poolSizes[0].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                poolSizes[1].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
                poolSizes[1].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                poolSizes[2].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                poolSizes[2].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                poolSizes[3].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
                poolSizes[3].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                poolSizes[4].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
                poolSizes[4].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                poolSizes[5].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                poolSizes[5].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight() * MAX_TEXTURES);

                if (descriptorPool[descriptorId][0] != nullptr) {
                    vkDestroyDescriptorPool(vkDevice.getDevice(), descriptorPool[descriptorId][0], nullptr);
                }
                VkDescriptorPoolCreateInfo poolInfo{};
                poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
                poolInfo.poolSizeCount = static_cast<uint32_t>(poolSizes.size());
                poolInfo.pPoolSizes = poolSizes.data();
                poolInfo.maxSets = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                if (vkCreateDescriptorPool(vkDevice.getDevice(), &poolInfo, nullptr, &descriptorPool[descriptorId][0]) != VK_SUCCESS) {
                    throw std::runtime_error("echec de la creation de la pool de descripteurs!");
                }
            } else if (shader == &perPixelLinkedListP2) {
                if (shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1) > descriptorPool.size())
                    descriptorPool.resize(shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1));
                unsigned int descriptorId =  p * shader->getNbShaders() + shader->getId();
                descriptorPool[descriptorId].resize(1);
                std::array<VkDescriptorPoolSize, 2> poolSizes{};
                poolSizes[0].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
                poolSizes[0].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                poolSizes[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                poolSizes[1].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());

                if (descriptorPool[descriptorId][0] != nullptr) {
                    vkDestroyDescriptorPool(vkDevice.getDevice(), descriptorPool[descriptorId][0], nullptr);
                }


                VkDescriptorPoolCreateInfo poolInfo{};
                poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
                poolInfo.poolSizeCount = static_cast<uint32_t>(poolSizes.size());
                poolInfo.pPoolSizes = poolSizes.data();
                poolInfo.maxSets = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                if (vkCreateDescriptorPool(vkDevice.getDevice(), &poolInfo, nullptr, &descriptorPool[descriptorId][0]) != VK_SUCCESS) {
                    throw std::runtime_error("echec de la creation de la pool de descripteurs!");
                }
            } else {
                unsigned int descriptorId = p * shader->getNbShaders() + shader->getId();
                if (shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1) > descriptorPool.size())
                    descriptorPool.resize(shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1));
                descriptorPool[descriptorId].resize(1);
                std::array<VkDescriptorPoolSize, 1> poolSizes;
                poolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                poolSizes[0].descriptorCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                if (descriptorPool[descriptorId][0] != nullptr) {
                    vkDestroyDescriptorPool(vkDevice.getDevice(), descriptorPool[descriptorId][0], nullptr);
                }
                VkDescriptorPoolCreateInfo poolInfo{};
                poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
                poolInfo.poolSizeCount = static_cast<uint32_t>(poolSizes.size());
                poolInfo.pPoolSizes = poolSizes.data();
                poolInfo.maxSets = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                if (vkCreateDescriptorPool(vkDevice.getDevice(), &poolInfo, nullptr, &descriptorPool[descriptorId][0]) != VK_SUCCESS) {
                    throw std::runtime_error("echec de la creation de la pool de descripteurs!");
                }
            }
        }
 void PerPixelLinkedListRenderComponent::createDescriptorSetLayout(RenderStates states) {
            std::vector<std::vector<VkDescriptorSetLayout>>& descriptorSetLayout = frameBuffer.getDescriptorSetLayout();
            Shader* shader = const_cast<Shader*>(states.shader);
            if (shader == &indirectRenderingShader) {
                if (shader->getNbShaders() > descriptorSetLayout.size())
                    descriptorSetLayout.resize(shader->getNbShaders());
                unsigned int descriptorId = shader->getId();
                descriptorSetLayout[descriptorId].resize(1);
                ////////std::cout<<"ppll descriptor id : "<<descriptorId<<std::endl;
                std::vector<Texture*> allTextures = Texture::getAllTextures();
                VkDescriptorSetLayoutBinding counterLayoutBinding{};
                counterLayoutBinding.binding = 0;
                counterLayoutBinding.descriptorCount = 1;
                counterLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                counterLayoutBinding.pImmutableSamplers = nullptr;
                counterLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;

                VkDescriptorSetLayoutBinding headPtrImageLayoutBinding;
                headPtrImageLayoutBinding.binding = 1;
                headPtrImageLayoutBinding.descriptorCount = 1;
                headPtrImageLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
                headPtrImageLayoutBinding.pImmutableSamplers = nullptr;
                headPtrImageLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;

                VkDescriptorSetLayoutBinding linkedListLayoutBinding{};
                linkedListLayoutBinding.binding = 2;
                linkedListLayoutBinding.descriptorCount = 1;
                linkedListLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                linkedListLayoutBinding.pImmutableSamplers = nullptr;
                linkedListLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;

                std::vector<VkDescriptorBindingFlags> bindingFlags(6, 0); // 6 bindings, flags par défaut à 0
                bindingFlags[5] = VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT |
                      VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT; // seulement pour sampler[]

                VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsInfo{};
                bindingFlagsInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO;
                bindingFlagsInfo.bindingCount = static_cast<uint32_t>(bindingFlags.size());
                bindingFlagsInfo.pBindingFlags = bindingFlags.data();

                VkDescriptorSetLayoutBinding modelDataLayoutBinding{};
                modelDataLayoutBinding.binding = 3;
                modelDataLayoutBinding.descriptorCount = 1;
                modelDataLayoutBinding.descriptorType = (useThread) ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC : VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                modelDataLayoutBinding.pImmutableSamplers = nullptr;
                modelDataLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;

                VkDescriptorSetLayoutBinding materialDataLayoutBinding{};
                materialDataLayoutBinding.binding = 4;
                materialDataLayoutBinding.descriptorCount = 1;
                materialDataLayoutBinding.descriptorType = (useThread) ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC : VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                materialDataLayoutBinding.pImmutableSamplers = nullptr;
                materialDataLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;

                VkDescriptorSetLayoutBinding samplerLayoutBinding{};
                samplerLayoutBinding.binding = 5;
                samplerLayoutBinding.descriptorCount = MAX_TEXTURES;
                samplerLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                samplerLayoutBinding.pImmutableSamplers = nullptr;
                samplerLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;



                if (descriptorSetLayout[descriptorId][0] != nullptr) {
                    vkDestroyDescriptorSetLayout(vkDevice.getDevice(), descriptorSetLayout[descriptorId][0], nullptr);
                }

                std::array<VkDescriptorSetLayoutBinding, 6> bindings = {counterLayoutBinding, headPtrImageLayoutBinding, linkedListLayoutBinding, modelDataLayoutBinding, materialDataLayoutBinding, samplerLayoutBinding};
                VkDescriptorSetLayoutCreateInfo layoutInfo{};
                layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
                layoutInfo.pNext = &bindingFlagsInfo;
                //layoutInfo.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR;
                layoutInfo.bindingCount = static_cast<uint32_t>(bindings.size());;
                layoutInfo.pBindings = bindings.data();

                if (vkCreateDescriptorSetLayout(vkDevice.getDevice(), &layoutInfo, nullptr, &descriptorSetLayout[descriptorId][0]) != VK_SUCCESS) {
                    throw std::runtime_error("failed to create descriptor set layout!");
                }
            } else {
                if (shader->getNbShaders() > descriptorSetLayout.size())
                    descriptorSetLayout.resize(shader->getNbShaders());
                unsigned int descriptorId = shader->getId();
                descriptorSetLayout[descriptorId].resize(1);
                //std::cout<<"shader id : "<<descriptorId<<std::endl;
                VkDescriptorSetLayoutBinding samplerLayoutBinding{};
                samplerLayoutBinding.binding = 0;
                samplerLayoutBinding.descriptorCount = 1;
                samplerLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                samplerLayoutBinding.pImmutableSamplers = nullptr;
                samplerLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
                if (descriptorSetLayout[descriptorId][0] != nullptr) {
                    vkDestroyDescriptorSetLayout(vkDevice.getDevice(), descriptorSetLayout[descriptorId][0], nullptr);
                }

                std::array<VkDescriptorSetLayoutBinding, 1> bindings = {samplerLayoutBinding};
                VkDescriptorSetLayoutCreateInfo layoutInfo{};
                layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
                //layoutInfo.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR;
                layoutInfo.bindingCount = static_cast<uint32_t>(bindings.size());;
                layoutInfo.pBindings = bindings.data();

                if (vkCreateDescriptorSetLayout(vkDevice.getDevice(), &layoutInfo, nullptr, &descriptorSetLayout[descriptorId][0]) != VK_SUCCESS) {
                    throw std::runtime_error("failed to create descriptor set layout!");
                }
            }
        }
        void PerPixelLinkedListRenderComponent::allocateDescriptorSets(unsigned int p, RenderStates states) {
            std::vector<std::vector<std::vector<VkDescriptorSet>>>& descriptorSets = frameBuffer.getDescriptorSet();
            std::vector<std::vector<VkDescriptorPool>>& descriptorPool = frameBuffer.getDescriptorPool();
            std::vector<std::vector<VkDescriptorSetLayout>>& descriptorSetLayout = frameBuffer.getDescriptorSetLayout();
            Shader* shader = const_cast<Shader*>(states.shader);
            if (shader == &indirectRenderingShader) {
                if (shader->getNbShaders()  * (Batcher::nbPrimitiveTypes - 1) > descriptorSets.size())
                    descriptorSets.resize(shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1));
                unsigned int descriptorId = p * shader->getNbShaders() + shader->getId();
                descriptorSets[descriptorId].resize(1);

                for (unsigned int i = 0; i < descriptorSets[descriptorId].size(); i++) {
                    descriptorSets[descriptorId][i].resize(frameBuffer.getMaxFramesInFlight());
                }
                std::vector<Texture*> allTextures = Texture::getAllTextures();
                std::vector<uint32_t> variableCounts(frameBuffer.getMaxFramesInFlight(), static_cast<uint32_t>(MAX_TEXTURES));

                VkDescriptorSetVariableDescriptorCountAllocateInfo variableCountInfo{};
                variableCountInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO;
                variableCountInfo.descriptorSetCount = static_cast<uint32_t>(variableCounts.size());;
                variableCountInfo.pDescriptorCounts = variableCounts.data();
                std::vector<VkDescriptorSetLayout> layouts(frameBuffer.getMaxFramesInFlight(), descriptorSetLayout[shader->getId()][0]);
                VkDescriptorSetAllocateInfo allocInfo{};
                allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
                allocInfo.pNext = &variableCountInfo;
                allocInfo.descriptorPool = descriptorPool[descriptorId][0];
                allocInfo.descriptorSetCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                allocInfo.pSetLayouts = layouts.data();
                if (vkAllocateDescriptorSets(vkDevice.getDevice(), &allocInfo, descriptorSets[descriptorId][0].data()) != VK_SUCCESS) {
                    throw std::runtime_error("echec de l'allocation d'un set de descripteurs!");
                }
            } else if (shader == &perPixelLinkedListP2) {
                if (shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1) > descriptorSets.size())
                    descriptorSets.resize(shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1));
                unsigned int descriptorId = p * shader->getNbShaders() + shader->getId();
                descriptorSets[descriptorId].resize(1);

                for (unsigned int i = 0; i < descriptorSets[descriptorId].size(); i++) {
                    descriptorSets[descriptorId][i].resize(frameBuffer.getMaxFramesInFlight());
                }
                std::vector<VkDescriptorSetLayout> layouts(frameBuffer.getMaxFramesInFlight(), descriptorSetLayout[shader->getId()][0]);
                VkDescriptorSetAllocateInfo allocInfo{};
                allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;

                allocInfo.descriptorPool = descriptorPool[descriptorId][0];
                allocInfo.descriptorSetCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                allocInfo.pSetLayouts = layouts.data();
                if (vkAllocateDescriptorSets(vkDevice.getDevice(), &allocInfo, descriptorSets[descriptorId][0].data()) != VK_SUCCESS) {
                    throw std::runtime_error("echec de l'allocation d'un set de descripteurs!");
                }
            } else {
                if (shader->getNbShaders()  * (Batcher::nbPrimitiveTypes - 1)> descriptorSets.size())
                    descriptorSets.resize(shader->getNbShaders() * (Batcher::nbPrimitiveTypes - 1));
                unsigned int descriptorId = p * shader->getNbShaders() + shader->getId();
                //std::cout<<"descriptor skybox ids : "<<descriptorId<<","<<shader->getId()<<std::endl;
                descriptorSets[descriptorId].resize(1);

                for (unsigned int i = 0; i < descriptorSets[descriptorId].size(); i++) {
                    descriptorSets[descriptorId][i].resize(frameBuffer.getMaxFramesInFlight());
                }
                std::vector<VkDescriptorSetLayout> layouts(frameBuffer.getMaxFramesInFlight(), descriptorSetLayout[shader->getId()][0]);
                VkDescriptorSetAllocateInfo allocInfo{};
                allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
                allocInfo.descriptorPool = descriptorPool[descriptorId][0];
                allocInfo.descriptorSetCount = static_cast<uint32_t>(frameBuffer.getMaxFramesInFlight());
                allocInfo.pSetLayouts = layouts.data();
                if (vkAllocateDescriptorSets(vkDevice.getDevice(), &allocInfo, descriptorSets[descriptorId][0].data()) != VK_SUCCESS) {
                    throw std::runtime_error("echec de l'allocation d'un set de descripteurs!");
                }
            }
        }
void PerPixelLinkedListRenderComponent::updateDescriptorSets(unsigned int currentFrame, unsigned int p, RenderStates states) {
            std::vector<std::vector<std::vector<VkDescriptorSet>>>& descriptorSets = frameBuffer.getDescriptorSet();
            Shader* shader = const_cast<Shader*>(states.shader);
            std::vector<Texture*> allTextures = Texture::getAllTextures();
            if (shader == &indirectRenderingShader) {

                unsigned int descriptorId = p * shader->getNbShaders() + shader->getId();
                std::vector<VkDescriptorImageInfo>	descriptorImageInfos;
                descriptorImageInfos.resize(allTextures.size());
                for (unsigned int j = 0; j < allTextures.size(); j++) {
                    descriptorImageInfos[j].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
                    descriptorImageInfos[j].imageView = allTextures[j]->getImageView();
                    descriptorImageInfos[j].sampler = allTextures[j]->getSampler();
                }
                std::array<VkWriteDescriptorSet, 6> descriptorWrites{};

                VkDescriptorBufferInfo counterStorageBufferInfoLastFrame{};
                counterStorageBufferInfoLastFrame.buffer = counterShaderStorageBuffers[currentFrame];
                counterStorageBufferInfoLastFrame.offset = 0;
                counterStorageBufferInfoLastFrame.range = sizeof(AtomicCounterSSBO);

                descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[0].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[0].dstBinding = 0;
                descriptorWrites[0].dstArrayElement = 0;
                descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                descriptorWrites[0].descriptorCount = 1;
                descriptorWrites[0].pBufferInfo = &counterStorageBufferInfoLastFrame;

                VkDescriptorImageInfo headPtrDescriptorImageInfo;
                headPtrDescriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
                headPtrDescriptorImageInfo.imageView = headPtrTextureImageView[currentFrame];
                headPtrDescriptorImageInfo.sampler = headPtrTextureSampler[currentFrame];

                descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[1].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[1].dstBinding = 1;
                descriptorWrites[1].dstArrayElement = 0;
                descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
                descriptorWrites[1].descriptorCount = 1;
                descriptorWrites[1].pImageInfo = &headPtrDescriptorImageInfo;

                VkDescriptorBufferInfo linkedListStorageBufferInfoLastFrame{};
                linkedListStorageBufferInfoLastFrame.buffer = linkedListShaderStorageBuffers[currentFrame];
                linkedListStorageBufferInfoLastFrame.offset = 0;
                unsigned int nodeSize = 5 * sizeof(float) + sizeof(unsigned int);
                linkedListStorageBufferInfoLastFrame.range = maxNodes * nodeSize;

                descriptorWrites[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[2].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[2].dstBinding = 2;
                descriptorWrites[2].dstArrayElement = 0;
                descriptorWrites[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                descriptorWrites[2].descriptorCount = 1;
                descriptorWrites[2].pBufferInfo = &linkedListStorageBufferInfoLastFrame;

                VkDescriptorBufferInfo modelDataStorageBufferInfoLastFrame{};
                modelDataStorageBufferInfoLastFrame.buffer = modelDataBufferMT[p][currentFrame];
                modelDataStorageBufferInfoLastFrame.offset = 0;
                modelDataStorageBufferInfoLastFrame.range = maxAlignedSizeModelData[p];

                descriptorWrites[3].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[3].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[3].dstBinding = 3;
                descriptorWrites[3].dstArrayElement = 0;
                descriptorWrites[3].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
                descriptorWrites[3].descriptorCount = 1;
                descriptorWrites[3].pBufferInfo = &modelDataStorageBufferInfoLastFrame;

                VkDescriptorBufferInfo materialDataStorageBufferInfoLastFrame{};
                materialDataStorageBufferInfoLastFrame.buffer = materialDataBufferMT[p][currentFrame];
                materialDataStorageBufferInfoLastFrame.offset = 0;
                materialDataStorageBufferInfoLastFrame.range = maxAlignedSizeMaterialData[p];

                descriptorWrites[4].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[4].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[4].dstBinding = 4;
                descriptorWrites[4].dstArrayElement = 0;
                descriptorWrites[4].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
                descriptorWrites[4].descriptorCount = 1;
                descriptorWrites[4].pBufferInfo = &materialDataStorageBufferInfoLastFrame;

                descriptorWrites[5].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[5].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[5].dstBinding = 5;
                descriptorWrites[5].dstArrayElement = 0;
                descriptorWrites[5].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                descriptorWrites[5].descriptorCount = allTextures.size();
                descriptorWrites[5].pImageInfo = descriptorImageInfos.data();

                vkUpdateDescriptorSets(vkDevice.getDevice(), static_cast<uint32_t>(descriptorWrites.size()), descriptorWrites.data(), 0, nullptr);

            } else if (shader == &perPixelLinkedListP2) {
                unsigned int descriptorId = p * shader->getNbShaders() + shader->getId();

                std::array<VkWriteDescriptorSet, 2> descriptorWrites{};

                VkDescriptorImageInfo headPtrDescriptorImageInfo;
                headPtrDescriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
                headPtrDescriptorImageInfo.imageView = headPtrTextureImageView[currentFrame];
                headPtrDescriptorImageInfo.sampler = headPtrTextureSampler[currentFrame];

                descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[0].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[0].dstBinding = 0;
                descriptorWrites[0].dstArrayElement = 0;
                descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
                descriptorWrites[0].descriptorCount = 1;
                descriptorWrites[0].pImageInfo = &headPtrDescriptorImageInfo;

                VkDescriptorBufferInfo linkedListStorageBufferInfoLastFrame{};
                linkedListStorageBufferInfoLastFrame.buffer = linkedListShaderStorageBuffers[currentFrame];
                linkedListStorageBufferInfoLastFrame.offset = 0;
                unsigned int nodeSize = 5 * sizeof(float) + sizeof(unsigned int);
                linkedListStorageBufferInfoLastFrame.range = maxNodes * nodeSize;

                descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[1].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[1].dstBinding = 1;
                descriptorWrites[1].dstArrayElement = 0;
                descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
                descriptorWrites[1].descriptorCount = 1;
                descriptorWrites[1].pBufferInfo = &linkedListStorageBufferInfoLastFrame;

                vkUpdateDescriptorSets(vkDevice.getDevice(), static_cast<uint32_t>(descriptorWrites.size()), descriptorWrites.data(), 0, nullptr);

            } else {
                unsigned int descriptorId = p * shader->getNbShaders() + shader->getId();
                VkDescriptorImageInfo	descriptorImageInfo;
                std::array<VkWriteDescriptorSet, 1> descriptorWrites{};
                descriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
                descriptorImageInfo.imageView = skybox->getTexture().getImageView();
                descriptorImageInfo.sampler = skybox->getTexture().getSampler();

                descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                descriptorWrites[0].dstSet = descriptorSets[descriptorId][0][currentFrame];
                descriptorWrites[0].dstBinding = 0;
                descriptorWrites[0].dstArrayElement = 0;
                descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                descriptorWrites[0].descriptorCount = 1;
                descriptorWrites[0].pImageInfo = &descriptorImageInfo;

                vkUpdateDescriptorSets(vkDevice.getDevice(), static_cast<uint32_t>(descriptorWrites.size()), descriptorWrites.data(), 0, nullptr);

            }
        }
void PerPixelLinkedListRenderComponent::createDescriptorSetLayout2(RenderStates states) {
            std::vector<std::vector<VkDescriptorSetLayout>>& descriptorSetLayout = frameBuffer.getDescriptorSetLayout();
            Shader* shader = const_cast<Shader*>(states.shader);
            if (shader->getNbShaders() > descriptorSetLayout.size())
                descriptorSetLayout.resize(shader->getNbShaders());
            unsigned int descriptorId = shader->getId();
            descriptorSetLayout[descriptorId].resize(1);
            VkDescriptorSetLayoutBinding headPtrImageLayoutBinding;
            headPtrImageLayoutBinding.binding = 0;
            headPtrImageLayoutBinding.descriptorCount = 1;
            headPtrImageLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
            headPtrImageLayoutBinding.pImmutableSamplers = nullptr;
            headPtrImageLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;

            VkDescriptorSetLayoutBinding linkedListLayoutBinding{};
            linkedListLayoutBinding.binding = 1;
            linkedListLayoutBinding.descriptorCount = 1;
            linkedListLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
            linkedListLayoutBinding.pImmutableSamplers = nullptr;
            linkedListLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;

            if (descriptorSetLayout[descriptorId][0] != nullptr) {
                vkDestroyDescriptorSetLayout(vkDevice.getDevice(), descriptorSetLayout[descriptorId][0], nullptr);
            }

            std::array<VkDescriptorSetLayoutBinding, 2> bindings = {headPtrImageLayoutBinding, linkedListLayoutBinding};
            VkDescriptorSetLayoutCreateInfo layoutInfo{};
            layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
            //layoutInfo.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR;
            layoutInfo.bindingCount = static_cast<uint32_t>(bindings.size());;
            layoutInfo.pBindings = bindings.data();

            if (vkCreateDescriptorSetLayout(vkDevice.getDevice(), &layoutInfo, nullptr, &descriptorSetLayout[descriptorId][0]) != VK_SUCCESS) {
                throw std::runtime_error("failed to create descriptor set layout!");
            }
        }

I don’t understand why I’ve device lost issue, without recreating descriptors everything runs fine…

Ho how stupid I’m, I just totally forgot to re-update my needToUpdateDescriptorDds bool array after relaunching my rendering thread!!! So, after recreating my descriptor sets there were no updated so I just got device lost issue. Working now, problem solved! Finally I checked during 2 days because of this stupid issue.