[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
@@ -15293,12 +15293,17 @@ namespace MobileGL::MG_Backend::DirectGLES {
MG_Util::ConvertGLEnumToTextureUploadTarget(target));
// GL_DEPTH_STENCIL can't be attached as a color attachment (glCheckFramebufferStatus
// would report it incomplete); it has its own combined depth+stencil attachment point.
// glReadBuffer only selects among color attachments, so it does not apply here.
if (format == GL_DEPTH_STENCIL || format == GL_DEPTH_COMPONENT) {
// A STENCIL_INDEX texture has a third one, GL_STENCIL_ATTACHMENT: attaching it as a
// depth attachment (or as a color one) leaves the scratch FBO incomplete, and the read
// that follows writes nothing at all. glReadBuffer only selects among color attachments,
// so it does not apply to any of the three.
const Bool depthStencilAttachment =
format == GL_DEPTH_STENCIL || format == GL_DEPTH_COMPONENT || format == GL_STENCIL_INDEX;
if (depthStencilAttachment) {
ScratchFBOImpl::EnsureDepthAttachment2D(
tempFB, GL_READ_FRAMEBUFFER, backendTexId,
backendAttachTarget == GL_UNKNOWN_MGL ? target : backendAttachTarget, level,
/*withStencil=*/format == GL_DEPTH_STENCIL);
/*withStencil=*/format == GL_DEPTH_STENCIL, /*stencilOnly=*/format == GL_STENCIL_INDEX);
} else if (backendAttachTarget == GL_TEXTURE_3D || backendAttachTarget == GL_TEXTURE_2D_ARRAY ||
backendAttachTarget == GL_TEXTURE_CUBE_MAP_ARRAY) {
// ES cannot attach 3D/array textures through glFramebufferTexture2D; layer 0 here, and
@@ -15313,7 +15318,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
tempFB, GL_READ_FRAMEBUFFER, backendTexId,
backendAttachTarget == GL_UNKNOWN_MGL ? target : backendAttachTarget, level);
}
if (format != GL_DEPTH_STENCIL && format != GL_DEPTH_COMPONENT) {
if (!depthStencilAttachment) {
MGLOG_D("GetTexImage: glReadBuffer(GL_COLOR_ATTACHMENT0)");
ScratchFBOImpl::EnsureReadBuffer(tempFB, GL_COLOR_ATTACHMENT0);
}