GPU: Restart when changing inflight frames setting.

We need to keep the push and pull in step, so changing at runtime is
messy.
This commit is contained in:
Unknown W. Brackets 2020-03-02 19:21:15 -08:00
parent fa8968f5c6
commit 051a84e9bd
15 changed files with 44 additions and 24 deletions

View File

@ -774,7 +774,7 @@ static ConfigSetting graphicsSettings[] = {
ConfigSetting("GfxDebugSplitSubmit", &g_Config.bGfxDebugSplitSubmit, false, false, false),
ConfigSetting("LogFrameDrops", &g_Config.bLogFrameDrops, false, true, false),
ConfigSetting("InflightFrames", &g_Config.iInflightFrames, 3, true, true),
ConfigSetting("InflightFrames", &g_Config.iInflightFrames, 3, true, false),
ConfigSetting(false),
};

View File

@ -97,9 +97,6 @@ GPU_GLES::GPU_GLES(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
textureCacheGL_->NotifyConfigChanged();
GLRenderManager *rm = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
rm->SetInflightFrames(g_Config.iInflightFrames);
// Load shader cache.
std::string discID = g_paramSFO.GetDiscID();
if (discID.size()) {
@ -358,9 +355,6 @@ void GPU_GLES::BeginHostFrame() {
GPUCommon::BeginHostFrame();
UpdateCmdInfo();
if (resized_) {
GLRenderManager *rm = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
rm->SetInflightFrames(g_Config.iInflightFrames);
CheckGPUFeatures();
framebufferManager_->Resized();
drawEngine_.Resized();

View File

@ -97,8 +97,6 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
if (vulkan_->GetDeviceFeatures().enabled.wideLines) {
drawEngine_.SetLineWidth(PSP_CoreParameter().renderWidth / 480.0f);
}
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
rm->SetInflightFrames(g_Config.iInflightFrames);
// Load shader cache.
std::string discID = g_paramSFO.GetDiscID();
@ -284,9 +282,6 @@ void GPU_Vulkan::BeginHostFrame() {
UpdateCmdInfo();
if (resized_) {
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
rm->SetInflightFrames(g_Config.iInflightFrames);
CheckGPUFeatures();
// In case the GPU changed.
BuildReportingInfo();

View File

@ -53,6 +53,7 @@ public:
draw_ = Draw::T3DCreateGLContext();
SetGPUBackend(GPUBackend::OPENGL);
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
bool success = draw_->CreatePresets();
_assert_msg_(G3D, success, "Failed to compile preset shaders");
}

View File

@ -74,6 +74,7 @@
GameSettingsScreen::GameSettingsScreen(std::string gamePath, std::string gameID, bool editThenRestore)
: UIDialogScreenWithGameBackground(gamePath), gameID_(gameID), enableReports_(false), editThenRestore_(editThenRestore) {
lastVertical_ = UseVerticalLayout();
prevInflightFrames_ = g_Config.iInflightFrames;
}
bool GameSettingsScreen::UseVerticalLayout() const {
@ -352,10 +353,7 @@ void GameSettingsScreen::CreateViews() {
if (GetGPUBackend() == GPUBackend::VULKAN || GetGPUBackend() == GPUBackend::OPENGL) {
static const char *bufferOptions[] = { "No buffer", "Up to 1", "Up to 2" };
PopupMultiChoice *inflightChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iInflightFrames, gr->T("Buffer graphics commands (faster, input lag)"), bufferOptions, 0, ARRAY_SIZE(bufferOptions), gr->GetName(), screenManager()));
inflightChoice->OnChoice.Add([=](EventParams &e) {
NativeMessageReceived("gpu_resized", "");
return UI::EVENT_CONTINUE;
});
inflightChoice->OnChoice.Handle(this, &GameSettingsScreen::OnInflightFramesChoice);
}
CheckBox *hwTransform = graphicsSettings->Add(new CheckBox(&g_Config.bHardwareTransform, gr->T("Hardware Transform")));
@ -1191,6 +1189,15 @@ void GameSettingsScreen::CallbackRenderingDevice(bool yes) {
}
}
void GameSettingsScreen::CallbackInflightFrames(bool yes) {
if (yes) {
g_Config.Save("GameSettingsScreen::InflightFramesYes");
System_SendMessage("graphics_restart", "");
} else {
g_Config.iInflightFrames = prevInflightFrames_;
}
}
UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) {
auto di = GetI18NCategory("Dialog");
@ -1214,6 +1221,15 @@ UI::EventReturn GameSettingsScreen::OnRenderingDevice(UI::EventParams &e) {
return UI::EVENT_DONE;
}
UI::EventReturn GameSettingsScreen::OnInflightFramesChoice(UI::EventParams &e) {
auto di = GetI18NCategory("Dialog");
if (g_Config.iInflightFrames != prevInflightFrames_) {
screenManager()->push(new PromptScreen(di->T("ChangingInflightFrames", "Changing graphics command buffering requires PPSSPP to restart. Restart now?"), di->T("Yes"), di->T("No"),
std::bind(&GameSettingsScreen::CallbackInflightFrames, this, std::placeholders::_1)));
}
return UI::EVENT_DONE;
}
UI::EventReturn GameSettingsScreen::OnCameraDeviceChange(UI::EventParams& e) {
Camera::onCameraDeviceChange();
return UI::EVENT_DONE;

View File

@ -44,6 +44,7 @@ protected:
void CallbackRestoreDefaults(bool yes);
void CallbackRenderingBackend(bool yes);
void CallbackRenderingDevice(bool yes);
void CallbackInflightFrames(bool yes);
#if PPSSPP_PLATFORM(ANDROID)
void CallbackMemstickFolder(bool yes);
#endif
@ -97,6 +98,7 @@ private:
UI::EventReturn OnRenderingMode(UI::EventParams &e);
UI::EventReturn OnRenderingBackend(UI::EventParams &e);
UI::EventReturn OnRenderingDevice(UI::EventParams &e);
UI::EventReturn OnInflightFramesChoice(UI::EventParams &e);
UI::EventReturn OnCameraDeviceChange(UI::EventParams& e);
UI::EventReturn OnAudioDevice(UI::EventParams &e);
UI::EventReturn OnJitAffectingSetting(UI::EventParams &e);
@ -132,6 +134,7 @@ private:
bool resolutionEnable_;
bool bloomHackEnable_;
bool tessHWEnable_;
int prevInflightFrames_;
#if PPSSPP_PLATFORM(ANDROID)
std::string pendingMemstickFolder_;

View File

@ -403,6 +403,7 @@ bool WindowsGLContext::InitFromRenderThread(std::string *error_message) {
CheckGLExtensions();
draw_ = Draw::T3DCreateGLContext();
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
SetGPUBackend(GPUBackend::OPENGL);
bool success = draw_->CreatePresets(); // if we get this far, there will always be a GLSL compiler capable of compiling these.
_assert_msg_(G3D, success, "Failed to compile preset shaders");

View File

@ -159,6 +159,7 @@ bool WindowsVulkanContext::Init(HINSTANCE hInst, HWND hWnd, std::string *error_m
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, g_Vulkan->GetBackbufferWidth(), g_Vulkan->GetBackbufferHeight());
VulkanRenderManager *renderManager = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager->SetInflightFrames(g_Config.iInflightFrames);
if (!renderManager->HasBackbuffers()) {
Shutdown();
return false;

View File

@ -51,6 +51,7 @@ bool AndroidEGLGraphicsContext::InitFromRenderThread(ANativeWindow *wnd, int des
draw_ = Draw::T3DCreateGLContext();
SetGPUBackend(GPUBackend::OPENGL);
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
bool success = draw_->CreatePresets(); // There will always be a GLSL compiler capable of compiling these.
_assert_msg_(G3D, success, "Failed to compile preset shaders");
return true;

View File

@ -19,6 +19,7 @@ bool AndroidJavaEGLGraphicsContext::InitFromRenderThread(ANativeWindow *wnd, int
g_display_rot_matrix.setIdentity();
draw_ = Draw::T3DCreateGLContext();
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
bool success = draw_->CreatePresets();
_assert_msg_(G3D, success, "Failed to compile preset shaders");
return success;

View File

@ -174,6 +174,7 @@ bool AndroidVulkanContext::InitFromRenderThread(ANativeWindow *wnd, int desiredB
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, g_Vulkan->GetBackbufferWidth(), g_Vulkan->GetBackbufferHeight());
VulkanRenderManager *renderManager = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager->SetInflightFrames(g_Config.iInflightFrames);
success = renderManager->HasBackbuffers();
} else {
success = false;

View File

@ -95,6 +95,12 @@ void GLRenderManager::ThreadStart(Draw::DrawContext *draw) {
threadFrame_ = threadInitFrame_;
renderThreadId = std::this_thread::get_id();
if (newInflightFrames_ != -1) {
ILOG("Updating inflight frames to %d", newInflightFrames_);
inflightFrames_ = newInflightFrames_;
newInflightFrames_ = -1;
}
// Don't save draw, we don't want any thread safety confusion.
bool mapBuffers = draw->GetBugs().Has(Draw::Bugs::ANY_MAP_BUFFER_RANGE_SLOW);
bool hasBufferStorage = gl_extensions.ARB_buffer_storage || gl_extensions.EXT_buffer_storage;
@ -449,10 +455,6 @@ void GLRenderManager::Finish() {
frameData.pull_condVar.notify_all();
curFrame_++;
if (newInflightFrames_ != -1) {
inflightFrames_ = newInflightFrames_;
newInflightFrames_ = -1;
}
if (curFrame_ >= inflightFrames_)
curFrame_ = 0;

View File

@ -202,6 +202,12 @@ void VulkanRenderManager::CreateBackbuffers() {
VLOG("Backbuffers Created");
}
if (newInflightFrames_ != -1) {
ILOG("Updating inflight frames to %d", newInflightFrames_);
vulkan_->UpdateInflightFrames(newInflightFrames_);
newInflightFrames_ = -1;
}
// Start the thread.
if (useThread_ && HasBackbuffers()) {
run_ = true;
@ -914,10 +920,6 @@ void VulkanRenderManager::Finish() {
frameData.pull_condVar.notify_all();
}
vulkan_->EndFrame();
if (newInflightFrames_ != -1) {
vulkan_->UpdateInflightFrames(newInflightFrames_);
newInflightFrames_ = -1;
}
insideFrame_ = false;
}

View File

@ -150,6 +150,7 @@ bool GLDummyGraphicsContext::InitFromRenderThread(std::string *errorMessage) {
CheckGLExtensions();
draw_ = Draw::T3DCreateGLContext();
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
SetGPUBackend(GPUBackend::OPENGL);
bool success = draw_->CreatePresets();
assert(success);

View File

@ -44,6 +44,7 @@ public:
CheckGLExtensions();
draw_ = Draw::T3DCreateGLContext();
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
SetGPUBackend(GPUBackend::OPENGL);
bool success = draw_->CreatePresets();
_assert_msg_(G3D, success, "Failed to compile preset shaders");