diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp index 169e9f7d93a9..0bc0cb34b414 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp @@ -643,6 +643,7 @@ DrawVerdict Driver::draw(QueueState& queue, std::span packe vertexInfos[i]->paClVsOutCntl = PositionExportLayout(program.snapshot.get(), program.codeOffset, program.binary.code, readRegister(queue.context, 0x207), program.tailContinuation.get()) | graphics.layerExports | graphics.viewportExports; vertexInfos[i]->depthRemapMode = graphics.depthRemap.mode; Graphics::ApplyPointSize(graphics, *vertexInfos[i]); + Graphics::ApplyInstanceStepRate(graphics, *vertexInfos[i]); } }; if (!registerKey) { @@ -905,6 +906,7 @@ DrawVerdict Driver::finishDraw(DrawTail& tail, PerformanceTimer& timing) { vertexInfos[i]->paClVsOutCntl = PositionExportLayout(program.snapshot.get(), program.codeOffset, program.binary.code, tail.reg207, program.tailContinuation.get()) | graphics.layerExports | graphics.viewportExports; vertexInfos[i]->depthRemapMode = graphics.depthRemap.mode; Graphics::ApplyPointSize(graphics, *vertexInfos[i]); + Graphics::ApplyInstanceStepRate(graphics, *vertexInfos[i]); } }; const auto fold = [&](const ShaderRecompiler::RecompileResult& main, Pm4::DrawParameters& parameters) { FoldDrawOffsets(main, programs.front(), parameters); }; @@ -1525,6 +1527,7 @@ void Driver::restartFinishedDraw(DrawTail& tail) { tail.vertexInfos[i]->paClVsOutCntl = PositionExportLayout(program.snapshot.get(), program.codeOffset, program.binary.code, tail.reg207, program.tailContinuation.get()) | graphics.layerExports | graphics.viewportExports; tail.vertexInfos[i]->depthRemapMode = graphics.depthRemap.mode; Graphics::ApplyPointSize(graphics, *tail.vertexInfos[i]); + Graphics::ApplyInstanceStepRate(graphics, *tail.vertexInfos[i]); } tail.shaderMemory = std::make_unique(tail.memory, &queryPendingWrite, &observePendingWrite, hookWaitCounter(), &QueryPendingSpan); } diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp index a86438247271..f563c8a763ee 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp @@ -60,6 +60,7 @@ void Driver::lookupDraw(const Submission& submission, const std::shared_ptr(vertex.pointSize)); mix(std::bit_cast(vertex.pointSizeMin)); mix(std::bit_cast(vertex.pointSizeMax)); + mix(vertex.instanceStepRate); for (std::uint32_t r = 0; r < vertex.resourcesNum; ++r) { for (const auto field : vertex.resources[r].fields) mix(field); const auto& destination = vertex.resourcesDst[r]; diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp index 462af75f23e7..a11917c8494a 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp @@ -214,7 +214,7 @@ void Driver::traceDrawKeyLookup(const std::array& components, } bool Driver::sameVertexInfo(const ShaderRecompiler::ShaderVertexStageInfo& a, const ShaderRecompiler::ShaderVertexStageInfo& b) { - if (a.resourcesNum != b.resourcesNum || a.fetchAttribReg != b.fetchAttribReg || a.fetchBufferReg != b.fetchBufferReg || a.fetchEmbedded != b.fetchEmbedded || a.paClVsOutCntl != b.paClVsOutCntl || a.pointList != b.pointList || a.pointSize != b.pointSize || a.pointSizeMin != b.pointSizeMin || a.pointSizeMax != b.pointSizeMax) return false; + if (a.resourcesNum != b.resourcesNum || a.fetchAttribReg != b.fetchAttribReg || a.fetchBufferReg != b.fetchBufferReg || a.fetchEmbedded != b.fetchEmbedded || a.paClVsOutCntl != b.paClVsOutCntl || a.pointList != b.pointList || a.pointSize != b.pointSize || a.pointSizeMin != b.pointSizeMin || a.pointSizeMax != b.pointSizeMax || a.instanceStepRate != b.instanceStepRate) return false; if (a.depthRemapMode != b.depthRemapMode) return false; for (std::uint32_t i = 0; i < a.resourcesNum && i < a.resources.size(); ++i) { if (a.resources[i].fields != b.resources[i].fields) return false; diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp index 0ad3de30274f..b028e433439a 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp @@ -2655,6 +2655,7 @@ std::vector PrepareGraphicsStages(const DrawDecode& decod vertex->paClVsOutCntl = PositionExportLayout(program.snapshot.get(), program.codeOffset, program.binary.code, decoded.state.paClVsOutCntl, program.tailContinuation.get()) | decoded.state.layerExports | decoded.state.viewportExports; vertex->depthRemapMode = decoded.state.depthRemap.mode; Graphics::ApplyPointSize(decoded.state, *vertex); + Graphics::ApplyInstanceStepRate(decoded.state, *vertex); } ShaderRecompiler::RecompileRequest request{program.binary, {wave, program.firstUserSgpr, program.userData, {}, fragment ? std::optional(decoded.pixel) : std::nullopt, vertex, memory, RegisteredFloatMode(*program.snapshot)}, target, {0, 0, offset, room}, ShaderRecompiler::GraphicsCompileContext{program.firstUserSgpr, linked, Graphics::StageMeshConfiguration(decoded.state.stages, program.binary.stage), decoded.state.stages.tessellation, {}}}; std::vector key; diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp index 100d1b435629..49de442d3f3e 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp @@ -44,6 +44,7 @@ struct ShaderStages { std::uint32_t hullWaveSize = 64; std::optional tessellationGeometry; bool legacyVertex = false; + std::uint32_t instanceStepRate = 1; }; inline constexpr std::uint16_t UnclampedBlendMask = 0xffffu; @@ -245,6 +246,7 @@ VkLogicOp LogicOpFromRop(std::uint8_t rop); ShaderStages DecodeShaderStages(const QueueState& queue, bool vertexWorkgroup = false); void ApplyPointSize(const State& state, ShaderRecompiler::ShaderVertexStageInfo& vertex); +void ApplyInstanceStepRate(const State& state, ShaderRecompiler::ShaderVertexStageInfo& vertex); State DecodeState(const QueueState& queue, bool vertexWorkgroup = false); void ApplyDepthRemap(const Context& context, State& state); void ApplyViewportIndex(const Context& context, State& state); diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cpp index 40151aece0c2..c409b0e12828 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cpp @@ -48,7 +48,7 @@ static_assert(sizeof(VkVertexInputBindingDescription) == 12, "VkVertexInputBindi static_assert(sizeof(VkVertexInputAttributeDescription) == 16, "VkVertexInputAttributeDescription changed: update the recipe codec"); #if defined(__linux__) && defined(__x86_64__) && defined(__GLIBCXX__) static_assert(sizeof(State) == 1008, "State changed: update CanonicalPipelineState and the recipe codec"); -static_assert(sizeof(ShaderStages) == 164, "ShaderStages changed: update the recipe codec"); +static_assert(sizeof(ShaderStages) == 168, "ShaderStages changed: update the recipe codec"); static_assert(sizeof(ShaderRecompiler::MeshConfiguration) == 40, "MeshConfiguration changed: update the recipe codec"); static_assert(sizeof(ShaderRecompiler::TessellationConfiguration) == 40, "TessellationConfiguration changed: update the recipe codec"); #endif diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp index 3849a708c1da..6b13e026964d 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp @@ -1332,6 +1332,10 @@ std::array PixelSampleLocations(const State& state, const Shad return locations; } +void ApplyInstanceStepRate(const State& state, ShaderRecompiler::ShaderVertexStageInfo& vertex) { + vertex.instanceStepRate = state.stages.legacyVertex ? state.stages.instanceStepRate : 1u; +} + void ApplyPointSize(const State& state, ShaderRecompiler::ShaderVertexStageInfo& vertex) { if (!state.vertexPoints && !(state.stages.mesh.has_value() && state.stages.mesh->outputPrimitiveSize == 1u)) return; vertex.paClVsOutCntl |= state.paClVsOutCntl & (1u << 16u); @@ -1390,12 +1394,16 @@ ShaderStages DecodeShaderStages(const QueueState& queue, bool vertexWorkgroup) { }; if (path == ShaderPath::Vertex && ShaderRecompiler::GcnGuestShaders() && (value & 0x2000u) == 0) { validate(value == 0, "GCN vertex routing other than a plain VS is unsupported"); - const auto unitStepRate = [&](std::uint32_t offset) { + const auto stepRate = [&](std::uint32_t offset) { const auto rate = find(queue.context, offset); - return rate == queue.context.end() || rate->second == 1u; + return rate == queue.context.end() ? 1u : rate->second; }; const auto components = (read(queue.shader, 0x4a, RegisterBank::Shader) >> 24u) & 3u; - validate(components == 0 || (unitStepRate(0x2a8) && (components == 1 || unitStepRate(0x2a9))), "GCN vertex instance step rates other than 1 are not implemented"); + if (components != 0) { + result.instanceStepRate = stepRate(0x2a8); + validate(result.instanceStepRate != 0, "GCN vertex instance step rate 0 of VGT_INSTANCE_STEP_RATE_0 is not implemented"); + } + validate(components < 2 || stepRate(0x2a9) == 1u, "GCN vertex instance step rates other than 1 in VGT_INSTANCE_STEP_RATE_1 are not implemented"); result.legacyVertex = true; } else if (path == ShaderPath::Vertex) { validate((value & 0x2000u) != 0, "legacy vertex routing without PRIMGEN_EN is unsupported"); diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index 3fe29cdc5044..c1276a6872af 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -4019,6 +4019,67 @@ void gcnColorSliceTests() { expectFailure([&] { static_cast(DecodeColorBuffer(queue.context, 0)); }, "the color view ends before its first slice"); } +void gcnInstanceStepRateTests() { + using AgcDriver::Graphics::DecodeShaderStages; + ShaderRecompiler::SetGcnGuestShaders(true); + struct Restore { + ~Restore() { ShaderRecompiler::SetGcnGuestShaders(false); } + } restore; + const auto legacy = [](std::uint32_t components) { + auto queue = makeState(); + queue.context[0x2d5] = 0; + queue.shader[0x4a] = components << 24u; + return queue; + }; + Require(DecodeShaderStages(legacy(1)).legacyVertex && DecodeShaderStages(legacy(1)).instanceStepRate == 1u, "a PS4 vertex program without VGT_INSTANCE_STEP_RATE_0 does not step once per instance"); + for (const std::uint32_t rate : {1u, 2u, 3u, 0xffffffffu}) { + for (const std::uint32_t components : {1u, 2u, 3u}) { + auto queue = legacy(components); + queue.context[0x2a8] = rate; + const auto stages = DecodeShaderStages(queue); + Require(stages.legacyVertex && stages.instanceStepRate == rate, "a PS4 vertex program that reads its instance does not take VGT_INSTANCE_STEP_RATE_0"); + AgcDriver::Graphics::State state{}; + state.stages = stages; + ShaderRecompiler::ShaderVertexStageInfo vertex{}; + AgcDriver::Graphics::ApplyInstanceStepRate(state, vertex); + Require(vertex.instanceStepRate == rate, "the vertex stage info does not carry VGT_INSTANCE_STEP_RATE_0"); + } + } + auto unread = legacy(0); + unread.context[0x2a8] = 0; + unread.context[0x2a9] = 5; + Require(DecodeShaderStages(unread).instanceStepRate == 1u, "a PS4 vertex program that reads no instance takes the instance step rates"); + auto zero = legacy(1); + zero.context[0x2a8] = 0; + expectFailure([&] { static_cast(DecodeShaderStages(zero)); }, "GCN vertex instance step rate 0 of VGT_INSTANCE_STEP_RATE_0 is not implemented"); + auto second = legacy(1); + second.context[0x2a9] = 4; + Require(DecodeShaderStages(second).instanceStepRate == 1u, "a PS4 vertex program that reads one instance VGPR refuses VGT_INSTANCE_STEP_RATE_1"); + for (const std::uint32_t components : {2u, 3u}) { + auto queue = legacy(components); + queue.context[0x2a8] = 2; + queue.context[0x2a9] = 4; + expectFailure([&] { static_cast(DecodeShaderStages(queue)); }, "GCN vertex instance step rates other than 1 in VGT_INSTANCE_STEP_RATE_1 are not implemented"); + } + AgcDriver::Graphics::State agc{}; + agc.stages.instanceStepRate = 2; + ShaderRecompiler::ShaderVertexStageInfo vertex{}; + vertex.instanceStepRate = 7; + AgcDriver::Graphics::ApplyInstanceStepRate(agc, vertex); + Require(vertex.instanceStepRate == 1u, "a vertex program outside the PS4 legacy path takes an instance step rate"); + ShaderRecompiler::RecompileRequest request{}; + const std::array code{0xbf810000u}; + request.shader = {ShaderRecompiler::ShaderStage::Vertex, 0x30000u, code, 0, {}}; + request.context.waveSize = 64; + request.context.vertex = ShaderRecompiler::ShaderVertexStageInfo{}; + const auto unitHash = ShaderRecompiler::RecompileCacheKey::ContextHash(request); + request.context.vertex->instanceStepRate = 3; + Require(ShaderRecompiler::RecompileCacheKey::ContextHash(request) != unitHash, "VGT_INSTANCE_STEP_RATE_0 does not key the vertex program's variant"); + const ShaderRecompiler::RequestSerializer serializer; + const auto back = serializer.Deserialize(serializer.Serialize(request)); + Require(back.request.context.vertex->instanceStepRate == 3u && back.vertex->instanceStepRate == 3u, "VGT_INSTANCE_STEP_RATE_0 did not survive request serialization"); +} + void cmaskTests() { using AgcDriver::Graphics::DecodeColorBuffer; using AgcDriver::Graphics::CmaskLayout; @@ -16151,6 +16212,7 @@ int main(int argc, char** argv) { metadataPassTests(); depthCopyPassTests(); cmaskTests(); + gcnInstanceStepRateTests(); gcnColorSliceTests(); uint16ExportTests(); uint8x2TargetTests(); diff --git a/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp b/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp index f9e4acc30052..5f13872385fa 100644 --- a/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp @@ -8957,7 +8957,7 @@ void verifyPixelRequestSerialization() { minimal.context.pixel->layerExported = true; minimal.context.pixel->ditheredAlphaToCoverage = true; const auto encoded = serializer.Serialize(minimal); - require(requestPrefix(encoded, 8u) == "NVNQQT8AAAA=", "new requests did not use serialization version 63"); + require(requestPrefix(encoded, 8u) == "NVNQQUAAAAA=", "new requests did not use serialization version 64"); auto withBarycentric = minimal; withBarycentric.target.fragmentBarycentricBuiltins = true; require(serializer.Deserialize(serializer.Serialize(withBarycentric)).request.target.fragmentBarycentricBuiltins && !serializer.Deserialize(encoded).request.target.fragmentBarycentricBuiltins, "barycentric built-ins were lost in serialization"); @@ -9078,7 +9078,7 @@ void verifyPixelRequestSerialization() { for (std::size_t bytes = 0; bytes < 45u; ++bytes) { expectFailure([&] { static_cast(serializer.Deserialize(requestPrefix(encoded, mappingOffset + bytes))); }, "truncated data", "a truncated pixel mapping, packing, dual-source, alpha-to-coverage, stencil reference export flag, primitive class, layer export, dither or front-face flag, quad pixel mask or quad sample mask was accepted"); } - for (const auto unsupported : {"NVNQQQAAAAA=", "NVNQQTIAAAA=", "NVNQQToAAAA=", "NVNQQT0AAAA=", "NVNQQUAAAAA="}) { + for (const auto unsupported : {"NVNQQQAAAAA=", "NVNQQTIAAAA=", "NVNQQToAAAA=", "NVNQQT0AAAA=", "NVNQQUEAAAA="}) { expectFailure([&] { static_cast(serializer.Deserialize(unsupported)); }, "serialization version", "an unsupported request version was accepted"); } static constexpr std::string_view version18Request{ @@ -9135,13 +9135,6 @@ std::vector decodeBase64(std::string_view text) { return bytes; } -std::vector version56Bytes(std::vector bytes) { - require(bytes.size() > 14u && bytes[4] == 63u, "a legacy fixture did not start from serialization version 63"); - bytes.resize(bytes.size() - 6u); - bytes[4] = 56u; - return bytes; -} - std::string encodeBase64(const std::vector& bytes) { constexpr std::string_view alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; std::string text; @@ -9157,6 +9150,14 @@ std::string encodeBase64(const std::vector& bytes) { return text; } +std::vector version56Bytes(std::vector bytes) { + require(bytes.size() > 14u && bytes[4] == 64u, "a legacy fixture did not start from serialization version 64"); + const bool vertex = ShaderRecompiler::RequestSerializer{}.Deserialize(encodeBase64(bytes)).request.context.vertex.has_value(); + bytes.resize(bytes.size() - 6u - (vertex ? 4u : 0u)); + bytes[4] = 56u; + return bytes; +} + void verifyEmulatedBarycentricRequests() { using namespace ShaderRecompiler; const std::array code{0xbf810000u}; @@ -9198,7 +9199,7 @@ void verifyEmulatedBarycentricRequests() { require(replay.request.graphics.has_value() && replay.request.graphics->emulateBarycentrics && serializer.Serialize(replay.request) == encoded, "emulated barycentrics were lost in serialization"); auto bytes = decodeBase64(serializer.Serialize(request)); auto flagged = decodeBase64(encoded); - require(bytes[4] == 63u && flagged.size() == bytes.size() + 1u && flagged.back() == 1u && std::equal(bytes.begin(), bytes.end(), flagged.begin()), "emulated barycentrics are not one trailing byte after an otherwise identical request"); + require(bytes[4] == 64u && flagged.size() == bytes.size() + 1u && flagged.back() == 1u && std::equal(bytes.begin(), bytes.end(), flagged.begin()), "emulated barycentrics are not one trailing byte after an otherwise identical request"); auto legacyBytes = bytes; legacyBytes[4] = 62u; const auto legacy = serializer.Deserialize(encodeBase64(legacyBytes)); diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/GcnInstanceStepRate.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/GcnInstanceStepRate.cpp new file mode 100644 index 000000000000..86b62e05fe41 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/GcnInstanceStepRate.cpp @@ -0,0 +1,240 @@ +#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp" +#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp" +#include "prx/libSceAgcDriver/Graphics/include/State.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Texture.hpp" +#include "prx/libc/include/GuestAllocations.hpp" +#include "prx/libc/include/GuestArena.hpp" +#include "prx/libc/include/GuestWriteWatch.hpp" +#include "Recompiler.hpp" +#include "RdnaDecoder/RdnaInstructionDecoder.hpp" +#include "VulkanTestDevice.hpp" +#ifdef _WIN32 +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +using AgcDriver::Graphics::Require; +using ShaderRecompiler::ShaderStage; + +constexpr std::uint32_t Width = 8; +constexpr std::uint32_t Height = 8; +constexpr std::uint32_t Format8888 = 10u; +constexpr std::uint32_t BlendClamp = 1u << 15u; +constexpr std::uint32_t Thin1D = 13u; +constexpr std::uint32_t Instances = 7; +constexpr std::uint32_t RecordBytes = 16; +constexpr std::size_t Slot = 0x10000; +constexpr std::size_t BlockBytes = 2u * Slot; +constexpr std::size_t ColorOffset = 0u; +constexpr std::size_t RecordOffset = Slot; +constexpr std::size_t RecordSpacing = 0x1000; +constexpr std::array StepRates{1u, 2u, 3u, 8u}; +constexpr std::uint64_t GcnAddressLimit = std::uint64_t{1} << 40u; +constexpr std::uint32_t Unwritten = 0xdeadbeefu; + +alignas(256) constexpr std::array VertexCode{ + 0xe0702000u, 0x80000103u, + 0xe0702004u, 0x80000203u, + 0xe0702008u, 0x80000303u, + 0x7e0802f4u, + 0x7e0a02f2u, + 0xbf8c0000u, + 0xf80008cfu, 0x05040404u, + 0xbf810000u, +}; + +alignas(256) constexpr std::array PixelCode{ + 0x7e080280u, 0x7e0a0280u, 0x7e0c0280u, 0x7e0e02f2u, + 0xf800180fu, 0x07060504u, + 0xbf810000u, +}; + +class LowBlock { +public: + LowBlock() { +#if defined(_WIN32) || defined(__APPLE__) + data = static_cast(GuestArena::GuestArenaAllocate_nid_postfix(BlockBytes, 65536)); +#ifdef _WIN32 + if (data != nullptr) GuestArena::GuestArenaCommit_nid_postfix(data, BlockBytes, PAGE_READWRITE, BlockBytes); +#else + constexpr std::uint32_t ReadWriteProtection = 0x04; + if (data != nullptr) GuestArena::GuestArenaCommit_nid_postfix(data, BlockBytes, ReadWriteProtection, BlockBytes); +#endif +#else +#ifdef ANYPS5_ENABLE_ASAN + constexpr std::uintptr_t FirstHint = 0x60000000; +#else + constexpr std::uintptr_t FirstHint = std::uintptr_t{1} << 32u; +#endif + for (std::uintptr_t hint = FirstHint; data == nullptr && hint < GcnAddressLimit; hint += std::uintptr_t{1} << 32u) { + void* mapped = mmap(reinterpret_cast(hint), BlockBytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0); + if (mapped != MAP_FAILED) data = static_cast(mapped); + } + if (data != nullptr && AgcDriver::GuestMemory::WriteWatched()) GuestWriteWatch::GuestWriteWatchRegister_nid_postfix(data, BlockBytes); +#endif + if (data == nullptr) return; + std::memset(data, 0, BlockBytes); + GuestAllocations::Mutation().Add(data, BlockBytes, true, true, true); + AgcDriver::GuestMemory::CollectWritesUncached(Address(), BlockBytes); + } + + ~LowBlock() { + if (data == nullptr) return; + AgcDriver::Graphics::StorageTexture::FlushPending(Address(), BlockBytes, nullptr, "test release"); + GuestAllocations::Mutation().Remove(data); +#if defined(_WIN32) || defined(__APPLE__) + GuestArena::GuestArenaReset_nid_postfix(data, BlockBytes); + GuestArena::GuestArenaRelease_nid_postfix(data, BlockBytes); +#else + munmap(data, BlockBytes); + if (AgcDriver::GuestMemory::WriteWatched()) GuestWriteWatch::GuestWriteWatchUnregister_nid_postfix(data, BlockBytes); +#endif + } + + LowBlock(const LowBlock&) = delete; + LowBlock& operator=(const LowBlock&) = delete; + + bool Usable() const { return data != nullptr && Address() + BlockBytes <= GcnAddressLimit; } + std::uint64_t Address() const { return static_cast(reinterpret_cast(data)); } + std::uint64_t At(std::size_t offset) const { return Address() + offset; } + std::uint8_t* Data(std::size_t offset) const { return data + offset; } + +private: + std::uint8_t* data = nullptr; +}; + +AgcDriver::Graphics::ColorTarget DecodeTarget(std::uint64_t color) { + AgcDriver::Registers cx; + cx[0x318] = static_cast(color >> 8u); + cx[0x319] = Width / 8u - 1u; + cx[0x31a] = Width * Height / 64u - 1u; + cx[0x31b] = 0u; + cx[0x31c] = (Format8888 << 2u) | BlendClamp; + cx[0x31d] = Thin1D; + return AgcDriver::Graphics::DecodeColorBuffer(cx, 0); +} + +ShaderRecompiler::ShaderPixelStageInfo PixelInfo() { + ShaderRecompiler::ShaderPixelStageInfo pixel{}; + pixel.inputAddr = ShaderRecompiler::PixelInputBit(ShaderRecompiler::PixelInput::PositionX) | ShaderRecompiler::PixelInputBit(ShaderRecompiler::PixelInput::PositionY); + pixel.posX = true; + pixel.posY = true; + pixel.targetOutputMode[0] = 9; + pixel.targetExportMapping.fill(0xe4u); + return pixel; +} + +std::array Draw(AgcDriver::VulkanDevice& device, const LowBlock& block, std::size_t recordOffset, std::uint32_t stepRate) { + std::array records{}; + const auto target = device.Target(); + const auto address = block.At(recordOffset); + const std::vector vertexUserData{static_cast(address), static_cast((address >> 32u) & 0xffffu) | (RecordBytes << 16u), Instances * RecordBytes, 0x00027facu}; + const std::array vertexMemory{{{reinterpret_cast(VertexCode.data()), std::as_bytes(std::span(VertexCode))}}}; + ShaderRecompiler::ShaderVertexStageInfo vertexInfo{}; + vertexInfo.instanceStepRate = stepRate; + ShaderRecompiler::RecompileRequest vertex{ + {ShaderStage::Vertex, reinterpret_cast(VertexCode.data()), VertexCode, 0, {}}, + {64u, 0, vertexUserData, std::nullopt, std::nullopt, vertexInfo, vertexMemory}, + target, + {0, 0, 0, 64} + }; + vertex.useCache = false; + const auto vertexResult = ShaderRecompiler::Recompile(vertex); + const auto vertexPush = static_cast(vertexResult.pushConstants.size()); + const std::vector pixelUserData(8, 0u); + const std::array pixelMemory{{{reinterpret_cast(PixelCode.data()), std::as_bytes(std::span(PixelCode))}}}; + ShaderRecompiler::RecompileRequest fragment{ + {ShaderStage::Fragment, reinterpret_cast(PixelCode.data()), PixelCode, 0, {}}, + {64u, 0, pixelUserData, std::nullopt, PixelInfo(), std::nullopt, pixelMemory}, + target, + PixelPushLayout(vertexPush, target) + }; + fragment.useCache = false; + const auto pixelResult = ShaderRecompiler::Recompile(fragment); + const std::array shaders{{ + {ShaderStage::Vertex, &vertexResult, 0}, + {ShaderStage::Fragment, &pixelResult, PixelPushOffset(vertexPush, target)} + }}; + const auto color = DecodeTarget(block.At(ColorOffset)); + AgcDriver::Graphics::State state{}; + state.stages = {AgcDriver::Graphics::ShaderPath::Vertex, 0u, 64u, 64u, std::nullopt, std::nullopt}; + state.stages.legacyVertex = true; + state.stages.instanceStepRate = stepRate; + state.colors = {color}; + state.color = color; + state.hasColorTarget = true; + state.renderExtent = {Width, Height}; + state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + state.viewport = {0, static_cast(Height), static_cast(Width), -static_cast(Height), 0, 1}; + state.negativeOneToOne = false; + state.scissor = {{0, 0}, {Width, Height}}; + state.cullMode = VK_CULL_MODE_NONE; + state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; + VkPipelineColorBlendAttachmentState blend{}; + blend.colorWriteMask = 0xf; + state.blends = {blend}; + state.blend = blend; + state.blendConstants = {}; + state.samples = 1; + const AgcDriver::Pm4::DrawParameters draw{0, 3, 0, Instances, 0, false}; + device.Draw(state, draw, shaders); + device.WaitIdle(); + AgcDriver::GuestMemory::Read(address, std::as_writable_bytes(std::span(records)), 4); + return records; +} + +void Check(AgcDriver::VulkanDevice& device, const LowBlock& block, std::size_t recordOffset, std::uint32_t stepRate) { + const auto records = Draw(device, block, recordOffset, stepRate); + for (std::uint32_t instance = 0; instance < Instances; ++instance) { + const auto* record = records.data() + instance * RecordBytes / 4u; + const std::string name = "GCN instance step rate " + std::to_string(stepRate) + ", instance " + std::to_string(instance) + ": "; + Require(record[0] == instance / stepRate, name + "v1 is " + std::to_string(record[0]) + ", not the instance divided by VGT_INSTANCE_STEP_RATE_0 (" + std::to_string(instance / stepRate) + ")"); + Require(record[1] == instance, name + "v2 is " + std::to_string(record[1]) + ", not the instance"); + Require(record[2] == instance, name + "v3 is " + std::to_string(record[2]) + ", not the instance"); + Require(record[3] == Unwritten, name + "the vertex program wrote past its three VGPRs"); + } +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + ShaderRecompiler::SetGcnGuestShaders(true); + const LowBlock block; + if (!block.Usable()) { + std::printf("skipped, no guest block below the 40-bit GCN address range (0x%llx)\n", static_cast(block.Address())); + return VulkanTestSkipped; + } + for (std::size_t rate = 0; rate < StepRates.size(); ++rate) { + auto* words = reinterpret_cast(block.Data(RecordOffset + rate * RecordSpacing)); + std::fill_n(words, Instances * RecordBytes / 4u, Unwritten); + } + for (std::size_t rate = 0; rate < StepRates.size(); ++rate) Check(*device, block, RecordOffset + rate * RecordSpacing, StepRates[rate]); + std::printf("GCN instance step rate tests passed: v1 holds the instance divided by VGT_INSTANCE_STEP_RATE_0 1, 2, 3 and 8 over %u instances, v2 and v3 the instance\n", Instances); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/shader/recompiler/CacheKey.hpp b/core/shader/recompiler/CacheKey.hpp index 56ddf0607580..003e57c9d4d9 100644 --- a/core/shader/recompiler/CacheKey.hpp +++ b/core/shader/recompiler/CacheKey.hpp @@ -288,6 +288,7 @@ class RecompileCacheKey { append(key, std::bit_cast(value.pointSize)); append(key, std::bit_cast(value.pointSizeMin)); append(key, std::bit_cast(value.pointSizeMax)); + append(key, value.instanceStepRate); if (value.resourcesNum > value.resources.size()) throw std::runtime_error("Shader cache: invalid vertex resource count"); append(key, value.resourcesNum); for (std::uint32_t i = 0; i < value.resourcesNum; ++i) { diff --git a/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp b/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp index e86af1545567..d26d2d9626b0 100644 --- a/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp +++ b/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp @@ -927,7 +927,7 @@ std::string RequestSerializer::Serialize(const RecompileRequest& request) const std::string buffer; Writer writer(buffer); writer.WriteU32(0x41505335u); - writer.WriteU32(63u); + writer.WriteU32(64u); writeShaderBinary(writer, request.shader); writeGuestContext(writer, request.context); writeSpirvTarget(writer, request.target); @@ -981,6 +981,7 @@ std::string RequestSerializer::Serialize(const RecompileRequest& request) const writer.WriteU32(request.target.maxImageArrayLayers); writer.WriteBool(request.target.fixedPushSlots); writer.WriteBool(request.target.spannedAnySubgroup); + if (request.context.vertex.has_value()) writer.WriteU32(request.context.vertex->instanceStepRate); if (request.graphics.has_value() && request.graphics->emulateBarycentrics) writer.WriteBool(true); return base64Encode(buffer); } @@ -990,7 +991,7 @@ DeserializedRequest RequestSerializer::Deserialize(std::string_view text) const Reader reader(decoded); if (reader.ReadU32() != 0x41505335u) throw std::runtime_error("invalid recompile request signature"); const auto version = reader.ReadU32(); - if (version < 1u || version > 63u || version == 50u || (version >= 58u && version <= 61u)) throw std::runtime_error("unsupported recompile request serialization version"); + if (version < 1u || version > 64u || version == 50u || (version >= 58u && version <= 61u)) throw std::runtime_error("unsupported recompile request serialization version"); DeserializedRequest result{}; result.request.shader = readShaderBinary(reader, result.shaderCode, result.shaderHeader); result.request.context = readGuestContext(reader, result, version); @@ -1066,6 +1067,10 @@ DeserializedRequest RequestSerializer::Deserialize(std::string_view text) const result.request.target.fixedPushSlots = reader.ReadBool(); } if (version >= 62u) result.request.target.spannedAnySubgroup = reader.ReadBool(); + if (version >= 64u && result.request.context.vertex.has_value()) { + result.request.context.vertex->instanceStepRate = reader.ReadU32(); + result.vertex = *result.request.context.vertex; + } if (version >= 63u && reader.Remaining() != 0u) { if (!reader.ReadBool()) throw std::runtime_error("RequestSerializer: a written emulated barycentrics flag is clear"); if (!result.request.graphics.has_value()) throw std::runtime_error("RequestSerializer: emulated barycentrics without a graphics context"); diff --git a/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp b/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp index 957290eaa63b..b81cebfbcbd8 100644 --- a/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp +++ b/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp @@ -137,6 +137,7 @@ struct ShaderVertexInputInfo { float pointSize = 1.0f; float pointSizeMin = 0.0f; float pointSizeMax = 0.0f; + std::uint32_t instanceStepRate = 1; ShaderClipSpaceTransform clipSpace; ShaderDepthRemap depthRemap; ShaderMeshInputInfo mesh; diff --git a/core/shader/recompiler/Recompiler.hpp b/core/shader/recompiler/Recompiler.hpp index ab48e2ae5cff..05ab02847920 100644 --- a/core/shader/recompiler/Recompiler.hpp +++ b/core/shader/recompiler/Recompiler.hpp @@ -288,6 +288,7 @@ struct ShaderVertexStageInfo { float pointSize = 1.0f; float pointSizeMin = 0.0f; float pointSizeMax = 0.0f; + std::uint32_t instanceStepRate = 1; }; struct ShaderFloatMode { diff --git a/core/shader/recompiler/Translation/src/InstructionTranslator.cpp b/core/shader/recompiler/Translation/src/InstructionTranslator.cpp index e7874bedd58c..c8bb9bc32417 100644 --- a/core/shader/recompiler/Translation/src/InstructionTranslator.cpp +++ b/core/shader/recompiler/Translation/src/InstructionTranslator.cpp @@ -526,7 +526,11 @@ void emitEntryPrologue(IrProgram& program, IrBlock& entryBlock, const TranslateO } if (options.gcnLegacyVertexInputs) { setVector(static_cast(0), drawIndex(StageInputKind::VertexIndex)); - for (std::uint32_t reg = 1u; reg <= 3u; reg++) setVector(static_cast(reg), drawIndex(StageInputKind::InstanceIndex)); + const auto stepRate = options.inputInfo.vertex != nullptr ? options.inputInfo.vertex->instanceStepRate : 1u; + if (stepRate == 0u) throw std::invalid_argument("GCN vertex instance step rate 0 is not implemented"); + IrValue& instance = drawIndex(StageInputKind::InstanceIndex); + setVector(static_cast(1), stepRate == 1u ? instance : entryIr.Emit(IrOpcode::UDiv32, IrOpcodeType(IrOpcode::UDiv32), {&instance, &entryIr.Constant(stepRate)})); + for (std::uint32_t reg = 2u; reg <= 3u; reg++) setVector(static_cast(reg), instance); } else { setVector(static_cast(5), drawIndex(StageInputKind::VertexIndex)); setVector(static_cast(8), drawIndex(StageInputKind::InstanceIndex)); diff --git a/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp b/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp index 2c11f280b4f3..d5f2635596e4 100644 --- a/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp +++ b/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp @@ -214,6 +214,7 @@ ShaderStageInputInfo BuildShaderStageInputInfo(ShaderStageKind stage, const Gues vertexStorage.pointSize = vertex.pointSize; vertexStorage.pointSizeMin = vertex.pointSizeMin; vertexStorage.pointSizeMax = vertex.pointSizeMax; + vertexStorage.instanceStepRate = vertex.instanceStepRate; vertexStorage.fetchExternal = false; vertexStorage.fetchAttribReg = static_cast(vertex.fetchAttribReg); vertexStorage.fetchBufferReg = static_cast(vertex.fetchBufferReg); diff --git a/core/shader/recompiler/tests/RequestSerializerTests.cpp b/core/shader/recompiler/tests/RequestSerializerTests.cpp index 7d03a1aa220a..e19b3006a370 100644 --- a/core/shader/recompiler/tests/RequestSerializerTests.cpp +++ b/core/shader/recompiler/tests/RequestSerializerTests.cpp @@ -202,12 +202,50 @@ void VerifyTessellationInstancePatches() { std::string SerializeVersion56(const ShaderRecompiler::RecompileRequest& request) { auto bytes = DecodeBase64(ShaderRecompiler::RequestSerializer{}.Serialize(request)); - Require(bytes.size() > 14u && bytes[4] == 63u); - bytes.resize(bytes.size() - 6u); + Require(bytes.size() > 14u && bytes[4] == 64u); + bytes.resize(bytes.size() - 6u - (request.context.vertex.has_value() ? 4u : 0u)); bytes[4] = 56u; return EncodeBase64(bytes); } +void VerifyInstanceStepRate() { + const ShaderRecompiler::RequestSerializer serializer; + for (const std::uint32_t rate : {1u, 2u, 7u, 0xffffffffu}) { + ShaderRecompiler::RecompileRequest request{}; + request.context.vertex = ShaderRecompiler::ShaderVertexStageInfo{}; + request.context.vertex->instanceStepRate = rate; + const auto encoded = serializer.Serialize(request); + const auto replay = serializer.Deserialize(encoded); + Require(replay.request.context.vertex.has_value() && replay.request.context.vertex->instanceStepRate == rate); + Require(replay.vertex.has_value() && replay.vertex->instanceStepRate == rate); + Require(serializer.Serialize(replay.request) == encoded); + auto bytes = DecodeBase64(encoded); + Require(bytes[4] == 64u); + for (std::size_t missing = 1u; missing <= 4u; ++missing) { + auto truncated = bytes; + truncated.resize(truncated.size() - missing); + bool rejected = false; + try { + static_cast(serializer.Deserialize(EncodeBase64(truncated))); + } catch (const std::runtime_error& error) { + rejected = std::string_view(error.what()) == "RequestSerializer: truncated data"; + } + Require(rejected); + } + bytes.resize(bytes.size() - 4u); + bytes[4] = 63u; + const auto legacy63 = serializer.Deserialize(EncodeBase64(bytes)); + Require(legacy63.request.context.vertex.has_value() && legacy63.request.context.vertex->instanceStepRate == 1u && legacy63.vertex->instanceStepRate == 1u); + bytes[4] = 62u; + const auto legacy62 = serializer.Deserialize(EncodeBase64(bytes)); + Require(legacy62.request.context.vertex.has_value() && legacy62.request.context.vertex->instanceStepRate == 1u && legacy62.vertex->instanceStepRate == 1u); + bytes.pop_back(); + bytes[4] = 57u; + const auto legacy57 = serializer.Deserialize(EncodeBase64(bytes)); + Require(legacy57.request.context.vertex.has_value() && legacy57.request.context.vertex->instanceStepRate == 1u && legacy57.vertex->instanceStepRate == 1u); + } +} + void VerifyTargetOptions() { const ShaderRecompiler::RequestSerializer serializer; for (const bool fixed : {true, false}) { @@ -226,7 +264,7 @@ void VerifyTargetOptions() { Require(replay.request.target.float16WidenNans == widen && replay.request.target.float16NarrowNans == narrow); Require(serializer.Serialize(replay.request) == encoded); auto bytes = DecodeBase64(encoded); - Require(bytes[4] == 63u && bytes.back() == 0u); + Require(bytes[4] == 64u && bytes.back() == 0u); for (std::size_t missing = 1u; missing <= 6u; ++missing) { auto truncated = bytes; truncated.resize(truncated.size() - missing); @@ -784,7 +822,7 @@ int VerifyVersion56Compatibility() { version40[4] = 40u; const auto replay40 = serializer.Deserialize(EncodeBase64(version40)); Require(!replay40.request.target.float32DenormPreserve && replay40.request.target.float32FlushToZero == !preserve); - for (const std::uint8_t unwritten : {58u, 59u, 60u, 61u, 64u}) { + for (const std::uint8_t unwritten : {58u, 59u, 60u, 61u, 65u}) { auto future = bytes; future[4] = unwritten; bool futureRejected = false; @@ -899,11 +937,13 @@ int VerifyVersion56Compatibility() { const auto replay35 = serializer.Deserialize(EncodeBase64(version35)); Require(replay35.request.target.spannedWaves == spanned && !replay35.request.target.float32FlushToZero); request.target.spannedAnySubgroup = spanned; - auto version62 = DecodeBase64(serializer.Serialize(request)); - Require(version62[4] == 63u && version62.back() == (spanned ? 1u : 0u)); + const auto version64 = DecodeBase64(serializer.Serialize(request)); + Require(version64[4] == 64u && version64.back() == (spanned ? 1u : 0u)); + Require(serializer.Deserialize(EncodeBase64(version64)).request.target.spannedAnySubgroup == spanned); + auto version62 = version64; version62[4] = 62u; Require(serializer.Deserialize(EncodeBase64(version62)).request.target.spannedAnySubgroup == spanned); - auto version57 = version62; + auto version57 = version64; version57[4] = 57u; version57.pop_back(); const auto replay57 = serializer.Deserialize(EncodeBase64(version57)); @@ -1194,7 +1234,7 @@ void VerifySingleSampleVersion63() { request.context.pixel->ditheredAlphaSamples = 1u; request.context.pixel->singleSampleDither = mode; const auto bytes = DecodeBase64(serializer.Serialize(request)); - Require(bytes[4] == 63u); + Require(bytes[4] == 64u); const auto replay = serializer.Deserialize(EncodeBase64(bytes)); Require(replay.request.context.pixel->singleSampleDither == mode && replay.request.context.pixel->ditheredAlphaSamples == 1u); Require(replay.request.target.maxImageArrayLayers == 4097u && replay.request.target.fixedPushSlots && replay.request.target.spannedAnySubgroup); @@ -1235,7 +1275,7 @@ void VerifySingleSampleVersion63() { Require(replay.request.target.maxImageArrayLayers == (version >= 57u ? 4097u : 0u) && replay.request.target.fixedPushSlots == (version >= 57u) && replay.request.target.spannedAnySubgroup == (version >= 62u)); } } - for (const auto [version, dither] : {std::pair{63u, 5u}, std::pair{64u, 3u}}) { + for (const auto [version, dither] : {std::pair{63u, 5u}, std::pair{64u, 5u}, std::pair{65u, 3u}}) { auto invalid = first; invalid[4] = version; invalid[ditherByte] = dither; @@ -1252,5 +1292,6 @@ void VerifySingleSampleVersion63() { int main() { VerifySingleSampleVersion63(); VerifyTargetOptions(); + VerifyInstanceStepRate(); return VerifyVersion56Compatibility(); } diff --git a/docs/dev/debt/libSceAgcDriver.md b/docs/dev/debt/libSceAgcDriver.md index 10b3b26c4127..81cd25fad26d 100644 --- a/docs/dev/debt/libSceAgcDriver.md +++ b/docs/dev/debt/libSceAgcDriver.md @@ -150,6 +150,7 @@ Eligible single-sample draws retain native finite bounds inside [0, 1] and use a - [PS4 flips without a resident image](../../../core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp) (libSceAgcDriver, PS4) - a tiled flip with no resident image, such as one before the title draws into the buffer, is decoded on the CPU one texel at a time through `ColorTargetLayout::Offset`, about 116 ms at 1920x1080 ([measured on #9673](https://github.com/boykopovar/AnyPS5/pull/9673)). It then takes the same upload, HDR10 scaler, frame dump and screenshot path as a linear buffer. - [PS4 render targets and display buffers](../../../core/libs/prx/libSceAgcDriver/Execution/src/DisplayBuffer.cpp) (libSceAgcDriver, PS4) - a tiled PS4 display buffer is read as Display2DThin with rows padded to 128 elements, as shadPS4's `image_info.cpp` does. A PS4 render target spans its surface padded to whole macro tiles (1920x1080 at 32 bits is 1920x1088), the display buffer is its top-left corner, and a texture over that corner with the same pitch, tiling and texel size is a [GPU copy](../../../core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp) of it. A PS4 `DB_Z_INFO` names a GB_TILE_MODE index; the depth image stays on the GPU and HTILE is kept, as for the PS5. shadPS4 (`image_info.cpp`, 0614ce324be0) rounds the width of a tiled display buffer up to a multiple of 128 itself, whereas `DisplayBufferSize` requires the pitch to be one already. A PS4 depth target spans `DB_DEPTH_SIZE`; a smaller level-0 depth view reads a plane copy of its corner, a stencil one guest memory. - [PS4 pattern fill](../../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cpp) (libSceAgcDriver, PS4) - the PS4 build of the pattern-fill compute kernel seen in Limbo (CUSA01664), with user data s[4:7] a 32-bit UINT source, s[8:11] the 32-bit UINT destination and s[12:15] a control record of count and index mask, where thread i stores source[i & mask], runs as a GPU fill when the mask is 0, a single repeated dword; other masks run the kernel, since running Limbo's two-dword clears of a 64-bit target as fills made its gameplay advance more slowly per frame. The kernel is recognized by its code, not by an SDK symbol. +- [PS4 (GCN) vertex instance step rates](../../../core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp) (libSceAgcDriver, PS4) - not checked on a console. A plain vertex program whose `SPI_SHADER_PGM_RSRC1_VS.VGPR_COMP_CNT` loads v1 gets the instance index divided by `VGT_INSTANCE_STEP_RATE_0` (1 when unset), and v2 and v3 the instance index, as the vertex case of `EmitPrologue` in [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/a26cac679b3f95fee5b591689adec9e53b62adfb/src/shader_recompiler/frontend/translate/translate.cpp) sets v1 and v3. A step rate of 0 throws: shadPS4 writes 0 to v1 then, which no measurement confirms. A `VGT_INSTANCE_STEP_RATE_1` other than 1 throws when v2 is loaded: shadPS4 divides the instance index by it, but what a plain vertex program receives in v2 is not confirmed here. No title is known to set either rate. ### Functional