Implement mulitsampling

This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent 3c73e6bac3
commit 2d230d7280
4 files changed
+73 -20

No files matched your search

+43 -8
View File
@@ -1,6 +1,7 @@
#include "rse_vulkan_image.h"
#include <stdint.h>
#include "src/vulkan_pipeline.h"
#include "utilities/file_utils.h"
#include "utilities/logger.h"
#include "utilities/rse_commons.h"
@@ -43,6 +44,7 @@ extern struct rse_vulkan_state_t g_vulkan_state;
struct rse_vulkan_image_t g_texture_images[RSE_MAX_IMAGE_COUNT];
struct rse_vulkan_image_t g_depth_image;
struct rse_vulkan_image_t g_color_image;
VkSampler g_sampler;
@@ -105,7 +107,13 @@ static rse_err_t find_supported_format(const VkFormat* candidates,
return VULKAN_ERROR_FORMAT_NOT_FOUND;
}
static rse_err_t create_image(struct rse_vulkan_image_t* image, uint32_t width, uint32_t height, VkFormat format, VkImageUsageFlags usage, VmaAllocationCreateFlags allocationFlags)
static rse_err_t create_image(struct rse_vulkan_image_t* image,
uint32_t width,
uint32_t height,
VkFormat format,
VkSampleCountFlagBits maa_samples,
VkImageUsageFlags usage,
VmaAllocationCreateFlags allocationFlags)
{
VkExtent3D image_extent = {0};
VkImageCreateInfo image_info = {0};
@@ -123,7 +131,7 @@ static rse_err_t create_image(struct rse_vulkan_image_t* image, uint32_t width,
image_info.extent = image_extent;
image_info.mipLevels = 1U;
image_info.arrayLayers = 1U;
image_info.samples = VK_SAMPLE_COUNT_1_BIT; //TODO: Enable multisampling
image_info.samples = maa_samples;
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_info.usage = usage;
image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; //TODO: Change if used by more than one queue family
@@ -183,10 +191,26 @@ static rse_err_t create_image_view(struct rse_vulkan_image_t* image, VkFormat fo
return RSE_ERROR_NO_ERROR;
}
// static rse_err_t create_color_resource()
// {
// return RSE_ERROR_NO_ERROR;
// }
static rse_err_t create_color_resource()
{
rse_err_t status = RSE_ERROR_NO_ERROR;
VkFormat color_format = IMAGE_FORMAT;
VkSurfaceCapabilitiesKHR physical_device_surface_capabilities;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_vulkan_state.physical_device,
g_vulkan_state.surface,
&physical_device_surface_capabilities);
STATUS_CHECK(create_image(&g_color_image,
physical_device_surface_capabilities.currentExtent.width,
physical_device_surface_capabilities.currentExtent.height,
color_format,
VK_SAMPLE_COUNT_16_BIT,
VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0U));
STATUS_CHECK(create_image_view(&g_color_image, color_format, VK_IMAGE_ASPECT_COLOR_BIT));
return status;
}
static rse_err_t create_depth_resources()
@@ -203,8 +227,11 @@ static rse_err_t create_depth_resources()
STATUS_CHECK(create_image(&g_depth_image,
physical_device_surface_capabilities.currentExtent.width,
physical_device_surface_capabilities.currentExtent.height,
depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0U));
physical_device_surface_capabilities.currentExtent.height,
depth_format,
VK_SAMPLE_COUNT_16_BIT,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
0U));
STATUS_CHECK(create_image_view(&g_depth_image, depth_format, VK_IMAGE_ASPECT_DEPTH_BIT));
return status;
@@ -273,6 +300,7 @@ static rse_err_t create_textured_image(uint32_t width,
width,
height,
format,
VK_SAMPLE_COUNT_1_BIT,
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT));
@@ -370,6 +398,7 @@ rse_err_t init_vulkan_images()
STATUS_CHECK(create_sampler());
STATUS_CHECK(create_depth_resources());
STATUS_CHECK(create_color_resource());
return status;
}
@@ -415,7 +444,9 @@ void rse_destroy_textures()
}
vkDestroyImageView(g_vulkan_state.device, g_depth_image.image_view, NULL);
vkDestroyImageView(g_vulkan_state.device, g_color_image.image_view, NULL);
vmaDestroyImage(g_vulkan_state.allocator, g_depth_image.image, g_depth_image.allocation);
vmaDestroyImage(g_vulkan_state.allocator, g_color_image.image, g_color_image.allocation);
}
uint8_t image_exists(uint8_t image_id) {
@@ -432,6 +463,10 @@ VkImageView rse_get_depth_image_view()
return g_depth_image.image_view;
}
VkImageView rse_get_color_image_view()
{
return g_color_image.image_view;
}
VkSampler rse_get_texture_sampler()
{