Commit Graph
67 Commits
Author SHA1 Message Date
Henrik Rydgård 3bd41376da More memory cleanup 2026-08-11 20:12:10 +02:00
Henrik Rydgård 9396030f02 More Read_U32 cleanup 2026-08-11 09:08:52 +02:00
James0124andClaude Opus 5 8afa18c21c sceFont: match hardware's glyph blending and destination combine
sceFontGetCharGlyphImage_Clip stored the glyph over the destination buffer.
Hardware adds it with saturation instead, so on hardware a glyph never erases
what was already in the buffer - the transparent parts contribute zero - while
we cleared them to 0. Text drawn as overlapping glyphs lost the earlier ones.

Measured on a PSP-1000 against a dumped ltn0.pgf, sweeping the pen position's
fractional part, both 4bpp and 8bpp, and several destination pre-fill values so
that "wrote a 0 here" could be told apart from "did not write here":

- The result is min(dst + blend, max), not blend.
- The two horizontal weights are rounded in opposite directions, down for the
  left neighbour and up for the pixel itself. That is not a free choice: it is
  what makes the pair sum to exactly the format's full scale whenever both
  samples are full ink, for every fraction. Rounding the combined sum once, as
  before, disagrees with hardware on about a fifth of the blended pixels.
- 4bpp blends the raw nibble and 8bpp the value swizzled to 8 bit. Blending at
  8 bit and narrowing afterwards is not the same thing and misses ~0.6%.
- The fractional part of yPos64 is discarded entirely. There is no vertical
  blending and the rectangle never grows downwards, so renderY2 loses its +1
  and the two render loops collapse into one - xFrac == 0 needs no special
  case, the first term vanishes and the second collapses to exactly b.

Only PSP_FONT_PIXELFORMAT_4 and _8 render at all. _4_REV, _24 and _32 return 0
and leave the buffer completely untouched, which is also the answer to the
"not sure how to make these produce an image" note in pspautotests'
charglyphimageclip.cpp. They are skipped now, with a report so that a game
relying on them can be found - only one buffer configuration was measured.

Verified with pspautotests: the new charglyphimagexfrac goes from 388 of 601
differing lines to passing, and charglyphimage and charglyphimageclip improve
from 57 differing lines to 3. No other font test changes. The remaining 3 are
a separate, pre-existing issue with bytesPerLine of 0 and 1.

Not covered: clip rectangles that actually clip, negative pen positions, and
the shadow glyph entry points.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-10 19:49:55 +09:00
Henrik Rydgård 04d8613d81 Bounds-check charPtr inside PGF::ReadCharGlyph
ReadCharGlyph read glyph metadata at an attacker-controlled bit offset
with no validation, and ReadShadowGlyph only checked after delegating to
it. Validate charPtr (with margin for the header reads) at the top of
ReadCharGlyph so it is safe regardless of caller, and drop the now
redundant checks at the ReadPtr call sites.
2026-08-01 11:57:27 +02:00
Henrik Rydgård 788150c28e Fix out-of-bounds reads in PGF font parsing
PGF::ReadPtr walked four length-prefixed tables and computed table sizes
before any bounds check, and used signed 32-bit size math that could
overflow, allowing a crafted font to read past the input buffer.

- Validate the total size of all tables up front using 64-bit math.
- Check the rev3 extra header fits before reading it.
- Cap charPointerLength/charMapLength/shadowMapLength to avoid absurd
  allocations.
- Bounds-check glyph data offsets before reading each glyph.

Also throw in a warning fix
2026-08-01 11:57:27 +02:00
nintendo424 e5689d1adc gpu: Preserve first-frame font render targets
Some games render HLE sceFont glyphs into small VRAM-backed framebuffers and immediately sample them as textures. This needs both the source glyph buffer and the temporary render target to be preserved before later commands overwrite or rebind them.

