Пример #1
0
        /// <summary>
        /// Submit an executable command buffer with optional wait and signal semaphores, and an optional fence to be signaled when the commands have been completed.
        /// </summary>
        /// <param name="queue">Queue.</param>
        /// <param name="wait">Wait.</param>
        /// <param name="signal">Signal.</param>
        /// <param name="fence">Fence.</param>
        public void Submit(VkQueue queue, VkSemaphore wait = default, VkSemaphore signal = default, Fence fence = null)
        {
            VkSubmitInfo submit_info = VkSubmitInfo.New();

            IntPtr dstStageMask = Marshal.AllocHGlobal(sizeof(uint));

            Marshal.WriteInt32(dstStageMask, (int)VkPipelineStageFlags.ColorAttachmentOutput);

            using (PinnedObjects pctx = new PinnedObjects()) {
                submit_info.pWaitDstStageMask = dstStageMask;
                if (signal != VkSemaphore.Null)
                {
                    submit_info.signalSemaphoreCount = 1;
                    submit_info.pSignalSemaphores    = signal.Pin(pctx);
                }
                if (wait != VkSemaphore.Null)
                {
                    submit_info.waitSemaphoreCount = 1;
                    submit_info.pWaitSemaphores    = wait.Pin(pctx);
                }

                submit_info.commandBufferCount = 1;
                submit_info.pCommandBuffers    = handle.Pin(pctx);

                Utils.CheckResult(vkQueueSubmit(queue, 1, ref submit_info, fence));
            }
            Marshal.FreeHGlobal(dstStageMask);
        }
Пример #2
0
        protected override void PlatformSwapBuffers()
        {
            // First, ensure all pending draws are submitted to the proper render passes, and are completed.
            FlushFrameDrawCommands();

            // Then, present the swapchain.
            VkPresentInfoKHR presentInfo = VkPresentInfoKHR.New();

            presentInfo.waitSemaphoreCount = 1;
            // Wait on the last render pass to complete before presenting.
            VkSemaphore signalSemaphore = _renderPassSemaphores[_renderPassStates.Count - 1];

            presentInfo.pWaitSemaphores = &signalSemaphore;

            VkSwapchainKHR swapchain = _scInfo.Swapchain;

            presentInfo.swapchainCount = 1;
            presentInfo.pSwapchains    = &swapchain;
            uint imageIndex = _scInfo.ImageIndex;

            presentInfo.pImageIndices = &imageIndex;

            vkQueuePresentKHR(_presentQueue, ref presentInfo);

            ClearFrameObjects();
            _framebufferChanged = true;
        }
Пример #3
0
        public DeferredPbrRenderer(Queue gQueue, string cubemapPath, uint width, uint height, float nearPlane, float farPlane)
        {
            this.gQueue      = gQueue;
            this.dev         = gQueue.Dev;
            this.cubemapPath = cubemapPath;
            this.width       = width;
            this.height      = height;

            DrawComplete = dev.CreateSemaphore();

            pipelineCache = new PipelineCache(dev);

            descriptorPool = new DescriptorPool(dev, 5,
                                                new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 3),
                                                new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 6),
                                                new VkDescriptorPoolSize(VkDescriptorType.InputAttachment, 5),
                                                new VkDescriptorPoolSize(VkDescriptorType.StorageImage, 4)
                                                );

            uboMatrices = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, matrices, true);
            uboLights   = new HostBuffer <Light> (dev, VkBufferUsageFlags.UniformBuffer, lights, true);

#if WITH_SHADOWS
            shadowMapRenderer = new ShadowMapRenderer(gQueue, this);
#endif

            init(nearPlane, farPlane);
        }
