Skip to content

Commit

Permalink
Add buffer synchronisation for GLES when using mapped buffers.
Browse files Browse the repository at this point in the history
  • Loading branch information
emileb authored and madame-rachelle committed Sep 20, 2021
1 parent 76875f0 commit db59a4f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
34 changes: 29 additions & 5 deletions src/common/rendering/gles/gles_buffers.cpp
Expand Up @@ -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
}


//===========================================================================
//
Expand Down Expand Up @@ -287,16 +315,12 @@ void GLDataBuffer::BindRange(FRenderState *state, size_t start, size_t length)
if (mBindingPoint == 3)// VIEWPOINT_BINDINGPOINT
{
static_cast<FGLRenderState*>(state)->ApplyViewport(memory + start);
}
else
{
//glBindBufferRange(mUseType, mBindingPoint, mBufferId, start, length);
}
}

void GLDataBuffer::BindBase()
{
//glBindBufferBase(mUseType, mBindingPoint, mBufferId);

}


Expand Down
4 changes: 4 additions & 0 deletions src/common/rendering/gles/gles_buffers.h
Expand Up @@ -19,6 +19,7 @@ class GLBuffer : virtual public IBuffer
int mAllocationSize = 0;
bool mPersistent = false;
bool nomap = true;
GLsync mGLSync = 0;

bool isData = false;
char *memory = nullptr;
Expand All @@ -32,6 +33,9 @@ class GLBuffer : virtual public IBuffer
void Resize(size_t newsize) override;
void *Lock(unsigned int size) override;
void Unlock() override;

void GPUDropSync();
void GPUWaitSync();
public:
void Bind();
void Upload(size_t start, size_t end);
Expand Down
2 changes: 2 additions & 0 deletions src/common/rendering/gles/gles_framebuffer.cpp
Expand Up @@ -240,11 +240,13 @@ void OpenGLFrameBuffer::Swap()
Finish.Reset();
Finish.Clock();

mVertexData->DropSync();

FPSLimit();
SwapBuffers();

mVertexData->NextPipelineBuffer();
mVertexData->WaitSync();

RenderState()->SetVertexBuffer(screen->mVertexData); // Needed for Raze because it does not reset it

Expand Down
1 change: 1 addition & 0 deletions src/common/rendering/gles/gles_system.cpp
Expand Up @@ -15,6 +15,7 @@ EXTERN_CVAR(Bool, gl_customshader);

PFNGLMAPBUFFERRANGEEXTPROC glMapBufferRange = NULL;
PFNGLUNMAPBUFFEROESPROC glUnmapBuffer = NULL;

#ifdef __ANDROID__
#include <dlfcn.h>

Expand Down
2 changes: 1 addition & 1 deletion src/common/rendering/hwrenderer/data/buffers.h
Expand Up @@ -6,7 +6,7 @@
class FRenderState;

#ifdef __ANDROID__
#define HW_MAX_PIPELINE_BUFFERS 8
#define HW_MAX_PIPELINE_BUFFERS 4
#define HW_BLOCK_SSBO 1
#else
// On desktop this is only useful fpr letting the GPU run in parallel with the playsim and for that 2 buffers are enough.
Expand Down

0 comments on commit db59a4f

Please sign in to comment.