Save first-frame data from the previous render target before creating a new framebuffer, since ResizeFramebufFBO() makes the new framebuffer current. Also flush pending draws before PGF writes over a glyph buffer that may still be referenced by queued texture draws.

Backend software transform normally reports safe framebuffer size during draw flush, but first-frame readback can happen before queued draws reach that path. Estimate through-mode rectangle/triangle bounds before SubmitPrim() and feed those bounds to SetSafeSize(), using actual vertices clamped to scissor instead of a tiny-target heuristic.

Fixes missing text in Evangelion JO.
2026-05-15 12:23:14 -04:00
Henrik Rydgård c91169e702 Restore removed <algorithm> includes.
Turns out these were needed after all. For some reason, on Windows and
Mac, <algorithm> gets auto-included by something else so I don't notice
when it's missing, and MSVC's include dependency tracker doesn't see it
either.
2024-12-19 09:53:07 +01:00
Henrik Rydgård 3e198c53b2 More include cleanup 2024-12-18 13:57:26 +01:00
Henrik Rydgård 0df2a40487 Remove the "GPUInterface" base class. Not really useful, GPUCommon is pretty much the same thing. 2024-12-02 11:12:14 +01:00
Herman Semenov 3c66f149d3 [Common/Core/Windows] Removed excess check pointer before delete or free() 2024-09-17 11:34:42 +02:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Unknown W. Brackets ca4a0a848a Font: Fix bad memory read on invalid font data. 2022-08-13 12:16:21 -07:00
Unknown W. Brackets 5abec6ca18 Font: Prevent a crash on invalid data. 2021-06-12 10:09:47 -07:00
aliaspider 9a3e5879bb Global: Correct many endian types and casts. 2021-02-18 22:25:24 -08:00
Henrik Rydgård 58f19051cd Attempt to fix #14022 2021-01-30 18:03:46 +01:00
Unknown W. Brackets b8342fb8ec SaveState: Rename ChunkFile files to Serialize.
Makes more sense and less weird than ChunkFileDoMap, etc.
2020-08-10 08:04:05 +00:00
Unknown W. Brackets 4b4e3432cd SaveState: Split Do() into a separate header. 2020-08-10 08:03:41 +00:00
Henrik Rydgård c5e0b799d9 Remove category from _assert_msg_ functions. We don't filter these by category anyway.
Fixes the inconsistency where we _assert_ didn't take a category but
_assert_msg_ did.
2020-07-19 20:33:25 +02:00
Unknown W. Brackets eacebd4c41 Font: Draw nothing for chars before first glyph.
This matches the logic in sceFontGetCharImageRect(), and improves tests.
Previously, we were drawing the alt character in these cases.
2016-08-27 09:41:01 -07:00
Unknown W. Brackets e8fb61cf43 Font: Fix clipping when x/y aren't 0.
The final X2/Y2 are relative to the glyph at x,y.
2016-01-23 16:01:25 -08:00
Unknown W. Brackets b8a2a6647d Font: Turns out this happens a lot. 2016-01-23 15:59:47 -08:00
Unknown W. Brackets 621f86c7f1 Font: Blend after swizzling to 8 bit.
This is much closer, but the values still are slightly off.
2016-01-23 15:42:42 -08:00
Unknown W. Brackets 1860180c2e Font: Implement subpixel rendering. 2016-01-23 15:37:19 -08:00
Unknown W. Brackets 32573ce121 Fix a typo in font loading. 2015-02-01 01:20:28 -08:00
Henrik Rydgard d6b51d4dfa Reduce some excessive logging 2014-06-09 19:40:05 +02:00
Unknown W. Brackets d65af7353b Avoid some ChunkFile includes. 2014-03-15 11:32:57 -07:00
Unknown W. Brackets 131cbc073c Implement sceFontGetShadowInfo(). 2014-03-01 00:18:19 -08:00
Unknown W. Brackets 29d2e81676 Cleanup errors in sceFontGet*ImageRect(). 2014-02-28 23:04:34 -08:00
Unknown W. Brackets bc3e123b61 Oops, fix negative clip regions.
Since they're summed, need to clamp the left/top side.  And the
bottom/right side is offset by x/y.
2014-02-28 21:25:45 -08:00
Unknown W. Brackets 46370e2860 Implement sceFontGetShadowGlyphImage().
Not sure if any games actually use it, though...
2014-02-28 20:57:18 -08:00
Unknown W. Brackets ab6b998710 Correct clipping in sceFontGetCharGlyphImage_Clip.
It was not clipping completely, and didn't handle negative clip w/h.
Also, reduce to debug log (seems to work fine now and has been working
fine in most games.)
2014-02-27 00:19:40 -08:00
Unknown W. Brackets 603c1dd614 Improve error codes in sceFontOpen*().
Fixes some unlikely cases of crashes as well.  I think there are leaks
here...
2014-02-22 20:35:58 -08:00
Ced2911 67de460ec6 [Xbox] Endian, missing on swap.h ? 2014-01-26 14:28:42 -08:00
Unknown W. Brackets 916768d938 Kill the "packagedFont" hack, correctly fixed now. 2013-12-10 23:19:25 -08:00
Unknown W. Brackets 952ec82678 Detect bad fonts ascenders and workaround.
Fixes #4765 with the fonts that come with PPSSPP.
2013-12-10 23:14:38 -08:00
Henrik Rydgard a3caefed18 Buildfix (pgf 64-bit) 2013-11-17 12:55:35 +01:00
Unknown W. Brackets 8f6315e375 Support replacement chars in sceFontGetCharInfo(). 2013-11-16 23:32:13 -08:00
Unknown W. Brackets d955d9b303 Cut down on unnecessary allocs in font loading. 2013-11-16 22:53:05 -08:00
Unknown W. Brackets 769ffbd33b Read in the shadow flags and give them to the game.
Yay, now this struct seems to match the PSP.
2013-11-16 21:08:34 -08:00
Unknown W. Brackets 4505cb4b3a Match ascender/descender values per character.
This makes sense, and matches the ascender/descender for my fonts.

