mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:55:52 +01:00
[PR #38] d3d12: a static sampler is also keyed by the S# the console's compiler writes (it isn't bit-equal to the layer's) #91
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#91
Loading…
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/ubiquitarianism/leonida/pull/38
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:old-pr/4765📝 Commits (2)
afbd39ed3d12: a static sampler is also keyed by the S# the console's compiler writes5969148d3d12: the console static-sampler key drops the layer's NEVER mark; a clash is logged📊 Changes
2 files changed (+122 additions, -4 deletions)
View changed files
📝
runtime/shims/d3d12_vulkan_device.cpp(+67 -4)📝
runtime/test/d3d12_descriptor_test.cpp(+55 -0)📄 Description
Original description (mentions and
#Nreferences are disabled; the numbers refer to the old repository):New D3D item (claim).
The problem
A root signature's static sampler takes no root argument: the shader holds its S# by value, and the layer finds the Vulkan sampler by those four dwords in the hash table.
CreateRootSignatureregistered the S# under the layer's own encoding of the description (sampler_descriptor+gfx10::encode). The shader holds what the console's compiler baked in, which isn't bit-equal. So the lookup misses, and the shader samples through the fallback sampler.Measured (my 1.0.2.1 copy, counts and field names only)
None of the game's 26,503 containers carries an
RTS0(docs/d3d12_vulkan.mdalready says so). The one place where a static sampler and the literal S# that uses it can be compared directly isamd_fidelityfx_upscaler_xbox.dll. Its only sampling program builds its S# from immediates: all 10 sampling instructions use one literal, and its PSV0 sampler binding is space 0, register 0, which is the root signature's single static sampler. Every field that affects sampling matches. The words differ in four places:encode()DEPTH_COMPARE_FUNCComparisonFunc − 1= 3, though the filter doesn't compareMAX_LOD(MaxLOD = FLT_MAX)MIP_POINT_PRECLAMP(WORD2 bit 28)BORDER_COLOR_TYPE(no border address mode)The game's own literals follow the same conventions. All 27 distinct literal S# values (174,796 sampling instructions,
#4268's dataflow) have the pre-clamp bit set. A non-zero border type appears only together with the border address mode.On the compare field: in the game, all 15,155 sampling instructions whose literal S# has a non-zero
DEPTH_COMPARE_FUNCare_ccomparison ops, and none is a plain sample. The FidelityFX program is the exception: a copied compare function on a plainimage_sample_lz.The change
register_static_samplersalso binds that console form, through a newbind_sampler_keyed(key_words, words). The key is the console form; the Vulkan sampler is still made from the layer's encoding. This means a plain sample never gets a comparing sampler from the copied compare function. Decoding the console words directly would setcompareEnablefor a plain filter, which is undefined in Vulkan.CreateSampler/CreateSampler2) and the existing static-sampler key are unchanged. When the two forms are equal, nothing extra is bound.console_static_sampler_words, with the measurement in the comment. The copy also drops the layer-onlykCompareNevermark. When a comparison and a plain sampler with otherwise equal fields would share a console key, the first keeps it and the clash is logged.Tests (RTX 3060, driver 616.64, Windows 11, clang-cl)
d3d12_descriptor_testgets a case with the FidelityFX description (LINEAR, CLAMP, MaxAnisotropy 16, LESS_EQUAL, OPAQUE_WHITE, MaxLOD FLT_MAX). The expected console words are derived field by field from that description in the test's comment, and match what the compiler wrote. The key isn't in the table beforeCreateRootSignatureand is after it.line 999: sampler_index(console) != 0) and passes with it.d3d12_descriptor_testalso passes withLEONIDA_VK_VALIDATION=1(0 validation errors).d3d12_vulkan_device_test,d3d12_m2_textured_testandroot_signature_testpass.Limits
The four rules come from one direct pair plus the conventions of the game's 27 literals. A MaxLOD between 15.0 and 16.0 keeps the layer's clamp, because I have no measurement of what the compiler writes there. The FidelityFX literal reaches the index only once
#4604foldss_bfm_b32. After that,#2887's literal path registers it by decoding, and this key, made from the description, is the one without the compare bit.Thanks
@Kam471for the RTX 5070 Ti run (Blackwell).@Atomic258for the second Blackwell run.@paratustrafor the review that found the NEVER-comparison mark and the compare/plain key clash (both handled in a follow-up commit).@Ayinakifor the RTX 5070 run of the review fixes.@gertifyfor the RTX 4080 run and@memorypressurefor the static review of the merge with main.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.