Пример #4
0
        public void Render()
        {
            if (!isInitialized)
            {
                return;
            }

            if (this.submitInfos == null)
            {
                InitRenderParams();
            }

            VkDevice    device = this.device; VkSwapchainKHR swapchain = this.swapchain;
            VkSemaphore semaphore = this.vkSemaphore; VkFence fence = this.vkFence;
            VkQueue     queue = this.vkQueue;
            //uint nextIndex = device.AcquireNextImageKHR(swapchain, ulong.MaxValue, semaphore);
            UInt32 nextIndex;

            vkAPI.vkAcquireNextImageKHR(device, swapchain, ulong.MaxValue,
                                        semaphore, new VkFence(), &nextIndex).Check();
            //device.ResetFence(fence);
            vkAPI.vkResetFences(device, 1, &fence).Check();

            //queue.Submit(ref this.submitInfos[nextIndex], fence);
            //VkSubmitInfo submitInfo = this.submitInfos[nextIndex];
            //vkAPI.vkQueueSubmit(queue, 1, &submitInfo, fence).Check();
            vkAPI.vkQueueSubmit(queue, 1, &this.submitInfos[nextIndex], fence).Check();
            //device.WaitForFence(fence, true, 100000000);
            vkAPI.vkWaitForFences(device, 1, &fence, true, 100000000).Check();
            //queue.PresentKHR(ref this.presentInfos[nextIndex]);
            //VkPresentInfoKHR presentInfo = this.presentInfos[nextIndex];
            //vkAPI.vkQueuePresentKHR(queue, &presentInfo).Check();
            vkAPI.vkQueuePresentKHR(queue, &this.presentInfos[nextIndex]).Check();
        }
Пример #5
0
 public VkResult AcquireNextImage(VkSwapchainKHR swapchain, long timeout, VkSemaphore semaphore, VkFence fence, out int pImageIndex)
 {
     pImageIndex      = m_NextImageIndex;
     m_NextImageIndex = (m_NextImageIndex + 1) % m_Images.Count;
     // semaphore?.Signal();
     // fence?.Signal();
     return(VkResult.VK_SUCCESS);
 }
Пример #6
0
 public static extern VkResult AcquireNextImageKHR(
     VkDevice device,
     VkSwapchainKHR swapchain,
     ulong timeout,
     VkSemaphore semaphore,
     VkFence fence,
     out uint pImageIndex
     );
Пример #7
0
 public override void Activate()
 {
     if (state != ActivableState.Activated)
     {
         presentComplete = Dev.CreateSemaphore();
         presentComplete.SetDebugMarkerName(Dev, "Semaphore PresentComplete");
     }
     base.Activate();
 }
Пример #8
0
 public uint AcquireNextImage(VkSemaphore semaphore, VkFence fence, ulong timeout = ulong.MaxValue)
 {
     unsafe
     {
         uint index = uint.MaxValue;
         Device.Handle.AcquireNextImageKHR(Handle, timeout, semaphore, fence, &index);
         return(index);
     }
 }
Пример #9
0
        /**
         * Acquires the next image in the swap chain
         *
         * @param presentCompleteSemaphore (Optional) Semaphore that is signaled when the image is ready for use
         * @param imageIndex Pointer to the image index that will be increased if the next image could be acquired
         *
         * @note The function will always wait until the next image has been acquired by setting timeout to UINT64_MAX
         *
         * @return VkResult of the image acquisition
         */
        public VkResult AcquireNextImage(VkSemaphore presentCompleteSemaphore, ref uint imageIndex)
        {
            // By setting timeout to UINT64_MAX we will always wait until the next image has been acquired or an actual error is thrown
            // With that we don't have to handle VK_NOT_READY
            uint     index  = 0;
            VkResult result = vkAcquireNextImageKHR(Device, Swapchain, ulong.MaxValue, presentCompleteSemaphore, new VkFence(), &index);

            imageIndex = index;
            return(result);
        }
Пример #10
0
        public static VkResult vkCreateSemaphore(VkDevice device, out VkSemaphore semaphore)
        {
            VkSemaphoreCreateInfo createInfo = new VkSemaphoreCreateInfo
            {
                sType = VkStructureType.SemaphoreCreateInfo,
                pNext = null,
                flags = VkSemaphoreCreateFlags.None
            };

            return(vkCreateSemaphore(device, &createInfo, null, out semaphore));
        }
