Skip to content

shader_recompiler: Reach in-game status in Control with fragment input fixes - #4863

Open
w1naenator wants to merge 51 commits into
shadps4-emu:mainfrom
w1naenator:reach-control-ingame-fix
Open

shader_recompiler: Reach in-game status in Control with fragment input fixes#4863
w1naenator wants to merge 51 commits into
shadps4-emu:mainfrom
w1naenator:reach-control-ingame-fix

Conversation

@w1naenator

Copy link
Copy Markdown
Contributor

Summary

Complete the fragment interpolation path for Liverpool shaders and correctly
translate fragment inputs across AMD and KHR Vulkan implementations.

This fixes incorrect lighting and dark rendering observed in Control while
preserving the alternate front-face encoding required by other games.

Changelog

Fragment interpolation

  • Implement specification-driven GCN V_INTERP_P1_F32,
    V_INTERP_P2_F32, and V_INTERP_MOV_F32 behavior.
  • Preserve the native GCN P0, P10, and P20 coefficient semantics.
  • Handle constant and flat shader inputs without applying artificial
    zero-slope interpolation.
  • Add support for perspective and no-perspective interpolation at:
    • Center
    • Centroid
    • Sample
  • Implement BaryCoordPullModel:
    • Use BaryCoordPullModelAMD when
      VK_AMD_shader_explicit_vertex_parameter is available.
    • Reconstruct (I/W, J/W, 1/W) using KHR barycentrics and
      FragCoord.w otherwise.
  • Support scalar per-vertex fragment parameters.
  • Generate properly qualified KHR barycentric inputs instead of using
    interpolation-function approximations.

Primitive and provoking-vertex handling

  • Carry fragment primitive topology and provoking-vertex state into shader
    runtime specialization.
  • Map per-vertex parameters according to the host API's primitive numbering.
  • Handle point, line, triangle, fan, strip, and adjacency topologies.
  • Account for odd/even triangle-strip vertex ordering where required.
  • Query VK_EXT_provoking_vertex feature support instead of relying only on
    extension presence.
  • Query
    triStripVertexOrderIndependentOfProvokingVertex from the KHR barycentric
    properties.
  • Add the PrimitiveId input only when topology remapping requires primitive
    parity.

Front-face encoding

  • Read FRONT_FACE_ALL_BITS from SPI_BARYC_CNTL.
  • Carry the selected encoding through fragment runtime specialization.
  • Represent Vulkan FrontFacing as a boolean IR attribute.
  • Encode the guest FRONT_FACE VGPR according to Liverpool state:
    • Raw +1.0f / -1.0f bits when FRONT_FACE_ALL_BITS is disabled.
    • Integer 1 / 0 when FRONT_FACE_ALL_BITS is enabled.
  • Avoid the unconditional sign encoding that caused regressions in geometry
    using the alternate mode.

This part is based on review suggestions from Roamic, Raphael, and
IndecisiveTurtle.

Sample coverage

  • Load SampleCoverage when enabled by the pixel-shader input registers.
  • Use a fast single-sample path without declaring SampleMask.
  • Mask multisample coverage to the active sample count.
  • Return zero coverage for helper invocations.
  • Carry the framebuffer sample count through fragment specialization.

Shader resource-table synchronization

  • Record the guest-memory ranges traversed by the flattened SRT walker.
  • Synchronize GPU-modified SRT ranges before flattening and shader
    specialization.
  • Support nested SRT pointers while retaining parent/child relationships.
  • Refresh flattened user data through the pipeline cache after required
    buffer-cache downloads.
  • Serialize SRT metadata field-by-field, including memory reservations,
    instead of serializing the raw structure.

