diff options
Diffstat (limited to 'make_game.py')
| -rw-r--r-- | make_game.py | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/make_game.py b/make_game.py index 03d93a2b8..f1af5a172 100644 --- a/make_game.py +++ b/make_game.py | |||
| @@ -1879,26 +1879,54 @@ def keep_recorded_fallback(flag: str, work: str) -> bool: | |||
| 1879 | return True | 1879 | return True |
| 1880 | 1880 | ||
| 1881 | 1881 | ||
| 1882 | def smallest_max_subgroup(vulkaninfo_text: str): | 1882 | def max_subgroup_decider(vulkaninfo_text: str): |
| 1883 | """The smallest maxSubgroupSize vulkaninfo reports over all devices (text or --json output), or None.""" | 1883 | """(size, device, left_out): the smallest maxSubgroupSize vulkaninfo reports (text or --json output), the name |
| 1884 | of the device that reports it (None when the output names no devices), and the names of the CPU devices left | ||
| 1885 | out. A CPU device (llvmpipe, lavapipe, SwiftShader) only counts when no other device is listed: the runtime | ||
| 1886 | ranks it below every GPU (runtime/src/vulkan_device_filter.h, tools/vk_subgroup_info.py device_rank), and | ||
| 1887 | llvmpipe's maxSubgroupSize of 8 would otherwise turn emulation on beside a GPU with native wave64. size is | ||
| 1888 | None when it can't be told.""" | ||
| 1884 | size = r'maxSubgroupSize"?\s*[=:]\s*(\d+)' | 1889 | size = r'maxSubgroupSize"?\s*[=:]\s*(\d+)' |
| 1885 | # A device's own name is the least indented one; deeper ones (VK_KHR_maintenance7's layered APIs, e.g. | 1890 | # A device's own name is the least indented one; deeper ones (VK_KHR_maintenance7's layered APIs, e.g. |
| 1886 | # MoltenVK's Metal device, in both the text and the --json output) belong to the device above them. | 1891 | # MoltenVK's Metal device, in both the text and the --json output) belong to the device above them. |
| 1887 | names = list(re.finditer(r'(?m)^([ \t]*)"?deviceName"?\s*[=:]', vulkaninfo_text)) | 1892 | names = list(re.finditer(r'(?m)^([ \t]*)"?deviceName"?\s*[=:]\s*"?([^"\n]*)', vulkaninfo_text)) |
| 1888 | depth = min((len(m.group(1)) for m in names), default=0) | 1893 | depth = min((len(m.group(1)) for m in names), default=0) |
| 1889 | starts = [m.start() for m in names if len(m.group(1)) == depth] | 1894 | devices = [m for m in names if len(m.group(1)) == depth] |
| 1890 | if not starts: | 1895 | if not devices: |
| 1891 | sizes = [int(n) for n in re.findall(size, vulkaninfo_text)] | 1896 | sizes = [int(n) for n in re.findall(size, vulkaninfo_text)] |
| 1892 | return min(sizes) if sizes else None | 1897 | return (min(sizes) if sizes else None), None, [] |
| 1898 | # deviceType sits beside deviceName in VkPhysicalDeviceProperties (just before it in the text output; the | ||
| 1899 | # --json output may order the keys differently), so each device takes the nearest one at the same depth. | ||
| 1900 | types = [(m.start(), m.group(2)) for m in | ||
| 1901 | re.finditer(r'(?m)^([ \t]*)"?deviceType"?\s*[=:]\s*"?([A-Z_0-9]+)', vulkaninfo_text) | ||
| 1902 | if len(m.group(1)) == depth] | ||
| 1903 | |||
| 1904 | def is_cpu(pos): | ||
| 1905 | if not types: | ||
| 1906 | return False | ||
| 1907 | kind = min(types, key=lambda t: abs(t[0] - pos))[1] | ||
| 1908 | return kind.endswith("TYPE_CPU") or kind == "4" | ||
| 1909 | |||
| 1893 | # One section per device (a 1.3 device can print the size twice, in two property structs): one value each, | 1910 | # One section per device (a 1.3 device can print the size twice, in two property structs): one value each, |
| 1894 | # and a device that prints none makes the answer unknown rather than being left out of the smallest. | 1911 | # and a device that prints none makes the answer unknown rather than being left out of the smallest. |
| 1895 | per_device = [] | 1912 | per_device = [] |
| 1896 | for a, b in zip(starts, starts[1:] + [len(vulkaninfo_text)]): | 1913 | ends = [m.start() for m in devices[1:]] + [len(vulkaninfo_text)] |
| 1897 | sizes = [int(n) for n in re.findall(size, vulkaninfo_text[a:b])] | 1914 | for m, end in zip(devices, ends): |
| 1898 | if not sizes: | 1915 | sizes = [int(n) for n in re.findall(size, vulkaninfo_text[m.start():end])] |
| 1899 | return None | 1916 | per_device.append((min(sizes) if sizes else None, m.group(2).strip().rstrip(","), is_cpu(m.start()))) |
| 1900 | per_device.append(min(sizes)) | 1917 | gpus = [d for d in per_device if not d[2]] |
| 1901 | return min(per_device) | 1918 | left_out = [d[1] for d in per_device if d[2]] if gpus else [] |
| 1919 | counted = gpus or per_device | ||
| 1920 | if any(d[0] is None for d in counted): | ||
| 1921 | return None, None, left_out | ||
| 1922 | smallest = min(counted, key=lambda d: d[0]) | ||
| 1923 | return smallest[0], smallest[1], left_out | ||
| 1924 | |||
| 1925 | |||
| 1926 | def smallest_max_subgroup(vulkaninfo_text: str): | ||
| 1927 | """The smallest maxSubgroupSize vulkaninfo reports (text or --json output), or None; CPU devices only count when | ||
| 1928 | no GPU is listed (max_subgroup_decider).""" | ||
| 1929 | return max_subgroup_decider(vulkaninfo_text)[0] | ||
| 1902 | 1930 | ||
| 1903 | 1931 | ||
| 1904 | def wave64_settings(mode: str, *, mesh_compute: bool = False) -> tuple[bool, bool]: | 1932 | def wave64_settings(mode: str, *, mesh_compute: bool = False) -> tuple[bool, bool]: |
| @@ -1906,7 +1934,8 @@ def wave64_settings(mode: str, *, mesh_compute: bool = False) -> tuple[bool, boo | |||
| 1906 | shader is only exact without it when the GPU gives it 64-wide subgroups; with it, it is exact on any subgroup | 1934 | shader is only exact without it when the GPU gives it 64-wide subgroups; with it, it is exact on any subgroup |
| 1907 | size, at the cost of a workgroup barrier per segment. "auto" keeps emulation off on native-wave64 RDNA1/2 | 1935 | size, at the cost of a workgroup barrier per segment. "auto" keeps emulation off on native-wave64 RDNA1/2 |
| 1908 | under the AMD Windows driver. Elsewhere it turns emulation on unless every Vulkan device reports | 1936 | under the AMD Windows driver. Elsewhere it turns emulation on unless every Vulkan device reports |
| 1909 | maxSubgroupSize >= 64 and the runtime probe does not rule out native wave64.""" | 1937 | maxSubgroupSize >= 64 and the runtime probe does not rule out native wave64; a CPU device (llvmpipe) only |
| 1938 | counts when no GPU is listed (max_subgroup_decider).""" | ||
| 1910 | if mode == "on": | 1939 | if mode == "on": |
| 1911 | return True, False | 1940 | return True, False |
| 1912 | if mode == "off": | 1941 | if mode == "off": |
| @@ -1927,24 +1956,28 @@ def wave64_settings(mode: str, *, mesh_compute: bool = False) -> tuple[bool, boo | |||
| 1927 | "(#857), so auto uses native wave64 and rebuilds emulated outputs (--wave64-emulate on to force emulation)") | 1956 | "(#857), so auto uses native wave64 and rebuilds emulated outputs (--wave64-emulate on to force emulation)") |
| 1928 | return False, False | 1957 | return False, False |
| 1929 | exe = shutil.which("vulkaninfo") | 1958 | exe = shutil.which("vulkaninfo") |
| 1930 | size = None | 1959 | size, decider, left_out = None, None, [] |
| 1931 | if exe: | 1960 | if exe: |
| 1932 | try: | 1961 | try: |
| 1933 | r = subprocess.run([exe], capture_output=True, text=True, errors="replace", timeout=120) | 1962 | r = subprocess.run([exe], capture_output=True, text=True, errors="replace", timeout=120) |
| 1934 | size = smallest_max_subgroup(r.stdout) | 1963 | size, decider, left_out = max_subgroup_decider(r.stdout) |
| 1935 | except (OSError, subprocess.SubprocessError): | 1964 | except (OSError, subprocess.SubprocessError): |
| 1936 | size = None | 1965 | size = None |
| 1966 | if left_out: | ||
| 1967 | log(f"shaders: left out of the wave64 choice, as the runtime never picks a CPU device beside a GPU: " | ||
| 1968 | f"{', '.join(left_out)}") | ||
| 1937 | if size is None: | 1969 | if size is None: |
| 1938 | log("shaders: couldn't read the GPU's subgroup size from vulkaninfo: wave64 emulation on " | 1970 | log("shaders: couldn't read the GPU's subgroup size from vulkaninfo: wave64 emulation on " |
| 1939 | "(exact on every GPU; --wave64-emulate off to skip it on a GPU with 64-wide subgroups)") | 1971 | "(exact on every GPU; --wave64-emulate off to skip it on a GPU with 64-wide subgroups)") |
| 1940 | return True, True | 1972 | return True, True |
| 1941 | on = size < 64 | 1973 | on = size < 64 |
| 1974 | by = f" ({decider})" if decider else "" | ||
| 1942 | if not on and native64 is False: | 1975 | if not on and native64 is False: |
| 1943 | stages = "compute" if compute_only else "both compute and mesh" | 1976 | stages = "compute" if compute_only else "both compute and mesh" |
| 1944 | log(f"shaders: smallest maximum subgroup size is {size}, but the Vulkan query found no 64-wide path for " | 1977 | log(f"shaders: smallest maximum subgroup size is {size}{by}, but the Vulkan query found no 64-wide path for " |
| 1945 | f"{stages} (fixed default size or required-size control): wave64 emulation on") | 1978 | f"{stages} (fixed default size or required-size control): wave64 emulation on") |
| 1946 | return True, True | 1979 | return True, True |
| 1947 | log(f"shaders: smallest maximum subgroup size is {size}: wave64 emulation {'on' if on else 'off'}") | 1980 | log(f"shaders: smallest maximum subgroup size is {size}{by}: wave64 emulation {'on' if on else 'off'}") |
| 1948 | return on, True | 1981 | return on, True |
| 1949 | 1982 | ||
| 1950 | 1983 | ||