Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic state3 multisample rasterization #856

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a930066
Add initial test framework.
pawel-jastrzebski-mobica Oct 13, 2023
f36f9e6
Add MSAAm sample code.
pawel-jastrzebski-mobica Oct 17, 2023
3c4b9fe
Add sample with SpaceModule scene.
pawel-jastrzebski-mobica Nov 8, 2023
e26d3da
Rendering proper BaseModule scene.
pawel-jastrzebski-mobica Nov 14, 2023
0175f6a
Fix copyrights.
pawel-jastrzebski-mobica Nov 14, 2023
0d06897
First version of MSAA works.
pawel-jastrzebski-mobica Nov 17, 2023
1170d1b
Implement dynamic sample selection.
pawel-jastrzebski-mobica Nov 24, 2023
46258c2
Add setter for last_requested_extension_feature.
pawel-jastrzebski-mobica Nov 27, 2023
447a3ad
Fix clang-format.
pawel-jastrzebski-mobica Nov 27, 2023
22c1930
Merge branch 'KhronosGroup:main' into dynamic_state3_multisample_rast…
pawel-jastrzebski-mobica Nov 27, 2023
7e5319f
Fix copyright.
pawel-jastrzebski-mobica Nov 27, 2023
4072330
Fix vulkan version.
pawel-jastrzebski-mobica Nov 28, 2023
5e73402
Update readme.
pawel-jastrzebski-mobica Nov 28, 2023
0f88145
Remove unneeded code from shader.
pawel-jastrzebski-mobica Nov 28, 2023
2eed170
Fix copyright.
pawel-jastrzebski-mobica Nov 28, 2023
032ca90
Add README.md
pawel-jastrzebski-mobica Nov 28, 2023
6b3e879
Add sample to CMake.
pawel-jastrzebski-mobica Nov 28, 2023
2e86179
Remove explicit reference from local viewport initializer.
pawel-jastrzebski-mobica Nov 28, 2023
37d42ce
Change resources create/update logic.
pawel-jastrzebski-mobica Nov 29, 2023
82be0a3
Fix clang-format.
pawel-jastrzebski-mobica Nov 29, 2023
ccc694c
Fix format for vertex input attribute descriptor.
pawel-jastrzebski-mobica Dec 1, 2023
c7b872f
Separate rendering for scene meshes with different rasterizer settings.
pawel-jastrzebski-mobica Dec 1, 2023
5d04e70
Change camera position.
pawel-jastrzebski-mobica Dec 4, 2023
792fc0a
Fix light position.
pawel-jastrzebski-mobica Dec 4, 2023
94db8df
Update README files.
pawel-jastrzebski-mobica Dec 4, 2023
a805676
Update sample image.
pawel-jastrzebski-mobica Dec 4, 2023
d812e3e
Merge branch 'KhronosGroup:main' into dynamic_state3_multisample_rast…
pawel-jastrzebski-mobica Dec 4, 2023
d537ce4
Fix warnings.
pawel-jastrzebski-mobica Dec 4, 2023
143196d
Fix typos in README files.
pawel-jastrzebski-mobica Dec 4, 2023
e5fb84c
Fix comment.
pawel-jastrzebski-mobica Dec 4, 2023
4e9f813
Fix review comments.
pawel-jastrzebski-mobica Dec 6, 2023
1bc20d4
Fix review comments.
pawel-jastrzebski-mobica Dec 18, 2023
59686d3
Fix review comments.
pawel-jastrzebski-mobica Dec 18, 2023
e6f1413
Merge branch 'main' into dynamic_state3_multisample_rasterization
pawel-jastrzebski-mobica Dec 18, 2023
e6829cd
Rename project.
pawel-jastrzebski-mobica Dec 19, 2023
92f0bbf
Fix review comments.
pawel-jastrzebski-mobica Jan 15, 2024
f037dc3
Add multisampling to GUI rendering.
pawel-jastrzebski-mobica Feb 1, 2024
d2016f3
Update README
pawel-jastrzebski-mobica Feb 2, 2024
ca0a459
Change rotation speed.
pawel-jastrzebski-mobica Feb 2, 2024
f4d0e0e
Fix clang-format.
pawel-jastrzebski-mobica Feb 2, 2024
9ca4309
Update copyright year.
pawel-jastrzebski-mobica Feb 5, 2024
8d4c1d1
Copyright fix in CMakeLists
Mateusz-Kowalewski-Mobica Feb 13, 2024
7e1e986
Fix review comments.
pawel-jastrzebski-mobica Feb 20, 2024
b2421ad
Fix review comments.
pawel-jastrzebski-mobica Feb 20, 2024
0b806c6
Fix VUID-VkSubpassDescription-pResolveAttachments-00848
Mateusz-Kowalewski-Mobica Feb 20, 2024
7e2434b
Image destroy refactor
Mateusz-Kowalewski-Mobica Feb 26, 2024
c4d78cb
Fix windows build issue
Mateusz-Kowalewski-Mobica Feb 27, 2024
ff3708b
Add dynamic rendering
Mateusz-Kowalewski-Mobica Mar 8, 2024
6f73a24
Gui merge conflicts fix
Mateusz-Kowalewski-Mobica Mar 8, 2024
65b93cd
Fix regressions after implementing dynamic rendering
Mateusz-Kowalewski-Mobica Mar 12, 2024
7af25fd
Merge branch 'main' into dynamic_state3_multisample_rasterization
Mateusz-Kowalewski-Mobica Mar 13, 2024
bdb6973
Adjust sample to changes from PR#910
Mateusz-Kowalewski-Mobica Mar 13, 2024
38fb8bd
Fix sync issue
Mateusz-Kowalewski-Mobica Mar 14, 2024
130d3e4
Documentation update
Mateusz-Kowalewski-Mobica Mar 27, 2024
8aacbb8
Merge branch 'main' into dynamic_state3_multisample_rasterization
Mateusz-Kowalewski-Mobica Apr 22, 2024
5467a77
Merge branch 'main' into dynamic_state3_multisample_rasterization
Mateusz-Kowalewski-Mobica May 7, 2024
7acbd64
Remove unused feature
Mateusz-Kowalewski-Mobica May 7, 2024
22b56ac
VK objects initializations added
Mateusz-Kowalewski-Mobica May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions framework/api_vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,11 @@ class ApiVulkanSample : public vkb::VulkanSample<vkb::BindingType::C>
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
19 changes: 17 additions & 2 deletions framework/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,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 @@ -669,13 +674,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 offsets[1] = {0};

