fix(agc): apply the sampler LOD bias in the shader where the portability subset disables it #20030
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20030"
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?
Imported from boykopovar/AnyPS5. Originally posted by XIIYAZ on 2026-11-14T12:27:20Z.
What
On MoltenVK, a guest sampler's LOD bias is lost.
VK_KHR_portability_subsetreportssamplerMipLodBias = VK_FALSE, soVkSamplerCreateInfo::mipLodBiasmust be 0 there and the driver ignores any other value.agc_driver_image_sample_lod_bias_sum,agc_driver_image_sample_lod_clampandagc_driver_image_sample_lod_clamp_shader_laneread the wrong mip level as a result. The shader already has a path that applies a bias:PipelineSpecialization::SamplerLodBiasBasespecialization constants, today used only for biases beyondSamplerLodBiasShaderThreshold. Setting the threshold to 0 in an experiment made all three tests pass, which confirms the cause.When the device does not support sampler LOD bias, a non-zero bias now goes through that shader path, and the sampler is created with a bias of 0:
VulkanDevicereadssamplerMipLodBiasfrom the portability features it already queries. It setsSpirvTarget::samplerLodBiasandGraphics::Context::samplerLodBias; both default totrue, so devices without the portability subset are unchanged.DescriptorBindingBuilder::Preparespecializes the bias into the shader when the device drops it. It does this only for samplers the shader can bias: not queried for LOD, not adjusted, not paired with a cube image. Other samplers keep the existing behavior.Samplerwrites amipLodBiasof 0 when the device drops the bias.ShaderDeviceProfilerejects a target that claims sampler LOD bias on a portability device that disables it. Its source file getsVK_ENABLE_BETA_EXTENSIONS, likeVulkanDevice.cpp, for the portability struct.CacheKey. It is also added toRequestSerializer, which moves to version 58. Version 57 requests still read, withsamplerLodBias = true.RequestSerializerTestsandShaderMemorymove their version 57 expectations to 58 and cover reading version 57.Tested
Setup:
-DCMAKE_OSX_ARCHITECTURES=x86_64; tests run under RosettaANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1mainwith the open macOS build fixes appliedResults:
agc_driver_image_sample_lod_bias_sum,agc_driver_image_sample_lod_clampandagc_driver_image_sample_lod_clamp_shader_lanefail before this change and pass after it.agc_shader_sampler_limits,agc_shader_device_profile, theagc_shader_disk_cache*tests,agc_lod_stats,agc_driver_image_sample_*,request_serializer,agc_shader_memoryandagc_shader_memory_coherent_atomic_loads.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(layer from the same SDK), the LOD tests pass with noVUID-messages.ctest -R '^(agc|shader|job)'(1578 tests,-j 2) and compared it with the same run before this change. The three LOD tests are fixed and no test that passed before fails because of this change.agc_driver_scratch_poolandagc_driver_label_after_import_copyfailed in this run, but they fail the same way with this change taken out of the same tree, so they are not caused by it.I did not run this on lavapipe, AMD or NVIDIA. On those devices
samplerLodBiasstaystrue, so the generated shaders are the same as before; only the serialized request carries one more byte.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T14:32:44Z.
Review: COMMENTED
Reviewed — no blocking findings
This review could not inspect the prepared change or verify its behavior because the repository reader was unavailable in this session.
What I ran
No commands were run; the reader could not be invoked.
Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
The description, commits, diff, manifest, changed file contents, and test coverage were not read. Files reviewed: none; files excluded: all changed files (not determined).
To get this to a good state
Nothing is required.
Continued review (pass 2)
This continuation pass read the listed added lines and their immediate context at head
412ade641581ce86da96336125462735ad885ba3; it does not cover the full pull request, so a formal merge decision is not justified.What I ran
No commands or tests were run. I read the requested continuation lines from
VulkanDevice.cpp,ShaderDeviceProfile.cpp,Sampler.cpp,Context.hpp,CMakeLists.txt,ShaderMemory.cpp,CacheKey.hpp,RequestSerializer.cpp,DescriptorBindingBuilder.hpp,DescriptorBindingBuilder.cpp,Recompiler.cpp,Recompiler.hpp, andRequestSerializerTests.cpp, plus the corresponding diff hunks.VulkanDevice.cppwas read through the pinned repository reader because its full text was excluded from the review folder.Results
Findings
Blocking
None in the lines reviewed.
Non-blocking
None in the lines reviewed.
Not verified
The rest of the pull request and the earlier pass’s findings were not reviewed in this continuation. No build, test suite, or runtime behavior was verified.
To get this to a good state
Nothing is required for the lines reviewed. Optional points: none.
Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T01:37:46Z.
Review: COMMENTED
Tested on an Apple M4 alongside #16953, in four variants with the same tests and environment.
Setup: Apple M4, macOS 27.2, MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1, x86-64 build under Rosetta 2. This device reports
samplerMipLodBias = false(portability subset).Base and variants:
mainat939d3630ed, inRequestSerializer.cpp,RequestSerializerTests.cppandShaderMemory.cpp.0f4538fa02), but both PRs merge cleanly onto #16953's merge-base,27b8778d4f(2026-11-16).27b8778d4f, with no conflict resolved by hand:27b8778d4f27b8778d4fmerged with the #20030 head (412ade6415)edac4156bd)main.Tests: the 29 GPU tests that fail on
mainon this Mac, viactest --test-dir build -R '<those 29>' -V, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer. Three runs per variant. Each run loggedInsert instance layer "VK_LAYER_KHRONOS_validation"32 times (layer 1.4.363) and never the missing-layer message.agc_driver_image_sample_lod_bias_sumagc_driver_image_sample_lod_clampagc_driver_image_sample_lod_clamp_shader_laneVUID-VkSamplerCreateInfo-samplerMipLodBias-04467per runVUID-VkDeviceCreateInfo-sType-uniqueper run (Recorder test device, fixed separately in #21965)One of the 25 is timing-dependent here.
agc_driver_label_after_import_copyfails as "round N: a CPU read after the label that followed the copy found 64 of 262144 destination bytes not yet copied" on every variant, including the base:It is not a test either PR targets, and it fails on the base too. I'm listing it because #16953 fails it noticeably more often on this machine. I can't tell from these counts whether that comes from the change or from timing.
Not tested: Linux, Windows or another GPU.
Result for this PR: on a device without
samplerMipLodBias, the shader-side bias fixes all three LOD tests and removes everysamplerMipLodBias-04467validation error, with or without #16953. No other test in the set changes, apart from the timing-dependent label test above. #16953 alone changes none of the three LOD tests here, so on MoltenVK this PR is the one that fixes them.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T18:36:45Z.
Review: COMMENTED
When portability requires a Vulkan sampler bias of zero,
DescriptorBindingBuilder::Preparecan silently discard an in-range guest bias for a cube sampler, LOD query, or adjusted use. The branch description calls out these exclusions. The existing diagnostic for an above-threshold bias already detects the same unsupported uses. Could the portability path use that diagnostic when the bias must move into the shader, so an unsupported draw cannot quietly select a different mip level?Source review of
412ade6415. Currentmainconflicts with the shader binding and request-serialization changes. The MoltenVK execution evidence is from the author's run.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.