[MG_Backend] (DirectGLES/DirectVulkan): the stencil-only scratch attachment and the aspect staging buffer's lifetime

Three follow-ups the first pass needed:

DirectGLES glGetTexImage has to attach a STENCIL_INDEX texture at
GL_STENCIL_ATTACHMENT. It went through the colour branch, which left the scratch
READ framebuffer incomplete for a stencil-only texture, so the readback bailed out
before the new stencil branch could run. ScratchFBOImpl::EnsureDepthAttachment2D
gains the stencil-only point; the shadow remembers which of the three points it
holds so a later depth attach is not deduped against it.

DirectVulkan's aspect staging buffer is recorded into the current frame's command
buffer and outlives the glBlitFramebuffer call that records it, so it retires with
the frame. VkBufferManager::DeferRelease is the manager's own deferred-release
entry point and moves to its public section for that.
This commit is contained in:
2026-09-20 21:34:14 -04:00
parent 5264f9a966
commit a7d7e2bc44
4 changed files with 33 additions and 10 deletions
+13 -4
View File
@@ -11596,6 +11596,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
fb.depthLevel = 0;
fb.depthLayer = -1;
fb.depthHasStencil = false;
fb.depthIsStencilOnly = false;
fb.attachmentsKnown = true;
}
@@ -11629,6 +11630,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
fb.depthLevel = 0;
fb.depthLayer = -1;
fb.depthHasStencil = false;
fb.depthIsStencilOnly = false;
}
} // namespace
@@ -11708,14 +11710,15 @@ namespace MobileGL::MG_Backend::DirectGLES {
}
void EnsureDepthAttachment2D(ScratchFramebuffer& fb, GLenum fbTarget, Uint tex, GLenum texTarget, GLint level,
Bool withStencil) {
Bool withStencil, Bool stencilOnly) {
PrepareForUse(fb, fbTarget);
if (fb.colorTex != 0) {
g_GLESFuncs.glFramebufferTexture2D(fbTarget, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
RecordNoColor(fb);
}
if (fb.depthTex == tex && fb.depthTarget == texTarget && fb.depthLevel == level &&
fb.depthLayer < 0 && fb.depthHasStencil == withStencil) {
fb.depthLayer < 0 && fb.depthHasStencil == withStencil &&
fb.depthIsStencilOnly == stencilOnly) {
return;
}
if (fb.depthTex != 0) {
@@ -11724,8 +11727,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
g_GLESFuncs.glFramebufferTexture2D(fbTarget, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
}
DrainPendingGLErrors();
// A stencil-only texture has no depth point to attach at, and a depth one has no
// stencil point; GL_DEPTH_STENCIL_ATTACHMENT is only the combined texture's form.
g_GLESFuncs.glFramebufferTexture2D(fbTarget,
withStencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT,
stencilOnly ? GL_STENCIL_ATTACHMENT
: (withStencil ? GL_DEPTH_STENCIL_ATTACHMENT
: GL_DEPTH_ATTACHMENT),
texTarget, tex, level);
if (g_GLESFuncs.glGetError() != GL_NO_ERROR) {
RecordNoDepth(fb);
@@ -11736,6 +11743,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
fb.depthLayer = -1;
fb.depthLevel = level;
fb.depthHasStencil = withStencil;
fb.depthIsStencilOnly = stencilOnly;
}
// The layer-point sibling of EnsureColorAttachmentLayer above, for a view's mip chain in
@@ -11749,7 +11757,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
RecordNoColor(fb);
}
if (fb.depthTex == tex && fb.depthTarget == 0 && fb.depthLevel == level && fb.depthLayer == layer &&
!fb.depthHasStencil) {
!fb.depthHasStencil && !fb.depthIsStencilOnly) {
return;
}
if (fb.depthTex != 0) {
@@ -11766,6 +11774,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
fb.depthLevel = level;
fb.depthLayer = layer;
fb.depthHasStencil = false;
fb.depthIsStencilOnly = false;
}
void EnsureNoColorAttachment(ScratchFramebuffer& fb, GLenum fbTarget) {