Skip to content

Commit 59c48ee

Browse files
committed
loongarch: Switch to software render when using LG100 series
1 parent 071df07 commit 59c48ee

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/render/SDL_render.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
#include "software/SDL_render_sw_c.h"
3030
#include "../video/SDL_pixels_c.h"
3131

32+
#if defined(__loongarch__)
33+
#if SDL_VIDEO_OPENGL
34+
#include "SDL_opengl.h"
35+
#endif /* SDL_VIDEO_OPENGL */
36+
#endif
37+
3238
#if defined(__ANDROID__)
3339
#include "../core/android/SDL_android.h"
3440
#endif
@@ -954,6 +960,34 @@ static void SDL_CalculateSimulatedVSyncInterval(SDL_Renderer *renderer, SDL_Wind
954960
}
955961
#endif /* !SDL_RENDER_DISABLED */
956962

963+
#if defined(__loongarch__)
964+
static SDL_bool SDL_CheckIntegratedGraphics()
965+
{
966+
SDL_Window *window = SDL_CreateWindow("OpenGL test", -32, -32, 32, 32,
967+
SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
968+
SDL_bool has_lg100_or_lg110 = SDL_FALSE;
969+
970+
if (window) {
971+
SDL_GLContext context = SDL_GL_CreateContext(window);
972+
973+
if (context) {
974+
const GLubyte *(APIENTRY *glGetStringFunc)(GLenum) =
975+
SDL_GL_GetProcAddress("glGetString");
976+
if (glGetStringFunc) {
977+
const char *renderer = (const char*)glGetStringFunc(GL_RENDERER);
978+
if (renderer && (SDL_strstr(renderer, "LG110") ||
979+
SDL_strstr(renderer, "LG100"))) {
980+
has_lg100_or_lg110 = SDL_TRUE;
981+
}
982+
}
983+
SDL_GL_DeleteContext(context);
984+
}
985+
SDL_DestroyWindow(window);
986+
}
987+
return has_lg100_or_lg110;
988+
}
989+
#endif
990+
957991
SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
958992
{
959993
#ifndef SDL_RENDER_DISABLED
@@ -967,6 +1001,14 @@ SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
9671001
Android_ActivityMutex_Lock_Running();
9681002
#endif
9691003

1004+
/* CPU acceleration runs faster than integrated graphics on Loongson at present. */
1005+
#if defined(__linux__) && defined(__loongarch__)
1006+
if (SDL_CheckIntegratedGraphics()) {
1007+
SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0");
1008+
flags = SDL_RENDERER_SOFTWARE;
1009+
}
1010+
#endif
1011+
9701012
if (!window) {
9711013
SDL_InvalidParamError("window");
9721014
goto error;

0 commit comments

Comments
 (0)