Ejemplo n.º 1
0
        uint ExtractSwapchains(List <IntPtr> attachedItems, MgPresentInfoKHRImage[] images, out IntPtr swapchains, out IntPtr imageIndices)
        {
            var  pSwapchains   = IntPtr.Zero;
            var  pImageIndices = IntPtr.Zero;
            uint count         = 0U;

            if (images != null)
            {
                count = (uint)images.Length;
                if (count > 0)
                {
                    pSwapchains = VkInteropsUtility.ExtractUInt64HandleArray(
                        images,
                        (sc) =>
                    {
                        var bSwapchain = (VkSwapchainKHR)sc.Swapchain;
                        Debug.Assert(bSwapchain != null);
                        return(bSwapchain.Handle);
                    });
                    attachedItems.Add(pSwapchains);

                    pImageIndices = VkInteropsUtility.AllocateHGlobalArray(
                        images,
                        (sc) => { return(sc.ImageIndex); });
                    attachedItems.Add(pImageIndices);
                }
            }
            swapchains   = pSwapchains;
            imageIndices = pImageIndices;
            return(count);
        }
Ejemplo n.º 2
0
        static IntPtr ExtractImageBinds(List <IntPtr> attachedItems, MgSparseImageMemoryBindInfo[] imageBinds, out uint imageBindCount)
        {
            var  dest  = IntPtr.Zero;
            uint count = 0U;

            if (imageBinds != null)
            {
                count = (uint)imageBinds.Length;
                if (count > 0)
                {
                    dest = VkInteropsUtility.AllocateNestedHGlobalArray(
                        attachedItems,
                        imageBinds,
                        (items, bind) =>
                    {
                        var bImage = (VkImage)bind.Image;
                        Debug.Assert(bImage != null);

                        Debug.Assert(bind.Binds != null);
                        var bindCount = (uint)bind.Binds.Length;

                        var pBinds = VkInteropsUtility.AllocateHGlobalArray(
                            bind.Binds,
                            (arg) =>
                        {
                            var bDeviceMemory = (VkDeviceMemory)arg.Memory;
                            Debug.Assert(bDeviceMemory != null);

                            return(new VkSparseImageMemoryBind
                            {
                                subresource = new VkImageSubresource
                                {
                                    aspectMask = (VkImageAspectFlags)arg.Subresource.AspectMask,
                                    arrayLayer = arg.Subresource.ArrayLayer,
                                    mipLevel = arg.Subresource.MipLevel,
                                },
                                offset = arg.Offset,
                                extent = arg.Extent,
                                memory = bDeviceMemory.Handle,
                                memoryOffset = arg.MemoryOffset,
                                flags = (VkSparseMemoryBindFlags)arg.Flags,
                            });
                        });
                        items.Add(pBinds);

                        return(new VkSparseImageMemoryBindInfo
                        {
                            image = bImage.Handle,
                            bindCount = bindCount,
                            pBinds = pBinds,
                        });
                    });

                    attachedItems.Add(dest);
                }
            }

            imageBindCount = count;
            return(dest);
        }
Ejemplo n.º 3
0
        static IntPtr ExtractBufferBinds(List <IntPtr> attachedItems, MgSparseBufferMemoryBindInfo[] bufferBinds, out uint bufferBindCount)
        {
            var  dest  = IntPtr.Zero;
            uint count = 0U;

            if (bufferBinds != null)
            {
                count = (uint)bufferBinds.Length;
                if (count > 0)
                {
                    dest = VkInteropsUtility.AllocateNestedHGlobalArray(
                        attachedItems,
                        bufferBinds,
                        (items, bind) =>
                    {
                        var bBuffer = (VkBuffer)bind.Buffer;
                        Debug.Assert(bBuffer != null);

                        Debug.Assert(bind.Binds != null);
                        var bindCount = (uint)bind.Binds.Length;
                        var pBinds    = VkInteropsUtility.AllocateHGlobalArray(
                            bind.Binds,
                            (arg) =>
                        {
                            var bDeviceMemory = (VkDeviceMemory)arg.Memory;
                            Debug.Assert(bDeviceMemory != null);

                            return(new VkSparseMemoryBind
                            {
                                resourceOffset = arg.ResourceOffset,
                                size = arg.Size,
                                memory = bDeviceMemory.Handle,
                                memoryOffset = arg.MemoryOffset,
                                flags = (VkSparseMemoryBindFlags)arg.Flags,
                            });
                        });
                        items.Add(pBinds);

                        return(new VkSparseBufferMemoryBindInfo
                        {
                            buffer = bBuffer.Handle,
                            bindCount = bindCount,
                            pBinds = pBinds,
                        });
                    }
                        );
                    attachedItems.Add(dest);
                }
            }

            bufferBindCount = count;
            return(dest);
        }
