VulkanDescriptorSet* VulkanDescriptorManager::createSet(VulkanDescriptorLayout* layout) { // Note: We always retrieve the last created pool, even though there could be free room in earlier pools. However // that requires additional tracking. Since the assumption is that the first pool will be large enough for all // descriptors, and the only reason to create a second pool is fragmentation, this approach should not result in // a major resource waste. VkDescriptorSetLayout setLayout = layout->getHandle(); VkDescriptorSetAllocateInfo allocateInfo; allocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; allocateInfo.pNext = nullptr; allocateInfo.descriptorPool = mPools.back()->getHandle(); allocateInfo.descriptorSetCount = 1; allocateInfo.pSetLayouts = &setLayout; VkDescriptorSet set; VkResult result = vkAllocateDescriptorSets(mDevice.getLogical(), &allocateInfo, &set); if(result < 0) // Possible fragmentation, try in a new pool { mPools.push_back(bs_new<VulkanDescriptorPool>(mDevice)); allocateInfo.descriptorPool = mPools.back()->getHandle(); result = vkAllocateDescriptorSets(mDevice.getLogical(), &allocateInfo, &set); assert(result == VK_SUCCESS); } return mDevice.getResourceManager().create<VulkanDescriptorSet>(set, allocateInfo.descriptorPool); }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo descriptorSetAllocInfo; // Scene rendering descriptorSetAllocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.scene, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAllocInfo, &descriptorSets.scene)); std::vector<VkWriteDescriptorSet> offScreenWriteDescriptorSets = { // Binding 0: Vertex shader uniform buffer vks::initializers::writeDescriptorSet(descriptorSets.scene, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.scene.descriptor), // Binding 1: Color gradient sampler vks::initializers::writeDescriptorSet(descriptorSets.scene, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &textures.gradient.descriptor), }; vkUpdateDescriptorSets(device, offScreenWriteDescriptorSets.size(), offScreenWriteDescriptorSets.data(), 0, NULL); // Fullscreen radial blur descriptorSetAllocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.radialBlur, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAllocInfo, &descriptorSets.radialBlur)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0: Vertex shader uniform buffer vks::initializers::writeDescriptorSet(descriptorSets.radialBlur, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.blurParams.descriptor), // Binding 0: Fragment shader texture sampler vks::initializers::writeDescriptorSet(descriptorSets.radialBlur, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &offscreenPass.descriptor), }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptors() { std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = { vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0) }; VkDescriptorSetLayoutCreateInfo descriptorLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings); VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayoutCI, nullptr, &descriptorSetLayout)); VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(&descriptorSetLayout, 1); VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout)); VkDescriptorPoolSize poolSize = vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2); VkDescriptorPoolCreateInfo descriptorPoolCI = vks::initializers::descriptorPoolCreateInfo(1, &poolSize, 2); VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolCI, nullptr, &descriptorPool)); VkDescriptorSetAllocateInfo descriptorSetAI = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAI, &descriptorSets.CW)); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAI, &descriptorSets.CCW)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { vks::initializers::writeDescriptorSet(descriptorSets.CW, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &textures.CW.descriptor), vks::initializers::writeDescriptorSet(descriptorSets.CCW, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &textures.CCW.descriptor) }; vkUpdateDescriptorSets(device, 2, &writeDescriptorSets[0], 0, nullptr); }
void setupDescriptorSets() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); // Occluder (plane) VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformData.vsScene.descriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); // Teapot VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.teapot)); writeDescriptorSets[0].dstSet = descriptorSets.teapot; writeDescriptorSets[0].pBufferInfo = &uniformData.teapot.descriptor; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); // Sphere VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.sphere)); writeDescriptorSets[0].dstSet = descriptorSets.sphere; writeDescriptorSets[0].pBufferInfo = &uniformData.sphere.descriptor; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSets() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayouts.models, 1); // 3D object descriptor set VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.object)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { vkTools::initializers::writeDescriptorSet(descriptorSets.object, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.matrices.descriptor), vkTools::initializers::writeDescriptorSet(descriptorSets.object, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &textures.envmap.descriptor), vkTools::initializers::writeDescriptorSet(descriptorSets.object, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2, &uniformBuffers.params.descriptor), }; vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); // Sky box descriptor set VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.skybox)); writeDescriptorSets = { vkTools::initializers::writeDescriptorSet(descriptorSets.skybox, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0,&uniformBuffers.matrices.descriptor), vkTools::initializers::writeDescriptorSet(descriptorSets.skybox, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &textures.envmap.descriptor), vkTools::initializers::writeDescriptorSet(descriptorSets.skybox, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2, &uniformBuffers.params.descriptor), }; vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); // Bloom filter allocInfo = vkTools::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.bloomFilter, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.bloomFilter)); std::vector<VkDescriptorImageInfo> colorDescriptors = { vkTools::initializers::descriptorImageInfo(offscreen.sampler, offscreen.color[0].view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL), vkTools::initializers::descriptorImageInfo(offscreen.sampler, offscreen.color[1].view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL), }; writeDescriptorSets = { vkTools::initializers::writeDescriptorSet(descriptorSets.bloomFilter, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &colorDescriptors[0]), vkTools::initializers::writeDescriptorSet(descriptorSets.bloomFilter, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &colorDescriptors[1]), }; vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); // Composition descriptor set allocInfo = vkTools::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.composition, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.composition)); colorDescriptors = { vkTools::initializers::descriptorImageInfo(offscreen.sampler, offscreen.color[0].view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL), vkTools::initializers::descriptorImageInfo(offscreen.sampler, filterPass.color[0].view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL), }; writeDescriptorSets = { vkTools::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &colorDescriptors[0]), vkTools::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &colorDescriptors[1]), }; vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSets() { // Image descriptor for the cube map texture VkDescriptorImageInfo cubeMapDescriptor = vkTools::initializers::descriptorImageInfo( cubeMap.sampler, cubeMap.view, VK_IMAGE_LAYOUT_GENERAL); VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); // 3D object descriptor set VkResult vkRes = vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.object); assert(!vkRes); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vkTools::initializers::writeDescriptorSet( descriptorSets.object, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformData.objectVS.descriptor), // Binding 1 : Fragment shader cubemap sampler vkTools::initializers::writeDescriptorSet( descriptorSets.object, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &cubeMapDescriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); // Sky box descriptor set vkRes = vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.skybox); assert(!vkRes); writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vkTools::initializers::writeDescriptorSet( descriptorSets.skybox, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformData.skyboxVS.descriptor), // Binding 1 : Fragment shader cubemap sampler vkTools::initializers::writeDescriptorSet( descriptorSets.skybox, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &cubeMapDescriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSets() { // Image descriptor for the cube map texture VkDescriptorImageInfo textureDescriptor = vks::initializers::descriptorImageInfo( cubeMap.sampler, cubeMap.view, cubeMap.imageLayout); VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); // 3D object descriptor set VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.object)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vks::initializers::writeDescriptorSet( descriptorSets.object, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.object.descriptor), // Binding 1 : Fragment shader cubemap sampler vks::initializers::writeDescriptorSet( descriptorSets.object, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &textureDescriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); // Sky box descriptor set VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.skybox)); writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vks::initializers::writeDescriptorSet( descriptorSets.skybox, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.skybox.descriptor), // Binding 1 : Fragment shader cubemap sampler vks::initializers::writeDescriptorSet( descriptorSets.skybox, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &textureDescriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void VulkanUniformBuffer::InitializeDescriptorSet ( VkDescriptorSet& aVkDescriptorSet, const VkDescriptorSetLayout& aVkDescriptorSetLayout, const VkDescriptorBufferInfo& aVkDescriptorBufferInfo ) { VkDescriptorSetAllocateInfo descriptor_set_allocate_info{}; descriptor_set_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptor_set_allocate_info.descriptorPool = mVkDescriptorPool; descriptor_set_allocate_info.descriptorSetCount = 1; descriptor_set_allocate_info.pSetLayouts = &aVkDescriptorSetLayout; if ( VkResult result = vkAllocateDescriptorSets ( mVulkanRenderer.GetDevice(), &descriptor_set_allocate_info, &aVkDescriptorSet ) ) { std::ostringstream stream; stream << "Allocate Descriptor Set failed: ( " << GetVulkanResultString ( result ) << " )"; throw std::runtime_error ( stream.str().c_str() ); } VkWriteDescriptorSet write_descriptor_set{}; write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; write_descriptor_set.pNext = nullptr; write_descriptor_set.dstSet = aVkDescriptorSet; write_descriptor_set.dstBinding = 0; write_descriptor_set.dstArrayElement = 0; write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; write_descriptor_set.descriptorCount = 1; write_descriptor_set.pBufferInfo = &aVkDescriptorBufferInfo; write_descriptor_set.pImageInfo = nullptr; write_descriptor_set.pTexelBufferView = nullptr; vkUpdateDescriptorSets ( mVulkanRenderer.GetDevice(), 1, &write_descriptor_set, 0, nullptr ); }
/* Please see header for specification */ bool Anvil::DescriptorPool::alloc_descriptor_sets(uint32_t n_sets, Anvil::DescriptorSetLayout** descriptor_set_layouts_ptr, VkDescriptorSet* out_descriptor_sets_vk_ptr) { VkDescriptorSetAllocateInfo ds_alloc_info; VkResult result_vk; m_ds_layout_cache.resize(n_sets); for (uint32_t n_set = 0; n_set < n_sets; ++n_set) { m_ds_layout_cache[n_set] = descriptor_set_layouts_ptr[n_set]->get_layout(); } ds_alloc_info.descriptorPool = m_pool; ds_alloc_info.descriptorSetCount = n_sets; ds_alloc_info.pNext = nullptr; ds_alloc_info.pSetLayouts = &m_ds_layout_cache[0]; ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; result_vk = vkAllocateDescriptorSets(m_device_ptr->get_device_vk(), &ds_alloc_info, out_descriptor_sets_vk_ptr); anvil_assert_vk_call_succeeded(result_vk); return is_vk_call_successful(result_vk); }
void Copy_To_Swapchain::update_resolution_dependent_descriptors(VkImageView output_image_view) { if (sets.size() < vk.swapchain_info.images.size()) { size_t n = vk.swapchain_info.images.size() - sets.size(); for (size_t i = 0; i < n; i++) { VkDescriptorSetAllocateInfo alloc_info { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO }; alloc_info.descriptorPool = vk.descriptor_pool; alloc_info.descriptorSetCount = 1; alloc_info.pSetLayouts = &set_layout; VkDescriptorSet set; VK_CHECK(vkAllocateDescriptorSets(vk.device, &alloc_info, &set)); sets.push_back(set); Descriptor_Writes(set).sampler(0, point_sampler); } } for (size_t i = 0; i < vk.swapchain_info.images.size(); i++) { Descriptor_Writes(sets[i]) .sampled_image(1, output_image_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) .storage_image(2, vk.swapchain_info.image_views[i]); } }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VkResult vkRes = vkAllocateDescriptorSets(device, &allocInfo, &descriptorSetPostCompute); assert(!vkRes); // Image descriptor for the color map texture VkDescriptorImageInfo texDescriptor = vkTools::initializers::descriptorImageInfo( textureColorMap.sampler, textureColorMap.view, VK_IMAGE_LAYOUT_GENERAL); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 1 : Fragment shader image sampler vkTools::initializers::writeDescriptorSet( descriptorSetPostCompute, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &texDescriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
std::vector<DescriptorSet *> DescriptorPool::alloc_sets( const Device &dev, const std::vector<const DescriptorSetLayout *> &layouts) { const std::vector<VkDescriptorSetLayout> layout_handles = make_handles<VkDescriptorSetLayout>(layouts); std::vector<VkDescriptorSet> set_handles; set_handles.resize(layout_handles.size()); VkDescriptorSetAllocateInfo alloc_info = {}; alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; alloc_info.descriptorSetCount = layout_handles.size(); alloc_info.descriptorPool = handle(); alloc_info.pSetLayouts = layout_handles.data(); VkResult err = vkAllocateDescriptorSets(device(), &alloc_info, set_handles.data()); EXPECT(err == VK_SUCCESS); std::vector<DescriptorSet *> sets; for (std::vector<VkDescriptorSet>::const_iterator it = set_handles.begin(); it != set_handles.end(); it++) { // do descriptor sets need memories bound? DescriptorSet *descriptorSet = new DescriptorSet(dev, this, *it); sets.push_back(descriptorSet); } return sets; }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); // Image descriptor for the texture array VkDescriptorImageInfo texArrayDescriptor = vkTools::initializers::descriptorImageInfo( textureArray.sampler, textureArray.view, VK_IMAGE_LAYOUT_GENERAL); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformData.vertexShader.descriptor), // Binding 1 : Fragment shader cubemap sampler vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &texArrayDescriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSets() { std::vector<VkDescriptorPoolSize> poolSizes = { vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1), }; VkDescriptorPoolCreateInfo descriptorPoolCI = vks::initializers::descriptorPoolCreateInfo(poolSizes.size(), poolSizes.data(), 1); VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolCI, nullptr, &descriptorPool)); std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = { vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0), }; VkDescriptorSetLayoutCreateInfo descriptorLayoutCI{}; descriptorLayoutCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; descriptorLayoutCI.bindingCount = static_cast<uint32_t>(setLayoutBindings.size()); descriptorLayoutCI.pBindings = setLayoutBindings.data(); VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayoutCI, nullptr, &descriptorSetLayout)); std::array<VkDescriptorSetLayout, 2> setLayouts = { descriptorSetLayout, scene.descriptorSetLayout }; VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(setLayouts.data(), 2); VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::vec4) * 2, 0); pipelineLayoutCI.pushConstantRangeCount = 1; pipelineLayoutCI.pPushConstantRanges = &pushConstantRange; VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout)); VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorSetAllocateInfo, &descriptorSet)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffer.descriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
VkBool32 Example::buildDescriptorSets() { VkResult result; // VkDescriptorSetAllocateInfo descriptorSetAllocateInfo; memset(&descriptorSetAllocateInfo, 0, sizeof(VkDescriptorSetAllocateInfo)); descriptorSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptorSetAllocateInfo.descriptorPool = descriptorPool; descriptorSetAllocateInfo.descriptorSetCount = 1; descriptorSetAllocateInfo.pSetLayouts = &descriptorSetLayout; result = vkAllocateDescriptorSets(device->getDevice(), &descriptorSetAllocateInfo, &descriptorSet); if (result != VK_SUCCESS) { vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not alloc descriptor sets."); return VK_FALSE; } return VK_TRUE; }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBufferVS.descriptor), // Binding 1 : Fragment shader texture sampler vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &texture.descriptor) }; vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSets() { // Descriptor Pool std::vector<VkDescriptorPoolSize> poolSizes = { vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4), }; VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(poolSizes, 2); VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool)); // Descriptor sets VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1); // 3D object descriptor set VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.object.descriptor), vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &uniformBuffers.params.descriptor), }; vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VkResult vkRes = vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet); assert(!vkRes); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Vertex shader shader ubo vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformData.VS.descriptor), // Binding 1 : Geometry shader ubo vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &uniformData.GS.descriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); VkDescriptorImageInfo texDescriptor = vks::initializers::descriptorImageInfo( textures.colorMap.sampler, textures.colorMap.view, VK_IMAGE_LAYOUT_GENERAL); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vks::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffer.descriptor), // Binding 1 : Color map vks::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &texDescriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSets() { VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.VS.descriptor) }; vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VkResult vkRes = vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet); assert(!vkRes); // Displacement map image descriptor VkDescriptorImageInfo texDescriptorDisplacementMap = vkTools::initializers::descriptorImageInfo( textures.heightMap.sampler, textures.heightMap.view, VK_IMAGE_LAYOUT_GENERAL); // Color map image descriptor VkDescriptorImageInfo texDescriptorColorMap = vkTools::initializers::descriptorImageInfo( textures.colorMap.sampler, textures.colorMap.view, VK_IMAGE_LAYOUT_GENERAL); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Tessellation control shader ubo vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformDataTC.descriptor), // Binding 1 : Tessellation evaluation shader ubo vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &uniformDataTE.descriptor), // Binding 2 : Displacement map vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, &texDescriptorDisplacementMap), // Binding 3 : Color map vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 3, &texDescriptorColorMap), }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VkResult vkRes = vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet); assert(!vkRes); // Color map image descriptor VkDescriptorImageInfo texDescriptorColorMap = vkTools::initializers::descriptorImageInfo( textures.colorMap.sampler, textures.colorMap.view, VK_IMAGE_LAYOUT_GENERAL); VkDescriptorImageInfo texDescriptorNormalHeightMap = vkTools::initializers::descriptorImageInfo( textures.normalHeightMap.sampler, textures.normalHeightMap.view, VK_IMAGE_LAYOUT_GENERAL); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { // Binding 0 : Vertex shader uniform buffer vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformData.vertexShader.descriptor), // Binding 1 : Fragment shader image sampler vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &texDescriptorColorMap), // Binding 2 : Combined normal and heightmap vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, &texDescriptorNormalHeightMap), // Binding 3 : Fragment shader uniform buffer vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 3, &uniformData.fragmentShader.descriptor) }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
VkDescriptorSet allocateDescriptorSet(VkDevice device, VkDescriptorPool pool, VkDescriptorSetLayout layout) { VkResult result; VkDescriptorSetAllocateInfo allocInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; allocInfo.descriptorPool = pool; allocInfo.descriptorSetCount = 1; allocInfo.pSetLayouts = &layout; VkDescriptorSet set; result = vkAllocateDescriptorSets(device, &allocInfo, &set); assert(result == VK_SUCCESS); return set; }
void allocateDescriptorSets(VkDevice device, VkDescriptorPool pool, VkDescriptorSetLayout layout, uint32_t count, std::vector<VkDescriptorSet>& sets) { sets.resize(count); std::vector<VkDescriptorSetLayout> layouts(count, layout); VkResult result; VkDescriptorSetAllocateInfo allocInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; allocInfo.descriptorPool = pool; allocInfo.descriptorSetCount = count; allocInfo.pSetLayouts = layouts.data(); result = vkAllocateDescriptorSets(device, &allocInfo, sets.data()); assert(result == VK_SUCCESS); }
VkDescriptorSet VKDevice::allocate_desc_set (const VkDescriptorSetAllocateInfo &info) { XCAM_ASSERT (XCAM_IS_VALID_VK_ID (_dev_id)); VkDescriptorSet set_id; XCAM_VK_CHECK_RETURN ( ERROR, vkAllocateDescriptorSets (_dev_id, &info, &set_id), VK_NULL_HANDLE, "vkdevice create desriptor set failed"); return set_id; }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); std::vector<VkWriteDescriptorSet> writeDescriptorSets; // Binding 0: Vertex shader uniform buffer writeDescriptorSets.push_back(vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBufferVS.descriptor)); // Binding 1: Sampled image VkDescriptorImageInfo textureDescriptor = vkTools::initializers::descriptorImageInfo( VK_NULL_HANDLE, texture.view, texture.imageLayout); writeDescriptorSets.push_back(vkTools::initializers::writeDescriptorSet( descriptorSet, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, &textureDescriptor)); // Binding 2: Sampler array std::vector<VkDescriptorImageInfo> samplerDescriptors; for (auto i = 0; i < samplers.size(); i++) { samplerDescriptors.push_back(vkTools::initializers::descriptorImageInfo(samplers[i], VK_NULL_HANDLE, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)); } VkWriteDescriptorSet samplerDescriptorWrite{}; samplerDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; samplerDescriptorWrite.dstSet = descriptorSet; samplerDescriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; samplerDescriptorWrite.descriptorCount = static_cast<uint32_t>(samplerDescriptors.size()); samplerDescriptorWrite.pImageInfo = samplerDescriptors.data(); samplerDescriptorWrite.dstBinding = 2; samplerDescriptorWrite.dstArrayElement = 0; writeDescriptorSets.push_back(samplerDescriptorWrite); vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); }
bool VKMaterial::setupDescriptorSet(VkDescriptorPool descriptorPool, VkDevice device) { VkResult err; //Setup the descriptor sets VkDescriptorSetAllocateInfo allocInfo = {}; allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; allocInfo.descriptorPool = descriptorPool; allocInfo.pSetLayouts = &m_materialLayout; allocInfo.descriptorSetCount = 1; err = vkAllocateDescriptorSets(device, &allocInfo, &m_materialSet); assert(!err); if (err != VK_SUCCESS) { #ifdef _DEBUG Core::DebugPrintF("VKMaterial::VPrepare: Failed to allocate descriptor set\n"); #endif return false; } std::vector<VkWriteDescriptorSet> descSetWrites = {}; VkWriteDescriptorSet uniformVSWrite = {}; uniformVSWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; uniformVSWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; uniformVSWrite.dstSet = m_materialSet; uniformVSWrite.dstBinding = 0; uniformVSWrite.pBufferInfo = &m_uniformVSBuffer.descriptor; uniformVSWrite.descriptorCount = 1; //VkWriteDescriptorSet uniformFSWrite = {}; //uniformFSWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; //uniformFSWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; //uniformFSWrite.dstSet = m_materialSet; //uniformFSWrite.dstBinding = 1; //uniformFSWrite.pBufferInfo = &m_uniformFSBuffer.descriptor; //uniformFSWrite.descriptorCount = 1; //TODO: Figure out the writes for the textures descSetWrites.push_back(uniformVSWrite); //descSetWrites.push_back(uniformFSWrite); vkUpdateDescriptorSets(device, static_cast<uint32_t>(descSetWrites.size()), descSetWrites.data(), 0, nullptr); return true; }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffer.descriptor), // Binding 0 : Vertex shader uniform buffer }; vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = vkTools::initializers::descriptorSetAllocateInfo( descriptorPool, &descriptorSetLayout, 1); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet)); std::vector<VkWriteDescriptorSet> writeDescriptorSets = { vkTools::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffer.descriptor), vkTools::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &textures.colormap.descriptor), }; vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); }
Arguments::Arguments(Program &function, std::vector<Buffer> resources) : Program(function) { // how many of each type VkDescriptorPoolSize descriptorPoolSizes[] = { {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, (uint32_t) resources.size()} }; VkDescriptorPoolCreateInfo descriptorPoolCreateInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; descriptorPoolCreateInfo.poolSizeCount = 1; descriptorPoolCreateInfo.maxSets = 1; descriptorPoolCreateInfo.pPoolSizes = descriptorPoolSizes; if (VK_SUCCESS != vkCreateDescriptorPool(device, &descriptorPoolCreateInfo, nullptr, &descriptorPool)) { throw ERROR_SHADER; } // allocate the descriptor set (according to the function's layout) VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; descriptorSetAllocateInfo.descriptorSetCount = 1; // 1? descriptorSetAllocateInfo.pSetLayouts = &descriptorSetLayout; descriptorSetAllocateInfo.descriptorPool = descriptorPool; if (VK_SUCCESS != vkAllocateDescriptorSets(device, &descriptorSetAllocateInfo, &descriptorSet)) { throw ERROR_SHADER; } // bind to this // buffers to bind VkDescriptorBufferInfo *descriptorBufferInfo = new VkDescriptorBufferInfo[resources.size()]; for (uint32_t i = 0; i < resources.size(); i++) { descriptorBufferInfo[i].buffer = resources[i]; descriptorBufferInfo[i].offset = 0; descriptorBufferInfo[i].range = VK_WHOLE_SIZE; } // bind stuff here VkWriteDescriptorSet writeDescriptorSet = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}; writeDescriptorSet.dstSet = descriptorSet;//pipeline.getDescriptorSet(); writeDescriptorSet.dstBinding = 0; writeDescriptorSet.descriptorCount = resources.size(); writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; writeDescriptorSet.pBufferInfo = descriptorBufferInfo; vkUpdateDescriptorSets(device, 1, &writeDescriptorSet, 0, nullptr); delete [] descriptorBufferInfo; }