Example #1
0
        public Result AllocateCommandBuffers(MgCommandBufferAllocateInfo pAllocateInfo, IMgCommandBuffer[] pCommandBuffers)
        {
            var cmdPool = pAllocateInfo.CommandPool as GLCommandPool;

            if (cmdPool == null)
            {
                throw new InvalidCastException("pAllocateInfo.CommandPool");
            }

            for (uint i = 0; i < pAllocateInfo.CommandBufferCount; ++i)
            {
                // TODO : for now
                var sorter   = new GLCmdIncrementalContextSorter();
                var dsBinder = new GLNextDescriptorSetBinder();
                var graphics = new GLCmdGraphicsEncoder(sorter, new GLCmdGraphicsBag(), mEntrypoint.VBO, dsBinder);
                var compute  = new GLCmdComputeEncoder();
                var blit     = new GLCmdBlitEncoder(sorter, new GLCmdBlitBag());
                var encoder  = new GLCmdCommandEncoder(sorter, graphics, compute, blit);


                var buffer = new GLCmdCommandBuffer(true, encoder);
                cmdPool.Buffers.Add(buffer);
                pCommandBuffers [i] = buffer;
            }

            return(Result.SUCCESS);
        }
Example #2
0
        // Command buffers for submitting present barriers
        void setupPresentationBarriers()
        {
            var cmdBufAllocateInfo = new MgCommandBufferAllocateInfo
            {
                CommandBufferCount = 2,
                CommandPool        = mManager.Configuration.Partition.CommandPool,
                Level = MgCommandBufferLevel.PRIMARY,
            };

            mPresentBuffers = new IMgCommandBuffer[2];

            var device = mManager.Configuration.Device;

            Debug.Assert(device != null);

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

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

            // Pre present
            mPrePresentCmdBuffer = mPresentBuffers[0];

            // Post present
            mPostPresentCmdBuffer = mPresentBuffers[1];
        }
Example #3
0
        void CreateCommandBuffers()
        {
            drawCmdBuffers = new IMgCommandBuffer[mGraphicsDevice.Framebuffers.Length];

            {
                var cmdBufAllocateInfo = new MgCommandBufferAllocateInfo
                {
                    CommandBufferCount = (uint)mGraphicsDevice.Framebuffers.Length,
                    CommandPool        = mConfiguration.Partition.CommandPool,
                    Level = MgCommandBufferLevel.PRIMARY,
                };

                var err = mConfiguration.Device.AllocateCommandBuffers(cmdBufAllocateInfo, drawCmdBuffers);
                Debug.Assert(err == Result.SUCCESS);
            }

            {
                var cmdBufAllocateInfo = new MgCommandBufferAllocateInfo
                {
                    CommandBufferCount = 2,
                    CommandPool        = mConfiguration.Partition.CommandPool,
                    Level = MgCommandBufferLevel.PRIMARY,
                };

                var presentBuffers = new IMgCommandBuffer[2];
                var err            = mConfiguration.Device.AllocateCommandBuffers(cmdBufAllocateInfo, presentBuffers);
                Debug.Assert(err == Result.SUCCESS);

                mPrePresentCmdBuffer  = presentBuffers[0];
                mPostPresentCmdBuffer = presentBuffers[1];
            }
        }
