Skip to content

Commit

Permalink
Add a new sample - subgroups operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk-Jastrzebski-Mobica committed Nov 20, 2023
1 parent a9ca1fb commit a67ff3e
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 105 deletions.
161 changes: 80 additions & 81 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,87 +48,86 @@ endforeach ()

# Order of the sample ids
set(ORDER_LIST
#API Samples
"hello_triangle"
"dynamic_uniform_buffers"
"texture_loading"
"hdr"
"instancing"
"compute_nbody"
"terrain_tessellation"
"hlsl"

#Extension Samples
"dynamic_rendering"
"conservative_rasterization"
"fragment_shading_rate"
"fragment_shading_rate_dynamic"
"full_screen_exclusive"
"calibrated_timestamps"
"graphics_pipeline_library"
"memory_budget"
"mesh_shader_culling"
"push_descriptors"
"ray_queries"
"ray_tracing_basic"
"ray_tracing_extended"
"ray_tracing_reflection"
"timeline_semaphore"
"shader_object"
"synchronization_2"
"buffer_device_address"
"descriptor_indexing"
"portability"
"vertex_dynamic_state"
"extended_dynamic_state2"
"logic_op_dynamic_state"
"patch_control_points"
"fragment_shader_barycentric"
"gshader_to_mshader"
"color_write_enable"
"subgroups_operations"


#Performance Samples
"swapchain_images"
"surface_rotation"
"pipeline_cache"
"descriptor_management"
"constant_data"
"render_passes"
"msaa"
"subpasses"
"pipeline_barriers"
"wait_idle"
"layout_transitions"
"specialization_constants"
"command_buffer_usage"
"multithreading_render_passes"
"afbc"
"16bit_storage_input_output"
"16bit_arithmetic"
"async_compute"
"multi_draw_indirect"
"texture_compression_comparison"

#Tooling samples
"profiles"

#HPP API Samples
"hpp_compute_nbody"
"hpp_dynamic_uniform_buffers"
"hpp_hdr"
"hpp_hello_triangle"
"hpp_hlsl_shaders"
"hpp_instancing"
"hpp_separate_image_sampler"
"hpp_terrain_tessellation"
"hpp_texture_loading"
"hpp_texture_mipmap_generation"

#HPP Performance Samples
"hpp_pipeline_cache"
"hpp_swapchain_images")
#API Samples
"hello_triangle"
"dynamic_uniform_buffers"
"texture_loading"
"hdr"
"instancing"
"compute_nbody"
"terrain_tessellation"
"hlsl"

#Extension Samples
"dynamic_rendering"
"conservative_rasterization"
"fragment_shading_rate"
"fragment_shading_rate_dynamic"
"full_screen_exclusive"
"calibrated_timestamps"
"graphics_pipeline_library"
"memory_budget"
"mesh_shader_culling"
"push_descriptors"
"ray_queries"
"ray_tracing_basic"
"ray_tracing_extended"
"ray_tracing_reflection"
"timeline_semaphore"
"shader_object"
"synchronization_2"
"buffer_device_address"
"descriptor_indexing"
"portability"
"vertex_dynamic_state"
"extended_dynamic_state2"
"logic_op_dynamic_state"
"patch_control_points"
"fragment_shader_barycentric"
"gshader_to_mshader"
"color_write_enable"
"subgroups_operations"

#Performance Samples
"swapchain_images"
"surface_rotation"
"pipeline_cache"
"descriptor_management"
"constant_data"
"render_passes"
"msaa"
"subpasses"
"pipeline_barriers"
"wait_idle"
"layout_transitions"
"specialization_constants"
"command_buffer_usage"
"multithreading_render_passes"
"afbc"
"16bit_storage_input_output"
"16bit_arithmetic"
"async_compute"
"multi_draw_indirect"
"texture_compression_comparison"

#Tooling samples
"profiles"

#HPP API Samples
"hpp_compute_nbody"
"hpp_dynamic_uniform_buffers"
"hpp_hdr"
"hpp_hello_triangle"
"hpp_hlsl_shaders"
"hpp_instancing"
"hpp_separate_image_sampler"
"hpp_terrain_tessellation"
"hpp_texture_loading"
"hpp_texture_mipmap_generation"

#HPP Performance Samples
"hpp_pipeline_cache"
"hpp_swapchain_images")

