From 3b078f43d4fe728c0ae6d4eb760570f4092c57cc Mon Sep 17 00:00:00 2001 From: RINNECODER <93304526+RINNECODER@users.noreply.github.com> Date: Sat, 17 Oct 2026 22:33:40 -0500 Subject: [PATCH] sync(upstream): integrate Batch 27 kernel error, fpathconf, pad firmware exports, and shader denormals --- .../libSceAgcDriver/Graphics/src/State.cpp | 3 +- .../prx/libSceAgcDriver/tests/Graphics.cpp | 17 + core/libs/prx/libSceAgcDriver/tests/Pm4.cpp | 2 + .../libSceAgcDriver/tests/ShaderMemory.cpp | 14 + .../tests/WaveControlDecode.cpp | 5 +- .../execution/F32AddMulDenormalModes.cpp | 188 +++++ .../tests/execution/GdsAppendConsume.cpp | 49 +- core/libs/prx/libScePad/Export.cpp | 745 ++++++++++++++++++ core/libs/prx/libc/src/LocaleSupport.cpp | 17 + core/libs/prx/libc/src/Math.cpp | 2 + core/libs/prx/libc/src/StandardStreams.cpp | 18 +- core/libs/prx/libkernel/CMakeLists.txt | 29 + core/libs/prx/libkernel/File/include/File.hpp | 3 +- .../libs/prx/libkernel/Pthread/src/Thread.cpp | 2 +- core/libs/prx/libkernel/System/src/Error.cpp | 8 + .../libs/prx/libkernel/System/src/Signals.cpp | 2 +- core/libs/prx/libkernel/Time/Time.cpp | 1 + core/libs/prx/libkernel_sys/Export.cpp | 71 +- .../tests/GuestClosedStandardDescriptors.cpp | 66 ++ core/libs/tests/GuestCredentials.cpp | 3 + core/libs/tests/GuestKernelSys.cpp | 43 + core/libs/tests/GuestLocale.cpp | 25 + core/libs/tests/GuestMath.cpp | 6 + core/libs/tests/GuestPthreadJoinSelf.cpp | 26 + core/libs/tests/GuestSignalSets.cpp | 20 + core/libs/tests/GuestThreadSelf.cpp | 3 +- core/libs/tests/GuestWaitTrace.cpp | 16 + core/libs/tests/KernelError.cpp | 28 + .../Optimization/src/ConstantFolder.cpp | 17 + .../SpirvMemory/SpirvMemoryInstructions.cpp | 6 +- .../SpirvBackend/src/SpirvOptimizer.cpp | 1 + .../Translation/TranslationContext.hpp | 2 +- .../src/TranslationContext/OperandAccess.cpp | 6 +- .../Translation/src/VectorInstructions.cpp | 6 + docs/dev/debt/libScePad.md | 149 ++++ docs/dev/debt/libc.md | 1 + docs/dev/debt/libkernel.md | 1 + docs/dev/debt/libkernel_sys.md | 2 +- docs/dev/debt/shader.md | 1 + 39 files changed, 1543 insertions(+), 61 deletions(-) create mode 100644 core/libs/prx/libSceAgcDriver/tests/execution/F32AddMulDenormalModes.cpp create mode 100644 core/libs/prx/libkernel/System/src/Error.cpp create mode 100644 core/libs/tests/GuestClosedStandardDescriptors.cpp create mode 100644 core/libs/tests/GuestWaitTrace.cpp create mode 100644 core/libs/tests/KernelError.cpp diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp index 0720ab29f516..e1fd5504e4a5 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp @@ -325,7 +325,8 @@ void decodeDepth(const Registers& cx, std::uint32_t depthControl, State& result) depth.lastSlice = (view >> 13u) & 0x7ffu; depth.address = zFormat != 0 ? base(0x012, 0x01a) : 0; depth.stencilAddress = stencil ? base(0x013, 0x01b) : 0; - Require(zFormat == 0 || depthReadOnly || base(0x014, 0x01c) == depth.address, "depth read and written at different addresses is unsupported"); + const bool depthWritten = zFormat != 0 && !depthReadOnly && (depthClear || (depthControl & 6u) == 6u || (read(cx, 0x000) & 0x60u) != 0); + Require(!depthWritten || base(0x014, 0x01c) == depth.address, "depth read and written at different addresses is unsupported"); Require(!stencil || stencilReadOnly || base(0x015, 0x01d) == depth.stencilAddress, "stencil read and written at different addresses is unsupported"); if (depth.samples != 1u) { depth.pipeBankXor = static_cast(depth.address & 65535u); diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index 62a973d20510..5b842853e5e4 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -1727,6 +1727,23 @@ void DepthStencilTests() { const auto rejection = AgcDriver::Graphics::DrawRejection(queue, false); Require(rejection.empty(), "precheck rejected a stencil draw with a surface: " + rejection); Require(state.depth && state.depth->address == 0x10000 && state.depth->stencilAddress == 0x20000 && state.depth->format == VK_FORMAT_D32_SFLOAT_S8_UINT && state.depth->clearStencil == 7 && state.depth->htileAddress == 0x10000030000ull && !state.depth->htileStencil, "depth surface decode changed"); + { + auto split = queue; + split.context[0x014] = 0; + for (const auto control : {0x00700711u, 0x00700715u, 0x00700713u}) { + split.context[0x200] = control; + const auto splitState = AgcDriver::Graphics::DecodeState(split); + Require(splitState.depth && splitState.depth->address == 0x10000 && !splitState.depthWrite, "a depth plane the draw does not write rejected another write address"); + Require(AgcDriver::Graphics::DrawRejection(split, false).empty(), "precheck rejected a depth plane the draw does not write at another write address"); + } + split.context[0x200] = 0x00700717u; + expectFailure([&] { AgcDriver::Graphics::DecodeState(split); }, "depth read and written at different addresses"); + split.context[0x200] = 0x00700711u; + for (const auto control : {0x01u, 0x20u, 0x40u, 0x60u}) { + split.context[0x000] = control; + expectFailure([&] { AgcDriver::Graphics::DecodeState(split); }, "depth read and written at different addresses"); + } + } for (const auto clear : {0u, 1u, 2u, 3u}) { auto retained = queue; retained.context[0x8e] = retained.context[0x8f] = retained.context[0x203] = 0; diff --git a/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp b/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp index f5b19424e951..391c4796e3ac 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp @@ -215,7 +215,9 @@ void testContextAndBases() { expectFailure([&] { AgcDriver::Pm4::Validate(makePacket(0x15, {1, 1, 1, 0x2063}, 2), 0); }, "dispatch modifiers"); expectFailure([&] { AgcDriver::Pm4::Validate(makePacket(0x15, {1, 1, 1, 0x41}, 4), 0); }, "header flags"); AgcDriver::Pm4::Validate(makePacket(0x15, {1, 1, 1, 0x49}), 0); + AgcDriver::Pm4::Validate(makePacket(0x16, {0, 0x49}), 0); expectFailure([&] { AgcDriver::Pm4::Validate(makePacket(0x15, {1, 1, 1, 0x51}), 0); }, "dispatch modifiers"); + expectFailure([&] { AgcDriver::Pm4::Validate(makePacket(0x16, {0, 0x51}), 0); }, "indirect dispatch modifiers"); execute(state, makePacket(0x13, {32})); execute(state, makePacket(0x26, {0x1000, 1})); execute(state, makePacket(0x2a, {1})); diff --git a/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp b/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp index e78b822450d2..42909d055262 100644 --- a/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp @@ -1328,6 +1328,20 @@ void verifyDescriptorPhis() { sequential.context.memory = sequentialMemory.Regions(); static_cast(Recompile(sequential, *sequentialCapture)); + const auto planRestoredSampler = [&](std::span code, const char* message) { + auto request = makeRequest(code); + const auto plan = GetResourcePlan(request); + require(plan->info.samplers.size() == 1u && plan->info.sampledPairs.size() == 1u, message); + AgcDriver::ShaderMemory memory({}); + const auto capture = memory.Capture(request); + request.context.memory = memory.Regions(); + static_cast(Recompile(request, *capture)); + }; + std::vector restoredSamplerCode{0xf40c0200u, 0xfa000000u, 0xf4080500u, 0xfa000020u, 0xf4080600u, 0xfa000040u, 0xbe930380u, 0xbf8cc07fu, 0xf09c0f08u, 0x00a20400u, 0xbe900380u, 0xbe910380u, 0xbe9c0414u, 0xbe9e0416u, 0xbf068011u, 0xbf850001u, 0x80128112u, 0xbe94041cu, 0xbe96041eu, 0x80118111u, 0xbf0a8211u, 0xbf85fff6u, 0xf09c0f08u, 0x00a20000u, 0x80108110u, 0xbf0a8210u, 0xbf85fff0u, 0x80138113u, 0xbf0a8213u, 0xbf85ffecu, 0xbf8c3f70u, 0xe0700000u, 0x80060000u, 0xe0700000u, 0x80060400u, 0x7d880090u, 0xbea23c6au, 0x4a020081u, 0xe0700000u, 0x80060100u, 0xbf810000u}; + planRestoredSampler(restoredSamplerCode, "descriptor Phi: an S# copied out and back in three nested loops was planned as more than one sampler"); + restoredSamplerCode.erase(restoredSamplerCode.end() - 6, restoredSamplerCode.end() - 1); + planRestoredSampler(restoredSamplerCode, "descriptor Phi: an S# copied out and back in three nested loops without a masked write was planned as more than one sampler"); + const auto entryWrites = [&](std::initializer_list words) { auto code = loopCode; code.insert(code.begin() + 8, words); diff --git a/core/libs/prx/libSceAgcDriver/tests/WaveControlDecode.cpp b/core/libs/prx/libSceAgcDriver/tests/WaveControlDecode.cpp index 16faeba83fc6..707159cd03a7 100644 --- a/core/libs/prx/libSceAgcDriver/tests/WaveControlDecode.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/WaveControlDecode.cpp @@ -62,7 +62,7 @@ void verifyDecode() { require(decoded[11].op == RdnaOpcode::SCodeEnd, "s_code_end"); } -std::string recompile(std::span code) { +std::string recompile(std::span code, std::uint32_t subgroupSize = 64u) { const std::array userData{0x10000000u, 0x00100000u, 0x40u, 0x00027facu}; const std::array capabilities{1u, 61u}; const std::array extensions{"SPV_KHR_storage_buffer_storage_class"}; @@ -74,7 +74,7 @@ std::string recompile(std::span code) { request.context.compute = ShaderComputeStageInfo{{64u, 1u, 1u}, 0u, {false, false, false}, false, 1u}; request.target.vulkanVersion = 0x00403000u; request.target.spirvVersion = 0x00010600u; - request.target.subgroupSize = 64u; + request.target.subgroupSize = subgroupSize; request.target.bdaAbiVersion = 1; request.target.supportedCapabilities = capabilities; request.target.supportedExtensions = extensions; @@ -104,6 +104,7 @@ void verifyTranslation() { require(recompile(trailingLoop).empty(), "a program padded with s_code_end after its last branch is refused: " + recompile(trailingLoop)); const auto orderedAdd = withStore({0xd8fe0000u, 0x05000001u}); require(recompile(orderedAdd).empty(), "ds_ordered_count adding to a GDS counter is refused: " + recompile(orderedAdd)); + require(recompile(orderedAdd, 32u).empty(), "ds_ordered_count of a wave64 on 32-lane subgroups is refused: " + recompile(orderedAdd, 32u)); const std::vector, std::string_view>> refused{ {"s_sethalt 1", withStore({0xbf8d0001u}), "s_sethalt 1 at pc 0 halts the wave"}, diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/F32AddMulDenormalModes.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/F32AddMulDenormalModes.cpp new file mode 100644 index 000000000000..0e3eca4bf510 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/F32AddMulDenormalModes.cpp @@ -0,0 +1,188 @@ +#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp" +#include "Recompiler.hpp" +#include "VulkanTestDevice.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +using AgcDriver::Graphics::Require; +using ShaderRecompiler::ShaderStage; + +constexpr std::uint32_t Threads = 64; +constexpr std::uint32_t Inputs = 4; +constexpr std::uint32_t Results = 16; +constexpr std::uint32_t Instructions = 5; +constexpr std::uint32_t FirstMultiply = 3; +alignas(256) std::array Input{}; +alignas(256) std::array Output{}; + +alignas(256) constexpr std::array Code{ + 0x34020084u, 0x34040086u, 0xe0381000u, 0x80000401u, 0xbf8c3f70u, 0x06140b04u, 0x08160b04u, 0x0a180b04u, + 0x101a0b04u, 0x0e1c0b04u, 0xe0781000u, 0x80010a02u, 0xe0701010u, 0x80010e02u, 0xbf810000u, +}; + +constexpr const char* Names[Instructions] = {"v_add_f32", "v_sub_f32", "v_subrev_f32", "v_mul_f32", "v_mul_legacy_f32"}; + +template +struct Vector { + std::uint32_t operands[2]; + std::uint32_t outputsFlushed[Count]; + std::uint32_t inputsFlushed[Count]; +}; + +constexpr std::array, 40> ArithmeticVectors{{ + {{0x00000000u, 0x00000001u}, {0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u}, {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}}, + {{0x00000001u, 0x00800002u}, {0x00800003u, 0x80800001u, 0x00800001u, 0x00000000u, 0x00000000u}, {0x00800002u, 0x80800002u, 0x00800002u, 0x00000000u, 0x00000000u}}, + {{0x00000001u, 0x81000001u}, {0x81000000u, 0x01000002u, 0x81000002u, 0x80000000u, 0x80000000u}, {0x81000001u, 0x01000001u, 0x81000001u, 0x80000000u, 0x00000000u}}, + {{0x00000002u, 0x3f800000u}, {0x3f800000u, 0xbf800000u, 0x3f800000u, 0x00000000u, 0x00000000u}, {0x3f800000u, 0xbf800000u, 0x3f800000u, 0x00000000u, 0x00000000u}}, + {{0x00000002u, 0xff7fffffu}, {0xff7fffffu, 0x7f7fffffu, 0xff7fffffu, 0xb57fffffu, 0xb57fffffu}, {0xff7fffffu, 0x7f7fffffu, 0xff7fffffu, 0x80000000u, 0x00000000u}}, + {{0x00000003u, 0x80000001u}, {0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0x80000000u}, {0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0x00000000u}}, + {{0x00400000u, 0x00000002u}, {0x00000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u}, {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}}, + {{0x00400000u, 0x807fffffu}, {0x80000000u, 0x00bfffffu, 0x80bfffffu, 0x80000000u, 0x80000000u}, {0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0x00000000u}}, + {{0x007fffffu, 0x00800000u}, {0x00ffffffu, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u}, {0x00800000u, 0x80800000u, 0x00800000u, 0x00000000u, 0x00000000u}}, + {{0x007fffffu, 0x80800002u}, {0x80000000u, 0x01000000u, 0x81000000u, 0x80000000u, 0x80000000u}, {0x80800002u, 0x00800002u, 0x80800002u, 0x80000000u, 0x00000000u}}, + {{0x00800000u, 0x80000001u}, {0x00000000u, 0x00800001u, 0x80800001u, 0x80000000u, 0x80000000u}, {0x00800000u, 0x00800000u, 0x80800000u, 0x80000000u, 0x00000000u}}, + {{0x00800001u, 0x33800000u}, {0x33800000u, 0xb3800000u, 0x33800000u, 0x00000000u, 0x00000000u}, {0x33800000u, 0xb3800000u, 0x33800000u, 0x00000001u, 0x00000001u}}, + {{0x00800002u, 0x00800000u}, {0x01000001u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u}, {0x01000001u, 0x00000002u, 0x80000002u, 0x00000000u, 0x00000000u}}, + {{0x00ffffffu, 0x00000002u}, {0x01000000u, 0x00fffffdu, 0x80fffffdu, 0x00000000u, 0x00000000u}, {0x00ffffffu, 0x00ffffffu, 0x80ffffffu, 0x00000000u, 0x00000000u}}, + {{0x00ffffffu, 0x80800002u}, {0x00000000u, 0x01400000u, 0x81400000u, 0x80000000u, 0x80000000u}, {0x007ffffdu, 0x01400000u, 0x81400000u, 0x80000000u, 0x80000000u}}, + {{0x01000000u, 0x80000003u}, {0x00fffffdu, 0x01000002u, 0x81000002u, 0x80000000u, 0x80000000u}, {0x01000000u, 0x01000000u, 0x81000000u, 0x80000000u, 0x00000000u}}, + {{0x01000001u, 0x80000001u}, {0x01000000u, 0x01000002u, 0x81000002u, 0x80000000u, 0x80000000u}, {0x01000001u, 0x01000001u, 0x81000001u, 0x80000000u, 0x00000000u}}, + {{0x3f800000u, 0x807fffffu}, {0x3f800000u, 0x3f800000u, 0xbf800000u, 0x80000000u, 0x80000000u}, {0x3f800000u, 0x3f800000u, 0xbf800000u, 0x80000000u, 0x00000000u}}, + {{0x34000000u, 0x00800001u}, {0x34000000u, 0x34000000u, 0xb4000000u, 0x00000000u, 0x00000000u}, {0x34000000u, 0x34000000u, 0xb4000000u, 0x00000001u, 0x00000001u}}, + {{0x7f7fffffu, 0x00000003u}, {0x7f7fffffu, 0x7f7fffffu, 0xff7fffffu, 0x35bfffffu, 0x35bfffffu}, {0x7f7fffffu, 0x7f7fffffu, 0xff7fffffu, 0x00000000u, 0x00000000u}}, + {{0x80000000u, 0x00000001u}, {0x00000000u, 0x80000000u, 0x00000000u, 0x80000000u, 0x00000000u}, {0x00000000u, 0x80000000u, 0x00000000u, 0x80000000u, 0x00000000u}}, + {{0x80000001u, 0x00800002u}, {0x00800001u, 0x80800003u, 0x00800003u, 0x80000000u, 0x80000000u}, {0x00800002u, 0x80800002u, 0x00800002u, 0x80000000u, 0x00000000u}}, + {{0x80000001u, 0x80ffffffu}, {0x81000000u, 0x00fffffeu, 0x80fffffeu, 0x00000000u, 0x00000000u}, {0x80ffffffu, 0x00ffffffu, 0x80ffffffu, 0x00000000u, 0x00000000u}}, + {{0x80000002u, 0x3f800000u}, {0x3f800000u, 0xbf800000u, 0x3f800000u, 0x80000000u, 0x80000000u}, {0x3f800000u, 0xbf800000u, 0x3f800000u, 0x80000000u, 0x00000000u}}, + {{0x80000002u, 0xff7fffffu}, {0xff7fffffu, 0x7f7fffffu, 0xff7fffffu, 0x357fffffu, 0x357fffffu}, {0xff7fffffu, 0x7f7fffffu, 0xff7fffffu, 0x00000000u, 0x00000000u}}, + {{0x80000003u, 0x7f800000u}, {0x7f800000u, 0xff800000u, 0x7f800000u, 0xff800000u, 0xff800000u}, {0x7f800000u, 0xff800000u, 0x7f800000u, 0xffc00000u, 0x00000000u}}, + {{0x80400000u, 0x00000002u}, {0x80000000u, 0x80000000u, 0x00000000u, 0x80000000u, 0x80000000u}, {0x00000000u, 0x80000000u, 0x00000000u, 0x80000000u, 0x00000000u}}, + {{0x80400000u, 0x80000003u}, {0x80000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u}, {0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}}, + {{0x807fffffu, 0x00800000u}, {0x00000000u, 0x80ffffffu, 0x00ffffffu, 0x80000000u, 0x80000000u}, {0x00800000u, 0x80800000u, 0x00800000u, 0x80000000u, 0x00000000u}}, + {{0x807fffffu, 0x80800001u}, {0x81000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u}, {0x80800001u, 0x00800001u, 0x80800001u, 0x00000000u, 0x00000000u}}, + {{0x80800000u, 0x80000001u}, {0x80800001u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u}, {0x80800000u, 0x80800000u, 0x00800000u, 0x00000000u, 0x00000000u}}, + {{0x80800001u, 0x33800000u}, {0x33800000u, 0xb3800000u, 0x33800000u, 0x80000000u, 0x80000000u}, {0x33800000u, 0xb3800000u, 0x33800000u, 0x80000001u, 0x80000001u}}, + {{0x80800002u, 0x00800000u}, {0x80000000u, 0x81000001u, 0x01000001u, 0x80000000u, 0x80000000u}, {0x80000002u, 0x81000001u, 0x01000001u, 0x80000000u, 0x80000000u}}, + {{0x80ffffffu, 0x00000002u}, {0x80fffffdu, 0x81000000u, 0x01000000u, 0x80000000u, 0x80000000u}, {0x80ffffffu, 0x80ffffffu, 0x00ffffffu, 0x80000000u, 0x00000000u}}, + {{0x80ffffffu, 0x80800002u}, {0x81400000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u}, {0x81400000u, 0x807ffffdu, 0x007ffffdu, 0x00000000u, 0x00000000u}}, + {{0x81000000u, 0x80000003u}, {0x81000002u, 0x80fffffdu, 0x00fffffdu, 0x00000000u, 0x00000000u}, {0x81000000u, 0x81000000u, 0x01000000u, 0x00000000u, 0x00000000u}}, + {{0x81000001u, 0x80000001u}, {0x81000002u, 0x81000000u, 0x01000000u, 0x00000000u, 0x00000000u}, {0x81000001u, 0x81000001u, 0x01000001u, 0x00000000u, 0x00000000u}}, + {{0xbf800000u, 0x807fffffu}, {0xbf800000u, 0xbf800000u, 0x3f800000u, 0x00000000u, 0x00000000u}, {0xbf800000u, 0xbf800000u, 0x3f800000u, 0x00000000u, 0x00000000u}}, + {{0xb4000000u, 0x00000003u}, {0xb4000000u, 0xb4000000u, 0x34000000u, 0x80000000u, 0x80000000u}, {0xb4000000u, 0xb4000000u, 0x34000000u, 0x80000000u, 0x00000000u}}, + {{0xff7fffffu, 0x00000003u}, {0xff7fffffu, 0xff7fffffu, 0x7f7fffffu, 0xb5bfffffu, 0xb5bfffffu}, {0xff7fffffu, 0xff7fffffu, 0x7f7fffffu, 0x80000000u, 0x00000000u}}, +}}; + +constexpr std::array, 24> TinyProductVectors{{ + {{0x3f7ffffeu, 0x00800001u}, {0x00800000u, 0x00800000u}, {0x00800000u, 0x00800000u}}, + {{0x3f7ffffeu, 0x80800001u}, {0x80800000u, 0x80800000u}, {0x80800000u, 0x80800000u}}, + {{0xbf7ffffeu, 0x00800001u}, {0x80800000u, 0x80800000u}, {0x80800000u, 0x80800000u}}, + {{0xbf7ffffeu, 0x80800001u}, {0x00800000u, 0x00800000u}, {0x00800000u, 0x00800000u}}, + {{0x3f800001u, 0x007fffffu}, {0x00800000u, 0x00800000u}, {0x00000000u, 0x00000000u}}, + {{0x3f800001u, 0x807fffffu}, {0x80800000u, 0x80800000u}, {0x80000000u, 0x00000000u}}, + {{0xbf800001u, 0x007fffffu}, {0x80800000u, 0x80800000u}, {0x80000000u, 0x00000000u}}, + {{0xbf800001u, 0x807fffffu}, {0x00800000u, 0x00800000u}, {0x00000000u, 0x00000000u}}, + {{0x3f800002u, 0x007ffffeu}, {0x00800000u, 0x00800000u}, {0x00000000u, 0x00000000u}}, + {{0x3f800002u, 0x807ffffeu}, {0x80800000u, 0x80800000u}, {0x80000000u, 0x00000000u}}, + {{0xbf800002u, 0x007ffffeu}, {0x80800000u, 0x80800000u}, {0x80000000u, 0x00000000u}}, + {{0xbf800002u, 0x807ffffeu}, {0x00800000u, 0x00800000u}, {0x00000000u, 0x00000000u}}, + {{0x3f7ffffeu, 0x00800000u}, {0x00000000u, 0x00000000u}, {0x007fffffu, 0x007fffffu}}, + {{0xbf7fffffu, 0x00400000u}, {0x80000000u, 0x80000000u}, {0x80000000u, 0x00000000u}}, + {{0x3f800001u, 0x80000001u}, {0x80000000u, 0x80000000u}, {0x80000000u, 0x00000000u}}, + {{0xbfffffffu, 0x00400000u}, {0x80000000u, 0x80000000u}, {0x80000000u, 0x00000000u}}, + {{0x3f400000u, 0x00800000u}, {0x00000000u, 0x00000000u}, {0x00600000u, 0x00600000u}}, + {{0x40000000u, 0x807fffffu}, {0x80fffffeu, 0x80fffffeu}, {0x80000000u, 0x00000000u}}, + {{0xcb000000u, 0x007ffffeu}, {0x8bfffffcu, 0x8bfffffcu}, {0x80000000u, 0x00000000u}}, + {{0xcb7fffffu, 0x807ffffeu}, {0x0c7ffffbu, 0x0c7ffffbu}, {0x00000000u, 0x00000000u}}, + {{0x5f800000u, 0x00400000u}, {0x20000000u, 0x20000000u}, {0x00000000u, 0x00000000u}}, + {{0x7f000000u, 0x80400000u}, {0xbf800000u, 0xbf800000u}, {0x80000000u, 0x00000000u}}, + {{0xb3800000u, 0x00ffffffu}, {0x80000000u, 0x80000000u}, {0x80000001u, 0x80000001u}}, + {{0xb4000000u, 0x80800000u}, {0x00000000u, 0x00000000u}, {0x00000001u, 0x00000001u}}, +}}; + +static_assert(ArithmeticVectors.size() + TinyProductVectors.size() <= Threads); + +std::array BufferDescriptor(const void* data, std::uint32_t bytes) { + const auto address = reinterpret_cast(data); + return {static_cast(address), static_cast((address >> 32u) & 0xffffu), bytes, 0x31016facu}; +} + +std::string Hex(std::uint32_t value) { + char text[16]; + std::snprintf(text, sizeof(text), "0x%08x", value); + return text; +} + +template +void Fill(const Vector& vector, std::uint32_t lane) { + Input[lane * Inputs] = vector.operands[0]; + Input[lane * Inputs + 1u] = vector.operands[1]; +} + +void Run(AgcDriver::VulkanDevice& device, ShaderRecompiler::ShaderFloatMode floatMode) { + Input.fill(0u); + for (std::uint32_t lane = 0; lane < ArithmeticVectors.size(); ++lane) Fill(ArithmeticVectors[lane], lane); + for (std::uint32_t row = 0; row < TinyProductVectors.size(); ++row) Fill(TinyProductVectors[row], static_cast(ArithmeticVectors.size()) + row); + Output.fill(0xdeadbeefu); + std::vector userData(8, 0u); + const auto input = BufferDescriptor(Input.data(), static_cast(Input.size() * 4u)); + const auto output = BufferDescriptor(Output.data(), static_cast(Output.size() * 4u)); + std::copy(input.begin(), input.end(), userData.begin()); + std::copy(output.begin(), output.end(), userData.begin() + 4); + const std::span code(Code); + const std::array memory{{{reinterpret_cast(code.data()), std::as_bytes(code)}}}; + const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0, {false, false, false}, false, 1}; + ShaderRecompiler::RecompileRequest request{ + {ShaderStage::Compute, reinterpret_cast(code.data()), code, 0, {}}, + {32, 0, userData, compute, std::nullopt, std::nullopt, memory}, + device.Target(), + {0, 0, 0, 128} + }; + request.useCache = false; + request.context.floatMode = floatMode; + const auto result = ShaderRecompiler::Recompile(request); + device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast(code.data())); + device.WaitIdle(); +} + +template +void Check(const Vector& vector, std::uint32_t lane, std::uint32_t firstInstruction, std::uint32_t denormals, bool ieee) { + for (std::uint32_t index = 0; index < Count; ++index) { + const std::uint32_t instruction = firstInstruction + index; + const auto actual = Output[lane * Results + instruction]; + const auto expected = denormals == 1u ? vector.outputsFlushed[index] : vector.inputsFlushed[index]; + Require(actual == expected, std::string(Names[instruction]) + " f32 denormal mode " + std::to_string(denormals) + (ieee ? ", IEEE=1" : ", IEEE=0") + " of " + + Hex(vector.operands[0]) + ", " + Hex(vector.operands[1]) + " is " + Hex(actual) + ", expected " + Hex(expected)); + } +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + for (const std::uint32_t denormals : {1u, 2u}) { + for (const bool ieee : {false, true}) { + Run(*device, ShaderRecompiler::ShaderFloatMode{0xc0u | denormals << 4u, true, ieee, false}); + for (std::uint32_t lane = 0; lane < ArithmeticVectors.size(); ++lane) Check(ArithmeticVectors[lane], lane, 0u, denormals, ieee); + for (std::uint32_t row = 0; row < TinyProductVectors.size(); ++row) { + Check(TinyProductVectors[row], static_cast(ArithmeticVectors.size()) + row, FirstMultiply, denormals, ieee); + } + } + } + std::puts("f32 add and multiply denormal mode 1 and 2 tests passed"); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/GdsAppendConsume.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/GdsAppendConsume.cpp index 9ac9376530a6..3be5f5b44a93 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/GdsAppendConsume.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/GdsAppendConsume.cpp @@ -25,9 +25,11 @@ constexpr std::uint32_t CounterOffset = 0x10; constexpr std::array Starts{1000, 2000, 3000, 4000}; constexpr std::uint32_t UntouchedAppend = 0x5eed0001u; constexpr std::uint32_t UntouchedConsume = 0x5eed0002u; +constexpr std::uint32_t UntouchedOrdered = 0x5eed0003u; constexpr std::size_t ActiveLanesLiteral = 12; -constexpr std::size_t OrderedM0Literal = 3; -constexpr std::array OrderedM0{0u, 7u}; +constexpr std::size_t OrderedWaveMaskLiteral = 5; +constexpr std::size_t OrderedM0Literal = 7; +constexpr std::size_t OrderedFirstLaneLiteral = 9; alignas(256) std::array Output{}; alignas(16) std::array CounterReadback{}; @@ -49,13 +51,24 @@ alignas(256) auto Code = std::to_array({ alignas(256) auto OrderedCode = std::to_array({ 0x34060082, 0x4a020083, + 0x7e0a02ff, UntouchedOrdered, + 0x360400ff, 0x0000003f, 0xbefc03ff, 0x0000ffff, + 0x7da604ff, 0x00000000, 0xd8fe0310, 0x05000001, + 0xbefe04c1, 0xbf8cc07f, 0xe0702000, 0x80000503, 0xbf810000, }); +struct OrderedRun { + std::uint32_t m0; + std::uint32_t firstLaneEighths; +}; + +constexpr std::array OrderedRuns{{{0, 0}, {7, 0}, {7, 2}, {7, 5}}}; + struct Workgroup { std::uint32_t threads; std::uint32_t waveSize; @@ -144,24 +157,29 @@ void CheckWaves(const Workgroup& workgroup, std::uint32_t result, std::uint32_t } } -void CheckOrdered(const Workgroup& workgroup, std::uint32_t m0, const std::array& counters) { +void CheckOrdered(const Workgroup& workgroup, std::uint32_t m0, std::uint32_t firstLane, const std::array& counters) { const auto waves = workgroup.threads / workgroup.waveSize; - const auto what = workgroup.Name() + " ds_ordered_count with M0 " + std::to_string(m0); + const auto what = workgroup.Name() + " ds_ordered_count with M0 " + std::to_string(m0) + " from lane " + std::to_string(firstLane) + " of each wave"; + std::vector values(waves); std::vector order(waves); for (std::uint32_t wave = 0; wave < waves; ++wave) { order[wave] = wave; - const auto first = wave * workgroup.waveSize; - for (std::uint32_t lane = first; lane < first + workgroup.waveSize; ++lane) { + const auto first = wave * workgroup.waveSize + firstLane; + values[wave] = Output[first * Results]; + for (std::uint32_t lane = wave * workgroup.waveSize; lane < (wave + 1u) * workgroup.waveSize; ++lane) { const auto actual = Output[lane * Results]; - Require(actual == Output[first * Results], what + ": lane " + std::to_string(lane) + " returned " + std::to_string(actual) + ", its wave's first lane " + std::to_string(Output[first * Results])); + if (lane < first) { + Require(actual == UntouchedOrdered, what + ": inactive lane " + std::to_string(lane) + " was written " + std::to_string(actual)); + continue; + } + Require(actual == values[wave], what + ": lane " + std::to_string(lane) + " returned " + std::to_string(actual) + ", its wave's first active lane " + std::to_string(values[wave])); } } - std::sort(order.begin(), order.end(), [&](std::uint32_t left, std::uint32_t right) { return Output[left * workgroup.waveSize * Results] < Output[right * workgroup.waveSize * Results]; }); + std::sort(order.begin(), order.end(), [&](std::uint32_t left, std::uint32_t right) { return values[left] < values[right]; }); auto expected = Starts[0]; for (const auto wave : order) { - const auto first = wave * workgroup.waveSize; - Require(Output[first * Results] == expected, what + ": wave " + std::to_string(wave) + " returned " + std::to_string(Output[first * Results]) + ", expected " + std::to_string(expected)); - expected += first + 3u; + Require(values[wave] == expected, what + ": wave " + std::to_string(wave) + " returned " + std::to_string(values[wave]) + ", expected " + std::to_string(expected)); + expected += wave * workgroup.waveSize + firstLane + 3u; } Require(counters[0] == expected, what + ": GDS counter 0 is " + std::to_string(counters[0]) + ", expected " + std::to_string(expected)); } @@ -201,11 +219,14 @@ int main() { Run(*device, workgroup, Code); Check(workgroup, pass, ReadCounters(queue)); } - for (const auto m0 : OrderedM0) { + for (const auto& run : OrderedRuns) { + const auto firstLane = workgroup.waveSize * run.firstLaneEighths / 8u; SetCounters(queue); - OrderedCode[OrderedM0Literal] = m0; + OrderedCode[OrderedWaveMaskLiteral] = workgroup.waveSize - 1u; + OrderedCode[OrderedM0Literal] = run.m0; + OrderedCode[OrderedFirstLaneLiteral] = firstLane; Run(*device, workgroup, OrderedCode); - CheckOrdered(workgroup, m0, ReadCounters(queue)); + CheckOrdered(workgroup, run.m0, firstLane, ReadCounters(queue)); } } std::puts("gds append consume tests passed"); diff --git a/core/libs/prx/libScePad/Export.cpp b/core/libs/prx/libScePad/Export.cpp index df39b768f18a..667dfcff49cc 100644 --- a/core/libs/prx/libScePad/Export.cpp +++ b/core/libs/prx/libScePad/Export.cpp @@ -326,4 +326,749 @@ int APS5_VABI scePadVrControllerGetTriggerEffectStates(void) { return 0; } +int APS5_VABI scePadSetTriggerEffectExt(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadLastLotusButtonData(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadReadStateExt(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetExtensionReport(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetExtensionUnitInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadEnableExtensionPort(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadEnableSpecificDeviceClass(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadOpenExt2(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDeviceOpen(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetDataInternal(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetUserColor(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisableVibration(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetVibrationStrength(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLightBarBaseBrightness(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLightBarBlinking(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetIdleCount(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetControllerIdleCount(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetPowerSavingState(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetAutoPowerOffCount(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadEnableUsbConnection(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadEnableAutoDetect(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadEnablePlayPauseEmulation(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisableTrackingLedBatterySaver(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLoginUserNumber(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetCapability(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadShareOutputData(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadShareOutputDataWithFunctionType(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetVibrationForce(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetVersionInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetControllerType(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisableDataConversion(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetButtonRemappingInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetProcessPrivilegeOfButtonRemapping(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetForceIntercepted(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadIsLightBarBaseBrightnessControllable(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSwitchConnection(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisableTriggerEffect(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetTriggerEffectStrength(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetTriggerEffectInternalState(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetUserNumber(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisableTransportButtons(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLotusIrCodeSetStart(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLotusIrCodeSetData(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLotusIrCodeSetEnd(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetLotusIrCodeSetResult(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLotusEnableIrKey(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLotusDisableIrKey(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetUsbDetectionState(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadUiReadState(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadUiReadStateForTuning(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetStickTriggerTuningMode(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetStickTuningParam(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetTriggerTuningParam(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetProfileHunt(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetProfileHunt(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadResetHunt(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetProfileInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetActiveProfileInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisableActiveProfileChange(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisableActiveProfileChangeByDeviceId(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetActiveProfileSlot(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetSavedSettingInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetSavedSettingInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVrControllerGetPhysicalUsbConnectionStatus(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadParseUniqueDataLeonardo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetControllerTypeLeonardo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetControllerTypeLeonardo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetProfileLeonardo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetProfileLeonardo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadResetLeonardo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetProfileEditMode(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetProfileEditMode(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetProfileEditModeLeonardo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetSelectButtonCustomizeMode(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetSelectButtonCustomizeMode(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetToggleAllReleaseLeonardo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadEnableControllerIndicator(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadEnableProfileIndicator(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetProfileIndicatorAnimation(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadIsCoPilot(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetIsCoPilot(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadRegisterCollaboInputMgrProcess(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetTelemetryInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetActiveTime(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetDeviceId(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetInfoByPortType(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadResetLightBarAll(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadResetLightBarAllByPortType(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetLightBarForTracker(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadReadForTracker(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadReadBlasterForTracker(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadResetOrientationForTracker(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetMotionTimerUnit(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetVrTrackingMode(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetMotionSensorPosition(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetSphereRadius(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadIsValidHandle(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadIsDS4Connected(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadIsBlasterConnected(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadIsMoveConnected(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetBluetoothAddress(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadIsMoveReproductionModel(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadReadAstonForTracker(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetAstonModel(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadMbusInit(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadMbusTerm(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadConnectPort(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisconnectPort(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadDisconnectDevice(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetDeviceInfo(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetProcessFocus(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVertualDeviceAddDevice(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVirtualDeviceAddDevice(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVirtualDeviceDeleteDevice(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVirtualDeviceInsertData(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVirtualDeviceInsertTriggerInternalState(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVirtualDeviceGetRemoteSetting(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVirtualDeviceSetTriggerEffectSetting(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadVirtualDeviceDisableButtonRemapping(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetShareButtonMaskForRemotePlay(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetPS4BcVibrationMode(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetVirtualDeviceComponentInformation(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadEnablePs4CompatibleMode(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetLicenseControllerInformation(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadReadHistory(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadStartRecording(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadStopRecording(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadRemoteControlInsertData(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadRemoteControlInsertDataForAston(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadGetFeatureReport2(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetFeatureReport2(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadSetMuteLed(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadBondUpdateInit(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadBondUpdateIsReady(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadBondUpdateStart(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadBondUpdateGetStatus(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadBondUpdateSendData(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadBondUpdateResetBond(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadBondUpdateGetReconnectStatus(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadBondUpdateTerm(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateInit(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateIsUpdateNeeded2(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateIsReady(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateStart(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateGetStatus(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateSendData(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateResetController(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateGetReconnectStatus(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + +int APS5_VABI scePadControllerUpdateTerm(void) { + NotImplemented_nid_no_patch(__func__); + return 0; +} + } diff --git a/core/libs/prx/libc/src/LocaleSupport.cpp b/core/libs/prx/libc/src/LocaleSupport.cpp index dfb0d8e1fb67..b6b13077b9b5 100644 --- a/core/libs/prx/libc/src/LocaleSupport.cpp +++ b/core/libs/prx/libc/src/LocaleSupport.cpp @@ -311,6 +311,23 @@ void APS5_VABI _ZNSt8ios_baseD2Ev_nid_postfix(GuestLocale::IosBase* self) { self->locale = nullptr; } +GuestLocale::IosBase* APS5_VABI SetStreamWidth(GuestLocale::IosBase* stream, std::int32_t width) { + if (stream == nullptr) throw std::invalid_argument("setw: null stream"); + stream->width = width; + return stream; +} + +struct StreamManipulator { + GuestLocale::IosBase* (APS5_VABI* function)(GuestLocale::IosBase*, std::int32_t); + std::int32_t argument; +}; + +static_assert(sizeof(StreamManipulator) == 0x10); + +StreamManipulator APS5_VABI _ZSt4setwi_nid_postfix(std::int32_t width) { + return {&SetStreamWidth, width}; +} + // Dinkumware's static locale::_Init(bool) returns the global _Locimp, which the caller copies. GuestLocale::Implementation* APS5_VABI _ZNSt6locale5_InitEv_nid_postfix() { std::lock_guard lock(g_localeInitMutex); diff --git a/core/libs/prx/libc/src/Math.cpp b/core/libs/prx/libc/src/Math.cpp index 329df1773091..57580273b5ba 100644 --- a/core/libs/prx/libc/src/Math.cpp +++ b/core/libs/prx/libc/src/Math.cpp @@ -539,6 +539,8 @@ long double APS5_VABI log10l_nid_postfix(long double x) { return std::log10(x); long double APS5_VABI powl_nid_postfix(long double base, long double exp) { return std::pow(base, exp); } long double APS5_VABI ldexpl_nid_postfix(long double x, int exp) { return std::ldexp(x, exp); } long double APS5_VABI truncl_nid_postfix(long double x) { return std::trunc(x); } +long double APS5_VABI ceill_nid_postfix(long double x) { return std::ceil(x); } +long double APS5_VABI floorl_nid_postfix(long double x) { return std::floor(x); } double APS5_VABI logb_nid_postfix(double x) { return std::logb(x); } double APS5_VABI remainder_nid_postfix(double x, double y) { return std::remainder(x, y); } float APS5_VABI _FSinh_nid_postfix(float x, float y) { return y * std::sinh(x); } diff --git a/core/libs/prx/libc/src/StandardStreams.cpp b/core/libs/prx/libc/src/StandardStreams.cpp index 9451e5edcdaf..c88a04bbc9ca 100644 --- a/core/libs/prx/libc/src/StandardStreams.cpp +++ b/core/libs/prx/libc/src/StandardStreams.cpp @@ -4,10 +4,26 @@ #ifdef _WIN32 #include #else +#include #include #endif -namespace { FileStream input{stdin}; } +namespace { +#ifndef _WIN32 +const bool standardDescriptorsOpen = [] { + for (int descriptor = 0; descriptor <= 2; ++descriptor) { + if (::fcntl(descriptor, F_GETFD) != -1 || errno != EBADF) continue; + const int opened = ::open("/dev/null", descriptor == 0 ? O_RDONLY : O_WRONLY); + if (opened > descriptor) { + ::dup2(opened, descriptor); + ::close(opened); + } + } + return true; +}(); +#endif +FileStream input{stdin}; +} extern "C" { FileStream* __stdinp_nid_postfix = &input; FileStream* __stdoutp_nid_postfix = &_Stdout_nid_postfix; diff --git a/core/libs/prx/libkernel/CMakeLists.txt b/core/libs/prx/libkernel/CMakeLists.txt index 7a828fd51e7d..025600c856c1 100644 --- a/core/libs/prx/libkernel/CMakeLists.txt +++ b/core/libs/prx/libkernel/CMakeLists.txt @@ -70,6 +70,7 @@ add_library(libkernel SHARED EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/System/src/SystemConfiguration.cpp ${CMAKE_CURRENT_SOURCE_DIR}/System/src/Login.cpp ${CMAKE_CURRENT_SOURCE_DIR}/System/src/SoftwareVersion.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/System/src/Error.cpp ${CMAKE_CURRENT_SOURCE_DIR}/System/src/ThermalSensors.cpp ${CMAKE_CURRENT_SOURCE_DIR}/System/src/Signals.cpp ${CMAKE_CURRENT_SOURCE_DIR}/System/src/SignalSets.cpp @@ -94,6 +95,15 @@ endif() configure_windows_unwind(libkernel) if(BUILD_TESTING) + add_test_executable(kernel_error_tests ${LIBS_INCLUDE_DIR}/tests/KernelError.cpp) + target_include_directories(kernel_error_tests PRIVATE ${LIBS_INCLUDE_DIR}) + target_link_libraries(kernel_error_tests PRIVATE libkernel libc) + configure_windows_unwind(kernel_error_tests) + add_test(NAME kernel_error COMMAND kernel_error_tests) + if(WIN32) + set_tests_properties(kernel_error PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() if(NOT WIN32) add_library(guest_memory_lifetime_module MODULE ${LIBS_INCLUDE_DIR}/tests/GuestMemoryLifetimeModule.cpp) target_include_directories(guest_memory_lifetime_module PRIVATE ${LIBS_INCLUDE_DIR}) @@ -148,6 +158,20 @@ if(BUILD_TESTING) set_tests_properties(guest_posix_sem_init guest_posix_sem_post PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") endif() + add_test_executable(guest_wait_trace_tests ${LIBS_INCLUDE_DIR}/tests/GuestWaitTrace.cpp) + target_include_directories(guest_wait_trace_tests PRIVATE ${LIBS_INCLUDE_DIR}) + target_link_libraries(guest_wait_trace_tests PRIVATE libkernel libc) + configure_windows_unwind(guest_wait_trace_tests) + add_test(NAME guest_wait_trace COMMAND guest_wait_trace_tests) + set_tests_properties(guest_wait_trace PROPERTIES + ENVIRONMENT "APS5_TRACE_WAITS=1" + PASS_REGULAR_EXPRESSION "wait_trace_active_zero[^|]*x1" + FAIL_REGULAR_EXPRESSION "wait_trace_inactive[^|]*x0" + TIMEOUT 30) + if(WIN32) + set_tests_properties(guest_wait_trace PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() add_test_executable(guest_process_time_tests ${LIBS_INCLUDE_DIR}/tests/GuestProcessTime.cpp) target_include_directories(guest_process_time_tests PRIVATE ${LIBS_INCLUDE_DIR}) target_link_libraries(guest_process_time_tests PRIVATE libkernel libc) @@ -261,6 +285,11 @@ if(BUILD_TESTING) target_link_libraries(guest_host_standard_error_tests PRIVATE libkernel libc) add_test(NAME guest_host_standard_error COMMAND guest_host_standard_error_tests) set_tests_properties(guest_host_standard_error PROPERTIES TIMEOUT 10) + add_test_executable(guest_closed_standard_descriptors_tests ${LIBS_INCLUDE_DIR}/tests/GuestClosedStandardDescriptors.cpp) + target_include_directories(guest_closed_standard_descriptors_tests PRIVATE ${LIBS_INCLUDE_DIR}) + target_link_libraries(guest_closed_standard_descriptors_tests PRIVATE libkernel libc) + add_test(NAME guest_closed_standard_descriptors COMMAND guest_closed_standard_descriptors_tests) + set_tests_properties(guest_closed_standard_descriptors PROPERTIES TIMEOUT 10) endif() add_test_executable(guest_truncate_tests ${LIBS_INCLUDE_DIR}/tests/GuestTruncate.cpp) target_include_directories(guest_truncate_tests PRIVATE ${LIBS_INCLUDE_DIR}) diff --git a/core/libs/prx/libkernel/File/include/File.hpp b/core/libs/prx/libkernel/File/include/File.hpp index 4a14063e0e9d..54e788dc5d3c 100644 --- a/core/libs/prx/libkernel/File/include/File.hpp +++ b/core/libs/prx/libkernel/File/include/File.hpp @@ -21,11 +21,10 @@ int APS5_VABI sceKernelFcntl(int d, int command, ...); #ifdef _WIN32 std::int64_t NativePositioned_nid_no_patch(int descriptor, void* buf, std::size_t nbytes, std::int64_t offset, bool write); #endif +bool DescriptorIsOpen_nid_no_patch(int descriptor); } -bool DescriptorIsOpen_nid_no_patch(int descriptor); - namespace File { int HostStandardError(); [[nodiscard]] std::unique_lock LockPositionedTransfer(int descriptor); diff --git a/core/libs/prx/libkernel/Pthread/src/Thread.cpp b/core/libs/prx/libkernel/Pthread/src/Thread.cpp index b8b58d16a784..c0ed813751ad 100644 --- a/core/libs/prx/libkernel/Pthread/src/Thread.cpp +++ b/core/libs/prx/libkernel/Pthread/src/Thread.cpp @@ -836,9 +836,9 @@ int APS5_VABI scePthreadCreate(Pthread* thread, const PthreadAttr* attr, Pthread int APS5_VABI scePthreadJoin(Pthread thread, void** retval) { if (!thread) return SCE_KERNEL_ERROR_EINVAL; + if (thread == CurrentGuestState().current) return SCE_KERNEL_ERROR_EDEADLK; if (thread->_detached) return SCE_KERNEL_ERROR_EINVAL; if (thread->_joined.load(std::memory_order_acquire)) return SCE_KERNEL_ERROR_ESRCH; - if (thread == CurrentGuestState().current) return SCE_KERNEL_ERROR_EDEADLK; ThreadCancel::Check(); { std::unique_lock lock(thread->_join_mtx); diff --git a/core/libs/prx/libkernel/System/src/Error.cpp b/core/libs/prx/libkernel/System/src/Error.cpp new file mode 100644 index 000000000000..a0eb19f9b636 --- /dev/null +++ b/core/libs/prx/libkernel/System/src/Error.cpp @@ -0,0 +1,8 @@ +#include "prx/libc/include/general/VabiMacros.hpp" +#include +#include + +extern "C" std::int32_t APS5_VABI sceKernelError(std::int32_t posixError) { + if (posixError == 0) return 0; + return std::bit_cast(static_cast(posixError) + 0x80020000u); +} diff --git a/core/libs/prx/libkernel/System/src/Signals.cpp b/core/libs/prx/libkernel/System/src/Signals.cpp index 23f4e7f97723..b4c82be76aea 100644 --- a/core/libs/prx/libkernel/System/src/Signals.cpp +++ b/core/libs/prx/libkernel/System/src/Signals.cpp @@ -526,6 +526,7 @@ int APS5_VABI sigaltstack_nid_postfix(const GuestStack* stack, GuestStack* previ return 0; } int APS5_VABI _sigprocmask_nid_postfix(int how, const GuestSignalSet* set, GuestSignalSet* previousSet) { + if (set != nullptr && (how < 1 || how > 3)) { *__error_nid_postfix() = 22; return -1; } { std::lock_guard lock(registration); if (previousSet != nullptr) { @@ -546,7 +547,6 @@ int APS5_VABI _sigprocmask_nid_postfix(int how, const GuestSignalSet* set, Guest blockedMask.store(set->bits[0]); for (int word = 1; word < 4; ++word) blockedMaskExtra[word - 1].store(set->bits[word]); break; - default: throw std::invalid_argument("_sigprocmask: invalid how"); } } } diff --git a/core/libs/prx/libkernel/Time/Time.cpp b/core/libs/prx/libkernel/Time/Time.cpp index 3d0f7c9cdf89..59786a1ffaed 100644 --- a/core/libs/prx/libkernel/Time/Time.cpp +++ b/core/libs/prx/libkernel/Time/Time.cpp @@ -262,6 +262,7 @@ void KernelTraceWait_nid_postfix(const char* kind, const void* caller, std::uint if (now - lastReport < 3000000000ULL) return; lastReport = now; std::vector> hot(sites.begin(), sites.end()); + std::erase_if(hot, [](const auto& item) { return item.second.calls == 0; }); std::sort(hot.begin(), hot.end(), [](const auto& a, const auto& b) { return a.second.nanos > b.second.nanos; }); std::fprintf(stderr, "[waits]"); for (std::size_t i = 0; i < hot.size() && i < 8; ++i) { diff --git a/core/libs/prx/libkernel_sys/Export.cpp b/core/libs/prx/libkernel_sys/Export.cpp index a1124a0dd607..40d4e7a55dc6 100644 --- a/core/libs/prx/libkernel_sys/Export.cpp +++ b/core/libs/prx/libkernel_sys/Export.cpp @@ -26,6 +26,7 @@ #include "prx/libkernel/File/include/DirectoryDescriptor.hpp" #include "prx/libc/include/CreationMask.hpp" #include "prx/libkernel/File/include/FileFlags.hpp" +#include "prx/libkernel/File/include/File.hpp" #ifdef _WIN32 #ifndef NOMINMAX #define NOMINMAX @@ -45,6 +46,7 @@ constexpr int GuestEnoent = 2; constexpr int GuestEperm = 1; constexpr int GuestEio = 5; constexpr int GuestEfault = 14; +constexpr int GuestEbadf = 9; constexpr int GuestEnotdir = 20; constexpr int GuestEisdir = 21; constexpr int GuestEinval = 22; @@ -109,6 +111,37 @@ std::int64_t Fail(int error) { return -1; } +std::int64_t PathConfigurationValue(int name, const char* function) { + switch (name) { + case PcLinkMax: return 32767; + case PcNameMax: return static_cast(GuestNameMax); + case PcPathMax: return static_cast(GuestPathMax); + case PcPipeBuf: return 512; + case PcChownRestricted: return 1; + case PcNoTrunc: return 1; + case PcFileSizeBits: return 64; + case PcRecMaxXferSize: return -1; + case PcSymlinkMax: return static_cast(GuestPathMax); + case PcPrioIo: return 0; + case PcSyncIo: return 0; + case PcMaxCanon: + case PcMaxInput: + case PcVdisable: + case PcAllocSizeMin: + case PcRecIncrXferSize: + case PcRecMinXferSize: + case PcRecXferAlign: + case PcMinHoleSize: + case PcAsyncIo: + case PcAclExtended: + case PcAclPathMax: + case PcMacPresent: + case PcAclNfs4: + throw std::runtime_error(std::string(function) + ": name " + std::to_string(name) + " depends on the console filesystem or kernel configuration"); + default: return Fail(GuestEinval); + } +} + int GuestError(const std::error_code& error) { const auto condition = error.default_error_condition(); if (condition == std::errc::resource_unavailable_try_again) return GuestEagain; @@ -329,34 +362,16 @@ std::int64_t APS5_VABI pathconf_nid_postfix(const char* path, int name) { const auto status = std::filesystem::status(native, error); if (error) return Fail(GuestError(error)); if (!std::filesystem::exists(status)) return Fail(GuestEnoent); - switch (name) { - case PcLinkMax: return 32767; - case PcNameMax: return static_cast(GuestNameMax); - case PcPathMax: return static_cast(GuestPathMax); - case PcPipeBuf: return 512; - case PcChownRestricted: return 1; - case PcNoTrunc: return 1; - case PcFileSizeBits: return 64; - case PcRecMaxXferSize: return -1; - case PcSymlinkMax: return static_cast(GuestPathMax); - case PcPrioIo: return 0; - case PcSyncIo: return 0; - case PcMaxCanon: - case PcMaxInput: - case PcVdisable: - case PcAllocSizeMin: - case PcRecIncrXferSize: - case PcRecMinXferSize: - case PcRecXferAlign: - case PcMinHoleSize: - case PcAsyncIo: - case PcAclExtended: - case PcAclPathMax: - case PcMacPresent: - case PcAclNfs4: - throw std::runtime_error("pathconf: name " + std::to_string(name) + " depends on the console filesystem or kernel configuration"); - default: return Fail(GuestEinval); - } + return PathConfigurationValue(name, "pathconf"); +} + +std::int64_t APS5_VABI _fpathconf_nid_postfix(int fd, int name) { + if (fd < 0 || !DescriptorIsOpen_nid_no_patch(fd)) return Fail(GuestEbadf); + return PathConfigurationValue(name, "fpathconf"); +} + +std::int64_t APS5_VABI fpathconf_nid_postfix(int fd, int name) { + return _fpathconf_nid_postfix(fd, name); } int APS5_VABI link_nid_postfix(const char* existing, const char* created) { diff --git a/core/libs/tests/GuestClosedStandardDescriptors.cpp b/core/libs/tests/GuestClosedStandardDescriptors.cpp new file mode 100644 index 000000000000..4cb0deece158 --- /dev/null +++ b/core/libs/tests/GuestClosedStandardDescriptors.cpp @@ -0,0 +1,66 @@ +#include "prx/libc/include/general/VabiMacros.hpp" +#include +#include +#include +#include +#include +#include + +extern "C" { +int APS5_VABI fcntl_nid_postfix(int, int, ...); +} + +namespace { + +constexpr int GuestGetFlags = 3; + +int Child(const char* closed) { + struct stat null{}; + if (::stat("/dev/null", &null) != 0) return 70; + for (int descriptor = 0; descriptor <= 2; ++descriptor) { + struct stat status{}; + if (::fstat(descriptor, &status) != 0) return 71 + descriptor; + if (closed[descriptor] != '1') continue; + if (!S_ISCHR(status.st_mode) || status.st_rdev != null.st_rdev) return 74 + descriptor; + if ((::fcntl(descriptor, F_GETFL) & O_ACCMODE) != (descriptor == 0 ? O_RDONLY : O_WRONLY)) return 77 + descriptor; + } + if (closed[0] == '1' && fcntl_nid_postfix(0, GuestGetFlags) < 0) return 80; + return 0; +} + +int RunClosed(const char* self, bool closeInput, bool closeOutput, bool closeError) { + const pid_t child = ::fork(); + if (child < 0) return -1; + if (child == 0) { + if (closeInput) ::close(0); + if (closeOutput) ::close(1); + if (closeError) ::close(2); + char closed[] = {closeInput ? '1' : '0', closeOutput ? '1' : '0', closeError ? '1' : '0', '\0'}; + char* const arguments[] = {const_cast(self), const_cast("--closed-child"), closed, nullptr}; + ::execv(self, arguments); + ::_exit(69); + } + int status = 0; + if (::waitpid(child, &status, 0) != child) return -1; + return WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status); +} + +} + +int main(int argc, char** argv) { + if (argc > 2 && std::strcmp(argv[1], "--closed-child") == 0 && std::strlen(argv[2]) == 3) return Child(argv[2]); + const struct { bool input, output, error; const char* name; } cases[] = { + {true, false, false, "stdin"}, + {false, true, false, "stdout"}, + {true, true, true, "all three"}, + }; + for (const auto& test : cases) { + const int result = RunClosed(argv[0], test.input, test.output, test.error); + if (result != 0) { + std::fprintf(stderr, "closed standard descriptors, %s: child exited with %d\n", test.name, result); + return 1; + } + } + std::puts("closed standard descriptors are reopened on /dev/null"); + return 0; +} diff --git a/core/libs/tests/GuestCredentials.cpp b/core/libs/tests/GuestCredentials.cpp index 01cc2d30037c..a87d68f39edf 100644 --- a/core/libs/tests/GuestCredentials.cpp +++ b/core/libs/tests/GuestCredentials.cpp @@ -14,7 +14,9 @@ int APS5_VABI setgroups_nid_postfix(int, const std::uint32_t*); int APS5_VABI getgroups_nid_postfix(int, std::uint32_t*); int APS5_VABI getuid_nid_postfix(void); int APS5_VABI geteuid_nid_postfix(void); +int APS5_VABI getgid_nid_postfix(void); int APS5_VABI getegid_nid_postfix(void); +int APS5_VABI issetugid_nid_postfix(void); int* APS5_VABI __error_nid_postfix(); } @@ -61,6 +63,7 @@ int main() { Require(setuid_nid_postfix(0) == 0); Require(getuid_nid_postfix() == 0 && geteuid_nid_postfix() == 0); + Require(getgid_nid_postfix() == 0 && getegid_nid_postfix() == 0 && issetugid_nid_postfix() == 0); Require(setreuid_nid_postfix(Unchanged, Unchanged) == 0); Require(setreuid_nid_postfix(0, Unchanged) == 0); Require(setreuid_nid_postfix(Unchanged, 0) == 0); diff --git a/core/libs/tests/GuestKernelSys.cpp b/core/libs/tests/GuestKernelSys.cpp index e557b1a1cc9f..10f556fdbc51 100644 --- a/core/libs/tests/GuestKernelSys.cpp +++ b/core/libs/tests/GuestKernelSys.cpp @@ -28,6 +28,8 @@ int APS5_VABI open_nid_postfix(const char*, int, int); int APS5_VABI close_nid_postfix(int); std::int64_t APS5_VABI readlink_nid_postfix(const char*, char*, std::size_t); std::int64_t APS5_VABI pathconf_nid_postfix(const char*, int); +std::int64_t APS5_VABI fpathconf_nid_postfix(int, int); +std::int64_t APS5_VABI _fpathconf_nid_postfix(int, int); int APS5_VABI fchdir_nid_postfix(int); int APS5_VABI chdir_nid_postfix(const char*); int APS5_VABI chroot_nid_postfix(const char*); @@ -110,6 +112,38 @@ void CheckPathconf(const std::filesystem::path& root, const std::string& file) { Require(pathconf_nid_postfix(longPath.c_str(), 4) == -1 && Error() == 63); } +template +bool DescriptorPathconfThrows(F fn, int descriptor, int name) { + try { + fn(descriptor, name); + } catch (const std::runtime_error&) { + return true; + } + return false; +} + +template +void CheckDescriptorPathconf(F fn, int descriptor) { + Require(fn(descriptor, 1) == 32767); + Require(fn(descriptor, 4) == 255); + Require(fn(descriptor, 5) == 1024); + Require(fn(descriptor, 6) == 512); + Require(fn(descriptor, 7) == 1); + Require(fn(descriptor, 8) == 1); + Require(fn(descriptor, 12) == 64); + *__error_nid_postfix() = 0; + Require(fn(descriptor, 15) == -1 && Error() == 0); + Require(fn(descriptor, 18) == 1024); + Require(fn(descriptor, 54) == 0); + Require(fn(descriptor, 55) == 0); + for (const int name : {0, 11, 61, 62, 65, -1}) + Require(fn(descriptor, name) == -1 && Error() == 22); + for (const int name : {2, 3, 9, 10, 14, 16, 17, 21, 53, 59, 60, 63, 64}) + Require(DescriptorPathconfThrows(fn, descriptor, name)); + Require(fn(-1, 4) == -1 && Error() == 9); + Require(fn(descriptor + 1000, 4) == -1 && Error() == 9); +} + int main() { Require(setsid_nid_postfix() == -1 && Error() == 1); Require(umask_nid_postfix(0) == 022); @@ -129,8 +163,17 @@ int main() { Require(std::memcmp(viaPublic, viaSyscall, 4) == 0 && std::memcmp(viaPublic + 16, viaSyscall + 16, 8) == 0); Require(std::memcmp(viaPublic + 280, viaSyscall + 280, 16) == 0); Require(fstatfs_nid_postfix(descriptor, nullptr) == -1 && Error() == 14); + CheckDescriptorPathconf(fpathconf_nid_postfix, descriptor); + CheckDescriptorPathconf(_fpathconf_nid_postfix, descriptor); Require(close_nid_postfix(descriptor) == 0); Require(fstatfs_nid_postfix(-1, viaPublic) == -1 && Error() == 9); + Require(fpathconf_nid_postfix(descriptor, 4) == -1 && Error() == 9); + Require(_fpathconf_nid_postfix(descriptor, 4) == -1 && Error() == 9); + const int dirDescriptor = open_nid_postfix(root.generic_string().c_str(), 0, 0); + Require(dirDescriptor >= 0); + CheckDescriptorPathconf(fpathconf_nid_postfix, dirDescriptor); + CheckDescriptorPathconf(_fpathconf_nid_postfix, dirDescriptor); + Require(close_nid_postfix(dirDescriptor) == 0); char buffer[64]; for (const auto& component : {std::string("missing"), std::string("file.txt")}) { const auto prefix = root.generic_string() + "/" + component + "/../"; diff --git a/core/libs/tests/GuestLocale.cpp b/core/libs/tests/GuestLocale.cpp index 04ddac5f380f..a72216251bc0 100644 --- a/core/libs/tests/GuestLocale.cpp +++ b/core/libs/tests/GuestLocale.cpp @@ -19,6 +19,11 @@ void APS5_VABI _ZNSt6locale5facet9_RegisterEv_nid_postfix(GuestLocale::Facet* se void APS5_VABI _ZNSt8_LocinfoC1EPKc_nid_postfix(GuestLocale::LocinfoStorage* self, const char* localeName); void APS5_VABI _ZNSt8_LocinfoD1Ev_nid_postfix(GuestLocale::LocinfoStorage* self); void APS5_VABI _ZNSt8ios_baseD2Ev_nid_postfix(GuestLocale::IosBase* self); +struct StreamManipulator { + GuestLocale::IosBase* (APS5_VABI* function)(GuestLocale::IosBase*, std::int32_t); + std::int32_t argument; +}; +StreamManipulator APS5_VABI _ZSt4setwi_nid_postfix(std::int32_t width); const short* APS5_VABI _Getpctype_nid_postfix(); const short* APS5_VABI _Getptolower_nid_postfix(); const short* APS5_VABI _Getptoupper_nid_postfix(); @@ -152,6 +157,25 @@ static void CheckStreamDestruction() { Require(object.stream.locale == &_ZSt21_sceLibcClassicLocale_nid_postfix); } +static void CheckStreamWidth() { + struct GuardedStream { + std::uint64_t before = 0x12345678; + GuestLocale::IosBase stream{}; + std::uint64_t after = 0x87654321; + } object; + object.stream.flags = 0x4000; + object.stream.precision = 6; + const auto manipulator = _ZSt4setwi_nid_postfix(12); + Require(manipulator.argument == 12 && manipulator.function != nullptr); + Require(manipulator.function(&object.stream, manipulator.argument) == &object.stream); + Require(object.stream.width == 12 && object.stream.flags == 0x4000 && object.stream.precision == 6); + Require(object.before == 0x12345678 && object.after == 0x87654321); + const auto reset = _ZSt4setwi_nid_postfix(0); + reset.function(&object.stream, reset.argument); + Require(object.stream.width == 0); + RequireException([&] { manipulator.function(nullptr, manipulator.argument); }); +} + static void CheckWideCaseTranslation() { const auto* lower = _Getptolower_nid_postfix(); const auto* upper = _Getptoupper_nid_postfix(); @@ -180,6 +204,7 @@ int main() { CheckCharacterTables(); CheckCharacterConversions(); CheckStreamDestruction(); + CheckStreamWidth(); CheckWideCaseTranslation(); _Locksyslock_nid_postfix(); _Locksyslock_nid_postfix(); diff --git a/core/libs/tests/GuestMath.cpp b/core/libs/tests/GuestMath.cpp index 493a6853b554..183a8eeef0f7 100644 --- a/core/libs/tests/GuestMath.cpp +++ b/core/libs/tests/GuestMath.cpp @@ -71,6 +71,8 @@ double APS5_VABI asin_nid_postfix(double); float APS5_VABI atan2f_nid_postfix(float, float); float APS5_VABI hypotf_nid_postfix(float, float); double APS5_VABI hypot_nid_postfix(double, double); +long double APS5_VABI ceill_nid_postfix(long double); +long double APS5_VABI floorl_nid_postfix(long double); float APS5_VABI tanf_nid_postfix(float); int APS5_VABI rand_nid_postfix(); void APS5_VABI srand_nid_postfix(unsigned int); @@ -377,6 +379,10 @@ static void CheckLongDouble() { Require(frexpl_nid_postfix(INFINITY, &exponent) == INFINITY && exponent == 77); Require(frexpl_nid_postfix(-INFINITY, &exponent) == -INFINITY && exponent == 77); Require(std::isnan(frexpl_nid_postfix(NAN, &exponent)) && exponent == 77); + Require(ceill_nid_postfix(2.2L) == 3.0L && ceill_nid_postfix(-2.7L) == -2.0L); + Require(floorl_nid_postfix(2.7L) == 2.0L && floorl_nid_postfix(-2.2L) == -3.0L); + Require(ceill_nid_postfix(2.0L) == 2.0L && floorl_nid_postfix(-2.0L) == -2.0L); + Require(std::isnan(ceill_nid_postfix(NAN)) && std::isnan(floorl_nid_postfix(NAN))); } static void CheckNearbyintl() { diff --git a/core/libs/tests/GuestPthreadJoinSelf.cpp b/core/libs/tests/GuestPthreadJoinSelf.cpp index 742fa9d7341b..2fec26bef7ca 100644 --- a/core/libs/tests/GuestPthreadJoinSelf.cpp +++ b/core/libs/tests/GuestPthreadJoinSelf.cpp @@ -1,12 +1,16 @@ #include "SceTypes.hpp" +#include +#include #include #include +#include extern "C" { int APS5_VABI scePthreadCreate(Pthread* thread, const PthreadAttr* attr, PthreadEntry entry, void* arg, const char* name); int APS5_VABI scePthreadJoin(Pthread thread, void** retval); Pthread APS5_VABI scePthreadSelf(void); int APS5_VABI pthread_join_nid_postfix(Pthread thread, void** retval); +int APS5_VABI scePthreadDetach(Pthread thread); } static constexpr int SCE_OK = 0; @@ -23,6 +27,18 @@ static void* APS5_VABI JoinSelf(void*) { return reinterpret_cast(std::uintptr_t{0x1234}); } +static std::atomic detachedChecks{0}; + +static void* APS5_VABI DetachThenJoinSelf(void*) { + void* result = reinterpret_cast(std::uintptr_t{0x66}); + Require(scePthreadDetach(scePthreadSelf()) == SCE_OK); + Require(scePthreadJoin(scePthreadSelf(), &result) == SCE_KERNEL_ERROR_EDEADLK); + Require(pthread_join_nid_postfix(scePthreadSelf(), &result) == GUEST_EDEADLK); + Require(result == reinterpret_cast(std::uintptr_t{0x66})); + detachedChecks.store(1); + return nullptr; +} + int main() { Pthread thread = nullptr; void* result = nullptr; @@ -36,4 +52,14 @@ int main() { Require(scePthreadCreate(&thread, &unset, JoinSelf, nullptr, "unset-attr") == SCE_OK); Require(scePthreadJoin(thread, &result) == SCE_OK); Require(result == reinterpret_cast(std::uintptr_t{0x1234})); + + thread = nullptr; + Require(scePthreadCreate(&thread, nullptr, DetachThenJoinSelf, nullptr, "detach-join-self") == SCE_OK); + for (int wait = 0; wait < 5000 && detachedChecks.load() == 0; ++wait) std::this_thread::sleep_for(std::chrono::milliseconds(1)); + Require(detachedChecks.load() == 1); + + result = reinterpret_cast(std::uintptr_t{0x77}); + Require(scePthreadJoin(scePthreadSelf(), &result) == SCE_KERNEL_ERROR_EDEADLK); + Require(pthread_join_nid_postfix(scePthreadSelf(), &result) == GUEST_EDEADLK); + Require(result == reinterpret_cast(std::uintptr_t{0x77})); } diff --git a/core/libs/tests/GuestSignalSets.cpp b/core/libs/tests/GuestSignalSets.cpp index ddbea3ad0211..786ddae94bc8 100644 --- a/core/libs/tests/GuestSignalSets.cpp +++ b/core/libs/tests/GuestSignalSets.cpp @@ -19,6 +19,7 @@ int APS5_VABI sigdelset_nid_postfix(GuestSignalSet*, int); int APS5_VABI sigismember_nid_postfix(const GuestSignalSet*, int); int* APS5_VABI __error_nid_postfix(); int APS5_VABI _sigprocmask_nid_postfix(int, const GuestSignalSet*, GuestSignalSet*); +int APS5_VABI sigprocmask_nid_postfix(int, const void*, void*); [[gnu::returns_twice]] int APS5_VABI sigsetjmp_nid_postfix(std::uint64_t* buffer, int saveMask); [[noreturn]] void APS5_VABI siglongjmp_nid_postfix(std::uint64_t* buffer, int value); int APS5_VABI JumpKeepingCalleeSaved(std::uint64_t* buffer); @@ -164,9 +165,28 @@ static void CheckSigsetjmp() { SetBlockedMask(0); } +static void CheckInvalidHow() { + SetBlockedMask(0x5u); + const GuestSignalSet blocked{{0x30u, 0, 0, 0}}; + for (const int how : {0, 4, -1, 1000}) { + GuestSignalSet previous{{0xa5a5a5a5u, 0xa5a5a5a5u, 0xa5a5a5a5u, 0xa5a5a5a5u}}; + *__error_nid_postfix() = 0; + Require(_sigprocmask_nid_postfix(how, &blocked, &previous) == -1 && *__error_nid_postfix() == 22); + Require(Equals(previous, 0xa5a5a5a5u, 0xa5a5a5a5u, 0xa5a5a5a5u, 0xa5a5a5a5u)); + *__error_nid_postfix() = 0; + Require(sigprocmask_nid_postfix(how, &blocked, &previous) == -1 && *__error_nid_postfix() == 22); + Require(Equals(previous, 0xa5a5a5a5u, 0xa5a5a5a5u, 0xa5a5a5a5u, 0xa5a5a5a5u)); + Require(BlockedMask() == 0x5u); + Require(_sigprocmask_nid_postfix(how, nullptr, &previous) == 0); + Require(Equals(previous, 0x5u, 0, 0, 0)); + } + SetBlockedMask(0); +} + int main() { CheckSigsetjmp(); CheckSiglongjmp(); + CheckInvalidHow(); static constexpr int Untouched = 5; GuestSignalSet set{{0x12345678u, 0x9abcdef0u, 0xffffffffu, 1u}}; *__error_nid_postfix() = Untouched; diff --git a/core/libs/tests/GuestThreadSelf.cpp b/core/libs/tests/GuestThreadSelf.cpp index 9c59471e9149..c94f557187a1 100644 --- a/core/libs/tests/GuestThreadSelf.cpp +++ b/core/libs/tests/GuestThreadSelf.cpp @@ -110,7 +110,8 @@ int main() { Require(pthread_getthreadid_np_nid_postfix() == static_cast(mainTid)); int local = 0; Require(StackContains(mainSelf, &local)); - Require(scePthreadJoin(mainSelf, nullptr) == SCE_KERNEL_ERROR_EINVAL); + Require(scePthreadJoin(mainSelf, nullptr) == SCE_KERNEL_ERROR_EDEADLK); + Require(pthread_join_nid_postfix(mainSelf, nullptr) == GUEST_EDEADLK); Require(scePthreadDetach(mainSelf) == SCE_KERNEL_ERROR_EINVAL); Require(scePthreadJoin(nullptr, nullptr) == SCE_KERNEL_ERROR_EINVAL); Require(scePthreadDetach(nullptr) == SCE_KERNEL_ERROR_EINVAL); diff --git a/core/libs/tests/GuestWaitTrace.cpp b/core/libs/tests/GuestWaitTrace.cpp new file mode 100644 index 000000000000..92f3c7f30af3 --- /dev/null +++ b/core/libs/tests/GuestWaitTrace.cpp @@ -0,0 +1,16 @@ +#include "prx/libkernel/Time/include/Time.hpp" +#include +#include +#include + +int main() { + const std::array inactive{}; + const int active = 0; + const int zeroDuration = 0; + for (const auto& site : inactive) KernelTraceWait_nid_postfix("wait_trace_inactive", &site, 1000000u, false); + std::this_thread::sleep_for(std::chrono::milliseconds(3100)); + KernelTraceWait_nid_postfix("wait_trace_active", &active, 2000000u, false); + std::this_thread::sleep_for(std::chrono::milliseconds(3100)); + KernelTraceWait_nid_postfix("wait_trace_active_zero", &zeroDuration, 0u, false); + return 0; +} diff --git a/core/libs/tests/KernelError.cpp b/core/libs/tests/KernelError.cpp new file mode 100644 index 000000000000..9355bd4b640c --- /dev/null +++ b/core/libs/tests/KernelError.cpp @@ -0,0 +1,28 @@ +#include "prx/libc/include/general/VabiMacros.hpp" +#include "prx/libkernel/KernelErrors.hpp" +#include +#include +#include +#include +#include + +extern "C" std::int32_t APS5_VABI sceKernelError(std::int32_t); +extern "C" int* APS5_VABI __error_nid_postfix(); + +static void Require(bool value) { if (!value) throw std::runtime_error("Kernel error conversion check failed"); } + +int main() { + *__error_nid_postfix() = 123; + const std::array, 6> cases{{ + {0, 0}, {1, SCE_KERNEL_ERROR_EPERM}, {2, SCE_KERNEL_ERROR_ENOENT}, + {4, SCE_KERNEL_ERROR_EINTR}, {14, SCE_KERNEL_ERROR_EFAULT}, {22, SCE_KERNEL_ERROR_EINVAL} + }}; + for (const auto [input, expected] : cases) { + Require(sceKernelError(input) == expected); + Require(*__error_nid_postfix() == 123); + } + Require(sceKernelError(-1) == static_cast(0x8001ffffu)); + Require(sceKernelError(std::numeric_limits::max()) == 0x1ffff); + Require(sceKernelError(std::numeric_limits::min()) == 0x20000); + Require(*__error_nid_postfix() == 123); +} diff --git a/core/shader/recompiler/Optimization/src/ConstantFolder.cpp b/core/shader/recompiler/Optimization/src/ConstantFolder.cpp index 3d51bdbb64e9..d047e7efdf0b 100644 --- a/core/shader/recompiler/Optimization/src/ConstantFolder.cpp +++ b/core/shader/recompiler/Optimization/src/ConstantFolder.cpp @@ -876,6 +876,23 @@ void ConstantFolder::Fold(IrProgram& program, std::span blocks) const auto success = tryFoldValue(program, *inst); } } + std::vector phis; + for (IrBlock* block : blocks) { + for (IrValue* inst : block->Instructions()) { + if (inst->Opcode() == IrOpcode::Phi) { + phis.push_back(inst); + } + } + } + bool folded = true; + while (folded) { + folded = false; + for (IrValue* phi : phis) { + if (phi->Opcode() == IrOpcode::Phi && foldPhi(*phi)) { + folded = true; + } + } + } std::vector words; for (IrBlock* block : blocks) { for (IrValue* inst : block->Instructions()) { diff --git a/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp b/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp index c2db12f032f9..19677db58940 100644 --- a/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp +++ b/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp @@ -1285,11 +1285,7 @@ std::uint32_t AppendConsume(SpirvValueEmitContext& ctx, const IrValue& inst, boo const auto count = Binary(state, spv::OpIAdd, TypeU32(state), Unary(state, spv::OpBitCount, TypeU32(state), low), Unary(state, spv::OpBitCount, TypeU32(state), high)); const auto first = ctx.FirstLane(ballot); const auto sourceLane = wave64 ? Binary(state, spv::OpBitwiseAnd, TypeU32(state), first, ConstantU32(state, 31u)) : first; - auto amount = count; - if (ordered) { - amount = state.module.AllocateId(); - state.module.AddFunction(spv::OpGroupNonUniformShuffle, TypeU32(state), amount, ConstantU32(state, spv::ScopeSubgroup), ctx.Arg(inst, 4), EmitHostSubgroupLane(state, sourceLane)); - } + const auto amount = ordered ? ctx.Shuffle(inst, 4, first) : count; const auto isFirst = Binary(state, spv::OpIEqual, TypeBool(state), EmitSubgroupLocalInvocationId(state), sourceLane); const auto storageBounds = EmitMemoryElementInBounds(state, access, index); const auto bounds = m0Address ? AndCondition(state, storageBounds, m0Bounds) : storageBounds; diff --git a/core/shader/recompiler/SpirvBackend/src/SpirvOptimizer.cpp b/core/shader/recompiler/SpirvBackend/src/SpirvOptimizer.cpp index 863b76afe19d..079100bb7c51 100644 --- a/core/shader/recompiler/SpirvBackend/src/SpirvOptimizer.cpp +++ b/core/shader/recompiler/SpirvBackend/src/SpirvOptimizer.cpp @@ -165,6 +165,7 @@ std::vector ValidateAndOptimizeSpirv(std::span sources); void writeF16Conversion(const RdnaOperand& operand, IrF32 value, std::initializer_list sources); IrU32 readU32(const RdnaOperand& operand); - IrU32 flushF32Denormal(IrU32 bits); + IrU32 flushF32Denormal(IrU32 bits, std::uint32_t flushBit = 1u); IrF32 flushTinyProduct(IrValue* lhs, IrValue* rhs, IrValue* product, IrValue* addend = nullptr, bool afterRounding = true); IrU32 quietNan32(IrU32 bits); IrU32 quietNan16(IrU32 bits); diff --git a/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp b/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp index e17fd6d3e183..4e570de520d7 100644 --- a/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp +++ b/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp @@ -145,8 +145,8 @@ RdnaOperand TranslationContext::plainOperand(const RdnaOperand& operand) { return result; } -IrU32 TranslationContext::flushF32Denormal(IrU32 bits) { - if ((f32DenormalFlush & 1u) == 0u) return bits; +IrU32 TranslationContext::flushF32Denormal(IrU32 bits, std::uint32_t flushBit) { + if ((f32DenormalFlush & flushBit) == 0u) return bits; if (bits.Value().HasImmediate()) { const std::uint32_t value = bits.Value().ImmediateU32(); return (value & 0x7f800000u) == 0u ? IrU32(ir.Constant(value & 0x80000000u)) : bits; @@ -249,7 +249,7 @@ void TranslationContext::writeOperand(const RdnaOperand& operand, IrValue* value } IrType type = value->Type(); if (type == IrType::F32) { - if ((f32DenormalFlush & 2u) != 0u) value = &ir.BitCastF32(flushF32Denormal(IrU32(ir.BitCastU32(*value))).Value()); + if ((f32DenormalFlush & 2u) != 0u) value = &ir.BitCastF32(flushF32Denormal(IrU32(ir.BitCastU32(*value)), 2u).Value()); value = &applyF32ResultModifiers(operand, IrF32(*value)).Value(); type = IrType::F32; } diff --git a/core/shader/recompiler/Translation/src/VectorInstructions.cpp b/core/shader/recompiler/Translation/src/VectorInstructions.cpp index 4db026c60701..3df645841630 100644 --- a/core/shader/recompiler/Translation/src/VectorInstructions.cpp +++ b/core/shader/recompiler/Translation/src/VectorInstructions.cpp @@ -31,6 +31,12 @@ std::uint32_t TranslationContext::f32DenormalFlushFor(const RdnaInstruction& ins case RdnaOpcode::VSubrevF32: case RdnaOpcode::VMulF32: case RdnaOpcode::VMulLegacyF32: + if (floatMode.has_value() && (floatMode->floatMode & 3u) == 0u) { + const std::uint32_t denormals = (floatMode->floatMode >> 4u) & 3u; + if (denormals == 1u || denormals == 2u) return denormals == 1u ? 2u : 1u; + } + flush = 3u; + break; case RdnaOpcode::VMullitF32: case RdnaOpcode::VMinF32: case RdnaOpcode::VMaxF32: diff --git a/docs/dev/debt/libScePad.md b/docs/dev/debt/libScePad.md index 573dc9d373ed..eab8866f6842 100644 --- a/docs/dev/debt/libScePad.md +++ b/docs/dev/debt/libScePad.md @@ -10,4 +10,153 @@ - [scePadIsRemoteController](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - the name hashes to NID `fCWdlnmB1Ks`; the signature `(int handle, bool* remote)` comes from PPSA16064, which zeroes a byte, passes its address after `scePadGetControllerInformation` and ignores the result. The error codes follow the other pad calls. Controllers are local devices, so the answer is always false - [scePadSetAngularVelocityBiasCorrectionState](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - inferred signature `(int handle, bool enabled)` follows `scePadSetTiltCorrectionState` and `scePadSetAngularVelocityDeadbandState`; an invalid handle returns `PAD_ERROR_INVALID_HANDLE`, disabling is a no-op, and enabling throws because bias correction is not modelled - [scePadUnknown_zBsgF0q8DIM](../../../core/libs/prx/libScePad/Export.cpp) (libScePad, NID `zBsgF0q8DIM`) - PPSA03671 imports it and fails to load without it. The aerolib list has no name for the NID, and none of the pad names in SharpProspero, shadPS4 or OpenOrbis, nor the trigger effect, motion sensor, VR controller, HD and haptic names tried, hashes to it. It is declared without parameters and throws. The title's executable has an import stub for it but no call, jump or address reference to that stub, so the argument count and whether the result is used are unknown +- [scePadSetTriggerEffectExt](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadLastLotusButtonData](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadReadStateExt](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetExtensionReport](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetExtensionUnitInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadEnableExtensionPort](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadEnableSpecificDeviceClass](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadOpenExt2](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDeviceOpen](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetDataInternal](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetUserColor](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisableVibration](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetVibrationStrength](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLightBarBaseBrightness](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLightBarBlinking](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetIdleCount](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetControllerIdleCount](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetPowerSavingState](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetAutoPowerOffCount](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadEnableUsbConnection](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadEnableAutoDetect](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadEnablePlayPauseEmulation](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisableTrackingLedBatterySaver](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLoginUserNumber](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetCapability](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadShareOutputData](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadShareOutputDataWithFunctionType](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetVibrationForce](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetVersionInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetControllerType](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisableDataConversion](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetButtonRemappingInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetProcessPrivilegeOfButtonRemapping](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetForceIntercepted](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadIsLightBarBaseBrightnessControllable](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSwitchConnection](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisableTriggerEffect](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetTriggerEffectStrength](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetTriggerEffectInternalState](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetUserNumber](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisableTransportButtons](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLotusIrCodeSetStart](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLotusIrCodeSetData](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLotusIrCodeSetEnd](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetLotusIrCodeSetResult](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLotusEnableIrKey](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLotusDisableIrKey](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetUsbDetectionState](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadUiReadState](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadUiReadStateForTuning](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetStickTriggerTuningMode](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetStickTuningParam](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetTriggerTuningParam](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetProfileHunt](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetProfileHunt](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadResetHunt](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetProfileInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetActiveProfileInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisableActiveProfileChange](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisableActiveProfileChangeByDeviceId](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetActiveProfileSlot](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetSavedSettingInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetSavedSettingInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVrControllerGetPhysicalUsbConnectionStatus](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadParseUniqueDataLeonardo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetControllerTypeLeonardo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetControllerTypeLeonardo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetProfileLeonardo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetProfileLeonardo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadResetLeonardo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetProfileEditMode](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetProfileEditMode](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetProfileEditModeLeonardo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetSelectButtonCustomizeMode](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetSelectButtonCustomizeMode](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetToggleAllReleaseLeonardo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadEnableControllerIndicator](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadEnableProfileIndicator](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetProfileIndicatorAnimation](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadIsCoPilot](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetIsCoPilot](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadRegisterCollaboInputMgrProcess](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetTelemetryInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetActiveTime](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetDeviceId](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetInfoByPortType](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadResetLightBarAll](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadResetLightBarAllByPortType](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetLightBarForTracker](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadReadForTracker](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadReadBlasterForTracker](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadResetOrientationForTracker](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetMotionTimerUnit](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetVrTrackingMode](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetMotionSensorPosition](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetSphereRadius](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadIsValidHandle](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadIsDS4Connected](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadIsBlasterConnected](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadIsMoveConnected](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetBluetoothAddress](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadIsMoveReproductionModel](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadReadAstonForTracker](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetAstonModel](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadMbusInit](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadMbusTerm](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadConnectPort](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisconnectPort](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadDisconnectDevice](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetDeviceInfo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetProcessFocus](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVertualDeviceAddDevice](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVirtualDeviceAddDevice](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVirtualDeviceDeleteDevice](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVirtualDeviceInsertData](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVirtualDeviceInsertTriggerInternalState](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVirtualDeviceGetRemoteSetting](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVirtualDeviceSetTriggerEffectSetting](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadVirtualDeviceDisableButtonRemapping](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetShareButtonMaskForRemotePlay](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetPS4BcVibrationMode](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetVirtualDeviceComponentInformation](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadEnablePs4CompatibleMode](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetLicenseControllerInformation](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadReadHistory](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadStartRecording](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadStopRecording](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadRemoteControlInsertData](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadRemoteControlInsertDataForAston](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadGetFeatureReport2](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetFeatureReport2](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadSetMuteLed](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadBondUpdateInit](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadBondUpdateIsReady](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadBondUpdateStart](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadBondUpdateGetStatus](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadBondUpdateSendData](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadBondUpdateResetBond](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadBondUpdateGetReconnectStatus](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadBondUpdateTerm](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateInit](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateIsUpdateNeeded2](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateIsReady](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateStart](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateGetStatus](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateSendData](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateResetController](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateGetReconnectStatus](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature +- [scePadControllerUpdateTerm](../../../core/libs/prx/libScePad/Export.cpp) (libScePad) - unknown signature - [scePadUnknown_n3kSX62fgNo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad, NID `n3kSX62fgNo`) - PPSA01530 and PPSA13356 import it and fail to load without it. The real name is unknown; it is declared without parameters and throws diff --git a/docs/dev/debt/libc.md b/docs/dev/debt/libc.md index d1bf0be24075..f312e93f6f83 100644 --- a/docs/dev/debt/libc.md +++ b/docs/dev/debt/libc.md @@ -44,6 +44,7 @@ - Windows direct-memory backing reserves a paging-file section. A [direct memory page](../../../core/libs/prx/libc/include/WindowsMappings.hpp) mapped at one guest address is private write-watched memory at that address and is not committed in the section; a page mapped at a second address moves its whole resident run into the section (committed there) and every address becomes a view of it, tracked by write protection. An unmapped resident page that is not all zeros is kept in a private reservation until it is mapped again. Committed section contents remain across unmap/remap and are released when the backing and its remaining views are destroyed. A host import alias over part of a resident run is refused. Linux retains its existing backing. Peak gameplay memory and Windows versions other than the tested host remain unverified. - [getc_unlocked, putc_unlocked, getchar_unlocked, putchar_unlocked](../../../core/libs/prx/libc/src/StandardStreams.cpp) (libc) - byte I/O uses the host unlocked operations; guest EOF/error flags and macro counters follow `FileStream`. Linux status queries use `feof_unlocked`/`ferror_unlocked` because [glibc `feof`](https://github.com/bminor/glibc/blob/d2097651cc57834dbfcaa102ddfacae0d86cfb66/libio/feof.c) and [`ferror`](https://github.com/bminor/glibc/blob/d2097651cc57834dbfcaa102ddfacae0d86cfb66/libio/ferror.c) can acquire the stream lock. Windows uses [the CRT no-lock byte operations](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fgetc-nolock-fgetwc-nolock) and `feof`/`ferror`, verified under a held stream lock on UCRT. Console behavior and other host CRTs remain unverified. - [fgetws, getwc, getwchar, putwc, putwchar](../../../core/libs/prx/libc/src/FormattingWide.cpp) (libc) - wide stream I/O encodes and decodes wide characters as UTF-8 on the underlying byte stream; `fgetws` reads characters into the destination buffer until newline or EOF and null-terminates, returning null on stream error. Console wide stream buffering and encoding details remain unverified. +- [Closed standard descriptors](../../../core/libs/prx/libc/src/StandardStreams.cpp) (libc) - on Linux and macOS, a descriptor 0, 1 or 2 that is closed when libc loads is opened on `/dev/null` (read-only for 0, write-only for 1 and 2) by a static initializer of libc, which runs before the libraries that depend on libc initialize and before the title starts. Within libc this relies on no static initializer opening a descriptor before it, which `guest_closed_standard_descriptors` checks. glibc does the same for set-user-ID programs ([`check_fds.c`](https://sourceware.org/git/?p=glibc.git;a=blob;f=csu/check_fds.c)). Without it the first descriptor a library opens, the write watch's `userfaultfd` for one, becomes the guest's standard input or output. What the console gives a title as its standard descriptors is not measured, and on Windows a process started without standard handles is not handled. - [ftrylockfile](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) - tries the host CRT stream lock that `flockfile`, `funlockfile` and each locking host stdio call on the stream take, so it returns -1 while another thread holds the stream through `flockfile` or is inside such a call, and 0 when it acquires the lock or already owns it (recursively, released by as many `funlockfile` calls), as FreeBSD 11 [`_ftrylockfile`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/stdio/_flock_stub.c#L89-L104) does. A libc export holds the lock only for each host call it makes, not across several host calls or while it updates the guest `FILE` prefix. Linux uses glibc `ftrylockfile`. UCRT has no try variant of `_lock_file`, so Windows calls `TryEnterCriticalSection` on the `CRITICAL_SECTION` that `_lock_file` enters, found through the private UCRT stream layout (`__crt_stdio_stream_data` in `ucrt/inc/corecrt_internal_stdio.h`, unchanged from Windows SDK 10.0.19041 to 10.0.26100); another CRT or a change of that layout breaks it. A null or closed stream throws where FreeBSD dereferences it - [Wide-character conversions](../../../core/libs/prx/libc/src/Multibyte.cpp) (libc) - The wide `wcsto*` functions parse the ASCII prefix of the guest string, as the C locale accepts only ASCII white space and digits. [`wcsrtombs`](../../../core/libs/prx/libc/src/Multibyte.cpp) uses the guest's single-byte C locale through `wcrtomb`; other encodings and shift states are not supported - [realpath](../../../core/libs/prx/libc/src/RealPath.cpp) (libc) follows FreeBSD 11's [`realpath.c`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libc/stdlib/realpath.c) except for symlinks. The console's guest filesystem has none, so a host symlink under the guest root is followed for existence and type but not expanded, and `..` drops the previous component lexically, as `Resolve` does for every guest path. Through a host link `linkdir -> sub/deep`, `linkdir/../x` gives `x` beside the link, not beside its target. diff --git a/docs/dev/debt/libkernel.md b/docs/dev/debt/libkernel.md index 391aa3bbccec..7dc9f58de1e0 100644 --- a/docs/dev/debt/libkernel.md +++ b/docs/dev/debt/libkernel.md @@ -12,6 +12,7 @@ ### Unknown function info +- [sceKernelError](../../../core/libs/prx/libkernel/System/src/Error.cpp) follows [shadPS4's kernel implementation](https://github.com/shadps4-emu/shadPS4/blob/23c41333822fe8eca4c609b43119180af63ae4ac/src/core/libraries/kernel/kernel.cpp): zero returns zero; other guest POSIX error values receive the `0x80020000` bias without modifying errno. Arithmetic is defined modulo 32 bits to avoid signed overflow for inputs outside the errno domain. Console behavior for those inputs and PS5 equivalence have not been measured. - [getlogin_r](../../../core/libs/prx/libkernel/System/src/Login.cpp) (libkernel) returns the host effective account name: `GetUserNameW` as UTF-8 on Windows and `getpwuid_r(geteuid())` on POSIX. A valid account returns a name even without a login session; host `getlogin_r`, `USER` and `LOGNAME` are not consulted. The console's login name and behaviour without a session are unknown. Account lookup or encoding failures, a missing or empty account name, and POSIX account records exceeding the 16 KiB lookup buffer throw; there is no replacement name or retry. A short guest buffer returns `ERANGE` without modifying it, and a null output returns `EFAULT`. - [sceKernelGetSystemSwVersion](../../../core/libs/prx/libkernel/System/src/SystemConfiguration.cpp) (libkernel) reports baseline system software version `0x01000000` ("01.000.000") for ProsperoStore (PPSA99000); the console's firmware version is not modeled. Measured on PS5 firmware 13.42: record values 0, 24, 39, 40, 41, 48 and 64 in the leading 64-bit field are accepted and preserved, the 28-byte string at offset 8 and packed version at 0x24 are filled, and bytes from 0x28 onward remain untouched. This API reports "13.590.001" / `0x13590001` in that environment, while the Prospero variant reports "13.420.000" / `0x13420000`; their values must not be assumed identical. A null pointer still returns `SCE_KERNEL_ERROR_EFAULT`, which was not measured; other firmware versions and record values remain unverified. - [kern.rng_pseudo](../../../core/libs/prx/libkernel/System/src/SystemConfiguration.cpp) (libkernel) - `sysctlbyname` fills the whole output buffer with bytes from the host's `std::random_device` and leaves the length unchanged; a write returns -1 with `EPERM` and a call without an output buffer throws. The only caller seen is mbedTLS's `mbedtls_hardware_poll` in the catalog's ProsperoLight boilerplate, which asks for 64-byte blocks and fails if fewer come back. The console's generator, its per-call maximum and its answer to a size query are unknown diff --git a/docs/dev/debt/libkernel_sys.md b/docs/dev/debt/libkernel_sys.md index 8fb1dba0286f..cf69a61b5df0 100644 --- a/docs/dev/debt/libkernel_sys.md +++ b/docs/dev/debt/libkernel_sys.md @@ -5,7 +5,7 @@ - [fchdir](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) changes the guest working directory to the descriptor's directory: on Windows through the path recorded when the descriptor was opened, on Linux through the `/proc/self/fd` link target. It returns `EBADF` for a descriptor that is not open and `ENOTDIR` for one that is not a directory. FreeBSD `change_dir`'s search-permission check (`EACCES`) is not modelled, and a directory renamed after it was opened is still reached through the recorded path. Console behaviour is unverified - [openat](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) passes `AT_FDCWD` (-100) and absolute paths to `open`. Any other relative path is joined to the descriptor's host directory, found the same way as for `fchdir`, so guest path aliases and case-insensitive name matching do not apply to it, and a `..` component is not kept inside the guest root. It returns `EBADF` for a descriptor that is not open and `ENOTDIR` for one that is not a directory. As with `open`, `O_NOFOLLOW` and `O_NONBLOCK` are ignored. PPSA99003 opens directory entries this way. Console behaviour is unverified - [fchmodat](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) passes `AT_FDCWD` (-100) and absolute paths to `chmod`; any other relative path is joined to the descriptor's host directory the same way as for `openat`, so guest path aliases and case-insensitive name matching do not apply to it and a `..` component is not kept inside the guest root. A flag other than `0` or `AT_SYMLINK_NOFOLLOW` (0x200) returns `EINVAL`; the mode is masked to `07777`. With `AT_SYMLINK_NOFOLLOW` a symbolic link throws, since the host cannot change a link's own mode, while a regular file is changed either way. The mode maps to the host file mode, which on Windows is only the CRT's read-only bit. PPSA99621 calls it through `std::filesystem::permissions`. Console behaviour is unverified -- [pathconf](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) looks the path up as FreeBSD 11's `kern_pathconf` does (links followed, `ENAMETOOLONG` for a path of 1024 bytes or more or a component over 255) and returns the constants of FreeBSD 11's UFS `ufs_pathconf` for files and directories alike: `_PC_LINK_MAX` 32767, `_PC_NAME_MAX` 255, `_PC_PATH_MAX` and `_PC_SYMLINK_MAX` 1024, `_PC_PIPE_BUF` 512, `_PC_CHOWN_RESTRICTED` and `_PC_NO_TRUNC` 1, `_PC_FILESIZEBITS` 64, `_PC_REC_MAX_XFER_SIZE` -1, `_PC_PRIO_IO` and `_PC_SYNC_IO` 0. Whether the console's filesystems report the same is not verified. It throws for the names whose UFS value depends on the mount (`_PC_ALLOC_SIZE_MIN`, `_PC_REC_INCR_XFER_SIZE`, `_PC_REC_MIN_XFER_SIZE`, `_PC_MIN_HOLE_SIZE`), the kernel options (`_PC_ACL_EXTENDED`, `_PC_ACL_PATH_MAX`, `_PC_ACL_NFS4`, `_PC_MAC_PRESENT`) or the page size (`_PC_REC_XFER_ALIGN`), and on which UFS and `vop_stdpathconf` disagree (`_PC_MAX_CANON`, `_PC_MAX_INPUT`, `_PC_VDISABLE`, `_PC_ASYNC_IO`); other names fail with `EINVAL` +- [pathconf, fpathconf, _fpathconf](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) query filesystem configuration values. `pathconf` looks the path up as FreeBSD 11's `kern_pathconf` does (links followed, `ENAMETOOLONG` for a path of 1024 bytes or more or a component over 255). `fpathconf` and `_fpathconf` operate on an open descriptor, returning `EBADF` if the descriptor is negative or not open. All three report the constants of FreeBSD 11's UFS `ufs_pathconf` for files and directories alike: `_PC_LINK_MAX` 32767, `_PC_NAME_MAX` 255, `_PC_PATH_MAX` and `_PC_SYMLINK_MAX` 1024, `_PC_PIPE_BUF` 512, `_PC_CHOWN_RESTRICTED` and `_PC_NO_TRUNC` 1, `_PC_FILESIZEBITS` 64, `_PC_REC_MAX_XFER_SIZE` -1, `_PC_PRIO_IO` and `_PC_SYNC_IO` 0. Whether the console's filesystems report the same is not verified. They throw for the names whose UFS value depends on the mount (`_PC_ALLOC_SIZE_MIN`, `_PC_REC_INCR_XFER_SIZE`, `_PC_REC_MIN_XFER_SIZE`, `_PC_MIN_HOLE_SIZE`), the kernel options (`_PC_ACL_EXTENDED`, `_PC_ACL_PATH_MAX`, `_PC_ACL_NFS4`, `_PC_MAC_PRESENT`) or the page size (`_PC_REC_XFER_ALIGN`), and on which UFS and `vop_stdpathconf` disagree (`_PC_MAX_CANON`, `_PC_MAX_INPUT`, `_PC_VDISABLE`, `_PC_ASYNC_IO`); other names fail with `EINVAL` - [mkdirat](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) passes `AT_FDCWD` (-100) and absolute paths to `mkdir`. Any other relative path is joined to the descriptor's host directory, found the same way as for `fchdir`, so guest path aliases and case-insensitive name matching do not apply to it, and a `..` component is not kept inside the guest root. It returns `EBADF` for a descriptor that is not open and `ENOTDIR` for one that is not a directory. On Windows, `mode` is ignored. Console behaviour is unverified - [readlink](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) on Windows reads a symbolic link's target from its reparse data and returns it with `/` separators, only when the target is relative, as `symlink` creates them. A symbolic link with an absolute target and a junction throw, as a host path has no guest form. Any other reparse point throws too, where FreeBSD reports `EINVAL` for a file that is not a link - [readlinkat](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) passes `AT_FDCWD` (-100) and absolute paths to `readlink`. Any other relative path is joined to the descriptor's host directory, found the same way as for `fchdir`, so guest path aliases and case-insensitive name matching do not apply to it, and a `..` component is not kept inside the guest root. It returns `EBADF` for a descriptor that is not open and `ENOTDIR` for one that is not a directory. Console behaviour is unverified diff --git a/docs/dev/debt/shader.md b/docs/dev/debt/shader.md index dd7b021c8282..cf62583aa404 100644 --- a/docs/dev/debt/shader.md +++ b/docs/dev/debt/shader.md @@ -23,6 +23,7 @@ ### Functional - [f64 compares](../../../core/shader/recompiler/Translation/src/CompareInstructions.cpp) flush denormal inputs to signed zero when bit 0 of the `FLOAT_MODE` f16/f64 denormal field is clear (modes 0 and 2); modes 1 and 3 and an unknown mode keep them. This follows the RDNA2 ISA section 6.4 and LLVM's sign-preserving AMDGPU denormal modes. The gfx1036 audit in [#981](https://github.com/boykopovar/AnyPS5/issues/981#issuecomment-6070046381) reports mode-sensitive `VopcCompareF64` results. Class compares still inspect the original bits. The full four-mode matrix has not been newly measured on AMD hardware or the PS5's gfx1013. +- [v_add_f32, v_sub_f32, v_subrev_f32, v_mul_f32 and v_mul_legacy_f32 in denormal modes 1 and 2](../../../core/shader/recompiler/Translation/src/VectorInstructions.cpp) follow the `FLOAT_MODE` f32 denormal field with f32 round to nearest even: mode 1 keeps denormal inputs and flushes a result below 2^-126 to a zero of its sign, a product only when it is still below 2^-126 after rounding to 24 bits with an unbounded exponent, as in mode 0; mode 2 flushes denormal inputs to zeros of their sign and keeps a denormal result. Measured on RDNA2 (gfx1030, Radeon RX 6800, AMD Windows driver 32.0.21045.5002 through HIP) over 1,296 operand pairs of 36 values (zeros, 2^-149 to 3 * 2^-149, 0x00400000, 0x007fffff, normals from 2^-126 to 0x01000001, 2^-24, 2^-23, 1, 0x7f7fffff, infinity and a quiet NaN, of both signs) and 896 products around 2^-126 (16 by 14 magnitudes with all four sign combinations) at IEEE=0 and IEEE=1 with each f32 denormal mode 0 to 3 and f32 round mode 0 to 3, DX10_CLAMP=1, f16 denormals kept, f16 round to nearest even and FP16_OVFL=0: the exact result rounded in the f32 round mode and flushed as above matches every row without a NaN or infinity input, with a +0 product for a zero factor of `v_mul_legacy_f32`. With a directed f32 round mode, modes 1 and 2 still throw: the host rounds these sums and products to nearest even in every mode, so with a directed round mode they also differ from the hardware in modes 0 and 3 (up to 344 of the 1,296 pairs and 190 of the 896 products per mode). Mode 1 depends on the driver keeping denormal inputs as mode 3 does. The PS5's gfx1013 is not measured. - [Unlinked calls](../../../core/shader/recompiler/ControlFlow/src/GraphBuilder.cpp) - the `s_swappc_b64` a table call's compare chain falls back to, when its target matches no linked copy, records the `UnlinkedCall` fault with the target and the program counter and stops the invocation, or continues after the call in programs whose faults do not stop invocations (see `bdaStopsInvocations`). The driver lists those calls in the request (`linkedCallFallbacks`), and it reports the fault like a BDA fault, naming the target: a dispatch that checks its faults when it completes throws, one whose check runs in a deferred write-back logs it and continues. The hardware would jump to the target, which is not modelled. Any other `s_swappc_b64` whose target is not resolved still throws when the shader is compiled. - [Cached source IR](../../../core/shader/recompiler/Recompiler.cpp) releases lazily allocated SSA construction tables after resource preparation and reclaims values unreachable from instructions, metadata and resource plans when retaining a pending source program. Immediate shader preparation skips reclamation because compilation consumes the program. Reclamation must account for every new IR pointer owner; a remaining external use throws. Live IDs are retained. Source and variant entries remain cached without an eviction bound. A pending source program is released after its first variant is obtained; memory beyond the measured title checkpoint and Linux performance remain unmeasured.