Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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;
            }
        }