mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-26 00:05:58 +03:00
[PR #1290] [MERGED] shader_recompiler: Move sampling parameter resolution to tracking pass and support more derivative types. #2037
Labels
No labels
Bloodborne
bug
contributor wanted
documentation
enhancement
frontend
good first issue
help wanted
linux
pull-request
question
release
verification progress
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/shadPS4#2037
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/shadps4-emu/shadPS4/pull/1290
Author: @squidbus
Created: 10/8/2024
Status: ✅ Merged
Merged: 10/10/2024
Merged by: @raphaelthegreat
Base:
main← Head:sampling📝 Commits (3)
418ceb2shader_recompiler: Move sampling parameter resolution to tracking pass and support more derivative types.7b04637shader_recompiler: Only track sampler sharp on sample instructions.106305bshader_recompiler: Fix Inst args size.📊 Changes
10 files changed (+333 additions, -267 deletions)
View changed files
📝
src/shader_recompiler/backend/spirv/emit_spirv_image.cpp(+17 -10)📝
src/shader_recompiler/backend/spirv/emit_spirv_instructions.h(+4 -2)📝
src/shader_recompiler/frontend/translate/vector_memory.cpp(+71 -113)📝
src/shader_recompiler/ir/ir_emitter.cpp(+26 -17)📝
src/shader_recompiler/ir/ir_emitter.h(+16 -10)📝
src/shader_recompiler/ir/opcodes.h(+1 -1)📝
src/shader_recompiler/ir/opcodes.inc(+6 -5)📝
src/shader_recompiler/ir/passes/resource_tracking_pass.cpp(+189 -107)📝
src/shader_recompiler/ir/reg.h(+2 -1)📝
src/shader_recompiler/ir/value.h(+1 -1)📄 Description
The current code for the
IMAGE_SAMPLEinstruction does not work with derivatives for non-2D images as the type is not known when the IR is emitted, and thus it cannot determine how many derivative parameters there are.Instead, we can emit a placeholder IR instruction with all of the addressing data, and then once the resource is known we can resolve all of the parameters using the type and replace it with the correct instruction.
With the emission of the exact sampling IR instruction moved to after the resource has been determined, non-2D image derivatives are now supported, and the parameter handling is cleaner since it no longer uses individual placeholder arguments that need to be resolved.
As part of this change I ended up needing to increase the max IR argument count to 6, in order to pass the full set of derivatives for the ImageGradient instruction. Technically you could probably pack one of the vectors in with the
lod_clamp, but it would make things a lot messier having to place thelod_clampat the right index depending on the derivative size, as well as unpack and pass the right data later on in SPIR-V. It is much cleaner if we can just have one more parameter slot to pass it in separately.I also changed the sample dref instructions to have a F32x4 return type, with the right component extracted in the IR for the result. Otherwise the typing would be inconsistent between the placeholder and replacement instructions, and in the initial IR the type would be wrong compared to what the code expects. Some of the other argument types have also been fixed up in the sampling instructions to match what they must be.
Tested in a few games. Fixes missing cube derivative support in some shaders in CUSA16429.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.