Skip to content

Commit

Permalink
Deal with some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
krOoze committed Apr 23, 2020
1 parent e0dc8e4 commit d2df2ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
27 changes: 14 additions & 13 deletions src/ErrorHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct VulkanResultException{
// just use cout for logging now
std::ostream& logger = std::cout;

enum Highlight{ highlightOff = 0, highlightOn };
enum class Highlight{ off, on };
void genericDebugCallback( std::string flags, Highlight highlight, std::string msgCode, std::string object, const char* message );

VKAPI_ATTR VkBool32 VKAPI_CALL genericDebugReportCallback(
Expand All @@ -51,15 +51,16 @@ VKAPI_ATTR VkBool32 VKAPI_CALL genericDebugUtilsCallback(
void* /*pUserData*/
);

enum class DebugObjectType{ debugReport, debugUtils } tag;
struct DebugObjectVariant{
enum DebugObjectTag{ debugReportType, debugUtilsType } tag;
DebugObjectType tag;
union{
VkDebugReportCallbackEXT debugReportCallback;
VkDebugUtilsMessengerEXT debugUtilsMessenger;
};
};

DebugObjectVariant initDebug( const VkInstance instance, const DebugObjectVariant::DebugObjectTag debugExtension, const VkDebugUtilsMessageSeverityFlagsEXT debugSeverity, const VkDebugUtilsMessageTypeFlagsEXT debugType );
DebugObjectVariant initDebug( const VkInstance instance, const DebugObjectType debugExtension, const VkDebugUtilsMessageSeverityFlagsEXT debugSeverity, const VkDebugUtilsMessageTypeFlagsEXT debugType );
void killDebug( VkInstance instance, DebugObjectVariant debug );

VkDebugReportFlagsEXT translateFlags( const VkDebugUtilsMessageSeverityFlagsEXT debugSeverity, const VkDebugUtilsMessageTypeFlagsEXT debugType );
Expand All @@ -73,7 +74,7 @@ void genericDebugCallback( std::string flags, Highlight highlight, std::string m

const string report = flags + ": " + object + ": " + msgCode + ", \"" + message + '"';

if( highlight ){
if( highlight != Highlight::off ){
const string border( 80, '!' );

logger << border << endl;
Expand All @@ -100,9 +101,9 @@ VKAPI_ATTR VkBool32 VKAPI_CALL genericDebugReportCallback(

Highlight highlight;
if( (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) || (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) || (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) ){
highlight = highlightOn;
highlight = Highlight::on;
}
else highlight = highlightOff;
else highlight = Highlight::off;


genericDebugCallback( dbrflags_to_string( flags ), highlight, string(pLayerPrefix) + ", " + to_string( messageCode ), to_string( objectType ) + "(" + to_string_hex( object ) + ")", pMessage );
Expand All @@ -121,9 +122,9 @@ VKAPI_ATTR VkBool32 VKAPI_CALL genericDebugUtilsCallback(

Highlight highlight;
if( (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) || (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)){
highlight = highlightOn;
highlight = Highlight::on;
}
else highlight = highlightOff;
else highlight = Highlight::off;

string objects;
bool first = true;
Expand Down Expand Up @@ -154,11 +155,11 @@ VkDebugReportFlagsEXT translateFlags( const VkDebugUtilsMessageSeverityFlagsEXT
return flags;
}

DebugObjectVariant initDebug( const VkInstance instance, const DebugObjectVariant::DebugObjectTag debugExtension, const VkDebugUtilsMessageSeverityFlagsEXT debugSeverity, const VkDebugUtilsMessageTypeFlagsEXT debugType ){
DebugObjectVariant initDebug( const VkInstance instance, const DebugObjectType debugExtension, const VkDebugUtilsMessageSeverityFlagsEXT debugSeverity, const VkDebugUtilsMessageTypeFlagsEXT debugType ){
DebugObjectVariant debug;
debug.tag = debugExtension;

if( debugExtension == DebugObjectVariant::debugUtilsType ){
if( debugExtension == DebugObjectType::debugUtils ){
const VkDebugUtilsMessengerCreateInfoEXT dmci = {
VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
nullptr, // pNext
Expand All @@ -171,7 +172,7 @@ DebugObjectVariant initDebug( const VkInstance instance, const DebugObjectVarian

const VkResult errorCode = vkCreateDebugUtilsMessengerEXT( instance, &dmci, nullptr, &debug.debugUtilsMessenger ); RESULT_HANDLER( errorCode, "vkCreateDebugUtilsMessengerEXT" );
}
else if( debugExtension == DebugObjectVariant::debugReportType ){
else if( debugExtension == DebugObjectType::debugReport ){
const VkDebugReportCallbackCreateInfoEXT debugCreateInfo{
VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
nullptr, // pNext
Expand All @@ -190,10 +191,10 @@ DebugObjectVariant initDebug( const VkInstance instance, const DebugObjectVarian
}

void killDebug( const VkInstance instance, const DebugObjectVariant debug ){
if( debug.tag == DebugObjectVariant::debugUtilsType ){
if( debug.tag == DebugObjectType::debugUtils ){
vkDestroyDebugUtilsMessengerEXT( instance, debug.debugUtilsMessenger, nullptr );
}
else if( debug.tag == DebugObjectVariant::debugReportType ){
else if( debug.tag == DebugObjectType::debugReport ){
vkDestroyDebugReportCallbackEXT( instance, debug.debugReportCallback, nullptr );
}
else{
Expand Down
10 changes: 5 additions & 5 deletions src/HelloTriangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ int helloTriangle() try{
};

#if VULKAN_VALIDATION
DebugObjectVariant::DebugObjectTag debugExtensionTag;
DebugObjectType debugExtensionTag;
if( isExtensionSupported( VK_EXT_DEBUG_UTILS_EXTENSION_NAME, supportedInstanceExtensions ) ){
debugExtensionTag = DebugObjectVariant::debugUtilsType;
debugExtensionTag = DebugObjectType::debugUtils;
requestedInstanceExtensions.push_back( VK_EXT_DEBUG_UTILS_EXTENSION_NAME );
}
else if( isExtensionSupported( VK_EXT_DEBUG_REPORT_EXTENSION_NAME, supportedInstanceExtensions ) ){
debugExtensionTag = DebugObjectVariant::debugReportType;
debugExtensionTag = DebugObjectType::debugReport;
requestedInstanceExtensions.push_back( VK_EXT_DEBUG_REPORT_EXTENSION_NAME );
}
else throw "VULKAN_VALIDATION is enabled but neither VK_EXT_debug_utils nor VK_EXT_debug_report extension is supported!";
Expand All @@ -297,7 +297,7 @@ int helloTriangle() try{

const int32_t uncoded = 0;
const char* introMsg = "Validation Layers are enabled!";
if( debugExtensionTag == DebugObjectVariant::debugUtilsType ){
if( debugExtensionTag == DebugObjectType::debugUtils ){
VkDebugUtilsObjectNameInfoEXT object = {
VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
nullptr, // pNext
Expand All @@ -317,7 +317,7 @@ int helloTriangle() try{
};
vkSubmitDebugUtilsMessageEXT( instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT, VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT, &dumcd );
}
else if( debugExtensionTag == DebugObjectVariant::debugReportType ){
else if( debugExtensionTag == DebugObjectType::debugReport ){
vkDebugReportMessageEXT( instance, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, (uint64_t)instance, __LINE__, uncoded, "Application", introMsg );
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/VulkanEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,4 @@
//#error "Unsupported OS platform." // caught in main.cpp instead
#endif

TODO( "Add other (all would be awesome) platforms" )

#endif //COMMON_VULKAN_ENVIRONMENT_H

0 comments on commit d2df2ec

Please sign in to comment.