Partage
  • Partager sur Facebook
  • Partager sur Twitter

[VULKAN] Validation layer erreur.

Erreur que je ne comprend pas.

Sujet résolu
    12 décembre 2022 à 19:42:30

    Salut! J'essaye d'afficher une texture avec vulkan mais le validation layer me met des erreurs que je ne comprend pas bien avec le descriptor pool.

    RenderTarget::RenderTarget() :
            m_defaultView(), m_view() {
    
            }
            RenderTarget::~RenderTarget() {
                cleanup();
                vkDestroyRenderPass(vkSettup->getDevice(), renderPass, nullptr);
            }
            void RenderTarget::initialize(window::VkSettup& settup) {
                vkSettup = &settup;
    
                m_defaultView = View (static_cast<float>(getSize().x), static_cast<float>(getSize().y), -static_cast<float>(getSize().y) - 200, static_cast<float>(getSize().y)+200);
                m_defaultView.reset(physic::BoundingBox(0, 0, -static_cast<float>(getSize().y) - 200,static_cast<float>(getSize().x), static_cast<float>(getSize().y),static_cast<float>(getSize().y)+200));
                m_view = m_defaultView;
                const std::string defaultVertexShader = R"(#version 450
                                                            layout(binding = 0) uniform UniformBufferObject {
                                                                mat4 model;
                                                                mat4 view;
                                                                mat4 proj;
                                                            } ubo;
                                                            layout(location = 0) in vec3 inPosition;
                                                            layout(location = 1) in vec4 inColor;
                                                            layout(location = 2) in vec2 inTexCoord;
    
                                                            layout(location = 0) out vec4 fragColor;
                                                            layout(location = 1) out vec2 fragTexCoord;
    
                                                            out gl_PerVertex {
                                                                vec4 gl_Position;
                                                            };
    
                                                            void main() {
                                                                gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
                                                                fragColor = inColor;
                                                                fragTexCoord = inTexCoord;
                                                            }
                                                            )";
                const std::string defaultFragmentShader = R"(#version 450
                                                              #extension GL_ARB_separate_shader_objects : enable
                                                              layout(location = 0) in vec4 fragColor;
                                                              layout(location = 1) in vec2 fragTexCoord;
                                                              layout(location = 0) out vec4 outColor;
                                                              layout(binding = 1) uniform sampler2D texSampler;
                                                              void main() {
                                                                  outColor = texture(texSampler, fragTexCoord);
                                                              })";
                 defaultShader.setVkSettup(vkSettup);
                 if (!defaultShader.loadFromMemory(defaultVertexShader, defaultFragmentShader)) {
                      throw core::Erreur (0, "Failed to load default shader", 1);
                 }
                 createRenderPass();
                 createDescriptorSetLayout();
                 createCommandPool();
                 createUniformBuffers();
                 createDescriptorPool();
    
            }
            void RenderTarget::clear(const sf::Color& color) {
                cleanup();
                clearColor = color;
            }
            void RenderTarget::clearDepth() {
            }
            void RenderTarget::setView(View view)
            {
                m_view = view;
            }
            View& RenderTarget::getView() {
                return m_view;
            }
            View& RenderTarget::getDefaultView() {
                return m_defaultView;
            }
             math::Vec3f RenderTarget::mapPixelToCoords(const math::Vec3f& point)
            {
                return mapPixelToCoords(point, getView());
            }
    
    
            math::Vec3f RenderTarget::mapPixelToCoords(const math::Vec3f& point, View& view)
            {
                ViewportMatrix vpm;
                vpm.setViewport(math::Vec3f(view.getViewport().getPosition().x, view.getViewport().getPosition().y, 0)
                                            ,math::Vec3f(view.getViewport().getWidth(), view.getViewport().getHeight(), 1));
                math::Vec3f coords = vpm.toNormalizedCoordinates(point);
                coords = view.getProjMatrix().unProject(coords);
                coords = coords.normalizeToVec3();
                coords = view.getViewMatrix().inverseTransform(coords);
                return coords;
            }
    
            math::Vec3f RenderTarget::mapCoordsToPixel(const math::Vec3f& point)
            {
                return mapCoordsToPixel(point, getView());
            }
    
    
            math::Vec3f RenderTarget::mapCoordsToPixel(const math::Vec3f& point, View& view) {
                ViewportMatrix vpm;
                vpm.setViewport(math::Vec3f(view.getViewport().getPosition().x, view.getViewport().getPosition().y, 0),
                math::Vec3f(view.getViewport().getWidth(), view.getViewport().getHeight(), 1));
                math::Vec3f coords = view.getViewMatrix().transform(point);
                coords = view.getProjMatrix().project(coords);
                coords = coords.normalizeToVec3();
                coords = vpm.toViewportCoordinates(coords);
                return coords;
            }
            void RenderTarget::draw(Drawable& drawable, RenderStates states)
            {
                drawable.draw(*this, states);
            }
            void RenderTarget::draw(const Vertex* vertices, unsigned int vertexCount, sf::PrimitiveType type,
                          RenderStates states) {
    
                 createGraphicPipeline(vertices, vertexCount, type, states);
    
                 vertexBuffer.setVkSettup(*vkSettup);
                 vertexBuffer.clear();
                 for (unsigned int i = 0; i < vertexCount; i++) {
                    vertexBuffer.append(vertices[i]);
                 }
                 UniformBufferObject ubo;
                 ubo.model = states.transform.getMatrix().transpose();
    
                 updateUniformBuffer(vkSettup->getCurrentFrame(), ubo);
                 createDescriptorSets(states.texture);
                 createCommandBuffers();
    
            }
            void RenderTarget::createRenderPass() {
                VkAttachmentDescription colorAttachment{};
                colorAttachment.format =    vkSettup->getSwapchainImageFormat();
                colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
                colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
                colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
                colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
                colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
                colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
                colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
    
                VkAttachmentReference colorAttachmentRef{};
                colorAttachmentRef.attachment = 0;
                colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
    
                VkSubpassDescription subpass{};
                subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
                subpass.colorAttachmentCount = 1;
                subpass.pColorAttachments = &colorAttachmentRef;
    
                VkRenderPassCreateInfo renderPassInfo{};
                renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
                renderPassInfo.attachmentCount = 1;
                renderPassInfo.pAttachments = &colorAttachment;
                renderPassInfo.subpassCount = 1;
                renderPassInfo.pSubpasses = &subpass;
                VkSubpassDependency dependency{};
                dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
                dependency.dstSubpass = 0;
                dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
                dependency.srcAccessMask = 0;
                dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
                dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
                renderPassInfo.dependencyCount = 1;
                renderPassInfo.pDependencies = &dependency;
                if (vkCreateRenderPass(vkSettup->getDevice(), &renderPassInfo, nullptr, &renderPass) != VK_SUCCESS) {
                    throw core::Erreur(0, "failed to create render pass!", 1);
                }
    
            }
            void RenderTarget::createDescriptorSetLayout() {
                VkDescriptorSetLayoutBinding uboLayoutBinding{};
                uboLayoutBinding.binding = 0;
                uboLayoutBinding.descriptorCount = 1;
                uboLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
                uboLayoutBinding.pImmutableSamplers = nullptr;
                uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
    
                VkDescriptorSetLayoutBinding samplerLayoutBinding{};
                samplerLayoutBinding.binding = 1;
                samplerLayoutBinding.descriptorCount = 1;
                samplerLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                samplerLayoutBinding.pImmutableSamplers = nullptr;
                samplerLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
                std::array<VkDescriptorSetLayoutBinding, 2> bindings = {uboLayoutBinding, samplerLayoutBinding};
    
                VkDescriptorSetLayoutCreateInfo layoutInfo{};
                layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
                layoutInfo.bindingCount = static_cast<uint32_t>(bindings.size());;
                layoutInfo.pBindings = bindings.data();
    
                if (vkCreateDescriptorSetLayout(vkSettup->getDevice(), &layoutInfo, nullptr, &descriptorSetLayout) != VK_SUCCESS) {
                    throw std::runtime_error("failed to create descriptor set layout!");
                }
            }
            void RenderTarget::createDescriptorPool() {
                std::array<VkDescriptorPoolSize, 2> poolSizes{};
                poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
                poolSizes[0].descriptorCount = static_cast<uint32_t>(vkSettup->MAX_FRAMES_IN_FLIGHT);
                poolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                poolSizes[1].descriptorCount = static_cast<uint32_t>(vkSettup->MAX_FRAMES_IN_FLIGHT);
    
                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>(vkSettup->MAX_FRAMES_IN_FLIGHT);
                if (vkCreateDescriptorPool(vkSettup->getDevice(), &poolInfo, nullptr, &descriptorPool) != VK_SUCCESS) {
                    throw std::runtime_error("echec de la creation de la pool de descripteurs!");
                }
            }
            void RenderTarget::createDescriptorSets(const Texture* texture) {
                std::vector<VkDescriptorSetLayout> layouts(vkSettup->MAX_FRAMES_IN_FLIGHT, descriptorSetLayout);
                VkDescriptorSetAllocateInfo allocInfo{};
                allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
                allocInfo.descriptorPool = descriptorPool;
                allocInfo.descriptorSetCount = static_cast<uint32_t>(vkSettup->MAX_FRAMES_IN_FLIGHT);
                allocInfo.pSetLayouts = layouts.data();
                descriptorSets.resize(vkSettup->MAX_FRAMES_IN_FLIGHT);
                if (vkAllocateDescriptorSets(vkSettup->getDevice(), &allocInfo, descriptorSets.data()) != VK_SUCCESS) {
                    throw std::runtime_error("echec de l'allocation d'un set de descripteurs!");
                }
                for (size_t i = 0; i < vkSettup->MAX_FRAMES_IN_FLIGHT; i++) {
                    VkDescriptorBufferInfo bufferInfo{};
                    bufferInfo.buffer = uniformBuffers[i];
                    bufferInfo.offset = 0;
                    bufferInfo.range = sizeof(UniformBufferObject);
    
                    VkDescriptorImageInfo imageInfo{};
                    imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
                    imageInfo.imageView = texture->getImageView();
                    imageInfo.sampler = texture->getSampler();
    
                    std::array<VkWriteDescriptorSet, 2> descriptorWrites{};
    
                    descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                    descriptorWrites[0].dstSet = descriptorSets[i];
                    descriptorWrites[0].dstBinding = 0;
                    descriptorWrites[0].dstArrayElement = 0;
                    descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
                    descriptorWrites[0].descriptorCount = 1;
                    descriptorWrites[0].pBufferInfo = &bufferInfo;
    
                    descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
                    descriptorWrites[1].dstSet = descriptorSets[i];
                    descriptorWrites[1].dstBinding = 1;
                    descriptorWrites[1].dstArrayElement = 0;
                    descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                    descriptorWrites[1].descriptorCount = 1;
                    descriptorWrites[1].pImageInfo = &imageInfo;
                    vkUpdateDescriptorSets(vkSettup->getDevice(), static_cast<uint32_t>(descriptorWrites.size()), descriptorWrites.data(), 0, nullptr);
                }
            }
            void RenderTarget::createGraphicPipeline(const Vertex* vertices, unsigned int vertexCount, sf::PrimitiveType type,
                          RenderStates states = RenderStates::Default) {
                defaultShader.createShaderModules();
                VkShaderModule vertShaderModule = defaultShader.getVertexShaderModule();
                VkShaderModule fragShaderModule = defaultShader.getFragmentShaderModule();
                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 shaderStages[] = {vertShaderStageInfo, fragShaderStageInfo};
    
                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;
                inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
                inputAssembly.primitiveRestartEnable = VK_FALSE;
    
                VkViewport viewport{};
                viewport.x = 0.0f;
                viewport.y = 0.0f;
                viewport.width = vkSettup->getSwapchainExtends().width;
                viewport.height = vkSettup->getSwapchainExtends().height;
                viewport.minDepth = 0.0f;
                viewport.maxDepth = 1.0f;
    
                VkRect2D scissor{};
                scissor.offset = {0, 0};
                scissor.extent = vkSettup->getSwapchainExtends();
    
                VkPipelineViewportStateCreateInfo viewportState{};
                viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
                viewportState.viewportCount = 1;
                viewportState.pViewports = &viewport;
                viewportState.scissorCount = 1;
                viewportState.pScissors = &scissor;
    
                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;
                rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
                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_FALSE;
    
                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;
    
                VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
                pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
                pipelineLayoutInfo.setLayoutCount = 1;
                pipelineLayoutInfo.pSetLayouts = &descriptorSetLayout;
    
                if (vkCreatePipelineLayout(vkSettup->getDevice(), &pipelineLayoutInfo, nullptr, &pipelineLayout) != VK_SUCCESS) {
                    throw core::Erreur(0, "failed to create pipeline layout!", 1);
                }
                VkGraphicsPipelineCreateInfo pipelineInfo{};
                pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
                pipelineInfo.stageCount = 2;
                pipelineInfo.pStages = shaderStages;
                pipelineInfo.pVertexInputState = &vertexInputInfo;
                pipelineInfo.pInputAssemblyState = &inputAssembly;
                pipelineInfo.pViewportState = &viewportState;
                pipelineInfo.pRasterizationState = &rasterizer;
                pipelineInfo.pMultisampleState = &multisampling;
                pipelineInfo.pColorBlendState = &colorBlending;
                pipelineInfo.layout = pipelineLayout;
                pipelineInfo.renderPass = renderPass;
                pipelineInfo.subpass = 0;
                pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
    
                if (vkCreateGraphicsPipelines(vkSettup->getDevice(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) {
                    throw core::Erreur(0, "failed to create graphics pipeline!", 1);
                }
                defaultShader.cleanupShaderModules();
            }
            void RenderTarget::createCommandPool() {
                window::VkSettup::QueueFamilyIndices queueFamilyIndices = vkSettup->findQueueFamilies(vkSettup->getPhysicalDevice());
    
                VkCommandPoolCreateInfo poolInfo{};
                poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
                poolInfo.queueFamilyIndex = queueFamilyIndices.graphicsFamily;
                poolInfo.flags = 0; // Optionel
                if (vkCreateCommandPool(vkSettup->getDevice(), &poolInfo, nullptr, &commandPool) != VK_SUCCESS) {
                    throw core::Erreur(0, "échec de la création d'une command pool!", 1);
                }
                vkSettup->setCommandPool(commandPool);
            }
            void RenderTarget::createUniformBuffers() {
                VkDeviceSize bufferSize = sizeof(UniformBufferObject);
    
                uniformBuffers.resize(vkSettup->MAX_FRAMES_IN_FLIGHT);
                uniformBuffersMemory.resize(vkSettup->MAX_FRAMES_IN_FLIGHT);
    
                for (size_t i = 0; i < vkSettup->MAX_FRAMES_IN_FLIGHT; i++) {
                    createBuffer(bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, uniformBuffers[i], uniformBuffersMemory[i]);
                }
            }
            void RenderTarget::updateUniformBuffer(uint32_t currentImage, UniformBufferObject ubo) {
                ubo.proj = m_view.getProjMatrix().getMatrix().transpose();
                ubo.proj.m22 *= -1;
                ubo.view = m_view.getViewMatrix().getMatrix().transpose();
                void* data;
                vkMapMemory(vkSettup->getDevice(), uniformBuffersMemory[currentImage], 0, sizeof(ubo), 0, &data);
                    memcpy(data, &ubo, sizeof(ubo));
                vkUnmapMemory(vkSettup->getDevice(), uniformBuffersMemory[currentImage]);
    
            }
            void RenderTarget::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory) {
                VkBufferCreateInfo bufferInfo{};
                bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
                bufferInfo.size = size;
                bufferInfo.usage = usage;
                bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
    
                if (vkCreateBuffer(vkSettup->getDevice(), &bufferInfo, nullptr, &buffer) != VK_SUCCESS) {
                    throw std::runtime_error("failed to create buffer!");
                }
    
                VkMemoryRequirements memRequirements;
                vkGetBufferMemoryRequirements(vkSettup->getDevice(), buffer, &memRequirements);
    
                VkMemoryAllocateInfo allocInfo{};
                allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
                allocInfo.allocationSize = memRequirements.size;
                allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
    
                if (vkAllocateMemory(vkSettup->getDevice(), &allocInfo, nullptr, &bufferMemory) != VK_SUCCESS) {
                    throw std::runtime_error("failed to allocate buffer memory!");
                }
    
                vkBindBufferMemory(vkSettup->getDevice(), buffer, bufferMemory, 0);
            }
            uint32_t RenderTarget::findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties) {
                VkPhysicalDeviceMemoryProperties memProperties;
                vkGetPhysicalDeviceMemoryProperties(vkSettup->getPhysicalDevice(), &memProperties);
                for (uint32_t i = 0; i < memProperties.memoryTypeCount; i++) {
                    if ((typeFilter & (1 << i)) && (memProperties.memoryTypes[i].propertyFlags & properties) == properties) {
                        return i;
                    }
                }
                throw std::runtime_error("aucun type de memoire ne satisfait le buffer!");
            }
            void RenderTarget::createCommandBuffers() {
                commandBuffers.resize(swapChainFramebuffers.size());
    
                VkCommandBufferAllocateInfo allocInfo{};
                allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
                allocInfo.commandPool = commandPool;
                allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
                allocInfo.commandBufferCount = (uint32_t) commandBuffers.size();
    
                if (vkAllocateCommandBuffers(vkSettup->getDevice(), &allocInfo, commandBuffers.data()) != VK_SUCCESS) {
                    throw core::Erreur(0, "failed to allocate command buffers!", 1);
                }
    
                for (size_t i = 0; i < commandBuffers.size(); i++) {
                    VkCommandBufferBeginInfo beginInfo{};
                    beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
    
                    if (vkBeginCommandBuffer(commandBuffers[i], &beginInfo) != VK_SUCCESS) {
                        throw core::Erreur(0, "failed to begin recording command buffer!", 1);
                    }
                    VkRenderPassBeginInfo renderPassInfo{};
                    renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
                    renderPassInfo.renderPass = renderPass;
                    renderPassInfo.framebuffer = swapChainFramebuffers[i];
                    renderPassInfo.renderArea.offset = {0, 0};
                    renderPassInfo.renderArea.extent = vkSettup->getSwapchainExtends();
    
                    VkClearValue clrColor = {clearColor.r / 255.f,clearColor.g / 255.f, clearColor.b / 255.f, clearColor.a / 255.f};
                    renderPassInfo.clearValueCount = 1;
                    renderPassInfo.pClearValues = &clrColor;
    
                    vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
                    vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
                    VkBuffer vertexBuffers[] = {vertexBuffer.getVertexBuffer()};
                    VkDeviceSize offsets[] = {0};
                    vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets);
                    vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[vkSettup->getCurrentFrame()], 0, nullptr);
                    if(vertexBuffer.getIndicesSize() > 0) {
                        vkCmdBindIndexBuffer(commandBuffers[i], vertexBuffer.getIndexBuffer(), 0, VK_INDEX_TYPE_UINT16);
                    }
                    if(vertexBuffer.getIndicesSize() > 0) {
                        vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(vertexBuffer.getIndicesSize()), 1, 0, 0, 0);
                    } else {
                        vkCmdDraw(commandBuffers[i], static_cast<uint32_t>(vertexBuffer.getSize()), 1, 0, 0);
                    }
                    vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
    
                    vkCmdDraw(commandBuffers[i], 3, 1, 0, 0);
    
                    vkCmdEndRenderPass(commandBuffers[i]);
    
                    if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
                        throw core::Erreur(0, "failed to record command buffer!", 1);
                    }
    
                }
                vkSettup->setCommandBuffers(commandBuffers);
            }
            void RenderTarget::cleanup() {
                vkDestroyCommandPool(vkSettup->getDevice(), commandPool, nullptr);
                vkDestroyPipeline(vkSettup->getDevice(), graphicsPipeline, nullptr);
                vkDestroyPipelineLayout(vkSettup->getDevice(), pipelineLayout, nullptr);
                vkDestroyRenderPass(vkSettup->getDevice(), renderPass, nullptr);
                vkDestroyDescriptorSetLayout(vkSettup->getDevice(), descriptorSetLayout, nullptr);
                for (size_t i = 0; i < vkSettup->getSwapchainImages().size(); i++) {
                    vkDestroyBuffer(vkSettup->getDevice(), uniformBuffers[i], nullptr);
                    vkFreeMemory(vkSettup->getDevice(), uniformBuffersMemory[i], nullptr);
                }
                 vkDestroyDescriptorPool(vkSettup->getDevice(), descriptorPool, nullptr);
                 vkDestroyDescriptorSetLayout(vkSettup->getDevice(), descriptorSetLayout, nullptr);
            }


    Merci d'avance pour votre aide.

    EDIT : ha bah j'ai changé l'endroit ou je l'appelle et ça marche.

    void RenderTarget::draw(const Vertex* vertices, unsigned int vertexCount, sf::PrimitiveType type,
                          RenderStates states) {
    
                 createGraphicPipeline(vertices, vertexCount, type, states);
    
                 vertexBuffer.setVkSettup(*vkSettup);
                 vertexBuffer.clear();
                 for (unsigned int i = 0; i < vertexCount; i++) {
                    vertexBuffer.append(vertices[i]);
                 }
                 UniformBufferObject ubo;
                 ubo.model = states.transform.getMatrix().transpose();
    
                 updateUniformBuffer(vkSettup->getCurrentFrame(), ubo);
                 createDescriptorPool();
                 createDescriptorSets(states.texture);
                 createCommandBuffers();
    
            }

    Ca y est j'arrive à afficher des textures avec vulkan super!!!

    -
    Edité par OmbreNoire 12 décembre 2022 à 19:56:21

    • Partager sur Facebook
    • Partager sur Twitter

    [VULKAN] Validation layer erreur.

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown