コード例 #1
0
        public void CmdBindVertexBuffers(UInt32 firstBinding, IMgBuffer[] pBuffers, UInt64[] pOffsets)
        {
            var bindingCount = (uint)pBuffers.Length;
            var src          = new ulong[pBuffers.Length];

            for (uint i = 0; i < bindingCount; ++i)
            {
                var bBuffer = (VkBuffer)pBuffers[i];
                Debug.Assert(bBuffer != null);
                src[i] = bBuffer.Handle;
            }

            Interops.vkCmdBindVertexBuffers(this.Handle, firstBinding, bindingCount, src, pOffsets);
        }
コード例 #2
0
        public Result BindImageMemory(IMgDevice device, IMgDeviceMemory memory, UInt64 memoryOffset)
        {
            Debug.Assert(!mIsDisposed);

            var bDevice = (VkDevice)device;

            Debug.Assert(bDevice != null);

            var bMemory = (VkDeviceMemory)memory;

            Debug.Assert(bMemory != null);

            return(Interops.vkBindImageMemory(bDevice.Handle, this.Handle, bMemory.Handle, memoryOffset));
        }
コード例 #3
0
        public void CmdExecuteCommands(IMgCommandBuffer[] pCommandBuffers)
        {
            var handles = new IntPtr[pCommandBuffers.Length];

            var bufferCount = (uint)pCommandBuffers.Length;

            for (uint i = 0; i < bufferCount; ++i)
            {
                var bBuffer = (VkCommandBuffer)pCommandBuffers[i];
                Debug.Assert(bBuffer != null);
                handles[i] = bBuffer.Handle;
            }

            Interops.vkCmdExecuteCommands(this.Handle, bufferCount, handles);
        }
コード例 #4
0
        public void DestroySemaphore(IMgDevice device, IMgAllocationCallbacks allocator)
        {
            if (mIsDisposed)
            {
                return;
            }

            var bDevice = (VkDevice)device;

            Debug.Assert(bDevice != null);

            var    bAllocator   = (MgVkAllocationCallbacks)allocator;
            IntPtr allocatorPtr = bAllocator != null ? bAllocator.Handle : IntPtr.Zero;

            Interops.vkDestroySemaphore(bDevice.Handle, this.Handle, allocatorPtr);

            this.Handle = 0UL;
            mIsDisposed = true;
        }
コード例 #5
0
        public void DestroyDebugReportCallbackEXT(IMgInstance instance, IMgAllocationCallbacks allocator)
        {
            if (mIsDisposed)
            {
                return;
            }

            var bInstance = (VkInstance)instance;

            Debug.Assert(bInstance != null);

            var    bAllocator   = (MgVkAllocationCallbacks)allocator;
            IntPtr allocatorPtr = bAllocator != null ? bAllocator.Handle : IntPtr.Zero;

            Interops.vkDestroyDebugReportCallbackEXT(bInstance.Handle, this.Handle, allocatorPtr);

            this.Handle = 0UL;
            mIsDisposed = true;
        }
コード例 #6
0
        public void CmdBindDescriptorSets(MgPipelineBindPoint pipelineBindPoint, IMgPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, IMgDescriptorSet[] pDescriptorSets, UInt32[] pDynamicOffsets)
        {
            var bLayout = (VkPipelineLayout)layout;

            Debug.Assert(bLayout != null);

            var    stride = Marshal.SizeOf(typeof(IntPtr));
            IntPtr sets   = Marshal.AllocHGlobal((int)(stride * descriptorSetCount));

            var src = new ulong[descriptorSetCount];

            for (uint i = 0; i < descriptorSetCount; ++i)
            {
                var bDescSet = (VkDescriptorSet)pDescriptorSets[i];
                Debug.Assert(bDescSet != null);
                src[i] = bDescSet.Handle;
            }

            Interops.vkCmdBindDescriptorSets(this.Handle, (VkPipelineBindPoint)pipelineBindPoint, bLayout.Handle, firstSet, descriptorSetCount, src, (uint)pDynamicOffsets.Length, pDynamicOffsets);
        }
