Add buffer synchronisation for GLES when using mapped buffers.

This commit is contained in:
Emile Belanger 2021-09-20 21:40:47 +01:00 committed by Rachael Alexanderson
parent 76875f0a3c
commit db59a4f9af
5 changed files with 37 additions and 6 deletions

View File

@ -232,6 +232,34 @@ void GLBuffer::Resize(size_t newsize)
} }
} }
void GLBuffer::GPUDropSync()
{
#if !(USE_GLES2) // Only applicable when running on desktop for now
if (mGLSync != NULL)
{
glDeleteSync(mGLSync);
}
mGLSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
#endif
}
void GLBuffer::GPUWaitSync()
{
#if !(USE_GLES2) // Only applicable when running on desktop for now
GLenum status = glClientWaitSync(mGLSync, GL_SYNC_FLUSH_COMMANDS_BIT, 1000 * 1000 * 50); // Wait for a max of 50ms...
if (status != GL_ALREADY_SIGNALED && status != GL_CONDITION_SATISFIED)
{
//Printf("Error on glClientWaitSync: %d\n", status);
}
glDeleteSync(mGLSync);
mGLSync = NULL;
#endif
}
//=========================================================================== //===========================================================================
// //
@ -287,16 +315,12 @@ void GLDataBuffer::BindRange(FRenderState *state, size_t start, size_t length)
if (mBindingPoint == 3)// VIEWPOINT_BINDINGPOINT if (mBindingPoint == 3)// VIEWPOINT_BINDINGPOINT
{ {
static_cast<FGLRenderState*>(state)->ApplyViewport(memory + start); static_cast<FGLRenderState*>(state)->ApplyViewport(memory + start);
}
else
{
//glBindBufferRange(mUseType, mBindingPoint, mBufferId, start, length);
} }
} }
void GLDataBuffer::BindBase() void GLDataBuffer::BindBase()
{ {
//glBindBufferBase(mUseType, mBindingPoint, mBufferId);
} }

View File

@ -19,6 +19,7 @@ protected:
int mAllocationSize = 0; int mAllocationSize = 0;
bool mPersistent = false; bool mPersistent = false;
bool nomap = true; bool nomap = true;
GLsync mGLSync = 0;
bool isData = false; bool isData = false;
char *memory = nullptr; char *memory = nullptr;
@ -32,6 +33,9 @@ protected:
void Resize(size_t newsize) override; void Resize(size_t newsize) override;
void *Lock(unsigned int size) override; void *Lock(unsigned int size) override;
void Unlock() override; void Unlock() override;
void GPUDropSync();
void GPUWaitSync();
public: public:
void Bind(); void Bind();
void Upload(size_t start, size_t end); void Upload(size_t start, size_t end);

View File

@ -240,11 +240,13 @@ void OpenGLFrameBuffer::Swap()
Finish.Reset(); Finish.Reset();
Finish.Clock(); Finish.Clock();
mVertexData->DropSync();
FPSLimit(); FPSLimit();
SwapBuffers(); SwapBuffers();
mVertexData->NextPipelineBuffer(); mVertexData->NextPipelineBuffer();
mVertexData->WaitSync();
RenderState()->SetVertexBuffer(screen->mVertexData); // Needed for Raze because it does not reset it RenderState()->SetVertexBuffer(screen->mVertexData); // Needed for Raze because it does not reset it

View File

@ -15,6 +15,7 @@ EXTERN_CVAR(Bool, gl_customshader);
PFNGLMAPBUFFERRANGEEXTPROC glMapBufferRange = NULL; PFNGLMAPBUFFERRANGEEXTPROC glMapBufferRange = NULL;
PFNGLUNMAPBUFFEROESPROC glUnmapBuffer = NULL; PFNGLUNMAPBUFFEROESPROC glUnmapBuffer = NULL;
#ifdef __ANDROID__ #ifdef __ANDROID__
#include <dlfcn.h> #include <dlfcn.h>

View File

@ -6,7 +6,7 @@
class FRenderState; class FRenderState;
#ifdef __ANDROID__ #ifdef __ANDROID__
#define HW_MAX_PIPELINE_BUFFERS 8 #define HW_MAX_PIPELINE_BUFFERS 4
#define HW_BLOCK_SSBO 1 #define HW_BLOCK_SSBO 1
#else #else
// On desktop this is only useful fpr letting the GPU run in parallel with the playsim and for that 2 buffers are enough. // On desktop this is only useful fpr letting the GPU run in parallel with the playsim and for that 2 buffers are enough.