Пример #1
0
        void buildCommandBuffers()
        {
            var cmdBufInfo = new MgCommandBufferBeginInfo
            {
            };

            var renderPassBeginInfo = new MgRenderPassBeginInfo
            {
                RenderPass = mManager.Graphics.Renderpass,
                RenderArea = new MgRect2D
                {
                    Offset = new MgOffset2D {
                        X = 0, Y = 0
                    },
                    Extent = new MgExtent2D {
                        Width  = mManager.Width,
                        Height = mManager.Height
                    },
                },
                ClearValues = new MgClearValue[]
                {
                    MgClearValue.FromColorAndFormat(mManager.Swapchains.Format, new MgColor4f(0f, 0f, 0f, 0f)),
                    new MgClearValue {
                        DepthStencil = new MgClearDepthStencilValue(1024f, 0)
                    }
                },
            };

            var cmdBufferCount = (uint)mManager.Graphics.Framebuffers.Length;

            drawCmdBuffers = new IMgCommandBuffer[cmdBufferCount];

            var cmdBufAllocateInfo = new MgCommandBufferAllocateInfo
            {
                CommandBufferCount = cmdBufferCount,
                CommandPool        = mManager.Configuration.Partition.CommandPool,
                Level = MgCommandBufferLevel.PRIMARY,
            };

            var device = mManager.Configuration.Device;

            Debug.Assert(device != null);

            var err = device.AllocateCommandBuffers(cmdBufAllocateInfo, drawCmdBuffers);

            Debug.Assert(err == Result.SUCCESS);

            for (var i = 0; i < cmdBufferCount; ++i)
            {
                // Set target frame buffer
                renderPassBeginInfo.Framebuffer = mManager.Graphics.Framebuffers[i];

                var cmdBuf = drawCmdBuffers[i];

                err = cmdBuf.BeginCommandBuffer(cmdBufInfo);
                Debug.Assert(err == Result.SUCCESS);

                cmdBuf.CmdBeginRenderPass(renderPassBeginInfo, MgSubpassContents.INLINE);

                var viewport = new MgViewport
                {
                    Width    = mManager.Width,
                    Height   = mManager.Height,
                    MinDepth = 0f,
                    MaxDepth = 2f,
                };

                cmdBuf.CmdSetViewport(0, new[] { viewport });

                //var scissor = new MgRect2D {
                //    Extent = new MgExtent2D
                //    {
                //        Height = mManager.Height,
                //        Width = mManager.Width,
                //    },
                //    Offset = new MgOffset2D
                //    {
                //        X = 0,
                //        Y = 0,
                //    }
                //};
                cmdBuf.CmdSetScissor(0, new [] { mManager.Graphics.Scissor });

                cmdBuf.CmdBindDescriptorSets(MgPipelineBindPoint.GRAPHICS, mPipelineLayout, 0, 1, mDescriptorSets, null);
                cmdBuf.CmdBindPipeline(MgPipelineBindPoint.GRAPHICS, mSolidPipeline);

                cmdBuf.CmdBindVertexBuffers(0, new[] { vertexBuffer.InternalBuffer }, new[] { 0UL });
                cmdBuf.CmdBindIndexBuffer(indexBuffer.InternalBuffer, 0, MgIndexType.UINT32);

                cmdBuf.CmdDrawIndexed(indexCount, 1, 0, 0, 0);

                cmdBuf.CmdEndRenderPass();

                err = cmdBuf.EndCommandBuffer();
                Debug.Assert(err == Result.SUCCESS);
            }
        }
Пример #2
0
        void BuildCommandBuffers()
        {
            var renderPassBeginInfo = new MgRenderPassBeginInfo {
                RenderPass = mGraphicsDevice.Renderpass,
                RenderArea = new MgRect2D
                {
                    Offset = new MgOffset2D {
                        X = 0, Y = 0
                    },
                    Extent = new MgExtent2D {
                        Width = mWidth, Height = mHeight
                    },
                },
                ClearValues = new MgClearValue[]
                {
                    MgClearValue.FromColorAndFormat(mSwapchains.Format, new MgColor4f(0f, 0f, 0f, 0f)),
                    new MgClearValue {
                        DepthStencil = new MgClearDepthStencilValue(1.0f, 0)
                    },
                },
            };

            for (var i = 0; i < drawCmdBuffers.Length; ++i)
            {
                renderPassBeginInfo.Framebuffer = mGraphicsDevice.Framebuffers[i];

                var cmdBuf = drawCmdBuffers[i];

                var cmdBufInfo = new MgCommandBufferBeginInfo {
                };
                var err        = cmdBuf.BeginCommandBuffer(cmdBufInfo);
                Debug.Assert(err == Result.SUCCESS);

                cmdBuf.CmdBeginRenderPass(renderPassBeginInfo, MgSubpassContents.INLINE);

                cmdBuf.CmdSetViewport(0,
                                      new[] {
                    new MgViewport {
                        Height   = (float)mHeight,
                        Width    = (float)mWidth,
                        MinDepth = 0.0f,
                        MaxDepth = 1.0f,
                    }
                }
                                      );

                cmdBuf.CmdSetScissor(0,
                                     new[] {
                    new MgRect2D {
                        Extent = new MgExtent2D {
                            Width = mWidth, Height = mHeight
                        },
                        Offset = new MgOffset2D {
                            X = 0, Y = 0
                        },
                    }
                }
                                     );

                cmdBuf.CmdBindDescriptorSets(MgPipelineBindPoint.GRAPHICS, mPipelineLayout, 0, 1, new[] { mDescriptorSet }, null);

                cmdBuf.CmdBindPipeline(MgPipelineBindPoint.GRAPHICS, mPipeline);

                cmdBuf.CmdBindVertexBuffers(0, new[] { vertices.buffer }, new [] { 0UL });

                cmdBuf.CmdBindIndexBuffer(indices.buffer, 0, MgIndexType.UINT32);

                cmdBuf.CmdDrawIndexed(indices.count, 1, 0, 0, 1);

                cmdBuf.CmdEndRenderPass();

                err = cmdBuf.EndCommandBuffer();
                Debug.Assert(err == Result.SUCCESS);
            }
        }
