Skip to content

Post shaders: Support more than one previous frame - #22591

Open
LunaMoo wants to merge 1 commit into
hrydgard:masterfrom
LunaMoo:postshader-previous-frames
Open

LunaMoo wants to merge 1 commit into
hrydgard:masterfrom
LunaMoo:postshader-previous-frames

Conversation

@LunaMoo

@LunaMoo LunaMoo commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Post shaders can ask for several previous frames with PreviousFrames=N in their ini section (plain UsePreviousFrame=True still means 1). They are bound as sampler2 (1 frame ago), sampler3 (2 frames ago) and so on, and the fragment shader gets "#define PPSSPP_PREVIOUS_FRAMES " with the count it actually got, so it can adapt with #if on devices with fewer slots.

The count is limited by what the backend can bind, keeping 2 texture slots free for future post-shader inputs (depth, multipass), and capped at 16:

  • thin3d gets DeviceCaps::maxTextureSlots, MAX_TEXTURE_SLOTS goes 3 -> 20.
  • GL: GL_MAX_TEXTURE_IMAGE_UNITS (GLES 2.0 minimum of 8 gives 4 frames).
  • D3D11: 16 slots on FL10+, 8 on FL9.x.
  • Vulkan: the thin3d descriptor set layout is sized from the device's sampler limits, and each draw pushes only the descriptors it uses.

Previous frames live in a ring of N+1 framebuffers. Until enough frames have been rendered, missing ones repeat the oldest available one, and on the very first frame the current input is bound instead.

Adds a "Motion Blur (multi-frame)" example shader.

- Fixes hrydgard#15668

Post shaders can ask for several previous frames with PreviousFrames=N in
their ini section (plain UsePreviousFrame=True still means 1). They are
bound as sampler2 (1 frame ago), sampler3 (2 frames ago) and so on, and the
fragment shader gets "#define PPSSPP_PREVIOUS_FRAMES <n>" with the count it
actually got, so it can adapt with #if on devices with fewer slots.

The count is limited by what the backend can bind, keeping 2 texture slots
free for future post-shader inputs (depth, multipass), and capped at 16:
- thin3d gets DeviceCaps::maxTextureSlots, MAX_TEXTURE_SLOTS goes 3 -> 20.
- GL: GL_MAX_TEXTURE_IMAGE_UNITS (GLES 2.0 minimum of 8 gives 4 frames).
- D3D11: 16 slots on FL10+, 8 on FL9.x.
- Vulkan: the thin3d descriptor set layout is sized from the device's
  sampler limits, and each draw pushes only the descriptors it uses.

Previous frames live in a ring of N+1 framebuffers. Until enough frames
have been rendered, missing ones repeat the oldest available one, and on
the very first frame the current input is bound instead.

Adds a "Motion Blur (multi-frame)" example shader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hrydgard

Copy link
Copy Markdown
Owner

It's kind of a cool thing to have but the use cases over 1 frame of history seem really, really limited. Not sure I want to increase the complexity here.

@LunaMoo

LunaMoo commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

Well, the motion blur can be really smooth with just few extra frames and will allow to simulate awfulness of early LCD screens ghosting, but personally I care only about having better post process effect support than RA, mostly already is, but RA has this and we don't ^_^;

@LunaMoo LunaMoo mentioned this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for more past frames in post process effects

2 participants