Repository navigation
Conversation
…texcoords handling - Fix pointer scaling overflow in rsxSetupContextData by casting addr to uintptr_t before adding byte length. - Add allowTex (bit 15) flag in compilerfp.cpp and LoadFragmentProgramLocation when fragment program samples textures. - Correct SetVertexProgramConstants second burst source offset to &value[16] instead of value. - Fix SetTimeStamp writing outside allocated packet bounds (currenp[1] instead of [2]). - Fix ResetCommandBuffer to query real buffer start offset via gcmAddressToOffset and rewind context->current. - Fix rsxContextCallback assembly calling convention to preserve registers across 32-bit OPD invocations. - Add missing vdec codec defines in vdec.h.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces critical stability fixes to
librsx,cgcomp, and related GCM headers inPSL1GHT. These patches resolve severe hardware deadlocks, memory corruptions, pointer arithmetic overflows, and shader compilation failures that break continuous drawing and streaming workloads.These issues directly surfaced during the porting and bare-metal deployment of PS3-Moonlight and PS3-Movian.
Important
Bare-Metal Hardware Verification:
Both the reproduced failure states and their corresponding fixes have been thoroughly tested and validated on physical PlayStation 3 retail hardware running HEN as well as RPCS3. These fixes are proven in sustained real-world production workloads.
Technical Problem Breakdown & Fix Details
1.
librsx: Wrap User Callback in__get_opd32to Prevent Fatal Crash on Buffer Wrap03a2c10ppu/librsx/init.cIn the 64-bit PowerPC ELF ABI (
ppc64), C function pointers do not point directly to executable machine code; they point to a 24-byte Official Procedure Descriptor (OPD) consisting of[function_entry_address, toc_pointer, environment_pointer].However, in
ppu/include/rsx/rsx_function_macros.h, the low-level GCM assembly callback dispatcher (rsxContextCallback) is designed with 32-bit word instructions (lwz 0, 0(%3); lwz 2, 4(%3); mtctr 0; bctrl), expecting a 32-bit OPD layout (opd32).Passing a standard 64-bit function pointer directly to
rsxSetContextCallbackcauses the dispatcher to read high 32-bit word halves as function entry and TOC pointers. The moment the RSX command buffer wraps around, the dispatcher executes a jump to corrupted memory, immediately producing a fatal PPU trap / panic.rsxSetContextCallbacknow wraps user callback handlers through__get_opd32(), guaranteeing that a properly formatted 32-bit OPD entry point and TOC descriptor are stored intocontext->callback.2.
librsx&cgcomp: Fix Pointer Arithmetic Overflow, Vertex Constant Offsets, and Texture Sampling Flagb7c7ed9ppu/librsx/init.c,ppu/librsx/commands_impl.h,ppu/librsx/buffer_impl.h,ppu/include/rsx/rsx_function_macros.h,tools/cgcomp/source/compilerfp.cpp,ppu/include/codec/vdec.hrsxSetupContextData(init.c):The command buffer initialization previously performed pointer arithmetic by adding a byte
lengthdirectly to a typeduint32_t*pointer. In standard C/C++, addinglengthtouint32_t*scales the offset bysizeof(uint32_t) == 4. For instance, a 1 MB buffer resulted in settingcontext->current4 MB ahead, pointing far outside the allocated buffer boundaries and immediately causing heap/memory corruption.Fix: Cast the base address to
uintptr_t/ raw byte offsets before adding the byte length.cgcompTexture Sampler Control Bit (allowTex/0x8000):When compiling Cg fragment shaders that perform texture sampling (such as YUV-to-RGB color space conversion in video playback and streaming), the RSX microcode requires bit 15 (
0x8000) to be set in the fragment program instruction word. Without this flag, texture coordinate interpolation and texture unit fetches fail or output black/garbage frames.Fix: Explicitly set
allowTex(bit 15) incompilerfp.cppwhenever the fragment shader references texture samplers.commands_impl.h):In
SetVertexProgramConstants, the second burst packet was reusing the base pointervalueinstead of advancing by 16 floats (&value[16]). When uploading matrix blocks or multi-vector arrays exceeding 16 constants, the first chunk was repeatedly overwritten while subsequent vectors were dropped.Fix: Properly advance the source data pointer to
&value[16]for the second transfer chunk.SetTimeStamp(commands_impl.h):SetTimeStampwas writing tocurrent[1]instead of[2], corrupting the command stream and misaligning subsequent GPU commands.Fix: Corrected packet indexing to respect packet payload sizing.
rsx_function_macros.h):The inline callback macro was clobbering caller-saved registers during 32-bit OPD dispatch, causing mysterious crashes upon returning from user callbacks.
Fix: Guarded register preservation across the assembly invocation.
vdec.h):Added missing standard VDEC codec constants (MPEG2, AVC/H.264, VC-1, DivX) required for hardware video decoding integration.
3.
librsx: Bounded Spin Timeout and Hardware Memory Barrier inResetCommandBuffer9378160ppu/librsx/buffer_impl.hResetCommandBufferhad an unbounded loop waiting for the GPU read pointer to reach the offset:ctrl->getmay never matchoffset. This caused the PPU thread to enter an infinite spinlock, hard-freezing the entire console and requiring a physical power-cord disconnection.spins < 100000, ~3 second timeout) to gracefully break out of deadlocks.__sync()) before updatingctrl->put = offsetto ensure all previous cache flushes and memory transactions are committed to the RSX memory controller.gcmAddressToOffset(context->begin).Real-World Project Impact
0x8000), and hard PS3 freezes on frame burst stalls.