# Orders the sample ids by the order list above
set(ORDERED_LIST)
Expand Down
47 changes: 24 additions & 23 deletions samples/extensions/subgroups_operations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@
# 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 "subgroups_operations"
DESCRIPTION "Demonstrates the use of a subgroups feature"
SHADER_FILES_GLSL
"subgroups_operations/skybox.vert"
"subgroups_operations/skybox.frag"
"subgroups_operations/ocean.vert"
"subgroups_operations/ocean.frag"
"subgroups_operations/ocean.tesc"
"subgroups_operations/ocean.tese"
"subgroups_operations/fft_invert.comp"
"subgroups_operations/butterfly_precomp.comp"
"subgroups_operations/fft_tilde_h.comp"
"subgroups_operations/fft_tilde_h0.comp"
"subgroups_operations/fft_normal_map.comp"
"subgroups_operations/fft.comp")
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 "subgroups_operations"
DESCRIPTION "Demonstrates the use of a subgroups feature"
SHADER_FILES_GLSL
"subgroups_operations/skybox.vert"
"subgroups_operations/skybox.frag"
"subgroups_operations/ocean.vert"
"subgroups_operations/ocean.frag"
"subgroups_operations/ocean.tesc"
"subgroups_operations/ocean.tese"
"subgroups_operations/fft_invert.comp"
"subgroups_operations/butterfly_precomp.comp"
"subgroups_operations/fft_tilde_h.comp"
"subgroups_operations/fft_tilde_h0.comp"
"subgroups_operations/fft_normal_map.comp"
"subgroups_operations/fft.comp")

51 changes: 51 additions & 0 deletions samples/extensions/subgroups_operations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--
- Copyright (c) 2023, 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.
-
-->

# Subgroups Operations


## Overview

This sample demonstrates how to use and enable the Subgroups operations feature.


## GLSL Shaders
In shader enable `GL_KHR_shader_subgroup_basic` extension.
TODO: add more description


## Enabling the Feature

To enable the subgroups feature in the Vulkan API you must create a Vulkan instance with a minimum version of version 1.1. Enable the extension `VK_EXT_subgroup_size_control` and get the subgroup properties of a physical device
```C++
VkPhysicalDeviceSubgroupProperties subgroups_properties;
subgroups_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
subgroups_properties.pNext = VK_NULL_HANDLE;

VkPhysicalDeviceProperties2 device_properties2 = {};
device_properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
device_properties2.pNext = &subgroups_properties;
vkGetPhysicalDeviceProperties2(gpu.get_handle(), &device_properties2);
```
TODO: add more description
## Additional information
More about subgroups you can read [in this article](https://www.khronos.org/blog/vulkan-subgroup-tutorial).
Documentation: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceSubgroupProperties.html
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ void SubgroupsOperations::create_pipelines()
dynamic_state_enables.data(),
static_cast<uint32_t>(dynamic_state_enables.size()),
0u);

VkPipelineTessellationStateCreateInfo tessellation_state = vkb::initializers::pipeline_tessellation_state_create_info(3u);

std::array<VkPipelineShaderStageCreateInfo, 4> shader_stages = {
Expand Down Expand Up @@ -1491,4 +1492,4 @@ void SubgroupsOperations::Wind::recalc()
std::unique_ptr<vkb::VulkanSample> create_subgroups_operations()
{
return std::make_unique<SubgroupsOperations>();
}
}
28 changes: 28 additions & 0 deletions shaders/subgroups_operations/base.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#version 450
/* Copyright (c) 2023, 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.
*/

layout (binding = 1) uniform sampler2D samplerColor;

layout (location = 0) in vec2 inUV;

layout (location = 0) out vec4 outFragColor;

void main()
{
outFragColor = texture(samplerColor, inUV);
}
35 changes: 35 additions & 0 deletions shaders/subgroups_operations/base.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#version 450
/* Copyright (c) 2023, 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.
*/

layout (location = 0) in vec3 inPos;
layout (location = 1) in vec2 inUV;

layout(location = 0) out vec2 outUv;

layout (binding = 0) uniform Ubo
{
mat4 projection;
mat4 model;
vec4 view;
} ubo;

void main()
{
outUv = inUV;
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0f);
}
Loading

0 comments on commit a67ff3e

Please sign in to comment.