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); }
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); }
protected DescriptorSetExample() : base() { this.DescriptorPool = CreateDescriptorPool(); this.DescriptorSets = AllocateDescriptorSets(); DescriptorBufferInfo info = new DescriptorBufferInfo { Buffer = UniformBuffer, Offset = 0, Range = this.UniformBufferSize }; WriteDescriptorSet write = new WriteDescriptorSet { SType = StructureType.WriteDescriptorSet, DstSet = this.DescriptorSets[0], DescriptorCount = 1, DescriptorType = DescriptorType.UniformBuffer, PBufferInfo = &info, DstArrayElement = 0, DstBinding = 0 }; VkApi.UpdateDescriptorSets(this.Device, 1, &write, 0, null); }
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 }); } }
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); }
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_final_pl() { descriptorPool = new DescriptorPool(dev, 3, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 2), new VkDescriptorPoolSize(VkDescriptorType.StorageImage, 4) ); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, DeferredPbrRenderer.NUM_SAMPLES); if (DeferredPbrRenderer.NUM_SAMPLES != VkSampleCountFlags.SampleCount1) { cfg.multisampleState.sampleShadingEnable = true; cfg.multisampleState.minSampleShading = 0.5f; } cfg.Layout = new PipelineLayout(dev, new VkPushConstantRange(VkShaderStageFlags.Fragment, 2 * sizeof(float)), new DescriptorSetLayout(dev, 0, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) )); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, DeferredPbrRenderer.NUM_SAMPLES); using (ShaderInfo vs = new ShaderInfo(dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv")) using (ShaderInfo fs = new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.tone_mapping.frag.spv")) { cfg.AddShaders(vs, fs); plToneMap = new GraphicPipeline(cfg); } descriptorSet = descriptorPool.Allocate(cfg.Layout.DescriptorSetLayouts[0]); }
public DeferredPbrRenderer(Queue gQueue, string cubemapPath, uint width, uint height, float nearPlane, float farPlane) { this.gQueue = gQueue; this.dev = gQueue.Dev; this.cubemapPath = cubemapPath; this.width = width; this.height = height; DrawComplete = dev.CreateSemaphore(); pipelineCache = new PipelineCache(dev); descriptorPool = new DescriptorPool(dev, 5, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 3), new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 6), new VkDescriptorPoolSize(VkDescriptorType.InputAttachment, 5), new VkDescriptorPoolSize(VkDescriptorType.StorageImage, 4) ); uboMatrices = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, matrices, true); uboLights = new HostBuffer <Light> (dev, VkBufferUsageFlags.UniformBuffer, lights, true); #if WITH_SHADOWS shadowMapRenderer = new ShadowMapRenderer(gQueue, this); #endif init(nearPlane, farPlane); }
protected override void CreateDescriptorPool() { var poolSizes = new DescriptorPoolSize[] { new DescriptorPoolSize { Type = DescriptorType.UniformBuffer, DescriptorCount = (uint)images.Length, }, new DescriptorPoolSize { Type = DescriptorType.CombinedImageSampler, DescriptorCount = (uint)images.Length } }; DescriptorPoolCreateInfo poolInfo = new DescriptorPoolCreateInfo { PoolSizeCount = (uint)poolSizes.Length, PoolSizes = poolSizes, MaxSets = (uint)images.Length }; descriptorPool = device.CreateDescriptorPool(poolInfo); }
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 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 void CreateDescriptorPool() { this.descriptorPool = device.CreateDescriptorPool( 1, new DescriptorPoolSize { DescriptorCount = 1, Type = DescriptorType.UniformBuffer }); }
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; } }
public ShadowMapRenderer(Device dev, DeferredPbrRenderer renderer, float farPlane = 16f) { this.lightFarPlane = farPlane; this.dev = dev; this.renderer = renderer; descriptorPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 2) ); init(); }
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); }
static int GetPool(IntPtr L) { try { ToLua.CheckArgsCount(L, 0); DescriptorPool o = LuaPB.GetPool(); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
protected override void initVulkan() { base.initVulkan(); //first create the needed buffers vbo = new HostBuffer <Vertex> (dev, VkBufferUsageFlags.VertexBuffer, vertices); ibo = new HostBuffer <ushort> (dev, VkBufferUsageFlags.IndexBuffer, indices); //because mvp matrice may be updated by mouse move, we keep it mapped after creation. uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, mvp, true); //a descriptor pool to allocate the mvp matrice descriptor from. descriptorPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer)); //Graphic pipeline configuration are predefined by the GraphicPipelineConfig class, which ease sharing config for several pipelines having lots in common. using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false)) { //Create the pipeline layout, it will be automatically activated on pipeline creation, so that sharing layout among different pipelines will benefit //from the reference counting to automatically dispose unused layout on pipeline clean up. It's the same for DescriptorSetLayout. cfg.Layout = new PipelineLayout(dev, new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer))); //create a default renderpass with just a color attachment for the swapchain image, a default subpass is automatically created and the renderpass activation //will follow the pipeline life cicle and will be automatically disposed when no longuer used. cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, cfg.Samples); //configuration of vertex bindings and attributes cfg.AddVertexBinding <Vertex> (0); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat); //position + color //shader are automatically compiled by SpirVTasks if added to the project. The resulting shaders are automatically embedded in the assembly. //To specifiy that the shader path is a resource name, put the '#' prefix. Else the path will be search on disk. cfg.AddShaders( new ShaderInfo(dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"), new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv") ); //create and activate the pipeline with the configuration we've just done. pipeline = new GraphicPipeline(cfg); } //because descriptor layout used for a pipeline are only activated on pipeline activation, descriptor set must not be allocated before, except if the layout has been manually activated, //but in this case, layout will need also to be explicitly disposed. descriptorSet = descriptorPool.Allocate(pipeline.Layout.DescriptorSetLayouts[0]); //Write the content of the descriptor, the mvp matrice. DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descriptorSet, pipeline.Layout.DescriptorSetLayouts[0]); //Descriptor property of the mvp buffer will return a default descriptor with no offset of the full size of the buffer. uboUpdate.Write(dev, uboMats.Descriptor); //allocate the default VkWindow buffers, one per swapchain image. Their will be only reset when rebuilding and not reallocated. cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); }
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(); } }
private void CreateDescriptorPool() { this.descriptorPool = device.CreateDescriptorPool(new DescriptorPoolCreateInfo { PoolSizes = new[] { new DescriptorPoolSize { DescriptorCount = 1, Type = DescriptorType.UniformBuffer } }, MaxSets = 1 }); }
public EnumDescriptor(DescriptorPool pool, ProtoBase parent, EnumDescriptorProto def) { Define = def; base.Init(pool, parent); for (int i = 0; i < def.value.Count; i++) { var fieldDef = def.value[i]; var fieldD = new EnumValueDescriptor(this, fieldDef); _fieldByName.Add(fieldDef.name, fieldD); _fieldByNumber.Add(fieldDef.number, fieldD); } }
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); }
private void CreateDescriptorPool() { var poolSize = new DescriptorPoolSize() { Type = DescriptorType.UniformBuffer, DescriptorCount = 1, }; var poolInfo = new DescriptorPoolCreateInfo() { PoolSizes = new DescriptorPoolSize[] { poolSize }, MaxSets = 1, }; vkDescriptorPool = vkDevice.CreateDescriptorPool(poolInfo); }
static int GetEnum(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); DescriptorPool obj = (DescriptorPool)ToLua.CheckObject(L, 1, typeof(DescriptorPool)); string arg0 = ToLua.CheckString(L, 2); EnumDescriptor o = obj.GetEnum(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int get_Pool(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ProtoBase obj = (ProtoBase)o; DescriptorPool ret = obj.Pool; ToLua.PushObject(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index Pool on a nil value" : e.Message)); } }
private void CreateDescriptorPool() { this.descriptorPool = device.CreateDescriptorPool(2, new[] { new DescriptorPoolSize { DescriptorCount = 2, Type = DescriptorType.UniformBuffer }, new DescriptorPoolSize { DescriptorCount = 2, Type = DescriptorType.CombinedImageSampler } }); }
DescriptorSet CreateDescriptorSet(DescriptorPool pool, DescriptorSetLayout layout, ImageData imageData, UniformData uniformData) { var allocInfo = new DescriptorSetAllocateInfo(pool, new[] { layout }); var sets = device.AllocateDescriptorSets(allocInfo); var descriptorSet = sets.First(); var texDescriptor = new DescriptorImageInfo(imageData.Sampler, imageData.View, ImageLayout.General); var writeDescriptorSets = new[] { new WriteDescriptorSet(descriptorSet, 0, 0, DescriptorType.UniformBuffer, null, null, null), new WriteDescriptorSet(descriptorSet, 1, 0, DescriptorType.CombinedImageSampler, null, null, null), }; writeDescriptorSets[0].BufferInfo = new[] { uniformData.Descriptor }; writeDescriptorSets[1].ImageInfo = new[] { texDescriptor }; device.UpdateDescriptorSets(writeDescriptorSets, null); return(descriptorSet); }
public void AllocateSetsAndFreeSets() { var layoutCreateInfo = new DescriptorSetLayoutCreateInfo( new DescriptorSetLayoutBinding(0, DescriptorType.StorageBuffer, 1)); var poolCreateInfo = new DescriptorPoolCreateInfo( 1, new[] { new DescriptorPoolSize(DescriptorType.StorageBuffer, 1) }, DescriptorPoolCreateFlags.FreeDescriptorSet); using (DescriptorSetLayout layout = Device.CreateDescriptorSetLayout(layoutCreateInfo)) using (DescriptorPool pool = Device.CreateDescriptorPool(poolCreateInfo)) { using (pool.AllocateSets(new DescriptorSetAllocateInfo(1, layout))[0]) { } DescriptorSet set = pool.AllocateSets(new DescriptorSetAllocateInfo(1, layout))[0]; pool.FreeSets(set); } }
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); }
protected override void initVulkan() { base.initVulkan(); cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); loadTexture(imgPathes[currentImgIndex]); vbo = new GPUBuffer <float> (presentQueue, cmdPool, VkBufferUsageFlags.VertexBuffer, vertices); ibo = new GPUBuffer <ushort> (presentQueue, cmdPool, VkBufferUsageFlags.IndexBuffer, indices); descriptorPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer), new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler) ); dsLayout = new DescriptorSetLayout(dev, 0, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount4)) { cfg.Layout = new PipelineLayout(dev, dsLayout); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), cfg.Samples); cfg.AddVertexBinding(0, 5 * sizeof(float)); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); cfg.AddShader(dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"); cfg.AddShader(dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv"); pipeline = new GraphicPipeline(cfg); } uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, matrices); uboMats.Map(); //permanent map descriptorSet = descriptorPool.Allocate(dsLayout); updateTextureSet(); DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descriptorSet, dsLayout.Bindings[0]); uboUpdate.Write(dev, uboMats.Descriptor); }
internal static unsafe extern Result vkCreateDescriptorPool(Device device, DescriptorPoolCreateInfo* createInfo, AllocationCallbacks* allocator, DescriptorPool* descriptorPool);
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); }
public unsafe void ResetDescriptorPool(DescriptorPool descriptorPool, DescriptorPoolResetFlags flags) { vkResetDescriptorPool(this, descriptorPool, flags).CheckError(); }
public unsafe void FreeDescriptorSets(DescriptorPool descriptorPool, uint descriptorSetCount, DescriptorSet* descriptorSets) { vkFreeDescriptorSets(this, descriptorPool, descriptorSetCount, descriptorSets).CheckError(); }
public unsafe void DestroyDescriptorPool(DescriptorPool descriptorPool, AllocationCallbacks* allocator = null) { vkDestroyDescriptorPool(this, descriptorPool, allocator); }
internal static unsafe extern void vkDestroyDescriptorPool(Device device, DescriptorPool descriptorPool, AllocationCallbacks* allocator);
internal static unsafe extern Result vkFreeDescriptorSets(Device device, DescriptorPool descriptorPool, uint descriptorSetCount, DescriptorSet* descriptorSets);
internal static unsafe extern Result vkResetDescriptorPool(Device device, DescriptorPool descriptorPool, DescriptorPoolResetFlags flags);