Expand Down Expand Up @@ -729,6 +734,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;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would stay on the same abstraction level as this class, and return a vkb::core::Sampler const &, and vkb::core::ImageView const &, respectively.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since sampler and image_view are defined as std::unique_ptr's it would mean that it's either returned by std::move - not a good idea to change ownership of a pointer of internal class member. Or alternatively, in my opinion even worse to return raw pointer. It could be also defined as std::shared_ptr and this means a design change. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, returning a vkb::core::Sampler const & and a vkb::core::ImageView const & would be right.
As as they both don't support copy construction or copy assignment, you would not be able to accidentally assign or copy them.

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 @@ -89,6 +89,7 @@ set(ORDER_LIST
"fragment_shader_barycentric"
"gshader_to_mshader"
"color_write_enable"
"dynamic_multisample_rasterization"
"sparse_image"
"dynamic_primitive_clipping"

Expand Down
8 changes: 7 additions & 1 deletion samples/extensions/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,10 @@ Demonstrates how to use https://en.wikipedia.org/wiki/Printf[Printf] statements

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

Rendering using primitive clipping and depth clipping configured by dynamic pipeline state.
Rendering using primitive clipping and depth clipping configured by dynamic pipeline state.

=== 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 "Extended Dynamic State3 Multisample Rasterization"
DESCRIPTION "Sample description"
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/1.3-extensions/man/html/VK_EXT_extended_dynamic_state3.html
https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetRasterizationSamplesEXT.html
Loading
Loading