Exemple #1
0
        public static VkDescriptorSet AllocateDescriptorSets(ref VkDescriptorSetAllocateInfo pAllocateInfo)
        {
            VkDescriptorSet pDescriptorSets;

            VulkanUtil.CheckResult(vkAllocateDescriptorSets(device, Utilities.AsPtr(ref pAllocateInfo), &pDescriptorSets));
            return(pDescriptorSets);
        }
Exemple #2
0
        public static VkDeviceMemory AllocateMemory(ref VkMemoryAllocateInfo pAllocateInfo)
        {
            VkDeviceMemory pMemory;

            VulkanUtil.CheckResult(vkAllocateMemory(device, Utilities.AsPtr(ref pAllocateInfo), null, &pMemory));
            return(pMemory);
        }
Exemple #3
0
        public void Submit(VkSemaphore waitSemaphore, VkPipelineStageFlags waitDstStageMask,
                           VkCommandBuffer commandBuffer, VkSemaphore signalSemaphore, VkFence fence = default)
        {
            VkCommandBuffer commandBufferHandle = commandBuffer;

            var nativeSubmit = new VkSubmitInfo
            {
                sType = VkStructureType.SubmitInfo
            };

            if (waitSemaphore != default)
            {
                nativeSubmit.waitSemaphoreCount = 1;
                nativeSubmit.pWaitSemaphores    = &waitSemaphore;
                nativeSubmit.pWaitDstStageMask  = &waitDstStageMask;
            }

            if (commandBuffer != null)
            {
                nativeSubmit.commandBufferCount = 1;
                nativeSubmit.pCommandBuffers    = &commandBufferHandle;
            }

            if (signalSemaphore != default)
            {
                nativeSubmit.signalSemaphoreCount = 1;
                nativeSubmit.pSignalSemaphores    = &signalSemaphore;
            }

            VulkanUtil.CheckResult(vkQueueSubmit(this, 1, &nativeSubmit, fence));
        }
Exemple #4
0
        public static VkPipeline CreateComputePipeline(ref VkComputePipelineCreateInfo pCreateInfos)
        {
            VkPipeline pPipelines;

            VulkanUtil.CheckResult(vkCreateComputePipelines(device, pipelineCache, 1, Utilities.AsPtr(ref pCreateInfos), null, &pPipelines));
            return(pPipelines);
        }
Exemple #5
0
        public void Begin(VkCommandBufferUsageFlags flags = VkCommandBufferUsageFlags.None)
        {
            var cmdBufInfo = new VkCommandBufferBeginInfo();

            cmdBufInfo.sType = VkStructureType.CommandBufferBeginInfo;
            cmdBufInfo.flags = flags;
            VulkanUtil.CheckResult(vkBeginCommandBuffer(commandBuffer, &cmdBufInfo));
            opened = true;
            ClearDescriptorSets();
        }
Exemple #6
0
        public static void AllocateCommandBuffers(VkCommandPool cmdPool, VkCommandBufferLevel level, uint count, VkCommandBuffer *cmdBuffers)
        {
            VkCommandBufferAllocateInfo cmdBufAllocateInfo = new VkCommandBufferAllocateInfo
            {
                sType = VkStructureType.CommandBufferAllocateInfo
            };

            cmdBufAllocateInfo.commandPool        = cmdPool;
            cmdBufAllocateInfo.level              = level;
            cmdBufAllocateInfo.commandBufferCount = count;

            VulkanUtil.CheckResult(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, cmdBuffers));
        }
Exemple #7
0
 public void Begin(VkCommandBufferUsageFlags flags, ref CommandBufferInheritanceInfo commandBufferInheritanceInfo)
 {
     unsafe
     {
         var cmdBufBeginInfo = new VkCommandBufferBeginInfo
         {
             sType            = VkStructureType.CommandBufferBeginInfo,
             flags            = flags,
             pInheritanceInfo = (VkCommandBufferInheritanceInfo *)Unsafe.AsPointer(ref commandBufferInheritanceInfo.native)
         };
         VulkanUtil.CheckResult(vkBeginCommandBuffer(commandBuffer, &cmdBufBeginInfo));
     }
     opened = true;
     ClearDescriptorSets();
 }
