Skip to content

Commit

Permalink
merian: extensions: consider unsupported if core feature is not avail…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
LDAP committed Nov 7, 2024
1 parent bc497c8 commit 2ec53b2
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 44 deletions.
12 changes: 7 additions & 5 deletions include/merian/vk/extension/extension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ class Extension {
}

/* Custom check for compatibility after the physical device is ready.
* If this method returns false, it is guaranteed that on_unsupported is called.
* At this time the structs wired up in pnext_get_features_2 is valid, you can use those to
* check if features are available.
*
* At this time the structs wired up in pnext_get_features_2 is valid.
* If this method returns false, it is guaranteed that on_unsupported is called.
*/
virtual bool extension_supported(const Context::PhysicalDeviceContainer& /*unused*/) {
return true;
Expand All @@ -96,8 +97,8 @@ class Extension {
return p_next;
}
/* Do not change pNext. You can use pnext_device_create_info for that. */
virtual void enable_device_features(const Context::FeaturesContainer& /*unused*/,
Context::FeaturesContainer& /*unused*/) {}
virtual void enable_device_features(const Context::FeaturesContainer& /*supportedFeatures*/,
Context::FeaturesContainer& /*enableFeatures*/) {}
virtual void on_device_created(const vk::Device& /*unused*/) {}
/* Called right before context constructor returns. */
virtual void on_context_created(const ContextHandle& /*unused*/) {}
Expand All @@ -117,7 +118,8 @@ class Extension {

// return strings that should be defined when compiling shaders with Merians shader compiler.
// Note that device, instance and Merian context extensions are automatically defined as
// MERIAN_DEVICE_EXT_ENABLED_<NAME>, MERIAN_INSTANCE_EXT_ENABLED_<NAME>, MERIAN_CONTEXT_EXT_ENABLED_
// MERIAN_DEVICE_EXT_ENABLED_<NAME>, MERIAN_INSTANCE_EXT_ENABLED_<NAME>,
// MERIAN_CONTEXT_EXT_ENABLED_
virtual std::map<std::string, std::string> shader_macro_definitions() {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ namespace merian {
/**
* @brief This class describes an extension to access
* VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME.
*
*
* Note that you must enable Ray Query or Ray Tracing Pipeline extension for this to work.
*/
class ExtensionVkAccelerationStructure : public Extension {
public:
ExtensionVkAccelerationStructure() : Extension("ExtensionVkAccelerationStructure") {
acceleration_structure_features.accelerationStructure = VK_TRUE;
}
ExtensionVkAccelerationStructure() : Extension("ExtensionVkAccelerationStructure") {}
~ExtensionVkAccelerationStructure() {}

std::vector<const char*> required_device_extension_names(vk::PhysicalDevice) const override {
Expand All @@ -32,6 +30,16 @@ class ExtensionVkAccelerationStructure : public Extension {
props2.pNext = &acceleration_structure_properties;
pd_container.physical_device.getProperties2(&props2);
}

void* pnext_get_features_2(void* const p_next) override {
acceleration_structure_features.setPNext(p_next);
return &acceleration_structure_features;
}

bool extension_supported(const Context::PhysicalDeviceContainer& /*unused*/) override {
return acceleration_structure_features.accelerationStructure == VK_TRUE;
}

void* pnext_device_create_info(void* const p_next) override {
acceleration_structure_features.pNext = p_next;
return &acceleration_structure_features;
Expand Down
6 changes: 3 additions & 3 deletions include/merian/vk/extension/extension_vk_debug_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "merian/vk/context.hpp"
#include "merian/vk/extension/extension.hpp"

#include <vulkan/vulkan.hpp>
#include <unordered_set>
#include <vulkan/vulkan.hpp>

namespace merian {

Expand Down Expand Up @@ -48,9 +48,9 @@ class ExtensionVkDebugUtils : public Extension {

// Own methods
template <typename T> void set_object_name(vk::Device& device, T handle, std::string name) {
vk::DebugUtilsObjectNameInfoEXT infoEXT(
vk::DebugUtilsObjectNameInfoEXT info_ext(
handle.objectType, uint64_t(static_cast<typename T::CType>(handle)), name.c_str());
device.setDebugUtilsObjectNameEXT(infoEXT);
device.setDebugUtilsObjectNameEXT(info_ext);
}

void cmd_begin_label(const vk::CommandBuffer& cmd, const std::string& name) {
Expand Down
3 changes: 2 additions & 1 deletion include/merian/vk/extension/extension_vk_filter_cubic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class ExtensionVkFilterCubic : public Extension {
public:
ExtensionVkFilterCubic() : Extension("ExtensionVkFilterCubic") {}
~ExtensionVkFilterCubic() {}
std::vector<const char*> required_device_extension_names(vk::PhysicalDevice) const override {
std::vector<const char*>
required_device_extension_names(vk::PhysicalDevice /*unused*/) const override {
return {VK_EXT_FILTER_CUBIC_EXTENSION_NAME};
}
};
Expand Down
8 changes: 4 additions & 4 deletions include/merian/vk/extension/extension_vk_float_atomics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class ExtensionVkFloatAtomics : public Extension {
}

void* pnext_device_create_info(void* const p_next) override {
if (supported_atomic_features.shaderImageFloat32Atomics) {
if (supported_atomic_features.shaderImageFloat32Atomics == VK_TRUE) {
SPDLOG_DEBUG("shaderImageFloat32Atomics supported. Enabling feature");
enable_atomic_features.shaderImageFloat32Atomics = true;
enable_atomic_features.shaderImageFloat32Atomics = VK_TRUE;
} else {
SPDLOG_WARN("shaderImageFloat32Atomics not supported");
}

if (supported_atomic_features.shaderImageFloat32AtomicAdd) {
if (supported_atomic_features.shaderImageFloat32AtomicAdd == VK_TRUE) {
SPDLOG_DEBUG("shaderImageFloat32AtomicAdd supported. Enabling feature");
enable_atomic_features.shaderImageFloat32AtomicAdd = true;
enable_atomic_features.shaderImageFloat32AtomicAdd = VK_TRUE;
} else {
SPDLOG_WARN("shaderImageFloat32AtomicAdd not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ExtensionVkNvComputeShaderDerivatives : public Extension {
public:
ExtensionVkNvComputeShaderDerivatives() : Extension("ExtensionVkNvComputeShaderDerivatives") {}
~ExtensionVkNvComputeShaderDerivatives() {}
std::vector<const char*> required_device_extension_names(vk::PhysicalDevice) const override {
std::vector<const char*> required_device_extension_names(vk::PhysicalDevice /*unused*/) const override {
return {VK_NV_COMPUTE_SHADER_DERIVATIVES_EXTENSION_NAME};
}

Expand All @@ -17,16 +17,21 @@ class ExtensionVkNvComputeShaderDerivatives : public Extension {
return &supported_features;
}

bool extension_supported(const Context::PhysicalDeviceContainer& /*unused*/) override {
return supported_features.computeDerivativeGroupLinear == VK_TRUE ||
supported_features.computeDerivativeGroupQuads == VK_TRUE;
}

void* pnext_device_create_info(void* const p_next) override {
if (supported_features.computeDerivativeGroupQuads) {
if (supported_features.computeDerivativeGroupQuads == VK_TRUE) {
SPDLOG_DEBUG("computeDerivativeGroupQuads supported. Enabling feature");
enabled_features.computeDerivativeGroupQuads = true;
enabled_features.computeDerivativeGroupQuads = VK_TRUE;
} else {
SPDLOG_ERROR("computeDerivativeGroupQuads requested but not supported");
}
if (supported_features.computeDerivativeGroupLinear) {
if (supported_features.computeDerivativeGroupLinear == VK_TRUE) {
SPDLOG_DEBUG("computeDerivativeGroupLinear supported. Enabling feature");
enabled_features.computeDerivativeGroupLinear = true;
enabled_features.computeDerivativeGroupLinear = VK_TRUE;
} else {
SPDLOG_ERROR("computeDerivativeGroupLinear requested but not supported");
}
Expand Down
23 changes: 17 additions & 6 deletions include/merian/vk/extension/extension_vk_ray_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ namespace merian {
*/
class ExtensionVkRayQuery : public Extension {
public:
ExtensionVkRayQuery() : Extension("ExtensionVkRaytraceQuery") {
physical_device_ray_query_features.rayQuery = VK_TRUE;
}
ExtensionVkRayQuery() : Extension("ExtensionVkRaytraceQuery") {}
~ExtensionVkRayQuery() {}
std::vector<const char*> required_device_extension_names(vk::PhysicalDevice) const override {

std::vector<const char*>
required_device_extension_names(vk::PhysicalDevice /*unused*/) const override {
return {
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, // intel doesn't have it pre 2015 (hd 520)
VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME, VK_KHR_RAY_QUERY_EXTENSION_NAME,
VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME,
VK_KHR_RAY_QUERY_EXTENSION_NAME,
};
}

// LIFECYCLE
void* pnext_get_features_2(void* const p_next) override {
physical_device_ray_query_features.setPNext(p_next);
return &physical_device_ray_query_features;
}

bool extension_supported(const Context::PhysicalDeviceContainer& /*unused*/) override {
return physical_device_ray_query_features.rayQuery == VK_TRUE;
}

void* pnext_device_create_info(void* const p_next) override {
physical_device_ray_query_features.pNext = p_next;
return &physical_device_ray_query_features;
Expand Down
19 changes: 15 additions & 4 deletions include/merian/vk/extension/extension_vk_ray_tracing_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ namespace merian {
*/
class ExtensionVkRayTracingPipeline : public Extension {
public:
ExtensionVkRayTracingPipeline() : Extension("ExtensionVkRayTracingPipeline") {
ray_tracing_pipeline_features.rayTracingPipeline = VK_TRUE;
}
ExtensionVkRayTracingPipeline() : Extension("ExtensionVkRayTracingPipeline") {}

~ExtensionVkRayTracingPipeline() {}
std::vector<const char*> required_device_extension_names(vk::PhysicalDevice) const override {

std::vector<const char*>
required_device_extension_names(vk::PhysicalDevice /*unused*/) const override {
return {
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
Expand All @@ -29,12 +30,22 @@ class ExtensionVkRayTracingPipeline : public Extension {

// LIFECYCLE

void* pnext_get_features_2(void* const p_next) override {
ray_tracing_pipeline_features.setPNext(p_next);
return &ray_tracing_pipeline_features;
}

bool extension_supported(const Context::PhysicalDeviceContainer& /*unused*/) override {
return ray_tracing_pipeline_features.rayTracingPipeline == VK_TRUE;
}

void
on_physical_device_selected(const Context::PhysicalDeviceContainer& pd_container) override {
vk::PhysicalDeviceProperties2KHR props2;
props2.pNext = &ray_tracing_pipeline_properties;
pd_container.physical_device.getProperties2(&props2);
}

void* pnext_device_create_info(void* const p_next) override {
ray_tracing_pipeline_features.pNext = p_next;
return &ray_tracing_pipeline_features;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class ExtensionVkRayTracingPositionFetch : public Extension {
public:
ExtensionVkRayTracingPositionFetch() : Extension("ExtensionVkRayTracingPositionFetch") {}
~ExtensionVkRayTracingPositionFetch() {}
std::vector<const char*> required_device_extension_names(vk::PhysicalDevice) const override {
std::vector<const char*>
required_device_extension_names(vk::PhysicalDevice /*unused*/) const override {
return {VK_KHR_RAY_TRACING_POSITION_FETCH_EXTENSION_NAME};
}

Expand All @@ -17,10 +18,14 @@ class ExtensionVkRayTracingPositionFetch : public Extension {
return &supported_features;
}

bool extension_supported(const Context::PhysicalDeviceContainer& /*unused*/) override {
return supported_features.rayTracingPositionFetch == VK_TRUE;
}

void* pnext_device_create_info(void* const p_next) override {
if (supported_features.rayTracingPositionFetch) {
if (supported_features.rayTracingPositionFetch == VK_TRUE) {
SPDLOG_DEBUG("rayTracingPositionFetch supported. Enabling feature");
enabled_features.rayTracingPositionFetch = true;
enabled_features.rayTracingPositionFetch = VK_TRUE;
} else {
SPDLOG_ERROR("rayTracingPositionFetch requested but not supported");
}
Expand Down
12 changes: 6 additions & 6 deletions include/merian/vk/extension/extension_vk_robustness_2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ class ExtensionVkRobustnessAccess2 : public Extension {
}

void* pnext_device_create_info(void* const p_next) override {
if (supported_image_robustness_features.robustImageAccess2) {
if (supported_image_robustness_features.robustImageAccess2 == VK_TRUE) {
SPDLOG_DEBUG("robustImageAccess2 supported. Enabling feature");
enable_image_robustness_features.robustImageAccess2 = true;
enable_image_robustness_features.robustImageAccess2 = VK_TRUE;
} else {
SPDLOG_WARN("robustImageAccess2 requested but not supported");
}

if (supported_image_robustness_features.robustBufferAccess2) {
if (supported_image_robustness_features.robustBufferAccess2 == VK_TRUE) {
SPDLOG_DEBUG("robustBufferAccess2 supported. Enabling feature");
enable_image_robustness_features.robustBufferAccess2 = true;
enable_image_robustness_features.robustBufferAccess2 = VK_TRUE;
} else {
SPDLOG_WARN("robustBufferAccess2 requested but not supported");
}

if (supported_image_robustness_features.nullDescriptor) {
if (supported_image_robustness_features.nullDescriptor == VK_TRUE) {
SPDLOG_DEBUG("nullDescriptor supported. Enabling feature");
enable_image_robustness_features.nullDescriptor = true;
enable_image_robustness_features.nullDescriptor = VK_TRUE;
} else {
SPDLOG_WARN("nullDescriptor requested but not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class ExtensionVkShaderMaximalReconvergence : public Extension {
public:
ExtensionVkShaderMaximalReconvergence() : Extension("ExtensionVkShaderMaximalReconvergence") {}
~ExtensionVkShaderMaximalReconvergence() {}
std::vector<const char*> required_device_extension_names(vk::PhysicalDevice) const override {
std::vector<const char*>
required_device_extension_names(vk::PhysicalDevice /*unused*/) const override {
return {VK_KHR_SHADER_MAXIMAL_RECONVERGENCE_EXTENSION_NAME};
}

Expand All @@ -18,9 +19,9 @@ class ExtensionVkShaderMaximalReconvergence : public Extension {
}

void* pnext_device_create_info(void* const p_next) override {
if (supported_features.shaderMaximalReconvergence) {
if (supported_features.shaderMaximalReconvergence == VK_TRUE) {
SPDLOG_DEBUG("shaderMaximalReconvergence supported. Enabling feature");
enabled_features.shaderMaximalReconvergence = true;
enabled_features.shaderMaximalReconvergence = VK_TRUE;
} else {
SPDLOG_ERROR("shaderMaximalReconvergence requested but not supported");
}
Expand All @@ -29,6 +30,10 @@ class ExtensionVkShaderMaximalReconvergence : public Extension {
return &enabled_features;
}

bool extension_supported(const Context::PhysicalDeviceContainer& /*unused*/) override {
return supported_features.shaderMaximalReconvergence == VK_TRUE;
}

private:
vk::PhysicalDeviceShaderMaximalReconvergenceFeaturesKHR supported_features;
vk::PhysicalDeviceShaderMaximalReconvergenceFeaturesKHR enabled_features;
Expand Down

0 comments on commit 2ec53b2

Please sign in to comment.