void setupDescriptorSet() { // Scene rendering { VkDescriptorSetLayout dsl = setLayoutScene; var info = VkDescriptorSetAllocateInfo.Alloc(); info->setLayouts = dsl; info->descriptorPool = descriptorPool; VkDescriptorSet set; vkAllocateDescriptorSets(device, info, &set); this.setScene = set; } { var descriptor0 = uniformBufferScene.descriptor; var descriptor1 = textures_gradient.descriptor; var writes = VkWriteDescriptorSet.Alloc(2); { // Binding 0: Vertex shader uniform buffer writes[0].dstSet = setScene; writes[0].data.descriptorType = VkDescriptorType.UniformBuffer; writes[0].dstBinding = 0; writes[0].data.Set(descriptor0); // Binding 1: Color gradient sampler writes[1].dstSet = setScene; writes[1].data.descriptorType = VkDescriptorType.CombinedImageSampler; writes[1].dstBinding = 1; writes[1].data.Set(descriptor1); } vkUpdateDescriptorSets(device, 2, writes, 0, null); } // Fullscreen radial blur { VkDescriptorSetLayout dsl = setLayoutRadialBlur; var info = VkDescriptorSetAllocateInfo.Alloc(); info->setLayouts = dsl; info->descriptorPool = descriptorPool; VkDescriptorSet set; vkAllocateDescriptorSets(device, info, &set); this.setRadialBlur = set; } { VkDescriptorBufferInfo descriptor0 = uniformBufferBlurParams.descriptor; VkDescriptorImageInfo descriptor1 = offscreenPass.descriptorImage; var writes = VkWriteDescriptorSet.Alloc(2); { // Binding 0: Vertex shader uniform buffer writes[0].dstSet = setRadialBlur; writes[0].data.descriptorType = VkDescriptorType.UniformBuffer; writes[0].dstBinding = 0; writes[0].data.Set(descriptor0); // Binding 0: Fragment shader texture sampler writes[1].dstSet = setRadialBlur; writes[1].data.descriptorType = VkDescriptorType.CombinedImageSampler; writes[1].dstBinding = 1; writes[1].data.Set(descriptor1); } vkUpdateDescriptorSets(device, 2, writes, 0, null); } }
public static VkDescriptorSet AllocateDescriptorSets(ref VkDescriptorSetAllocateInfo pAllocateInfo) { VkDescriptorSet pDescriptorSets; VulkanUtil.CheckResult(vkAllocateDescriptorSets(device, Utilities.AsPtr(ref pAllocateInfo), &pDescriptorSets)); return(pDescriptorSets); }
public unsafe DescriptorSet(DescriptorPool descriptorPool, uint setCount = 1) { _device = descriptorPool.Device; _descriptorPool = descriptorPool; var layouts = new NativeList <VkDescriptorSetLayout>(setCount); for (int i = 0; i < setCount; i++) { layouts.Add(descriptorPool.Layout.Handle); } var allocateInfo = new VkDescriptorSetAllocateInfo { sType = VkStructureType.DescriptorSetAllocateInfo, descriptorPool = descriptorPool.Handle, descriptorSetCount = setCount, pSetLayouts = (VkDescriptorSetLayout *)layouts.Data.ToPointer() }; VkDescriptorSet descriptorSet; if (VulkanNative.vkAllocateDescriptorSets( _device.Handle, &allocateInfo, &descriptorSet ) != VkResult.Success) { throw new Exception("failed to allocate descriptor sets"); } _handle = descriptorSet; }
void setupDescriptorSet() { var dsl = descriptorSetLayout; VkDescriptorSetAllocateInfo allocInfo = Initializers.descriptorSetAllocateInfo( descriptorPool, &dsl, 1); Util.CheckResult(vkAllocateDescriptorSets(device, &allocInfo, out descriptorSet)); VkDescriptorImageInfo texDescriptor = Initializers.descriptorImageInfo( textures_colorMap.sampler, textures_colorMap.view, VkImageLayout.General); var temp = uniformBuffers_scene.descriptor; FixedArray2 <VkWriteDescriptorSet> writeDescriptorSets = new FixedArray2 <VkWriteDescriptorSet>( // Binding 0 : Vertex shader uniform buffer Initializers.writeDescriptorSet( descriptorSet, VkDescriptorType.UniformBuffer, 0, &temp), // Binding 1 : Color map Initializers.writeDescriptorSet( descriptorSet, VkDescriptorType.CombinedImageSampler, 1, &texDescriptor)); vkUpdateDescriptorSets(device, (writeDescriptorSets.Count), ref writeDescriptorSets.First, 0, null); }
public DescriptorSet(DescriptorSetLayout resLayout) { resLayout.Build(); descriptorPool = Graphics.DescriptorPoolManager.GetPool(ref resLayout.descriptorResourceCounts, Swapchain.IMAGE_COUNT); resourceLayout = resLayout; unsafe { var setLayouts = stackalloc VkDescriptorSetLayout[3] { resLayout.Handle, resLayout.Handle, resLayout.Handle }; var descriptorSetAllocateInfo = new VkDescriptorSetAllocateInfo { sType = VkStructureType.DescriptorSetAllocateInfo, descriptorPool = descriptorPool, pSetLayouts = setLayouts, descriptorSetCount = Swapchain.IMAGE_COUNT }; Device.AllocateDescriptorSets(ref descriptorSetAllocateInfo, (VkDescriptorSet *)descriptorSet.Data); } bindedRes = new IBindableResource[resLayout.NumBindings]; for (int i = 0; i < Swapchain.IMAGE_COUNT; i++) { writeDescriptorSets[i] = new VkWriteDescriptorSet[resLayout.NumBindings]; } }
void SetupDescriptorSet(Pipeline pipeline, GraphicsDevice device, UniformBuffer uniformBuffer, Texture2D texture_colorMap) { var dsl = pipeline.descriptorSetLayout; VkDescriptorSetAllocateInfo allocInfo = Initializers.descriptorSetAllocateInfo( pipeline.descriptorPool, &dsl, 1); Util.CheckResult(vkAllocateDescriptorSets(device.device, &allocInfo, out pipeline.descriptorSet)); VkDescriptorImageInfo texDescriptor = Initializers.descriptorImageInfo( texture_colorMap.sampler, texture_colorMap.view, VkImageLayout.General); VkDescriptorBufferInfo temp = uniformBuffer.GetVkDescriptor(); FixedArray2 <VkWriteDescriptorSet> writeDescriptorSets = new FixedArray2 <VkWriteDescriptorSet>( // Binding 0 : Vertex shader uniform buffer Initializers.writeDescriptorSet( pipeline.descriptorSet, VkDescriptorType.UniformBuffer, uniformBuffer.location, &temp), // Binding 1 : Color map Initializers.writeDescriptorSet( pipeline.descriptorSet, VkDescriptorType.CombinedImageSampler, 1, &texDescriptor)); vkUpdateDescriptorSets(device.device, (writeDescriptorSets.Count), ref writeDescriptorSets.First, 0, null); }
void CreateDescriptorSet() { var layouts = new List <VkDescriptorSetLayout> { descriptorSetLayout }; var info = new VkDescriptorSetAllocateInfo(); info.setLayouts = layouts; descriptorSet = descriptorPool.Allocate(info)[0]; var bufferInfo = new VkDescriptorBufferInfo(); bufferInfo.buffer = uniformBuffer; bufferInfo.offset = 0; bufferInfo.range = Interop.SizeOf <UniformBufferObject>(); var descriptorWrites = new List <VkWriteDescriptorSet>(); descriptorWrites.Add(new VkWriteDescriptorSet()); descriptorWrites[0].dstSet = descriptorSet; descriptorWrites[0].dstBinding = 0; descriptorWrites[0].dstArrayElement = 0; descriptorWrites[0].descriptorType = VkDescriptorType.UniformBuffer; descriptorWrites[0].bufferInfo = new List <VkDescriptorBufferInfo> { bufferInfo }; descriptorSet.Update(descriptorWrites, null); }
VkDescriptorSet CreateDescriptorSet(VkDevice device, VkDescriptorSetLayout descriptorSetLayout) { VkDescriptorPool descriptorPool; { // this pool can allocate one uniform descriptor. var info = new VkDescriptorPoolCreateInfo { sType = VkStructureType.DescriptorPoolCreateInfo }; var size = new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 1); info.poolSizes = size; info.maxSets = 1; vkAPI.vkCreateDescriptorPool(device, &info, null, &descriptorPool).Check(); info.Free(); } VkDescriptorSet descriptorSet; { var info = new VkDescriptorSetAllocateInfo { sType = VkStructureType.DescriptorSetAllocateInfo }; info.setLayouts = descriptorSetLayout; info.descriptorPool = descriptorPool; vkAPI.vkAllocateDescriptorSets(device, &info, &descriptorSet).Check(); info.Free(); } return(descriptorSet); }
void setupDescriptorSets() { // Image descriptor for the cube map texture VkDescriptorImageInfo textureDescriptor = Initializers.descriptorImageInfo( cubeMap.sampler, cubeMap.view, cubeMap.imageLayout); var dsl = descriptorSetLayout; VkDescriptorSetAllocateInfo allocInfo = Initializers.descriptorSetAllocateInfo( descriptorPool, &dsl, 1); // 3D object descriptor set Util.CheckResult(vkAllocateDescriptorSets(device, &allocInfo, out descriptorSets_object)); var bufferInfo = uniformBuffers_object.descriptor; FixedArray2 <VkWriteDescriptorSet> writeDescriptorSets = new FixedArray2 <VkWriteDescriptorSet> ( // Binding 0 : Vertex shader uniform buffer Initializers.writeDescriptorSet( descriptorSets_object, VkDescriptorType.UniformBuffer, 0, &bufferInfo), // Binding 1 : Fragment shader cubemap sampler Initializers.writeDescriptorSet( descriptorSets_object, VkDescriptorType.CombinedImageSampler, 1, &textureDescriptor)); vkUpdateDescriptorSets(device, writeDescriptorSets.Count, ref writeDescriptorSets.First, 0, null); // Sky box descriptor set Util.CheckResult(vkAllocateDescriptorSets(device, &allocInfo, out descriptorSets_skybox)); var descriptor = uniformBuffers_skybox.descriptor; writeDescriptorSets = new FixedArray2 <VkWriteDescriptorSet> ( // Binding 0 : Vertex shader uniform buffer Initializers.writeDescriptorSet( descriptorSets_skybox, VkDescriptorType.UniformBuffer, 0, &descriptor), // Binding 1 : Fragment shader cubemap sampler Initializers.writeDescriptorSet( descriptorSets_skybox, VkDescriptorType.CombinedImageSampler, 1, &textureDescriptor)); vkUpdateDescriptorSets(device, writeDescriptorSets.Count, ref writeDescriptorSets.First, 0, null); }
public VkResourceSet(VkGraphicsDevice gd, ref ResourceSetDescription description) { _gd = gd; VkResourceLayout vkLayout = Util.AssertSubtype <ResourceLayout, VkResourceLayout>(description.Layout); VkDescriptorSetAllocateInfo dsAI = VkDescriptorSetAllocateInfo.New(); dsAI.descriptorSetCount = 1; VkDescriptorSetLayout dsl = vkLayout.DescriptorSetLayout; dsAI.pSetLayouts = &dsl; dsAI.descriptorPool = _gd.SharedDescriptorPool; VkResult result = vkAllocateDescriptorSets(_gd.Device, ref dsAI, out _descriptorSet); CheckResult(result); BindableResource[] boundResources = description.BoundResources; uint descriptorWriteCount = (uint)boundResources.Length; VkWriteDescriptorSet * descriptorWrites = stackalloc VkWriteDescriptorSet[(int)descriptorWriteCount]; VkDescriptorBufferInfo *bufferInfos = stackalloc VkDescriptorBufferInfo[(int)descriptorWriteCount]; VkDescriptorImageInfo * imageInfos = stackalloc VkDescriptorImageInfo[(int)descriptorWriteCount]; for (int i = 0; i < descriptorWriteCount; i++) { VkDescriptorType type = vkLayout.DescriptorTypes[i]; descriptorWrites[i].sType = VkStructureType.WriteDescriptorSet; descriptorWrites[i].descriptorCount = 1; descriptorWrites[i].descriptorType = type; descriptorWrites[i].dstBinding = (uint)i; descriptorWrites[i].dstSet = _descriptorSet; if (type == VkDescriptorType.UniformBuffer) { VkUniformBuffer uniformBuffer = Util.AssertSubtype <BindableResource, VkUniformBuffer>(boundResources[i]); bufferInfos[i].buffer = uniformBuffer.DeviceBuffer; bufferInfos[i].range = uniformBuffer.SizeInBytes; descriptorWrites[i].pBufferInfo = &bufferInfos[i]; } else if (type == VkDescriptorType.SampledImage) { VkTextureView textureView = Util.AssertSubtype <BindableResource, VkTextureView>(boundResources[i]); imageInfos[i].imageView = textureView.ImageView; imageInfos[i].imageLayout = VkImageLayout.ShaderReadOnlyOptimal; descriptorWrites[i].pImageInfo = &imageInfos[i]; } else if (type == VkDescriptorType.Sampler) { VkSampler sampler = Util.AssertSubtype <BindableResource, VkSampler>(boundResources[i]); imageInfos[i].sampler = sampler.DeviceSampler; descriptorWrites[i].pImageInfo = &imageInfos[i]; } } vkUpdateDescriptorSets(_gd.Device, descriptorWriteCount, descriptorWrites, 0, null); }
public VkResult AllocateDescriptorSets(VkDescriptorSetAllocateInfo pAllocateInfo, VkDescriptorSet[] pDescriptorSets) { for (int i = 0; i < pAllocateInfo.descriptorSetCount; i++) { var descriptorSet = new SoftwareDescriptorSet(this, (SoftwareDescriptorSetLayout)pAllocateInfo.pSetLayouts[i]); m_DescriptorSets.Add(descriptorSet); pDescriptorSets[i] = descriptorSet; } return VkResult.VK_SUCCESS; }
public void Allocate(DescriptorSet descriptorSet) { VkDescriptorSetAllocateInfo allocInfo = VkDescriptorSetAllocateInfo.New(); allocInfo.descriptorPool = handle; allocInfo.descriptorSetCount = (uint)descriptorSet.descriptorSetLayouts.Count; allocInfo.pSetLayouts = descriptorSet.descriptorSetLayouts.Pin(); Utils.CheckResult(vkAllocateDescriptorSets(Dev.VkDev, ref allocInfo, out descriptorSet.handle)); descriptorSet.descriptorSetLayouts.Unpin(); }
public static VkDescriptorSetAllocateInfo descriptorSetAllocateInfo( VkDescriptorPool descriptorPool, VkDescriptorSetLayout *pSetLayouts, uint descriptorSetCount) { VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = VkDescriptorSetAllocateInfo.New(); descriptorSetAllocateInfo.descriptorPool = descriptorPool; descriptorSetAllocateInfo.pSetLayouts = pSetLayouts; descriptorSetAllocateInfo.descriptorSetCount = descriptorSetCount; return(descriptorSetAllocateInfo); }
private void PrepareDescriptor(VkDevice device) { // 定数バッファを1つだけ持つものを作る. VkDescriptorPoolSize descriptorPoolSize = new VkDescriptorPoolSize() { descriptorCount = 1, type = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, }; var descriptorPoolCreateInfo = new VkDescriptorPoolCreateInfo() { poolSizes = new[] { descriptorPoolSize }, maxSets = 1, flags = VkDescriptorPoolCreateFlags.VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, }; VulkanAPI.vkCreateDescriptorPool(device, ref descriptorPoolCreateInfo, out m_descriptorPool); // ディスクリプタセットレイアウトの作成. // 今は定数バッファを1つ持つだけのものを作成. var descriptorLayoutBinding = new VkDescriptorSetLayoutBinding(); descriptorLayoutBinding.binding = 0; descriptorLayoutBinding.descriptorCount = 1; descriptorLayoutBinding.descriptorType = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; descriptorLayoutBinding.stageFlags = VkShaderStageFlagBits.VK_SHADER_STAGE_VERTEX_BIT; var descriptorSetLayoutCreateInfo = new VkDescriptorSetLayoutCreateInfo(); descriptorSetLayoutCreateInfo.bindings = new[] { descriptorLayoutBinding }; 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]; // ディスクリプタを更新. // 定数バッファ1つを持つレイアウトでディスクリプタを作る. VkDescriptorBufferInfo descUniformBufferInfo = new VkDescriptorBufferInfo(); descUniformBufferInfo.buffer = m_uniformBuffer; descUniformBufferInfo.range = Marshal.SizeOf <Transform>(); var descriptor = new VkWriteDescriptorSet(); descriptor.descriptorCount = 1; descriptor.descriptorType = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; descriptor.pBufferInfo = new[] { descUniformBufferInfo }; descriptor.dstBinding = 0; descriptor.dstSet = m_descriptorSet; VulkanAPI.vkUpdateDescriptorSets(device, new[] { descriptor }, null); }
public unsafe DescriptorAllocationToken Allocate(DescriptorResourceCounts counts, VkDescriptorSetLayout setLayout) { VkDescriptorPool pool = GetPool(counts); VkDescriptorSetAllocateInfo dsAI = VkDescriptorSetAllocateInfo.New(); dsAI.descriptorSetCount = 1; dsAI.pSetLayouts = &setLayout; dsAI.descriptorPool = pool; VkResult result = vkAllocateDescriptorSets(_gd.Device, ref dsAI, out VkDescriptorSet set); VulkanUtil.CheckResult(result); return(new DescriptorAllocationToken(set, pool)); }
public void Build(int devId) { if (!locked) { if (Layout.Layouts.Count == 0 | Pool.PoolEntries.Count == 0) { return; } unsafe { var layout_sets = stackalloc IntPtr[] { Layout.hndl }; var desc_set_alloc_info = new VkDescriptorSetAllocateInfo() { sType = VkStructureType.StructureTypeDescriptorSetAllocateInfo, descriptorPool = Pool.hndl, descriptorSetCount = 1, pSetLayouts = layout_sets, }; fixed(IntPtr *hndl_p = &hndl) if (vkAllocateDescriptorSets(GraphicsDevice.GetDeviceInfo(devId).Device, desc_set_alloc_info.Pointer(), hndl_p) != VkResult.Success) { throw new Exception("Failed to allocate descriptor sets."); } devID = devId; if (GraphicsDevice.EnableValidation) { var objName = new VkDebugUtilsObjectNameInfoEXT() { sType = VkStructureType.StructureTypeDebugUtilsObjectNameInfoExt, pObjectName = Name, objectType = VkObjectType.ObjectTypeDescriptorSet, objectHandle = (ulong)hndl }; GraphicsDevice.SetDebugUtilsObjectNameEXT(GraphicsDevice.GetDeviceInfo(devID).Device, objName.Pointer()); } } locked = true; } else { throw new Exception("DescriptorSet is locked."); } }
void setupDescriptorSet() { var allocInfo = new VkDescriptorSetAllocateInfo(); allocInfo.sType = DescriptorSetAllocateInfo; allocInfo.descriptorPool = descriptorPool; allocInfo.setLayouts = descriptorSetLayout; VkDescriptorSet set; vkAllocateDescriptorSets(device, &allocInfo, &set); this.descriptorSet = set; VkDescriptorBufferInfo descriptor0 = uniformBuffers_view.descriptor; VkDescriptorBufferInfo descriptor1 = uniformBuffers_dynamic.descriptor; var writeDescriptorSets = new VkWriteDescriptorSet[2]; { // Binding 0 : Projection/View matrix uniform buffer var a = new VkWriteDescriptorSet() { sType = WriteDescriptorSet, dstSet = descriptorSet, dstBinding = 0, }; a.data.descriptorType = VkDescriptorType.UniformBuffer; a.data.Set(descriptor0); writeDescriptorSets[0] = a; // Binding 1 : Instance matrix as dynamic uniform buffer var b = new VkWriteDescriptorSet() { sType = WriteDescriptorSet, dstSet = descriptorSet, dstBinding = 1, }; b.data.descriptorType = VkDescriptorType.UniformBufferDynamic; b.data.Set(descriptor1); writeDescriptorSets[1] = b; }; fixed(VkWriteDescriptorSet *pointer = writeDescriptorSets) { vkUpdateDescriptorSets(device, (UInt32)writeDescriptorSets.Length, pointer, 0, null); } }
void CreateDescriptorSet() { var layouts = new List <VkDescriptorSetLayout> { descriptorSetLayout }; var info = new VkDescriptorSetAllocateInfo(); info.setLayouts = layouts; descriptorSet = descriptorPool.Allocate(info)[0]; var bufferInfo = new VkDescriptorBufferInfo(); bufferInfo.buffer = uniformBuffer; bufferInfo.offset = 0; bufferInfo.range = Interop.SizeOf <UniformBufferObject>(); var imageInfo = new VkDescriptorImageInfo(); imageInfo.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; imageInfo.imageView = textureImageView; imageInfo.sampler = textureSampler; var descriptorWrites = new List <VkWriteDescriptorSet>(); descriptorWrites.Add(new VkWriteDescriptorSet()); descriptorWrites[0].dstSet = descriptorSet; descriptorWrites[0].dstBinding = 0; descriptorWrites[0].dstArrayElement = 0; descriptorWrites[0].descriptorType = VkDescriptorType.UniformBuffer; descriptorWrites[0].bufferInfo = new List <VkDescriptorBufferInfo> { bufferInfo }; descriptorWrites.Add(new VkWriteDescriptorSet()); descriptorWrites[1].dstSet = descriptorSet; descriptorWrites[1].dstBinding = 1; descriptorWrites[1].dstArrayElement = 0; descriptorWrites[1].descriptorType = VkDescriptorType.CombinedImageSampler; descriptorWrites[1].imageInfo = new List <VkDescriptorImageInfo> { imageInfo }; descriptorSet.Update(descriptorWrites, null); }
void setupDescriptorSet() { VkDescriptorSetAllocateInfo allocInfo = VkDescriptorSetAllocateInfo.New(); allocInfo.descriptorPool = descriptorPool; allocInfo.pSetLayouts = (VkDescriptorSetLayout *)descriptorSetLayout.Data.ToPointer(); allocInfo.descriptorSetCount = 1; Util.CheckResult(vkAllocateDescriptorSets(Device, &allocInfo, out descriptorSet)); var descriptor = uniformBuffer.descriptor; VkWriteDescriptorSet writeDescriptorSets = Initializers.writeDescriptorSet( descriptorSet, VkDescriptorType.UniformBuffer, 0, &descriptor); vkUpdateDescriptorSets(Device, 1, ref writeDescriptorSets, 0, null); }
void setupDescriptorSet() { VkDescriptorSetLayout dsl = descriptorSetLayout; VkDescriptorSetAllocateInfo allocInfo = new VkDescriptorSetAllocateInfo(); allocInfo.sType = DescriptorSetAllocateInfo; allocInfo.descriptorPool = descriptorPool; allocInfo.setLayouts = dsl; { VkDescriptorSet set; vkAllocateDescriptorSets(device, &allocInfo, &set); this.descriptorSet = set; } VkDescriptorImageInfo texDescriptor = new VkDescriptorImageInfo(); texDescriptor.sampler = textures_colorMap.sampler; texDescriptor.imageView = textures_colorMap.view; texDescriptor.imageLayout = VkImageLayout.General; VkDescriptorBufferInfo temp = uniformBuffers_scene.descriptor; var writes = new VkWriteDescriptorSet[2]; // Binding 0 : Vertex shader uniform buffer writes[0] = new VkWriteDescriptorSet(); writes[0].sType = WriteDescriptorSet; writes[0].dstSet = descriptorSet; writes[0].data.descriptorType = VkDescriptorType.UniformBuffer; writes[0].dstBinding = 0; writes[0].data.Set(temp); // Binding 1 : Color map writes[1] = new VkWriteDescriptorSet(); writes[1].sType = WriteDescriptorSet; writes[1].dstSet = descriptorSet; writes[1].data.descriptorType = VkDescriptorType.CombinedImageSampler; writes[1].dstBinding = 1; writes[1].data.Set(texDescriptor); fixed(VkWriteDescriptorSet *pointer = writes) { vkUpdateDescriptorSets(device, (UInt32)writes.Length, pointer, 0, null); } }
public DescriptorSet(DescriptorPool pool, DescriptorSetLayout layout) { unsafe { var layoutHandle = layout.Handle; var info = new VkDescriptorSetAllocateInfo() { SType = VkStructureType.DescriptorSetAllocateInfo, PNext = IntPtr.Zero, DescriptorPool = pool.Handle, DescriptorSetCount = 1, PSetLayouts = &layoutHandle }; VkDescriptorSet result; VkException.Check(VkDevice.vkAllocateDescriptorSets(pool.Device.Handle, &info, &result)); DescriptorPool = pool; Handle = result; } }
void setupDescriptorSet() { var dsl = descriptorSetLayout; VkDescriptorSetAllocateInfo allocInfo = Initializers.descriptorSetAllocateInfo( descriptorPool, &dsl, 1); Util.CheckResult(vkAllocateDescriptorSets(device, &allocInfo, out descriptorSet)); var descriptor1 = uniformBuffer.descriptor; var descriptor2 = textures_colormap.descriptor; FixedArray2 <VkWriteDescriptorSet> writeDescriptorSets = new FixedArray2 <VkWriteDescriptorSet>( Initializers.writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &descriptor1), Initializers.writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &descriptor2)); vkUpdateDescriptorSets(device, (uint)(writeDescriptorSets.Count), &writeDescriptorSets.First, 0, null); }
private VkDescriptorSet CreateVulkanDescriptorSet() { VkDescriptorSet vulkanDescriptorSet = VK_NULL_HANDLE; var vulkanDescriptorPool = VulkanDescriptorPool; if (vulkanDescriptorPool != VK_NULL_HANDLE) { var vulkanDescriptorSetLayout = VulkanDescriptorSetLayout; var descriptorSetAllocateInfo = new VkDescriptorSetAllocateInfo { sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, descriptorPool = vulkanDescriptorPool, descriptorSetCount = 1, pSetLayouts = (ulong *)&vulkanDescriptorSetLayout, }; ThrowExternalExceptionIfNotSuccess(vkAllocateDescriptorSets(Device.VulkanDevice, &descriptorSetAllocateInfo, (ulong *)&vulkanDescriptorSet), nameof(vkAllocateDescriptorSets)); } return(vulkanDescriptorSet); }
void setupDescriptorSet() { var dsl = descriptorSetLayout; VkDescriptorSetAllocateInfo allocInfo = Initializers.descriptorSetAllocateInfo( descriptorPool, &dsl, 1); Util.CheckResult(vkAllocateDescriptorSets(device, &allocInfo, out descriptorSet)); var descriptor0 = uniformBuffers_view.descriptor; var descriptor1 = uniformBuffers_dynamic.descriptor; FixedArray2 <VkWriteDescriptorSet> writeDescriptorSets = new FixedArray2 <VkWriteDescriptorSet>( // Binding 0 : Projection/View matrix uniform buffer Initializers.writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &descriptor0), // Binding 1 : Instance matrix as dynamic uniform buffer Initializers.writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, &descriptor1)); vkUpdateDescriptorSets(device, writeDescriptorSets.Count, &writeDescriptorSets.First, 0, null); }
private void PrepareDescriptor(VkDevice device) { // 今は定数バッファを1つを格納できるだけのディスクリプタプールを準備. var descriptorPoolSize = new VkDescriptorPoolSize() { descriptorCount = 1, type = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, }; m_descriptorPool = m_resourceManager.CreateDescriptorPool(device, new[] { descriptorPoolSize }, 1); // ディスクリプタセットレイアウトの作成. // - 定数バッファを1つ var descLayoutBinding = new VkDescriptorSetLayoutBinding() { binding = 0, descriptorCount = 1, descriptorType = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, stageFlags = VkShaderStageFlagBits.VK_SHADER_STAGE_VERTEX_BIT }; m_descriptorSetLayout = m_resourceManager.CreateDescriptorSetLayout(device, new[] { descLayoutBinding }); // ディスクリプタを作成&更新. 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 descForUniform = SampleHelpers.CreateDescriptorFromUniformBuffer(0, descUniform, m_descriptorSet); var descriptorWrites = new[] { descForUniform }; VulkanAPI.vkUpdateDescriptorSets(device, descriptorWrites, null); }
public DescriptorSet(DescriptorSetLayout resLayout, params IBindableResource[] bindables) { resLayout.Build(); descriptorPool = Graphics.DescriptorPoolManager.GetPool(ref resLayout.descriptorResourceCounts, Swapchain.IMAGE_COUNT); resourceLayout = resLayout; unsafe { var setLayouts = stackalloc VkDescriptorSetLayout[3] { resLayout.Handle, resLayout.Handle, resLayout.Handle }; var descriptorSetAllocateInfo = new VkDescriptorSetAllocateInfo { sType = VkStructureType.DescriptorSetAllocateInfo, descriptorPool = descriptorPool, pSetLayouts = setLayouts, descriptorSetCount = Swapchain.IMAGE_COUNT }; Device.AllocateDescriptorSets(ref descriptorSetAllocateInfo, (VkDescriptorSet *)descriptorSet.Data); } bindedRes = new IBindableResource[resLayout.NumBindings]; System.Diagnostics.Debug.Assert(bindables.Length == resLayout.NumBindings); for (int i = 0; i < Swapchain.IMAGE_COUNT; i++) { writeDescriptorSets[i] = new VkWriteDescriptorSet[resLayout.NumBindings]; } for (uint i = 0; i < resLayout.NumBindings; i++) { BindResource(i, bindables[i]); } UpdateSets(); }
void setupDescriptorSet() { var dsl = descriptorSetLayout; VkDescriptorSetAllocateInfo allocInfo = Initializers.descriptorSetAllocateInfo( descriptorPool, &dsl, 1); Util.CheckResult(vkAllocateDescriptorSets(device, &allocInfo, out descriptorSet)); var descriptor = uniformBuffer.descriptor; // Binding 0 : Vertex shader uniform buffer VkWriteDescriptorSet writeDescriptorSet = Initializers.writeDescriptorSet( descriptorSet, VkDescriptorType.UniformBuffer, 0, &descriptor); vkUpdateDescriptorSets(device, 1, &writeDescriptorSet, 0, null); }
private static VkDescriptorSet[] AllocateDescriptorSets(VkDevice device, VkDescriptorSetLayout layout, VkDescriptorPool pool, uint swapchainImageCount) { VkDescriptorSetLayout[] localLayouts = new VkDescriptorSetLayout[swapchainImageCount]; for (int i = 0; i < localLayouts.Length; i++) { localLayouts[i] = layout; } VkDescriptorSetAllocateInfo allocateInfo = VkDescriptorSetAllocateInfo.New(); allocateInfo.descriptorPool = pool; allocateInfo.descriptorSetCount = swapchainImageCount; fixed(VkDescriptorSetLayout *ptr = localLayouts) allocateInfo.pSetLayouts = ptr; VkDescriptorSet[] sets = new VkDescriptorSet[swapchainImageCount]; fixed(VkDescriptorSet *ptr = sets) Assert(vkAllocateDescriptorSets(device, &allocateInfo, ptr)); return(sets); }
void setupDescriptorSet() { VkDescriptorSetLayout layout = this.layout; var allocInfo = VkDescriptorSetAllocateInfo.Alloc(); allocInfo[0].descriptorPool = descriptorPool; allocInfo[0].setLayouts = layout; { VkDescriptorSet set; vkAllocateDescriptorSets(device, allocInfo, &set); this.descriptorSet = set; } // Setup a descriptor image info for the current texture to be used as a combined image sampler VkDescriptorImageInfo imageInfo; imageInfo.imageView = texture.view; // The image's view (images are never directly accessed by the shader, but rather through views defining subresources) imageInfo.sampler = texture.sampler; // The sampler (Telling the pipeline how to sample the texture, including repeat, border, etc.) imageInfo.imageLayout = texture.imageLayout; // The current layout of the image (Note: Should always fit the actual use, e.g. shader read) VkDescriptorBufferInfo bufferInfo = uniformBufferVS.descriptor; var writes = VkWriteDescriptorSet.Alloc(2); { // Binding 0 : Vertex shader uniform buffer writes[0].dstSet = descriptorSet; writes[0].dstBinding = 0; writes[0].data.descriptorType = VkDescriptorType.UniformBuffer; writes[0].data.Set(bufferInfo); // Binding 1 : Fragment shader texture sampler // Fragment shader: layout (binding = 1) uniform sampler2D samplerColor; writes[1].dstSet = descriptorSet; writes[1].dstBinding = 1; writes[1].data.descriptorType = VkDescriptorType.CombinedImageSampler; writes[1].data.Set(imageInfo); } vkUpdateDescriptorSets(device, 2, writes, 0, null); }
void setupDescriptorSet() { var layout = descriptorSetLayout; VkDescriptorSetAllocateInfo allocInfo = Initializers.descriptorSetAllocateInfo( descriptorPool, &layout, 1); Util.CheckResult(vkAllocateDescriptorSets(device, &allocInfo, out descriptorSet)); // Setup a descriptor image info for the current texture to be used as a combined image sampler VkDescriptorImageInfo textureDescriptor; textureDescriptor.imageView = texture.view; // The image's view (images are never directly accessed by the shader, but rather through views defining subresources) textureDescriptor.sampler = texture.sampler; // The sampler (Telling the pipeline how to sample the texture, including repeat, border, etc.) textureDescriptor.imageLayout = texture.imageLayout; // The current layout of the image (Note: Should always fit the actual use, e.g. shader read) var descriptor = uniformBufferVS.descriptor; FixedArray2 <VkWriteDescriptorSet> writeDescriptorSets = new FixedArray2 <VkWriteDescriptorSet>( // Binding 0 : Vertex shader uniform buffer Initializers.writeDescriptorSet( descriptorSet, VkDescriptorType.UniformBuffer, 0, &descriptor), // Binding 1 : Fragment shader texture sampler // Fragment shader: layout (binding = 1) uniform sampler2D samplerColor; Initializers.writeDescriptorSet( descriptorSet, VkDescriptorType.CombinedImageSampler, // The descriptor set will use a combined image sampler (sampler and image could be split) 1, // Shader binding point 1 &textureDescriptor) // Pointer to the descriptor image for our texture ); vkUpdateDescriptorSets(device, writeDescriptorSets.Count, ref writeDescriptorSets.First, 0, null); }