Renderer and descriptor robustness

  • Expand compute image-copy detection to support variants with an optional
    small bounds buffer.
  • Validate unique source and destination buffers before replacing a compute
    dispatch with an image copy.
  • Clamp shader buffers to actual mapped memory intervals.
  • Ignore fully unmapped buffer descriptors safely.
  • Invalidate aliased cached images after both formatted and raw
    storage-buffer writes.
  • Preserve the correct descriptor type for null or invalid storage images.
  • Reject reserved sampler descriptor encodings before creating Vulkan
    samplers.
  • Bind a null sampler for invalid descriptors exposed by untaken dynamic
    shader branches.

Vulkan and SPIR-V

  • Prefer VK_AMD_shader_explicit_vertex_parameter when available.
  • Use VK_KHR_fragment_shader_barycentric as the portable fallback,
    including Vulkan 1.4 core availability.
  • Request interpolation, geometry, barycentric, and sample-rate capabilities
    only when required by the generated shader.
  • Add missing no-perspective centroid and pull-model IR attributes.
  • Add a boolean GetAttributeU1 IR path for boolean Vulkan built-ins.

Shader cache

  • Include topology, sample count, provoking-vertex state, and front-face
    encoding in fragment runtime specialization.
  • Update shader binary and metadata cache versions to invalidate
    incompatible cached shaders.
  • Serialize the new SRT metadata explicitly.

w1naenator and others added 14 commits May 16, 2026 22:29
- implement no-perspective centroid barycentrics
- honor center, centroid, and sample evaluation on the KHR path
- handle provoking-vertex and topology-dependent vertex ordering
- preserve native GCN P0/P10/P20 and pull-model semantics
- reject inexact interpolation fallbacks instead of applying zero-slope hacks
- add numerical coverage for interpolation modes and vertex mappings
- sync with main
- implement specification-driven AMD and KHR barycentric interpolation
- handle topology, provoking vertex, centroid, sample, and pull-model inputs
- keep clip-plane and null-image descriptors valid
- expand GCN interpolation tests
Read FRONT_FACE_ALL_BITS from SPI_BARYC_CNTL and carry it through
fragment runtime specialization. Represent Vulkan FrontFacing as a
boolean IR attribute, then encode the guest VGPR value as either
+1.0/-1.0 or integer 1/0 according to the register mode.

Update shader cache versions and add regression tests for both
encodings.

Based on review suggestions from Roamic, Raphael, and
IndecisiveTurtle.
@w1naenator

w1naenator commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Control completes level loading and reaches in-game. The framerate is ~30 FPS, and the game looks very close to the real PS4.
image
image

w1naenator added 2 commits August 17, 2026 07:05
@raphaelthegreat

Copy link
Copy Markdown
Contributor

The barycentric changes need their separate PR. Also when making multi-patch PRs like this avoid having any "merge main" commits it makes it harder to review

@w1naenator

Copy link
Copy Markdown
Contributor Author

The barycentric changes need their separate PR. Also when making multi-patch PRs like this avoid having any "merge main" commits it makes it harder to review

I'll do it when this PR became acceptable.

@w1naenator

Copy link
Copy Markdown
Contributor Author

Ok, needed regression tests again.

@bigol83

bigol83 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

No more device lost in games, Control still looks good

Yakuza 6 still looks like this though
immagine

@w1naenator

Copy link
Copy Markdown
Contributor Author

hmm

No more device lost in games, Control still looks good

Yakuza 6 still looks like this though immagine

But it is beautiful, no?
Ok, I try to understand where it goes wrong.

@bigol83

bigol83 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

hmm

No more device lost in games, Control still looks good
Yakuza 6 still looks like this though immagine

But it is beautiful, no? Ok, I try to understand where it goes wrong.

Zombie Kiryu is great 😄

Anyway there is also a bit of performance loss in Kingdom Hearts 3, like 3-4 fps slower compared to main

@w1naenator

w1naenator commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

hmm

No more device lost in games, Control still looks good
Yakuza 6 still looks like this though immagine

But it is beautiful, no? Ok, I try to understand where it goes wrong.

Zombie Kiryu is great 😄

Anyway there is also a bit of performance loss in Kingdom Hearts 3, like 3-4 fps slower compared to main

