public VkShaderResourceBindingSlots(VkDevice device, ShaderResourceDescription[] resources) { Resources = resources; VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = VkDescriptorSetLayoutCreateInfo.New(); descriptorSetLayoutCI.bindingCount = (uint)resources.Length; VkDescriptorSetLayoutBinding *bindings = stackalloc VkDescriptorSetLayoutBinding[resources.Length]; for (int i = 0; i < resources.Length; i++) { ShaderResourceDescription desc = resources[i]; bindings[i].binding = (uint)i; bindings[i].descriptorType = MapDescriptorType(desc.Type); bindings[i].descriptorCount = 1; bindings[i].stageFlags = MapStageFlags(desc.Stages); } descriptorSetLayoutCI.pBindings = bindings; vkCreateDescriptorSetLayout(device, ref descriptorSetLayoutCI, null, out VkDescriptorSetLayout descriptorSetLayout); DescriptorSetLayout = descriptorSetLayout; VkPipelineLayoutCreateInfo pipelineLayoutCI = VkPipelineLayoutCreateInfo.New(); pipelineLayoutCI.setLayoutCount = 1; pipelineLayoutCI.pSetLayouts = &descriptorSetLayout; VkResult result = vkCreatePipelineLayout(device, ref pipelineLayoutCI, null, out VkPipelineLayout layout); CheckResult(result); PipelineLayout = layout; }
public VkResourceLayout(VkGraphicsDevice gd, ref ResourceLayoutDescription description) { _gd = gd; VkDescriptorSetLayoutCreateInfo dslCI = VkDescriptorSetLayoutCreateInfo.New(); ResourceLayoutElementDescription[] elements = description.Elements; _descriptorTypes = new VkDescriptorType[elements.Length]; VkDescriptorSetLayoutBinding *bindings = stackalloc VkDescriptorSetLayoutBinding[elements.Length]; for (uint i = 0; i < elements.Length; i++) { bindings[i].binding = i; bindings[i].descriptorCount = 1; VkDescriptorType descriptorType = VkFormats.VdToVkDescriptorType(elements[i].Kind); bindings[i].descriptorType = descriptorType; bindings[i].stageFlags = VkFormats.VdToVkShaderStages(elements[i].Stages); _descriptorTypes[i] = descriptorType; } dslCI.bindingCount = (uint)elements.Length; dslCI.pBindings = bindings; VkResult result = vkCreateDescriptorSetLayout(_gd.Device, ref dslCI, null, out _dsl); CheckResult(result); }
public void Set(params VkDescriptorSetLayoutBinding[] value) { IntPtr ptr = (IntPtr)this.pointer; value.Set(ref ptr, ref this.count); this.pointer = (VkDescriptorSetLayoutBinding *)ptr; }
private VkDescriptorSetLayout CreateDescriptorSetLayout() { VkDescriptorSetLayoutBinding *bindings = stackalloc VkDescriptorSetLayoutBinding[2]; bindings[0] = new VkDescriptorSetLayoutBinding { binding = 0, descriptorType = VkDescriptorType.UniformBuffer, descriptorCount = 1, stageFlags = VkShaderStageFlags.Vertex }; bindings[1] = new VkDescriptorSetLayoutBinding { binding = 1, descriptorType = VkDescriptorType.CombinedImageSampler, descriptorCount = 1, stageFlags = VkShaderStageFlags.Fragment }; var createInfo = new VkDescriptorSetLayoutCreateInfo { sType = VkStructureType.DescriptorSetLayoutCreateInfo, pNext = null, bindingCount = 2, pBindings = bindings }; VkDescriptorSetLayout layout; vkCreateDescriptorSetLayout(Context.Device, &createInfo, null, out layout).CheckResult(); return(layout); }
public static VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( VkDescriptorSetLayoutBinding *pBindings, uint bindingCount) { VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = VkDescriptorSetLayoutCreateInfo.New(); descriptorSetLayoutCreateInfo.pBindings = pBindings; descriptorSetLayoutCreateInfo.bindingCount = bindingCount; return(descriptorSetLayoutCreateInfo); }
public VkDescriptorSetLayoutBindingGroup(params VkDescriptorSetLayoutBinding[] value) { this.count = 0; this.pointer = null; if (value != null) { IntPtr ptr = IntPtr.Zero; value.Set(ref ptr, ref this.count); this.pointer = (VkDescriptorSetLayoutBinding *)ptr; } }
public VkResourceLayout(VkGraphicsDevice gd, ref ResourceLayoutDescription description) : base(ref description) { _gd = gd; VkDescriptorSetLayoutCreateInfo dslCI = VkDescriptorSetLayoutCreateInfo.New(); ResourceLayoutElementDescription[] elements = description.Elements; _descriptorTypes = new VkDescriptorType[elements.Length]; VkDescriptorSetLayoutBinding *bindings = stackalloc VkDescriptorSetLayoutBinding[elements.Length]; uint uniformBufferCount = 0; uint sampledImageCount = 0; uint samplerCount = 0; uint storageBufferCount = 0; uint storageImageCount = 0; for (uint i = 0; i < elements.Length; i++) { bindings[i].binding = i; bindings[i].descriptorCount = 1; VkDescriptorType descriptorType = VkFormats.VdToVkDescriptorType(elements[i].Kind, elements[i].Options); bindings[i].descriptorType = descriptorType; bindings[i].stageFlags = VkFormats.VdToVkShaderStages(elements[i].Stages); if ((elements[i].Options & ResourceLayoutElementOptions.DynamicBinding) != 0) { DynamicBufferCount += 1; } _descriptorTypes[i] = descriptorType; switch (descriptorType) { case VkDescriptorType.Sampler: samplerCount += 1; break; case VkDescriptorType.SampledImage: sampledImageCount += 1; break; case VkDescriptorType.StorageImage: storageImageCount += 1; break; case VkDescriptorType.UniformBuffer: uniformBufferCount += 1; break; case VkDescriptorType.StorageBuffer: storageBufferCount += 1; break; } } DescriptorResourceCounts = new DescriptorResourceCounts( uniformBufferCount, sampledImageCount, samplerCount, storageBufferCount, storageImageCount); dslCI.bindingCount = (uint)elements.Length; dslCI.pBindings = bindings; VkResult result = vkCreateDescriptorSetLayout(_gd.Device, ref dslCI, null, out _dsl); CheckResult(result); }