From f39c76c4c533a965d7f4804e5da7d151bceae5c5 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 15 Jul 2025 22:02:40 +0800 Subject: [PATCH] [Fix] (Buffer): use GL_MAP_COHERENT_BIT to replace GL_MAP_FLUSH_EXPLICIT_BIT + glFlushMappedBufferRange This fixed entity rendering bugs on certain Adreno drivers. Thanks OpenLTW! (https://github.com/artdeell/LTW/commit/5e6cc9ff295b100bad37a9518fb049faee01a963) --- src/main/cpp/gl/buffer.cpp | 14 ++++++++++++-- src/main/cpp/gl/buffer.h | 2 ++ src/main/cpp/gl/gl_native.cpp | 4 ++-- src/main/cpp/gl/gl_stub.cpp | 2 ++ src/main/cpp/version.h | 4 ++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/cpp/gl/buffer.cpp b/src/main/cpp/gl/buffer.cpp index d833b8c..4ce3629 100644 --- a/src/main/cpp/gl/buffer.cpp +++ b/src/main/cpp/gl/buffer.cpp @@ -401,6 +401,13 @@ extern "C" { } #endif +void* glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) { + LOG() + access &= ~GL_MAP_FLUSH_EXPLICIT_BIT; +// access |= GL_MAP_UNSYNCHRONIZED_BIT; + return GLES.glMapBufferRange(target, offset, length, access); +} + GLboolean glUnmapBuffer(GLenum target) { LOG() LOG_D("%s(%s)", __func__, glEnumToString(target)); @@ -438,8 +445,11 @@ GLboolean glUnmapBuffer(GLenum target) { void glBufferStorage(GLenum target, GLsizeiptr size, const void* data, GLbitfield flags) { LOG() - if(GLES.glBufferStorageEXT) - GLES.glBufferStorageEXT(target,size,data,flags); + if(GLES.glBufferStorageEXT) { + if ((flags & GL_MAP_PERSISTENT_BIT) != 0 || (flags & GL_DYNAMIC_STORAGE_BIT) != 0) + flags |= (GL_MAP_WRITE_BIT | GL_MAP_COHERENT_BIT | GL_MAP_PERSISTENT_BIT); + GLES.glBufferStorageEXT(target, size, data, flags); + } CHECK_GL_ERROR } diff --git a/src/main/cpp/gl/buffer.h b/src/main/cpp/gl/buffer.h index 4624af4..9edb4cf 100644 --- a/src/main/cpp/gl/buffer.h +++ b/src/main/cpp/gl/buffer.h @@ -77,6 +77,8 @@ GLAPI GLAPIENTRY GLboolean glUnmapBuffer(GLenum target); GLAPI GLAPIENTRY void *glMapBuffer(GLenum target, GLenum access); +GLAPI GLAPIENTRY void* glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); + GLAPI GLAPIENTRY void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage); GLAPI GLAPIENTRY void glBufferStorage(GLenum target, GLsizeiptr size, const void* data, GLbitfield flags); diff --git a/src/main/cpp/gl/gl_native.cpp b/src/main/cpp/gl/gl_native.cpp index d4ff350..a1ea90f 100644 --- a/src/main/cpp/gl/gl_native.cpp +++ b/src/main/cpp/gl/gl_native.cpp @@ -179,7 +179,7 @@ NATIVE_FUNCTION_HEAD(void, glUniformMatrix4x3fv, GLint location, GLsizei count, NATIVE_FUNCTION_HEAD(void, glBlitFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) NATIVE_FUNCTION_END_NO_RETURN(void, glBlitFramebuffer, srcX0,srcY0,srcX1,srcY1,dstX0,dstY0,dstX1,dstY1,mask,filter) //NATIVE_FUNCTION_HEAD(void, glRenderbufferStorageMultisample, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) NATIVE_FUNCTION_END_NO_RETURN(void, glRenderbufferStorageMultisample, target,samples,internalformat,width,height) NATIVE_FUNCTION_HEAD(void, glFramebufferTextureLayer, GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) NATIVE_FUNCTION_END_NO_RETURN(void, glFramebufferTextureLayer, target,attachment,texture,level,layer) -NATIVE_FUNCTION_HEAD(void, glFlushMappedBufferRange, GLenum target, GLintptr offset, GLsizeiptr length) NATIVE_FUNCTION_END_NO_RETURN(void, glFlushMappedBufferRange, target,offset,length) +//NATIVE_FUNCTION_HEAD(void, glFlushMappedBufferRange, GLenum target, GLintptr offset, GLsizeiptr length) NATIVE_FUNCTION_END_NO_RETURN(void, glFlushMappedBufferRange, target,offset,length) //NATIVE_FUNCTION_HEAD(void, glBindVertexArray, GLuint array) NATIVE_FUNCTION_END_NO_RETURN(void, glBindVertexArray, array) //NATIVE_FUNCTION_HEAD(void, glDeleteVertexArrays, GLsizei n, const GLuint *arrays) NATIVE_FUNCTION_END_NO_RETURN(void, glDeleteVertexArrays, n,arrays) //NATIVE_FUNCTION_HEAD(void, glGenVertexArrays, GLsizei n, GLuint *arrays) NATIVE_FUNCTION_END_NO_RETURN(void, glGenVertexArrays, n,arrays) @@ -367,4 +367,4 @@ NATIVE_FUNCTION_HEAD(void, glGetSamplerParameterIuiv, GLuint sampler, GLenum pna //NATIVE_FUNCTION_HEAD(void, glTexBuffer, GLenum target, GLenum internalformat, GLuint buffer) NATIVE_FUNCTION_END_NO_RETURN(void, glTexBuffer, target,internalformat,buffer) //NATIVE_FUNCTION_HEAD(void, glTexBufferRange, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size) NATIVE_FUNCTION_END_NO_RETURN(void, glTexBufferRange, target,internalformat,buffer,offset,size) NATIVE_FUNCTION_HEAD(void, glTexStorage3DMultisample, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations) NATIVE_FUNCTION_END_NO_RETURN(void, glTexStorage3DMultisample, target,samples,internalformat,width,height,depth,fixedsamplelocations) -NATIVE_FUNCTION_HEAD(void*, glMapBufferRange, GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) NATIVE_FUNCTION_END(void*, glMapBufferRange, target,offset,length,access) +//NATIVE_FUNCTION_HEAD(void*, glMapBufferRange, GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) NATIVE_FUNCTION_END(void*, glMapBufferRange, target,offset,length,access) diff --git a/src/main/cpp/gl/gl_stub.cpp b/src/main/cpp/gl/gl_stub.cpp index 4c79a2d..6dd5b1a 100644 --- a/src/main/cpp/gl/gl_stub.cpp +++ b/src/main/cpp/gl/gl_stub.cpp @@ -2487,6 +2487,8 @@ STUB_FUNCTION_HEAD(void, glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN,const STUB_FUNCTION_HEAD(void, glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN, GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); STUB_FUNCTION_END_NO_RETURN(void, glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN,rc,s,t,r,g,b,a,nx,ny,nz,x,y,z) STUB_FUNCTION_HEAD(void, glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN,const GLuint* rc, const GLfloat* tc, const GLfloat* c, const GLfloat* n, const GLfloat* v); STUB_FUNCTION_END_NO_RETURN(void, glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN,rc,tc,c,n,v) +NATIVE_FUNCTION_HEAD(void, glFlushMappedBufferRange, GLenum target, GLintptr offset, GLsizeiptr length) STUB_FUNCTION_END_NO_RETURN(void, glFlushMappedBufferRange, target,offset,length) + #ifdef __cplusplus } #endif diff --git a/src/main/cpp/version.h b/src/main/cpp/version.h index ceeb5b1..1f11f83 100644 --- a/src/main/cpp/version.h +++ b/src/main/cpp/version.h @@ -10,10 +10,10 @@ #define MAJOR 1 #define MINOR 2 -#define REVISION 6 +#define REVISION 7 #define PATCH 0 -#define VERSION_TYPE VERSION_RELEASE +#define VERSION_TYPE VERSION_DEVELOPMENT #define VERSION_SUFFIX ""