Skip to content

Fixed the grass rendering - #8

Merged
viktor-ferenczi merged 1 commit into
mainfrom
grass-fix
Aug 28, 2026
Merged

Fixed the grass rendering#8
viktor-ferenczi merged 1 commit into
mainfrom
grass-fix

Conversation

@viktor-ferenczi

Copy link
Copy Markdown
Contributor

Fixed the grass rendering (div by zero in shader).


  • Fixes the inverted grass LOD pattern in Space Engineers on the NVIDIA Vulkan driver (no grass near the player, grass beyond a sharp circular boundary), caused by undefined division-by-zero in shaders translated by DXVK's dxbc-spirv converter.
  • Root cause: DXBC defines unsigned division by zero as returning all bits set, but Converter::handleIntDivide emitted SPIR-V OpUDiv/OpUMod with the original, possibly-zero divisor and only corrected the result with a later OpSelect. SPIR-V leaves the zero-divisor operation itself undefined, and the undefined result leaked into the foliage skip logic (GetSkip in Foliage.hlsl).
  • Adds Patches/dxvk/0003-dxbc-spirv-select-nonzero-divisor.patch: selects a nonzero divisor (-1 when the divisor is zero) before emitting OpUDiv/OpUMod, keeping the existing result selection so DXBC semantics are unchanged while the SPIR-V is always defined.
  • Adds the same fix re-rooted onto vkd3d-proton's own vendored copy of the converter (Patches/vkd3d-proton/vkd3d-proton-dxbc-spirv-select-nonzero-divisor.patch), so SM ≤ 5 DXBC shaders reaching the SE2 D3D12 layer are covered too.
  • The fix lands in the shared DXBC converter rather than a game-shader or driver-specific workaround, so all DXBC shaders get defined division; both patches are documented in the series READMEs with provenance and should be dropped once upstream doitsujin/dxbc-spirv contains the fix and the pins catch up.
  • Verified with the dxbc-spirv converter test suite (199,608 checks, no failures) and in-game before/after comparison; the patched DXVK build is reproducible and ships byte-identically in both the SE1 and SE2 archives.

@viktor-ferenczi
viktor-ferenczi merged commit a7c1447 into main Aug 28, 2026
1 check passed
@viktor-ferenczi
viktor-ferenczi deleted the grass-fix branch August 28, 2026 21:13
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.

1 participant