コード例 #7
0
        public Result EnumerateInstanceExtensionProperties(string layerName, out MgExtensionProperties[] pProperties)
        {
            var pLayerName = IntPtr.Zero;

            try
            {
                if (!string.IsNullOrWhiteSpace(layerName))
                {
                    pLayerName = VkInteropsUtility.NativeUtf8FromString(layerName);
                }

                UInt32 pPropertyCount = 0;
                var    first          = Interops.vkEnumerateInstanceExtensionProperties(pLayerName, ref pPropertyCount, null);

                if (first != Result.SUCCESS)
                {
                    pProperties = null;
                    return(first);
                }

                var extensionProperties = new VkExtensionProperties[pPropertyCount];
                var last = Interops.vkEnumerateInstanceExtensionProperties(pLayerName, ref pPropertyCount, extensionProperties);

                pProperties = new MgExtensionProperties[pPropertyCount];
                for (uint i = 0; i < pPropertyCount; ++i)
                {
                    pProperties[i] = new MgExtensionProperties
                    {
                        ExtensionName = VkInteropsUtility.ByteArrayToTrimmedString(extensionProperties[i].extensionName),
                        SpecVersion   = extensionProperties[i].specVersion,
                    };
                }
                return(last);
            }
            finally
            {
                if (pLayerName != IntPtr.Zero)
                {
                }
            }
        }
コード例 #8
0
        public void CmdSetViewport(UInt32 firstViewport, MgViewport[] pViewports)
        {
            var viewportHandle = GCHandle.Alloc(pViewports, GCHandleType.Pinned);

            try
            {
                unsafe
                {
                    var viewportCount = (UInt32)pViewports.Length;
                    var pinnedObject  = viewportHandle.AddrOfPinnedObject();

                    var viewports = (MgViewport *)pinnedObject.ToPointer();

                    Interops.vkCmdSetViewport(this.Handle, firstViewport, viewportCount, viewports);
                }
            }
            finally
            {
                viewportHandle.Free();
            }
        }
コード例 #9
0
        public void CmdSetScissor(UInt32 firstScissor, MgRect2D[] pScissors)
        {
            var scissorHandle = GCHandle.Alloc(pScissors, GCHandleType.Pinned);

            try
            {
                unsafe
                {
                    var count        = (UInt32)pScissors.Length;
                    var pinnedObject = scissorHandle.AddrOfPinnedObject();

                    var scissors = (MgRect2D *)pinnedObject.ToPointer();

                    Interops.vkCmdSetScissor(this.Handle, firstScissor, count, scissors);
                }
            }
            finally
            {
                scissorHandle.Free();
            }
        }
コード例 #10
0
        public Result CreateDisplayPlaneSurfaceKHR(MgDisplaySurfaceCreateInfoKHR createInfo, IMgAllocationCallbacks allocator, out IMgSurfaceKHR pSurface)
        {
            if (createInfo == null)
            {
                throw new ArgumentNullException(nameof(createInfo));
            }

            Debug.Assert(!mIsDisposed);

            var bDisplayMode = (VkDisplayModeKHR)createInfo.DisplayMode;

            Debug.Assert(bDisplayMode != null);

            var pCreateInfo = new VkDisplaySurfaceCreateInfoKHR
            {
                sType           = VkStructureType.StructureTypeDisplaySurfaceCreateInfoKhr,
                pNext           = IntPtr.Zero,
                flags           = createInfo.Flags,
                displayMode     = bDisplayMode.Handle,
                planeIndex      = createInfo.PlaneIndex,
                planeStackIndex = createInfo.PlaneStackIndex,
                transform       = (VkSurfaceTransformFlagsKhr)createInfo.Transform,
                globalAlpha     = createInfo.GlobalAlpha,
                alphaMode       = (VkDisplayPlaneAlphaFlagsKhr)createInfo.AlphaMode,
                imageExtent     = createInfo.ImageExtent,
            };

            // MIGHT NEED GetInstanceProcAddr INSTEAD

            var allocatorHandle = GetAllocatorHandle(allocator);

            UInt64 handle = 0UL;
            var    result = Interops.vkCreateDisplayPlaneSurfaceKHR(Handle, ref pCreateInfo, allocatorHandle, ref handle);

            pSurface = new VkSurfaceKHR(handle);

            return(result);
        }