Пример #11
0
        protected virtual void Draw(Timer timer)
        {
            // Acquire an index of drawing image for this frame.
            uint     nextImageIndex;
            VkResult result = vkAcquireNextImageKHR(Context.Device, Swapchain, ulong.MaxValue, ImageAvailableSemaphore, VkFence.Null, out nextImageIndex);

            result.CheckResult();

            // Use a fence to wait until the command buffer has finished execution before using it again
            VkFence fence = SubmitFences[nextImageIndex];

            result = vkWaitForFences(Context.Device, 1, &fence, false, ulong.MaxValue);
            result.CheckResult();

            result = vkResetFences(Context.Device, 1, &fence);
            result.CheckResult();

            VkSemaphore          signalSemaphore = RenderingFinishedSemaphore;
            VkSemaphore          waitSemaphore   = ImageAvailableSemaphore;
            VkPipelineStageFlags waitStages      = VkPipelineStageFlags.ColorAttachmentOutput;
            VkCommandBuffer      commandBuffer   = CommandBuffers[nextImageIndex];

            VkSubmitInfo submitInfo = new VkSubmitInfo()
            {
                sType = VkStructureType.SubmitInfo,
                waitSemaphoreCount   = 1,
                pWaitSemaphores      = &waitSemaphore,
                pWaitDstStageMask    = &waitStages,
                commandBufferCount   = 1,
                pCommandBuffers      = &commandBuffer,
                signalSemaphoreCount = 1,
                pSignalSemaphores    = &signalSemaphore,
            };

            result = vkQueueSubmit(Context.GraphicsQueue, 1, &submitInfo, SubmitFences[nextImageIndex]);
            result.CheckResult();

            // Present the color output to screen.
            VkSemaphore    waitSemaphoreHandle = RenderingFinishedSemaphore;
            VkSwapchainKHR swapchainHandle     = Swapchain;
            var            nativePresentInfo   = new VkPresentInfoKHR
            {
                sType = VkStructureType.PresentInfoKHR,
                pNext = null,
                waitSemaphoreCount = 1,
                pWaitSemaphores    = &waitSemaphoreHandle,
                swapchainCount     = 1,
                pSwapchains        = &swapchainHandle,
                pImageIndices      = &nextImageIndex
            };

            result = vkQueuePresentKHR(Context.PresentQueue, &nativePresentInfo);
            result.CheckResult();
        }