Example #4
0
        IMgCommandBuffer getCommandBuffer(bool begin)
        {
            var buffers = new IMgCommandBuffer[1];

            var cmdBufAllocateInfo = new MgCommandBufferAllocateInfo
            {
                CommandPool        = mConfiguration.Partition.CommandPool,
                Level              = MgCommandBufferLevel.PRIMARY,
                CommandBufferCount = 1,
            };

            var err = mConfiguration.Device.AllocateCommandBuffers(cmdBufAllocateInfo, buffers);

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

            var cmdBuf = buffers[0];

            if (begin)
            {
                var cmdBufInfo = new MgCommandBufferBeginInfo();

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

            return(cmdBuf);
        }
Example #5
0
        public void Initialize(MgGraphicsDeviceCreateInfo createInfo)
        {
            mWidth  = createInfo.Width;
            mHeight = createInfo.Height;

            mConfiguration.Initialize(mWidth, mHeight);

            Debug.Assert(mConfiguration.Partition != null);


            const int NO_OF_BUFFERS = 1;
            var       buffers       = new IMgCommandBuffer[NO_OF_BUFFERS];
            var       pAllocateInfo = new MgCommandBufferAllocateInfo
            {
                CommandBufferCount = NO_OF_BUFFERS,
                CommandPool        = mConfiguration.Partition.CommandPool,
                Level = MgCommandBufferLevel.PRIMARY,
            };

            mConfiguration.Device.AllocateCommandBuffers(pAllocateInfo, buffers);



            var setupCmdBuffer = buffers[0];

            var cmdBufInfo = new MgCommandBufferBeginInfo
            {
            };


            var err = setupCmdBuffer.BeginCommandBuffer(cmdBufInfo);

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

            mGraphicsDevice.Create(setupCmdBuffer, mSwapchains, createInfo);

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


            var submission = new[] {
                new MgSubmitInfo
                {
                    CommandBuffers = new IMgCommandBuffer[]
                    {
                        buffers[0],
                    },
                }
            };

            err = mConfiguration.Queue.QueueSubmit(submission, null);
            Debug.Assert(err == Result.SUCCESS);

            mConfiguration.Queue.QueueWaitIdle();

            mConfiguration.Device.FreeCommandBuffers(mConfiguration.Partition.CommandPool, buffers);
        }
Example #6
0
        private void InitSwapchain(uint width, uint height)
        {
            Debug.Assert(mConfiguration.Partition != null);


            const int NO_OF_BUFFERS = 1;
            var       buffers       = new IMgCommandBuffer[NO_OF_BUFFERS];
            var       pAllocateInfo = new MgCommandBufferAllocateInfo
            {
                CommandBufferCount = NO_OF_BUFFERS,
                CommandPool        = mConfiguration.Partition.CommandPool,
                Level = MgCommandBufferLevel.PRIMARY,
            };

            mConfiguration.Device.AllocateCommandBuffers(pAllocateInfo, buffers);

            var createInfo = new MgGraphicsDeviceCreateInfo
            {
                Samples      = MgSampleCountFlagBits.COUNT_1_BIT,
                Color        = MgFormat.R8G8B8A8_UINT,
                DepthStencil = MgFormat.D24_UNORM_S8_UINT,
                Width        = mWidth,
                Height       = mHeight,
            };

            var setupCmdBuffer = buffers[0];

            var cmdBufInfo = new MgCommandBufferBeginInfo();

            var err = setupCmdBuffer.BeginCommandBuffer(cmdBufInfo);

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

            mGraphicsDevice.Create(setupCmdBuffer, mSwapchains, createInfo);

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


            var submission = new[] {
                new MgSubmitInfo
                {
                    CommandBuffers = new IMgCommandBuffer[]
                    {
                        buffers[0],
                    },
                }
            };

            err = mConfiguration.Queue.QueueSubmit(submission, null);
            Debug.Assert(err == Result.SUCCESS);

            mConfiguration.Queue.QueueWaitIdle();

            mConfiguration.Device.FreeCommandBuffers(mConfiguration.Partition.CommandPool, buffers);
        }
Example #7
0
        void SetupGraphicsDevice()
        {
            try
            {
                var setupCommands = new IMgCommandBuffer[1];
                var pAllocateInfo = new MgCommandBufferAllocateInfo
                {
                    CommandPool        = mConfiguration.Partition.CommandPool,
                    CommandBufferCount = 1,
                    Level = MgCommandBufferLevel.PRIMARY,
                };

                var err = mConfiguration.Device.AllocateCommandBuffers(pAllocateInfo, setupCommands);
                Debug.Assert(err == Result.SUCCESS);

                var dsCreateInfo = new MgGraphicsDeviceCreateInfo
                {
                    Color        = MgFormat.B8G8R8A8_UNORM,
                    DepthStencil = MgFormat.D32_SFLOAT_S8_UINT,
                    Samples      = MgSampleCountFlagBits.COUNT_1_BIT,
                    Width        = mWidth,
                    Height       = mHeight,
                };

                var cmdBuf     = setupCommands[0];
                var cmdBufInfo = new MgCommandBufferBeginInfo {
                };
                cmdBuf.BeginCommandBuffer(cmdBufInfo);
                mGraphicsDevice.Create(cmdBuf, mSwapchains, dsCreateInfo);
                cmdBuf.EndCommandBuffer();

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

                mConfiguration.Partition.Queue.QueueSubmit(pSubmits, null);
                mConfiguration.Partition.Queue.QueueWaitIdle();

                mConfiguration.Partition.Device.FreeCommandBuffers(
                    mConfiguration.Partition.CommandPool, setupCommands);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
        }
Example #8
0
        public Result AllocateCommandBuffers(MgCommandBufferAllocateInfo pAllocateInfo, IMgCommandBuffer[] pCommandBuffers)
        {
            if (pAllocateInfo == null)
            {
                throw new ArgumentNullException(nameof(pAllocateInfo));
            }

            if (pCommandBuffers == null)
            {
                throw new ArgumentNullException(nameof(pCommandBuffers));
            }

            if (pAllocateInfo.CommandBufferCount != pCommandBuffers.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(pAllocateInfo.CommandBufferCount) + " !=  " + nameof(pCommandBuffers.Length));
            }

            var commandPool = (AmtCommandPool)pAllocateInfo.CommandPool;

            Debug.Assert(commandPool != null, nameof(pAllocateInfo.CommandPool) + " is null");

            var arraySize = pAllocateInfo.CommandBufferCount;

            for (var i = 0; i < arraySize; ++i)
            {
                var instructions = new AmtIncrementalChunkifier();
                var computeBag   = new AmtComputeBag();
                var compute      = new AmtComputeEncoder(instructions, computeBag);
                var graphicsBag  = new AmtGraphicsBag();
                var graphics     = new AmtGraphicsEncoder(instructions, mDevice, graphicsBag, commandPool.DepthCache);
                var blitBag      = new AmtBlitBag();
                var blit         = new AmtBlitEncoder(blitBag, instructions);

                var command = new AmtCommandEncoder(instructions, graphics, compute, blit);
                var cmdBuf  = new AmtCommandBuffer(commandPool.CanIndividuallyReset, command);

                commandPool.Add(cmdBuf);

                pCommandBuffers[i] = cmdBuf;
            }

            return(Result.SUCCESS);
        }
Example #9
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);
            }
        }
Example #10
0
 public Result AllocateCommandBuffers(MgCommandBufferAllocateInfo pAllocateInfo, IMgCommandBuffer[] pCommandBuffers)
 {
     throw new NotImplementedException();
 }