I haven't Yakuza 6, is it still zombie? Maybe you can provide log?

@bigol83

bigol83 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Still an issue
immagine

@w1naenator

Copy link
Copy Markdown
Contributor Author

ok, i found that I am bro

Still an issue immagine

I found last night that I had broken V_INTERP_MOV_F32 in commit d8993a5f. I’ve fixed it, done some cleanup, and a new commit will follow soon.

- restore direct P10/P20/P0 selection for V_INTERP_MOV_F32
- remove the incorrect P0-relative reconstruction that corrupted texture coordinates
- update LDS synchronization for loops with divergent Break or Repeat conditions
- defer unsafe loop-local barriers until workgroup invocations reconverge
- add interpolation and shared-memory barrier regression coverage
- update the stale KHR barycentric test to match current decoration behavior
@w1naenator

Copy link
Copy Markdown
Contributor Author

@bigol83 Can you, please test again?

@w1naenator

Copy link
Copy Markdown
Contributor Author

Seems like it gives something good to my favorite game too.
Screenshot 2026-08-18 235242
Screenshot 2026-08-18 235004

@w1naenator

w1naenator commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

With it, FIST shows intro now. ^^ image

It crashes when skipping it... shad_log.zip

With this #4561 menu and loading screen is reachable. But intro skipped.

@tochnonechelovek

Copy link
Copy Markdown

No notable changes or regressions in my titles.

w1naenator and others added 25 commits August 30, 2026 00:07
…e-fix

# Conflicts:
#	src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
#	src/shader_recompiler/backend/spirv/spirv_emit_context.cpp
#	src/video_core/renderer_vulkan/vk_rasterizer.cpp
…tor/shadPS4 into reach-control-ingame-fix

# Conflicts:
#	src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
#	src/shader_recompiler/backend/spirv/spirv_emit_context.cpp
- implement no-perspective centroid barycentrics
- honor center, centroid, and sample evaluation on the KHR path
- handle provoking-vertex and topology-dependent vertex ordering
- preserve native GCN P0/P10/P20 and pull-model semantics
- reject inexact interpolation fallbacks instead of applying zero-slope hacks
- add numerical coverage for interpolation modes and vertex mappings
- sync with main
- implement specification-driven AMD and KHR barycentric interpolation
- handle topology, provoking vertex, centroid, sample, and pull-model inputs
- keep clip-plane and null-image descriptors valid
- expand GCN interpolation tests
Read FRONT_FACE_ALL_BITS from SPI_BARYC_CNTL and carry it through
fragment runtime specialization. Represent Vulkan FrontFacing as a
boolean IR attribute, then encode the guest VGPR value as either
+1.0/-1.0 or integer 1/0 according to the register mode.

Update shader cache versions and add regression tests for both
encodings.

Based on review suggestions from Roamic, Raphael, and
IndecisiveTurtle.
- restore direct P10/P20/P0 selection for V_INTERP_MOV_F32
- remove the incorrect P0-relative reconstruction that corrupted texture coordinates
- update LDS synchronization for loops with divergent Break or Repeat conditions
- defer unsafe loop-local barriers until workgroup invocations reconverge
- add interpolation and shared-memory barrier regression coverage
- update the stale KHR barycentric test to match current decoration behavior
Restored correct KHR fragment barycentric ordering based on primitive topology and provoking-vertex state, while leaving the AMD/VINTRP path unchanged.

Added mappings for triangle lists, fans, strips, and adjacency, including primitive-parity selection when required by Vulkan strip ordering.

Updated Vulkan capability detection and fragment runtime metadata to propagate topology and provoking-vertex information into SPIR-V generation.

Added regression tests for provoking-vertex rotation, unsupported host modes, and odd-strip PrimitiveId selection.

Updated shader serialization versions for the new metadata and generated SPIR-V behavior.

Based on IndecisiveTurtle's review suggestion and Vulkan/RADV barycentric semantics.
…32 and update front face handling in Translator
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.

6 participants