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 rendering #186

Merged
merged 16 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ option(avk_toolkit_CreateDependencySymlinks "Create symbolic links instead of co
option(avk_toolkit_BuildExamples "Build all examples for Auto-Vk-Toolkit." OFF)
option(avk_toolkit_BuildHelloWorld "Build example: hello_world." OFF)
option(avk_toolkit_BuildFramebuffer "Build example: framebuffer." OFF)
option(avk_toolkit_BuildDynamicRendering "Build example: dynamic_rendering." OFF)
option(avk_toolkit_BuildComputeImageProcessing "Build example: compute_image_processing." OFF)
option(avk_toolkit_BuildMultiInvokeeRendering "Build example: multi_invokee_rendering." OFF)
option(avk_toolkit_BuildModelLoader "Build example: model_loader." OFF)
Expand All @@ -57,6 +58,7 @@ option(avk_toolkit_BuildPresentFromCompute "Build example: present_from_compute.
if (avk_toolkit_BuildExamples)
set(avk_toolkit_BuildHelloWorld ON)
set(avk_toolkit_BuildFramebuffer ON)
set(avk_toolkit_BuildDynamicRendering ON)
set(avk_toolkit_BuildComputeImageProcessing ON)
set(avk_toolkit_BuildMultiInvokeeRendering ON)
set(avk_toolkit_BuildModelLoader ON)
Expand Down Expand Up @@ -226,6 +228,11 @@ if (avk_toolkit_BuildFramebuffer)
add_subdirectory(examples/framebuffer)
endif()

## dynamic_rendering
if (avk_toolkit_BuildDynamicRendering)
add_subdirectory(examples/dynamic_rendering)
endif()

## compute_image_processing
if (avk_toolkit_BuildComputeImageProcessing)
add_subdirectory(examples/compute_image_processing)
Expand Down
2 changes: 2 additions & 0 deletions auto_vk_toolkit/include/context_vulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ namespace avk
#endif
bool supports_mesh_shader_nv(const vk::PhysicalDevice& device);
bool is_mesh_shader_nv_requested();
bool supports_dynamic_rendering(const vk::PhysicalDevice& device);
bool is_dynamic_rendering_requested();

#if VK_HEADER_VERSION >= 162
bool ray_tracing_pipeline_extension_requested();
Expand Down
25 changes: 25 additions & 0 deletions auto_vk_toolkit/src/context_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ namespace avk
deviceFeatures.setPNext(&meshShaderFeatureNV);
}

auto dynamicRenderingFeature = VkPhysicalDeviceDynamicRenderingFeaturesKHR{};
dynamicRenderingFeature.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES_KHR;
dynamicRenderingFeature.dynamicRendering = VK_TRUE;
if(is_dynamic_rendering_requested() && supports_dynamic_rendering(context().physical_device())){
dynamicRenderingFeature.pNext = deviceFeatures.pNext;
deviceFeatures.setPNext(&dynamicRenderingFeature);
}

// Unconditionally enable Synchronization2, because synchronization abstraction depends on it; it is just not implemented for Synchronization1:
auto physicalDeviceSync2Features = vk::PhysicalDeviceSynchronization2FeaturesKHR{}
.setPNext(deviceFeatures.pNext)
Expand Down Expand Up @@ -911,6 +919,18 @@ namespace avk
}
#endif

bool context_vulkan::supports_dynamic_rendering(const vk::PhysicalDevice& device)
{
vk::PhysicalDeviceProperties2 physicalProperties;
device.getProperties2(&physicalProperties, dispatch_loader_core());

vk::PhysicalDeviceFeatures2 supportedExtFeatures;
auto dynamicRenderingFeatures = vk::PhysicalDeviceDynamicRenderingFeaturesKHR{};
supportedExtFeatures.pNext = &dynamicRenderingFeatures;
device.getFeatures2(&supportedExtFeatures, dispatch_loader_core());
return dynamicRenderingFeatures.dynamicRendering == VK_TRUE;
}

bool context_vulkan::supports_mesh_shader_nv(const vk::PhysicalDevice& device)
{
vk::PhysicalDeviceFeatures2 supportedExtFeatures;
Expand All @@ -925,6 +945,11 @@ namespace avk
const auto& devex = get_all_enabled_device_extensions();
return std::find(std::begin(devex), std::end(devex), std::string(VK_NV_MESH_SHADER_EXTENSION_NAME)) != std::end(devex);
}
bool context_vulkan::is_dynamic_rendering_requested()
{
const auto& devex = get_all_enabled_device_extensions();
return std::find(std::begin(devex), std::end(devex), std::string(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) != std::end(devex);
}

#if VK_HEADER_VERSION >= 162
bool context_vulkan::ray_tracing_pipeline_extension_requested()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class compute_image_processing_app : public avk::invokee

auto submission = avk::context().record({
// Begin and end one renderpass:
avk::command::render_pass(mGraphicsPipeline->renderpass_reference(), avk::context().main_window()->current_backbuffer_reference(), {
avk::command::render_pass(mGraphicsPipeline->renderpass_reference().value(), avk::context().main_window()->current_backbuffer_reference(), {

// Draw left viewport:
avk::command::custom_commands([&,this](avk::command_buffer_t& cb) { // If there is no avk::command::... struct for a particular command, we can always use avk::command::custom_commands
Expand Down
13 changes: 13 additions & 0 deletions examples/dynamic_rendering/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_executable(dynamic_rendering
source/dynamic_rendering.cpp)
target_include_directories(dynamic_rendering PRIVATE ${PROJECT_NAME})
target_link_libraries(dynamic_rendering PRIVATE ${PROJECT_NAME})

get_target_property(dynamic_rendering_BINARY_DIR dynamic_rendering BINARY_DIR)

add_post_build_commands(dynamic_rendering
${PROJECT_SOURCE_DIR}/examples/dynamic_rendering/shaders
${dynamic_rendering_BINARY_DIR}/shaders
$<TARGET_FILE_DIR:dynamic_rendering>/assets
""
${avk_toolkit_CreateDependencySymlinks})
4 changes: 4 additions & 0 deletions examples/dynamic_rendering/dynamic_rendering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# "Dynamic rendering" Example's Root Folder

This is the root directory of the "Dynamic rendering" example. It contains all the source code for the example.

10 changes: 10 additions & 0 deletions examples/dynamic_rendering/shaders/color.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) in vec3 fragColor;

layout(location = 0) out vec4 outColor;

void main() {
outColor = vec4(fragColor, 1.0);
}
21 changes: 21 additions & 0 deletions examples/dynamic_rendering/shaders/screen_space_tri.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) out vec3 fragColor;

const vec2[] positions = vec2[3] (
vec2( 0.5, 0.5),
vec2( 0.0, -0.5),
vec2(-0.5, 0.5)
);

const vec3[] colors = vec3[3] (
vec3( 1.0, 0.0, 0.0),
vec3( 0.0, 1.0, 0.0),
vec3( 0.0, 0.0, 1.0)
);

void main() {
gl_Position = vec4(positions[gl_VertexIndex], 0.5, 1.0);
fragColor = colors[gl_VertexIndex];
}
Loading
Loading