egl: fix composition rendering black on real hardware
Two faults found on the first run against a real DXGI multi-monitor host, each of which left the composed view black while every geometry check passed: - Compose setup ran on the frame thread via onFrameFormat, but the VAO and FBO it creates are container objects that only exist in the creating context. The render thread drew with empty ones. Setup is now deferred to the render thread and picked up before the next draw (composeSetupPending), and a post-process pass is forced afterwards so a frame that arrived before setup completed is not presented stale. - A DMA-imported atlas is an external image and must be sampled with samplerExternalOES. Compose only compiled the plain sampler2D variant, so the DMA path sampled black. Both variants are now compiled and setup selects one, mirroring what the desktop shaders already do. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WxYTZ8oBdHX3YrHGgdLKwC
This commit is contained in:
1 parent
43a94005f3
commit
c04a12d2b5
3 files changed
+77
-31
No files matched your search
@@ -44,9 +44,12 @@
|
||||
struct EGL_Compose
|
||||
{
|
||||
EGL_Framebuffer * framebuffer;
|
||||
EGL_Shader * shader;
|
||||
EGL_Uniform * uViewSize;
|
||||
EGL_Uniform * uAtlasSize;
|
||||
/* [0] samples a plain texture, [1] an imported DMA buffer, which needs the
|
||||
* external image sampler. Which one runs is chosen at setup. */
|
||||
EGL_Shader * shader [2];
|
||||
EGL_Uniform * uViewSize [2];
|
||||
EGL_Uniform * uAtlasSize[2];
|
||||
bool useDMA;
|
||||
|
||||
GLuint vao;
|
||||
GLuint buffers[2];
|
||||
@@ -68,20 +71,29 @@ bool egl_composeInit(EGL_Compose ** compose)
|
||||
|
||||
EGL_Compose * this = *compose;
|
||||
|
||||
if (!egl_framebufferInit(&this->framebuffer) ||
|
||||
!egl_shaderInit(&this->shader) ||
|
||||
!egl_shaderCompile(this->shader,
|
||||
b_shader_compose_vert, b_shader_compose_vert_size,
|
||||
b_shader_compose_frag, b_shader_compose_frag_size,
|
||||
false, NULL))
|
||||
if (!egl_framebufferInit(&this->framebuffer))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the display composition");
|
||||
egl_composeFree(compose);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->uViewSize = egl_shaderGetUniform(this->shader, "viewSize" );
|
||||
this->uAtlasSize = egl_shaderGetUniform(this->shader, "atlasSize");
|
||||
for(int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (!egl_shaderInit(&this->shader[i]) ||
|
||||
!egl_shaderCompile(this->shader[i],
|
||||
b_shader_compose_vert, b_shader_compose_vert_size,
|
||||
b_shader_compose_frag, b_shader_compose_frag_size,
|
||||
i == 1, NULL))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the display composition");
|
||||
egl_composeFree(compose);
|
||||
return false;
|
||||
}
|
||||
|
||||
this->uViewSize [i] = egl_shaderGetUniform(this->shader[i], "viewSize" );
|
||||
this->uAtlasSize[i] = egl_shaderGetUniform(this->shader[i], "atlasSize");
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &this->vao);
|
||||
egl_stateBindVertexArray(this->vao);
|
||||
@@ -134,16 +146,19 @@ void egl_composeFree(EGL_Compose ** compose)
|
||||
egl_stateInvalidateShared();
|
||||
}
|
||||
|
||||
egl_shaderFree(&this->shader);
|
||||
egl_shaderFree(&this->shader[0]);
|
||||
egl_shaderFree(&this->shader[1]);
|
||||
egl_framebufferFree(&this->framebuffer);
|
||||
free(this);
|
||||
*compose = NULL;
|
||||
}
|
||||
|
||||
bool egl_composeSetup(EGL_Compose * this, const LG_RendererFormat * format)
|
||||
bool egl_composeSetup(EGL_Compose * this, const LG_RendererFormat * format,
|
||||
bool useDMA)
|
||||
{
|
||||
this->configured = false;
|
||||
this->quadCount = 0;
|
||||
this->useDMA = useDMA;
|
||||
|
||||
if (!format->displayCount)
|
||||
return false;
|
||||
@@ -265,10 +280,11 @@ EGL_Texture * egl_composeRun(EGL_Compose * this, EGL_Texture * atlas)
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
const int variant = this->useDMA ? 1 : 0;
|
||||
egl_textureBind(atlas);
|
||||
egl_shaderUse(this->shader);
|
||||
egl_uniform2f(this->uViewSize , this->viewWidth , this->viewHeight );
|
||||
egl_uniform2f(this->uAtlasSize, this->atlasWidth, this->atlasHeight);
|
||||
egl_uniform2f(this->uViewSize [variant], this->viewWidth , this->viewHeight );
|
||||
egl_uniform2f(this->uAtlasSize[variant], this->atlasWidth, this->atlasHeight);
|
||||
egl_shaderUse(this->shader[variant]);
|
||||
|
||||
egl_stateBindVertexArray(this->vao);
|
||||
glDrawElements(GL_TRIANGLES, this->quadCount * INDICES_PER_DISPLAY,
|
||||
|
||||
@@ -44,7 +44,8 @@ void egl_composeFree(EGL_Compose ** compose);
|
||||
* Returns false if the format cannot be composed, in which case the caller
|
||||
* should fall back to presenting the raw atlas rather than showing nothing.
|
||||
*/
|
||||
bool egl_composeSetup(EGL_Compose * compose, const LG_RendererFormat * format);
|
||||
bool egl_composeSetup(EGL_Compose * compose, const LG_RendererFormat * format,
|
||||
bool useDMA);
|
||||
|
||||
/**
|
||||
* Compose `atlas` into the configured view.
|
||||
|
||||
@@ -114,6 +114,10 @@ struct EGL_Desktop
|
||||
* width/height below describe the composed view rather than the atlas. */
|
||||
EGL_Compose * compose;
|
||||
bool composeActive;
|
||||
/* Compose setup creates GL container objects (VAO, FBO) that only exist in
|
||||
* the context that made them. The format arrives on the frame thread, so
|
||||
* setup is deferred to the render thread via this flag. */
|
||||
_Atomic(bool) composeSetupPending;
|
||||
};
|
||||
|
||||
// forwards
|
||||
@@ -408,21 +412,16 @@ bool egl_desktopSetup(EGL_Desktop * desktop, const LG_RendererFormat format)
|
||||
desktop->composeActive = false;
|
||||
if (format.displayCount)
|
||||
{
|
||||
if (egl_composeSetup(desktop->compose, &desktop->format))
|
||||
{
|
||||
unsigned int viewWidth, viewHeight;
|
||||
egl_composeGetSize(desktop->compose, &viewWidth, &viewHeight);
|
||||
desktop->width = viewWidth;
|
||||
desktop->height = viewHeight;
|
||||
desktop->composeActive = true;
|
||||
|
||||
DEBUG_INFO("Composing %u displays from a %ux%u atlas into a %ux%u view",
|
||||
format.displayCount, format.frameWidth, format.frameHeight,
|
||||
desktop->width, desktop->height);
|
||||
}
|
||||
else
|
||||
DEBUG_WARN("Display composition unavailable, showing the packed frame");
|
||||
/* The GL objects composition needs (VAO, FBO) are container objects and
|
||||
* only exist in the creating context. This runs on the frame thread's
|
||||
* context, so only record the intent here; the render thread performs
|
||||
* the actual setup on its own context before the next draw. */
|
||||
desktop->width = format.viewWidth;
|
||||
desktop->height = format.viewHeight;
|
||||
atomic_store(&desktop->composeSetupPending, true);
|
||||
}
|
||||
else
|
||||
atomic_store(&desktop->composeSetupPending, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -518,6 +517,36 @@ bool egl_desktopRender(EGL_Desktop * desktop, unsigned int outputWidth,
|
||||
DEBUG_ERROR("Failed to process the desktop texture");
|
||||
}
|
||||
|
||||
if (atomic_exchange(&desktop->composeSetupPending, false))
|
||||
{
|
||||
if (egl_composeSetup(desktop->compose, &desktop->format,
|
||||
desktop->useDMA))
|
||||
{
|
||||
unsigned int viewWidth, viewHeight;
|
||||
egl_composeGetSize(desktop->compose, &viewWidth, &viewHeight);
|
||||
desktop->width = viewWidth;
|
||||
desktop->height = viewHeight;
|
||||
desktop->composeActive = true;
|
||||
width = viewWidth;
|
||||
height = viewHeight;
|
||||
atomic_store(&desktop->processFrame, true);
|
||||
|
||||
DEBUG_INFO("Composing %u displays from a %ux%u atlas into a %ux%u view",
|
||||
desktop->format.displayCount,
|
||||
desktop->format.frameWidth, desktop->format.frameHeight,
|
||||
desktop->width, desktop->height);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_WARN("Display composition unavailable, showing the packed frame");
|
||||
desktop->composeActive = false;
|
||||
desktop->width = desktop->format.frameWidth;
|
||||
desktop->height = desktop->format.frameHeight;
|
||||
width = desktop->width;
|
||||
height = desktop->height;
|
||||
}
|
||||
}
|
||||
|
||||
/* Compose the packed atlas into the presented view before anything else
|
||||
* runs, so post processing, HDR, the cursor and damage all operate on one
|
||||
* ordinary frame and need no multi-display handling of their own. */
|
||||
|
||||
Reference in new issue
Block a user