Exemple #8
0
        public unsafe void QueuePresent(VkQueue queue, uint imageIndex, VkSemaphore waitSemaphore = default)
        {
            var sc          = swapchain;
            var presentInfo = new VkPresentInfoKHR
            {
                sType          = VkStructureType.PresentInfoKHR,
                pNext          = null,
                swapchainCount = 1,
                pSwapchains    = &sc,
                pImageIndices  = &imageIndex
            };

            // Check if a wait semaphore has been specified to wait for before presenting the image
            if (waitSemaphore != VkSampler.Null)
            {
                presentInfo.pWaitSemaphores    = (VkSemaphore *)Unsafe.AsPointer(ref waitSemaphore);
                presentInfo.waitSemaphoreCount = 1;
            }

            VulkanUtil.CheckResult(vkQueuePresentKHR(queue, &presentInfo));
        }
Exemple #9
0
        public void BindSparse(VkBindSparseInfo[] bindInfo, VkFence fence = default)
        {
            int count = bindInfo?.Length ?? 0;

            VulkanUtil.CheckResult(vkQueueBindSparse(this, (uint)count, bindInfo != null ? (VkBindSparseInfo *)Unsafe.AsPointer(ref bindInfo[0]) : null, fence));
        }
Exemple #10
0
 public void WaitIdle()
 {
     VulkanUtil.CheckResult(vkQueueWaitIdle(this));
 }
Exemple #11
0
 public void BindSparse(VkBindSparseInfo bindInfo, VkFence fence = default)
 {
     VulkanUtil.CheckResult(vkQueueBindSparse(this, 1, &bindInfo, fence));
 }
Exemple #12
0
 public void Submit(VkSubmitInfo submit, VkFence fence = default)
 {
     VulkanUtil.CheckResult(vkQueueSubmit(this, 1, &submit, fence));
 }
Exemple #13
0
 public static void WaitIdle()
 {
     VulkanUtil.CheckResult(vkDeviceWaitIdle(device));
 }
Exemple #14
0
 public static void FreeDescriptorSets(VkDescriptorPool descriptorPool, uint descriptorSetCount, ref VkDescriptorSet pDescriptorSets)
 {
     VulkanUtil.CheckResult(vkFreeDescriptorSets(device, descriptorPool, descriptorSetCount, Utilities.AsPtr(ref pDescriptorSets)));
 }
Exemple #15
0
        public void Submit(VkSubmitInfo[] submits, VkFence fence = default)
        {
            int count = submits?.Length ?? 0;

            VulkanUtil.CheckResult(vkQueueSubmit(this, (uint)count, submits != null ? (VkSubmitInfo *)Unsafe.AsPointer(ref submits[0]) : null, fence));
        }
Exemple #16
0
 public static void GetSwapchainImagesKHR(VkSwapchainKHR swapchain, uint *pSwapchainImageCount, VkImage *pSwapchainImages)
 {
     VulkanUtil.CheckResult(vkGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages));
 }
Exemple #17
0
 public static void AllocateDescriptorSets(ref VkDescriptorSetAllocateInfo pAllocateInfo, VkDescriptorSet *pDescriptorSets)
 {
     VulkanUtil.CheckResult(vkAllocateDescriptorSets(device, Utilities.AsPtr(ref pAllocateInfo), pDescriptorSets));
 }
Exemple #18
0
 public static void InvalidateMappedMemoryRanges(uint memoryRangeCount, ref VkMappedMemoryRange pMemoryRanges)
 {
     VulkanUtil.CheckResult(vkInvalidateMappedMemoryRanges(device, memoryRangeCount, Utilities.AsPtr(ref pMemoryRanges)));
 }
Exemple #19
0
 public void End()
 {
     VulkanUtil.CheckResult(vkEndCommandBuffer(commandBuffer));
     opened = false;
 }
