Compare commits

...
28 Commits
Author SHA1 Message Date
swung0x48 30b1bf25a4 [Docs] close Magma RD32 cache regression with host and device evidence 2026-09-20 09:34:47 -04:00
swung0x48 ac1fbcdd7b [CI] validate Magma cached object lifetime scenarios with Vulkan layers 2026-09-20 09:04:01 -04:00
swung0x48 70fb6689ce [Magma] key wire pipelines by exact render-pass compatibility identities 2026-09-20 08:42:47 -04:00
swung0x48 0ece468e14 [Magma] reuse wire framebuffer objects within fenced frame slots 2026-09-20 08:28:55 -04:00
swung0x48 62621213b1 [Test] (Disaggregated): preserve wire cache identity through queued GL mutations 2026-09-20 08:24:38 -04:00
swung0x48 a53b85ad93 [MG_Backend] (Disaggregated): memoize immutable wire vertex format capabilities 2026-09-20 08:21:24 -04:00
swung0x48 ed507b1a6a [MG_Backend] (Disaggregated): reuse exact wire image views within a frame slot 2026-09-20 08:16:21 -04:00
swung0x48 21d8c456e7 [Docs] (Disaggregated): record same-build RD32 four-way FCL performance 2026-09-20 08:02:44 -04:00
swung0x48 dbb70307c0 [Docs] identify SPIRV-Cross generated version metadata 2026-09-20 05:48:48 -04:00
swung0x48 06e12f933a [Docs] (Disaggregated): distinguish symbol gate from build metadata byte differences 2026-09-20 05:47:40 -04:00
swung0x48 bf762e44a4 [Docs] (Disaggregated): close Magma run-ahead with host gates and paired Redmi FCL evidence 2026-09-20 05:41:41 -04:00
swung0x48 194382c96a [MG_Backend, CI] (Disaggregated): reclaim abandoned wire objects only after texture uploads are idle 2026-09-20 05:24:25 -04:00
swung0x48 509c056b85 [tools] (Disaggregated): preserve paired FCL run-ahead validation recipe 2026-09-20 05:19:52 -04:00
swung0x48 112da7ca5f [CI] (Disaggregated): enforce run-ahead negative control and Vulkan synchronization validation 2026-09-20 05:18:22 -04:00
swung0x48 4f762262a0 [MG_Backend] (Disaggregated): make Magma descriptors and present barriers Vulkan-valid 2026-09-20 05:17:21 -04:00
swung0x48 7f42cb9d78 [MG_Impl] (Disaggregated): remove VAO collision tracing after device confirmation 2026-09-20 05:15:59 -04:00
swung0x48 c1f463e15e [MG_Test] cover colliding VAO shutter identities through validation 2026-09-20 05:15:30 -04:00
swung0x48 f55b046c12 [tools] (Disaggregated): require Magma run-ahead evidence in current device gate 2026-09-20 05:15:01 -04:00
swung0x48 376c04bee6 [MG_Impl] (Disaggregated): compare VAO identities exactly before suppressing vertex state 2026-09-20 05:12:10 -04:00
swung0x48 6f764c4237 [MG_Backend] (Disaggregated): identify rejected Magma wire vertex layouts 2026-09-20 04:59:54 -04:00
swung0x48 911a957085 [MG_IntegrationTest] (Disaggregated): sample frame statistics after present is applied 2026-09-20 04:51:49 -04:00
swung0x48 3c97ea9cfc [MG_Backend] (Disaggregated): validate wire framebuffer identity without frontend getters 2026-09-20 04:38:40 -04:00
swung0x48 1164ff45b7 [MG_Backend] (Disaggregated): arm Magma run-ahead after queued-state validation 2026-09-20 04:33:01 -04:00
swung0x48 b010b5f0ac [MG_Impl, MG_Test] (Disaggregated): keep local compute limits off the apply barrier 2026-09-20 04:29:28 -04:00
swung0x48 b3e4b7b78b [MG_Backend] (Disaggregated): retire the final wire pass at present submission 2026-09-20 04:17:18 -04:00
swung0x48 8c9f655b8d [MG_Test, MG_Backend] (Disaggregated): keep required replies outside run-ahead holds 2026-09-20 04:14:01 -04:00
swung0x48 51e61ddabe [MG_Backend] (Disaggregated): order Magma GPU work and defer wire object retirement 2026-09-20 04:11:36 -04:00
swung0x48 c1960fdfaa [MG_IntegrationTest] (Disaggregated): prove real Magma queued state and present credit 2026-09-20 04:02:44 -04:00
51 changed files with 3743 additions and 135 deletions
+52 -1
View File
@@ -1152,7 +1152,7 @@ jobs:
- name: Install runtime dependencies
run: |
sudo apt-get update
sudo apt-get install -y libvulkan1 libegl1 libegl-mesa0 libgles2 libgl1-mesa-dri mesa-vulkan-drivers
sudo apt-get install -y libvulkan1 libegl1 libegl-mesa0 libgles2 libgl1-mesa-dri mesa-vulkan-drivers vulkan-validationlayers
- name: Download Linux split runtime
uses: actions/download-artifact@v8
@@ -1474,6 +1474,57 @@ jobs:
["DirectVulkan.Split.Buffers." + name for name in cases])
PY
- name: Magma run-ahead must queue real GPU work and enforce credits 1 and 3
working-directory: build-split
run: |
ctest -L integration-magma-runahead --show-only=json-v1 > "${RUNNER_TEMP}/magma-runahead-lane.json"
ctest -L integration-magma-runahead --no-tests=error -j 2 --output-on-failure \
--output-junit "${RUNNER_TEMP}/magma-runahead.xml"
python3 - "${GITHUB_WORKSPACE}/MobileGL/MG_IntegrationTest/Harness/split_log_paths.py" \
"${RUNNER_TEMP}/magma-runahead-lane.json" "${RUNNER_TEMP}/magma-runahead.xml" <<'PY'
import importlib.util, json, sys
spec = importlib.util.spec_from_file_location("slp", sys.argv[1])
slp = importlib.util.module_from_spec(spec); spec.loader.exec_module(slp)
cases = [
"QueuedBufferVersionsAndDeletedNameReuseKeepTheirPixels",
"QueuedProgramRebindsKeepEachUniformSnapshot",
"QueuedGpuWritesReadBackTheLastDispatchBytes",
"MixedNativeAndConvertedGpuVertexStreamsKeepTheirReservation",
"TextureUploadCannotOvertakeThePreviouslyQueuedDraw",
"GpuClearSurvivesTheFirstStorageImageUpgrade",
"PresentCreditActuallyParksTheClientAtItsConfiguredLimit",
]
required = [f"DirectVulkan.Split.RunAhead.Credit{credit}.MagmaRunAheadScenario.{name}"
for credit in (1, 3) for name in cases]
slp.require_green(json.load(open(sys.argv[2])), sys.argv[3], required)
PY
- name: Magma run-ahead off loses real queue lead and restores green
run: |
python3 scripts/ci/magma_runahead_checks.py negative --build-dir build-split \
--out "${RUNNER_TEMP}/magma-runahead-negative" --execute
- name: Magma run-ahead passes Vulkan synchronization validation
run: |
python3 scripts/ci/magma_runahead_checks.py validation --build-dir build-split \
--out "${RUNNER_TEMP}/magma-runahead-syncval" --execute
- name: Magma cached views and framebuffers pass Vulkan synchronization validation
run: |
python3 scripts/ci/magma_cache_checks.py --build-dir build-split \
--out "${RUNNER_TEMP}/magma-cache-syncval" --execute
- name: Upload Magma run-ahead control and validation evidence
if: always()
uses: actions/upload-artifact@v7
with:
name: magma-runahead-checks
path: |
${{ runner.temp }}/magma-runahead-negative
${{ runner.temp }}/magma-runahead-syncval
${{ runner.temp }}/magma-cache-syncval
if-no-files-found: ignore
- name: Magma P7 native mip format debt stays a named refusal
working-directory: build-split
env:
@@ -7,6 +7,9 @@
// End of Source File Header
#include "FrameContext.h"
#if MOBILEGL_BUILD_DISAGGREGATED
#include <Config.h>
#endif
namespace MobileGL::MG_Backend::DirectVulkan {
VkResult FrameContext::Initialize(VkDevice device, VkCommandPool commandPool, Uint32 frameCount) {
@@ -217,6 +220,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
VkImageMemoryBarrier presentBarrier{};
presentBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
presentBarrier.srcAccessMask = 0;
#if MOBILEGL_BUILD_DISAGGREGATED
// A layout transition writes the image too. Order it after the wire
// render pass's storeOp, clears and copies instead of relying on the old
// per-draw queue-idle path. This applies even when contents are discarded.
if (MG_Config::Transport != MG_Config::TransportMode::Monolith)
presentBarrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
#endif
presentBarrier.dstAccessMask = 0;
presentBarrier.oldLayout = oldLayout;
presentBarrier.newLayout = presentLayout;
@@ -228,7 +238,14 @@ namespace MobileGL::MG_Backend::DirectVulkan {
presentBarrier.subresourceRange.levelCount = 1;
presentBarrier.subresourceRange.baseArrayLayer = 0;
presentBarrier.subresourceRange.layerCount = 1;
vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0,
vkCmdPipelineBarrier(commandBuffer,
#if MOBILEGL_BUILD_DISAGGREGATED
MG_Config::Transport != MG_Config::TransportMode::Monolith
? VK_PIPELINE_STAGE_ALL_COMMANDS_BIT : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
#else
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
#endif
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0,
nullptr, 0, nullptr, 1, &presentBarrier);
if (openedRecording) {
@@ -198,7 +198,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.programHash, sizeof(payload.programHash)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.vertexInputHash, sizeof(payload.vertexInputHash)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.pipelineLayout, sizeof(payload.pipelineLayout)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.renderPass, sizeof(payload.renderPass)));
#if MOBILEGL_BUILD_DISAGGREGATED
if (payload.wireRenderPassCompatibilityId != 0) {
constexpr Uint64 wireDomain = 0x5749524552504b59ull;
XXHASH_VERIFY(XXH64_update(m_hashState, &wireDomain, sizeof(wireDomain)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.wireRenderPassCompatibilityId,
sizeof(payload.wireRenderPassCompatibilityId)));
} else
#endif
{
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.renderPass, sizeof(payload.renderPass)));
}
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.colorAttachmentCount, sizeof(payload.colorAttachmentCount)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.rasterizationSamples, sizeof(payload.rasterizationSamples)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.sampleShadingEnable, sizeof(payload.sampleShadingEnable)));
@@ -275,7 +285,14 @@ namespace MobileGL::MG_Backend::DirectVulkan {
static_cast<unsigned long long>(payload.programHash));
return VK_NULL_HANDLE;
}
m_cache.emplace(hash, PipelineCacheEntry{pipeline, payload.programHash, payload.renderPass,
m_cache.emplace(hash, PipelineCacheEntry{pipeline, payload.programHash,
#if MOBILEGL_BUILD_DISAGGREGATED
// Wire pipelines outlive their creator pass and
// may serve another compatible pass in flight.
// Never evict them by a recycled native handle.
payload.wireRenderPassCompatibilityId != 0 ? VK_NULL_HANDLE :
#endif
payload.renderPass,
m_frameCounter});
return pipeline;
}
@@ -35,6 +35,11 @@ namespace MobileGL::MG_Backend::DirectVulkan {
HashType vertexInputHash = 0;
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
VkRenderPass renderPass = VK_NULL_HANDLE;
#if MOBILEGL_BUILD_DISAGGREGATED
// Nonzero is an exact, renderer-lifetime compatibility identity.
// renderPass remains the valid creation handle, not the cache key.
Uint64 wireRenderPassCompatibilityId = 0;
#endif
Uint32 colorAttachmentCount = 1;
VkSampleCountFlagBits rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
// glEnable(GL_SAMPLE_SHADING) + glMinSampleShading, which Vulkan bakes into the
@@ -3365,6 +3365,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
updateAfterBindSampledImages + updateAfterBindStorageImages;
const auto& uab = m_updateAfterBindLimits;
entry.usesUpdateAfterBind =
#if MOBILEGL_BUILD_DISAGGREGATED
// Vulkan forbids ANY update-after-bind binding in a set layout that
// contains a dynamic buffer descriptor (VUID 03001/03011). Wire draws
// retain UniformManager's per-frame, content-versioned descriptor sets;
// this selects the legal ordinary pool, not in-place mutation of a live set.
(!program.IsWire() || entry.dynamicBindings.empty()) &&
#endif
uab.enabled && updateAfterBindSamplers <= uab.maxPerStageSamplers &&
updateAfterBindUniformBuffers <= uab.maxPerStageUniformBuffers &&
updateAfterBindStorageBuffers <= uab.maxPerStageStorageBuffers &&
@@ -41,6 +41,30 @@
namespace MobileGL::MG_Backend::DirectVulkan {
#if MOBILEGL_BUILD_DISAGGREGATED
SizeT UniformManager::WireImageViewKeyHash::operator()(const WireImageViewKey& key) const {
SizeT hash = std::hash<VkImage>{}(key.image);
const auto mix = [&hash](Uint64 value) {
hash ^= std::hash<Uint64>{}(value) + static_cast<SizeT>(0x9e3779b97f4a7c15ULL) +
(hash << 6) + (hash >> 2);
};
mix(key.root.Slot);
mix(key.root.Gen);
mix(key.imageEpoch);
mix(key.flags);
mix(key.type);
mix(key.format);
mix(key.components.r);
mix(key.components.g);
mix(key.components.b);
mix(key.components.a);
mix(key.range.aspectMask);
mix(key.range.baseMipLevel);
mix(key.range.levelCount);
mix(key.range.baseArrayLayer);
mix(key.range.layerCount);
return hash;
}
[[noreturn]] static void WireDescriptorFatal(const char* detail) {
MGLOG_F("MGPipe: Fatal{UnmigratedVerb, \"Magma:%s\"}", detail);
std::abort();
@@ -192,8 +216,19 @@ namespace MobileGL::MG_Backend::DirectVulkan {
info.components = {swizzle(0), swizzle(1), swizzle(2), swizzle(3)};
}
VkImageView view = VK_NULL_HANDLE;
if (vkCreateImageView(m_device, &info, nullptr, &view) != VK_SUCCESS) return false;
m_frames[m_wireFrameIndex].wireImageViews.push_back(view);
const WireImageViewKey key{root, info.image, m_textureManager->GetTextureImageEpoch(),
info.flags, info.viewType, info.format, info.components, info.subresourceRange};
const auto& frame = m_frames[m_wireFrameIndex];
const auto cached = frame.wireImageViewCache.find(key);
if (cached != frame.wireImageViewCache.end()) {
view = cached->second;
} else {
if (vkCreateImageView(m_device, &info, nullptr, &view) != VK_SUCCESS) return false;
frame.wireImageViews.push_back(view);
frame.wireImageViewCache.emplace(key, view);
}
// Only view creation is memoized. Layout/memory dependencies above and
// write tracking below still run for every descriptor, including hits.
out.imageView = view;
out.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
if (storage) {
@@ -539,6 +574,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
for (auto& frame : m_frames) {
if (m_device != VK_NULL_HANDLE) {
#if MOBILEGL_BUILD_DISAGGREGATED
frame.wireImageViewCache.clear();
for (const auto view : frame.wireImageViews) vkDestroyImageView(m_device, view, nullptr);
frame.wireImageViews.clear();
#endif
@@ -585,6 +621,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
auto& frame = m_frames[frameIndex];
#if MOBILEGL_BUILD_DISAGGREGATED
m_wireFrameIndex = frameIndex;
frame.wireImageViewCache.clear();
for (const auto view : frame.wireImageViews) vkDestroyImageView(m_device, view, nullptr);
frame.wireImageViews.clear();
#endif
@@ -2763,6 +2800,41 @@ namespace MobileGL::MG_Backend::DirectVulkan {
}
}
#if MOBILEGL_BUILD_DISAGGREGATED
Bool UniformManager::PrepareWireTextureResources(const MagmaProgramSource& program,
const ProgramFactory::VkProgramObject& programObj) {
if (!program.IsWire()) return true;
if (programObj.declinedDescriptors || m_textureManager == nullptr) return false;
const auto& state = MG_Pipe::MGPipeApplier();
// Resolve writable images first: aliases sampled by the same draw must
// see the final STORAGE-capable allocation before any view is built.
for (const Bool storage : {true, false}) {
const auto wanted = storage ? ProgramFactory::DescriptorBindingKind::StorageImage
: ProgramFactory::DescriptorBindingKind::CombinedImageSampler;
for (const Uint32 binding : programObj.activeBindings) {
if (binding >= m_maxBindings) break;
if (programObj.bindingKinds[binding] != wanted) continue;
const Int baseLocation = programObj.samplerUniformLocationByBinding[binding];
const Uint32 count = BindingDescriptorCount(programObj, binding);
for (Uint32 element = 0; element < count; ++element) {
const Int location = baseLocation + static_cast<Int>(element);
if (baseLocation < 0 || !program.UniformLocationsAliasSameUniform(baseLocation, location))
return false;
const Int unit = program.GetUniformSamplerOrImageUnitIndex(static_cast<Uint>(location));
if (unit < 0 || static_cast<Uint32>(unit) >=
(storage ? MG_Pipe::kMGPipeMaxImageUnits : MG_Pipe::kMGPipeMaxTextureUnits)) return false;
const auto handle = storage ? state.BoundShaderImages[unit].Res
: state.BoundSamplerViews[unit].Texture;
if (MG_Pipe::MGPipeHandleIsNull(handle)) WireDescriptorFatal("unbound-image-placeholder@P7");
if (!m_textureManager->SyncTextureResourceByHandle(handle, false, storage)) return false;
}
}
}
m_textureManager->FlushPendingUploads();
return true;
}
#endif
Bool UniformManager::BindProgramUniformBuffers(VkCommandBuffer commandBuffer,
const MagmaProgramSource& program,
const ProgramFactory::VkProgramObject& programObj,
@@ -100,6 +100,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
Vector<SamplerImageFeedbackBinding>& outBindings) const;
static Bool SamplerOverlapsWritableImageSubresource(Int samplerBaseLevel, Int samplerMaxLevel,
GLint imageLevel, GLenum imageAccess);
#if MOBILEGL_BUILD_DISAGGREGATED
// Resolve lazy texture uploads/promotions before the caller captures the
// command buffer passed to BindProgramUniformBuffers. Preparation may
// submit older work, but descriptor recording must never rotate it.
Bool PrepareWireTextureResources(const MagmaProgramSource& program,
const ProgramFactory::VkProgramObject& programObj);
#endif
// samplerDescriptorsUnchangedHint: the caller (SetupDraw fast path) proved that
// every input of every combined-image-sampler resolution is unchanged since the
// previous draw's resolve - same (texture, sampler) per binding, texture params
@@ -152,12 +159,46 @@ namespace MobileGL::MG_Backend::DirectVulkan {
Uint32 cursor = 0;
};
#if MOBILEGL_BUILD_DISAGGREGATED
// ResolveWireImageDescriptor emits no pNext chain. Key every view-create
// value explicitly: hash collisions must never alias different windows,
// formats or swizzles. The root handle and allocation epoch also prevent
// a recycled native image handle from reviving an older view.
struct WireImageViewKey {
MG_Pipe::MGPipeHandle root{};
VkImage image = VK_NULL_HANDLE;
Uint64 imageEpoch = 0;
VkImageViewCreateFlags flags = 0;
VkImageViewType type = VK_IMAGE_VIEW_TYPE_2D;
VkFormat format = VK_FORMAT_UNDEFINED;
VkComponentMapping components{};
VkImageSubresourceRange range{};
Bool operator==(const WireImageViewKey& other) const {
return root == other.root && image == other.image && imageEpoch == other.imageEpoch &&
flags == other.flags && type == other.type && format == other.format &&
components.r == other.components.r && components.g == other.components.g &&
components.b == other.components.b && components.a == other.components.a &&
range.aspectMask == other.range.aspectMask && range.baseMipLevel == other.range.baseMipLevel &&
range.levelCount == other.range.levelCount && range.baseArrayLayer == other.range.baseArrayLayer &&
range.layerCount == other.range.layerCount;
}
};
struct WireImageViewKeyHash {
SizeT operator()(const WireImageViewKey& key) const;
};
#endif
struct FrameResources {
Vector<DescriptorPoolBucket> descriptorPools;
UnorderedMap<VkDescriptorSetLayout, DescriptorSetCacheEntry> descriptorSetCacheByLayout;
Vector<VkBufferView> texelBufferViews;
#if MOBILEGL_BUILD_DISAGGREGATED
mutable Vector<VkImageView> wireImageViews;
// Own views in the vector above until this slot's fence/idle proof.
// Cache hits preserve the handle, enabling descriptor-content reuse.
mutable UnorderedMap<WireImageViewKey, VkImageView, WireImageViewKeyHash> wireImageViewCache;
#endif
Uint32 activeDescriptorPoolIndex = 0;
Uint32 allocatedSetsThisFrame = 0;
@@ -442,33 +442,41 @@ namespace MobileGL::MG_Backend::DirectVulkan {
for (Uint32 location = 0; location < elements.AttributeCount; ++location) {
const auto& attr = elements.Attributes[location];
if (!attr.Enabled || !(activeMask & (1u << location))) continue;
const auto reject = [&](const char* reason, VkFormat format = VK_FORMAT_UNDEFINED) {
MGLOG_E("Magma wire vertex layout: %s location=%u type=%u size=%u normalized=%u integer=%u long=%u bgra=%u stride=%d offset=%llu format=%d bufferWindow=%u+%u activeMask=0x%x",
reason, location, attr.Type, static_cast<Uint32>(attr.Size), static_cast<Uint32>(attr.Normalized),
static_cast<Uint32>(attr.IsInteger), static_cast<Uint32>(attr.IsLong), static_cast<Uint32>(attr.IsBgra),
attr.Stride, static_cast<unsigned long long>(attr.Offset), static_cast<Int>(format),
state.VertexBufferStart, state.VertexBufferCount, activeMask);
return false;
};
// set_vertex_buffers is flattened PER ATTRIBUTE (VertexInputEmit.h), not
// indexed by the original ARB binding point in attr.BindingIndex.
if (location < state.VertexBufferStart ||
location - state.VertexBufferStart >= state.VertexBufferCount) return false;
location - state.VertexBufferStart >= state.VertexBufferCount) return reject("buffer-window");
const auto& buffer = state.VertexBuffers[location];
const auto type = static_cast<DataType>(attr.Type);
if (attr.Stride < 0 || attr.Size < 1 || attr.Size > 4) return false;
if (attr.Stride < 0 || attr.Size < 1 || attr.Size > 4) return reject("attribute-shape");
VkFormat format = ToVkVertexFormat(type, attr.Size, attr.Normalized, attr.IsInteger,
attr.IsBgra, attr.IsLong);
auto conversion = VertexStreamConversion::None;
if (format == VK_FORMAT_UNDEFINED && type == DataType::Float64) {
const auto* backend = MG_Remote::Server::ServerLoopInstance().Backend();
if (backend && backend->GetDynamicParameters().SupportsFloat64VertexAttributes) return false;
if (backend && backend->GetDynamicParameters().SupportsFloat64VertexAttributes) return reject("native-fp64-format");
format = ToFloat32VertexFormat(attr.Size);
conversion = VertexStreamConversion::Float64ToFloat32;
}
if (format == VK_FORMAT_UNDEFINED) return false;
if (format == VK_FORMAT_UNDEFINED) return reject("format-map");
if (!SupportsVertexBufferFormat(format)) {
if (!IsScaledIntegerVertexFormat(format)) return false;
if (!IsScaledIntegerVertexFormat(format)) return reject("native-format-feature", format);
format = ToFloat32VertexFormat(attr.Size);
conversion = VertexStreamConversion::ScaledIntegerToFloat32;
if (!SupportsVertexBufferFormat(format)) return false;
if (!SupportsVertexBufferFormat(format)) return reject("converted-format-feature", format);
}
const SizeT elementSize = GetAttributeByteSize(type, attr.Size, attr.IsBgra);
if (!elementSize) return false;
if (!elementSize) return reject("element-size", format);
const Uint64 offset = attr.Offset + buffer.Offset;
if (offset < attr.Offset) return false;
if (offset < attr.Offset) return reject("offset-overflow", format);
const SizeT alignment = (type == DataType::Int2101010Rev || type == DataType::Uint2101010Rev)
? elementSize : GetComponentSize(type);
if (conversion == VertexStreamConversion::None && alignment > 1 &&
@@ -779,6 +787,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
if (m_physicalDevice == VK_NULL_HANDLE || format == VK_FORMAT_UNDEFINED) {
return false;
}
#if MOBILEGL_BUILD_DISAGGREGATED
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
const auto found = m_wireVertexFormatSupport.find(format);
if (found != m_wireVertexFormatSupport.end()) return found->second;
VkFormatProperties properties{};
vkGetPhysicalDeviceFormatProperties(m_physicalDevice, format, &properties);
const Bool supported = (properties.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0;
m_wireVertexFormatSupport.emplace(format, supported);
return supported;
}
#endif
VkFormatProperties properties{};
vkGetPhysicalDeviceFormatProperties(m_physicalDevice, format, &properties);
return (properties.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0;
@@ -183,6 +183,11 @@ namespace MobileGL::MG_Backend::DirectVulkan {
const VulkanRendererConfig& m_config;
VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
#if MOBILEGL_BUILD_DISAGGREGATED
// Physical-device format capabilities never change during this factory's
// lifetime. The wire path rebuilds layouts without the legacy VAO memo.
mutable UnorderedMap<VkFormat, Bool> m_wireVertexFormatSupport;
#endif
// Values are heap-allocated: UnorderedMap is open-addressing, so INSERT
// invalidates references to stored values - and so does ERASE, which shifts
// the rest of the probe cluster into the hole and therefore moves entries
@@ -316,7 +316,14 @@ namespace MobileGL::MG_Backend::DirectVulkan {
// Concurrent GPU reads do not prevent a CPU read. Only staged copies or
// shader writes need a host visibility barrier and a submission wait;
// ordinary index/vertex inspection must not stall once per draw.
if (resource->gpuWritesPending && !WaitForWireBufferHostAccess(*resource)) return false;
if (resource->gpuWritesPending) {
if (!WaitForWireBufferHostAccess(*resource)) return false;
// A draw may already hold a native slice of this store while another
// attribute needs a CPU conversion. The wait completes previous GPU
// work, not the draw that will bind that previously acquired slice.
// Preserve its reservation even if the idle drain advanced the frame.
resource->lastUseSerial = m_frameSerial;
}
if (!resource->buffer.Invalidate(size, offset)) return false;
Memcpy(dst, static_cast<const Uint8*>(resource->buffer.GetMappedData()) + offset, static_cast<SizeT>(size));
return true;
@@ -22,6 +22,7 @@
// (shape) and the server's staged-texture store (texels).
#include <MG_Pipe/PipeApply.h>
#include <MG_Remote/Server/StagedTextureStore.h>
#include "../DirectVulkan.h"
#endif
#include <algorithm>
#include <cstdio>
@@ -2187,6 +2188,11 @@ namespace MobileGL::MG_Backend::DirectVulkan {
resource.sampleCount == VK_SAMPLE_COUNT_1_BIT &&
resolvedSampleCount == VK_SAMPLE_COUNT_1_BIT &&
resource.layout != VK_IMAGE_LAYOUT_UNDEFINED;
// Preservation submits its copy separately. Earlier draws/clears of the
// old image must reach the queue first; waiting only for the preservation
// fence cannot order work that is still in the renderer's open recording.
// The descriptor caller preflights this before capturing its command buffer.
if (preserve && pVulkanRenderer && !pVulkanRenderer->FlushWirePendingCommandsForTextureUpdate()) return false;
TextureResource replacement;
VkImageCreateInfo imageInfo{};
@@ -2429,6 +2435,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
return true;
}
// This upload will be independently submitted by FlushPendingUploads.
// Submit older renderer work before adding the new bytes to the batch,
// otherwise Draw(old T), TexSubImage(T), Draw(new T) can upload before
// the first draw. A clean texture never reaches this submission boundary.
if (pVulkanRenderer && !pVulkanRenderer->FlushWirePendingCommandsForTextureUpdate()) return false;
// UploadDirtyMipLevels' batching rules, verbatim: flush an open batch that already
// writes this image and was touched by the open recording, and bound the staging bytes
// a batch pins.
@@ -3513,6 +3525,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
return current->mapped + alignedCursor;
}
#if MOBILEGL_BUILD_DISAGGREGATED
Bool VkTextureManager::WireUploadsAreIdle() {
// An open batch still owns references even before it has a fence. Poll
// submitted batches without waiting; reclamation is deferred if any lives.
if (m_uploadBatchOpen) return false;
ReclaimCompletedUploads();
return m_pendingUploadReclaims.empty();
}
#endif
void VkTextureManager::FlushPendingUploads() {
if (!m_uploadBatchOpen) {
return;
@@ -480,6 +480,12 @@ public:
// preserve-on-recreate copy are the existing callers. No-op when the
// batch is empty.
void FlushPendingUploads();
#if MOBILEGL_BUILD_DISAGGREGATED
// Non-blocking idle proof for wire-object retirement. Independent texture
// submissions are not represented by VulkanRenderer's submit counter.
Bool WireUploadsAreIdle();
#endif
// Drains every frame slot's deferred image/view releases. Only valid when
// the caller has proven every queue submission complete; used by the
// present-less frame-boundary drain.
@@ -3431,6 +3431,8 @@ void main() {
}
#if MOBILEGL_BUILD_DISAGGREGATED
DestroyWireDrawPass();
CollectWireObjects(m_submitCounter, true);
ClearAllWireDrawPassCaches();
DestroyWireColorBlitResources();
#endif
OnSubmitsCompletedUpTo(m_submitCounter);
@@ -5288,7 +5290,7 @@ void main() {
VkPipeline VulkanRenderer::GetOrCreatePipelineWithInput(GLenum mode, const MagmaProgramSource& program,
const ProgramFactory::VkProgramObject& programObj, ProgramFactory::CompileOptionFlags transformFlags,
const VertexInputStateFactory::BackendVertexInputState& vis, const RenderPassEntry& renderPassEntry,
Bool primitiveRestartEnable) {
Bool primitiveRestartEnable, Uint64 wireRenderPassCompatibilityId) {
#endif
Bool invertClockwise = transformFlags & ProgramFactory::CompileOptionBit::PositionYFlip;
if (programObj.stages.empty()) {
@@ -5311,7 +5313,11 @@ void main() {
auto& vis = m_vertexInputStateFactory->GetOrCreateVertexInputState(vao);
#endif
const Uint64 vertexLayoutHash = vis.layoutHash;
const Uint64 renderPassHash = renderPassEntry.hash;
const Uint64 renderPassHash =
#if MOBILEGL_BUILD_DISAGGREGATED
wireRenderPassCompatibilityId != 0 ? 0 :
#endif
renderPassEntry.hash;
// The pipeline-relevant subset only: glViewport / glScissor / glBlendColor / glStencilMask
// and friends are dynamic state or not pipeline state at all, and keying the memo on the
// all-state counter made any of them evict a perfectly good VkPipeline. The memo compares
@@ -5355,6 +5361,9 @@ void main() {
if (entry.pipeline != VK_NULL_HANDLE && entry.mode == mode &&
entry.programHash == programObj.hash && entry.vertexInputHash == vertexLayoutHash &&
entry.renderPassHash == renderPassHash &&
#if MOBILEGL_BUILD_DISAGGREGATED
entry.wireRenderPassCompatibilityId == wireRenderPassCompatibilityId &&
#endif
entry.pipelineStateHash == pipelineStateHash &&
#if MOBILEGL_PIPE_PUSH
entry.renderStateCso == renderStateCso &&
@@ -5648,6 +5657,9 @@ void main() {
.vertexInputHash = vertexLayoutHash,
.pipelineLayout = programObj.pipelineLayout,
.renderPass = renderPassEntry.renderPass,
#if MOBILEGL_BUILD_DISAGGREGATED
.wireRenderPassCompatibilityId = wireRenderPassCompatibilityId,
#endif
.colorAttachmentCount = renderPassEntry.colorAttachmentCount,
.rasterizationSamples = renderPassEntry.sampleCount,
// ARB_sample_shading. Dropped on a device without sampleRateShading rather than
@@ -5783,7 +5795,11 @@ void main() {
const auto& drawFboBinding =
MGB_CTX->GetFramebufferBindingSlot(FramebufferTarget::Draw).GetBoundObject();
#endif
#if MOBILEGL_BUILD_DISAGGREGATED
MOBILEGL_ASSERT(wireFbo != nullptr || drawFboBinding != nullptr, "GetOrCreatePipeline: draw framebuffer is null");
#else
MOBILEGL_ASSERT(drawFboBinding != nullptr, "GetOrCreatePipeline: draw framebuffer is null");
#endif
#if MOBILEGL_BUILD_DISAGGREGATED
const Bool isDefaultDrawFbo = wireFbo ? wireFbo->IsDefault : drawFboBinding->IsDefaultFramebuffer();
Array<FramebufferAttachmentType, MG_Pipe::kMGPipeMaxColorAttachments> wireDrawBuffers{};
@@ -6071,6 +6087,9 @@ void main() {
entry.programHash = programObj.hash;
entry.vertexInputHash = vertexLayoutHash;
entry.renderPassHash = renderPassHash;
#if MOBILEGL_BUILD_DISAGGREGATED
entry.wireRenderPassCompatibilityId = wireRenderPassCompatibilityId;
#endif
entry.pipelineStateHash = pipelineStateHash;
#if MOBILEGL_PIPE_PUSH
entry.renderStateCso = renderStateCso;
@@ -6438,6 +6457,12 @@ void main() {
// the SAME draw-framebuffer binding the draw uses - see the assert below.
MOBILEGL_ASSERT(
[&] {
#if MOBILEGL_BUILD_DISAGGREGATED
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
const auto* fbo = MG_Pipe::MGPipeApplier().DrawFramebuffer();
return isDefaultFbo == (fbo != nullptr && fbo->IsDefault);
}
#endif
const auto& fbo =
MGB_CTX->GetFramebufferBindingSlot(FramebufferTarget::Draw).GetBoundObject();
return isDefaultFbo == (fbo != nullptr && fbo->IsDefaultFramebuffer());
@@ -6799,6 +6824,9 @@ void main() {
if (entry.pipeline != VK_NULL_HANDLE && entry.mode == mode &&
entry.programHash == programObj.hash && entry.vertexInputHash == vaoLayoutHash &&
entry.renderPassHash == snap.renderPassHash &&
#if MOBILEGL_BUILD_DISAGGREGATED
entry.wireRenderPassCompatibilityId == 0 &&
#endif
entry.pipelineStateHash == pipelineStateHash &&
#if MOBILEGL_PIPE_PUSH
entry.renderStateCso == renderStateCso &&
@@ -7660,7 +7688,16 @@ void main() {
VkMemoryBarrier memoryBarrier = BuildMemoryBarrierForGlBarriers(barriers);
MGLOG_D("DirectVulkan: glMemoryBarrier(0x%x)", static_cast<Uint32>(barriers));
vkCmdPipelineBarrier(frame.commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
vkCmdPipelineBarrier(frame.commandBuffer,
#if MOBILEGL_BUILD_DISAGGREGATED
// ALL_COMMANDS does not include HOST. The barrier's
// HOST_WRITE access must have a matching source stage.
MG_Config::Transport != MG_Config::TransportMode::Monolith
? VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT
: VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
#else
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
#endif
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
1, &memoryBarrier, 0, nullptr, 0, nullptr);
}
@@ -13051,9 +13088,15 @@ void main() {
// Mid-frame-flushed command buffers whose submission just completed can
// be freed now; present-less flush loops have no other reclaim point.
m_frameContext.FreeRetiredCommandBuffersCompletedUpTo(m_completedSubmitCounter);
#if MOBILEGL_BUILD_DISAGGREGATED
CollectWireObjects(m_completedSubmitCounter);
#endif
}
Bool VulkanRenderer::TryDrainFrameTransients() {
#if MOBILEGL_BUILD_DISAGGREGATED
if (m_wirePreparationDepth != 0) return false;
#endif
if (m_device == VK_NULL_HANDLE || m_frameContext.GetFrameCount() == 0) {
return false;
}
@@ -13067,6 +13110,19 @@ void main() {
return false;
}
#if MOBILEGL_BUILD_DISAGGREGATED
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
// Texture uploads submit on this queue with their own fences. The
// renderer watermark alone cannot prove images/views are idle.
if (m_textureManager && !m_textureManager->WireUploadsAreIdle()) return false;
// No preparation, recording or GPU work remains. A minimized Present
// may have abandoned a recording tagged for a submission that will
// never occur, so reclaim those future-tagged objects as well.
CollectWireObjects(m_completedSubmitCounter, true);
ClearAllWireDrawPassCaches();
}
#endif
// Every submission is complete and nothing recorded references the
// per-frame transients. Pure-reclaim work runs on every drain: it only
// releases memory that is provably dead, never invalidates anything a
@@ -13170,6 +13226,9 @@ void main() {
}
Bool VulkanRenderer::SubmitPendingCommandBuffer(FrameContext::FrameData& frame, VkFence fence, Bool pooledFence) {
#if MOBILEGL_BUILD_DISAGGREGATED
RetireWireDrawPass();
#endif
// Batched texture uploads must reach the queue before the frame's
// commands: the recording being submitted may sample images whose
// texels only exist in the texture manager's open upload batch.
@@ -13435,6 +13494,11 @@ void main() {
}
void VulkanRenderer::Present() {
#if MOBILEGL_BUILD_DISAGGREGATED
// Present has its own submit path. Tag its last wire pass before that
// submission, rather than retaining it until a draw in the next frame.
RetireWireDrawPass();
#endif
if (m_swapchainObject.GetHandle() == VK_NULL_HANDLE || m_presentSuspended) {
// No usable swapchain: the window was zero-area at initialization, or
// presentation was suspended when the window minimized. Try to bring a
@@ -13624,6 +13688,11 @@ void main() {
// inside OnSubmitsCompletedUpTo.
OnSubmitsCompletedUpTo(m_frameContext.GetCurrent().lastSubmitIndex);
CollectDeferredDepthMipmapCleanup(m_frameContext.GetCurrentFrameIndex());
#if MOBILEGL_BUILD_DISAGGREGATED
// Its previous recording has completed. Drop cached attachment views
// before the texture manager can release their retired images.
ClearWireDrawPassCache(m_frameContext.GetCurrentFrameIndex());
#endif
m_textureManager->BeginFrame(m_frameContext.GetCurrentFrameIndex());
m_bufferManager.BeginFrame(m_frameContext.GetCurrentFrameIndex());
m_convertedVertexStreams.clear();
@@ -14256,7 +14325,14 @@ void main() {
descriptorIndexingFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES;
VkPhysicalDeviceDescriptorIndexingProperties descriptorIndexingProperties{};
descriptorIndexingProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES;
const Bool descriptorIndexingCore = m_physicalDevice.properties.apiVersion >= VK_API_VERSION_1_2;
const Bool descriptorIndexingCore =
#if MOBILEGL_BUILD_DISAGGREGATED && !defined(VK_USE_PLATFORM_WIN32_KHR)
// CreateInstance requests Vulkan 1.1 on these platforms. A 1.2+ GPU
// does not promote descriptor indexing into that application's core
// API; the wire path must enable VK_EXT_descriptor_indexing instead.
(MG_Config::Transport == MG_Config::TransportMode::Monolith) &&
#endif
m_physicalDevice.properties.apiVersion >= VK_API_VERSION_1_2;
const Bool descriptorIndexingExtension =
IsExtensionSupported(availableExtensions, VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
auto getPhysicalDeviceProperties2 = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2>(
@@ -15414,6 +15490,13 @@ void main() {
vkDeviceWaitIdle(m_device);
OnSubmitsCompletedUpTo(m_submitCounter);
#if MOBILEGL_BUILD_DISAGGREGATED
// The old swapchain will be destroyed below, including recordings that
// are being abandoned instead of submitted. Release all their views now.
DestroyWireDrawPass();
CollectWireObjects(m_submitCounter, true);
ClearAllWireDrawPassCaches();
#endif
if (m_timerQueryManager) {
// The in-progress command buffer is abandoned below (its recording
@@ -22,6 +22,9 @@
#include "VkSamplerManager.h"
#include "VkTextureManager.h"
#include "VkTimerQueryManager.h"
#if MOBILEGL_BUILD_DISAGGREGATED
#include "WireRenderPassCompatibility.h"
#endif
#include "MG_Util/Math/VectorTypes.h"
#include <Includes.h>
#include <MG_Backend/BackendObject.h>
@@ -143,6 +146,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
VkCommandBuffer AcquireBufferCopyCommandBuffer() override;
#if MOBILEGL_BUILD_DISAGGREGATED
VkBufferManager& GetWireBufferManager() { return m_bufferManager; }
Bool FlushWirePendingCommandsForTextureUpdate() {
return !HasPendingRecordedWork() || FlushPendingCommands();
}
#endif
// FrameContext::IRecordingObserver: prepares the frame's timer-query
@@ -470,13 +476,62 @@ namespace MobileGL::MG_Backend::DirectVulkan {
Bool SetupWireDraw(FrameContext::FrameData& frame, GLenum mode, Flags<DrawSetupAspect> aspects,
const DrawCmdParam& drawParams, const IndexBufferView* indices);
void DestroyWireDrawPass();
void RetireWireDrawPass();
struct WireDrawAttachmentKey {
MG_Pipe::MGPipeHandle storage = MG_Pipe::kMGPipeNullHandle;
Uint32 resourceKind = 0;
VkImage image = VK_NULL_HANDLE;
VkImageViewType viewType = VK_IMAGE_VIEW_TYPE_2D;
VkFormat format = VK_FORMAT_UNDEFINED;
VkImageAspectFlags aspect = 0, requestedAspect = 0;
Uint32 level = 0, layer = 0, layers = 1, imageLevels = 1;
Uint32 width = 0, height = 0;
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
Bool operator==(const WireDrawAttachmentKey&) const = default;
};
struct WireDrawPassKey {
Vector<WireDrawAttachmentKey> attachments;
Vector<Uint32> colorReferences;
Uint32 depthReference = VK_ATTACHMENT_UNUSED;
Uint32 width = 0, height = 0, layers = 1;
Uint64 textureImageEpoch = 0, resourceEraseEpoch = 0;
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Uint32 swapchainImageIndex = 0;
Bool isDefault = false, framebufferSrgb = false;
Bool operator==(const WireDrawPassKey&) const = default;
};
struct WireDrawPassCacheEntry {
WireDrawPassKey key;
UniquePtr<RenderPassEntry> pass;
Vector<VkImageView> views;
};
// Objects only: every draw still ends/begins its pass and records the
// existing memory dependencies. Each slot is cleared after its fence.
Bool AcquireCachedWireDrawPass(const WireDrawPassKey& key);
void ClearWireDrawPassCache(Uint32 frameIndex);
void ClearAllWireDrawPassCaches();
Vector<Vector<WireDrawPassCacheEntry>> m_wireDrawPassCaches;
WireDrawPassKey m_wireDrawPassKey;
WireRenderPassCompatibilityTable m_wireRenderPassCompatibility;
struct WireRetiredObjects {
Uint64 submitIndex = 0;
UniquePtr<RenderPassEntry> drawPass;
Vector<VkFramebuffer> framebuffers;
Vector<VkRenderPass> renderPasses;
Vector<VkImageView> imageViews;
Vector<VkDescriptorPool> descriptorPools;
};
void RetireWireObjects(WireRetiredObjects objects);
void CollectWireObjects(Uint64 completedSubmit, Bool all = false);
Vector<WireRetiredObjects> m_wireRetiredObjects;
Uint32 m_wirePreparationDepth = 0;
void DispatchWireCompute(GLuint x, GLuint y, GLuint z);
UniquePtr<RenderPassEntry> m_wireDrawPass;
Vector<VkImageView> m_wireDrawViews;
VkPipeline GetOrCreatePipelineWithInput(GLenum mode, const MagmaProgramSource& program,
const ProgramFactory::VkProgramObject& programObj, ProgramFactory::CompileOptionFlags transformFlags,
const VertexInputStateFactory::BackendVertexInputState& vis, const RenderPassEntry& renderPassEntry,
Bool primitiveRestartEnable);
Bool primitiveRestartEnable, Uint64 wireRenderPassCompatibilityId = 0);
void CopyWireFramebufferToTexture(GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLint x, GLint y, GLsizei width, GLsizei height);
@@ -875,6 +930,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
Uint64 programHash = 0;
Uint64 vertexInputHash = 0;
Uint64 renderPassHash = 0;
#if MOBILEGL_BUILD_DISAGGREGATED
Uint64 wireRenderPassCompatibilityId = 0;
#endif
// The PRE-HANDLE arm's key component (P2 brief D12.1), and 0 in every entry the
// handle arm mints. VALUE hash of the pipeline-relevant fixed-function state (see
// ComputePipelineStateHash), not the monotonic pipeline-state version: the version
@@ -11,8 +11,6 @@
};
VkShaderModule vertex = VK_NULL_HANDLE, fragment = VK_NULL_HANDLE;
VkDescriptorSetLayout descriptorLayout = VK_NULL_HANDLE;
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
VkDescriptorSet descriptorSet = VK_NULL_HANDLE;
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
VkSampler nearest = VK_NULL_HANDLE, linear = VK_NULL_HANDLE;
Vector<Target> targets;
@@ -20,8 +18,8 @@
void VulkanRenderer::DestroyWireColorBlitResources() {
if (!m_wireColorBlitResources) return;
// Shutdown calls this after vkDeviceWaitIdle; every individual blit also
// waits before recycling its descriptor set or destroying temporary views.
// Shutdown calls this after vkDeviceWaitIdle and after all per-submit
// descriptor pools/framebuffers/views have been collected.
auto& cache = *m_wireColorBlitResources;
for (const auto& target : cache.targets) {
vkDestroyPipeline(m_device, target.pipeline, nullptr);
@@ -29,7 +27,6 @@
}
vkDestroySampler(m_device, cache.nearest, nullptr);
vkDestroySampler(m_device, cache.linear, nullptr);
vkDestroyDescriptorPool(m_device, cache.descriptorPool, nullptr);
vkDestroyPipelineLayout(m_device, cache.pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(m_device, cache.descriptorLayout, nullptr);
vkDestroyShaderModule(m_device, cache.vertex, nullptr);
@@ -90,17 +87,6 @@
pipelineLayout.pushConstantRangeCount = 1;
pipelineLayout.pPushConstantRanges = &push;
VK_VERIFY(vkCreatePipelineLayout(m_device, &pipelineLayout, nullptr, &cache.pipelineLayout));
const VkDescriptorPoolSize poolSize{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1};
VkDescriptorPoolCreateInfo pool{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
pool.maxSets = 1;
pool.poolSizeCount = 1;
pool.pPoolSizes = &poolSize;
VK_VERIFY(vkCreateDescriptorPool(m_device, &pool, nullptr, &cache.descriptorPool));
VkDescriptorSetAllocateInfo alloc{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
alloc.descriptorPool = cache.descriptorPool;
alloc.descriptorSetCount = 1;
alloc.pSetLayouts = &cache.descriptorLayout;
VK_VERIFY(vkAllocateDescriptorSets(m_device, &alloc, &cache.descriptorSet));
VkSamplerCreateInfo sampler{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
sampler.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
sampler.addressModeU = sampler.addressModeV = sampler.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
@@ -211,10 +197,25 @@
framebufferInfo.layers = 1;
VkFramebuffer framebuffer = VK_NULL_HANDLE;
VK_VERIFY(vkCreateFramebuffer(m_device, &framebufferInfo, nullptr, &framebuffer));
// Each in-flight blit owns its descriptor set. Updating a cached set
// would rewrite the source view of an older queued blit.
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
VkDescriptorSet descriptorSet = VK_NULL_HANDLE;
const VkDescriptorPoolSize poolSize{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1};
VkDescriptorPoolCreateInfo pool{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
pool.maxSets = 1;
pool.poolSizeCount = 1;
pool.pPoolSizes = &poolSize;
VK_VERIFY(vkCreateDescriptorPool(m_device, &pool, nullptr, &descriptorPool));
VkDescriptorSetAllocateInfo alloc{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
alloc.descriptorPool = descriptorPool;
alloc.descriptorSetCount = 1;
alloc.pSetLayouts = &cache.descriptorLayout;
VK_VERIFY(vkAllocateDescriptorSets(m_device, &alloc, &descriptorSet));
const VkDescriptorImageInfo sampled{filter == GL_LINEAR ? cache.linear : cache.nearest,
sourceView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL};
VkWriteDescriptorSet write{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
write.dstSet = cache.descriptorSet;
write.dstSet = descriptorSet;
write.dstBinding = 0;
write.descriptorCount = 1;
write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
@@ -244,17 +245,21 @@
vkCmdSetViewport(frame.commandBuffer, 0, 1, &viewport);
vkCmdSetScissor(frame.commandBuffer, 0, 1, &scissor);
vkCmdBindDescriptorSets(frame.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
cache.pipelineLayout, 0, 1, &cache.descriptorSet, 0, nullptr);
cache.pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
vkCmdPushConstants(frame.commandBuffer, cache.pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT,
0, sizeof(constants), &constants);
vkCmdDraw(frame.commandBuffer, 6, 1, 0, 0);
vkCmdEndRenderPass(frame.commandBuffer);
ResetDynamicStateShadow();
InvalidatePipelineMemo();
if (!SubmitReadbackCommandsAndWait(frame)) MagmaWireFatal("color-blit-submit");
vkDestroyFramebuffer(m_device, framebuffer, nullptr);
vkDestroyImageView(m_device, sourceView, nullptr);
vkDestroyImageView(m_device, destinationView, nullptr);
// This native pass binds its own set/layout without going through the
// application's descriptor binder. Its next fast path must rebind.
if (m_uniformManager) m_uniformManager->OnCommandBufferBoundary();
WireRetiredObjects retired{};
retired.framebuffers.push_back(framebuffer);
retired.imageViews = {sourceView, destinationView};
retired.descriptorPools.push_back(descriptorPool);
RetireWireObjects(Move(retired));
m_swapchainObject.SetImageContentDefined(m_imageIndexAcquired, true);
return true;
}
@@ -53,14 +53,107 @@
}
void VulkanRenderer::DestroyWireDrawPass() {
// FlushPendingCommands only submits. These objects may still be referenced by
// that submission, so retire this temporary pass after the queue completes.
if (m_wireDrawPass || !m_wireDrawViews.empty()) VK_VERIFY(vkQueueWaitIdle(m_graphicsQueue));
// Only shutdown/swapchain replacement calls this, after device idle.
if (m_wireDrawPass && m_frameContext.GetFrameCount() != 0) {
auto& frame = m_frameContext.GetCurrent();
if (frame.isCommandRecording && VkRenderPassManager::GetActiveRenderPass())
VkRenderPassManager::EndRenderPass(frame.commandBuffer);
}
m_wireDrawPass.reset();
for (const auto view : m_wireDrawViews) vkDestroyImageView(m_device, view, nullptr);
m_wireDrawViews.clear();
m_wireDrawPassKey = {};
}
void VulkanRenderer::RetireWireObjects(WireRetiredObjects objects) {
// The current recording is the next graphics submission. Do not use a
// frame number: mid-frame flushes and readbacks can split one frame.
objects.submitIndex = m_submitCounter + 1;
m_wireRetiredObjects.push_back(Move(objects));
}
void VulkanRenderer::RetireWireDrawPass() {
if (!m_wireDrawPass) return;
auto& frame = m_frameContext.GetCurrent();
if (frame.isCommandRecording && VkRenderPassManager::GetActiveRenderPass())
VkRenderPassManager::EndRenderPass(frame.commandBuffer);
const Uint32 frameIndex = m_frameContext.GetCurrentFrameIndex();
if (m_wireDrawPassCaches.size() < m_frameContext.GetFrameCount())
m_wireDrawPassCaches.resize(m_frameContext.GetFrameCount());
auto& cache = m_wireDrawPassCaches[frameIndex];
// Bound a present-less stream of distinct framebuffer configurations.
// Overflow retains the original submit-index retirement path.
constexpr SizeT kMaxCachedWirePassesPerFrame = 32;
if (cache.size() < kMaxCachedWirePassesPerFrame) {
cache.push_back({Move(m_wireDrawPassKey), Move(m_wireDrawPass), Move(m_wireDrawViews)});
return;
}
WireRetiredObjects retired{};
retired.drawPass = Move(m_wireDrawPass);
retired.imageViews = Move(m_wireDrawViews);
RetireWireObjects(Move(retired));
m_wireDrawPassKey = {};
}
Bool VulkanRenderer::AcquireCachedWireDrawPass(const WireDrawPassKey& key) {
const Uint32 frameIndex = m_frameContext.GetCurrentFrameIndex();
if (frameIndex >= m_wireDrawPassCaches.size()) return false;
auto& cache = m_wireDrawPassCaches[frameIndex];
for (auto it = cache.begin(); it != cache.end(); ++it) {
// Exact values, not a compatibility hash: two FBOs with the same
// formats can name different images, windows or draw-buffer slots.
if (!(it->key == key)) continue;
m_wireDrawPassKey = Move(it->key);
m_wireDrawPass = Move(it->pass);
m_wireDrawViews = Move(it->views);
cache.erase(it);
return true;
}
return false;
}
void VulkanRenderer::ClearWireDrawPassCache(Uint32 frameIndex) {
if (frameIndex >= m_wireDrawPassCaches.size()) return;
auto& cache = m_wireDrawPassCaches[frameIndex];
for (auto& entry : cache) {
entry.pass.reset();
for (const auto view : entry.views) vkDestroyImageView(m_device, view, nullptr);
}
cache.clear();
}
void VulkanRenderer::ClearAllWireDrawPassCaches() {
for (Uint32 frameIndex = 0; frameIndex < m_wireDrawPassCaches.size(); ++frameIndex)
ClearWireDrawPassCache(frameIndex);
}
void VulkanRenderer::CollectWireObjects(Uint64 completedSubmit, Bool all) {
SizeT retained = 0;
for (SizeT index = 0; index < m_wireRetiredObjects.size(); ++index) {
auto& entry = m_wireRetiredObjects[index];
if (!all && entry.submitIndex > completedSubmit) {
if (retained != index) m_wireRetiredObjects[retained] = Move(entry);
++retained;
continue;
}
// Framebuffers/descriptor sets stop naming their views first.
entry.drawPass.reset();
for (const auto pool : entry.descriptorPools) vkDestroyDescriptorPool(m_device, pool, nullptr);
for (const auto framebuffer : entry.framebuffers) vkDestroyFramebuffer(m_device, framebuffer, nullptr);
for (const auto pass : entry.renderPasses) vkDestroyRenderPass(m_device, pass, nullptr);
for (const auto view : entry.imageViews) vkDestroyImageView(m_device, view, nullptr);
}
// Erase once: repeated front erases move the whole remaining cohort for
// every draw retired by a fence, turning a batch retirement quadratic.
m_wireRetiredObjects.resize(retained);
}
struct WirePreparationScope {
Uint32& depth;
explicit WirePreparationScope(Uint32& value) : depth(value) { ++depth; }
~WirePreparationScope() { --depth; }
};
Bool VulkanRenderer::SetupWireDraw(FrameContext::FrameData& frame, GLenum mode,
Flags<DrawSetupAspect> aspects, const DrawCmdParam& drawParams, const IndexBufferView* indices) {
auto& state = MG_Pipe::MGPipeApplier();
@@ -70,8 +163,10 @@
WireBufferLegacyFatal();
const auto* fbo = state.DrawFramebuffer();
if (!fbo) MagmaWireFatal("draw-framebuffer-record");
if (HasPendingRecordedWork() && !FlushPendingCommands()) MagmaWireFatal("draw-flush");
DestroyWireDrawPass();
RetireWireDrawPass();
// CPU preparation may synchronize GPU-produced vertex/index bytes. Do
// not rewind an arena while this draw owns as-yet-unrecorded slices.
WirePreparationScope preparing(m_wirePreparationDepth);
ProgramFactory::CompileOptionFlags flags =
ProgramFactory::CompileOptionFlags(GetBaseTransformFlagsRaw(fbo->IsDefault));
@@ -82,6 +177,18 @@
}
if (programObject->pointSizeCapabilityUnsupported) return false;
const auto& programObj = *programObject;
if (!m_uniformManager->PrepareWireTextureResources(program, programObj)) return false;
// Lazy image uploads/promotions can submit the old recording. Resolve
// ALL attachments before descriptor binding captures the current cmd.
for (Uint32 i = 0; i < MG_Pipe::kMGPipeMaxColorAttachments; ++i) {
const Int32 slot = fbo->DrawBuffers[i];
if (slot >= 0) (void)ResolveWireImage(*fbo, fbo->Color[slot], VK_IMAGE_ASPECT_COLOR_BIT);
}
if (fbo->IsDefault || fbo->Depth.Kind != MG_Pipe::kMGPipeSurfaceKindNone)
(void)ResolveWireImage(*fbo, fbo->Depth, VK_IMAGE_ASPECT_DEPTH_BIT);
else if (fbo->Stencil.Kind != MG_Pipe::kMGPipeSurfaceKindNone)
(void)ResolveWireImage(*fbo, fbo->Stencil, VK_IMAGE_ASPECT_STENCIL_BIT);
m_textureManager->FlushPendingUploads();
const auto vaoHandle = state.BoundVertexElements;
if (MG_Pipe::MGPipeHandleIsNull(vaoHandle)) MagmaWireFatal("vertex-elements-record");
if (vaoHandle.Slot >= state.VertexElementsCsos.size()) MagmaWireFatal("vertex-elements-record");
@@ -187,13 +294,20 @@
m_frameContext.GetCurrentFrameIndex(), VK_PIPELINE_BIND_POINT_GRAPHICS)) return false;
Vector<VkAttachmentDescription> attachments;
Vector<VkImageView> views;
Vector<VkImageViewCreateInfo> viewInfos;
Vector<VkAttachmentReference> colors;
VkAttachmentReference depth{VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL};
VkExtent2D extent{~0u, ~0u};
Uint32 layers = ~0u;
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
Uint64 passHash = 0;
WireDrawPassKey passKey{};
passKey.isDefault = fbo->IsDefault;
passKey.framebufferSrgb = MGB_CTX->IsCapabilityEnabled(CapabilityInput::FramebufferSrgb);
if (fbo->IsDefault) {
passKey.swapchain = m_swapchainObject.GetHandle();
passKey.swapchainImageIndex = m_imageIndexAcquired;
}
const auto add = [&](const MG_Pipe::MGPSurface& surface, VkImageAspectFlags aspect) -> Uint32 {
WireImage image = ResolveWireImage(*fbo, surface, aspect);
if (!image.image) return VK_ATTACHMENT_UNUSED;
@@ -211,10 +325,11 @@
info.subresourceRange = {aspect, image.level, 1, image.layer, image.layers};
if (image.format == VK_FORMAT_D24_UNORM_S8_UINT || image.format == VK_FORMAT_D32_SFLOAT_S8_UINT)
info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
VkImageView view = VK_NULL_HANDLE;
VK_VERIFY(vkCreateImageView(m_device, &info, nullptr, &view));
m_wireDrawViews.push_back(view);
views.push_back(view);
viewInfos.push_back(info);
passKey.attachments.push_back({image.storage, static_cast<Uint32>(surface.Kind), image.image,
image.viewType, image.format, info.subresourceRange.aspectMask, aspect,
image.level, image.layer, image.layers, image.levels, image.extent.width, image.extent.height,
image.samples});
VkAttachmentDescription description{};
description.format = image.format;
description.samples = image.samples;
@@ -246,6 +361,15 @@
else if (fbo->Stencil.Kind != MG_Pipe::kMGPipeSurfaceKindNone)
depth.attachment = add(fbo->Stencil, VK_IMAGE_ASPECT_STENCIL_BIT);
if (attachments.empty()) return false;
passKey.width = extent.width;
passKey.height = extent.height;
passKey.layers = layers;
passKey.depthReference = depth.attachment;
for (const auto& color : colors) passKey.colorReferences.push_back(color.attachment);
// A native handle can be recycled after image replacement or death.
// Sample epochs after every lazy resolve, then compare them with the key.
passKey.textureImageEpoch = m_textureManager->GetTextureImageEpoch();
passKey.resourceEraseEpoch = m_textureManager->GetResourceEraseEpoch();
VkSubpassDescription subpass{};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = static_cast<Uint32>(colors.size());
@@ -256,24 +380,43 @@
passInfo.pAttachments = attachments.data();
passInfo.subpassCount = 1;
passInfo.pSubpasses = &subpass;
m_wireDrawPass = MakeUnique<RenderPassEntry>();
if (!AcquireCachedWireDrawPass(passKey)) {
m_wireDrawPassKey = Move(passKey);
Vector<VkImageView> views;
views.reserve(viewInfos.size());
for (const auto& info : viewInfos) {
VkImageView view = VK_NULL_HANDLE;
VK_VERIFY(vkCreateImageView(m_device, &info, nullptr, &view));
m_wireDrawViews.push_back(view);
views.push_back(view);
}
m_wireDrawPass = MakeUnique<RenderPassEntry>();
auto& created = *m_wireDrawPass;
VK_VERIFY(vkCreateRenderPass(m_device, &passInfo, nullptr, &created.renderPass));
VkFramebufferCreateInfo fbInfo{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO};
fbInfo.renderPass = created.renderPass;
fbInfo.attachmentCount = static_cast<Uint32>(views.size());
fbInfo.pAttachments = views.data();
fbInfo.width = extent.width; fbInfo.height = extent.height; fbInfo.layers = layers;
VK_VERIFY(vkCreateFramebuffer(m_device, &fbInfo, nullptr, &created.framebuffer));
created.attachmentCount = static_cast<Uint32>(attachments.size());
created.colorAttachmentCount = static_cast<Uint32>(colors.size());
created.hasDepthStencilAttachment = depth.attachment != VK_ATTACHMENT_UNUSED;
created.sampleCount = samples;
created.extent = {static_cast<Int>(extent.width), static_cast<Int>(extent.height)};
created.layers = layers;
created.hash = created.compatibilityHash = XXH64(colors.data(), colors.size() * sizeof(colors[0]), passHash);
}
auto& pass = *m_wireDrawPass;
VK_VERIFY(vkCreateRenderPass(m_device, &passInfo, nullptr, &pass.renderPass));
VkFramebufferCreateInfo fbInfo{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO};
fbInfo.renderPass = pass.renderPass;
fbInfo.attachmentCount = static_cast<Uint32>(views.size());
fbInfo.pAttachments = views.data();
fbInfo.width = extent.width; fbInfo.height = extent.height; fbInfo.layers = layers;
VK_VERIFY(vkCreateFramebuffer(m_device, &fbInfo, nullptr, &pass.framebuffer));
pass.attachmentCount = static_cast<Uint32>(attachments.size());
pass.colorAttachmentCount = static_cast<Uint32>(colors.size());
pass.hasDepthStencilAttachment = depth.attachment != VK_ATTACHMENT_UNUSED;
pass.sampleCount = samples;
pass.extent = {static_cast<Int>(extent.width), static_cast<Int>(extent.height)};
pass.layers = layers;
pass.hash = pass.compatibilityHash = XXH64(colors.data(), colors.size() * sizeof(colors[0]), passHash);
WireRenderPassCompatibilityKey pipelinePassKey{};
for (const auto& attachment : attachments)
pipelinePassKey.attachmentFormatsAndSamples.push_back(
(static_cast<Uint64>(attachment.format) << 32) | static_cast<Uint32>(attachment.samples));
for (const auto& color : colors) pipelinePassKey.colorReferences.push_back(color.attachment);
pipelinePassKey.depthReference = depth.attachment;
const Uint64 compatibilityId = m_wireRenderPassCompatibility.Intern(pipelinePassKey);
const auto pipeline = GetOrCreatePipelineWithInput(mode, program, programObj, flags, input, pass,
ResolvePrimitiveRestartEnable(aspects, indices));
ResolvePrimitiveRestartEnable(aspects, indices), compatibilityId);
if (pipeline == VK_NULL_HANDLE) return false;
for (Uint32 i = 0; i < vertexSlices.size(); ++i)
vkCmdBindVertexBuffers(frame.commandBuffer, i, 1, &vertexSlices[i].buffer, &vertexSlices[i].offset);
@@ -301,11 +444,12 @@
}
void VulkanRenderer::DispatchWireCompute(GLuint x, GLuint y, GLuint z) {
if (HasPendingRecordedWork() && !FlushPendingCommands()) MagmaWireFatal("dispatch-flush");
RetireWireDrawPass();
auto& frame = m_frameContext.GetCurrent();
const auto program = WireProgramSource(MG_Pipe::MGPipeApplier().DispatchProgram);
if (!program.GetLinkStatus() || !program.GetSpirvStatus()) return;
const auto& programObj = m_programFactory->GetOrCreateProgram(program, {});
if (!m_uniformManager->PrepareWireTextureResources(program, programObj)) return;
const auto pipeline = GetOrCreateComputePipeline(programObj);
if (!pipeline) return;
if (!frame.isCommandRecording) m_frameContext.BeginCommandRecording();
@@ -67,6 +67,16 @@
VkImageAspectFlags barrierAspect = image.aspect;
if (image.format == VK_FORMAT_D24_UNORM_S8_UINT || image.format == VK_FORMAT_D32_SFLOAT_S8_UINT)
barrierAspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
if (image.layout == layout) {
// GENERAL->GENERAL is not a layout transition, but the next load,
// sample or blit still depends on earlier attachment/shader writes.
// The old per-verb queue idle must not be its only ordering edge.
VkMemoryBarrier memory{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
memory.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
memory.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
vkCmdPipelineBarrier(frame.commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 1, &memory, 0, nullptr, 0, nullptr);
}
if (!VkTextureManager::TransitionImageLayout(frame.commandBuffer, image.image, image.layout, layout,
stage, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, access,
VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, barrierAspect, 0, image.levels))
@@ -81,7 +91,7 @@
void VulkanRenderer::ClearWireFramebuffer(const MG_Pipe::MGPFramebufferState& fbo,
const ClearAttachmentPayload& payload, GLint drawbuffer) {
if (HasPendingRecordedWork() && !FlushPendingCommands()) MagmaWireFatal("wire-verb-flush");
RetireWireDrawPass();
if (MGB_CTX->IsCapabilityEnabled(CapabilityInput::RasterizerDiscard)) return;
const auto clearSurface = [&](const MG_Pipe::MGPSurface& surface, VkImageAspectFlags aspect,
Uint32 colorIndex) {
@@ -171,12 +181,11 @@
vkCmdBeginRenderPass(frame.commandBuffer, &begin, VK_SUBPASS_CONTENTS_INLINE);
vkCmdClearAttachments(frame.commandBuffer, 1, &clear, 1, &rect);
vkCmdEndRenderPass(frame.commandBuffer);
// P5f changes ownership, not Magma's wait contract. Synchronous retirement keeps
// these temporary server resources bounded and makes their lifetime explicit.
if (!SubmitReadbackCommandsAndWait(frame)) MagmaWireFatal("clear-submit");
vkDestroyFramebuffer(m_device, fb, nullptr);
vkDestroyRenderPass(m_device, pass, nullptr);
vkDestroyImageView(m_device, view, nullptr);
WireRetiredObjects retired{};
retired.framebuffers.push_back(fb);
retired.renderPasses.push_back(pass);
retired.imageViews.push_back(view);
RetireWireObjects(Move(retired));
if (!image.isDefault && surface.Kind == MG_Pipe::kMGPipeSurfaceKindTexture)
m_textureManager->MarkWireTextureGpuWritten(image.storage, image.level, image.layer, image.layers);
if (image.isDefault) {
@@ -253,7 +262,7 @@
void VulkanRenderer::BlitWireFramebuffers(GLint sx0, GLint sy0, GLint sx1, GLint sy1,
GLint dx0, GLint dy0, GLint dx1, GLint dy1, GLbitfield mask, GLenum filter) {
if (HasPendingRecordedWork() && !FlushPendingCommands()) MagmaWireFatal("wire-verb-flush");
RetireWireDrawPass();
// The scissor test clips blit writes: intersect the destination rectangle with
// the scissor box and shrink the source proportionally.
if (MGB_CTX->IsCapabilityEnabled(CapabilityInput::ScissorTest)) {
@@ -377,7 +386,7 @@
"CopyTexSubImage2D currently only supports GL_TEXTURE_2D destinations.");
return;
}
if (HasPendingRecordedWork() && !FlushPendingCommands()) MagmaWireFatal("wire-verb-flush");
RetireWireDrawPass();
auto& state = MG_Pipe::MGPipeApplier();
const auto* read = state.ReadFramebuffer();
if (!read) MagmaWireFatal("copy-framebuffer-record");
@@ -415,7 +424,7 @@
}
void VulkanRenderer::GenerateWireMipmap() {
if (HasPendingRecordedWork() && !FlushPendingCommands()) MagmaWireFatal("wire-verb-flush");
RetireWireDrawPass();
auto& state = MG_Pipe::MGPipeApplier();
Uint32 base = state.VerbMipBaseLevel, baseLayer = 0, layerCount = 1;
const auto handle = m_textureManager->ResolveWireTextureStorage(state.VerbMipRes, base, baseLayer,
@@ -423,7 +432,7 @@
auto* resource = m_textureManager->SyncTextureResourceByHandle(handle);
if (!resource) MagmaWireFatal("mipmap-resource");
m_textureManager->FlushPendingUploads();
if (HasPendingRecordedWork() && !FlushPendingCommands()) MagmaWireFatal("mipmap-flush");
RetireWireDrawPass();
auto& frame = m_frameContext.GetCurrent();
if (!frame.isCommandRecording) m_frameContext.BeginCommandRecording();
const Uint32 count = state.VerbMipLevelCount;
@@ -0,0 +1,49 @@
#pragma once
#include <Includes.h>
#include "../VkIncludes.h"
#if MOBILEGL_BUILD_DISAGGREGATED
namespace MobileGL::MG_Backend::DirectVulkan {
// The wire draw pass has one graphics subpass, no input attachments,
// multiview or extensions. Its Vulkan pipeline compatibility is formats,
// sample counts and the ordered attachment references, not native handles,
// image identity, dimensions, load/store operations or image layouts.
struct WireRenderPassCompatibilityKey {
Vector<Uint64> attachmentFormatsAndSamples;
Vector<Uint32> colorReferences;
Uint32 depthReference = VK_ATTACHMENT_UNUSED;
Bool operator==(const WireRenderPassCompatibilityKey&) const = default;
};
struct WireRenderPassCompatibilityHash {
SizeT operator()(const WireRenderPassCompatibilityKey& key) const {
SizeT hash = 0;
const auto mix = [&](Uint64 value) {
hash ^= static_cast<SizeT>(value) + 0x9e3779b97f4a7c15ull + (hash << 6) + (hash >> 2);
};
mix(key.attachmentFormatsAndSamples.size());
for (const auto value : key.attachmentFormatsAndSamples) mix(value);
mix(key.colorReferences.size());
for (const auto value : key.colorReferences) mix(value);
mix(key.depthReference);
return hash;
}
};
class WireRenderPassCompatibilityTable {
public:
Uint64 Intern(const WireRenderPassCompatibilityKey& key) {
if (const auto found = m_ids.find(key); found != m_ids.end()) return found->second;
// No reset/eviction: an ID cannot be reused while a pipeline factory
// or a renderer memo can still hold its previous meaning.
MOBILEGL_ASSERT(m_nextId != 0, "wire render-pass compatibility ID exhausted");
const Uint64 id = m_nextId++;
m_ids.emplace(key, id);
return id;
}
private:
UnorderedMap<WireRenderPassCompatibilityKey, Uint64, WireRenderPassCompatibilityHash> m_ids;
Uint64 m_nextId = 1; // zero selects the native-handle pipeline domain
};
}
#endif
+7 -16
View File
@@ -96,11 +96,12 @@ namespace MobileGL::MG_Backend {
// the apply thread reading client memory that has already moved, which renders wrong
// rather than aborting.
constexpr Bool kMGPipeP5eRunAheadReady = true;
constexpr Bool kMGPipeMagmaRunAheadReady = true;
// The Magma transport now owns buffer stores and consumes their vertex,
// index and shader binding records. Both backends publish the resource
// family only alongside a real op table (checked below). This does not
// publish kCapRunAheadApply: Magma keeps its existing lockstep contract.
// itself establish run-ahead readiness: that has its separate gate below.
Uint64 ConsumedSubsystemsFor(BackendType type) {
switch (type) {
case BackendType::DirectGLES: return MG_Pipe::kMGPipeSubsystemsMigratedAtP5e;
@@ -186,21 +187,11 @@ namespace MobileGL::MG_Backend {
serverBackend->GetBackendFunctions().GL.EndTransformFeedback != nullptr) {
capBits |= MG_Pipe::kCapBackendOwnsXfbCapture;
}
// P5e (CONTRACT-P5E.md §1, §6): kCapRunAheadApply, THE DIRECTGLES ARM AND ONLY IT.
//
// Magma is deliberately absent and is not an omission: it keeps the lockstep for
// the whole of P5e, its four apply-thread allocator sites are real debt P7 retires,
// and MGPipeApplierCurrentRecordIsBarriered() answers true for every record on a
// server that does not publish this bit - which is exactly what keeps those probes
// and its BARRIER_PULLED reads inside P5C's semantics and its rsp accounting
// honest. Publishing the bit here for DirectVulkan would turn accounted pulls into
// torn ones, so MagmaPipeIdentityTest pins its absence.
//
// The Espryt arm is gated on kMGPipeP5eRunAheadReady, which is false until the
// integration commit: the bit is what ARMS the client, so every package before it
// lands inert.
capBits |= MG_Pipe::MGPipeRunAheadCapBitsFor(MG_Config::ActiveBackendType,
kMGPipeP5eRunAheadReady);
// Each backend has an independent implementation-readiness gate.
// The runtime RunAhead knob can decline the feature, never create it.
const Bool runAheadReady = MG_Config::ActiveBackendType == BackendType::DirectVulkan
? kMGPipeMagmaRunAheadReady : kMGPipeP5eRunAheadReady;
capBits |= MG_Pipe::MGPipeRunAheadCapBitsFor(MG_Config::ActiveBackendType, runAheadReady);
session.SetCapabilityBits(capBits);
session.SetBackend(loop.Backend());
@@ -1179,7 +1179,16 @@ namespace MobileGL::MG_Impl::GLImpl {
: GetMinComputeWorkGroupSize(index);
GLint backendValue = 0;
if (getIntegeri) {
#if MOBILEGL_BUILD_DISAGGREGATED
// Transport's Class A caps mirror answers these two pnames
// locally and emits no record. A fill would wrongly quiesce
// the apply thread before every compute dispatch validation.
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) {
#endif
MGP_FILL(GetIntegeri_v);
#if MOBILEGL_BUILD_DISAGGREGATED
}
#endif
getIntegeri(target, index, &backendValue);
}
*data = std::max(backendValue, minimum);
+21 -1
View File
@@ -322,8 +322,11 @@ namespace MobileGL::MG_Pipe {
now[Index(MGPipeDirty::NewVertexAttribDefaults)] = ctx.GetAnyVertexAttribDefaultGeneration();
const auto& vao = ctx.GetBoundVertexArray();
const Uint64 vaoLifetime = vao ? vao->GetLifetimeId() : 0;
const Uint32 vaoConfig = vao ? vao->GetConfigVersion() : 0;
const Bool vaoChanged = !m_primed || vaoLifetime != m_lastVaoLifetime || vaoConfig != m_lastVaoConfig;
const Uint64 vaoIdentity =
vao ? MGPipeMixShutter(vao->GetLifetimeId(), vao->GetConfigVersion()) : 0;
vao ? MGPipeMixShutter(vaoLifetime, vaoConfig) : 0;
now[Index(MGPipeDirty::NewVertexElements)] = vaoIdentity;
// Deliberately NOT GetProgramForDraw: that joins a pending link, and the tracker
@@ -722,6 +725,19 @@ namespace MobileGL::MG_Pipe {
m_lastPushed[i] = now[i];
}
// The lifetime/configuration pair is an identity, not a content hash.
// hash_combine collides readily for nearby integer pairs; missing a
// VAO bind can pair the old layout with the new VAO's buffer window.
// Revalidate all three vertex families on an exact pair change. Their
// own emitters still suppress unchanged records.
if (vaoChanged) {
dirty |= MGPipeDirtyBit(MGPipeDirty::NewVertexElements) |
MGPipeDirtyBit(MGPipeDirty::NewVertexBuffers) |
MGPipeDirtyBit(MGPipeDirty::NewIndexBuffer);
}
m_lastVaoLifetime = vaoLifetime;
m_lastVaoConfig = vaoConfig;
// ---- bit 2: the PACK half of the pixel store, BitwiseEqual ----
const PixelStoreParameters pack = ctx.GetPixelStoreParameters(false);
if (!m_primed || std::memcmp(&pack, &m_pack, sizeof(pack)) != 0) {
@@ -773,6 +789,8 @@ namespace MobileGL::MG_Pipe {
// by MGPipeLeaveVerb, which is where a per-call argument belongs.
void Reset() {
std::memset(m_lastPushed, 0, sizeof(m_lastPushed));
m_lastVaoLifetime = 0;
m_lastVaoConfig = 0;
m_renderStateVersion.Reset();
m_pipelineStateVersion.Reset();
m_framebufferBind.Reset();
@@ -861,6 +879,8 @@ namespace MobileGL::MG_Pipe {
};
Uint64 m_lastPushed[kMGPipeDirtyCount]{};
Uint64 m_lastVaoLifetime = 0;
Uint32 m_lastVaoConfig = 0;
MGPipeWidenedCounter m_renderStateVersion;
MGPipeWidenedCounter m_pipelineStateVersion;
// The draw framebuffer BINDING slot version, widened for the same reason: a Uint16
@@ -2457,6 +2457,70 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
endforeach()
endif()
# Real Magma run-ahead, including client lead and present-credit backpressure.
# The test fixture requires an actually armed production session; a missing cap
# fails rather than turning this dedicated lane into a skip or a lockstep pass.
if (MOBILEGL_BUILD_DISAGGREGATED)
target_sources(MobileGLIntegrationTest PRIVATE Scenarios/MagmaRunAheadScenario.cpp)
foreach(credit 1 3)
mgl_itest_join_environment(MGL_ITEST_MAGMA_RUNAHEAD_ENVIRONMENT
"MOBILEGL_BACKEND_TYPE=DirectVulkan" "MOBILEGL_TRANSPORT=inproc"
"MOBILEGL_IPC_ROLE_SPLIT_STATE=1" "MOBILEGL_IPC_STRICT_ERRORS=1"
"MOBILEGL_IPC_RUN_AHEAD=1" "MOBILEGL_IPC_PRESENT_CREDIT=${credit}"
"MOBILEGL_IPC_SPIN_US=0" "MOBILEGL_IPC_ADOPT_TIER=2"
"MGITEST_MAGMA_RUNAHEAD_LANE=1" "MGITEST_SPLIT_LANE=1"
"MOBILEGL_ITEST_REQUIRE_GPU=1"
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
foreach(runAheadCase
QueuedBufferVersionsAndDeletedNameReuseKeepTheirPixels
QueuedProgramRebindsKeepEachUniformSnapshot
QueuedGpuWritesReadBackTheLastDispatchBytes
MixedNativeAndConvertedGpuVertexStreamsKeepTheirReservation
TextureUploadCannotOvertakeThePreviouslyQueuedDraw
GpuClearSurvivesTheFirstStorageImageUpgrade
PresentCreditActuallyParksTheClientAtItsConfiguredLimit)
gtest_discover_tests(MobileGLIntegrationTest
TEST_PREFIX "DirectVulkan.Split.RunAhead.Credit${credit}."
TEST_FILTER "MagmaRunAheadScenario.${runAheadCase}"
DISCOVERY_TIMEOUT 30
PROPERTIES LABELS "integration-magma-split\;integration-magma-runahead"
TIMEOUT ${MGL_ITEST_TIMEOUT}
ENVIRONMENT "${MGL_ITEST_MAGMA_RUNAHEAD_ENVIRONMENT}\;MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/magma-runahead-credit${credit}-${runAheadCase}.log")
endforeach()
endforeach()
endif()
# Magma wire caches: exact view/attachment identity across public GL mutations.
# Split-only source preserves pull discovery; generic split-build registrations
# retain these names but skip outside this dedicated, strict inproc environment.
if (MOBILEGL_BUILD_DISAGGREGATED)
target_sources(MobileGLIntegrationTest PRIVATE Scenarios/MagmaWireCacheScenario.cpp)
mgl_itest_join_environment(MGL_ITEST_MAGMA_CACHES_ENVIRONMENT
"MOBILEGL_BACKEND_TYPE=DirectVulkan" "MOBILEGL_TRANSPORT=inproc"
"MOBILEGL_IPC_ROLE_SPLIT_STATE=1" "MOBILEGL_IPC_STRICT_ERRORS=1"
"MOBILEGL_IPC_RUN_AHEAD=1" "MOBILEGL_IPC_PRESENT_CREDIT=3"
"MOBILEGL_IPC_SPIN_US=0" "MOBILEGL_IPC_ADOPT_TIER=2"
"MGITEST_MAGMA_CACHES_LANE=1" "MGITEST_SPLIT_LANE=1"
"MOBILEGL_ITEST_REQUIRE_GPU=1"
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
foreach(cacheCase
SamplerSwizzleAtoBtoAKeepsEachQueuedPixel
SamplerRespecifyKeepsOldAndNewNativeImages
SamplerViewsDistinguishMipLayerAndViewType
FramebuffersAtoBtoAKeepDistinctAttachments
FramebufferReattachmentDistinguishesMipAndLayer
FramebufferSrgbPolicyAtoBtoAUsesDistinctFormats
FramebufferRespecifyRebindsTheNewNativeImage)
gtest_discover_tests(MobileGLIntegrationTest
TEST_PREFIX "DirectVulkan.Split.Caches."
TEST_FILTER "MagmaWireCacheScenario.${cacheCase}"
DISCOVERY_TIMEOUT 30
PROPERTIES LABELS "integration-magma-split\;integration-magma-caches"
TIMEOUT ${MGL_ITEST_TIMEOUT}
ENVIRONMENT "${MGL_ITEST_MAGMA_CACHES_ENVIRONMENT}\;MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/magma-caches-${cacheCase}.log")
endforeach()
endif()
# P5c ct (MG_Remote/CONTRACT-P5C.md §5): the two control records, split-only source for the
# same reason as f1's - the scenario reads the SERVER sink's tallies, which a monolith build
# has no symbol for. One block per case with a LOG PATH OF ITS OWN, the F1 pattern:
@@ -21,11 +21,90 @@
#include <MG_Remote/Client/EmitTables.h>
#include <MG_Remote/Server/ServerLoop.h>
#include <chrono>
#include <atomic>
#include <thread>
#define MGITEST_SPLIT_RUNTIME_PEEK_LIVE 1
#endif
namespace MGITest {
#if defined(MGITEST_SPLIT_RUNTIME_PEEK_LIVE)
namespace {
std::atomic<bool> g_holdArmed{false}, g_holdActive{false}, g_holdRelease{true};
void HoldOneAppliedBatch() {
if (!g_holdArmed.exchange(false, std::memory_order_acq_rel)) return;
g_holdActive.store(true, std::memory_order_release);
const auto until = std::chrono::steady_clock::now() + std::chrono::seconds(2);
while (!g_holdRelease.load(std::memory_order_acquire) && std::chrono::steady_clock::now() < until)
std::this_thread::sleep_for(std::chrono::milliseconds(1));
g_holdActive.store(false, std::memory_order_release);
}
}
#endif
bool ArmSplitApplyHoldForTesting() {
#if defined(MGITEST_SPLIT_RUNTIME_PEEK_LIVE)
g_holdRelease.store(false, std::memory_order_release);
g_holdArmed.store(true, std::memory_order_release);
MobileGL::MG_Remote::Server::ServerLoopInstance().SetBeforeRetireHookForTesting(&HoldOneAppliedBatch);
return true;
#else
return false;
#endif
}
bool WaitForSplitApplyHoldForTesting(unsigned int timeoutMs) {
#if defined(MGITEST_SPLIT_RUNTIME_PEEK_LIVE)
const auto until = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeoutMs);
while (std::chrono::steady_clock::now() < until) {
if (g_holdActive.load(std::memory_order_acquire)) return true;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
#else
(void)timeoutMs;
#endif
return false;
}
bool SplitApplyHoldIsActiveForTesting() {
#if defined(MGITEST_SPLIT_RUNTIME_PEEK_LIVE)
return g_holdActive.load(std::memory_order_acquire);
#else
return false;
#endif
}
void ReleaseSplitApplyHoldForTesting() {
#if defined(MGITEST_SPLIT_RUNTIME_PEEK_LIVE)
g_holdRelease.store(true, std::memory_order_release);
g_holdArmed.store(false, std::memory_order_release);
MobileGL::MG_Remote::Server::ServerLoopInstance().SetBeforeRetireHookForTesting(nullptr);
while (g_holdActive.load(std::memory_order_acquire))
std::this_thread::sleep_for(std::chrono::milliseconds(1));
#endif
}
bool SplitProducerIsParkedForTesting() {
#if defined(MGITEST_SPLIT_RUNTIME_PEEK_LIVE)
// This is the only reader intended for the observer thread. Do not call
// PeekSplitRuntime there: its encoder and client-ledger fields are not atomic.
auto* session = MobileGL::MG_Remote::Client::ClientSession::Active();
return session && session->Control() && session->Control()->producerParked.load(std::memory_order_acquire);
#else
return false;
#endif
}
bool WaitForSplitAppliedForTesting(unsigned long long seq, unsigned int timeoutMs) {
#if defined(MGITEST_SPLIT_RUNTIME_PEEK_LIVE)
auto* session = MobileGL::MG_Remote::Client::ClientSession::Active();
auto* control = session ? session->Control() : nullptr;
if (!control) return false;
const auto until = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeoutMs);
do {
if (control->appliedSeq.load(std::memory_order_acquire) >= seq) return true;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
} while (std::chrono::steady_clock::now() < until);
return control->appliedSeq.load(std::memory_order_acquire) >= seq;
#else
(void)seq; (void)timeoutMs;
return false;
#endif
}
void DelaySplitRetirementForTesting(bool enabled) {
#if defined(MGITEST_SPLIT_RUNTIME_PEEK_LIVE)
MobileGL::MG_Remote::Server::ServerLoopInstance().SetBeforeRetireHookForTesting(
@@ -60,6 +139,15 @@ namespace MGITest {
// neither emits anything - this is a read.
const MobileGL::MG_Remote::Wire::PipeWireEncoder& encoder = session->Encoder();
state.emitSeq = encoder.EmitSeq();
state.runAheadArmed = session->RunAheadArmed();
state.presentCredit = MobileGL::MG_Config::Ipc.PresentCredit;
state.presentCreditWaits = session->PresentCreditWaits();
if (const auto* control = session->Control()) {
state.appliedSeq = control->appliedSeq.load(std::memory_order_acquire);
state.retiredSeq = control->retiredSeq.load(std::memory_order_acquire);
state.presentAckSerial = control->presentAckSerial.load(std::memory_order_acquire);
}
// The producer's ledger. Every one of these is a plain member read on the encoder
// or on the RingProducer it holds; none of them emits, publishes or waits, so a
// case may read them between two GL calls without changing what the next record is.
@@ -70,6 +70,15 @@ namespace MGITest {
unsigned int totalVerbSlots = 0;
// The encoder's highest produced record ordinal, or 0 when there is no session.
unsigned long long emitSeq = 0;
// Real session state/watermarks. Only the client thread reads this snapshot;
// the scheduling observer below reads producerParked separately.
bool runAheadArmed = false;
unsigned int presentCredit = 0;
unsigned long long appliedSeq = 0;
unsigned long long retiredSeq = 0;
unsigned long long presentAckSerial = 0;
unsigned long long presentCreditWaits = 0;
// ---- the wire producer's ledger, for exit gates E3(e) and R-10's proof obligation ---
//
@@ -104,6 +113,18 @@ namespace MGITest {
SplitRuntimeState PeekSplitRuntime();
// Scheduling-only perturbation; never changes a watermark or counter.
void DelaySplitRetirementForTesting(bool enabled);
// Holds the existing before-retire scheduling hook once, after a real drain
// batch. Never writes sequence numbers, caps, pixel state or production data.
// A two-second fail-safe releases a lockstep negative control without hanging.
bool ArmSplitApplyHoldForTesting();
bool WaitForSplitApplyHoldForTesting(unsigned int timeoutMs = 1000);
bool SplitApplyHoldIsActiveForTesting();
void ReleaseSplitApplyHoldForTesting();
bool SplitProducerIsParkedForTesting();
// Observe completion for assertions about an emitted frame; does not emit a
// GL command or change the production wait rule.
bool WaitForSplitAppliedForTesting(unsigned long long seq, unsigned int timeoutMs = 5000);
// Empty when this process is a real split run that can be asserted about; otherwise the
// reason to GTEST_SKIP() with, naming the first fact that is not true and the package that
@@ -161,6 +161,9 @@ void main() { color = vec4(value, 0.25, 0.75, 1.0); }
EXPECT_NEAR(pixel[2], 191, 1);
EXPECT_EQ(pixel[3], 255);
Gl().EndFrame();
// Present returns before apply under run-ahead. Inspect this completed
// frame's window, not the previous (possibly empty setup) log line.
ASSERT_TRUE(WaitForSplitAppliedForTesting(PeekSplitRuntime().emitSeq));
const auto window = PipeStatsWindow::LastFromLaneLog();
ASSERT_TRUE(window.found) << "P5f rsp window missing on frame " << frame;
// Magma does not publish Espryt's draw counter. The changing uniform and
@@ -0,0 +1,334 @@
// Real Magma run-ahead: observe client lead over an actually held apply thread,
// then verify GPU pixels/bytes. The scheduling hook never changes a watermark.
#include "../Harness/ScenarioFixture.h"
#include "../Harness/SplitRuntimePeek.h"
#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <cstring>
#include <initializer_list>
#include <thread>
#include <utility>
#include <vector>
#ifdef GLAPI
#undef GLAPI
#endif
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glcorearb.h>
#undef GL_GLEXT_PROTOTYPES
namespace MGITest {
namespace {
constexpr int kWidth = 32, kHeight = 8;
constexpr const char* kVertexId = R"(#version 430 core
void main() {
vec2 p[3] = vec2[3](vec2(-1,-1),vec2(3,-1),vec2(-1,3));
gl_Position=vec4(p[gl_VertexID],0,1);
})";
using Pixel = std::array<GLubyte, 4>;
constexpr Pixel red{255,0,0,255}, green{0,255,0,255}, blue{0,0,255,255}, yellow{255,255,0,255}, black{0,0,0,255};
struct HeldApply {
~HeldApply() { ReleaseSplitApplyHoldForTesting(); }
void Release() { ReleaseSplitApplyHoldForTesting(); }
};
class MagmaRunAheadScenario : public ScenarioTest {
protected:
GLuint target = 0;
std::vector<GLuint> buffers, programs, textures, fbos, vaos;
SplitRuntimeState held{};
void SetUp() override {
ScenarioTest::SetUp();
if (!Ready()) return;
if (!SplitLane::MarkerIsOne("MGITEST_MAGMA_RUNAHEAD_LANE"))
GTEST_SKIP() << "dedicated Magma run-ahead lane only";
ASSERT_EQ(Gl().BackendName(), "DirectVulkan");
const auto runtime = PeekSplitRuntime();
ASSERT_TRUE(runtime.peekAvailable && runtime.sessionActive && runtime.transportResolved);
RecordProperty("run_ahead_armed", runtime.runAheadArmed ? "1" : "0");
ASSERT_TRUE(runtime.presentCredit == 1 || runtime.presentCredit == 3);
target = NewFbo(NewTexture(kWidth, kHeight, nullptr));
glBindFramebuffer(GL_FRAMEBUFFER, target);
glViewport(0, 0, kWidth, kHeight);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
GLuint vao = 0;
glGenVertexArrays(1, &vao);
vaos.push_back(vao);
glBindVertexArray(vao);
}
void TearDown() override {
ReleaseSplitApplyHoldForTesting();
if (!Ready()) return;
glUseProgram(0);
glBindVertexArray(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (!buffers.empty()) glDeleteBuffers(GLsizei(buffers.size()), buffers.data());
if (!vaos.empty()) glDeleteVertexArrays(GLsizei(vaos.size()), vaos.data());
if (!fbos.empty()) glDeleteFramebuffers(GLsizei(fbos.size()), fbos.data());
if (!textures.empty()) glDeleteTextures(GLsizei(textures.size()), textures.data());
for (GLuint program : programs) glDeleteProgram(program);
}
GLuint NewBuffer(GLenum target, GLsizeiptr size, const void* bytes) {
GLuint buffer = 0;
glGenBuffers(1, &buffer);
buffers.push_back(buffer);
glBindBuffer(target, buffer);
glBufferData(target, size, bytes, GL_DYNAMIC_DRAW);
return buffer;
}
GLuint NewTexture(int width, int height, const void* pixels) {
GLuint texture = 0;
glGenTextures(1, &texture);
textures.push_back(texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,pixels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
return texture;
}
GLuint NewFbo(GLuint texture) {
GLuint fbo = 0;
glGenFramebuffers(1,&fbo);
fbos.push_back(fbo);
glBindFramebuffer(GL_FRAMEBUFFER,fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texture,0);
EXPECT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GLenum(GL_FRAMEBUFFER_COMPLETE));
return fbo;
}
GLuint Link(std::initializer_list<std::pair<GLenum,const char*>> stages) {
const GLuint program = glCreateProgram();
programs.push_back(program);
for (const auto& [kind, source] : stages) {
const GLuint shader = glCreateShader(kind);
glShaderSource(shader,1,&source,nullptr);
glCompileShader(shader);
GLint ok = GL_FALSE;
glGetShaderiv(shader,GL_COMPILE_STATUS,&ok);
EXPECT_EQ(ok,GL_TRUE) << "run-ahead shader compile";
glAttachShader(program,shader);
glDeleteShader(shader);
}
glLinkProgram(program);
GLint ok = GL_FALSE;
glGetProgramiv(program,GL_LINK_STATUS,&ok);
EXPECT_EQ(ok,GL_TRUE) << "run-ahead program link";
return program;
}
void HoldNextBatch() {
// Fully drain SETUP, then hold after one real clear batch. No wait/readback
// is inserted among the operations whose queued ordering is under test.
glClear(GL_COLOR_BUFFER_BIT);
glFinish();
ASSERT_TRUE(ArmSplitApplyHoldForTesting());
glClear(GL_COLOR_BUFFER_BIT);
ASSERT_TRUE(WaitForSplitApplyHoldForTesting())
<< "the clear waited for apply instead of returning while its server batch was held";
held = PeekSplitRuntime();
}
void ExpectQueued(unsigned int minimumRecords) {
const auto now = PeekSplitRuntime();
EXPECT_TRUE(now.runAheadArmed) << "Magma production session did not arm run-ahead";
EXPECT_TRUE(SplitApplyHoldIsActiveForTesting()) << "client waited for apply instead of running ahead";
EXPECT_EQ(now.appliedSeq, held.appliedSeq) << "held server advanced unexpectedly";
EXPECT_GE(now.emitSeq, held.emitSeq + minimumRecords);
EXPECT_GT(now.emitSeq, now.appliedSeq) << "no real client lead over the apply watermark";
RecordProperty("observed_queued_records", std::to_string(now.emitSeq - now.appliedSeq));
}
void DrawTile(int tile) {
glViewport(tile * 8,0,8,kHeight);
glDrawArrays(GL_TRIANGLES,0,3);
}
void ExpectPixel(int x, int y, Pixel expected, const char* why) {
Pixel actual{};
glReadPixels(x,y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,actual.data());
EXPECT_EQ(actual,expected) << why;
EXPECT_EQ(FirstGLError(), GLenum(GL_NO_ERROR)) << why;
}
};
TEST_F(MagmaRunAheadScenario, QueuedBufferVersionsAndDeletedNameReuseKeepTheirPixels) {
if (!Ready() || IsSkipped()) return;
const char* vs = R"(#version 430 core
layout(location=0) in vec4 color; out vec4 v;
void main(){vec2 p[3]=vec2[3](vec2(-1,-1),vec2(3,-1),vec2(-1,3));gl_Position=vec4(p[gl_VertexID],0,1);v=color;})";
const char* fs = "#version 430 core\nin vec4 v;layout(location=0) out vec4 c;void main(){c=v;}";
glUseProgram(Link({{GL_VERTEX_SHADER,vs},{GL_FRAGMENT_SHADER,fs}}));
const auto colors = [](float r,float g,float b) { return std::array<GLfloat,12>{r,g,b,1,r,g,b,1,r,g,b,1}; };
const auto r=colors(1,0,0), g=colors(0,1,0), b=colors(0,0,1), y=colors(1,1,0);
const GLuint buffer=NewBuffer(GL_ARRAY_BUFFER,sizeof(r),r.data());
glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,16,nullptr); glEnableVertexAttribArray(0);
HeldApply hold; ASSERT_NO_FATAL_FAILURE(HoldNextBatch());
DrawTile(0);
glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(g),g.data()); DrawTile(1);
ExpectQueued(2); hold.Release();
// Resource creation requires a reply, and storage definitions may require an
// allocation acknowledgement. Do not hold the apply owner across those legal
// waits. There is still no GPU readback/Finish before all four draws, so the
// old GPU store must survive respecify and deletion until its draws complete.
glBufferData(GL_ARRAY_BUFFER,sizeof(b),b.data(),GL_STREAM_DRAW); DrawTile(2);
glDeleteBuffers(1,&buffer);
// Request the recycled name through the public allocator. Record reuse must
// have a distinct lifetime even though the application-visible name is equal.
GLuint replacement=0;
glGenBuffers(1,&replacement);
EXPECT_EQ(replacement,buffer) << "the intended GL-name reuse did not occur";
if (replacement!=buffer) buffers.push_back(replacement);
glBindBuffer(GL_ARRAY_BUFFER,replacement);
glBufferData(GL_ARRAY_BUFFER,sizeof(y),y.data(),GL_DYNAMIC_DRAW);
glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,16,nullptr); DrawTile(3);
ExpectPixel(4,4,red,"original buffer version"); ExpectPixel(12,4,green,"SubData version");
ExpectPixel(20,4,blue,"respecified store"); ExpectPixel(28,4,yellow,"recreated GL name");
}
TEST_F(MagmaRunAheadScenario, QueuedProgramRebindsKeepEachUniformSnapshot) {
if (!Ready() || IsSkipped()) return;
const char* a="#version 430 core\nuniform vec4 tint;layout(location=0) out vec4 c;void main(){c=tint;}";
const char* b="#version 430 core\nuniform vec4 tint;layout(location=0) out vec4 c;void main(){c=tint.bgra;}";
const GLuint pa=Link({{GL_VERTEX_SHADER,kVertexId},{GL_FRAGMENT_SHADER,a}}), pb=Link({{GL_VERTEX_SHADER,kVertexId},{GL_FRAGMENT_SHADER,b}});
const GLint la=glGetUniformLocation(pa,"tint"), lb=glGetUniformLocation(pb,"tint");
ASSERT_GE(la,0); ASSERT_GE(lb,0);
HeldApply hold; ASSERT_NO_FATAL_FAILURE(HoldNextBatch());
glUseProgram(pa); glUniform4f(la,1,0,0,1); DrawTile(0);
glUseProgram(pb); glUniform4f(lb,0,1,0,1); DrawTile(1);
glUseProgram(pa); glUniform4f(la,0,0,1,1); DrawTile(2);
glUseProgram(pb); glUniform4f(lb,0,1,1,1); DrawTile(3);
ExpectQueued(4); hold.Release();
ExpectPixel(4,4,red,"program A first uniform"); ExpectPixel(12,4,green,"program B first uniform");
ExpectPixel(20,4,blue,"program A rebound"); ExpectPixel(28,4,yellow,"program B swizzled second uniform");
}
TEST_F(MagmaRunAheadScenario, QueuedGpuWritesReadBackTheLastDispatchBytes) {
if (!Ready() || IsSkipped()) return;
const char* cs=R"(#version 430 core
layout(local_size_x=1) in;layout(std430,binding=0) buffer Out{uint value[];};uniform uint seed;
void main(){uint i=gl_GlobalInvocationID.x;value[i]=seed+i;})";
const GLuint program=Link({{GL_COMPUTE_SHADER,cs}});
const GLint seed=glGetUniformLocation(program,"seed"); ASSERT_GE(seed,0);
std::array<GLuint,32> data{};
const GLuint buffer=NewBuffer(GL_SHADER_STORAGE_BUFFER,sizeof(data),data.data());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER,0,buffer); glUseProgram(program);
HeldApply hold; ASSERT_NO_FATAL_FAILURE(HoldNextBatch());
glUniform1ui(seed,0x11110000u); glDispatchCompute(32,1,1);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glUniform1ui(seed,0x22220000u); glDispatchCompute(32,1,1);
ExpectQueued(2); hold.Release();
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER,0,sizeof(data),data.data());
for (GLuint i=0;i<data.size();++i) EXPECT_EQ(data[i],0x22220000u+i) << i;
EXPECT_EQ(FirstGLError(), GLenum(GL_NO_ERROR)); glBindBufferBase(GL_SHADER_STORAGE_BUFFER,0,0);
}
TEST_F(MagmaRunAheadScenario, MixedNativeAndConvertedGpuVertexStreamsKeepTheirReservation) {
if (!Ready() || IsSkipped()) return;
const char* cs=R"(#version 430 core
layout(local_size_x=1) in;layout(std430,binding=0) buffer Out{uint words[];};
void main(){vec2 p[3]=vec2[3](vec2(-1,-1),vec2(0,-1),vec2(-1,1));
for(uint i=0u;i<3u;++i){words[4u*i]=floatBitsToUint(p[i].x);words[4u*i+1u]=floatBitsToUint(p[i].y);
words[4u*i+2u]=0u;words[4u*i+3u]=0x3ff00000u;}})";
const char* vs=R"(#version 430 core
layout(location=0) in vec2 position;layout(location=1) in float code;out vec4 v;
void main(){gl_Position=vec4(position,0,1);v=vec4(1.0-float(code),float(code),0,1);})";
const char* fs="#version 430 core\nin vec4 v;layout(location=0) out vec4 c;void main(){c=v;}";
const GLuint compute=Link({{GL_COMPUTE_SHADER,cs}}), graphics=Link({{GL_VERTEX_SHADER,vs},{GL_FRAGMENT_SHADER,fs}});
struct Vertex { GLfloat x,y; GLdouble code; };
static_assert(sizeof(Vertex)==16);
std::array<Vertex,3> vertices{};
const GLuint buffer=NewBuffer(GL_ARRAY_BUFFER,sizeof(vertices),vertices.data());
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,16,nullptr); glEnableVertexAttribArray(0);
glVertexAttribPointer(1,1,GL_DOUBLE,GL_FALSE,16,reinterpret_cast<const void*>(8)); glEnableVertexAttribArray(1);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER,0,buffer);
HeldApply hold; ASSERT_NO_FATAL_FAILURE(HoldNextBatch());
glUseProgram(compute); glDispatchCompute(1,1,1);
glMemoryBarrier(GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT | GL_BUFFER_UPDATE_BARRIER_BIT);
glUseProgram(graphics); glDrawArrays(GL_TRIANGLES,0,3);
vertices={Vertex{0,-1,0},Vertex{1,-1,0},Vertex{1,1,0}};
glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(vertices),vertices.data());
glDrawArrays(GL_TRIANGLES,0,3);
ExpectQueued(3); hold.Release();
ExpectPixel(2,1,green,"native position reservation survives the other attribute's Double conversion read");
ExpectPixel(29,1,red,"later SubData reaches only the later draw");
glBindBufferBase(GL_SHADER_STORAGE_BUFFER,0,0);
}
TEST_F(MagmaRunAheadScenario, TextureUploadCannotOvertakeThePreviouslyQueuedDraw) {
if (!Ready() || IsSkipped()) return;
const char* fs="#version 430 core\nuniform sampler2D src;layout(location=0) out vec4 c;void main(){c=texture(src,vec2(0.5));}";
glUseProgram(Link({{GL_VERTEX_SHADER,kVertexId},{GL_FRAGMENT_SHADER,fs}}));
const std::array<GLubyte,16> oldPixels{255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255};
const std::array<GLubyte,16> newPixels{0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255};
const GLuint source=NewTexture(2,2,oldPixels.data());
HeldApply hold; ASSERT_NO_FATAL_FAILURE(HoldNextBatch());
DrawTile(0); ExpectQueued(1); hold.Release();
// Texture uploads have a wire reply. That is not a GPU completion barrier for
// the prior draw; no ReadPixels/Finish is permitted before the second draw.
glBindTexture(GL_TEXTURE_2D,source);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,2,2,GL_RGBA,GL_UNSIGNED_BYTE,newPixels.data());
DrawTile(1);
ExpectPixel(4,4,red,"draw issued before texture update");
ExpectPixel(12,4,green,"draw issued after texture update");
}
TEST_F(MagmaRunAheadScenario, GpuClearSurvivesTheFirstStorageImageUpgrade) {
if (!Ready() || IsSkipped()) return;
std::array<GLubyte,4*4*4> bytes{};
for (size_t i=0;i<bytes.size();i+=4) { bytes[i]=255; bytes[i+3]=255; }
const GLuint source=NewTexture(4,4,bytes.data()), sourceFbo=NewFbo(source);
const char* cs=R"(#version 430 core
layout(local_size_x=1) in;layout(rgba8,binding=0) uniform writeonly image2D img;
void main(){imageStore(img,ivec2(0),vec4(0,0,1,1));})";
const GLuint compute=Link({{GL_COMPUTE_SHADER,cs}});
HeldApply hold; ASSERT_NO_FATAL_FAILURE(HoldNextBatch());
glClearColor(0,1,0,1); glClear(GL_COLOR_BUFFER_BIT); ExpectQueued(1); hold.Release();
glBindFramebuffer(GL_FRAMEBUFFER,target);
glBindImageTexture(0,source,0,GL_FALSE,0,GL_WRITE_ONLY,GL_RGBA8);
glUseProgram(compute); glDispatchCompute(1,1,1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL_FRAMEBUFFER_BARRIER_BIT);
glBindFramebuffer(GL_READ_FRAMEBUFFER,sourceFbo);
ExpectPixel(0,0,blue,"compute writes the new STORAGE image");
ExpectPixel(2,2,green,"usage upgrade preserves the earlier GPU clear, not the old red CPU upload");
glBindImageTexture(0,0,0,GL_FALSE,0,GL_WRITE_ONLY,GL_RGBA8);
}
TEST_F(MagmaRunAheadScenario, PresentCreditActuallyParksTheClientAtItsConfiguredLimit) {
if (!Ready() || IsSkipped()) return;
glBindFramebuffer(GL_FRAMEBUFFER,0);
HeldApply hold; ASSERT_NO_FATAL_FAILURE(HoldNextBatch());
const auto before=PeekSplitRuntime();
ASSERT_EQ(before.presentAckSerial,0u) << "this isolated case has not presented yet";
for (unsigned i=0;i<before.presentCredit;++i) { glClear(GL_COLOR_BUFFER_BIT); Gl().EndFrame(); }
ExpectQueued(before.presentCredit);
const auto full=PeekSplitRuntime();
EXPECT_EQ(full.presentAckSerial,before.presentAckSerial);
EXPECT_EQ(full.presentCreditWaits,before.presentCreditWaits);
std::atomic<bool> sawPark{false}, stop{false};
std::thread observer([&] {
const auto until=std::chrono::steady_clock::now()+std::chrono::seconds(1);
while (!stop.load() && std::chrono::steady_clock::now()<until) {
if (SplitProducerIsParkedForTesting()) { sawPark.store(true); break; }
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
ReleaseSplitApplyHoldForTesting();
});
Gl().EndFrame(); // credit + 1 must park before it can publish its present.
stop.store(true); observer.join(); hold.Release();
EXPECT_TRUE(sawPark.load()) << "no real producer park while the present window was full";
glFinish();
const auto after=PeekSplitRuntime();
EXPECT_EQ(after.presentCreditWaits,before.presentCreditWaits+1);
EXPECT_EQ(after.presentAckSerial,before.presentCredit+1);
EXPECT_EQ(after.appliedSeq,after.emitSeq);
RecordProperty("observed_present_credit",std::to_string(before.presentCredit));
RecordProperty("observed_producer_park",sawPark.load() ? "yes" : "no");
}
} // namespace
} // namespace MGITest
@@ -0,0 +1,352 @@
// Wire view/framebuffer caches must preserve public GL state transitions. All
// draws in each case precede its first readback: no Finish/Present can retire an
// old view between A -> B -> A or hide an allocation change from an in-flight draw.
#include "../Harness/ScenarioFixture.h"
#include "../Harness/SplitRuntimePeek.h"
#include <array>
#include <vector>
#ifdef GLAPI
#undef GLAPI
#endif
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glcorearb.h>
#undef GL_GLEXT_PROTOTYPES
namespace MGITest {
namespace {
using Pixel = std::array<GLubyte, 4>;
constexpr Pixel red{255, 0, 0, 255}, green{0, 255, 0, 255}, blue{0, 0, 255, 255};
constexpr Pixel yellow{255, 255, 0, 255}, black{0, 0, 0, 255};
constexpr int kWidth = 32, kHeight = 8;
constexpr const char* kVertex = R"(#version 430 core
void main() {
vec2 p[3] = vec2[3](vec2(-1,-1), vec2(3,-1), vec2(-1,3));
gl_Position = vec4(p[gl_VertexID], 0, 1);
})";
constexpr const char* kSample2D = R"(#version 430 core
uniform sampler2D src;
layout(location=0) out vec4 color;
void main() { color = texelFetch(src, ivec2(0), 0); })";
constexpr const char* kSampleArray = R"(#version 430 core
uniform sampler2DArray src;
layout(location=0) out vec4 color;
void main() { color = texelFetch(src, ivec3(0,0,1), 0); })";
constexpr const char* kTint = R"(#version 430 core
uniform vec4 tint;
layout(location=0) out vec4 color;
void main() { color = tint; })";
class MagmaWireCacheScenario : public ScenarioTest {
protected:
GLuint target = 0;
std::vector<GLuint> textures, fbos, programs, vaos;
void SetUp() override {
ScenarioTest::SetUp();
if (!Ready()) return;
if (!SplitLane::MarkerIsOne("MGITEST_MAGMA_CACHES_LANE"))
GTEST_SKIP() << "dedicated Magma cache lane only";
ASSERT_EQ(Gl().BackendName(), "DirectVulkan");
const auto runtime = PeekSplitRuntime();
ASSERT_TRUE(runtime.peekAvailable && runtime.sessionActive && runtime.transportResolved);
ASSERT_EQ(runtime.transportName, "inproc");
ASSERT_TRUE(SplitLane::MarkerIsOne("MOBILEGL_IPC_ROLE_SPLIT_STATE"));
ASSERT_TRUE(SplitLane::MarkerIsOne("MOBILEGL_IPC_STRICT_ERRORS"));
glActiveTexture(GL_TEXTURE0);
glBindSampler(0, 0);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
glDisable(GL_RASTERIZER_DISCARD);
glDisable(GL_FRAMEBUFFER_SRGB);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
GLuint vao = 0;
glGenVertexArrays(1, &vao);
vaos.push_back(vao);
glBindVertexArray(vao);
target = NewFramebuffer(NewTexture(kWidth, kHeight, black));
}
void TearDown() override {
if (!Ready()) return;
glDisable(GL_FRAMEBUFFER_SRGB);
glUseProgram(0);
glBindVertexArray(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (!vaos.empty()) glDeleteVertexArrays(GLsizei(vaos.size()), vaos.data());
if (!fbos.empty()) glDeleteFramebuffers(GLsizei(fbos.size()), fbos.data());
if (!textures.empty()) glDeleteTextures(GLsizei(textures.size()), textures.data());
for (GLuint program : programs) glDeleteProgram(program);
}
static std::vector<Pixel> Pixels(int width, int height, Pixel color) {
return std::vector<Pixel>(size_t(width) * size_t(height), color);
}
GLuint TextureName() {
GLuint texture = 0;
glGenTextures(1, &texture);
textures.push_back(texture);
return texture;
}
void DefineTexture(GLuint texture, int width, int height, Pixel color, GLenum format = GL_RGBA8) {
const auto pixels = Pixels(width, height, color);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
}
static void Nearest(GLenum target) {
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
GLuint NewTexture(int width, int height, Pixel color, GLenum format = GL_RGBA8) {
const GLuint texture = TextureName();
DefineTexture(texture, width, height, color, format);
Nearest(GL_TEXTURE_2D);
return texture;
}
GLuint NewArray() {
const GLuint texture = TextureName();
glBindTexture(GL_TEXTURE_2D_ARRAY, texture);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 8, 8, 2);
Nearest(GL_TEXTURE_2D_ARRAY);
for (int level = 0; level < 2; ++level) {
const int size = 8 >> level;
const auto pixels = Pixels(size, size, black);
for (int layer = 0; layer < 2; ++layer)
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, layer, size, size, 1,
GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
}
return texture;
}
GLuint NewFramebuffer(GLuint texture = 0) {
GLuint fbo = 0;
glGenFramebuffers(1, &fbo);
fbos.push_back(fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
if (texture) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
EXPECT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GLenum(GL_FRAMEBUFFER_COMPLETE));
}
return fbo;
}
GLuint Link(const char* fragment) {
const GLuint program = glCreateProgram();
programs.push_back(program);
const std::array<GLenum, 2> kinds{GL_VERTEX_SHADER, GL_FRAGMENT_SHADER};
const std::array<const char*, 2> sources{kVertex, fragment};
for (size_t i = 0; i < kinds.size(); ++i) {
const GLuint shader = glCreateShader(kinds[i]);
glShaderSource(shader, 1, &sources[i], nullptr);
glCompileShader(shader);
GLint ok = GL_FALSE;
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
std::array<GLchar, 2048> log{};
if (!ok) glGetShaderInfoLog(shader, GLsizei(log.size()), nullptr, log.data());
EXPECT_EQ(ok, GL_TRUE) << log.data();
glAttachShader(program, shader);
glDeleteShader(shader);
}
glLinkProgram(program);
GLint ok = GL_FALSE;
glGetProgramiv(program, GL_LINK_STATUS, &ok);
std::array<GLchar, 2048> log{};
if (!ok) glGetProgramInfoLog(program, GLsizei(log.size()), nullptr, log.data());
EXPECT_EQ(ok, GL_TRUE) << log.data();
return ok ? program : 0;
}
static void DrawTile(int tile) {
glViewport(tile * 8, 0, 8, kHeight);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
static void Tint(GLint location, Pixel color) {
glUniform4f(location, color[0] / 255.0f, color[1] / 255.0f,
color[2] / 255.0f, color[3] / 255.0f);
}
void ExpectPixel(int x, int y, Pixel expected, const char* why, int tolerance = 0) {
Pixel actual{};
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, actual.data());
for (size_t channel = 0; channel < actual.size(); ++channel)
EXPECT_NEAR(int(actual[channel]), int(expected[channel]), tolerance) << why << " channel=" << channel;
EXPECT_EQ(FirstGLError(), GLenum(GL_NO_ERROR)) << why;
}
};
TEST_F(MagmaWireCacheScenario, SamplerSwizzleAtoBtoAKeepsEachQueuedPixel) {
if (!Ready() || IsSkipped()) return;
const GLuint program = Link(kSample2D);
ASSERT_NE(program, 0u);
NewTexture(2, 2, red);
glUseProgram(program);
glBindFramebuffer(GL_FRAMEBUFFER, target);
const GLint identity[]{GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA};
const GLint swapped[]{GL_GREEN, GL_RED, GL_BLUE, GL_ALPHA};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, identity);
DrawTile(0);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swapped);
DrawTile(1);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, identity);
DrawTile(2);
DrawTile(3); // The unchanged view is eligible for actual cache reuse too.
ExpectPixel(4, 4, red, "swizzle A before B");
ExpectPixel(12, 4, green, "swizzle B has its own descriptor");
ExpectPixel(20, 4, red, "swizzle A restored");
ExpectPixel(28, 4, red, "unchanged A reused");
}
TEST_F(MagmaWireCacheScenario, SamplerRespecifyKeepsOldAndNewNativeImages) {
if (!Ready() || IsSkipped()) return;
const GLuint program = Link(kSample2D);
ASSERT_NE(program, 0u);
const GLuint source = NewTexture(2, 2, red);
glUseProgram(program);
glBindFramebuffer(GL_FRAMEBUFFER, target);
DrawTile(0);
// TexImage may require a wire reply; it must still preserve the old GPU
// image referenced by the first draw. There is no intervening GPU readback.
DefineTexture(source, 4, 4, green);
DrawTile(1);
DefineTexture(source, 2, 2, blue);
DrawTile(2);
ExpectPixel(4, 4, red, "old allocation before first respecify");
ExpectPixel(12, 4, green, "larger replacement allocation");
ExpectPixel(20, 4, blue, "original dimensions with a new allocation");
}
TEST_F(MagmaWireCacheScenario, SamplerViewsDistinguishMipLayerAndViewType) {
if (!Ready() || IsSkipped()) return;
const GLuint sample2D = Link(kSample2D), sampleArray = Link(kSampleArray);
ASSERT_NE(sample2D, 0u);
ASSERT_NE(sampleArray, 0u);
const GLuint root = NewArray();
const auto upload = [&](int level, int layer, Pixel color) {
const int size = 8 >> level;
const auto pixels = Pixels(size, size, color);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, layer, size, size, 1,
GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
};
upload(0, 0, red);
upload(0, 1, green);
upload(1, 1, yellow);
const GLuint viewA = TextureName(), viewB = TextureName();
glTextureView(viewA, GL_TEXTURE_2D, root, GL_RGBA8, 0, 1, 0, 1);
glTextureView(viewB, GL_TEXTURE_2D, root, GL_RGBA8, 1, 1, 1, 1);
for (GLuint view : {viewA, viewB}) {
glBindTexture(GL_TEXTURE_2D, view);
Nearest(GL_TEXTURE_2D);
}
glBindFramebuffer(GL_FRAMEBUFFER, target);
glUseProgram(sample2D);
glBindTexture(GL_TEXTURE_2D, viewA);
DrawTile(0);
glBindTexture(GL_TEXTURE_2D, viewB);
DrawTile(1);
glBindTexture(GL_TEXTURE_2D, viewA);
DrawTile(2);
glUseProgram(sampleArray);
glBindTexture(GL_TEXTURE_2D_ARRAY, root);
DrawTile(3);
ExpectPixel(4, 4, red, "2D view of root mip 0 layer 0");
ExpectPixel(12, 4, yellow, "2D view of root mip 1 layer 1");
ExpectPixel(20, 4, red, "first subresource view restored");
ExpectPixel(28, 4, green, "array view type retains layer selection");
}
TEST_F(MagmaWireCacheScenario, FramebuffersAtoBtoAKeepDistinctAttachments) {
if (!Ready() || IsSkipped()) return;
const GLuint program = Link(kTint);
ASSERT_NE(program, 0u);
const GLint tint = glGetUniformLocation(program, "tint");
ASSERT_GE(tint, 0);
const GLuint a = NewFramebuffer(NewTexture(kWidth, kHeight, black));
const GLuint b = NewFramebuffer(NewTexture(kWidth, kHeight, black));
glUseProgram(program);
glBindFramebuffer(GL_FRAMEBUFFER, a); Tint(tint, red); DrawTile(0);
glBindFramebuffer(GL_FRAMEBUFFER, b); Tint(tint, green); DrawTile(1);
glBindFramebuffer(GL_FRAMEBUFFER, a); Tint(tint, blue); DrawTile(2);
ExpectPixel(4, 4, red, "A retains its first draw");
ExpectPixel(12, 4, black, "B draw did not use A's compatible framebuffer");
ExpectPixel(20, 4, blue, "A selected again after B");
glBindFramebuffer(GL_FRAMEBUFFER, b);
ExpectPixel(4, 4, black, "first A draw did not reach B");
ExpectPixel(12, 4, green, "B owns its draw");
ExpectPixel(20, 4, black, "last A draw did not reach B");
}
TEST_F(MagmaWireCacheScenario, FramebufferReattachmentDistinguishesMipAndLayer) {
if (!Ready() || IsSkipped()) return;
const GLuint program = Link(kTint);
ASSERT_NE(program, 0u);
const GLint tint = glGetUniformLocation(program, "tint");
ASSERT_GE(tint, 0);
const GLuint root = NewArray();
NewFramebuffer();
const auto attach = [&](int level, int layer) {
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, root, level, layer);
};
glUseProgram(program);
attach(0, 0); glViewport(0, 0, 8, 8); Tint(tint, red); glDrawArrays(GL_TRIANGLES, 0, 3);
attach(1, 1); glViewport(0, 0, 4, 4); Tint(tint, green); glDrawArrays(GL_TRIANGLES, 0, 3);
attach(0, 1); glViewport(0, 0, 8, 8); Tint(tint, blue); glDrawArrays(GL_TRIANGLES, 0, 3);
attach(0, 0); glViewport(0, 0, 4, 8); Tint(tint, yellow); glDrawArrays(GL_TRIANGLES, 0, 3);
ExpectPixel(2, 4, yellow, "restored mip 0 layer 0 left half");
ExpectPixel(6, 4, red, "restored mip 0 layer 0 preserves first draw");
attach(1, 1); ExpectPixel(2, 2, green, "smaller mip 1 layer 1 attachment");
attach(0, 1); ExpectPixel(6, 4, blue, "same mip with a different layer");
attach(1, 0); ExpectPixel(2, 2, black, "untouched mip 1 layer 0");
}
TEST_F(MagmaWireCacheScenario, FramebufferSrgbPolicyAtoBtoAUsesDistinctFormats) {
if (!Ready() || IsSkipped()) return;
const GLuint program = Link(kTint);
ASSERT_NE(program, 0u);
const GLint tint = glGetUniformLocation(program, "tint");
ASSERT_GE(tint, 0);
NewFramebuffer(NewTexture(kWidth, kHeight, black, GL_SRGB8_ALPHA8));
glUseProgram(program);
glUniform4f(tint, 0.5f, 0.5f, 0.5f, 1.0f);
DrawTile(0);
glEnable(GL_FRAMEBUFFER_SRGB); DrawTile(1);
glDisable(GL_FRAMEBUFFER_SRGB); DrawTile(2);
ExpectPixel(4, 4, Pixel{128, 128, 128, 255}, "linear writes before conversion", 1);
ExpectPixel(12, 4, Pixel{188, 188, 188, 255}, "sRGB attachment write conversion", 1);
ExpectPixel(20, 4, Pixel{128, 128, 128, 255}, "linear attachment format restored", 1);
}
TEST_F(MagmaWireCacheScenario, FramebufferRespecifyRebindsTheNewNativeImage) {
if (!Ready() || IsSkipped()) return;
const GLuint paint = Link(kTint), sample = Link(kSample2D);
ASSERT_NE(paint, 0u);
ASSERT_NE(sample, 0u);
const GLint tint = glGetUniformLocation(paint, "tint");
ASSERT_GE(tint, 0);
const GLuint source = NewTexture(8, 8, black), sourceFbo = NewFramebuffer(source);
const auto drawThenSample = [&](Pixel color, int width, int tile) {
glBindFramebuffer(GL_FRAMEBUFFER, sourceFbo);
glUseProgram(paint); Tint(tint, color);
glViewport(0, 0, width, 8); glDrawArrays(GL_TRIANGLES, 0, 3);
glBindFramebuffer(GL_FRAMEBUFFER, target);
glUseProgram(sample); glBindTexture(GL_TEXTURE_2D, source); DrawTile(tile);
};
drawThenSample(red, 8, 0);
DefineTexture(source, 16, 8, black);
drawThenSample(green, 16, 1);
DefineTexture(source, 8, 8, black);
drawThenSample(blue, 8, 2);
ExpectPixel(4, 4, red, "pixels produced by the original attachment allocation");
ExpectPixel(12, 4, green, "same FBO writes the larger replacement allocation");
ExpectPixel(20, 4, blue, "same dimensions cannot revive the retired attachment");
}
} // namespace
} // namespace MGITest
+5 -10
View File
@@ -152,17 +152,12 @@ namespace MobileGL::MG_Pipe {
kCapRunAheadApply = 1ull << 10,
};
// THE RUN-AHEAD ARM, AS A PURE FUNCTION, so that "Magma never" is something a unit case can
// hold rather than a line inside MG_Backend/Init.cpp's InitSplitRoles that only a live
// split session reaches. `ready` is Init.cpp's kMGPipeP5eRunAheadReady - false until the
// P5e integration commit - and the BACKEND TYPE is the half that must not depend on it:
// whatever `ready` says, a DirectVulkan server publishes no bit 10, because Magma keeps the
// lockstep for the whole of P5e (CONTRACT-P5E.md §6) and its apply thread really does read
// client memory inside MagmaP7AllocatorDebtScope. MG_Test/Pipe/MagmaPipeIdentityTest.cpp
// pins both halves; reverting the type test there is the phase's named red.
// Readiness is supplied independently by each backend's integration gate.
// The capability names client-memory independence, not merely a config knob.
// See CONTRACT-MAGMA-RUNAHEAD.md for the Vulkan resource/submission contract.
inline constexpr Uint64 MGPipeRunAheadCapBitsFor(BackendType type, Bool ready) {
return (ready && type == BackendType::DirectGLES) ? static_cast<Uint64>(kCapRunAheadApply)
: static_cast<Uint64>(kCapNone);
return (ready && (type == BackendType::DirectGLES || type == BackendType::DirectVulkan))
? static_cast<Uint64>(kCapRunAheadApply) : static_cast<Uint64>(kCapNone);
}
struct MGPCaps {
@@ -0,0 +1,63 @@
# CONTRACT — Magma run-ahead
This extends CONTRACT-P5E to DirectVulkan after P5f and the Magma application-buffer
migration. The P5e rule F, wait-class table, reply ownership, event flow control,
present credit and one-way run-ahead latch remain the protocol. This document
supersedes the historical requirement that Magma never publish `kCapRunAheadApply`.
It does not make Magma a multi-process transport or complete every P7/P8 GL shape.
## Readiness and waits
Magma has an independent implementation-readiness constant in `MG_Backend/Init.cpp`.
Only the integration commit may enable it after the queued-state tests pass. A
ready server advertises the existing bit 10; `MOBILEGL_IPC_RUN_AHEAD=0` remains the
paired lockstep control. Unsupported backends/readiness=false advertise no bit.
The knob alone never arms run-ahead. A later caps snapshot may disarm, not arm it.
Unbarriered apply reads only records, server storage and immutable capabilities.
No frontend object/registry or legacy pointer getter is admitted by a barrier,
scope, or backend choice. Unsupported GL shapes keep named refusals. Reply rows,
explicit synchronization, control operations and present-credit exhaustion retain
their existing waits; a test that removes all waits would violate the protocol.
## GPU resource and submission order
1. Wire buffer updates use exact owned bytes. A busy store is updated by ordered
GPU copy or a justified host-access wait; CPU readback does not revoke a slice
already reserved for a following draw. Store identity includes generation.
2. Lazy texture upload/preserve submissions are ordered after earlier renderer
recordings. Descriptor resolution prepares all active texture/image resources
and framebuffer attachments before capturing the current command buffer; a
later lazy upload cannot silently move bindings into an already submitted one.
3. CPU draw preparation can own future transient slices even before a draw is
recorded. Idle-drain/arena rewind must not reclaim them during that interval.
4. Wire draw, clear and color blit retain every native framebuffer, render pass,
view and descriptor pool until the submission that names it completes. Retirement
is keyed to submit indices, not an assumed number of frames or client progress.
Swapchain replacement/shutdown drains these after device idle, including abandoned
recordings. Independent blits never overwrite a descriptor set still in flight.
Wire sampled views and draw framebuffer objects may be reused within a frame slot:
exact keys include native storage identity/generation and every view/window value,
and the slot is cleared only after its actual fence completes. Overflow still uses
submit-index retirement. A cache hit never skips the image dependencies or pass boundaries.
Pipelines use renderer-lifetime, non-recycled identities interned from exact render-pass
compatibility values. A creator's temporary native render-pass handle is not a wire
pipeline cache key or an eviction proof for another compatible pass using that pipeline.
5. GPU writes retain their reverse notifications; readback waits for actual GPU
completion and returns owned bytes. Removing a per-draw queue idle does not
remove explicit GL synchronization or image/buffer memory dependencies.
## Evidence required before activation
Real Magma tests must hold apply at a known boundary while the client publishes
later commands, observe real sequence/ack counters, then verify pixels/bytes from
each queued state. Include resource rewrite/respecify/death-reuse, program/uniform
rebinding, GPU write/readback, texture ordering/promotion, and present credits 1/3.
The dedicated discovery set must execute completely without skips. A real
run-ahead-off control must fail the queued-progress assertion, then restore green.
Keep strict/dual-block and zero-residual gates; preserve pull G1 and test-name
ratchets. On Redmi, verify the installed library identity, actual `run-ahead ARMED`,
both roles, world rendering and liveness, and record a paired run-ahead-off arm.
Performance numbers are recorded with their workload/clock limits, not substituted
for correctness or inferred from the capability log alone.
+4
View File
@@ -1,5 +1,9 @@
# CONTRACT-P5E — the client runs ahead of apply on the Espryt draw path
> Historical P5e backend scope: the later [Magma run-ahead contract](CONTRACT-MAGMA-RUNAHEAD.md)
> supersedes this document's "Magma never publishes bit 10" restriction after P5f and the
> server-buffer migration. The wire wait classes, events and present-credit protocol remain.
Authority: this file, beside `CONTRACT-P5.md` (table 0, byte carriers, field ownership, R-1…R-17),
`CONTRACT-P5B.md` (the class-C slots) and `CONTRACT-P5C.md` (rule E, the two named exemptions,
SEG_EVENT, the guards). Where it disagrees with any of them this file is newer and wins; §8 lists
+2 -3
View File
@@ -1150,9 +1150,8 @@ namespace MobileGL::MG_Remote::Client {
// told that, or an A/B arm that measured nothing looks like an A/B arm that
// measured no difference (Config.h's own argument for parsing it everywhere).
MGLOG_W_ONCE("MG_Remote client: run-ahead requested, server does not publish "
"kCapRunAheadApply - running lockstep. This is Magma always, and "
"Espryt until the P5e integration commit flips "
"kMGPipeP5eRunAheadReady");
"kCapRunAheadApply - running lockstep. The selected backend has "
"not enabled its implementation-readiness gate");
}
return;
}
@@ -218,19 +218,14 @@ namespace {
EXPECT_EQ(mint.Count(), 1u);
}
// Application buffer record consumers do not imply run-ahead readiness.
// Magma retains its lockstep lifetime/submission contract; the capability
// must remain absent even when the Espryt readiness constant is true.
// Historical test name retained. Each backend's readiness is now a real gate:
// false forbids the capability, true permits it. Production keeps its own
// Magma readiness constant, which the bootstrap and GPU queue tests also check.
TEST_F(MagmaPipeIdentityTest, AMagmaServerNeverPublishesTheRunAheadCapBit) {
// Whatever the integration constant says. `true` is what the P5e integration commit
// will pass, so the Magma answer is pinned on BOTH sides of that flip and the case
// does not quietly stop asserting anything the day the constant moves.
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectVulkan, /*ready=*/false) &
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply),
0u);
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectVulkan, /*ready=*/true) &
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply),
0u);
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectVulkan, /*ready=*/false), 0u);
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectVulkan, /*ready=*/true),
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply));
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::Unknown, /*ready=*/true), 0u);
// And the Espryt half, so the case says what the arm IS and not only what it is not:
// the bit is published for DirectGLES and ONLY once the integration commit flips
+81
View File
@@ -95,6 +95,7 @@ namespace {
X(TrackerAttribPayload, AUintWriteCarriesTheUintWordsAndNamesItsClass) \
X(TrackerAttribPayload, TheSameNumbersWrittenThroughADifferentClassAreADifferentValue) \
X(TrackerShippedEmitter, ABlendToggleThroughTheValidatePointMintsTwoCsos) \
X(TrackerShippedEmitter, CollidingVaoShuttersStillPublishTheCurrentElementsAndBufferWindow) \
X(TrackerShippedEmitter, TheSteadyStateThroughTheValidatePointEmitsNothing) \
X(TrackerShippedEmitter, APushedAttributeDefaultTheApplierCannotReproduceIsRepaired) \
X(TrackerShippedEmitter, AViewportThroughTheValidatePointMintsNoCso) \
@@ -1064,6 +1065,86 @@ namespace {
UniquePtr<GLContext> m_previous;
};
TEST_F(TrackerShippedEmitter, CollidingVaoShuttersStillPublishTheCurrentElementsAndBufferWindow) {
MG_Config::Features.PipePush = kMGPipeSubsystemsMigratedAtP2 | kMGPipeSubsystemResources |
kMGPipeSubsystemVertexInput;
using MG_State::GLState::VertexArrayObject;
const SharedPtr<VertexArrayObject> a = Ctx().CreateVertexArrayObject(1);
const SharedPtr<VertexArrayObject> b = Ctx().CreateVertexArrayObject(2);
const auto buffer = Ctx().CreateBufferObject(1);
buffer->Respecify(256, nullptr);
for (Uint location : {0u, 1u}) {
a->SetAttributeFormat(location, location == 0 ? 3 : 2, DataType::Float32, false, 20,
location == 0 ? 0 : 12, false);
a->BindAttributeBuffer(location, buffer);
a->EnableAttribute(location);
}
b->SetAttributeFormat(0, 3, DataType::Float32, false, 12, 0, false);
b->BindAttributeBuffer(0, buffer);
b->EnableAttribute(0);
// Preserve the old collision independently of how production later mixes
// shutters. These ordinary small counter pairs really collide, rather
// than requiring a probabilistic 64-bit hash collision search.
constexpr Uint64 kCombine = 0x9e3779b97f4a7c15ull;
const auto oldMix = [](Uint64 identity, Uint64 version) {
return identity ^ (version + kCombine + (identity << 6) + (identity >> 2));
};
ASSERT_EQ(oldMix(1, 64), oldMix(2, 1));
ASSERT_EQ(oldMix(174, 37), oldMix(48, 8026)); // observed on Redmi while switching world draws
Uint32 versionA = 0, versionB = 0;
const Uint32 firstA = a->GetConfigVersion() + 64;
const Uint32 firstB = b->GetConfigVersion() + 1;
for (Uint32 candidate = firstA; candidate < firstA + 4096; ++candidate) {
const Uint64 hash = oldMix(a->GetLifetimeId(), candidate);
const Uint64 other = (hash ^ b->GetLifetimeId()) - kCombine -
(b->GetLifetimeId() << 6) - (b->GetLifetimeId() >> 2);
if (other < firstB || other >= firstB + 4096) continue;
versionA = candidate;
versionB = static_cast<Uint32>(other);
break;
}
ASSERT_NE(versionA, 0u) << "could not construct a bounded collision for these real VAO identities";
const auto advanceConfig = [](VertexArrayObject& vao, Uint32 version) {
// Change a disabled attribute, leaving the enabled 0/1 versus 0
// windows intact. No private lifetime/version field is overwritten.
while (vao.GetConfigVersion() < version) {
vao.SetAttributeFormat(31, 4, DataType::Float32, !vao.GetAttribute(31).Normalized,
16, 0, false);
}
};
advanceConfig(*a, versionA);
Ctx().BindVertexArray(1);
Draw();
const MGPipeHandle handleA = MGPipeApplier().BoundVertexElements;
ASSERT_FALSE(MGPipeHandleIsNull(handleA));
ASSERT_EQ(MGPipeApplier().VertexBufferCount, 2u);
ASSERT_TRUE(MGPipeApplier().VertexElementsCsos[handleA.Slot].Attributes[1].Enabled);
// Mutating B after A's draw moves the attribute aggregate. Before the
// repair this publishes B's Count=1 buffer set, but the colliding CSO
// shutter leaves A bound with attribute 1 still enabled: the phone's
// exact "buffer-window location=1 window=0+1" mismatch.
advanceConfig(*b, versionB);
ASSERT_EQ(oldMix(a->GetLifetimeId(), a->GetConfigVersion()),
oldMix(b->GetLifetimeId(), b->GetConfigVersion()));
Ctx().BindVertexArray(2);
Draw();
const MGPipeHandle handleB = MGPipeApplier().BoundVertexElements;
ASSERT_FALSE(MGPipeHandleIsNull(handleB));
EXPECT_NE(handleB, handleA) << "a VAO identity change must publish its vertex-elements binding";
EXPECT_EQ(MGPipeApplier().VertexBufferCount, 1u);
EXPECT_FALSE(MGPipeApplier().VertexElementsCsos[handleB.Slot].Attributes[1].Enabled);
// Switching back moves no attribute aggregate: the exact identity pair
// must also re-open the buffer-family shutter, restoring Count=2.
Ctx().BindVertexArray(1);
Draw();
EXPECT_EQ(MGPipeApplier().BoundVertexElements, handleA);
EXPECT_EQ(MGPipeApplier().VertexBufferCount, 2u);
EXPECT_TRUE(MGPipeApplier().VertexElementsCsos[handleA.Slot].Attributes[1].Enabled);
}
TEST_F(TrackerShippedEmitter, ABlendToggleThroughTheValidatePointMintsTwoCsos) {
constexpr int kToggles = 16;
Draw(); // prime: a fresh context resets the cache inside the emitter and mints once
@@ -11,6 +11,9 @@
#include <Config.h>
#include <MG_Backend/DirectVulkan/Renderer/PipelineFactory.h>
#include <MG_Backend/DirectVulkan/Renderer/ProgramFactory.h>
#if MOBILEGL_BUILD_DISAGGREGATED
#include <MG_Backend/DirectVulkan/Renderer/WireRenderPassCompatibility.h>
#endif
using namespace MobileGL;
using MobileGL::MG_Backend::DirectVulkan::PipelineFactory;
@@ -457,3 +460,58 @@ TEST(ReflectedReadsInstanceIndexBuiltin, FalseForAnEmptyModule) {
SpvReflectShaderModule emptyModule{};
EXPECT_FALSE(ProgramFactory::ReflectedReadsInstanceIndexBuiltin(emptyModule));
}
TEST(WirePipelineCompatibility, ExactCompatibilitySurvivesNativeObjectTurnover) {
#if MOBILEGL_BUILD_DISAGGREGATED
using namespace MobileGL::MG_Backend::DirectVulkan;
WireRenderPassCompatibilityTable table;
WireRenderPassCompatibilityKey a{{(Uint64(VK_FORMAT_R8G8B8A8_UNORM) << 32) | VK_SAMPLE_COUNT_1_BIT}, {0},
VK_ATTACHMENT_UNUSED};
const Uint64 first = table.Intern(a);
ASSERT_NE(first, 0u);
auto b = a;
b.attachmentFormatsAndSamples[0] = (Uint64(VK_FORMAT_R8G8B8A8_SRGB) << 32) | VK_SAMPLE_COUNT_1_BIT;
EXPECT_NE(table.Intern(b), first);
b = a;
b.attachmentFormatsAndSamples[0] = (Uint64(VK_FORMAT_R8G8B8A8_UNORM) << 32) | VK_SAMPLE_COUNT_4_BIT;
EXPECT_NE(table.Intern(b), first);
b = a;
b.colorReferences = {VK_ATTACHMENT_UNUSED, 0};
EXPECT_NE(table.Intern(b), first);
b = a;
b.depthReference = 0;
EXPECT_NE(table.Intern(b), first);
// Native pass/image turnover and swapchain changes never reset this table.
EXPECT_EQ(table.Intern(a), first);
#else
GTEST_SKIP() << "wire pipeline compatibility requires disaggregated build";
#endif
}
TEST(WirePipelineCompatibility, HashUsesCompatibilityIdentityAndSeparatesNativeDomain) {
#if MOBILEGL_BUILD_DISAGGREGATED
using namespace MobileGL::MG_Backend::DirectVulkan;
VulkanRendererConfig config{};
config.DisablePipelineCache = true;
// Hash-only unit: DisablePipelineCache prevents all device calls, and no
// pipeline is created. These tokens are never passed to a Vulkan driver.
PipelineFactory factory(reinterpret_cast<VkDevice>(uintptr_t{1}), config);
PipelineFactory::PipelineCreatePayload payload{};
payload.renderPass = (VkRenderPass)(uintptr_t{1});
payload.wireRenderPassCompatibilityId = 1;
const auto a = factory.ComputeHash(payload);
payload.renderPass = (VkRenderPass)(uintptr_t{2});
EXPECT_EQ(factory.ComputeHash(payload), a) << "compatible passes must reuse the pipeline across native handles";
payload.wireRenderPassCompatibilityId = 2;
EXPECT_NE(factory.ComputeHash(payload), a) << "a recycled native handle must not alias incompatible passes";
payload.renderPass = (VkRenderPass)(uintptr_t{1});
payload.wireRenderPassCompatibilityId = 0;
EXPECT_NE(factory.ComputeHash(payload), a) << "native handles and wire identities are different domains";
const auto native = factory.ComputeHash(payload);
payload.renderPass = (VkRenderPass)(uintptr_t{2});
EXPECT_NE(factory.ComputeHash(payload), native);
#else
GTEST_SKIP() << "wire pipeline compatibility requires disaggregated build";
#endif
}
+3 -2
View File
@@ -634,6 +634,7 @@ TEST(CapsMirrorTest, ObjectFamilyEmissionTracksIndependentConsumerCapsWithoutBuf
#endif
}
// Historical name retained; the real bootstrap must now publish and arm Magma readiness.
TEST(CapsMirrorTest, MagmaTransportPublishesRealBufferConsumersWithoutRunAhead) {
#if MGTEST_HAVE_FORK
const ChildResult result = RunInChild([] {
@@ -654,7 +655,7 @@ TEST(CapsMirrorTest, MagmaTransportPublishesRealBufferConsumersWithoutRunAhead)
const Uint64 mask = server.CallMask();
EXPECT_TRUE(MGCapsServerConsumes(mask, kMGPipeSubsystemResources));
EXPECT_TRUE(MGCapsServerConsumes(mask, kMGPipeSubsystemBufferBindings));
EXPECT_EQ(mask & static_cast<Uint64>(kCapRunAheadApply), 0u);
EXPECT_EQ(mask & static_cast<Uint64>(kCapRunAheadApply), static_cast<Uint64>(kCapRunAheadApply));
}
const auto* ops = MG_Pipe::MGPipeGetResourceOps();
EXPECT_NE(ops, nullptr);
@@ -669,7 +670,7 @@ TEST(CapsMirrorTest, MagmaTransportPublishesRealBufferConsumersWithoutRunAhead)
if (ops->MapPersistent) EXPECT_EQ(ops->MapPersistent({7, 1}, 64, nullptr), nullptr)
<< "Magma must not donate a server address as a client persistent map";
}
EXPECT_FALSE(ClientSessionInstance().RunAheadArmed());
EXPECT_TRUE(ClientSessionInstance().RunAheadArmed());
ClientSessionInstance().Stop();
MG_Remote::Server::ServerLoopInstance().Stop();
std::fflush(nullptr);
+11 -1
View File
@@ -17,10 +17,20 @@
## 2. P5f 最终验收
**Magma RD32 性能补修已完成**(`70fb6689`):inproc平均从86.85提升至116.73 FPS,
同包monolith为115.01 FPS。重复native对象与pipeline缓存键已修正,保留同步/角色边界;
7项新缓存场景、Vulkan同步验证和主机全门通过。见 [报告](notes/p5f/magma-rd32-performance-fix.md)。
**Magma run-ahead 已完成**(最终行为头 `194382c9`,2026-09-20):异步 GPU 生命周期、
真实 client lead、present credit 1/3、负控与 Vulkan 同步验证已通过;实机 VAO 哈希碰撞
已修复。Redmi 同一 `.mgdebug.debug` APK 的 Magma RA=1 / RA=0、GLES RA=1 均完成
至少60秒 MC `26.3-rc-3` 世界运行并验图。最终 unit 2312、GPU 1401、双块245 均零失败,
完整结果与边界见 [run-ahead 报告](notes/p5f/magma-runahead.md)。下面为此前修复与原 P5f 快照。
**Magma inproc 游戏修复**(行为头 `38919d45`,2026-09-20):已编入 Redmi 的
`com.tungsten.fcl.mgdebug.debug`。MC `26.3-rc-3` 世界 `test` 的 Magma inproc、GLES inproc
与 Magma monolith 均完成至少60秒运行及人工验图;应用 buffer 拒绝与 Android 90° blit
错误已修复。Magma inproc 仍 lockstep,实测约20 FPS,性能没有冒称齐平。最新19项专项门、
错误已修复。该历史包为 lockstep,实测约20 FPS。该包的19项专项门、
1387项GPU结果和剩余边界见 [修复报告](notes/p5f/magma-inproc-fix.md)。
旧 [fcl-e2e-report.md](notes/p5f/fcl-e2e-report.md) 保留 `aa78f102` 失败;下面六臂数字
仍是原 P5f 公开 GL runner 快照,不能冒充 FCL 测试或覆盖最新修复报告。
+4 -2
View File
@@ -2,6 +2,8 @@
> 状态:**P0、P0.5、P1、P2、P3a、P4a、P5、P5b、P5c、P5d、P5e、P5f 已收官**。P5f 于 2026-09-20 完成主机门、Redmi 六个 clean-boot 臂、跨模型族审查及修复验证;最终验收代码为 WSL `cfca93c7885fd8db1e881f91189ba59090ae9c52`(Windows `c42577a4` 等价)。证据见 [`notes/p5f/close-report.md`](notes/p5f/close-report.md)、[`close-review.md`](notes/p5f/close-review.md)、[`device-report.md`](notes/p5f/device-report.md)。**P6 的 P5f 前提已解除,a6 / c6 / spawn 实施尚未开始**。逐门数字、主分支合入记录和下一步见 [`CURRENT_STAGE_PROGRESS.md`](CURRENT_STAGE_PROGRESS.md) 与收官报告;设计见 `ARCHITECTURE.md`。P5e 的历史性能与 E1 对照债保留在阶段行、[`P5E-RUNAHEAD.md`](P5E-RUNAHEAD.md) 和 `MEASUREMENTS.md`,不由 P5f 的新对照代为关闭。
> **P5f 后续 Magma run-ahead 已完成**(`194382c9`,2026-09-20):主机真实排队、credit、负控及 Vulkan 同步验证通过,Redmi 同包 Magma 开/关与 GLES 三臂 FCL 世界实测通过。见 [报告](notes/p5f/magma-runahead.md)。P6 / P7 全阶段状态不因此改变。
## 通用纪律(每个 commit)
- 默认 ALL target 必须完整构建;禁止提交热路径插桩(CI grep 门)。
@@ -32,7 +34,7 @@
| **P5f** 一切状态上 wire | ✅ **已收官(2026-09-20)**;验收代码 Windows `c42577a4` / WSL `cfca93c7885f` | f0 普查、f1 双块、fc 控制帧、fe Espryt 字段、fm Magma record consumers、fs 静态世代/角色及 liveness、fr registry、fv 反向回调均已合并。字段归属 **41 RECORD_SUPPLIED / 6 APPLIER_DERIVED / 0 BARRIER_PULLED / 16 FATAL**;strict / dualblock 预期 marker 集合均空。控制帧与静态量工作已完成,不再列为 P6 待实现项 | unit **2310 = 2300 PASS + 10 skip**;GPU **1377** 零失败;ordinary / strict split **180 = 176 PASS + 4 skip**;双块 **212 = 206 PASS + 6 精确具名 skip**;双后端 RSP 门 **2 PASS / 0 skip**、逐帧 rsp=0。G1 `.text` 10806051、symbols 27815 恒等且 0/0/0/0;G2 3016 同名;G14 3646→3744 无删名。逐包与收官修复均有 red-once;Claude 异族终审 P1/P2 已修;Redmi 六 clean-boot 臂 **60 PASS / 6 skip / 0 failed**、36 个窗口 rsp=0。详见 [`close-report`](notes/p5f/close-report.md) |
| **P6** spawn transport | **P5f 前提已解除,尚未实施**;a6 / c6 待开始 | `SocketTransport`(socketpair + fork/execve,envp 剔除 + 强制 monolith 双保险);`ServerMain`;`MOBILEGL_IPC_SERVER_PATH` + `dladdr` 兜底;有界重试握手;EOF 即时退出;device-lost latch。消费 P5f 已落地的值控制帧与 server-owned 状态,不重做 EGL 帧化或静态世代隔离。依赖序见 [`P6-SPAWN-PLAN.md`](P6-SPAWN-PLAN.md):**a6**(核验进程装配/链接边界)→ **c6**(契约)→ **so / sm / cp / st / t6**。契约草稿 [`P6-CONTRACT-DRAFT.md`](P6-CONTRACT-DRAFT.md)。边界仍为 pbuffer / surfaceless / 离屏;真窗口到达归 P12。需区分不等待的 client 与已死亡的 server,不以超时阈值代替 device-lost 判定 | P5b 的完整渲染路径在 `spawn` 下绿;进程树只多一个子进程;`HeadlessGL` fork 预检无孤儿;OpenRA 在 Adreno 830 上 split SSIM ≥ 0.99;`integration-spawn` 与 `integration-split` 名集合一致;每条私有日志证明子进程 pid 与 `transport=spawn`;socket 门铃代价实际测量,性能只记录 |
| **P3b / P4b** 深化(Espryt) | 待排 | 按存储属主键控的发射游标与 view 索引重映射;`g_fboTextureSyncList`;`ResolvedTextureBindingMemo` / `SamplerPassMemo` / image sweep / program registry 重键;XFB scatter 搬到 client;删 fragColor 重推导 workaround 与 `g_broadcastMemo*`;raw-depth-fetch sampler 的 monolith 清理(transport 原生臂已由 P5f fs 落地);回读 / pack state;P4a 记下的 R-3 / R-4 / R-5 / R-7 / R-10 / R-11;`ProgramArtifacts.h` 的 NDK 尺寸钉 | 纹理 / program 场景;CTS `texture_*` / `shader_image_*` / `packed_pixels` 在 0.5 pp 内;每一个 Iris trace;`TextureUploadShapeScenario` 升级成门 |
| **P7** DirectVulkan(Magma)全量迁移 | 部分已提前落地,阶段未收官 | `38919d45` 已补实际游戏的 server buffer consumers 和 Android 旋转 blit([报告](notes/p5f/magma-inproc-fix.md));其余工作: 其余 10 个子系统:`SetupDrawSnapshot` 探测字段塌成 dirty mask;占位纹理原生化;具名 UBO host payload(D-B8);内部 shader 烘焙;`VertexInputStateFactory` 内容寻址 CSO;D18 容器纪律保留 | 集成 + trace 在 Magma 的 push 与 split 下全绿;verify 零分歧;`nm -D libMobileGLServer.so \| grep glslang` 为空;CTS 0.5 pp 内。**再基线检查点:中点完成子系统 < 40% 立即重定基线** |
| **P7** DirectVulkan(Magma)全量迁移 | 部分已提前落地,阶段未收官 | `38919d45` 已补实际游戏的 server buffer consumers 和 Android 旋转 blit([报告](notes/p5f/magma-inproc-fix.md));`194382c9` 又完成 Magma run-ahead、GPU 延迟退休与 VAO 身份碰撞修复([报告](notes/p5f/magma-runahead.md));其余工作:其余子系统:`SetupDrawSnapshot` 探测字段塌成 dirty mask;占位纹理原生化;具名 UBO host payload(D-B8);内部 shader 烘焙;`VertexInputStateFactory` 内容寻址 CSO;D18 容器纪律保留 | 集成 + trace 在 Magma 的 push 与 split 下全绿;verify 零分歧;`nm -D libMobileGLServer.so \| grep glslang` 为空;CTS 0.5 pp 内。**再基线检查点:中点完成子系统 < 40% 立即重定基线** |
| **P8** emulation 下放 + 索引宿主镜像 + 协议广度 | 待排 | `MG_Impl/Pipe/HostResolve.cpp`(client 数组范围、最大索引扫描、`*IndirectCount` 解析,逐站点 reconcile);`Server/IndexHostMirror`;CopyImage 镜像搬到 client;viewport-array 回放验证;`generate_mipmap` 计划 + CPU 回退纹素;大 blob carrier(开放问题 11);无 present fence tick;`kCapDriverOrderedXfbCapture` | `'^DirectGLES\.Split\.'` 与 `'^DirectGLES\.'` 逐名相同;trace split 双后端 SSIM ≥ 0.99 含两个 `coherent_as_flush` fixture;`ClientArrayAfterComputeWriteScenario`;`create-indirect` 上 `roundtrips-per-frame` 读零;`index-mirror-bytes` 逐用例发布 |
| **P9** 反向通道 | 待排 | `SEG_REPLY` 异步 slot 池;PBO 回读 fire-and-forget;`OnGpuWritten` 收窄;`OnBufferWriteback` 批处理 + epoch 排序;`OnXfbScatterReady`;`OnTextureWriteback`;`OnMipLevelsGenerated`;纹理拉取四条缓解 + 终止符;`OnGlError` 有序;`OnSurfaceChanged`;`OnLog` 分级;`SEG_EVENT` 溢出策略;class-C 的 readback 尾 | 回读 / XFB 场景在 split 下绿;`TextureRemintPullScenario`(含无解用例);拉取计数逐 trace 发布;两条故障注入 |
| **P10** sync / query / present 节奏 | 待排 | client 铸造 query handle;轮询入口成门铃点 + `MOBILEGL_IPC_POLL_ESCALATE`;fence 完成度来自逐 fence 退休;非 present fence tick;`present` 1:1;credit 默认 1;roundtrip 计数器与输入延迟直方图;class-C 的 query / swap-interval 尾 | query / XFB / `AsyncCompile` 场景在 split 下绿;trace 上 draw / state / upload 路径 roundtrip 读零;零 timeout 轮询有界退出;配对 A/B 记录 |
@@ -125,7 +127,7 @@ P5c 当时移交的对象类 BARRIER-PULLED、transport registry 前端键、EGL
| ABI fingerprint | 不混 segment sizes;改变 8/32/16 MiB + 256 KiB ledger 时仍欠这项 |
| 默认 32 MiB staging | 目标负载单次 128 MiB 上传装不进默认 stage;普查 / Redmi 显式 256 MiB profile,默认不改;分块 / 专用 carrier 归 P8(开放问题 11) |
| P5b 的 inproc 依赖 | 历史的 scoped client binding、mip registry 查询与 FBO death mailbox 已经 P5c/P5f 改为记录、句柄和控制/事件路径;P6 核验并装配已有载体,不再重做这些迁移 |
| 未迁移与仿真路径 | 15 个 class-C 槽(query / sync 尾 / `GetTexImage` / `SetSwapInterval`)→ P9 / P10;client vertex arrays、multi-draw client indices、RGB 三通道 CPU mip、renderbuffer copy endpoint、未绑定 named clear、`texture-remint-pull` 仿真保留具名拒绝 → P8 / P9;Magma split compute / image 的“82 个错答”是 P5b 历史普查计数,不是当前失败清单;P5f 后续已补应用 buffer consumers 与 Android 旋转 blit,Magma inproc 已能运行所测 MC 世界;XFB、部分不对齐范围、placeholder/native-format 及性能仍归 P7([报告](notes/p5f/magma-inproc-fix.md)) | **P5e 补**:client vertex arrays 在 run-ahead 下是**具名拒绝**(ID-82,`Fatal{UnmigratedVerb, "DrawArrays+CLIENT_ARRAYS"}`),并有自己的预期红车道 `integration-clientarrays-split`(ID-134);staging 仍归 P8
| 未迁移与仿真路径 | 15 个 class-C 槽(query / sync 尾 / `GetTexImage` / `SetSwapInterval`)→ P9 / P10;client vertex arrays、multi-draw client indices、RGB 三通道 CPU mip、renderbuffer copy endpoint、未绑定 named clear、`texture-remint-pull` 仿真保留具名拒绝 → P8 / P9;Magma split compute / image 的“82 个错答”是 P5b 历史普查计数,不是当前失败清单;P5f 后续已补应用 buffer consumers 与 Android 旋转 blit,Magma inproc 已能运行所测 MC 世界;后续 run-ahead 已完成([报告](notes/p5f/magma-runahead.md));XFB、部分不对齐范围、placeholder/native-format 及进一步性能工作仍归 P7([报告](notes/p5f/magma-inproc-fix.md)) | **P5e 补**:client vertex arrays 在 run-ahead 下是**具名拒绝**(ID-82,`Fatal{UnmigratedVerb, "DrawArrays+CLIENT_ARRAYS"}`),并有自己的预期红车道 `integration-clientarrays-split`(ID-134);staging 仍归 P8
| E2 wire 内容控制 | draw-drop 是 OpenRA 的有效控制(758 draws,SSIM 0.000036);clear-drop 被全屏 overdraw 掩盖,不能作控制 |
| max record bytes | 实测 reduced / OpenRA `maxrec=784 B`,默认 cap 4 MiB;只代表所测负载,后续索引 / indirect 尾仍须记录 |
| 树外脚本 | 普查跑器、`wsl_p5_gate.sh`、Redmi 定频行都在 `~/w7/notes/`,git merge 不会传播 |
+15 -4
View File
@@ -4,12 +4,22 @@
> `C:/Users/geekerwan/AndroidStudioProjects/FoldCraftLauncher/MobileGL-disagg`,分支 `feat/disaggregated`。
> 完整结果见 [close-report.md](close-report.md),设备见 [device-report.md](device-report.md),
> 阶段终审见 [close-review.md](close-review.md)。原 P5f 行为验收头 `cfca93c7`;
> 后续 Magma 游戏修复的行为头为 `38919d45`,见下。
> 后续 Magma run-ahead 的最终行为头为 `194382c9`,见下。
>
> **Magma RD32 性能补修(2026-09-20,`70fb6689`)**:修复重复view/framebuffer创建销毁和
> 临时render-pass句柄造成的pipeline缓存退化;inproc **116.73 FPS**,同包monolith **115.01 FPS**。
> 缓存回归、Vulkan同步验证及主机全门通过。见 [性能报告](magma-rd32-performance-fix.md)。
>
> **Magma run-ahead 已完成(2026-09-20)**:独立 readiness 已开启,GPU 提交/资源
> 退休时序、真实排队/credit 1/3、负控、Vulkan 同步验证均通过。Redmi 同一
> `.mgdebug.debug` APK 的 Magma RA=1 / RA=0 与 GLES RA=1 三臂均完成至少60秒
> 世界运行与验图;修复了实机发现的 VAO 身份哈希碰撞。见 [最终报告](magma-runahead.md)。
>
> **Magma inproc 游戏修复(2026-09-20)**:已补 server buffer consumers 与 Android quarter-turn
> color blit。`38919d45` 的 `.mgdebug.debug` FCL 在 MC `26.3-rc-3` 世界 `test` 上,
> Magma inproc、GLES inproc 和 Magma monolith 均完成至少60秒运行与人工验图。
> Magma inproc 仍 lockstep、约20 FPS;不是 P7 全量完成。见 [修复报告](magma-inproc-fix.md)。
> 该历史包仍 lockstep、约20 FPS;当前版本以上面的 run-ahead 报告为准。
> 不是 P7 全量完成。见 [修复报告](magma-inproc-fix.md)。
> 旧 [fcl-e2e-report.md](fcl-e2e-report.md) 保留 `aa78f102` 的真实失败,不代表当前结果。
## 0. 当前结论
@@ -41,8 +51,9 @@ P6 的 P5f 前提解除;P6 的 a6 审计、c6 契约冻结和 spawn 实现均
## 1. 下一阶段需要知道的边界
- Magma 仍不发布 `kCapRunAheadApply`;可达路径已经在 role-split + strict 下验证,
lockstep 没有 frontend registry/allocator 豁免。P7 buffer/native-format 等功能仍具名拒绝。
- Magma 已发布 `kCapRunAheadApply`;`RUN_AHEAD=0` 保留配对对照。
可达路径已经在 role-split + strict 下验证,没有 frontend registry/allocator 豁免。
其余 P7/P8 shape 限制仍具名拒绝;run-ahead 不代表 P7 全量完成。
- P8 client arrays、P12 window/present 到达语义等路线图债保留;不是未完成的 P5f 包。
- server context 的 unpack/render shadow 按 native generation / served serial / role 核键。
XFB 以 lifetime id 分区;served context 切换保留暂停 span,native context 销毁才废弃旧
+2 -1
View File
@@ -11,7 +11,8 @@
用户随后要求的 [首次 FCL 游戏端到端补测](fcl-e2e-report.md) 暴露 Magma inproc 的 P7
`buffer-legacy-arm`。后续 [Magma 游戏修复](magma-inproc-fix.md) 补齐 buffer consumers 与
Android 旋转 blit,`38919d45` 已在同一 MC `26.3-rc-3` 世界正常运行。本文余下数字保留原
P5f 收口快照;最新修复没有宣称 P7 全量迁移或 Magma run-ahead 已完成。
P5f 收口快照。随后 `194382c9` 已完成 [Magma run-ahead](magma-runahead.md),
有独立主机门和 FCL 实测证据;P7 全量迁移仍未收官。
## 1. 完成的行为
@@ -1,6 +1,7 @@
# Magma inproc 实际游戏修复
> 当前行为头 `38919d45`,分支 `codex/magma-inproc`;本报告记录 P5f 后的实际游戏补修。
> 历史行为头 `38919d45`,分支 `codex/magma-inproc`;本报告记录 P5f 后的实际游戏补修。
> 后续 `194382c9` 已完成 [Magma run-ahead](magma-runahead.md),本报告保留当时 lockstep 数据。
> Redmi Magma inproc 已通过运行与人工图像检查;同 APK 的 GLES inproc 与 Magma monolith 复跑、最终 G1/G2/G14 均已通过。
> 功能修复、主机门与真机验证完成;保留以下性能和功能边界,未宣称 P7 全阶段收官。
@@ -0,0 +1,163 @@
{
"production_head": "70fb6689",
"source_artifact": {
"source": "70fb6689",
"apk": "C:\\Users\\geekerwan\\.codex\\tmp\\magma-perf-fix\\FCL-magma-perf-70fb6689.apk",
"apk_sha256": "bfa352bcb3402d9a31252503bacf6fcdc21e28ffaaa929fd8c80e6f2e2781e4e",
"library_sha256": "11f26ca1f1d6c9a3d89134c31b2348306e669b1d9ebcc2fc77c7f5def2b4f818"
},
"baseline_fps": {
"Magma-inproc": 86.85293459363007,
"Magma-monolith": 116.07722925432384
},
"clock_control": "stock-dvfs",
"render_distance": 32,
"simulation_distance": 12,
"fan_target": 2,
"after": [
{
"name": "Magma-inproc",
"backend": "DirectVulkan",
"transport": "inproc",
"performance": {
"fps": 116.73138991101129,
"fps_median": 117.0,
"fps_p10": 115.0,
"fps_min": 106.0,
"fps_max": 119.0,
"fps_stdev": 1.8717476401816064,
"seconds": 61.02900004386902,
"intervals": 61,
"frames": 7124,
"method": "sum(reset-counter frames) / sum(actual adjacent-log seconds)"
},
"hardware": {
"clock_control": "stock-dvfs",
"samples": 11,
"temperature_c_min": 57.0,
"temperature_c_max": 58.1,
"fan": {
"fan_rpm": [
"14487",
"14591",
"14676",
"14697",
"14804"
],
"fan_target": [
"2"
]
},
"frequencies": {
"policy0_cur": {
"min": 1555200,
"max": 1555200
},
"policy6_cur": {
"min": 1209600,
"max": 1689600
},
"gpu": {
"min": 832000000,
"max": 900000000
},
"busy": {
"min": 82,
"max": 84
}
}
},
"boot_id": "e69d0329-2264-4a2d-9b00-e1a4ffb6154d",
"actual_runtime": {
"backend_names": [
"Direct (Vulkan)"
],
"ipc_lines": [
"Config: IPC ring=8MiB stage=256MiB spin=50us persistent-block=64KiB adopt-tier=2 verb-barrier=1 run-ahead=1 present-credit=1 strict=1 audit=0 role-split-state=1 affinity='auto'"
],
"run_ahead_armed": true,
"caps_call_masks": [
"0x0",
"0x3fff00000400"
],
"run_ahead_cap_bit_seen": true,
"stats_rows": 237,
"residual_pulls_max": 0.0
}
},
{
"name": "Magma-monolith",
"backend": "DirectVulkan",
"transport": "monolith",
"performance": {
"fps": 115.00581747506094,
"fps_median": 115.0,
"fps_p10": 113.0,
"fps_min": 112.0,
"fps_max": 118.0,
"fps_stdev": 1.310503381393822,
"seconds": 61.02300000190735,
"intervals": 61,
"frames": 7018,
"method": "sum(reset-counter frames) / sum(actual adjacent-log seconds)"
},
"hardware": {
"clock_control": "stock-dvfs",
"samples": 11,
"temperature_c_min": 55.4,
"temperature_c_max": 58.9,
"fan": {
"fan_rpm": [
"14282",
"14363",
"14384",
"14487"
],
"fan_target": [
"2"
]
},
"frequencies": {
"policy0_cur": {
"min": 1363200,
"max": 1555200
},
"policy6_cur": {
"min": 1689600,
"max": 1689600
},
"gpu": {
"min": 734000000,
"max": 900000000
},
"busy": {
"min": 73,
"max": 76
}
}
},
"boot_id": "b52edced-93b3-416e-890b-5d9a2ea4e8d2",
"actual_runtime": {
"backend_names": [
"Direct (Vulkan)"
],
"ipc_lines": [],
"run_ahead_armed": false,
"caps_call_masks": [],
"run_ahead_cap_bit_seen": false,
"stats_rows": 250,
"residual_pulls_max": 0.0
}
}
],
"restoration": {
"original_world_files_unchanged": 61,
"config": {
"mg_env.txt": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"mg_transport.txt": "1d80cf637af2284a1763196d824b41f6f12bea849aa81f95ab8db0e5ce043c95",
"options.txt": "4d1cd0cb595819d924f8d5823910b643c865f12b3f59b6900abd54b04e2ee646"
},
"fan_restored": true,
"installed_library_sha256": "11f26ca1f1d6c9a3d89134c31b2348306e669b1d9ebcc2fc77c7f5def2b4f818"
}
}
@@ -0,0 +1,105 @@
# Magma RD32 inproc 性能修复
**已完成,2026-09-20**。生产行为头 `70fb6689`,之后仅追加 CI 脚本、契约与报告。
原 [RD32 四组合记录](rd32-fourway.md) 的 Magma inproc 86.85 FPS / monolith 116.08 FPS
是本次基线,保留原数据。修复后的同包对照已回到约115–117 FPS,同一场景的25%差距消失。
## 结果
| 模式 | 修复前平均 FPS | 修复后平均 FPS | 修复后区间中位数 | 修复后区间 P10 |
|---|---:|---:|---:|---:|
| Magma-monolith | 116.08 | 115.01 | 115.00 | 113.00 |
| Magma-inproc | 86.85 | 116.73 | 117.00 | 115.00 |
inproc 相比旧实现平均提升 **34.4%**;同包 inproc 比 monolith 高约1.5%。只有单轮,
不能据此认定稳定领先;本场景已不再呈现原先约25%的差距,两者均接近120 FPS量级。
不宣称无上限吞吐或零架构开销。
P10为约一秒计数区间的FPS分位,不是逐帧1% low。
## 原因与改动
实机30秒 `simpleperf cpu-clock` 采样中,服务端仍反复
构造和销毁 native GPU 对象:`vkCreateFramebuffer` inclusive占7.91%,
`vkDestroyFramebuffer` 6.21%,`SetupWireDraw` 21.15%。这些是各自采样份额,存在调用层级,
不能把父子项全部相加。客户端与服务端都存在工作/等待交替,不能把两个线程CPU时间相加当帧延迟。
本次修复:
1. **采样/storage image view复用**:UniformManager按帧槽缓存完整创建参数,包括root handle/gen、
native image与allocation epoch、format/type、swizzle、aspect及mip/layer窗口。逐字段比较,
不把相同hash当相同视图。句柄稳定后,原descriptor内容缓存可以复用。
2. **draw framebuffer对象复用**:每个frame slot最多缓存32个inactive pass/view/framebuffer组合,
精确匹配附件身份、窗口、格式、samples、draw-buffer映射和交换链信息。命中仍执行原有
End/Begin、image transition及memory dependency;溢出走原submit-index退休。
清理依赖真实slot fence或完整idle证明,发生在texture manager释放旧image之前。
3. **pipeline兼容性身份修复**:原PipelineFactory把临时 `VkRenderPass` 句柄放进缓存key,
跨帧重建容易重复创建pipeline,句柄回收也存在旧key别名风险。现在用精确formats/samples、
有序color refs/holes与depth ref分配非零身份,renderer生命周期内不复用ID,
与native句柄域分离。原句柄只供Vulkan创建调用;wire pipeline不再按creator pass的销毁
事件回收,继续沿program/age/整体销毁生命周期,避免误删另一个兼容pass在途使用的pipeline。
4. **其余热路径**:缓存物理设备不变的vertex-format支持结果;退休队列由逐项erase的二次搬移
改为一次稳定压缩。没有移除GPU同步、reply等待、present credit或角色守卫。
修复后独立post-window profile中,framebuffer创建采样份额降到3.56%;旧pipeline创建/
`inflate`热点不再出现在0.1%阈值以上的服务端采样项。仍有每帧必要对象工作,未声称零创建。
服务端样本18,017→13,106,但两份profile处于动态频率、不同运行时刻,不能读成精确同频周期倍率。
计时窗口与profile分开,profile开销没有混入上表的FPS。
## 验证
| 门 | PASS / skip / failed |
|---|---:|
| unit | 2304 / 10 / 0 |
| GPU | 1119 / 296 / 0 |
| strict split | 176 / 4 / 0 |
| 双块 split + Magma | 246 / 6 / 0 |
| cache专项(含Vulkan同步验证) | 7 / 0 / 0 |
| run-ahead专项(含Vulkan同步验证) | 14 / 0 / 0 |
| buffer专项 | 19 / 0 / 0 |
- 新7项公开GL场景覆盖sampler swizzle A→B→A、respec、mip/layer/view type、
FBO A→B→A、重挂附件、sRGB切换及attachment respec。所有draw先排队,之后才统一读像素。
- 新2项unit覆盖兼容性身份稳定、raw句柄换代与wire/native分域。临时禁止生产ComputeHash的
wire key分支时,same-ID/different-native-RP断言实际rc1;逐字节恢复后完整构建和该case rc0。
- cache7与run-ahead14均证明Khronos layer实际插入,零VUID/SYNC-HAZARD/validation error。
既有caps枚举 `GL_STENCIL_INDEX8` 应用诊断仍分列,未掩盖Vulkan错误。
- run-ahead=0负控实际等apply并失去queue lead后失败,恢复1转绿。strict两类marker棘轮为空。
- GPU skip集合精确为旧282加新cache generic双后端14;专用cache7全部执行。无删名或额外skip。
- pull/push构建与生成器、field/dirty self-test、4个include probes全过。
G1 section-size/defined-symbol比较全0,`.text 10806051`、symbols增/删/变长/改名0/0/0/0;
不是跨构建原始机器码逐字节承诺。G2 **3019==3019**;G14 **3803→3826,+23/-0**。
- cache同步验证已加入CI,使用 `scripts/ci/magma_cache_checks.py`;入仓版本也独立跑过7/7。
## 实机条件与交付
Redmi `2f7cbe2e`,FCL `com.tungsten.fcl.mgdebug.debug`,Minecraft `26.3-rc-3`,
同一冻结初始世界副本、固定相机、RD32/simulation12、2620×1280、VSync off/maxFps260。
每臂独立重启、入场CPU温度低于40°C、进入世界后预热180秒,再采至少60秒。
最终所选两臂采样窗全部风扇观测均档位2、RPM>0;原始FCL计数按实际相邻日志间隔归一化。
| 模式 | CPU温度 °C | 大核观测 GHz | GPU观测 MHz |
|---|---:|---:|---:|
| Magma-monolith | 55.4–58.9 | 1.690–1.690 | 734–900 |
| Magma-inproc | 57.0–58.1 | 1.210–1.690 | 832–900 |
使用默认DVFS,没有关闭温控。初次候选inproc计时为116.77 FPS,但风扇被系统关闭,
该次计时不纳入最终配对,只保留其post-window profile。最终另跑一次fan2 inproc,
没有把两次结果平均或挑选最好值。新增fan变化检查会重新预热,采样窗若漂移则拒绝该次结果。
两组actual backend/transport/capability、全部stats `rsp=0`、PID与前后画面均核查;
inproc实际ARMED、strict/role-split=1;monolith无IPC配置、vbs=0。
- APK:`C:/Users/geekerwan/.codex/tmp/magma-perf-fix/FCL-magma-perf-70fb6689.apk`
- APK SHA256:`bfa352bcb3402d9a31252503bacf6fcdc21e28ffaaa929fd8c80e6f2e2781e4e`
- 已安装库SHA256:`11f26ca1f1d6c9a3d89134c31b2348306e669b1d9ebcc2fc77c7f5def2b4f818`
- 最终配对证据:`C:/Users/geekerwan/.codex/tmp/magma-perf-fix/final-evidence/`,
结论文件 `magma-pair.json`;包含source selection、原始计数/日志、4张验图、真实恢复核验。
通用四臂分析器的 `performance.json` 标2/4是因为本次只测Magma两臂,不能冒称又重测了Espryt。
- profile:`../magma-perf-baseline-profile/` 与 `../magma-perf-candidate70fb-bench/`,
含原始perf.data、匹配Build ID的符号缓存及报告。测试计时不使用profile期间的FPS。
- 主机证据:`/home/swung/w7/magma-perf-logs/`,前缀 `final-gates-70fb6689`、
`syncval-caches-70fb6689`、`syncval-runahead-70fb6689`、`negative-70fb6689`、
`pipeline-key-red-once-70fb`、`ci-cache7-ac1f`。
原世界61个文件已逐项SHA256核对不变,options/mg_env/mg_transport逐字节恢复、风扇恢复0,
只保留新APK安装。已有Gradle修改和父FCL冲突索引未动。没有将缓存优化写成P7全量完成。
@@ -0,0 +1,142 @@
# Magma run-ahead
**已完成,2026-09-20**。最终生产与实机行为头 `194382c96a8a5f51ef23f412fdccfbd40a82bf78`。
后续 `70fb6689` 已修复 RD32 下的 Magma inproc 性能差距:**86.85→116.73 FPS**,
同包 monolith **115.01 FPS**;根因、缓存生命周期与复测见 [性能修复报告](magma-rd32-performance-fix.md)。
后续同包的 **render distance 32 四组合性能测量**见 [rd32-fourway.md](rd32-fourway.md)。
该轮默认动态频率下,Espryt monolith/inproc 为62.18/64.02 FPS,Magma 为116.08/86.85 FPS;
不要将下面的功能验证窗口替代这份高负载性能记录。
本次是在已完成的 P5f 与 Magma inproc 游戏修复上继续实现异步排队,
不是重开 P5f 包,也不宣称 P6 spawn 或 P7/P8 全量实现。
契约见 `MobileGL/MG_Remote/CONTRACT-MAGMA-RUNAHEAD.md`。
## 实现
- Magma 独立 readiness 条件满足后发布 `kCapRunAheadApply`,复用既有客户端闩、
wait class、反向事件流控和 present credit。`MOBILEGL_IPC_RUN_AHEAD=0` 保留为配对对照。
reply、显式同步和 credit 耗尽的等待仍保留。
- wire draw/clear/color blit 不再逐 draw 提交并 `vkQueueWaitIdle`。render pass、
framebuffer、view 和 blit descriptor pool 按实际 submit index 延迟释放;
Present、重建和 shutdown 处理最后一批对象。独立 blit 不复写在途 descriptor set。
- texture 上传和 GPU 内容保留提交不能越过旧 draw;draw/dispatch 在取得当前
command buffer 前准备 image、sampled texture 和 FBO attachments。native blit
后同时失效 pipeline/dynamic state 与 uniform manager 的 descriptor 绑定缓存。
- GPU buffer readback 后保留后续 draw 已预约的 slice;CPU draw preparation 期间
不允许 idle-drain 回卷 transient arena。同 layout image transition 保留内存依赖。
- compute work-group 上限由本地 CapsMirror 回答,不再通过三个 getter 插入无谓
barrier。修改限于 transport 的两个 compute COUNT/SIZE 查询。
- Vulkan 验证层发现并修复 descriptor indexing API/extension 启用条件、含 dynamic
UBO layout 的非法 UPDATE_AFTER_BIND、HOST_WRITE stage 和 Present layout transition
的写后写依赖。wire 使用已有按内容版本分配的 descriptor set,不原地修改在途 set。
- 最小化窗口丢弃 recording 后,只有 CPU preparation、renderer submit 和纹理独立
upload fence 都空闲才回收 future-tag 对象。纹理 fence 只轮询,不新增 queue wait;
同时避免对象持续累积和误把 renderer watermark 当作整个队列的 idle 证明。
## Redmi 发现的 VAO 状态漏发
初版 `3c97ea9c` run-ahead 进入世界后触发 `Magma:vertex-layout@P7`。
`6f764c42` 诊断包关闭 run-ahead 仍复现:enabled attribute 1 对应的 buffer window
却是 `0+1`。因此没有删去边界检查,也没有把它当作驱动格式限制绕过。
根因是 dirty tracker 把 `{VAO lifetime, configVersion}` 用普通 hash-combine
压成一个值判断身份变化。普通整数对会碰撞;Redmi 实际记录的两个身份为
`174/37` 与 `48/8026`。缓冲家族因 aggregate 变化发布了新窗口,CSO 家族却
漏发 bind,形成旧布局与新窗口组合。现在精确比较两个字段,变化时重新检查
三个 vertex families,各 emitter 仍可抑制自身未变化的记录。
新测试通过合法 setter 构造真实 VAO 的碰撞配置,经实际 validate 路径检查
`A(0+1 enabled) → B(0 enabled) → A` 的绑定及窗口 `2→1→2`,不改私有计数器。
候选修复 `376c04be` 已在 Redmi 捕获碰撞被修复的日志,世界连续运行 64.167 秒,
验图正常。该诊断包不是最终交付验收包;初版失败证据保留。
## 主机验证
七种实际排队场景各测 present credit 1/3,共 14 项:
buffer SubData/respecify/delete-name-reuse、program/uniform 快照、SSBO 写回读、
native 与 double-converted vertex slice、旧 texture draw 与后续上传的顺序、
GPU clear 后首次 storage image 升级、credit 用完时客户端真实停车。
用已有 apply hook 暂停真实服务端,观察真实 emit/applied watermark 和 producerParked,
不伪造 capability/sequence,也不把 ARMED 日志当作排队证明。
关闭 run-ahead 的负控同一 testcase 必须实际等 apply、失去 client lead 并失败,
恢复后转绿。同步验证必须证明 Khronos layer 被 loader 插入,完整执行 14 项,
且零 VUID / SYNC-HAZARD / validation error。两项均已接入 CI,脚本为
`scripts/ci/magma_runahead_checks.py`。
RSP 测试采样也修正了真实的 fixture race:异步 EndFrame 返回不代表 Present
统计已发布,测试现在等该条已发出的 Present applied 后再读日志;生产未加等待。
最终行为头的结果如下,skip 不计 PASS,完整发现集与 JUnit 核对:
| 门 | 总数 | PASS | skip | failed |
|---|---:|---:|---:|---:|
| unit | 2312 | 2302 | 10 | 0 |
| integration-gpu | 1401 | 1119 | 282 | 0 |
| strict integration-split | 180 | 176 | 4 | 0 |
| 双块 split + magma | 245 | 239 | 6 | 0 |
| 其中 run-ahead 专项 | 14 | 14 | 0 | 0 |
| 其中 buffer 专项 | 19 | 19 | 0 | 0 |
| 其中两后端逐帧 RSP | 2 | 2 | 0 | 0 |
| Khronos synchronization validation | 14 | 14 | 0 | 0 |
- unit / GPU / 双块的 skip 名称与前一轮完整结果集精确相同;普通 GPU 发现的 14 个
run-ahead 副本只在专用车道运行,因此在那里按 fixture 声明 skip,专用 14 项均执行。
- strict marker 与双块 fatal 棘轮均空;初版负控与最终 run-ahead-off 负控均真实红转绿。
Tracker 碰撞回归临时撤掉 exact-pair dirty 分支后 rc=1,恢复后 rc=0;改动已还原。
- Vulkan layer 实际插入 14 次,零 VUID / SYNC-HAZARD / validation error。日志另外保留
28 条既有 MobileGL `GL_STENCIL_INDEX8` caps 枚举应用 ERROR;它们不是 layer 消息,
checker 按来源分列,含 Vulkan 标识的消息和 loader ERROR 仍硬失败。
- pull / push 构建通过;G1 `.text 10806051 → 10806051`,27815 defined symbols,
added/removed/resized/renamed **0/0/0/0**。G2 **3017 == 3017**。
G14 完整 JSON 名称集合 **3774 → 3803,+29 / -0**。
- G1 上述结论是仓库脚本的 section size / symbol name / symbol size 比较,
不声称不同构建的原始 `.text` 逐字节相等。额外只读反汇编核对发现原始差异全部
来自元数据:7255 条 RIP 引用因生成的 SPIRV-Cross version 字符串缩短7字节而
位移,解引用字符串相同;107 条 immediate 对应同一源码文本的 `__LINE__` 位移。
生成的版本字符串和时间戳也不同,未把这种构建可复现性差异记成运行逻辑变化。
- wire/field/dirty generators、field self-test 与四个 include closure probes 全过。
证据目录 `final-gates-194382c9/`、`negative-194382c9/`、`syncval-194382c9/`、
`tracker-red-once-194382c9/`,均在上述主机日志根目录下。
## FCL 实机验证
设备限定 Redmi `2f7cbe2e`,包名 `com.tungsten.fcl.mgdebug.debug`,
Minecraft `26.3-rc-3`,世界 `test`。复现脚本与准备/恢复步骤见
`tools/device_bench/magma_runahead/README.md`。
最终 APK `FCL-magma-runahead-194382c9.apk` 已覆盖安装,保留游戏数据:
- APK SHA256:`69973e2f51b87bd0128420da62b92fa2fb862a11067baf1b54a142f971d13357`
- `libMobileGL.so` SHA256:`046d86c288ce891b16770148578ba1a6fea4057783b69c2359f5830e58b7b223`
- APK 内与 `/data/app/.../lib/arm64/libMobileGL.so` 哈希一致,记录在
`final-artifact-identity.json`。三臂均使用此 APK,分别重启设备后运行。
| 臂 | 实际能力 | 世界连续运行 | 帧增量 / 近似 FPS | 图像 |
|---|---|---:|---:|---|
| Magma inproc RA=1 | ARMED | 64.472 s | 7680 / 119.122 | 地形、天空、手、hotbar 与方向正常 |
| Magma inproc RA=0 | 实际 Config run-ahead=0,无 ARMED | 60.589 s | 7320 / 120.813 | 同上 |
| GLES inproc RA=1 | ARMED | 60.865 s | 7080 / 116.323 | 同上 |
三臂数据与截图位于 `final-Magma-on/`、`final-Magma-off/`、`final-GLES-on/`。
Magma-on 有一次 `adb pidof` 查询超时(rc=124),随后仍为同一 PID `10141`,
帧与日志持续推进、无进程重启或 crash;不将它写成应用退出。
三臂共 193 个 stats windows 全部 `rsp=0`,strict=1、role-split-state=1,
六张世界截图均已检查;证据结论见各目录 `screenshot-review.json` 和汇总
`final-device-verdict.json`。三个不同 boot-id 分别为
`300c0044-058f-4c34-9e88-6e888d834877`、`bf9a1b6c-ce58-4ca6-bc71-8da52a856684`、
`f61e1c51-e354-4867-b708-72ca463e2119`。
原 `mg_env.txt`(空文件)和 `mg_transport.txt`(`inproc\n`)已恢复并逐一核对
SHA256,世界已保存退出;没有回滚世界内容。用户两份 Gradle 配置及父 FCL 的
原有未合并索引未改动。本轮未将库/APK 二进制提交到 Git。
所有主机原始日志保留在 `/home/swung/w7/magma-ra-logs/`;设备证据在
`C:/Users/geekerwan/.codex/tmp/magma-runahead/`。静态镜头、未锁频、天气和温度不受控,
帧计数只能作本次运行记录,不能把所有提升都归因于客户端 run-ahead;
本次还同时取消了 GPU 逐 draw 等待。具名 P7/P8 shape refusals 继续保留。
本次 RA=1 与 RA=0 的近似均值接近,不能据此宣称客户端 run-ahead 有特定 FPS 收益;
能确认的是所测世界已能在约 120 FPS 水平运行,真实排队与 credit 语义由主机专项证明。
@@ -0,0 +1,594 @@
{
"date": "2026-09-20",
"source": "194382c96a8a5f51ef23f412fdccfbd40a82bf78",
"library_sha256": "046d86c288ce891b16770148578ba1a6fea4057783b69c2359f5830e58b7b223",
"clock_control": "stock-dvfs",
"render_distance": 32,
"simulation_distance": 12,
"warmup_seconds": 180,
"fan_target": 2,
"arms": [
{
"name": "Espryt-monolith",
"mean_fps": 62.178237711677376,
"median_interval_fps": 59.97003214006533,
"p10_interval_fps": 56.94306106612412,
"sample_seconds": 60.020999908447266,
"intervals": 60,
"boot_id": "b19a24d3-bf9d-4c99-a64e-1e70fac40f0f",
"hardware_window": {
"samples": 11,
"all_observed_pins_match": null,
"fixed_clock_evaluation": "not_applicable_stock_dvfs",
"drift_samples": null,
"observed_clock_ranges": {
"policy0_min": {
"min": 556800,
"max": 556800,
"observed_values": [
556800
]
},
"policy0_max": {
"min": 1555200,
"max": 1996800,
"observed_values": [
1555200,
1785600,
1996800
]
},
"policy0_cur": {
"min": 1555200,
"max": 1996800,
"observed_values": [
1555200,
1785600,
1996800
]
},
"policy6_min": {
"min": 1017600,
"max": 1017600,
"observed_values": [
1017600
]
},
"policy6_max": {
"min": 1689600,
"max": 1958400,
"observed_values": [
1689600,
1958400
]
},
"policy6_cur": {
"min": 1689600,
"max": 1958400,
"observed_values": [
1689600,
1958400
]
},
"gpu": {
"min": 525000000,
"max": 660000000,
"observed_values": [
525000000,
607000000,
660000000
]
},
"gpu_min": {
"min": 12,
"max": 12,
"observed_values": [
12
]
},
"gpu_max": {
"min": 0,
"max": 0,
"observed_values": [
0
]
},
"busy": {
"min": 65,
"max": 81,
"observed_values": [
65,
66,
69,
70,
71,
77,
80,
81
]
}
},
"fan_observed_values": {
"fan_rpm": [
"14466",
"14487",
"14570",
"14591"
],
"fan_target": [
"2"
]
},
"temperature_c_min": 53.1,
"temperature_c_max": 55.8,
"sample_elapsed_seconds": [
219.111,
224.585,
230.177,
235.749,
241.223,
246.748,
252.337,
257.904,
263.443,
269.017,
274.616
]
},
"actual_runtime": {
"backend_names": [
"Direct (OpenGL ES)"
],
"ipc_lines": [],
"run_ahead_armed": false,
"caps_call_masks": [],
"run_ahead_cap_bit_seen": false,
"stats_rows": 137,
"residual_pulls_max": 0.0
},
"source_directory": "C:\\Users\\geekerwan\\.codex\\tmp\\rd32-fourway-20260920-stock-fan2-espryt\\Espryt-monolith"
},
{
"name": "Espryt-inproc",
"mean_fps": 64.02439006486937,
"median_interval_fps": 63.0,
"p10_interval_fps": 58.94104917019154,
"sample_seconds": 60.02400016784668,
"intervals": 60,
"boot_id": "ede56fd0-78de-44ec-8f52-125ea4c072b1",
"hardware_window": {
"samples": 11,
"all_observed_pins_match": null,
"fixed_clock_evaluation": "not_applicable_stock_dvfs",
"drift_samples": null,
"observed_clock_ranges": {
"policy0_min": {
"min": 556800,
"max": 556800,
"observed_values": [
556800
]
},
"policy0_max": {
"min": 1555200,
"max": 1785600,
"observed_values": [
1555200,
1785600
]
},
"policy0_cur": {
"min": 1555200,
"max": 1785600,
"observed_values": [
1555200,
1785600
]
},
"policy6_min": {
"min": 1017600,
"max": 1017600,
"observed_values": [
1017600
]
},
"policy6_max": {
"min": 1689600,
"max": 1689600,
"observed_values": [
1689600
]
},
"policy6_cur": {
"min": 1689600,
"max": 1689600,
"observed_values": [
1689600
]
},
"gpu": {
"min": 443000000,
"max": 607000000,
"observed_values": [
443000000,
525000000,
607000000
]
},
"gpu_min": {
"min": 12,
"max": 12,
"observed_values": [
12
]
},
"gpu_max": {
"min": 0,
"max": 0,
"observed_values": [
0
]
},
"busy": {
"min": 68,
"max": 83,
"observed_values": [
68,
73,
77,
78,
79,
83
]
}
},
"fan_observed_values": {
"fan_rpm": [
"14163",
"14262",
"14363"
],
"fan_target": [
"2"
]
},
"temperature_c_min": 53.9,
"temperature_c_max": 56.6,
"sample_elapsed_seconds": [
215.636,
221.183,
226.728,
232.298,
237.875,
243.496,
249.053,
254.657,
260.27,
265.886,
271.475
]
},
"actual_runtime": {
"backend_names": [
"Direct (OpenGL ES)"
],
"ipc_lines": [
"Config: IPC ring=8MiB stage=256MiB spin=50us persistent-block=64KiB adopt-tier=2 verb-barrier=1 run-ahead=1 present-credit=1 strict=1 audit=0 role-split-state=1 affinity='auto'"
],
"run_ahead_armed": true,
"caps_call_masks": [
"0x0",
"0x3fff00000600"
],
"run_ahead_cap_bit_seen": true,
"stats_rows": 137,
"residual_pulls_max": 0.0
},
"source_directory": "C:\\Users\\geekerwan\\.codex\\tmp\\rd32-fourway-20260920-stock\\Espryt-inproc"
},
{
"name": "Magma-monolith",
"mean_fps": 116.07722925432384,
"median_interval_fps": 116.0,
"p10_interval_fps": 114.8736338247419,
"sample_seconds": 60.02900004386902,
"intervals": 60,
"boot_id": "addd73b6-b29a-4f65-a359-7c2a39bb60a0",
"hardware_window": {
"samples": 11,
"all_observed_pins_match": null,
"fixed_clock_evaluation": "not_applicable_stock_dvfs",
"drift_samples": null,
"observed_clock_ranges": {
"policy0_min": {
"min": 556800,
"max": 556800,
"observed_values": [
556800
]
},
"policy0_max": {
"min": 1555200,
"max": 1555200,
"observed_values": [
1555200
]
},
"policy0_cur": {
"min": 1555200,
"max": 1555200,
"observed_values": [
1555200
]
},
"policy6_min": {
"min": 1017600,
"max": 1017600,
"observed_values": [
1017600
]
},
"policy6_max": {
"min": 1689600,
"max": 1689600,
"observed_values": [
1689600
]
},
"policy6_cur": {
"min": 1689600,
"max": 1689600,
"observed_values": [
1689600
]
},
"gpu": {
"min": 832000000,
"max": 900000000,
"observed_values": [
832000000,
900000000
]
},
"gpu_min": {
"min": 12,
"max": 12,
"observed_values": [
12
]
},
"gpu_max": {
"min": 0,
"max": 0,
"observed_values": [
0
]
},
"busy": {
"min": 73,
"max": 78,
"observed_values": [
73,
74,
75,
76,
78
]
}
},
"fan_observed_values": {
"fan_rpm": [
"14163",
"14182",
"14363",
"14384",
"14487"
],
"fan_target": [
"2"
]
},
"temperature_c_min": 55.8,
"temperature_c_max": 56.6,
"sample_elapsed_seconds": [
216.537,
222.12,
227.724,
233.316,
238.927,
244.534,
250.192,
255.859,
261.488,
267.099,
272.72
]
},
"actual_runtime": {
"backend_names": [
"Direct (Vulkan)"
],
"ipc_lines": [],
"run_ahead_armed": false,
"caps_call_masks": [],
"run_ahead_cap_bit_seen": false,
"stats_rows": 251,
"residual_pulls_max": 0.0
},
"source_directory": "C:\\Users\\geekerwan\\.codex\\tmp\\rd32-fourway-20260920-stock\\Magma-monolith"
},
{
"name": "Magma-inproc",
"mean_fps": 86.85293459363007,
"median_interval_fps": 84.5,
"p10_interval_fps": 70.0,
"sample_seconds": 60.021000146865845,
"intervals": 60,
"boot_id": "7627b982-c264-4d2f-a9cb-1ecf40146c9c",
"hardware_window": {
"samples": 11,
"all_observed_pins_match": null,
"fixed_clock_evaluation": "not_applicable_stock_dvfs",
"drift_samples": null,
"observed_clock_ranges": {
"policy0_min": {
"min": 556800,
"max": 556800,
"observed_values": [
556800
]
},
"policy0_max": {
"min": 1555200,
"max": 1996800,
"observed_values": [
1555200,
1996800
]
},
"policy0_cur": {
"min": 1363200,
"max": 1996800,
"observed_values": [
1363200,
1555200,
1785600,
1996800
]
},
"policy6_min": {
"min": 1017600,
"max": 1017600,
"observed_values": [
1017600
]
},
"policy6_max": {
"min": 1689600,
"max": 1958400,
"observed_values": [
1689600,
1958400
]
},
"policy6_cur": {
"min": 1689600,
"max": 1958400,
"observed_values": [
1689600,
1958400
]
},
"gpu": {
"min": 525000000,
"max": 734000000,
"observed_values": [
525000000,
607000000,
660000000,
734000000
]
},
"gpu_min": {
"min": 12,
"max": 12,
"observed_values": [
12
]
},
"gpu_max": {
"min": 0,
"max": 0,
"observed_values": [
0
]
},
"busy": {
"min": 73,
"max": 82,
"observed_values": [
73,
75,
76,
78,
79,
80,
82
]
}
},
"fan_observed_values": {
"fan_rpm": [
"14570",
"14591",
"14697",
"14783",
"14804"
],
"fan_target": [
"2"
]
},
"temperature_c_min": 52.3,
"temperature_c_max": 56.2,
"sample_elapsed_seconds": [
216.05,
221.629,
227.22,
232.809,
238.395,
243.946,
249.485,
255.097,
260.705,
266.288,
271.93
]
},
"actual_runtime": {
"backend_names": [
"Direct (Vulkan)"
],
"ipc_lines": [
"Config: IPC ring=8MiB stage=256MiB spin=50us persistent-block=64KiB adopt-tier=2 verb-barrier=1 run-ahead=1 present-credit=1 strict=1 audit=0 role-split-state=1 affinity='auto'"
],
"run_ahead_armed": true,
"caps_call_masks": [
"0x0",
"0x3fff00000400"
],
"run_ahead_cap_bit_seen": true,
"stats_rows": 183,
"residual_pulls_max": 0.0
},
"source_directory": "C:\\Users\\geekerwan\\.codex\\tmp\\rd32-fourway-20260920-stock\\Magma-inproc"
}
],
"comparisons": [
{
"backend": "Espryt",
"monolith_fps": 62.178237711677376,
"inproc_fps": 64.02439006486937,
"inproc_over_monolith_ratio": 1.0296912942716816,
"scope": "One round of observed sustained stock-DVFS performance; clocks may differ across arms, so this is not isolated architecture overhead."
},
{
"backend": "Magma",
"monolith_fps": 116.07722925432384,
"inproc_fps": 86.85293459363007,
"inproc_over_monolith_ratio": 0.7482340434172177,
"scope": "One round of observed sustained stock-DVFS performance; clocks may differ across arms, so this is not isolated architecture overhead."
}
],
"restoration": {
"world_files": 61,
"world_hashes_match_backup": true,
"config": {
"options.txt": "4d1cd0cb595819d924f8d5823910b643c865f12b3f59b6900abd54b04e2ee646",
"mg_env.txt": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"mg_transport.txt": "1d80cf637af2284a1763196d824b41f6f12bea849aa81f95ab8db0e5ce043c95"
},
"fan_target": "0",
"installed_library_sha256": "046d86c288ce891b16770148578ba1a6fea4057783b69c2359f5830e58b7b223"
}
}
@@ -0,0 +1,85 @@
# Redmi RD32 四组合性能记录
> 本文保留 `194382c9` 的基线。后续 `70fb6689` 已修复 Magma inproc 的缓存退化,
> 同RD32场景实测 inproc **116.73 FPS**、monolith **115.01 FPS**;见 [性能修复报告](magma-rd32-performance-fix.md)。
2026-09-20。用户要求把 Espryt / Magma × monolith / inproc 的 render distance 都设为32,实测一轮。
最终每组合选入一次完整窗口;原始数据、排除项与复算方法均保留。
## 结果
| 组合 | 平均 FPS | 秒区间 FPS 中位数 | 秒区间 FPS P10 | 有效秒数 / 区间数 |
|---|---:|---:|---:|---:|
| Espryt-monolith | 62.18 | 59.97 | 56.94 | 60.021 / 60 |
| Espryt-inproc | 64.02 | 63.00 | 58.94 | 60.024 / 60 |
| Magma-monolith | 116.08 | 116.00 | 114.87 | 60.029 / 60 |
| Magma-inproc | 86.85 | 84.50 | 70.00 | 60.021 / 60 |
这轮 Espryt inproc / monolith 为 **1.030 倍**,小差异不足以确立稳定优势;
Magma inproc / monolith 为 **0.748 倍**,即本轮平均低约 **25.2%**。
Magma monolith 仍在约120 FPS的平台附近,不能据此推断其无上限吞吐。
两种 inproc 均实际 `run-ahead ARMED`;不是把 Magma lockstep 混作 inproc 结果。
这是**单轮默认动态频率下的持续性能观测**,不是隔离出的固定频率架构开销。
不能把差值全部归因于线程拆分,也不能把它与此前 RD12、未统一条件的旧结果作严格倍率比较。
## 共同条件与采样
- Redmi M332BF `2f7cbe2e`;FCL `com.tungsten.fcl.mgdebug.debug`;Minecraft `26.3-rc-3`。
- 同一 APK / MobileGL 行为代码 `194382c96a8a5f51ef23f412fdccfbd40a82bf78`,测试期间未安装新库。
`libMobileGL.so` SHA256:`046d86c288ce891b16770148578ba1a6fea4057783b69c2359f5830e58b7b223`,测试结束仍一致。
APK 身份继承 [run-ahead 报告](magma-runahead.md);后续 Git 提交仅文档。
- `renderDistance:32`、`simulationDistance:12`、`overrideWidth:2620`、`overrideHeight:1280`、
`enableVsync:false`、`maxFps:260`、`inactivityFpsLimit:"minimized"`。F3关闭,FCL FPS计数开启。
测前/测后 options 均保留,并核对关键值。
- 原世界完整保留,在副本上固定初始相机、晴天和正午,关闭时间/天气推进与新生物生成;
每组恢复同一个副本快照,不依赖 force-stop 阻止自动保存。既有生物模拟仍保留。
- 每组独立重启,`cpuss-0-0` 入场低于40°C,进入世界后预热180秒,再独立采样至少60秒。
所选四组有四个不同 boot-id,八张 pre-window/final 图均人工检查;场景、方向与HUD正常。
- 所选四组测量窗所有硬件观测均为风扇档位2、RPM>0。CPU/GPU由系统DVFS与温控管理,
没有关闭温控。每约5秒记录频率、温度、GPU busy与风扇状态。
- FCL `getFps()` 返回的是自上次读取的 swap 计数。以同PID相邻 `FCLFPS` 日志的真实时间差归一化,
只保留完整落在测量窗内的区间;平均为总帧数/总时间。P10与中位数是这些约一秒区间的FPS分位,
**不是逐帧1% low**。MGPipe的120帧窗口计数仅作近似交叉核对,不作为主结果。
- 每组实际 backend/transport、capability 与 `rsp=0` 均核查。inproc使用strict=1、role-split=1、
stage=256 MiB、present credit=1;monolith实际无IPC配置、`vbs=0`。
## 测量窗硬件观测
| 组合 | CPU温度 °C | 大核实际频率 GHz | GPU实际频率 MHz | 风扇 RPM |
|---|---:|---:|---:|---:|
| Espryt-monolith | 53.1–55.8 | 1.690–1.958 | 525–660 | 14466–14591 |
| Espryt-inproc | 53.9–56.6 | 1.690–1.690 | 443–607 | 14163–14363 |
| Magma-monolith | 55.8–56.6 | 1.690–1.690 | 832–900 | 14163–14487 |
| Magma-inproc | 52.3–56.2 | 1.690–1.958 | 525–734 | 14570–14804 |
表中为有限采样点的范围,不表示采样间绝无变化。部分截图有读取硬件状态时产生的
Shell root toast;所有组使用相同遥测方式,未把它当作游戏图形错误。
Magma monolith的屏幕缺口留白在右侧,其余组在左侧;前后图方向一致,游戏视口均为2620×1280。
## 排除与恢复
最初按历史档案尝试固定频率:1100 MHz被厂商限到1050,1050持续负载又降到900,
900尝试则在正式窗口开始后发现大核被温控从1958.4改到1689.6 MHz。这些尝试均作废,
不进入表格,也没有通过关闭保护来强行维持频率。
第一份 stock Espryt monolith 结果为59.884 FPS,但窗口风扇全程为0/RPM0;它保留为排除控制。
补测的fan2结果62.178 FPS替代它,未合并、未平均或挑选多个有效窗口中的最好者。
其他三组原始窗口直接选入。选择映射与原因保存在 `selection.json`。
结束后原世界61个文件逐一SHA256核对完全一致;options.txt、mg_env.txt、mg_transport.txt
逐字节恢复(包括原RD12设置),风扇恢复0。临时设备世界副本已清理,主机证据保留。
既有Gradle修改与父FCL未合并索引未改动;本轮没有改渲染代码。
## 证据
最终选入证据:`C:/Users/geekerwan/.codex/tmp/rd32-fourway-20260920-final/`,包括:
- `performance.json`:从原始日志重算的完整区间、硬件观测与运行模式检查;
- `root-signoff.json`、`restoration-verified.json`、`fixture-hashes.json`:验图与真实恢复核验;
- `selection.json` 与四组原始summary、完整library/logcat、before/after截图;
- 原采样脚本在 `../rd32-fourway-20260920-stock/benchmark.py`;补测在
`../rd32-fourway-20260920-stock-fan2-espryt/benchmark.py`;离线分析器在
`../rd32-fourway-20260920-1050/analyze.py`,支持 `--root <目录> --require-complete`。
仓库内精简机读数据见 [rd32-fourway.json](rd32-fourway.json)。
+220
View File
@@ -0,0 +1,220 @@
#!/usr/bin/env python3
"""Run exactly seven CTest-discovered Magma cache cases under Vulkan sync validation.
Preparation is inert: --execute is required before discovery, log deletion or tests.
Run only while other host GPU lanes that share these private logs are idle.
This script does not build, modify source, or operate a device.
"""
from __future__ import annotations
import argparse
import copy
import hashlib
import importlib.util
import json
from pathlib import Path
import subprocess
import sys
import xml.etree.ElementTree as ET
CASES = (
"SamplerSwizzleAtoBtoAKeepsEachQueuedPixel",
"SamplerRespecifyKeepsOldAndNewNativeImages",
"SamplerViewsDistinguishMipLayerAndViewType",
"FramebuffersAtoBtoAKeepDistinctAttachments",
"FramebufferReattachmentDistinguishesMipAndLayer",
"FramebufferSrgbPolicyAtoBtoAUsesDistinctFormats",
"FramebufferRespecifyRebindsTheNewNativeImage",
)
PREFIX = "DirectVulkan.Split.Caches."
REQUIRED = {PREFIX + "MagmaWireCacheScenario." + name for name in CASES}
SETTINGS = {
"VK_INSTANCE_LAYERS": "VK_LAYER_KHRONOS_validation",
"VK_LAYER_ENABLES": "VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT",
"VK_LOADER_DEBUG": "layer",
}
REQUIRED_ENV = {
"MOBILEGL_BACKEND_TYPE": "DirectVulkan",
"MOBILEGL_TRANSPORT": "inproc",
"MOBILEGL_IPC_ROLE_SPLIT_STATE": "1",
"MOBILEGL_IPC_STRICT_ERRORS": "1",
"MOBILEGL_IPC_RUN_AHEAD": "1",
"MOBILEGL_IPC_PRESENT_CREDIT": "3",
"MGITEST_MAGMA_CACHES_LANE": "1",
"MGITEST_SPLIT_LANE": "1",
"MOBILEGL_ITEST_REQUIRE_GPU": "1",
}
def sha256(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def write_json(path, value):
path.write_text(json.dumps(value, ensure_ascii=False, indent=2), encoding="utf-8")
def load_checker(source):
path = source / "scripts/ci/magma_runahead_checks.py"
spec = importlib.util.spec_from_file_location("magma_shared_checker", path)
if spec is None or spec.loader is None:
raise RuntimeError(f"cannot import repository checker: {path}")
checker = importlib.util.module_from_spec(spec)
spec.loader.exec_module(checker)
return checker, path
def discover(build, out, checker):
result = subprocess.run(
["ctest", "--test-dir", str(build), "-L", "^integration-magma-caches$",
"--show-only=json-v1"], capture_output=True, text=True, timeout=60)
(out / "discovery.json").write_text(result.stdout, encoding="utf-8")
(out / "discovery.stderr.txt").write_text(result.stderr, encoding="utf-8")
if result.returncode:
raise RuntimeError(f"CTest discovery returned {result.returncode}")
rows = json.loads(result.stdout)["tests"]
tests = {test["name"]: test for test in rows}
if len(rows) != 7 or len(tests) != 7 or set(tests) != REQUIRED:
raise RuntimeError(f"exact-seven discovery mismatch: missing={sorted(REQUIRED-set(tests))}, "
f"extra={sorted(set(tests)-REQUIRED)}, rows={len(rows)}")
executables = {}
private_logs = set()
for name, test in tests.items():
command, declared, cwd, _ = checker.recipe(test)
wrong = {key: declared.get(key) for key, expected in REQUIRED_ENV.items()
if declared.get(key) != expected}
if wrong:
raise RuntimeError(f"{name}: required strict cache environment changed: {wrong}")
private = Path(declared["MOBILEGL_LOG_FILE_PATH"])
private = (cwd / private).resolve() if not private.is_absolute() else private.resolve()
if not private.is_relative_to(build) or private in private_logs:
raise RuntimeError(f"private library log is not unique and inside the build: {private}")
private_logs.add(private)
executable = Path(command[0]).resolve(strict=True)
executables[str(executable)] = sha256(executable)
if len(executables) != 1:
raise RuntimeError(f"cache cases do not share one executable: {list(executables)}")
return tests, executables
def inspect_exact_case(directory, expected):
# The repository's inspect() intentionally admits only its run-ahead cases.
# Preserve the same no-skip/execution checks with this lane's exact identity.
document = ET.parse(directory / "gtest.xml").getroot()
cases = document.findall(".//testcase")
if len(cases) != 1:
raise RuntimeError(f"expected exactly one testcase, found {len(cases)}")
case = cases[0]
actual = f"{case.get('classname')}.{case.get('name')}"
if actual != expected.removeprefix(PREFIX):
raise RuntimeError(f"executed testcase {actual!r} does not match {expected!r}")
return case
def validate(tests, build, out, checker, executable_hashes):
outcomes = []
junit = ET.Element("testsuite", name="MagmaWireCacheSynchronizationValidation")
for name in sorted(REQUIRED):
directory = out / name
result = {"ctest_name": name, "verdict": "FAILED_CHECK"}
copied = None
try:
# Shared code uses the discovered argv/ENVIRONMENT/WORKING_DIRECTORY,
# applies overrides AFTER CTest's values, and saves executable SHA,
# effective recipe, raw XML, merged stdout/stderr, and private log.
result.update(checker.run_case(tests[name], build, directory, SETTINGS))
stdout = (directory / "stdout.txt").read_text(encoding="utf-8", errors="replace")
private = (directory / "private.log").read_text(encoding="utf-8", errors="replace")
validation, application = checker.split_diagnostics(stdout, private)
(directory / "validation-errors.txt").write_text("\n".join(validation), encoding="utf-8")
(directory / "application-errors.txt").write_text("\n".join(application), encoding="utf-8")
result.update(validation_error_lines=len(validation), application_error_lines=len(application),
layer_inserted=bool(checker.LAYER.search(stdout + "\n" + private)))
# Application ERROR diagnostics (including the existing stencil caps
# messages) are retained separately by the repository classifier.
# Embedded validation/VUID/SYNC-HAZARD and loader ERROR remain fatal.
case = inspect_exact_case(directory, name)
copied = copy.deepcopy(case)
copied.set("name", name)
junit.append(copied)
skipped = (case.find("skipped") is not None or case.get("status") != "run" or
case.get("result") != "completed")
result["testcase_completed_without_skip"] = not skipped
if skipped:
raise RuntimeError("selected cache testcase skipped or did not complete")
if result["returncode"] or case.find("failure") is not None or case.find("error") is not None:
raise RuntimeError("cache testcase did not pass with process exit zero")
if not result["private_log_present"]:
raise RuntimeError("actual private library log is missing")
if not result["layer_inserted"]:
raise RuntimeError("loader output does not prove Khronos validation-layer insertion")
if validation:
raise RuntimeError("VUID / synchronization hazard / validation or loader error found")
recipe = json.loads((directory / "recipe.json").read_text(encoding="utf-8"))
executable = str(Path(recipe["command"][0]).resolve(strict=True))
if recipe["executable_sha256"] != executable_hashes[executable]:
raise RuntimeError("test executable changed since discovery")
result["verdict"] = "GREEN"
except (RuntimeError, OSError, ValueError, KeyError, ET.ParseError) as exc:
result.update(verdict="FAILED_CHECK", error=str(exc))
if copied is None:
copied = ET.SubElement(junit, "testcase", name=name)
ET.SubElement(copied, "failure", message=str(exc))
outcomes.append(result)
junit.set("tests", str(len(outcomes)))
junit.set("failures", str(sum(row["verdict"] != "GREEN" for row in outcomes)))
junit.set("skipped", str(sum(case.find("skipped") is not None for case in junit)))
write_json(out / "summary.json", outcomes)
ET.ElementTree(junit).write(out / "aggregate-gtest.xml", encoding="utf-8", xml_declaration=True)
print(f"{name}: process_rc={result.get('returncode')} verdict={result['verdict']}", flush=True)
unchanged = all(sha256(Path(path)) == digest for path, digest in executable_hashes.items())
complete = len(outcomes) == 7 and {row["ctest_name"] for row in outcomes} == REQUIRED
green = complete and unchanged and all(row["verdict"] == "GREEN" for row in outcomes)
write_json(out / "totals.json", {
"verdict": "GREEN" if green else "FAILED_CHECK", "complete_exact_seven": complete,
"passed": sum(row["verdict"] == "GREEN" for row in outcomes),
"failed": sum(row["verdict"] != "GREEN" for row in outcomes),
"layer_inserted_cases": sum(row.get("layer_inserted", False) for row in outcomes),
"validation_error_lines": sum(row.get("validation_error_lines", 0) for row in outcomes),
"application_error_lines": sum(row.get("application_error_lines", 0) for row in outcomes),
"executables_unchanged_after_all_cases": unchanged,
})
return 0 if green else 1
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source-root", type=Path, default=Path(__file__).resolve().parents[2])
parser.add_argument("--build-dir", type=Path, help="defaults to source-root/build-split")
parser.add_argument("--out", type=Path, required=True, help="new evidence directory; existing paths are refused")
parser.add_argument("--execute", action="store_true", help="run serially after other GPU lanes are idle")
args = parser.parse_args()
if not args.execute:
print("Prepared only. Add --execute after other host GPU lanes are idle; nothing was discovered or run.")
return 0
source = args.source_root.resolve(strict=True)
build = (args.build_dir or source / "build-split").resolve(strict=True)
out = args.out.resolve()
out.mkdir(parents=True, exist_ok=False)
try:
checker, checker_path = load_checker(source)
tests, executable_hashes = discover(build, out, checker)
head = subprocess.check_output(["git", "-C", str(source), "rev-parse", "HEAD"], text=True).strip()
write_json(out / "runner-identity.json", {
"source_root": str(source), "source_head_at_start": head, "build_dir": str(build),
"shared_checker": str(checker_path), "shared_checker_sha256": sha256(checker_path),
"runner": str(Path(__file__).resolve()), "runner_sha256": sha256(Path(__file__)),
"executable_sha256_by_path": executable_hashes, "validation_overrides": SETTINGS,
"required_cases": sorted(REQUIRED),
})
return validate(tests, build, out, checker, executable_hashes)
except (RuntimeError, OSError, ValueError, KeyError, ET.ParseError, subprocess.TimeoutExpired,
subprocess.CalledProcessError) as exc:
(out / "runner-error.txt").write_text(str(exc), encoding="utf-8")
print(f"FAILED: {exc}", file=sys.stderr)
return 1
if __name__ == "__main__":
sys.exit(main())
+252
View File
@@ -0,0 +1,252 @@
#!/usr/bin/env python3
"""Run CTest-discovered Magma negative controls or synchronization validation.
No build, source edit, commit, device operation or synthetic sequence change.
--execute is required because these tests share their CTest private log paths.
Each fresh process uses the discovered argv, ENVIRONMENT and WORKING_DIRECTORY.
Only RUN_AHEAD changes for the negative control (plus a gtest XML output argument).
"""
from __future__ import annotations
import argparse
import copy
import hashlib
import json
import os
from pathlib import Path
import re
import subprocess
import sys
import time
import xml.etree.ElementTree as ET
CASES = (
"QueuedBufferVersionsAndDeletedNameReuseKeepTheirPixels",
"QueuedProgramRebindsKeepEachUniformSnapshot",
"QueuedGpuWritesReadBackTheLastDispatchBytes",
"MixedNativeAndConvertedGpuVertexStreamsKeepTheirReservation",
"TextureUploadCannotOvertakeThePreviouslyQueuedDraw",
"GpuClearSurvivesTheFirstStorageImageUpgrade",
"PresentCreditActuallyParksTheClientAtItsConfiguredLimit",
)
PREFIX = "DirectVulkan.Split.RunAhead.Credit"
REQUIRED = {f"{PREFIX}{credit}.MagmaRunAheadScenario.{name}" for credit in (1, 3) for name in CASES}
NEGATIVE = f"{PREFIX}1.MagmaRunAheadScenario.QueuedProgramRebindsKeepEachUniformSnapshot"
CLEAR_ASSERTION = "the clear waited for apply instead of returning while its server batch was held"
ERROR = re.compile(r"VUID-[A-Za-z0-9_-]+|SYNC-HAZARD-[A-Z_]+|Validation Error|\bERROR\b", re.I)
LAYER = re.compile(r'Insert instance layer\s+["\']?VK_LAYER_KHRONOS_validation', re.I)
# MobileGL's own diagnostics are not Vulkan-layer messages. Keep them visible
# separately; an embedded validation/VUID/hazard message is never classified away.
APPLICATION_ERROR = re.compile(r"^\[\d{2}:\d{2}:\d{2}(?:\.\d+)?\] \[(?:Linux|Android|Windows|macOS)[^\]]*/ERROR\]:")
VALIDATION_MARKER = re.compile(r"VUID-|SYNC-HAZARD|\bvalidation\b", re.I)
def split_diagnostics(stdout, private):
validation, application = [], []
for line in (stdout + "\n" + private).splitlines():
if not ERROR.search(line):
continue
if APPLICATION_ERROR.search(line) and not VALIDATION_MARKER.search(line):
application.append(line)
else:
validation.append(line)
return validation, application
def write_json(path, data):
path.write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")
def discover(build, out):
run = subprocess.run(["ctest", "--test-dir", str(build), "-L", "integration-magma-runahead",
"--show-only=json-v1"], capture_output=True, text=True, timeout=60)
(out / "discovery.stderr.txt").write_text(run.stderr, encoding="utf-8")
if run.returncode:
raise RuntimeError(f"CTest discovery failed: {run.returncode}")
(out / "discovery.json").write_text(run.stdout, encoding="utf-8")
document = json.loads(run.stdout)
tests = {test["name"]: test for test in document["tests"]}
if len(document["tests"]) != len(tests) or set(tests) != REQUIRED:
raise RuntimeError(f"discovery mismatch: missing={sorted(REQUIRED-set(tests))}, extra={sorted(set(tests)-REQUIRED)}")
return tests
def recipe(test):
props = {p["name"]: p["value"] for p in test["properties"]}
if props.get("ENVIRONMENT_MODIFICATION"):
raise RuntimeError("ENVIRONMENT_MODIFICATION must be interpreted explicitly before using this runner")
declared = {}
for entry in props["ENVIRONMENT"]:
key, value = entry.split("=", 1)
declared[key] = value
cwd = Path(props["WORKING_DIRECTORY"]).resolve(strict=True)
command = list(test["command"])
if not command or not Path(command[0]).is_file():
raise RuntimeError("discovered test executable does not exist")
if declared.get("MOBILEGL_IPC_RUN_AHEAD") != "1":
raise RuntimeError("the discovered lane no longer declares RUN_AHEAD=1")
return command, declared, cwd, float(props.get("TIMEOUT", 120))
def run_case(test, build, directory, overrides):
directory.mkdir()
command, declared, cwd, timeout = recipe(test)
env = os.environ.copy()
env.update(declared)
env.update(overrides) # Deliberately AFTER CTest ENVIRONMENT, which otherwise wins.
private = Path(env["MOBILEGL_LOG_FILE_PATH"])
private = (cwd / private).resolve() if not private.is_absolute() else private.resolve()
if not private.is_relative_to(build):
raise RuntimeError(f"refusing to reset a private log outside the selected build: {private}")
private.unlink(missing_ok=True)
xml = directory / "gtest.xml"
command = [arg for arg in command if not arg.startswith("--gtest_output=")]
command.append(f"--gtest_output=xml:{xml}")
visible_env = {key: value for key, value in env.items() if key.startswith(
("MOBILEGL_", "MGITEST_", "VK_", "EGL_", "__EGL_", "GTEST_")) or key == "LD_LIBRARY_PATH"}
write_json(directory / "recipe.json", {
"ctest_name": test["name"], "command": command, "working_directory": str(cwd),
"ctest_environment": declared, "overrides": overrides, "effective_graphics_environment": visible_env,
"private_log": str(private), "timeout_seconds": timeout,
"executable_sha256": hashlib.sha256(Path(command[0]).read_bytes()).hexdigest(),
})
started = time.monotonic()
with (directory / "stdout.txt").open("w", encoding="utf-8") as output:
try:
run = subprocess.run(command, cwd=cwd, env=env, stdout=output, stderr=subprocess.STDOUT,
text=True, timeout=timeout)
rc = run.returncode
except subprocess.TimeoutExpired:
rc = 124
output.write("\nRUNNER_TIMEOUT: process killed after discovered CTest timeout\n")
private_text = private.read_text(encoding="utf-8", errors="replace") if private.is_file() else ""
(directory / "private.log").write_text(private_text, encoding="utf-8")
result = {"ctest_name": test["name"], "returncode": rc,
"seconds": round(time.monotonic()-started, 3), "private_log_present": private.is_file()}
write_json(directory / "process.json", result)
return result
def inspect(directory):
root = ET.parse(directory / "gtest.xml").getroot()
cases = root.findall(".//testcase")
if len(cases) != 1:
raise RuntimeError(f"expected exactly one executed testcase, observed {len(cases)}")
case = cases[0]
name = f"{case.get('classname')}.{case.get('name')}"
if name not in {f"MagmaRunAheadScenario.{s}" for s in CASES}:
raise RuntimeError(f"unexpected testcase {name}")
if case.find("skipped") is not None or case.get("status") != "run" or case.get("result") != "completed":
raise RuntimeError("selected testcase skipped or did not execute")
failed = case.find("failure") is not None or case.find("error") is not None
stdout = (directory / "stdout.txt").read_text(encoding="utf-8", errors="replace")
private = (directory / "private.log").read_text(encoding="utf-8", errors="replace")
return case, failed, stdout, private
def negative(tests, build, out):
outcomes = []
# Always restore the green arm even if the red assertion check does not match.
for arm, value in (("run_ahead_0", "0"), ("restored_run_ahead_1", "1")):
directory = out / arm
result = run_case(tests[NEGATIVE], build, directory, {"MOBILEGL_IPC_RUN_AHEAD": value})
try:
case, failed, stdout, private = inspect(directory)
if f"{case.get('classname')}.{case.get('name')}" != "MagmaRunAheadScenario.QueuedProgramRebindsKeepEachUniformSnapshot":
raise RuntimeError("the named program-rebind case did not run")
if not result["private_log_present"]:
raise RuntimeError("missing actual private library log")
if not re.search(r"Config: IPC [^\n]*run-ahead=" + value + r"\b", private):
raise RuntimeError("private log does not prove the requested runtime knob")
if value == "0":
# Accept either scheduling point, but only from this exact failed
# testcase's XML failures. A bare ARMED/cap failure is insufficient.
failure_text = "\n".join(node.get("message", "") + " " + " ".join(node.itertext())
for tag in ("failure", "error") for node in case.findall(tag))
clear_wait = CLEAR_ASSERTION in failure_text
queue_wait = ("client waited for apply instead of running ahead" in failure_text and
"no real client lead over the apply watermark" in failure_text)
if result["returncode"] == 0 or not failed or not (clear_wait or queue_wait):
raise RuntimeError("negative arm did not fail on real held-apply waiting and lost queue lead")
result["control_failure"] = "clear_wait" if clear_wait else "client_wait_and_no_apply_lead"
elif result["returncode"] != 0 or failed:
raise RuntimeError("restored arm did not pass")
result["verdict"] = "EXPECTED_RED" if value == "0" else "GREEN"
except (RuntimeError, OSError, ET.ParseError) as exc:
result.update(verdict="FAILED_CHECK", error=str(exc))
outcomes.append(result)
write_json(out / "summary.json", outcomes)
print(f"{arm}: process_rc={result['returncode']} verdict={result['verdict']}", flush=True)
return 0 if [r["verdict"] for r in outcomes] == ["EXPECTED_RED", "GREEN"] else 1
def validation(tests, build, out):
outcomes = []
junit = ET.Element("testsuite", name="MagmaRunAheadSynchronizationValidation")
settings = {
"VK_INSTANCE_LAYERS": "VK_LAYER_KHRONOS_validation",
"VK_LAYER_ENABLES": "VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT",
# Loader diagnostics prove the layer was inserted, rather than merely installed.
"VK_LOADER_DEBUG": "layer",
}
for name in sorted(tests):
directory = out / name
result = run_case(tests[name], build, directory, settings)
copied = None
try:
case, failed, stdout, private = inspect(directory)
if f"{case.get('classname')}.{case.get('name')}" != name.split(".", 4)[-1]:
raise RuntimeError("executed testcase does not match its discovered entry")
copied = copy.deepcopy(case)
copied.set("name", name) # Raw gtest.xml remains unchanged beside this aggregate.
junit.append(copied)
lines, application_lines = split_diagnostics(stdout, private)
(directory / "validation-errors.txt").write_text("\n".join(lines), encoding="utf-8")
(directory / "application-errors.txt").write_text("\n".join(application_lines), encoding="utf-8")
result.update(validation_error_lines=len(lines), application_error_lines=len(application_lines),
layer_inserted=bool(LAYER.search(stdout + private)))
if result["returncode"] or failed or not result["private_log_present"]:
raise RuntimeError("GPU case did not complete with a passing result and actual private log")
if not result["layer_inserted"]:
raise RuntimeError("loader output does not prove validation-layer insertion")
if lines:
raise RuntimeError("VUID / synchronization hazard / error output found; see validation-errors.txt")
result["verdict"] = "GREEN"
except (RuntimeError, OSError, ET.ParseError) as exc:
result.update(verdict="FAILED_CHECK", error=str(exc))
if copied is None:
copied = ET.SubElement(junit, "testcase", name=name)
ET.SubElement(copied, "failure", message=str(exc))
outcomes.append(result)
junit.set("tests", str(len(outcomes)))
junit.set("failures", str(sum(r["verdict"] != "GREEN" for r in outcomes)))
write_json(out / "summary.json", outcomes)
ET.ElementTree(junit).write(out / "aggregate-gtest.xml", encoding="utf-8", xml_declaration=True)
print(f"{name}: process_rc={result['returncode']} verdict={result['verdict']}", flush=True)
return 0 if len(outcomes) == 14 and all(r["verdict"] == "GREEN" for r in outcomes) else 1
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("mode", choices=("negative", "validation"))
parser.add_argument("--build-dir", type=Path, default=Path("build-split"))
parser.add_argument("--out", type=Path, required=True)
parser.add_argument("--execute", action="store_true", help="execute serially with other GPU lanes that share private logs")
args = parser.parse_args()
if not args.execute:
print("Add --execute with other GPU lanes idle; no discovery or tests were run")
return 0
build = args.build_dir.resolve(strict=True)
out = args.out.resolve()
out.mkdir(parents=True, exist_ok=False)
try:
tests = discover(build, out)
return negative(tests, build, out) if args.mode == "negative" else validation(tests, build, out)
except (RuntimeError, OSError, ValueError, subprocess.TimeoutExpired) as exc:
(out / "runner-error.txt").write_text(str(exc), encoding="utf-8")
print(f"FAILED: {exc}", file=sys.stderr)
return 1
if __name__ == "__main__":
sys.exit(main())
@@ -0,0 +1,42 @@
# Magma run-ahead FCL check
This runner targets only Redmi `2f7cbe2e`, package
`com.tungsten.fcl.mgdebug.debug`, Minecraft `26.3-rc-3`, existing world `test`.
It expects the launcher to Quick Play that world. The existing GLES renderer entry
reads `mg_env.txt`; use it with the explicit backend override. The launcher's built-in
Magma entry may select monolith without reading this override.
Build/install one FCL APK containing the current disaggregated/PUSH MobileGL library.
Archive its source revision and SHA256, including the packaged and installed
`libMobileGL.so`. Back up `/sdcard/FCL/mg_env.txt`, `mg_transport.txt` and the world
before running. After any reboot, wait for shared game storage as well as boot
completion. `ADB_BIN` can select the host adb executable; every call pins the serial.
Run each arm serially with a fresh evidence directory:
```sh
python run_fcl_arm.py --backend DirectVulkan --transport inproc --run-ahead 1 --out magma-on
python run_fcl_arm.py --backend DirectVulkan --transport inproc --run-ahead 0 --out magma-off
python run_fcl_arm.py --backend DirectGLES --transport inproc --run-ahead 1 --out gles-on
```
The runner requires fresh world logs, the actual runtime backend/capability,
strict role split, zero residual pulls, progressing frames, and at least 60 seconds
without crash/restart. Its success remains **pending screenshot review**: inspect
`in-world.png` and `final.png` for world/UI rendering and orientation. Save and quit
the world before starting the next arm. Restore the two original configuration
files and verify their hashes when finished; the runner intentionally leaves the
app available for inspection and does not restore configuration itself.
FPS derived from polled frame counters is approximate and includes warm-up. Without
fixed clocks, camera, weather, and workload this is a correctness run, not a benchmark.
The host lane proves actual client lead over held apply and present-credit blocking:
```sh
ctest --test-dir build-split -L integration-magma-runahead --no-tests=error
python scripts/ci/magma_runahead_checks.py negative --out negative --execute
python scripts/ci/magma_runahead_checks.py validation --out syncval --execute
```
Run these host lanes serially because they share private logs. Validation requires
the Khronos layer and proves loader insertion as well as checking VUIDs and hazards.
@@ -0,0 +1,281 @@
#!/usr/bin/env python3
"""One FCL arm on Redmi 2f7cbe2e; root coordinates backup/reboot beforehand.
No logcat clear, clock pin, APK install, or global-setting change. The app is left
in its final state for inspection. Only mg_env.txt, mg_transport.txt and the new
library log are written on the device. All subprocess calls use argv lists.
The 180-second deadline includes the required 60-second stable in-world window.
"""
from __future__ import annotations
import argparse
import hashlib
import json
import os
import re
import shutil
import subprocess
import sys
import time
from datetime import datetime, timezone
from pathlib import Path
ADB = Path(os.environ.get("ADB_BIN") or shutil.which("adb") or "adb")
SERIAL = "2f7cbe2e"
PACKAGE = "com.tungsten.fcl.mgdebug.debug"
ACTIVITY = PACKAGE + "/com.tungsten.fcl.activity.SplashActivity"
LATEST = "/sdcard/FCL/.minecraft/versions/26.3-rc-3/logs/latest.log"
POLL_SECONDS, DEADLINE_SECONDS, STABLE_SECONDS = 5, 180, 60
FATAL = re.compile(r"Fatal\{|Fatal signal|FATAL EXCEPTION|SIGSEGV|SIGABRT|Abort message", re.I)
WORLD = re.compile(r"joined the game|logged in with entity id|Loaded \d+ advancements", re.I)
BACKEND_NAMES = {"DirectGLES": "Direct (OpenGL ES)", "DirectVulkan": "Direct (Vulkan)"}
def redact(text: str) -> str:
# Keep complete diagnostic logs locally without retaining game credential arguments.
text = re.sub(r'(?i)(--(?:accessToken|clientToken|refreshToken|idToken)\s+)("[^"]*"|\S+)', r'\1<redacted>', text)
text = re.sub(r'(?i)((?:accessToken|clientToken|refreshToken|idToken)["\s]*[:=]\s*["\s]*)([^"\s,}]+)', r'\1<redacted>', text)
return re.sub(r'(?i)(Authorization\s*[:=]\s*Bearer\s+)\S+', r'\1<redacted>', text)
def decode(data: bytes | None) -> str:
return (data or b"").decode("utf-8", errors="replace").replace("\r\n", "\n")
class Arm:
def __init__(self, args: argparse.Namespace):
self.args, self.out = args, args.out.resolve()
self.out.mkdir(parents=True, exist_ok=False)
tag = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S%fZ")
self.remote_log = f"/sdcard/FCL/p5f-fcl-{tag}-{args.backend}-{args.transport}.log"
self.start = time.monotonic()
self.log_since = ""
self.library = self.latest = self.logcat = ""
self.known_pids: set[str] = set()
self.summary = {
"backend": args.backend, "transport": args.transport, "run_ahead": args.run_ahead,
"serial": SERIAL, "package": PACKAGE, "game_version": "26.3-rc-3",
"world": "test", "remote_library_log": self.remote_log,
"deadline_seconds": DEADLINE_SECONDS, "stable_seconds_required": STABLE_SECONDS,
"status": "preparing", "screenshot_review_required": True,
}
def save(self, name: str, text: str) -> None:
(self.out / name).write_text(redact(text), encoding="utf-8")
def event(self, kind: str, **fields) -> None:
record = {"utc": datetime.now(timezone.utc).isoformat(), "elapsed": round(time.monotonic() - self.start, 3), "kind": kind, **fields}
with (self.out / "lifecycle.jsonl").open("a", encoding="utf-8") as f:
f.write(json.dumps(record, ensure_ascii=False) + "\n")
def adb(self, *args: str, required: bool = False, timeout: int = 15) -> subprocess.CompletedProcess:
argv = [str(ADB), "-s", SERIAL, *args]
try:
result = subprocess.run(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout)
except subprocess.TimeoutExpired as exc:
result = subprocess.CompletedProcess(argv, 124, exc.stdout or b"", exc.stderr or b"")
self.event("adb", argv=argv[3:], returncode=result.returncode)
if required and result.returncode:
self.save("last-adb-error.txt", decode(result.stdout) + decode(result.stderr))
raise RuntimeError(f"adb command failed (rc={result.returncode}); see last-adb-error.txt")
return result
def remote_text(self, path: str) -> str | None:
result = self.adb("exec-out", "cat", path)
return decode(result.stdout) if result.returncode == 0 else None
def pids(self) -> set[str]:
result = self.adb("shell", "pidof", PACKAGE)
found = set(re.findall(r"\b\d+\b", decode(result.stdout))) if result.returncode == 0 else set()
self.known_pids.update(found)
return found
def screenshot(self, name: str) -> None:
result = self.adb("exec-out", "screencap", "-p")
if result.returncode == 0 and result.stdout.startswith(b"\x89PNG\r\n\x1a\n"):
(self.out / name).write_bytes(result.stdout)
else:
self.save(name + ".error.txt", decode(result.stderr) or "No valid PNG returned")
def collect(self, final: bool = False) -> None:
for path, attr, filename in ((self.remote_log, "library", "library.log"), (LATEST, "latest", "latest.log")):
data = self.remote_text(path)
if data is not None:
setattr(self, attr, data)
self.save(filename, data)
if self.log_since:
result = self.adb("logcat", "-d", "-v", "epoch", "-T", self.log_since,
"-b", "main", "-b", "system", "-b", "crash",
"MobileGL:V", "FCLFPS:I", "AndroidRuntime:E", "libc:E", "DEBUG:E", "ActivityManager:I", "*:S")
if result.returncode == 0:
self.logcat = decode(result.stdout)
self.save("logcat-window.txt", self.logcat)
if final:
self.screenshot("final.png")
result = self.adb("logcat", "-d", "-v", "epoch", "-T", self.log_since or "1", "-b", "crash")
self.save("crash-window.txt", decode(result.stdout) + decode(result.stderr))
def stats(self) -> list[dict]:
result = []
for line in self.library.splitlines():
if "MGPipe stats:" not in line or not re.search(r"\bframes=\d+", line):
continue
values = dict(re.findall(r"\b(frames|window|draws|draws/f|rsp|vbs)=([0-9.]+)", line))
if values:
result.append({key: float(value) if "." in value else int(value) for key, value in values.items()})
return result
def runtime(self, stats: list[dict]) -> tuple[bool, bool, str | None]:
names = re.findall(r"Backend Name:\s*([^\r\n]+)", self.library)
expected = BACKEND_NAMES[self.args.backend]
if names and any(name.strip() != expected for name in names):
return False, False, "backend_mismatch"
backend_ok = bool(names)
ipc = re.findall(r"Config: IPC [^\r\n]+", self.library)
if self.args.transport == "inproc":
if ipc and not all("strict=1" in line and "role-split-state=1" in line for line in ipc):
return backend_ok, False, "ipc_configuration_mismatch"
expected_knob = "run-ahead=" + str(self.args.run_ahead)
capability_ok = ("run-ahead ARMED" in self.library) if self.args.run_ahead else (
"run-ahead ARMED" not in self.library and any(expected_knob in line for line in ipc))
ipc_ok = bool(ipc) and capability_ok and any(row.get("vbs", 0) > 0 for row in stats)
else:
if ipc or any(row.get("vbs", 0) != 0 for row in stats):
return backend_ok, False, "monolith_control_used_transport"
ipc_ok = bool(stats) and all("vbs" in row for row in stats)
if any(row.get("rsp", 0) != 0 for row in stats):
return backend_ok, ipc_ok, "nonzero_residual_pull"
return backend_ok, ipc_ok, None
def run(self) -> int:
status, reason = "FAILED", "not_started"
world_at = None
world_frame = 0
stable_pids: set[str] = set()
seen_process, missing_polls = False, 0
try:
if not ADB.is_file():
raise RuntimeError("Expected Windows adb executable is missing")
self.adb("get-state", required=True)
self.save("boot-id.txt", decode(self.adb("shell", "cat", "/proc/sys/kernel/random/boot_id", required=True).stdout))
before = self.remote_text(LATEST) or ""
before_hash = hashlib.sha256(before.encode()).hexdigest()
self.save("latest.before.log", before)
self.event("pid_before", pids=sorted(self.pids()))
env = {
"MOBILEGL_BACKEND_TYPE": self.args.backend,
"MOBILEGL_TRANSPORT": self.args.transport,
"MOBILEGL_IPC_ROLE_SPLIT_STATE": "1" if self.args.transport == "inproc" else "0",
"MOBILEGL_IPC_STRICT_ERRORS": "1", "MOBILEGL_IPC_RUN_AHEAD": str(self.args.run_ahead),
"MOBILEGL_IPC_STAGE_MB": "256", "MOBILEGL_PIPE_STATS": "1",
"MOBILEGL_PIPE_STATS_PERIOD": "120", "MOBILEGL_LOG_FILE_PATH": self.remote_log,
}
self.save("mg_env.txt", "".join(f"{key}={value}\n" for key, value in env.items()))
self.save("mg_transport.txt", self.args.transport + "\n")
self.adb("shell", "am", "force-stop", PACKAGE, required=True)
self.adb("push", str(self.out / "mg_env.txt"), "/sdcard/FCL/mg_env.txt", required=True)
self.adb("push", str(self.out / "mg_transport.txt"), "/sdcard/FCL/mg_transport.txt", required=True)
self.adb("shell", "input", "keyevent", "224", required=True)
self.adb("shell", "input", "keyevent", "82", required=True)
self.log_since = decode(self.adb("shell", "date '+%m-%d %H:%M:%S.000'", required=True).stdout).strip()
if not re.fullmatch(r"\d\d-\d\d \d\d:\d\d:\d\d\.000", self.log_since):
raise RuntimeError("Could not obtain a device timestamp for the logcat window")
self.summary["logcat_since_device_time"] = self.log_since
self.start = time.monotonic()
launched = self.adb("shell", "am", "start", "-n", ACTIVITY, required=True, timeout=30)
self.save("launch.txt", decode(launched.stdout) + decode(launched.stderr))
self.event("launched")
while time.monotonic() - self.start < DEADLINE_SECONDS:
current_pids = self.pids()
self.collect()
rows = self.stats()
fresh_latest = bool(self.latest) and hashlib.sha256(self.latest.encode()).hexdigest() != before_hash
target_logcat = "\n".join(line for line in self.logcat.splitlines()
if PACKAGE in line or any(re.search(r"\b" + pid + r"\b", line) for pid in self.known_pids))
fatal_match = FATAL.search(self.library + (self.latest if fresh_latest else "") + target_logcat)
if fatal_match:
reason = "fatal_or_crash_marker"
break
backend_ok, ipc_ok, problem = self.runtime(rows)
if problem:
reason = problem
break
if current_pids:
seen_process, missing_polls = True, 0
elif seen_process:
missing_polls += 1
if missing_polls >= 2:
reason = "app_process_exited"
break
if world_at is not None and current_pids and current_pids != stable_pids:
reason = "app_process_restarted_during_stable_window"
break
world_log = bool(fresh_latest and WORLD.search(self.latest))
drawing = len(rows) >= 3 and all(row.get("window") == 120 and row.get("draws/f", 0) >= 400 for row in rows[-3:])
# Magma does not implement the draws/f counter: use the fresh game log
# and actual frame progress, then require root to inspect the screenshots.
progress = bool(rows and rows[-1].get("frames", 0) > 0)
ready = bool(current_pids and world_log and backend_ok and ipc_ok and
(drawing if self.args.backend == "DirectGLES" else progress))
if world_at is None and ready:
world_at, world_frame, stable_pids = time.monotonic(), rows[-1]["frames"], current_pids
self.summary["time_to_in_world_seconds"] = round(world_at - self.start, 3)
self.event("in_world", frame=world_frame, pids=sorted(current_pids), source="fresh_latest_log_and_runtime")
self.screenshot("in-world.png")
stable = 0 if world_at is None else time.monotonic() - world_at
self.event("poll", pids=sorted(current_pids), backend_ok=backend_ok, ipc_ok=ipc_ok,
fresh_latest=fresh_latest, world_log=world_log, stable_seconds=round(stable, 2),
stats=rows[-1] if rows else None)
print(f"{self.args.backend}/{self.args.transport}: elapsed={int(time.monotonic()-self.start)}s "
f"pid={'alive' if current_pids else 'absent'} world={'yes' if world_at else 'waiting'} stable={int(stable)}s", flush=True)
if stable >= STABLE_SECONDS:
if not current_pids or not rows or rows[-1].get("frames", 0) <= world_frame:
reason = "no_frame_progress_during_stable_window"
break
status, reason = "PASS_PENDING_SCREENSHOT_REVIEW", "stable_window_completed"
self.summary["stable_seconds"] = round(stable, 3)
self.summary["stable_frame_delta"] = rows[-1]["frames"] - world_frame
self.summary["fps_approx_from_polled_stats"] = round((rows[-1]["frames"] - world_frame) / stable, 3)
break
time.sleep(min(POLL_SECONDS, max(0, DEADLINE_SECONDS - (time.monotonic() - self.start))))
else:
reason = "timeout_before_in_world" if world_at is None else "timeout_before_60s_stable"
except (RuntimeError, OSError, KeyboardInterrupt) as exc:
reason = "interrupted" if isinstance(exc, KeyboardInterrupt) else "runner_or_adb_error"
self.save("runner-error.txt", str(exc))
finally:
# Best effort capture cannot replace the original failure or lose prior polls.
try:
self.collect(final=True)
final_pids = sorted(self.pids())
self.event("final_pid", pids=final_pids)
self.summary["final_pids"] = final_pids
if status == "PASS_PENDING_SCREENSHOT_REVIEW":
if not final_pids or FATAL.search(self.library):
status, reason = "FAILED", "app_failed_during_final_capture"
elif not (self.out / "final.png").is_file():
status, reason = "FAILED", "final_screenshot_unavailable"
except (OSError, RuntimeError) as exc:
self.save("collection-error.txt", str(exc))
self.summary.update(status=status, reason=reason, elapsed_seconds=round(time.monotonic() - self.start, 3),
stats=self.stats(), app_left_in_final_state=True)
(self.out / "summary.json").write_text(json.dumps(self.summary, ensure_ascii=False, indent=2), encoding="utf-8")
self.event("finished", status=status, reason=reason)
print(f"{status}: {reason}; evidence={self.out}", flush=True)
return 0 if status == "PASS_PENDING_SCREENSHOT_REVIEW" else 1
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--backend", choices=BACKEND_NAMES, required=True)
parser.add_argument("--transport", choices=("inproc", "monolith"), required=True)
parser.add_argument("--run-ahead", type=int, choices=(0, 1), default=1)
parser.add_argument("--out", type=Path, required=True)
args = parser.parse_args()
if args.out.exists():
parser.error("--out must be a new directory; existing evidence is never overwritten")
return Arm(args).run()
if __name__ == "__main__":
sys.exit(main())
+3
View File
@@ -20,6 +20,9 @@ It allows only Magma's two pre-existing per-distance-enable limitations, matched
exact case and skip reason. They are never counted as passes and must be identical across arms.
Every other skip/failure is an error. Every actual stats window must have `rsp=0`; inproc must
publish `vbs>0` and correct runtime/capability logs, monolith must keep `vbs=0`.
The current verifier requires `run-ahead ARMED` on both inproc backends. To replay
the historical P5f bundle where Magma withheld that capability, use the verifier
from the bundle's source revision.
Android's normal integration target omits F1/Ct/DualBlock and private peek bridges. This runner
therefore does not claim those host cases ran on Android. See `device-report.md` in the P5f notes
+3 -2
View File
@@ -65,8 +65,9 @@ vbs = [int(re.search(r'\bvbs=(\d+)', line)[1]) for line in stats]
if arm['transport'] == 'inproc':
assert any(v > 0 for v in vbs), 'no applied verb boundaries; transport not proven'
assert re.search(r'Config: IPC .*strict=1 .*role-split-state=' + arm['role'] + r'\b', log)
expected = 'run-ahead ARMED' if arm['backend'] == 'DirectGLES' else 'run-ahead requested, server does not publish'
assert expected in log, 'missing runtime capability evidence'
# Current Magma publishes the capability after its queued-state migration.
# Historical P5f bundles should be checked with their matching source verifier.
assert 'run-ahead ARMED' in log, 'missing runtime capability evidence'
else:
assert all(v == 0 for v in vbs), 'monolith control has applied verb boundaries'
print(f'PASS {arm}: {len(cases)-len(skipped)} passed, {len(skipped)} named legacy feature skips, {len(stats)} stats windows, rsp=0, vbs={sum(vbs)}')