Ejemplo n.º 4
0
        public Result QueueSubmit(MgSubmitInfo[] pSubmits, IMgFence fence)
        {
            var bFence    = (VkFence)fence;
            var bFencePtr = bFence != null ? bFence.Handle : 0UL;

            var attachedItems = new List <IntPtr>();

            try
            {
                unsafe
                {
                    uint submitCount = 0;

                    if (pSubmits != null)
                    {
                        submitCount = (uint)pSubmits.Length;
                    }

                    var submissions = stackalloc VkSubmitInfo[(int)submitCount];

                    for (var i = 0; i < submitCount; ++i)
                    {
                        var currentInfo = pSubmits[i];

                        var waitSemaphoreCount = 0U;
                        var pWaitSemaphores    = IntPtr.Zero;
                        var pWaitDstStageMask  = IntPtr.Zero;

                        if (currentInfo.WaitSemaphores != null)
                        {
                            waitSemaphoreCount = (uint)currentInfo.WaitSemaphores.Length;
                            if (waitSemaphoreCount > 0)
                            {
                                pWaitSemaphores = VkInteropsUtility.ExtractUInt64HandleArray(
                                    currentInfo.WaitSemaphores,
                                    (arg) =>
                                {
                                    var bSemaphore = (VkSemaphore)arg.WaitSemaphore;
                                    Debug.Assert(bSemaphore != null);
                                    return(bSemaphore.Handle);
                                });
                                attachedItems.Add(pWaitSemaphores);

                                pWaitDstStageMask = VkInteropsUtility.AllocateHGlobalArray <MgSubmitInfoWaitSemaphoreInfo, uint>(
                                    currentInfo.WaitSemaphores,
                                    (arg) => { return((uint)arg.WaitDstStageMask); });
                                attachedItems.Add(pWaitDstStageMask);
                            }
                        }

                        var commandBufferCount = 0U;
                        var pCommandBuffers    = IntPtr.Zero;

                        if (currentInfo.CommandBuffers != null)
                        {
                            commandBufferCount = (uint)currentInfo.CommandBuffers.Length;
                            if (commandBufferCount > 0)
                            {
                                pCommandBuffers = VkInteropsUtility.ExtractIntPtrHandleArray
                                                  (
                                    currentInfo.CommandBuffers,
                                    (arg) =>
                                {
                                    var bCommandBuffer = (VkCommandBuffer)arg;
                                    Debug.Assert(bCommandBuffer != null);
                                    return(bCommandBuffer.Handle);
                                }
                                                  );
                                attachedItems.Add(pCommandBuffers);
                            }
                        }

                        var signalSemaphoreCount = 0U;
                        var pSignalSemaphores    = IntPtr.Zero;

                        if (currentInfo.SignalSemaphores != null)
                        {
                            signalSemaphoreCount = (uint)currentInfo.SignalSemaphores.Length;

                            if (signalSemaphoreCount > 0)
                            {
                                pSignalSemaphores = VkInteropsUtility.ExtractUInt64HandleArray(
                                    currentInfo.SignalSemaphores,
                                    (arg) =>
                                {
                                    var bSemaphore = (VkSemaphore)arg;
                                    Debug.Assert(bSemaphore != null);
                                    return(bSemaphore.Handle);
                                });
                                attachedItems.Add(pSignalSemaphores);
                            }
                        }

                        submissions[i] = new VkSubmitInfo
                        {
                            sType = VkStructureType.StructureTypeSubmitInfo,
                            pNext = IntPtr.Zero,
                            waitSemaphoreCount   = waitSemaphoreCount,
                            pWaitSemaphores      = pWaitSemaphores,
                            pWaitDstStageMask    = pWaitDstStageMask,
                            commandBufferCount   = commandBufferCount,
                            pCommandBuffers      = pCommandBuffers,
                            signalSemaphoreCount = signalSemaphoreCount,
                            pSignalSemaphores    = pSignalSemaphores,
                        };
                    }

                    return(Interops.vkQueueSubmit(Handle, submitCount, submitCount > 0  ? submissions : null, bFencePtr));
                }
            }
            finally
            {
                foreach (var item in attachedItems)
                {
                    Marshal.FreeHGlobal(item);
                }
            }
        }