Exemple #20
0
        public static VkDevice Create(Settings settings, VkPhysicalDeviceFeatures enabledFeatures, CStringList enabledExtensions,
                                      VkQueueFlags requestedQueueTypes = VkQueueFlags.Graphics | VkQueueFlags.Compute | VkQueueFlags.Transfer)
        {
            instanceExtensions.Add(Vulkan.KHRSurfaceExtensionName);
            instanceExtensions.Add(Vulkan.KHRGetPhysicalDeviceProperties2ExtensionName);

            enabledExtensions.Add(Vulkan.KHRMaintenance1ExtensionName);
            enabledExtensions.Add(Vulkan.EXTInlineUniformBlockExtensionName);

            //enabledExtensions.Add(Strings.VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT);

            CreateInstance(settings);

            // Physical Device
            var physicalDevices = Vulkan.vkEnumeratePhysicalDevices(VkInstance);

            // TODO: Implement arg parsing, etc.
            int selectedDevice = 0;

            PhysicalDevice = physicalDevices[selectedDevice];
            Debug.Assert(PhysicalDevice.Handle != IntPtr.Zero);

            vkGetPhysicalDeviceProperties(PhysicalDevice, out VkPhysicalDeviceProperties properties);
            Properties = properties;

            vkGetPhysicalDeviceFeatures(PhysicalDevice, out VkPhysicalDeviceFeatures features);
            Features = features;

            if (features.tessellationShader)
            {
                enabledFeatures.tessellationShader = true;
            }

            if (features.multiDrawIndirect)
            {
                enabledFeatures.multiDrawIndirect = true;
            }
            // Enable anisotropic filtering if supported
            if (features.samplerAnisotropy)
            {
                enabledFeatures.samplerAnisotropy = true;
            }
            // Enable texture compression
            if (features.textureCompressionBC)
            {
                enabledFeatures.textureCompressionBC = true;
            }
            else if (features.textureCompressionASTC_LDR)
            {
                enabledFeatures.textureCompressionASTC_LDR = true;
            }
            else if (features.textureCompressionETC2)
            {
                enabledFeatures.textureCompressionETC2 = true;
            }

            if (features.sparseBinding && features.sparseResidencyImage2D)
            {
                enabledFeatures.shaderResourceResidency = true;
                enabledFeatures.shaderResourceMinLod    = true;
                enabledFeatures.sparseBinding           = true;
                enabledFeatures.sparseResidencyImage2D  = true;
            }
            else
            {
                Log.Warn("Sparse binding not supported");
            }

            // Memory properties are used regularly for creating all kinds of buffers
            VkPhysicalDeviceMemoryProperties memoryProperties;

            vkGetPhysicalDeviceMemoryProperties(PhysicalDevice, out memoryProperties);
            MemoryProperties = memoryProperties;

            var qf = Vulkan.vkGetPhysicalDeviceQueueFamilyProperties(PhysicalDevice);

            QueueFamilyProperties.Add(qf);

            var extensions = Vulkan.vkEnumerateDeviceExtensionProperties(PhysicalDevice);

            foreach (var ext in extensions)
            {
                string strExt = UTF8String.FromPointer(ext.extensionName);
                //enabledExtensions.Add((IntPtr)ext.extensionName);
                supportedExtensions.Add(strExt);
            }

            device = CreateLogicalDevice(Features, enabledExtensions, true, requestedQueueTypes);

            if (device != VkDevice.Null)
            {
                VkPipelineCacheCreateInfo pipelineCacheCreateInfo = new VkPipelineCacheCreateInfo()
                {
                    sType = VkStructureType.PipelineCacheCreateInfo
                };

                VulkanUtil.CheckResult(vkCreatePipelineCache(device, &pipelineCacheCreateInfo, null, out pipelineCache));
            }

            return(device);
        }
Exemple #21
0
 public static void BindImageMemory(VkImage image, VkDeviceMemory memory, ulong offset)
 {
     VulkanUtil.CheckResult(vkBindImageMemory(device, image, memory, offset));
 }
Exemple #22
0
 public static void BindBufferMemory(VkBuffer buffer, VkDeviceMemory memory, ulong memoryOffset)
 {
     VulkanUtil.CheckResult(vkBindBufferMemory(device, buffer, memory, memoryOffset));
 }