Skip to content

Commit a67ff3e

Browse files
Add a new sample - subgroups operation
1 parent a9ca1fb commit a67ff3e

File tree

7 files changed

+287
-105
lines changed

7 files changed

+287
-105
lines changed

samples/CMakeLists.txt

Lines changed: 80 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -48,87 +48,86 @@ endforeach ()
4848

4949
# Order of the sample ids
5050
set(ORDER_LIST
51-
#API Samples
52-
"hello_triangle"
53-
"dynamic_uniform_buffers"
54-
"texture_loading"
55-
"hdr"
56-
"instancing"
57-
"compute_nbody"
58-
"terrain_tessellation"
59-
"hlsl"
60-
61-
#Extension Samples
62-
"dynamic_rendering"
63-
"conservative_rasterization"
64-
"fragment_shading_rate"
65-
"fragment_shading_rate_dynamic"
66-
"full_screen_exclusive"
67-
"calibrated_timestamps"
68-
"graphics_pipeline_library"
69-
"memory_budget"
70-
"mesh_shader_culling"
71-
"push_descriptors"
72-
"ray_queries"
73-
"ray_tracing_basic"
74-
"ray_tracing_extended"
75-
"ray_tracing_reflection"
76-
"timeline_semaphore"
77-
"shader_object"
78-
"synchronization_2"
79-
"buffer_device_address"
80-
"descriptor_indexing"
81-
"portability"
82-
"vertex_dynamic_state"
83-
"extended_dynamic_state2"
84-
"logic_op_dynamic_state"
85-
"patch_control_points"
86-
"fragment_shader_barycentric"
87-
"gshader_to_mshader"
88-
"color_write_enable"
89-
"subgroups_operations"
90-
91-
92-
#Performance Samples
93-
"swapchain_images"
94-
"surface_rotation"
95-
"pipeline_cache"
96-
"descriptor_management"
97-
"constant_data"
98-
"render_passes"
99-
"msaa"
100-
"subpasses"
101-
"pipeline_barriers"
102-
"wait_idle"
103-
"layout_transitions"
104-
"specialization_constants"
105-
"command_buffer_usage"
106-
"multithreading_render_passes"
107-
"afbc"
108-
"16bit_storage_input_output"
109-
"16bit_arithmetic"
110-
"async_compute"
111-
"multi_draw_indirect"
112-
"texture_compression_comparison"
113-
114-
#Tooling samples
115-
"profiles"
116-
117-
#HPP API Samples
118-
"hpp_compute_nbody"
119-
"hpp_dynamic_uniform_buffers"
120-
"hpp_hdr"
121-
"hpp_hello_triangle"
122-
"hpp_hlsl_shaders"
123-
"hpp_instancing"
124-
"hpp_separate_image_sampler"
125-
"hpp_terrain_tessellation"
126-
"hpp_texture_loading"
127-
"hpp_texture_mipmap_generation"
128-
129-
#HPP Performance Samples
130-
"hpp_pipeline_cache"
131-
"hpp_swapchain_images")
51+
#API Samples
52+
"hello_triangle"
53+
"dynamic_uniform_buffers"
54+
"texture_loading"
55+
"hdr"
56+
"instancing"
57+
"compute_nbody"
58+
"terrain_tessellation"
59+
"hlsl"
60+
61+
#Extension Samples
62+
"dynamic_rendering"
63+
"conservative_rasterization"
64+
"fragment_shading_rate"
65+
"fragment_shading_rate_dynamic"
66+
"full_screen_exclusive"
67+
"calibrated_timestamps"
68+
"graphics_pipeline_library"
69+
"memory_budget"
70+
"mesh_shader_culling"
71+
"push_descriptors"
72+
"ray_queries"
73+
"ray_tracing_basic"
74+
"ray_tracing_extended"
75+
"ray_tracing_reflection"
76+
"timeline_semaphore"
77+
"shader_object"
78+
"synchronization_2"
79+
"buffer_device_address"
80+
"descriptor_indexing"
81+
"portability"
82+
"vertex_dynamic_state"
83+
"extended_dynamic_state2"
84+
"logic_op_dynamic_state"
85+
"patch_control_points"
86+
"fragment_shader_barycentric"
87+
"gshader_to_mshader"
88+
"color_write_enable"
89+
"subgroups_operations"
90+
91+
#Performance Samples
92+
"swapchain_images"
93+
"surface_rotation"
94+
"pipeline_cache"
95+
"descriptor_management"
96+
"constant_data"
97+
"render_passes"
98+
"msaa"
99+
"subpasses"
100+
"pipeline_barriers"
101+
"wait_idle"
102+
"layout_transitions"
103+
"specialization_constants"
104+
"command_buffer_usage"
105+
"multithreading_render_passes"
106+
"afbc"
107+
"16bit_storage_input_output"
108+
"16bit_arithmetic"
109+
"async_compute"
110+
"multi_draw_indirect"
111+
"texture_compression_comparison"
112+
113+
#Tooling samples
114+
"profiles"
115+
116+
#HPP API Samples
117+
"hpp_compute_nbody"
118+
"hpp_dynamic_uniform_buffers"
119+
"hpp_hdr"
120+
"hpp_hello_triangle"
121+
"hpp_hlsl_shaders"
122+
"hpp_instancing"
123+
"hpp_separate_image_sampler"
124+
"hpp_terrain_tessellation"
125+
"hpp_texture_loading"
126+
"hpp_texture_mipmap_generation"
127+
128+
#HPP Performance Samples
129+
"hpp_pipeline_cache"
130+
"hpp_swapchain_images")
132131