コード例 #11
0
        public void CmdClearAttachments(MgClearAttachment[] pAttachments, MgClearRect[] pRects)
        {
            var attachmentHandle = GCHandle.Alloc(pAttachments, GCHandleType.Pinned);
            var rectsHandle      = GCHandle.Alloc(pRects, GCHandleType.Pinned);

            try
            {
                unsafe
                {
                    var attachmentCount = (uint)pAttachments.Length;
                    var attachment      = attachmentHandle.AddrOfPinnedObject();

                    var rectCount = (uint)pRects.Length;
                    var rects     = rectsHandle.AddrOfPinnedObject();
                    Interops.vkCmdClearAttachments(this.Handle, attachmentCount, (Magnesium.MgClearAttachment *)attachment.ToPointer(), rectCount, (Magnesium.MgClearRect *)rects.ToPointer());
                }
            }
            finally
            {
                rectsHandle.Free();
                attachmentHandle.Free();
            }
        }
コード例 #12
0
        public Result EnumeratePhysicalDevices(out IMgPhysicalDevice[] physicalDevices)
        {
            Debug.Assert(!mIsDisposed);

            var pPropertyCount = 0U;

            var first = Interops.vkEnumeratePhysicalDevices(Handle, ref pPropertyCount, null);

            if (first != Result.SUCCESS)
            {
                physicalDevices = null;
                return(first);
            }

            var devices = new IntPtr[pPropertyCount];
            var last    = Interops.vkEnumeratePhysicalDevices(Handle, ref pPropertyCount, devices);

            physicalDevices = new VkPhysicalDevice[pPropertyCount];
            for (uint i = 0; i < pPropertyCount; ++i)
            {
                physicalDevices[i] = new VkPhysicalDevice(devices[i]);
            }
            return(last);
        }
コード例 #13
0
 public void CmdDispatch(UInt32 x, UInt32 y, UInt32 z)
 {
     Interops.vkCmdDispatch(this.Handle, x, y, z);
 }
