Permalink
Browse files

Vulkan: Improve init/shutdown logging on Android. Fix a bug where we'…

…d not run InitDeviceObjects on GPU_Vulkan sometimes.
  • Loading branch information...
hrydgard committed Nov 9, 2017
1 parent cd55e9d commit ec504756e03bbe5e68a83ccdbb857b39d75dfe7a
@@ -165,8 +165,13 @@ VkResult VulkanContext::CreateInstance(const char *app_name, int app_ver, uint32
}
VulkanContext::~VulkanContext() {
assert(instance_ == VK_NULL_HANDLE);
}
void VulkanContext::DestroyInstance() {
vkDestroyInstance(instance_, nullptr);
VulkanFree();
instance_ = VK_NULL_HANDLE;
}
void VulkanContext::BeginFrame() {
@@ -797,6 +802,7 @@ VkFence VulkanContext::CreateFence(bool presignalled) {
}
void VulkanContext::DestroyDevice() {
ILOG("VulkanContext::DestroyDevice (performing deletes)");
// If there happen to be any pending deletes, now is a good time.
for (int i = 0; i < ARRAY_SIZE(frame_); i++) {
frame_[i].deleteList.PerformDeletes(device_);
@@ -214,7 +214,8 @@ class VulkanContext {
~VulkanContext();
VkResult CreateInstance(const char *app_name, int app_ver, uint32_t flags);
void DestroyInstance();
int GetBestPhysicalDevice();
void ChooseDevice(int physical_device);
bool EnableDeviceExtension(const char *extension);
@@ -781,13 +781,16 @@ void GPU_Vulkan::FastLoadBoneMatrix(u32 target) {
}
void GPU_Vulkan::InitDeviceObjects() {
ILOG("GPU_Vulkan::InitDeviceObjects");
// Initialize framedata
for (int i = 0; i < VulkanContext::MAX_INFLIGHT_FRAMES; i++) {
assert(!frameData_[i].push_);
frameData_[i].push_ = new VulkanPushBuffer(vulkan_, 64 * 1024);
}
}
void GPU_Vulkan::DestroyDeviceObjects() {
ILOG("GPU_Vulkan::DestroyDeviceObjects");
for (int i = 0; i < VulkanContext::MAX_INFLIGHT_FRAMES; i++) {
if (frameData_[i].push_) {
frameData_[i].push_->Destroy(vulkan_);
@@ -810,6 +813,8 @@ void GPU_Vulkan::DeviceLost() {
void GPU_Vulkan::DeviceRestore() {
vulkan_ = (VulkanContext *)PSP_CoreParameter().graphicsContext->GetAPIContext();
InitDeviceObjects();
CheckGPUFeatures();
BuildReportingInfo();
UpdateCmdInfo();
View
@@ -1104,12 +1104,16 @@ void EmuScreen::deviceLost() {
ILOG("EmuScreen::deviceLost()");
if (gpu)
gpu->DeviceLost();
else
ILOG("No gpu to deviceLost!");
}
void EmuScreen::deviceRestore() {
ILOG("EmuScreen::deviceRestore()");
if (gpu)
gpu->DeviceRestore();
else
ILOG("No gpu to deviceRestore!");
RecreateViews();
}
@@ -218,6 +218,8 @@ void WindowsVulkanContext::Shutdown() {
g_Vulkan->DestroyObjects();
g_Vulkan->DestroyDevice();
g_Vulkan->DestroyDebugMsgCallback();
g_Vulkan->DestroyInstance();
delete g_Vulkan;
g_Vulkan = nullptr;
@@ -189,6 +189,11 @@ static VulkanContext *g_Vulkan;
class AndroidVulkanContext : public AndroidGraphicsContext {
public:
AndroidVulkanContext() : draw_(nullptr) {}
~AndroidVulkanContext() {
delete g_Vulkan;
g_Vulkan = nullptr;
}
bool Init(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) override;
void Shutdown() override;
void SwapInterval(int interval) override;
@@ -270,10 +275,7 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL Vulkan_Dbg(VkDebugReportFlagsEXT msgFlags,
}
bool AndroidVulkanContext::Init(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) {
if (g_Vulkan) {
return false;
}
ILOG("AndroidVulkanContext::Init");
init_glslang();
g_LogOptions.breakOnError = true;
@@ -282,7 +284,10 @@ bool AndroidVulkanContext::Init(ANativeWindow *wnd, int desiredBackbufferSizeX,
ILOG("Creating vulkan context");
Version gitVer(PPSSPP_GIT_VERSION);
g_Vulkan = new VulkanContext();
if (!g_Vulkan) {
g_Vulkan = new VulkanContext();
}
if (VK_SUCCESS != g_Vulkan->CreateInstance("PPSSPP", gitVer.ToInteger(), VULKAN_FLAG_PRESENT_MAILBOX | VULKAN_FLAG_PRESENT_FIFO_RELAXED)) {
ELOG("Failed to create vulkan context: %s", g_Vulkan->InitError().c_str());
delete g_Vulkan;
@@ -326,6 +331,7 @@ bool AndroidVulkanContext::Init(ANativeWindow *wnd, int desiredBackbufferSizeX,
bool success = draw_->CreatePresets(); // Doesn't fail, we ship the compiler.
assert(success);
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, g_Vulkan->GetBackbufferWidth(), g_Vulkan->GetBackbufferHeight());
ILOG("AndroidVulkanContext::Init completed");
return true;
}
@@ -337,26 +343,31 @@ void AndroidVulkanContext::Shutdown() {
NativeShutdownGraphics();
g_Vulkan->WaitUntilQueueIdle();
g_Vulkan->DestroyObjects();
g_Vulkan->DestroyDebugMsgCallback();
g_Vulkan->DestroyDevice();
g_Vulkan->DestroyDebugMsgCallback();
g_Vulkan->DestroyInstance();
delete g_Vulkan;
g_Vulkan = nullptr;
// We keep the g_Vulkan context around to avoid invalidating a ton of pointers around the app.
finalize_glslang();
ILOG("AndroidVulkanContext::Shutdown completed");
}
void AndroidVulkanContext::SwapBuffers() {
}
void AndroidVulkanContext::Resize() {
ILOG("AndroidVulkanContext::Resize begin");
draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER, g_Vulkan->GetBackbufferWidth(), g_Vulkan->GetBackbufferHeight());
g_Vulkan->DestroyObjects();
// backbufferResize updated these values. TODO: Notify another way?
g_Vulkan->ReinitSurfaceAndroid(pixel_xres, pixel_yres);
g_Vulkan->InitObjects();
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, g_Vulkan->GetBackbufferWidth(), g_Vulkan->GetBackbufferHeight());
ILOG("AndroidVulkanContext::Resize end");
}
void AndroidVulkanContext::SwapInterval(int interval) {
@@ -1124,7 +1135,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
ProcessFrameCommands(env);
}
ILOG("After render loop.");
ILOG("Leaving EGL/Vulkan render loop.");
g_gameInfoCache->WorkQueue()->Flush();
NativeDeviceLost();
@@ -647,10 +647,10 @@ protected void onPause() {
loseAudioFocus(this.audioManager, this.audioFocusChangeListener);
NativeApp.pause();
if (!javaGL) {
Log.i(TAG, "Pausing surface view");
mSurfaceView.onPause();
Log.i(TAG, "Joining render thread");
Log.i(TAG, "Joining render thread...");
joinRenderLoopThread();
Log.i(TAG, "Joined render thread");
} else {
if (mGLSurfaceView != null) {
mGLSurfaceView.onPause();

0 comments on commit ec50475

Please sign in to comment.