133132
# Orders the sample ids by the order list above
134133
set(ORDERED_LIST)

samples/extensions/subgroups_operations/CMakeLists.txt

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,28 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
18-
get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
19-
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
20-
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME)
2117

22-
add_sample(
23-
ID ${FOLDER_NAME}
24-
CATEGORY ${CATEGORY_NAME}
25-
AUTHOR "Mobica"
26-
NAME "subgroups_operations"
27-
DESCRIPTION "Demonstrates the use of a subgroups feature"
28-
SHADER_FILES_GLSL
29-
"subgroups_operations/skybox.vert"
30-
"subgroups_operations/skybox.frag"
31-
"subgroups_operations/ocean.vert"
32-
"subgroups_operations/ocean.frag"
33-
"subgroups_operations/ocean.tesc"
34-
"subgroups_operations/ocean.tese"
35-
"subgroups_operations/fft_invert.comp"
36-
"subgroups_operations/butterfly_precomp.comp"
37-
"subgroups_operations/fft_tilde_h.comp"
38-
"subgroups_operations/fft_tilde_h0.comp"
39-
"subgroups_operations/fft_normal_map.comp"
40-
"subgroups_operations/fft.comp")
18+
get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
19+
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
20+
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME)
21+
22+
add_sample(
23+
ID ${FOLDER_NAME}
24+
CATEGORY ${CATEGORY_NAME}
25+
AUTHOR "Mobica"
26+
NAME "subgroups_operations"
27+
DESCRIPTION "Demonstrates the use of a subgroups feature"
28+
SHADER_FILES_GLSL
29+
"subgroups_operations/skybox.vert"
30+
"subgroups_operations/skybox.frag"
31+
"subgroups_operations/ocean.vert"
32+
"subgroups_operations/ocean.frag"
33+
"subgroups_operations/ocean.tesc"
34+
"subgroups_operations/ocean.tese"
35+
"subgroups_operations/fft_invert.comp"
36+
"subgroups_operations/butterfly_precomp.comp"
37+
"subgroups_operations/fft_tilde_h.comp"
38+
"subgroups_operations/fft_tilde_h0.comp"
39+
"subgroups_operations/fft_normal_map.comp"
40+
"subgroups_operations/fft.comp")
41+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!--
2+
- Copyright (c) 2023, Mobica Limited
3+
-
4+
- SPDX-License-Identifier: Apache-2.0
5+
-
6+
- Licensed under the Apache License, Version 2.0 the "License";
7+
- you may not use this file except in compliance with the License.
8+
- You may obtain a copy of the License at
9+
-
10+
- http://www.apache.org/licenses/LICENSE-2.0
11+
-
12+
- Unless required by applicable law or agreed to in writing, software
13+
- distributed under the License is distributed on an "AS IS" BASIS,
14+
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
- See the License for the specific language governing permissions and
16+
- limitations under the License.
17+
-
18+
-->
19+
20+
# Subgroups Operations
21+
22+
23+
## Overview
24+
25+
This sample demonstrates how to use and enable the Subgroups operations feature.
26+
27+
28+
## GLSL Shaders
29+
In shader enable `GL_KHR_shader_subgroup_basic` extension.
30+
TODO: add more description
31+
32+
33+
## Enabling the Feature
34+
35+
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
36+
```C++
37+
VkPhysicalDeviceSubgroupProperties subgroups_properties;
38+
subgroups_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
39+
subgroups_properties.pNext = VK_NULL_HANDLE;
40+
41+
VkPhysicalDeviceProperties2 device_properties2 = {};
42+
device_properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
43+
device_properties2.pNext = &subgroups_properties;
44+
vkGetPhysicalDeviceProperties2(gpu.get_handle(), &device_properties2);
45+
```
46+
TODO: add more description
47+
48+
## Additional information
49+
50+
More about subgroups you can read [in this article](https://www.khronos.org/blog/vulkan-subgroup-tutorial).
51+
Documentation: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceSubgroupProperties.html

samples/extensions/subgroups_operations/subgroups_operations.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ void SubgroupsOperations::create_pipelines()
769769
dynamic_state_enables.data(),
770770
static_cast<uint32_t>(dynamic_state_enables.size()),
771771
0u);
772+
772773
VkPipelineTessellationStateCreateInfo tessellation_state = vkb::initializers::pipeline_tessellation_state_create_info(3u);
773774

774775
std::array<VkPipelineShaderStageCreateInfo, 4> shader_stages = {
@@ -1491,4 +1492,4 @@ void SubgroupsOperations::Wind::recalc()
14911492
std::unique_ptr<vkb::VulkanSample> create_subgroups_operations()
14921493
{
14931494
return std::make_unique<SubgroupsOperations>();
1494-
}
1495+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#version 450
2+
/* Copyright (c) 2023, Mobica Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 the "License";
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
layout (binding = 1) uniform sampler2D samplerColor;
20+
21+
layout (location = 0) in vec2 inUV;
22+
23+
layout (location = 0) out vec4 outFragColor;
24+
25+
void main()
26+
{
27+
outFragColor = texture(samplerColor, inUV);
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#version 450
2+
/* Copyright (c) 2023, Mobica Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 the "License";
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
layout (location = 0) in vec3 inPos;
20+
layout (location = 1) in vec2 inUV;
21+
22+
layout(location = 0) out vec2 outUv;
23+
24+
layout (binding = 0) uniform Ubo
25+
{
26+
mat4 projection;
27+
mat4 model;
28+
vec4 view;
29+
} ubo;
30+
31+
void main()
32+
{
33+
outUv = inUV;
34+
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0f);
35+
}

0 commit comments

Comments
 (0)