public MeshSpatialObject(GraphicsState graphics, SpatialState spatial, AssetFactoryState assets, Mesh mesh, bool culling) { Graphics = graphics; Spatial = spatial; Mesh = mesh; // TextureLayer = textureLayer; VertexBuffer = new ArrayBuffer <Vertex>(graphics, BufferUsage.StructuredBufferReadOnly, mesh.Vertices, ShaderStages.Compute); WorldVertexBuffer = new ArrayBuffer <Vertex>(graphics, BufferUsage.StructuredBufferReadWrite, mesh.Vertices.Length, ShaderStages.Compute | ShaderStages.Vertex); ScreenCoordsBuffer = new ArrayBuffer <Vector3D>(graphics, BufferUsage.StructuredBufferReadWrite, mesh.Vertices.Length, ShaderStages.Compute | ShaderStages.Vertex); ParameterBuffer = new StructBuffer <Parameters>(graphics, BufferUsage.UniformBuffer, ShaderStages.Compute); // Texture = texture; FaceBuffer = new ResourcelessArrayBuffer <Face>(graphics, BufferUsage.VertexBuffer, mesh.Faces); TransformPipeline = new ComputePipeline(graphics, assets.Get <ShaderSet>("Shaders.MeshSpatialObject.Transform"), VertexBuffer, WorldVertexBuffer, ScreenCoordsBuffer, ParameterBuffer); ColorPipeline = new GraphicsPipeline(graphics, Blend.Override, DepthTest.On, culling, assets.Get <ShaderSet>("Shaders.MeshSpatialObject.Color"), graphics.IntermediateOutputDescription, WorldVertexBuffer, ScreenCoordsBuffer); Commands = new Commands(graphics); }
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 void CreatePipelineState() { string fragment = Constants.ShadersFile + @"ComputeTexture\Fragment.hlsl"; string vertex = Constants.ShadersFile + @"ComputeTexture\Vertex.hlsl"; string compute = Constants.ShadersFile + @"ComputeTexture\Compute.hlsl"; Image image = new(Device, new() { ImageType = VkImageType.Image2D, Usage = ResourceUsage.GPU_Only, Flags = ImageFlags.ReadWriteImage | ImageFlags.ShaderResource, Format = VkFormat.R8G8B8A8SNorm, Width = Framebuffer.SwapChain.Width, Height = Framebuffer.SwapChain.Height, Depth = 1, MipLevels = 1, ArraySize = 1, }); Sampler sampler = new Sampler(Device); ComputePipelineDescription ComputePipelineDescription = new(); ComputePipelineDescription.Shader = new ShaderBytecode(compute, ShaderStage.Compute); PipelineState_1 = new(Device, ComputePipelineDescription); DescriptorData descriptorData_1 = new(); descriptorData_1.SetReadWriteImage(0, image); DescriptorSet_1 = new(PipelineState_1, descriptorData_1); GraphicsPipelineDescription Pipelinedescription0 = new(); Pipelinedescription0.SetFramebuffer(Framebuffer); Pipelinedescription0.SetShader(new ShaderBytecode(fragment, ShaderStage.Fragment)); Pipelinedescription0.SetShader(new ShaderBytecode(vertex, ShaderStage.Vertex)); PipelineState_0 = new(Pipelinedescription0); DescriptorData descriptorData_0 = new(); descriptorData_0.SetImage(1, image); descriptorData_0.SetSampler(2, sampler); DescriptorSet_0 = new(PipelineState_0, descriptorData_0); }
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); }
public Program() : base() { if (Instance.DEBUG_UTILS) { dbgReport = new DebugReport(instance, VkDebugReportFlagsEXT.ErrorEXT | VkDebugReportFlagsEXT.DebugEXT | VkDebugReportFlagsEXT.WarningEXT | VkDebugReportFlagsEXT.PerformanceWarningEXT ); } imgResult = new Image(dev, VkFormat.R32g32b32a32Sfloat, VkImageUsageFlags.TransferDst | VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, imgDim, imgDim); imgResult.CreateView(); imgResult.CreateSampler(VkFilter.Nearest, VkFilter.Nearest, VkSamplerMipmapMode.Nearest, VkSamplerAddressMode.ClampToBorder); imgResult.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; datas = new float[data_size]; addSeed(imgDim / 2 - 1, imgDim / 2 - 1); stagingDataBuff = new HostBuffer <float> (dev, VkBufferUsageFlags.TransferSrc, datas); stagingDataBuff.Map(); inBuff = new GPUBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferSrc | VkBufferUsageFlags.TransferDst, (int)data_size); outBuff = new GPUBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferSrc, (int)data_size); dsPool = new DescriptorPool(dev, 3, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler), new VkDescriptorPoolSize(VkDescriptorType.StorageBuffer, 4)); dslImage = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); dslCompute = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer) ); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1); cfg.Layout = new PipelineLayout(dev, dslImage); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), VkSampleCountFlags.SampleCount1); cfg.RenderPass.ClearValues[0] = new VkClearValue { color = new VkClearColorValue(0.0f, 0.1f, 0.0f) }; cfg.ResetShadersAndVerticesInfos(); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true); grPipeline = new GraphicPipeline(cfg); plCompute = new ComputePipeline( new PipelineLayout(dev, new VkPushConstantRange(VkShaderStageFlags.Compute, 2 * sizeof(int)), dslCompute), "shaders/computeTest.comp.spv"); plNormalize = new ComputePipeline( plCompute.Layout, "shaders/normalize.comp.spv"); dsImage = dsPool.Allocate(dslImage); dsetPing = dsPool.Allocate(dslCompute); dsetPong = dsPool.Allocate(dslCompute); DescriptorSetWrites dsUpdate = new DescriptorSetWrites(dsetPing, dslCompute); dsUpdate.Write(dev, inBuff.Descriptor, outBuff.Descriptor); dsUpdate.Write(dev, dsetPong, outBuff.Descriptor, inBuff.Descriptor); dsUpdate = new DescriptorSetWrites(dsImage, dslImage); dsUpdate.Write(dev, imgResult.Descriptor); UpdateFrequency = 5; }
public Program() : base() { #if DEBUG dbgReport = new DebugReport(instance, VkDebugReportFlagsEXT.ErrorEXT | VkDebugReportFlagsEXT.DebugEXT | VkDebugReportFlagsEXT.WarningEXT | VkDebugReportFlagsEXT.PerformanceWarningEXT ); #endif imgResult = new Image(dev, VkFormat.R32g32b32a32Sfloat, VkImageUsageFlags.TransferDst | VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, IMG_DIM, IMG_DIM); imgResult.CreateView(); imgResult.CreateSampler(VkFilter.Nearest, VkFilter.Nearest, VkSamplerMipmapMode.Nearest, VkSamplerAddressMode.ClampToBorder); imgResult.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; staggingVBO = new HostBuffer <Vector2> (dev, VkBufferUsageFlags.TransferSrc, MAX_VERTICES); staggingVBO.Map(); vbo = new GPUBuffer <Vector2> (dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferDst, MAX_VERTICES); ibo = new GPUBuffer <uint> (dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.StorageBuffer, MAX_VERTICES * 3); inBuff = new GPUBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferSrc | VkBufferUsageFlags.TransferDst, (int)data_size); outBuff = new GPUBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferSrc | VkBufferUsageFlags.TransferDst, (int)data_size); dsPool = new DescriptorPool(dev, 4, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler), new VkDescriptorPoolSize(VkDescriptorType.StorageBuffer, 6)); dslImage = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); dslCompute = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer) ); dslVAO = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer) ); plInit = new ComputePipeline( new PipelineLayout(dev, new VkPushConstantRange(VkShaderStageFlags.Compute, 3 * sizeof(int)), dslCompute, dslVAO), "shaders/init.comp.spv"); plCompute = new ComputePipeline(plInit.Layout, "shaders/computeTest.comp.spv"); plNormalize = new ComputePipeline(plInit.Layout, "shaders/normalize.comp.spv"); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1); cfg.Layout = new PipelineLayout(dev, dslImage); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), VkSampleCountFlags.SampleCount1); cfg.RenderPass.ClearValues[0] = new VkClearValue { color = new VkClearColorValue(0.1f, 0.1f, 0.1f) }; cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true); grPipeline = new GraphicPipeline(cfg); cfg.ResetShadersAndVerticesInfos(); cfg.Layout = new PipelineLayout(dev, new VkPushConstantRange(VkShaderStageFlags.Vertex, 4 * sizeof(int))); cfg.inputAssemblyState.topology = VkPrimitiveTopology.LineStrip; cfg.AddVertexBinding <Vector2> (0); cfg.SetVertexAttributes(0, VkFormat.R32g32Sfloat); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/triangle.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/triangle.frag.spv"); trianglesPipeline = new GraphicPipeline(cfg); dsImage = dsPool.Allocate(dslImage); dsPing = dsPool.Allocate(dslCompute); dsPong = dsPool.Allocate(dslCompute); dsVAO = dsPool.Allocate(dslCompute); DescriptorSetWrites dsUpdate = new DescriptorSetWrites(dsPing, dslCompute); dsUpdate.Write(dev, inBuff.Descriptor, outBuff.Descriptor); dsUpdate.Write(dev, dsPong, outBuff.Descriptor, inBuff.Descriptor); dsUpdate = new DescriptorSetWrites(dsImage, dslImage); dsUpdate.Write(dev, imgResult.Descriptor); dsUpdate = new DescriptorSetWrites(dsVAO, dslVAO); dsUpdate.Write(dev, vbo.Descriptor, ibo.Descriptor); UpdateFrequency = 5; addPoint(IMG_DIM / 2 - 1, IMG_DIM / 2 - 1); }