Skip to content

Commit 7bf23d1

Browse files
committed
Enable hardware gpu
1 parent 2109047 commit 7bf23d1

10 files changed

Lines changed: 38 additions & 11 deletions

File tree

Common/GPU/OpenGL/GLCommon.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#if PPSSPP_PLATFORM(IOS)
66
#include <OpenGLES/ES3/gl.h>
77
#include <OpenGLES/ES3/glext.h>
8+
#elif defined(__EMSCRIPTEN__)
9+
#include <GLES3/gl3.h>
10+
#include <GLES2/gl2ext.h>
11+
#define GL_BGRA_EXT 0x80E1
812
#elif defined(USING_GLES2)
913
#include <GLES2/gl2.h>
1014
#include <GLES2/gl2ext.h>

Common/GPU/OpenGL/GLMemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void *GLRBuffer::Map(GLBufferStrategy strategy) {
3232
if (!hasStorage_) {
3333
GLbitfield storageFlags = access & ~(GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
3434
#ifdef USING_GLES2
35-
#ifdef GL_EXT_buffer_storage
35+
#if defined(GL_EXT_buffer_storage) && !defined(__EMSCRIPTEN__)
3636
glBufferStorageEXT(target_, size_, nullptr, storageFlags);
3737
#endif
3838
#else

Common/GPU/OpenGL/GLProfiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ void GLProfiler::BeginFrame() {
121121
}
122122

123123
GLuint64 startTime = 0, endTime = 0;
124+
#ifndef __EMSCRIPTEN__
124125
glGetQueryObjectui64v(queries_[scope.startQueryId], GL_QUERY_RESULT, &startTime);
125126
glGetQueryObjectui64v(queries_[scope.endQueryId], GL_QUERY_RESULT, &endTime);
127+
#endif
126128

127129
// Times are in nanoseconds, convert to milliseconds
128130
double milliseconds = (double)(endTime - startTime) / 1000000.0;
@@ -154,7 +156,9 @@ void GLProfiler::Begin(const char *fmt, ...) {
154156
scopeStack_.push_back(scopes_.size());
155157
scopes_.push_back(scope);
156158

159+
#ifndef __EMSCRIPTEN__
157160
glQueryCounter(queries_[numQueries_], GL_TIMESTAMP);
161+
#endif
158162
numQueries_++;
159163
}
160164

@@ -174,6 +178,8 @@ void GLProfiler::End() {
174178
GLProfilerScope &scope = scopes_[scopeId];
175179
scope.endQueryId = numQueries_;
176180

181+
#ifndef __EMSCRIPTEN__
177182
glQueryCounter(queries_[numQueries_], GL_TIMESTAMP);
183+
#endif
178184
numQueries_++;
179185
}

Common/GPU/OpenGL/GLQueueRunner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void GLQueueRunner::RunInitSteps(const FastVec<GLRInitStep> &steps, bool skipGLC
214214
} else if (gl_extensions.VersionGEThan(3, 0, 0)) {
215215
glBindFragDataLocation(program->program, 0, "fragColor0");
216216
}
217-
#elif !PPSSPP_PLATFORM(IOS)
217+
#elif !PPSSPP_PLATFORM(IOS) && !defined(__EMSCRIPTEN__)
218218
if (gl_extensions.GLES3 && step.create_program.support_dual_source) {
219219
// For GLES2, we use gl_SecondaryFragColorEXT as fragColor1.
220220
_dbg_assert_msg_(gl_extensions.EXT_blend_func_extended, "EXT_blend_func_extended required for dual src");
@@ -1477,7 +1477,7 @@ void GLQueueRunner::PerformCopy(const GLRStep &step) {
14771477
_assert_msg_(caps_.framebufferCopySupported, "Image copy extension expected");
14781478

14791479
#if defined(USING_GLES2)
1480-
#if !PPSSPP_PLATFORM(IOS)
1480+
#if !PPSSPP_PLATFORM(IOS) && !defined(__EMSCRIPTEN__)
14811481
glCopyImageSubDataOES(
14821482
srcTex, target, srcLevel, srcRect.x, srcRect.y, srcZ,
14831483
dstTex, target, dstLevel, dstPos.x, dstPos.y, dstZ,

Common/GPU/OpenGL/gl3stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "Common/GPU/OpenGL/GLCommon.h"
2020

2121
#if defined(USING_GLES2)
22-
#if !PPSSPP_PLATFORM(IOS)
22+
#if !PPSSPP_PLATFORM(IOS) && !defined(__EMSCRIPTEN__)
2323
#include "EGL/egl.h"
2424

2525
GLboolean gl3stubInit() {

Common/GPU/OpenGL/gl3stub.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ extern "C" {
4747
* otherwise. */
4848
GLboolean gl3stubInit();
4949

50-
#if !PPSSPP_PLATFORM(IOS)
51-
50+
#if !PPSSPP_PLATFORM(IOS) && !defined(__EMSCRIPTEN__)
51+
5252
/*-------------------------------------------------------------------------
5353
* Data type definitions
5454
*-----------------------------------------------------------------------*/

Common/TimeUtil.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#ifdef __EMSCRIPTEN__
1515
#include <emscripten/emscripten.h>
16+
#include <emscripten/threading.h>
1617
#endif // __EMSCRIPTEN__
1718

1819
#ifdef _WIN32
@@ -267,7 +268,10 @@ void sleep_ms(int ms, const char *reason) {
267268
#elif defined(HAVE_LIBNX)
268269
svcSleepThread(ms * 1000000);
269270
#elif defined(__EMSCRIPTEN__)
270-
emscripten_sleep(ms);
271+
if (emscripten_is_main_browser_thread())
272+
emscripten_sleep(ms);
273+
else
274+
emscripten_thread_sleep(ms);
271275
#else
272276
usleep(ms * 1000);
273277
#endif
@@ -285,7 +289,10 @@ void sleep_us(int us, const char *reason) {
285289
#elif defined(HAVE_LIBNX)
286290
svcSleepThread(us * 1000);
287291
#elif defined(__EMSCRIPTEN__)
288-
emscripten_sleep(us / 1000);
292+
if (emscripten_is_main_browser_thread())
293+
emscripten_sleep(us / 1000);
294+
else
295+
emscripten_thread_sleep(us / 1000);
289296
#else
290297
usleep(us);
291298
#endif
@@ -342,7 +349,10 @@ void sleep_precise(double seconds, const char *reason) {
342349
#elif defined(HAVE_LIBNX)
343350
svcSleepThread((int64_t)(seconds * 1000000000.0));
344351
#elif defined(__EMSCRIPTEN__)
345-
emscripten_sleep(seconds * 1000.0);
352+
if (emscripten_is_main_browser_thread())
353+
emscripten_sleep((unsigned int)(seconds * 1000.0));
354+
else
355+
emscripten_thread_sleep(seconds * 1000.0);
346356
#else
347357
usleep(seconds * 1000000.0);
348358
#endif

Core/HLE/sceDisplay.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,17 @@ static void DoFrameTiming(bool throttle, bool *skipFrame, float scaledTimestep,
455455
// Wait until we've caught up.
456456
// If we're ending the frame here, we'll defer the sleep until after the command buffers
457457
// have been handed off to the render thread, for some more overlap.
458+
#ifdef __EMSCRIPTEN__
459+
WaitUntil(curFrameTime, nextFrameTime, "display-wait");
460+
curFrameTime = time_now_d();
461+
#else
458462
if (endOfFrame) {
459463
g_frameTiming.DeferWaitUntil(nextFrameTime, &curFrameTime);
460464
} else {
461465
WaitUntil(curFrameTime, nextFrameTime, "display-wait");
462466
curFrameTime = time_now_d(); // I guess we could also just set it to nextFrameTime...
463467
}
468+
#endif
464469
}
465470
}
466471

libretro/LibretroGLContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
class LibretroGLContext : public LibretroHWRenderContext {
88
public:
99
LibretroGLContext()
10-
#ifdef USING_GLES2
10+
#ifdef __EMSCRIPTEN__
11+
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGLES3, 3, 0)
12+
#elif defined(USING_GLES2)
1113
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGLES2)
1214
#else
1315
: LibretroHWRenderContext(RETRO_HW_CONTEXT_OPENGL)

libretro/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ endif
425425
include Makefile.common
426426

427427
ifeq ($(GLES), 1)
428-
GLFLAGS += -DGLES # -DUSING_GLES2
428+
GLFLAGS += -DGLES -DUSING_GLES2
429429
else
430430
GLFLAGS += -DHAVE_OPENGL
431431
endif

0 commit comments

Comments
 (0)