private void PrepareDescriptor(VkDevice device) { // 今は定数バッファを1つ、サンプラーを1つを格納できるだけのディスクリプタプールを準備. VkDescriptorPoolSize descriptorPoolSize = new VkDescriptorPoolSize() { descriptorCount = 1, type = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, }; VkDescriptorPoolSize descriptorPoolSizeForSampler = new VkDescriptorPoolSize() { descriptorCount = 1, type = VkDescriptorType.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, }; var descriptorPoolCreateInfo = new VkDescriptorPoolCreateInfo() { poolSizes = new[] { descriptorPoolSize, descriptorPoolSizeForSampler }, maxSets = 1, flags = VkDescriptorPoolCreateFlags.VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, }; VulkanAPI.vkCreateDescriptorPool(device, ref descriptorPoolCreateInfo, out m_descriptorPool); // ディスクリプタセットレイアウトの作成. // - 定数バッファを1つ // - テクスチャサンプラ1つ var descLayoutBindingForUniform = new VkDescriptorSetLayoutBinding(); descLayoutBindingForUniform.binding = 0; descLayoutBindingForUniform.descriptorCount = 1; descLayoutBindingForUniform.descriptorType = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; descLayoutBindingForUniform.stageFlags = VkShaderStageFlagBits.VK_SHADER_STAGE_VERTEX_BIT; var descLayoutBindingForSampler = new VkDescriptorSetLayoutBinding(); descLayoutBindingForSampler.binding = 1; descLayoutBindingForSampler.descriptorCount = 1; descLayoutBindingForSampler.descriptorType = VkDescriptorType.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; descLayoutBindingForSampler.stageFlags = VkShaderStageFlagBits.VK_SHADER_STAGE_FRAGMENT_BIT; var descriptorSetLayoutCreateInfo = new VkDescriptorSetLayoutCreateInfo(); descriptorSetLayoutCreateInfo.bindings = new[] { descLayoutBindingForUniform, descLayoutBindingForSampler }; VulkanAPI.vkCreateDescriptorSetLayout(device, ref descriptorSetLayoutCreateInfo, out m_descriptorSetLayout); // ディスクリプタを作成&更新. VkDescriptorSet[] descriptorSets; var descriptorSetAllocateInfo = new VkDescriptorSetAllocateInfo(m_descriptorPool, new[] { m_descriptorSetLayout }); VulkanAPI.vkAllocateDescriptorSets(device, ref descriptorSetAllocateInfo, out descriptorSets); m_descriptorSet = descriptorSets[0]; var descUniform = new VkDescriptorBufferInfo() { buffer = m_uniformBuffer, range = Marshal.SizeOf <Transform>(), }; var descSampler = new VkDescriptorImageInfo() { imageView = m_imageView, sampler = m_imageSampler, }; var descForUniform = SampleHelpers.CreateDescriptorFromUniformBuffer(0, descUniform, m_descriptorSet); var descForSampler = SampleHelpers.CreateDescriptorFromImageSampler(1, descSampler, m_descriptorSet); var descriptorWrites = new[] { descForUniform, descForSampler }; VulkanAPI.vkUpdateDescriptorSets(device, descriptorWrites, null); }