mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-30 06:32:27 +00:00
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1090c603ea | ||
|
|
245542efb4 | ||
|
|
f6bec97548 | ||
|
|
638673a173 | ||
|
|
7feebe38f6 | ||
|
|
00c270062b | ||
|
|
4389f74b2b | ||
|
|
0ab348cb5d | ||
|
|
46e7135f6c | ||
|
|
bff53517be | ||
|
|
6898077c20 | ||
|
|
49585b92b0 | ||
|
|
ab7863142e | ||
|
|
80fb4cc1f6 |
No files matched your search
@@ -26,6 +26,7 @@ remains unsupported.
|
||||
- `dxbc-accc` no longer classifies `DXIL` chunks whose bitcode payload starts with the `NOBC` header-only placeholder as executable DXIL (Track D prerequisite from ADR 0008 / `docs/roadmap.md`). `inspect_dxbc` and `bx_shader_inspect` still report the container's `dxil_chunk_size`, stage, and shader model, but leave `kind` as `Unknown` (or `AcccOnly` when paired with an `ACCC` chunk) instead of `Dxil` or `DualDxilAndAccc`, and `bx_shader_prepare_for_d3dmetal` returns `BX_SHADER_ERR_UNSUPPORTED` rather than passing a bitcode-less container through. Covered by synthetic `NOBC`, mixed-chunk, and bounds-safety unit tests in `dxbc-accc`; live CrossOver execution is unchanged.
|
||||
|
||||
### Added
|
||||
- `xgameruntime.dll` serves `XGameSaveGetContainerInfo` (slot 13) and `XGameSaveEnumerateContainerInfoByName` (slot 15) on `IXGameSaveImpl` (#667). `XGameSaveGetContainerInfo` reads container metadata without loading blob payloads and, when the named container does not exist, succeeds without invoking the callback (source rank 3 inference). `XGameSaveEnumerateContainerInfoByName` filters containers by name prefix (treating `nullptr` or empty prefix as all containers), sorts by name, and stops early when the callback returns `false`. `test_xgameruntime_saves` checks both slots through `QueryApiImpl`.
|
||||
- `xgameruntime.dll` serves `XAsyncRun`, `XTaskQueueCreateComposite`, `XTaskQueueGetPort` and `XTaskQueueDuplicateHandle` through `IXGameRuntimeCore` slots 6, 13, 14 and 15 (#666). `XAsyncRun` runs the title's work callback on the block's work port and completes the block with its result. A duplicated queue handle shares the queue, and only the last close shuts its lanes down. A composite queue forwards each port to the port it was made from, and an async block's completion returns through the queue the block named. A project-authorized target build uses these for its save-game work and exited when `XAsyncRun` was unimplemented. `test_xgameruntime` checks all four through `QueryApiImpl`.
|
||||
- `bx-cli report <log.jsonl>...` (#664, part 1): a run report per log (one log is one run) and a summary across runs. Per run: how it ended, the frames presented (a lower bound), every unimplemented call with its count, faults whose innermost frame is in a BetterXen module, and pipelines by kind. The summary counts clean runs and lists each blocker signature with the number of runs that hit it; blocker issues are titled with those signatures. `bx-cli run` now appends a `run_end` record to its log (exited with a status, timeout, signal or launch failure), which the report reads. A log without it has an unknown outcome and is never counted as clean.
|
||||
- `xgameruntime.dll` serves `XUserDuplicateHandle` through `IXUser` slot 3 (#680). A duplicate is a new handle to the one offline user; each handle is closed on its own, and `XUserCompare` returns 0 for any two valid handles of that user. A project-authorized target build duplicates its user handle after sign-in and waited when the slot was unimplemented. `test_xgameruntime` checks the slot through `QueryApiImpl`.
|
||||
@@ -89,6 +90,12 @@ remains unsupported.
|
||||
- `d3d12_xs.dll!D3D12ConfigureVirtualMemoryX` now decodes the Xbox virtual-memory configuration (`D3D12XBOX_VIRTUAL_MEMORY_CONFIGURATION`) alongside the existing `BXVM` contract. Layout and behaviour follow the authorized GDK documentation of the function and structure: no flags, a GPU page-table size in 4 MB units clamped to 33, a frame-buffer preserve size (0, -1 for the legacy size, or bytes clamped to 64 MiB), and two output addresses, the minimum always 2 GiB and the maximum 159.375 GiB at the default 5 pages. The call fails with `E_FAIL` once a D3D12 device exists. Call-site observation of a project-authorized target build agrees with the documented layout. Inferred, and marked as such: the maximum for other page-table sizes scales linearly (`max_estimated=1` in the log), and a page-table size of 0, an unreadable configuration or unwritable outputs fail with `E_INVALIDARG`. The host sizes no GPU page tables and keeps no cross-process frame buffer, so the path records both (`vmem_config_recorded`, `applied=0 recorded_only=1`), leaves the `BXVM` record and cached backing heap untouched, and still emits `BX_STUB_LOG`. `tests/conformance/test_d3d12_vmem_xbox/` checks the documented outputs, clamps and post-device `E_FAIL`, the refused cases, and that a cached `BXVM` backing heap survives.
|
||||
|
||||
### Fixed
|
||||
- **`d3d12_xs.dll`: an index or vertex binding at a title address without a host buffer no longer crashes the process.** A title binds index and vertex data by address in plain title memory, with no Direct3D resource behind it. The address reached D3DMetal unchanged and it read through a null buffer (`IASetIndexBuffer`). Such a binding is now left empty and logged as unimplemented (`IASetIndexBuffer(title memory without a host buffer)`, likewise `IASetVertexBuffers`); bindings inside resources BetterXen created are translated as before. Supplying the data is separate work. Test: `test_d3d12_unbacked_buffers` (13 checks; without the fix it dies with the same null read).
|
||||
- **`d3d12_xs.dll`: console-only DXGI formats and depth-stencil unordered-access views no longer end the process.** The Xbox Series `DXGI_FORMAT` enumeration has values the PC one lacks (116-120, 189, 190; GDK `d3d12_xs.h`). D3DMetal turns one into an invalid Metal pixel format and Metal aborts, which a target build's crash reporter then turned into either "exit status 5" or a stall with every thread stopped.
|
||||
- **Formats:** `console_formats.h` maps each to the nearest host format (a depth texture is created typeless, each view names the concrete format). The three `GetResourceAllocationInfo` forms, `CreatePlacedResource`, `CreateReservedResource`, the four view-creation methods, the committed-resource forms and the placed (X) resource and view forms translate before the host call.
|
||||
- **Depth-stencil unordered-access views** (allowed on the console, forbidden on PC): the descriptor gets a null view and the call is logged as unimplemented (`CreateUnorderedAccessView(depth-stencil resource)`).
|
||||
- **Limits:** sizes reported for a translated format are the host format's, `GetDesc` reports the host format, and pipeline-state formats are not translated yet.
|
||||
- **Test:** `test_d3d12_console_formats` (21 checks; without the fix the process dies at the first console-only format).
|
||||
- `bx_runtime_veh.dll` completes a `CLZERO` loop in one exception (#665). A title that zeroes memory with `clzero; add rax,0x40; cmp rax,<reg64>; jb` raised one illegal-instruction exception per 64 bytes under Rosetta 2, which stalled a project-authorized target build's frame loop for tens of seconds. When the trapped `CLZERO` is followed by exactly that form, the handler zeroes every remaining line below the limit and leaves `RAX` at the last one, so the title's own `add`/`cmp`/`jb` leaves the loop. The range is zeroed region by region and stops at memory that is not committed and writable, where the next `CLZERO` traps and faults as before. Other loop forms keep the per-instruction path. `test_veh_clzero_loop` checks the memory result and counts the exceptions; it fails on the old handler.
|
||||
- `d3d12_xs.dll` no longer turns `DeserializeGraphicsPipelineStateX`, `DeserializeComputePipelineStateX`, `CreateDerivedGraphicsPipelineStateX` or `CreateDerivedComputePipelineStateX` into null pipelines in null-render mode (`BX_NULL_RENDER=1`) (#669). All four calls now always return `E_NOTIMPL`, clear `*ppv` and log `pipeline_refused` without `; null pipeline returned`, so a title falls back to creating pipelines from shader containers instead of silently receiving null pipelines. `test_d3d12_serialized_pipelines` checks all four slots and their refusal log lines with `BX_NULL_RENDER=1` active alongside a control shader-container null pipeline.
|
||||
- `XCRDAPI.dll` Xbox DirectStorage fixes:
|
||||
|
||||
@@ -0,0 +1,620 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Experimental RDNA 2 (gfx1030) -> HLSL translator for straight-line console VS/PS pairs.
|
||||
|
||||
Input: the VS and PS of a console graphics pipeline, each either a raw GPU instruction blob
|
||||
(from a deserialized pipeline) or a console shader container (DXBC with an XBCH record).
|
||||
Output, in --out: <vs>_<ps>.vs.hlsl / .ps.hlsl, compiled .vs.dxil / .ps.dxil (when --dxc is
|
||||
given), and <vs>_<ps>.il, the input layout the shim creates the host pipeline with.
|
||||
|
||||
Model (inferences from the console compiler's listings and the target build's code; see the
|
||||
first-frame notes):
|
||||
* Code starts after a header of 12-byte `v_nop` + literal records (VOP3 word top half 0xD580).
|
||||
* VS user data: s[0:1] = vertex-buffer descriptor table (16-byte V#s), s2 = base vertex.
|
||||
Both stages: s8 = 32-bit pointer to root parameter 0's descriptor table (32-byte entries).
|
||||
* A buffer V# loaded from the root table is a constant buffer; an 8-dword T# is a texture.
|
||||
* PS v0:v1 are barycentrics; `v_interp_p1/p2 ... attrN.c` is attribute N, component c.
|
||||
* VS `exp paramN` pairs with PS `attrN`; `exp pos0` is the position.
|
||||
HLSL resources use register space 100 (+ root parameter index); the shim widens each title root
|
||||
signature with overlapping ranges in that space so table entry k is register k.
|
||||
|
||||
Only straight-line code with the instructions below is accepted; anything else fails loudly.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import zlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
LLVM_MC = os.environ.get("LLVM_MC", "/opt/homebrew/opt/llvm/bin/llvm-mc")
|
||||
|
||||
DXGI = {"R32_UINT": 42, "R32G32_UINT": 17, "R32G32B32_UINT": 7, "R32G32B32A32_UINT": 3,
|
||||
"R8G8B8A8_UNORM": 28, "R16G16_FLOAT": 34, "R16G16B16A16_FLOAT": 10, "R32G32_FLOAT": 16}
|
||||
TBUF_FMT = {"BUF_FMT_8_8_8_8_UNORM": ("R8G8B8A8_UNORM", 4, "float"),
|
||||
"BUF_FMT_16_16_FLOAT": ("R16G16_FLOAT", 2, "float"),
|
||||
"BUF_FMT_16_16_16_16_FLOAT": ("R16G16B16A16_FLOAT", 4, "float"),
|
||||
"BUF_FMT_32_32_FLOAT": ("R32G32_FLOAT", 2, "float")}
|
||||
|
||||
|
||||
class Unsupported(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def container_code(blob):
|
||||
"""The GPU code of one stage from a console shader container.
|
||||
|
||||
A container is a DXBC file whose DXIL part carries no bitcode; the console code is in an
|
||||
`XBCH` record: magic, version, compressed size (u64), uncompressed size (u64), then a zlib
|
||||
stream. It inflates to an `FSSM` block: a 16-byte header (magic, version, size), then
|
||||
offsets relative to the end of that header. One of the per-stage slots at 0x18..0x78 is not
|
||||
0xDEADBEEF filler and locates the stage record, whose first two u64 fields are the code
|
||||
offset and the code size. (Layout inferred from containers of a project-authorized build.)
|
||||
"""
|
||||
at = blob.find(b"XBCH")
|
||||
if at < 0:
|
||||
raise Unsupported("container has no XBCH record")
|
||||
csize, usize = struct.unpack_from("<QQ", blob, at + 8)
|
||||
fssm = zlib.decompress(blob[at + 24:at + 24 + csize])
|
||||
if len(fssm) != usize or fssm[:4] != b"FSSM":
|
||||
raise Unsupported("XBCH record does not inflate to an FSSM block")
|
||||
base = 16
|
||||
record = None
|
||||
for slot in range(0x18, 0x78, 8):
|
||||
(v,) = struct.unpack_from("<Q", fssm, slot)
|
||||
if v != 0xDEADBEEFDEADBEEF:
|
||||
record = base + v
|
||||
break
|
||||
if record is None:
|
||||
raise Unsupported("FSSM block has no stage record")
|
||||
code_off, code_size = struct.unpack_from("<QQ", fssm, record)
|
||||
code = fssm[base + code_off:base + code_off + code_size]
|
||||
if len(code) < 12 or struct.unpack_from("<I", code, 0)[0] >> 16 != 0xD580:
|
||||
raise Unsupported("stage code does not start with the expected header records")
|
||||
return code
|
||||
|
||||
|
||||
def code_words(blob):
|
||||
if blob[:4] == b"DXBC":
|
||||
blob = container_code(blob)
|
||||
off = 0
|
||||
while off + 12 <= len(blob) and struct.unpack_from("<I", blob, off)[0] >> 16 == 0xD580:
|
||||
off += 12
|
||||
return blob[off:]
|
||||
|
||||
|
||||
def disassemble(blob):
|
||||
body = code_words(blob)
|
||||
text = " ".join("0x%02x" % b for b in body)
|
||||
r = subprocess.run([LLVM_MC, "--disassemble", "-arch=amdgcn", "-mcpu=gfx1030"], input=text,
|
||||
capture_output=True, text=True)
|
||||
out = []
|
||||
for line in r.stdout.splitlines():
|
||||
line = line.split(";")[0].strip()
|
||||
if not line or line.startswith("."):
|
||||
continue
|
||||
out.append(line)
|
||||
if line == "s_endpgm":
|
||||
break
|
||||
if "s_endpgm" not in out:
|
||||
raise Unsupported("no s_endpgm in decoded code")
|
||||
return out
|
||||
|
||||
|
||||
def split_ops(rest):
|
||||
ops, depth, cur = [], 0, ""
|
||||
for ch in rest:
|
||||
if ch in "[(":
|
||||
depth += 1
|
||||
elif ch in "])":
|
||||
depth -= 1
|
||||
if ch == "," and depth == 0:
|
||||
ops.append(cur.strip())
|
||||
cur = ""
|
||||
else:
|
||||
cur += ch
|
||||
if cur.strip():
|
||||
ops.append(cur.strip())
|
||||
return ops
|
||||
|
||||
|
||||
def reg_range(op):
|
||||
m = re.fullmatch(r"([sv])\[(\d+):(\d+)\]", op)
|
||||
if m:
|
||||
return m.group(1), int(m.group(2)), int(m.group(3))
|
||||
m = re.fullmatch(r"([sv])(\d+)", op)
|
||||
if m:
|
||||
return m.group(1), int(m.group(2)), int(m.group(2))
|
||||
return None
|
||||
|
||||
|
||||
class Translator:
|
||||
def __init__(self, stage):
|
||||
self.stage = stage
|
||||
self.lines = []
|
||||
self.sprov = {} # sgpr -> provenance tuple
|
||||
self.cbs = set() # table indices used as constant buffers
|
||||
self.textures = set()
|
||||
self.inputs = [] # VS: (semantic index, fmt, slot, offset, ncomp, kind)
|
||||
self.attrs = set() # PS attribute indices read
|
||||
self.exports = {} # name -> list of 4 expressions
|
||||
self.used_v = set()
|
||||
self.used_s = set()
|
||||
self.written_v = set()
|
||||
self.fetch_call = False # VS: attributes arrive in v4.. from the vertex-fetch subroutine
|
||||
self.fetch_attrs = set() # attribute indices read that way
|
||||
self.nexp = 0
|
||||
self.ntmp = 0
|
||||
self.tmps = []
|
||||
|
||||
# ---- operands -------------------------------------------------------------
|
||||
def src(self, op, as_float=False):
|
||||
"""HLSL expression (uint) for a 32-bit source operand."""
|
||||
neg = False
|
||||
if op.startswith("-") and not re.fullmatch(r"-\d+(\.\d+)?", op):
|
||||
neg, op = True, op[1:]
|
||||
m = re.fullmatch(r"neg\((.+)\)", op)
|
||||
if m:
|
||||
neg, op = True, m.group(1)
|
||||
r = reg_range(op)
|
||||
if r and r[1] == r[2]:
|
||||
kind, n, _ = r
|
||||
(self.used_v if kind == "v" else self.used_s).add(n)
|
||||
if kind == "v" and self.fetch_call and n >= 4 and n not in self.written_v:
|
||||
self.fetch_attrs.add((n - 4) // 4)
|
||||
e = "%s%d" % (kind, n)
|
||||
elif re.fullmatch(r"-?\d+\.\d+", op):
|
||||
e = "asuint(%sf)" % op
|
||||
elif re.fullmatch(r"0x[0-9a-fA-F]+", op):
|
||||
e = "0x%xu" % int(op, 16)
|
||||
elif re.fullmatch(r"-?\d+", op):
|
||||
v = int(op)
|
||||
e = "%du" % (v & 0xFFFFFFFF)
|
||||
else:
|
||||
raise Unsupported("operand %r" % op)
|
||||
if neg:
|
||||
e = "(asuint(-asfloat(%s)))" % e
|
||||
return "asfloat(%s)" % e if as_float else e
|
||||
|
||||
def dst(self, op):
|
||||
r = reg_range(op)
|
||||
if not r or r[1] != r[2]:
|
||||
raise Unsupported("destination %r" % op)
|
||||
(self.used_v if r[0] == "v" else self.used_s).add(r[1])
|
||||
if r[0] == "v":
|
||||
self.written_v.add(r[1])
|
||||
return "%s%d" % (r[0], r[1])
|
||||
|
||||
def emit(self, s):
|
||||
self.lines.append(" " + s)
|
||||
|
||||
# ---- instructions -----------------------------------------------------------
|
||||
def run(self, insts):
|
||||
ignore = re.compile(r"^(s_waitcnt|s_clause|s_inst_prefetch|s_setprio|s_nop|s_wqm_b64|s_endpgm|v_nop)\b")
|
||||
for line in insts:
|
||||
if ignore.match(line):
|
||||
continue
|
||||
parts = line.split(None, 1)
|
||||
op, rest = parts[0], parts[1] if len(parts) > 1 else ""
|
||||
mods = ""
|
||||
ops = split_ops(rest)
|
||||
# modifiers after operands (e.g. "0 idxen offset:12", "dmask:0xf dim:...")
|
||||
handler = getattr(self, "i_" + op, None)
|
||||
if handler is None:
|
||||
raise Unsupported("instruction %r" % line)
|
||||
handler(ops, line)
|
||||
|
||||
def exec_write(self, ops):
|
||||
return ops and ops[0].startswith("exec")
|
||||
|
||||
def i_s_mov_b32(self, ops, line):
|
||||
if ops[0] == "m0":
|
||||
return
|
||||
r = reg_range(ops[0])
|
||||
s = reg_range(ops[1])
|
||||
if s and s[0] == "s":
|
||||
self.sprov[r[1]] = self.sprov.get(s[1], ("sgpr", s[1]))
|
||||
elif re.fullmatch(r"-?(0x[0-9a-fA-F]+|\d+)", ops[1]):
|
||||
self.sprov[r[1]] = ("imm", int(ops[1], 0) & 0xFFFFFFFF)
|
||||
else:
|
||||
self.sprov[r[1]] = ("unknown",)
|
||||
self.emit("%s = %s;" % (self.dst(ops[0]), self.src(ops[1])))
|
||||
|
||||
def i_s_swappc_b64(self, ops, line):
|
||||
# The call to the vertex-fetch subroutine the console runtime builds from the pipeline's
|
||||
# input layout: on return, input element k is in v[4+4k : 7+4k] (observed: three-element
|
||||
# layouts read v4..v15 in groups of four). The host input assembler does the fetch.
|
||||
if self.stage != "vs" or self.lines or ops != ["s[4:5]", "s[4:5]"]:
|
||||
raise Unsupported(line)
|
||||
self.fetch_call = True
|
||||
|
||||
def i_s_mov_b64(self, ops, line):
|
||||
if ops[0] == "exec" or ops[1] == "exec":
|
||||
return
|
||||
d = reg_range(ops[0])
|
||||
s = reg_range(ops[1])
|
||||
if s:
|
||||
self.sprov[d[1]] = self.sprov.get(s[1], ("sgpr", s[1]))
|
||||
self.sprov[d[1] + 1] = self.sprov.get(s[1] + 1, ("sgpr", s[1] + 1))
|
||||
else:
|
||||
v = int(ops[1], 0)
|
||||
self.sprov[d[1]] = ("imm", v & 0xFFFFFFFF)
|
||||
self.sprov[d[1] + 1] = ("imm", (v >> 32) & 0xFFFFFFFF)
|
||||
|
||||
def i_s_and_b64(self, ops, line):
|
||||
# `s_and_b64 exec, exec, s[n:n+1]` restores the execution mask saved before s_wqm_b64
|
||||
# (helper-pixel bookkeeping); it has no HLSL counterpart.
|
||||
if ops[0] != "exec" or ops[1] != "exec":
|
||||
raise Unsupported(line)
|
||||
|
||||
def i_s_movk_i32(self, ops, line):
|
||||
r = reg_range(ops[0])
|
||||
self.sprov[r[1]] = ("imm", int(ops[1], 0) & 0xFFFFFFFF)
|
||||
self.emit("%s = %du;" % (self.dst(ops[0]), int(ops[1], 0) & 0xFFFFFFFF))
|
||||
|
||||
def i_s_bfe_u32(self, ops, line):
|
||||
pass # masks the high half of a copied table pointer; provenance is unchanged
|
||||
|
||||
def table_of(self, base):
|
||||
b = reg_range(base)
|
||||
p = self.sprov.get(b[1], ("sgpr", b[1]))
|
||||
if p == ("sgpr", 0) and self.stage == "vs":
|
||||
return "vbtable"
|
||||
if p == ("sgpr", 8):
|
||||
return "root0"
|
||||
raise Unsupported("descriptor load from %r (provenance %r)" % (base, p))
|
||||
|
||||
def smem_load(self, ops, line, ndw):
|
||||
d = reg_range(ops[0])
|
||||
table = self.table_of(ops[1])
|
||||
off = 0 if ops[2] == "null" else int(ops[2], 0)
|
||||
if table == "vbtable":
|
||||
prov = ("vb", off // 16)
|
||||
elif ndw == 4:
|
||||
prov = ("cb", off // 32)
|
||||
elif ndw == 8:
|
||||
prov = ("tex", off // 32)
|
||||
else:
|
||||
raise Unsupported(line)
|
||||
for i in range(ndw):
|
||||
self.sprov[d[1] + i] = prov
|
||||
|
||||
def i_s_load_dwordx4(self, ops, line):
|
||||
self.smem_load(ops, line, 4)
|
||||
|
||||
def i_s_load_dwordx8(self, ops, line):
|
||||
self.smem_load(ops, line, 8)
|
||||
|
||||
def s_buffer_load(self, ops, line, ndw):
|
||||
d = reg_range(ops[0])
|
||||
desc = reg_range(ops[1])
|
||||
p = self.sprov.get(desc[1])
|
||||
if not p or p[0] != "cb":
|
||||
raise Unsupported("s_buffer_load from %r" % (p,))
|
||||
cb = p[1]
|
||||
self.cbs.add(cb)
|
||||
off = 0 if ops[2] == "null" else int(ops[2], 0)
|
||||
for i in range(ndw):
|
||||
word = off // 4 + i
|
||||
self.sprov[d[1] + i] = ("cbword", cb, word)
|
||||
self.emit("s%d = cb%d_word(%d);" % (d[1] + i, cb, word))
|
||||
self.used_s.add(d[1] + i)
|
||||
|
||||
def i_s_buffer_load_dword(self, ops, line):
|
||||
self.s_buffer_load(ops, line, 1)
|
||||
|
||||
def i_s_buffer_load_dwordx2(self, ops, line):
|
||||
self.s_buffer_load(ops, line, 2)
|
||||
|
||||
def i_s_buffer_load_dwordx4(self, ops, line):
|
||||
self.s_buffer_load(ops, line, 4)
|
||||
|
||||
def i_s_buffer_load_dwordx8(self, ops, line):
|
||||
self.s_buffer_load(ops, line, 8)
|
||||
|
||||
def i_s_buffer_load_dwordx16(self, ops, line):
|
||||
self.s_buffer_load(ops, line, 16)
|
||||
|
||||
# vertex fetch -> input layout element
|
||||
def vb_slot(self, op):
|
||||
p = self.sprov.get(reg_range(op)[1])
|
||||
if not p or p[0] != "vb":
|
||||
raise Unsupported("vertex fetch through %r" % (p,))
|
||||
return p[1]
|
||||
|
||||
def fetch(self, ops, line, ncomp, fmt, kind):
|
||||
if "idxen" not in line or "offen" in line:
|
||||
raise Unsupported(line)
|
||||
d = reg_range(ops[0])
|
||||
p = self.sprov.get(reg_range(ops[2])[1])
|
||||
if p and p[0] == "cb" and "offset:" not in line:
|
||||
# An indexed load from a buffer bound through the root table: element i is 16 bytes.
|
||||
cb = p[1]
|
||||
self.cbs.add(cb)
|
||||
idx = self.src(ops[1])
|
||||
for i in range(d[2] - d[1] + 1):
|
||||
self.emit("t%d_%d = cb%d[%s].%s;" % (self.ntmp, i, cb, idx, "xyzw"[i]))
|
||||
for i in range(d[2] - d[1] + 1):
|
||||
self.emit("%s = t%d_%d;" % (self.dst("v%d" % (d[1] + i)), self.ntmp, i))
|
||||
self.tmps.append((self.ntmp, d[2] - d[1] + 1))
|
||||
self.ntmp += 1
|
||||
return
|
||||
slot = self.vb_slot(ops[2])
|
||||
m = re.search(r"offset:(\d+)", line)
|
||||
off = int(m.group(1)) if m else 0
|
||||
sem = len(self.inputs)
|
||||
self.inputs.append((sem, fmt, slot, off, ncomp, kind))
|
||||
comps = "xyzw"
|
||||
for i in range(d[2] - d[1] + 1):
|
||||
src = "in%d.%s" % (sem, comps[i])
|
||||
self.emit("v%d = %s;" % (d[1] + i, "asuint(%s)" % src if kind == "float" else src))
|
||||
self.used_v.add(d[1] + i)
|
||||
|
||||
def i_buffer_load_dword(self, ops, line):
|
||||
self.fetch(ops, line, 1, "R32_UINT", "uint")
|
||||
|
||||
def i_buffer_load_dwordx2(self, ops, line):
|
||||
self.fetch(ops, line, 2, "R32G32_UINT", "uint")
|
||||
|
||||
def i_buffer_load_dwordx3(self, ops, line):
|
||||
self.fetch(ops, line, 3, "R32G32B32_UINT", "uint")
|
||||
|
||||
def i_buffer_load_dwordx4(self, ops, line):
|
||||
self.fetch(ops, line, 4, "R32G32B32A32_UINT", "uint")
|
||||
|
||||
def i_tbuffer_load_format_xyzw(self, ops, line):
|
||||
m = re.search(r"format:\[(\w+)\]", line)
|
||||
if not m or m.group(1) not in TBUF_FMT:
|
||||
raise Unsupported(line)
|
||||
fmt, n, kind = TBUF_FMT[m.group(1)]
|
||||
self.fetch(ops, line, 4, fmt, kind)
|
||||
|
||||
# ALU
|
||||
def vop2f(self, ops, expr):
|
||||
a, b = self.src(ops[1], True), self.src(ops[2], True)
|
||||
self.emit("%s = asuint(%s);" % (self.dst(ops[0]), expr % (a, b)))
|
||||
|
||||
def i_v_mul_f32_e32(self, ops, line):
|
||||
self.vop2f(ops, "%s * %s")
|
||||
|
||||
i_v_mul_f32_e64 = i_v_mul_f32_e32
|
||||
|
||||
def i_v_add_f32_e32(self, ops, line):
|
||||
self.vop2f(ops, "%s + %s")
|
||||
|
||||
i_v_add_f32_e64 = i_v_add_f32_e32
|
||||
|
||||
def i_v_sub_f32_e32(self, ops, line):
|
||||
self.vop2f(ops, "%s - %s")
|
||||
|
||||
def i_v_max_f32_e32(self, ops, line):
|
||||
self.vop2f(ops, "max(%s, %s)")
|
||||
|
||||
def i_v_min_f32_e32(self, ops, line):
|
||||
self.vop2f(ops, "min(%s, %s)")
|
||||
|
||||
def i_v_fmac_f32_e32(self, ops, line):
|
||||
d = self.dst(ops[0])
|
||||
self.emit("%s = asuint(mad(%s, %s, asfloat(%s)));" % (d, self.src(ops[1], True), self.src(ops[2], True), d))
|
||||
|
||||
def i_v_cvt_i32_f32_e32(self, ops, line):
|
||||
self.emit("%s = (uint)(int)%s;" % (self.dst(ops[0]), self.src(ops[1], True)))
|
||||
|
||||
def i_v_med3_f32(self, ops, line):
|
||||
a, b, c = (self.src(o, True) for o in ops[1:4])
|
||||
self.emit("%s = asuint(max(min(%s, %s), min(max(%s, %s), %s)));" % (self.dst(ops[0]), a, b, a, b, c))
|
||||
|
||||
def i_v_mul_legacy_f32_e32(self, ops, line):
|
||||
a, b = self.src(ops[1], True), self.src(ops[2], True)
|
||||
self.emit("%s = asuint((%s == 0.0f || %s == 0.0f) ? 0.0f : %s * %s);" % (self.dst(ops[0]), a, b, a, b))
|
||||
|
||||
i_v_mul_legacy_f32_e64 = i_v_mul_legacy_f32_e32
|
||||
|
||||
def i_v_cvt_pkrtz_f16_f32_e32(self, ops, line):
|
||||
a, b = self.src(ops[1], True), self.src(ops[2], True)
|
||||
self.emit("%s = f32tof16(%s) | (f32tof16(%s) << 16);" % (self.dst(ops[0]), a, b))
|
||||
|
||||
i_v_cvt_pkrtz_f16_f32_e64 = i_v_cvt_pkrtz_f16_f32_e32
|
||||
|
||||
def i_v_interp_mov_f32_e32(self, ops, line):
|
||||
m = re.fullmatch(r"attr(\d+)\.([xyzw])", ops[2])
|
||||
if not m:
|
||||
raise Unsupported(line)
|
||||
n = int(m.group(1))
|
||||
self.attrs.add(n)
|
||||
self.emit("%s = asuint(attr%d.%s);" % (self.dst(ops[0]), n, m.group(2)))
|
||||
|
||||
def i_v_fma_f32(self, ops, line):
|
||||
self.emit("%s = asuint(mad(%s, %s, %s));" % (self.dst(ops[0]), self.src(ops[1], True),
|
||||
self.src(ops[2], True), self.src(ops[3], True)))
|
||||
|
||||
def i_v_mov_b32_e32(self, ops, line):
|
||||
self.emit("%s = %s;" % (self.dst(ops[0]), self.src(ops[1])))
|
||||
|
||||
def i_v_add_nc_u32_e32(self, ops, line):
|
||||
# only the vertex-index computation uses it here; the index itself is the IA's job
|
||||
if self.stage == "vs":
|
||||
return
|
||||
self.emit("%s = %s + %s;" % (self.dst(ops[0]), self.src(ops[1]), self.src(ops[2])))
|
||||
|
||||
def fma_mix(self, ops, line, hi):
|
||||
m = re.search(r"op_sel_hi:\[(\d),(\d),(\d)\]", line)
|
||||
if "op_sel:" in line or not m:
|
||||
raise Unsupported(line)
|
||||
srcs = []
|
||||
for i, sel in enumerate(m.groups()):
|
||||
o = ops[1 + i].split()[0]
|
||||
neg = False
|
||||
mm = re.fullmatch(r"neg\((.+)\)", o)
|
||||
if mm:
|
||||
neg, o = True, mm.group(1)
|
||||
e = self.src(o)
|
||||
f = "f16tof32(%s & 0xffffu)" % e if sel == "1" else "asfloat(%s)" % e
|
||||
srcs.append("(-%s)" % f if neg else f)
|
||||
d = self.dst(ops[0])
|
||||
val = "f32tof16(mad(%s, %s, %s))" % tuple(srcs)
|
||||
if hi:
|
||||
self.emit("%s = (%s & 0xffffu) | (%s << 16);" % (d, d, val))
|
||||
else:
|
||||
self.emit("%s = (%s & 0xffff0000u) | %s;" % (d, d, val))
|
||||
|
||||
def i_v_fma_mixlo_f16(self, ops, line):
|
||||
self.fma_mix(ops, line, False)
|
||||
|
||||
def i_v_fma_mixhi_f16(self, ops, line):
|
||||
self.fma_mix(ops, line, True)
|
||||
|
||||
# PS interpolation
|
||||
def i_v_interp_p1_f32_e32(self, ops, line):
|
||||
pass
|
||||
|
||||
def i_v_interp_p2_f32_e32(self, ops, line):
|
||||
m = re.fullmatch(r"attr(\d+)\.([xyzw])", ops[2])
|
||||
if not m:
|
||||
raise Unsupported(line)
|
||||
n = int(m.group(1))
|
||||
self.attrs.add(n)
|
||||
self.emit("%s = asuint(attr%d.%s);" % (self.dst(ops[0]), n, m.group(2)))
|
||||
|
||||
def i_image_sample(self, ops, line):
|
||||
d = reg_range(ops[0])
|
||||
c = reg_range(ops[1])
|
||||
t = self.sprov.get(reg_range(ops[2])[1])
|
||||
if not t or t[0] != "tex" or "dim:SQ_RSRC_IMG_2D" not in line or "dmask:0xf" not in line:
|
||||
raise Unsupported(line)
|
||||
self.textures.add(t[1])
|
||||
self.used_v.update([c[1], c[1] + 1])
|
||||
self.emit("{ float4 r = tex%d.Sample(smp0, float2(asfloat(v%d), asfloat(v%d)));" % (t[1], c[1], c[1] + 1))
|
||||
for i in range(4):
|
||||
self.emit(" v%d = asuint(r.%s);" % (d[1] + i, "xyzw"[i]))
|
||||
self.used_v.add(d[1] + i)
|
||||
self.emit("}")
|
||||
|
||||
def i_exp(self, ops, line):
|
||||
target = ops[0]
|
||||
vals = [o.split()[0] for o in ops[1:5]]
|
||||
compr = " compr" in line
|
||||
if compr:
|
||||
a, b = self.src(vals[0]), self.src(vals[2])
|
||||
ex = ["f16tof32(%s & 0xffffu)" % a, "f16tof32(%s >> 16)" % a,
|
||||
"f16tof32(%s & 0xffffu)" % b, "f16tof32(%s >> 16)" % b]
|
||||
else:
|
||||
ex = ["0.0f" if v == "off" else self.src(v, True) for v in vals]
|
||||
# registers are reused after an export: take the values now
|
||||
name = "exp%d_%s" % (self.nexp, target)
|
||||
self.nexp += 1
|
||||
self.emit("float4 %s = float4(%s);" % (name, ", ".join(ex)))
|
||||
self.exports[target] = ["%s.%s" % (name, c) for c in "xyzw"]
|
||||
|
||||
# ---- output -----------------------------------------------------------------
|
||||
def resources(self):
|
||||
out = []
|
||||
for cb in sorted(self.cbs):
|
||||
out.append("cbuffer CB%d : register(b%d, space100) { uint4 cb%d[4096]; };" % (cb, cb, cb))
|
||||
out.append("uint cb%d_word(uint w) { return cb%d[w >> 2][w & 3]; }" % (cb, cb))
|
||||
for t in sorted(self.textures):
|
||||
out.append("Texture2D<float4> tex%d : register(t%d, space100);" % (t, t))
|
||||
if self.textures:
|
||||
out.append("SamplerState smp0 : register(s0, space100);")
|
||||
return out
|
||||
|
||||
def regs(self):
|
||||
decl = []
|
||||
for n in sorted(self.used_v):
|
||||
k = (n - 4) // 4
|
||||
if self.fetch_call and n >= 4 and k in self.fetch_attrs:
|
||||
decl.append("uint v%d = asuint(a%d.%s);" % (n, k, "xyzw"[(n - 4) % 4]))
|
||||
else:
|
||||
decl.append("uint v%d = 0;" % n)
|
||||
decl += ["uint s%d = 0;" % n for n in sorted(self.used_s)]
|
||||
for n, count in self.tmps:
|
||||
decl += ["uint t%d_%d = 0;" % (n, i) for i in range(count)]
|
||||
return [" " + d for d in decl]
|
||||
|
||||
|
||||
def build_vs(t):
|
||||
ins = ["float4 a%d : ATTR%d" % (k, k) for k in sorted(t.fetch_attrs)]
|
||||
for sem, fmt, slot, off, n, kind in t.inputs:
|
||||
ty = ("float%d" if kind == "float" else "uint%d") % n if n > 1 else ("float" if kind == "float" else "uint")
|
||||
ins.append("%s in%d : ATTR%d" % (ty, sem, sem))
|
||||
params = sorted(k for k in t.exports if k.startswith("param"))
|
||||
outs = ["float4 pos : SV_Position"] + ["float4 %s : PARAM%s" % (p, p[5:]) for p in params]
|
||||
src = t.resources()
|
||||
src.append("struct VSOut { %s; };" % "; ".join(outs))
|
||||
src.append("VSOut main(%s) {" % ", ".join(ins))
|
||||
src += t.regs() + t.lines
|
||||
src.append(" VSOut o;")
|
||||
pos = t.exports.get("pos0")
|
||||
if not pos:
|
||||
raise Unsupported("VS exports no position")
|
||||
src.append(" o.pos = float4(%s);" % ", ".join(pos))
|
||||
for p in params:
|
||||
src.append(" o.%s = float4(%s);" % (p, ", ".join(t.exports[p])))
|
||||
src.append(" return o;\n}")
|
||||
return "\n".join(src) + "\n", params
|
||||
|
||||
|
||||
def build_ps(t, vs_params):
|
||||
for a in t.attrs:
|
||||
if "param%d" % a not in vs_params:
|
||||
raise Unsupported("PS reads attr%d that the VS does not export" % a)
|
||||
ins = ["float4 pos : SV_Position"] + ["float4 attr%s : PARAM%s" % (p[5:], p[5:]) for p in vs_params]
|
||||
if "mrt0" not in t.exports:
|
||||
raise Unsupported("PS exports no mrt0")
|
||||
src = t.resources()
|
||||
src.append("float4 main(%s) : SV_Target0 {" % ", ".join(ins))
|
||||
src += t.regs() + t.lines
|
||||
src.append(" return float4(%s);\n}" % ", ".join(t.exports["mrt0"]))
|
||||
return "\n".join(src) + "\n"
|
||||
|
||||
|
||||
def fnv1a(data):
|
||||
h = 1469598103934665603
|
||||
for b in data:
|
||||
h = ((h ^ b) * 1099511628211) & 0xFFFFFFFFFFFFFFFF
|
||||
return "%016x" % h
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("vs")
|
||||
ap.add_argument("ps")
|
||||
ap.add_argument("--out", required=True)
|
||||
ap.add_argument("--dxc", help="command prefix that runs a Windows dxc.exe (e.g. a wine wrapper)")
|
||||
a = ap.parse_args()
|
||||
vsb, psb = open(a.vs, "rb").read(), open(a.ps, "rb").read()
|
||||
key = "%s_%s" % (fnv1a(vsb), fnv1a(psb))
|
||||
vt, pt = Translator("vs"), Translator("ps")
|
||||
vt.run(disassemble(vsb))
|
||||
pt.run(disassemble(psb))
|
||||
vs_src, params = build_vs(vt)
|
||||
ps_src = build_ps(pt, params)
|
||||
os.makedirs(a.out, exist_ok=True)
|
||||
base = os.path.join(a.out, key)
|
||||
open(base + ".vs.hlsl", "w").write(vs_src)
|
||||
open(base + ".ps.hlsl", "w").write(ps_src)
|
||||
with open(base + ".il", "w") as f:
|
||||
if vt.fetch_call:
|
||||
f.write("FETCH %d\n" % (max(vt.fetch_attrs) + 1 if vt.fetch_attrs else 0))
|
||||
for sem, fmt, slot, off, n, kind in vt.inputs:
|
||||
f.write("ATTR %d %d %d %d\n" % (sem, DXGI[fmt], slot, off))
|
||||
for cb in sorted(vt.cbs | pt.cbs):
|
||||
f.write("USE CB %d\n" % cb)
|
||||
for tex in sorted(vt.textures | pt.textures):
|
||||
f.write("USE TEX %d\n" % tex)
|
||||
if a.dxc:
|
||||
for st, prof in (("vs", "vs_6_0"), ("ps", "ps_6_0")):
|
||||
cmd = a.dxc.split() + ["-T", prof, "-E", "main", "-Fo", base + ".%s.dxil" % st, base + ".%s.hlsl" % st]
|
||||
r = subprocess.run(cmd, capture_output=True, text=True)
|
||||
err = "\n".join(l for l in (r.stdout + r.stderr).splitlines() if "fixme" not in l)
|
||||
if r.returncode or not os.path.exists(base + ".%s.dxil" % st):
|
||||
sys.exit("dxc failed for %s:\n%s" % (st, err))
|
||||
print(key)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except Unsupported as e:
|
||||
sys.exit("unsupported: %s" % e)
|
||||
@@ -10,7 +10,9 @@ bx_add_shim_dll(d3d12_xs d3d12_xs d3d12_xs.def
|
||||
placed_x.cpp
|
||||
descriptor_heaps.cpp
|
||||
committed.cpp
|
||||
console_formats.cpp
|
||||
pipelines.cpp
|
||||
console_translate.cpp
|
||||
gpu_writes.cpp
|
||||
fences.cpp
|
||||
presentx_xbox.cpp
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
#include "xbox_facade.h"
|
||||
|
||||
#include "console_formats.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
extern "C" __declspec(dllimport) PVOID WINAPI XMemAlloc(SIZE_T size, ULONGLONG attributes);
|
||||
@@ -57,6 +59,10 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource(void* self, c
|
||||
D3D12_RESOURCE_STATES state, const D3D12_CLEAR_VALUE* clear,
|
||||
REFIID riid, void** ppv) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateCommittedResource");
|
||||
BxHostFormat<D3D12_RESOURCE_DESC> host_desc;
|
||||
BxHostFormat<D3D12_CLEAR_VALUE> host_clear;
|
||||
desc = host_desc.of_resource(desc, "CreateCommittedResource");
|
||||
clear = host_clear.of(clear, "CreateCommittedResource");
|
||||
auto* device = bx_xbox_host<ID3D12Device>(self);
|
||||
return finish(device, device->CreateCommittedResource(heap, flags, desc, state, clear, riid, ppv), riid, ppv,
|
||||
"CreateCommittedResource");
|
||||
@@ -68,6 +74,10 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource1(void* self,
|
||||
ID3D12ProtectedResourceSession* session, REFIID riid,
|
||||
void** ppv) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateCommittedResource1");
|
||||
BxHostFormat<D3D12_RESOURCE_DESC> host_desc;
|
||||
BxHostFormat<D3D12_CLEAR_VALUE> host_clear;
|
||||
desc = host_desc.of_resource(desc, "CreateCommittedResource1");
|
||||
clear = host_clear.of(clear, "CreateCommittedResource1");
|
||||
auto* device = bx_xbox_host<ID3D12Device4>(self);
|
||||
return finish(device, device->CreateCommittedResource1(heap, flags, desc, state, clear, bx_xbox_unwrap_as(session), riid, ppv),
|
||||
riid, ppv, "CreateCommittedResource1");
|
||||
@@ -79,6 +89,10 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource2(void* self,
|
||||
ID3D12ProtectedResourceSession* session, REFIID riid,
|
||||
void** ppv) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateCommittedResource2");
|
||||
BxHostFormat<D3D12_RESOURCE_DESC1> host_desc;
|
||||
BxHostFormat<D3D12_CLEAR_VALUE> host_clear;
|
||||
desc = host_desc.of_resource(desc, "CreateCommittedResource2");
|
||||
clear = host_clear.of(clear, "CreateCommittedResource2");
|
||||
auto* device = bx_xbox_host<ID3D12Device8>(self);
|
||||
return finish(device, device->CreateCommittedResource2(heap, flags, desc, state, clear, bx_xbox_unwrap_as(session), riid, ppv),
|
||||
riid, ppv, "CreateCommittedResource2");
|
||||
@@ -90,6 +104,10 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource3(void* self,
|
||||
ID3D12ProtectedResourceSession* session, UINT32 formats,
|
||||
DXGI_FORMAT* castable, REFIID riid, void** ppv) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateCommittedResource3");
|
||||
BxHostFormat<D3D12_RESOURCE_DESC1> host_desc;
|
||||
BxHostFormat<D3D12_CLEAR_VALUE> host_clear;
|
||||
desc = host_desc.of_resource(desc, "CreateCommittedResource3");
|
||||
clear = host_clear.of(clear, "CreateCommittedResource3");
|
||||
auto* device = bx_xbox_host<ID3D12Device10>(self);
|
||||
return finish(device,
|
||||
device->CreateCommittedResource3(heap, flags, desc, layout, clear, bx_xbox_unwrap_as(session), formats,
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Console-only DXGI formats and console-only view combinations: the Xbox-layout device entry
|
||||
* points that carry a format to the host and are otherwise plain forwarders. See
|
||||
* console_formats.h for the formats and the reason.
|
||||
*
|
||||
* Covered here: the three GetResourceAllocationInfo forms, CreatePlacedResource,
|
||||
* CreateReservedResource and the four view-creation methods. Committed resources and the placed
|
||||
* (X) resources and views translate in committed.cpp and placed_x.cpp. Pipeline-state formats are
|
||||
* not translated yet: no console pipeline is created on the host so far.
|
||||
*/
|
||||
#include "console_formats.h"
|
||||
|
||||
#include "xbox_facade.h"
|
||||
#include "console_translate.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
void bx_note_console_format(DXGI_FORMAT format, const char* where) {
|
||||
static std::atomic<uint32_t> noted{0}; // one bit per console-only format
|
||||
const int f = static_cast<int>(format);
|
||||
const uint32_t bit = 1u << (f >= 189 ? f - 189 + 8 : f - 116);
|
||||
if (noted.fetch_or(bit) & bit) return;
|
||||
char detail[200];
|
||||
std::snprintf(detail, sizeof(detail),
|
||||
"console-only format %d is translated for the host (view and clear format %d, resource format %d; first seen in %s)",
|
||||
f, static_cast<int>(bx_host_format(format)), static_cast<int>(bx_host_resource_format(format)), where);
|
||||
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "console_format", detail);
|
||||
}
|
||||
|
||||
/* The console allows D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL together with ALLOW_UNORDERED_ACCESS,
|
||||
* and a title writes the depth plane from a compute shader through an R32_FLOAT unordered-access
|
||||
* view. PC Direct3D 12 forbids the combination. D3DMetal accepts the resource, answers the view
|
||||
* with a Metal texture view that Metal refuses ("texture view pixelFormat
|
||||
* (MTLPixelFormatDepth32Float) not castable"), and Metal aborts the process.
|
||||
*
|
||||
* Until that write path is emulated, such a descriptor gets a null view of the same description
|
||||
* (Direct3D 12 defines it: reads return zero, writes are discarded) and the call is logged as
|
||||
* unimplemented, so the gap is visible in every run report instead of ending the process. */
|
||||
void bx_xbox_create_host_uav(ID3D12Device* device, ID3D12Resource* host, ID3D12Resource* counter,
|
||||
const D3D12_UNORDERED_ACCESS_VIEW_DESC* desc, D3D12_CPU_DESCRIPTOR_HANDLE host_dest,
|
||||
const char* method) {
|
||||
BxHostFormat<D3D12_UNORDERED_ACCESS_VIEW_DESC> translated;
|
||||
desc = translated.of(desc, method);
|
||||
if (host && (host->GetDesc().Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) {
|
||||
BX_STUB_LOG("d3d12_xs.dll", "CreateUnorderedAccessView(depth-stencil resource)");
|
||||
// A null view needs a description; without one the descriptor is left as it was.
|
||||
if (desc) device->CreateUnorderedAccessView(nullptr, nullptr, desc, host_dest);
|
||||
return;
|
||||
}
|
||||
device->CreateUnorderedAccessView(host, counter, desc, host_dest);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/* An array of resource descriptions as the host must see it. */
|
||||
template <typename Desc>
|
||||
class HostDescs {
|
||||
public:
|
||||
HostDescs(const Desc* in, UINT count, const char* where) : descs_(in) {
|
||||
if (!in) return;
|
||||
for (UINT i = 0; i < count; ++i) {
|
||||
if (!bx_is_console_only_format(in[i].Format)) continue;
|
||||
if (copy_.empty()) copy_.assign(in, in + count);
|
||||
bx_note_console_format(in[i].Format, where);
|
||||
copy_[i].Format = bx_host_resource_format(in[i].Format);
|
||||
}
|
||||
if (!copy_.empty()) descs_ = copy_.data();
|
||||
}
|
||||
const Desc* get() const { return descs_; }
|
||||
|
||||
private:
|
||||
const Desc* descs_;
|
||||
std::vector<Desc> copy_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE bx_xbox_device_get_resource_allocation_info(void* self, UINT mask, UINT count,
|
||||
const D3D12_RESOURCE_DESC* descs) {
|
||||
BX_D3D_TRACE("XboxDevice", "GetResourceAllocationInfo");
|
||||
const HostDescs<D3D12_RESOURCE_DESC> host(descs, count, "GetResourceAllocationInfo");
|
||||
D3D12_RESOURCE_ALLOCATION_INFO result{};
|
||||
bx_xbox_host<ID3D12Device>(self)->GetResourceAllocationInfo(&result, mask, count, host.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE bx_xbox_device_get_resource_allocation_info1(
|
||||
void* self, UINT mask, UINT count, const D3D12_RESOURCE_DESC* descs, D3D12_RESOURCE_ALLOCATION_INFO1* each) {
|
||||
BX_D3D_TRACE("XboxDevice", "GetResourceAllocationInfo1");
|
||||
const HostDescs<D3D12_RESOURCE_DESC> host(descs, count, "GetResourceAllocationInfo1");
|
||||
D3D12_RESOURCE_ALLOCATION_INFO result{};
|
||||
bx_xbox_host<ID3D12Device4>(self)->GetResourceAllocationInfo1(&result, mask, count, host.get(), each);
|
||||
return result;
|
||||
}
|
||||
|
||||
D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE bx_xbox_device_get_resource_allocation_info2(
|
||||
void* self, UINT mask, UINT count, const D3D12_RESOURCE_DESC1* descs, D3D12_RESOURCE_ALLOCATION_INFO1* each) {
|
||||
BX_D3D_TRACE("XboxDevice", "GetResourceAllocationInfo2");
|
||||
const HostDescs<D3D12_RESOURCE_DESC1> host(descs, count, "GetResourceAllocationInfo2");
|
||||
D3D12_RESOURCE_ALLOCATION_INFO result{};
|
||||
bx_xbox_host<ID3D12Device8>(self)->GetResourceAllocationInfo2(&result, mask, count, host.get(), each);
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_placed_resource(void* self, ID3D12Heap* heap, UINT64 offset,
|
||||
const D3D12_RESOURCE_DESC* desc, D3D12_RESOURCE_STATES state,
|
||||
const D3D12_CLEAR_VALUE* clear, REFIID riid, void** ppv) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreatePlacedResource");
|
||||
BxHostFormat<D3D12_RESOURCE_DESC> host_desc;
|
||||
BxHostFormat<D3D12_CLEAR_VALUE> host_clear;
|
||||
HRESULT hr = bx_xbox_host<ID3D12Device>(self)->CreatePlacedResource(
|
||||
bx_xbox_unwrap_as<ID3D12Heap>(heap), offset, host_desc.of_resource(desc, "CreatePlacedResource"), state,
|
||||
host_clear.of(clear, "CreatePlacedResource"), riid, ppv);
|
||||
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreatePlacedResource", hr);
|
||||
return bx_xbox_wrap_result(hr, riid, ppv);
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_reserved_resource(void* self, const D3D12_RESOURCE_DESC* desc,
|
||||
D3D12_RESOURCE_STATES state, const D3D12_CLEAR_VALUE* clear,
|
||||
REFIID riid, void** ppv) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateReservedResource");
|
||||
BxHostFormat<D3D12_RESOURCE_DESC> host_desc;
|
||||
BxHostFormat<D3D12_CLEAR_VALUE> host_clear;
|
||||
HRESULT hr = bx_xbox_host<ID3D12Device>(self)->CreateReservedResource(
|
||||
host_desc.of_resource(desc, "CreateReservedResource"), state, host_clear.of(clear, "CreateReservedResource"), riid, ppv);
|
||||
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreateReservedResource", hr);
|
||||
return bx_xbox_wrap_result(hr, riid, ppv);
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_shader_resource_view(void* self, ID3D12Resource* resource,
|
||||
const D3D12_SHADER_RESOURCE_VIEW_DESC* desc,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dest) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateShaderResourceView");
|
||||
BxHostFormat<D3D12_SHADER_RESOURCE_VIEW_DESC> host;
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateShaderResourceView(bx_xbox_unwrap_as<ID3D12Resource>(resource),
|
||||
host.of(desc, "CreateShaderResourceView"),
|
||||
bx_xbox_host_cpu_handle(dest));
|
||||
bx_console_note_srv(dest.ptr, bx_xbox_unwrap_as<ID3D12Resource>(resource), desc);
|
||||
bx_console_mark_srv(dest.ptr, bx_xbox_unwrap_as<ID3D12Resource>(resource), desc);
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_unordered_access_view(void* self, ID3D12Resource* resource, ID3D12Resource* counter,
|
||||
const D3D12_UNORDERED_ACCESS_VIEW_DESC* desc,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dest) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateUnorderedAccessView");
|
||||
bx_xbox_create_host_uav(bx_xbox_host<ID3D12Device>(self), bx_xbox_unwrap_as<ID3D12Resource>(resource),
|
||||
bx_xbox_unwrap_as<ID3D12Resource>(counter), desc, bx_xbox_host_cpu_handle(dest),
|
||||
"CreateUnorderedAccessView");
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_render_target_view(void* self, ID3D12Resource* resource,
|
||||
const D3D12_RENDER_TARGET_VIEW_DESC* desc,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dest) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateRenderTargetView");
|
||||
BxHostFormat<D3D12_RENDER_TARGET_VIEW_DESC> host;
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateRenderTargetView(bx_xbox_unwrap_as<ID3D12Resource>(resource),
|
||||
host.of(desc, "CreateRenderTargetView"),
|
||||
bx_xbox_host_cpu_handle(dest));
|
||||
if (bx_console_translation_enabled()) {
|
||||
DXGI_FORMAT f = desc ? bx_host_format(desc->Format) : DXGI_FORMAT_UNKNOWN;
|
||||
if (f == DXGI_FORMAT_UNKNOWN && resource) f = bx_xbox_unwrap_as<ID3D12Resource>(resource)->GetDesc().Format;
|
||||
bx_console_rtv_created(bx_xbox_host_cpu_handle(dest).ptr, f, bx_xbox_unwrap_as<ID3D12Resource>(resource));
|
||||
}
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_depth_stencil_view(void* self, ID3D12Resource* resource,
|
||||
const D3D12_DEPTH_STENCIL_VIEW_DESC* desc,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dest) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateDepthStencilView");
|
||||
BxHostFormat<D3D12_DEPTH_STENCIL_VIEW_DESC> host;
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateDepthStencilView(bx_xbox_unwrap_as<ID3D12Resource>(resource),
|
||||
host.of(desc, "CreateDepthStencilView"),
|
||||
bx_xbox_host_cpu_handle(dest));
|
||||
if (bx_console_translation_enabled()) {
|
||||
DXGI_FORMAT f = desc ? bx_host_format(desc->Format) : DXGI_FORMAT_UNKNOWN;
|
||||
if (f == DXGI_FORMAT_UNKNOWN && resource) f = bx_xbox_unwrap_as<ID3D12Resource>(resource)->GetDesc().Format;
|
||||
bx_console_dsv_created(bx_xbox_host_cpu_handle(dest).ptr, f);
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,91 @@
|
||||
/* Console-only DXGI formats.
|
||||
*
|
||||
* The Xbox Series DXGI_FORMAT enumeration (GDK d3d12_xs.h) has values the PC enumeration does
|
||||
* not have: 116-120, 189 and 190. A PC Direct3D 12 implementation does not know them. D3DMetal
|
||||
* turns one into an invalid Metal pixel format, and Metal then aborts the process ("Texture
|
||||
* Descriptor Validation: MTLTextureDescriptor has invalid pixelFormat"), so no error code ever
|
||||
* comes back. Every format that reaches the host therefore goes through bx_host_format first.
|
||||
*
|
||||
* The host format is the nearest one the host can create that holds at least the same precision:
|
||||
*
|
||||
* 116 R10G10B10_7E3_A2_FLOAT -> R16G16B16A16_FLOAT
|
||||
* 117 R10G10B10_6E4_A2_FLOAT -> R16G16B16A16_FLOAT
|
||||
* 118 D16_UNORM_S8_UINT -> D32_FLOAT_S8X24_UINT (depth + stencil; views, clear values)
|
||||
* -> R32G8X24_TYPELESS (the texture itself, see below)
|
||||
* 119 R16_UNORM_X8_TYPELESS -> R32_FLOAT_X8X24_TYPELESS (its depth plane, read)
|
||||
* 120 X16_TYPELESS_G8_UINT -> X32_TYPELESS_G8X24_UINT (its stencil plane, read)
|
||||
* 189 R10G10B10_SNORM_A2_UNORM -> R16G16B16A16_SNORM
|
||||
* 190 R4G4_UNORM -> R8G8_UNORM
|
||||
*
|
||||
* A depth texture that is also read is created typeless on the host, with the concrete format
|
||||
* named by each view: D3DMetal creates a fully typed depth-stencil texture without the ability
|
||||
* to be viewed in another format, and Metal aborts on the depth-plane view. The title's own
|
||||
* D32 buffers already follow that pattern (R32G8X24_TYPELESS texture, D32_FLOAT_S8X24_UINT view).
|
||||
* bx_host_resource_format is therefore used for resource descriptions and bx_host_format for
|
||||
* everything else.
|
||||
*
|
||||
* Known limits. The texel size differs, so a host resource of a substituted format cannot take
|
||||
* the title's raw texel bytes (part of uploading placed texture contents, which is separate
|
||||
* work), the sizes GetResourceAllocationInfo and GetCopyableFootprints report are the host
|
||||
* format's, and GetDesc on such a resource reports the host format.
|
||||
*/
|
||||
#ifndef BX_D3D12_XS_CONSOLE_FORMATS_H
|
||||
#define BX_D3D12_XS_CONSOLE_FORMATS_H
|
||||
|
||||
#include <dxgiformat.h>
|
||||
|
||||
constexpr int kBxFormatR10G10B10_7E3_A2_FLOAT = 116;
|
||||
constexpr int kBxFormatR10G10B10_6E4_A2_FLOAT = 117;
|
||||
constexpr int kBxFormatD16_UNORM_S8_UINT = 118;
|
||||
constexpr int kBxFormatR16_UNORM_X8_TYPELESS = 119;
|
||||
constexpr int kBxFormatX16_TYPELESS_G8_UINT = 120;
|
||||
constexpr int kBxFormatR10G10B10_SNORM_A2_UNORM = 189;
|
||||
constexpr int kBxFormatR4G4_UNORM = 190;
|
||||
|
||||
constexpr bool bx_is_console_only_format(DXGI_FORMAT format) {
|
||||
const int f = static_cast<int>(format);
|
||||
return (f >= 116 && f <= 120) || f == 189 || f == 190;
|
||||
}
|
||||
|
||||
constexpr DXGI_FORMAT bx_host_format(DXGI_FORMAT format) {
|
||||
switch (static_cast<int>(format)) {
|
||||
case kBxFormatR10G10B10_7E3_A2_FLOAT:
|
||||
case kBxFormatR10G10B10_6E4_A2_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
|
||||
case kBxFormatD16_UNORM_S8_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
|
||||
case kBxFormatR16_UNORM_X8_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
|
||||
case kBxFormatX16_TYPELESS_G8_UINT: return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
|
||||
case kBxFormatR10G10B10_SNORM_A2_UNORM: return DXGI_FORMAT_R16G16B16A16_SNORM;
|
||||
case kBxFormatR4G4_UNORM: return DXGI_FORMAT_R8G8_UNORM;
|
||||
default: return format;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr DXGI_FORMAT bx_host_resource_format(DXGI_FORMAT format) {
|
||||
return static_cast<int>(format) == kBxFormatD16_UNORM_S8_UINT ? DXGI_FORMAT_R32G8X24_TYPELESS : bx_host_format(format);
|
||||
}
|
||||
|
||||
/* Logs the first translation of each console-only format (console_formats.cpp). */
|
||||
void bx_note_console_format(DXGI_FORMAT format, const char* where);
|
||||
|
||||
/* A structure with a `Format` member (resource description, clear value, view description) as
|
||||
* the host must see it. of() returns the caller's pointer unchanged when nothing needs
|
||||
* translating, so the common case costs one comparison and no copy. */
|
||||
template <typename T>
|
||||
class BxHostFormat {
|
||||
public:
|
||||
const T* of(const T* in, const char* where) { return translate(in, where, false); }
|
||||
/* For D3D12_RESOURCE_DESC and D3D12_RESOURCE_DESC1. */
|
||||
const T* of_resource(const T* in, const char* where) { return translate(in, where, true); }
|
||||
|
||||
private:
|
||||
const T* translate(const T* in, const char* where, bool resource) {
|
||||
if (!in || !bx_is_console_only_format(in->Format)) return in;
|
||||
bx_note_console_format(in->Format, where);
|
||||
value_ = *in;
|
||||
value_.Format = resource ? bx_host_resource_format(in->Format) : bx_host_format(in->Format);
|
||||
return &value_;
|
||||
}
|
||||
T value_;
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,104 @@
|
||||
#pragma once
|
||||
/*
|
||||
* Experimental translation of deserialized console pipelines (raw RDNA 2 code) for the first
|
||||
* frames of a project-authorized target build. See console_translate.cpp.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <d3d12.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
/* Records a created root signature's serialized form (host object -> description). */
|
||||
void bx_console_root_signature_created(ID3D12RootSignature* host, const void* blob, size_t size);
|
||||
|
||||
/* The 1.1-converted description of a recorded root signature, or nullptr. */
|
||||
const D3D12_ROOT_SIGNATURE_DESC1* bx_console_root_signature_desc(ID3D12RootSignature* host);
|
||||
|
||||
/* Writes a compact description of a recorded root signature. */
|
||||
void bx_console_describe_root_signature(ID3D12RootSignature* host, char* out, size_t room);
|
||||
|
||||
/* True when BX_CONSOLE_SHADER_CACHE names a folder of translated shaders (opt-in). */
|
||||
bool bx_console_translation_enabled();
|
||||
|
||||
/* With translation enabled: a serialized root signature widened with the translator's register
|
||||
space (overlapping CBV/SRV ranges per descriptor table, one static sampler). The caller
|
||||
creates the host root signature from it and falls back to the original on failure. */
|
||||
ID3DBlob* bx_console_widen_root_signature(const void* blob, size_t size);
|
||||
|
||||
/* A console graphics pipeline whose stages have translated shaders in the cache. */
|
||||
struct BxTranslated;
|
||||
|
||||
/* Looks the VS/PS pair up in the cache; nullptr when either is missing. */
|
||||
std::shared_ptr<BxTranslated> bx_console_translate_graphics(ID3D12Device* device, ID3D12RootSignature* host_root,
|
||||
const void* vs, size_t vs_size, const void* ps,
|
||||
size_t ps_size);
|
||||
|
||||
/* True when the translated vertex shader takes its attributes from the pipeline's own input
|
||||
layout (the console vertex-fetch call); the host pipeline is then built from the title's
|
||||
stream, and bx_console_set_pipeline hands it over (the reference is taken). */
|
||||
bool bx_console_uses_stream_layout(const BxTranslated* translated);
|
||||
const void* bx_console_shader(const BxTranslated* translated, bool pixel, size_t* size);
|
||||
void bx_console_set_pipeline(BxTranslated* translated, ID3D12PipelineState* host);
|
||||
/* Hands over the title's stream (shaders already substituted) and its input elements; host
|
||||
pipelines are then created from it per bound target formats. Offsets are payload offsets of
|
||||
the input layout, render-target formats, depth format and topology type (SIZE_MAX: absent). */
|
||||
void bx_console_set_stream(BxTranslated* translated, std::vector<uint8_t>&& stream,
|
||||
std::vector<D3D12_INPUT_ELEMENT_DESC>&& elements, size_t layout_at, size_t rt_at, size_t ds_at,
|
||||
size_t topology_at);
|
||||
void bx_console_note_ib(ID3D12GraphicsCommandList* list, const D3D12_INDEX_BUFFER_VIEW* view);
|
||||
/* The title set a viewport (true) or scissor rectangle (false) on this list since its reset. */
|
||||
void bx_console_note_raster(ID3D12GraphicsCommandList* list, bool viewport);
|
||||
void bx_console_note_viewport(ID3D12GraphicsCommandList* list, UINT count, const D3D12_VIEWPORT* viewports);
|
||||
void bx_console_note_scissor(ID3D12GraphicsCommandList* list, UINT count, const D3D12_RECT* rects);
|
||||
void bx_console_note_topology(ID3D12GraphicsCommandList* list, D3D12_PRIMITIVE_TOPOLOGY topology);
|
||||
/* Diagnostic: logs the state a translated draw runs with (first few per pipeline). */
|
||||
void bx_console_draw_state(const char* key, ID3D12GraphicsCommandList* list, UINT count, UINT instances, UINT start, INT base,
|
||||
bool indexed);
|
||||
void bx_console_stream_state(const char* key, const char* text);
|
||||
/* A non-indexed draw on a list whose topology is the console rectangle list: draws each
|
||||
rectangle as a four-vertex triangle strip built from the title's three vertices. True when the
|
||||
draw was handled (the caller then skips its own draw). */
|
||||
bool bx_console_draw_rect_list(BxTranslated* translated, ID3D12GraphicsCommandList* list, UINT vertices, UINT instances,
|
||||
UINT first_vertex, UINT first_instance);
|
||||
/* Diagnostic: the distinct render targets translated draws went into (at most `max`). */
|
||||
int bx_console_debug_targets(ID3D12Resource** out, int max);
|
||||
|
||||
/* placed_x.cpp: makes sure [va, va + size) of plain title memory has a host buffer behind it. */
|
||||
extern "C" bool bx_xbox_back_title_buffer(ID3D12Device* device, uint64_t va, uint64_t size);
|
||||
|
||||
/* Render-target bookkeeping, so translated pipelines are created with the bound formats. */
|
||||
void bx_console_rtv_created(SIZE_T host_cpu, DXGI_FORMAT format, ID3D12Resource* resource = nullptr);
|
||||
void bx_console_dsv_created(SIZE_T host_cpu, DXGI_FORMAT format);
|
||||
void bx_console_list_set_render_targets(ID3D12GraphicsCommandList* list, UINT count, const D3D12_CPU_DESCRIPTOR_HANDLE* rtvs,
|
||||
BOOL single_range, const D3D12_CPU_DESCRIPTOR_HANDLE* dsv);
|
||||
|
||||
/* Draw-time evidence (BX_PSO_PROFILE=1, local only). Handles are title descriptor addresses. */
|
||||
void bx_console_note_cbv(uint64_t title_handle, uint64_t va, UINT size);
|
||||
void bx_console_note_srv(uint64_t title_handle, ID3D12Resource* host, const D3D12_SHADER_RESOURCE_VIEW_DESC* desc);
|
||||
void bx_console_note_table(ID3D12GraphicsCommandList* list, UINT param, uint64_t title_handle);
|
||||
void bx_console_note_vb(ID3D12GraphicsCommandList* list, UINT start, UINT count, const D3D12_VERTEX_BUFFER_VIEW* views);
|
||||
void bx_console_evidence(const char* key, ID3D12GraphicsCommandList* list, UINT vertices);
|
||||
const char* bx_console_key(const BxTranslated* translated);
|
||||
|
||||
/* Inline console descriptors: draws are recorded per list and decoded when it is submitted. */
|
||||
void bx_console_list_reset(ID3D12GraphicsCommandList* list);
|
||||
void bx_console_record_draw(const std::shared_ptr<BxTranslated>& translated, ID3D12GraphicsCommandList* list);
|
||||
void bx_console_submit(ID3D12CommandList* const* lists, UINT count);
|
||||
|
||||
/* Descriptor markers in title memory (see console_translate.cpp, part 5). */
|
||||
void bx_console_mark_cbv(uint64_t dest, const D3D12_CONSTANT_BUFFER_VIEW_DESC& host_desc, uint64_t title_va);
|
||||
void bx_console_mark_srv(uint64_t dest, ID3D12Resource* host, const D3D12_SHADER_RESOURCE_VIEW_DESC* desc,
|
||||
uint64_t title_va = 0, uint64_t title_size = 0);
|
||||
void bx_console_copy_title(uint64_t dest, uint64_t src, UINT count);
|
||||
|
||||
/* placed_x.cpp: copies a title-memory range to the host shadow its address resolves to. */
|
||||
extern "C" bool bx_xbox_sync_title_range(uint64_t title_va, uint64_t size);
|
||||
extern "C" uint64_t bx_xbox_shadow_title_va(ID3D12Resource* host);
|
||||
|
||||
void bx_console_note_root_srv(ID3D12GraphicsCommandList* list, UINT param, uint64_t title_va);
|
||||
|
||||
/* Binds a translated pipeline to a host list before a draw; false when it cannot be created. */
|
||||
bool bx_console_apply(BxTranslated* translated, ID3D12GraphicsCommandList* list);
|
||||
@@ -13,6 +13,7 @@
|
||||
* other titles' descriptor writes on the out-of-line path, which reaches the host heap.
|
||||
*/
|
||||
#include "xbox_facade.h"
|
||||
#include "console_translate.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
@@ -187,6 +188,8 @@ void STDMETHODCALLTYPE bx_xbox_device_create_constant_buffer_view(void* self, co
|
||||
host_desc.BufferLocation = bx_xbox_host_gpu_va(desc->BufferLocation);
|
||||
}
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateConstantBufferView(desc ? &host_desc : nullptr, bx_xbox_host_cpu_handle(dest));
|
||||
if (desc) bx_console_note_cbv(dest.ptr, desc->BufferLocation, desc->SizeInBytes);
|
||||
if (desc) bx_console_mark_cbv(dest.ptr, host_desc, desc->BufferLocation);
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_device_copy_descriptors(void* self, UINT dest_ranges, const D3D12_CPU_DESCRIPTOR_HANDLE* dest_starts,
|
||||
@@ -198,6 +201,17 @@ void STDMETHODCALLTYPE bx_xbox_device_copy_descriptors(void* self, UINT dest_ran
|
||||
if (!dst) return;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE* src = dst + dest_ranges;
|
||||
for (UINT i = 0; i < dest_ranges; ++i) dst[i] = bx_xbox_host_cpu_handle(dest_starts[i]);
|
||||
if (type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && dest_starts && src_starts) {
|
||||
// console descriptors are bytes: copy the title's too (range by range, sizes default to 1)
|
||||
UINT di = 0, dn = 0, si = 0, sn = 0;
|
||||
auto dsize = [&](UINT i) { return dest_sizes ? dest_sizes[i] : 1u; };
|
||||
auto ssize = [&](UINT i) { return src_sizes ? src_sizes[i] : 1u; };
|
||||
while (di < dest_ranges && si < src_ranges) {
|
||||
bx_console_copy_title(dest_starts[di].ptr + 32ull * dn, src_starts[si].ptr + 32ull * sn, 1);
|
||||
if (++dn >= dsize(di)) { ++di; dn = 0; }
|
||||
if (++sn >= ssize(si)) { ++si; sn = 0; }
|
||||
}
|
||||
}
|
||||
for (UINT i = 0; i < src_ranges; ++i) src[i] = bx_xbox_host_cpu_handle(src_starts[i]);
|
||||
bx_xbox_host<ID3D12Device>(self)->CopyDescriptors(dest_ranges, dst, dest_sizes, src_ranges, src, src_sizes, type);
|
||||
delete[] dst;
|
||||
@@ -212,8 +226,34 @@ void STDMETHODCALLTYPE bx_xbox_list_om_set_render_targets(void* self, UINT count
|
||||
const D3D12_CPU_DESCRIPTOR_HANDLE host_dsv = dsv ? bx_xbox_host_cpu_handle(*dsv) : D3D12_CPU_DESCRIPTOR_HANDLE{};
|
||||
bx_xbox_host<ID3D12GraphicsCommandList>(self)->OMSetRenderTargets(n, rtvs ? host_rtvs : nullptr, single_range,
|
||||
dsv ? &host_dsv : nullptr);
|
||||
if (bx_console_translation_enabled()) {
|
||||
bx_console_list_set_render_targets(bx_xbox_host<ID3D12GraphicsCommandList>(self), n, rtvs ? host_rtvs : nullptr,
|
||||
single_range, dsv ? &host_dsv : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/* On the console a GPU virtual address is the title's own address, so a title can bind index and
|
||||
* vertex data that lives in plain title memory, with no Direct3D resource created for it. This
|
||||
* layer has a host buffer only for memory it was told about (placed and committed resources).
|
||||
* An address without one must not reach the host: it is not a host address, and D3DMetal
|
||||
* dereferences the buffer it fails to find (a null read under IASetIndexBuffer). Such a binding
|
||||
* is left empty and logged as unimplemented; the first few are logged with their details.
|
||||
* Supplying the data (a host buffer filled from the title memory) is separate work. */
|
||||
void note_unbacked(const char* what, D3D12_GPU_VIRTUAL_ADDRESS address, UINT size, const char* stub) {
|
||||
static std::atomic<uint32_t> noted{0};
|
||||
if (noted.fetch_add(1) < 8) {
|
||||
char detail[128];
|
||||
std::snprintf(detail, sizeof(detail), "%s at 0x%llx (%u bytes) has no host buffer; the binding is left empty", what,
|
||||
static_cast<unsigned long long>(address), size);
|
||||
bx_log_emit(BX_LOG_WARN, "d3d12_xs", "unbacked_buffer", detail);
|
||||
}
|
||||
BX_STUB_LOG("d3d12_xs.dll", stub);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_list_ia_set_vertex_buffers(void* self, UINT start, UINT count,
|
||||
const D3D12_VERTEX_BUFFER_VIEW* views) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "IASetVertexBuffers");
|
||||
@@ -221,17 +261,43 @@ void STDMETHODCALLTYPE bx_xbox_list_ia_set_vertex_buffers(void* self, UINT start
|
||||
const UINT n = count > 32 ? 32 : count;
|
||||
for (UINT i = 0; views && i < n; ++i) {
|
||||
host[i] = views[i];
|
||||
host[i].BufferLocation = bx_xbox_host_gpu_va(views[i].BufferLocation);
|
||||
if (views[i].BufferLocation && bx_console_translation_enabled()) {
|
||||
ID3D12Device* device = nullptr;
|
||||
auto* list = bx_xbox_host<ID3D12GraphicsCommandList>(self);
|
||||
if (SUCCEEDED(list->GetDevice(__uuidof(ID3D12Device), reinterpret_cast<void**>(&device))) && device) {
|
||||
bx_xbox_back_title_buffer(device, views[i].BufferLocation, views[i].SizeInBytes);
|
||||
device->Release();
|
||||
}
|
||||
}
|
||||
if (views[i].BufferLocation && !bx_xbox_try_host_gpu_va(views[i].BufferLocation, &host[i].BufferLocation)) {
|
||||
note_unbacked("vertex buffer", views[i].BufferLocation, views[i].SizeInBytes,
|
||||
"IASetVertexBuffers(title memory without a host buffer)");
|
||||
host[i] = D3D12_VERTEX_BUFFER_VIEW{};
|
||||
}
|
||||
}
|
||||
bx_xbox_host<ID3D12GraphicsCommandList>(self)->IASetVertexBuffers(start, n, views ? host : nullptr);
|
||||
bx_console_note_vb(bx_xbox_host<ID3D12GraphicsCommandList>(self), start, n, views);
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_list_ia_set_index_buffer(void* self, const D3D12_INDEX_BUFFER_VIEW* view) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "IASetIndexBuffer");
|
||||
D3D12_INDEX_BUFFER_VIEW host{};
|
||||
bx_console_note_ib(bx_xbox_host<ID3D12GraphicsCommandList>(self), view);
|
||||
if (view) {
|
||||
host = *view;
|
||||
host.BufferLocation = bx_xbox_host_gpu_va(view->BufferLocation);
|
||||
if (view->BufferLocation && bx_console_translation_enabled()) {
|
||||
ID3D12Device* device = nullptr;
|
||||
auto* list = bx_xbox_host<ID3D12GraphicsCommandList>(self);
|
||||
if (SUCCEEDED(list->GetDevice(__uuidof(ID3D12Device), reinterpret_cast<void**>(&device))) && device) {
|
||||
bx_xbox_back_title_buffer(device, view->BufferLocation, view->SizeInBytes);
|
||||
device->Release();
|
||||
}
|
||||
}
|
||||
if (view->BufferLocation && !bx_xbox_try_host_gpu_va(view->BufferLocation, &host.BufferLocation)) {
|
||||
note_unbacked("index buffer", view->BufferLocation, view->SizeInBytes,
|
||||
"IASetIndexBuffer(title memory without a host buffer)");
|
||||
view = nullptr;
|
||||
}
|
||||
}
|
||||
bx_xbox_host<ID3D12GraphicsCommandList>(self)->IASetIndexBuffer(view ? &host : nullptr);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
*/
|
||||
#include "xbox_facade.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
@@ -43,6 +45,22 @@ UINT64 g_next_token = 1;
|
||||
UINT64 g_last_origin_token = 0;
|
||||
bool g_thread_started = false;
|
||||
|
||||
/* Origin occurrences by token, for GetFrameStatisticsX (host QueryPerformanceCounter ticks). */
|
||||
struct OriginRecord {
|
||||
UINT64 token = 0;
|
||||
UINT64 signal_qpc = 0;
|
||||
UINT64 wait_call_qpc = 0;
|
||||
UINT64 wait_return_qpc = 0;
|
||||
};
|
||||
constexpr size_t kOriginRing = 256;
|
||||
OriginRecord g_origins[kOriginRing];
|
||||
|
||||
UINT64 qpc_now() {
|
||||
LARGE_INTEGER t;
|
||||
QueryPerformanceCounter(&t);
|
||||
return static_cast<UINT64>(t.QuadPart);
|
||||
}
|
||||
|
||||
void close_ancillary(Scheduled& e) {
|
||||
for (UINT i = 0; i < e.ancillary_count; ++i) CloseHandle(e.ancillary[i]);
|
||||
e.ancillary_count = 0;
|
||||
@@ -52,7 +70,13 @@ void signal(UINT type) {
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
const Scheduled& e = g_events[type];
|
||||
if (!e.active) return;
|
||||
if (type == kOrigin) g_last_origin_token = g_next_token++;
|
||||
if (type == kOrigin) {
|
||||
g_last_origin_token = g_next_token++;
|
||||
OriginRecord& r = g_origins[g_last_origin_token % kOriginRing];
|
||||
r = {};
|
||||
r.token = g_last_origin_token;
|
||||
r.signal_qpc = qpc_now();
|
||||
}
|
||||
SetEvent(g_signal[type]);
|
||||
for (UINT i = 0; i < e.ancillary_count; ++i) SetEvent(e.ancillary[i]);
|
||||
}
|
||||
@@ -156,6 +180,7 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_wait_frame_event_x(void*, UINT type, UI
|
||||
}
|
||||
const UINT ancillary = waits ? waits->Count : 0;
|
||||
for (UINT i = 0; i < ancillary; ++i) handles[1 + i] = waits->pObjects[i];
|
||||
const UINT64 wait_call = qpc_now();
|
||||
const DWORD result = WaitForMultipleObjects(1 + ancillary, handles, (flags & kWaitAll) != 0,
|
||||
timeout_ms == kInfinite ? INFINITE : timeout_ms);
|
||||
const bool satisfied = result < WAIT_OBJECT_0 + 1 + ancillary;
|
||||
@@ -166,8 +191,115 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_wait_frame_event_x(void*, UINT type, UI
|
||||
if (type == kOrigin && token && (satisfied || (flags & kWaitProcessTokenOnTimeout))) {
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
*token = satisfied ? g_last_origin_token : g_next_token++;
|
||||
OriginRecord& r = g_origins[*token % kOriginRing];
|
||||
if (r.token != *token) {
|
||||
r = {};
|
||||
r.token = *token;
|
||||
r.signal_qpc = wait_call;
|
||||
}
|
||||
r.wait_call_qpc = wait_call;
|
||||
r.wait_return_qpc = qpc_now();
|
||||
}
|
||||
return satisfied ? S_OK : S_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* GetFrameStatisticsX (structures from the authorized GDK header; semantics inferred, there is
|
||||
* no documentation text for this call): one D3D12XBOX_FRAME_STATISTICS element per requested
|
||||
* type, at most *pCount, with host QueryPerformanceCounter ticks for every time. There is no
|
||||
* display here: the vertical sync and flip are reported one frame interval after the origin,
|
||||
* and GPU durations as half an interval. Each first request per type set is logged.
|
||||
*/
|
||||
struct BxFrameStatistics {
|
||||
UINT type;
|
||||
UINT pad;
|
||||
union {
|
||||
struct { UINT length_us, period, flags; } interval;
|
||||
struct { UINT event_type; UINT pad; UINT64 wait_call, signal, wait_return; UINT offset_us, signal_flags, stat_flags; } event;
|
||||
struct { UINT64 context, origin, available, query; } input;
|
||||
struct { UINT8 plane; UINT8 pad[7]; UINT64 write_complete, busy; } render;
|
||||
struct { UINT8 plane, plane_count, view_count; UINT8 pad[5]; UINT64 call, queue, ret, gpu; UINT8 queued; UINT8 pad2;
|
||||
UINT16 swap_mask; UINT flags; } present;
|
||||
struct { UINT8 plane; UINT8 pad[7]; UINT64 vsync, flip; FLOAT scanned; } display;
|
||||
struct { UINT8 plane; UINT8 pad[7]; UINT64 busy_scaled; double factor; } power;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(BxFrameStatistics) == 56, "D3D12XBOX_FRAME_STATISTICS size");
|
||||
|
||||
HRESULT STDMETHODCALLTYPE bx_xbox_device_get_frame_statistics_x(void*, UINT64 token, UINT type_set, UINT* count,
|
||||
BxFrameStatistics* stats) {
|
||||
BX_D3D_TRACE("XboxDevice", "GetFrameStatisticsX");
|
||||
if (!count) return E_INVALIDARG;
|
||||
const UINT capacity = *count;
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
OriginRecord origin;
|
||||
UINT interval_us, period;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
origin = g_origins[token % kOriginRing];
|
||||
interval_us = g_interval_us ? g_interval_us : 16667;
|
||||
period = g_period ? g_period : 1;
|
||||
}
|
||||
const UINT64 now = qpc_now();
|
||||
if (origin.token != token || !origin.signal_qpc) {
|
||||
origin = {};
|
||||
origin.token = token;
|
||||
origin.signal_qpc = origin.wait_call_qpc = origin.wait_return_qpc = now;
|
||||
}
|
||||
const UINT64 frame_ticks = static_cast<UINT64>(freq.QuadPart) * interval_us * period / 1000000ull;
|
||||
UINT written = 0;
|
||||
auto next = [&](UINT type) -> BxFrameStatistics* {
|
||||
if (!(type_set & type) || written >= capacity || !stats) return nullptr;
|
||||
BxFrameStatistics* s = &stats[written++];
|
||||
std::memset(s, 0, sizeof(*s));
|
||||
s->type = type;
|
||||
return s;
|
||||
};
|
||||
if (BxFrameStatistics* s = next(0x1)) {
|
||||
s->interval.length_us = interval_us;
|
||||
s->interval.period = period;
|
||||
}
|
||||
if (BxFrameStatistics* s = next(0x2)) {
|
||||
s->event.event_type = kOrigin;
|
||||
s->event.wait_call = origin.wait_call_qpc ? origin.wait_call_qpc : origin.signal_qpc;
|
||||
s->event.signal = origin.signal_qpc;
|
||||
s->event.wait_return = origin.wait_return_qpc ? origin.wait_return_qpc : origin.signal_qpc;
|
||||
}
|
||||
if (BxFrameStatistics* s = next(0x4)) {
|
||||
s->power.busy_scaled = frame_ticks / 2;
|
||||
s->power.factor = 1.0;
|
||||
}
|
||||
if (BxFrameStatistics* s = next(0x100)) {
|
||||
s->render.write_complete = origin.signal_qpc + frame_ticks / 2;
|
||||
s->render.busy = frame_ticks / 2;
|
||||
}
|
||||
if (BxFrameStatistics* s = next(0x1000)) {
|
||||
s->present.plane_count = 1;
|
||||
s->present.view_count = 1;
|
||||
s->present.call = s->present.queue = s->present.ret = origin.signal_qpc + frame_ticks / 2;
|
||||
s->present.gpu = frame_ticks / 2;
|
||||
s->present.swap_mask = 1;
|
||||
}
|
||||
if (BxFrameStatistics* s = next(0x10000)) {
|
||||
s->display.vsync = origin.signal_qpc + frame_ticks;
|
||||
s->display.flip = origin.signal_qpc + frame_ticks;
|
||||
s->display.scanned = 0.0f;
|
||||
}
|
||||
if (BxFrameStatistics* s = next(0x100000)) {
|
||||
s->input.origin = origin.signal_qpc;
|
||||
s->input.available = origin.signal_qpc;
|
||||
s->input.query = origin.wait_return_qpc ? origin.wait_return_qpc : origin.signal_qpc;
|
||||
}
|
||||
*count = written;
|
||||
static std::atomic<int> logged{0};
|
||||
if (logged.fetch_add(1) < 6) {
|
||||
char detail[160];
|
||||
std::snprintf(detail, sizeof(detail), "token=%llu type_set=0x%x capacity=%u written=%u (host clock, no display)",
|
||||
static_cast<unsigned long long>(token), type_set, capacity, written);
|
||||
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "frame_statistics", detail);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -8,6 +8,7 @@
|
||||
* writes are therefore synchronous (logged once); executes without writes are not changed.
|
||||
*/
|
||||
#include "xbox_facade.h"
|
||||
#include "console_translate.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
@@ -158,6 +159,7 @@ void execute(void* self, UINT count, ID3D12CommandList* const* lists) {
|
||||
for (const Write& w : pending) {
|
||||
if (w.wait) apply_wait(queue, w);
|
||||
}
|
||||
bx_console_submit(host.data(), count);
|
||||
queue->ExecuteCommandLists(count, host.data());
|
||||
bool any_write = false;
|
||||
for (const Write& w : pending) any_write = any_write || !w.wait;
|
||||
|
||||
+370
-14
@@ -18,12 +18,17 @@
|
||||
|
||||
#include "proxy.h"
|
||||
#include "shader_gate.h"
|
||||
#include "console_translate.h"
|
||||
#include "console_formats.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -38,10 +43,37 @@ bool null_render_enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/* BX_PSO_PROFILE=1 (local diagnostics, off by default): each null pipeline gets an id, its
|
||||
creation is described in a `pso_profile` record, and skipped draws and dispatches name the id
|
||||
they were recorded with. The records hold title-derived sizes and hashes: they belong in
|
||||
private evidence, never in the repository. */
|
||||
bool pso_profile_enabled() {
|
||||
static const bool enabled = [] {
|
||||
char value[8] = {};
|
||||
const DWORD n = GetEnvironmentVariableA("BX_PSO_PROFILE", value, sizeof(value));
|
||||
return n > 0 && n < sizeof(value) && value[0] == '1';
|
||||
}();
|
||||
return enabled;
|
||||
}
|
||||
thread_local const char* t_pending_profile = nullptr; // description of the pipeline being refused
|
||||
thread_local std::shared_ptr<BxTranslated> t_pending_translated; // translation for the pipeline being refused
|
||||
struct DrawArgs {
|
||||
UINT count, instances, start;
|
||||
INT base;
|
||||
bool indexed;
|
||||
};
|
||||
thread_local DrawArgs t_draw{}; // diagnostic: arguments of the draw being recorded
|
||||
thread_local std::shared_ptr<BxTranslated> t_applied; // the translated pipeline list_skips just bound, if any
|
||||
std::atomic<uint32_t> g_next_null_id{1};
|
||||
|
||||
/* A pipeline-state object with no host pipeline behind it. */
|
||||
class NullPipelineState final : public ID3D12PipelineState {
|
||||
public:
|
||||
explicit NullPipelineState(ID3D12Device* device) : device_(device) { device_->AddRef(); }
|
||||
explicit NullPipelineState(ID3D12Device* device) : device_(device), id_(g_next_null_id.fetch_add(1)) {
|
||||
device_->AddRef();
|
||||
}
|
||||
uint32_t id() const { return id_; }
|
||||
std::shared_ptr<BxTranslated> translated; // console stages with translated shaders, if any
|
||||
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv) override {
|
||||
if (!ppv) return E_POINTER;
|
||||
@@ -78,6 +110,7 @@ public:
|
||||
|
||||
private:
|
||||
ID3D12Device* device_;
|
||||
uint32_t id_;
|
||||
std::atomic<ULONG> refs_{1};
|
||||
};
|
||||
|
||||
@@ -88,6 +121,9 @@ size_t g_null_capacity = 0;
|
||||
ID3D12GraphicsCommandList** g_lists = nullptr; // lists whose bound pipeline is a null pipeline
|
||||
size_t g_list_count = 0;
|
||||
size_t g_list_capacity = 0;
|
||||
std::unordered_map<const void*, uint32_t> g_list_pso; // profile: null pipeline id bound per list
|
||||
std::unordered_map<uint32_t, uint64_t> g_pso_uses; // profile: skipped work per null pipeline id
|
||||
std::unordered_map<const void*, std::shared_ptr<BxTranslated>> g_list_translated; // translated pipeline bound per list
|
||||
|
||||
template <typename T>
|
||||
bool push(T**& items, size_t& count, size_t& capacity, T* item) {
|
||||
@@ -124,24 +160,71 @@ bool contains(T* const* items, size_t count, const T* item) {
|
||||
}
|
||||
|
||||
/* Returns the host pipeline for a title pipeline, or nullptr for a null pipeline. */
|
||||
ID3D12PipelineState* host_pipeline(ID3D12PipelineState* title, bool* is_null) {
|
||||
ID3D12PipelineState* host_pipeline(ID3D12PipelineState* title, bool* is_null, uint32_t* null_id = nullptr,
|
||||
std::shared_ptr<BxTranslated>* translated = nullptr) {
|
||||
ID3D12PipelineState* host = bx_xbox_unwrap_as(title);
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
*is_null = host && contains(g_nulls, g_null_count, static_cast<NullPipelineState*>(static_cast<void*>(host)));
|
||||
auto* as_null = static_cast<NullPipelineState*>(static_cast<void*>(host));
|
||||
*is_null = host && contains(g_nulls, g_null_count, as_null);
|
||||
if (null_id) *null_id = *is_null ? as_null->id() : 0;
|
||||
if (translated) *translated = *is_null ? as_null->translated : nullptr;
|
||||
return *is_null ? nullptr : host;
|
||||
}
|
||||
|
||||
void set_list_null(ID3D12GraphicsCommandList* list, bool null_bound) {
|
||||
void set_list_null(ID3D12GraphicsCommandList* list, bool null_bound, uint32_t null_id = 0,
|
||||
std::shared_ptr<BxTranslated> translated = nullptr) {
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
if (translated) {
|
||||
g_list_translated[list] = std::move(translated);
|
||||
} else {
|
||||
g_list_translated.erase(list);
|
||||
}
|
||||
if (pso_profile_enabled()) g_list_pso[list] = null_bound ? null_id : 0;
|
||||
const bool present = contains(g_lists, g_list_count, list);
|
||||
if (null_bound && !present) push(g_lists, g_list_count, g_list_capacity, list);
|
||||
if (!null_bound && present) erase(g_lists, g_list_count, list);
|
||||
}
|
||||
|
||||
bool list_skips(ID3D12GraphicsCommandList* list, const char* what) {
|
||||
bool list_skips(ID3D12GraphicsCommandList* list, const char* what, bool is_draw = false) {
|
||||
uint32_t id = 0;
|
||||
uint64_t uses = 0;
|
||||
std::shared_ptr<BxTranslated> translated;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
if (!contains(g_lists, g_list_count, list)) return false;
|
||||
if (is_draw) {
|
||||
auto it = g_list_translated.find(list);
|
||||
if (it != g_list_translated.end()) translated = it->second;
|
||||
}
|
||||
}
|
||||
t_applied.reset();
|
||||
if (translated && bx_console_apply(translated.get(), list)) {
|
||||
t_applied = translated;
|
||||
bx_console_evidence(bx_console_key(translated.get()), list, 0);
|
||||
bx_console_draw_state(bx_console_key(translated.get()), list, t_draw.count, t_draw.instances, t_draw.start, t_draw.base,
|
||||
t_draw.indexed);
|
||||
bx_console_record_draw(translated, list);
|
||||
static std::atomic<uint64_t> drawn{0};
|
||||
const uint64_t k = ++drawn;
|
||||
if ((k & (k - 1)) == 0) {
|
||||
char detail[96];
|
||||
std::snprintf(detail, sizeof(detail), "%s with a translated console pipeline; total=%llu", what,
|
||||
static_cast<unsigned long long>(k));
|
||||
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "console_draw", detail);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
if (pso_profile_enabled()) {
|
||||
id = g_list_pso[list];
|
||||
uses = ++g_pso_uses[id];
|
||||
}
|
||||
}
|
||||
if (pso_profile_enabled() && (uses & (uses - 1)) == 0) { // each id's 1st, 2nd, 4th, ... use
|
||||
char detail[96];
|
||||
std::snprintf(detail, sizeof(detail), "use id=%u %s uses=%llu", id, what, static_cast<unsigned long long>(uses));
|
||||
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "pso_profile", detail);
|
||||
}
|
||||
static std::atomic<uint64_t> skipped{0};
|
||||
const uint64_t n = ++skipped;
|
||||
@@ -169,6 +252,15 @@ HRESULT refused(ID3D12Device* device, HRESULT hr, const char* kind, REFIID riid,
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
}
|
||||
if (pso_profile_enabled()) {
|
||||
char detail[1800];
|
||||
std::snprintf(detail, sizeof(detail), "create id=%u kind=%s %s", null_pso->id(), kind,
|
||||
t_pending_profile ? t_pending_profile : "");
|
||||
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "pso_profile", detail);
|
||||
}
|
||||
t_pending_profile = nullptr;
|
||||
null_pso->translated = std::move(t_pending_translated);
|
||||
t_pending_translated.reset();
|
||||
*ppv = static_cast<ID3D12PipelineState*>(null_pso);
|
||||
return bx_xbox_wrap_result(S_OK, riid, ppv);
|
||||
}
|
||||
@@ -217,6 +309,9 @@ HRESULT create_graphics(void* self, const D3D12_GRAPHICS_PIPELINE_STATE_DESC* de
|
||||
return bx_xbox_wrap_result(hr, riid, ppv);
|
||||
}
|
||||
|
||||
void dump_blob(const char* name, uint64_t hash, const char* part, const void* data, size_t size);
|
||||
uint64_t fnv1a(const void* data, size_t size);
|
||||
|
||||
HRESULT create_stream(void* self, const D3D12_PIPELINE_STATE_STREAM_DESC* desc, REFIID riid, void** ppv) {
|
||||
if (!desc || !ppv) return E_INVALIDARG;
|
||||
*ppv = nullptr;
|
||||
@@ -237,20 +332,181 @@ HRESULT create_stream(void* self, const D3D12_PIPELINE_STATE_STREAM_DESC* desc,
|
||||
ID3D12RootSignature* root = nullptr;
|
||||
std::memcpy(&root, &stream[root_offset], sizeof(root));
|
||||
root = bx_xbox_unwrap_as(root);
|
||||
if (pso_profile_enabled()) {
|
||||
char d[64];
|
||||
std::snprintf(d, sizeof(d), "stream pipeline root=%p", static_cast<void*>(root));
|
||||
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "pso_profile", d);
|
||||
}
|
||||
std::memcpy(&stream[root_offset], &root, sizeof(root));
|
||||
}
|
||||
BxShaderGate gate;
|
||||
for (size_t i = 0; i < offsets.size() && SUCCEEDED(hr); ++i) {
|
||||
HRESULT first_failure = S_OK;
|
||||
D3D12_SHADER_BYTECODE vs{}, ps{};
|
||||
bool other_stage = false;
|
||||
thread_local char stream_profile[400];
|
||||
size_t described = 0;
|
||||
stream_profile[0] = 0;
|
||||
ID3D12RootSignature* host_root = nullptr;
|
||||
if (root_offset != SIZE_MAX) std::memcpy(&host_root, &stream[root_offset], sizeof(host_root));
|
||||
for (size_t i = 0; i < offsets.size(); ++i) {
|
||||
D3D12_SHADER_BYTECODE in{};
|
||||
std::memcpy(&in, &stream[offsets[i]], sizeof(in));
|
||||
D3D12_SHADER_BYTECODE out = in;
|
||||
if (in.pShaderBytecode && in.BytecodeLength) {
|
||||
const uint64_t h = fnv1a(in.pShaderBytecode, in.BytecodeLength);
|
||||
dump_blob(names[i], h, "container", in.pShaderBytecode, in.BytecodeLength);
|
||||
if (std::strcmp(names[i], "VS") == 0) {
|
||||
vs = in;
|
||||
} else if (std::strcmp(names[i], "PS") == 0) {
|
||||
ps = in;
|
||||
} else {
|
||||
other_stage = true;
|
||||
}
|
||||
if (pso_profile_enabled() && described < sizeof(stream_profile)) {
|
||||
const int k = std::snprintf(stream_profile + described, sizeof(stream_profile) - described, " %s=%llu#%016llx",
|
||||
names[i], static_cast<unsigned long long>(in.BytecodeLength),
|
||||
static_cast<unsigned long long>(h));
|
||||
if (k > 0) described += static_cast<size_t>(k);
|
||||
}
|
||||
}
|
||||
hr = gate.admit("stream", names[i], in, out);
|
||||
if (SUCCEEDED(hr)) std::memcpy(&stream[offsets[i]], &out, sizeof(out));
|
||||
else if (SUCCEEDED(first_failure)) first_failure = hr;
|
||||
}
|
||||
hr = first_failure;
|
||||
D3D12_PIPELINE_STATE_STREAM_DESC admitted = *desc;
|
||||
admitted.pPipelineStateSubobjectStream = stream.data();
|
||||
if (SUCCEEDED(hr)) hr = device->CreatePipelineState(&admitted, riid, ppv);
|
||||
if (FAILED(hr)) return refused(device, hr, "stream", riid, ppv);
|
||||
if (FAILED(hr)) {
|
||||
if (pso_profile_enabled() && described) t_pending_profile = stream_profile;
|
||||
// Console shader containers: a VS/PS pair with translated shaders in the cache (opt-in).
|
||||
if (bx_console_translation_enabled() && !other_stage && vs.pShaderBytecode && ps.pShaderBytecode && host_root) {
|
||||
t_pending_translated = bx_console_translate_graphics(device, host_root, vs.pShaderBytecode, vs.BytecodeLength,
|
||||
ps.pShaderBytecode, ps.BytecodeLength);
|
||||
if (bx_console_uses_stream_layout(t_pending_translated.get())) {
|
||||
// The title's own stream with three substitutions: the translated shaders, an
|
||||
// input layout whose semantics are ATTR<k> in element order, and host formats.
|
||||
std::vector<uint8_t> host_stream = stream;
|
||||
std::vector<D3D12_INPUT_ELEMENT_DESC> elements;
|
||||
for (size_t i = 0; i < offsets.size(); ++i) {
|
||||
const bool pixel = std::strcmp(names[i], "PS") == 0;
|
||||
// Only the two translated stages: the stream also carries (empty) entries for
|
||||
// the tessellation and geometry stages, which must stay empty.
|
||||
if (!pixel && std::strcmp(names[i], "VS") != 0) continue;
|
||||
D3D12_SHADER_BYTECODE code{};
|
||||
size_t size = 0;
|
||||
code.pShaderBytecode = bx_console_shader(t_pending_translated.get(), pixel, &size);
|
||||
code.BytecodeLength = size;
|
||||
std::memcpy(&host_stream[offsets[i]], &code, sizeof(code));
|
||||
}
|
||||
const size_t layout_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT);
|
||||
if (layout_at != SIZE_MAX) {
|
||||
D3D12_INPUT_LAYOUT_DESC layout{};
|
||||
std::memcpy(&layout, &host_stream[layout_at], sizeof(layout));
|
||||
for (UINT k = 0; layout.pInputElementDescs && k < layout.NumElements; ++k) {
|
||||
D3D12_INPUT_ELEMENT_DESC e = layout.pInputElementDescs[k];
|
||||
e.SemanticName = "ATTR";
|
||||
e.SemanticIndex = k;
|
||||
e.Format = bx_host_format(e.Format);
|
||||
elements.push_back(e);
|
||||
}
|
||||
layout.pInputElementDescs = elements.data();
|
||||
std::memcpy(&host_stream[layout_at], &layout, sizeof(layout));
|
||||
}
|
||||
const size_t rt_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS);
|
||||
D3D12_RT_FORMAT_ARRAY formats{};
|
||||
if (rt_at != SIZE_MAX) {
|
||||
std::memcpy(&formats, &host_stream[rt_at], sizeof(formats));
|
||||
for (UINT k = 0; k < 8; ++k) formats.RTFormats[k] = bx_host_format(formats.RTFormats[k]);
|
||||
std::memcpy(&host_stream[rt_at], &formats, sizeof(formats));
|
||||
}
|
||||
const size_t ds_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT);
|
||||
DXGI_FORMAT depth = DXGI_FORMAT_UNKNOWN;
|
||||
if (ds_at != SIZE_MAX) {
|
||||
std::memcpy(&depth, &host_stream[ds_at], sizeof(depth));
|
||||
depth = bx_host_format(depth);
|
||||
std::memcpy(&host_stream[ds_at], &depth, sizeof(depth));
|
||||
}
|
||||
const size_t topology_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY);
|
||||
bx_console_set_stream(t_pending_translated.get(), std::vector<uint8_t>(host_stream), std::move(elements), layout_at,
|
||||
rt_at, ds_at, topology_at);
|
||||
{
|
||||
char text[600];
|
||||
int at = 0;
|
||||
auto add = [&](const char* fmt, auto... args) {
|
||||
if (at < static_cast<int>(sizeof(text)) - 1) at += std::snprintf(text + at, sizeof(text) - at, fmt, args...);
|
||||
};
|
||||
const size_t blend_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND);
|
||||
if (blend_at != SIZE_MAX) {
|
||||
D3D12_BLEND_DESC b{};
|
||||
std::memcpy(&b, &host_stream[blend_at], sizeof(b));
|
||||
add("blend0 enable=%d src=%d dst=%d op=%d srcA=%d dstA=%d mask=0x%x a2c=%d indep=%d; ", b.RenderTarget[0].BlendEnable,
|
||||
b.RenderTarget[0].SrcBlend, b.RenderTarget[0].DestBlend, b.RenderTarget[0].BlendOp, b.RenderTarget[0].SrcBlendAlpha,
|
||||
b.RenderTarget[0].DestBlendAlpha, b.RenderTarget[0].RenderTargetWriteMask, b.AlphaToCoverageEnable,
|
||||
b.IndependentBlendEnable);
|
||||
} else add("no blend; ");
|
||||
const size_t mask_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK);
|
||||
if (mask_at != SIZE_MAX) {
|
||||
UINT m = 0;
|
||||
std::memcpy(&m, &host_stream[mask_at], sizeof(m));
|
||||
add("sample_mask=0x%x; ", m);
|
||||
} else add("no sample mask; ");
|
||||
const size_t rs_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER);
|
||||
if (rs_at != SIZE_MAX) {
|
||||
D3D12_RASTERIZER_DESC r{};
|
||||
std::memcpy(&r, &host_stream[rs_at], sizeof(r));
|
||||
add("fill=%d cull=%d ccw=%d clip=%d ms=%d forced=%u cons=%d; ", r.FillMode, r.CullMode, r.FrontCounterClockwise,
|
||||
r.DepthClipEnable, r.MultisampleEnable, r.ForcedSampleCount, r.ConservativeRaster);
|
||||
} else add("no rasterizer; ");
|
||||
for (auto type : {D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1}) {
|
||||
const size_t ds = bx_stream_payload(host_stream, type);
|
||||
if (ds == SIZE_MAX) continue;
|
||||
D3D12_DEPTH_STENCIL_DESC d{};
|
||||
std::memcpy(&d, &host_stream[ds], sizeof(d));
|
||||
add("depth%d enable=%d write=%d func=%d stencil=%d rmask=0x%x front(func=%d); ",
|
||||
type == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1, d.DepthEnable, d.DepthWriteMask, d.DepthFunc,
|
||||
d.StencilEnable, d.StencilReadMask, d.FrontFace.StencilFunc);
|
||||
}
|
||||
const size_t topo_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY);
|
||||
if (topo_at != SIZE_MAX) {
|
||||
UINT topo = 0;
|
||||
std::memcpy(&topo, &host_stream[topo_at], sizeof(topo));
|
||||
add("topology_type=%u; ", topo);
|
||||
} else add("no topology type; ");
|
||||
const size_t sd_at = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC);
|
||||
if (sd_at != SIZE_MAX) {
|
||||
DXGI_SAMPLE_DESC sd{};
|
||||
std::memcpy(&sd, &host_stream[sd_at], sizeof(sd));
|
||||
add("samples=%u/%u", sd.Count, sd.Quality);
|
||||
} else add("no sample desc");
|
||||
bx_console_stream_state(bx_console_key(t_pending_translated.get()), text);
|
||||
{ // every subobject in the stream: type and the first words of its payload
|
||||
char list_text[640];
|
||||
int lt = 0;
|
||||
for (uint32_t type = 0; type < 32 && lt < static_cast<int>(sizeof(list_text)) - 60; ++type) {
|
||||
const size_t at = bx_stream_payload(host_stream, type);
|
||||
if (at == SIZE_MAX) continue;
|
||||
uint32_t w[4] = {};
|
||||
std::memcpy(w, &host_stream[at], std::min<size_t>(sizeof(w), host_stream.size() - at));
|
||||
lt += std::snprintf(list_text + lt, sizeof(list_text) - lt, " t%u@%zu[%x %x %x %x]", type, at, w[0], w[1], w[2], w[3]);
|
||||
}
|
||||
std::string k = std::string(bx_console_key(t_pending_translated.get())) + "#subobjects";
|
||||
bx_console_stream_state(k.c_str(), list_text);
|
||||
const size_t ds1 = bx_stream_payload(host_stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1);
|
||||
if (ds1 != SIZE_MAX) {
|
||||
D3D12_DEPTH_STENCIL_DESC1 d1{};
|
||||
std::memcpy(&d1, &host_stream[ds1], sizeof(d1));
|
||||
char dt[120];
|
||||
std::snprintf(dt, sizeof(dt), "depth bounds test enable=%d (size of stream %zu)", d1.DepthBoundsTestEnable, host_stream.size());
|
||||
k = std::string(bx_console_key(t_pending_translated.get())) + "#depthbounds";
|
||||
bx_console_stream_state(k.c_str(), dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return refused(device, hr, "stream", riid, ppv);
|
||||
}
|
||||
return bx_xbox_wrap_result(hr, riid, ppv);
|
||||
}
|
||||
|
||||
@@ -274,6 +530,7 @@ void bx_xbox_pipeline_forget(IUnknown* host) {
|
||||
}
|
||||
|
||||
void bx_xbox_list_forget(IUnknown* host) {
|
||||
bx_console_list_reset(static_cast<ID3D12GraphicsCommandList*>(static_cast<void*>(host)));
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
erase(g_lists, g_list_count, static_cast<ID3D12GraphicsCommandList*>(static_cast<void*>(host)));
|
||||
}
|
||||
@@ -312,8 +569,10 @@ void STDMETHODCALLTYPE bx_xbox_list_set_pipeline_state(void* self, ID3D12Pipelin
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "SetPipelineState");
|
||||
auto* list = bx_xbox_host<ID3D12GraphicsCommandList>(self);
|
||||
bool is_null = false;
|
||||
ID3D12PipelineState* host = host_pipeline(pso, &is_null);
|
||||
set_list_null(list, is_null);
|
||||
uint32_t null_id = 0;
|
||||
std::shared_ptr<BxTranslated> translated;
|
||||
ID3D12PipelineState* host = host_pipeline(pso, &is_null, &null_id, &translated);
|
||||
set_list_null(list, is_null, null_id, std::move(translated));
|
||||
if (!is_null) list->SetPipelineState(host);
|
||||
}
|
||||
|
||||
@@ -321,9 +580,12 @@ HRESULT STDMETHODCALLTYPE bx_xbox_list_reset(void* self, ID3D12CommandAllocator*
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "Reset");
|
||||
auto* list = bx_xbox_host<ID3D12GraphicsCommandList>(self);
|
||||
bool is_null = false;
|
||||
ID3D12PipelineState* host = host_pipeline(pso, &is_null);
|
||||
set_list_null(list, is_null);
|
||||
uint32_t null_id = 0;
|
||||
std::shared_ptr<BxTranslated> translated;
|
||||
ID3D12PipelineState* host = host_pipeline(pso, &is_null, &null_id, &translated);
|
||||
set_list_null(list, is_null, null_id, std::move(translated));
|
||||
bx_xbox_gpu_writes_reset(list);
|
||||
bx_console_list_reset(list);
|
||||
return list->Reset(bx_xbox_unwrap_as(allocator), host);
|
||||
}
|
||||
|
||||
@@ -331,14 +593,20 @@ void STDMETHODCALLTYPE bx_xbox_list_draw_instanced(void* self, UINT vertices, UI
|
||||
UINT first_instance) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "DrawInstanced");
|
||||
auto* list = bx_xbox_host<ID3D12GraphicsCommandList>(self);
|
||||
if (!list_skips(list, "DrawInstanced")) list->DrawInstanced(vertices, instances, first_vertex, first_instance);
|
||||
t_draw = {vertices, instances, first_vertex, 0, false};
|
||||
if (!list_skips(list, "DrawInstanced", true)) {
|
||||
if (!t_applied || !bx_console_draw_rect_list(t_applied.get(), list, vertices, instances, first_vertex, first_instance)) {
|
||||
list->DrawInstanced(vertices, instances, first_vertex, first_instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_list_draw_indexed_instanced(void* self, UINT indices, UINT instances, UINT first_index,
|
||||
INT base_vertex, UINT first_instance) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "DrawIndexedInstanced");
|
||||
auto* list = bx_xbox_host<ID3D12GraphicsCommandList>(self);
|
||||
if (!list_skips(list, "DrawIndexedInstanced")) {
|
||||
t_draw = {indices, instances, first_index, base_vertex, true};
|
||||
if (!list_skips(list, "DrawIndexedInstanced", true)) {
|
||||
list->DrawIndexedInstanced(indices, instances, first_index, base_vertex, first_instance);
|
||||
}
|
||||
}
|
||||
@@ -438,6 +706,85 @@ void STDMETHODCALLTYPE bx_xbox_allocator_set_callback_x(void*, void* callback, U
|
||||
|
||||
} // extern "C"
|
||||
|
||||
namespace {
|
||||
/* Layouts from the authorized GDK header (D3D12XBOX_DESERIALIZE_*_PIPELINE_STATE). */
|
||||
struct DeserializeShader {
|
||||
const void* instructions;
|
||||
SIZE_T instructions_size;
|
||||
const void* metadata;
|
||||
SIZE_T metadata_size;
|
||||
};
|
||||
struct DeserializeGraphics {
|
||||
ID3D12RootSignature* root;
|
||||
void* packet;
|
||||
SIZE_T packet_size;
|
||||
void* metadata;
|
||||
SIZE_T metadata_size;
|
||||
DeserializeShader stages[7]; // PS, VS, GS, ES, HS, LS, FS
|
||||
};
|
||||
struct DeserializeCompute {
|
||||
ID3D12RootSignature* root;
|
||||
void* packet;
|
||||
SIZE_T packet_size;
|
||||
void* metadata;
|
||||
SIZE_T metadata_size;
|
||||
DeserializeShader cs;
|
||||
};
|
||||
|
||||
uint64_t fnv1a(const void* data, size_t size) {
|
||||
uint64_t h = 1469598103934665603ull;
|
||||
const auto* p = static_cast<const uint8_t*>(data);
|
||||
for (size_t i = 0; data && i < size; ++i) h = (h ^ p[i]) * 1099511628211ull;
|
||||
return h;
|
||||
}
|
||||
|
||||
/* BX_PSO_DUMP=<folder> with BX_PSO_DUMP_HASHES=<hex,hex,...>: writes the stages whose
|
||||
instruction hash is listed (local evidence only). */
|
||||
void dump_blob(const char* name, uint64_t hash, const char* part, const void* data, size_t size) {
|
||||
static char folder[512] = {};
|
||||
static char hashes[1024] = {};
|
||||
static const bool on = [] {
|
||||
return GetEnvironmentVariableA("BX_PSO_DUMP", folder, sizeof(folder)) > 0 &&
|
||||
GetEnvironmentVariableA("BX_PSO_DUMP_HASHES", hashes, sizeof(hashes)) > 0;
|
||||
}();
|
||||
if (!on || !data || !size) return;
|
||||
char hex[20];
|
||||
std::snprintf(hex, sizeof(hex), "%016llx", static_cast<unsigned long long>(hash));
|
||||
if (!std::strstr(hashes, hex)) return;
|
||||
char path[640];
|
||||
std::snprintf(path, sizeof(path), "%s\\%s_%s.%s.bin", folder, hex, name, part);
|
||||
if (FILE* f = std::fopen(path, "wb")) {
|
||||
std::fwrite(data, 1, size, f);
|
||||
std::fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
size_t describe_stage(char* out, size_t room, const char* name, const DeserializeShader& s) {
|
||||
if (!s.instructions || !s.instructions_size || room < 2) return 0;
|
||||
{
|
||||
const uint64_t h = fnv1a(s.instructions, s.instructions_size);
|
||||
dump_blob(name, h, "code", s.instructions, s.instructions_size);
|
||||
dump_blob(name, h, "meta", s.metadata, s.metadata_size);
|
||||
}
|
||||
const int n = std::snprintf(out, room, " %s=%llu/%llu#%016llx", name,
|
||||
static_cast<unsigned long long>(s.instructions_size),
|
||||
static_cast<unsigned long long>(s.metadata_size),
|
||||
static_cast<unsigned long long>(fnv1a(s.instructions, s.instructions_size)));
|
||||
return n > 0 && static_cast<size_t>(n) < room ? static_cast<size_t>(n) : 0;
|
||||
}
|
||||
|
||||
thread_local char t_profile_buffer[1600];
|
||||
|
||||
size_t describe_header(const void* packet, SIZE_T packet_size, SIZE_T metadata_size) {
|
||||
dump_blob("pipeline", fnv1a(packet, packet_size), "packet", packet, packet_size);
|
||||
const int n = std::snprintf(t_profile_buffer, sizeof(t_profile_buffer), "packet=%llu#%016llx meta=%llu",
|
||||
static_cast<unsigned long long>(packet_size),
|
||||
static_cast<unsigned long long>(fnv1a(packet, packet_size)),
|
||||
static_cast<unsigned long long>(metadata_size));
|
||||
return n > 0 ? static_cast<size_t>(n) : 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/*
|
||||
* DeserializeGraphics/ComputePipelineStateX create a pipeline from a serialized console pipeline
|
||||
* (console shader code), which has no host form. They always fail with E_NOTIMPL and log
|
||||
@@ -471,7 +818,16 @@ namespace {
|
||||
HRESULT derived(ID3D12PipelineState* source, void** ppv, const char* kind) {
|
||||
if (!ppv) return E_POINTER;
|
||||
*ppv = nullptr;
|
||||
const bool from_null = bx_xbox_pipeline_is_null(source);
|
||||
bool from_null = false;
|
||||
uint32_t source_id = 0;
|
||||
std::shared_ptr<BxTranslated> inherited;
|
||||
host_pipeline(source, &from_null, &source_id, &inherited);
|
||||
t_pending_translated = std::move(inherited); // a derived pipeline runs the same shaders
|
||||
thread_local char derived_profile[48];
|
||||
if (pso_profile_enabled()) {
|
||||
std::snprintf(derived_profile, sizeof(derived_profile), "source=%u", source_id);
|
||||
t_pending_profile = derived_profile;
|
||||
}
|
||||
if (!from_null) {
|
||||
static std::atomic<int> logged{0};
|
||||
if (logged.fetch_add(1) < 4) {
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
* from GetGPUVirtualAddress. Keeping the shadow in step with later CPU writes, and translating
|
||||
* title addresses in GPU calls, are not done yet; both are logged when reached.
|
||||
*/
|
||||
#include "console_formats.h"
|
||||
#include "xbox_facade.h"
|
||||
#include "console_translate.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
@@ -102,6 +104,10 @@ HRESULT make_shadow(ID3D12Device* device, uint64_t title_va, const D3D12_RESOURC
|
||||
constexpr UINT kPcResourceFlags = 0x1FF;
|
||||
host_desc.Layout = buffer ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR : D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||
host_desc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(desc.Flags & kPcResourceFlags);
|
||||
if (bx_is_console_only_format(desc.Format)) {
|
||||
bx_note_console_format(desc.Format, "CreatePlacedResourceX");
|
||||
host_desc.Format = bx_host_resource_format(desc.Format);
|
||||
}
|
||||
ID3D12Resource* resource = nullptr;
|
||||
HRESULT hr = device->CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &host_desc, D3D12_RESOURCE_STATE_COMMON,
|
||||
nullptr, __uuidof(ID3D12Resource), reinterpret_cast<void**>(&resource));
|
||||
@@ -207,7 +213,9 @@ void STDMETHODCALLTYPE bx_xbox_device_create_placed_raw_srv_x(void* self, const
|
||||
if (!resource) return;
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC pc{};
|
||||
std::memcpy(&pc, xbox_desc, kPcViewDescBytes);
|
||||
device->CreateShaderResourceView(resource, &pc, bx_xbox_host_cpu_handle(dest));
|
||||
BxHostFormat<D3D12_SHADER_RESOURCE_VIEW_DESC> host;
|
||||
device->CreateShaderResourceView(resource, host.of(&pc, "CreatePlacedRawShaderResourceViewX"), bx_xbox_host_cpu_handle(dest));
|
||||
bx_console_mark_srv(dest.ptr, resource, &pc, view_location(xbox_desc), resource_desc->Width);
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_placed_raw_uav_x(void* self, const D3D12_RESOURCE_DESC* resource_desc,
|
||||
@@ -219,7 +227,7 @@ void STDMETHODCALLTYPE bx_xbox_device_create_placed_raw_uav_x(void* self, const
|
||||
if (!resource) return;
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC pc{};
|
||||
std::memcpy(&pc, xbox_desc, kPcViewDescBytes);
|
||||
device->CreateUnorderedAccessView(resource, nullptr, &pc, bx_xbox_host_cpu_handle(dest));
|
||||
bx_xbox_create_host_uav(device, resource, nullptr, &pc, bx_xbox_host_cpu_handle(dest), "CreatePlacedRawUnorderedAccessViewX");
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_placed_srv_x(void* self, ID3D12Resource* resource, const void* xbox_desc,
|
||||
@@ -227,8 +235,11 @@ void STDMETHODCALLTYPE bx_xbox_device_create_placed_srv_x(void* self, ID3D12Reso
|
||||
BX_D3D_TRACE("XboxDevice", "CreatePlacedShaderResourceViewX");
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC pc{};
|
||||
if (xbox_desc) std::memcpy(&pc, xbox_desc, kPcViewDescBytes);
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateShaderResourceView(bx_xbox_unwrap_as(resource), xbox_desc ? &pc : nullptr,
|
||||
bx_xbox_host_cpu_handle(dest));
|
||||
BxHostFormat<D3D12_SHADER_RESOURCE_VIEW_DESC> host;
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateShaderResourceView(
|
||||
bx_xbox_unwrap_as(resource), xbox_desc ? host.of(&pc, "CreatePlacedShaderResourceViewX") : nullptr,
|
||||
bx_xbox_host_cpu_handle(dest));
|
||||
bx_console_mark_srv(dest.ptr, bx_xbox_unwrap_as(resource), xbox_desc ? &pc : nullptr);
|
||||
}
|
||||
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_placed_uav_x(void* self, ID3D12Resource* resource, const void* xbox_desc,
|
||||
@@ -236,8 +247,20 @@ void STDMETHODCALLTYPE bx_xbox_device_create_placed_uav_x(void* self, ID3D12Reso
|
||||
BX_D3D_TRACE("XboxDevice", "CreatePlacedUnorderedAccessViewX");
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC pc{};
|
||||
if (xbox_desc) std::memcpy(&pc, xbox_desc, kPcViewDescBytes);
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateUnorderedAccessView(bx_xbox_unwrap_as(resource), nullptr,
|
||||
xbox_desc ? &pc : nullptr, bx_xbox_host_cpu_handle(dest));
|
||||
bx_xbox_create_host_uav(bx_xbox_host<ID3D12Device>(self), bx_xbox_unwrap_as(resource), nullptr, xbox_desc ? &pc : nullptr,
|
||||
bx_xbox_host_cpu_handle(dest), "CreatePlacedUnorderedAccessViewX");
|
||||
}
|
||||
|
||||
bool bx_xbox_try_host_gpu_va(D3D12_GPU_VIRTUAL_ADDRESS title, D3D12_GPU_VIRTUAL_ADDRESS* host) {
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
for (size_t i = 0; i < g_count; ++i) {
|
||||
const Shadow& s = g_shadows[i];
|
||||
if (title >= s.title_va && title < s.title_va + s.size) {
|
||||
*host = s.host->GetGPUVirtualAddress() + (title - s.title_va);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
D3D12_GPU_VIRTUAL_ADDRESS bx_xbox_host_gpu_va(D3D12_GPU_VIRTUAL_ADDRESS title) {
|
||||
@@ -250,6 +273,50 @@ D3D12_GPU_VIRTUAL_ADDRESS bx_xbox_host_gpu_va(D3D12_GPU_VIRTUAL_ADDRESS title) {
|
||||
return title; // not a title address this layer knows: a host address already, or untranslated
|
||||
}
|
||||
|
||||
/* Plain title memory bound as index or vertex data: a CPU-writable host buffer of the same size
|
||||
is created for the range (once; later ranges inside it reuse it) and refreshed at submission. */
|
||||
bool bx_xbox_back_title_buffer(ID3D12Device* device, uint64_t va, uint64_t size) {
|
||||
if (!device || !va || !size) return false;
|
||||
D3D12_GPU_VIRTUAL_ADDRESS host = 0;
|
||||
if (bx_xbox_try_host_gpu_va(va, &host) && bx_xbox_try_host_gpu_va(va + size - 1, &host)) return true;
|
||||
D3D12_RESOURCE_DESC desc{};
|
||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
desc.Width = size;
|
||||
desc.Height = 1;
|
||||
desc.DepthOrArraySize = 1;
|
||||
desc.MipLevels = 1;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
||||
ID3D12Resource* resource = nullptr;
|
||||
return SUCCEEDED(make_shadow(device, va, desc, "host buffer for bound title memory", &resource)) && resource;
|
||||
}
|
||||
|
||||
/* The title address a host shadow resource was created for (0 when it is not a shadow). */
|
||||
uint64_t bx_xbox_shadow_title_va(ID3D12Resource* host) {
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
for (size_t i = 0; i < g_count; ++i) {
|
||||
if (g_shadows[i].host == host) return g_shadows[i].title_va;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Copies [title_va, title_va + size) from title memory to the host shadow that
|
||||
bx_xbox_host_gpu_va resolves the address to (first match). False when there is none. */
|
||||
bool bx_xbox_sync_title_range(uint64_t title_va, uint64_t size) {
|
||||
if (!title_va || !size) return false;
|
||||
std::lock_guard<std::mutex> guard(g_lock);
|
||||
for (size_t i = 0; i < g_count; ++i) {
|
||||
const Shadow& s = g_shadows[i];
|
||||
if (title_va >= s.title_va && title_va < s.title_va + s.size) {
|
||||
const uint64_t begin = title_va - s.title_va;
|
||||
const uint64_t end = begin + size > s.size ? s.size : begin + size;
|
||||
if (!readable(reinterpret_cast<const void*>(title_va), end - begin)) return false;
|
||||
return copy_buffer(s, true, begin, end);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bx_xbox_title_memory_attach(ID3D12Resource* host, uint64_t title_va, uint64_t size, ULONGLONG attributes) {
|
||||
return remember({host, title_va, size, host->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER, host->GetDesc(),
|
||||
attributes});
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
* destination rectangles, colour spaces and scaling are not applied (logged once).
|
||||
*/
|
||||
#include "xbox_facade.h"
|
||||
#include "console_translate.h"
|
||||
|
||||
#include <dxgi1_4.h>
|
||||
|
||||
@@ -186,9 +187,10 @@ UINT64 dump_every() {
|
||||
return every;
|
||||
}
|
||||
|
||||
void dump_frame(ID3D12CommandQueue* queue, ID3D12Resource* source, const D3D12_RESOURCE_DESC& desc, UINT64 frame) {
|
||||
void dump_frame(ID3D12CommandQueue* queue, ID3D12Resource* source, const D3D12_RESOURCE_DESC& desc, UINT64 frame,
|
||||
const wchar_t* tag = L"frame") {
|
||||
static int written = 0;
|
||||
if (written >= 32 || desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) return;
|
||||
if (written >= 160 || desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) return;
|
||||
const DXGI_FORMAT f = desc.Format;
|
||||
const bool bgra = f == DXGI_FORMAT_B8G8R8A8_UNORM || f == DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
|
||||
const bool rgba = f == DXGI_FORMAT_R8G8B8A8_UNORM || f == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
||||
@@ -255,7 +257,7 @@ void dump_frame(ID3D12CommandQueue* queue, ID3D12Resource* source, const D3D12_R
|
||||
}
|
||||
readback->Unmap(0, nullptr);
|
||||
wchar_t path[MAX_PATH];
|
||||
std::swprintf(path, MAX_PATH, L"%ls\\frame_%06llu.bmp", dump_folder(), static_cast<unsigned long long>(frame));
|
||||
std::swprintf(path, MAX_PATH, L"%ls\\%ls_%06llu.bmp", dump_folder(), tag, static_cast<unsigned long long>(frame));
|
||||
HANDLE file = CreateFileW(path, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (file != INVALID_HANDLE_VALUE) {
|
||||
DWORD wrote = 0;
|
||||
@@ -289,6 +291,18 @@ extern "C" HRESULT STDMETHODCALLTYPE bx_xbox_queue_present_x(void* self, UINT pl
|
||||
std::lock_guard<std::mutex> guard(g.lock);
|
||||
if (g.failed) return S_OK;
|
||||
const D3D12_RESOURCE_DESC desc = source->GetDesc();
|
||||
{ // diagnostic: which buffer is presented
|
||||
static ID3D12Resource* last = nullptr;
|
||||
static std::atomic<int> shown{0};
|
||||
if (source != last && shown.fetch_add(1) < 12) {
|
||||
char detail[160];
|
||||
std::snprintf(detail, sizeof(detail), "presented buffer %p %llux%u format=%d planes=%u resources=%u", static_cast<void*>(source),
|
||||
static_cast<unsigned long long>(desc.Width), desc.Height, static_cast<int>(desc.Format), plane_count,
|
||||
planes[0].ResourceCount);
|
||||
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "console_target", detail);
|
||||
}
|
||||
last = source;
|
||||
}
|
||||
if (!g.swapchain && !create_locked(queue, desc)) {
|
||||
g.failed = true;
|
||||
return S_OK; // the title keeps running; frames are not shown (logged)
|
||||
@@ -340,6 +354,16 @@ extern "C" HRESULT STDMETHODCALLTYPE bx_xbox_queue_present_x(void* self, UINT pl
|
||||
g.queue->Signal(g.fence, g.fence_values[index]);
|
||||
const UINT64 n = ++g.presents;
|
||||
if (dump_folder() && copyable && n % dump_every() == 0) dump_frame(g.queue, source, desc, n);
|
||||
if (dump_folder() && n % dump_every() == 0) { // diagnostic: the targets translated draws went into
|
||||
ID3D12Resource* targets[8];
|
||||
const int count = bx_console_debug_targets(targets, 8);
|
||||
for (int k = 0; k < count; ++k) {
|
||||
if (targets[k] == source) continue;
|
||||
wchar_t tag[32];
|
||||
std::swprintf(tag, 32, L"target%d", k);
|
||||
dump_frame(g.queue, targets[k], targets[k]->GetDesc(), n, tag);
|
||||
}
|
||||
}
|
||||
if ((n & (n - 1)) == 0) {
|
||||
char detail[96];
|
||||
std::snprintf(detail, sizeof(detail), "frames presented=%llu last hr=0x%08lx", static_cast<unsigned long long>(n),
|
||||
|
||||
@@ -559,6 +559,19 @@ HRESULT copy_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, std::vector<ui
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
size_t bx_stream_payload(const std::vector<uint8_t>& stream, uint32_t type) {
|
||||
size_t offset = 0;
|
||||
while (offset + sizeof(SIZE_T) <= stream.size()) {
|
||||
uint32_t raw = 0;
|
||||
std::memcpy(&raw, &stream[offset], sizeof(raw));
|
||||
const StreamSubobject* entry = find_subobject(raw);
|
||||
if (!entry) return SIZE_MAX;
|
||||
if (raw == type) return offset + entry->payload_offset;
|
||||
offset += entry->record_size;
|
||||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE BxDeviceProxy::CreatePipelineState(const D3D12_PIPELINE_STATE_STREAM_DESC* desc, REFIID riid, void** ppv) {
|
||||
BX_D3D_TRACE("ID3D12Device2", "CreatePipelineState");
|
||||
if (!h_ID3D12Device2) {
|
||||
|
||||
@@ -124,3 +124,5 @@ using BxCommandListProxy = BxChildProxy<BxCommandListProxyGen>;
|
||||
HRESULT copy_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, std::vector<uint8_t>& copy,
|
||||
std::vector<size_t>& stage_offsets, std::vector<const char*>& stage_names,
|
||||
size_t* root_offset);
|
||||
/* The payload offset of the subobject of `type` in a stream copy_stream accepted, or SIZE_MAX. */
|
||||
size_t bx_stream_payload(const std::vector<uint8_t>& stream, uint32_t type);
|
||||
@@ -71,6 +71,15 @@ CUSTOM = {
|
||||
"CreateGraphicsPipelineState": "bx_xbox_device_create_graphics_pipeline_state",
|
||||
"CreateComputePipelineStateX": "bx_xbox_device_create_compute_pipeline_state_x",
|
||||
"CreateGraphicsPipelineStateX": "bx_xbox_device_create_graphics_pipeline_state_x",
|
||||
"GetResourceAllocationInfo": "bx_xbox_device_get_resource_allocation_info",
|
||||
"GetResourceAllocationInfo1": "bx_xbox_device_get_resource_allocation_info1",
|
||||
"GetResourceAllocationInfo2": "bx_xbox_device_get_resource_allocation_info2",
|
||||
"CreatePlacedResource": "bx_xbox_device_create_placed_resource",
|
||||
"CreateReservedResource": "bx_xbox_device_create_reserved_resource",
|
||||
"CreateShaderResourceView": "bx_xbox_device_create_shader_resource_view",
|
||||
"CreateUnorderedAccessView": "bx_xbox_device_create_unordered_access_view",
|
||||
"CreateRenderTargetView": "bx_xbox_device_create_render_target_view",
|
||||
"CreateDepthStencilView": "bx_xbox_device_create_depth_stencil_view",
|
||||
"CreateCommittedResource": "bx_xbox_device_create_committed_resource",
|
||||
"CreateCommittedResource1": "bx_xbox_device_create_committed_resource1",
|
||||
"CreateCommittedResource2": "bx_xbox_device_create_committed_resource2",
|
||||
|
||||
@@ -176,6 +176,9 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_wait_frame_event_x(void* self, UINT typ
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE bx_xbox_host_cpu_handle(D3D12_CPU_DESCRIPTOR_HANDLE title);
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE bx_xbox_host_gpu_handle(D3D12_GPU_DESCRIPTOR_HANDLE title);
|
||||
D3D12_GPU_VIRTUAL_ADDRESS bx_xbox_host_gpu_va(D3D12_GPU_VIRTUAL_ADDRESS title);
|
||||
/* True, with the host address in *host, when `title` lies in memory this layer has a host buffer
|
||||
* for; false (and *host untouched) otherwise. */
|
||||
bool bx_xbox_try_host_gpu_va(D3D12_GPU_VIRTUAL_ADDRESS title, D3D12_GPU_VIRTUAL_ADDRESS* host);
|
||||
UINT bx_xbox_descriptor_size(D3D12_DESCRIPTOR_HEAP_TYPE type);
|
||||
void bx_xbox_descriptor_heap_forget(IUnknown* host);
|
||||
/* Records title-visible memory (from XMemAlloc) for a host resource; freed when it is released. */
|
||||
@@ -290,6 +293,38 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource3(void* self,
|
||||
ID3D12ProtectedResourceSession* session, UINT32 formats,
|
||||
DXGI_FORMAT* castable, REFIID riid, void** ppv);
|
||||
|
||||
/* Creates an unordered-access view on the host, or a null view (logged as unimplemented) when the
|
||||
* resource is a depth-stencil texture, which the host cannot give one (console_formats.cpp). */
|
||||
void bx_xbox_create_host_uav(ID3D12Device* device, ID3D12Resource* host, ID3D12Resource* counter,
|
||||
const D3D12_UNORDERED_ACCESS_VIEW_DESC* desc, D3D12_CPU_DESCRIPTOR_HANDLE host_dest,
|
||||
const char* method);
|
||||
|
||||
/* Entry points that only translate console-only formats before the host call (console_formats.cpp). */
|
||||
D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE bx_xbox_device_get_resource_allocation_info(void* self, UINT mask, UINT count,
|
||||
const D3D12_RESOURCE_DESC* descs);
|
||||
D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE bx_xbox_device_get_resource_allocation_info1(
|
||||
void* self, UINT mask, UINT count, const D3D12_RESOURCE_DESC* descs, D3D12_RESOURCE_ALLOCATION_INFO1* each);
|
||||
D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE bx_xbox_device_get_resource_allocation_info2(
|
||||
void* self, UINT mask, UINT count, const D3D12_RESOURCE_DESC1* descs, D3D12_RESOURCE_ALLOCATION_INFO1* each);
|
||||
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_placed_resource(void* self, ID3D12Heap* heap, UINT64 offset,
|
||||
const D3D12_RESOURCE_DESC* desc, D3D12_RESOURCE_STATES state,
|
||||
const D3D12_CLEAR_VALUE* clear, REFIID riid, void** ppv);
|
||||
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_reserved_resource(void* self, const D3D12_RESOURCE_DESC* desc,
|
||||
D3D12_RESOURCE_STATES state, const D3D12_CLEAR_VALUE* clear,
|
||||
REFIID riid, void** ppv);
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_shader_resource_view(void* self, ID3D12Resource* resource,
|
||||
const D3D12_SHADER_RESOURCE_VIEW_DESC* desc,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dest);
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_unordered_access_view(void* self, ID3D12Resource* resource, ID3D12Resource* counter,
|
||||
const D3D12_UNORDERED_ACCESS_VIEW_DESC* desc,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dest);
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_render_target_view(void* self, ID3D12Resource* resource,
|
||||
const D3D12_RENDER_TARGET_VIEW_DESC* desc,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dest);
|
||||
void STDMETHODCALLTYPE bx_xbox_device_create_depth_stencil_view(void* self, ID3D12Resource* resource,
|
||||
const D3D12_DEPTH_STENCIL_VIEW_DESC* desc,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dest);
|
||||
|
||||
/* Descriptor heaps with title-visible storage (descriptor_heaps.cpp). */
|
||||
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_descriptor_heap(void* self, const D3D12_DESCRIPTOR_HEAP_DESC* desc,
|
||||
REFIID riid, void** ppv);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Generated by shims/d3d12_xs/tools/gen_xbox_tables.py from the Xbox Series D3D12 header (slot
|
||||
// order, names and types only) and the toolchain's <d3d12.h>. Do not edit by hand.
|
||||
#include "xbox_tables_generated.h"
|
||||
#include "console_translate.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -58,26 +59,16 @@ static HRESULT STDMETHODCALLTYPE x_Device_13(void* self, D3D12_FEATURE a0, void
|
||||
}
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_16(void* self, UINT a0, const void * a1, SIZE_T a2, REFIID a3, void ** a4) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateRootSignature");
|
||||
HRESULT hr = bx_xbox_host<ID3D12Device>(self)->CreateRootSignature(a0, a1, a2, a3, a4);
|
||||
HRESULT hr = E_FAIL;
|
||||
if (ID3DBlob* wide = bx_console_widen_root_signature(a1, a2)) { // opt-in console translation
|
||||
hr = bx_xbox_host<ID3D12Device>(self)->CreateRootSignature(a0, wide->GetBufferPointer(), wide->GetBufferSize(), a3, a4);
|
||||
wide->Release();
|
||||
}
|
||||
if (FAILED(hr)) hr = bx_xbox_host<ID3D12Device>(self)->CreateRootSignature(a0, a1, a2, a3, a4);
|
||||
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreateRootSignature", hr);
|
||||
if (SUCCEEDED(hr) && a4 && *a4) bx_console_root_signature_created(static_cast<ID3D12RootSignature*>(*a4), a1, a2);
|
||||
return bx_xbox_wrap_result(hr, a3, a4);
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_Device_18(void* self, ID3D12Resource * a0, const D3D12_SHADER_RESOURCE_VIEW_DESC * a1, D3D12_CPU_DESCRIPTOR_HANDLE a2) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateShaderResourceView");
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateShaderResourceView(bx_xbox_unwrap_as<ID3D12Resource>(a0), a1, bx_xbox_host_cpu_handle(a2));
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_Device_19(void* self, ID3D12Resource * a0, ID3D12Resource * a1, const D3D12_UNORDERED_ACCESS_VIEW_DESC * a2, D3D12_CPU_DESCRIPTOR_HANDLE a3) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateUnorderedAccessView");
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateUnorderedAccessView(bx_xbox_unwrap_as<ID3D12Resource>(a0), bx_xbox_unwrap_as<ID3D12Resource>(a1), a2, bx_xbox_host_cpu_handle(a3));
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_Device_20(void* self, ID3D12Resource * a0, const D3D12_RENDER_TARGET_VIEW_DESC * a1, D3D12_CPU_DESCRIPTOR_HANDLE a2) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateRenderTargetView");
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateRenderTargetView(bx_xbox_unwrap_as<ID3D12Resource>(a0), a1, bx_xbox_host_cpu_handle(a2));
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_Device_21(void* self, ID3D12Resource * a0, const D3D12_DEPTH_STENCIL_VIEW_DESC * a1, D3D12_CPU_DESCRIPTOR_HANDLE a2) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateDepthStencilView");
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateDepthStencilView(bx_xbox_unwrap_as<ID3D12Resource>(a0), a1, bx_xbox_host_cpu_handle(a2));
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_Device_22(void* self, const D3D12_SAMPLER_DESC * a0, D3D12_CPU_DESCRIPTOR_HANDLE a1) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateSampler");
|
||||
bx_xbox_host<ID3D12Device>(self)->CreateSampler(a0, bx_xbox_host_cpu_handle(a1));
|
||||
@@ -85,12 +76,7 @@ static void STDMETHODCALLTYPE x_Device_22(void* self, const D3D12_SAMPLER_DESC *
|
||||
static void STDMETHODCALLTYPE x_Device_24(void* self, UINT a0, const D3D12_CPU_DESCRIPTOR_HANDLE a1, const D3D12_CPU_DESCRIPTOR_HANDLE a2, D3D12_DESCRIPTOR_HEAP_TYPE a3) {
|
||||
BX_D3D_TRACE("XboxDevice", "CopyDescriptorsSimple");
|
||||
bx_xbox_host<ID3D12Device>(self)->CopyDescriptorsSimple(a0, bx_xbox_host_cpu_handle(a1), bx_xbox_host_cpu_handle(a2), a3);
|
||||
}
|
||||
static D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE x_Device_25(void* self, UINT a0, UINT a1, const D3D12_RESOURCE_DESC * a2) {
|
||||
BX_D3D_TRACE("XboxDevice", "GetResourceAllocationInfo");
|
||||
D3D12_RESOURCE_ALLOCATION_INFO result{};
|
||||
bx_xbox_host<ID3D12Device>(self)->GetResourceAllocationInfo(&result, a0, a1, a2);
|
||||
return result;
|
||||
if (a3 == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) bx_console_copy_title(a1.ptr, a2.ptr, a0);
|
||||
}
|
||||
static D3D12_HEAP_PROPERTIES STDMETHODCALLTYPE x_Device_26(void* self, UINT a0, D3D12_HEAP_TYPE a1) {
|
||||
BX_D3D_TRACE("XboxDevice", "GetCustomHeapProperties");
|
||||
@@ -104,18 +90,6 @@ static HRESULT STDMETHODCALLTYPE x_Device_28(void* self, const D3D12_HEAP_DESC *
|
||||
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreateHeap", hr);
|
||||
return bx_xbox_wrap_result(hr, a1, a2);
|
||||
}
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_29(void* self, ID3D12Heap * a0, UINT64 a1, const D3D12_RESOURCE_DESC * a2, D3D12_RESOURCE_STATES a3, const D3D12_CLEAR_VALUE * a4, REFIID a5, void ** a6) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreatePlacedResource");
|
||||
HRESULT hr = bx_xbox_host<ID3D12Device>(self)->CreatePlacedResource(bx_xbox_unwrap_as<ID3D12Heap>(a0), a1, a2, a3, a4, a5, a6);
|
||||
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreatePlacedResource", hr);
|
||||
return bx_xbox_wrap_result(hr, a5, a6);
|
||||
}
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_30(void* self, const D3D12_RESOURCE_DESC * a0, D3D12_RESOURCE_STATES a1, const D3D12_CLEAR_VALUE * a2, REFIID a3, void ** a4) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateReservedResource");
|
||||
HRESULT hr = bx_xbox_host<ID3D12Device>(self)->CreateReservedResource(a0, a1, a2, a3, a4);
|
||||
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreateReservedResource", hr);
|
||||
return bx_xbox_wrap_result(hr, a3, a4);
|
||||
}
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_31(void* self, ID3D12DeviceChild * a0, const SECURITY_ATTRIBUTES * a1, DWORD a2, const WCHAR * a3, HANDLE * a4) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateSharedHandle");
|
||||
HRESULT hr = bx_xbox_host<ID3D12Device>(self)->CreateSharedHandle(bx_xbox_unwrap_as<ID3D12DeviceChild>(a0), a1, a2, a3, a4);
|
||||
@@ -225,7 +199,7 @@ static HRESULT STDMETHODCALLTYPE x_Device_76(void*) { BX_VTABLE_STUB_LOG("XboxDe
|
||||
/* Xbox-only method */
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_77(void*) { BX_VTABLE_STUB_LOG("XboxDevice", 77u, "CreateComponentPlacedResourceX1"); return E_NOTIMPL; }
|
||||
/* Xbox-only method */
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_81(void*) { BX_VTABLE_STUB_LOG("XboxDevice", 81u, "GetFrameStatisticsX"); return E_NOTIMPL; }
|
||||
extern "C" HRESULT STDMETHODCALLTYPE bx_xbox_device_get_frame_statistics_x(void*, UINT64, UINT, UINT*, void*);
|
||||
/* Xbox-only method */
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_82(void*) { BX_VTABLE_STUB_LOG("XboxDevice", 82u, "CreateCounterSetX"); return E_NOTIMPL; }
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_83(void* self, const void * a0, SIZE_T a1, REFIID a2, void ** a3) {
|
||||
@@ -294,12 +268,6 @@ static HRESULT STDMETHODCALLTYPE x_Device_94(void* self, const D3D12_RESOURCE_DE
|
||||
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreateReservedResource1", hr);
|
||||
return bx_xbox_wrap_result(hr, a4, a5);
|
||||
}
|
||||
static D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE x_Device_95(void* self, UINT a0, UINT a1, const D3D12_RESOURCE_DESC * a2, D3D12_RESOURCE_ALLOCATION_INFO1 * a3) {
|
||||
BX_D3D_TRACE("XboxDevice", "GetResourceAllocationInfo1");
|
||||
D3D12_RESOURCE_ALLOCATION_INFO result{};
|
||||
bx_xbox_host<ID3D12Device4>(self)->GetResourceAllocationInfo1(&result, a0, a1, a2, a3);
|
||||
return result;
|
||||
}
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_96(void* self, ID3D12LifetimeOwner * a0, REFIID a1, void ** a2) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreateLifetimeTracker");
|
||||
HRESULT hr = bx_xbox_host<ID3D12Device5>(self)->CreateLifetimeTracker(bx_xbox_unwrap_as<ID3D12LifetimeOwner>(a0), a1, a2);
|
||||
@@ -362,12 +330,6 @@ static HRESULT STDMETHODCALLTYPE x_Device_107(void* self, const D3D12_PROTECTED_
|
||||
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreateProtectedResourceSession1", hr);
|
||||
return bx_xbox_wrap_result(hr, a1, a2);
|
||||
}
|
||||
static D3D12_RESOURCE_ALLOCATION_INFO STDMETHODCALLTYPE x_Device_108(void* self, UINT a0, UINT a1, const D3D12_RESOURCE_DESC1 * a2, D3D12_RESOURCE_ALLOCATION_INFO1 * a3) {
|
||||
BX_D3D_TRACE("XboxDevice", "GetResourceAllocationInfo2");
|
||||
D3D12_RESOURCE_ALLOCATION_INFO result{};
|
||||
bx_xbox_host<ID3D12Device8>(self)->GetResourceAllocationInfo2(&result, a0, a1, a2, a3);
|
||||
return result;
|
||||
}
|
||||
static HRESULT STDMETHODCALLTYPE x_Device_110(void* self, ID3D12Heap * a0, UINT64 a1, const D3D12_RESOURCE_DESC1 * a2, D3D12_RESOURCE_STATES a3, const D3D12_CLEAR_VALUE * a4, REFIID a5, void ** a6) {
|
||||
BX_D3D_TRACE("XboxDevice", "CreatePlacedResource1");
|
||||
HRESULT hr = bx_xbox_host<ID3D12Device8>(self)->CreatePlacedResource1(bx_xbox_unwrap_as<ID3D12Heap>(a0), a1, a2, a3, a4, a5, a6);
|
||||
@@ -468,19 +430,19 @@ const void* const kDeviceTable[] = {
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_get_descriptor_handle_increment_size),
|
||||
reinterpret_cast<const void*>(&x_Device_16),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_constant_buffer_view),
|
||||
reinterpret_cast<const void*>(&x_Device_18),
|
||||
reinterpret_cast<const void*>(&x_Device_19),
|
||||
reinterpret_cast<const void*>(&x_Device_20),
|
||||
reinterpret_cast<const void*>(&x_Device_21),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_shader_resource_view),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_unordered_access_view),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_render_target_view),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_depth_stencil_view),
|
||||
reinterpret_cast<const void*>(&x_Device_22),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_copy_descriptors),
|
||||
reinterpret_cast<const void*>(&x_Device_24),
|
||||
reinterpret_cast<const void*>(&x_Device_25),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_get_resource_allocation_info),
|
||||
reinterpret_cast<const void*>(&x_Device_26),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_committed_resource),
|
||||
reinterpret_cast<const void*>(&x_Device_28),
|
||||
reinterpret_cast<const void*>(&x_Device_29),
|
||||
reinterpret_cast<const void*>(&x_Device_30),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_placed_resource),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_reserved_resource),
|
||||
reinterpret_cast<const void*>(&x_Device_31),
|
||||
reinterpret_cast<const void*>(&x_Device_32),
|
||||
reinterpret_cast<const void*>(&x_Device_33),
|
||||
@@ -531,7 +493,7 @@ const void* const kDeviceTable[] = {
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_set_frame_interval_x),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_schedule_frame_event_x),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_wait_frame_event_x),
|
||||
reinterpret_cast<const void*>(&x_Device_81),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_get_frame_statistics_x),
|
||||
reinterpret_cast<const void*>(&x_Device_82),
|
||||
reinterpret_cast<const void*>(&x_Device_83),
|
||||
reinterpret_cast<const void*>(&x_Device_84),
|
||||
@@ -545,7 +507,7 @@ const void* const kDeviceTable[] = {
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_committed_resource1),
|
||||
reinterpret_cast<const void*>(&x_Device_93),
|
||||
reinterpret_cast<const void*>(&x_Device_94),
|
||||
reinterpret_cast<const void*>(&x_Device_95),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_get_resource_allocation_info1),
|
||||
reinterpret_cast<const void*>(&x_Device_96),
|
||||
reinterpret_cast<const void*>(&x_Device_97),
|
||||
reinterpret_cast<const void*>(&x_Device_98),
|
||||
@@ -558,7 +520,7 @@ const void* const kDeviceTable[] = {
|
||||
reinterpret_cast<const void*>(&x_Device_105),
|
||||
reinterpret_cast<const void*>(&x_Device_106),
|
||||
reinterpret_cast<const void*>(&x_Device_107),
|
||||
reinterpret_cast<const void*>(&x_Device_108),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_get_resource_allocation_info2),
|
||||
reinterpret_cast<const void*>(&bx_xbox_device_create_committed_resource2),
|
||||
reinterpret_cast<const void*>(&x_Device_110),
|
||||
reinterpret_cast<const void*>(&x_Device_111),
|
||||
@@ -607,7 +569,7 @@ const IID kDeviceIids[] = {
|
||||
{0xc4fec28f, 0x7966, 0x4e95, {0x9f, 0x94, 0xf4, 0x31, 0xcb, 0x56, 0xc3, 0xb8}}, /* ID3D12Object */
|
||||
};
|
||||
|
||||
/* ID3D12Device11: 139 slots (63 forwarded, 35 shared, 41 stubs); hosted on ID3D12Device10. */
|
||||
/* ID3D12Device11: 139 slots (54 forwarded, 44 shared, 41 stubs); hosted on ID3D12Device10. */
|
||||
const IID kHostDevice = __uuidof(ID3D12Device10);
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE x_Resource_3(void* self, REFGUID a0, UINT * a1, void * a2) {
|
||||
@@ -1351,14 +1313,19 @@ static void STDMETHODCALLTYPE x_GraphicsCommandList_19(void* self, ID3D12Resourc
|
||||
static void STDMETHODCALLTYPE x_GraphicsCommandList_20(void* self, D3D12_PRIMITIVE_TOPOLOGY a0) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "IASetPrimitiveTopology");
|
||||
bx_xbox_host<ID3D12GraphicsCommandList>(self)->IASetPrimitiveTopology(a0);
|
||||
bx_console_note_topology(bx_xbox_host<ID3D12GraphicsCommandList>(self), a0);
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_GraphicsCommandList_21(void* self, UINT a0, const D3D12_VIEWPORT * a1) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "RSSetViewports");
|
||||
bx_xbox_host<ID3D12GraphicsCommandList>(self)->RSSetViewports(a0, a1);
|
||||
bx_console_note_raster(bx_xbox_host<ID3D12GraphicsCommandList>(self), true);
|
||||
bx_console_note_viewport(bx_xbox_host<ID3D12GraphicsCommandList>(self), a0, a1);
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_GraphicsCommandList_22(void* self, UINT a0, const D3D12_RECT * a1) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "RSSetScissorRects");
|
||||
bx_xbox_host<ID3D12GraphicsCommandList>(self)->RSSetScissorRects(a0, a1);
|
||||
bx_console_note_raster(bx_xbox_host<ID3D12GraphicsCommandList>(self), false);
|
||||
bx_console_note_scissor(bx_xbox_host<ID3D12GraphicsCommandList>(self), a0, a1);
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_GraphicsCommandList_23(void* self, const FLOAT a0[4]) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "OMSetBlendFactor");
|
||||
@@ -1409,6 +1376,7 @@ static void STDMETHODCALLTYPE x_GraphicsCommandList_35(void* self, UINT a0, D3D1
|
||||
static void STDMETHODCALLTYPE x_GraphicsCommandList_36(void* self, UINT a0, D3D12_GPU_DESCRIPTOR_HANDLE a1) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "SetGraphicsRootDescriptorTable");
|
||||
bx_xbox_host<ID3D12GraphicsCommandList>(self)->SetGraphicsRootDescriptorTable(a0, bx_xbox_host_gpu_handle(a1));
|
||||
bx_console_note_table(bx_xbox_host<ID3D12GraphicsCommandList>(self), a0, a1.ptr);
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_GraphicsCommandList_37(void* self, UINT a0, UINT a1, UINT a2) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "SetComputeRoot32BitConstant");
|
||||
@@ -1441,6 +1409,7 @@ static void STDMETHODCALLTYPE x_GraphicsCommandList_43(void* self, UINT a0, D3D1
|
||||
static void STDMETHODCALLTYPE x_GraphicsCommandList_44(void* self, UINT a0, D3D12_GPU_VIRTUAL_ADDRESS a1) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "SetGraphicsRootShaderResourceView");
|
||||
bx_xbox_host<ID3D12GraphicsCommandList>(self)->SetGraphicsRootShaderResourceView(a0, bx_xbox_host_gpu_va(a1));
|
||||
bx_console_note_root_srv(bx_xbox_host<ID3D12GraphicsCommandList>(self), a0, a1);
|
||||
}
|
||||
static void STDMETHODCALLTYPE x_GraphicsCommandList_45(void* self, UINT a0, D3D12_GPU_VIRTUAL_ADDRESS a1) {
|
||||
BX_D3D_TRACE("XboxGraphicsCommandList", "SetComputeRootUnorderedAccessView");
|
||||
|
||||
@@ -786,8 +786,6 @@ BX_HR(gs_quota_result, "IXGameSaveImpl", 9, "XGameSaveGetRemainingQuotaResult")
|
||||
BX_HR(gs_delete, "IXGameSaveImpl", 10, "XGameSaveDeleteContainer")
|
||||
BX_HR(gs_delete_async, "IXGameSaveImpl", 11, "XGameSaveDeleteContainerAsync")
|
||||
BX_HR(gs_delete_result, "IXGameSaveImpl", 12, "XGameSaveDeleteContainerResult")
|
||||
BX_HR(gs_container_info, "IXGameSaveImpl", 13, "XGameSaveGetContainerInfo")
|
||||
BX_HR(gs_enum_by_name, "IXGameSaveImpl", 15, "XGameSaveEnumerateContainerInfoByName")
|
||||
BX_HR(gs_enum_blobs, "IXGameSaveImpl", 18, "XGameSaveEnumerateBlobInfo")
|
||||
BX_HR(gs_enum_blobs_by_name, "IXGameSaveImpl", 19, "XGameSaveEnumerateBlobInfoByName")
|
||||
BX_HR(gs_blob_delete, "IXGameSaveImpl", 26, "XGameSaveSubmitBlobDelete")
|
||||
@@ -833,9 +831,9 @@ const std::array<const void*, 33> kGameSaveVtbl = [] {
|
||||
v[10] = reinterpret_cast<const void*>(&gs_delete);
|
||||
v[11] = reinterpret_cast<const void*>(&gs_delete_async);
|
||||
v[12] = reinterpret_cast<const void*>(&gs_delete_result);
|
||||
v[13] = reinterpret_cast<const void*>(&gs_container_info);
|
||||
v[13] = reinterpret_cast<const void*>(&get_container_info);
|
||||
v[14] = reinterpret_cast<const void*>(&enumerate_container_info);
|
||||
v[15] = reinterpret_cast<const void*>(&gs_enum_by_name);
|
||||
v[15] = reinterpret_cast<const void*>(&enumerate_container_info_by_name);
|
||||
v[16] = reinterpret_cast<const void*>(&create_container);
|
||||
v[17] = reinterpret_cast<const void*>(&close_container);
|
||||
v[18] = reinterpret_cast<const void*>(&gs_enum_blobs);
|
||||
|
||||
@@ -841,7 +841,55 @@ HRESULT WINAPI read_blob_data_result(void*, void* async, size_t size, void* blob
|
||||
});
|
||||
}
|
||||
|
||||
HRESULT WINAPI enumerate_container_info(void*, void* provider, void* context, GameSaveContainerInfoCallback callback) {
|
||||
HRESULT WINAPI get_container_info(void*, void* provider, const char* container_name, void* context,
|
||||
GameSaveContainerInfoCallback callback) {
|
||||
if (!callback) return E_INVALIDARG;
|
||||
const auto typed = reinterpret_cast<ContainerInfoCallback>(callback);
|
||||
const auto generation = active_runtime_generation();
|
||||
ContainerData data;
|
||||
bool exists = false;
|
||||
try {
|
||||
std::wstring dir;
|
||||
{
|
||||
std::lock_guard lock(handle_mutex);
|
||||
const auto* open = find_provider(provider, generation);
|
||||
if (!open) return stale_handle_error(generation);
|
||||
if (!valid_container_name(container_name)) return kInvalidContainerName;
|
||||
dir = open->dir;
|
||||
}
|
||||
const std::string name(container_name);
|
||||
DirectoryLock lock(dir);
|
||||
if (FAILED(lock.status())) return lock.status();
|
||||
const auto path = container_file(dir, name);
|
||||
std::vector<uint8_t> bytes;
|
||||
const auto hr = read_file(path, bytes, exists);
|
||||
if (FAILED(hr)) return hr;
|
||||
if (exists) {
|
||||
if (!parse(bytes, data, false)) {
|
||||
log_bad_file("corrupt_container", path);
|
||||
return kFileCorrupt;
|
||||
}
|
||||
if (data.name != name) {
|
||||
log_bad_file("container_id_collision", path);
|
||||
return HRESULT_FROM_WIN32(ERROR_FILE_EXISTS);
|
||||
}
|
||||
}
|
||||
} catch (const std::bad_alloc&) {
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
// Inference (source rank 3, #667): when the named container does not exist, succeed without
|
||||
// invoking the callback.
|
||||
if (!exists) return S_OK;
|
||||
// No lock is held here, so the callback may call back into XGameSave.
|
||||
const ContainerInfo info{data.name.c_str(), data.display_name.c_str(),
|
||||
static_cast<uint32_t>(data.blobs.size()), data.total_size,
|
||||
static_cast<time_t>(data.last_modified), false};
|
||||
(void)typed(&info, context);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT WINAPI enumerate_container_info_by_name(void*, void* provider, const char* prefix, void* context,
|
||||
GameSaveContainerInfoCallback callback) {
|
||||
if (!callback) return E_INVALIDARG;
|
||||
const auto typed = reinterpret_cast<ContainerInfoCallback>(callback);
|
||||
const auto generation = active_runtime_generation();
|
||||
@@ -854,10 +902,14 @@ HRESULT WINAPI enumerate_container_info(void*, void* provider, void* context, Ga
|
||||
if (!open) return stale_handle_error(generation);
|
||||
dir = open->dir;
|
||||
}
|
||||
const std::string filter = prefix ? std::string(prefix) : std::string();
|
||||
DirectoryLock lock(dir);
|
||||
if (FAILED(lock.status())) return lock.status();
|
||||
const auto hr = list_containers(dir, list);
|
||||
if (FAILED(hr)) return hr;
|
||||
if (!filter.empty()) {
|
||||
std::erase_if(list, [&](const ContainerData& item) { return !item.name.starts_with(filter); });
|
||||
}
|
||||
} catch (const std::bad_alloc&) {
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
@@ -872,6 +924,10 @@ HRESULT WINAPI enumerate_container_info(void*, void* provider, void* context, Ga
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT WINAPI enumerate_container_info(void*, void* provider, void* context, GameSaveContainerInfoCallback callback) {
|
||||
return enumerate_container_info_by_name(nullptr, provider, nullptr, context, callback);
|
||||
}
|
||||
|
||||
// Synchronous public slots. Each one runs the async operation above on the process task
|
||||
// queue (a null XAsyncBlock queue) and waits. syncOnDemand is passed through and has no
|
||||
// effect, the same as InitializeProviderAsync. Signatures follow the public Microsoft Learn
|
||||
|
||||
@@ -83,8 +83,12 @@ HRESULT WINAPI initialize_provider_result(void* self, void* async, void** provid
|
||||
void WINAPI close_provider(void* self, void* provider);
|
||||
HRESULT WINAPI create_container(void* self, void* provider, const char* name, void** out);
|
||||
void WINAPI close_container(void* self, void* container);
|
||||
HRESULT WINAPI get_container_info(void* self, void* provider, const char* container_name, void* context,
|
||||
GameSaveContainerInfoCallback callback);
|
||||
HRESULT WINAPI enumerate_container_info(void* self, void* provider, void* context,
|
||||
GameSaveContainerInfoCallback callback);
|
||||
HRESULT WINAPI enumerate_container_info_by_name(void* self, void* provider, const char* prefix, void* context,
|
||||
GameSaveContainerInfoCallback callback);
|
||||
HRESULT WINAPI read_blob_data(void* self, void* container, const char** names, uint32_t* count, size_t size,
|
||||
void* blobs);
|
||||
HRESULT WINAPI read_blob_data_async(void* self, void* container, const char** names, uint32_t count, void* async);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
add_executable(test_d3d12_console_formats main.cpp)
|
||||
target_compile_definitions(test_d3d12_console_formats PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
|
||||
target_link_libraries(test_d3d12_console_formats PRIVATE d3d12_xs kernel32 uuid)
|
||||
@@ -0,0 +1,300 @@
|
||||
/*
|
||||
* Conformance test: console-only DXGI formats and console-only view combinations must not reach
|
||||
* the host Direct3D 12 implementation.
|
||||
*
|
||||
* Contract (Xbox Series GDK d3d12_xs.h): DXGI_FORMAT has values the PC enumeration lacks:
|
||||
* 116 R10G10B10_7E3_A2_FLOAT, 117 R10G10B10_6E4_A2_FLOAT, 118 D16_UNORM_S8_UINT,
|
||||
* 119 R16_UNORM_X8_TYPELESS, 120 X16_TYPELESS_G8_UINT, 189 R10G10B10_SNORM_A2_UNORM,
|
||||
* 190 R4G4_UNORM.
|
||||
* A title built for the console passes them to resource, allocation-info and view calls, and
|
||||
* creates unordered-access views on depth-stencil textures (the console allows
|
||||
* ALLOW_DEPTH_STENCIL together with ALLOW_UNORDERED_ACCESS; PC Direct3D 12 does not).
|
||||
*
|
||||
* On a host that does not know them (D3DMetal), either makes Metal abort the process, so the
|
||||
* failure mode of this test without the fix is that the process dies at the first such call and
|
||||
* the runner sees a non-zero exit with no PASS line.
|
||||
*
|
||||
* Every call goes through the Xbox-layout function table of an Xbox-layout device (ADR 0009).
|
||||
* Slots: 2 Release; device 14 CreateDescriptorHeap, 18 CreateShaderResourceView,
|
||||
* 19 CreateUnorderedAccessView, 21 CreateDepthStencilView, 25 GetResourceAllocationInfo,
|
||||
* 27 CreateCommittedResource, 95 GetResourceAllocationInfo1, 108 GetResourceAllocationInfo2;
|
||||
* resource 10 GetDesc; descriptor heap 9 GetCPUDescriptorHandleForHeapStart.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <d3d12.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(PVOID adapter, const void* params, REFIID riid,
|
||||
void** ppv);
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int kRelease = 2;
|
||||
constexpr int kDevCreateDescriptorHeap = 14, kDevCreateShaderResourceView = 18, kDevCreateUnorderedAccessView = 19;
|
||||
constexpr int kDevCreateDepthStencilView = 21, kDevGetResourceAllocationInfo = 25, kDevCreateCommittedResource = 27;
|
||||
constexpr int kDevGetResourceAllocationInfo1 = 95, kDevGetResourceAllocationInfo2 = 108;
|
||||
constexpr int kResGetDesc = 10, kHeapGetCpuStart = 9;
|
||||
|
||||
// Console-only formats, by number: the PC <dxgiformat.h> has no names for them.
|
||||
constexpr DXGI_FORMAT kD16_UNORM_S8_UINT = static_cast<DXGI_FORMAT>(118);
|
||||
constexpr DXGI_FORMAT kR16_UNORM_X8_TYPELESS = static_cast<DXGI_FORMAT>(119);
|
||||
constexpr DXGI_FORMAT kX16_TYPELESS_G8_UINT = static_cast<DXGI_FORMAT>(120);
|
||||
|
||||
int g_checks = 0;
|
||||
int g_failed = 0;
|
||||
|
||||
#define CHECK(cond, ...) \
|
||||
do { \
|
||||
++g_checks; \
|
||||
if (!(cond)) { \
|
||||
++g_failed; \
|
||||
std::fprintf(stderr, "FAIL: test_d3d12_console_formats:%d: ", __LINE__); \
|
||||
std::fprintf(stderr, __VA_ARGS__); \
|
||||
std::fprintf(stderr, "\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
template <typename Fn>
|
||||
Fn slot(void* object, int index) {
|
||||
return reinterpret_cast<Fn>((*static_cast<void* const* const*>(object))[index]);
|
||||
}
|
||||
|
||||
using ReleaseFn = ULONG(STDMETHODCALLTYPE*)(void*);
|
||||
using AllocationInfoFn = D3D12_RESOURCE_ALLOCATION_INFO(STDMETHODCALLTYPE*)(void*, UINT, UINT, const D3D12_RESOURCE_DESC*);
|
||||
using AllocationInfo1Fn = D3D12_RESOURCE_ALLOCATION_INFO(STDMETHODCALLTYPE*)(void*, UINT, UINT, const D3D12_RESOURCE_DESC*,
|
||||
D3D12_RESOURCE_ALLOCATION_INFO1*);
|
||||
using AllocationInfo2Fn = D3D12_RESOURCE_ALLOCATION_INFO(STDMETHODCALLTYPE*)(void*, UINT, UINT, const D3D12_RESOURCE_DESC1*,
|
||||
D3D12_RESOURCE_ALLOCATION_INFO1*);
|
||||
using CreateCommittedFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_HEAP_PROPERTIES*, D3D12_HEAP_FLAGS,
|
||||
const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_STATES,
|
||||
const D3D12_CLEAR_VALUE*, REFIID, void**);
|
||||
using CreateHeapFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_DESCRIPTOR_HEAP_DESC*, REFIID, void**);
|
||||
using HeapStartFn = D3D12_CPU_DESCRIPTOR_HANDLE(STDMETHODCALLTYPE*)(void*);
|
||||
using GetDescFn = void(STDMETHODCALLTYPE*)(void*, D3D12_RESOURCE_DESC*);
|
||||
using CreateSrvFn = void(STDMETHODCALLTYPE*)(void*, void*, const D3D12_SHADER_RESOURCE_VIEW_DESC*, D3D12_CPU_DESCRIPTOR_HANDLE);
|
||||
using CreateUavFn = void(STDMETHODCALLTYPE*)(void*, void*, void*, const D3D12_UNORDERED_ACCESS_VIEW_DESC*,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE);
|
||||
using CreateDsvFn = void(STDMETHODCALLTYPE*)(void*, void*, const D3D12_DEPTH_STENCIL_VIEW_DESC*, D3D12_CPU_DESCRIPTOR_HANDLE);
|
||||
|
||||
D3D12_RESOURCE_DESC texture(DXGI_FORMAT format, D3D12_RESOURCE_FLAGS flags) {
|
||||
D3D12_RESOURCE_DESC desc{};
|
||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
||||
desc.Width = 256;
|
||||
desc.Height = 256;
|
||||
desc.DepthOrArraySize = 1;
|
||||
desc.MipLevels = 1;
|
||||
desc.Format = format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Flags = flags;
|
||||
return desc;
|
||||
}
|
||||
|
||||
std::string read_log() {
|
||||
char path[MAX_PATH];
|
||||
const DWORD n = GetEnvironmentVariableA("BX_LOG_FILE", path, sizeof(path));
|
||||
if (n == 0 || n >= sizeof(path)) return {};
|
||||
std::string text;
|
||||
if (FILE* f = std::fopen(path, "rb")) {
|
||||
char buffer[4096];
|
||||
size_t got;
|
||||
while ((got = std::fread(buffer, 1, sizeof(buffer), f)) > 0) text.append(buffer, got);
|
||||
std::fclose(f);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
size_t count_of(const std::string& text, const char* needle) {
|
||||
size_t n = 0;
|
||||
for (size_t pos = text.find(needle); pos != std::string::npos; pos = text.find(needle, pos + 1)) ++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
alignas(8) unsigned char title_params[80] = {};
|
||||
const UINT version = 0x20004; // a non-zero version selects the Xbox-layout device
|
||||
std::memcpy(title_params, &version, sizeof(version));
|
||||
void* dev = nullptr;
|
||||
HRESULT hr = D3D12XboxCreateDevice(nullptr, title_params, __uuidof(ID3D12Device), &dev);
|
||||
if (hr == E_NOINTERFACE) {
|
||||
std::printf("SKIP: test_d3d12_console_formats: host lacks the Xbox-layout device interface (E_NOINTERFACE)\n");
|
||||
return 77;
|
||||
}
|
||||
CHECK(hr == S_OK && dev != nullptr, "Xbox-layout device creation hr=0x%08lx", static_cast<unsigned long>(hr));
|
||||
if (!dev) return 1;
|
||||
const size_t stubs_before = count_of(read_log(), "CreateUnorderedAccessView(depth-stencil resource)");
|
||||
|
||||
// 1. Allocation info for a console-only format. The host's answer for the PC format the shim
|
||||
// documents as its substitute (R32G8X24_TYPELESS for a D16_UNORM_S8_UINT texture) is the
|
||||
// expected value, asked for directly so the expectation does not pass through the
|
||||
// translation under test.
|
||||
const D3D12_RESOURCE_FLAGS depth = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
|
||||
const D3D12_RESOURCE_DESC console_depth = texture(kD16_UNORM_S8_UINT, depth);
|
||||
const D3D12_RESOURCE_DESC pc_depth = texture(DXGI_FORMAT_R32G8X24_TYPELESS, depth);
|
||||
const D3D12_RESOURCE_ALLOCATION_INFO want = slot<AllocationInfoFn>(dev, kDevGetResourceAllocationInfo)(dev, 0, 1, &pc_depth);
|
||||
CHECK(want.SizeInBytes != 0 && want.SizeInBytes != UINT64_MAX, "control: host sizes a PC depth texture (size=%llu)",
|
||||
static_cast<unsigned long long>(want.SizeInBytes));
|
||||
D3D12_RESOURCE_ALLOCATION_INFO got = slot<AllocationInfoFn>(dev, kDevGetResourceAllocationInfo)(dev, 0, 1, &console_depth);
|
||||
CHECK(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment,
|
||||
"GetResourceAllocationInfo(format 118): size=%llu alignment=%llu, want %llu/%llu",
|
||||
static_cast<unsigned long long>(got.SizeInBytes), static_cast<unsigned long long>(got.Alignment),
|
||||
static_cast<unsigned long long>(want.SizeInBytes), static_cast<unsigned long long>(want.Alignment));
|
||||
|
||||
D3D12_RESOURCE_ALLOCATION_INFO1 each{};
|
||||
got = slot<AllocationInfo1Fn>(dev, kDevGetResourceAllocationInfo1)(dev, 0, 1, &console_depth, &each);
|
||||
CHECK(got.SizeInBytes == want.SizeInBytes, "GetResourceAllocationInfo1(format 118): size=%llu, want %llu",
|
||||
static_cast<unsigned long long>(got.SizeInBytes), static_cast<unsigned long long>(want.SizeInBytes));
|
||||
|
||||
D3D12_RESOURCE_DESC1 console_depth1{};
|
||||
std::memcpy(&console_depth1, &console_depth, sizeof(console_depth)); // DESC1 is DESC plus a trailing region
|
||||
got = slot<AllocationInfo2Fn>(dev, kDevGetResourceAllocationInfo2)(dev, 0, 1, &console_depth1, &each);
|
||||
CHECK(got.SizeInBytes == want.SizeInBytes, "GetResourceAllocationInfo2(format 118): size=%llu, want %llu",
|
||||
static_cast<unsigned long long>(got.SizeInBytes), static_cast<unsigned long long>(want.SizeInBytes));
|
||||
|
||||
// An array with a console-only format in the second place only: every entry is translated,
|
||||
// not just the first.
|
||||
const D3D12_RESOURCE_DESC pair[2] = {texture(DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE), console_depth};
|
||||
const D3D12_RESOURCE_DESC pc_pair[2] = {pair[0], pc_depth};
|
||||
const D3D12_RESOURCE_ALLOCATION_INFO want_pair = slot<AllocationInfoFn>(dev, kDevGetResourceAllocationInfo)(dev, 0, 2, pc_pair);
|
||||
got = slot<AllocationInfoFn>(dev, kDevGetResourceAllocationInfo)(dev, 0, 2, pair);
|
||||
CHECK(got.SizeInBytes == want_pair.SizeInBytes && got.SizeInBytes != 0,
|
||||
"GetResourceAllocationInfo(two descriptions, the second console-only): size=%llu, want %llu",
|
||||
static_cast<unsigned long long>(got.SizeInBytes), static_cast<unsigned long long>(want_pair.SizeInBytes));
|
||||
|
||||
// The colour formats: each is sized as the documented substitute.
|
||||
const struct {
|
||||
int console;
|
||||
DXGI_FORMAT substitute;
|
||||
} colour[] = {{116, DXGI_FORMAT_R16G16B16A16_FLOAT},
|
||||
{117, DXGI_FORMAT_R16G16B16A16_FLOAT},
|
||||
{189, DXGI_FORMAT_R16G16B16A16_SNORM},
|
||||
{190, DXGI_FORMAT_R8G8_UNORM}};
|
||||
for (const auto& c : colour) {
|
||||
const D3D12_RESOURCE_DESC a = texture(static_cast<DXGI_FORMAT>(c.console), D3D12_RESOURCE_FLAG_NONE);
|
||||
const D3D12_RESOURCE_DESC b = texture(c.substitute, D3D12_RESOURCE_FLAG_NONE);
|
||||
const D3D12_RESOURCE_ALLOCATION_INFO expected = slot<AllocationInfoFn>(dev, kDevGetResourceAllocationInfo)(dev, 0, 1, &b);
|
||||
got = slot<AllocationInfoFn>(dev, kDevGetResourceAllocationInfo)(dev, 0, 1, &a);
|
||||
CHECK(got.SizeInBytes == expected.SizeInBytes && got.SizeInBytes != 0, "GetResourceAllocationInfo(format %d): size=%llu, want %llu",
|
||||
c.console, static_cast<unsigned long long>(got.SizeInBytes), static_cast<unsigned long long>(expected.SizeInBytes));
|
||||
}
|
||||
|
||||
// 2. A committed depth texture of the console format, with a clear value of the console format.
|
||||
D3D12_HEAP_PROPERTIES heap{};
|
||||
heap.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
D3D12_CLEAR_VALUE clear{};
|
||||
clear.Format = kD16_UNORM_S8_UINT;
|
||||
clear.DepthStencil.Depth = 1.0f;
|
||||
void* depth_texture = nullptr;
|
||||
hr = slot<CreateCommittedFn>(dev, kDevCreateCommittedResource)(dev, &heap, D3D12_HEAP_FLAG_NONE, &console_depth,
|
||||
D3D12_RESOURCE_STATE_DEPTH_WRITE, &clear,
|
||||
__uuidof(ID3D12Resource), &depth_texture);
|
||||
CHECK(hr == S_OK && depth_texture, "CreateCommittedResource(format 118) hr=0x%08lx", static_cast<unsigned long>(hr));
|
||||
|
||||
// Views on it: depth-stencil in the console format, and its two planes read through the
|
||||
// console's plane formats.
|
||||
D3D12_DESCRIPTOR_HEAP_DESC dsv_heap_desc{};
|
||||
dsv_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
|
||||
dsv_heap_desc.NumDescriptors = 2;
|
||||
void* dsv_heap = nullptr;
|
||||
hr = slot<CreateHeapFn>(dev, kDevCreateDescriptorHeap)(dev, &dsv_heap_desc, __uuidof(ID3D12DescriptorHeap), &dsv_heap);
|
||||
CHECK(hr == S_OK && dsv_heap, "CreateDescriptorHeap(DSV) hr=0x%08lx", static_cast<unsigned long>(hr));
|
||||
D3D12_DESCRIPTOR_HEAP_DESC view_heap_desc{};
|
||||
view_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
view_heap_desc.NumDescriptors = 8;
|
||||
void* view_heap = nullptr;
|
||||
hr = slot<CreateHeapFn>(dev, kDevCreateDescriptorHeap)(dev, &view_heap_desc, __uuidof(ID3D12DescriptorHeap), &view_heap);
|
||||
CHECK(hr == S_OK && view_heap, "CreateDescriptorHeap(CBV_SRV_UAV) hr=0x%08lx", static_cast<unsigned long>(hr));
|
||||
if (!depth_texture || !dsv_heap || !view_heap) {
|
||||
std::fprintf(stderr, "FAIL: test_d3d12_console_formats: setup\n");
|
||||
return 1;
|
||||
}
|
||||
const D3D12_CPU_DESCRIPTOR_HANDLE dsv = slot<HeapStartFn>(dsv_heap, kHeapGetCpuStart)(dsv_heap);
|
||||
const D3D12_CPU_DESCRIPTOR_HANDLE views = slot<HeapStartFn>(view_heap, kHeapGetCpuStart)(view_heap);
|
||||
constexpr SIZE_T kXboxViewSize = 32; // console CBV/SRV/UAV descriptor size (ADR 0009)
|
||||
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc{};
|
||||
dsv_desc.Format = kD16_UNORM_S8_UINT;
|
||||
dsv_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
|
||||
slot<CreateDsvFn>(dev, kDevCreateDepthStencilView)(dev, depth_texture, &dsv_desc, dsv);
|
||||
CHECK(true, "CreateDepthStencilView(format 118) returned");
|
||||
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc{};
|
||||
srv_desc.Format = kR16_UNORM_X8_TYPELESS;
|
||||
srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
||||
srv_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
srv_desc.Texture2D.MipLevels = 1;
|
||||
slot<CreateSrvFn>(dev, kDevCreateShaderResourceView)(dev, depth_texture, &srv_desc, views);
|
||||
CHECK(true, "CreateShaderResourceView(format 119, depth plane) returned");
|
||||
srv_desc.Format = kX16_TYPELESS_G8_UINT;
|
||||
srv_desc.Texture2D.PlaneSlice = 1;
|
||||
slot<CreateSrvFn>(dev, kDevCreateShaderResourceView)(dev, depth_texture, &srv_desc, {views.ptr + kXboxViewSize});
|
||||
CHECK(true, "CreateShaderResourceView(format 120, stencil plane) returned");
|
||||
|
||||
// The documented limit: GetDesc reports the host format of the texture.
|
||||
D3D12_RESOURCE_DESC reported{};
|
||||
slot<GetDescFn>(depth_texture, kResGetDesc)(depth_texture, &reported);
|
||||
CHECK(reported.Format == DXGI_FORMAT_R32G8X24_TYPELESS && reported.Width == 256,
|
||||
"GetDesc of the format-118 texture reports host format %d (want %d)", static_cast<int>(reported.Format),
|
||||
static_cast<int>(DXGI_FORMAT_R32G8X24_TYPELESS));
|
||||
|
||||
// 3. An unordered-access view on a depth-stencil texture: the descriptor gets a null view and
|
||||
// the call is logged as unimplemented. A view on an ordinary texture is not affected.
|
||||
void* depth_uav_texture = nullptr;
|
||||
const D3D12_RESOURCE_DESC depth_uav =
|
||||
texture(DXGI_FORMAT_R32G8X24_TYPELESS, depth | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
|
||||
hr = slot<CreateCommittedFn>(dev, kDevCreateCommittedResource)(dev, &heap, D3D12_HEAP_FLAG_NONE, &depth_uav,
|
||||
D3D12_RESOURCE_STATE_DEPTH_WRITE, nullptr,
|
||||
__uuidof(ID3D12Resource), &depth_uav_texture);
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc{};
|
||||
uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
|
||||
uav_desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
|
||||
bool depth_uav_exercised = false;
|
||||
if (hr == S_OK && depth_uav_texture) {
|
||||
slot<CreateUavFn>(dev, kDevCreateUnorderedAccessView)(dev, depth_uav_texture, nullptr, &uav_desc,
|
||||
{views.ptr + 2 * kXboxViewSize});
|
||||
CHECK(true, "CreateUnorderedAccessView(R32_FLOAT on a depth-stencil texture) returned");
|
||||
depth_uav_exercised = true;
|
||||
} else {
|
||||
// A host that refuses the resource itself cannot reach the view; say so instead of passing silently.
|
||||
std::printf("note: host refused a depth-stencil texture with unordered access (hr=0x%08lx); the view check did not run\n",
|
||||
static_cast<unsigned long>(hr));
|
||||
}
|
||||
|
||||
void* colour_texture = nullptr;
|
||||
const D3D12_RESOURCE_DESC colour_uav = texture(DXGI_FORMAT_R32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
|
||||
hr = slot<CreateCommittedFn>(dev, kDevCreateCommittedResource)(dev, &heap, D3D12_HEAP_FLAG_NONE, &colour_uav,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr,
|
||||
__uuidof(ID3D12Resource), &colour_texture);
|
||||
CHECK(hr == S_OK && colour_texture, "CreateCommittedResource(R32_FLOAT, unordered access) hr=0x%08lx",
|
||||
static_cast<unsigned long>(hr));
|
||||
if (colour_texture) {
|
||||
slot<CreateUavFn>(dev, kDevCreateUnorderedAccessView)(dev, colour_texture, nullptr, &uav_desc,
|
||||
{views.ptr + 3 * kXboxViewSize});
|
||||
}
|
||||
|
||||
const std::string log = read_log();
|
||||
if (!log.empty()) {
|
||||
const size_t stubs = count_of(log, "CreateUnorderedAccessView(depth-stencil resource)") - stubs_before;
|
||||
CHECK(stubs == (depth_uav_exercised ? 1u : 0u),
|
||||
"the depth-stencil view is logged as unimplemented once and the ordinary view is not (logged %zu time(s))", stubs);
|
||||
CHECK(log.find("console-only format 118") != std::string::npos, "the first translation of format 118 is logged");
|
||||
} else {
|
||||
std::printf("note: no BX_LOG_FILE; the log checks did not run\n");
|
||||
}
|
||||
|
||||
if (colour_texture) slot<ReleaseFn>(colour_texture, kRelease)(colour_texture);
|
||||
if (depth_uav_texture) slot<ReleaseFn>(depth_uav_texture, kRelease)(depth_uav_texture);
|
||||
slot<ReleaseFn>(view_heap, kRelease)(view_heap);
|
||||
slot<ReleaseFn>(dsv_heap, kRelease)(dsv_heap);
|
||||
slot<ReleaseFn>(depth_texture, kRelease)(depth_texture);
|
||||
slot<ReleaseFn>(dev, kRelease)(dev);
|
||||
|
||||
std::printf("%s: test_d3d12_console_formats (%d of %d checks passed)\n", g_failed ? "FAIL" : "PASS", g_checks - g_failed,
|
||||
g_checks);
|
||||
return g_failed ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
add_executable(test_d3d12_unbacked_buffers main.cpp)
|
||||
target_compile_definitions(test_d3d12_unbacked_buffers PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
|
||||
target_link_libraries(test_d3d12_unbacked_buffers PRIVATE d3d12_xs kernel32 uuid)
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Conformance test: index and vertex bindings at a title address that has no host buffer behind it
|
||||
* must not reach the host Direct3D 12 implementation.
|
||||
*
|
||||
* Contract: on the console a GPU virtual address is the title's own address, so a title binds
|
||||
* index and vertex data that lives in plain title memory, with no Direct3D resource created for
|
||||
* it (observed in a project-authorized target build: a 384 KiB index buffer and a 1.1 MiB vertex
|
||||
* buffer bound this way every frame). BetterXen has a host buffer only for memory it created a
|
||||
* resource for. Passed through unchanged, such an address is not a host address, and D3DMetal
|
||||
* dereferences the buffer it fails to find: the process dies with a null read inside
|
||||
* IASetIndexBuffer. Without the fix the failure mode of this test is that crash.
|
||||
*
|
||||
* With the fix the binding is left empty (Direct3D 12 defines a null binding) and the call is
|
||||
* logged as unimplemented. A binding at an address inside a resource BetterXen created is still
|
||||
* translated and is not logged.
|
||||
*
|
||||
* Slots (Xbox-layout tables, ADR 0009): 2 Release; device 9 CreateCommandAllocator,
|
||||
* 27 CreateCommittedResource, 48 CreateCommandQueueX, 73 CreateCommandListX; resource 11
|
||||
* GetGPUVirtualAddress; graphics command list 9 Close, 47 IASetIndexBuffer, 48 IASetVertexBuffers.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <d3d12.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(PVOID adapter, const void* params, REFIID riid,
|
||||
void** ppv);
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int kRelease = 2;
|
||||
constexpr int kDevCreateCommandAllocator = 9, kDevCreateCommittedResource = 27, kDevCreateCommandQueueX = 48;
|
||||
constexpr int kDevCreateCommandListX = 73;
|
||||
constexpr int kResGetGpuVirtualAddress = 11;
|
||||
constexpr int kListClose = 9, kListIASetIndexBuffer = 47, kListIASetVertexBuffers = 48;
|
||||
|
||||
int g_checks = 0;
|
||||
int g_failed = 0;
|
||||
|
||||
#define CHECK(cond, ...) \
|
||||
do { \
|
||||
++g_checks; \
|
||||
if (!(cond)) { \
|
||||
++g_failed; \
|
||||
std::fprintf(stderr, "FAIL: test_d3d12_unbacked_buffers:%d: ", __LINE__); \
|
||||
std::fprintf(stderr, __VA_ARGS__); \
|
||||
std::fprintf(stderr, "\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
template <typename Fn>
|
||||
Fn slot(void* object, int index) {
|
||||
return reinterpret_cast<Fn>((*static_cast<void* const* const*>(object))[index]);
|
||||
}
|
||||
|
||||
struct QueueDescX {
|
||||
D3D12_COMMAND_LIST_TYPE Type;
|
||||
UINT Flags, EngineOrPipeIndex, QueueIndex;
|
||||
};
|
||||
struct ListDescX {
|
||||
D3D12_COMMAND_LIST_TYPE Type;
|
||||
UINT Flags, NodeMask, ResourceBarrierBatchSize;
|
||||
};
|
||||
|
||||
using ReleaseFn = ULONG(STDMETHODCALLTYPE*)(void*);
|
||||
using CreateQueueXFn = HRESULT(STDMETHODCALLTYPE*)(void*, const QueueDescX*, REFIID, void**);
|
||||
using CreateAllocatorFn = HRESULT(STDMETHODCALLTYPE*)(void*, D3D12_COMMAND_LIST_TYPE, REFIID, void**);
|
||||
using CreateListXFn = HRESULT(STDMETHODCALLTYPE*)(void*, const ListDescX*, void*, void*, REFIID, void**);
|
||||
using CreateCommittedFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_HEAP_PROPERTIES*, D3D12_HEAP_FLAGS,
|
||||
const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_STATES,
|
||||
const D3D12_CLEAR_VALUE*, REFIID, void**);
|
||||
using GetGpuVaFn = D3D12_GPU_VIRTUAL_ADDRESS(STDMETHODCALLTYPE*)(void*);
|
||||
using CloseFn = HRESULT(STDMETHODCALLTYPE*)(void*);
|
||||
using SetIndexFn = void(STDMETHODCALLTYPE*)(void*, const D3D12_INDEX_BUFFER_VIEW*);
|
||||
using SetVertexFn = void(STDMETHODCALLTYPE*)(void*, UINT, UINT, const D3D12_VERTEX_BUFFER_VIEW*);
|
||||
|
||||
std::string read_log() {
|
||||
char path[MAX_PATH];
|
||||
const DWORD n = GetEnvironmentVariableA("BX_LOG_FILE", path, sizeof(path));
|
||||
if (n == 0 || n >= sizeof(path)) return {};
|
||||
std::string text;
|
||||
if (FILE* f = std::fopen(path, "rb")) {
|
||||
char buffer[4096];
|
||||
size_t got;
|
||||
while ((got = std::fread(buffer, 1, sizeof(buffer), f)) > 0) text.append(buffer, got);
|
||||
std::fclose(f);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
size_t count_of(const std::string& text, const char* needle) {
|
||||
size_t n = 0;
|
||||
for (size_t pos = text.find(needle); pos != std::string::npos; pos = text.find(needle, pos + 1)) ++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
constexpr const char* kIndexStub = "IASetIndexBuffer(title memory without a host buffer)";
|
||||
constexpr const char* kVertexStub = "IASetVertexBuffers(title memory without a host buffer)";
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
alignas(8) unsigned char title_params[80] = {};
|
||||
const UINT version = 0x20004; // a non-zero version selects the Xbox-layout device
|
||||
std::memcpy(title_params, &version, sizeof(version));
|
||||
void* dev = nullptr;
|
||||
HRESULT hr = D3D12XboxCreateDevice(nullptr, title_params, __uuidof(ID3D12Device), &dev);
|
||||
if (hr == E_NOINTERFACE) {
|
||||
std::printf("SKIP: test_d3d12_unbacked_buffers: host lacks the Xbox-layout device interface (E_NOINTERFACE)\n");
|
||||
return 77;
|
||||
}
|
||||
CHECK(hr == S_OK && dev != nullptr, "Xbox-layout device creation hr=0x%08lx", static_cast<unsigned long>(hr));
|
||||
if (!dev) return 1;
|
||||
|
||||
const QueueDescX qdesc{D3D12_COMMAND_LIST_TYPE_DIRECT, 0, 0, 0};
|
||||
const ListDescX ldesc{D3D12_COMMAND_LIST_TYPE_DIRECT, 0, 0, 0};
|
||||
void* queue = nullptr;
|
||||
void* allocator = nullptr;
|
||||
void* list = nullptr;
|
||||
CHECK(slot<CreateQueueXFn>(dev, kDevCreateCommandQueueX)(dev, &qdesc, __uuidof(ID3D12CommandQueue), &queue) == S_OK,
|
||||
"CreateCommandQueueX");
|
||||
CHECK(slot<CreateAllocatorFn>(dev, kDevCreateCommandAllocator)(dev, D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
__uuidof(ID3D12CommandAllocator), &allocator) == S_OK,
|
||||
"CreateCommandAllocator");
|
||||
hr = slot<CreateListXFn>(dev, kDevCreateCommandListX)(dev, &ldesc, allocator, nullptr, __uuidof(ID3D12GraphicsCommandList),
|
||||
&list);
|
||||
CHECK(hr == S_OK && list, "CreateCommandListX hr=0x%08lx", static_cast<unsigned long>(hr));
|
||||
|
||||
// A buffer BetterXen created: its GPU address is a title address with a host buffer behind it.
|
||||
D3D12_HEAP_PROPERTIES upload{};
|
||||
upload.Type = D3D12_HEAP_TYPE_UPLOAD;
|
||||
D3D12_RESOURCE_DESC desc{};
|
||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
desc.Width = 64 * 1024;
|
||||
desc.Height = 1;
|
||||
desc.DepthOrArraySize = 1;
|
||||
desc.MipLevels = 1;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
||||
void* backed = nullptr;
|
||||
hr = slot<CreateCommittedFn>(dev, kDevCreateCommittedResource)(dev, &upload, D3D12_HEAP_FLAG_NONE, &desc,
|
||||
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
|
||||
__uuidof(ID3D12Resource), &backed);
|
||||
CHECK(hr == S_OK && backed, "CreateCommittedResource(64 KiB upload buffer) hr=0x%08lx", static_cast<unsigned long>(hr));
|
||||
|
||||
// Plain title memory: no Direct3D resource was created for it.
|
||||
auto* plain = static_cast<unsigned char*>(VirtualAlloc(nullptr, 64 * 1024, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
|
||||
CHECK(plain != nullptr, "VirtualAlloc(64 KiB)");
|
||||
if (!queue || !allocator || !list || !backed || !plain) {
|
||||
std::fprintf(stderr, "FAIL: test_d3d12_unbacked_buffers: setup\n");
|
||||
return 1;
|
||||
}
|
||||
const D3D12_GPU_VIRTUAL_ADDRESS backed_va = slot<GetGpuVaFn>(backed, kResGetGpuVirtualAddress)(backed);
|
||||
const auto plain_va = reinterpret_cast<D3D12_GPU_VIRTUAL_ADDRESS>(plain);
|
||||
CHECK(backed_va != 0, "the committed buffer reports a GPU address");
|
||||
|
||||
const std::string before = read_log();
|
||||
const size_t index_before = count_of(before, kIndexStub);
|
||||
const size_t vertex_before = count_of(before, kVertexStub);
|
||||
|
||||
// 1. Bindings inside the buffer BetterXen created: translated, not logged.
|
||||
const D3D12_INDEX_BUFFER_VIEW backed_index{backed_va + 256, 4096, DXGI_FORMAT_R16_UINT};
|
||||
slot<SetIndexFn>(list, kListIASetIndexBuffer)(list, &backed_index);
|
||||
const D3D12_VERTEX_BUFFER_VIEW backed_vertex{backed_va + 8192, 4096, 16};
|
||||
slot<SetVertexFn>(list, kListIASetVertexBuffers)(list, 0, 1, &backed_vertex);
|
||||
CHECK(true, "bindings inside a created buffer returned");
|
||||
|
||||
// 2. Bindings in plain title memory: the process must survive them.
|
||||
const D3D12_INDEX_BUFFER_VIEW plain_index{plain_va, 4096, DXGI_FORMAT_R16_UINT};
|
||||
slot<SetIndexFn>(list, kListIASetIndexBuffer)(list, &plain_index);
|
||||
CHECK(true, "IASetIndexBuffer at a title address without a host buffer returned");
|
||||
// Two vertex streams: the first backed, the second not. Only the second is emptied.
|
||||
const D3D12_VERTEX_BUFFER_VIEW streams[2] = {backed_vertex, {plain_va + 4096, 4096, 16}};
|
||||
slot<SetVertexFn>(list, kListIASetVertexBuffers)(list, 0, 2, streams);
|
||||
CHECK(true, "IASetVertexBuffers with one stream in plain title memory returned");
|
||||
|
||||
// 3. Null bindings stay null bindings and are not logged.
|
||||
slot<SetIndexFn>(list, kListIASetIndexBuffer)(list, nullptr);
|
||||
const D3D12_INDEX_BUFFER_VIEW zero_index{0, 0, DXGI_FORMAT_R16_UINT};
|
||||
slot<SetIndexFn>(list, kListIASetIndexBuffer)(list, &zero_index);
|
||||
const D3D12_VERTEX_BUFFER_VIEW zero_vertex{0, 0, 0};
|
||||
slot<SetVertexFn>(list, kListIASetVertexBuffers)(list, 0, 1, &zero_vertex);
|
||||
|
||||
CHECK(slot<CloseFn>(list, kListClose)(list) == S_OK, "the list still closes");
|
||||
|
||||
const std::string after = read_log();
|
||||
if (!after.empty()) {
|
||||
CHECK(count_of(after, kIndexStub) - index_before == 1,
|
||||
"exactly the unbacked index binding is logged as unimplemented (logged %zu time(s))",
|
||||
count_of(after, kIndexStub) - index_before);
|
||||
CHECK(count_of(after, kVertexStub) - vertex_before == 1,
|
||||
"exactly the unbacked vertex stream is logged as unimplemented (logged %zu time(s))",
|
||||
count_of(after, kVertexStub) - vertex_before);
|
||||
} else {
|
||||
std::printf("note: no BX_LOG_FILE; the log checks did not run\n");
|
||||
}
|
||||
|
||||
VirtualFree(plain, 0, MEM_RELEASE);
|
||||
for (void* object : {backed, list, allocator, queue, dev}) slot<ReleaseFn>(object, kRelease)(object);
|
||||
std::printf("%s: test_d3d12_unbacked_buffers (%d of %d checks passed)\n", g_failed ? "FAIL" : "PASS", g_checks - g_failed,
|
||||
g_checks);
|
||||
return g_failed ? 1 : 0;
|
||||
}
|
||||
@@ -568,6 +568,87 @@ void check_public_dispatch(void* user, void* synthetic_save, void* synthetic_pac
|
||||
CHECK(listing.seen[0].blob_count == 1 && listing.seen[0].total_size == sizeof(payload));
|
||||
CHECK(!listing.seen[0].needs_sync && listing.seen[0].modified >= started);
|
||||
|
||||
// IXGameSaveImpl slots 13 (XGameSaveGetContainerInfo) and 15 (XGameSaveEnumerateContainerInfoByName) (#667).
|
||||
{
|
||||
using GetContainerInfoFn = HRESULT(WINAPI*)(void*, void*, const char*, void*, InfoCallback);
|
||||
using EnumerateByNameFn = HRESULT(WINAPI*)(void*, void*, const char*, void*, InfoCallback);
|
||||
const auto get_info = slot<GetContainerInfoFn>(save, kGsGetContainerInfo);
|
||||
const auto enum_by_name = slot<EnumerateByNameFn>(save, kGsEnumerateByName);
|
||||
|
||||
Listing single;
|
||||
CHECK(get_info(save, provider, kContainer, &single, collect) == S_OK);
|
||||
CHECK(single.seen.size() == 1);
|
||||
CHECK(single.seen[0].name == kContainer && single.seen[0].display_name == kDisplay);
|
||||
CHECK(single.seen[0].blob_count == 1 && single.seen[0].total_size == sizeof(payload));
|
||||
CHECK(!single.seen[0].needs_sync && single.seen[0].modified >= started);
|
||||
|
||||
// Missing container succeeds without invoking the callback (source rank 3 inference).
|
||||
Listing missing;
|
||||
CHECK(get_info(save, provider, "no_such_container", &missing, collect) == S_OK);
|
||||
CHECK(missing.seen.empty());
|
||||
|
||||
// Validation errors on slot 13.
|
||||
CHECK(get_info(save, provider, kContainer, &missing, nullptr) == E_INVALIDARG);
|
||||
CHECK(get_info(save, provider, nullptr, &missing, collect) == kInvalidContainerName);
|
||||
CHECK(get_info(save, provider, "", &missing, collect) == kInvalidContainerName);
|
||||
CHECK(get_info(save, provider, "../bad", &missing, collect) == kInvalidContainerName);
|
||||
CHECK(get_info(save, nullptr, kContainer, &missing, collect) == kInvalidHandle);
|
||||
|
||||
// Use a dedicated provider for slot 15 so persisting three containers does not disturb
|
||||
// kPublicScid's single-container check on subsequent runs in the same bottle.
|
||||
constexpr const char* kPrefixScid = "22222222-2222-2222-2222-222222222222";
|
||||
void* prefix_provider = nullptr;
|
||||
CHECK(slot<InitFn>(save, kGsInit)(save, user, kPrefixScid, false, &prefix_provider) == S_OK && prefix_provider);
|
||||
|
||||
auto write_extra = [&](const char* cname, const char* dname) {
|
||||
void* c = nullptr;
|
||||
CHECK(slot<CreateContainerFn>(save, kGsCreateContainer)(save, prefix_provider, cname, &c) == S_OK && c);
|
||||
void* u = nullptr;
|
||||
CHECK(slot<CreateUpdateFn>(save, kGsCreateUpdate)(save, c, dname, &u) == S_OK && u);
|
||||
CHECK(slot<BlobWriteFn>(save, kGsBlobWrite)(save, u, kBlob, payload, sizeof(payload)) == S_OK);
|
||||
CHECK(slot<SubmitFn>(save, kGsSubmit)(save, u) == S_OK);
|
||||
slot<CloseFn>(save, kGsCloseUpdate)(save, u);
|
||||
slot<CloseFn>(save, kGsCloseContainer)(save, c);
|
||||
};
|
||||
write_extra("pub_slot", "Round 1");
|
||||
write_extra("pub_slot_2", "Round 2");
|
||||
write_extra("other_slot", "Other");
|
||||
|
||||
Listing pub_only;
|
||||
CHECK(enum_by_name(save, prefix_provider, "pub_slot", &pub_only, collect) == S_OK);
|
||||
CHECK(pub_only.seen.size() == 2);
|
||||
CHECK(pub_only.seen[0].name == "pub_slot" && pub_only.seen[1].name == "pub_slot_2");
|
||||
|
||||
Listing other_only;
|
||||
CHECK(enum_by_name(save, prefix_provider, "other_", &other_only, collect) == S_OK);
|
||||
CHECK(other_only.seen.size() == 1 && other_only.seen[0].name == "other_slot");
|
||||
|
||||
Listing none;
|
||||
CHECK(enum_by_name(save, prefix_provider, "nomatch_", &none, collect) == S_OK);
|
||||
CHECK(none.seen.empty());
|
||||
|
||||
Listing all_null;
|
||||
CHECK(enum_by_name(save, prefix_provider, nullptr, &all_null, collect) == S_OK);
|
||||
CHECK(all_null.seen.size() == 3);
|
||||
CHECK(all_null.seen[0].name == "other_slot" && all_null.seen[1].name == "pub_slot" &&
|
||||
all_null.seen[2].name == "pub_slot_2");
|
||||
|
||||
Listing all_empty;
|
||||
CHECK(enum_by_name(save, prefix_provider, "", &all_empty, collect) == S_OK);
|
||||
CHECK(all_empty.seen.size() == 3);
|
||||
|
||||
Listing stopped;
|
||||
stopped.stop_after = 1;
|
||||
CHECK(enum_by_name(save, prefix_provider, "pub_slot", &stopped, collect) == S_OK);
|
||||
CHECK(stopped.seen.size() == 1 && stopped.seen[0].name == "pub_slot");
|
||||
|
||||
// Validation errors on slot 15.
|
||||
CHECK(enum_by_name(save, prefix_provider, "pub_slot", &none, nullptr) == E_INVALIDARG);
|
||||
CHECK(enum_by_name(save, nullptr, "pub_slot", &none, collect) == kInvalidHandle);
|
||||
|
||||
slot<CloseFn>(save, kGsCloseProvider)(save, prefix_provider);
|
||||
}
|
||||
|
||||
slot<CloseFn>(save, kGsCloseUpdate)(save, update);
|
||||
slot<CloseFn>(save, kGsCloseContainer)(save, container);
|
||||
slot<CloseFn>(save, kGsCloseProvider)(save, provider);
|
||||
|
||||
Reference in new issue
Block a user