Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
Henrik Rydgård
f6cc10f532 Vulkan: Fix device selection in the SDL path 2020-06-27 10:12:58 +02:00
Henrik Rydgård
3b980eb442 Improve some logging, and print the line number from PanicAlerts. 2020-06-27 09:41:48 +02:00
7 changed files with 27 additions and 25 deletions

View file

@ -24,9 +24,9 @@
#include "base/logging.h"
#include "util/text/utf8.h"
bool MsgHandler(const char *caption, const char *text, bool yes_no, int Style);
bool MsgHandler(const char *caption, const char *text, const char *file, int line, bool yes_no, int Style);
bool MsgAlert(bool yes_no, int Style, const char* format, ...) {
bool MsgAlert(bool yes_no, int Style, const char *file, int line, const char* format, ...) {
// Read message and write it to the log
char buffer[2048];
static const char *captions[] = {
@ -42,10 +42,10 @@ bool MsgAlert(bool yes_no, int Style, const char* format, ...) {
CharArrayFromFormatV(buffer, sizeof(buffer)-1, format, args);
va_end(args);
// Normal logging (will also log to Android log)
ERROR_LOG(SYSTEM, "%s: %s", caption, buffer);
ERROR_LOG(SYSTEM, "(%s:%d) %s: %s", file, line, caption, buffer);
// Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored
if (Style == QUESTION || Style == CRITICAL)
return MsgHandler(caption, buffer, yes_no, Style);
return MsgHandler(caption, buffer, file, line, yes_no, Style);
return true;
}
@ -54,7 +54,7 @@ bool MsgAlert(bool yes_no, int Style, const char* format, ...) {
#endif
// Default non library dependent panic alert
bool MsgHandler(const char* caption, const char* text, bool yes_no, int Style) {
bool MsgHandler(const char* caption, const char* text, const char *file, int line, bool yes_no, int Style) {
#if defined(USING_WIN_UI)
int msgBoxStyle = MB_ICONINFORMATION;
if (Style == QUESTION) msgBoxStyle = MB_ICONQUESTION;
@ -69,7 +69,7 @@ bool MsgHandler(const char* caption, const char* text, bool yes_no, int Style) {
return false;
#else
// Will use android-log if available, printf if not.
ELOG("%s", text);
ELOG("(%s:%d) %s", file, line, text);
return false;
#endif
}

View file

@ -25,13 +25,13 @@ enum MSG_TYPE {
CRITICAL
};
bool MsgAlert(bool yes_no, int Style, const char* format, ...)
bool MsgAlert(bool yes_no, int Style, const char *file, int line, const char* format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 3, 4)))
__attribute__((format(printf, 5, 6)))
#endif
;
#define PanicAlert(...) MsgAlert(false, WARNING, __VA_ARGS__)
#define PanicAlert(...) MsgAlert(false, WARNING, __FILE__, __LINE__, __VA_ARGS__)
// Used only for asserts.
#define PanicYesNo(...) MsgAlert(true, CRITICAL, __VA_ARGS__)
#define PanicYesNo(...) MsgAlert(true, CRITICAL, __FILE__, __LINE__, __VA_ARGS__)

View file

@ -619,7 +619,8 @@ bool VulkanContext::EnableDeviceExtension(const char *extension) {
VkResult VulkanContext::CreateDevice() {
if (!init_error_.empty() || physical_device_ < 0) {
ELOG("Vulkan init failed: %s", init_error_.c_str());
// Forgot to call ChooseDevice?
ELOG("Vulkan init of physical device %d failed: %s", physical_device_, init_error_.c_str());
return VK_ERROR_INITIALIZATION_FAILED;
}

View file

@ -413,6 +413,7 @@ bool VulkanMayBeAvailable() {
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
ILOG("VulkanMayBeAvailable: Found usable device: '%s'", props.deviceName);
anyGood = true;
break;
default:

View file

@ -793,7 +793,7 @@ int main(int argc, char *argv[]) {
g_Config.bFullScreen = fullscreen;
// Hide/Show cursor correctly toggling fullscreen
if (lastUIState == UISTATE_INGAME && fullscreen && !g_Config.bShowTouchControls) {
if (lastUIState == UISTATE_INGAME && fullscreen && !g_Config.bShowTouchControls && !g_Config.bShowDeveloperMenu) {
SDL_ShowCursor(SDL_DISABLE);
} else if (lastUIState != UISTATE_INGAME || !fullscreen) {
SDL_ShowCursor(SDL_ENABLE);

View file

@ -56,7 +56,15 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode,
vulkan_ = nullptr;
return false;
}
vulkan_->ChooseDevice(vulkan_->GetBestPhysicalDevice());
int deviceNum = vulkan_->GetPhysicalDeviceByName(g_Config.sVulkanDevice);
if (deviceNum < 0) {
deviceNum = vulkan_->GetBestPhysicalDevice();
if (!g_Config.sVulkanDevice.empty())
g_Config.sVulkanDevice = vulkan_->GetPhysicalDeviceProperties(deviceNum).properties.deviceName;
}
vulkan_->ChooseDevice(deviceNum);
if (vulkan_->CreateDevice() != VK_SUCCESS) {
*error_message = vulkan_->InitError();
delete vulkan_;
@ -65,7 +73,7 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode,
}
SDL_SysWMinfo sys_info{};
SDL_VERSION(&sys_info.version); //Set SDL version
SDL_VERSION(&sys_info.version); // Set SDL version
if (!SDL_GetWindowWMInfo(window, &sys_info)) {
fprintf(stderr, "Error getting SDL window wm info: %s\n", SDL_GetError());
exit(1);

View file

@ -1033,7 +1033,7 @@ void VulkanRenderManager::BeginSubmitFrame(int frame) {
WLOG("VK_SUBOPTIMAL_KHR returned - ignoring");
outOfDateFrames_++;
} else if (res == VK_ERROR_OUT_OF_DATE_KHR) {
WLOG("VK_ERROR_OUT_OF_DATE_KHR returned - not presenting");
WLOG("VK_ERROR_OUT_OF_DATE_KHR returned - processing the frame, but not presenting");
frameData.skipSwap = true;
outOfDateFrames_++;
} else {
@ -1079,11 +1079,7 @@ void VulkanRenderManager::Submit(int frame, bool triggerFence) {
submit_info.pCommandBuffers = cmdBufs;
res = vkQueueSubmit(vulkan_->GetGraphicsQueue(), 1, &submit_info, VK_NULL_HANDLE);
if (res == VK_ERROR_DEVICE_LOST) {
#ifdef _WIN32
_assert_msg_(G3D, false, "Lost the Vulkan device! If this happens again, switch Graphics Backend from Vulkan to Direct3D11");
#else
_assert_msg_(G3D, false, "Lost the Vulkan device! If this happens again, switch Graphics Backend from Vulkan to OpenGL");
#endif
_assert_msg_(G3D, false, "Lost the Vulkan device in split submit! If this happens again, switch Graphics Backend away from Vulkan");
} else {
_assert_msg_(G3D, res == VK_SUCCESS, "vkQueueSubmit failed (init)! result=%s", VulkanResultToString(res));
}
@ -1107,11 +1103,7 @@ void VulkanRenderManager::Submit(int frame, bool triggerFence) {
}
res = vkQueueSubmit(vulkan_->GetGraphicsQueue(), 1, &submit_info, triggerFence ? frameData.fence : VK_NULL_HANDLE);
if (res == VK_ERROR_DEVICE_LOST) {
#ifdef _WIN32
_assert_msg_(G3D, false, "Lost the Vulkan device! If this happens again, switch Graphics Backend from Vulkan to Direct3D11");
#else
_assert_msg_(G3D, false, "Lost the Vulkan device! If this happens again, switch Graphics Backend from Vulkan to OpenGL");
#endif
_assert_msg_(G3D, false, "Lost the Vulkan device in vkQueueSubmit! If this happens again, switch Graphics Backend away from Vulkan");
} else {
_assert_msg_(G3D, res == VK_SUCCESS, "vkQueueSubmit failed (main, split=%d)! result=%s", (int)splitSubmit_, VulkanResultToString(res));
}