/* Please see header for specification */ bool Anvil::DescriptorPool::reset() { VkResult result_vk; if (m_pool != VK_NULL_HANDLE) { result_vk = vkResetDescriptorPool(m_device_ptr->get_device_vk(), m_pool, 0 /* flags */); anvil_assert_vk_call_succeeded(result_vk); if (is_vk_call_successful(result_vk) ) { /* Alloced descriptor sets went out of scope. Send out a call-back, so that descriptor set * wrapper instances can mark themselves as unusable */ callback(DESCRIPTOR_POOL_CALLBACK_ID_POOL_RESET, this); } } else { result_vk = VK_SUCCESS; } return is_vk_call_successful(result_vk); }
void DescriptorSetAllocator::clear() { set_nodes.clear(); for (auto &pool : pools) { vkResetDescriptorPool(device->get_device(), pool, 0); vkDestroyDescriptorPool(device->get_device(), pool, nullptr); } pools.clear(); }
void CommandBufferManager::ActivateCommandBuffer() { // Move to the next command buffer. m_current_frame = (m_current_frame + 1) % NUM_COMMAND_BUFFERS; FrameResources& resources = m_frame_resources[m_current_frame]; // Wait for the GPU to finish with all resources for this command buffer. if (resources.needs_fence_wait) { VkResult res = vkWaitForFences(g_vulkan_context->GetDevice(), 1, &resources.fence, true, UINT64_MAX); if (res != VK_SUCCESS) LOG_VULKAN_ERROR(res, "vkWaitForFences failed: "); OnCommandBufferExecuted(m_current_frame); } // Reset fence to unsignaled before starting. VkResult res = vkResetFences(g_vulkan_context->GetDevice(), 1, &resources.fence); if (res != VK_SUCCESS) LOG_VULKAN_ERROR(res, "vkResetFences failed: "); // Reset command pools to beginning since we can re-use the memory now res = vkResetCommandPool(g_vulkan_context->GetDevice(), resources.command_pool, 0); if (res != VK_SUCCESS) LOG_VULKAN_ERROR(res, "vkResetCommandPool failed: "); // Enable commands to be recorded to the two buffers again. VkCommandBufferBeginInfo begin_info = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, nullptr}; for (VkCommandBuffer command_buffer : resources.command_buffers) { res = vkBeginCommandBuffer(command_buffer, &begin_info); if (res != VK_SUCCESS) LOG_VULKAN_ERROR(res, "vkBeginCommandBuffer failed: "); } // Also can do the same for the descriptor pools res = vkResetDescriptorPool(g_vulkan_context->GetDevice(), resources.descriptor_pool, 0); if (res != VK_SUCCESS) LOG_VULKAN_ERROR(res, "vkResetDescriptorPool failed: "); // Reset upload command buffer state resources.init_command_buffer_used = false; }
void VkeDrawCall::initDescriptor(){ VulkanDC *dc = VulkanDC::Get(); VulkanDC::Device *device = dc->getDefaultDevice(); VkWriteDescriptorSet writes[1]; vkResetDescriptorPool(device->getVKDevice(), m_descriptor_pool, 0); VkDescriptorSetAllocateInfo descAlloc = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO }; descAlloc.descriptorPool = m_descriptor_pool; descAlloc.pSetLayouts = (m_renderer->getTransformDescriptorLayout()); descAlloc.descriptorSetCount = 1; VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_transform_descriptor_set), "Could not allocate descriptor sets.\n"); descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, (m_renderer->getTransformsDescriptor()), VK_NULL_HANDLE, 0, m_transform_descriptor_set);//transform vkUpdateDescriptorSets(device->getVKDevice(), 1, writes, 0, NULL); }
void vkeGameRendererDynamic::initDescriptorSets(){ VulkanDC *dc = VulkanDC::Get(); VulkanDC::Device *device = dc->getDefaultDevice(); uint32_t count = 1; if (!dc) return; initCamera(); vkResetDescriptorPool(device->getVKDevice(), getDescriptorPool(), 0); VkWriteDescriptorSet writes[5]; /*---------------------------------------------------------- Get the resource data for the bindings. ----------------------------------------------------------*/ /* Terrain textures. */ VkeTexture::Data terrain = m_textures.getTexture(0)->getData(); /* Camera and Light uniforms */ VkDescriptorBufferInfo camInfo = m_camera->getDescriptor(); VkDescriptorBufferInfo lightInfo = m_light->getDescriptor(); /* Cube map texture. */ VkeCubeTexture::Data cube = m_cube_textures.getTexture(1)->getData(); /* Create descriptor image info array for the terrain textures. */ VkDescriptorImageInfo fpSampler = { terrain.sampler, terrain.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL }; VkeMaterial *material = m_materials->getMaterial(0); /* Create descriptor image info array for the scene textures. */ uint32_t texCount = m_materials->count(); VkDescriptorImageInfo *texImageInfo = (VkDescriptorImageInfo*)malloc(texCount * sizeof(VkDescriptorImageInfo)); for (uint32_t i = 0; i < texCount; ++i){ VkeMaterial *mtrl = m_materials->getMaterial(i); VkeTexture::Data texData = mtrl->getTextures().getTexture(0)->getData(); texImageInfo[i].imageView = texData.view; texImageInfo[i].sampler = texData.sampler; } /* Create descriptor image info for the cube map texture. */ VkDescriptorImageInfo cubeTexture; cubeTexture.sampler = cube.sampler; cubeTexture.imageView = cube.view; cubeTexture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; /* Capture the layouts for the scene descriptor sets and the texture descriptor sets. */ VkDescriptorSetLayout *textureLayouts = (VkDescriptorSetLayout*)malloc(sizeof(VkDescriptorSetLayout) * texCount); for (uint32_t i = 0; i < texCount; ++i){ textureLayouts[i] = m_texture_descriptor_set_layout; } /* Allocate storage for the scene and texture descriptor sets. */ /*---------------------------------------------------------- Allocate the descriptor sets. ----------------------------------------------------------*/ m_texture_descriptor_sets = (VkDescriptorSet*)malloc(sizeof(VkDescriptorSet)); /* Set up the alocate info structure for the descriptor sets. */ VkDescriptorSetAllocateInfo descAlloc; memset(&descAlloc, 0, sizeof(descAlloc)); descAlloc.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descAlloc.descriptorPool = getDescriptorPool(); descAlloc.pSetLayouts = &m_scene_descriptor_layout; descAlloc.descriptorSetCount = 1; VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_scene_descriptor_set), "Could not allocate descriptor sets.\n"); /* Set up the texture descriptor sets. */ descAlloc.pSetLayouts = &m_texture_descriptor_set_layout; descAlloc.descriptorSetCount = 1; VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, m_texture_descriptor_sets), "Could not allocate texture descriptor sets.\n"); /* Set up the skybox descriptor sets. */ descAlloc.pSetLayouts = &m_quad_descriptor_set_layout; descAlloc.descriptorSetCount = 1; VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_quad_descriptor_set), "Could not allocate descriptor sets.\n"); /* Set up the terrian descriptor sets. */ descAlloc.pSetLayouts = &m_terrain_descriptor_set_layout; descAlloc.descriptorSetCount = 1; VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_terrain_descriptor_set), "Could not allocate descriptor sets.\n"); /* Set up the transforms descriptor sets. */ descAlloc.pSetLayouts = &m_transform_descriptor_layout; descAlloc.descriptorSetCount = 1; VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_transform_descriptor_set), "Could not allocate descriptor sets.\n"); /*---------------------------------------------------------- Update the descriptor sets with resource bindings. ----------------------------------------------------------*/ /* Scene layout bindings (set 0) Binding 0: Environment Cube Map Binding 1: Camera Matrix Binding 2: Model Matrix Binding 3: Material */ descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_NULL_HANDLE, &cubeTexture, 0, m_scene_descriptor_set);//cubemap descriptorSetWrite(&writes[1], 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &camInfo, VK_NULL_HANDLE, 0, m_scene_descriptor_set); //Camera descriptorSetWrite(&writes[2], 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &m_uniforms_descriptor, VK_NULL_HANDLE, 0, m_scene_descriptor_set);//modelview descriptorSetWrite(&writes[3], 3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &material->getDescriptor(), VK_NULL_HANDLE, 0, m_scene_descriptor_set);//material vkUpdateDescriptorSets(device->getVKDevice(), 4, writes, 0, NULL); /* Transform layout bindings (set 0) Binding 0: Transform */ descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &m_transforms_descriptor, VK_NULL_HANDLE, 0, m_transform_descriptor_set);//transform vkUpdateDescriptorSets(device->getVKDevice(), 1, writes, 0, NULL); /* Scene layout bindings (set 1) Binding 0: Scene texture array */ descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, texCount, VK_NULL_HANDLE, texImageInfo, 0, m_texture_descriptor_sets[0]);//cubemap vkUpdateDescriptorSets(device->getVKDevice(), (uint32_t)1, writes, 0, NULL); //Free the texture image info allocated earlier. free(texImageInfo); /* Skybox layout bindings (set 0) Binding 0: Skybox Uniforms Binding 1: Skybox Textures Binding 2: Camera uniforms */ descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &m_screen_quad.getData().descriptor, VK_NULL_HANDLE, 0, m_quad_descriptor_set); descriptorSetWrite(&writes[1], 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_NULL_HANDLE, &cubeTexture, 0, m_quad_descriptor_set); descriptorSetWrite(&writes[2], 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &camInfo, VK_NULL_HANDLE, 0, m_quad_descriptor_set); vkUpdateDescriptorSets(device->getVKDevice(), 3, writes, 0, NULL); /* Terrain layout bindings (set 0) Binding 0: Terrain Uniforms Binding 1: Camera Uniforms Binding 2: Terrain texture array */ descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &m_terrain_quad.getData().descriptor, VK_NULL_HANDLE, 0, m_terrain_descriptor_set); descriptorSetWrite(&writes[1], 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &camInfo, VK_NULL_HANDLE, 0, m_terrain_descriptor_set); descriptorSetWrite(&writes[2], 2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_NULL_HANDLE, &fpSampler, 0, m_terrain_descriptor_set); descriptorSetWrite(&writes[3], 3, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_NULL_HANDLE, &cubeTexture, 0, m_terrain_descriptor_set); vkUpdateDescriptorSets(device->getVKDevice(), 4, writes, 0, NULL); /*---------------------------------------------------------- Initialise the terrain and scene command buffers. ----------------------------------------------------------*/ initTerrainCommand(); for (uint32_t i = 0; i < m_max_draw_calls; ++i){ m_draw_calls[i]->initDescriptor(); } //m_test_drawcall->initDrawCommands(m_node_data->count()); //this needs to happen in the thread. //m_draw_calls[0]->initDrawCommands(m_node_data->count()); }
void Vulkan2D::BeginFrame() { FrameData &frame = frameData_[curFrame_]; frame.descSets.clear(); vkResetDescriptorPool(vulkan_->GetDevice(), frame.descPool, 0); }
void DescriptorPool::reset() { EXPECT(vkResetDescriptorPool(device(), handle(), 0) == VK_SUCCESS); }
void DescriptorPool::Reset() const { VK_THROW_IF_NOT_SUCCESS(vkResetDescriptorPool(m_Device->GetHandle(), m_Handle, 0), "Failed to reset descriptor pool"); }