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)) { } } } }
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)) { } } }
private Pipeline CreateComputePipeline() { var pipelineCreateInfo = new ComputePipelineCreateInfo( new PipelineShaderStageCreateInfo(ShaderStages.Compute, Content.Load <ShaderModule>("shader.comp.spv"), "main"), _computePipelineLayout); return(Context.Device.CreateComputePipeline(pipelineCreateInfo)); }
void CreateComputePipeline() { /* * We create a compute pipeline here. */ /* * Create a shader module. A shader module basically just encapsulates some shader code. */ // the code in comp.spv was created by running the command: // glslangValidator.exe -V shader.comp byte[] code = ReadFile("shaders/shader.comp.spv"); ShaderModuleCreateInfo createInfo = new ShaderModuleCreateInfo() { Code = code }; computeShaderModule = device.CreateShaderModule(createInfo); /* * Now let us actually create the compute pipeline. * A compute pipeline is very simple compared to a graphics pipeline. * It only consists of a single stage with a compute shader. * So first we specify the compute shader stage, and it's entry point(main). */ PipelineShaderStageCreateInfo shaderStageCreateInfo = new PipelineShaderStageCreateInfo() { Stage = ShaderStages.Compute,// VK_SHADER_STAGE_COMPUTE_BIT; Module = computeShaderModule, Name = "main" }; /* * The pipeline layout allows the pipeline to access descriptor sets. * So we just specify the descriptor set layout we created earlier. */ PipelineLayoutCreateInfo pipelineLayoutCreateInfo = new PipelineLayoutCreateInfo(new[] { descriptorSetLayout }); pipelineLayout = device.CreatePipelineLayout(pipelineLayoutCreateInfo); ComputePipelineCreateInfo pipelineCreateInfo = new ComputePipelineCreateInfo() { Stage = shaderStageCreateInfo, Layout = pipelineLayout }; /* * Now, we finally create the compute pipeline. */ ComputePipelineCreateInfo[] ci = { pipelineCreateInfo }; pipelines = device.CreateComputePipelines(ci); }
private void CreateComputePipeline() { var pipelineLayoutCreateInfo = new PipelineLayoutCreateInfo(new[] { _descriptorSetLayout }); _pipelineLayout = Device.Logical.CreatePipelineLayout(pipelineLayoutCreateInfo); using (ShaderModule shader = Device.Logical.CreateShaderModule(new ShaderModuleCreateInfo(SpirV))) { var computePipelineCreateInfo = new ComputePipelineCreateInfo( new PipelineShaderStageCreateInfo(ShaderStages.Compute, shader, "main"), _pipelineLayout); _pipeline = Device.Logical.CreateComputePipeline(computePipelineCreateInfo); } }
public void CmdBindPipeline() { 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); using (Pipeline pipeline = Device.CreateComputePipeline(pipelineCreateInfo)) { CommandBuffer.Begin(); CommandBuffer.CmdBindPipeline(PipelineBindPoint.Compute, pipeline); CommandBuffer.End(); } } }
/// <summary> /// Creates a new compute pipeline object. /// </summary> /// <param name="createInfo"> /// Structure specifying parameters of a newly created compute pipeline. /// </param> /// <param name="cache"> /// Is either <c>null</c>, indicating that pipeline caching is disabled; or the handle of a /// valid pipeline cache object, in which case use of that cache is enabled for the duration /// of the command. /// </param> /// <param name="allocator">Controls host memory allocation.</param> /// <returns>The resulting compute pipeline object.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public Pipeline CreateComputePipeline(ComputePipelineCreateInfo createInfo, PipelineCache cache = null, AllocationCallbacks?allocator = null) { return(new Pipeline(this, cache, ref createInfo, ref allocator)); }
internal static unsafe extern Result vkCreateComputePipelines(Device device, PipelineCache pipelineCache, uint createInfoCount, ComputePipelineCreateInfo* createInfos, AllocationCallbacks* allocator, Pipeline* pipelines);
public unsafe Pipeline CreateComputePipelines(PipelineCache pipelineCache, uint createInfoCount, ComputePipelineCreateInfo* createInfos, AllocationCallbacks* allocator = null) { Pipeline pipelines; vkCreateComputePipelines(this, pipelineCache, createInfoCount, createInfos, allocator, &pipelines).CheckError(); return pipelines; }