Repository navigation
nvn/vulkan: add software linear filtering fallback for formats without HW linear support - #436
Conversation
|
Thanks! Real bilinear instead of nearest where the format can't be filtered is the right fix, and the A few things before merging:
On the evidence: #461 describes the same tiles (64x64 R16G16B16A16_UNORM, Little Twin River, Dueling Peaks) as a sync bug that loses the water. Could you redo the phantom-water repro on the G925 with #461 applied, to show this is a separate bug? Logs or before/after screenshots would help. On the Adreno 830 here I'll check that no |
ab828a1 to
f92454e
Compare
…30 A/B + clock check, and 11-scene audit [skip ci]
|
Thanks for the thorough review. I have updated
|
|
Thanks, the REPEAT handling looks right and the redone repro on top of #461 is what I needed. Two small things before merging:
Minor: the lazy init in |
…t HW linear support When a sampled 2D or 2D-array texture format lacks hardware SAMPLED_IMAGE_FILTER_LINEAR support (e.g., VK_FORMAT_R16G16B16A16_UNORM / NVN 0x2a on Mali-G925), mamcjr#307's vk_sampler_nearest fallback smears shoreline texel heights across BOTW's cascading 64x64 water clipmap passes before GPU->CPU readback into Havok heightfields, causing a phantom physical and visual water volume near Dueling Peaks Stable. Emulate 1/256-quantized bilinear filtering in translated GLSL shaders via texelFetch (slinN / slinN_i / slinN_b) for active non-shadow, non-integer 2D / 2D_ARRAY slots requesting linear filtering, while preserving hardware linear filtering where supported, mamcjr#307's nearest fallback for other cases, and LARECOMP_NO_FILTER_FALLBACK=1. Also checks vk_sampled_format before fallback, disables anisotropy on nearest-fallback samplers, and guards copy_texture blits on vk_format_filters_linear. Validated on v0.4.3-beta (5946454) using SM-X730 (Mali-G925, Vulkan 1.3.278) and CPH2653 (Adreno 830, Vulkan 1.3.284), plus tools/test_soft_linear.py.
f92454e to
a106b0c
Compare
|
Thanks for the review — I have rebased
Re-verification (
|
…mamcjr#436/mamcjr#475 updated [skip ci]
|
Thanks, all three are done right: the fallback to the base program, the format in the memo, and |
|
Thanks! Tested on the POCO F7 Ultra (Adreno 830, Turnip) merged with #475 on current main: no "can't be filtered linearly" line, so the soft path stays off there, and the Plateau benchmark's GPU times match main's (23.0 / 22.9 ms vs 22.8 / 25.5 ms). The Mali side rests on your G925 runs. Merging. |




Summary
Adds a targeted shader-level software bilinear filtering fallback (
soft_linear) for sampled 2D and 2D-array textures whose sampledVkFormatlacksVK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BITon the host Vulkan GPU, while keeping native hardware linear filtering wherever supported, keeping zero draw-path overhead on GPUs with full linear filtering, keeping the nearest-sampler fallback (vk_sampler_nearest) from #307 for non-2D/shadow/integer cases, and preservingLARECOMP_NO_FILTER_FALLBACK=1.Root Cause
Commit from #307 (
vk_sampler_nearest) fixed black grass / sample hangs on GPUs that reject linear filtering on unsupported formats, but replaced bilinear filtering withVK_FILTER_NEARESTwhenever!vk_format_filters_linear(tfmt).On Arm Immortalis-G925 (Vulkan
1.3.278),VK_FORMAT_R16G16B16A16_UNORM(NVN 0x2a,VK_FORMAT 91) lacks hardwareSAMPLED_IMAGE_FILTER_LINEAR. During BOTW's cascading64x64water clipmap passes (which sample withwrap=1REPEATbefore GPU->CPU readback into Havok water heightfields), nearest-neighbor sampling smeared elevated river texels out across dry adjacent terrain instead of interpolating them down at the shoreline, producing a persistent phantom physical and visual water volume near Dueling Peaks Stable.Changes (rebased onto
main26da3fa, commita106b0c)runtime/nvn/maxwell/shader.h:soft_linear,soft_linear_mip,soft_linear_rep_u, andsoft_linear_rep_v(4 x uint64_tbitmasks,sizeof(ShaderKey) == 88) plusbool sampledonShaderTexture.runtime/nvn/maxwell/translate.c:slinN/slinN_i/slinN_bhelpers usingtexelFetchwith1/256sub-texel coordinate quantization.REPEAT(fract(uv)and% isz) whensoft_linear_rep_u/soft_linear_rep_vis set and[0, isz - 1]clamping otherwise.int il = 0directly withouttextureQueryLevels/textureQueryLodwhen!(soft_linear_mip & bit); when mipmapped (min_filter > 1), clamps/roundstextureQueryLod(...).x(on rawuv) againstmax(textureQueryLevels(tN) - 1, 0).runtime/nvn/vulkan/exec.c:stage_fill_soft_linear()handlingCLAMP/CLAMP_TO_EDGE(0,7) andREPEAT(1) per axis (skippingMIRROR*andCLAMP_TO_BORDER) for active non-shadow, non-integer 2D / 2D-array samplers requesting linear filtering.vkey/fkeyfromlast_progindraw_()before hashing so steady-state draws keep hittinglast_prog, falls back to the base program if asoft_linearvariant fails to compile (state == 2) indraw_()anddispatch_compute(), and hashes/matches all four masks inget_program()andcompute_program().tfmt(vk_sampled_format(rt, ...)behindrt && rt->backend) insidetexture_info()'s per-framememo[1024]slot and guardscopy_texture()vkCmdBlitImagelinear filter flag onvk_format_filters_linear().runtime/nvn/vulkan/textures.c&runtime/nvn/vulkan/vk.h:vk_format_is_int()and race-safeatomic_fetch_or_explicitlazy init invk_any_format_no_linear()(bit1= initialized, bit2= non-integer format lacks linear filtering; updated invk_format_filters_linear()if any non-integer format lacks linear support; respectsLARECOMP_NO_FILTER_FALLBACK), ensuring zero draw-path work or startup log noise when hardware linear filtering is available.make_sampler()wheng_force_nearestis active forvk_sampler_nearest().tools/test_soft_linear.py:glslcSPIR-V compilation acrossCLAMP/REPEATandmip/!mipcombinations,atomic_fetch_orrace safety,state == 2/memo[ms].tfmtinvariants, and numerical bilinear accuracy checks.Testing & Device Validation
a106b0con26da3fa):python -B tools/test_soft_linear.py:23wasm32 C tests +3Vulkan 1.1glslcSPIR-V compile checks +203numerical math checksPASS(rc=0).test_vulkan_compat.py(16),test_vulkan_startup.py(33),./gradlew :app:assembleDebug(JDK 17), andtools/test_android_runtime.ps1(6/6Bionic arm64 tests onSM-X730:test_kernel_affinity,test_bc_shadow,test_buffer_copy,test_nvn_lifetime,test_object_cache,test_benchmark_trace):PASS.SM-X730,Mali-G925,plateaubenchmark scene at30 fps, updateda106b0cbuild):status = "ok",30.0 fps(1% low 29.52,gpu.p50 27.101 ms,over_50ms = 0,0Vulkan/shader errors);[vk] format 91 can't be filtered linearlyand[vk] sampled format 91 (nvn 0x2a, 64x64) has no linear filtering hereactive; Great Plateau grass renders cleanly green without black or stretched blades.SM-X730,Mali-G925-Immortalis MC12,LARECOMP_NATIVE=1, Dueling Peaks Stable):#461(6f83821) alone (runA-461only.log):[vk] format 91 can't be filtered linearlyfires and the translucent phantom water box remains visible in the dry stable yard (30.0 fps,0errors).#461 + #436(6f83821 + f92454e) (runB-461plus436.log):[vk] format 91 can't be filtered linearlystill fires (93write-backs including8f0x2a,fbcopy 540 (breaks 0),30.0 fpsmax 35ms,0errors), and the dry stable yard renders cleanly with the phantom water volume eliminated.#4616f83821only)#4616f83821+#436f92454e)Known Limitations
TEXTYPE_2DandTEXTYPE_2D_ARRAYsampled textures usingCLAMP,CLAMP_TO_EDGE, orREPEATwrap modes;MIRROR*,CLAMP_TO_BORDER,1D,3D,CUBE, shadow (compare), and integer formats continue using#307vk_sampler_nearestwhen hardware linear filtering is unavailable.floor(clamp(lod, 0, ml) + 0.5f)) without cross-mip trilinear interpolation, and sub-texel weights are quantized to1/256steps.