Skip to content

Commit

Permalink
[*] Try to fix MSAA
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmNotHanni committed Oct 26, 2023
1 parent 92de322 commit 342548b
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 86 deletions.
4 changes: 2 additions & 2 deletions include/inexor/vulkan-renderer/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Application {
std::vector<std::uint32_t> m_octree_indices;

std::unique_ptr<RenderGraph> m_render_graph;
TextureResource *m_back_buffer{nullptr};
TextureResource *m_msaa_color_buffer{nullptr};
TextureResource *m_depth_buffer{nullptr};
TextureResource *m_msaa_target{nullptr};
TextureResource *m_msaa_depth_buffer{nullptr};
BufferResource *m_index_buffer{nullptr};
BufferResource *m_vertex_buffer{nullptr};
BufferResource *m_uniform_buffer{nullptr};
Expand Down
29 changes: 9 additions & 20 deletions include/inexor/vulkan-renderer/render_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ enum class TextureUsage {
// TODO: Refactor back buffer system more (remove need for BACK_BUFFER texture usage)
BACK_BUFFER,

/// A render target for multi sampling anti aliasing (MSAA)
MSAA_RENDER_TARGET,
MSAA_BACK_BUFFER,

/// Specifies that this texture is a combined depth/stencil buffer
/// @note This may mean that this texture is completely GPU-sided and cannot be accessed by the CPU in any way.
DEPTH_STENCIL_BUFFER,

/// A render target for multi sampling anti aliasing (MSAA)
MSAA_DEPTH_STENCIL_BUFFER,

/// Specifies that this texture isn't used for any special purpose
NORMAL,
};
Expand Down Expand Up @@ -316,6 +318,7 @@ class GraphicsStage : public RenderStage {
.lineWidth = 1.0f,
}),
};
bool m_multisampling{false};
VkPipelineMultisampleStateCreateInfo m_multisample_sci{
wrapper::make_info<VkPipelineMultisampleStateCreateInfo>({
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
Expand Down Expand Up @@ -442,10 +445,13 @@ class GraphicsStage : public RenderStage {
[[nodiscard]] GraphicsStage *set_line_width(float width);

/// Set the most important MSAA settings
/// @warning This method will not check if the specified sample count is supported! Also, there is no check if
/// sample shading is enabled if it's specified. It is the responsibility of the programmer to check for this!
/// @param sample_count The number of samples used in rasterization
/// @param min_sample_shading A minimum fraction of sample shading
/// @return A reference to the dereferenced this pointer (allows method calls to be chained)
[[nodiscard]] GraphicsStage *set_multisampling(VkSampleCountFlagBits sample_count, float min_sample_shading);
[[nodiscard]] GraphicsStage *set_multisampling(VkSampleCountFlagBits sample_count,
std::optional<float> min_sample_shading);

/// Store the pipeline layout
/// @param layout The pipeline layout
Expand Down Expand Up @@ -595,23 +601,6 @@ class PhysicalImage : public PhysicalResource {
}
};

class PhysicalBackBuffer : public PhysicalResource {
friend RenderGraph;

private:
const wrapper::Swapchain &m_swapchain;

public:
PhysicalBackBuffer(const wrapper::Device &device, const wrapper::Swapchain &swapchain)
: PhysicalResource(device), m_swapchain(swapchain) {}
PhysicalBackBuffer(const PhysicalBackBuffer &) = delete;
PhysicalBackBuffer(PhysicalBackBuffer &&) = delete;
~PhysicalBackBuffer() override = default;

PhysicalBackBuffer &operator=(const PhysicalBackBuffer &) = delete;
PhysicalBackBuffer &operator=(PhysicalBackBuffer &&) = delete;
};

class PhysicalStage : public PhysicalResource {
friend RenderGraph;

Expand Down
16 changes: 16 additions & 0 deletions include/inexor/vulkan-renderer/wrapper/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ class Image {
Image(const Device &device, VkFormat format, std::uint32_t width, std::uint32_t height, VkImageUsageFlags usage,
VkImageAspectFlags aspect_flags, VkImageLayout initial_layout, const std::string &name);

/// Constructor 7 (calls constructor 3 internally)
/// @param device The device wrapper
/// @param format The image format
/// @param width The image width
/// @param height The image height
/// @param usage The image usage
/// @param aspect_flags The image aspect flags
/// @param initial_layout The initial layout of the image
/// @param name The internal debug name of the image and the image view (must not be empty)
/// @exception std::invalid_argument The internal debug name is empty
/// @exception VulkanException vmaCreateImage call failed
/// @exception VulkanException vkCreateImageView call failed
Image(const Device &device, VkFormat format, std::uint32_t width, std::uint32_t height, VkImageUsageFlags usage,
VkImageAspectFlags aspect_flags, VkImageLayout initial_layout, VkSampleCountFlagBits sample_flags,
const std::string &name);

Image(const Image &) = delete;
Image(Image &&) noexcept;
~Image();
Expand Down
19 changes: 11 additions & 8 deletions src/vulkan-renderer/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debug_messenger_callback(VkDebugUtilsMessageSever
}
if (severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
spdlog::critical("{}", data->pMessage);
abort();
}

// TODO: Print data of VkDebugUtilsMessengerCallbackDataEXT
Expand Down Expand Up @@ -304,6 +305,7 @@ Application::Application(int argc, char **argv) {

const VkPhysicalDeviceFeatures required_features{
// Add required physical device features here
.sampleRateShading = VK_TRUE,
};

const VkPhysicalDeviceFeatures optional_features{
Expand Down Expand Up @@ -393,10 +395,10 @@ void Application::recreate_swapchain() {
m_camera->set_rotation_speed(0.5f);

m_imgui_overlay.reset();
m_imgui_overlay = std::make_unique<ImGUIOverlay>(*m_device, m_render_graph.get(), m_back_buffer,
m_imgui_overlay = std::make_unique<ImGUIOverlay>(*m_device, m_render_graph.get(), m_msaa_color_buffer,
[&]() { update_imgui_overlay(); });

m_render_graph->compile(m_back_buffer);
m_render_graph->compile(m_msaa_color_buffer);
}

void Application::render_frame() {
Expand Down Expand Up @@ -430,15 +432,15 @@ void Application::render_frame() {
}

void Application::setup_render_graph() {
m_back_buffer =
m_render_graph->add<TextureResource>(TextureUsage::BACK_BUFFER, m_swapchain->image_format(), "Back Buffer");

m_msaa_target = m_render_graph->add<TextureResource>(TextureUsage::MSAA_RENDER_TARGET, m_swapchain->image_format(),
"MSAA Target");
m_msaa_color_buffer = m_render_graph->add<TextureResource>(TextureUsage::MSAA_BACK_BUFFER,
m_swapchain->image_format(), "MSAA Back Buffer");

m_depth_buffer = m_render_graph->add<TextureResource>(TextureUsage::DEPTH_STENCIL_BUFFER,
VK_FORMAT_D32_SFLOAT_S8_UINT, "Depth Buffer");

m_msaa_depth_buffer = m_render_graph->add<TextureResource>(TextureUsage::MSAA_DEPTH_STENCIL_BUFFER,
VK_FORMAT_D32_SFLOAT_S8_UINT, "MSAA Depth Buffer");

m_vertex_buffer = m_render_graph->add<BufferResource>("Octree", BufferUsage::VERTEX_BUFFER, [&]() {
if (m_input_data->was_key_pressed_once(GLFW_KEY_N)) {
load_octree_geometry(false);
Expand Down Expand Up @@ -490,8 +492,9 @@ void Application::setup_render_graph() {
},
})
->set_vertex_input_binding_descriptions<OctreeGpuVertex>()
->writes_to(m_back_buffer)
->writes_to(m_depth_buffer)
->writes_to(m_msaa_depth_buffer)
->writes_to(m_msaa_color_buffer)
->reads_from(m_index_buffer)
->reads_from(m_vertex_buffer)
->reads_from(m_uniform_buffer, VK_SHADER_STAGE_VERTEX_BIT)
Expand Down
Loading

0 comments on commit 342548b

Please sign in to comment.