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 49 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
4 changes: 2 additions & 2 deletions framework/api_vulkan_sample.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019-2023, Sascha Willems
/* Copyright (c) 2019-2024, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -424,7 +424,7 @@ class ApiVulkanSample : public vkb::VulkanSample
std::string title = "Vulkan Example";
std::string name = "vulkanExample";

struct
struct ImageData
{
VkImage image;
VkDeviceMemory mem;
Expand Down
23 changes: 19 additions & 4 deletions framework/gui.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2018-2023, Arm Limited and Contributors
* Copyright (c) 2019-2023, Sascha Willems
/* Copyright (c) 2018-2024, Arm Limited and Contributors
* Copyright (c) 2019-2024, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down 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
17 changes: 15 additions & 2 deletions framework/gui.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2018-2023, Arm Limited and Contributors
* Copyright (c) 2019-2023, Sascha Willems
/* Copyright (c) 2018-2024, Arm Limited and Contributors
* Copyright (c) 2019-2024, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -349,6 +349,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 @@ -407,6 +416,10 @@ class Gui

void set_subpass(const uint32_t subpass);

VkSampler get_sampler() const;

VkImageView get_font_image_view() const;

private:
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.

/**
* @brief Block size of a buffer pool in kilobytes
Expand Down
3 changes: 2 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, Arm Limited and Contributors
# Copyright (c) 2019-2024, Arm Limited and Contributors
#
# SPDX-License-Identifier: Apache-2.0
#
Expand Down Expand Up @@ -87,6 +87,7 @@ set(ORDER_LIST
"fragment_shader_barycentric"
"gshader_to_mshader"
"color_write_enable"
"dynamic_multisample_rasterization"
"sparse_image"

#Performance Samples
Expand Down
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")
55 changes: 55 additions & 0 deletions samples/extensions/dynamic_multisample_rasterization/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
////
- 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[]
SaschaWillems marked this conversation as resolved.
Show resolved Hide resolved

== 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.

== 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 between `vkCmdBeginRenderPass` and `vkCmdEndRenderPass`.

== Known issues

The extension always reports the following validation errors when enabled:
....
VUID-vkCmdDraw-rasterizationSamples-07474(ERROR / SPEC): msgNum: -2007336333 - Validation Error: [ VUID-vkCmdDraw-rasterizationSamples-07474 ] Object 0: handle = 0x1ab5b866f50, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x885a7a73 | vkCmdDraw(): Render pass attachment 1 samples VK_SAMPLE_COUNT_1_BIT does not match samples VK_SAMPLE_COUNT_4_BIT set with vkCmdSetRasterizationSamplesEXT(). The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT state enabled, and neither the VK_AMD_mixed_attachment_samples nor the VK_NV_framebuffer_mixed_samples extensions are enabled, then the rasterizationSamples in the last call to vkCmdSetRasterizationSamplesEXT must be the same as the current subpass color and/or depth/stencil attachments (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdDraw-rasterizationSamples-07474)
VUID-vkCmdDraw-renderPass-02684: Validation Error: [ VUID-vkCmdDraw-renderPass-02684 ] Object 0: handle = 0x7533b600000006c9, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0x30f5a50000000020, type = VK_OBJECT_TYPE_RENDER_PASS; | MessageID = 0x50685725 | vkCmdDraw(): RenderPasses incompatible between active render pass w/ VkRenderPass 0x7533b600000006c9[] and pipeline state object w/ VkRenderPass 0x30f5a50000000020[] Attachment 0 is not compatible with 0: They have different samples.. The Vulkan spec states: The current render pass must be compatible with the renderPass member of the VkGraphicsPipelineCreateInfo structure specified when creating the VkPipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdDraw-renderPass-02684)
....

The root cause for the validation errors is currently unknown and under analysis by Vulkan Validation Layers team:

https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/7327

== 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