mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-18 23:43:23 +09:00
[MG_Impl] guard the monolith mip generate arm against immutable storage and views
EnsureGeneratedMipmapStorageAllocated branched on the transport. The split arm
planned the generation window from BASE_LEVEL/MAX_LEVEL and refused to touch
immutable storage (70c8230b); the monolith arm rebuilt the chain from the bound
object's level-0 extent and then truncated it. Through a view that is
destructive in a way the split arm had already been fixed for: a view's level-0
extent is one slice of the owner's layers, so a two-layer view of a four-layer
array resized every owner level the generation touched to two layers - the
storage behind the owner's other layers was gone - and redefined the owner's
levels out of the view's window as well.
Both arms now take one path. An immutable texture or a view returns before any
allocation: it already owns every level generation can write. A mutable texture
gets levels from the plan's Base..End window and nothing else moves - the chain
is not truncated, because neither MAX_LEVEL nor a generate is a truncation (a
level-0 respecification drops the stale tail itself, in
DiscardMipmapChainOnBaseRespecification). MipmapGenerationPlan.h is no longer
behind MOBILEGL_BUILD_DISAGGREGATED for the same reason: the window is a
property of the GL call, not of how the backend is reached, and the plan the
wire carrier publishes (MGPMipPlan::LevelCount, end-exclusive) is this one.
The window rule was asserted only by the split-only F1WireScenario, whose
fixture skips under every other transport - so the monolith arm, which is what
a non-disaggregated library runs for every application, had no coverage at all.
TextureViewScenario.GenerateMipmapThroughAViewLeavesTheOwnerShapeAlone runs in
an integration-gpu lane under both transports and pins the owner's layer counts,
its own level extents, and the pixels of the levels and layers outside the
view's window. It is DirectGLES-only, and the skip names why: Magma reallocates
the chain through the bound object in its own generate path
(DirectVulkan/Renderer/VulkanRenderer.cpp's EnsureGenerateMipmapStorageAllocated),
and a CPU sub-image into the layers of mip 2 or 3 does not read back through
Magma at all - a run of the same scenario with the generate removed fails
identically - so the per-level colours this case is built on are unobservable on
that backend rather than merely wrong.
This commit is contained in:
@@ -508,65 +508,36 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return size;
|
||||
}
|
||||
|
||||
// glGenerateMipmap defines levels BASE_LEVEL+1 up to the level the base image's extent and
|
||||
// MAX_LEVEL admit, and leaves every other level exactly as it was (GL 4.6 core 8.17). Both
|
||||
// transports take this one path: the window, and the refusal to redefine the levels around
|
||||
// it, are properties of the GL call rather than of how the backend is reached.
|
||||
Bool EnsureGeneratedMipmapStorageAllocated(
|
||||
MG_State::GLState::TextureObjectMipmap& texture,
|
||||
TextureUploadTarget uploadTarget) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
const auto plan = ComputeMipmapGenerationRange(texture, uploadTarget);
|
||||
if (plan.End <= plan.Base) return false;
|
||||
// Immutable textures and views already own every generated level.
|
||||
// Allocating through a view would redefine its owner's complete
|
||||
// level, destroying layers and levels outside the view window.
|
||||
if (texture.IsImmutable()) return true;
|
||||
const IntVec3 baseSize = texture.GetMipmapTexelSize(uploadTarget, plan.Base);
|
||||
const SizeT baseBytes = texture.GetMipmapByteSize(uploadTarget, plan.Base);
|
||||
const SizeT texels = static_cast<SizeT>(baseSize.x()) * baseSize.y() * baseSize.z();
|
||||
if (!baseBytes || !texels || baseBytes % texels) return false;
|
||||
const SizeT pixelBytes = baseBytes / texels;
|
||||
const Int axes = MipShrinkingAxisCount(texture.GetTarget());
|
||||
for (Uint level = plan.Base + 1; level < plan.End; ++level) {
|
||||
const auto size = ComputeMipmapTexelSize(baseSize, level - plan.Base, axes);
|
||||
const SizeT bytes = pixelBytes * static_cast<SizeT>(size.x()) * size.y() * size.z();
|
||||
texture.AllocateStorage(uploadTarget, level, {size, bytes});
|
||||
texture.MarkStorageDirty(uploadTarget, level, false);
|
||||
}
|
||||
// Levels before BASE_LEVEL and after the generated end remain
|
||||
// valid images. In particular, MAX_LEVEL is not a truncate call.
|
||||
texture.BumpContentVersion();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
const Uint existingLevelCount = texture.GetMipmapLevelCount();
|
||||
if (existingLevelCount == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const IntVec3 baseTexelSize = texture.GetMipmapTexelSize(uploadTarget, 0);
|
||||
const SizeT baseByteSize = texture.GetMipmapByteSize(uploadTarget, 0);
|
||||
const SizeT baseTexelCount = static_cast<SizeT>(baseTexelSize.x()) *
|
||||
static_cast<SizeT>(baseTexelSize.y()) *
|
||||
static_cast<SizeT>(baseTexelSize.z());
|
||||
if (baseTexelSize.x() <= 0 || baseTexelSize.y() <= 0 || baseTexelSize.z() <= 0 ||
|
||||
baseByteSize == 0 || baseTexelCount == 0 || (baseByteSize % baseTexelCount) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const SizeT bytesPerTexel = baseByteSize / baseTexelCount;
|
||||
const Int shrinkingAxes = MipShrinkingAxisCount(texture.GetTarget());
|
||||
const Uint requiredLevelCount = ComputeFullMipmapLevelCount(baseTexelSize, shrinkingAxes);
|
||||
for (Uint level = 1; level < requiredLevelCount; ++level) {
|
||||
const IntVec3 levelTexelSize = ComputeMipmapTexelSize(baseTexelSize, level, shrinkingAxes);
|
||||
const SizeT levelByteSize = bytesPerTexel * static_cast<SizeT>(levelTexelSize.x()) *
|
||||
static_cast<SizeT>(levelTexelSize.y()) *
|
||||
static_cast<SizeT>(levelTexelSize.z());
|
||||
texture.AllocateStorage(uploadTarget, level, {levelTexelSize, levelByteSize});
|
||||
const auto plan = ComputeMipmapGenerationRange(texture, uploadTarget);
|
||||
if (plan.End <= plan.Base) return false;
|
||||
// Immutable textures and views already own every level generation can write.
|
||||
// Allocating through a view would redefine its owner's levels at the VIEW's base
|
||||
// extent - one slice of the owner's layers - destroying the storage of every layer and
|
||||
// level outside the view window.
|
||||
if (texture.IsImmutable()) return true;
|
||||
const IntVec3 baseSize = texture.GetMipmapTexelSize(uploadTarget, plan.Base);
|
||||
const SizeT baseBytes = texture.GetMipmapByteSize(uploadTarget, plan.Base);
|
||||
const SizeT texels = static_cast<SizeT>(baseSize.x()) * baseSize.y() * baseSize.z();
|
||||
if (!baseBytes || !texels || baseBytes % texels) return false;
|
||||
const SizeT pixelBytes = baseBytes / texels;
|
||||
const Int axes = MipShrinkingAxisCount(texture.GetTarget());
|
||||
for (Uint level = plan.Base + 1; level < plan.End; ++level) {
|
||||
const auto size = ComputeMipmapTexelSize(baseSize, level - plan.Base, axes);
|
||||
const SizeT bytes = pixelBytes * static_cast<SizeT>(size.x()) * size.y() * size.z();
|
||||
texture.AllocateStorage(uploadTarget, level, {size, bytes});
|
||||
texture.MarkStorageDirty(uploadTarget, level, false);
|
||||
}
|
||||
// glGenerateMipmap defines exactly levels 0..requiredLevelCount-1. AllocateStorage only
|
||||
// grows, so a previously longer chain (a bigger base image before respecification) would
|
||||
// otherwise keep a tail of stale levels here and read as incomplete.
|
||||
texture.TruncateMipmapLevels(uploadTarget, requiredLevelCount);
|
||||
// Levels before BASE_LEVEL and after the generated end remain valid images and are left
|
||||
// alone: neither MAX_LEVEL nor a generate truncates the chain. AllocateStorage only
|
||||
// grows, so a longer chain a level-0 respecification left behind is dropped there
|
||||
// (DiscardMipmapChainOnBaseRespecification) rather than here.
|
||||
// Mip generation grows/regenerates the level set on the GPU without marking any CPU
|
||||
// level dirty (MarkStorageDirty(...,false) above). Bump the content version so the
|
||||
// backend re-syncs: a cached sampled VkImageView built for the pre-generate level
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The plan is the GL call's own window, not a transport's, so both arms of
|
||||
// EnsureGeneratedMipmapStorageAllocated compute it here and the wire carrier
|
||||
// (MGPMipPlan::LevelCount) publishes the same end-exclusive number.
|
||||
#include <MG_State/GLState/TextureState/TextureObject.h>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -42,4 +44,3 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user