コード例 #14
0
 public void CmdDrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstIndex, Int32 vertexOffset, UInt32 firstInstance)
 {
     Interops.vkCmdDrawIndexed(this.Handle, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
 }
コード例 #15
0
 public Result ResetCommandBuffer(MgCommandBufferResetFlagBits flags)
 {
     return(Interops.vkResetCommandBuffer(this.Handle, (VkCommandBufferResetFlags)flags));
 }
コード例 #16
0
 public void CmdNextSubpass(MgSubpassContents contents)
 {
     Interops.vkCmdNextSubpass(this.Handle, (VkSubpassContents)contents);
 }
コード例 #17
0
 public void CmdSetStencilCompareMask(MgStencilFaceFlagBits faceMask, UInt32 compareMask)
 {
     Interops.vkCmdSetStencilCompareMask(this.Handle, (VkStencilFaceFlags)faceMask, compareMask);
 }
コード例 #18
0
 public void CmdSetDepthBounds(float minDepthBounds, float maxDepthBounds)
 {
     Interops.vkCmdSetDepthBounds(this.Handle, minDepthBounds, maxDepthBounds);
 }
コード例 #19
0
        public Result BeginCommandBuffer(MgCommandBufferBeginInfo pBeginInfo)
        {
            IntPtr inheritanceInfo = IntPtr.Zero;

            try
            {
                var param_0 = new VkCommandBufferBeginInfo();
                param_0.sType = VkStructureType.StructureTypeCommandBufferBeginInfo;
                param_0.pNext = IntPtr.Zero;
                param_0.flags = (VkCommandBufferUsageFlags)pBeginInfo.Flags;

                if (pBeginInfo.InheritanceInfo != null)
                {
                    var ihData = new VkCommandBufferInheritanceInfo();
                    ihData.sType = VkStructureType.StructureTypeCommandBufferInheritanceInfo;
                    ihData.pNext = IntPtr.Zero;

                    {
                        UInt64 internalPtr = 0UL;
                        var    container   = pBeginInfo.InheritanceInfo.RenderPass;
                        if (container != null)
                        {
                            var rp = (VkRenderPass)container;
                            Debug.Assert(rp != null);
                            internalPtr = rp.Handle;
                        }
                        ihData.renderPass = internalPtr;
                    }

                    ihData.subpass = pBeginInfo.InheritanceInfo.Subpass;

                    {
                        UInt64 internalPtr = 0UL;
                        var    container   = pBeginInfo.InheritanceInfo.Framebuffer;
                        if (container != null)
                        {
                            var fb = (VkFramebuffer)container;
                            Debug.Assert(fb != null);
                            internalPtr = fb.Handle;
                        }
                        ihData.framebuffer = internalPtr;
                    }

                    ihData.occlusionQueryEnable = new VkBool32 {
                        Value = pBeginInfo.InheritanceInfo.OcclusionQueryEnable ? 1U : 0U
                    };
                    ihData.queryFlags         = (VkQueryControlFlags)pBeginInfo.InheritanceInfo.QueryFlags;
                    ihData.pipelineStatistics = (VkQueryPipelineStatisticFlags)pBeginInfo.InheritanceInfo.PipelineStatistics;

                    // Copy data
                    inheritanceInfo = Marshal.AllocHGlobal(Marshal.SizeOf(ihData));
                    Marshal.StructureToPtr(ihData, inheritanceInfo, false);
                }

                param_0.pInheritanceInfo = inheritanceInfo;

                return(Interops.vkBeginCommandBuffer(this.Handle, ref param_0));
            }
            finally
            {
                if (inheritanceInfo != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(inheritanceInfo);
                }
            }
        }
コード例 #20
0
 public void CmdSetDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor)
 {
     Interops.vkCmdSetDepthBias(this.Handle, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
 }
コード例 #21
0
 public void CmdSetLineWidth(float lineWidth)
 {
     Interops.vkCmdSetLineWidth(this.Handle, lineWidth);
 }
コード例 #22
0
        public void CmdWaitEvents(IMgEvent[] pEvents, MgPipelineStageFlagBits srcStageMask, MgPipelineStageFlagBits dstStageMask, MgMemoryBarrier[] pMemoryBarriers, MgBufferMemoryBarrier[] pBufferMemoryBarriers, MgImageMemoryBarrier[] pImageMemoryBarriers)
        {
            unsafe
            {
                var eventHandles = stackalloc UInt64[pEvents.Length];
                var eventCount   = (uint)pEvents.Length;
                for (var i = 0; i < eventCount; ++i)
                {
                    var bEvent = (VkEvent)pEvents[i];
                    Debug.Assert(bEvent != null);
                    eventHandles[i] = bEvent.Handle;
                }

                var memBarrierCount           = 0U;
                VkMemoryBarrier *pMemBarriers = null;
                if (pMemoryBarriers != null)
                {
                    memBarrierCount = (uint)pMemoryBarriers.Length;
                    var tempMem = stackalloc VkMemoryBarrier[pMemoryBarriers.Length];
                    for (var i = 0; i < memBarrierCount; ++i)
                    {
                        tempMem[i] = new VkMemoryBarrier
                        {
                            sType         = VkStructureType.StructureTypeMemoryBarrier,
                            pNext         = IntPtr.Zero,
                            srcAccessMask = (VkAccessFlags)pMemoryBarriers[i].SrcAccessMask,
                            dstAccessMask = (VkAccessFlags)pMemoryBarriers[i].DstAccessMask,
                        };
                    }
                    pMemBarriers = tempMem;
                }

                uint bufBarrierCount = 0;
                VkBufferMemoryBarrier *pBufBarriers = null;
                if (pBufferMemoryBarriers != null)
                {
                    bufBarrierCount = (uint)pBufferMemoryBarriers.Length;
                    var tempBuf = stackalloc VkBufferMemoryBarrier[pBufferMemoryBarriers.Length];
                    for (var i = 0; i < bufBarrierCount; ++i)
                    {
                        var current = pBufferMemoryBarriers[i];
                        var bBuffer = (VkBuffer)current.Buffer;
                        Debug.Assert(bBuffer != null);

                        tempBuf[i] = new VkBufferMemoryBarrier
                        {
                            sType               = VkStructureType.StructureTypeBufferMemoryBarrier,
                            pNext               = IntPtr.Zero,
                            dstAccessMask       = (VkAccessFlags)current.DstAccessMask,
                            srcAccessMask       = (VkAccessFlags)current.SrcAccessMask,
                            srcQueueFamilyIndex = current.SrcQueueFamilyIndex,
                            dstQueueFamilyIndex = current.DstQueueFamilyIndex,
                            buffer              = bBuffer.Handle,
                            offset              = current.Offset,
                            size = current.Size,
                        };
                    }
                    pBufBarriers = tempBuf;
                }

                uint imgBarriersCount = 0;
                VkImageMemoryBarrier *pImgBarriers = null;

                if (pImageMemoryBarriers != null)
                {
                    imgBarriersCount = (uint)pImageMemoryBarriers.Length;
                    var tempImg = stackalloc VkImageMemoryBarrier[pImageMemoryBarriers.Length];
                    for (var i = 0; i < bufBarrierCount; ++i)
                    {
                        var current = pImageMemoryBarriers[i];
                        var bImage  = (VkImage)current.Image;
                        Debug.Assert(bImage != null);

                        tempImg[i] = new VkImageMemoryBarrier
                        {
                            sType               = VkStructureType.StructureTypeImageMemoryBarrier,
                            pNext               = IntPtr.Zero,
                            dstAccessMask       = (VkAccessFlags)current.DstAccessMask,
                            srcAccessMask       = (VkAccessFlags)current.SrcAccessMask,
                            oldLayout           = (Magnesium.Vulkan.VkImageLayout)current.OldLayout,
                            newLayout           = (Magnesium.Vulkan.VkImageLayout)current.NewLayout,
                            srcQueueFamilyIndex = current.SrcQueueFamilyIndex,
                            dstQueueFamilyIndex = current.DstQueueFamilyIndex,
                            image               = bImage.Handle,
                            subresourceRange    = new VkImageSubresourceRange
                            {
                                aspectMask     = (Magnesium.Vulkan.VkImageAspectFlags)current.SubresourceRange.AspectMask,
                                baseArrayLayer = current.SubresourceRange.BaseArrayLayer,
                                baseMipLevel   = current.SubresourceRange.BaseMipLevel,
                                layerCount     = current.SubresourceRange.LayerCount,
                                levelCount     = current.SubresourceRange.LevelCount,
                            }
                        };
                    }
                    pImgBarriers = tempImg;
                }

                Interops.vkCmdWaitEvents(
                    this.Handle,
                    eventCount,
                    eventHandles,
                    (VkPipelineStageFlags)srcStageMask,
                    (VkPipelineStageFlags)dstStageMask,
                    memBarrierCount,
                    pMemBarriers,
                    bufBarrierCount,
                    pBufBarriers,
                    imgBarriersCount,
                    pImgBarriers);
            }
        }
コード例 #23
0
        public void CmdPipelineBarrier(MgPipelineStageFlagBits srcStageMask, MgPipelineStageFlagBits dstStageMask, MgDependencyFlagBits dependencyFlags, MgMemoryBarrier[] pMemoryBarriers, MgBufferMemoryBarrier[] pBufferMemoryBarriers, MgImageMemoryBarrier[] pImageMemoryBarriers)
        {
            unsafe
            {
                var memBarrierCount = pMemoryBarriers != null ? (uint)pMemoryBarriers.Length : 0U;
                var pMemBarriers    = stackalloc VkMemoryBarrier[(int)memBarrierCount];

                for (var i = 0; i < memBarrierCount; ++i)
                {
                    pMemBarriers[i] = new VkMemoryBarrier
                    {
                        sType         = VkStructureType.StructureTypeMemoryBarrier,
                        pNext         = IntPtr.Zero,
                        srcAccessMask = (VkAccessFlags)pMemoryBarriers[i].SrcAccessMask,
                        dstAccessMask = (VkAccessFlags)pMemoryBarriers[i].DstAccessMask,
                    };
                }


                uint bufBarrierCount = pBufferMemoryBarriers != null ? (uint)pBufferMemoryBarriers.Length : 0U;
                var  pBufBarriers    = stackalloc VkBufferMemoryBarrier[(int)bufBarrierCount];
                for (var j = 0; j < bufBarrierCount; ++j)
                {
                    var current = pBufferMemoryBarriers[j];
                    var bBuffer = (VkBuffer)current.Buffer;
                    Debug.Assert(bBuffer != null);

                    pBufBarriers[j] = new VkBufferMemoryBarrier
                    {
                        sType               = VkStructureType.StructureTypeBufferMemoryBarrier,
                        pNext               = IntPtr.Zero,
                        dstAccessMask       = (VkAccessFlags)current.DstAccessMask,
                        srcAccessMask       = (VkAccessFlags)current.SrcAccessMask,
                        srcQueueFamilyIndex = current.SrcQueueFamilyIndex,
                        dstQueueFamilyIndex = current.DstQueueFamilyIndex,
                        buffer              = bBuffer.Handle,
                        offset              = current.Offset,
                        size = current.Size,
                    };
                }


                uint imgBarriersCount = pImageMemoryBarriers != null ? (uint)pImageMemoryBarriers.Length : 0U;
                var  pImgBarriers     = stackalloc VkImageMemoryBarrier[(int)imgBarriersCount];

                for (var k = 0; k < imgBarriersCount; ++k)
                {
                    var current = pImageMemoryBarriers[k];
                    var bImage  = (VkImage)current.Image;
                    Debug.Assert(bImage != null);

                    pImgBarriers[k] = new VkImageMemoryBarrier
                    {
                        sType               = VkStructureType.StructureTypeImageMemoryBarrier,
                        pNext               = IntPtr.Zero,
                        dstAccessMask       = (VkAccessFlags)current.DstAccessMask,
                        srcAccessMask       = (VkAccessFlags)current.SrcAccessMask,
                        oldLayout           = (VkImageLayout)current.OldLayout,
                        newLayout           = (VkImageLayout)current.NewLayout,
                        srcQueueFamilyIndex = current.SrcQueueFamilyIndex,
                        dstQueueFamilyIndex = current.DstQueueFamilyIndex,
                        image               = bImage.Handle,
                        subresourceRange    = new VkImageSubresourceRange
                        {
                            aspectMask     = (VkImageAspectFlags)current.SubresourceRange.AspectMask,
                            baseArrayLayer = current.SubresourceRange.BaseArrayLayer,
                            baseMipLevel   = current.SubresourceRange.BaseMipLevel,
                            layerCount     = current.SubresourceRange.LayerCount,
                            levelCount     = current.SubresourceRange.LevelCount,
                        }
                    };
                }

                VkMemoryBarrier *      mems   = memBarrierCount > 0 ? pMemBarriers : null;
                VkBufferMemoryBarrier *bufs   = bufBarrierCount > 0 ? pBufBarriers : null;
                VkImageMemoryBarrier * images = imgBarriersCount > 0 ? pImgBarriers : null;


                Interops.vkCmdPipelineBarrier(Handle,
                                              (VkPipelineStageFlags)srcStageMask,
                                              (VkPipelineStageFlags)dstStageMask,
                                              (VkDependencyFlags)dependencyFlags,
                                              memBarrierCount,
                                              mems,
                                              bufBarrierCount,
                                              bufs,
                                              imgBarriersCount,
                                              images);
            }
        }
コード例 #24
0
 public void CmdSetStencilReference(MgStencilFaceFlagBits faceMask, UInt32 reference)
 {
     Interops.vkCmdSetStencilReference(this.Handle, (VkStencilFaceFlags)faceMask, reference);
 }
コード例 #25
0
 public void CmdEndRenderPass()
 {
     Interops.vkCmdEndRenderPass(this.Handle);
 }
コード例 #26
0
        public Result QueueBindSparse(MgBindSparseInfo[] pBindInfo, IMgFence fence)
        {
            var bFence    = (VkFence)fence;
            var bFencePtr = bFence != null ? bFence.Handle : 0UL;

            var attachedItems = new List <IntPtr>();

            try
            {
                unsafe
                {
                    var bindInfoCount = 0U;

                    var bindInfos = stackalloc VkBindSparseInfo[(int)bindInfoCount];

                    for (var i = 0; i < bindInfoCount; ++i)
                    {
                        var current = pBindInfo[i];

                        uint waitSemaphoreCount;
                        var  pWaitSemaphores = ExtractSemaphores(attachedItems, current.WaitSemaphores, out waitSemaphoreCount);

                        uint bufferBindCount;
                        var  pBufferBinds = ExtractBufferBinds(attachedItems, current.BufferBinds, out bufferBindCount);

                        uint imageOpaqueBindCount;
                        var  pImageOpaqueBinds = ExtractImageOpaqueBinds(attachedItems, current.ImageOpaqueBinds, out imageOpaqueBindCount);

                        uint imageBindCount;
                        var  pImageBinds = ExtractImageBinds(attachedItems, current.ImageBinds, out imageBindCount);

                        uint signalSemaphoreCount;
                        var  pSignalSemaphores = ExtractSemaphores(attachedItems, current.SignalSemaphores, out signalSemaphoreCount);

                        bindInfos[i] = new VkBindSparseInfo
                        {
                            sType = VkStructureType.StructureTypeBindSparseInfo,
                            pNext = IntPtr.Zero,
                            waitSemaphoreCount   = waitSemaphoreCount,
                            pWaitSemaphores      = pWaitSemaphores,
                            bufferBindCount      = bufferBindCount,
                            pBufferBinds         = pBufferBinds,
                            imageOpaqueBindCount = imageOpaqueBindCount,
                            pImageOpaqueBinds    = pImageOpaqueBinds,
                            imageBindCount       = imageBindCount,
                            pImageBinds          = pImageBinds,
                            signalSemaphoreCount = signalSemaphoreCount,
                            pSignalSemaphores    = pSignalSemaphores,
                        };
                    }

                    return(Interops.vkQueueBindSparse(Handle, bindInfoCount, bindInfos, bFencePtr));
                }
            }
            finally
            {
                foreach (var item in attachedItems)
                {
                    Marshal.FreeHGlobal(item);
                }
            }
        }
コード例 #27
0
 public Result EndCommandBuffer()
 {
     return(Interops.vkEndCommandBuffer(this.Handle));
 }
コード例 #28
0
 public void CmdDraw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
 {
     Interops.vkCmdDraw(this.Handle, vertexCount, instanceCount, firstVertex, firstInstance);
 }
コード例 #29
0
 public void CmdSetStencilWriteMask(MgStencilFaceFlagBits faceMask, UInt32 writeMask)
 {
     Interops.vkCmdSetStencilWriteMask(this.Handle, (VkStencilFaceFlags)faceMask, writeMask);
 }
コード例 #30
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);
                }
            }
        }