diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp index 4b447a4faf0e..a95784d4fdf4 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp @@ -2113,7 +2113,7 @@ class DepthSurface { std::exception_ptr publicationFailure; void capturePublication() { - if ((target.format != VK_FORMAT_D32_SFLOAT_S8_UINT && !bareDepthTarget(target)) || context.detiler == nullptr) return; + if ((target.format != VK_FORMAT_D32_SFLOAT && target.format != VK_FORMAT_D32_SFLOAT_S8_UINT) || context.detiler == nullptr) return; try { const auto lease = GuestAllocations::GuestAllocationsAcquireAll_nid_postfix(); CheckCurrent(); @@ -3240,6 +3240,7 @@ std::uint32_t expandedHtileWord(std::uint32_t word, bool stencilInHtile, VkImage } bool DepthSurface::PublishToGuest(DepthReadCause cause) { + const bool stencil = target.format == VK_FORMAT_D32_SFLOAT_S8_UINT; Require(!Recorder::InCompletion(), "native multisample depth publication inside a GPU completion is not implemented"); Require(!publicationInProgress, "recursive native multisample depth publication is not implemented"); Require(!publicationFailed, "a previous native multisample depth publication store did not complete"); @@ -3251,10 +3252,17 @@ bool DepthSurface::PublishToGuest(DepthReadCause cause) { if (publicationFailure) std::rethrow_exception(publicationFailure); const bool bare = bareDepthTarget(target); const bool htile = !uniformPlaneTarget(target) && !bare; - const bool publishable = bare ? publication.size() == 1u : target.format == VK_FORMAT_D32_SFLOAT_S8_UINT && publication.size() == (htile ? 3u : 2u); + if (!stencil && !bare) { + Require(target.format != VK_FORMAT_D16_UNORM, "guest publication of a written native multisample D16 depth is not implemented"); + Require(target.format == VK_FORMAT_D32_SFLOAT && hostFormat == target.format, "sample-preserving guest publication of a written native multisample depth that the device stores in another format is not implemented"); + Require(sampleable, "guest publication of a written native multisample depth the device cannot sample is not implemented"); + Require(context.detiler != nullptr, "guest publication of a written native multisample depth needs the texture detiler"); + ApplyFastClear(); + } + const bool publishable = bare ? publication.size() == 1u : publication.size() == (stencil && htile ? 3u : 2u); Require(publishable && hostFormat == target.format, "sample-preserving guest publication of native multisample depth is not implemented for this owner"); Require(sampling.refusal.empty(), sampling.refusal); - RequireStencilProven(); + if (stencil) RequireStencilProven(); Require(!clearPending && clearGeneration == 0u && stencilClearGeneration == 0u && pendingClear == 0u, "native multisample depth publication with an unapplied clear is not implemented"); Require(sampleable && context.detiler != nullptr, "sample-preserving guest publication of native multisample depth requires sampled readback support"); const auto lease = GuestAllocations::GuestAllocationsAcquireAll_nid_postfix(); @@ -3306,7 +3314,7 @@ bool DepthSurface::PublishToGuest(DepthReadCause cause) { for (std::size_t offset = 0u; offset < result[1].size(); offset += 4u) { std::uint32_t word; std::memcpy(&word, result[1].data() + offset, 4u); - word = expandedHtileWord(word, !target.htileDepthOnly, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); + word = expandedHtileWord(word, !target.htileDepthOnly, VK_IMAGE_ASPECT_DEPTH_BIT | (stencil ? VK_IMAGE_ASPECT_STENCIL_BIT : 0u)); std::memcpy(result[1].data() + offset, &word, 4u); } } @@ -3380,6 +3388,9 @@ bool DepthSurface::PublishToGuest(DepthReadCause cause) { publication.clear(); if (superseded[0]) RetireMultisampleColorTarget(sampling.depthAlias->active); if (superseded[2]) RetireMultisampleColorTarget(sampling.stencilAlias->active); + if (!stencil && !bare) { + active->store(false, std::memory_order_release); + } return std::ranges::find(tookGuest, true) != tookGuest.end(); } diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp index fd03d811a94c..9e508fc0dfa2 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp @@ -7956,7 +7956,7 @@ void GuestBufferMemory::recordGpuCopies(std::span copies, bool ad for (const auto* region : copies) reads.emplace_back(region->begin, region->end); recorder->NoteAccess(Recorder::CommandClass::StagingIn, Recorder::Access{reads, {}, {}, VK_PIPELINE_STAGE_TRANSFER_BIT}); } - constexpr BarrierMask leading{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT}; + constexpr BarrierMask leading{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT}; if (!inRun && !Recorder::ElideCovered(Recorder::CommandClass::StagingIn, leading, covered)) { RecordMemoryBarrier(context, commands, leading.srcStage, leading.dstStage, leading.srcAccess, leading.dstAccess); Recorder::CountBarriers(Recorder::CommandClass::StagingIn); diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp index d4764b90f64b..f71a5572322e 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp @@ -4597,6 +4597,7 @@ bool ShaderResources::Revalidate(std::span shaders, ProofR provedEpoch = 0; return false; } + requireGuestBuffers(); if (EpochProofs()) { const auto epoch = GuestMemory::CollectEpoch(); const auto proof = GuestMemory::ProofSerial(); diff --git a/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_native_multisample_depth_tests.cmake b/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_native_multisample_depth_tests.cmake index f4d40eea4c65..a1b12a4beaaf 100644 --- a/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_native_multisample_depth_tests.cmake +++ b/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_native_multisample_depth_tests.cmake @@ -68,6 +68,15 @@ if(BUILD_TESTING) if(WIN32) set_tests_properties(agc_driver_native_depth_pending_units PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") endif() + add_test(NAME agc_driver_native_depth_buffer_publication COMMAND agc_driver_native_multisample_depth_tests --buffer-publication) + add_test(NAME agc_driver_native_depth_buffer_publication_items COMMAND agc_driver_native_multisample_depth_tests --buffer-publication) + add_test(NAME agc_driver_native_depth_cached_draw_publication COMMAND agc_driver_native_multisample_depth_tests --cached-draw-publication) + set_tests_properties(agc_driver_native_depth_buffer_publication agc_driver_native_depth_buffer_publication_items agc_driver_native_depth_cached_draw_publication PROPERTIES TIMEOUT 30 ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") + set_property(TEST agc_driver_native_depth_buffer_publication_items APPEND PROPERTY ENVIRONMENT "APS5_PIPELINE_DISPATCH=1") + set_property(TEST agc_driver_native_depth_cached_draw_publication APPEND PROPERTY ENVIRONMENT "APS5_DRAW_PIPELINE=1") + if(WIN32) + set_tests_properties(agc_driver_native_depth_buffer_publication agc_driver_native_depth_buffer_publication_items agc_driver_native_depth_cached_draw_publication PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") + endif() add_test(NAME agc_driver_native_depth_colour_import COMMAND agc_driver_native_multisample_depth_tests --colour-over-owner) set_tests_properties(agc_driver_native_depth_colour_import PROPERTIES TIMEOUT 30 ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") if(WIN32) diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp index 5d0cfcaf8572..571d3ba6e0de 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp @@ -1,5 +1,6 @@ #include "../PortabilitySubset.hpp" #include "prx/libSceAgcDriver/Graphics/include/Texture.hpp" +#include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hpp" #include "prx/libSceAgcDriver/Graphics/include/TextureFormat.hpp" #include "prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp" #include "prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp" @@ -404,6 +405,10 @@ void TargetRefuses(Action action, std::string_view expected) { Require(message.find(expected) != std::string::npos, "multisample target refusal did not match " + std::string(expected) + ": " + message); } +std::string_view PublicationRefusal(VkFormat format) { + return format == VK_FORMAT_D16_UNORM ? "guest publication of a written native multisample D16 depth is not implemented" : "guest publication of a written native multisample depth needs the texture detiler"; +} + void QueueTargetByteWrite(const Context& context, Recorder& recorder, std::uint64_t address, std::byte value) { auto buffer = std::make_shared(context, 4u, VK_BUFFER_USAGE_TRANSFER_DST_BIT); const auto commands = recorder.Commands(); @@ -705,7 +710,7 @@ std::vector DepthFragmentShader() { return module.Finalize(); } -std::vector DepthFeedbackFragmentShader(std::uint32_t binding, bool sampling) { +std::vector DepthFeedbackFragmentShader(std::uint32_t binding, bool sampling, float constantDepth = 0.0f, bool bufferWrite = false) { ShaderRecompiler::SpirvModule module; module.EmitCapability(spv::CapabilityShader); module.AddMemoryModel(spv::AddressingModelLogical, spv::MemoryModelGLSL450); @@ -725,10 +730,23 @@ std::vector DepthFeedbackFragmentShader(std::uint32_t binding, bo module.AddAnnotation(spv::OpDecorate, depth, spv::DecorationBuiltIn, spv::BuiltInFragDepth); const auto zero = module.Constant(spv::OpConstant, i32, 0u); const auto coordinate = module.Constant(spv::OpConstantComposite, v2, zero, zero); + const auto u32 = module.Type(spv::OpTypeInt, 32u, 0u); + std::uint32_t output = 0u; + if (bufferWrite) { + const auto values = module.Type(spv::OpTypeRuntimeArray, u32); + module.AddAnnotation(spv::OpDecorate, values, spv::DecorationArrayStride, 4u); + const auto block = module.Type(spv::OpTypeStruct, values); + module.AddAnnotation(spv::OpDecorate, block, spv::DecorationBlock); + module.AddAnnotation(spv::OpMemberDecorate, block, 0u, spv::DecorationOffset, 0u); + const auto descriptors = module.Type(spv::OpTypeArray, block, module.Constant(spv::OpConstant, u32, 1u)); + output = module.DefineGlobalVariable(module.Type(spv::OpTypePointer, spv::StorageClassStorageBuffer, descriptors), spv::StorageClassStorageBuffer); + module.AddAnnotation(spv::OpDecorate, output, spv::DecorationDescriptorSet, ShaderRecompiler::RuntimeAbi::DescriptorSet); + module.AddAnnotation(spv::OpDecorate, output, spv::DecorationBinding, static_cast(ShaderRecompiler::RuntimeAbi::Binding::Buffers)); + } const auto main = module.AllocateId(); module.AddFunction(spv::OpFunction, voidType, main, spv::FunctionControlMaskNone, module.Type(spv::OpTypeFunction, voidType)); module.AddFunction(spv::OpLabel, module.AllocateId()); - auto value = module.Constant(spv::OpConstant, f32, 0u); + auto value = module.Constant(spv::OpConstant, f32, std::bit_cast(constantDepth)); if (sampling) { const auto element = module.AllocateId(), object = module.AllocateId(), fetched = module.AllocateId(); value = module.AllocateId(); @@ -737,6 +755,12 @@ std::vector DepthFeedbackFragmentShader(std::uint32_t binding, bo module.AddFunction(spv::OpImageFetch, v4, fetched, object, coordinate, spv::ImageOperandsSampleMask, zero); module.AddFunction(spv::OpCompositeExtract, f32, value, fetched, 0u); } + if (bufferWrite) { + const auto address = module.AllocateId(); + module.AddFunction(spv::OpAccessChain, module.Type(spv::OpTypePointer, spv::StorageClassStorageBuffer, u32), address, output, zero, zero, zero); + const auto word = module.Constant(spv::OpConstant, u32, 0x12345678u); + module.AddFunction(spv::OpStore, address, word); + } module.AddFunction(spv::OpStore, depth, value); module.AddFunction(spv::OpReturn); module.AddFunction(spv::OpFunctionEnd); @@ -1548,8 +1572,7 @@ void CheckDrawFeedback() { device->Draw(state, draw, initial); device->WaitIdle(); std::array probe{}; - TargetRefuses([&] { AgcDriver::GuestMemory::Read(depth.address, probe); }, "sample-preserving guest publication"); - Require(DepthSurfaceAt(depth.address), "a refused guest read retired a native depth surface a draw wrote"); + Require(DepthSurfaceAt(depth.address), "a draw left no resident native depth surface"); reader.spirv = DepthFeedbackFragmentShader(binding, true); reader.variantId = 3u; const auto words = DepthSampleWords(depth); @@ -1581,7 +1604,347 @@ void CheckDrawFeedback() { AgcDriver::GuestMemory::Read(tested.address + depthBytes - 1u, probe); Require(probe[0] == guestByte(depthBytes - 1u), "a guest read after a depth-test-only draw did not return its guest bytes"); Require(!DepthSurfaceAt(tested.address), "a guest read left a native depth surface only depth-tested resident"); - std::puts("Native depth feedback refused through the draw resource path; a written surface refused and a depth-tested one retired on guest read"); + std::puts("Native depth feedback refused through the draw resource path; a depth-tested surface retired on guest read"); +} + +bool CheckRetiredNativeWriteRefusal(bool attachment = false) { + const auto device = OpenVulkanTestDevice(); + Require(device != nullptr, "covered native depth retirement requires Vulkan"); + const auto context = device->graphicsContext(); +#ifndef _WIN32 + if (PrepareImportWatch(context) == ImportWatch::Unwatch) { + std::puts("skipped, native depth publication requires imports that retain write tracking"); + return false; + } +#endif + constexpr VkExtent2D extent{5u, 3u}; + constexpr std::uint32_t samples = 4u; + const auto bytes = static_cast(MultisampledDepthBytes_nid_no_patch(extent, 4u, samples)); + TargetMemory memory(bytes), metadata(65536u); + std::memset(memory.Data(), 0x3c, bytes); + std::memset(metadata.Data(), 0, 65536u); + struct Cleanup { + AgcDriver::VulkanDevice& device; + ~Cleanup() { device.WaitIdle(); ClearCachedTextures(device.Device()); ClearDepthSurfaces(device.Device()); } + } cleanup{*device}; + DepthTarget depth{memory.Address(), 0u, extent, VK_FORMAT_D32_SFLOAT, 0.0f, 0u, metadata.Address(), false, samples}; + depth.depthSwizzle = 24u; + depth.iterate256 = depth.htilePipeAligned = depth.htileDepthOnly = true; + const auto firstView = DepthSurfaceView(context, depth); + NoteDepthSurfaceWrite(context, depth); + const auto words = DepthSampleWords(depth); + const auto resource = DecodeTextureResource(words); + auto held = DepthSurfaceTexture(context, words, resource, VkComponentMapping{}); + Require(held != nullptr, "covered retirement fixture has no held native view"); + const std::array partial{std::pair{memory.Address(), memory.Address() + bytes / 2u}}; + if (attachment) RetireDepthSurfaces(context.device, partial[0].first, partial[0].second - partial[0].first); + else RetireCoveredDepthSurfaces(context.device, partial, {}); + Require(DepthSurfaceView(context, depth) == firstView, "partial overwrite coverage discarded native depth"); + Require(DepthSurfaceHolds(context, resource, held.get()), "partial storage coverage invalidated native sampling"); + RetireDepthSurfaces(context.device, partial[0].first, partial[0].second - partial[0].first); + const std::array full{std::pair{memory.Address(), memory.Address() + bytes}}; + if (attachment) RetireDepthSurfaces(context.device, full[0].first, full[0].second - full[0].first); + else RetireCoveredDepthSurfaces(context.device, full, {}); + Require(!DepthSurfaceAt(depth.address), "complete overwrite coverage kept native depth attached"); + std::memset(memory.Data(), 0x5a, bytes); + AgcDriver::GuestMemory::MarkWritten(memory.Address(), bytes); + TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(memory.Address(), 1u); }, "guest writes"); + Require(std::all_of(memory.Data(), memory.Data() + bytes, [](std::byte value) { return value == std::byte{0x5a}; }), "refused retirement published obsolete guest bytes"); + std::puts("unproven retired native writes remain refused"); + return true; +} + +bool CheckPairedBufferOverwrite() { + alignas(256) static constexpr std::array code{ + 0xbfa00001u, 0xd7460002u, 0x04011204u, 0xf4040180u, 0xfa000000u, 0x8f6b8904u, + 0xbf8cc07fu, 0xf4001a83u, 0xfa000000u, 0xbf8cc07fu, 0x7e02026au, 0xd76d0000u, + 0x0401fe6bu, 0x00000100u, 0xf4080201u, 0xfa000000u, 0xbf8cc07fu, 0xe0702000u, + 0x80420102u, 0xe0702000u, 0x80420100u, 0xbf810000u}; + Shader header{}; + header.file_header = 0x34333231u; + header.version = 0x18u; + header.header_size = sizeof(Shader); + header.shader_size = sizeof(code); + header.code = code.data(); + AgcDriverRegisterShader_nid_postfix(&header); + std::unique_lock gpuLock(AgcDriver::GuestMemory::GpuMutex()); + TargetMemory warmup(65536u, true); + const auto context = SubmitDriverHtileClear(warmup.Address(), gpuLock, false); +#ifndef _WIN32 + if (PrepareImportWatch(context) == ImportWatch::Unwatch) { + std::puts("skipped, native depth publication requires imports that retain write tracking"); + return false; + } +#endif + const auto clear = [&] { ClearCachedTextures(context.device); ClearDepthSurfaces(context.device); }; + struct Cleanup { decltype(clear)& action; ~Cleanup() { action(); } } cleanup{clear}; + constexpr VkExtent2D extent{128u, 64u}; + constexpr std::uint32_t samples = 4u; + constexpr std::size_t allocationBytes = 196608u; + const auto depthBytes = MultisampledDepthBytes_nid_no_patch(extent, 4u, samples); + const auto driverDevice = AgcDriver::DriverDetail::DriverTestAccess::GetDevice(); + ShaderRecompiler::RecompileResult vertex, pixel; + vertex.spirv = DepthVertexShader(); + vertex.variantId = 1u; + pixel.spirv = DepthFeedbackFragmentShader(ShaderRecompiler::RuntimeAbi::FirstImageBinding, false); + pixel.variantId = 2u; + const std::array stages{{{ShaderRecompiler::ShaderStage::Vertex, &vertex, 0u}, {ShaderRecompiler::ShaderStage::Fragment, &pixel, PixelPushOffset(0u, driverDevice->Target())}}}; + const auto render = [&](const DepthTarget& depth) { + State state{}; + state.stages = {ShaderPath::Vertex, 0u, 32u, 32u, std::nullopt, std::nullopt}; + state.depth = depth; + state.depthTest = state.depthWrite = true; + state.depthCompare = VK_COMPARE_OP_ALWAYS; + state.renderExtent = extent; + state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + state.viewport = {0.0f, 0.0f, static_cast(extent.width), static_cast(extent.height), 0.0f, 1.0f}; + state.negativeOneToOne = false; + state.scissor = {{0, 0}, extent}; + state.cullMode = VK_CULL_MODE_NONE; + state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + state.samples = samples; + driverDevice->Draw(state, {0u, 3u, 0u, 1u, 0u, false}, stages); + driverDevice->WaitIdle(); + }; + for (const auto wave : {32u, 64u}) for (const auto groups : {1u, 96u}) { + TargetMemory memory(1u << 20u, true), control(65536u, true); + std::memset(memory.Data() + depthBytes, 0, HtileMetadataBytes(extent)); + DepthTarget depth{memory.Address(), 0u, extent, VK_FORMAT_D32_SFLOAT, 0.0f, 0u, memory.Address() + depthBytes, false, samples}; + depth.depthSwizzle = 24u; + depth.iterate256 = depth.htilePipeAligned = depth.htileDepthOnly = true; + render(depth); + Require(DepthSurfaceAt(depth.address), "paired fill fixture has no native depth attachment"); + const auto words = DepthSampleWords(depth); + auto held = DepthSurfaceTexture(context, words, DecodeTextureResource(words), VkComponentMapping{}); + Require(held != nullptr, "paired fill fixture has no sampled native depth"); + const std::uint32_t value = 0x5a5a5a5au; + std::memcpy(control.Data(), &value, 4u); + const auto source = control.Address(); + std::memcpy(control.Data() + 8u, &source, 8u); + const std::array descriptor{static_cast(memory.Address()), static_cast(memory.Address() >> 32u) | (4u << 16u), allocationBytes / 4u, 0x00014204u}; + std::memcpy(control.Data() + 16u, descriptor.data(), sizeof(descriptor)); + const auto shader = reinterpret_cast(code.data()); + std::vector commands; + const auto append = [&](std::vector packet) { commands.insert(commands.end(), packet.begin(), packet.end()); }; + append(DriverPm4Packet(0x76u, {0x20cu, static_cast(shader >> 8u)})); + append(DriverPm4Packet(0x76u, {0x20du, static_cast(shader >> 40u)})); + append(DriverPm4Packet(0x76u, {0x207u, 256u, 1u, 1u})); + append(DriverPm4Packet(0x76u, {0x213u, (4u << 1u) | 0x80u})); + append(DriverPm4Packet(0x76u, {0x240u, static_cast(control.Address() + 8u), static_cast(control.Address() >> 32u), static_cast(control.Address() + 16u), static_cast(control.Address() >> 32u)})); + append(DriverPm4Packet(0x15u, {groups, 1u, 1u, 0x41u | (wave == 32u ? 0x8000u : 0u)})); + Packet packet{commands.data(), static_cast(commands.size()), 0u, {}}; + std::printf("paired fill wave=%u groups=%u first submission\n", wave, groups); + Require(sceAgcDriverSubmitDcb(&packet) == 0, "paired fill submission failed"); + gpuLock.unlock(); + try { AgcDriverWaitIdle_nid_postfix(); } catch (...) { gpuLock.lock(); throw; } + gpuLock.lock(); + AgcDriver::GuestMemory::FlushGpuWrites(memory.Address(), allocationBytes); + Require(!DepthSurfaceAt(depth.address), "paired complete buffer fill retained obsolete native depth ownership"); + RequireNoResidentDepthRead_nid_no_patch(depth.address, 1u); + RequireNoResidentDepthRead_nid_no_patch(depth.htileAddress, 1u); + const auto checkContents = [&] { + for (std::size_t offset = 0u; offset < allocationBytes; ++offset) { + const auto expected = offset < static_cast(groups) * 2048u ? std::byte{0x5a} : offset < depthBytes ? std::byte{0} : offset < depthBytes + HtileMetadataBytes(extent) ? static_cast(0xfffc000fu >> (8u * (offset % 4u))) : std::byte{0xa5}; + Require(memory.Data()[offset] == expected, "native buffer alias lost published or stored bytes at " + std::to_string(offset)); + } + Require(std::all_of(memory.Data() + allocationBytes, memory.Data() + (1u << 20u), [](std::byte byte) { return byte == std::byte{0xa5}; }), "native buffer alias wrote past its descriptor range"); + }; + checkContents(); + std::memset(memory.Data() + depthBytes, 0, HtileMetadataBytes(extent)); + AgcDriver::GuestMemory::MarkWritten(depth.htileAddress, static_cast(HtileMetadataBytes(extent))); + render(depth); + Require(DepthSurfaceAt(depth.address), "cached paired fill has no replacement native depth"); + auto fresh = DepthSurfaceTexture(context, words, DecodeTextureResource(words), VkComponentMapping{}); + Require(fresh != nullptr, "cached alias fixture is not sampling-eligible after host import"); + const auto retiredBefore = AgcDriver::DriverDetail::DrawPipeline::Queue0().Retired(); + std::printf("paired fill wave=%u groups=%u cached submission\n", wave, groups); + Require(sceAgcDriverSubmitDcb(&packet) == 0, "cached paired fill submission failed"); + gpuLock.unlock(); + try { AgcDriverWaitIdle_nid_postfix(); } catch (...) { gpuLock.lock(); throw; } + gpuLock.lock(); + Require(!DepthSurfaceAt(depth.address), "cached paired fill retained native depth ownership"); + RequireNoResidentDepthRead_nid_no_patch(depth.address, 1u); + RequireNoResidentDepthRead_nid_no_patch(depth.htileAddress, 1u); + checkContents(); + const auto retired = AgcDriver::DriverDetail::DrawPipeline::Queue0().Retired() - retiredBefore; + if (const auto* pipeline = std::getenv("APS5_PIPELINE_DISPATCH"); pipeline != nullptr && pipeline[0] != '0') Require(retired != 0u, "paired fill did not exercise a dispatch commit item"); + std::printf("paired fill wave=%u groups=%u cached submission retired %llu commit items\n", wave, groups, static_cast(retired)); + held.reset(); + fresh.reset(); + clear(); + } + std::puts("paired GPU fill overwrites native depth and metadata in wave32 and wave64"); + return true; +} + +bool CheckCachedDrawPublication() { + const auto device = OpenVulkanTestDevice(); + Require(device != nullptr, "cached native depth publication requires Vulkan"); +#ifndef _WIN32 + if (PrepareImportWatch(device->graphicsContext()) == ImportWatch::Unwatch) { + std::puts("skipped, native depth publication requires imports that retain write tracking"); + return false; + } +#endif + constexpr VkExtent2D extent{5u, 3u}; + constexpr std::uint32_t samples = 4u; + const auto bytes = static_cast(MultisampledDepthBytes_nid_no_patch(extent, 4u, samples)); + TargetMemory memory(1u << 20u, true), otherMemory(1u << 20u); + std::memset(memory.Data() + bytes, 0, 65536u); + struct Cleanup { + AgcDriver::VulkanDevice& device; + ~Cleanup() { device.WaitIdle(); ClearCachedTextures(device.Device()); ClearDepthSurfaces(device.Device()); } + } cleanup{*device}; + DepthTarget depth{memory.Address(), 0u, extent, VK_FORMAT_D32_SFLOAT, 0.0f, 0u, memory.Address() + bytes, false, samples}; + depth.depthSwizzle = 24u; + depth.iterate256 = depth.htilePipeAligned = depth.htileDepthOnly = true; + State state{}; + state.stages = {ShaderPath::Vertex, 0u, 32u, 32u, std::nullopt, std::nullopt}; + state.depth = depth; + state.depthTest = state.depthWrite = true; + state.depthCompare = VK_COMPARE_OP_ALWAYS; + state.renderExtent = extent; + state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + state.viewport = {0.0f, 0.0f, static_cast(extent.width), static_cast(extent.height), 0.0f, 1.0f}; + state.negativeOneToOne = false; + state.scissor = {{0, 0}, extent}; + state.cullMode = VK_CULL_MODE_NONE; + state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + state.samples = samples; + ShaderRecompiler::RecompileResult vertex, producer, writer; + vertex.spirv = DepthVertexShader(); + vertex.variantId = 1u; + constexpr auto binding = ShaderRecompiler::RuntimeAbi::FirstImageBinding; + producer.spirv = DepthFeedbackFragmentShader(binding, false); + producer.variantId = 2u; + writer.spirv = DepthFeedbackFragmentShader(binding, false, 0.0f, true); + writer.variantId = 3u; + ShaderRecompiler::DescriptorBinding buffer{}; + buffer.kind = ShaderRecompiler::DescriptorKind::StorageBuffer; + buffer.role = ShaderRecompiler::DescriptorRole::GuestBuffers; + buffer.descriptorSet = ShaderRecompiler::RuntimeAbi::DescriptorSet; + buffer.binding = static_cast(ShaderRecompiler::RuntimeAbi::Binding::Buffers); + buffer.count = 1u; + buffer.guestDescriptor = {static_cast(memory.Address()), static_cast(memory.Address() >> 32u) | (4u << 16u), 196608u / 4u, 0x00014204u}; + buffer.bufferWritten = {true}; + buffer.bufferRead = {false}; + writer.bindings.push_back(std::move(buffer)); + const auto push = PixelPushOffset(0u, device->Target()); + const std::array writing{{{ShaderRecompiler::ShaderStage::Vertex, &vertex, 0u}, {ShaderRecompiler::ShaderStage::Fragment, &writer, push}}}; + const std::array producing{{{ShaderRecompiler::ShaderStage::Vertex, &vertex, 0u}, {ShaderRecompiler::ShaderStage::Fragment, &producer, push}}}; + const AgcDriver::Pm4::DrawParameters draw{0u, 3u, 0u, 1u, 0u, false}; + auto other = depth; + other.address = otherMemory.Address(); + other.htileAddress = 0u; + other.samples = 1u; + other.depthSwizzle = 0u; + auto onePixel = state; + onePixel.depth = other; + onePixel.samples = 1u; + onePixel.scissor.extent = {1u, 1u}; + std::shared_ptr recipe; + device->Draw(onePixel, draw, writing, {}, &recipe); + device->WaitIdle(); + auto resources = recipe != nullptr ? recipe->templateRef.lock() : nullptr; + Require(resources != nullptr && resources->Reusable(), "cached draw fixture produced no reusable template"); + AgcDriver::GuestMemory::BumpCollectEpoch(); + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + Require(resources->Revalidate(writing), "cached draw fixture could not prime its resource proof"); + } + std::memset(memory.Data() + bytes, 0, 65536u); + AgcDriver::GuestMemory::MarkWritten(depth.htileAddress, static_cast(HtileMetadataBytes(extent))); + AgcDriver::GuestMemory::BumpCollectEpoch(); + device->Draw(state, draw, producing); + device->WaitIdle(); + Require(DepthSurfaceAt(depth.address), "cached draw fixture produced no native depth owner"); + const auto sampledWords = DepthSampleWords(depth); + auto held = DepthSurfaceTexture(device->graphicsContext(), sampledWords, DecodeTextureResource(sampledWords), VkComponentMapping{}); + Require(held != nullptr, "cached draw fixture produced no sampling-eligible native depth"); + { + std::lock_guard gpu(AgcDriver::GuestMemory::GpuMutex()); + Require(resources->Revalidate(writing), "publishing native depth invalidated the imported draw buffer"); + Require(!DepthSurfaceAt(depth.address), "cached draw proof retained a native depth owner"); + } + const auto replay = device->DrawFromRecipe(onePixel, draw, writing, {}, recipe); + if (replay == AgcDriver::RecipeOutcome::Rebuild) device->Draw(onePixel, draw, writing); + device->WaitIdle(); + AgcDriver::GuestMemory::FlushGpuWrites(memory.Address(), 4u); + std::uint32_t value = 0u; + std::memcpy(&value, memory.Data(), sizeof(value)); + Require(value == 0x12345678u, "cached draw did not store through the published buffer"); + std::printf("Cached draw proof published native depth; buffer store checked, recipe %s\n", replay == AgcDriver::RecipeOutcome::Recorded ? "recorded" : "rebuilt"); + return true; +} + +void CheckWrittenPublication(std::uint32_t samples, VkExtent2D extent, bool depthOnly, std::uint32_t pipeBankXor) { + const auto device = OpenVulkanTestDevice(); + Require(device != nullptr, "native depth publication requires Vulkan"); + const auto depthBytes = static_cast(MultisampledDepthBytes_nid_no_patch(extent, 4u, samples)); + const auto metadataBytes = static_cast(HtileMetadataBytes(extent)); + TargetMemory memory(depthBytes), metadata(65536u); + std::memset(metadata.Data(), 0, 65536u); + const auto guestByte = [](std::size_t offset) { return static_cast(offset * 7u + 3u); }; + for (std::size_t offset = 0u; offset < depthBytes; ++offset) memory.Data()[offset] = guestByte(offset); + DepthTarget depth{memory.Address(), 0u, extent, VK_FORMAT_D32_SFLOAT, 0.0f, 0u, metadata.Address(), false, samples}; + depth.depthSwizzle = 24u; + depth.pipeBankXor = pipeBankXor; + depth.htileDepthOnly = depthOnly; + depth.iterate256 = depth.htilePipeAligned = true; + struct Cleanup { + AgcDriver::VulkanDevice& device; + ~Cleanup() { device.WaitIdle(); ClearCachedTextures(device.Device()); ClearDepthSurfaces(device.Device()); } + } cleanup{*device}; + State state{}; + state.stages = {ShaderPath::Vertex, 0u, 32u, 32u, std::nullopt, std::nullopt}; + state.depth = depth; + state.depthTest = state.depthWrite = true; + state.depthCompare = VK_COMPARE_OP_ALWAYS; + state.renderExtent = extent; + state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + state.viewport = {0.0f, 0.0f, static_cast(extent.width), static_cast(extent.height), 0.0f, 1.0f}; + state.negativeOneToOne = false; + state.scissor = {{0, 0}, extent}; + state.cullMode = VK_CULL_MODE_NONE; + state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + state.samples = samples; + ShaderRecompiler::RecompileResult vertex, producer; + vertex.spirv = DepthVertexShader(); + vertex.variantId = 1u; + constexpr float written = 0.375f; + producer.spirv = DepthFeedbackFragmentShader(ShaderRecompiler::RuntimeAbi::FirstImageBinding, false, written); + producer.variantId = 2u; + const AgcDriver::Pm4::DrawParameters draw{0u, 3u, 0u, 1u, 0u, false}; + const std::array shaders{{{ShaderRecompiler::ShaderStage::Vertex, &vertex, 0u}, {ShaderRecompiler::ShaderStage::Fragment, &producer, PixelPushOffset(0u, device->Target())}}}; + device->Draw(state, draw, shaders); + device->WaitIdle(); + Require(DepthSurfaceAt(depth.address), "a draw left no resident native depth surface"); + std::array probe{}; + AgcDriver::GuestMemory::Read(depth.address, probe); + Require(!DepthSurfaceAt(depth.address), "publishing a written native depth surface left it resident"); + const MultisampleTextureLayout layout(TextureTileMode::kZ64KBX, 4u, samples, extent.width, extent.height, 1u, pipeBankXor); + Require(layout.Bytes() == depthBytes, "published native depth layout differs from its guarded range"); + std::vector covered(depthBytes); + const auto expected = std::bit_cast(written); + for (std::uint32_t y = 0u; y < extent.height; ++y) { + for (std::uint32_t x = 0u; x < extent.width; ++x) { + for (std::uint32_t sample = 0u; sample < samples; ++sample) { + const auto offset = static_cast(layout.Offset(x, y, 0u, sample)); + std::uint32_t value = 0u; + std::memcpy(&value, memory.Data() + offset, sizeof(value)); + Require(value == expected, "a published native depth sample lost its drawn value"); + for (std::size_t byte = 0u; byte < sizeof(value); ++byte) covered[offset + byte] = true; + } + } + } + for (std::size_t offset = 0u; offset < depthBytes; ++offset) Require(covered[offset] || memory.Data()[offset] == guestByte(offset), "publishing native depth changed guest bytes outside its samples"); + const std::uint32_t htile = depthOnly ? 0xfffc000fu : 0xfffff00fu; + for (std::size_t offset = 0u; offset < metadataBytes; offset += 4u) { + std::uint32_t word = 0u; + std::memcpy(&word, metadata.Data() + offset, sizeof(word)); + Require(word == htile, "publishing native depth did not expand its HTILE"); + } + std::printf("Native depth publication samples=%u extent=%ux%u depthOnly=%u xor=0x%x: samples, HTILE and padding checked\n", samples, extent.width, extent.height, depthOnly, pipeBankXor); } void CheckDepthAttachmentAlias() { @@ -1742,8 +2105,8 @@ void CheckDepthTarget(Context context, VkFormat format, std::uint32_t fragments, Require(DepthSurfaceView(context, target) == view, "native depth attachment did not reuse its image"); NoteDepthSurfaceWrite(context, target); std::array beforeSampling{}; - TargetRefuses([&] { AgcDriver::GuestMemory::Read(target.address + bytes - 1u, beforeSampling); }, "sample-preserving guest publication"); - TargetRefuses([&] { RequireNoMultisampleTarget(target.htileAddress + metadataBytes - 1u, 1u, "a DMA copy"); }, "sample-preserving guest publication"); + TargetRefuses([&] { AgcDriver::GuestMemory::Read(target.address + bytes - 1u, beforeSampling); }, PublicationRefusal(format)); + TargetRefuses([&] { RequireNoMultisampleTarget(target.htileAddress + metadataBytes - 1u, 1u, "a DMA copy"); }, PublicationRefusal(format)); const auto words = DepthSampleWords(target); auto texture = CachedSampledTexture(context, words); auto arrayTexture = CachedSampledTexture(context, words, VK_IMAGE_VIEW_TYPE_2D_ARRAY); @@ -1890,22 +2253,22 @@ void CheckDepthTarget(Context context, VkFormat format, std::uint32_t fragments, Require(AgcDriver::GuestMemory::CollectWritesUncached(target.htileAddress, static_cast(metadataBytes)) > beforeImport, "HTILE import window did not stamp its changed page"); } if (completionCandidate && fault == ClearFault::None) { - TargetRefuses([&] { + if (format == VK_FORMAT_D32_SFLOAT) TargetRefuses([&] { auto uploadContext = context; uploadContext.hostImportAlignment = 0; GuestBufferMemory buffer(uploadContext); buffer.AddWritable(target.htileAddress, metadataBytes); buffer.Upload(false); - }, "sample-preserving guest publication"); + }, "guest publication of a written native multisample depth needs the texture detiler"); const auto accepted = std::pair{target.htileAddress, static_cast(metadataBytes)}; RequireNoResidentDepthRead_nid_no_patch(target.htileAddress, metadataBytes, accepted); - TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(target.address, bytes, accepted); }, "sample-preserving guest publication"); - TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(target.htileAddress, metadataBytes + 1u, accepted); }, "sample-preserving guest publication"); + if (format == VK_FORMAT_D32_SFLOAT) TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(target.address, bytes, accepted); }, "guest publication of a written native multisample depth needs the texture detiler"); + if (format == VK_FORMAT_D32_SFLOAT) TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(target.htileAddress, metadataBytes + 1u, accepted); }, "guest publication of a written native multisample depth needs the texture detiler"); Require(DepthSurfaceAt(target.address), "an accepted HTILE buffer access retired its native depth owner"); } if (completionCandidate) ArmHtileDepthClear(target.htileAddress, static_cast(metadataBytes)); - if (completionCandidate && fault == ClearFault::None) { - TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(target.htileAddress, metadataBytes, std::pair{target.htileAddress, static_cast(metadataBytes)}); }, "sample-preserving guest publication"); + if (completionCandidate && fault == ClearFault::None && format == VK_FORMAT_D32_SFLOAT) { + TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(target.htileAddress, metadataBytes, std::pair{target.htileAddress, static_cast(metadataBytes)}); }, "guest publication of a written native multisample depth needs the texture detiler"); } if (fault == ClearFault::Overlap) NoteHtileDepthClear(target.htileAddress, static_cast(metadataBytes), nativeBytes); if (fault == ClearFault::SupersededClear) { @@ -1977,19 +2340,19 @@ void CheckDepthTarget(Context context, VkFormat format, std::uint32_t fragments, Require(std::all_of(memory.Data(), memory.Data() + bytes, [](auto value) { return value == std::byte{0xa5}; }), "native depth sampling silently published guest memory"); std::array probe{}; for (const auto address : {target.address, target.address + bytes - 1u, target.htileAddress, target.htileAddress + metadataBytes - 1u}) { - TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(address, 1u); }, "sample-preserving guest publication"); - TargetRefuses([&] { AgcDriver::GuestMemory::Read(address, probe); }, "sample-preserving guest publication"); - TargetRefuses([&] { RequireNoMultisampleTarget(address, 1u, "a DMA copy"); }, "sample-preserving guest publication"); + TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(address, 1u); }, PublicationRefusal(format)); + TargetRefuses([&] { AgcDriver::GuestMemory::Read(address, probe); }, PublicationRefusal(format)); + TargetRefuses([&] { RequireNoMultisampleTarget(address, 1u, "a DMA copy"); }, PublicationRefusal(format)); } TargetMemory unrelated(65536u); AgcDriver::GuestMemory::Read(unrelated.Address(), probe); Require(probe[0] == std::byte{0xa5}, "resident depth guard blocked an unrelated read"); auto alias = target; alias.htileAddress += 65536u; - TargetRefuses([&] { DepthSurfaceView(context, alias); }, "sample-preserving guest publication"); + TargetRefuses([&] { DepthSurfaceView(context, alias); }, PublicationRefusal(format)); alias = target; alias.htileDepthOnly = !target.htileDepthOnly; - TargetRefuses([&] { DepthSurfaceView(context, alias); }, "sample-preserving guest publication"); + TargetRefuses([&] { DepthSurfaceView(context, alias); }, PublicationRefusal(format)); auto resource = DecodeTextureResource(words); for (std::uint32_t field = 0u; field < 18u; ++field) { auto changed = resource; @@ -2069,8 +2432,8 @@ void CheckUnwrittenGuestAccess(Context context, VkFormat format, std::uint32_t f view = rebound; } NoteDepthSurfaceWrite(context, target); - TargetRefuses([&] { AgcDriver::GuestMemory::Read(target.address, probe); }, "sample-preserving guest publication"); - TargetRefuses([&] { RequireNoMultisampleTarget(target.htileAddress, 1u, "a DMA copy"); }, "sample-preserving guest publication"); + TargetRefuses([&] { AgcDriver::GuestMemory::Read(target.address, probe); }, PublicationRefusal(format)); + TargetRefuses([&] { RequireNoMultisampleTarget(target.htileAddress, 1u, "a DMA copy"); }, PublicationRefusal(format)); Require(resident(), "a refused guest access retired a written native depth surface"); for (std::size_t offset = 0u; offset < bytes; ++offset) Require(memory.Data()[offset] == guestByte(offset), "retiring an unwritten native depth surface changed its guest bytes"); Require(std::all_of(metadata.Data(), metadata.Data() + metadataBytes, [](std::byte value) { return value == std::byte{0}; }), "retiring an unwritten native depth surface changed its HTILE"); @@ -3311,7 +3674,7 @@ void CheckRetirement(Context context, VkFormat format, std::uint32_t samples, st Require(MultisampleTargetView(context, color) != VK_NULL_HANDLE, "retirement fixture has no color attachment"); recorder.Sync(); const auto guarded = [&] { - TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(target.address, 1u); }, "sample-preserving"); + TargetRefuses([&] { RequireNoResidentDepthRead_nid_no_patch(target.address, 1u); }, PublicationRefusal(format)); }; { GuestAllocations::Mutation mutation; @@ -5338,6 +5701,16 @@ int main(int argc, char** argv) { std::printf("Native depth initial owner cases checked=%u unavailable=%u\n", checked, unavailable); return checked == 0u ? VulkanTestSkipped : 0; } + if (argc == 2 && std::string_view(argv[1]) == "--cached-draw-publication") { + const bool checked = CheckCachedDrawPublication(); + AgcDriver::DriverDetail::DriverTestAccess::Stop(); + return checked ? 0 : VulkanTestSkipped; + } + if (argc == 2 && std::string_view(argv[1]) == "--buffer-publication") { + const bool checked = CheckRetiredNativeWriteRefusal() && CheckRetiredNativeWriteRefusal(true) && CheckPairedBufferOverwrite(); + AgcDriver::DriverDetail::DriverTestAccess::Stop(); + return checked ? 0 : VulkanTestSkipped; + } const auto context = device->GetContext(); if (argc == 2 && std::string_view(argv[1]) == "--publication") { std::unique_lock lock(AgcDriver::GuestMemory::GpuMutex()); @@ -5379,6 +5752,13 @@ int main(int argc, char** argv) { return 0; } CheckDrawFeedback(); + if (argc == 1) { + for (const auto samples : {2u, 4u, 8u}) { + if (!DepthSupported(context, VK_FORMAT_D32_SFLOAT, samples)) continue; + CheckWrittenPublication(samples, {5u, 3u}, false, 0u); + CheckWrittenPublication(samples, {70u, 67u}, true, 0x8c00u); + } + } if (argc == 1) CheckDepthAttachmentAlias(); if (argc == 1) CheckStorageAliasRetirement(); std::unique_lock lock(AgcDriver::GuestMemory::GpuMutex()); diff --git a/docs/dev/debt/changes/fix-cached-native-depth-publication.md b/docs/dev/debt/changes/fix-cached-native-depth-publication.md new file mode 100644 index 000000000000..1b864af29fc1 --- /dev/null +++ b/docs/dev/debt/changes/fix-cached-native-depth-publication.md @@ -0,0 +1,5 @@ +# libSceAgcDriver + +## change [Shader buffer access to native multisample targets] + +- [Shader buffer access to native multisample targets](../../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp) - Shader buffer descriptors retain the existing native color/depth guest-access refusal during preparation, completion and binding, including cached bindings and moved draw ranges. The check covers logical descriptor ranges, not larger import windows; dynamically addressed BDA heaps and vertex/index input snapshots remain outside this check. Native color buffer publication and console equivalence remain unimplemented or unmeasured; supported D32/D32S8 publication is described above. diff --git a/docs/dev/debt/changes/fix-published-native-depth-retirement.md b/docs/dev/debt/changes/fix-published-native-depth-retirement.md new file mode 100644 index 000000000000..ac990b213a0b --- /dev/null +++ b/docs/dev/debt/changes/fix-published-native-depth-retirement.md @@ -0,0 +1,13 @@ +# libSceAgcDriver + +## add Functional + +- [Native depth owner reclamation](../../../core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp): written HTILE D32 multisampled owners without completed guest publication remain cached unless their guest allocations are released; bounded eviction and reconstruction from arbitrary guest bytes are not implemented. Publication makes HTILE D32 owners inactive only after both planes commit; reclamation follows the inactive, unwritten and released-view checks. Console decompression bytes remain unmeasured. Bare D32 and D32S8 owner retention follows the publication rules below. + +## change [Native D32S8 guest publication] + +- [Native depth guest publication](../../../core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp) overwrites a late CPU store only when it matches the snapshot and the host changes that byte; other late stores are kept and the read throws. When a written page holds the snapshot byte, the host result differs and no driver store covers it, reuse by a draw input, storage image, colour or depth target takes the guest's byte (inferred); CPU, DMA, texture and buffer reads throw. HTILE is published expanded; stencil is retiled with the depth XOR. HTILE D32 retires after both planes commit. Bare D32 and D32S8 retire on reuse that takes a guest byte. A new depth target over a retained owner throws; retained host bytes are rebased and a plane with a guest byte or hole throws at next use. D16, unproven clears, resident colour aliases, colour acquisition mid-read, pending storage-image units and in-completion publication throw. + +## change [Native multisampled D32S8 depth without HTILE] + +- [Native multisampled D32S8 depth without HTILE](../../../core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp) is imported when its depth plane repeats one float in [0, 1], its separate stencil plane repeats one byte and no multisampled colour target covers either plane; the host image starts at those values and the sampled descriptor must name no metadata, whose pipe-aligned and ITERATE_256 bits are then not compared. The depth plane is sampled as a 32-bit float, the stencil plane through the R8_UINT descriptor of the stencil plane sampling entry below. That every sample then holds them is inferred from the uncompressed layout, not measured on the console. A written owner is published on a guest read as the native depth guest publication entry above describes, with no HTILE to expand. Other planes import once a stencil readback shows the first draw (depth ALWAYS with writes, stencil ALWAYS/REPLACE, mask 0xff) reached every sample; else they throw, as D16 without HTILE does.