From 91940781b8e52f911cced1c2bcb1e198549b7f83 Mon Sep 17 00:00:00 2001 From: psucien Date: Thu, 27 Jun 2024 13:36:55 +0200 Subject: [PATCH 1/2] libraries: gnmdriver: complete HW stat init functions --- src/core/libraries/gnmdriver/gnmdriver.cpp | 774 +++++++++++++++++++-- src/core/libraries/gnmdriver/gnmdriver.h | 2 +- src/video_core/amdgpu/liverpool.cpp | 6 + 3 files changed, 731 insertions(+), 51 deletions(-) diff --git a/src/core/libraries/gnmdriver/gnmdriver.cpp b/src/core/libraries/gnmdriver/gnmdriver.cpp index 80901c0b..fbaca634 100644 --- a/src/core/libraries/gnmdriver/gnmdriver.cpp +++ b/src/core/libraries/gnmdriver/gnmdriver.cpp @@ -38,10 +38,7 @@ enum ShaderStages : u32 { static constexpr std::array indirect_sgpr_offsets{0u, 0u, 0x4cu, 0u, 0xccu, 0u, 0x14cu}; -// In case of precise gnm driver emulation we need to send a bunch of HW-specific -// initialization commands. It may slowdown development at early stage as their -// support is not important and can be ignored for a while. -static constexpr bool g_fair_hw_init = false; +static constexpr auto HwInitPacketSize = 0x100u; // In case if `submitDone` is issued we need to block submissions until GPU idle static u32 submission_lock{}; @@ -79,6 +76,25 @@ static inline u32* WriteTrailingNop(u32* cmdbuf) { return cmdbuf + data_block_size + 1 /* header */; } +static inline u32* ClearContextState(u32* cmdbuf) { + cmdbuf[0x00] = 0xc0012800; + cmdbuf[0x01] = 0x80000000; + cmdbuf[0x02] = 0x80000000; + + cmdbuf[0x03] = 0xc0001200; + cmdbuf[0x04] = 0; + + cmdbuf[0x05] = 0xc0055800; + cmdbuf[0x06] = 0x2ec47fc0; + cmdbuf[0x07] = 0xffffffff; + cmdbuf[0x08] = 0; + cmdbuf[0x09] = 0; + cmdbuf[0x0a] = 0; + cmdbuf[0x0b] = 10; + + return cmdbuf + 0xc; +} + s32 PS4_SYSV_ABI sceGnmAddEqEvent(SceKernelEqueue eq, u64 id, void* udata) { LOG_TRACE(Lib_GnmDriver, "called"); if (id != SceKernelEvent::Type::GfxEop) { @@ -305,26 +321,22 @@ int PS4_SYSV_ABI sceGnmDispatchIndirectOnMec() { u32 PS4_SYSV_ABI sceGnmDispatchInitDefaultHardwareState(u32* cmdbuf, u32 size) { LOG_TRACE(Lib_GnmDriver, "called"); - if (size > 0xff) { - if constexpr (g_fair_hw_init) { - cmdbuf = PM4CmdSetData::SetShReg(cmdbuf, 0x216u, - 0xffffffffu); // COMPUTE_STATIC_THREAD_MGMT_SE0 - cmdbuf = PM4CmdSetData::SetShReg(cmdbuf, 0x217u, - 0xffffffffu); // COMPUTE_STATIC_THREAD_MGMT_SE1 - cmdbuf = PM4CmdSetData::SetShReg(cmdbuf, 0x215u, 0x170u); // COMPUTE_RESOURCE_LIMITS - - cmdbuf = WriteHeader( - cmdbuf, 6); // for some reason the packet indicates larger size - cmdbuf = WriteBody(cmdbuf, 0x28000000u, 0u, 0u, 0u, 0u); - - cmdbuf = WriteHeader(cmdbuf, 0xef); - cmdbuf = WriteBody(cmdbuf, 0xau, 0u); - } else { - cmdbuf = cmdbuf = WriteHeader(cmdbuf, 0xff); - } - return 0x100; // it is a size, not a retcode + if (size < HwInitPacketSize) { + return 0; } - return 0; + + cmdbuf = PM4CmdSetData::SetShReg(cmdbuf, 0x216u, + 0xffffffffu); // COMPUTE_STATIC_THREAD_MGMT_SE0 + cmdbuf = PM4CmdSetData::SetShReg(cmdbuf, 0x217u, + 0xffffffffu); // COMPUTE_STATIC_THREAD_MGMT_SE1 + cmdbuf = PM4CmdSetData::SetShReg(cmdbuf, 0x215u, 0x170u); // COMPUTE_RESOURCE_LIMITS + + cmdbuf = WriteHeader(cmdbuf, 6); + cmdbuf = WriteBody(cmdbuf, 0x28000000u, 0u, 0u, 0u, 0u, 0u); + + cmdbuf = WriteHeader(cmdbuf, 0xef); + cmdbuf = WriteBody(cmdbuf, 0xau, 0u); + return HwInitPacketSize; } s32 PS4_SYSV_ABI sceGnmDrawIndex(u32* cmdbuf, u32 size, u32 index_count, uintptr_t index_addr, @@ -451,51 +463,713 @@ int PS4_SYSV_ABI sceGnmDrawIndirectMulti() { return ORBIS_OK; } -int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState() { - LOG_ERROR(Lib_GnmDriver, "(STUBBED) called"); - return ORBIS_OK; +u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState(u32* cmdbuf, u32 size) { + LOG_TRACE(Lib_GnmDriver, "called"); + + if (size < HwInitPacketSize) { + return 0; + } + + const auto& SetupContext = [](u32* cmdbuf, u32 size, bool clear_state) { + if (clear_state) { + cmdbuf = ClearContextState(cmdbuf); + } + + cmdbuf[0x00] = 0xc0017600; + cmdbuf[0x01] = 0x216; + cmdbuf[0x02] = 0xffffffff; + + cmdbuf[0x03] = 0xc0017600; + cmdbuf[0x04] = 0x217; + cmdbuf[0x05] = 0xffffffff; + + cmdbuf[0x06] = 0xc0017600; + cmdbuf[0x07] = 0x215; + cmdbuf[0x08] = 0; + + cmdbuf[0x09] = 0xc0016900; + cmdbuf[0x0a] = 0x2f9; + cmdbuf[0x0b] = 0x2d; + + cmdbuf[0x0c] = 0xc0016900; + cmdbuf[0x0d] = 0x282; + cmdbuf[0x0e] = 8; + + cmdbuf[0x0f] = 0xc0016900; + cmdbuf[0x10] = 0x280; + cmdbuf[0x11] = 0x80008; + + cmdbuf[0x12] = 0xc0016900; + cmdbuf[0x13] = 0x281; + cmdbuf[0x14] = 0xffff0000; + + cmdbuf[0x15] = 0xc0016900; + cmdbuf[0x16] = 0x204; + cmdbuf[0x17] = 0; + + cmdbuf[0x18] = 0xc0016900; + cmdbuf[0x19] = 0x206; + cmdbuf[0x1a] = 0x43f; + + cmdbuf[0x1b] = 0xc0016900; + cmdbuf[0x1c] = 0x83; + cmdbuf[0x1d] = 0xffff; + + cmdbuf[0x1e] = 0xc0016900; + cmdbuf[0x1f] = 0x317; + cmdbuf[0x20] = 0x10; + + cmdbuf[0x21] = 0xc0016900; + cmdbuf[0x22] = 0x2fa; + cmdbuf[0x23] = 0x3f800000; + + cmdbuf[0x24] = 0xc0016900; + cmdbuf[0x25] = 0x2fc; + cmdbuf[0x26] = 0x3f800000; + + cmdbuf[0x27] = 0xc0016900; + cmdbuf[0x28] = 0x2fb; + cmdbuf[0x29] = 0x3f800000; + + cmdbuf[0x2a] = 0xc0016900; + cmdbuf[0x2b] = 0x2fd; + cmdbuf[0x2c] = 0x3f800000; + + cmdbuf[0x2d] = 0xc0016900; + cmdbuf[0x2e] = 0x202; + cmdbuf[0x2f] = 0xcc0010; + + cmdbuf[0x30] = 0xc0016900; + cmdbuf[0x31] = 0x30e; + cmdbuf[0x32] = 0xffffffff; + + cmdbuf[0x33] = 0xc0016900; + cmdbuf[0x34] = 0x30f; + cmdbuf[0x35] = 0xffffffff; + + cmdbuf[0x36] = 0xc0002f00; + cmdbuf[0x37] = 1; + + cmdbuf[0x38] = 0xc0017600; + cmdbuf[0x39] = 7; + cmdbuf[0x3a] = 0x1ff; + + cmdbuf[0x3b] = 0xc0017600; + cmdbuf[0x3c] = 0x46; + cmdbuf[0x3d] = 0x1ff; + + cmdbuf[0x3e] = 0xc0017600; + cmdbuf[0x3f] = 0x87; + cmdbuf[0x40] = 0x1ff; + + cmdbuf[0x41] = 0xc0017600; + cmdbuf[0x42] = 199; + cmdbuf[0x43] = 0x1ff; + + cmdbuf[0x44] = 0xc0017600; + cmdbuf[0x45] = 0x107; + cmdbuf[0x46] = 0; + + cmdbuf[0x47] = 0xc0017600; + cmdbuf[0x48] = 0x147; + cmdbuf[0x49] = 0x1ff; + + cmdbuf[0x4a] = 0xc0016900; + cmdbuf[0x4b] = 0x1b1; + cmdbuf[0x4c] = 2; + + cmdbuf[0x4d] = 0xc0016900; + cmdbuf[0x4e] = 0x101; + cmdbuf[0x4f] = 0; + + cmdbuf[0x50] = 0xc0016900; + cmdbuf[0x51] = 0x100; + cmdbuf[0x52] = 0xffffffff; + + cmdbuf[0x53] = 0xc0016900; + cmdbuf[0x54] = 0x103; + cmdbuf[0x55] = 0; + + cmdbuf[0x56] = 0xc0016900; + cmdbuf[0x57] = 0x284; + cmdbuf[0x58] = 0; + + cmdbuf[0x59] = 0xc0016900; + cmdbuf[0x5a] = 0x290; + cmdbuf[0x5b] = 0; + + cmdbuf[0x5c] = 0xc0016900; + cmdbuf[0x5d] = 0x2ae; + cmdbuf[0x5e] = 0; + + cmdbuf[0x5f] = 0xc0016900; + cmdbuf[0x60] = 0x292; + cmdbuf[0x61] = 0; + + cmdbuf[0x62] = 0xc0016900; + cmdbuf[0x63] = 0x293; + cmdbuf[0x64] = 0x6000000; + + cmdbuf[0x65] = 0xc0016900; + cmdbuf[0x66] = 0x2f8; + cmdbuf[0x67] = 0; + + cmdbuf[0x68] = 0xc0016900; + cmdbuf[0x69] = 0x2de; + cmdbuf[0x6a] = 0x1e9; + + cmdbuf[0x6b] = 0xc0036900; + cmdbuf[0x6c] = 0x295; + cmdbuf[0x6d] = 0x100; + cmdbuf[0x6e] = 0x100; + cmdbuf[0x6f] = 4; + + cmdbuf[0x70] = 0xc0017900; + cmdbuf[0x71] = 0x200; + cmdbuf[0x72] = 0xe0000000; + + const auto cmdbuf_left = 0x100 - 0x74 - (clear_state ? 0xc : 0); + cmdbuf = WriteHeader(cmdbuf + 0x73, cmdbuf_left); + cmdbuf = WriteBody(cmdbuf, 0u); + + return HwInitPacketSize; + }; + + return SetupContext(cmdbuf, size, true); } u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState175(u32* cmdbuf, u32 size) { LOG_TRACE(Lib_GnmDriver, "called"); - if (size > 0xff) { - if constexpr (g_fair_hw_init) { - ASSERT_MSG(0, "Not implemented"); - } else { - cmdbuf = WriteHeader(cmdbuf, 0xff); - } - return 0x100; // it is a size, not a retcode + if (size < HwInitPacketSize) { + return 0; } - return 0; + + ClearContextState(cmdbuf); + + cmdbuf[0x0c] = 0xc0017600; + cmdbuf[0x0d] = 0x216; + cmdbuf[0x0e] = 0xffffffff; + + cmdbuf[0x0f] = 0xc0017600; + cmdbuf[0x10] = 0x217; + cmdbuf[0x11] = 0xffffffff; + + cmdbuf[0x12] = 0xc0017600; + cmdbuf[0x13] = 0x215; + cmdbuf[0x14] = 0; + + cmdbuf[0x15] = 0xc0016900; + cmdbuf[0x16] = 0x2f9; + cmdbuf[0x17] = 0x2d; + + cmdbuf[0x18] = 0xc0016900; + cmdbuf[0x19] = 0x282; + cmdbuf[0x1a] = 8; + + cmdbuf[0x1b] = 0xc0016900; + cmdbuf[0x1c] = 0x280; + cmdbuf[0x1d] = 0x80008; + + cmdbuf[0x1e] = 0xc0016900; + cmdbuf[0x1f] = 0x281; + cmdbuf[0x20] = 0xffff0000; + + cmdbuf[0x21] = 0xc0016900; + cmdbuf[0x22] = 0x204; + cmdbuf[0x23] = 0; + + cmdbuf[0x24] = 0xc0016900; + cmdbuf[0x25] = 0x206; + cmdbuf[0x26] = 0x43f; + + cmdbuf[0x27] = 0xc0016900; + cmdbuf[0x28] = 0x83; + cmdbuf[0x29] = 0xffff; + + cmdbuf[0x2a] = 0xc0016900; + cmdbuf[0x2b] = 0x317; + cmdbuf[0x2c] = 0x10; + + cmdbuf[0x2d] = 0xc0016900; + cmdbuf[0x2e] = 0x2fa; + cmdbuf[0x2f] = 0x3f800000; + + cmdbuf[0x30] = 0xc0016900; + cmdbuf[0x31] = 0x2fc; + cmdbuf[0x32] = 0x3f800000; + + cmdbuf[0x33] = 0xc0016900; + cmdbuf[0x34] = 0x2fb; + cmdbuf[0x35] = 0x3f800000; + + cmdbuf[0x36] = 0xc0016900; + cmdbuf[0x37] = 0x2fd; + cmdbuf[0x38] = 0x3f800000; + + cmdbuf[0x39] = 0xc0016900; + cmdbuf[0x3a] = 0x202; + cmdbuf[0x3b] = 0xcc0010; + + cmdbuf[0x3c] = 0xc0016900; + cmdbuf[0x3d] = 0x30e; + cmdbuf[0x3e] = 0xffffffff; + + cmdbuf[0x3f] = 0xc0016900; + cmdbuf[0x40] = 0x30f; + cmdbuf[0x41] = 0xffffffff; + + cmdbuf[0x42] = 0xc0002f00; + cmdbuf[0x43] = 1; + + cmdbuf[0x44] = 0xc0017600; + cmdbuf[0x45] = 7; + cmdbuf[0x46] = 0x1ff; + + cmdbuf[0x47] = 0xc0017600; + cmdbuf[0x48] = 0x46; + cmdbuf[0x49] = 0x1ff; + + cmdbuf[0x4a] = 0xc0017600; + cmdbuf[0x4b] = 0x87; + cmdbuf[0x4c] = 0x1ff; + + cmdbuf[0x4d] = 0xc0017600; + cmdbuf[0x4e] = 199; + cmdbuf[0x4f] = 0x1ff; + + cmdbuf[0x50] = 0xc0017600; + cmdbuf[0x51] = 0x107; + cmdbuf[0x52] = 0; + + cmdbuf[0x53] = 0xc0017600; + cmdbuf[0x54] = 0x147; + cmdbuf[0x55] = 0x1ff; + + cmdbuf[0x56] = 0xc0016900; + cmdbuf[0x57] = 0x1b1; + cmdbuf[0x58] = 2; + + cmdbuf[0x59] = 0xc0016900; + cmdbuf[0x5a] = 0x101; + cmdbuf[0x5b] = 0; + + cmdbuf[0x5c] = 0xc0016900; + cmdbuf[0x5d] = 0x100; + cmdbuf[0x5e] = 0xffffffff; + + cmdbuf[0x5f] = 0xc0016900; + cmdbuf[0x60] = 0x103; + cmdbuf[0x61] = 0; + + cmdbuf[0x62] = 0xc0016900; + cmdbuf[0x63] = 0x284; + cmdbuf[0x64] = 0; + + cmdbuf[0x65] = 0xc0016900; + cmdbuf[0x66] = 0x290; + cmdbuf[0x67] = 0; + + cmdbuf[0x68] = 0xc0016900; + cmdbuf[0x69] = 0x2ae; + cmdbuf[0x6a] = 0; + + cmdbuf[0x6b] = 0xc0016900; + cmdbuf[0x6c] = 0x292; + cmdbuf[0x6d] = 0; + + cmdbuf[0x6e] = 0xc0016900; + cmdbuf[0x6f] = 0x293; + cmdbuf[0x70] = 0x6020000; + + cmdbuf[0x71] = 0xc0016900; + cmdbuf[0x72] = 0x2f8; + cmdbuf[0x73] = 0; + + cmdbuf[0x74] = 0xc0016900; + cmdbuf[0x75] = 0x2de; + cmdbuf[0x76] = 0x1e9; + + cmdbuf[0x77] = 0xc0036900; + cmdbuf[0x78] = 0x295; + cmdbuf[0x79] = 0x100; + cmdbuf[0x7a] = 0x100; + cmdbuf[0x7b] = 4; + + cmdbuf[0x7c] = 0xc0017900; + cmdbuf[0x7d] = 0x200; + cmdbuf[0x7e] = 0xe0000000; + + cmdbuf[0x7f] = 0xc07f1000; + cmdbuf[0x80] = 0; + + return HwInitPacketSize; } u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState200(u32* cmdbuf, u32 size) { LOG_TRACE(Lib_GnmDriver, "called"); - if (size > 0xff) { - if constexpr (g_fair_hw_init) { - ASSERT_MSG(0, "Not implemented"); - } else { - cmdbuf = WriteHeader(cmdbuf, 0xff); - } - return 0x100; // it is a size, not a retcode + if (size < HwInitPacketSize) { + return 0; } - return 0; + + const auto& SetupContext200 = [](u32* cmdbuf, u32 size, bool clear_state) { + if (clear_state) { + cmdbuf = ClearContextState(cmdbuf); + } + + cmdbuf[0x00] = 0xc0017600; + cmdbuf[0x01] = 0x216; + cmdbuf[0x02] = 0xffffffff; + + cmdbuf[0x03] = 0xc0017600; + cmdbuf[0x04] = 0x217; + cmdbuf[0x05] = 0xffffffff; + + cmdbuf[0x06] = 0xc0017600; + cmdbuf[0x07] = 0x215; + cmdbuf[0x08] = 0; + + cmdbuf[0x09] = 0xc0016900; + cmdbuf[0x0a] = 0x2f9; + cmdbuf[0x0b] = 0x2d; + + cmdbuf[0x0c] = 0xc0016900; + cmdbuf[0x0d] = 0x282; + cmdbuf[0x0e] = 8; + + cmdbuf[0x0f] = 0xc0016900; + cmdbuf[0x10] = 0x280; + cmdbuf[0x11] = 0x80008; + + cmdbuf[0x12] = 0xc0016900; + cmdbuf[0x13] = 0x281; + cmdbuf[0x14] = 0xffff0000; + + cmdbuf[0x15] = 0xc0016900; + cmdbuf[0x16] = 0x204; + cmdbuf[0x17] = 0; + + cmdbuf[0x18] = 0xc0016900; + cmdbuf[0x19] = 0x206; + cmdbuf[0x1a] = 0x43f; + + cmdbuf[0x1b] = 0xc0016900; + cmdbuf[0x1c] = 0x83; + cmdbuf[0x1d] = 0xffff; + + cmdbuf[0x1e] = 0xc0016900; + cmdbuf[0x1f] = 0x317; + cmdbuf[0x20] = 0x10; + + cmdbuf[0x21] = 0xc0016900; + cmdbuf[0x22] = 0x2fa; + cmdbuf[0x23] = 0x3f800000; + + cmdbuf[0x24] = 0xc0016900; + cmdbuf[0x25] = 0x2fc; + cmdbuf[0x26] = 0x3f800000; + + cmdbuf[0x27] = 0xc0016900; + cmdbuf[0x28] = 0x2fb; + cmdbuf[0x29] = 0x3f800000; + + cmdbuf[0x2a] = 0xc0016900; + cmdbuf[0x2b] = 0x2fd; + cmdbuf[0x2c] = 0x3f800000; + + cmdbuf[0x2d] = 0xc0016900; + cmdbuf[0x2e] = 0x202; + cmdbuf[0x2f] = 0xcc0010; + + cmdbuf[0x30] = 0xc0016900; + cmdbuf[0x31] = 0x30e; + cmdbuf[0x32] = 0xffffffff; + + cmdbuf[0x33] = 0xc0016900; + cmdbuf[0x34] = 0x30f; + cmdbuf[0x35] = 0xffffffff; + + cmdbuf[0x36] = 0xc0002f00; + cmdbuf[0x37] = 1; + + cmdbuf[0x38] = 0xc0017600; + cmdbuf[0x39] = 7; + cmdbuf[0x3a] = 0x1701ff; + + cmdbuf[0x3b] = 0xc0017600; + cmdbuf[0x3c] = 0x46; + cmdbuf[0x3d] = 0x1701fd; + + cmdbuf[0x3e] = 0xc0017600; + cmdbuf[0x3f] = 0x87; + cmdbuf[0x40] = 0x1701ff; + + cmdbuf[0x41] = 0xc0017600; + cmdbuf[0x42] = 199; + cmdbuf[0x43] = 0x1701fd; + + cmdbuf[0x44] = 0xc0017600; + cmdbuf[0x45] = 0x107; + cmdbuf[0x46] = 0x17; + + cmdbuf[0x47] = 0xc0017600; + cmdbuf[0x48] = 0x147; + cmdbuf[0x49] = 0x1701fd; + + cmdbuf[0x4a] = 0xc0017600; + cmdbuf[0x4b] = 0x47; + cmdbuf[0x4c] = 0x1c; + + cmdbuf[0x4d] = 0xc0016900; + cmdbuf[0x4e] = 0x1b1; + cmdbuf[0x4f] = 2; + + cmdbuf[0x50] = 0xc0016900; + cmdbuf[0x51] = 0x101; + cmdbuf[0x52] = 0; + + cmdbuf[0x53] = 0xc0016900; + cmdbuf[0x54] = 0x100; + cmdbuf[0x55] = 0xffffffff; + + cmdbuf[0x56] = 0xc0016900; + cmdbuf[0x57] = 0x103; + cmdbuf[0x58] = 0; + + cmdbuf[0x59] = 0xc0016900; + cmdbuf[0x5a] = 0x284; + cmdbuf[0x5b] = 0; + + cmdbuf[0x5c] = 0xc0016900; + cmdbuf[0x5d] = 0x290; + cmdbuf[0x5e] = 0; + + cmdbuf[0x5f] = 0xc0016900; + cmdbuf[0x60] = 0x2ae; + cmdbuf[0x61] = 0; + + cmdbuf[0x62] = 0xc0016900; + cmdbuf[0x63] = 0x292; + cmdbuf[0x64] = 0; + + cmdbuf[0x65] = 0xc0016900; + cmdbuf[0x66] = 0x293; + cmdbuf[0x67] = 0x6020000; + + cmdbuf[0x68] = 0xc0016900; + cmdbuf[0x69] = 0x2f8; + cmdbuf[0x6a] = 0; + + cmdbuf[0x6b] = 0xc0016900; + cmdbuf[0x6c] = 0x2de; + cmdbuf[0x6d] = 0x1e9; + + cmdbuf[0x6e] = 0xc0036900; + cmdbuf[0x6f] = 0x295; + cmdbuf[0x70] = 0x100; + cmdbuf[0x71] = 0x100; + cmdbuf[0x72] = 4; + + cmdbuf[0x73] = 0xc0017900; + cmdbuf[0x74] = 0xe0000000; + cmdbuf[0x75] = 0x200; + + const auto cmdbuf_left = 0x100 - 0x77 - (clear_state ? 0xc : 0); + cmdbuf = WriteHeader(cmdbuf + 0x76, cmdbuf_left); + cmdbuf = WriteBody(cmdbuf, 0u); + + return HwInitPacketSize; + }; + + return SetupContext200(cmdbuf, size, true); } u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350(u32* cmdbuf, u32 size) { LOG_TRACE(Lib_GnmDriver, "called"); - if (size > 0xff) { - if constexpr (g_fair_hw_init) { - ASSERT_MSG(0, "Not implemented"); - } else { - cmdbuf = WriteHeader(cmdbuf, 0xff); - } - return 0x100; // it is a size, not a retcode + if (size < HwInitPacketSize) { + return 0; } - return 0; + + const auto& SetupContext350 = [](u32* cmdbuf, u32 size, bool clear_state) { + if (clear_state) { + cmdbuf = ClearContextState(cmdbuf); + } + + cmdbuf[0x00] = 0xc0017600; + cmdbuf[0x01] = 0x216; + cmdbuf[0x02] = 0xffffffff; + + cmdbuf[0x03] = 0xc0017600; + cmdbuf[0x04] = 0x217; + cmdbuf[0x05] = 0xffffffff; + + cmdbuf[0x06] = 0xc0017600; + cmdbuf[0x07] = 0x215; + cmdbuf[0x08] = 0; + + cmdbuf[0x09] = 0xc0016900; + cmdbuf[0x0a] = 0x2f9; + cmdbuf[0x0b] = 0x2d; + + cmdbuf[0x0c] = 0xc0016900; + cmdbuf[0x0d] = 0x282; + cmdbuf[0x0e] = 8; + + cmdbuf[0x0f] = 0xc0016900; + cmdbuf[0x10] = 0x280; + cmdbuf[0x11] = 0x80008; + + cmdbuf[0x12] = 0xc0016900; + cmdbuf[0x13] = 0x281; + cmdbuf[0x14] = 0xffff0000; + + cmdbuf[0x15] = 0xc0016900; + cmdbuf[0x16] = 0x204; + cmdbuf[0x17] = 0; + + cmdbuf[0x18] = 0xc0016900; + cmdbuf[0x19] = 0x206; + cmdbuf[0x1a] = 0x43f; + + cmdbuf[0x1b] = 0xc0016900; + cmdbuf[0x1c] = 0x83; + cmdbuf[0x1d] = 0xffff; + + cmdbuf[0x1e] = 0xc0016900; + cmdbuf[0x1f] = 0x317; + cmdbuf[0x20] = 0x10; + + cmdbuf[0x21] = 0xc0016900; + cmdbuf[0x22] = 0x2fa; + cmdbuf[0x23] = 0x3f800000; + + cmdbuf[0x24] = 0xc0016900; + cmdbuf[0x25] = 0x2fc; + cmdbuf[0x26] = 0x3f800000; + + cmdbuf[0x27] = 0xc0016900; + cmdbuf[0x28] = 0x2fb; + cmdbuf[0x29] = 0x3f800000; + + cmdbuf[0x2a] = 0xc0016900; + cmdbuf[0x2b] = 0x2fd; + cmdbuf[0x2c] = 0x3f800000; + + cmdbuf[0x2d] = 0xc0016900; + cmdbuf[0x2e] = 0x202; + cmdbuf[0x2f] = 0xcc0010; + + cmdbuf[0x30] = 0xc0016900; + cmdbuf[0x31] = 0x30e; + cmdbuf[0x32] = 0xffffffff; + + cmdbuf[0x33] = 0xc0016900; + cmdbuf[0x34] = 0x30f; + cmdbuf[0x35] = 0xffffffff; + + cmdbuf[0x36] = 0xc0002f00; + cmdbuf[0x37] = 1; + + cmdbuf[0x38] = 0xc0017600; + cmdbuf[0x39] = 7; + cmdbuf[0x3a] = 0x1701ff; + + cmdbuf[0x3b] = 0xc0017600; + cmdbuf[0x3c] = 0x46; + cmdbuf[0x3d] = 0x1701fd; + + cmdbuf[0x3e] = 0xc0017600; + cmdbuf[0x3f] = 0x87; + cmdbuf[0x40] = 0x1701ff; + + cmdbuf[0x41] = 0xc0017600; + cmdbuf[0x42] = 199; + cmdbuf[0x43] = 0x1701fd; + + cmdbuf[0x44] = 0xc0017600; + cmdbuf[0x45] = 0x107; + cmdbuf[0x46] = 0x17; + + cmdbuf[0x47] = 0xc0017600; + cmdbuf[0x48] = 0x147; + cmdbuf[0x49] = 0x1701fd; + + cmdbuf[0x4a] = 0xc0017600; + cmdbuf[0x4b] = 0x47; + cmdbuf[0x4c] = 0x1c; + + cmdbuf[0x4d] = 0xc0016900; + cmdbuf[0x4e] = 0x1b1; + cmdbuf[0x4f] = 2; + + cmdbuf[0x50] = 0xc0016900; + cmdbuf[0x51] = 0x101; + cmdbuf[0x52] = 0; + + cmdbuf[0x53] = 0xc0016900; + cmdbuf[0x54] = 0x100; + cmdbuf[0x55] = 0xffffffff; + + cmdbuf[0x56] = 0xc0016900; + cmdbuf[0x57] = 0x103; + cmdbuf[0x58] = 0; + + cmdbuf[0x59] = 0xc0016900; + cmdbuf[0x5a] = 0x284; + cmdbuf[0x5b] = 0; + + cmdbuf[0x5c] = 0xc0016900; + cmdbuf[0x5d] = 0x290; + cmdbuf[0x5e] = 0; + + cmdbuf[0x5f] = 0xc0016900; + cmdbuf[0x60] = 0x2ae; + cmdbuf[0x61] = 0; + + cmdbuf[0x62] = 0xc0016900; + cmdbuf[0x63] = 0x102; + cmdbuf[0x64] = 0; + + cmdbuf[0x65] = 0xc0016900; + cmdbuf[0x66] = 0x292; + cmdbuf[0x67] = 0; + + cmdbuf[0x68] = 0xc0016900; + cmdbuf[0x69] = 0x293; + cmdbuf[0x6a] = 0x6020000; + + cmdbuf[0x6b] = 0xc0016900; + cmdbuf[0x6c] = 0x2f8; + cmdbuf[0x6d] = 0; + + cmdbuf[0x6e] = 0xc0016900; + cmdbuf[0x6f] = 0x2de; + cmdbuf[0x70] = 0x1e9; + + cmdbuf[0x71] = 0xc0036900; + cmdbuf[0x72] = 0x295; + cmdbuf[0x73] = 0x100; + cmdbuf[0x74] = 0x100; + cmdbuf[0x75] = 4; + + cmdbuf[0x76] = 0xc0017900; + cmdbuf[0x77] = 0x200; + cmdbuf[0x78] = 0xe0000000; + + cmdbuf[0x79] = 0xc0016900; + cmdbuf[0x7a] = 0x000002aa; + cmdbuf[0x7b] = 0xff; + + const auto cmdbuf_left = 0x100 - 0x7d - (clear_state ? 0xc : 0); + cmdbuf = WriteHeader(cmdbuf + 0x7c, cmdbuf_left); + cmdbuf = WriteBody(cmdbuf, 0u); + + return HwInitPacketSize; + }; + + return SetupContext350(cmdbuf, size, true); } int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextState() { diff --git a/src/core/libraries/gnmdriver/gnmdriver.h b/src/core/libraries/gnmdriver/gnmdriver.h index b05d15f9..915775d5 100644 --- a/src/core/libraries/gnmdriver/gnmdriver.h +++ b/src/core/libraries/gnmdriver/gnmdriver.h @@ -56,7 +56,7 @@ s32 PS4_SYSV_ABI sceGnmDrawIndirect(u32* cmdbuf, u32 size, u32 data_offset, u32 u32 vertex_sgpr_offset, u32 instance_vgpr_offset, u32 flags); int PS4_SYSV_ABI sceGnmDrawIndirectCountMulti(); int PS4_SYSV_ABI sceGnmDrawIndirectMulti(); -int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState(); +u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState(u32* cmdbuf, u32 size); u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState175(u32* cmdbuf, u32 size); u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState200(u32* cmdbuf, u32 size); u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350(u32* cmdbuf, u32 size); diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 6e0aca43..5f0c923e 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -181,6 +181,12 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span dcb, std::span(header); const auto reg_addr = ContextRegWordOffset + set_data->reg_offset; From 7fd832b68c1ff8b92ba19c5f95f650f9ecd74942 Mon Sep 17 00:00:00 2001 From: psucien Date: Thu, 27 Jun 2024 15:47:18 +0200 Subject: [PATCH 2/2] things prettified --- src/core/libraries/gnmdriver/gnmdriver.cpp | 845 +++++---------------- 1 file changed, 198 insertions(+), 647 deletions(-) diff --git a/src/core/libraries/gnmdriver/gnmdriver.cpp b/src/core/libraries/gnmdriver/gnmdriver.cpp index fbaca634..c17dbce4 100644 --- a/src/core/libraries/gnmdriver/gnmdriver.cpp +++ b/src/core/libraries/gnmdriver/gnmdriver.cpp @@ -40,6 +40,180 @@ static constexpr std::array indirect_sgpr_offsets{0u, 0u, 0x4cu, 0u, 0xccu, 0u, static constexpr auto HwInitPacketSize = 0x100u; +// clang-format off +static constexpr std::array InitSequence{ + 0xc0017600u, 0x216u, 0xffffffffu, + 0xc0017600u, 0x217u, 0xffffffffu, + 0xc0017600u, 0x215u, 0u, + 0xc0016900u, 0x2f9u, 0x2du, + 0xc0016900u, 0x282u, 8u, + 0xc0016900u, 0x280u, 0x80008u, + 0xc0016900u, 0x281u, 0xffff0000u, + 0xc0016900u, 0x204u, 0u, + 0xc0016900u, 0x206u, 0x43fu, + 0xc0016900u, 0x83u, 0xffffu, + 0xc0016900u, 0x317u, 0x10u, + 0xc0016900u, 0x2fau, 0x3f800000u, + 0xc0016900u, 0x2fcu, 0x3f800000u, + 0xc0016900u, 0x2fbu, 0x3f800000u, + 0xc0016900u, 0x2fdu, 0x3f800000u, + 0xc0016900u, 0x202u, 0xcc0010u, + 0xc0016900u, 0x30eu, 0xffffffffu, + 0xc0016900u, 0x30fu, 0xffffffffu, + 0xc0002f00u, 1u, + 0xc0017600u, 7u, 0x1ffu, + 0xc0017600u, 0x46u, 0x1ffu, + 0xc0017600u, 0x87u, 0x1ffu, + 0xc0017600u, 0xc7u, 0x1ffu, + 0xc0017600u, 0x107u, 0u, + 0xc0017600u, 0x147u, 0x1ffu, + 0xc0016900u, 0x1b1u, 2u, + 0xc0016900u, 0x101u, 0u, + 0xc0016900u, 0x100u, 0xffffffffu, + 0xc0016900u, 0x103u, 0u, + 0xc0016900u, 0x284u, 0u, + 0xc0016900u, 0x290u, 0u, + 0xc0016900u, 0x2aeu, 0u, + 0xc0016900u, 0x292u, 0u, + 0xc0016900u, 0x293u, 0x6000000u, + 0xc0016900u, 0x2f8u, 0u, + 0xc0016900u, 0x2deu, 0x1e9u, + 0xc0036900u, 0x295u, 0x100u, 0x100u, 4u, + 0xc0017900u, 0x200u, 0xe0000000u, +}; +static_assert(InitSequence.size() == 0x73); + +static constexpr std::array InitSequence175{ + 0xc0017600u, 0x216u, 0xffffffffu, + 0xc0017600u, 0x217u, 0xffffffffu, + 0xc0017600u, 0x215u, 0u, + 0xc0016900u, 0x2f9u, 0x2du, + 0xc0016900u, 0x282u, 8u, + 0xc0016900u, 0x280u, 0x80008u, + 0xc0016900u, 0x281u, 0xffff0000u, + 0xc0016900u, 0x204u, 0u, + 0xc0016900u, 0x206u, 0x43fu, + 0xc0016900u, 0x83u, 0xffffu, + 0xc0016900u, 0x317u, 0x10u, + 0xc0016900u, 0x2fau, 0x3f800000u, + 0xc0016900u, 0x2fcu, 0x3f800000u, + 0xc0016900u, 0x2fbu, 0x3f800000u, + 0xc0016900u, 0x2fdu, 0x3f800000u, + 0xc0016900u, 0x202u, 0xcc0010u, + 0xc0016900u, 0x30eu, 0xffffffffu, + 0xc0016900u, 0x30fu, 0xffffffffu, + 0xc0002f00u, 1u, + 0xc0017600u, 7u, 0x1ffu, + 0xc0017600u, 0x46u, 0x1ffu, + 0xc0017600u, 0x87u, 0x1ffu, + 0xc0017600u, 0xc7u, 0x1ffu, + 0xc0017600u, 0x107u, 0u, + 0xc0017600u, 0x147u, 0x1ffu, + 0xc0016900u, 0x1b1u, 2u, + 0xc0016900u, 0x101u, 0u, + 0xc0016900u, 0x100u, 0xffffffffu, + 0xc0016900u, 0x103u, 0u, + 0xc0016900u, 0x284u, 0u, + 0xc0016900u, 0x290u, 0u, + 0xc0016900u, 0x2aeu, 0u, + 0xc0016900u, 0x292u, 0u, + 0xc0016900u, 0x293u, 0x6020000u, + 0xc0016900u, 0x2f8u, 0u, + 0xc0016900u, 0x2deu, 0x1e9u, + 0xc0036900u, 0x295u, 0x100u, 0x100u, 4u, + 0xc0017900u, 0x200u, 0xe0000000u, +}; +static_assert(InitSequence175.size() == 0x73); + +static constexpr std::array InitSequence200{ + 0xc0017600u, 0x216u, 0xffffffffu, + 0xc0017600u, 0x217u, 0xffffffffu, + 0xc0017600u, 0x215u, 0u, + 0xc0016900u, 0x2f9u, 0x2du, + 0xc0016900u, 0x282u, 8u, + 0xc0016900u, 0x280u, 0x80008u, + 0xc0016900u, 0x281u, 0xffff0000u, + 0xc0016900u, 0x204u, 0u, + 0xc0016900u, 0x206u, 0x43fu, + 0xc0016900u, 0x83u, 0xffffu, + 0xc0016900u, 0x317u, 0x10u, + 0xc0016900u, 0x2fau, 0x3f800000u, + 0xc0016900u, 0x2fcu, 0x3f800000u, + 0xc0016900u, 0x2fbu, 0x3f800000u, + 0xc0016900u, 0x2fdu, 0x3f800000u, + 0xc0016900u, 0x202u, 0xcc0010u, + 0xc0016900u, 0x30eu, 0xffffffffu, + 0xc0016900u, 0x30fu, 0xffffffffu, + 0xc0002f00u, 1u, + 0xc0017600u, 7u, 0x1701ffu, + 0xc0017600u, 0x46u, 0x1701fdu, + 0xc0017600u, 0x87u, 0x1701ffu, + 0xc0017600u, 0xc7u, 0x1701fdu, + 0xc0017600u, 0x107u, 0x17u, + 0xc0017600u, 0x147u, 0x1701fdu, + 0xc0017600u, 0x47u, 0x1cu, + 0xc0016900u, 0x1b1u, 2u, + 0xc0016900u, 0x101u, 0u, + 0xc0016900u, 0x100u, 0xffffffffu, + 0xc0016900u, 0x103u, 0u, + 0xc0016900u, 0x284u, 0u, + 0xc0016900u, 0x290u, 0u, + 0xc0016900u, 0x2aeu, 0u, + 0xc0016900u, 0x292u, 0u, + 0xc0016900u, 0x293u, 0x6020000u, + 0xc0016900u, 0x2f8u, 0u, + 0xc0016900u, 0x2deu, 0x1e9u, + 0xc0036900u, 0x295u, 0x100u, 0x100u, 4u, + 0xc0017900u, 0x200u, 0xe0000000u, +}; +static_assert(InitSequence200.size() == 0x76); + +static constexpr std::array InitSequence350{ + 0xc0017600u, 0x216u, 0xffffffffu, + 0xc0017600u, 0x217u, 0xffffffffu, + 0xc0017600u, 0x215u, 0u, + 0xc0016900u, 0x2f9u, 0x2du, + 0xc0016900u, 0x282u, 8u, + 0xc0016900u, 0x280u, 0x80008u, + 0xc0016900u, 0x281u, 0xffff0000u, + 0xc0016900u, 0x204u, 0u, + 0xc0016900u, 0x206u, 0x43fu, + 0xc0016900u, 0x83u, 0xffffu, + 0xc0016900u, 0x317u, 0x10u, + 0xc0016900u, 0x2fau, 0x3f800000u, + 0xc0016900u, 0x2fcu, 0x3f800000u, + 0xc0016900u, 0x2fbu, 0x3f800000u, + 0xc0016900u, 0x2fdu, 0x3f800000u, + 0xc0016900u, 0x202u, 0xcc0010u, + 0xc0016900u, 0x30eu, 0xffffffffu, + 0xc0016900u, 0x30fu, 0xffffffffu, + 0xc0002f00u, 1u, + 0xc0017600u, 7u, 0x1701ffu, + 0xc0017600u, 0x46u, 0x1701fdu, + 0xc0017600u, 0x87u, 0x1701ffu, + 0xc0017600u, 0xc7u, 0x1701fdu, + 0xc0017600u, 0x107u, 0x17u, + 0xc0017600u, 0x147u, 0x1701fdu, + 0xc0017600u, 0x47u, 0x1cu, + 0xc0016900u, 0x1b1u, 2u, + 0xc0016900u, 0x101u, 0u, + 0xc0016900u, 0x100u, 0xffffffffu, + 0xc0016900u, 0x103u, 0u, + 0xc0016900u, 0x284u, 0u, + 0xc0016900u, 0x290u, 0u, + 0xc0016900u, 0x2aeu, 0u, + 0xc0016900u, 0x102u, 0u, + 0xc0016900u, 0x292u, 0u, + 0xc0016900u, 0x293u, 0x6020000u, + 0xc0016900u, 0x2f8u, 0u, + 0xc0016900u, 0x2deu, 0x1e9u, + 0xc0036900u, 0x295u, 0x100u, 0x100u, 4u, + 0xc0017900u, 0x200u, 0xe0000000u, + 0xc0016900u, 0x2aau, 0xffu, +}; +static_assert(InitSequence350.size() == 0x7c); +// clang-format on + // In case if `submitDone` is issued we need to block submissions until GPU idle static u32 submission_lock{}; static std::mutex m_submission{}; @@ -77,22 +251,14 @@ static inline u32* WriteTrailingNop(u32* cmdbuf) { } static inline u32* ClearContextState(u32* cmdbuf) { - cmdbuf[0x00] = 0xc0012800; - cmdbuf[0x01] = 0x80000000; - cmdbuf[0x02] = 0x80000000; + static constexpr std::array ClearStateSequence{ + 0xc0012800u, 0x80000000u, 0x80000000u, 0xc0001200u, 0u, 0xc0055800u, + 0x2ec47fc0u, 0xffffffffu, 0u, 0u, 0u, 10u, + }; + static_assert(ClearStateSequence.size() == 0xc); - cmdbuf[0x03] = 0xc0001200; - cmdbuf[0x04] = 0; - - cmdbuf[0x05] = 0xc0055800; - cmdbuf[0x06] = 0x2ec47fc0; - cmdbuf[0x07] = 0xffffffff; - cmdbuf[0x08] = 0; - cmdbuf[0x09] = 0; - cmdbuf[0x0a] = 0; - cmdbuf[0x0b] = 10; - - return cmdbuf + 0xc; + std::memcpy(cmdbuf, ClearStateSequence.data(), ClearStateSequence.size() * 4); + return cmdbuf + ClearStateSequence.size(); } s32 PS4_SYSV_ABI sceGnmAddEqEvent(SceKernelEqueue eq, u64 id, void* udata) { @@ -475,161 +641,12 @@ u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState(u32* cmdbuf, u32 size) { cmdbuf = ClearContextState(cmdbuf); } - cmdbuf[0x00] = 0xc0017600; - cmdbuf[0x01] = 0x216; - cmdbuf[0x02] = 0xffffffff; + std::memcpy(cmdbuf, InitSequence.data(), InitSequence.size() * 4); + cmdbuf += InitSequence.size(); - cmdbuf[0x03] = 0xc0017600; - cmdbuf[0x04] = 0x217; - cmdbuf[0x05] = 0xffffffff; - - cmdbuf[0x06] = 0xc0017600; - cmdbuf[0x07] = 0x215; - cmdbuf[0x08] = 0; - - cmdbuf[0x09] = 0xc0016900; - cmdbuf[0x0a] = 0x2f9; - cmdbuf[0x0b] = 0x2d; - - cmdbuf[0x0c] = 0xc0016900; - cmdbuf[0x0d] = 0x282; - cmdbuf[0x0e] = 8; - - cmdbuf[0x0f] = 0xc0016900; - cmdbuf[0x10] = 0x280; - cmdbuf[0x11] = 0x80008; - - cmdbuf[0x12] = 0xc0016900; - cmdbuf[0x13] = 0x281; - cmdbuf[0x14] = 0xffff0000; - - cmdbuf[0x15] = 0xc0016900; - cmdbuf[0x16] = 0x204; - cmdbuf[0x17] = 0; - - cmdbuf[0x18] = 0xc0016900; - cmdbuf[0x19] = 0x206; - cmdbuf[0x1a] = 0x43f; - - cmdbuf[0x1b] = 0xc0016900; - cmdbuf[0x1c] = 0x83; - cmdbuf[0x1d] = 0xffff; - - cmdbuf[0x1e] = 0xc0016900; - cmdbuf[0x1f] = 0x317; - cmdbuf[0x20] = 0x10; - - cmdbuf[0x21] = 0xc0016900; - cmdbuf[0x22] = 0x2fa; - cmdbuf[0x23] = 0x3f800000; - - cmdbuf[0x24] = 0xc0016900; - cmdbuf[0x25] = 0x2fc; - cmdbuf[0x26] = 0x3f800000; - - cmdbuf[0x27] = 0xc0016900; - cmdbuf[0x28] = 0x2fb; - cmdbuf[0x29] = 0x3f800000; - - cmdbuf[0x2a] = 0xc0016900; - cmdbuf[0x2b] = 0x2fd; - cmdbuf[0x2c] = 0x3f800000; - - cmdbuf[0x2d] = 0xc0016900; - cmdbuf[0x2e] = 0x202; - cmdbuf[0x2f] = 0xcc0010; - - cmdbuf[0x30] = 0xc0016900; - cmdbuf[0x31] = 0x30e; - cmdbuf[0x32] = 0xffffffff; - - cmdbuf[0x33] = 0xc0016900; - cmdbuf[0x34] = 0x30f; - cmdbuf[0x35] = 0xffffffff; - - cmdbuf[0x36] = 0xc0002f00; - cmdbuf[0x37] = 1; - - cmdbuf[0x38] = 0xc0017600; - cmdbuf[0x39] = 7; - cmdbuf[0x3a] = 0x1ff; - - cmdbuf[0x3b] = 0xc0017600; - cmdbuf[0x3c] = 0x46; - cmdbuf[0x3d] = 0x1ff; - - cmdbuf[0x3e] = 0xc0017600; - cmdbuf[0x3f] = 0x87; - cmdbuf[0x40] = 0x1ff; - - cmdbuf[0x41] = 0xc0017600; - cmdbuf[0x42] = 199; - cmdbuf[0x43] = 0x1ff; - - cmdbuf[0x44] = 0xc0017600; - cmdbuf[0x45] = 0x107; - cmdbuf[0x46] = 0; - - cmdbuf[0x47] = 0xc0017600; - cmdbuf[0x48] = 0x147; - cmdbuf[0x49] = 0x1ff; - - cmdbuf[0x4a] = 0xc0016900; - cmdbuf[0x4b] = 0x1b1; - cmdbuf[0x4c] = 2; - - cmdbuf[0x4d] = 0xc0016900; - cmdbuf[0x4e] = 0x101; - cmdbuf[0x4f] = 0; - - cmdbuf[0x50] = 0xc0016900; - cmdbuf[0x51] = 0x100; - cmdbuf[0x52] = 0xffffffff; - - cmdbuf[0x53] = 0xc0016900; - cmdbuf[0x54] = 0x103; - cmdbuf[0x55] = 0; - - cmdbuf[0x56] = 0xc0016900; - cmdbuf[0x57] = 0x284; - cmdbuf[0x58] = 0; - - cmdbuf[0x59] = 0xc0016900; - cmdbuf[0x5a] = 0x290; - cmdbuf[0x5b] = 0; - - cmdbuf[0x5c] = 0xc0016900; - cmdbuf[0x5d] = 0x2ae; - cmdbuf[0x5e] = 0; - - cmdbuf[0x5f] = 0xc0016900; - cmdbuf[0x60] = 0x292; - cmdbuf[0x61] = 0; - - cmdbuf[0x62] = 0xc0016900; - cmdbuf[0x63] = 0x293; - cmdbuf[0x64] = 0x6000000; - - cmdbuf[0x65] = 0xc0016900; - cmdbuf[0x66] = 0x2f8; - cmdbuf[0x67] = 0; - - cmdbuf[0x68] = 0xc0016900; - cmdbuf[0x69] = 0x2de; - cmdbuf[0x6a] = 0x1e9; - - cmdbuf[0x6b] = 0xc0036900; - cmdbuf[0x6c] = 0x295; - cmdbuf[0x6d] = 0x100; - cmdbuf[0x6e] = 0x100; - cmdbuf[0x6f] = 4; - - cmdbuf[0x70] = 0xc0017900; - cmdbuf[0x71] = 0x200; - cmdbuf[0x72] = 0xe0000000; - - const auto cmdbuf_left = 0x100 - 0x74 - (clear_state ? 0xc : 0); - cmdbuf = WriteHeader(cmdbuf + 0x73, cmdbuf_left); + const auto cmdbuf_left = + HwInitPacketSize - InitSequence.size() - (clear_state ? 0xc : 0) - 1; + cmdbuf = WriteHeader(cmdbuf, cmdbuf_left); cmdbuf = WriteBody(cmdbuf, 0u); return HwInitPacketSize; @@ -645,160 +662,8 @@ u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState175(u32* cmdbuf, u32 size) { return 0; } - ClearContextState(cmdbuf); - - cmdbuf[0x0c] = 0xc0017600; - cmdbuf[0x0d] = 0x216; - cmdbuf[0x0e] = 0xffffffff; - - cmdbuf[0x0f] = 0xc0017600; - cmdbuf[0x10] = 0x217; - cmdbuf[0x11] = 0xffffffff; - - cmdbuf[0x12] = 0xc0017600; - cmdbuf[0x13] = 0x215; - cmdbuf[0x14] = 0; - - cmdbuf[0x15] = 0xc0016900; - cmdbuf[0x16] = 0x2f9; - cmdbuf[0x17] = 0x2d; - - cmdbuf[0x18] = 0xc0016900; - cmdbuf[0x19] = 0x282; - cmdbuf[0x1a] = 8; - - cmdbuf[0x1b] = 0xc0016900; - cmdbuf[0x1c] = 0x280; - cmdbuf[0x1d] = 0x80008; - - cmdbuf[0x1e] = 0xc0016900; - cmdbuf[0x1f] = 0x281; - cmdbuf[0x20] = 0xffff0000; - - cmdbuf[0x21] = 0xc0016900; - cmdbuf[0x22] = 0x204; - cmdbuf[0x23] = 0; - - cmdbuf[0x24] = 0xc0016900; - cmdbuf[0x25] = 0x206; - cmdbuf[0x26] = 0x43f; - - cmdbuf[0x27] = 0xc0016900; - cmdbuf[0x28] = 0x83; - cmdbuf[0x29] = 0xffff; - - cmdbuf[0x2a] = 0xc0016900; - cmdbuf[0x2b] = 0x317; - cmdbuf[0x2c] = 0x10; - - cmdbuf[0x2d] = 0xc0016900; - cmdbuf[0x2e] = 0x2fa; - cmdbuf[0x2f] = 0x3f800000; - - cmdbuf[0x30] = 0xc0016900; - cmdbuf[0x31] = 0x2fc; - cmdbuf[0x32] = 0x3f800000; - - cmdbuf[0x33] = 0xc0016900; - cmdbuf[0x34] = 0x2fb; - cmdbuf[0x35] = 0x3f800000; - - cmdbuf[0x36] = 0xc0016900; - cmdbuf[0x37] = 0x2fd; - cmdbuf[0x38] = 0x3f800000; - - cmdbuf[0x39] = 0xc0016900; - cmdbuf[0x3a] = 0x202; - cmdbuf[0x3b] = 0xcc0010; - - cmdbuf[0x3c] = 0xc0016900; - cmdbuf[0x3d] = 0x30e; - cmdbuf[0x3e] = 0xffffffff; - - cmdbuf[0x3f] = 0xc0016900; - cmdbuf[0x40] = 0x30f; - cmdbuf[0x41] = 0xffffffff; - - cmdbuf[0x42] = 0xc0002f00; - cmdbuf[0x43] = 1; - - cmdbuf[0x44] = 0xc0017600; - cmdbuf[0x45] = 7; - cmdbuf[0x46] = 0x1ff; - - cmdbuf[0x47] = 0xc0017600; - cmdbuf[0x48] = 0x46; - cmdbuf[0x49] = 0x1ff; - - cmdbuf[0x4a] = 0xc0017600; - cmdbuf[0x4b] = 0x87; - cmdbuf[0x4c] = 0x1ff; - - cmdbuf[0x4d] = 0xc0017600; - cmdbuf[0x4e] = 199; - cmdbuf[0x4f] = 0x1ff; - - cmdbuf[0x50] = 0xc0017600; - cmdbuf[0x51] = 0x107; - cmdbuf[0x52] = 0; - - cmdbuf[0x53] = 0xc0017600; - cmdbuf[0x54] = 0x147; - cmdbuf[0x55] = 0x1ff; - - cmdbuf[0x56] = 0xc0016900; - cmdbuf[0x57] = 0x1b1; - cmdbuf[0x58] = 2; - - cmdbuf[0x59] = 0xc0016900; - cmdbuf[0x5a] = 0x101; - cmdbuf[0x5b] = 0; - - cmdbuf[0x5c] = 0xc0016900; - cmdbuf[0x5d] = 0x100; - cmdbuf[0x5e] = 0xffffffff; - - cmdbuf[0x5f] = 0xc0016900; - cmdbuf[0x60] = 0x103; - cmdbuf[0x61] = 0; - - cmdbuf[0x62] = 0xc0016900; - cmdbuf[0x63] = 0x284; - cmdbuf[0x64] = 0; - - cmdbuf[0x65] = 0xc0016900; - cmdbuf[0x66] = 0x290; - cmdbuf[0x67] = 0; - - cmdbuf[0x68] = 0xc0016900; - cmdbuf[0x69] = 0x2ae; - cmdbuf[0x6a] = 0; - - cmdbuf[0x6b] = 0xc0016900; - cmdbuf[0x6c] = 0x292; - cmdbuf[0x6d] = 0; - - cmdbuf[0x6e] = 0xc0016900; - cmdbuf[0x6f] = 0x293; - cmdbuf[0x70] = 0x6020000; - - cmdbuf[0x71] = 0xc0016900; - cmdbuf[0x72] = 0x2f8; - cmdbuf[0x73] = 0; - - cmdbuf[0x74] = 0xc0016900; - cmdbuf[0x75] = 0x2de; - cmdbuf[0x76] = 0x1e9; - - cmdbuf[0x77] = 0xc0036900; - cmdbuf[0x78] = 0x295; - cmdbuf[0x79] = 0x100; - cmdbuf[0x7a] = 0x100; - cmdbuf[0x7b] = 4; - - cmdbuf[0x7c] = 0xc0017900; - cmdbuf[0x7d] = 0x200; - cmdbuf[0x7e] = 0xe0000000; + cmdbuf = ClearContextState(cmdbuf); + std::memcpy(cmdbuf, InitSequence175.data(), InitSequence175.size() * 4); cmdbuf[0x7f] = 0xc07f1000; cmdbuf[0x80] = 0; @@ -818,165 +683,12 @@ u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState200(u32* cmdbuf, u32 size) { cmdbuf = ClearContextState(cmdbuf); } - cmdbuf[0x00] = 0xc0017600; - cmdbuf[0x01] = 0x216; - cmdbuf[0x02] = 0xffffffff; + std::memcpy(cmdbuf, InitSequence200.data(), InitSequence200.size() * 4); + cmdbuf += InitSequence200.size(); - cmdbuf[0x03] = 0xc0017600; - cmdbuf[0x04] = 0x217; - cmdbuf[0x05] = 0xffffffff; - - cmdbuf[0x06] = 0xc0017600; - cmdbuf[0x07] = 0x215; - cmdbuf[0x08] = 0; - - cmdbuf[0x09] = 0xc0016900; - cmdbuf[0x0a] = 0x2f9; - cmdbuf[0x0b] = 0x2d; - - cmdbuf[0x0c] = 0xc0016900; - cmdbuf[0x0d] = 0x282; - cmdbuf[0x0e] = 8; - - cmdbuf[0x0f] = 0xc0016900; - cmdbuf[0x10] = 0x280; - cmdbuf[0x11] = 0x80008; - - cmdbuf[0x12] = 0xc0016900; - cmdbuf[0x13] = 0x281; - cmdbuf[0x14] = 0xffff0000; - - cmdbuf[0x15] = 0xc0016900; - cmdbuf[0x16] = 0x204; - cmdbuf[0x17] = 0; - - cmdbuf[0x18] = 0xc0016900; - cmdbuf[0x19] = 0x206; - cmdbuf[0x1a] = 0x43f; - - cmdbuf[0x1b] = 0xc0016900; - cmdbuf[0x1c] = 0x83; - cmdbuf[0x1d] = 0xffff; - - cmdbuf[0x1e] = 0xc0016900; - cmdbuf[0x1f] = 0x317; - cmdbuf[0x20] = 0x10; - - cmdbuf[0x21] = 0xc0016900; - cmdbuf[0x22] = 0x2fa; - cmdbuf[0x23] = 0x3f800000; - - cmdbuf[0x24] = 0xc0016900; - cmdbuf[0x25] = 0x2fc; - cmdbuf[0x26] = 0x3f800000; - - cmdbuf[0x27] = 0xc0016900; - cmdbuf[0x28] = 0x2fb; - cmdbuf[0x29] = 0x3f800000; - - cmdbuf[0x2a] = 0xc0016900; - cmdbuf[0x2b] = 0x2fd; - cmdbuf[0x2c] = 0x3f800000; - - cmdbuf[0x2d] = 0xc0016900; - cmdbuf[0x2e] = 0x202; - cmdbuf[0x2f] = 0xcc0010; - - cmdbuf[0x30] = 0xc0016900; - cmdbuf[0x31] = 0x30e; - cmdbuf[0x32] = 0xffffffff; - - cmdbuf[0x33] = 0xc0016900; - cmdbuf[0x34] = 0x30f; - cmdbuf[0x35] = 0xffffffff; - - cmdbuf[0x36] = 0xc0002f00; - cmdbuf[0x37] = 1; - - cmdbuf[0x38] = 0xc0017600; - cmdbuf[0x39] = 7; - cmdbuf[0x3a] = 0x1701ff; - - cmdbuf[0x3b] = 0xc0017600; - cmdbuf[0x3c] = 0x46; - cmdbuf[0x3d] = 0x1701fd; - - cmdbuf[0x3e] = 0xc0017600; - cmdbuf[0x3f] = 0x87; - cmdbuf[0x40] = 0x1701ff; - - cmdbuf[0x41] = 0xc0017600; - cmdbuf[0x42] = 199; - cmdbuf[0x43] = 0x1701fd; - - cmdbuf[0x44] = 0xc0017600; - cmdbuf[0x45] = 0x107; - cmdbuf[0x46] = 0x17; - - cmdbuf[0x47] = 0xc0017600; - cmdbuf[0x48] = 0x147; - cmdbuf[0x49] = 0x1701fd; - - cmdbuf[0x4a] = 0xc0017600; - cmdbuf[0x4b] = 0x47; - cmdbuf[0x4c] = 0x1c; - - cmdbuf[0x4d] = 0xc0016900; - cmdbuf[0x4e] = 0x1b1; - cmdbuf[0x4f] = 2; - - cmdbuf[0x50] = 0xc0016900; - cmdbuf[0x51] = 0x101; - cmdbuf[0x52] = 0; - - cmdbuf[0x53] = 0xc0016900; - cmdbuf[0x54] = 0x100; - cmdbuf[0x55] = 0xffffffff; - - cmdbuf[0x56] = 0xc0016900; - cmdbuf[0x57] = 0x103; - cmdbuf[0x58] = 0; - - cmdbuf[0x59] = 0xc0016900; - cmdbuf[0x5a] = 0x284; - cmdbuf[0x5b] = 0; - - cmdbuf[0x5c] = 0xc0016900; - cmdbuf[0x5d] = 0x290; - cmdbuf[0x5e] = 0; - - cmdbuf[0x5f] = 0xc0016900; - cmdbuf[0x60] = 0x2ae; - cmdbuf[0x61] = 0; - - cmdbuf[0x62] = 0xc0016900; - cmdbuf[0x63] = 0x292; - cmdbuf[0x64] = 0; - - cmdbuf[0x65] = 0xc0016900; - cmdbuf[0x66] = 0x293; - cmdbuf[0x67] = 0x6020000; - - cmdbuf[0x68] = 0xc0016900; - cmdbuf[0x69] = 0x2f8; - cmdbuf[0x6a] = 0; - - cmdbuf[0x6b] = 0xc0016900; - cmdbuf[0x6c] = 0x2de; - cmdbuf[0x6d] = 0x1e9; - - cmdbuf[0x6e] = 0xc0036900; - cmdbuf[0x6f] = 0x295; - cmdbuf[0x70] = 0x100; - cmdbuf[0x71] = 0x100; - cmdbuf[0x72] = 4; - - cmdbuf[0x73] = 0xc0017900; - cmdbuf[0x74] = 0xe0000000; - cmdbuf[0x75] = 0x200; - - const auto cmdbuf_left = 0x100 - 0x77 - (clear_state ? 0xc : 0); - cmdbuf = WriteHeader(cmdbuf + 0x76, cmdbuf_left); + const auto cmdbuf_left = + HwInitPacketSize - InitSequence200.size() - (clear_state ? 0xc : 0) - 1; + cmdbuf = WriteHeader(cmdbuf, cmdbuf_left); cmdbuf = WriteBody(cmdbuf, 0u); return HwInitPacketSize; @@ -997,173 +709,12 @@ u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350(u32* cmdbuf, u32 size) { cmdbuf = ClearContextState(cmdbuf); } - cmdbuf[0x00] = 0xc0017600; - cmdbuf[0x01] = 0x216; - cmdbuf[0x02] = 0xffffffff; + std::memcpy(cmdbuf, InitSequence350.data(), InitSequence350.size() * 4); + cmdbuf += InitSequence350.size(); - cmdbuf[0x03] = 0xc0017600; - cmdbuf[0x04] = 0x217; - cmdbuf[0x05] = 0xffffffff; - - cmdbuf[0x06] = 0xc0017600; - cmdbuf[0x07] = 0x215; - cmdbuf[0x08] = 0; - - cmdbuf[0x09] = 0xc0016900; - cmdbuf[0x0a] = 0x2f9; - cmdbuf[0x0b] = 0x2d; - - cmdbuf[0x0c] = 0xc0016900; - cmdbuf[0x0d] = 0x282; - cmdbuf[0x0e] = 8; - - cmdbuf[0x0f] = 0xc0016900; - cmdbuf[0x10] = 0x280; - cmdbuf[0x11] = 0x80008; - - cmdbuf[0x12] = 0xc0016900; - cmdbuf[0x13] = 0x281; - cmdbuf[0x14] = 0xffff0000; - - cmdbuf[0x15] = 0xc0016900; - cmdbuf[0x16] = 0x204; - cmdbuf[0x17] = 0; - - cmdbuf[0x18] = 0xc0016900; - cmdbuf[0x19] = 0x206; - cmdbuf[0x1a] = 0x43f; - - cmdbuf[0x1b] = 0xc0016900; - cmdbuf[0x1c] = 0x83; - cmdbuf[0x1d] = 0xffff; - - cmdbuf[0x1e] = 0xc0016900; - cmdbuf[0x1f] = 0x317; - cmdbuf[0x20] = 0x10; - - cmdbuf[0x21] = 0xc0016900; - cmdbuf[0x22] = 0x2fa; - cmdbuf[0x23] = 0x3f800000; - - cmdbuf[0x24] = 0xc0016900; - cmdbuf[0x25] = 0x2fc; - cmdbuf[0x26] = 0x3f800000; - - cmdbuf[0x27] = 0xc0016900; - cmdbuf[0x28] = 0x2fb; - cmdbuf[0x29] = 0x3f800000; - - cmdbuf[0x2a] = 0xc0016900; - cmdbuf[0x2b] = 0x2fd; - cmdbuf[0x2c] = 0x3f800000; - - cmdbuf[0x2d] = 0xc0016900; - cmdbuf[0x2e] = 0x202; - cmdbuf[0x2f] = 0xcc0010; - - cmdbuf[0x30] = 0xc0016900; - cmdbuf[0x31] = 0x30e; - cmdbuf[0x32] = 0xffffffff; - - cmdbuf[0x33] = 0xc0016900; - cmdbuf[0x34] = 0x30f; - cmdbuf[0x35] = 0xffffffff; - - cmdbuf[0x36] = 0xc0002f00; - cmdbuf[0x37] = 1; - - cmdbuf[0x38] = 0xc0017600; - cmdbuf[0x39] = 7; - cmdbuf[0x3a] = 0x1701ff; - - cmdbuf[0x3b] = 0xc0017600; - cmdbuf[0x3c] = 0x46; - cmdbuf[0x3d] = 0x1701fd; - - cmdbuf[0x3e] = 0xc0017600; - cmdbuf[0x3f] = 0x87; - cmdbuf[0x40] = 0x1701ff; - - cmdbuf[0x41] = 0xc0017600; - cmdbuf[0x42] = 199; - cmdbuf[0x43] = 0x1701fd; - - cmdbuf[0x44] = 0xc0017600; - cmdbuf[0x45] = 0x107; - cmdbuf[0x46] = 0x17; - - cmdbuf[0x47] = 0xc0017600; - cmdbuf[0x48] = 0x147; - cmdbuf[0x49] = 0x1701fd; - - cmdbuf[0x4a] = 0xc0017600; - cmdbuf[0x4b] = 0x47; - cmdbuf[0x4c] = 0x1c; - - cmdbuf[0x4d] = 0xc0016900; - cmdbuf[0x4e] = 0x1b1; - cmdbuf[0x4f] = 2; - - cmdbuf[0x50] = 0xc0016900; - cmdbuf[0x51] = 0x101; - cmdbuf[0x52] = 0; - - cmdbuf[0x53] = 0xc0016900; - cmdbuf[0x54] = 0x100; - cmdbuf[0x55] = 0xffffffff; - - cmdbuf[0x56] = 0xc0016900; - cmdbuf[0x57] = 0x103; - cmdbuf[0x58] = 0; - - cmdbuf[0x59] = 0xc0016900; - cmdbuf[0x5a] = 0x284; - cmdbuf[0x5b] = 0; - - cmdbuf[0x5c] = 0xc0016900; - cmdbuf[0x5d] = 0x290; - cmdbuf[0x5e] = 0; - - cmdbuf[0x5f] = 0xc0016900; - cmdbuf[0x60] = 0x2ae; - cmdbuf[0x61] = 0; - - cmdbuf[0x62] = 0xc0016900; - cmdbuf[0x63] = 0x102; - cmdbuf[0x64] = 0; - - cmdbuf[0x65] = 0xc0016900; - cmdbuf[0x66] = 0x292; - cmdbuf[0x67] = 0; - - cmdbuf[0x68] = 0xc0016900; - cmdbuf[0x69] = 0x293; - cmdbuf[0x6a] = 0x6020000; - - cmdbuf[0x6b] = 0xc0016900; - cmdbuf[0x6c] = 0x2f8; - cmdbuf[0x6d] = 0; - - cmdbuf[0x6e] = 0xc0016900; - cmdbuf[0x6f] = 0x2de; - cmdbuf[0x70] = 0x1e9; - - cmdbuf[0x71] = 0xc0036900; - cmdbuf[0x72] = 0x295; - cmdbuf[0x73] = 0x100; - cmdbuf[0x74] = 0x100; - cmdbuf[0x75] = 4; - - cmdbuf[0x76] = 0xc0017900; - cmdbuf[0x77] = 0x200; - cmdbuf[0x78] = 0xe0000000; - - cmdbuf[0x79] = 0xc0016900; - cmdbuf[0x7a] = 0x000002aa; - cmdbuf[0x7b] = 0xff; - - const auto cmdbuf_left = 0x100 - 0x7d - (clear_state ? 0xc : 0); - cmdbuf = WriteHeader(cmdbuf + 0x7c, cmdbuf_left); + const auto cmdbuf_left = + HwInitPacketSize - InitSequence350.size() - (clear_state ? 0xc : 0) - 1; + cmdbuf = WriteHeader(cmdbuf, cmdbuf_left); cmdbuf = WriteBody(cmdbuf, 0u); return HwInitPacketSize;