コード例 #1
0
        public void SubmitPrePresentBarrier(IMgCommandBuffer prePresent, IMgImage image)
        {
            if (prePresent == null)
            {
                throw new InvalidOperationException();
            }

            MgCommandBufferBeginInfo cmdBufInfo = new MgCommandBufferBeginInfo
            {
            };

            var vkRes = prePresent.BeginCommandBuffer(cmdBufInfo);

            Debug.Assert(vkRes == Result.SUCCESS, vkRes + " != Result.SUCCESS");

            const uint VK_QUEUE_FAMILY_IGNORED = ~0U;

            var prePresentBarrier = new MgImageMemoryBarrier
            {
                Image               = image,
                SrcAccessMask       = MgAccessFlagBits.COLOR_ATTACHMENT_WRITE_BIT,
                DstAccessMask       = 0,
                OldLayout           = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL,
                NewLayout           = MgImageLayout.PRESENT_SRC_KHR,
                SrcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
                DstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
                SubresourceRange    = new MgImageSubresourceRange
                {
                    AspectMask     = MgImageAspectFlagBits.COLOR_BIT,
                    BaseArrayLayer = 0,
                    LayerCount     = 1,
                    BaseMipLevel   = 0,
                    LevelCount     = 1,
                },
            };

            const int VK_FLAGS_NONE = 0;

            prePresent.CmdPipelineBarrier(
                MgPipelineStageFlagBits.ALL_COMMANDS_BIT,
                MgPipelineStageFlagBits.TOP_OF_PIPE_BIT,
                VK_FLAGS_NONE,
                null,                 // No memory barriers,
                null,                 // No buffer barriers,
                new[] { prePresentBarrier });

            vkRes = prePresent.EndCommandBuffer();
            Debug.Assert(vkRes == Result.SUCCESS, vkRes + " != Result.SUCCESS");
        }
コード例 #2
0
        void flushCommandBuffer(IMgCommandBuffer commandBuffer)
        {
            Debug.Assert(commandBuffer != null);

            var err = commandBuffer.EndCommandBuffer();

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

            var submitInfos = new []
            {
                new MgSubmitInfo
                {
                    CommandBuffers = new []
                    {
                        commandBuffer
                    }
                }
            };

            var fenceCreateInfo = new MgFenceCreateInfo();

            err = mConfiguration.Device.CreateFence(fenceCreateInfo, null, out IMgFence fence);
            Debug.Assert(err == Result.SUCCESS);

            err = mConfiguration.Queue.QueueSubmit(submitInfos, fence);
            Debug.Assert(err == Result.SUCCESS);

            err = mConfiguration.Queue.QueueWaitIdle();
            Debug.Assert(err == Result.SUCCESS);

            err = mConfiguration.Device.WaitForFences(new[] { fence }, true, ulong.MaxValue);
            Debug.Assert(err == Result.SUCCESS);

            fence.DestroyFence(mConfiguration.Device, null);
            mConfiguration.Device.FreeCommandBuffers(mConfiguration.Partition.CommandPool, new[] { commandBuffer });
        }
コード例 #3
0
        public void Build(IMgCommandBuffer cmdBuf, int sliceIndex)
        {
            cmdBuf.BeginCommandBuffer(new MgCommandBufferBeginInfo {
            });

            // TODO: RENDER PASS STUFF
            // CLEAR COLOR
            // VIEWPORTS
            // SCISSORS

            foreach (var group in Groups.Values)
            {
                cmdBuf.CmdBindPipeline(MgPipelineBindPoint.GRAPHICS, group.Pipeline);
                var noOfDescriptorSets = DescriptorSets.Length;
                for (var i = 0; i < noOfDescriptorSets; i += 1)
                {
                    cmdBuf.CmdBindDescriptorSets(
                        MgPipelineBindPoint.GRAPHICS,
                        group.Layout,
                        0,
                        new[] { DescriptorSets[i] },
                        null
                        );

                    var range = group.Ranges[i];

                    var meshPrimitive = Scene.MeshPrimitives[range.MeshPrimitive];
                    foreach (var drawCall in range.InstanceDrawCalls)
                    {
                        var perInstance      = mDynamicStorage.Map.Allocations[drawCall.PerInstance[sliceIndex]];
                        var perInstanceBlock = mDynamicStorage.Storage.Blocks[perInstance.BlockIndex];

                        var perVertex      = mStaticStorage.Map.Allocations[meshPrimitive.Vertices[sliceIndex]];
                        var perVertexBlock = mStaticStorage.Storage.Blocks[perVertex.BlockIndex];

                        cmdBuf.CmdBindVertexBuffers(
                            0,
                            // TODO: multiple per-vertex buffers
                            new[] {
                            perVertexBlock.Buffer,
                            perInstanceBlock.Buffer,
                        },
                            new []
                        {
                            perVertex.Offset,
                            perInstance.Offset,
                        }
                            );

                        switch (group.DrawMode)
                        {
                        case LocalDrawMode.Draw:
                            CmdDraw(cmdBuf, meshPrimitive, drawCall, sliceIndex);
                            break;

                        case LocalDrawMode.DrawIndexed:
                            CmdDrawIndexed(cmdBuf, meshPrimitive, drawCall, sliceIndex);
                            break;

                        default:
                            throw new InvalidOperationException("draw mode not implemented");
                        }
                    }
                }
            }

            cmdBuf.EndCommandBuffer();
        }