"""Whole guest sessions: a small library of steps that compose into a guest driver's lifetime, for the interplay scenarios (scenarios/interplay_session.py). A Session is a Scenario plus what a macOS guest driver keeps between steps: the negotiated version, the kernel task (task 0) with its IOSurface backings and cursor glyphs, the display pages, the GPU tasks with their objects, the child FIFOs, and how many display callbacks of each kind the host has seen so far (the runner counts callbacks cumulatively, across displays and across a recreated device, so every wait names the running total). Every layout below is the one the per-area builders already restate; this module only composes them: - the root FIFO, child FIFOs and barriers: fifo.py - tasks, object lists, segments: task.py - render and compute objects: render_lib.py, compute_objects.py, exec_objects.py - heaps and heap buffers, blit records, deletions: resources_build.py - the display's shared page and opcodes 1-12: display_guest.py - EFI: efi_guest.py - the IOSurface host device: iosfc_guest.py - suspend and resume: rvg_device_will_suspend and the rest of the C API's migration calls, as scenarios/suspend.py drives them Nothing here is imported from the library's code. """ import struct from . import abi from . import render_lib as R from .abi import PAGE from .compute_objects import Compute as C, compute_blob, compute_pipeline_record from .display_guest import (SS_CURSOR_POS, SS_GUEST_CURSOR_SHOW, SS_MODE_COUNT, display, p_ack, p_glyph, p_present3, p_set_shared, p_show, p_swap, pattern) from .efi_guest import EFI from .exec_objects import pipeline_record, render_blob from .fifo import ChildFIFO from .iosfc_guest import CMD_MAP, CMD_TEST, CMD_UNMAP, IOSFC, desc_v2 from .resources_build import (BGRA8Unorm, OPT_SHARED, b_copy_buf_buf, b_copy_tex_buf, b_fill_buf, desc1, heap_buffer_rec, heap_rec, iosurface_op, mapper_ref_rec) from .scenario import SETUPS, Scenario from .task import GPUTask, seg # Operation IDs of opcode 40, the serialized delete (reims-vgpu-core's # resources::manager::cache, Deletion). DEL_RESOURCE, DEL_FUNCTION, DEL_COMPUTE_PSO, DEL_RENDER_PSO = 1000, 1005, 1006, 1007 # Each phase of GPU work writes 0x300 bytes of results into a task's out # buffer, at phase x PHASE: the blit's 0x100, the compute's 0x100, then the # render target read back through a blit (8 x 8 RGBA8). PHASE = 0x400 BLIT_OFF, COMPUTE_OFF, RENDER_OFF = 0x000, 0x100, 0x200 RESULT = 0x300 TW = TH = 8 # the render target FW, FH = 16, 8 # frames the displays show def u32s(*v): return struct.pack("<%dI" % len(v), *v) class SessionTask(GPUTask): """A GPU task holding what a guest app's session uses: a source buffer of its own pattern, an out buffer of 4 pages that each phase writes into, a private heap with a buffer placed in it, add_one's function and compute pipeline (fixtures/shaders/compute_add.metal), tri_vert and tri_frag's functions and render pipeline (vert.metal, frag.metal: one full-target triangle of (1, 0.5, 0.25, 1)), and an 8 x 8 RGBA8 render target over a shared buffer (type 8, commandType 9). Object references are handed out in that order, the same in every task.""" def __init__(self, s, tid, seed, pages=64): super().__init__(s, tid=tid, pages=pages) self.seed = seed self.shared = [] # every shared buffer: listed in each exec (section 6.12) self.src, self.src_va = self._buf(PAGE, bytes((i * 7 + seed) & 0xFF for i in range(0x100))) self.out, self.out_va = self._buf(4 * PAGE) self.heap_va = self.reserve(4 * PAGE) self.heap = self.ol.add(abi.T_HEAP, heap_rec(self.heap_va // PAGE, 4 * PAGE, 1)) self.hbuf = self.ol.add(abi.T_HEAP_BUFFER, heap_buffer_rec(self.heap, PAGE, PAGE)) self.f_add = self._function("shaders/compute_add.metallib") self.cpso = self.ol.add(abi.T_SERIALIZED, compute_pipeline_record(compute_blob(self.f_add))) self.f_vert = self._function("shaders/vert.metallib") self.f_frag = self._function("shaders/frag.metallib") self.rpso = self.ol.add(abi.T_SERIALIZED, pipeline_record(14, render_blob(self.f_vert, self.f_frag, 70))) self.tbuf, self.tbuf_va = self._buf(PAGE) self.tex = self.ol.add(abi.T_SERIALIZER_TEXTURE, R.op_header(9) + struct.pack( " 1: desc["port_count"] = ports if efi: desc["trace"] = True disp = [display(p, name="head%d" % p, modes=modes) for p in (range(ports) if displays is None else displays)] self.s = Scenario(name, setups=setups, host=host, watchdog_s=watchdog_s, displays=disp, descriptor=desc or None, iosfc=iosfc, exclusive=exclusive, doc=doc) self.n = {} # callbacks seen so far, by kind # A new process's callbacks count from 0 (Scenario.phase). self.s.on_phase(lambda: setattr(self, "n", {})) self.pages = {} # port -> shared page self.t0 = None self.tasks = [] self.children = {} self.backings = [] # (ref, va) in task 0 self.efi = None self.iosfc = None self.version = None # ---- callbacks ---- def expect(self, kind, n=1, label=None): """Waits until the host has called `kind` n more times.""" self.n[kind] = self.n.get(kind, 0) + n self.s.wait(cb=kind, cb_count=self.n[kind], label=label or "%s %d" % (kind, self.n[kind])) # ---- bring-up ---- def negotiate(self, asks=(0x100, 0x800000F0), version=abi.MAX_VERSION): """Version negotiation as a guest probes it: requests that the device answers with another version (above 0xf5 it offers 0xf5; a request with bit 31 set is ignored, set_binary_version), each read back with the port count and connection types, then the version the driver settles on.""" s = self.s for v in asks: s.w(abi.R_VERSION, v) s.r(abi.R_VERSION, "asked 0x%x" % v) s.w(abi.R_VERSION, version) s.r(abi.R_VERSION, "settled") s.r(abi.R_PORT_COUNT, "settled") s.r(abi.R_PORT_TYPES, "settled") self.version = version def root(self, fifo_pages=2): """Root page, root FIFO, enable (docs/testing.md, section 6.25 a).""" self.s.bring_up(version=None, fifo_pages=fifo_pages) self.s.submit(abi.OP_NOP, label="first NOP") def device_info(self, max_key=45): """GetDeviceInfo (58) {maxKey, maxCount, page} into a page filled with 0xa5 first.""" s = self.s page = s.alloc_page() s.fill(s.pa(page), 0x180, 0xA5) s.submit(abi.OP_GET_DEVICE_INFO, struct.pack("I", b"BGRA")[0], 1) + struct.pack("