mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:08:40 +00:00
Merges main at1154976d4into the integration branch at273b3bdf9(merge baseece4ba5b3). 42 files conflicted; this commit is the resolution only. Build and test repairs follow in their own commits. Rule of resolution: where both sides added different things, both stay; where both made the same change in two forms, main's reviewed form stays and whatever #984's form did in addition is carried into it; where the two changed the same code for different purposes, both purposes are kept. Xbox proxy code (runtime/shims/d3d12_xs_device.cpp, d3d12_xs_device.h, d3d12_xs.cpp, d3d12_xs_alloc_size.h, d3d12_xs_desc_clean.h, registry.cpp): - d3d12_xs_device.cpp is #984's file with main's differing pieces ported in: env_slot and the configurable device routes, XboxQueueSlotRoutes, PresentationHandler / set_presentation_handler, the console caller rule for device slots 61 and 74 (#383, #385), route_xbox_device_slot, slot 81 as GetFrameStatisticsX, create_host_device, the console-form rule for slots 25 and 56, the console list IID of #359, and the forms of queue slot 18 (#403) and list slot 139 (#396). - Kept from #984: the list proxy with handle translation, queue slots 16/17 as Signal/Wait, the fence's completed-value mirror, the shared FrameTokenSource, PresentX through queue_present_x when no handler is attached (slot 30, or 32 on a queue detected as the newer layout), slots 27/53/55/57/70/71/133, the wider pc_resource_desc, S_OK for queue slots past the PC table. - Dropped: #984's GetFrameEventsX and LEONIDA_XS_FRAME_EVENTS_SLOT, its second-word rule for slot 61, its undetected-layout rule for queue slot 18, its list IID mapping to GraphicsCommandList6; main's copy of the base list proxy, its null-view slot 70 and its refusing slot 133. Proxy tests (runtime/test/xs_proxy_mock_test.cpp, device_proxy_test.cpp, queue_proxy_test.cpp): - Checks of both sides, each run once; main's forms of the render-target size and layout checks with #984's extra cases added; main's --env-slots-74 and #984's --env-slots-70. - Adapted to the merged code: the queue tail answers S_OK, slot 73 answers an unknown IID with the list proxy, the queue slot 18 case installs a console caller. Dropped: #984's slot 81 GetFrameEventsX cases. D3D12/Vulkan layer (runtime/shims/d3d12_com.cpp, d3d12_vulkan_device.cpp, runtime/src/command_list.h, frame_pacer.h, shader_library.h, vulkan_backend.h, vulkan_replay.h, runtime/test/command_list_test.cpp, d3d12_close_parity_test.cpp, d3d12_execute_indirect_validation_test.cpp, replay_texture_barrier_test.cpp, vk_pipeline_check.cpp, vk_test_device.h): - Resource::create_texture: #984's title images (deferred placed, pending streamed, title pool) and main's ordinary textures (#1413 shared blocks, #1364 staging fallback) are exclusive branches chosen by the texture's origin, so both pools run on disjoint sets of textures. - frame_pacer.h is main's pacer (#402) with #984's FrameTokenSource as the token counter. - main's forms kept for ExecuteIndirect (#1066, #377), the barrier into LAYOUT_UNDEFINED (#1055), the B4G4R4A4 stand-in, per-face stencil masks, the unaligned tile staging (#528) and the device-lost flag (#980). - shader_library.h: main's block inflate; #984's `bulk` parameter now defaults to true so main's callers keep it. - Dropped: #984's B8G8R8A8 stand-in for B4G4R4A4 targets, its refusal of separate stencil masks, its zero-count refusal in ExecuteIndirect, its wider UNDEFINED -> UNDEFINED release and the test case for it. Other shims (runtime/shims/dstorage.cpp, file_system.cpp, gameinput.cpp, xgameruntime_offline.cpp, runtime/test/xgameruntime_offline_test.cpp, xmem_test.cpp): - ReadFile and DirectStorage reads: #984's pinned kernel_writes read, then main's touch_pages retry on ERROR_NOACCESS. main's rt::fs::read_file is folded into #984's read_file. - gameinput: main's strict LEONIDA_INPUT_SCRIPT parser with #984's rsup/rsdown entries. - Speech synthesis: main's one silent voice and handle checks; #984's accept-anything form dropped. Build, tools, docs (runtime/CMakeLists.txt, runtime/cmake/translator_deps.cmake, scripts/build_runtime.ps1, make_game.py, tools/rdna2spirv.py, shader_disasm.py, shader_ir.py, shader_library.py, runtime/test/shaders/cs_imgload_tfe.asm, cs_imgload_d16_tfe.asm, docs/README.md, boot.md, d3d12_vulkan.md, runtime/README.md): - Unions of the test, target and source lists; spirv_loop_guard.py added to translator_deps.cmake. - rdna2spirv.py: main's DPP compare rule (#957), SMEM vcc base (#647) and widen_wave64_masks (#1021); #984's restore_skipped_instructions and restore_dot4_inline_sel. #984's duplicate widen_wave64_valu_masks dropped. - shader_disasm.py and shader_ir.py: main's structure with #984's one-line-per-dword llvm-mc input and wave flags. - shader_library.py: main's structure with #984's --compute-hashes and per-state compute variants. One file that did not conflict is changed here: tools/rdna2_decode.py. Git kept both sides' decoders for a VOPC compare with a DPP operand, and #984's narrower one shadowed main's; it is main's file again. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
213 lines
9.3 KiB
Python
213 lines
9.3 KiB
Python
"""Folders outside the ANSI code page reach the native tools in a form they can open.
|
|
|
|
python -I tests/test_native_tool_paths.py
|
|
|
|
On Windows, spirv-as, spirv-val and the GPU test programs read their command line in the ANSI code page, so a folder
|
|
name with a character outside it (a Cyrillic or CJK user name, as under %TEMP%) reached them as '?'. Every shader then
|
|
failed with "file does not exist". The folders here use a private-use character, which no ANSI code page maps.
|
|
tools/rdna2spirv.py's assemble_spirv now runs the tools in the output folder with relative names; run_gpu_tests.py
|
|
uses the work folder's 8.3 short name, or stops with one error line when there is none. Standard library only; no
|
|
game files.
|
|
"""
|
|
import io
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.join(ROOT, "tools"))
|
|
sys.path.insert(0, os.path.join(ROOT, "scripts"))
|
|
|
|
import rdna2spirv # noqa: E402
|
|
import run_gpu_tests # noqa: E402
|
|
|
|
MARK = "\ue9c3"
|
|
MINIMAL_CS = """OpCapability Shader
|
|
OpMemoryModel Logical GLSL450
|
|
OpEntryPoint GLCompute %main "main"
|
|
OpExecutionMode %main LocalSize 1 1 1
|
|
%void = OpTypeVoid
|
|
%fn = OpTypeFunction %void
|
|
%main = OpFunction %void None %fn
|
|
%entry = OpLabel
|
|
OpReturn
|
|
OpFunctionEnd
|
|
"""
|
|
|
|
|
|
@unittest.skipUnless(shutil.which("spirv-as") and shutil.which("spirv-val"), "needs spirv-as and spirv-val")
|
|
class AssembleSpirv(unittest.TestCase):
|
|
def assemble(self, asm_dir, out_dir):
|
|
sa = os.path.join(asm_dir, "cs_min.spvasm")
|
|
sv = os.path.join(out_dir, "cs_min.spv")
|
|
with open(sa, "w", encoding="utf-8", newline="\n") as f:
|
|
f.write(MINIMAL_CS)
|
|
result = rdna2spirv.assemble_spirv(sa, sv)
|
|
self.assertEqual(result.returncode, 0, result.stderr + result.stdout)
|
|
with open(sv, "rb") as f:
|
|
self.assertEqual(f.read(4), b"\x03\x02\x23\x07") # the SPIR-V magic, little-endian
|
|
self.assertEqual([n for n in os.listdir(out_dir or ".") if n.endswith(".tmp")], [], "the staging file is removed")
|
|
|
|
@unittest.skipUnless(shutil.which("spirv-opt"), "needs spirv-opt")
|
|
def test_compact_binary_before_publish(self):
|
|
body = MINIMAL_CS.replace("%fn = OpTypeFunction", "%uint = OpTypeInt 32 0\n"
|
|
"%seven = OpConstant %uint 7\n%fn = OpTypeFunction")
|
|
body = body.replace("OpReturn", "%dead = OpIAdd %uint %seven %seven\nOpReturn")
|
|
with tempfile.TemporaryDirectory(prefix=MARK) as folder:
|
|
sa = os.path.join(folder, "input.spvasm")
|
|
sv = os.path.join(folder, "out.spv")
|
|
with open(sa, "w", encoding="utf-8", newline="\n") as f:
|
|
f.write(body)
|
|
for compact in (False, True):
|
|
result = rdna2spirv.assemble_spirv(sa, sv, compact=compact)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
if compact:
|
|
self.assertLess(os.path.getsize(sv), original_size)
|
|
else:
|
|
original_size = os.path.getsize(sv)
|
|
self.assertFalse(any(name.endswith(".tmp") for name in os.listdir(folder)))
|
|
|
|
def test_a_folder_outside_the_code_page(self):
|
|
# Before: spirv-as got '...\shaders-?\cs_min.spvasm' and failed with "file does not exist".
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
out = os.path.join(tmp, "shaders-" + MARK)
|
|
os.makedirs(out)
|
|
self.assemble(out, out)
|
|
|
|
def test_the_spvasm_in_another_folder(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
asm_dir, out = os.path.join(tmp, "asm-" + MARK), os.path.join(tmp, "spv")
|
|
os.makedirs(asm_dir)
|
|
os.makedirs(out)
|
|
self.assemble(asm_dir, out)
|
|
|
|
def test_a_relative_output_path(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
cwd = os.getcwd()
|
|
os.chdir(tmp)
|
|
try:
|
|
self.assemble("", "")
|
|
finally:
|
|
os.chdir(cwd)
|
|
|
|
|
|
class NativeFolder(unittest.TestCase):
|
|
def test_a_path_the_code_page_holds_is_kept(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
self.assertEqual(run_gpu_tests.native_folder(tmp, ansi="utf-8"), tmp)
|
|
|
|
def test_other_systems_keep_the_path(self):
|
|
with patch.object(run_gpu_tests.os, "name", "posix"):
|
|
self.assertEqual(run_gpu_tests.native_folder("/tmp/work-" + MARK), "/tmp/work-" + MARK)
|
|
|
|
def test_a_utf8_code_page_keeps_non_ascii_paths(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
work = os.path.join(tmp, "leonida_gpu_work_" + MARK)
|
|
os.makedirs(work)
|
|
self.assertEqual(run_gpu_tests.native_folder(work, ansi="utf-8"), work)
|
|
|
|
@unittest.skipUnless(os.name == "nt", "8.3 short names are a Windows thing")
|
|
def test_a_folder_outside_the_code_page_gets_its_short_name_or_none(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
work = os.path.join(tmp, "leonida_gpu_work_" + MARK)
|
|
os.makedirs(work)
|
|
native = run_gpu_tests.native_folder(work, ansi="cp1252")
|
|
if native is None:
|
|
self.skipTest("this volume keeps no 8.3 short names (the error path is tested below)")
|
|
native.encode("cp1252") # raises if the short name still has a character the code page lacks
|
|
self.assertNotIn(MARK, native)
|
|
self.assertTrue(os.path.samefile(native, work))
|
|
|
|
|
|
@unittest.skipUnless(os.name == "nt", "8.3 short names are a Windows thing")
|
|
class NativeFolderLookup(unittest.TestCase):
|
|
def test_a_failed_lookup_rejects_the_buffer_contents(self):
|
|
work, short = "C:\\work-" + MARK, r"C:\WORK~1"
|
|
|
|
def get_short_path(path, buf, size):
|
|
self.assertEqual(path, work)
|
|
buf.value = short
|
|
return 0
|
|
|
|
with patch("ctypes.windll.kernel32.GetShortPathNameW", side_effect=get_short_path) as lookup:
|
|
self.assertIsNone(run_gpu_tests.native_folder(work, ansi="ascii"))
|
|
lookup.assert_called_once()
|
|
|
|
def test_an_insufficient_buffer_rejects_the_buffer_contents(self):
|
|
work, short = "C:\\work-" + MARK, r"C:\WORK~1"
|
|
for extra in (0, 1):
|
|
with self.subTest(required_length_extra=extra):
|
|
def get_short_path(path, buf, size):
|
|
self.assertEqual(path, work)
|
|
self.assertEqual(size, len(buf))
|
|
buf.value = short
|
|
return size + extra
|
|
|
|
with patch("ctypes.windll.kernel32.GetShortPathNameW", side_effect=get_short_path) as lookup:
|
|
self.assertIsNone(run_gpu_tests.native_folder(work, ansi="ascii"))
|
|
lookup.assert_called_once()
|
|
|
|
def test_a_short_name_outside_the_code_page_is_rejected(self):
|
|
work = "C:\\work-" + MARK
|
|
|
|
def get_short_path(path, buf, size):
|
|
self.assertEqual(path, work)
|
|
buf.value = work
|
|
return len(work)
|
|
|
|
with patch("ctypes.windll.kernel32.GetShortPathNameW", side_effect=get_short_path) as lookup:
|
|
self.assertIsNone(run_gpu_tests.native_folder(work, ansi="ascii"))
|
|
lookup.assert_called_once()
|
|
|
|
def test_a_successful_short_name_lookup_is_kept(self):
|
|
work, short = "C:\\work-" + MARK, r"C:\WORK~1"
|
|
|
|
def get_short_path(path, buf, size):
|
|
self.assertEqual(path, work)
|
|
buf.value = short
|
|
return len(short)
|
|
|
|
with patch("ctypes.windll.kernel32.GetShortPathNameW", side_effect=get_short_path) as lookup:
|
|
self.assertEqual(run_gpu_tests.native_folder(work, ansi="ascii"), short)
|
|
lookup.assert_called_once()
|
|
|
|
|
|
class MainUsesTheNativeFolder(unittest.TestCase):
|
|
def run_main(self, native):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
build = os.path.join(tmp, "build")
|
|
os.makedirs(build)
|
|
ext = ".exe" if os.name == "nt" else ""
|
|
for name in {*run_gpu_tests.TEST_PROGRAMS, *run_gpu_tests.REQUIRED_TEST_PROGRAMS}:
|
|
open(os.path.join(build, name + ext), "wb").close()
|
|
work = os.path.join(tmp, "work-" + MARK)
|
|
seen = []
|
|
err = io.StringIO()
|
|
argv = ["run_gpu_tests.py", "--build", build, "--work", work]
|
|
with patch.object(sys, "argv", argv), patch("sys.stderr", err), patch("sys.stdout", io.StringIO()), \
|
|
patch.object(run_gpu_tests, "native_folder", return_value=native), \
|
|
patch.object(run_gpu_tests, "run_suite", side_effect=lambda a, w: seen.append(w) or 0):
|
|
code = run_gpu_tests.main()
|
|
self.assertTrue(os.path.isdir(work), "--work is created before its native spelling is asked for")
|
|
return code, seen, err.getvalue()
|
|
|
|
def test_the_suite_runs_in_the_native_spelling(self):
|
|
code, seen, _ = self.run_main(r"C:\WORK-1~1")
|
|
self.assertEqual(code, 0)
|
|
self.assertEqual(seen, [r"C:\WORK-1~1"])
|
|
|
|
def test_no_native_spelling_is_one_error_line(self):
|
|
code, seen, err = self.run_main(None)
|
|
self.assertEqual(code, 2)
|
|
self.assertEqual(seen, [], "nothing runs")
|
|
self.assertIn("outside this PC's ANSI code page", err)
|
|
self.assertIn("--work", err)
|
|
self.assertEqual(len(err.strip().splitlines()), 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|