From cd95cc25f9d5a44aff58fe0a9372d4f884feaa99 Mon Sep 17 00:00:00 2001 From: Romans Pokrovskis Date: Thu, 5 Nov 2026 20:16:54 +0200 Subject: [PATCH] feat(agc): snapshot native multisample color from captured guest baselines --- .../Graphics/include/MultisampleTarget.hpp | 7 + .../Graphics/src/MultisampleTarget.cpp | 166 +++++++- ...iver_sample_multisample_target_tests.cmake | 10 + .../execution/SampleMultisampleTarget.cpp | 380 +++++++++++++++++- docs/dev/debt/libSceAgcDriver.md | 2 + 5 files changed, 549 insertions(+), 16 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp index e0d922a1b9a8..2ab937b069e7 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp @@ -100,6 +100,13 @@ bool TakeMultisampledClear(MultisampledCmask& cmask, MultisampledColorFill& colo SampleOrderTarget MultisampleTargetOrderTarget(const Context& context, const ColorTarget& target); std::shared_ptr MultisampleTargetTexture(const Context& context, const GuestTextureResource& resource, VkComponentMapping components, VkImageViewType viewType = VK_IMAGE_VIEW_TYPE_2D); std::shared_ptr MultisampleTargetFirstSample(const Context& context, const GuestTextureResource& resource, VkComponentMapping components); +struct MultisampleColorSnapshot { + std::vector original; + std::vector current; +}; + +std::vector ReadMultisampleTargetSamples_nid_no_patch(const Context& context, const ColorTarget& target); +MultisampleColorSnapshot ReadMultisampleTargetColorSnapshot_nid_no_patch(const Context& context, const ColorTarget& target); VkImageView MultisampleTargetView(const Context& context, const ColorTarget& target, VkImage* image = nullptr); VkImageView MultisampleTargetView(const Context& context, const ColorTarget& target, std::shared_ptr& owner, VkImage* image = nullptr); void PrepareMultisampleTargetForDraw_nid_no_patch(const Context& context, const ColorTarget& target); diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp index 62611fc9d100..c239a5432fcc 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp @@ -202,7 +202,7 @@ std::shared_ptr stageGuestSamples(const Context& context, const Multisam class MultisampleTarget : public std::enable_shared_from_this { public: - MultisampleTarget(const Context& context, const ColorTarget& target, bool guestSamples = false, std::optional initialClear = std::nullopt, std::shared_ptr preparedUpload = {}) : context(context), target(target), cmask(target.cmaskAddress, target.cmaskBytes), colorFill(target) { + MultisampleTarget(const Context& context, const ColorTarget& target, bool guestSamples = false, std::optional initialClear = std::nullopt, std::shared_ptr preparedUpload = {}, std::vector initialBaseline = {}) : context(context), target(target), cmask(target.cmaskAddress, target.cmaskBytes), colorFill(target), guestColorBaseline(std::move(initialBaseline)) { this->context.bufferPool.reset(); if (target.dccAddress != 0) metadataValid = std::make_shared>(true); const auto initial = initialClear ? *initialClear : initialDccClear(target); @@ -311,7 +311,7 @@ class MultisampleTarget : public std::enable_shared_from_this VkDeviceSize bytes = 0; }; - Allocation allocate(VkImageUsageFlags imageUsage, VkImageCreateFlags flags) { + Allocation allocate(VkImageUsageFlags imageUsage, VkImageCreateFlags flags, VkFormat sampleFormat = VK_FORMAT_UNDEFINED) { Allocation created; try { VkImageCreateInfo info{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; @@ -347,12 +347,12 @@ class MultisampleTarget : public std::enable_shared_from_this Check(context.Function("vkBindImageMemory")(context.device, created.image, created.memory, 0), "vkBindImageMemory multisampled target"); VkImageViewCreateInfo viewInfo{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; viewInfo.image = created.image; - viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; - viewInfo.format = target.format; + viewInfo.viewType = sampleFormat == VK_FORMAT_UNDEFINED ? VK_IMAGE_VIEW_TYPE_2D : VK_IMAGE_VIEW_TYPE_2D_ARRAY; + viewInfo.format = sampleFormat == VK_FORMAT_UNDEFINED ? target.format : sampleFormat; viewInfo.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; VkImageViewUsageCreateInfo viewUsage{VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO}; - viewUsage.usage = imageUsage & ~VK_IMAGE_USAGE_STORAGE_BIT; - if ((imageUsage & VK_IMAGE_USAGE_STORAGE_BIT) != 0) viewInfo.pNext = &viewUsage; + viewUsage.usage = sampleFormat == VK_FORMAT_UNDEFINED ? imageUsage & ~VK_IMAGE_USAGE_STORAGE_BIT : VK_IMAGE_USAGE_SAMPLED_BIT; + if (sampleFormat != VK_FORMAT_UNDEFINED || (imageUsage & VK_IMAGE_USAGE_STORAGE_BIT) != 0) viewInfo.pNext = &viewUsage; Check(context.Function("vkCreateImageView")(context.device, &viewInfo, nullptr, &created.view), "vkCreateImageView multisampled target"); } catch (...) { destroy(created); @@ -429,7 +429,7 @@ class MultisampleTarget : public std::enable_shared_from_this void Keep() { if (auto* recorder = Recorder::Active(); recorder != nullptr && recorder->Device() == context.device) { recorder->Keep(shared_from_this()); - recorder->KeepBytes(this, allocationBytes); + recorder->KeepBytes(this, allocationBytes + guestColorBaseline.size()); } } @@ -540,6 +540,99 @@ class MultisampleTarget : public std::enable_shared_from_this return orderView; } + std::vector ReadSamples() { + Require(context.detiler != nullptr, "multisample color sample readback requires a texture detiler"); + Require(target.samples == 2u || target.samples == 4u || target.samples == 8u, "unsupported multisample color readback fragment count"); + Require(target.eqaaFragments == 0u && target.layers == 1u && target.arraySlice == 0u && target.arrayLastSlice == 0u && target.depth == 1u && target.depthSlice == 0u && target.mipCount == 1u && target.mip == 0u && !target.mipTail, "multisample color readback of EQAA, arrays, volumes or mips is not implemented"); + auto& recorder = readbackRecorder(); + Require(cmask.Refusal().empty(), cmask.Refusal()); + Require(cmask.Keys() != DccKeys::Clear0000, "reading a multisampled color target whose CMASK fast clear no draw has applied is not implemented"); + Require(FindGuestColorTargetFormat(target.format, target.elementBytes).has_value(), "multisample color readback source format or element size is unsupported"); + const auto format = TextureDetiler::ImageElementFormat(target.elementBytes); + constexpr auto readUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; + constexpr auto readFlags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT; + const auto checkSupport = [&](VkFormat imageFormat, VkImageUsageFlags imageUsage, VkImageCreateFlags flags) { + VkImageFormatProperties supported{}; + Check(context.imageFormatProperties(context.physical, imageFormat, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, imageUsage, flags, &supported), "vkGetPhysicalDeviceImageFormatProperties multisample color readback"); + Require((supported.sampleCounts & target.samples) != 0 && target.extent.width <= supported.maxExtent.width && target.extent.height <= supported.maxExtent.height && supported.maxArrayLayers != 0, "multisample color readback exceeds device image limits"); + }; + checkSupport(format, VK_IMAGE_USAGE_SAMPLED_BIT, 0u); + checkSupport(target.format, readUsage, readFlags); + const auto elements = static_cast(target.extent.width) * target.extent.height * target.samples; + Require(elements != 0 && elements <= std::numeric_limits::max(), "multisample color readback element count is unsupported"); + const auto bytes = elements * target.elementBytes; + const auto alignedBytes = (bytes + 3u) & ~std::uint64_t{3}; + Require(alignedBytes <= std::numeric_limits::max(), "multisample color readback exceeds host address space"); + const auto alignment = std::max({4u, target.elementBytes, context.limits.minStorageBufferOffsetAlignment}); + const auto stride = context.limits.maxStorageBufferRange / alignment * alignment; + Require(stride != 0, "multisample color readback storage range cannot hold an aligned element"); + recorder.Sync(); + Require(active->load(std::memory_order_acquire), "multisampled color target was retired before sample readback"); + SettleStorageWrites(); + ApplyFastClear(target); + recorder.Sync(); + Require(active->load(std::memory_order_acquire), "multisampled color target was retired during sample readback"); + checkDccCurrent(target, false); + const auto snapshot = allocate(readUsage, readFlags, format); + try { + DeviceBuffer samples(context, static_cast(alignedBytes), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT); + Buffer staging(context, static_cast(alignedBytes), VK_BUFFER_USAGE_TRANSFER_DST_BIT); + context.detiler->BeginBatch(); + CommandBatch batch(context); + const auto commands = batch.Handle(); + recordToGeneral(commands, snapshot.image); + RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT); + VkImageCopy region{}; + region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; + region.dstSubresource = region.srcSubresource; + region.extent = {target.extent.width, target.extent.height, 1}; + context.Function("vkCmdCopyImage")(commands, image, VK_IMAGE_LAYOUT_GENERAL, snapshot.image, VK_IMAGE_LAYOUT_GENERAL, 1, ®ion); + RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT); + for (VkDeviceSize offset = 0; offset < bytes; offset += stride) { + const auto count = std::min(stride, bytes - offset); + context.detiler->DispatchMultisampleReadback(commands, format, samples.Handle(), offset, (count + 3u) & ~VkDeviceSize{3}, snapshot.view, target.extent.width, target.extent.height, 1u, target.samples, static_cast(offset / target.elementBytes), static_cast(count / target.elementBytes)); + } + RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT); + CopyBuffer(context, commands, samples.Handle(), 0u, staging.Handle(), 0u, alignedBytes); + RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT); + batch.SubmitAndWait(); + staging.Invalidate(); + std::vector result(static_cast(bytes)); + std::memcpy(result.data(), staging.Bytes().data(), result.size()); + destroy(snapshot); + return result; + } catch (...) { + destroy(snapshot); + throw; + } + } + + void NoteFill(std::uint64_t address, std::size_t bytes, std::uint32_t pattern) { + colorFill.NoteFill(address, bytes, pattern); + if (address > target.address) return; + const auto offset = target.address - address; + const auto colorBytes = MultisampledColorBytes(target); + if (colorBytes != 0 && offset <= bytes && colorBytes <= bytes - offset) paddingFill = pattern; + } + + MultisampleColorSnapshot ColorSnapshot() { + Require(target.tileMode == ColorTileMode::RenderTarget && target.dccAddress == 0 && target.cmaskAddress == 0, "guest color snapshots with unsupported tiling or multisample metadata are not implemented"); + Require(!guestColorBaseline.empty(), "guest color snapshot has no initial footprint"); + readbackRecorder().Sync(); + Require(active->load(std::memory_order_acquire), "multisampled color target was retired before guest color snapshot"); + auto original = currentGuestColor(); + const auto samples = ReadSamples(); + Require(currentGuestColor() == original, "guest color changed during native multisample snapshot"); + auto current = original; + if (paddingFill) { + for (std::size_t offset = 0; offset < current.size(); offset += sizeof(*paddingFill)) std::memcpy(current.data() + offset, &*paddingFill, sizeof(*paddingFill)); + } + const MultisampleTextureLayout layout(TextureTileMode::kR64KBX, target.elementBytes, target.samples, target.extent.width, target.extent.height, 1u, target.pipeBankXor); + Require(layout.Bytes() == current.size(), "guest color snapshot layout and footprint differ"); + layout.Tile(samples, current); + return {std::move(original), std::move(current)}; + } + void NoteMetadataFill(std::uint64_t fillAddress, std::size_t fillBytes, std::uint32_t pattern) { const auto note = [&](std::uint64_t address, std::uint64_t bytes, std::optional& filled) { if (address == 0 || fillAddress >= address + bytes || address >= fillAddress + fillBytes) return; @@ -775,6 +868,28 @@ class MultisampleTarget : public std::enable_shared_from_this return true; } + std::vector guestColorBaseline; + std::optional paddingFill; + + Recorder& readbackRecorder() const { + Require(!Recorder::InCompletion(), "native color readback during a recorder completion is not implemented"); + auto* recorder = context.recorder != nullptr ? context.recorder : Recorder::Active(); + Require(recorder != nullptr && recorder->Device() == context.device, "multisample color sample readback requires a recorder for its device"); + const auto* recording = Recorder::Active(); + Require(recording == nullptr || recording->Device() != context.device || recording == recorder, "native color readback with another active recorder on the same device is not implemented"); + return *recorder; + } + + std::vector currentGuestColor() const { + if (GuestMemory::CompareMapped(target.address, guestColorBaseline) == GuestMemory::Compare::Equal) return guestColorBaseline; + if (paddingFill) { + auto filled = guestColorBaseline; + for (std::size_t offset = 0; offset < filled.size(); offset += sizeof(*paddingFill)) std::memcpy(filled.data() + offset, &*paddingFill, sizeof(*paddingFill)); + if (GuestMemory::CompareMapped(target.address, filled) == GuestMemory::Compare::Equal) return filled; + } + throw std::runtime_error("AGC graphics: guest color no longer matches its initial contents or a known full fill"); + } + VkImageView uploadView = VK_NULL_HANDLE; std::shared_ptr guestSampleUpload(const ColorTarget& use) { @@ -786,7 +901,9 @@ class MultisampleTarget : public std::enable_shared_from_this Require(layout.LinearBytes() / use.elementBytes <= std::numeric_limits::max(), "the multisampled guest color element count is unsupported"); std::vector guest(static_cast(layout.Bytes())); GuestMemory::Read(use.address, guest); - return stageGuestSamples(context, layout, guest); + auto upload = stageGuestSamples(context, layout, guest); + guestColorBaseline = std::move(guest); + return upload; } VkClearColorValue initialDccClear(const ColorTarget& use) { @@ -1065,7 +1182,7 @@ bool holdHostOnly(const MultisampleTarget& target) { return true; } -MultisampleTarget& acquire(const Context& context, const ColorTarget& requested, std::optional initialClear = std::nullopt, std::shared_ptr initialUpload = {}) { +MultisampleTarget& acquire(const Context& context, const ColorTarget& requested, std::optional initialClear = std::nullopt, std::shared_ptr initialUpload = {}, std::vector initialBaseline = {}) { discardRetiredTargets(); for (const auto& target : targets()) { if (!target->active->load(std::memory_order_acquire)) continue; @@ -1110,7 +1227,7 @@ MultisampleTarget& acquire(const Context& context, const ColorTarget& requested, return *target; } const auto& use = requested; - auto target = std::make_shared(context, use, false, initialClear, std::move(initialUpload)); + auto target = std::make_shared(context, use, false, initialClear, std::move(initialUpload), std::move(initialBaseline)); target->Keep(); targets().push_back(std::move(target)); auto& created = *targets().back(); @@ -1186,13 +1303,24 @@ MultisampleTarget& createFilled(const Context& context, const GuestTextureResour auto& created = *targets().back(); created.use->hostOnly.store(written, std::memory_order_release); guard(context, use, created.active, created.metadataValid, created.use); - if (uniform) created.colorFill.NoteFill(use.address, static_cast(bytes), value); + if (uniform) created.NoteFill(use.address, static_cast(bytes), value); created.fromTexture = true; created.htileAddress = resource.dccAddress; created.htileBytes = htileBytes; return created; } +std::shared_ptr snapshotTarget(const Context& context, const ColorTarget& use) { + TargetsLock lock; + for (const auto& candidate : targets()) { + if (!candidate->active->load(std::memory_order_acquire) || candidate->context.device != context.device || !sameTarget(candidate->target, use)) continue; + const auto& target = candidate->target; + Require(target.address == use.address && target.mip == use.mip && target.mipCount == use.mipCount && target.mipTail == use.mipTail && target.layers == use.layers && target.depth == use.depth && target.arraySlice == use.arraySlice && target.arrayLastSlice == use.arrayLastSlice && target.depthSlice == use.depthSlice && target.elementBytes == use.elementBytes && target.tileMode == use.tileMode && target.pipeBankXor == use.pipeBankXor && target.dccAddress == use.dccAddress && target.cmaskAddress == use.cmaskAddress, "multisample color readback subresource does not match the resident target"); + return candidate; + } + throw std::runtime_error("AGC graphics: multisample color sample readback requires an existing resident target"); +} + } void InstallResidentImageReadGuard_nid_no_patch() { @@ -1471,7 +1599,7 @@ void PrepareMultisampleTargetForDraw_nid_no_patch(const Context& context, const TargetsLock lock; requireUnowned(); Require(GuestMemory::CompareMapped(target.address, snapshot) == GuestMemory::Compare::Equal, "initial multisample color contents changed during upload preparation"); - acquire(context, target, clear, std::move(upload)); + acquire(context, target, clear, std::move(upload), std::move(snapshot)); } SampleOrderTarget MultisampleTargetOrderTarget(const Context& context, const ColorTarget& target) { @@ -1586,6 +1714,16 @@ void MaterializeMultisampleTargetClear(const Context& context, const ColorTarget acquire(context, target); } +std::vector ReadMultisampleTargetSamples_nid_no_patch(const Context& context, const ColorTarget& target) { + std::lock_guard gpu(GuestMemory::GpuMutex()); + return snapshotTarget(context, target)->ReadSamples(); +} + +MultisampleColorSnapshot ReadMultisampleTargetColorSnapshot_nid_no_patch(const Context& context, const ColorTarget& target) { + std::lock_guard gpu(GuestMemory::GpuMutex()); + return snapshotTarget(context, target)->ColorSnapshot(); +} + VkImageView MultisampleTargetStorageView(const Context& context, const GuestTextureResource& resource, bool uintStorage) { TargetsLock lock; discardRetiredTargets(); @@ -1657,11 +1795,11 @@ void NoteColorMetadataFill(std::uint64_t address, std::size_t bytes, std::uint32 TargetsLock lock; for (const auto& target : targets()) { if (!target->active->load(std::memory_order_acquire)) continue; - target->colorFill.NoteFill(address, bytes, pattern); + target->NoteFill(address, bytes, pattern); if (target->htileBytes != 0 && address < target->htileAddress + target->htileBytes && target->htileAddress < address + bytes) { if (pattern == 0u && address <= target->htileAddress && address + bytes >= target->htileAddress + target->htileBytes) { target->htileRefusal.clear(); - target->colorFill.NoteFill(target->target.address, static_cast(MultisampledColorBytes(target->target)), 0u); + target->NoteFill(target->target.address, static_cast(MultisampledColorBytes(target->target)), 0u); } else { char text[224]; std::snprintf(text, sizeof(text), "a fill of 0x%llx+0x%zx with 0x%08x over the HTILE 0x%llx+0x%llx of a sampled multisampled depth-layout texture is not modeled", static_cast(address), bytes, pattern, static_cast(target->htileAddress), static_cast(target->htileBytes)); diff --git a/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_sample_multisample_target_tests.cmake b/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_sample_multisample_target_tests.cmake index 1b7d821453fa..f4f164726863 100644 --- a/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_sample_multisample_target_tests.cmake +++ b/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_sample_multisample_target_tests.cmake @@ -31,3 +31,13 @@ if(BUILD_TESTING) endif() endforeach() endif() + +if(BUILD_TESTING) + foreach(nativeColorMode IN ITEMS readback snapshot snapshot_refusals) + add_test(NAME agc_driver_native_color_${nativeColorMode} COMMAND agc_driver_sample_multisample_target_tests --${nativeColorMode}) + set_tests_properties(agc_driver_native_color_${nativeColorMode} PROPERTIES TIMEOUT 30 ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") + if(WIN32) + set_tests_properties(agc_driver_native_color_${nativeColorMode} PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") + endif() + endforeach() +endif() diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp index f341db03bddd..63847ff33b41 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp @@ -1057,8 +1057,12 @@ int NonuniformInitialLifetime(AgcDriver::VulkanDevice& device) { std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); recorder.Activate(); PrepareMultisampleTargetForDraw_nid_no_patch(recorded, color); - view = MultisampleTargetView(recorded, color, owner); + VkImage image = VK_NULL_HANDLE; + view = MultisampleTargetView(recorded, color, owner, &image); + VkMemoryRequirements requirements{}; + context.Function("vkGetImageMemoryRequirements")(context.device, image, &requirements); initialBytes = recorder.OpenKeptBytes(); + Require(initialBytes == requirements.size + BlockBytes + (uniform ? 0u : uploadBytes), "initial native color accounting omits the retained guest baseline or transient upload"); const auto premature = recorded.bufferPool->Take(uploadBytes, usage); if (premature) recorded.bufferPool->Put(*premature); Require(!premature.has_value(), "initial upload was recycled before submission completed"); @@ -1075,7 +1079,7 @@ int NonuniformInitialLifetime(AgcDriver::VulkanDevice& device) { std::shared_ptr reusedOwner; Require(MultisampleTargetView(recorded, color, reusedOwner) == view && reusedOwner == owner, "initial-content accounting did not reuse its resident target"); const auto targetBytes = recorder.OpenKeptBytes(); - Require(targetBytes != 0 && initialBytes == targetBytes + (uniform ? 0u : uploadBytes), "reused target still counts initial color snapshot or upload bytes"); + Require(targetBytes != 0 && initialBytes == targetBytes + (uniform ? 0u : uploadBytes), "reused target still counts initial upload bytes"); KeepMultisampleTarget_nid_no_patch(owner); Require(recorder.OpenKeptBytes() == targetBytes, "one target is counted twice within a submission"); recorder.Submit(); @@ -1177,6 +1181,375 @@ void NonuniformInitialHook(AgcDriver::VulkanDevice& device) { std::puts("nonuniform initial upload captures once outside the targets lock"); } +void CheckReadbackSamples(const AgcDriver::Graphics::State& state, const std::vector>& loaded, const std::array& background, std::span> supplied = {}) { + const auto locations = AgcDriver::Graphics::SampleLocations(state); + Require(loaded.size() == Side * Side * state.samples, "the multisample result has the wrong element count"); + Require(supplied.empty() || supplied.size() == loaded.size(), "the initial sample count does not match the rendered target"); + std::vector pixelsByCoverage(state.samples + 1u); + std::vector coveredBySample(state.samples); + std::uint32_t checked = 0; + for (std::uint32_t y = 0; y < Side; ++y) { + for (std::uint32_t x = 0; x < Side; ++x) { + std::uint32_t covered = 0; + for (std::uint32_t sample = 0; sample < state.samples; ++sample) { + const auto index = (y * Side + x) * state.samples + sample; + const auto& texel = loaded[index]; + const bool drawn = texel == Drawn; + const bool empty = texel == (supplied.empty() ? background : supplied[index]); + char where[160]; + std::snprintf(where, sizeof(where), "sample %u of pixel (%u, %u) loaded (%g, %g, %g, %g)", sample, x, y, texel[0], texel[1], texel[2], texel[3]); + Require(drawn || empty, std::string(where) + ", neither the drawn color nor the initial target sample"); + covered += drawn ? 1u : 0u; + coveredBySample[sample] += drawn ? 1u : 0u; + const auto px = x + static_cast(locations[sample].x); + const auto py = y + static_cast(locations[sample].y); + const auto distance = std::min({EdgeDistance(px, py, 0), EdgeDistance(px, py, 1), EdgeDistance(px, py, 2)}); + if (std::fabs(distance) < EdgeMargin) continue; + ++checked; + Require(drawn == (distance > 0), std::string(where) + (distance > 0 ? ", which the triangle covers" : ", which the triangle does not cover")); + } + ++pixelsByCoverage[covered]; + } + } + Require(checked >= Side * Side * state.samples * 9u / 10u, "fewer than nine in ten samples are clear of the triangle's edges"); + Require(pixelsByCoverage[0] != 0 && pixelsByCoverage[state.samples] != 0, "the triangle covers every pixel or none"); + if (state.samples == Samples) { + Require(std::any_of(pixelsByCoverage.begin() + 1, pixelsByCoverage.end() - 1, [](auto count) { return count != 0; }), "no pixel is partly covered, so the samples of a pixel were not told apart"); + Require(std::adjacent_find(coveredBySample.begin(), coveredBySample.end(), std::not_equal_to<>()) != coveredBySample.end(), "every sample index has the same coverage, so the sample index was not told apart"); + } +} + +std::vector> ReadHalfSamples(const AgcDriver::Graphics::Context& context, const AgcDriver::Graphics::ColorTarget& color) { + const auto bytes = AgcDriver::Graphics::ReadMultisampleTargetSamples_nid_no_patch(context, color); + Require(bytes.size() == Side * Side * color.samples * 8u, "native color readback has the wrong byte count"); + std::vector> result(Side * Side * color.samples); + constexpr std::array, 4> bits{{{}, {0x3400u, 0x3800u, 0x3000u, 0x3c00u}, {0x3c00u, 0x3c00u, 0x3c00u, 0x3c00u}, {0x3a00u, 0x3400u, 0x3800u, 0x3c00u}}}; + constexpr std::array, 4> values{{{}, Drawn, Ones, Written}}; + for (std::size_t index = 0; index < result.size(); ++index) { + std::array sample{}; + std::memcpy(sample.data(), bytes.data() + index * sizeof(sample), sizeof(sample)); + const auto found = std::find(bits.begin(), bits.end(), sample); + Require(found != bits.end(), "native color readback changed a half-float sample at element " + std::to_string(index)); + result[index] = values[static_cast(found - bits.begin())]; + } + return result; +} + +void RequireReadbackRefused(const AgcDriver::Graphics::Context& context, const AgcDriver::Graphics::ColorTarget& color, const std::string& expected) { + std::string refusal; + try { + static_cast(AgcDriver::Graphics::ReadMultisampleTargetSamples_nid_no_patch(context, color)); + } catch (const std::exception& error) { + refusal = error.what(); + } + Require(refusal.find(expected) != std::string::npos, "native color readback was not refused: " + refusal); +} + +void RequireInitialRefused(const AgcDriver::Graphics::Context& context, const AgcDriver::Graphics::ColorTarget& color, const std::string& expected) { + std::string refusal; + try { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + AgcDriver::Graphics::PrepareMultisampleTargetForDraw_nid_no_patch(context, color); + } catch (const std::exception& error) { + refusal = error.what(); + } + Require(refusal.find(expected) != std::string::npos, "native color initialization was not refused: " + refusal); +} + +bool InitialCountSupported(const AgcDriver::Graphics::Context& context, VkFormat format, std::uint32_t samples) { + VkImageFormatProperties supported{}; + const auto result = context.imageFormatProperties(context.physical, format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, 0u, &supported); + if (result != VK_ERROR_FORMAT_NOT_SUPPORTED) AgcDriver::Graphics::Check(result, "native color initialization fixture format query"); + if (result == VK_SUCCESS && (supported.sampleCounts & samples) != 0 && (context.limits.framebufferColorSampleCounts & samples) != 0) return true; + std::printf("skipped, the device lacks native color initialization format=%d samples=%u\n", static_cast(format), samples); + return false; +} + +PFN_vkGetPhysicalDeviceImageFormatProperties imageFormatProperties = nullptr; + +VKAPI_ATTR VkResult VKAPI_CALL NoReadbackImage(VkPhysicalDevice physical, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* properties) { + if ((flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT) != 0 && usage == (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT)) return VK_ERROR_FORMAT_NOT_SUPPORTED; + return imageFormatProperties(physical, format, type, tiling, usage, flags, properties); +} + +std::vector> LoadColorSamples(AgcDriver::VulkanDevice& device, const Block& block, const AgcDriver::Graphics::ColorTarget& color) { + auto descriptor = TargetDescriptor(block, std::countr_zero(color.samples)); + descriptor[0] ^= color.pipeBankXor >> 8u; + return LoadSamples(device, descriptor, color.samples); +} + + +void Readback(AgcDriver::VulkanDevice& device) { + using namespace AgcDriver::Graphics; + auto context = AgcDriver::VulkanDeviceTestAccess::ContextOf(device); + context.limits.maxStorageBufferRange = 256u; + std::uint32_t exercised = 0; + for (const auto fragments : {2u, 4u, 8u}) { + if (!InitialCountSupported(context, VK_FORMAT_R16G16B16A16_SFLOAT, fragments)) continue; + Block block(BlockBytes); + auto color = DecodeTarget(block.Address(), std::countr_zero(fragments)); + RequireReadbackRefused(context, color, "requires an existing resident target"); + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + MultisampleTargetView(context, color); + } + const auto state = TargetState(color); + Draw(device, state); + const auto read = ReadHalfSamples(context, color); + Require(read == LoadColorSamples(device, block, color), "native readback disagrees with independent MIMG sample reads"); + CheckReadbackSamples(state, read, {}); + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + auto* recording = Recorder::Active(); + Require(recording != nullptr && context.recorder != nullptr, "the readback fixture has no owning recorder"); + Recorder other(context); + other.Activate(); + RequireReadbackRefused(context, color, "another active recorder on the same device"); + recording->Activate(); + } + auto otherDevice = context; + otherDevice.device = VK_NULL_HANDLE; + RequireReadbackRefused(otherDevice, color, "requires an existing resident target"); + auto otherMip = color; + otherMip.mip = 1; + RequireReadbackRefused(context, otherMip, "subresource does not match"); + NoteColorMetadataFill(block.Address(), static_cast(MultisampledColorBytes(color)), FillOnes); + CheckUniform(ReadHalfSamples(context, color), Ones, "after a native color fill"); + if (fragments == Samples) { + CheckUniform(LoadSamples(device, block), Ones, "before storage migration"); + const auto selected = [](std::uint32_t x, std::uint32_t, std::uint32_t sample) { return x < Side / 2u && sample == StoredSample; }; + StoreSamples(device, TargetDescriptor(block, SampleShift), SampleWrites(selected)); + CheckWritten(std::vector>(Side * Side * Samples, Ones), ReadHalfSamples(context, color), selected, "after storage migration and per-sample writes"); + } + std::printf("native color readback: RGBA16F samples=%u coverage/fill/refusals/chunks passed\n", fragments); + ++exercised; + { + Block exact(BlockBytes); + auto exactColor = DecodeTarget(exact.Address(), std::countr_zero(fragments)); + exactColor.pipeBankXor = 0x8100u; + const MultisampleTextureLayout layout(TextureTileMode::kR64KBX, 8u, fragments, Side, Side, 1u, exactColor.pipeBankXor); + constexpr std::array patterns{0u, 0x8000u, 1u, 0x8001u, 0x03ffu, 0x0400u, 0x7c00u, 0xfc00u, 0x7e01u, 0xfe55u, 0x7d01u, 0xfdffu}; + std::vector words(static_cast(layout.LinearBytes()) / sizeof(std::uint16_t)); + for (std::size_t index = 0; index < words.size(); ++index) words[index] = patterns[index % patterns.size()]; + const auto expected = std::as_bytes(std::span(words)); + auto tiled = std::as_writable_bytes(std::span(exact.data, exact.bytes)); + layout.Tile(expected, tiled); + const std::vector before(tiled.begin(), tiled.end()); + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + PrepareMultisampleTargetForDraw_nid_no_patch(context, exactColor); + MultisampleTargetView(context, exactColor); + } + const auto samples = ReadMultisampleTargetSamples_nid_no_patch(context, exactColor); + Require(std::equal(samples.begin(), samples.end(), expected.begin(), expected.end()), "native half-float readback changed an exceptional-value bit pattern"); + const auto snapshot = ReadMultisampleTargetColorSnapshot_nid_no_patch(context, exactColor); + Require(snapshot.original == before && snapshot.current == before && std::equal(before.begin(), before.end(), tiled.begin()), "native exceptional-value snapshot changed samples, padding or guest bytes"); + std::printf("native color readback: RGBA16F samples=%u signed zeros/subnormals/infinities/NaN payload bits preserved\n", fragments); + } + } + constexpr std::array formats{VK_FORMAT_R8_UINT, VK_FORMAT_R16_UINT, VK_FORMAT_R32_UINT, VK_FORMAT_R32G32_UINT, VK_FORMAT_R32G32B32A32_UINT}; + constexpr std::array pattern{0x5au, 0x89abcdefu, 0x01234567u, 0xfedcba98u}; + for (std::size_t index = 0; index < formats.size(); ++index) { + if (!InitialCountSupported(context, formats[index], Samples)) continue; + Block block(BlockBytes); + auto color = DecodeTarget(block); + color.format = formats[index]; + color.elementBytes = 1u << index; + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + VkImage image = VK_NULL_HANDLE; + MultisampleTargetView(context, color, &image); + Recorder::Active()->Sync(); + CommandBatch batch(context); + RecordMemoryBarrier(context, batch.Handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT); + VkClearColorValue clear{}; + std::copy(pattern.begin(), pattern.end(), clear.uint32); + const VkImageSubresourceRange range{VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u}; + context.Function("vkCmdClearColorImage")(batch.Handle(), image, VK_IMAGE_LAYOUT_GENERAL, &clear, 1u, &range); + batch.SubmitAndWait(); + } + const auto bytes = ReadMultisampleTargetSamples_nid_no_patch(context, color); + Require(bytes.size() == Side * Side * Samples * color.elementBytes, "native integer sample count is wrong"); + for (std::size_t offset = 0; offset < bytes.size(); offset += color.elementBytes) Require(std::memcmp(bytes.data() + offset, pattern.data(), color.elementBytes) == 0, "native integer sample bytes changed at " + std::to_string(offset)); + std::printf("native color readback: elementBytes=%u integer bits/chunks passed\n", color.elementBytes); + } + if (InitialCountSupported(context, VK_FORMAT_R16G16B16A16_SFLOAT, Samples)) { + Block block(BlockBytes); + const auto color = DecodeTarget(block); + auto unsupported = context; + imageFormatProperties = context.imageFormatProperties; + unsupported.imageFormatProperties = NoReadbackImage; + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + MultisampleTargetView(unsupported, color); + } + Draw(device, TargetState(color)); + RequireReadbackRefused(unsupported, color, "multisample color readback"); + CheckReadbackSamples(TargetState(color), LoadSamples(device, block), {}); + std::puts("native color readback: unsupported snapshot format refuses readback and retains rendering"); + Block invalidBlock(BlockBytes); + auto invalid = DecodeTarget(invalidBlock); + invalid.elementBytes = 4u; + RequireInitialRefused(context, invalid, "color format or element size is unsupported"); + std::puts("native color readback: mismatched source format and element size is refused before view creation"); + } + Require(exercised != 0, "no supported native color readback sample count was exercised"); +} + +std::vector HalfSamples(std::span> samples) { + constexpr std::array, 4> bits{{{}, {0x3400u, 0x3800u, 0x3000u, 0x3c00u}, {0x3c00u, 0x3c00u, 0x3c00u, 0x3c00u}, {0x3a00u, 0x3400u, 0x3800u, 0x3c00u}}}; + constexpr std::array, 4> values{{{}, Drawn, Ones, Written}}; + std::vector result(samples.size() * sizeof(bits[0])); + for (std::size_t index = 0; index < samples.size(); ++index) { + const auto found = std::find(values.begin(), values.end(), samples[index]); + Require(found != values.end(), "guest MIMG returned an unexpected sample color"); + std::memcpy(result.data() + index * sizeof(bits[0]), bits[static_cast(found - values.begin())].data(), sizeof(bits[0])); + } + return result; +} + +void RequireColorSnapshotRefused(const AgcDriver::Graphics::Context& context, const AgcDriver::Graphics::ColorTarget& color, const std::string& expected) { + std::string refusal; + try { + static_cast(AgcDriver::Graphics::ReadMultisampleTargetColorSnapshot_nid_no_patch(context, color)); + } catch (const std::exception& error) { + refusal = error.what(); + } + Require(refusal.find(expected) != std::string::npos, "guest color snapshot was not refused: " + refusal); +} + + +void CheckColorSnapshot(AgcDriver::VulkanDevice& device, const AgcDriver::Graphics::ColorTarget& color, const Block& block, const std::vector>& loaded, std::optional padding = std::nullopt) { + using namespace AgcDriver::Graphics; + const auto context = AgcDriver::VulkanDeviceTestAccess::ContextOf(device); + const auto* begin = reinterpret_cast(block.data); + const std::vector before(begin, begin + block.bytes); + const auto snapshot = ReadMultisampleTargetColorSnapshot_nid_no_patch(context, color); + Require(snapshot.original == before, "guest snapshot baseline differs from the mapped original bytes"); + auto expected = before; + if (padding) { + for (std::size_t offset = 0; offset < expected.size(); offset += sizeof(*padding)) std::memcpy(expected.data() + offset, &*padding, sizeof(*padding)); + } + const MultisampleTextureLayout layout(TextureTileMode::kR64KBX, color.elementBytes, color.samples, Side, Side, 1u, color.pipeBankXor); + layout.Tile(HalfSamples(loaded), expected); + Require(snapshot.current == expected, "guest color snapshot differs from the MIMG samples or preserved padding"); + Require(std::equal(before.begin(), before.end(), begin), "capturing the guest color snapshot modified guest memory"); + Require(ReadHalfSamples(context, color) == loaded, "native snapshot readback disagrees with guest MIMG"); + Require(LoadColorSamples(device, block, color) == loaded, "sampling after the native snapshot changed the image contents"); + std::string guard; + try { + RequireNoMultisampleTarget(block.Address(), 1u, "snapshot validation"); + } catch (const std::exception& error) { + guard = error.what(); + } + Require(guard.find("overlaps multisampled color target") != std::string::npos, "capturing a snapshot removed the native target's guest-access guard"); + Draw(device, TargetState(color)); + Require(LoadColorSamples(device, block, color) == loaded, "attachment reuse after the native snapshot changed untouched samples"); +} + + +void ColorSnapshots(AgcDriver::VulkanDevice& device) { + using namespace AgcDriver::Graphics; + const auto context = AgcDriver::VulkanDeviceTestAccess::ContextOf(device); + std::uint32_t exercised = 0u; + for (const auto fragments : {2u, 4u, 8u}) { + if (!InitialCountSupported(context, VK_FORMAT_R16G16B16A16_SFLOAT, fragments)) continue; + for (const auto pipeBankXor : {0u, 0x8100u}) { + Block block(BlockBytes); + StoreInitial(block, fragments, pipeBankXor, false); + auto color = DecodeTarget(block.Address(), std::countr_zero(fragments)); + color.pipeBankXor = pipeBankXor; + const auto state = TargetState(color); + Draw(device, state); + CheckColorSnapshot(device, color, block, LoadColorSamples(device, block, color)); + if (fragments == Samples && pipeBankXor == 0u) { + NoteColorMetadataFill(block.Address(), block.bytes, FillOnes); + Draw(device, state); + CheckColorSnapshot(device, color, block, LoadColorSamples(device, block, color), FillOnes); + StoreWords(block, block.bytes, FillOnes); + NoteColorMetadataFill(block.Address(), block.bytes, FillOnes); + Draw(device, state); + CheckColorSnapshot(device, color, block, LoadColorSamples(device, block, color), FillOnes); + block.data[BlockBytes - 1u] ^= 1u; + RequireColorSnapshotRefused(context, color, "no longer matches its initial contents or a known full fill"); + block.data[BlockBytes - 1u] ^= 1u; + auto wrong = color; + wrong.mip = 1u; + RequireColorSnapshotRefused(context, wrong, "subresource does not match the resident target"); + } + device.SubmitRecorded(true); + device.WaitIdle(); + ClearCachedTextures(context.device); + ClearMultisampleTargets(context.device); + std::printf("native color snapshot: %u fragments xor=0x%x preserves MIMG samples, padding, guest bytes and ownership\n", fragments, pipeBankXor); + ++exercised; + } + } + Require(exercised != 0u, "no native color snapshot sample count was exercised"); + Block uniform(BlockBytes); + StoreWords(uniform, uniform.bytes, FillOnes); + const auto color = DecodeTarget(uniform); + Draw(device, TargetState(color)); + CheckColorSnapshot(device, color, uniform, LoadSamples(device, uniform)); +} + +void ColorSnapshotRefusals(AgcDriver::VulkanDevice& device) { + using namespace AgcDriver::Graphics; + const auto context = AgcDriver::VulkanDeviceTestAccess::ContextOf(device); + { + Block block(BlockBytes); + const auto color = DecodeTarget(block); + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + MultisampleTargetView(context, color); + } + RequireColorSnapshotRefused(context, color, "has no initial footprint"); + Draw(device, TargetState(color)); + CheckReadbackSamples(TargetState(color), ReadHalfSamples(context, color), {}); + } + { + Block block(BlockBytes); + StoreWords(block, block.bytes, FillOnes); + auto color = DecodeTarget(block); + color.tileMode = ColorTileMode::Z64KBX; + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + PrepareMultisampleTargetForDraw_nid_no_patch(context, color); + } + RequireColorSnapshotRefused(context, color, "unsupported tiling or multisample metadata"); + } + auto completed = std::make_shared(BlockBytes); + const auto completedColor = DecodeTarget(*completed); + StoreInitial(*completed, Samples, 0u, false); + Draw(device, TargetState(completedColor)); + auto refusals = std::make_shared>(); + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + auto* recorder = context.recorder != nullptr ? context.recorder : Recorder::Active(); + Require(recorder != nullptr, "the snapshot fixture has no owning recorder"); + recorder->OnComplete([completed, completedColor, context, refusals] { + try { static_cast(ReadMultisampleTargetSamples_nid_no_patch(context, completedColor)); } + catch (const std::exception& error) { (*refusals)[0] = error.what(); } + try { static_cast(ReadMultisampleTargetColorSnapshot_nid_no_patch(context, completedColor)); } + catch (const std::exception& error) { (*refusals)[1] = error.what(); } + StoreWords(*completed, completed->bytes, FillOnes); + NoteColorMetadataFill(completed->Address(), completed->bytes, FillOnes); + }); + auto* recording = Recorder::Active(); + Require(recording != nullptr, "the snapshot fixture has no active recorder"); + Recorder other(context); + other.Activate(); + RequireColorSnapshotRefused(context, completedColor, "another active recorder on the same device"); + recording->Activate(); + } + const auto snapshot = ReadMultisampleTargetColorSnapshot_nid_no_patch(context, completedColor); + Require(std::all_of(refusals->begin(), refusals->end(), [](const auto& error) { return error.find("during a recorder completion") != std::string::npos; }), "a native color snapshot recursively completed its producer"); + std::vector expected(completed->bytes); + for (std::size_t offset = 0; offset < expected.size(); offset += sizeof(FillOnes)) std::memcpy(expected.data() + offset, &FillOnes, sizeof(FillOnes)); + Require(snapshot.original == expected && snapshot.current == expected, "the native snapshot captured its baseline before producer completion"); + std::puts("native color snapshot: missing baseline, tiling, foreign recorder and completion reentry refuse; producer completion precedes current guest capture"); +} + void UniformInitialContents(AgcDriver::VulkanDevice& device) { using namespace AgcDriver::Graphics; const auto context = AgcDriver::VulkanDeviceTestAccess::ContextOf(device); @@ -1674,6 +2047,9 @@ int main(int argc, char** argv) { return 0; } if (argc == 2 && std::string_view(argv[1]) == "--native-vertex-input") return NativeVertexInput(device); + if (argc == 2 && std::string_view(argv[1]) == "--readback") { Readback(*device); return 0; } + if (argc == 2 && std::string_view(argv[1]) == "--snapshot") { ColorSnapshots(*device); return 0; } + if (argc == 2 && std::string_view(argv[1]) == "--snapshot_refusals") { ColorSnapshotRefusals(*device); return 0; } if (argc == 2 && std::string_view(argv[1]) == "--initial-nonuniform_lifetime") return NonuniformInitialLifetime(*device); if (argc == 2 && std::string_view(argv[1]) == "--initial-nonuniform_capabilities") { NonuniformInitialCapabilities(*device); return 0; } if (argc == 2 && std::string_view(argv[1]) == "--initial-nonuniform_hook") { NonuniformInitialHook(*device); return 0; } diff --git a/docs/dev/debt/libSceAgcDriver.md b/docs/dev/debt/libSceAgcDriver.md index c7240632c456..180f8613443a 100644 --- a/docs/dev/debt/libSceAgcDriver.md +++ b/docs/dev/debt/libSceAgcDriver.md @@ -406,3 +406,5 @@ - [Draw finisher](../../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cpp) (`APS5_DRAW_PIPELINE`) - opt-in. The Linux main-image page table it adds matches what Windows already does by default. - [Multi-submit count overflow and buffer validation](../../../core/libs/prx/libSceAgcDriver/Submit/src/Dcb.cpp) (libSceAgcDriver) - whether the console driver imposes an architectural submission packet limit or allows null buffer pointers with non-zero sizes in multi-submit arrays is unmeasured; AgcDriver::SubmitMany validates count against 32-bit pointer array bounds overflow and rejects null addresses for non-empty command buffers with a runtime exception. + +- [Native multisample color snapshots](../../../core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp) do not publish guest memory. Guest-footprint snapshots require uncompressed single-layer R_X and a retained initial footprint; low-level view creation without a captured baseline refuses. Raw sample readback does not support EQAA, arrays, volumes or mips. The baseline remains accounted for during the resident target's lifetime, while upload buffers expire after completion. Snapshots preserve padding and guards and reject unexpected guest changes, another active recorder on the same device, and completion reentry. Callers must keep guest mappings alive during comparisons. Automatic consumers, console equivalence, unsynchronized guest writes and large-title costs remain unverified.