Skip to content

Commit

Permalink
+ vk - initial support for VK_KHR_dynamic_rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Mar 5, 2023
1 parent 5b48688 commit 63e05df
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/tz/gl/impl/vulkan/detail/extensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace tz::gl::vk2
/// - Enables Swapchain operations (required to create a swapchain and present images)
Swapchain,
ShaderDebugPrint,
DynamicRendering,

Count
};
Expand All @@ -46,11 +47,11 @@ namespace tz::gl::vk2
namespace util
{
constexpr std::array<const char*, static_cast<int>(InstanceExtension::Count)> instance_extension_tz_names{"Debug Messenger"};
constexpr std::array<const char*, static_cast<int>(DeviceExtension::Count)> device_extension_tz_names{"Swapchain", "Shader Debug Print"};
constexpr std::array<const char*, static_cast<int>(DeviceExtension::Count)> device_extension_tz_names{"Swapchain", "Shader Debug Print", "Dynamic Rendering"};

using VkExtension = const char*;
constexpr std::array<VkExtension, static_cast<int>(InstanceExtension::Count)> instance_extension_names{VK_EXT_DEBUG_UTILS_EXTENSION_NAME};
constexpr std::array<VkExtension, static_cast<int>(DeviceExtension::Count)> device_extension_names{VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME};
constexpr std::array<VkExtension, static_cast<int>(DeviceExtension::Count)> device_extension_names{VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME};

constexpr VkExtension to_vk_extension(InstanceExtension extension)
{
Expand Down
17 changes: 14 additions & 3 deletions src/tz/gl/impl/vulkan/detail/features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ namespace tz::gl::vk2
/// - Enables vertex, geometry, and tessellation shaders to write to storage buffers.
VertexPipelineResourceWrite,
/// - Enables fragment shaders to write to storage buffers.
FragmentShaderResourceWrite
FragmentShaderResourceWrite,
/// - Enables dynamic rendering. this is not optional.
DynamicRendering
};

using DeviceFeatureField = tz::enum_field<DeviceFeature>;
Expand All @@ -49,10 +51,11 @@ namespace tz::gl::vk2
return feats;
}

constexpr VkPhysicalDeviceVulkan12Features empty_12_features()
constexpr VkPhysicalDeviceVulkan12Features empty_12_features(VkPhysicalDeviceDynamicRenderingFeaturesKHR& next)
{
VkPhysicalDeviceVulkan12Features feats{};
feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
feats.pNext = &next;
return feats;
}

Expand All @@ -64,9 +67,17 @@ namespace tz::gl::vk2
return feats;
}

constexpr VkPhysicalDeviceDynamicRenderingFeaturesKHR empty_dynamic_rendering_features()
{
VkPhysicalDeviceDynamicRenderingFeaturesKHR feats{};
feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES;
return feats;
}

struct DeviceFeatureInfo
{
VkPhysicalDeviceVulkan12Features features12 = empty_12_features();
VkPhysicalDeviceDynamicRenderingFeaturesKHR features_dr = empty_dynamic_rendering_features();
VkPhysicalDeviceVulkan12Features features12 = empty_12_features(features_dr);
VkPhysicalDeviceVulkan11Features features11 = empty_11_features(features12);
VkPhysicalDeviceFeatures2 features = empty_features2(features11);
};
Expand Down
6 changes: 6 additions & 0 deletions src/tz/gl/impl/vulkan/detail/hardware/physical_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ namespace tz::gl::vk2
{
ret |= DeviceFeature::FragmentShaderResourceWrite;
}
if(features.features_dr.dynamicRendering)
{
ret |= DeviceFeature::DynamicRendering;
}

return ret;
}
Expand Down Expand Up @@ -111,6 +115,8 @@ namespace tz::gl::vk2
info.features12.descriptorBindingVariableDescriptorCount = VK_TRUE;
info.features12.runtimeDescriptorArray = VK_TRUE;
}

info.features_dr.dynamicRendering = feature_field.contains(DeviceFeature::DynamicRendering);
return info;
}

Expand Down
5 changes: 3 additions & 2 deletions src/tz/gl/impl/vulkan/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,11 @@ namespace tz::gl
vk2::DeviceFeature::TessellationShaders,
vk2::DeviceFeature::VertexPipelineResourceWrite,
vk2::DeviceFeature::FragmentShaderResourceWrite,
vk2::DeviceFeature::TimelineSemaphores
vk2::DeviceFeature::TimelineSemaphores,
vk2::DeviceFeature::DynamicRendering
};
tz::assert(pdev.get_supported_features().contains(dev_feats), "One or both of DeviceFeatures 'BindlessDescriptors' and 'ColourBlendLogicalOperations' are not supported by this machine/driver. Please ensure your machine meets the system requirements.");
dev_exts = {vk2::DeviceExtension::Swapchain};
dev_exts = {vk2::DeviceExtension::Swapchain, vk2::DeviceExtension::DynamicRendering};
#if TZ_DEBUG
dev_exts |= vk2::DeviceExtension::ShaderDebugPrint;
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/tz/gl/impl/vulkan/device2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,11 @@ namespace tz::gl
vk2::DeviceFeature::TessellationShaders,
vk2::DeviceFeature::VertexPipelineResourceWrite,
vk2::DeviceFeature::FragmentShaderResourceWrite,
vk2::DeviceFeature::TimelineSemaphores
vk2::DeviceFeature::TimelineSemaphores,
vk2::DeviceFeature::DynamicRendering
};
tz::assert(pdev.get_supported_features().contains(dev_feats), "One or both of DeviceFeatures 'BindlessDescriptors' and 'ColourBlendLogicalOperations' are not supported by this machine/driver. Please ensure your machine meets the system requirements.");
dev_exts = {vk2::DeviceExtension::Swapchain};
dev_exts = {vk2::DeviceExtension::Swapchain, vk2::DeviceExtension::DynamicRendering};
#if TZ_DEBUG
dev_exts |= vk2::DeviceExtension::ShaderDebugPrint;
#endif
Expand Down

0 comments on commit 63e05df

Please sign in to comment.