Skip to content

Commit

Permalink
tests: Skip ray tracing tests when unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyg-lunarg committed Dec 16, 2024
1 parent 8d91989 commit 5309ad7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
20 changes: 20 additions & 0 deletions tests/framework/test_fixtures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ void CDLTestBase::InitInstance() {
print_phys_devices_ = false;
}

bool CDLTestBase::ExtensionsSupported(const std::vector<const char*>& extensions) {
auto extension_props = physical_device_.enumerateDeviceExtensionProperties();
for (const auto* ext_chars : extensions) {
bool found = false;
std::string_view ext(ext_chars);
for (const auto& prop : extension_props) {
if (ext == prop.extensionName) {
found = true;
break;
}
}

if (!found) {
std::cout << "Device extension " << ext << " is not supported." << std::endl;
return false;
}
}
return true;
}

void CDLTestBase::InitDevice(std::vector<const char*> extensions, const vk::PhysicalDeviceFeatures2* features2) {
if (!*instance_) {
InitInstance();
Expand Down
1 change: 1 addition & 0 deletions tests/framework/test_fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CDLTestBase : public ::testing::Test {
~CDLTestBase() {}
void InitInstance();
void InitDevice(std::vector<const char*> extensions = {}, const vk::PhysicalDeviceFeatures2* features2 = nullptr);
bool ExtensionsSupported(const std::vector<const char*>& extensions);

static void InitArgs(int argc, char* argv[]);

Expand Down
46 changes: 38 additions & 8 deletions tests/unit/ray_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ TEST_F(RayTracing, BuildPositive) {
physical_device_
.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceAccelerationStructurePropertiesKHR>();

InitDevice({"VK_KHR_acceleration_structure", "VK_KHR_deferred_host_operations"}, &features2);
std::vector<const char *> extensions{
VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME,
VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME,
};
if (!ExtensionsSupported(extensions)) {
GTEST_SKIP() << "Required extensions unsupported.";
}
InitDevice(extensions, &features2);

constexpr size_t kNumElems = 256;
constexpr VkDeviceSize kBuffSize = kNumElems * sizeof(float);
Expand Down Expand Up @@ -141,7 +148,14 @@ TEST_F(RayTracing, BuildCrash) {
physical_device_
.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceAccelerationStructurePropertiesKHR>();

InitDevice({"VK_KHR_acceleration_structure", "VK_KHR_deferred_host_operations"}, &features2);
std::vector<const char *> extensions{
VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME,
VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME,
};
if (!ExtensionsSupported(extensions)) {
GTEST_SKIP() << "Required extensions unsupported.";
}
InitDevice(extensions, &features2);

constexpr size_t kNumElems = 256;
constexpr VkDeviceSize kBuffSize = kNumElems * sizeof(float);
Expand Down Expand Up @@ -261,9 +275,17 @@ TEST_F(RayTracing, TraceRaysPositive) {

auto &rt_props = prop_chain.get<vk::PhysicalDeviceRayTracingPipelinePropertiesKHR>();

InitDevice({VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME,
VK_KHR_RAY_QUERY_EXTENSION_NAME, VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME},
&features2);
std::vector<const char *> extensions{
VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME,
VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME,
VK_KHR_RAY_QUERY_EXTENSION_NAME,
VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME,
};
if (!ExtensionsSupported(extensions)) {
GTEST_SKIP() << "Required extensions unsupported.";
}
InitDevice(extensions, &features2);

static const char *minimal = R"glsl(
#version 460
#extension GL_EXT_ray_tracing : require // Requires SPIR-V 1.5 (Vulkan 1.2)
Expand Down Expand Up @@ -335,9 +357,17 @@ TEST_F(RayTracing, TraceRaysCrash) {

auto &rt_props = prop_chain.get<vk::PhysicalDeviceRayTracingPipelinePropertiesKHR>();

InitDevice({VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME,
VK_KHR_RAY_QUERY_EXTENSION_NAME, VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME},
&features2);
std::vector<const char *> extensions{
VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME,
VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME,
VK_KHR_RAY_QUERY_EXTENSION_NAME,
VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME,
};
if (!ExtensionsSupported(extensions)) {
GTEST_SKIP() << "Required extensions unsupported.";
}
InitDevice(extensions, &features2);

static const char *minimal = R"glsl(
#version 460
#extension GL_EXT_ray_tracing : require // Requires SPIR-V 1.5 (Vulkan 1.2)
Expand Down

0 comments on commit 5309ad7

Please sign in to comment.