Skip to content

Commit

Permalink
Dynamic state3 multisample rasterization (#856)
Browse files Browse the repository at this point in the history
* Add initial test framework.

Signed-off-by: Pawel Jastrzebski <[email protected]>

* Add MSAAm sample code.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Add sample with SpaceModule scene.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Rendering proper BaseModule scene.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix copyrights.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* First version of MSAA works.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Implement dynamic sample selection.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Add setter for last_requested_extension_feature.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix clang-format.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix copyright.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix vulkan version.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Update readme.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Remove unneeded code from shader.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix copyright.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Add README.md

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Add sample to CMake.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Remove explicit reference from local viewport initializer.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Change resources create/update logic.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix clang-format.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix format for vertex input attribute descriptor.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Separate rendering for scene meshes with different rasterizer settings.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Change camera position.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix light position.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Update README files.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Update sample image.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix warnings.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix typos in README files.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix comment.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix review comments.

Changes made:
* Remove explicit reset of command pool and command buffer
* Change extension request mechanism
* Remove markdown version of README

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix review comments.

Changes made:
- Fix errors in README
- Remove mandatory setting for Vulkan 1.1
- Add additional checks and asserts
- Replace loop with algorithms
- Remove unnecessary code and conditions
- Reorganise rendering of opaque and transparent meshes
- Change filename and class name of the sample

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix review comments.

Changes made:
- Fix misleading description in README
- Change textures handling in rendering

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Rename project.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix review comments.

Issues solved:
- remove unneeded code
- fix vulkan validation errors

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Add multisampling to GUI rendering.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Update README

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Change rotation speed.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix clang-format.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Update copyright year.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Copyright fix in CMakeLists

* Fix review comments.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix review comments.

Signed-off-by: pawel-jastrzebski-mobica <[email protected]>

* Fix VUID-VkSubpassDescription-pResolveAttachments-00848

* Image destroy refactor

* Fix windows build issue

* Add dynamic rendering

* Gui merge conflicts fix

* Fix regressions after implementing dynamic rendering

* Adjust sample to changes from PR#910

* Fix sync issue

* Documentation update

* Remove unused feature

* VK objects initializations added

* Fixing framework calls after merge

* Documentation and code small fixes

---------

Signed-off-by: Pawel Jastrzebski <[email protected]>
Signed-off-by: pawel-jastrzebski-mobica <[email protected]>
Co-authored-by: Mateusz Kowalewski <[email protected]>
  • Loading branch information
1 parent 6137284 commit 04f6080
Show file tree
Hide file tree
Showing 14 changed files with 1,318 additions and 6 deletions.
1 change: 1 addition & 0 deletions antora/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
** xref:samples/extensions/synchronization_2/README.adoc[Synchronization 2]
** xref:samples/extensions/timeline_semaphore/README.adoc[Timeline semaphore]
** xref:samples/extensions/vertex_dynamic_state/README.adoc[Vertex dynamic state]
** xref:samples/extensions/dynamic_multisample_rasterization/README.adoc[Dynamic multisample rasterization]
* xref:samples/performance/README.adoc[Performance samples]
** xref:samples/performance/16bit_arithmetic/README.adoc[16bit arithmetic]
** xref:samples/performance/16bit_storage_input_output/README.adoc[16bit storage input output]
Expand Down
8 changes: 4 additions & 4 deletions framework/api_vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,11 @@ class ApiVulkanSample : public vkb::VulkanSampleC
std::string title = "Vulkan Example";
std::string name = "vulkanExample";

struct
struct ImageData
{
VkImage image;
VkDeviceMemory mem;
VkImageView view;
VkImage image{VK_NULL_HANDLE};
VkDeviceMemory mem{VK_NULL_HANDLE};
VkImageView view{VK_NULL_HANDLE};
} depth_stencil;

struct
Expand Down
2 changes: 2 additions & 0 deletions framework/camera_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ void Camera::set_perspective(float fov, float aspect, float znear, float zfar)
this->znear = znear;
this->zfar = zfar;
matrices.perspective = glm::perspective(glm::radians(fov), aspect, znear, zfar);
updated = true;
}

void Camera::update_aspect_ratio(float aspect)
{
matrices.perspective = glm::perspective(glm::radians(fov), aspect, znear, zfar);
updated = true;
}

void Camera::set_position(const glm::vec3 &position)
Expand Down
19 changes: 17 additions & 2 deletions framework/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ void Gui::draw(CommandBuffer &command_buffer)
}

void Gui::draw(VkCommandBuffer command_buffer)
{
draw(command_buffer, pipeline, pipeline_layout->get_handle(), descriptor_set);
}

void Gui::draw(VkCommandBuffer command_buffer, const VkPipeline pipeline, const VkPipelineLayout pipeline_layout, const VkDescriptorSet descriptor_set)
{
if (!visible)
{
Expand All @@ -689,13 +694,13 @@ void Gui::draw(VkCommandBuffer command_buffer)
}

vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout->get_handle(), 0, 1, &descriptor_set, 0, NULL);
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptor_set, 0, NULL);