However, it could be wrong for vertical fonts... not sure.
2013-11-16 20:35:50 -08:00
Unknown W. Brackets bb94f31ec7 Simplify GetGlyph() and getBits() usage a bit. 2013-11-16 20:16:49 -08:00
Unknown W. Brackets d446659b2a Improve the performance of getBits().
Well, it's not used much, although it's much faster now, heh.
2013-11-16 19:34:45 -08:00
Unknown W. Brackets e77b8bc5b5 Check for non-indexed glyph advance values.
This change from JPCSP:
http://code.google.com/p/jpcsp/source/detail?r=3350
2013-11-16 18:35:15 -08:00
Unknown W. Brackets 2d7741a433 Return # of glyphs, not charmaps, in font info.
This makes it match the value from the PSP, and seems logical (the charmap
value is hardly useful, and might lead me to overallocate space for the
glyph bitmaps...)
2013-11-16 18:33:10 -08:00
Unknown W. Brackets 68af1ea6f8 Flip the descender in char info.
This makes it close to the value from a PSP (just rounded to 64...)
2013-11-16 18:32:06 -08:00
raven02 98cbd90178 Regression font alignment fix 2013-11-02 20:31:39 +08:00
raven02 92042e6b55 Apply offset by 1px to our provided PSP fonts 2013-10-27 10:02:13 +08:00
adrian17 7e3f35dfe3 Removed redundant includes 2013-09-30 19:05:04 +02:00
Unknown W. Brackets 50e9e45d65 Check version in each DoState() func.
They bail on PointerWrap error or bad version.
2013-09-14 20:23:03 -07:00
Henrik Rydgard 8c88dff5a4 More log categories, use them (and existing ones). Improve log config. 2013-09-07 22:02:55 +02:00