예제 #1
0
        private void RecreateSwapChain()
        {
            this.device.WaitIdle();

            foreach (var frameBuffer in this.frameBuffers)
            {
                frameBuffer.Dispose();
            }
            this.frameBuffers = null;

            this.pipeline.Dispose();
            this.pipeline = null;

            this.pipelineLayout.Dispose();
            this.pipelineLayout = null;

            foreach (var imageView in this.swapChainImageViews)
            {
                imageView.Dispose();
            }
            this.swapChainImageViews = null;

            this.renderPass.Dispose();
            this.renderPass = null;

            this.swapChain.Dispose();
            this.swapChain = null;

            this.CreateSwapChain();
            this.CreateImageViews();
            this.CreateRenderPass();
            this.CreateGraphicsPipeline();
            this.CreateFrameBuffers();
            this.CreateCommandBuffers();
        }
예제 #2
0
        private void CreateGraphicsPipeline()
        {
            var vertShader = ShanqShader.CreateVertexModule(this.device,
                                                            shanq => from input in shanq.GetInput <Vertex>()
                                                            from ubo in shanq.GetBinding <UniformBufferObject>()
                                                            let transform = ubo.Proj * ubo.View * ubo.Model
                                                                            select new VertexOutput
            {
                Position = transform * new vec4(input.Position, 0, 1),
                Colour   = input.Colour
            });

            var fragShader = ShanqShader.CreateFragmentModule(this.device,
                                                              shanq => from input in shanq.GetInput <FragmentInput>()
                                                              from ubo in shanq.GetBinding <UniformBufferObject>()
                                                              let colour = new vec4(input.Colour, 1)
                                                                           select new FragmentOutput
            {
                Colour = colour
            });

            var bindingDescription    = Vertex.GetBindingDescription();
            var attributeDescriptions = Vertex.GetAttributeDescriptions();

            this.pipelineLayout = device.CreatePipelineLayout(new PipelineLayoutCreateInfo()
            {
                SetLayouts = new[]
                {
                    this.descriptorSetLayout
                }
            });

            this.pipeline = device.CreateGraphicsPipelines(null, new[]
            {
                new GraphicsPipelineCreateInfo
                {
                    Layout           = this.pipelineLayout,
                    RenderPass       = this.renderPass,
                    Subpass          = 0,
                    VertexInputState = new PipelineVertexInputStateCreateInfo()
                    {
                        VertexBindingDescriptions   = new [] { bindingDescription },
                        VertexAttributeDescriptions = attributeDescriptions
                    },
                    InputAssemblyState = new PipelineInputAssemblyStateCreateInfo
                    {
                        PrimitiveRestartEnable = false,
                        Topology = PrimitiveTopology.TriangleList
                    },
                    ViewportState = new PipelineViewportStateCreateInfo
                    {
                        Viewports = new[]
                        {
                            new Viewport
                            {
                                X        = 0f,
                                Y        = 0f,
                                Width    = this.swapChainExtent.Width,
                                Height   = this.swapChainExtent.Height,
                                MaxDepth = 1,
                                MinDepth = 0
                            }
                        },
                        Scissors = new[]
                        {
                            new Rect2D
                            {
                                Offset = new Offset2D(),
                                Extent = this.swapChainExtent
                            }
                        }
                    },
                    RasterizationState = new PipelineRasterizationStateCreateInfo
                    {
                        DepthClampEnable        = false,
                        RasterizerDiscardEnable = false,
                        PolygonMode             = PolygonMode.Fill,
                        LineWidth       = 1,
                        CullMode        = CullModeFlags.Back,
                        FrontFace       = FrontFace.CounterClockwise,
                        DepthBiasEnable = false
                    },
                    MultisampleState = new PipelineMultisampleStateCreateInfo
                    {
                        SampleShadingEnable  = false,
                        RasterizationSamples = SampleCountFlags.SampleCount1,
                        MinSampleShading     = 1
                    },
                    ColorBlendState = new PipelineColorBlendStateCreateInfo
                    {
                        Attachments = new[]
                        {
                            new PipelineColorBlendAttachmentState
                            {
                                ColorWriteMask = ColorComponentFlags.R
                                                 | ColorComponentFlags.G
                                                 | ColorComponentFlags.B
                                                 | ColorComponentFlags.A,
                                BlendEnable                 = false,
                                SourceColorBlendFactor      = BlendFactor.One,
                                DestinationColorBlendFactor = BlendFactor.Zero,
                                ColorBlendOp                = BlendOp.Add,
                                SourceAlphaBlendFactor      = BlendFactor.One,
                                DestinationAlphaBlendFactor = BlendFactor.Zero,
                                AlphaBlendOp                = BlendOp.Add
                            }
                        },
                        LogicOpEnable  = false,
                        LogicOp        = LogicOp.Copy,
                        BlendConstants = new float[] { 0, 0, 0, 0 }
                    },
                    Stages = new[]
                    {
                        new PipelineShaderStageCreateInfo
                        {
                            Stage  = ShaderStageFlags.Vertex,
                            Module = vertShader,
                            Name   = "main"
                        },
                        new PipelineShaderStageCreateInfo
                        {
                            Stage  = ShaderStageFlags.Fragment,
                            Module = fragShader,
                            Name   = "main"
                        }
                    }
                }
            }).Single();
        }
예제 #3
0
        private void TearDown()
        {
            device.WaitIdle();

            this.renderFinishedSemaphore.Dispose();
            this.renderFinishedSemaphore = null;

            this.imageAvailableSemaphore.Dispose();
            this.imageAvailableSemaphore = null;

            this.descriptorPool.Dispose();
            this.descriptorPool = null;
            this.descriptorSet  = null;

            this.device.FreeMemory(this.uniformBufferMemory);
            this.uniformBufferMemory = null;

            this.uniformBuffer.Dispose();
            this.uniformBuffer = null;

            this.device.FreeMemory(this.uniformStagingBufferMemory);
            this.uniformStagingBufferMemory = null;

            this.uniformStagingBuffer.Dispose();
            this.uniformStagingBuffer = null;

            this.device.FreeMemory(this.indexBufferMemory);
            this.indexBufferMemory = null;

            this.indexBuffer.Dispose();
            this.indexBuffer = null;

            this.device.FreeMemory(this.vertexBufferMemory);
            this.vertexBufferMemory = null;

            this.vertexBuffer.Dispose();
            this.vertexBuffer = null;

            this.commandPool.Dispose();
            this.commandPool    = null;
            this.commandBuffers = null;
            this.transientCommandPool.Dispose();
            this.transientCommandPool = null;

            foreach (var frameBuffer in this.frameBuffers)
            {
                frameBuffer.Dispose();
            }
            this.frameBuffers = null;

            this.pipeline.Dispose();
            this.pipeline = null;

            this.pipelineLayout.Dispose();
            this.pipelineLayout = null;

            foreach (var imageView in this.swapChainImageViews)
            {
                imageView.Dispose();
            }
            this.swapChainImageViews = null;

            this.descriptorSetLayout.Dispose();
            this.descriptorSetLayout = null;

            this.renderPass.Dispose();
            this.renderPass = null;

            this.swapChain.Dispose();
            this.swapChain = null;

            this.device.Dispose();
            this.device = null;

            this.surface.Dispose();
            this.surface = null;

            this.debugCallback.Dispose();
            this.debugCallback = null;

            this.instance.Dispose();
            this.instance = null;
        }