Beispiel #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));
        }
Beispiel #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]));
            }
        }
Beispiel #3
0
 public CommandBuffer GetCommandBuffer()
 {
     if (_commandBufferIndex >= COMMAND_BUFFER_RESET_THRESHOLD)
     {
         VkUtil.AssertVulkan(_vk.ResetCommandPool(_device, _commandPool, 0));
         _commandBufferIndex = 0;
     }
     return(_commandBuffers[_commandBufferIndex++]);
 }
Beispiel #4
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;
        }