Пример #12
0
        /**
         * Queue an image for presentation
         *
         * @param queue Presentation queue for presenting the image
         * @param imageIndex Index of the swapchain image to queue for presentation
         * @param waitSemaphore (Optional) Semaphore that is waited on before the image is presented (only used if != VK_NULL_HANDLE)
         *
         * @return VkResult of the queue presentation
         */
        public VkResult QueuePresent(VkQueue queue, uint imageIndex, VkSemaphore waitSemaphore = new VkSemaphore())
        {
            var presentInfo = VkPresentInfoKHR.Alloc();

            presentInfo->swapchainsImages.Set(Swapchain);
            presentInfo->swapchainsImages.Set(imageIndex);
            // Check if a wait semaphore has been specified to wait for before presenting the image
            if (waitSemaphore != 0ul)
            {
                presentInfo->waitSemaphores = waitSemaphore;
            }
            return(vkQueuePresentKHR(queue, presentInfo));
        }
        void drawFrame()
        {
            int imageIndex;

            Vulkan.vkAcquireNextImageKHR(device, swapChain, long.MaxValue, imageAvailableSemaphore, null, out imageIndex);

            VkSubmitInfo submitInfo = new VkSubmitInfo();

            submitInfo.sType = VkStructureType.VK_STRUCTURE_TYPE_SUBMIT_INFO;

            VkSemaphore[]             waitSemaphores = new VkSemaphore[] { imageAvailableSemaphore };
            VkPipelineStageFlagBits[] waitStages     = new VkPipelineStageFlagBits[] { VkPipelineStageFlagBits.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
            submitInfo.waitSemaphoreCount = 1;
            submitInfo.pWaitSemaphores    = waitSemaphores;
            submitInfo.pWaitDstStageMask  = waitStages;

            submitInfo.commandBufferCount = 1;
            submitInfo.pCommandBuffers    = new VkCommandBuffer[] { commandBuffers[imageIndex] };

            VkSemaphore[] signalSemaphores = new VkSemaphore[] { renderFinishedSemaphore };
            submitInfo.signalSemaphoreCount = 1;
            submitInfo.pSignalSemaphores    = signalSemaphores;

            fpsSubmitQueue.Begin();
            VkResult result = Vulkan.vkQueueSubmit(graphicsQueue, 1, new VkSubmitInfo[] { submitInfo }, null);

            fpsSubmitQueue.End(); fpsSubmitQueue.DebugPeriodicReport();

            if (result != VkResult.VK_SUCCESS)
            {
                throw Program.Throw("failed to submit draw command buffer!");
            }

            VkPresentInfoKHR presentInfo = new VkPresentInfoKHR();

            presentInfo.sType = VkStructureType.VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;

            presentInfo.waitSemaphoreCount = 1;
            presentInfo.pWaitSemaphores    = signalSemaphores;

            VkSwapchainKHR[] swapChains = new VkSwapchainKHR[] { swapChain };
            presentInfo.swapchainCount = 1;
            presentInfo.pSwapchains    = swapChains;
            presentInfo.pImageIndices  = new int[] { imageIndex };

            fpsPresentQueue.Begin();
            Vulkan.vkQueuePresentKHR(presentQueue, presentInfo);
            fpsPresentQueue.End(); fpsPresentQueue.DebugPeriodicReport();

            Vulkan.vkQueueWaitIdle(presentQueue);
        }
Пример #14
0
        public static void SetDebugMarkerName(this VkSemaphore obj, Device dev, string name)
        {
            if (!dev.DebugMarkersEnabled)
            {
                return;
            }
            VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT(VkDebugReportObjectTypeEXT.SemaphoreEXT,
                                                                                    obj.Handle)
            {
                pObjectName = name.Pin()
            };

            Utils.CheckResult(vkDebugMarkerSetObjectNameEXT(dev.VkDev, ref dmo));
            name.Unpin();
        }
Пример #15
0
        private void CreateSemaphores()
        {
            var semaphoreInfo = new VkSemaphoreCreateInfo()
            {
                sType = VkStructureType.VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
            };

            VkSemaphore vkSemaphore;
            var         result = VulkanNative.vkCreateSemaphore(vkDevice, &semaphoreInfo, null, &vkSemaphore);

            vkImageAvailableSemaphore = vkSemaphore;
            Helpers.CheckErrors(result);

            result = VulkanNative.vkCreateSemaphore(vkDevice, &semaphoreInfo, null, &vkSemaphore);
            vkRenderFinishedSemaphore = vkSemaphore;
            Helpers.CheckErrors(result);
        }
Пример #16
0
        private VkResult AcquireNextImage(out uint imageIndex)
        {
            VkSemaphore acquireSemaphore;

            if (_recycledSemaphores.Count == 0)
            {
                vkCreateSemaphore(VkDevice, out acquireSemaphore).CheckResult();
            }
            else
            {
                acquireSemaphore = _recycledSemaphores[_recycledSemaphores.Count - 1];
                _recycledSemaphores.RemoveAt(_recycledSemaphores.Count - 1);
            }

            VkResult result = vkAcquireNextImageKHR(VkDevice, Swapchain.Handle, ulong.MaxValue, acquireSemaphore, VkFence.Null, out imageIndex);

            if (result != VkResult.Success)
            {
                _recycledSemaphores.Add(acquireSemaphore);
                return(result);
            }

            if (_perFrame[imageIndex].QueueSubmitFence != VkFence.Null)
            {
                vkWaitForFences(VkDevice, _perFrame[imageIndex].QueueSubmitFence, true, ulong.MaxValue);
                vkResetFences(VkDevice, _perFrame[imageIndex].QueueSubmitFence);
            }

            if (_perFrame[imageIndex].PrimaryCommandPool != VkCommandPool.Null)
            {
                vkResetCommandPool(VkDevice, _perFrame[imageIndex].PrimaryCommandPool, VkCommandPoolResetFlags.None);
            }

            // Recycle the old semaphore back into the semaphore manager.
            VkSemaphore old_semaphore = _perFrame[imageIndex].SwapchainAcquireSemaphore;

            if (old_semaphore != VkSemaphore.Null)
            {
                _recycledSemaphores.Add(old_semaphore);
            }

            _perFrame[imageIndex].SwapchainAcquireSemaphore = acquireSemaphore;

            return(VkResult.Success);
        }
Пример #17
0
        public VkResult AcquireNextImage(ulong timeout, Semaphore semaphore, Fence fence, out uint index)
        {
            VkSemaphore sTemp = VkSemaphore.Null;
            VkFence     fTemp = VkFence.Null;

            if (semaphore != null)
            {
                sTemp = semaphore.Native;
            }
            if (fence != null)
            {
                fTemp = fence.Native;
            }

            var result = Device.Commands.acquireNextImage(Device.Native, swapchain, timeout, sTemp, fTemp, out index);

            return(result);
        }
Пример #18
0
        /**
         * Queue an image for presentation
         *
         * @param queue Presentation queue for presenting the image
         * @param imageIndex Index of the swapchain image to queue for presentation
         * @param waitSemaphore (Optional) Semaphore that is waited on before the image is presented (only used if != VK_NULL_HANDLE)
         *
         * @return VkResult of the queue presentation
         */
        public VkResult QueuePresent(VkQueue queue, uint imageIndex, VkSemaphore waitSemaphore = new VkSemaphore())
        {
            VkPresentInfoKHR presentInfo = VkPresentInfoKHR.New();

            presentInfo.pNext          = null;
            presentInfo.swapchainCount = 1;
            var sc = Swapchain;

            presentInfo.pSwapchains   = &sc;
            presentInfo.pImageIndices = &imageIndex;
            // Check if a wait semaphore has been specified to wait for before presenting the image
            if (waitSemaphore.Handle != 0)
            {
                presentInfo.pWaitSemaphores    = &waitSemaphore;
                presentInfo.waitSemaphoreCount = 1;
            }
            return(vkQueuePresentKHR(queue, &presentInfo));
        }
Пример #19
0
        public void Present(SwapChain swapChain, VkSemaphore wait)
        {
            VkPresentInfoKHR present = VkPresentInfoKHR.New();

            uint           idx = swapChain.currentImageIndex;
            VkSwapchainKHR sc  = swapChain.handle;

            present.swapchainCount     = 1;
            present.pSwapchains        = sc.Pin();
            present.waitSemaphoreCount = 1;
            present.pWaitSemaphores    = wait.Pin();
            present.pImageIndices      = idx.Pin();

            Utils.CheckResult(vkQueuePresentKHR(handle, ref present));

            sc.Unpin();
            wait.Unpin();
            idx.Unpin();
        }
Пример #20
0
        public void AcquireNextImage(VkDevice device, VkSemaphore semaphore, VkFence fence)
        {
            VkResult result = vkAcquireNextImageKHR(
                device,
                _swapchain,
                ulong.MaxValue,
                semaphore,
                fence,
                ref _currentImageIndex);

            if (result == VkResult.ErrorOutOfDateKHR || result == VkResult.SuboptimalKHR)
            {
                // RecreateSwapChain();
            }
            else if (result != VkResult.Success)
            {
                throw new VeldridException("Could not acquire next image from the Vulkan swapchain.");
            }
        }
Пример #21
0
        public void Present()
        {
            VkSemaphore    Semaphore   = NativeDevice.RenderFinishedSemaphore;
            VkSwapchainKHR swapchain   = SwapChain;
            CommandList    commandList = NativeDevice.NativeCommandList;

            VkPresentInfoKHR presentInfo = new VkPresentInfoKHR()
            {
                sType = VkStructureType.PresentInfoKHR,
                waitSemaphoreCount = 1,
                pWaitSemaphores    = &Semaphore,
                swapchainCount     = 1,
                pSwapchains        = &swapchain,
                pImageIndices      = Interop.AllocToPointer(ref commandList.imageIndex),
            };


            vkQueuePresentKHR(NativeDevice.NativeCommandQueue, &presentInfo);
        }
Пример #22
0
        private void InitRenderParams()
        {
            VkSwapchainKHR swapchain = this.swapchain;
            VkSemaphore    semaphore = this.vkSemaphore;

            VkCommandBuffer[] commandBuffers = this.commandBuffers;

            submitInfos  = VkSubmitInfo.Alloc(2);
            presentInfos = VkPresentInfoKHR.Alloc(2);
            for (uint index = 0; index < 2; index++)
            {
                //submitInfos[index].waitSemaphoresDstStageMasks.Set(semaphore);
                submitInfos[index].waitSemaphores = semaphore;
                submitInfos[index].waitSemaphoresDstStageMasks.Set(VkPipelineStageFlagBits.AllGraphics);
                submitInfos[index].commandBuffers = commandBuffers[index];

                presentInfos[index].swapchains = swapchain;
                //presentInfo->swapchainsImages.Set(swapchain);
                presentInfos[index].swapchainsImages.Set(index);
            }
        }
Пример #23
0
        public unsafe Semaphore(Device device)
        {
            _device = device;
            var createInfo = new VkSemaphoreCreateInfo
            {
                sType = VkStructureType.SemaphoreCreateInfo
            };

            VkSemaphore semaphore;

            if (VulkanNative.vkCreateSemaphore(
                    _device.Handle,
                    &createInfo,
                    null,
                    &semaphore
                    ) != VkResult.Success)
            {
                throw new Exception("failed to create semaphore");
            }
            _handle = semaphore;
        }
Пример #24
0
        public void Submit()
        {
            VkSemaphore          signalSemaphore = NativeDevice.RenderFinishedSemaphore;
            VkSemaphore          waitSemaphore   = NativeDevice.ImageAvailableSemaphore;
            VkPipelineStageFlags waitStages      = VkPipelineStageFlags.ColorAttachmentOutput;
            VkCommandBuffer      commandBuffer   = CommandBuffer;


            VkSubmitInfo submitInfo = new VkSubmitInfo()
            {
                sType = VkStructureType.SubmitInfo,
                waitSemaphoreCount   = 1,
                pWaitSemaphores      = &waitSemaphore,
                pWaitDstStageMask    = &waitStages,
                commandBufferCount   = 1,
                pCommandBuffers      = &commandBuffer,
                signalSemaphoreCount = 1,
                pSignalSemaphores    = &signalSemaphore,
            };

            vkQueueSubmit(NativeDevice.NativeCommandQueue, 1, &submitInfo, VkFence.Null);
        }
Пример #25
0
        public void InitializePlatformDevice()
        {
            // Features should be checked by the examples before using them
            CreateFeatures();



            // Memory properties are used regularly for creating all kinds of buffers
            CreateMemoryProperties();



            // Queue family properties, used for setting up requested queues upon device creation
            CreateQueueFamilyProperties();



            // Get list of supported extensions
            CreateExtensionProperties();



            // Desired queues need to be requested upon logical device creation
            // Due to differing queue family configurations of Vulkan implementations this can be a bit tricky, especially if the application
            // requests different queue types
            CreateDevice();



            // Create CommandQueues
            CreateCommandQueues();


            // Create Semaphores
            ImageAvailableSemaphore = CreateSemaphore();

            RenderFinishedSemaphore = CreateSemaphore();
        }
Пример #26
0
        public static VkResult vkQueuePresentKHR(VkQueue queue, VkSemaphore waitSemaphore, VkSwapchainKHR swapchain, uint imageIndex)
        {
            var presentInfo = new VkPresentInfoKHR
            {
                sType = VkStructureType.PresentInfoKHR,
                pNext = null
            };

            if (waitSemaphore != VkSemaphore.Null)
            {
                presentInfo.waitSemaphoreCount = 1u;
                presentInfo.pWaitSemaphores    = &waitSemaphore;
            }

            if (swapchain != VkSwapchainKHR.Null)
            {
                presentInfo.swapchainCount = 1u;
                presentInfo.pSwapchains    = &swapchain;
                presentInfo.pImageIndices  = &imageIndex;
            }

            return(vkQueuePresentKHR(queue, &presentInfo));
        }
Пример #27
0
        void draw()
        {
            prepareFrame();

            // Offscreen rendering

            // Wait for swap chain presentation to finish
            submitInfo[0].waitSemaphoresDstStageMasks.Set(((Semaphores *)semaphores.header)->PresentComplete);
            // Signal ready with offscreen semaphore
            var signalSemaphore = offscreenPass.semaphore;

            submitInfo[0].signalSemaphores = signalSemaphore;

            // Submit work
            var commandBuffer = offscreenPass.commandBuffer;

            submitInfo[0].commandBuffers = commandBuffer;
            vkQueueSubmit(queue, 1, submitInfo, new VkFence());

            // Scene rendering

            // Wait for offscreen semaphore
            VkSemaphore semaphore = offscreenPass.semaphore;

            submitInfo->waitSemaphoresDstStageMasks.Set(semaphore);
            // Signal ready with render complete semaphpre
            submitInfo->signalSemaphores = ((Semaphores *)semaphores.header)->RenderComplete;

            // Submit work
            VkCommandBuffer cmdBuffer = drawCmdBuffers[currentBuffer];

            submitInfo->commandBuffers = cmdBuffer;
            vkQueueSubmit(queue, 1, submitInfo, new VkFence());

            submitFrame();
        }
Пример #28
0
        public void Init(IntPtr hwnd, IntPtr processHandle)
        {
            if (this.isInitialized)
            {
                return;
            }

            this.instance = InitInstance();
            InitDebugCallback(this.instance);
            this.surface          = InitSurface(this.instance, hwnd, processHandle);
            this.vkPhysicalDevice = InitPhysicalDevice(this.instance);
            VkSurfaceFormatKHR surfaceFormat = SelectFormat(this.vkPhysicalDevice, this.surface);

            this.device = CreateDevice(this.vkPhysicalDevice, this.surface);

            this.vkQueue = this.device.GetQueue(0, 0);

            VkSurfaceCapabilitiesKHR surfaceCapabilities;

            //this.vkPhysicalDevice.GetSurfaceCapabilitiesKhr(this.vkSurface, out surfaceCapabilities);
            vkAPI.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(this.vkPhysicalDevice, this.surface, &surfaceCapabilities).Check();

            this.swapchain = CreateSwapchain(this.device, this.surface, surfaceFormat, surfaceCapabilities);

            this.vkImages = this.device.GetSwapchainImages(this.swapchain);

            this.renderPass = CreateRenderPass(this.device, surfaceFormat);

            this.framebuffers = CreateFramebuffers(this.device, this.vkImages, surfaceFormat, this.renderPass, surfaceCapabilities);

            this.vkFence     = this.device.CreateFence();
            this.vkSemaphore = this.device.CreateSemaphore();

            // buffers for vertex data.
            VkBuffer vertexBuffer = CreateBuffer(this.vkPhysicalDevice, this.device, Vertices, VkBufferUsageFlagBits.VertexBuffer, typeof(float));

            VkBuffer indexBuffer = CreateBuffer(this.vkPhysicalDevice, this.device, Indexes, VkBufferUsageFlagBits.IndexBuffer, typeof(short));

            var uniformBufferData = new AreaUniformBuffer(1, 1);

            this.originalWidth  = 1; this.width = this.originalWidth;
            this.originalHeight = 1; this.height = this.originalHeight;

            this.uniformBuffer = CreateBuffer(this.vkPhysicalDevice, this.device, uniformBufferData, VkBufferUsageFlagBits.UniformBuffer, typeof(AreaUniformBuffer));

            this.descriptorSetLayout = CreateDescriptorSetLayout(this.device);

            this.vkPipelineLayout = CreatePipelineLayout(this.device, this.descriptorSetLayout);

            VkPipeline pipeline = CreatePipeline(this.device, surfaceCapabilities, this.renderPass, this.vkPipelineLayout);

            this.descriptorSet = CreateDescriptorSet(this.device, this.descriptorSetLayout);

            UpdateDescriptorSets(this.device, this.uniformBuffer, this.descriptorSet);

            this.commandBuffers = CreateCommandBuffers(
                this.device, this.renderPass, surfaceCapabilities,
                this.vkImages, this.framebuffers, pipeline,
                vertexBuffer, indexBuffer, (uint)Indexes.Length,
                this.vkPipelineLayout, this.descriptorSet);

            this.isInitialized = true;
        }
Пример #29
0
 void CreateSemaphores()
 {
     imageAvailableSemaphore = new VkSemaphore(device);
     renderFinishedSemaphore = new VkSemaphore(device);
 }
Пример #30
0
        public static VkResult vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, long timeout, VkSemaphore semaphore, VkFence fence, out int pImageIndex)
        {
            VkPreconditions.CheckNull(device, nameof(device));
            VkPreconditions.CheckNull(swapchain, nameof(swapchain));
            VkPreconditions.CheckRange(timeout, 1, long.MaxValue, nameof(timeout));

            return(GetDevice(device).AcquireNextImage(swapchain, timeout, semaphore, fence, out pImageIndex));
        }