Пример #3
0
        public void Test_GL001()
        {
            uint     width  = 600;
            uint     height = 400;
            MgFormat format = MgFormat.R8G8B8A8_UINT;

            var beginInfo = new MgCommandBufferBeginInfo {
                Flags = 0,
            };

            cmdBuf.BeginCommandBuffer(beginInfo);

            var passBeginInfo = new MgRenderPassBeginInfo
            {
                Framebuffer = framebuffer,
                RenderPass  = renderpass,
                RenderArea  = new MgRect2D
                {
                    Extent = new MgExtent2D
                    {
                        Width  = width,
                        Height = height,
                    },
                    Offset = new MgOffset2D
                    {
                        X = 0,
                        Y = 0,
                    }
                },
                ClearValues = new[]
                {
                    MgClearValue.FromColorAndFormat(format, new MgColor4f(1f, 0, 1f, 1f)),
                    new MgClearValue {
                        DepthStencil = new MgClearDepthStencilValue(1f, 0),
                    }
                },
            };

            cmdBuf.CmdBeginRenderPass(passBeginInfo, MgSubpassContents.INLINE);

            cmdBuf.CmdBindPipeline(MgPipelineBindPoint.GRAPHICS, pipeline);

            cmdBuf.CmdBindVertexBuffers(0, new[] { vertexBuffer }, new ulong[] { 0 });
            cmdBuf.CmdBindIndexBuffer(indexBuffer, 0, MgIndexType.UINT32);
            cmdBuf.CmdDrawIndexed(6, 1, 0, 0, 0);

            cmdBuf.CmdEndRenderPass();

            var err = cmdBuf.EndCommandBuffer();

            var submitInfo = new[]
            {
                new MgSubmitInfo
                {
                    CommandBuffers = new []
                    {
                        cmdBuf,
                    }
                }
            };

            queue.QueueSubmit(submitInfo, null);
            queue.QueueWaitIdle();

            // MAKE SURE DOUBLE SUBMISSION WORKS
            queue.QueueSubmit(submitInfo, null);
            queue.QueueWaitIdle();
        }
Пример #4
0
        void GenerateRenderingCommandBuffers()
        {
            var noOfFramebuffers = (uint)mGraphicsDevice.Framebuffers.Length;
            var uniformStride    = Marshal.SizeOf(typeof(Uniforms));

            mRenderCmdBuffers = new Magnesium.IMgCommandBuffer[noOfFramebuffers];
            var pAllocateInfo = new Magnesium.MgCommandBufferAllocateInfo
            {
                CommandPool        = mConfiguration.Partition.CommandPool,
                CommandBufferCount = noOfFramebuffers,
                Level = Magnesium.MgCommandBufferLevel.PRIMARY,
            };

            var err = mConfiguration.Device.AllocateCommandBuffers(pAllocateInfo, mRenderCmdBuffers);

            Debug.Assert(err == Result.SUCCESS);

            for (var i = 0; i < noOfFramebuffers; ++i)
            {
                var cmdBuf = mRenderCmdBuffers[i];
                var fb     = mGraphicsDevice.Framebuffers[i];

                MgCommandBufferBeginInfo pBeginInfo = new MgCommandBufferBeginInfo
                {
                };
                // Create a new command buffer for each renderpass to the current drawable
                cmdBuf.BeginCommandBuffer(pBeginInfo);

                var pRenderPassBegin = new MgRenderPassBeginInfo
                {
                    RenderPass  = mGraphicsDevice.Renderpass,
                    Framebuffer = fb,
                    RenderArea  = mGraphicsDevice.Scissor,
                    ClearValues = new MgClearValue[]
                    {
                        MgClearValue.FromColorAndFormat(mSwapchains.Format, new MgColor4f(0.5f, 0.5f, 0.5f, 0.5f)),
                        new MgClearValue {
                            DepthStencil = new MgClearDepthStencilValue {
                                Depth = 1f
                            }
                        },
                    },
                };
                cmdBuf.CmdBeginRenderPass(pRenderPassBegin, MgSubpassContents.INLINE);

                cmdBuf.CmdBindPipeline(MgPipelineBindPoint.GRAPHICS, mPipelineState);
                cmdBuf.CmdBindVertexBuffers(
                    0,
                    new IMgBuffer[]
                {
                    mVertices.Buffer,
                },
                    new[]
                {
                    mVertices.Offset,
                }
                    );
                cmdBuf.CmdBindDescriptorSets(
                    MgPipelineBindPoint.GRAPHICS,
                    mPipelineLayout,
                    0,
                    1,
                    new[]
                {
                    mUniformDescriptorSet,
                },
                    new[]
                {
                    (uint)(constantDataBufferIndex * uniformStride),
                }
                    );
                cmdBuf.CmdBindIndexBuffer(
                    mIndices.Buffer,
                    mIndices.Offset,
                    MgIndexType.UINT32);

                cmdBuf.CmdDrawIndexed((uint)indicesVboData.Length, 1, 0, 0, 0);
                //cmdBuf.CmdDrawIndexed(15, 1, 0, 0, 0);

                cmdBuf.CmdEndRenderPass();

                cmdBuf.EndCommandBuffer();
            }
        }