[client] opengl: handle configuration failure properly

This commit is contained in:
Geoffrey McRae 2019-12-12 23:32:31 +11:00
parent 30e3a43311
commit a6f23f00b4
2 changed files with 50 additions and 25 deletions

View File

@ -1 +1 @@
B1-20-gdce6aaefea+1 B1-21-g30e3a43311+1

View File

@ -169,8 +169,15 @@ struct Inst
static bool _check_gl_error(unsigned int line, const char * name); static bool _check_gl_error(unsigned int line, const char * name);
#define check_gl_error(name) _check_gl_error(__LINE__, name) #define check_gl_error(name) _check_gl_error(__LINE__, name)
enum ConfigStatus
{
CONFIG_STATUS_OK,
CONFIG_STATUS_ERROR,
CONFIG_STATUS_NOOP
};
static void deconfigure(struct Inst * this); static void deconfigure(struct Inst * this);
static bool configure(struct Inst * this, SDL_Window *window); static enum ConfigStatus configure(struct Inst * this, SDL_Window *window);
static void update_mouse_shape(struct Inst * this, bool * newShape); static void update_mouse_shape(struct Inst * this, bool * newShape);
static bool draw_frame(struct Inst * this); static bool draw_frame(struct Inst * this);
static void draw_mouse(struct Inst * this); static void draw_mouse(struct Inst * this);
@ -549,10 +556,20 @@ bool opengl_render(void * opaque, SDL_Window * window)
if (!this) if (!this)
return false; return false;
if (configure(this, window)) switch(configure(this, window))
if (!draw_frame(this)) {
case CONFIG_STATUS_ERROR:
DEBUG_ERROR("configure failed");
return false; return false;
case CONFIG_STATUS_NOOP :
break;
case CONFIG_STATUS_OK :
if (!draw_frame(this))
return false;
}
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -828,13 +845,13 @@ static bool _check_gl_error(unsigned int line, const char * name)
return true; return true;
} }
static bool configure(struct Inst * this, SDL_Window *window) static enum ConfigStatus configure(struct Inst * this, SDL_Window *window)
{ {
LG_LOCK(this->formatLock); LG_LOCK(this->formatLock);
if (!this->reconfigure) if (!this->reconfigure)
{ {
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return this->configured; return CONFIG_STATUS_NOOP;
} }
if (this->configured) if (this->configured)
@ -862,7 +879,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
default: default:
DEBUG_ERROR("Unknown/unsupported compression type"); DEBUG_ERROR("Unknown/unsupported compression type");
return false; return CONFIG_STATUS_ERROR;
} }
// calculate the texture size in bytes // calculate the texture size in bytes
@ -880,30 +897,36 @@ static bool configure(struct Inst * this, SDL_Window *window)
if (this->amdPinnedMemSupport) if (this->amdPinnedMemSupport)
{ {
const int pagesize = getpagesize(); const int pagesize = getpagesize();
this->texPixels[0] = memalign(pagesize, this->texSize * BUFFER_COUNT);
memset(this->texPixels[0], 0, this->texSize * BUFFER_COUNT);
for(int i = 1; i < BUFFER_COUNT; ++i)
this->texPixels[i] = this->texPixels[0] + this->texSize;
for(int i = 0; i < BUFFER_COUNT; ++i) for(int i = 0; i < BUFFER_COUNT; ++i)
{ {
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, this->vboID[i]); this->texPixels[i] = aligned_alloc(pagesize, this->texSize);
if (!this->texPixels[i])
{
DEBUG_ERROR("Failed to allocate memory for texture");
return CONFIG_STATUS_ERROR;
}
memset(this->texPixels[i], 0, this->texSize);
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, this->vboID[i]);
if (check_gl_error("glBindBuffer")) if (check_gl_error("glBindBuffer"))
{ {
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return false; return CONFIG_STATUS_ERROR;
} }
glBufferData( glBufferData(
GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD,
this->texSize, this->texSize,
this->texPixels[i], this->texPixels[i],
GL_STREAM_DRAW); GL_STREAM_DRAW
);
if (check_gl_error("glBufferData")) if (check_gl_error("glBufferData"))
{ {
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return false; return CONFIG_STATUS_ERROR;
} }
} }
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0); glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);
@ -916,7 +939,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
if (check_gl_error("glBindBuffer")) if (check_gl_error("glBindBuffer"))
{ {
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return false; return CONFIG_STATUS_ERROR;
} }
glBufferData( glBufferData(
@ -928,7 +951,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
if (check_gl_error("glBufferData")) if (check_gl_error("glBufferData"))
{ {
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return false; return CONFIG_STATUS_ERROR;
} }
} }
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
@ -939,7 +962,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
if (check_gl_error("glGenTextures")) if (check_gl_error("glGenTextures"))
{ {
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return false; return CONFIG_STATUS_ERROR;
} }
this->hasFrames = true; this->hasFrames = true;
@ -950,7 +973,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
if (check_gl_error("glBindTexture")) if (check_gl_error("glBindTexture"))
{ {
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return false; return CONFIG_STATUS_ERROR;
} }
glTexImage2D( glTexImage2D(
@ -967,7 +990,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
if (check_gl_error("glTexImage2D")) if (check_gl_error("glTexImage2D"))
{ {
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return false; return CONFIG_STATUS_ERROR;
} }
// configure the texture // configure the texture
@ -998,7 +1021,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
this->reconfigure = false; this->reconfigure = false;
LG_UNLOCK(this->formatLock); LG_UNLOCK(this->formatLock);
return true; return CONFIG_STATUS_OK;
} }
static void deconfigure(struct Inst * this) static void deconfigure(struct Inst * this)
@ -1026,9 +1049,6 @@ static void deconfigure(struct Inst * this)
if (this->amdPinnedMemSupport) if (this->amdPinnedMemSupport)
{ {
if (this->texPixels[0])
free(this->texPixels[0]);
for(int i = 0; i < BUFFER_COUNT; ++i) for(int i = 0; i < BUFFER_COUNT; ++i)
{ {
if (this->fences[i]) if (this->fences[i])
@ -1036,7 +1056,12 @@ static void deconfigure(struct Inst * this)
glDeleteSync(this->fences[i]); glDeleteSync(this->fences[i]);
this->fences[i] = NULL; this->fences[i] = NULL;
} }
this->texPixels[i] = NULL;
if (this->texPixels[i])
{
free(this->texPixels[i]);
this->texPixels[i] = NULL;
}
} }
} }