OpenGL ES: Crash as early as possible if things are bad

There's a huge variety of crash report in the Play Console of various
opengl failures. Try to concentrate them to early points in
initialization
This commit is contained in:
Henrik Rydgård 2022-07-25 12:22:50 +02:00
parent 094666ef4b
commit dd0409d68c
4 changed files with 33 additions and 7 deletions

View File

@ -10,6 +10,7 @@
#include "Common/Data/Convert/SmallDataConvert.h"
#include "Common/Math/math_util.h"
#include "Common/Math/lin/matrix4x4.h"
#include "Common/Log.h"
#include "Common/GPU/thin3d.h"
#include "Common/GPU/Shader.h"
#include "Common/GPU/OpenGL/DataFormatGL.h"
@ -249,9 +250,13 @@ bool OpenGLShaderModule::Compile(GLRenderManager *render, ShaderLanguage languag
if (source_.find("#version") == source_.npos) {
source_ = ApplyGLSLPrelude(source_, glstage_);
}
} else {
// Unsupported shader type
return false;
}
shader_ = render->CreateShader(glstage_, source_, tag_);
_assert_(shader_ != nullptr); // normally can't fail since we defer creation, unless there's a memory error or similar.
return true;
}
@ -276,7 +281,9 @@ public:
for (auto &iter : shaders) {
iter->Release();
}
if (program_) render_->DeleteProgram(program_);
if (program_) {
render_->DeleteProgram(program_);
}
}
bool LinkShaders();

View File

@ -934,6 +934,16 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) {
bool CreateGlobalPipelines() {
using namespace Draw;
ShaderModule *vs_color_2d = g_draw->GetVshaderPreset(VS_COLOR_2D);
ShaderModule *fs_color_2d = g_draw->GetFshaderPreset(FS_COLOR_2D);
ShaderModule *vs_texture_color_2d = g_draw->GetVshaderPreset(VS_TEXTURE_COLOR_2D);
ShaderModule *fs_texture_color_2d = g_draw->GetFshaderPreset(FS_TEXTURE_COLOR_2D);
if (!vs_color_2d || !fs_color_2d || !vs_texture_color_2d || !fs_texture_color_2d) {
ERROR_LOG(G3D, "Failed to get shader preset");
return false;
}
InputLayout *inputLayout = ui_draw2d.CreateInputLayout(g_draw);
BlendState *blendNormal = g_draw->CreateBlendState({ true, 0xF, BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA });
DepthStencilState *depth = g_draw->CreateDepthStencilState({ false, false, Comparison::LESS });
@ -941,12 +951,12 @@ bool CreateGlobalPipelines() {
PipelineDesc colorDesc{
Primitive::TRIANGLE_LIST,
{ g_draw->GetVshaderPreset(VS_COLOR_2D), g_draw->GetFshaderPreset(FS_COLOR_2D) },
{ vs_color_2d, fs_color_2d },
inputLayout, depth, blendNormal, rasterNoCull, &vsColBufDesc,
};
PipelineDesc texColorDesc{
Primitive::TRIANGLE_LIST,
{ g_draw->GetVshaderPreset(VS_TEXTURE_COLOR_2D), g_draw->GetFshaderPreset(FS_TEXTURE_COLOR_2D) },
{ vs_texture_color_2d, fs_texture_color_2d },
inputLayout, depth, blendNormal, rasterNoCull, &vsTexColBufDesc,
};

View File

@ -13,13 +13,18 @@ AndroidJavaEGLGraphicsContext::AndroidJavaEGLGraphicsContext() {
bool AndroidJavaEGLGraphicsContext::InitFromRenderThread(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) {
INFO_LOG(G3D, "AndroidJavaEGLGraphicsContext::InitFromRenderThread");
CheckGLExtensions();
// OpenGL handles rotated rendering in the driver.
g_display_rotation = DisplayRotation::ROTATE_0;
g_display_rot_matrix.setIdentity();
draw_ = Draw::T3DCreateGLContext(); // Can't fail
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
draw_->CreatePresets();
if (!draw_->CreatePresets()) {
_assert_msg_(false, "Failed to compile preset shaders");
return false;
}
return true;
}

View File

@ -13,9 +13,8 @@
#include <thread>
#include <atomic>
#include <android/log.h>
#ifndef _MSC_VER
#include <jni.h>
#include <android/native_window_jni.h>
#include <android/log.h>
@ -286,7 +285,12 @@ static void EmuThreadFunc() {
} else {
INFO_LOG(SYSTEM, "Runloop: Graphics context available! %p", graphicsContext);
}
NativeInitGraphics(graphicsContext);
if (!NativeInitGraphics(graphicsContext)) {
_assert_msg_(false, "Failed to initialize graphics, might as well bail");
emuThreadState = (int)EmuThreadState::QUIT_REQUESTED;
return;
}
INFO_LOG(SYSTEM, "Graphics initialized. Entering loop.");