Skip to content

Commit 9bb6cd5

Browse files
authored
Make validation errors a test error. (#258)
The current use of the validation layer will emit a message, but it will not cause tests to fail. By adding a call back that returns true for error messages and warnings, test that have a validation error or warning will fail.
1 parent 852c065 commit 9bb6cd5

File tree

6 files changed

+100
-1
lines changed

6 files changed

+100
-1
lines changed

lib/API/VK/Device.cpp

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static VkDescriptorType getDescriptorType(const ResourceKind RK) {
5959
static VkBufferUsageFlagBits getFlagBits(const ResourceKind RK) {
6060
switch (RK) {
6161
case ResourceKind::Buffer:
62+
return VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
6263
case ResourceKind::RWBuffer:
6364
return VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
6465
case ResourceKind::ByteAddressBuffer:
@@ -67,7 +68,7 @@ static VkBufferUsageFlagBits getFlagBits(const ResourceKind RK) {
6768
case ResourceKind::RWStructuredBuffer:
6869
return VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
6970
case ResourceKind::ConstantBuffer:
70-
return VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
71+
return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7172
}
7273
llvm_unreachable("All cases handled");
7374
}
@@ -86,6 +87,73 @@ static bool isUniform(const ResourceKind RK) {
8687
}
8788
llvm_unreachable("All cases handled");
8889
}
90+
91+
static std::string getMessageSeverityString(
92+
VkDebugUtilsMessageSeverityFlagBitsEXT MessageSeverity) {
93+
if (MessageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
94+
return "Error";
95+
if (MessageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
96+
return "Warning";
97+
if (MessageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT)
98+
return "Info";
99+
if (MessageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT)
100+
return "Verbose";
101+
return "Unknown";
102+
}
103+
104+
static VkBool32
105+
debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT MessageSeverity,
106+
VkDebugUtilsMessageTypeFlagsEXT MessageType,
107+
const VkDebugUtilsMessengerCallbackDataEXT *Data, void *) {
108+
// Only interested in messages from the validation layers.
109+
if (!(MessageType & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT))
110+
return VK_FALSE;
111+
112+
llvm::dbgs() << "Validation " << getMessageSeverityString(MessageSeverity);
113+
llvm::dbgs() << ": [ " << Data->pMessageIdName << " ]\n";
114+
llvm::dbgs() << Data->pMessage;
115+
116+
for (uint32_t I = 0; I < Data->objectCount; I++) {
117+
llvm::dbgs() << '\n';
118+
if (Data->pObjects[I].pObjectName) {
119+
llvm::dbgs() << "[" << Data->pObjects[I].pObjectName << "]";
120+
}
121+
}
122+
llvm::dbgs() << '\n';
123+
124+
// Return true to turn the validation error or warning into an error in the
125+
// vulkan API. This should causes tests to fail.
126+
const bool IsErrorOrWarning =
127+
MessageSeverity & (VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT |
128+
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT);
129+
if (IsErrorOrWarning)
130+
return VK_TRUE;
131+
132+
// Continue to run even with VERBOSE and INFO messages.
133+
return VK_FALSE;
134+
}
135+
136+
static VkDebugUtilsMessengerEXT registerDebugUtilCallback(VkInstance Instance) {
137+
VkDebugUtilsMessengerCreateInfoEXT CreateInfo = {};
138+
CreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
139+
CreateInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
140+
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
141+
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
142+
CreateInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
143+
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
144+
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
145+
CreateInfo.pfnUserCallback = debugCallback;
146+
CreateInfo.pUserData = nullptr; // Optional
147+
auto Func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
148+
Instance, "vkCreateDebugUtilsMessengerEXT");
149+
if (Func == nullptr)
150+
return VK_NULL_HANDLE;
151+
152+
VkDebugUtilsMessengerEXT DebugMessenger;
153+
Func(Instance, &CreateInfo, nullptr, &DebugMessenger);
154+
return DebugMessenger;
155+
}
156+
89157
namespace {
90158

91159
class VKDevice : public offloadtest::Device {
@@ -800,6 +868,7 @@ class VKDevice : public offloadtest::Device {
800868
class VKContext {
801869
private:
802870
VkInstance Instance = VK_NULL_HANDLE;
871+
VkDebugUtilsMessengerEXT DebugMessenger = VK_NULL_HANDLE;
803872
llvm::SmallVector<std::shared_ptr<VKDevice>> Devices;
804873

805874
VKContext() = default;
@@ -813,6 +882,13 @@ class VKContext {
813882
}
814883

815884
void cleanup() {
885+
#ifndef NDEBUG
886+
auto Func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
887+
Instance, "vkDestroyDebugUtilsMessengerEXT");
888+
if (Func != nullptr) {
889+
Func(Instance, DebugMessenger, nullptr);
890+
}
891+
#endif
816892
vkDestroyInstance(Instance, NULL);
817893
Instance = VK_NULL_HANDLE;
818894
}
@@ -860,6 +936,10 @@ class VKContext {
860936
const char *ValidationLayer = "VK_LAYER_KHRONOS_validation";
861937
CreateInfo.ppEnabledLayerNames = &ValidationLayer;
862938
CreateInfo.enabledLayerCount = 1;
939+
940+
const char *DebugUtilsExtensionName = "VK_EXT_debug_utils";
941+
CreateInfo.ppEnabledExtensionNames = &DebugUtilsExtensionName;
942+
CreateInfo.enabledExtensionCount = 1;
863943
#endif
864944

865945
Res = vkCreateInstance(&CreateInfo, NULL, &Instance);
@@ -871,6 +951,10 @@ class VKContext {
871951
"Unknown Vulkan initialization error %d",
872952
Res);
873953

954+
#ifndef NDEBUG
955+
DebugMessenger = registerDebugUtilCallback(Instance);
956+
#endif
957+
874958
DeviceCount = 0;
875959
if (vkEnumeratePhysicalDevices(Instance, &DeviceCount, nullptr))
876960
return llvm::createStringError(std::errc::no_such_device,

test/Basic/TestPipeline.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ DescriptorSets:
4040
...
4141
#--- end
4242

43+
# Tracking issue: https://github.com/llvm/llvm-project/issues/144580
44+
# XFAIL: Clang-Vulkan
45+
4346
# RUN: split-file %s %t
4447
# RUN: %dxc_target -T cs_6_0 -E CSMain -Fo %t.o %t/source.hlsl
4548
# RUN: %offloader %t/pipeline.yaml %t.o | FileCheck %s

test/Feature/WaveOps/WaveActiveAllTrue.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ DescriptorSets:
6363
...
6464
#--- end
6565

66+
# https://github.com/llvm/llvm-project/issues/145513
67+
# XFAIL: Clang-Vulkan
68+
6669
# RUN: split-file %s %t
6770
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
6871
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/WaveOps/WaveActiveAnyTrue.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ DescriptorSets:
6262
...
6363
#--- end
6464

65+
# https://github.com/llvm/llvm-project/issues/145513
66+
# XFAIL: Clang-Vulkan
67+
6568
# RUN: split-file %s %t
6669
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
6770
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/WaveOps/WaveActiveCountBits.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ DescriptorSets:
6464
...
6565
#--- end
6666

67+
# https://github.com/llvm/llvm-project/issues/145513
68+
# XFAIL: Clang-Vulkan
69+
6770
# RUN: split-file %s %t
6871
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
6972
# RUN: %offloader %t/pipeline.yaml %t.o

test/Feature/WaveOps/WaveIsFirstLane.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ DescriptorSets:
6161
...
6262
#--- end
6363

64+
# https://github.com/llvm/llvm-project/issues/145513
65+
# XFAIL: Clang-Vulkan
66+
6467
# RUN: split-file %s %t
6568
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
6669
# RUN: %offloader %t/pipeline.yaml %t.o

0 commit comments

Comments
 (0)