Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ Use `--wave64-emulate on` to force emulation or `--wave64-emulate off` to force
Four fallback flags are forwarded to the translator the same way, saved next to the translated shaders, and changing
them translates them again: `--no-float-controls` (drop `SignedZeroInfNanPreserve`, for devices whose pipeline check
skips a shader without `shaderSignedZeroInfNanPreserveFloat32`; needs PR #664's translator flag), `--bary-fallback`
(read raw barycentrics from an interpolated input, for devices without `VK_KHR_fragment_shader_barycentric`),
(read raw barycentrics from an interpolated input; on by itself when the runtime's GPU lacks
`VK_KHR_fragment_shader_barycentric` with `geometryShader` or has a known `BaryCoordKHR` driver bug, unless
`LEONIDA_BARY_FALLBACK=0`),
`--texel-offset-fallback` (fold `image_sample*_o` offsets into the coordinate, for devices without
`VK_KHR_maintenance8`) and `--mesh-compute` (mesh shaders as compute, for devices without `VK_EXT_mesh_shader`;
on by itself on Intel's Windows Vulkan driver, whose native mesh draws crash, BUILD-2202, unless `--native-mesh`).
`VK_KHR_maintenance8`) and `--mesh-compute` (mesh shaders as compute; on by itself when the runtime's GPU has no
`VK_EXT_mesh_shader` / `meshShader` or uses Intel's Windows Vulkan driver, whose native mesh draws crash, BUILD-2202,
unless `--native-mesh`).
Each is documented in [docs/design.md](docs/design.md).

The build records which llvm-mc command and version produced the disassembly. Changing either, or reusing a work
Expand Down
4 changes: 2 additions & 2 deletions docs/design.md

Large diffs are not rendered by default.

60 changes: 45 additions & 15 deletions make_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,15 +2010,25 @@ def runtime_gpu_per_vertex():


def runtime_gpu_barycentric_fallback():
"""Whether the selected Vulkan GPU's driver has a known BaryCoordKHR bug (Mesa ANV, AMD Windows on gfx90c), or None
when it can't be told."""
"""Whether the selected Vulkan GPU needs --bary-fallback (no VK_KHR_fragment_shader_barycentric on a device with
geometryShader, or a known BaryCoordKHR bug on Mesa ANV / AMD Windows gfx90c), or None when it can't be told."""
try:
v = runtime_gpu_info().get("barycentric_fallback")
return v if isinstance(v, bool) else None
except (AttributeError, TypeError):
return None


def runtime_gpu_fragment_shader_barycentric():
"""Whether the selected Vulkan GPU exposes VK_KHR_fragment_shader_barycentric (fragmentShaderBarycentric), or None
when tools/vk_subgroup_info.py can't tell."""
try:
v = runtime_gpu_info().get("fragment_shader_barycentric")
return v if isinstance(v, bool) else None
except (AttributeError, TypeError):
return None


def barycentric_fallback_override():
"""LEONIDA_BARY_FALLBACK=1/0 forces the same barycentric path as the GPU test runner; None leaves it automatic."""
v = (os.environ.get("LEONIDA_BARY_FALLBACK") or "").strip().lower()
Expand All @@ -2033,6 +2043,16 @@ def barycentric_fallback_override():
VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS = 5


def runtime_gpu_mesh_shader():
"""Whether the GPU the runtime would use exposes VK_EXT_mesh_shader with meshShader, or None when
tools/vk_subgroup_info.py can't tell."""
try:
v = runtime_gpu_info().get("mesh_shader")
return v if isinstance(v, bool) else None
except (AttributeError, TypeError):
return None


def runtime_gpu_mesh_draws_crash():
"""True where the GPU the runtime would use is on Intel's Windows Vulkan driver with VK_EXT_mesh_shader: there
vkCmdDrawMeshTasksEXT crashes (0xC0000409 in igvk64.dll) for a mesh shader with a live push-constant load at
Expand All @@ -2042,8 +2062,8 @@ def runtime_gpu_mesh_draws_crash():
info = runtime_gpu_info()
if not info or "driver_id" not in info:
return None
return info.get("driver_id") == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS and \
info.get("mesh_in_supported_stages") is True
has_mesh = info.get("mesh_shader") if "mesh_shader" in info else info.get("mesh_in_supported_stages")
return info.get("driver_id") == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS and has_mesh is True


def runtime_gpu_max_push_constants():
Expand Down Expand Up @@ -3143,21 +3163,22 @@ def main() -> int:
"shaderSignedZeroInfNanPreserveFloat32 or shaderDenormPreserveFloat16")
ap.add_argument("--bary-fallback", action="store_true",
help="translate raw barycentric reads from an interpolated vec3 input (with a pass-through "
"geometry shader the runtime draws), for devices without "
"VK_KHR_fragment_shader_barycentric")
"geometry shader the runtime draws); on by itself when the runtime's GPU lacks "
"VK_KHR_fragment_shader_barycentric (with geometryShader) or has a known BaryCoordKHR "
"driver bug (Mesa ANV, AMD Windows on gfx90c)")
ap.add_argument("--texel-offset-fallback", action="store_true",
help="fold the run-time texel offset of image_sample*_o into the coordinate, for devices "
"without VK_KHR_maintenance8")
ap.add_argument("--f16-interp-fallback", action="store_true",
help="16-bit interpolation from decoded halves the vertex/mesh shader exports instead of "
"PerVertexKHR inputs; on by itself when the runtime's GPU can't use them (MoltenVK)")
ap.add_argument("--mesh-compute", action="store_true",
help="translate mesh shaders to compute shaders writing an output buffer, for devices "
"without VK_EXT_mesh_shader; on by itself on Intel's Windows Vulkan driver, whose mesh "
"draws crash on the corpus' mesh shaders (BUILD-2202)")
help="translate mesh shaders to compute shaders writing an output buffer; on by itself when "
"the runtime's GPU lacks VK_EXT_mesh_shader (meshShader) or uses Intel's Windows Vulkan "
"driver, whose mesh draws crash on the corpus' mesh shaders (BUILD-2202)")
ap.add_argument("--native-mesh", action="store_true",
help="keep native mesh shaders on Intel's Windows Vulkan driver instead of turning on "
"--mesh-compute (for a driver that fixes BUILD-2202's crash)")
help="keep native mesh shaders instead of turning on --mesh-compute automatically (for example "
"to translate for another GPU, or for an Intel Windows driver that fixes BUILD-2202)")
ap.add_argument("--pc-tail-ubo", action="store_true",
help="keep s0..s31 in 128 push-constant bytes and move heap/code base to a set-1 uniform "
"block; on by itself when the runtime's GPU reports maxPushConstantsSize below what "
Expand Down Expand Up @@ -3229,12 +3250,17 @@ def main() -> int:
log(f"{', '.join(WINDOWS_ONLY)}: left out, the cross-build needs {'; '.join(lacking)} "
"(or pass --runtime-build)")
if "shaders" in stages and not a.mesh_compute and not a.native_mesh:
mesh_shader = runtime_gpu_mesh_shader()
crash = runtime_gpu_mesh_draws_crash()
if crash:
if mesh_shader is False:
log("shaders: the GPU the runtime would use has no VK_EXT_mesh_shader (meshShader): "
"translating with --mesh-compute (--native-mesh keeps them native)")
a.mesh_compute = True
elif crash:
log("shaders: the GPU the runtime would use is on Intel's Windows Vulkan driver, whose mesh draws crash on "
"these mesh shaders (BUILD-2202): translating with --mesh-compute (--native-mesh keeps them native)")
a.mesh_compute = True
elif crash is None:
elif mesh_shader is None or crash is None:
a.mesh_compute = keep_recorded_fallback("--mesh-compute", work)
emulate, keep_emulated = (wave64_settings(a.wave64_emulate, mesh_compute=a.mesh_compute) if "shaders" in stages
else (False, a.wave64_emulate == "auto"))
Expand All @@ -3261,8 +3287,12 @@ def main() -> int:
else:
bary_fallback = runtime_gpu_barycentric_fallback()
if bary_fallback is True:
log("shaders: this GPU's driver has a known BaryCoordKHR bug (Mesa ANV, or AMD's Windows driver "
"on gfx90c): translating with --bary-fallback")
if runtime_gpu_fragment_shader_barycentric() is False:
log("shaders: the GPU the runtime would use has no VK_KHR_fragment_shader_barycentric "
"(fragmentShaderBarycentric): translating with --bary-fallback")
else:
log("shaders: this GPU's driver has a known BaryCoordKHR bug (Mesa ANV, or AMD's Windows "
"driver on gfx90c): translating with --bary-fallback")
a.bary_fallback = True
elif bary_fallback is None:
a.bary_fallback = keep_recorded_fallback("--bary-fallback", work)
Expand Down
3 changes: 2 additions & 1 deletion scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ def run_cmd(cmd: list[str], env: dict | None = None, gpu: bool = True, *,

def bary_fallback() -> bool:
"""LEONIDA_BARY_FALLBACK=1 (or 0): translate raw barycentrics to an ordinary vec3 input and draw it through
tools/bary_fallback_gs.py. Unset, it is on where tools/vk_subgroup_info.py reports a driver with a known
tools/bary_fallback_gs.py. Unset, it is on where tools/vk_subgroup_info.py reports no
VK_KHR_fragment_shader_barycentric with geometryShader (NVIDIA Pascal, ...) or a driver with a known
BaryCoordKHR bug: Mesa ANV (SHADER-925) and AMD's Windows driver on gfx90c iGPUs (#5933)."""
v = (os.environ.get("LEONIDA_BARY_FALLBACK") or "").strip().lower()
if v in ("1", "true", "yes", "on"):
Expand Down
1 change: 1 addition & 0 deletions tests/test_make_game_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def test_custom_jobs_forwarded_to_shaders(self):
patch("make_game.runtime_gpu_per_vertex", return_value=None), \
patch("make_game.runtime_gpu_barycentric_fallback", return_value=None), \
patch("make_game.runtime_gpu_max_push_constants", return_value=None), \
patch("make_game.runtime_gpu_mesh_shader", return_value=None), \
patch("make_game.runtime_gpu_mesh_draws_crash", return_value=None):
ret = make_game.main()
self.assertEqual(ret, 0)
Expand Down
Loading
Loading