"""Builders for the render decoder (segment type 0) and the render-side state objects: render pipelines (type 7, commandType 14 and 51), depth-stencil states (4), samplers (3), rasterization rate maps (50), fences (13), and the textures a render pass targets (docs/testing.md, sections 6.16, 6.18, 6.19). Layouts name the reims-vgpu-core module or item that reads them. """ import os import struct from . import abi from .abi import PAGE from .scenario import FIXTURES from .task import GPUTask, rec, seg # ---- serialized pipeline descriptors (section 6.18) ---- # Serialized on the host by fixtures/shaders/render_blobs.m (Metal's # -serializeRenderPipelineDescriptor: and the tile variant), with sentinel # function refs that pipeline_blob() replaces by object-list references. A # blob does not depend on which functions it names, only on their refs, so # one blob serves every vertex/fragment pair of the same shape. SENT_V, SENT_F, SENT_T = b"\xa1" * 4, b"\xb2" * 4, b"\xc3" * 4 BLOBS = { # vertex V, fragment F, colour[0] RGBA8Unorm "basic": "030804140000000104a1a1a1a10204b2b2b2b200010000000800000002000400000000010446000000", # the same, colour[0] blending: rgb = src * blendColor + dst, a = src * blendAlpha "blend": "030804140000000104a1a1a1a10204b2b2b2b20001000000080000000600040000000001044600000002040100000003040b00000004040100000006040d000000", # a vertex descriptor: attr 0 float2 @0, attr 1 uchar4normalized @8, buffer 0, stride 12 "vdesc": "0403041c0000000804800000000104a1a1a1a10204b2b2b2b20000000200041000000001043c000000000000020000000c000000190000000200040000000001041d00000003000401000000010409000000020408000000020000000c000000190000000200040000000003040c0000000200040000000003040c0000000000010000000800000002000400000000010446000000", # depth and stencil Depth32Float_Stencil8 (260) "depth": "050804200000000904040100000a04040100000104a1a1a1a10204b2b2b2b200010000000800000002000400000000010446000000", # rasterSampleCount 4 "msaa4": "0404040400000008041c0000000104a1a1a1a10204b2b2b2b2000000010000000800000002000400000000010446000000", # a vertex function alone: no fragment function, no colour attachment "nocolor": "010104a1a1a1a1", # the same, rasterSampleCount 4 "nocolor4": "020404040000000104a1a1a1a1", # colour[0] and colour[1] RGBA8Unorm "two": "030804140000000104a1a1a1a10204b2b2b2b200020000000c000000190000000200040000000001044600000002000401000000010446000000", # maxVertexAmplificationCount 2 "amp2": "0408041c0000001a04020000000104a1a1a1a10204b2b2b2b2000000010000000800000002000400000000010446000000", # tessellation: integer partitioning, triangle patches from render_tess "tess": "0408041c0000000c04010000000104a1a1a1a10204b2b2b2b2000000010000000800000002000400000000010446000000", # the same, with UInt16 control-point indices "tess_idx": "050804200000000c04010000001004010000000104a1a1a1a10204b2b2b2b200010000000800000002000400000000010446000000", # tile: function T, threadgroupSizeMatchesTileSize, colour[0] RGBA8Unorm "tile": "030404010000000304140000000104c3c3c3c300010000000800000002000400000000010446000000", } def pipeline_blob(name, v=None, f=None, t=None): """A serialized descriptor with its function sentinels replaced by object-list references (a function is its functionRef, section 6.18).""" b = bytes.fromhex(BLOBS[name]) for sent, ref in ((SENT_V, v), (SENT_F, f), (SENT_T, t)): if sent in b: assert ref is not None, "%s needs a function for %s" % (name, sent.hex()) b = b.replace(sent, struct.pack(" 8 throws.""" n = len(points) if count is None else count return rec(0x20, struct.pack(" max colour index throws.""" return rec(0x66, struct.pack(" maxViewportCount throws.""" return rec(0x76, struct.pack("= max colour index throws.""" return rec(0x96, struct.pack("= 20 bytes): {u64 task VA of the metallib, u32 its length, u32 commandType 15, u32 unread} (`resources::manager::create::function`).""" n = os.path.getsize(os.path.join(FIXTURES, fixture)) va = self.reserve(n) self.s.mem_file(self.gpa(va), fixture) # a task's VA pages are consecutive RAM pages return self.ol.add(abi.T_FUNCTION, struct.pack(" 7 * PAGE: self.reset_cmdbufs() cb = self.cmdbuf(seg(abi.ENC_RENDER, b"".join(records), cont_prev, cont_next)) res = [(r, 0) for r in (self.bufs if resources is None else resources)] return self.exec3([cb], resources=res, fault=fault, label=label, **kw) def exec3_cmd(self, records, resources=None, barriers=()): """Writes an exec (67) of one render segment into the root FIFO without ringing or waiting; returns its stamp. With barriers, the FIFO holds the command until those stamps arrive.""" if self._cmd > 7 * PAGE: self.reset_cmdbufs() va, n = self.cmdbuf(seg(abi.ENC_RENDER, b"".join(records))) res = [(r, 0) for r in (self.bufs if resources is None else resources)] p = struct.pack(" 6 * PAGE: self.reset_cmdbufs() cbs = [self.cmdbuf(sg) for sg in segments] res = [(r, 0) for r in (self.bufs if resources is None else resources)] return self.exec3(cbs, resources=res, fault=fault, label=label, **kw) def ratemap_record(w, h, layers, mutable=0, min_factor=0.0, command_type=50, raw_tail=None, count=None): """layers: [(horizontal samples, vertical samples)], each a list of f32 rates or a count of 1.0s. count overrides layerCount; raw_tail replaces everything after the layer headers.""" def rates(x): return [1.0] * x if isinstance(x, int) else list(x) n = len(layers) if count is None else count body = op_header(command_type) + struct.pack("