protected override void CreateDescriptorSetLayout() { var uboLayoutBinding = new DescriptorSetLayoutBinding { Binding = 0, DescriptorType = DescriptorType.UniformBuffer, DescriptorCount = 1, ImmutableSamplers = null, StageFlags = ShaderStageFlags.Vertex }; var samplerLayoutBinding = new DescriptorSetLayoutBinding { Binding = 1, DescriptorCount = 1, DescriptorType = DescriptorType.CombinedImageSampler, ImmutableSamplers = null, StageFlags = ShaderStageFlags.Fragment }; var bindings = new[] { uboLayoutBinding, samplerLayoutBinding }; var layoutInfo = new DescriptorSetLayoutCreateInfo { BindingCount = (uint)bindings.Length, Bindings = bindings, }; descriptorSetLayout = device.CreateDescriptorSetLayout(layoutInfo); }
Program() : base(false) { vbo = new HostBuffer <Vertex> (dev, VkBufferUsageFlags.VertexBuffer, vertices); ibo = new HostBuffer <ushort> (dev, VkBufferUsageFlags.IndexBuffer, indices); uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, matrices); descriptorPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer)); dsLayout = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1); cfg.Layout = new PipelineLayout(dev, dsLayout); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), cfg.Samples); cfg.AddVertexBinding <Vertex> (0); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/triangle.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/triangle.frag.spv"); pipeline = new GraphicPipeline(cfg); descriptorSet = descriptorPool.Allocate(dsLayout); DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descriptorSet, dsLayout); uboUpdate.Write(dev, uboMats.Descriptor); uboMats.Map(); }
void init(VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4) { descriptorPool = new DescriptorPool(dev, 2, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler) ); descLayout = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, samples); cfg.Layout = new PipelineLayout(dev, descLayout); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), samples); cfg.ResetShadersAndVerticesInfos(); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true); uiPipeline = new GraphicPipeline(cfg); dsVkvg = descriptorPool.Allocate(descLayout); }
private void CreateDescriptors() { int bindingCount = Inputs.Count + 1; // + 1 output. // Setup bindings. var bindings = new DescriptorSetLayoutBinding[bindingCount]; for (int i = 0; i < Inputs.Count; i++) { bindings[i] = Inputs[i].GetDescriptorSetLayoutBinding(i); } bindings[Inputs.Count] = Output.GetDescriptorSetLayoutBinding(Inputs.Count); _descriptorSetLayout = Device.Logical.CreateDescriptorSetLayout(new DescriptorSetLayoutCreateInfo(bindings)); var descriptorPoolCreateInfo = new DescriptorPoolCreateInfo( 1, new[] { new DescriptorPoolSize(DescriptorType.StorageBuffer, bindingCount) }); _descriptorPool = Device.Logical.CreateDescriptorPool(descriptorPoolCreateInfo); _descriptorSet = _descriptorPool.AllocateSets(new DescriptorSetAllocateInfo(1, _descriptorSetLayout))[0]; // Setup write descriptors. var writeDescriptorSets = new WriteDescriptorSet[bindingCount]; for (int i = 0; i < Inputs.Count; i++) { writeDescriptorSets[i] = Inputs[i].GetWriteDescriptorSet(_descriptorSet, i); } writeDescriptorSets[Inputs.Count] = Output.GetWriteDescriptorSet(_descriptorSet, Inputs.Count); _descriptorPool.UpdateSets(writeDescriptorSets); }
public void GetData() { var descriptorSetLayoutCreateInfo = new DescriptorSetLayoutCreateInfo( new DescriptorSetLayoutBinding(0, DescriptorType.StorageBuffer, 1, ShaderStages.Compute), new DescriptorSetLayoutBinding(1, DescriptorType.StorageBuffer, 1, ShaderStages.Compute)); using (DescriptorSetLayout descriptorSetLayout = Device.CreateDescriptorSetLayout(descriptorSetLayoutCreateInfo)) using (PipelineLayout pipelineLayout = Device.CreatePipelineLayout(new PipelineLayoutCreateInfo(new[] { descriptorSetLayout }))) using (ShaderModule shader = Device.CreateShaderModule(new ShaderModuleCreateInfo(ReadAllBytes("Shader.comp.spv")))) { var pipelineCreateInfo = new ComputePipelineCreateInfo( new PipelineShaderStageCreateInfo(ShaderStages.Compute, shader, "main"), pipelineLayout); byte[] cacheBytes; // Populate cache. using (PipelineCache cache = Device.CreatePipelineCache()) { using (Device.CreateComputePipeline(pipelineCreateInfo, cache)) { } cacheBytes = cache.GetData(); } Assert.False(cacheBytes.All(x => x == 0)); // Recreate pipeline from cache. using (PipelineCache cache = Device.CreatePipelineCache(new PipelineCacheCreateInfo(cacheBytes))) { using (Device.CreateComputePipeline(pipelineCreateInfo, cache)) { } } } }
private RenderSystemResourceGroupLayout CreateDrawResourceGroupLayout(ResourceGroupDescription resourceGroupDescription, EffectBytecode effectBytecode) { if (resourceGroupDescription.DescriptorSetLayout == null) { return(null); } var result = new RenderSystemResourceGroupLayout { DescriptorSetLayout = DescriptorSetLayout.New(RenderSystem.GraphicsDevice, resourceGroupDescription.DescriptorSetLayout), ConstantBufferReflection = resourceGroupDescription.ConstantBufferReflection, }; if (resourceGroupDescription.ConstantBufferReflection != null) { result.ConstantBufferSize = resourceGroupDescription.ConstantBufferReflection.Size; result.ConstantBufferHash = resourceGroupDescription.ConstantBufferReflection.Hash; } // Resolve slots result.ConstantBufferOffsets = new int[drawCBufferOffsetSlots.Count]; for (int index = 0; index < drawCBufferOffsetSlots.Count; index++) { ResolveCBufferOffset(result, index, drawCBufferOffsetSlots[index].Variable); } return(result); }
void CreateDescriptorSetLayout() { /* * Here we specify a descriptor set layout. This allows us to bind our descriptors to * resources in the shader. */ /* * Here we specify a binding of type VK_DESCRIPTOR_TYPE_STORAGE_BUFFER to the binding point * 0. This binds to * layout(std140, binding = 0) buffer buf * in the compute shader. */ DescriptorSetLayoutBinding descriptorSetLayoutBinding = new DescriptorSetLayoutBinding() { Binding = 0, // binding = 0 DescriptorType = DescriptorType.StorageBuffer, // VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; DescriptorCount = 1, StageFlags = ShaderStages.Compute // VK_SHADER_STAGE_COMPUTE_BIT; }; DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = new DescriptorSetLayoutCreateInfo(); // descriptorSetLayoutCreateInfo.bindingCount = 1; // only a single binding in this descriptor set layout. DescriptorSetLayoutBinding[] temp = { descriptorSetLayoutBinding }; descriptorSetLayoutCreateInfo.Bindings = temp; // Create the descriptor set layout. descriptorSetLayout = device.CreateDescriptorSetLayout(descriptorSetLayoutCreateInfo); }
public Auto <DescriptorSetCollection> AllocateDescriptorSet(Vk api, DescriptorSetLayout layout) { Span <DescriptorSetLayout> layouts = stackalloc DescriptorSetLayout[1]; layouts[0] = layout; return(AllocateDescriptorSets(api, layouts)); }
public static DescriptorSet CreateDescriptorSet(DescriptorPool pool, DescriptorSetLayout setLayout, DescriptorItem[] items, out Sampler[] samplers) { DescriptorSet descriptorSet = pool.AllocateSets(new DescriptorSetAllocateInfo(1, setLayout))[0]; var writeDescriptorSets = new WriteDescriptorSet[items.Length]; for (var i = 0; i < items.Length; i++) { var item = items[i]; switch (item.Type) { case DescriptorItem.DescriptorType.UniformBuffer: writeDescriptorSets[i] = new WriteDescriptorSet(descriptorSet, i, 0, item.Count, DescriptorType.UniformBuffer, bufferInfo: new[] { new DescriptorBufferInfo(item.Buffer, 0, item.Buffer.Size) }); break; case DescriptorItem.DescriptorType.CombinedImageSampler: _SamplerCollection.Add(item.Sampler); writeDescriptorSets[i] = new WriteDescriptorSet(descriptorSet, i, 0, 1, DescriptorType.CombinedImageSampler, imageInfo: new[] { new DescriptorImageInfo(item.Sampler, item.Texture.View, VulkanCore.ImageLayout.General) }); break; default: throw new NotImplementedException($"No case for {item.Type}"); } } pool.UpdateSets(writeDescriptorSets); samplers = _SamplerCollection.ToArray(); _SamplerCollection.Clear(); return(descriptorSet); }
public void CreateComputePipeline() { var descriptorSetLayoutCreateInfo = new DescriptorSetLayoutCreateInfo( new DescriptorSetLayoutBinding(0, DescriptorType.StorageBuffer, 1, ShaderStages.Compute), new DescriptorSetLayoutBinding(1, DescriptorType.StorageBuffer, 1, ShaderStages.Compute)); using (DescriptorSetLayout descriptorSetLayout = Device.CreateDescriptorSetLayout(descriptorSetLayoutCreateInfo)) using (PipelineLayout pipelineLayout = Device.CreatePipelineLayout(new PipelineLayoutCreateInfo(new[] { descriptorSetLayout }))) using (ShaderModule shader = Device.CreateShaderModule(new ShaderModuleCreateInfo(ReadAllBytes("Shader.comp.spv")))) using (PipelineCache cache = Device.CreatePipelineCache()) { var pipelineCreateInfo = new ComputePipelineCreateInfo( new PipelineShaderStageCreateInfo(ShaderStages.Compute, shader, "main"), pipelineLayout); using (Device.CreateComputePipelines(new[] { pipelineCreateInfo })[0]) { } using (Device.CreateComputePipelines(new[] { pipelineCreateInfo }, cache)[0]) { } using (Device.CreateComputePipelines(new[] { pipelineCreateInfo }, allocator: CustomAllocator)[0]) { } using (Device.CreateComputePipelines(new[] { pipelineCreateInfo }, cache, CustomAllocator)[0]) { } using (Device.CreateComputePipeline(pipelineCreateInfo)) { } using (Device.CreateComputePipeline(pipelineCreateInfo, allocator: CustomAllocator)) { } using (Device.CreateComputePipeline(pipelineCreateInfo, cache)) { } using (Device.CreateComputePipeline(pipelineCreateInfo, cache, CustomAllocator)) { } } }
public void UpdateSetsDescriptorWrite() { const int bufferSize = 256; var layoutCreateInfo = new DescriptorSetLayoutCreateInfo( new DescriptorSetLayoutBinding(0, DescriptorType.StorageBuffer, 1)); var poolCreateInfo = new DescriptorPoolCreateInfo( 1, new[] { new DescriptorPoolSize(DescriptorType.StorageBuffer, 1) }, DescriptorPoolCreateFlags.FreeDescriptorSet); using (Buffer buffer = Device.CreateBuffer(new BufferCreateInfo(bufferSize, BufferUsages.StorageBuffer))) using (DeviceMemory memory = Device.AllocateMemory(new MemoryAllocateInfo(bufferSize, 0))) using (DescriptorSetLayout layout = Device.CreateDescriptorSetLayout(layoutCreateInfo)) using (DescriptorPool pool = Device.CreateDescriptorPool(poolCreateInfo)) using (DescriptorSet set = pool.AllocateSets(new DescriptorSetAllocateInfo(1, layout))[0]) { // Required to satisfy the validation layer. buffer.GetMemoryRequirements(); buffer.BindMemory(memory); var descriptorWrite = new WriteDescriptorSet(set, 0, 0, 1, DescriptorType.StorageBuffer, bufferInfo: new[] { new DescriptorBufferInfo(buffer) }); pool.UpdateSets(new[] { descriptorWrite }); } }
public BindlessDescriptorSet(Vk vk, Device device, int pushConstantSize, int numSampledImages = 512 * 1024, int numStorageImages = 64 * 1024, int numSamplers = 4 * 1024) { _vk = vk; _device = device; _pushConstantSize = pushConstantSize; _numSampledImages = numSampledImages; _numStorageImages = numStorageImages; _numSamplers = numSamplers; var pBindings = stackalloc DescriptorSetLayoutBinding[] { new DescriptorSetLayoutBinding(SampledImageBinding, DescriptorType.SampledImage, (uint)numSampledImages, ShaderStageFlags.ShaderStageAll), new DescriptorSetLayoutBinding(StorageImageBinding, DescriptorType.StorageImage, (uint)numStorageImages, ShaderStageFlags.ShaderStageAll), new DescriptorSetLayoutBinding(SamplerBinding, DescriptorType.Sampler, (uint)numSamplers, ShaderStageFlags.ShaderStageAll), }; _vk.CreateDescriptorSetLayout(_device, new DescriptorSetLayoutCreateInfo(flags: DescriptorSetLayoutCreateFlags.DescriptorSetLayoutCreateUpdateAfterBindPoolBit, bindingCount: 3, pBindings: pBindings), null, out var layout).ThrowCode(); _descriptorSetLayout = layout; if (pushConstantSize > 0) { var pushConstantRange = new PushConstantRange(ShaderStageFlags.ShaderStageAll, 0, (uint)pushConstantSize); _vk.CreatePipelineLayout(_device, new PipelineLayoutCreateInfo(setLayoutCount: 1, pSetLayouts: &layout, pushConstantRangeCount: 1, pPushConstantRanges: &pushConstantRange), null, out _pipelineLayout).ThrowCode(); } else { _vk.CreatePipelineLayout(_device, new PipelineLayoutCreateInfo(setLayoutCount: 1, pSetLayouts: &layout, pushConstantRangeCount: 0, pPushConstantRanges: null), null, out _pipelineLayout).ThrowCode(); } }
public Program() { instance = new Instance(); phy = instance.GetAvailablePhysicalDevice().FirstOrDefault(); dev = new Device(phy); computeQ = new Queue(dev, VkQueueFlags.Compute); dev.Activate(default(VkPhysicalDeviceFeatures)); createRandomDatas(); inBuff = new HostBuffer <int> (dev, VkBufferUsageFlags.StorageBuffer, datas); outBuff = new HostBuffer <int> (dev, VkBufferUsageFlags.StorageBuffer, data_size); dsPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.StorageBuffer, 2)); dsLayout = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer) ); plCompute = new ComputePipeline(new PipelineLayout(dev, dsLayout), "#shaders.compute.comp.spv"); dset = dsPool.Allocate(dsLayout); DescriptorSetWrites dsUpdate = new DescriptorSetWrites(dset, dsLayout); dsUpdate.Write(dev, inBuff.Descriptor, outBuff.Descriptor); }
protected override void CreateDescriptorSets() { var layouts = new DescriptorSetLayout[images.Length]; for (int i = 0; i < layouts.Length; i++) { layouts[i] = descriptorSetLayout; } var allocInfo = new DescriptorSetAllocateInfo { DescriptorPool = descriptorPool, DescriptorSetCount = (uint)images.Length, SetLayouts = layouts }; descriptorSets = device.AllocateDescriptorSets(allocInfo); for (int a = 0; a < descriptorSets.Length; a++) { var bufferInfo = new DescriptorBufferInfo { Buffer = uniformBuffers[a], Offset = 0, Range = (sizeof(float) * 16) * 3 }; var imageInfo = new DescriptorImageInfo { ImageLayout = ImageLayout.ShaderReadOnlyOptimal, ImageView = textureImageView, Sampler = textureSampler }; //TODO: Dispose this var descriptorWrites = new WriteDescriptorSet[] { new WriteDescriptorSet { DstSet = descriptorSets[a], DstBinding = 0, DstArrayElement = 0, DescriptorType = DescriptorType.UniformBuffer, DescriptorCount = 1, BufferInfo = new DescriptorBufferInfo[] { bufferInfo } }, new WriteDescriptorSet { DstSet = descriptorSets[a], DstBinding = 1, DstArrayElement = 0, DescriptorType = DescriptorType.CombinedImageSampler, DescriptorCount = 1, ImageInfo = new DescriptorImageInfo[] { imageInfo } } }; //device.UpdateDescriptorSet(descriptorWrites[0], null); //device.UpdateDescriptorSet(descriptorWrites[1], null); device.UpdateDescriptorSets(descriptorWrites, null); } }
public DescriptorSetManager(VulkanRenderer renderer) { _layout = renderer.Shader.DescriptorSetLayout; _renderer = renderer; _descriptorSets = Array.Empty <DescriptorSet>(); _count = 0; _capacity = 0; }
protected override unsafe DescriptorSetLayout[] CreateDescriptorSetLayouts(VulkanGraphicsDevice gd, Device device, out PipelineLayout layout) { DescriptorSetLayoutBinding uLayoutBindings = new DescriptorSetLayoutBinding { Binding = 0, DescriptorType = DescriptorType.UniformBuffer, DescriptorCount = 1, StageFlags = ShaderStageFlags.ShaderStageVertexBit }; DescriptorSetLayoutBinding tLayoutBindings = new DescriptorSetLayoutBinding { Binding = 0, DescriptorType = DescriptorType.CombinedImageSampler, DescriptorCount = 1, StageFlags = ShaderStageFlags.ShaderStageFragmentBit }; DescriptorSetLayout[] layouts = new DescriptorSetLayout[3]; var uDescriptorSetLayoutCreateInfo = new DescriptorSetLayoutCreateInfo() { SType = StructureType.DescriptorSetLayoutCreateInfo, PBindings = &uLayoutBindings, BindingCount = 1 }; var sDescriptorSetLayoutCreateInfo = new DescriptorSetLayoutCreateInfo() { SType = StructureType.DescriptorSetLayoutCreateInfo, BindingCount = 0 }; var tDescriptorSetLayoutCreateInfo = new DescriptorSetLayoutCreateInfo() { SType = StructureType.DescriptorSetLayoutCreateInfo, PBindings = &tLayoutBindings, BindingCount = 1 }; gd.Api.CreateDescriptorSetLayout(device, uDescriptorSetLayoutCreateInfo, null, out layouts[0]).ThrowOnError(); gd.Api.CreateDescriptorSetLayout(device, sDescriptorSetLayoutCreateInfo, null, out layouts[1]).ThrowOnError(); gd.Api.CreateDescriptorSetLayout(device, tDescriptorSetLayoutCreateInfo, null, out layouts[2]).ThrowOnError(); fixed(DescriptorSetLayout *pLayouts = layouts) { var pipelineLayoutCreateInfo = new PipelineLayoutCreateInfo() { SType = StructureType.PipelineLayoutCreateInfo, PSetLayouts = pLayouts, SetLayoutCount = 3 }; gd.Api.CreatePipelineLayout(device, &pipelineLayoutCreateInfo, null, out layout).ThrowOnError(); } return(layouts); }
private PipelineLayout CreatePipelineLayout(DescriptorSetLayout descriptorSetLayout) { var pipelineLayoutCreateInfo = new PipelineLayoutCreateInfo { SetLayouts = new DescriptorSetLayout[] { descriptorSetLayout } }; return(VulkanRenderer.SelectedLogicalDevice.CreatePipelineLayout(pipelineLayoutCreateInfo)); }
public PBRPipeline(Queue staggingQ, RenderPass renderPass, string cubeMapPath, PipelineCache pipelineCache = null) : base(renderPass, pipelineCache, "pbr pipeline") { descriptorPool = new DescriptorPool(Dev, 2, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 2), new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 8) ); descLayoutMain = new DescriptorSetLayout(Dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); descLayoutTextures = new DescriptorSetLayout(Dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, renderPass.Samples)) { cfg.Layout = new PipelineLayout(Dev, descLayoutMain, descLayoutTextures); cfg.Layout.AddPushConstants( new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()), new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64) ); cfg.RenderPass = renderPass; cfg.AddVertexBinding <PbrModel.Vertex> (0); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat); cfg.AddShader(Dev, VkShaderStageFlags.Vertex, "#shaders.pbr.vert.spv"); cfg.AddShader(Dev, VkShaderStageFlags.Fragment, "#shaders.pbr_khr.frag.spv"); layout = cfg.Layout; init(cfg); } dsMain = descriptorPool.Allocate(descLayoutMain); envCube = new EnvironmentCube(cubeMapPath, layout, staggingQ, RenderPass); matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels; uboMats = new HostBuffer(Dev, VkBufferUsageFlags.UniformBuffer, matrices, true); DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descLayoutMain.Bindings.GetRange(0, 4).ToArray()); uboUpdate.Write(Dev, dsMain, uboMats.Descriptor, envCube.irradianceCube.Descriptor, envCube.prefilterCube.Descriptor, envCube.lutBrdf.Descriptor); }
private ViewResourceGroupLayout CreateViewResourceGroupLayout(ResourceGroupDescription resourceGroupDescription, RenderEffectState effectState) { if (resourceGroupDescription.DescriptorSetLayout == null) { return(null); } // We combine both hash for DescriptorSet and cbuffer itself (if it exists) var hash = resourceGroupDescription.Hash; var effectStateHash = new ObjectId(0, 0, 0, (uint)effectState); ObjectId.Combine(ref effectStateHash, ref hash, out hash); ViewResourceGroupLayout result; if (!viewResourceLayouts.TryGetValue(hash, out result)) { result = new ViewResourceGroupLayout { DescriptorSetLayoutBuilder = resourceGroupDescription.DescriptorSetLayout, DescriptorSetLayout = DescriptorSetLayout.New(RenderSystem.GraphicsDevice, resourceGroupDescription.DescriptorSetLayout), ConstantBufferReflection = resourceGroupDescription.ConstantBufferReflection, Entries = new ResourceGroupEntry[RenderSystem.Views.Count], State = effectState, }; for (int index = 0; index < result.Entries.Length; index++) { result.Entries[index].Resources = new ResourceGroup(); } if (resourceGroupDescription.ConstantBufferReflection != null) { result.ConstantBufferSize = resourceGroupDescription.ConstantBufferReflection.Size; result.ConstantBufferHash = resourceGroupDescription.ConstantBufferReflection.Hash; } // Resolve slots result.ConstantBufferOffsets = new int[viewCBufferOffsetSlots.Count]; for (int index = 0; index < viewCBufferOffsetSlots.Count; index++) { ResolveCBufferOffset(result, index, viewCBufferOffsetSlots[index].Variable); } // Resolve logical groups result.LogicalGroups = new LogicalGroup[viewLogicalGroups.Count]; for (int index = 0; index < viewLogicalGroups.Count; index++) { ResolveLogicalGroup(result, index, viewLogicalGroups[index].Variable); } viewResourceLayouts.Add(hash, result); } return(result); }
internal Chunk(Device logicalDevice, ReadOnlySpan <IShaderInput> inputs, int size = 5) { types = new DescriptorType[inputs.Length]; for (int i = 0; i < types.Length; i++) { types[i] = inputs[i].DescriptorType; } //Gather how many inputs of each type we have var poolSizes = new ResizeArray <DescriptorPoolSize>(); for (int i = 0; i < types.Length; i++) { for (int j = 0; j < poolSizes.Count; j++) { if (poolSizes.Data[j].Type == types[i]) { poolSizes.Data[j].DescriptorCount += size; continue; } } poolSizes.Add(new DescriptorPoolSize(types[i], size)); } //Create a pool for 'size' types the amount of resources of one set pool = logicalDevice.CreateDescriptorPool(new DescriptorPoolCreateInfo( maxSets: size, poolSizes: poolSizes.ToArray(), flags: DescriptorPoolCreateFlags.None)); //Create a layout that matches the inputs layout = CreateLayout(logicalDevice, inputs); //Even tho we use the same layout for the entire pool the 'VkDescriptorSetAllocateInfo' //expects a layout per allocation so we create a array of layouts all pointing to the //same layout var layouts = new DescriptorSetLayout[size]; for (int i = 0; i < layouts.Length; i++) { layouts[i] = layout; } //Pre-allocate all the sets from the pool sets = pool.AllocateSets(new DescriptorSetAllocateInfo( descriptorSetCount: size, setLayouts: layouts)); //Mark all the sets as being free isFree = new bool[size]; for (int i = 0; i < isFree.Length; i++) { isFree[i] = true; } }
private void CreateDescriptorSetLayout() { this.descriptorSetLayout = device.CreateDescriptorSetLayout( new DescriptorSetLayoutBinding { Binding = 0, DescriptorType = DescriptorType.UniformBuffer, StageFlags = ShaderStageFlags.Vertex | ShaderStageFlags.Fragment, DescriptorCount = 1 }); }
public void Destroy(IMgDevice device) { if (Layout != null) { Layout.DestroyPipelineLayout(device, null); } if (DescriptorSetLayout != null) { DescriptorSetLayout.DestroyDescriptorSetLayout(device, null); } }
public DescriptorSetLayout CreateUniqueDescriptorSetLayout(DescriptorSetLayoutBuilder descriptorSetLayoutBuilder) { DescriptorSetLayout descriptorSetLayout; if (!createdDescriptorSetLayouts.TryGetValue(descriptorSetLayoutBuilder.Hash, out descriptorSetLayout)) { descriptorSetLayout = DescriptorSetLayout.New(RenderSystem.GraphicsDevice, descriptorSetLayoutBuilder); createdDescriptorSetLayouts.Add(descriptorSetLayoutBuilder.Hash, descriptorSetLayout); } return(descriptorSetLayout); }
protected override void InitializePermanent() { var cube = GeometricPrimitive.Box(1.0f, 1.0f, 1.0f); _cubeTexture = Content.Load <VulkanImage>("IndustryForgedDark512.ktx"); _cubeVertices = ToDispose(VulkanBuffer.Vertex(Context, cube.Vertices)); _cubeIndices = ToDispose(VulkanBuffer.Index(Context, cube.Indices)); _sampler = ToDispose(CreateSampler()); _uniformBuffer = ToDispose(VulkanBuffer.DynamicUniform <WorldViewProjection>(Context, 1)); _descriptorSetLayout = ToDispose(CreateDescriptorSetLayout()); _pipelineLayout = ToDispose(CreatePipelineLayout()); _descriptorPool = ToDispose(CreateDescriptorPool()); _descriptorSet = CreateDescriptorSet(); // Will be freed when pool is destroyed. }
/* public void Write(string name, DescriptorImageInfo myInfo) * internal void WriteUniform<T>(string v, T mYBuffer) where T : struct*/ internal void AllocateFrom(DescriptorPool myNewPoolObject) { DescriptorSetLayout myBindings = GetDescriptorSetLayout(); DescriptorSetLayoutCreateInfo myInfo = new DescriptorSetLayoutCreateInfo(); DescriptorSetAllocateInfo mySetAlloc = new DescriptorSetAllocateInfo(); //TODO: Garbage and memory stuff mySetAlloc.SetLayouts = new DescriptorSetLayout[] { myBindings }; mySetAlloc.DescriptorPool = myNewPoolObject; myDSet = VulkanRenderer.SelectedLogicalDevice.AllocateDescriptorSets(mySetAlloc); // Debug.Assert(myDSet.Count() == myBindings.Count); }
public PbrModelSeparatedTextures(Queue transferQ, string path, DescriptorSetLayout layout, params AttachmentType[] attachments) { dev = transferQ.Dev; using (CommandPool cmdPool = new CommandPool(dev, transferQ.index)) { using (glTFLoader ctx = new glTFLoader(path, transferQ, cmdPool)) { loadSolids(ctx); textures = ctx.LoadImages(); loadMaterials(ctx, layout, attachments); materialUBO = new HostBuffer <Material> (dev, VkBufferUsageFlags.UniformBuffer, materials); } } }
public void ResetPool() { var layoutCreateInfo = new DescriptorSetLayoutCreateInfo( new DescriptorSetLayoutBinding(0, DescriptorType.StorageBuffer, 1)); var poolCreateInfo = new DescriptorPoolCreateInfo( 1, new[] { new DescriptorPoolSize(DescriptorType.StorageBuffer, 1) }); using (DescriptorSetLayout layout = Device.CreateDescriptorSetLayout(layoutCreateInfo)) using (DescriptorPool pool = Device.CreateDescriptorPool(poolCreateInfo)) { pool.AllocateSets(new DescriptorSetAllocateInfo(1, layout)); pool.Reset(); } }
public override void Initialize(PhysicalDevice physicalDevice, SurfaceKhr surface) { base.Initialize(physicalDevice, surface); var vertexBuffer = CreateBuffer(physicalDevice, Logo.Vertices, BufferUsageFlags.VertexBuffer, typeof(float)); var indexBuffer = CreateBuffer(physicalDevice, Logo.Indexes, BufferUsageFlags.IndexBuffer, typeof(short)); uniformBuffer = CreateUniformBuffer(physicalDevice); descriptorSetLayout = CreateDescriptorSetLayout(); var pipelines = CreatePipelines(); descriptorSets = CreateDescriptorSets(); UpdateDescriptorSets(); commandBuffers = CreateCommandBuffers(images, framebuffers, pipelines [0], vertexBuffer, indexBuffer, (uint)Logo.Indexes.Length); }
public void Build() { DescriptorSetLayout?.Dispose(); PipelineLayout?.Dispose(); //UsingSamplers?.DisposeRange(); DescriptorPool?.Dispose(); RenderPass?.Dispose(); Pipeline?.Dispose(); DescriptorSetLayout = VKHelper.CreateDescriptorSetLayout(Graphics, DescriptorItems); PipelineLayout = VKHelper.CreatePipelineLayout(Graphics, DescriptorSetLayout); DescriptorPool = VKHelper.CreateDescriptorPool(Graphics, DescriptorItems); DescriptorSet = VKHelper.CreateDescriptorSet(DescriptorPool, DescriptorSetLayout, DescriptorItems, out UsingSamplers); RenderPass = VKHelper.CreateRenderPass(Graphics, ClearDepthOnBeginPass); Pipeline = VKHelper.CreateGraphicsPipeline(Graphics, PipelineLayout, RenderPass, Shaders, DepthTest, DepthWrite, Instancing, InstanceInfoType, BlendMode, PrimitiveType, PrimitiveRenderMode, PrimitiveCullMode, LineWidth, ViewportPos, ViewportSize); }
public Program() { instance = new Instance(); #if DEBUG dbgReport = new DebugReport(instance, VkDebugReportFlagsEXT.ErrorEXT | VkDebugReportFlagsEXT.DebugEXT | VkDebugReportFlagsEXT.WarningEXT | VkDebugReportFlagsEXT.PerformanceWarningEXT ); #endif phy = instance.GetAvailablePhysicalDevice().FirstOrDefault(); dev = new Device(phy); computeQ = new Queue(dev, VkQueueFlags.Compute); dev.Activate(enabledFeatures, enabledExtensions); datas = new float[data_size]; Random rnd = new Random(); for (uint i = 0; i < data_size; i++) { datas[i] = (float)rnd.NextDouble(); } inBuff = new HostBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer, datas); outBuff = new HostBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer, data_size); dsPool = new DescriptorPool(dev, 2, new VkDescriptorPoolSize(VkDescriptorType.StorageBuffer, 4)); dsLayoutCompute = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer) ); plCompute = new ComputePipeline( new PipelineLayout(dev, new VkPushConstantRange(VkShaderStageFlags.Compute, sizeof(int)), dsLayoutCompute), "shaders/computeTest.comp.spv"); dsetPing = dsPool.Allocate(dsLayoutCompute); dsetPong = dsPool.Allocate(dsLayoutCompute); DescriptorSetWrites dsUpdate = new DescriptorSetWrites(dsetPing, dsLayoutCompute); dsUpdate.Write(dev, inBuff.Descriptor, outBuff.Descriptor); dsUpdate.Write(dev, dsetPong, outBuff.Descriptor, inBuff.Descriptor); }
internal static unsafe extern void vkDestroyDescriptorSetLayout(Device device, DescriptorSetLayout descriptorSetLayout, AllocationCallbacks* allocator);
public unsafe void DestroyDescriptorSetLayout(DescriptorSetLayout descriptorSetLayout, AllocationCallbacks* allocator = null) { vkDestroyDescriptorSetLayout(this, descriptorSetLayout, allocator); }
private unsafe void CreatePipelineLayout() { var binding = new DescriptorSetLayoutBinding { Binding = 0, DescriptorCount = 1, DescriptorType = DescriptorType.UniformBuffer, StageFlags = ShaderStageFlags.Vertex }; var descriptorSetLayoutCreateInfo = new DescriptorSetLayoutCreateInfo { StructureType = StructureType.DescriptorSetLayoutCreateInfo, BindingCount = 1, Bindings = new IntPtr(&binding) }; descriptorSetLayout = device.CreateDescriptorSetLayout(ref descriptorSetLayoutCreateInfo); var localDescriptorSetLayout = descriptorSetLayout; var createInfo = new PipelineLayoutCreateInfo { StructureType = StructureType.PipelineLayoutCreateInfo, SetLayoutCount = 1, SetLayouts = new IntPtr(&localDescriptorSetLayout) }; pipelineLayout = device.CreatePipelineLayout(ref createInfo); var poolSize = new DescriptorPoolSize { DescriptorCount = 2, Type = DescriptorType.UniformBuffer }; var descriptorPoolCreateinfo = new DescriptorPoolCreateInfo { StructureType = StructureType.DescriptorPoolCreateInfo, PoolSizeCount = 1, PoolSizes = new IntPtr(&poolSize), MaxSets = 2 }; descriptorPool = device.CreateDescriptorPool(ref descriptorPoolCreateinfo); var bufferCreateInfo = new BufferCreateInfo { StructureType = StructureType.BufferCreateInfo, Usage = BufferUsageFlags.UniformBuffer, Size = 64, }; uniformBuffer = device.CreateBuffer(ref bufferCreateInfo); MemoryRequirements memoryRequirements; device.GetBufferMemoryRequirements(uniformBuffer, out memoryRequirements); var memory = AllocateMemory(MemoryPropertyFlags.HostVisible | MemoryPropertyFlags.HostCoherent, memoryRequirements); device.BindBufferMemory(uniformBuffer, memory, 0); var mappedMemory = device.MapMemory(memory, 0, 64, MemoryMapFlags.None); var data = new[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, }; Utilities.Write(mappedMemory, data, 0, data.Length); device.UnmapMemory(memory); }
internal static unsafe extern Result vkCreateDescriptorSetLayout(Device device, DescriptorSetLayoutCreateInfo* createInfo, AllocationCallbacks* allocator, DescriptorSetLayout* setLayout);