Exemplo n.º 1
0
        public unsafe DepthImage(uint width, uint height, PhysicalDevice physicalDevice, Device device)
        {
            _width          = width;
            _height         = height;
            _vk             = VkUtil.Vk;
            _physicalDevice = physicalDevice;
            _device         = device;

            Format = FindFormat(FormatFeatureFlags.FormatFeatureDepthStencilAttachmentBit, Format.D32SfloatS8Uint, Format.D24UnormS8Uint);

            ImageCreateInfo imageCreateInfo = VkInit.ImageCreateInfo(ImageType.ImageType2D, Format, _width, _height);

            VkUtil.AssertVulkan(_vk.CreateImage(_device, imageCreateInfo, null, out _image));

            _vk.GetImageMemoryRequirements(_device, _image, out MemoryRequirements memReqs);
            _vk.GetPhysicalDeviceMemoryProperties(_physicalDevice, out PhysicalDeviceMemoryProperties memoryProperties);
            uint index = VkUtil.FindMemoryTypeIndex(memReqs.MemoryTypeBits, MemoryPropertyFlags.MemoryPropertyDeviceLocalBit, memoryProperties);

            MemoryAllocateInfo memoryAllocateInfo = VkInit.MemoryAllocateInfo(memReqs.Size, index);

            VkUtil.AssertVulkan(_vk.AllocateMemory(_device, memoryAllocateInfo, null, out _memory));
            VkUtil.AssertVulkan(_vk.BindImageMemory(_device, _image, _memory, 0));

            ImageViewCreateInfo imageViewCreateInfo = VkInit.ImageViewCreateInfo(Format, _image, ImageAspectFlags.ImageAspectDepthBit);

            VkUtil.AssertVulkan(_vk.CreateImageView(_device, imageViewCreateInfo, null, out _imageView));
        }
Exemplo n.º 2
0
        public void CreateCommandBuffers()
        {
            CommandBufferAllocateInfo commandBufferAllocateInfo = VkInit.CommandBufferAllocateInfo(_commandPool, COMMAND_BUFFER_RESET_THRESHOLD);

            for (int i = 0; i < COMMAND_BUFFER_RESET_THRESHOLD; i++)
            {
                VkUtil.AssertVulkan(_vk.AllocateCommandBuffers(_device, commandBufferAllocateInfo, out _commandBuffers[0]));
            }
        }
Exemplo n.º 3
0
        public unsafe Frame(uint graphicsQueueFamily, Device device, Vk vk)
        {
            _device = device;
            _vk     = vk;

            FenceCreateInfo     fenceCreateInfo     = VkInit.FenceCreateInfo(true);
            SemaphoreCreateInfo semaphoreCreateInfo = VkInit.SemaphoreCreateInfo();

            VkUtil.AssertVulkan(vk.CreateFence(_device, fenceCreateInfo, null, out Fence renderFence));
            VkUtil.AssertVulkan(vk.CreateSemaphore(_device, semaphoreCreateInfo, null, out Semaphore renderSemaphore));
            VkUtil.AssertVulkan(vk.CreateSemaphore(_device, semaphoreCreateInfo, null, out Semaphore presentSemaphore));
            RenderSemaphore  = renderSemaphore;
            PresentSemaphore = presentSemaphore;
            RenderFence      = renderFence;

            CommandPoolCreateInfo commandPoolCreateInfo = VkInit.CommandPoolCreateInfo(graphicsQueueFamily, 0);

            VkUtil.AssertVulkan(_vk.CreateCommandPool(_device, commandPoolCreateInfo, null, out _commandPool));

            CreateCommandBuffers();

            _commandBufferIndex = 0;
        }
Exemplo n.º 4
0
        public static unsafe Instance CreateInstance(string[] instanceLayers, string[] instanceExtensions, IVkSurface windowSurface)
        {
            ApplicationInfo appInfo = new()
            {
                SType = StructureType.ApplicationInfo,

                PApplicationName   = (byte *)SilkMarshal.StringToPtr("SilkyNvg-Vulkan-Example"),
                ApplicationVersion = Vk.MakeVersion(1, 0, 0),
                PEngineName        = (byte *)SilkMarshal.StringToPtr("SilkyNvg (Renderer: Vulkan)"),
                EngineVersion      = Vk.MakeVersion(1, 0, 0),
                ApiVersion         = Vk.Version12
            };

            byte **windowExtensionsPtr   = windowSurface.GetRequiredExtensions(out uint windowExtensionCount);
            byte **instanceExtensionsPtr = (byte **)SilkMarshal.StringArrayToPtr(instanceExtensions);
            byte **extensions            = stackalloc byte *[(int)windowExtensionCount + instanceExtensions.Length];
            int    i = 0;

            for (; i < windowExtensionCount; i++)
            {
                extensions[i] = windowExtensionsPtr[i];
            }
            for (; i < windowExtensionCount + instanceExtensions.Length; i++)
            {
                extensions[i] = instanceExtensionsPtr[i];
            }
            CheckInstanceExtensionsPresent(extensions, (int)windowExtensionCount + instanceExtensions.Length);

            CheckInstanceLayersPresent(instanceLayers);
            byte **layers = (byte **)SilkMarshal.StringArrayToPtr(instanceLayers);

            InstanceCreateInfo instanceCreateInfo = VkInit.InstanceCreateInfo(appInfo, layers,
                                                                              (uint)instanceLayers.Length, extensions, windowExtensionCount);

            AssertVulkan(Vk.CreateInstance(instanceCreateInfo, null, out Instance instance));
            return(instance);
        }