// Push constants
auto push_transform = glm::mat4(1.0f);
push_transform = glm::translate(push_transform, glm::vec3(-1.0f, -1.0f, 0.0f));
push_transform = glm::scale(push_transform, glm::vec3(2.0f / io.DisplaySize.x, 2.0f / io.DisplaySize.y, 0.0f));
vkCmdPushConstants(command_buffer, pipeline_layout->get_handle(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), &push_transform);
vkCmdPushConstants(command_buffer, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), &push_transform);

VkDeviceSize vertex_offsets[1] = {0};
VkBuffer vertex_buffer_handle = vertex_buffer->get_handle();
Expand Down Expand Up @@ -754,6 +759,16 @@ Drawer &Gui::get_drawer()
return drawer;
}

VkSampler Gui::get_sampler() const
{
return sampler->get_handle();
}

VkImageView Gui::get_font_image_view() const
{
return font_image_view->get_handle();
}

Font &Gui::get_font(const std::string &font_name)
{
assert(!fonts.empty() && "No fonts exist");
Expand Down
13 changes: 13 additions & 0 deletions framework/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ class Gui
*/
void draw(VkCommandBuffer command_buffer);

/**
* @brief Draws the Gui using an external pipeline
* @param command_buffer Command buffer to register draw-commands
* @param pipeline Pipeline to bind to perform draw-commands
* @param pipeline_layout PipelineLayout for given pieline
* @param descriptor_set DescriptorSet to bind to perform draw-commands
*/
void draw(VkCommandBuffer command_buffer, const VkPipeline pipeline, const VkPipelineLayout pipeline_layout, const VkDescriptorSet descriptor_set);

/**
* @brief Shows an overlay top window with app info and maybe stats
* @param app_name Application name
Expand Down Expand Up @@ -248,6 +257,10 @@ class Gui

void set_subpass(const uint32_t subpass);

VkSampler get_sampler() const;

VkImageView get_font_image_view() const;

private:
/**
* @brief Block size of a buffer pool in kilobytes
Expand Down
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ set(ORDER_LIST
"fragment_shader_barycentric"
"gshader_to_mshader"
"color_write_enable"
"dynamic_multisample_rasterization"
"sparse_image"
"dynamic_primitive_clipping"

Expand Down
5 changes: 5 additions & 0 deletions samples/extensions/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,8 @@ Rendering using primitive clipping and depth clipping configured by dynamic pipe

Demonstrate the use of the host image extension to directly copy from a host buffer to an image on the device without going through a staging buffer.

=== xref:./{extension_samplespath}dynamic_multisample_rasterization/README.adoc[Dynamic multisample rasterization]

*Extensions:* https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_extended_dynamic_state3.html[`VK_EXT_line_rasterization`], https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_extended_dynamic_state3.html[`VK_EXT_extended_dynamic_state3`]

Demonstrate how to use dynamic multisample rasterization (MSAA)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2024, Mobica Limited
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 the "License";
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME)

add_sample(
ID ${FOLDER_NAME}
CATEGORY ${CATEGORY_NAME}
AUTHOR "Mobica"
NAME "Dynamic Multisample Rasterization"
DESCRIPTION "Demonstrate how to use dynamic multisample rasterization (MSAA) from VK_EXT_extended_dynamic_state3 extension"
SHADER_FILES_GLSL
"dynamic_multisample_rasterization/model.vert"
"dynamic_multisample_rasterization/model.frag")
44 changes: 44 additions & 0 deletions samples/extensions/dynamic_multisample_rasterization/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
////
- Copyright (c) 2024, Mobica Limited
-
- SPDX-License-Identifier: Apache-2.0
-
- Licensed under the Apache License, Version 2.0 the "License";
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
////
// Extended dynamic_state3: Rasterization samples


== Overview

This sample demonstrates one of the functionalities of VK_EXT_extended_dynamic_state3 related to rasterization samples.
The extension can be used to dynamically change sampling without need to swap pipelines.
image:./image/image.png[]

== Enabling the extension

To be able to use this extension in Vulkan API:
`VK_EXT_extended_dynamic_state3` depends on `VK_KHR_get_physical_device_properties2`, which is promoted to Vulkan 1.1. That is, to use this extension, `VK_EXT_extended_dynamic_state3` and either `VK_KHR_get_physical_device_properties2` or Vulkan 1.1 are required.
Additionally this sample uses `VK_KHR_dynamic_rendering` which required Vulkan 1.2.

== Using the extension

To use the extension:
1) `VK_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT` must be added to `VkPipelineDynamicStateCreateInfo`.
2) Method `void vkCmdSetRasterizationSamplesEXT(VkCommandBuffer commandBuffer, VkSampleCountFlagBits rasterizationSamples)` should be called with the active command buffer.

== Resources

https://registry.khronos.org/vulkan/specs/latest/man/html/VK_EXT_extended_dynamic_state3.html
https://registry.khronos.org/vulkan/specs/latest/man/html/vkCmdSetRasterizationSamplesEXT.html
Loading

0 comments on commit 04f6080

Please sign in to comment.