Compare commits

...
Author SHA1 Message Date
ates 29a5cd70c0 Merge remote-tracking branch 'origin/main' into pr704-r
Signed-off-by: ates <ahmetrizaates@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-30 03:36:48 +03:00
Ateş 690c756037 Merge pull request #696 from 1Bartosz/track-c/create-committed-resource-x
[Boot] unimplemented XboxDevice slot 76 (CreateCommittedResourceX)
2026-11-30 03:35:20 +03:00
ates 5c1efdb517 Merge remote-tracking branch 'origin/main' into pr696-r
Signed-off-by: ates <ahmetrizaates@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-30 03:35:06 +03:00
Ateş 413c46545d Merge pull request #699 from 1Bartosz/track-b/xmem-working-set-stats
[Boot] XMemGetWorkingSetStatistics does not follow the GDK signature
2026-11-30 03:34:45 +03:00
ates 0565e0ac37 Merge remote-tracking branch 'origin/main' into pr699
Signed-off-by: ates <ahmetrizaates@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-30 03:34:31 +03:00
Ateş a74ad2da44 Merge pull request #706 from 1Bartosz/track-f/671-d3dmetal-capability-checks
[Picture] D3DMetal capability checks for translated console shaders
2026-11-30 03:33:25 +03:00
Ateş fc358d0525 Merge pull request #707 from 1Bartosz/track-b/705-dstorage-physical-pages
[Picture] DirectStorage rejects zlib requests with physical-page destinations
2026-11-30 03:32:42 +03:00
Ateş e502559470 Merge pull request #703 from MacosPorters/abi/xmem-remap-guard-contract
[ABI] Define the XMem remap guard contract
2026-11-30 03:32:24 +03:00
Bartosz Szczepański 06cd29a9a4 Merge remote-tracking branch 'origin/main' into track-b/705-dstorage-physical-pages 2026-11-30 00:45:14 +01:00
Ateş b49b0d9696 Merge pull request #691 from 1Bartosz/track-b/668-xmem-atomic-remap
[Boot] fault in XCRDAPI.dll: page remapping in xmem is not atomic
2026-11-30 02:26:15 +03:00
Bartosz Szczepański 5a53fe1fd5 changelog: DirectStorage physical-page destinations (#705)
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-30 00:13:45 +01:00
Bartosz Szczepański 0c8a583378 d3d12_xs: read DccOptions as the GDK struct of two enums
D3D12XBOX_DCC_OPTIONS is a struct of CompressionLevel and ColorTransform
(GDK d3d12_xs.h), not a single 32-bit enum. CreateCommittedResourceX read
only the first field and logged only non-zero values, although
CompressionLevel 0 is 64B compression, not none. Both fields are now read
and logged for the first 8 calls; the test lays the struct out as two
32-bit fields and asserts the 64-byte size.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-30 00:13:12 +01:00
Bartosz Szczepański 6fbe856b4e xcrdapi: write DirectStorage requests into physical-page destinations (#705)
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-30 00:09:33 +01:00
Bartosz Szczepański 084714739f xcrdapi: claim: DirectStorage requests with a physical-page destination (#705)
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-30 00:04:51 +01:00
Bartosz Szczepański 33a3ec2329 Merge origin/main into track-b/xmem-working-set-stats
CHANGELOG.md: keep both sides' Fixed entries, this branch's first.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 23:38:47 +01:00
Bartosz Szczepański 84dd9e2df5 tests: cover the inflater and memory sources in test_xcrdapi_remap_guard
Review of #691 (point 1): the test only queued uncompressed requests into the window, so the mutant without the guard around the inflater passed. It now also inflates zlib streams into the window (built by hand from fixed Huffman codes, with a control run without remaps) and queues memory requests reading out of the window. The inflater mutant now dies in an access violation in 4 of 5 runs (a race, so not every run).

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 23:26:43 +01:00
ates 2dc58a3b25 Integrate main and address the DirectStorage remap guard review
Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-30 00:58:28 +03:00
Bartosz Szczepański 394525b8d0 Merge remote-tracking branch 'origin/main' into track-c/create-committed-resource-x
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-29 22:56:56 +01:00
Bartosz Szczepański 5acabd2f6e tests: D3DMetal capability checks for translated console shaders (#671)
test_d3dmetal_translator_caps measures, against the host D3D12 runtime: SM 6.6 descriptors fetched by index (runs correctly), a 64-lane wave emulated over a 64-thread group through groupshared memory and through merged host waves (workaround), and amplification and mesh shaders (runs correctly). With the 64-bit atomic results of test_d3dmetal_gpu_limits (workaround: native atomics are not run, the lock emulation is exact), no need is blocked. Results are recorded in docs/research/d3dmetal-gpu-limits.md.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 22:55:57 +01:00
Bartosz Szczepański 6957389fef tests: claim #671 D3DMetal capability checks for translated console shaders
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 22:49:49 +01:00
ates 147888c125 GameInput: expose a keyboard-backed gamepad
Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-30 00:46:24 +03:00
ates d649610b7b Define the XMem remap guard contract
Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-30 00:16:03 +03:00
Ateş 49e98cd684 Merge pull request #695 from 1Bartosz/track-c/console-texture-tile-size
[Boot] exit status 3 on the Series S path: committed render targets request host sizes, not console tile sizes
2026-11-30 00:07:24 +03:00
ates df7a83c734 Merge main into committed texture tile sizing
Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-30 00:03:45 +03:00
Ateş 710103c70a Merge pull request #698 from MacosPorters/track-c/title-memory-geometry
[Picture] UI layer draws nothing: index and vertex data bound from plain title memory
2026-11-29 23:38:36 +03:00
ates bddd6f0030 Merge main into Track C title-memory geometry
Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 23:35:14 +03:00
Ateş daca10b4fb Merge pull request #702 from MacosPorters/docs/own-translator
[Process] Roadmap: BetterXen writes its own shader translator
2026-11-29 23:29:09 +03:00
Ateş 441fec14c8 Merge pull request #697 from MacosPorters/track-c/rect-list
[Picture] half the screen missing: console rectangle lists
2026-11-29 23:28:51 +03:00
ates 9dd8f4f916 Merge remote-tracking branch 'origin/main' into track-c/rect-list
Signed-off-by: ates <ahmetrizaates@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-29 23:28:37 +03:00
Ateş c9388313e4 Merge pull request #694 from MacosPorters/track-a/clwb-flush-loop
[Boot] trap storm: CLWB range loop traps once per 64 bytes
2026-11-29 23:28:05 +03:00
ates 073aa40a97 Merge remote-tracking branch 'origin/main' into track-a/clwb-flush-loop
Signed-off-by: ates <ahmetrizaates@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-29 23:26:24 +03:00
ates 142fec28a2 Roadmap: BetterXen writes its own shader translator
The repository owner decided on 2026-11-29 not to use the upstream
emulator's translator. The Picture stage's translator step now
describes a translator of our own in shader-transpiler/: one rule per
instruction, registers as variables, control flow as numbered blocks in
a dispatch loop, each rule checked against the console compiler's
output for a shader of our own.

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 23:25:53 +03:00
Bartosz Szczepański 05b27f886f Merge origin/main into track-b/xmem-working-set-stats
CHANGELOG.md: keep both sides' Fixed entries, this branch's first.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 21:00:11 +01:00
ates 86ebd5c12c d3d12_xs: draw index and vertex data bound from plain title memory
On the console a GPU virtual address is the title's own address and the
GPU reads the memory when the commands execute. A title binds index and
vertex data it keeps in plain memory, with no Direct3D resource, and may
write it after recording the draw. Such bindings were left empty.

- bx_xbox_bind_title_memory (placed_x.cpp) finds the host buffer that
  holds the whole bound range, or creates a CPU-writable one for plain
  readable title memory, and records the range on the list.
- When a list is submitted, every range bound on it since its reset is
  copied from the title memory to its host buffer, before the host
  executes the list.
- Memory that is not readable still leaves the binding empty and is
  logged as unimplemented.

test_d3d12_title_memory_geometry draws an indexed triangle and a
non-indexed one (through a view that starts inside the same memory) from
VirtualAlloc memory written after the draws were recorded, then changes
the data and submits a second list: 26 of 26 checks by pixel readback,
twice in a row; against main's d3d12_xs the host never completes the
work. test_d3d12_unbacked_buffers now checks that plain memory is not
logged and that unreadable address space is, exactly once per binding.

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 22:12:58 +03:00
Bartosz Szczepański 73cee37ee3 d3d12_xs: implement CreateCommittedResourceX
Slot 76 takes D3D12XBOX_RESOURCE_DESC, the PC resource description followed by DccOptions. It now creates the resource from the PC part through the CreateCommittedResource path, so console formats are translated and the XMemAlloc request is made; DccOptions has no host counterpart and is logged and ignored. The generator routes the slot; the regenerated table differs only in that slot.

Test: test_d3d12_committed_resource_x; it fails on main with E_NOTIMPL.
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 20:03:48 +01:00
ates 10238c33b4 d3d12_xs: draw console rectangle lists as triangle strips
D3D_PRIMITIVE_TOPOLOGY_RECTLIST (17) and D3D12XBOX_PRIMITIVE_TOPOLOGY_TYPE_RECT
(19) are Xbox extensions: three vertices per rectangle, the fourth corner
v0 + v2 - v1. The host knows neither value; a title's full-screen passes
drew half a rectangle or nothing.

- Pipelines are created with the triangle topology type when the title
  asks for a console type, and their input layout is remembered.
- IASetPrimitiveTopology(RECTLIST) sets TRIANGLESTRIP on the host.
- A non-indexed draw builds four vertices per rectangle (order v1, v2,
  v0, v3, which keeps the winding) in a host upload ring, from the
  title's slot-0 vertex data and the pipeline's input layout, then puts
  the title's binding back.
- Indexed rectangle lists, layouts with per-vertex data outside slot 0
  and unhandled element formats are logged as unimplemented.

test_d3d12_rect_list renders through an Xbox-layout device and reads the
pixels back: full coverage and the computed fourth corner for one
rectangle, two rectangles in one draw from a non-zero first vertex, an
ordinary triangle list afterwards, and the unimplemented log for an
indexed rectangle list. 25 of 25 checks, twice in a row; against main's
d3d12_xs the host never completes the work.

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 22:02:21 +03:00
Bartosz Szczepański 5a8aa63835 d3d12_xs: claim: implement CreateCommittedResourceX
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 20:00:39 +01:00
Bartosz Szczepański c0698e9fd4 Merge remote-tracking branch 'origin/main' into track-c/console-texture-tile-size
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-29 19:35:37 +01:00
Bartosz Szczepański 9f6fef064c Merge remote-tracking branch 'origin/main' into track-b/668-xmem-atomic-remap
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-29 19:35:24 +01:00
Bartosz Szczepański 94a22926d2 d3d12_xs: request console 64 KB tile sizes for committed render targets
The console lays out a 2D render-target or UAV texture with one mip and one sample in 64 KB tiles (64KB_R_X), and a title hooking XMemAlloc sizes its pool for those requests and asserts that less than 2 MB is left. The XMemAlloc request for those textures is now the tile size, from the title's format; other resources keep the host's size. Render-target compression metadata is not modelled.

Test: test_d3d12_committed_tile_size; three of its six cases fail on main.
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 18:49:09 +01:00
Ateş f6bec97548 Merge pull request #693 from MacosPorters/track-c/unbacked-buffer-bindings
[Boot] null read in D3DMetal under IASetIndexBuffer: unbacked index and vertex bindings
2026-11-29 20:41:25 +03:00
ates 638673a173 Merge remote-tracking branch 'origin/main' into track-c/unbacked-buffer-bindings
Signed-off-by: ates <ahmetrizaates@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-29 20:41:08 +03:00
Bartosz Szczepański 1e0ffb642c Merge remote-tracking branch 'origin/main' into track-c/console-texture-tile-size
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 18:40:54 +01:00
Bartosz Szczepański b88fb86dbc d3d12_xs: claim: request console 64 KiB tile sizes for committed render targets
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 18:40:23 +01:00
Ateş 7feebe38f6 Merge pull request #690 from MacosPorters/track-c/console-only-formats
[Boot] Metal abort: console-only DXGI formats and depth-stencil unordered-access views
2026-11-29 20:40:14 +03:00
Bartosz Szczepański b8d709fed0 xmem: XMemGetWorkingSetStatistics follows the documented signature
The export took (out_stats, stats_size) and wrote BetterXen's own 32-byte
bx_xmem_stats_t. The authorized GDK header declares it as
(WorkingSetFlags, Statistics) with a 120-byte XMEM_WORKING_SET_STATISTICS,
so a title calling it as documented had its flags read as the output
address and the shim zeroed memory there.

The shim now takes the documented arguments and writes the whole
structure from xmem's own accounting: GameLimit is the title cap,
GameUsed everything the cap counts, GameUsedPeak its highest value and
GameAllocatedPhysicalPageCount the 64 KiB physical pages. Tools fields
are 0 since tools memory is unavailable; counters the host does not have
or xmem does not count are 0. A NULL structure or flags outside the five
XMEM_WORKING_SET_* values fail with ERROR_INVALID_PARAMETER.
bx_xmem_get_internal_stats keeps its contract for internal callers.

New test_xmem_working_set reads the structure between guard bands at
offsets written out from the header and fails against the previous
xmem.dll. test_xmem, test_xmem_physical, test_xmem_external_charge and
test_d3d12_placed use the documented form. test_xmem_physical reads its
two aliased page views through volatile, since the compiler cannot see
that they share a page and scheduled the read before the write.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 18:38:41 +01:00
ates f3eadff31c tests: conformance test for CLWB range loops
test_veh_clwb_loop runs its own machine-code loops (jbe with pointer
rcx and r9, jb with limit r10, an unaligned start with the limit inside
a line, a one-iteration range, a limit below the start, and a form with
a NOP that must keep the per-instruction path). It checks the final
pointer against the loop's definition, the number of illegal-instruction
exceptions, and that memory is unchanged.

Against main's handler the four loop cases take one exception per line
(1,000 to 12,345). 15 of 15 checks pass with the fix, twice in a row.

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 20:32:18 +03:00
ates 00c270062b tests: conformance test for unbacked index and vertex bindings
test_d3d12_unbacked_buffers records into an Xbox-layout command list:
bindings inside a committed buffer (translated, not logged), an index
binding and the second of two vertex streams in plain title memory
(each left empty and logged as unimplemented exactly once), and null
bindings (unchanged, not logged). The list must still close.

Against main's d3d12_xs the process dies with a read at 0xa8 inside
D3DMetal, the same fault the target build hit. 13 of 13 checks pass
with the fix, twice in a row.

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 20:19:39 +03:00
Bartosz Szczepański 961cf7e26c xmem, xcrdapi: hold a remap guard while storing into a window that is being remapped (#668)
Windows and Wine cannot replace a mapped view in one step, so a thread storing into a neighbouring page while XMemMapPhysicalPages, XMemMapPhysicalPagesScatter or XMemFreePhysicalPages remaps a range faults in the gap. xmem.dll now exports bx_xmem_remap_guard_enter/_leave; the three calls wait for every open guard and XCRDAPI.dll holds it while it stores into a memory destination.

Tests: test_xmem_remap_guard and test_xcrdapi_remap_guard; both die in an access violation without the guard.
Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-29 17:54:35 +01:00
ates 4389f74b2b d3d12_xs: leave index and vertex bindings empty when the address has no host buffer
A title binds index and vertex data by address in plain title memory,
with no Direct3D resource behind it. The address was passed to the host
unchanged and D3DMetal dereferenced the buffer it failed to find (a
null read under IASetIndexBuffer). Such a binding is now left empty and
logged as unimplemented. Supplying the data is separate work.

Work in progress: no conformance test or changelog entry yet.

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 18:50:57 +03:00
ates 0ab348cb5d tests: conformance test for console-only formats and depth-stencil unordered-access views
test_d3d12_console_formats drives an Xbox-layout device through its
function table: allocation info in all three forms for format 118 and
the four colour formats (expected sizes are the host's answers for the
documented substitute formats, asked for directly), a committed depth
texture and clear value in format 118, depth-stencil and plane views in
formats 118, 119 and 120, and an unordered-access view on a
depth-stencil texture, which must be logged as unimplemented exactly
once while a view on an ordinary texture is not.

Against main's d3d12_xs the process dies in Metal at the first
console-only format. 21 of 21 checks pass with the fix, twice in a row.

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 18:46:49 +03:00
ates 46e7135f6c d3d12_xs: translate console-only DXGI formats and refuse depth-stencil UAVs before the host sees them
The Xbox Series DXGI_FORMAT enumeration has values the PC one lacks
(116-120, 189, 190). D3DMetal turns one into an invalid Metal pixel
format and Metal aborts the process, so no error code comes back. A
title also creates unordered-access views on depth-stencil textures,
which the console allows and PC Direct3D 12 forbids; D3DMetal answers
with a Metal texture view that Metal refuses, again by aborting.

- console_formats.h: bx_host_format and bx_host_resource_format map
  each console-only format to the nearest host format. A depth texture
  is created typeless and each view names the concrete format.
- The three GetResourceAllocationInfo forms, CreatePlacedResource,
  CreateReservedResource, the four view-creation methods, the four
  committed-resource forms, CreatePlacedResourceX and the four placed
  view forms translate before calling the host.
- An unordered-access view on a depth-stencil resource becomes a null
  view of the same description and is logged as unimplemented.

The Xbox device table routes nine more slots to hand-written entry
points (generated by tools/gen_xbox_tables.py).

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 18:29:48 +03:00
ates 784e1ea439 runtime_veh: complete a CLWB range loop in one exception
A title flushes an address range with clwb [reg]; add reg, 0x40;
cmp reg, limit; jbe|jb. Each CLWB trapped, so a 6 MB range cost about
94,000 exception round trips. CLWB changes no register, flag or memory
content, so the handler now advances the pointer register to the last
value the loop would have used and lets the title's own add/cmp/jcc
leave the loop. Other forms keep the per-instruction path.

Signed-off-by: ates <ahmetrizaates@hotmail.com>
2026-11-29 17:43:32 +03:00
Ateş bff53517be Merge pull request #685 from MacosPorters/track-e/667-gamesave-container-info
[Boot] xgameruntime: serve IXGameSaveImpl slots 13 and 15
2026-11-29 16:57:49 +03:00
ates 6898077c20 Merge remote-tracking branch 'origin/main' into fix-685
Signed-off-by: ates <ahmetrizaates@hotmail.com>

# Conflicts:
#	CHANGELOG.md
2026-11-29 16:57:18 +03:00
Ateş 49585b92b0 Merge pull request #686 from MacosPorters/track-e/666-async-run-task-queues
[Boot] xgameruntime: XAsyncRun and task-queue duplicate, port and composite
2026-11-29 16:56:23 +03:00
erkinemreta1 ab7863142e test_xgameruntime_saves: isolate slot 15 prefix checks in their own provider
Signed-off-by: erkinemreta1 <erkinemreta1@users.noreply.github.com>
2026-11-29 15:07:47 +03:00
erkinemreta1 80fb4cc1f6 xgameruntime: serve IXGameSaveImpl slots 13 and 15
Signed-off-by: erkinemreta1 <erkinemreta1@users.noreply.github.com>
2026-11-29 14:45:06 +03:00
75 changed files with 8339 additions and 175 deletions

No files matched your search

+22
View File
@@ -10,6 +10,7 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game
remains unsupported.
### Changed
- **Roadmap, Picture stage: BetterXen writes its own shader translator** (repository owner's decision, 2026-11-29). The step that said to vendor the upstream GFX10-to-DXIL translator now describes a translator of our own in `shader-transpiler/`: one rule per instruction, control flow as numbered blocks, each rule checked against the console compiler.
- **A collaborator only has to say "work"** (AGENTS.md §0, step 1). When `bx-cli preflight` fails, the agent makes the machine ready itself: the new `bx-cli setup --find` searches the home folder, recognises the GDK by its header and the target build by its structure (a large PE32+ file that imports `d3d12_xs.dll`; never by name), ignores the GDK's own tools, treats byte-identical copies as one build and keeps the copy with its imported DLLs beside it, and saves both settings. The agent may install `mingw-w64`, `cmake` and `gh` with Homebrew and free disk space by removing its own scratch. It stops only for what it cannot supply: no Apple Silicon Mac, no CrossOver, the build or the GDK not on the machine, or more than one distinct build.
- **Working rules: the pull request is the unit of work, and the target build and the GDK are required** (AGENTS.md §0, [working method](docs/process/working-method.md)). An agent told to "work" first runs the new `bx-cli preflight`, which fails unless the host is an Apple Silicon Mac with CrossOver, D3DMetal and `mingw-w64`, the target build's executable and the GDK folder are known, and 10 GiB of disk is free. A collaborator records the two locations once with the new `bx-cli setup --target-exe <path> --gdk-root <folder>`, which checks them and keeps them in `~/.config/betterxen/local.conf`, outside the repository (`BX_TARGET_EXE` and `BX_GDK_ROOT` override it). If preflight fails the agent stops and does no work. A blocker the agent can fix no longer gets an issue: it is claimed by a draft pull request titled with its run-report signature. Issues are kept for handoffs (label `handoff`), decisions for a person, and the ladder status. Claims by comment and the 7-day stale window are gone; an idle draft may be taken over after 3 days.
- **BetterXen is no longer a clean-room project** (repository owner's decision, #650). `CONTRIBUTING.md` now says that material the project is authorized to use, such as the GDK and its compilers, may be used and that facts derived from it may be committed, while the material and its outputs are never committed. Leaked or unauthorized material remains forbidden.
@@ -26,6 +27,9 @@ 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
- `GameInput.dll` exposes one keyboard-backed gamepad through v0 blocking enumeration and current readings. Enter or Space maps to A, Escape or Backspace to B, arrow keys to the D-pad, WASD and IJKL to the two sticks, Q/E to shoulders, Z/C to triggers, F/H to stick clicks, X/Y to the matching face buttons, and P/Tab to Menu/View. Input returns to neutral when another application owns the foreground.
- **D3DMetal capability checks for translated console shaders** (#671). `test_d3dmetal_translator_caps` measures, against the host D3D12 runtime, the features a translator of console code needs: SM 6.6 descriptors fetched by index (UAV, raw and typed SRVs, texture and sampler) run correctly; a 64-lane wave emulated over a 64-thread group gives the 64-lane answers through groupshared memory and through merged 32-lane host waves; amplification and mesh shaders draw correctly. With the 64-bit atomic results of `test_d3dmetal_gpu_limits` (native 64-bit atomics are not run even though D3DMetal reports support; the lock emulation with a 1024 cap is exact), no need is blocked. Results are in [D3DMetal GPU limits](docs/research/d3dmetal-gpu-limits.md#capability-checks-for-translated-console-shaders-671).
- `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 +93,24 @@ 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
- **`CreateCommittedResourceX` is implemented** (#696). Slot 76 of the Xbox device table takes a `D3D12XBOX_RESOURCE_DESC`, which is the PC resource description followed by `DccOptions` (authorized GDK header). It now creates the resource from the PC part through the same path as `CreateCommittedResource` (console format translation, the `XMemAlloc` request a title's hook sees); `DccOptions` (a struct of `CompressionLevel` and `ColorTransform`), console colour compression, has no host counterpart; both fields are logged for the first 8 calls and ignored. Until now the slot returned `E_NOTIMPL`, and the target build exited with status 99 about a second after it was refused. `tools/gen_xbox_tables.py` routes the slot to the new entry point; the regenerated table differs only there. Test: `test_d3d12_committed_resource_x`.
- `xmem.dll!XMemGetWorkingSetStatistics` takes the documented `(WorkingSetFlags, Statistics)` and fills the documented 120-byte `XMEM_WORKING_SET_STATISTICS` (source: the authorized GDK header). Before, it took `(out_stats, stats_size)` and wrote BetterXen's own 32-byte `bx_xmem_stats_t`. A title calling it as documented had its flags read as the output address and its structure pointer as the size, and the shim zeroed memory at the flags value. A project-authorized target build calls it on a tools-memory path with the tools and kernel-pool flags and treats `FALSE` as fatal; runs have not reached that path yet.
- **Values:** the whole structure is written, whatever the flags. `GameLimit` is the title cap, `GameUsed` everything the cap counts (XMem heap, virtual commits, physical pages and external charges), `GameUsedPeak` its highest value and `GameAllocatedPhysicalPageCount` the 64 KiB physical pages. The tools fields are 0, since `XMemIsToolsMemAvailable` is `FALSE`. The counters the host does not have or xmem does not count are 0 (stack, GPU-optimal bandwidth, kernel pool, DirectStorage, frame-preserve buffer, page tables), and so are the reserved words. These values are BetterXen's inference.
- **Refusals:** a NULL structure, or flags outside the five `XMEM_WORKING_SET_*` values, fails with `ERROR_INVALID_PARAMETER` and logs `working_set_statistics`. `bx_xmem_get_internal_stats` is unchanged for internal callers.
- **Tests:** new `test_xmem_working_set` reads the structure between guard bands at offsets written out from the header, with the tools and kernel-pool flags, `XMEM_WORKING_SET_TITLE` and `XMEM_WORKING_SET_ALL`. Against the previous `xmem.dll` it fails with an access violation inside the call. `test_xmem`, `test_xmem_physical`, `test_xmem_external_charge` and `test_d3d12_placed` use the documented form. `test_xmem_physical` now reads its two aliased page views through `volatile`: the compiler cannot see that they share a page, and after this change it scheduled the read before the write.
- **Not covered:** `XMemVirtualQuery` and `XMemTransferMemory` still differ from their documented signatures (#642).
- **`XCRDAPI.dll`: DirectStorage requests can write into physical pages** (#705). With `DestinationIsPhysicalPages` (bit 21 of `DSTORAGE_REQUEST_OPTIONS`), the destination of an Xbox request is an array of 64 KB page numbers from `XMemAllocatePhysicalPages` and a 16-bit offset into the first page, at +0x08 and +0x10 (authorized GDK header). `IDStorageQueueX::EnqueueRequest` refused such requests with `E_NOTIMPL`, and the target build stopped at a breakpoint about two milliseconds later (exit status 3). The request now maps its pages through `xmem.dll`'s `XMemMapPhysicalPages` with a NULL address (the existing BetterXen extension) into a span of its own, writes the destination there, file or memory source, plain or zlib, and unmaps the span once it is fulfilled; the pages are sections, so the title's views see the bytes. A physical-page source (`SourceIsPhysicalPages`) is still refused and logged as `EnqueueRequest_physical_page_source`. Test: `test_xcrdapi_page_destination` (19 checks: a zlib file request across three pages given out of order from an offset, an uncompressed memory request across a page boundary, an unallocated page number, the refused source form).
- **`d3d12_xs.dll`: index and vertex data bound from plain title memory are drawn.** A title keeps such data in its own memory with no Direct3D resource, and may write it after recording the draw. A bound range now gets a CPU-writable host buffer (once; later ranges inside it reuse it) and every range bound on a list is copied from the title memory when the list is submitted (`bx_xbox_bind_title_memory`, `placed_x.cpp`). This replaces leaving such bindings empty; only memory that is not readable is still left empty and logged as unimplemented. Tests: `test_d3d12_title_memory_geometry` (26 checks, pixel readback, data written after recording and changed between submissions); `test_d3d12_unbacked_buffers` now covers the unreadable case.
- **`d3d12_xs.dll`: console rectangle lists are drawn.** `D3D_PRIMITIVE_TOPOLOGY_RECTLIST` (17) and the pipeline topology type `D3D12XBOX_PRIMITIVE_TOPOLOGY_TYPE_RECT` (19) are Xbox extensions (GDK `d3d12_xs.h`): three vertices per rectangle, the fourth corner `v0 + v2 - v1`. The host knew neither value, so a title's full-screen passes drew half a rectangle or nothing. A rectangle list is now drawn as triangle strips (`rect_list.cpp`): the pipeline is created with the triangle type, and a non-indexed draw builds four vertices per rectangle from the title's vertex data and the pipeline's input layout. Indexed rectangle lists and quad lists are not emulated and are logged as unimplemented. Test: `test_d3d12_rect_list` (25 checks, pixel readback).
- **`bx_runtime_veh.dll`: a CLWB range loop completes in one exception.** A title flushes an address range with `clwb [reg]; add reg, 0x40; cmp reg, <reg64>; jbe|jb`; each CLWB trapped under Rosetta, about 94,000 exception round trips per 6 MiB buffer. CLWB changes no register, flag or memory, so the handler now advances the pointer register to the last value the loop would have used and the title's own add/cmp/jcc leaves the loop. Other forms keep the per-instruction path. Test: `test_veh_clwb_loop` (15 checks; without the fix the four loop cases take one exception per line).
- **Committed render targets request the console's size from XMemAlloc** (#695). The console lays out a 2D render-target or unordered-access texture with one mip and one sample in 64 KB tiles (64KB_R_X for every size: 128x128 elements at 4 bytes, 128x64 at 8, 64x64 at 16, 256x128 at 2, 256x256 at 1; authorized GDK XG library), and a title that hooks XMemAlloc sizes its pool for those requests and asserts that less than 2 MB is left over. `d3d12_xs.dll` requested the host's size instead, 1920x1080 RGBA8 as 128 pages where the console takes 135, and on the Series S path the target build stopped on that assertion. The XMemAlloc request for those textures is now the tile size, computed from the title's format; every other resource keeps the host's size, and XG's render-target compression metadata after the tiles (8 KB to 96 KB in the cases measured) is not modelled. `GetResourceAllocationInfo` still answers with the host's size. Test: `test_d3d12_committed_tile_size`.
- **XCRDAPI holds an xmem guard while accessing title memory** (#668). Replacing a mapped view on Windows or Wine can temporarily make pages in that view inaccessible. DirectStorage reads and writes that can touch title memory now hold the shared guard while xmem mapping and freeing operations hold it exclusively. A loaded xmem DLL without both guard exports produces a warning. The guard covers DirectStorage accesses through BetterXen. `test_xcrdapi_remap_guard` exercises memory-to-memory stores into a window, zlib streams inflated into it and memory requests reading out of it while it is remapped; accesses by the title's own threads are not covered.
- **`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:
+2
View File
@@ -17,3 +17,5 @@ EXPORTS
bx_xmem_get_internal_stats
bx_xmem_try_charge_external
bx_xmem_release_charge_external
bx_xmem_remap_guard_enter @18
bx_xmem_remap_guard_leave @19
+12
View File
@@ -51,6 +51,18 @@ int bx_xmem_try_charge_external(uint64_t bytes);
* unchanged and an external_charge error is logged. */
void bx_xmem_release_charge_external(uint64_t bytes);
/* The remap guard protects BetterXen reads and writes to title memory while
* XMemMapPhysicalPages, XMemMapPhysicalPagesScatter or XMemFreePhysicalPages
* replaces mapped views. Those operations wait for active guards and block
* new guards until the remap completes.
*
* Pair each enter with one leave on the same thread. Keep the guard short,
* avoid nesting it, and release it before calling an XMem function.
* Consumers that resolve the helpers dynamically must resolve both or
* call neither. */
void bx_xmem_remap_guard_enter(void);
void bx_xmem_remap_guard_leave(void);
#ifdef __cplusplus
}
#endif
+20
View File
@@ -127,6 +127,26 @@ for a recording recipe. Through `bx-cli run` the guest status is returned unchan
Still to do for the issue's validation requirement: an independent run on CrossOver 26.3
(D3DMetal 3.0) by another contributor.
## Capability checks for translated console shaders (#671)
A translator of console code needs four things from D3DMetal. Each has a synthetic check with
one of three results: *runs correctly*, *workaround* (the translator can get the console's
answer another way) or *blocked*. The checks talk to the host `d3d12.dll` directly, so they
measure D3DMetal, not BetterXen. Expected values are computed on the CPU.
Machine: Apple M5 (32 GB), macOS 27.2.1, CrossOver 26.3, D3DMetal; each check run twice in a
row with the same result.
| Need | Check | Result | What was measured |
| --- | --- | --- | --- |
| Descriptors fetched by index (SM 6.6 dynamic resources) | `test_d3dmetal_translator_caps` `heap_index` | **runs correctly** | Resource binding tier 3. A UAV, a raw SRV, a typed SRV, a texture and a sampler, all taken from the descriptor heaps by index (`ResourceDescriptorHeap`, `SamplerDescriptorHeap`, root signature flags `CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED` and `SAMPLER_HEAP_DIRECTLY_INDEXED`): all 65 values correct. |
| 64-lane waves | `test_d3dmetal_translator_caps` `wave64`, with `test_d3dmetal_gpu_limits` `wave` | **workaround** | The host runs 32-lane waves (`WaveLaneCountMin = Max = 32`), and a `[WaveSize(64)]` kernel is created but not run (above). A 64-thread group standing for one 64-lane wave gives the 64-lane ballot, exclusive prefix sum, read-lane and sum on all 64 lanes, both through groupshared memory and through the host's own wave operations merged across its two waves. |
| 64-bit atomics on typed resources | `test_d3dmetal_gpu_limits` `atomic64`, `lock64` | **workaround** | D3DMetal reports `AtomicInt64OnTypedResourceSupported = 1` and `AtomicInt64OnDescriptorHeapResourceSupported = 1`, but kernels using 64-bit atomics, on typed and on raw resources, are created and not run: even their plain stores are missing. The per-texel lock over 32-bit words with a retry cap of 1024 is exact (0 of 512 updates dropped); with a cap of 64 it drops updates. A translator must not trust the reported support. |
| Amplification and mesh shaders | `test_d3dmetal_translator_caps` `mesh` | **runs correctly** | `D3D12_MESH_SHADER_TIER_1` (enum value 10). An amplification shader passes a payload to two mesh groups through `DispatchMesh`; each draws half of a 4x4 target with a pixel shader: all 16 pixels correct. |
No need is *blocked*, so no ADR is required by #671. The shaders are regenerated with
`tests/conformance/test_d3dmetal_translator_caps/shaders/compile.sh` (same DXC release as below).
## Unverified reports (not evidence)
Reported on #453 from local VIctory-macOS-based builds running a commercial title on one
+1 -1
View File
@@ -82,7 +82,7 @@ Every gate below is measured the same way ([working method](process/working-meth
This is where the shader translator becomes the critical path, and where the D3DMetal route is tested for real. The risk checks come **first**, before feature work depends on them.
1. **Capability checks on D3DMetal (first).** Synthetic tests, one each, for what translated shaders need: direct descriptor-heap indexing (SM 6.6), 64-lane compute behaviour through the translator's emulation, 64-bit atomics on typed resources, mesh and amplification shaders. Each ends in *runs correctly*, *can be worked around in the translator*, or *blocked*. A *blocked* result opens an ADR on the back end, marked `needs-human`, before anything else in this stage continues.
2. **The translator.** Vendor a pinned copy of the authorized upstream GFX10-to-DXIL translator into `shader-transpiler/` (per-file licence check, upstream registry and reuse matrix entries, ADR 0008 amendment), and expose it through `bx_shader_bridge.dll`. BetterXen owns its copy and fixes it.
2. **The translator.** BetterXen writes its own GFX10-to-DXIL translator in `shader-transpiler/` and exposes it through `bx_shader_bridge.dll`; the upstream emulator's translator is not used (repository owner's decision, 2026-11-29). The design is mechanical: one rule per instruction, registers as variables, and control flow as numbered blocks in a dispatch loop, so no structure has to be reconstructed. Each rule is checked against the console compiler's output for a shader of our own (source rank 2). A prototype on branch `experiment/visible-frame` translates the four pipelines of the build's first screen and is the reference for that screen.
3. **Translator verification.** Extend the known-source corpus (#650) so every instruction class the first screens use is checked against a reference result. A translator bug is found with a ten-line shader, not in a broken frame.
4. **The first pipelines.** The clear pipeline, the display-mapping compute shader, and whatever the first reference screen draws with, created on the host on first use.
5. **Descriptors and memory the shaders read.** The descriptor model the translated shaders expect; contents of textures placed in title memory (today a logged stub); title-written constant and vertex data reaching the GPU.
+2
View File
@@ -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
rect_list.cpp
gpu_writes.cpp
fences.cpp
presentx_xbox.cpp
+113 -8
View File
@@ -11,10 +11,21 @@
* hooks and title address checks see what they would see on the console. The page size the
* console runtime requests is not documented: this layer asks for 2 MB pages for allocations of
* at least 2 MB and 64 KB pages otherwise (measured against one title; logged per resource).
*
* The size of that request is the console's, not the host's, where the console layout is known:
* a 2D render-target or unordered-access texture with one mip and one sample is laid out by the
* console in 64 KB tiles (swizzle mode 64KB_R_X for every size; authorized GDK XG library). A
* title that sizes its pool for those requests and checks what is left over sees the amount it
* expects. The compression metadata XG adds after the tiles of a render target (8 KB to 96 KB in
* the cases measured) is not included; every other resource keeps the host's size.
*/
#include "xbox_facade.h"
#include "console_formats.h"
#include <atomic>
#include <cstdio>
#include <cstring>
extern "C" __declspec(dllimport) PVOID WINAPI XMemAlloc(SIZE_T size, ULONGLONG attributes);
@@ -26,18 +37,67 @@ constexpr ULONGLONG kPageSize64K = 1ull << 14; // XALLOC_ATTRIBUTES.PageS
constexpr ULONGLONG kPageSize2M = 2ull << 14;
constexpr UINT64 k2M = 2ull << 20;
HRESULT finish(ID3D12Device* device, HRESULT hr, REFIID riid, void** ppv, const char* method) {
constexpr UINT64 k64K = 64ull << 10;
// Bytes per element of an uncompressed colour format, 0 for anything else (depth, block
// compressed, video, 96-bit). Formats 116, 117, 189 and 190 are console-only (GDK DXGI_FORMAT).
UINT colour_element_bytes(DXGI_FORMAT f) {
const UINT v = static_cast<UINT>(f);
if (v >= DXGI_FORMAT_R32G32B32A32_TYPELESS && v <= DXGI_FORMAT_R32G32B32A32_SINT) return 16;
if (v >= DXGI_FORMAT_R16G16B16A16_TYPELESS && v <= DXGI_FORMAT_R32G32_SINT) return 8;
if (v >= DXGI_FORMAT_R10G10B10A2_TYPELESS && v <= DXGI_FORMAT_R32_SINT) return v == DXGI_FORMAT_D32_FLOAT ? 0 : 4;
if (v >= DXGI_FORMAT_R8G8_TYPELESS && v <= DXGI_FORMAT_R16_SINT) return v == DXGI_FORMAT_D16_UNORM ? 0 : 2;
if (v >= DXGI_FORMAT_R8_TYPELESS && v <= DXGI_FORMAT_A8_UNORM) return 1;
if (v >= DXGI_FORMAT_B8G8R8A8_UNORM && v <= DXGI_FORMAT_B8G8R8X8_UNORM_SRGB) return 4;
if (v == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM || v == DXGI_FORMAT_R9G9B9E5_SHAREDEXP) return 4;
if (v >= DXGI_FORMAT_B5G6R5_UNORM && v <= DXGI_FORMAT_B5G5R5A1_UNORM) return 2;
if (v == DXGI_FORMAT_B4G4R4A4_UNORM) return 2;
if (v == 116 || v == 117 || v == 189) return 4; // R10G10B10_7E3_A2_FLOAT, _6E4_A2_FLOAT, _SNORM_A2_UNORM
if (v == 190) return 1; // R4G4_UNORM
return 0;
}
// The console's size for `desc` (the host's geometry, the title's format) where its layout is
// known, else 0. The tile of a 64 KB swizzle holds 64 KB of elements: 256x256 at 1 byte,
// 256x128 at 2, 128x128 at 4, 128x64 at 8 and 64x64 at 16 (authorized GDK XG library: these
// tile counts match its sizes exactly, before the metadata of a render target).
UINT64 console_tiled_size(const D3D12_RESOURCE_DESC& desc, DXGI_FORMAT title_format) {
constexpr UINT kTargets = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.Layout != D3D12_TEXTURE_LAYOUT_UNKNOWN ||
desc.MipLevels != 1 || desc.SampleDesc.Count != 1 || !(desc.Flags & kTargets) ||
(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) {
return 0;
}
UINT tile_w = 0, tile_h = 0;
switch (colour_element_bytes(title_format)) {
case 1: tile_w = 256; tile_h = 256; break;
case 2: tile_w = 256; tile_h = 128; break;
case 4: tile_w = 128; tile_h = 128; break;
case 8: tile_w = 128; tile_h = 64; break;
case 16: tile_w = 64; tile_h = 64; break;
default: return 0;
}
const UINT64 across = (desc.Width + tile_w - 1) / tile_w;
const UINT64 down = (static_cast<UINT64>(desc.Height) + tile_h - 1) / tile_h;
return across * down * desc.DepthOrArraySize * k64K;
}
HRESULT finish(ID3D12Device* device, HRESULT hr, REFIID riid, void** ppv, const char* method,
DXGI_FORMAT title_format) {
if (FAILED(hr) || !ppv || !*ppv) return hr;
// *ppv is the host resource as `riid`; every ID3D12Resource* interface pointer is the object.
auto* resource = static_cast<ID3D12Resource*>(*ppv);
const D3D12_RESOURCE_DESC desc = resource->GetDesc();
const D3D12_RESOURCE_ALLOCATION_INFO info = device->GetResourceAllocationInfo(0, 1, &desc);
const UINT64 size = info.SizeInBytes ? info.SizeInBytes : desc.Width;
const UINT64 host_size = info.SizeInBytes ? info.SizeInBytes : desc.Width;
const UINT64 console_size = console_tiled_size(desc, title_format);
const UINT64 size = console_size ? console_size : host_size;
const ULONGLONG attributes = kObjectTypeResource | kAllocatorIdD3D | (size >= k2M ? kPageSize2M : kPageSize64K);
void* title = XMemAlloc(static_cast<SIZE_T>(size), attributes);
char detail[200];
std::snprintf(detail, sizeof(detail), "%s dim=%d size=%llu page=%s title_va=%p", method,
char detail[240];
std::snprintf(detail, sizeof(detail), "%s dim=%d size=%llu (%s, host %llu) page=%s title_va=%p", method,
static_cast<int>(desc.Dimension), static_cast<unsigned long long>(size),
console_size ? "console 64 KB tiles" : "host", static_cast<unsigned long long>(host_size),
size >= k2M ? "2MB" : "64KB", title);
bx_log_emit(title ? BX_LOG_INFO : BX_LOG_WARN, "d3d12_xs", "committed_title_memory", detail);
if (!title || !bx_xbox_title_memory_attach(resource, reinterpret_cast<uint64_t>(title), size, attributes)) {
@@ -57,9 +117,14 @@ 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;
const DXGI_FORMAT title_format = desc ? desc->Format : DXGI_FORMAT_UNKNOWN;
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");
"CreateCommittedResource", title_format);
}
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource1(void* self, const D3D12_HEAP_PROPERTIES* heap,
@@ -68,9 +133,14 @@ 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;
const DXGI_FORMAT title_format = desc ? desc->Format : DXGI_FORMAT_UNKNOWN;
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");
riid, ppv, "CreateCommittedResource1", title_format);
}
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource2(void* self, const D3D12_HEAP_PROPERTIES* heap,
@@ -79,9 +149,14 @@ 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;
const DXGI_FORMAT title_format = desc ? desc->Format : DXGI_FORMAT_UNKNOWN;
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");
riid, ppv, "CreateCommittedResource2", title_format);
}
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource3(void* self, const D3D12_HEAP_PROPERTIES* heap,
@@ -90,11 +165,41 @@ 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;
const DXGI_FORMAT title_format = desc ? desc->Format : DXGI_FORMAT_UNKNOWN;
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,
castable, riid, ppv),
riid, ppv, "CreateCommittedResource3");
riid, ppv, "CreateCommittedResource3", title_format);
}
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource_x(void* self, const D3D12_HEAP_PROPERTIES* heap,
D3D12_HEAP_FLAGS flags, const void* xbox_desc,
D3D12_RESOURCE_STATES state,
const D3D12_CLEAR_VALUE* clear, REFIID riid,
void** ppv) {
BX_D3D_TRACE("XboxDevice", "CreateCommittedResourceX");
if (!xbox_desc) return E_INVALIDARG;
// D3D12XBOX_RESOURCE_DESC begins with the PC description; DccOptions follows it. DccOptions is
// a struct of two 32-bit enums, CompressionLevel and ColorTransform; every value of either
// selects some form of colour compression (CompressionLevel 0 is 64B, not "none").
D3D12_RESOURCE_DESC desc{};
std::memcpy(&desc, xbox_desc, sizeof(desc));
UINT32 dcc[2] = {};
std::memcpy(dcc, static_cast<const char*>(xbox_desc) + sizeof(desc), sizeof(dcc));
static std::atomic<UINT> logged{0};
if (logged.fetch_add(1) < 8) {
char detail[128];
std::snprintf(detail, sizeof(detail),
"DccOptions CompressionLevel=%u ColorTransform=%u ignored (no colour compression on the host)",
dcc[0], dcc[1]);
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "CreateCommittedResourceX", detail);
}
return bx_xbox_device_create_committed_resource(self, heap, flags, &desc, state, clear, riid, ppv);
}
} // extern "C"
+172
View File
@@ -0,0 +1,172 @@
/*
* 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 <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));
}
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));
}
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));
}
} // extern "C"
+91
View File
@@ -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
+38 -2
View File
@@ -214,6 +214,29 @@ void STDMETHODCALLTYPE bx_xbox_list_om_set_render_targets(void* self, UINT count
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.
* bx_xbox_bind_title_memory (placed_x.cpp) gives such a range a host buffer and has it refreshed
* when the list is submitted. When that is not possible (the memory is not readable, or no
* buffer could be made) the address must still not reach the host: it is not a host address,
* and D3DMetal dereferences the buffer it fails to find (a null read under IASetIndexBuffer).
* The binding is then left empty and logged as unimplemented; the first few are logged with
* their details. */
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) cannot get a 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,9 +244,16 @@ 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_xbox_bind_title_memory(bx_xbox_host<ID3D12GraphicsCommandList>(self), views[i].BufferLocation, views[i].SizeInBytes,
&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_xbox_rect_note_vertex_buffers(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) {
@@ -231,7 +261,13 @@ void STDMETHODCALLTYPE bx_xbox_list_ia_set_index_buffer(void* self, const D3D12_
D3D12_INDEX_BUFFER_VIEW host{};
if (view) {
host = *view;
host.BufferLocation = bx_xbox_host_gpu_va(view->BufferLocation);
if (view->BufferLocation &&
!bx_xbox_bind_title_memory(bx_xbox_host<ID3D12GraphicsCommandList>(self), view->BufferLocation, view->SizeInBytes,
&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);
}
+1
View File
@@ -155,6 +155,7 @@ void execute(void* self, UINT count, ID3D12CommandList* const* lists) {
}
}
bx_xbox_sync_mapped_buffers();
bx_xbox_refresh_bound_memory(host.data(), count);
for (const Write& w : pending) {
if (w.wait) apply_wait(queue, w);
}
+41 -3
View File
@@ -200,6 +200,12 @@ HRESULT create_compute(void* self, const D3D12_COMPUTE_PIPELINE_STATE_DESC* desc
return bx_xbox_wrap_result(hr, riid, ppv);
}
/* The console's pipeline topology types for rectangle and quad lists
(D3D12XBOX_PRIMITIVE_TOPOLOGY_TYPE_RECT = 19, _QUAD = 32) are drawn with triangles on the host. */
D3D12_PRIMITIVE_TOPOLOGY_TYPE host_topology_type(D3D12_PRIMITIVE_TOPOLOGY_TYPE type) {
return type > D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH ? D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE : type;
}
HRESULT create_graphics(void* self, const D3D12_GRAPHICS_PIPELINE_STATE_DESC* desc, REFIID riid, void** ppv) {
if (!desc || !ppv) return E_INVALIDARG;
*ppv = nullptr;
@@ -212,8 +218,11 @@ HRESULT create_graphics(void* self, const D3D12_GRAPHICS_PIPELINE_STATE_DESC* de
if (SUCCEEDED(hr)) hr = gate.admit("graphics", "DS", desc->DS, admitted.DS);
if (SUCCEEDED(hr)) hr = gate.admit("graphics", "HS", desc->HS, admitted.HS);
if (SUCCEEDED(hr)) hr = gate.admit("graphics", "GS", desc->GS, admitted.GS);
admitted.PrimitiveTopologyType = host_topology_type(desc->PrimitiveTopologyType);
if (SUCCEEDED(hr)) hr = device->CreateGraphicsPipelineState(&admitted, riid, ppv);
if (FAILED(hr)) return refused(device, hr, "graphics", riid, ppv);
bx_xbox_rect_pipeline_created(static_cast<ID3D12PipelineState*>(*ppv), desc->InputLayout.pInputElementDescs,
desc->InputLayout.NumElements);
return bx_xbox_wrap_result(hr, riid, ppv);
}
@@ -247,10 +256,23 @@ HRESULT create_stream(void* self, const D3D12_PIPELINE_STATE_STREAM_DESC* desc,
hr = gate.admit("stream", names[i], in, out);
if (SUCCEEDED(hr)) std::memcpy(&stream[offsets[i]], &out, sizeof(out));
}
const size_t topology_at = bx_stream_payload(stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY);
if (topology_at != SIZE_MAX) {
D3D12_PRIMITIVE_TOPOLOGY_TYPE type{};
std::memcpy(&type, &stream[topology_at], sizeof(type));
type = host_topology_type(type);
std::memcpy(&stream[topology_at], &type, sizeof(type));
}
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);
{
D3D12_INPUT_LAYOUT_DESC layout{};
const size_t layout_at = bx_stream_payload(stream, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT);
if (layout_at != SIZE_MAX) std::memcpy(&layout, &stream[layout_at], sizeof(layout));
bx_xbox_rect_pipeline_created(static_cast<ID3D12PipelineState*>(*ppv), layout.pInputElementDescs, layout.NumElements);
}
return bx_xbox_wrap_result(hr, riid, ppv);
}
@@ -274,12 +296,19 @@ void bx_xbox_pipeline_forget(IUnknown* host) {
}
void bx_xbox_list_forget(IUnknown* host) {
bx_xbox_rect_list_forget(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)));
}
extern "C" {
void STDMETHODCALLTYPE bx_xbox_list_ia_set_primitive_topology(void* self, D3D12_PRIMITIVE_TOPOLOGY topology) {
BX_D3D_TRACE("XboxGraphicsCommandList", "IASetPrimitiveTopology");
auto* list = bx_xbox_host<ID3D12GraphicsCommandList>(self);
list->IASetPrimitiveTopology(bx_xbox_rect_note_topology(list, topology));
}
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_compute_pipeline_state(void* self, const D3D12_COMPUTE_PIPELINE_STATE_DESC* desc,
REFIID riid, void** ppv) {
BX_D3D_TRACE("XboxDevice", "CreateComputePipelineState");
@@ -314,6 +343,7 @@ void STDMETHODCALLTYPE bx_xbox_list_set_pipeline_state(void* self, ID3D12Pipelin
bool is_null = false;
ID3D12PipelineState* host = host_pipeline(pso, &is_null);
set_list_null(list, is_null);
bx_xbox_rect_note_pipeline(list, host);
if (!is_null) list->SetPipelineState(host);
}
@@ -324,6 +354,8 @@ HRESULT STDMETHODCALLTYPE bx_xbox_list_reset(void* self, ID3D12CommandAllocator*
ID3D12PipelineState* host = host_pipeline(pso, &is_null);
set_list_null(list, is_null);
bx_xbox_gpu_writes_reset(list);
bx_xbox_bound_memory_reset(list);
bx_xbox_rect_list_reset(list, host);
return list->Reset(bx_xbox_unwrap_as(allocator), host);
}
@@ -331,16 +363,22 @@ 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);
if (list_skips(list, "DrawInstanced")) return;
if (!bx_xbox_draw_rect_list(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")) {
list->DrawIndexedInstanced(indices, instances, first_index, base_vertex, first_instance);
if (list_skips(list, "DrawIndexedInstanced")) return;
if (bx_xbox_rect_list_bound(list)) {
BX_STUB_LOG("d3d12_xs.dll", "DrawIndexedInstanced(rectangle list)");
return;
}
list->DrawIndexedInstanced(indices, instances, first_index, base_vertex, first_instance);
}
void STDMETHODCALLTYPE bx_xbox_list_dispatch(void* self, UINT x, UINT y, UINT z) {
+128 -6
View File
@@ -15,12 +15,15 @@
* 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 <atomic>
#include <cstdio>
#include <cstring>
#include <mutex>
#include <vector>
#include <unordered_map>
extern "C" __declspec(dllimport) VOID WINAPI XMemFree(PVOID address, ULONGLONG attributes);
@@ -102,6 +105,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 +214,8 @@ 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));
}
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,10 @@ 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));
}
void STDMETHODCALLTYPE bx_xbox_device_create_placed_uav_x(void* self, ID3D12Resource* resource, const void* xbox_desc,
@@ -236,8 +246,120 @@ 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;
}
/*
* Title memory bound as index or vertex data.
*
* On the console a GPU virtual address is the title's own address and the GPU reads the memory
* when the commands execute. A title therefore binds index and vertex data that it keeps in
* plain memory, with no Direct3D resource, and may still be writing it after it has recorded the
* draw. Here such a range gets a CPU-writable host buffer of its own (once: later ranges inside
* it reuse it; like the other implicit shadows it lives for the rest of the process), and every
* range bound on a list is copied from the title memory to its host buffer when that list is
* submitted. A range inside a buffer this layer already has is refreshed the same way.
*/
namespace {
constexpr UINT64 kMaxBoundBytes = 256ull << 20; // refuse absurd sizes instead of allocating them
struct BoundRange {
uint64_t va, size;
};
std::mutex g_bound_lock;
std::unordered_map<const void*, std::vector<BoundRange>> g_bound; // host list -> ranges bound since its reset
// The index of a buffer shadow that holds the whole range, or SIZE_MAX. g_lock must be held.
size_t buffer_holding_locked(uint64_t va, uint64_t size) {
for (size_t i = 0; i < g_count; ++i) {
const Shadow& s = g_shadows[i];
if (s.buffer && va >= s.title_va && va + size <= s.title_va + s.size) return i;
}
return SIZE_MAX;
}
} // namespace
bool bx_xbox_bind_title_memory(ID3D12GraphicsCommandList* list, D3D12_GPU_VIRTUAL_ADDRESS title, UINT64 size,
D3D12_GPU_VIRTUAL_ADDRESS* host) {
if (!list || !title || !size || size > kMaxBoundBytes) return false;
bool found = false;
{
std::lock_guard<std::mutex> guard(g_lock);
const size_t i = buffer_holding_locked(title, size);
if (i != SIZE_MAX) {
*host = g_shadows[i].host->GetGPUVirtualAddress() + (title - g_shadows[i].title_va);
found = true;
}
}
if (!found) {
if (!readable(reinterpret_cast<const void*>(title), size)) return false;
ID3D12Device* device = nullptr;
if (FAILED(list->GetDevice(__uuidof(ID3D12Device), reinterpret_cast<void**>(&device))) || !device) return false;
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;
const HRESULT hr = make_shadow(device, title, desc, "host buffer for bound title memory", &resource);
device->Release();
if (FAILED(hr) || !resource) return false;
*host = resource->GetGPUVirtualAddress();
}
std::lock_guard<std::mutex> guard(g_bound_lock);
std::vector<BoundRange>& ranges = g_bound[list];
for (const BoundRange& r : ranges) {
if (title >= r.va && title + size <= r.va + r.size) return true; // already recorded
}
ranges.push_back({title, size});
return true;
}
void bx_xbox_bound_memory_reset(IUnknown* host_list) {
std::lock_guard<std::mutex> guard(g_bound_lock);
g_bound.erase(host_list);
}
void bx_xbox_refresh_bound_memory(ID3D12CommandList* const* host_lists, UINT count) {
std::vector<BoundRange> ranges;
{
std::lock_guard<std::mutex> guard(g_bound_lock);
for (UINT i = 0; i < count; ++i) {
auto it = g_bound.find(host_lists[i]);
if (it == g_bound.end()) continue;
for (const BoundRange& r : it->second) {
bool covered = false;
for (const BoundRange& have : ranges) covered = covered || (r.va >= have.va && r.va + r.size <= have.va + have.size);
if (!covered) ranges.push_back(r);
}
}
}
for (const BoundRange& r : ranges) {
if (!readable(reinterpret_cast<const void*>(r.va), r.size)) continue; // freed since it was bound
std::lock_guard<std::mutex> guard(g_lock);
const size_t i = buffer_holding_locked(r.va, r.size);
if (i == SIZE_MAX) continue;
const uint64_t begin = r.va - g_shadows[i].title_va;
copy_buffer(g_shadows[i], true, begin, begin + r.size);
}
}
D3D12_GPU_VIRTUAL_ADDRESS bx_xbox_host_gpu_va(D3D12_GPU_VIRTUAL_ADDRESS title) {
+13
View File
@@ -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) {
+2
View File
@@ -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);
+261
View File
@@ -0,0 +1,261 @@
/*
* Console rectangle lists.
*
* The Xbox Series headers add primitive topologies PC Direct3D 12 does not have. A title draws
* its full-screen passes with D3D_PRIMITIVE_TOPOLOGY_RECTLIST (17): three vertices per rectangle,
* the fourth corner being v0 + v2 - v1, in pipelines whose topology type is
* D3D12XBOX_PRIMITIVE_TOPOLOGY_TYPE_RECT (19). The host knows neither value. Passed through, the
* pipeline is created anyway and the three vertices are drawn as one triangle: half of every
* rectangle is missing and no error is reported.
*
* Here a rectangle list is drawn as triangle strips:
* - the pipeline's topology type becomes TRIANGLE when it is created (pipelines.cpp);
* - IASetPrimitiveTopology(RECTLIST) sets TRIANGLESTRIP on the host and is remembered;
* - a non-indexed draw builds four vertices per rectangle, in the order v1, v2, v0, v3 (which
* keeps the winding of v0, v1, v2), in a host upload buffer and draws them. The vertices are
* read from the title's memory behind vertex-buffer slot 0, and v3 is computed element by
* element from the pipeline's input layout.
*
* Limits, each logged as unimplemented when reached: indexed rectangle lists; layouts with
* per-vertex elements outside slot 0; element formats other than 32-bit float and 8-bit
* normalised (those elements take the third vertex's value). Quad lists, quad strips and line
* loops are not emulated.
*/
#include "xbox_facade.h"
#include <atomic>
#include <cstdio>
#include <cstring>
#include <mutex>
#include <unordered_map>
#include <vector>
namespace {
constexpr int kRectList = 17; // D3D_PRIMITIVE_TOPOLOGY_RECTLIST (Xbox extension)
struct Element {
DXGI_FORMAT format;
UINT slot;
UINT offset;
bool per_vertex;
};
struct ListState {
int topology = 0; // the title's last IASetPrimitiveTopology value
D3D12_VERTEX_BUFFER_VIEW vb0{}; // the title's view of slot 0 (title address)
ID3D12PipelineState* pipeline = nullptr; // host pipeline bound, or nullptr
};
std::mutex g_lock;
std::unordered_map<const void*, ListState> g_lists;
std::unordered_map<const void*, std::vector<Element>> g_layouts; // host pipeline -> input elements
bool readable(uint64_t address, uint64_t size) {
uint64_t cursor = address;
const uint64_t end = address + size;
while (cursor < end) {
MEMORY_BASIC_INFORMATION region{};
if (!VirtualQuery(reinterpret_cast<void*>(cursor), &region, sizeof(region)) || region.State != MEM_COMMIT ||
(region.Protect & (PAGE_NOACCESS | PAGE_GUARD))) {
return false;
}
cursor = reinterpret_cast<uintptr_t>(region.BaseAddress) + region.RegionSize;
}
return true;
}
/* Space for generated vertices: one upload buffer used as a ring. A position is reused after the
ring wraps, which is 4 MiB of generated rectangles later; frames use a few hundred bytes. */
bool ring_place(ID3D12Device* device, const uint8_t* data, size_t size, D3D12_GPU_VIRTUAL_ADDRESS* address) {
constexpr uint64_t kRing = 4ull << 20;
static std::mutex lock;
static ID3D12Resource* ring = nullptr;
static uint8_t* mapped = nullptr;
static uint64_t cursor = 0;
if (size == 0 || size > kRing) return false;
std::lock_guard<std::mutex> guard(lock);
if (!ring) {
D3D12_HEAP_PROPERTIES heap{};
heap.Type = D3D12_HEAP_TYPE_UPLOAD;
D3D12_RESOURCE_DESC desc{};
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
desc.Width = kRing;
desc.Height = 1;
desc.DepthOrArraySize = 1;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
ID3D12Resource* created = nullptr;
void* base = nullptr;
if (FAILED(device->CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
__uuidof(ID3D12Resource), reinterpret_cast<void**>(&created))) ||
!created) {
return false;
}
if (FAILED(created->Map(0, nullptr, &base)) || !base) {
created->Release();
return false;
}
ring = created;
mapped = static_cast<uint8_t*>(base);
}
const uint64_t aligned = (size + 15) & ~15ull;
if (cursor + aligned > kRing) cursor = 0;
std::memcpy(mapped + cursor, data, size);
*address = ring->GetGPUVirtualAddress() + cursor;
cursor += aligned;
return true;
}
void unimplemented(const char* what) { BX_STUB_LOG("d3d12_xs.dll", what); }
} // namespace
void bx_xbox_rect_pipeline_created(ID3D12PipelineState* host, const D3D12_INPUT_ELEMENT_DESC* elements, UINT count) {
if (!host) return;
std::vector<Element> layout;
for (UINT i = 0; elements && i < count; ++i) {
layout.push_back({elements[i].Format, elements[i].InputSlot, elements[i].AlignedByteOffset,
elements[i].InputSlotClass == D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA});
}
std::lock_guard<std::mutex> guard(g_lock);
g_layouts[host] = std::move(layout); // also replaces a released pipeline's entry at a reused address
}
D3D12_PRIMITIVE_TOPOLOGY bx_xbox_rect_note_topology(ID3D12GraphicsCommandList* list, D3D12_PRIMITIVE_TOPOLOGY topology) {
{
std::lock_guard<std::mutex> guard(g_lock);
g_lists[list].topology = static_cast<int>(topology);
}
return static_cast<int>(topology) == kRectList ? D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP : topology;
}
void bx_xbox_rect_note_vertex_buffers(ID3D12GraphicsCommandList* list, UINT start, UINT count,
const D3D12_VERTEX_BUFFER_VIEW* views) {
if (start != 0 || count == 0) return;
std::lock_guard<std::mutex> guard(g_lock);
g_lists[list].vb0 = views ? views[0] : D3D12_VERTEX_BUFFER_VIEW{};
}
void bx_xbox_rect_note_pipeline(ID3D12GraphicsCommandList* list, ID3D12PipelineState* host) {
std::lock_guard<std::mutex> guard(g_lock);
g_lists[list].pipeline = host;
}
void bx_xbox_rect_list_reset(ID3D12GraphicsCommandList* list, ID3D12PipelineState* host) {
std::lock_guard<std::mutex> guard(g_lock);
g_lists[list] = ListState{};
g_lists[list].pipeline = host;
}
void bx_xbox_rect_list_forget(ID3D12GraphicsCommandList* list) {
std::lock_guard<std::mutex> guard(g_lock);
g_lists.erase(list);
}
bool bx_xbox_rect_list_bound(ID3D12GraphicsCommandList* list) {
std::lock_guard<std::mutex> guard(g_lock);
auto it = g_lists.find(list);
return it != g_lists.end() && it->second.topology == kRectList;
}
/* True when the list's topology is the rectangle list: the draw was done here, or could not be
and was logged as unimplemented. Either way the caller must not issue its own draw. */
bool bx_xbox_draw_rect_list(ID3D12GraphicsCommandList* list, UINT vertices, UINT instances, UINT first_vertex,
UINT first_instance) {
ListState state;
std::vector<Element> layout;
bool have_layout = false;
{
std::lock_guard<std::mutex> guard(g_lock);
auto it = g_lists.find(list);
if (it == g_lists.end() || it->second.topology != kRectList) return false;
state = it->second;
auto found = g_layouts.find(state.pipeline);
if (found != g_layouts.end()) {
layout = found->second;
have_layout = true;
}
}
const UINT stride = state.vb0.StrideInBytes;
const UINT rects = vertices / 3;
if (rects == 0) return true;
if (!have_layout || !state.vb0.BufferLocation || stride == 0 || stride > 1024) {
unimplemented("DrawInstanced(rectangle list without a known input layout or slot-0 vertex buffer)");
return true;
}
for (const Element& e : layout) {
if (e.per_vertex && e.slot != 0) {
unimplemented("DrawInstanced(rectangle list with per-vertex elements outside slot 0)");
return true;
}
}
const uint64_t source = state.vb0.BufferLocation + static_cast<uint64_t>(first_vertex) * stride;
if (!readable(source, static_cast<uint64_t>(rects) * 3 * stride)) {
unimplemented("DrawInstanced(rectangle list whose vertices are not readable title memory)");
return true;
}
std::vector<uint8_t> out(static_cast<size_t>(rects) * 4 * stride);
for (UINT r = 0; r < rects; ++r) {
const auto* v0 = reinterpret_cast<const uint8_t*>(source + static_cast<uint64_t>(3 * r) * stride);
const uint8_t* v1 = v0 + stride;
const uint8_t* v2 = v1 + stride;
uint8_t* dst = &out[static_cast<size_t>(r) * 4 * stride];
std::memcpy(dst, v1, stride);
std::memcpy(dst + stride, v2, stride);
std::memcpy(dst + 2 * stride, v0, stride);
uint8_t* v3 = dst + 3 * stride;
std::memcpy(v3, v2, stride);
for (const Element& e : layout) {
if (!e.per_vertex || e.offset >= stride) continue;
unsigned floats = 0, bytes = 0;
switch (e.format) {
case DXGI_FORMAT_R32G32B32A32_FLOAT: floats = 4; break;
case DXGI_FORMAT_R32G32B32_FLOAT: floats = 3; break;
case DXGI_FORMAT_R32G32_FLOAT: floats = 2; break;
case DXGI_FORMAT_R32_FLOAT: floats = 1; break;
case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_B8G8R8A8_UNORM: bytes = 4; break;
default: unimplemented("DrawInstanced(rectangle list element format; third vertex's value used)"); break;
}
for (unsigned i = 0; i < floats && e.offset + 4 * (i + 1) <= stride; ++i) {
float a, b, c;
std::memcpy(&a, v0 + e.offset + 4 * i, 4);
std::memcpy(&b, v1 + e.offset + 4 * i, 4);
std::memcpy(&c, v2 + e.offset + 4 * i, 4);
const float d = a + c - b;
std::memcpy(v3 + e.offset + 4 * i, &d, 4);
}
for (unsigned i = 0; i < bytes && e.offset + i < stride; ++i) {
const int d = static_cast<int>(v0[e.offset + i]) + v2[e.offset + i] - v1[e.offset + i];
v3[e.offset + i] = static_cast<uint8_t>(d < 0 ? 0 : d > 255 ? 255 : d);
}
}
}
ID3D12Device* device = nullptr;
D3D12_GPU_VIRTUAL_ADDRESS placed = 0;
const bool ok = SUCCEEDED(list->GetDevice(__uuidof(ID3D12Device), reinterpret_cast<void**>(&device))) && device &&
ring_place(device, out.data(), out.size(), &placed);
if (device) device->Release();
if (!ok) {
unimplemented("DrawInstanced(rectangle list: no host buffer for the generated vertices)");
return true;
}
const D3D12_VERTEX_BUFFER_VIEW generated{placed, static_cast<UINT>(out.size()), stride};
list->IASetVertexBuffers(0, 1, &generated);
for (UINT r = 0; r < rects; ++r) list->DrawInstanced(4, instances, 4 * r, first_instance);
// Put the title's own slot-0 binding back.
D3D12_VERTEX_BUFFER_VIEW title = state.vb0;
if (bx_xbox_try_host_gpu_va(state.vb0.BufferLocation, &title.BufferLocation)) {
list->IASetVertexBuffers(0, 1, &title);
} else {
list->IASetVertexBuffers(0, 1, nullptr);
}
static std::atomic<bool> logged{false};
if (!logged.exchange(true)) {
bx_log_emit(BX_LOG_INFO, "d3d12_xs", "rect_list",
"console rectangle lists are drawn as triangle strips (fourth corner v0 + v2 - v1); later draws are not logged");
}
return true;
}
+11
View File
@@ -54,6 +54,7 @@ CUSTOM = {
"WaitFrameEventX": "bx_xbox_device_wait_frame_event_x",
"CreatePlacedResourceX": "bx_xbox_device_create_placed_resource_x",
"CreatePlacedResourceX1": "bx_xbox_device_create_placed_resource_x1",
"CreateCommittedResourceX": "bx_xbox_device_create_committed_resource_x",
"CreateDescriptorHeap": "bx_xbox_device_create_descriptor_heap",
"GetDescriptorHandleIncrementSize": "bx_xbox_device_get_descriptor_handle_increment_size",
"CreateConstantBufferView": "bx_xbox_device_create_constant_buffer_view",
@@ -71,6 +72,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",
@@ -96,6 +106,7 @@ CUSTOM = {
"CopyTextureRegion": "bx_xbox_list_copy_texture_region",
"OMSetRenderTargets": "bx_xbox_list_om_set_render_targets",
"IASetVertexBuffers": "bx_xbox_list_ia_set_vertex_buffers",
"IASetPrimitiveTopology": "bx_xbox_list_ia_set_primitive_topology",
"IASetIndexBuffer": "bx_xbox_list_ia_set_index_buffer",
"SetPipelineState": "bx_xbox_list_set_pipeline_state",
"Reset": "bx_xbox_list_reset",
+1
View File
@@ -218,6 +218,7 @@ ULONG STDMETHODCALLTYPE bx_xbox_release(void* self) {
if (object->iface == &bx_xbox_GraphicsCommandList) {
bx_xbox_list_forget(object->host);
bx_xbox_gpu_writes_reset(object->host);
bx_xbox_bound_memory_reset(object->host);
}
object->host->Release();
delete object;
+64
View File
@@ -176,6 +176,17 @@ 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);
/* Title memory bound as index or vertex data (placed_x.cpp). Finds the host buffer that holds
* [title, title + size), creating one for plain title memory that has none, gives its address
* in *host and records the range on `list` so that it is copied from the title memory when the
* list is submitted. False when the memory is not readable or no buffer could be made. */
bool bx_xbox_bind_title_memory(ID3D12GraphicsCommandList* list, D3D12_GPU_VIRTUAL_ADDRESS title, UINT64 size,
D3D12_GPU_VIRTUAL_ADDRESS* host);
void bx_xbox_bound_memory_reset(IUnknown* host_list);
void bx_xbox_refresh_bound_memory(ID3D12CommandList* const* host_lists, UINT count);
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. */
@@ -270,6 +281,14 @@ HRESULT STDMETHODCALLTYPE bx_xbox_device_register_page_pool_x(void* self, D3D12_
HRESULT STDMETHODCALLTYPE bx_xbox_device_unregister_page_pool_x(void* self, HANDLE handle);
/* Committed resources with title-visible memory (committed.cpp). */
// CreateCommittedResourceX takes D3D12XBOX_RESOURCE_DESC: the PC D3D12_RESOURCE_DESC followed by
// DccOptions, a struct of CompressionLevel and ColorTransform (authorized GDK header). DccOptions
// selects console colour compression, which the host does not have; it is logged and otherwise ignored.
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource_x(void* self, const D3D12_HEAP_PROPERTIES* heap,
D3D12_HEAP_FLAGS flags, const void* xbox_desc,
D3D12_RESOURCE_STATES state,
const D3D12_CLEAR_VALUE* clear, REFIID riid,
void** ppv);
HRESULT STDMETHODCALLTYPE bx_xbox_device_create_committed_resource(void* self, const D3D12_HEAP_PROPERTIES* heap,
D3D12_HEAP_FLAGS flags, const D3D12_RESOURCE_DESC* desc,
D3D12_RESOURCE_STATES state, const D3D12_CLEAR_VALUE* clear,
@@ -290,6 +309,51 @@ 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);
/* Console rectangle lists (rect_list.cpp). */
void bx_xbox_rect_pipeline_created(ID3D12PipelineState* host, const D3D12_INPUT_ELEMENT_DESC* elements, UINT count);
D3D12_PRIMITIVE_TOPOLOGY bx_xbox_rect_note_topology(ID3D12GraphicsCommandList* list, D3D12_PRIMITIVE_TOPOLOGY topology);
void bx_xbox_rect_note_vertex_buffers(ID3D12GraphicsCommandList* list, UINT start, UINT count,
const D3D12_VERTEX_BUFFER_VIEW* views);
void bx_xbox_rect_note_pipeline(ID3D12GraphicsCommandList* list, ID3D12PipelineState* host);
void bx_xbox_rect_list_reset(ID3D12GraphicsCommandList* list, ID3D12PipelineState* host);
void bx_xbox_rect_list_forget(ID3D12GraphicsCommandList* list);
bool bx_xbox_rect_list_bound(ID3D12GraphicsCommandList* list);
bool bx_xbox_draw_rect_list(ID3D12GraphicsCommandList* list, UINT vertices, UINT instances, UINT first_vertex,
UINT first_instance);
extern "C" void STDMETHODCALLTYPE bx_xbox_list_ia_set_primitive_topology(void* self, D3D12_PRIMITIVE_TOPOLOGY topology);
/* 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);
+13 -65
View File
@@ -62,22 +62,6 @@ static HRESULT STDMETHODCALLTYPE x_Device_16(void* self, UINT a0, const void * a
if (FAILED(hr)) bx_xbox_log_host_failure("XboxDevice", "CreateRootSignature", hr);
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));
@@ -86,12 +70,6 @@ static void STDMETHODCALLTYPE x_Device_24(void* self, UINT a0, const D3D12_CPU_D
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;
}
static D3D12_HEAP_PROPERTIES STDMETHODCALLTYPE x_Device_26(void* self, UINT a0, D3D12_HEAP_TYPE a1) {
BX_D3D_TRACE("XboxDevice", "GetCustomHeapProperties");
D3D12_HEAP_PROPERTIES result{};
@@ -104,18 +82,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);
@@ -221,8 +187,6 @@ static HRESULT STDMETHODCALLTYPE x_Device_69(void*) { BX_VTABLE_STUB_LOG("XboxDe
/* Xbox-only method */
static HRESULT STDMETHODCALLTYPE x_Device_72(void*) { BX_VTABLE_STUB_LOG("XboxDevice", 72u, "SetGpuMemoryPriorityX"); return E_NOTIMPL; }
/* Xbox-only method */
static HRESULT STDMETHODCALLTYPE x_Device_76(void*) { BX_VTABLE_STUB_LOG("XboxDevice", 76u, "CreateCommittedResourceX"); return E_NOTIMPL; }
/* 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; }
@@ -294,12 +258,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 +320,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 +420,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),
@@ -526,7 +478,7 @@ const void* const kDeviceTable[] = {
reinterpret_cast<const void*>(&bx_xbox_device_create_command_list_x),
reinterpret_cast<const void*>(&bx_xbox_device_register_page_pool_x),
reinterpret_cast<const void*>(&bx_xbox_device_unregister_page_pool_x),
reinterpret_cast<const void*>(&x_Device_76),
reinterpret_cast<const void*>(&bx_xbox_device_create_committed_resource_x),
reinterpret_cast<const void*>(&x_Device_77),
reinterpret_cast<const void*>(&bx_xbox_device_set_frame_interval_x),
reinterpret_cast<const void*>(&bx_xbox_device_schedule_frame_event_x),
@@ -545,7 +497,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 +510,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 +559,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, 45 shared, 40 stubs); hosted on ID3D12Device10. */
const IID kHostDevice = __uuidof(ID3D12Device10);
static HRESULT STDMETHODCALLTYPE x_Resource_3(void* self, REFGUID a0, UINT * a1, void * a2) {
@@ -1348,10 +1300,6 @@ static void STDMETHODCALLTYPE x_GraphicsCommandList_19(void* self, ID3D12Resourc
BX_D3D_TRACE("XboxGraphicsCommandList", "ResolveSubresource");
bx_xbox_host<ID3D12GraphicsCommandList>(self)->ResolveSubresource(bx_xbox_unwrap_as<ID3D12Resource>(a0), a1, bx_xbox_unwrap_as<ID3D12Resource>(a2), a3, a4);
}
static void STDMETHODCALLTYPE x_GraphicsCommandList_20(void* self, D3D12_PRIMITIVE_TOPOLOGY a0) {
BX_D3D_TRACE("XboxGraphicsCommandList", "IASetPrimitiveTopology");
bx_xbox_host<ID3D12GraphicsCommandList>(self)->IASetPrimitiveTopology(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);
@@ -1716,7 +1664,7 @@ const void* const kGraphicsCommandListTable[] = {
reinterpret_cast<const void*>(&x_GraphicsCommandList_17),
reinterpret_cast<const void*>(&x_GraphicsCommandList_18),
reinterpret_cast<const void*>(&x_GraphicsCommandList_19),
reinterpret_cast<const void*>(&x_GraphicsCommandList_20),
reinterpret_cast<const void*>(&bx_xbox_list_ia_set_primitive_topology),
reinterpret_cast<const void*>(&x_GraphicsCommandList_21),
reinterpret_cast<const void*>(&x_GraphicsCommandList_22),
reinterpret_cast<const void*>(&x_GraphicsCommandList_23),
@@ -1863,7 +1811,7 @@ const IID kGraphicsCommandListIids[] = {
{0xc4fec28f, 0x7966, 0x4e95, {0x9f, 0x94, 0xf4, 0x31, 0xcb, 0x56, 0xc3, 0xb8}}, /* ID3D12Object */
};
/* ID3D12GraphicsCommandList8: 150 slots (66 forwarded, 24 shared, 60 stubs); hosted on ID3D12GraphicsCommandList7. */
/* ID3D12GraphicsCommandList8: 150 slots (65 forwarded, 25 shared, 60 stubs); hosted on ID3D12GraphicsCommandList7. */
const IID kHostGraphicsCommandList = __uuidof(ID3D12GraphicsCommandList7);
} // namespace
+2 -1
View File
@@ -1,4 +1,5 @@
bx_add_shim_dll(gameinput GameInput GameInput.def
gameinput.cpp
keyboard_gamepad.cpp
)
target_link_libraries(gameinput PRIVATE bx_runtime_veh kernel32)
target_link_libraries(gameinput PRIVATE bx_runtime_veh kernel32 user32)
+56 -21
View File
@@ -7,16 +7,19 @@
#include <unordered_map>
#include "bx_log.h"
#include "keyboard_gamepad.h"
namespace {
// GameInputCreate @1 exposes the legacy v0 COM layout.
constexpr GUID game_input_v0 = {0x11be2a7e, 0x4254, 0x445a,
{0x9c, 0x09, 0xff, 0xc4, 0x0f, 0x00, 0x69, 0x18}};
using Callback = void (WINAPI*)();
using DeviceCallback = void (WINAPI*)(uint64_t, void*, IUnknown*, uint64_t, uint32_t, uint32_t);
// GameInputEnumerationKind values from Microsoft's public GDK GameInput (v0) reference:
// 0 = GameInputNoEnumeration, 1 = GameInputAsyncEnumeration, 2 = GameInputBlockingEnumeration.
constexpr uint32_t kMaxEnumerationKind = 2;
constexpr uint32_t kAsyncEnumeration = 1;
constexpr uint32_t kBlockingEnumeration = 2;
struct SrwExclusiveLock {
explicit SrwExclusiveLock(SRWLOCK& lock) : lock_(lock) { AcquireSRWLockExclusive(&lock_); }
@@ -34,7 +37,7 @@ struct RegisteredDeviceCallback {
uint32_t status_filter = 0;
uint32_t enumeration_kind = 0;
void* context = nullptr;
Callback callback = nullptr;
DeviceCallback callback = nullptr;
bool stopped = false;
};
@@ -91,9 +94,15 @@ public:
virtual uint64_t WINAPI GetCurrentTimestamp() {
return GetTickCount64() * 1000;
}
virtual HRESULT WINAPI GetCurrentReading(uint32_t, void*, void** out) {
BX_VTABLE_STUB_LOG("IGameInput", 4, "GetCurrentReading");
return unavailable(out);
virtual HRESULT WINAPI GetCurrentReading(uint32_t kind, void* device, void** out) {
if (!out) return E_POINTER;
*out = nullptr;
if (!(kind & keyboard_gamepad::input_kind)) {
BX_VTABLE_STUB_LOG("IGameInput", 4, "GetCurrentReading(non-gamepad)");
return E_NOTIMPL;
}
if (device && device != keyboard_gamepad::device()) return keyboard_gamepad::device_not_found;
return keyboard_gamepad::read(out);
}
virtual HRESULT WINAPI GetNextReading(void*, uint32_t, void*, void** out) {
BX_VTABLE_STUB_LOG("IGameInput", 5, "GetNextReading");
@@ -117,25 +126,45 @@ public:
uint32_t status_filter,
uint32_t enumeration_kind,
void* context,
Callback callback,
DeviceCallback callback,
uint64_t* out_token
) {
if (out_token) *out_token = 0;
if (!callback || input_kind == 0 || status_filter == 0 || enumeration_kind > kMaxEnumerationKind) {
if (!callback || input_kind == 0 || status_filter == 0 || enumeration_kind > kBlockingEnumeration) {
return E_INVALIDARG;
}
SrwExclusiveLock guard(callback_lock_);
const uint64_t token = next_token_++;
callbacks_.emplace(token, RegisteredDeviceCallback{
device,
input_kind,
status_filter,
enumeration_kind,
context,
callback,
false,
});
uint64_t token;
{
SrwExclusiveLock guard(callback_lock_);
token = next_token_++;
callbacks_.emplace(token, RegisteredDeviceCallback{
device,
input_kind,
status_filter,
enumeration_kind,
context,
callback,
false,
});
}
if (out_token) *out_token = token;
auto* pad = keyboard_gamepad::device();
const bool matches = (!device || device == pad) &&
(input_kind & keyboard_gamepad::input_kind) &&
(status_filter & keyboard_gamepad::device_status);
if (matches && enumeration_kind == kBlockingEnumeration) {
// The title requests blocking enumeration. The callback may reenter
// GameInput, so never call it under the registration lock.
static std::atomic_flag reported;
if (!reported.test_and_set(std::memory_order_relaxed)) {
bx_log_emit(BX_LOG_INFO, "gameinput", "keyboard_gamepad_connected",
"keyboard gamepad announced through v0 device enumeration");
}
callback(token, context, pad, GetCurrentTimestamp(), keyboard_gamepad::device_status, 0);
} else if (matches && enumeration_kind == kAsyncEnumeration) {
BX_VTABLE_STUB_LOG("IGameInput", 9, "RegisterDeviceCallback(async gamepad enumeration)");
}
return S_OK;
}
virtual HRESULT WINAPI RegisterSystemButtonCallback(void*, uint32_t, void*, Callback, uint64_t* out) {
@@ -166,9 +195,15 @@ public:
BX_VTABLE_STUB_LOG("IGameInput", 15, "CreateAggregateDevice");
return unavailable(out);
}
virtual HRESULT WINAPI FindDeviceFromId(const void*, void** out) {
BX_VTABLE_STUB_LOG("IGameInput", 16, "FindDeviceFromId");
return unavailable(out);
virtual HRESULT WINAPI FindDeviceFromId(const void* id, void** out) {
if (!out) return E_POINTER;
*out = nullptr;
if (!id) return E_INVALIDARG;
if (!keyboard_gamepad::has_id(id)) return keyboard_gamepad::device_not_found;
auto* pad = keyboard_gamepad::device();
pad->AddRef();
*out = pad;
return S_OK;
}
virtual HRESULT WINAPI FindDeviceFromObject(IUnknown*, void** out) {
BX_VTABLE_STUB_LOG("IGameInput", 17, "FindDeviceFromObject");
+306
View File
@@ -0,0 +1,306 @@
#include "keyboard_gamepad.h"
#include <array>
#include <atomic>
#include <cstddef>
#include <cstring>
#include <new>
#include "bx_log.h"
namespace keyboard_gamepad {
namespace {
// Legacy GameInput v0 interface identities and Win64 data layouts.
constexpr GUID device_iid = {0x31dd86fb, 0x4c1b, 0x408a, {0x86, 0x8f, 0x43, 0x9b, 0x3c, 0xd4, 0x71, 0x25}};
constexpr GUID reading_iid = {0x2156947a, 0xe1fa, 0x4de0, {0xa3, 0x0b, 0xd8, 0x12, 0x93, 0x1d, 0xbd, 0x8d}};
struct GamepadState {
uint32_t buttons;
float left_trigger;
float right_trigger;
float left_x;
float left_y;
float right_x;
float right_y;
};
static_assert(sizeof(GamepadState) == 28);
struct BatteryState {
float rate, max_rate, remaining, capacity;
uint32_t status;
};
static_assert(sizeof(BatteryState) == 20);
struct DeviceString {
uint32_t bytes;
uint32_t code_points;
const char* text;
};
using DeviceId = std::array<uint8_t, 32>;
constexpr DeviceId device_id{{'B', 'e', 't', 't', 'e', 'r', 'X', 'e', 'n', '-', 'K', 'e', 'y', 'b', 'o', 'a', 'r', 'd'}};
constexpr char device_name[] = "BetterXen Keyboard Gamepad";
constexpr DeviceString display_name{
sizeof(device_name) - 1, sizeof(device_name) - 1, device_name,
};
// Menu, View, A/B/X/Y, D-pad, shoulders, and stick clicks, in v0 label order.
constexpr std::array<uint32_t, 14> gamepad_labels{{4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 17, 20}};
// The virtual device supplies only fixed-format gamepad data. The arrays group
// the zero-valued v0 metadata for raw reports, other input kinds, and motors.
struct DeviceInfo {
uint32_t size;
uint16_t vendor_id, product_id, revision;
uint8_t interface_number, collection_number;
uint16_t usage_page, usage;
uint16_t hardware_version[4], firmware_version[4];
DeviceId id, root_id;
int32_t family;
uint32_t capabilities, supported_input, supported_rumble;
uint32_t counts[12];
const void* other_input_info[12];
const uint32_t* gamepad_info;
const void* wheel_navigation_motor_info[4];
const DeviceString* display_name;
const void* device_strings;
const void* descriptor;
};
static_assert(sizeof(DeviceInfo) == 320);
static_assert(offsetof(DeviceInfo, id) == 32);
static_assert(offsetof(DeviceInfo, supported_input) == 104);
static_assert(offsetof(DeviceInfo, gamepad_info) == 256);
static_assert(offsetof(DeviceInfo, display_name) == 296);
constexpr DeviceInfo device_info{
.size = sizeof(DeviceInfo),
.vendor_id = 0,
.product_id = 0,
.revision = 0,
.interface_number = 0,
.collection_number = 0,
.usage_page = 1,
.usage = 5,
.hardware_version = {},
.firmware_version = {},
.id = device_id,
.root_id = device_id,
.family = -1, // GameInputFamilyVirtual
.capabilities = 0,
.supported_input = input_kind,
.supported_rumble = 0,
.counts = {},
.other_input_info = {},
.gamepad_info = gamepad_labels.data(),
.wheel_navigation_motor_info = {},
.display_name = &display_name,
.device_strings = nullptr,
.descriptor = nullptr,
};
#define DEVICE_STUB(slot, method) BX_VTABLE_STUB_LOG("IGameInputDevice", slot, method)
#define READING_STUB(slot, method) BX_VTABLE_STUB_LOG("IGameInputReading", slot, method)
class Device final : public IUnknown {
LONG refs_ = 1; // The shim owns one reference for the lifetime of the device.
public:
HRESULT WINAPI QueryInterface(REFIID iid, void** out) override {
if (!out) return E_POINTER;
*out = nullptr;
if (iid != IID_IUnknown && iid != device_iid) return E_NOINTERFACE;
AddRef();
*out = this;
return S_OK;
}
ULONG WINAPI AddRef() override { return InterlockedIncrement(&refs_); }
ULONG WINAPI Release() override { return InterlockedDecrement(&refs_); }
virtual const DeviceInfo* WINAPI GetDeviceInfo() { return &device_info; }
virtual uint32_t WINAPI GetDeviceStatus() { return device_status; }
virtual void WINAPI GetBatteryState(BatteryState* out) { if (out) *out = {}; }
virtual HRESULT WINAPI CreateForceFeedbackEffect(uint32_t, const void*, void** out) {
DEVICE_STUB(6, "CreateForceFeedbackEffect");
if (out) *out = nullptr;
return E_NOTIMPL;
}
virtual bool WINAPI IsForceFeedbackMotorPoweredOn(uint32_t) { return false; }
virtual void WINAPI SetForceFeedbackMotorGain(uint32_t, float) { DEVICE_STUB(8, "SetForceFeedbackMotorGain"); }
virtual HRESULT WINAPI SetHapticMotorState(uint32_t, const void*) {
DEVICE_STUB(9, "SetHapticMotorState");
return E_NOTIMPL;
}
virtual void WINAPI SetRumbleState(const void*) { DEVICE_STUB(10, "SetRumbleState"); }
virtual void WINAPI SetInputSynchronizationState(bool) { DEVICE_STUB(11, "SetInputSynchronizationState"); }
virtual void WINAPI SendInputSynchronizationHint() { DEVICE_STUB(12, "SendInputSynchronizationHint"); }
virtual void WINAPI PowerOff() { DEVICE_STUB(13, "PowerOff"); }
virtual HRESULT WINAPI CreateRawDeviceReport(uint32_t, uint32_t, void** out) {
DEVICE_STUB(14, "CreateRawDeviceReport");
if (out) *out = nullptr;
return E_NOTIMPL;
}
virtual HRESULT WINAPI GetRawDeviceFeature(uint32_t, void** out) {
DEVICE_STUB(15, "GetRawDeviceFeature");
if (out) *out = nullptr;
return E_NOTIMPL;
}
virtual HRESULT WINAPI SetRawDeviceFeature(void*) {
DEVICE_STUB(16, "SetRawDeviceFeature");
return E_NOTIMPL;
}
virtual HRESULT WINAPI SendRawDeviceOutput(void*) {
DEVICE_STUB(17, "SendRawDeviceOutput");
return E_NOTIMPL;
}
virtual HRESULT WINAPI SendRawDeviceOutputWithResponse(void*, void** out) {
DEVICE_STUB(18, "SendRawDeviceOutputWithResponse");
if (out) *out = nullptr;
return E_NOTIMPL;
}
virtual HRESULT WINAPI ExecuteRawDeviceIoControl(uint32_t, size_t, const void*, size_t, void*, size_t* out) {
DEVICE_STUB(19, "ExecuteRawDeviceIoControl");
if (out) *out = 0;
return E_NOTIMPL;
}
virtual bool WINAPI AcquireExclusiveRawDeviceAccess(uint64_t) {
DEVICE_STUB(20, "AcquireExclusiveRawDeviceAccess");
return false;
}
virtual void WINAPI ReleaseExclusiveRawDeviceAccess() { DEVICE_STUB(21, "ReleaseExclusiveRawDeviceAccess"); }
};
Device virtual_device;
bool pressed(int key) { return (GetAsyncKeyState(key) & 0x8000) != 0; }
bool owns_foreground() {
const HWND foreground = GetForegroundWindow();
DWORD pid = 0;
return foreground && GetWindowThreadProcessId(foreground, &pid) && pid == GetCurrentProcessId();
}
void sample_stick(int left, int right, int down, int up, float& x, float& y) {
x = static_cast<float>(pressed(right) - pressed(left));
y = static_cast<float>(pressed(up) - pressed(down));
if (x != 0 && y != 0) {
constexpr float diagonal = 0.70710678f;
x *= diagonal;
y *= diagonal;
}
}
GamepadState sample_keyboard() {
GamepadState state{};
if (!owns_foreground()) return state;
constexpr struct KeyBinding { int key; uint32_t button; } buttons[] = {
{'P', 0x1}, {VK_TAB, 0x2}, {VK_RETURN, 0x4}, {VK_SPACE, 0x4},
{VK_ESCAPE, 0x8}, {VK_BACK, 0x8}, {'X', 0x10}, {'Y', 0x20},
{VK_UP, 0x40}, {VK_DOWN, 0x80}, {VK_LEFT, 0x100}, {VK_RIGHT, 0x200},
{'Q', 0x400}, {'E', 0x800}, {'F', 0x1000}, {'H', 0x2000},
};
for (const auto& binding : buttons) {
if (pressed(binding.key)) state.buttons |= binding.button;
}
state.left_trigger = pressed('Z') ? 1.0f : 0.0f;
state.right_trigger = pressed('C') ? 1.0f : 0.0f;
sample_stick('A', 'D', 'S', 'W', state.left_x, state.left_y);
sample_stick('J', 'L', 'K', 'I', state.right_x, state.right_y);
return owns_foreground() ? state : GamepadState{};
}
struct Sample {
GamepadState state{};
uint64_t sequence = 0;
uint64_t timestamp = 0;
};
SRWLOCK sample_lock = SRWLOCK_INIT;
Sample latest;
Sample sample() {
AcquireSRWLockExclusive(&sample_lock);
const GamepadState state = sample_keyboard();
if (!latest.sequence || std::memcmp(&state, &latest.state, sizeof(state)) != 0) {
latest = {state, latest.sequence + 1, GetTickCount64() * 1000};
}
const Sample snapshot = latest;
ReleaseSRWLockExclusive(&sample_lock);
return snapshot;
}
class Reading final : public IUnknown {
LONG refs_ = 1;
const Sample sample_;
public:
explicit Reading(const Sample& value) : sample_(value) {}
HRESULT WINAPI QueryInterface(REFIID iid, void** out) override {
if (!out) return E_POINTER;
*out = nullptr;
if (iid != IID_IUnknown && iid != reading_iid) return E_NOINTERFACE;
AddRef();
*out = this;
return S_OK;
}
ULONG WINAPI AddRef() override { return InterlockedIncrement(&refs_); }
ULONG WINAPI Release() override {
const auto left = InterlockedDecrement(&refs_);
if (!left) delete this;
return left;
}
virtual uint32_t WINAPI GetInputKind() { return input_kind; }
virtual uint64_t WINAPI GetSequenceNumber(uint32_t kind) { return kind & input_kind ? sample_.sequence : 0; }
virtual uint64_t WINAPI GetTimestamp() { return sample_.timestamp; }
virtual void WINAPI GetDevice(void** out) {
if (!out) return;
virtual_device.AddRef();
*out = &virtual_device;
}
virtual bool WINAPI GetRawReport(void** out) {
if (out) *out = nullptr;
return false;
}
virtual uint32_t WINAPI GetControllerAxisCount() { return 0; }
virtual uint32_t WINAPI GetControllerAxisState(uint32_t, float*) { return 0; }
virtual uint32_t WINAPI GetControllerButtonCount() { return 0; }
virtual uint32_t WINAPI GetControllerButtonState(uint32_t, bool*) { return 0; }
virtual uint32_t WINAPI GetControllerSwitchCount() { return 0; }
virtual uint32_t WINAPI GetControllerSwitchState(uint32_t, uint32_t*) { return 0; }
virtual uint32_t WINAPI GetKeyCount() { return 0; }
virtual uint32_t WINAPI GetKeyState(uint32_t, void*) { return 0; }
virtual bool WINAPI GetMouseState(void*) { READING_STUB(16, "GetMouseState"); return false; }
virtual uint32_t WINAPI GetTouchCount() { return 0; }
virtual uint32_t WINAPI GetTouchState(uint32_t, void*) { return 0; }
virtual bool WINAPI GetMotionState(void*) { READING_STUB(19, "GetMotionState"); return false; }
virtual bool WINAPI GetArcadeStickState(void*) { READING_STUB(20, "GetArcadeStickState"); return false; }
virtual bool WINAPI GetFlightStickState(void*) { READING_STUB(21, "GetFlightStickState"); return false; }
virtual bool WINAPI GetGamepadState(GamepadState* out) {
if (!out) return false;
*out = sample_.state;
static std::atomic_flag reported;
if ((out->buttons || out->left_trigger || out->right_trigger || out->left_x || out->left_y ||
out->right_x || out->right_y) && !reported.test_and_set(std::memory_order_relaxed)) {
bx_log_emit(BX_LOG_INFO, "gameinput", "keyboard_gamepad_input",
"guest read a non-neutral keyboard gamepad state");
}
return true;
}
virtual bool WINAPI GetRacingWheelState(void*) { READING_STUB(23, "GetRacingWheelState"); return false; }
virtual bool WINAPI GetUiNavigationState(void*) { READING_STUB(24, "GetUiNavigationState"); return false; }
};
} // namespace
IUnknown* device() { return &virtual_device; }
bool has_id(const void* id) {
return id && std::memcmp(id, device_id.data(), device_id.size()) == 0;
}
HRESULT read(void** out) {
*out = new (std::nothrow) Reading(sample());
return *out ? S_OK : E_OUTOFMEMORY;
}
} // namespace keyboard_gamepad
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include <windows.h>
#include <unknwn.h>
#include <cstdint>
namespace keyboard_gamepad {
constexpr uint32_t input_kind = 0x00040000;
constexpr uint32_t device_status = 0x3; // connected and input enabled
constexpr HRESULT device_not_found = static_cast<HRESULT>(0x838a0002u);
IUnknown* device();
bool has_id(const void* id);
HRESULT read(void** out);
} // namespace keyboard_gamepad
+64
View File
@@ -327,6 +327,65 @@ uint64_t clzero_loop_fast_path(CONTEXT& context) {
return done;
}
// A title that flushes an address range with CLWB does it in a loop, and each iteration would
// trap again: an exception round trip per 64 bytes, tens of thousands per second for as long as
// the range lasts. CLWB writes a cache line back to memory and changes no register, flag or
// memory content, so emulating it is skipping it, and skipping a whole range has the same result
// as skipping its lines one by one. When the trapped CLWB has the form `clwb [reg]` (no index, no
// displacement) and is followed by exactly
// add reg, 0x40 ; cmp reg, <reg64> ; jbe|jb <the clwb>
// the pointer register is advanced here to the last value for which the loop would still have run
// the CLWB, so the title's own add/cmp/jcc then leaves the loop. `length` is the decoded length
// of the CLWB at RIP. Returns the number of iterations skipped (0 when the form does not match).
uint64_t clwb_loop_fast_path(CONTEXT& context, size_t length) {
const auto* code = reinterpret_cast<const uint8_t*>(context.Rip);
MEMORY_BASIC_INFORMATION text{};
if (length < 4 || length > 5 || !VirtualQuery(code, &text, sizeof(text)) || text.State != MEM_COMMIT ||
reinterpret_cast<uintptr_t>(code) + length + 9 > reinterpret_cast<uintptr_t>(text.BaseAddress) + text.RegionSize) {
return 0;
}
// 66 [REX] 0F AE /6, ModRM mod=00 with a plain base register.
size_t i = 0;
if (code[i++] != 0x66) return 0;
uint8_t rex = 0;
if (length == 5) {
rex = code[i++];
if ((rex & 0xF0) != 0x40 || (rex & 0x02)) return 0; // no index extension: there is no SIB byte
}
if (code[i] != 0x0F || code[i + 1] != 0xAE) return 0;
const uint8_t modrm = code[i + 2];
if ((modrm & 0xC0) != 0x00 || ((modrm >> 3) & 7) != 6) return 0;
const unsigned low = modrm & 7;
if (low == 4 || low == 5) return 0; // SIB or RIP-relative
const unsigned pointer = low | ((rex & 0x01) ? 8 : 0);
const uint8_t* next = code + length;
// add pointer, 0x40 REX.W [+B] 83 /0 ib
if (next[0] != (pointer >= 8 ? 0x49 : 0x48) || next[1] != 0x83 || next[2] != (0xC0 | low) || next[3] != 0x40) return 0;
// cmp pointer, limit REX.W [+R] [+B] 39 /r, ModRM mod=11, rm = pointer, reg = limit
if ((next[4] & 0xFA) != 0x48 || next[5] != 0x39 || (next[6] & 0xC7) != (0xC0 | low)) return 0;
if (((next[4] & 0x01) != 0) != (pointer >= 8)) return 0;
const unsigned limit_reg = ((next[6] >> 3) & 7) | ((next[4] & 0x04) ? 8 : 0);
// jbe|jb back to the CLWB
const bool inclusive = next[7] == 0x76;
if (!inclusive && next[7] != 0x72) return 0;
if (next + 9 + static_cast<int8_t>(next[8]) != code) return 0;
if (limit_reg == pointer || pointer == 4 || limit_reg == 4) return 0;
DWORD64* registers = &context.Rax; // Rax, Rcx, Rdx, Rbx, Rsp, Rbp, Rsi, Rdi, R8..R15
constexpr uint64_t line = 64;
const uint64_t current = registers[pointer];
const uint64_t limit = registers[limit_reg];
// The loop runs the CLWB again for pointer values current + 64k that are <= limit (jbe) or
// < limit (jb). `top` is the largest value that still runs.
if (!inclusive && limit == 0) return 0;
const uint64_t top = inclusive ? limit : limit - 1;
if (current > top || top - current < line) return 0; // no further iteration
if (top > UINT64_MAX - line) return 0; // the title's add would wrap
const uint64_t skipped = (top - current) / line;
registers[pointer] = current + skipped * line;
return skipped;
}
bool apply_amd_instruction(const AmdInstruction& instruction, CONTEXT& context,
EXCEPTION_RECORD& exception) {
switch (instruction.kind) {
@@ -1302,6 +1361,11 @@ LONG CALLBACK bx_veh_handler(PEXCEPTION_POINTERS ep) {
if (len > 0) {
uint64_t count = g_clwb_traps.fetch_add(1, std::memory_order_relaxed) + 1;
log_sampled_trap("clwb_trapped", count, ep->ContextRecord->Rip, len);
static std::atomic<uint64_t> batched{0};
if (clwb_loop_fast_path(*ep->ContextRecord, len) && batched.fetch_add(1) == 0) {
bx_log_emit(BX_LOG_INFO, "runtime_veh", "clwb_loop",
"CLWB range loop (add reg,0x40; cmp; jbe|jb) completed in one trap; later loops are not logged");
}
ep->ContextRecord->Rip += len;
return EXCEPTION_CONTINUE_EXECUTION;
}
+4
View File
@@ -56,6 +56,10 @@ struct Request {
ID3D12Resource* resource = nullptr;
UINT64 resource_offset = 0;
DWORD output_size = 0; // compression_zlib: bytes the stream inflates to at `destination`
// Xbox physical-page destination: the span of xmem.dll pages this request writes through,
// mapped when it was enqueued and unmapped once it has been fulfilled (0 when unused).
void* page_span = nullptr;
ULONG_PTR page_span_count = 0;
};
inline constexpr UINT compression_none = 0;
+110 -9
View File
@@ -212,11 +212,48 @@ void transition(ID3D12GraphicsCommandList* list, ID3D12Resource* resource,
list->ResourceBarrier(1, &barrier);
}
HRESULT read_bytes(HANDLE file, UINT64 offset, void* destination, const void* source, DWORD size) {
// Title memory can be temporarily inaccessible while xmem replaces a mapped view. Keep reads
// and writes out of that window. Never nest guards or hold one across an XMem call.
class RemapGuard {
public:
explicit RemapGuard(bool needed = true) {
if (!needed) return;
const HMODULE xmem = GetModuleHandleW(L"xmem.dll");
if (!xmem) return;
const auto enter = resolve(xmem, "bx_xmem_remap_guard_enter");
leave_ = resolve(xmem, "bx_xmem_remap_guard_leave");
if (enter && leave_) {
enter();
} else {
leave_ = nullptr;
static std::atomic<bool> warned{false};
if (!warned.exchange(true)) {
bx_log_emit(BX_LOG_WARN, "xcrdapi", "dstorage_remap_guard",
"loaded xmem.dll does not provide both remap guard exports");
}
}
}
~RemapGuard() {
if (leave_) leave_();
}
RemapGuard(const RemapGuard&) = delete;
RemapGuard& operator=(const RemapGuard&) = delete;
private:
using Fn = void (*)();
static Fn resolve(HMODULE module, const char* name) {
return reinterpret_cast<Fn>(reinterpret_cast<void*>(GetProcAddress(module, name)));
}
Fn leave_ = nullptr;
};
HRESULT read_bytes(HANDLE file, UINT64 offset, void* destination, const void* source, DWORD size,
bool title_destination = false) {
if (!size) return S_OK;
if (!destination) return E_INVALIDARG;
if (!file) {
if (!source) return E_INVALIDARG;
RemapGuard remap_guard;
std::memmove(destination, source, size);
return S_OK;
}
@@ -229,6 +266,7 @@ HRESULT read_bytes(HANDLE file, UINT64 offset, void* destination, const void* so
DWORD bytes = 0;
HRESULT result = S_OK;
RemapGuard remap_guard(title_destination);
if (!ReadFile(file, destination, size, &bytes, &operation)) {
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING) {
@@ -252,7 +290,7 @@ HRESULT write_mapped(HANDLE file, const Request& request) {
return E_FAIL;
}
auto* destination = static_cast<unsigned char*>(mapped) + static_cast<SIZE_T>(request.resource_offset);
const HRESULT read_hr = read_bytes(file, request.file_offset, destination, request.source, request.size);
const HRESULT read_hr = read_bytes(file, request.file_offset, destination, request.source, request.size, true);
D3D12_RANGE written{
static_cast<SIZE_T>(request.resource_offset),
static_cast<SIZE_T>(request.resource_offset + request.size)};
@@ -424,6 +462,7 @@ HRESULT inflate_request(HANDLE file, const Request& request) {
if (!compressed) return E_OUTOFMEMORY;
HRESULT hr = read_bytes(file, request.file_offset, compressed, request.source, request.size);
if (SUCCEEDED(hr)) {
RemapGuard remap_guard;
const BxInflateResult r = bx_zlib_inflate(compressed, request.size, static_cast<uint8_t*>(request.destination),
request.output_size);
if (r != BxInflateResult::ok) {
@@ -461,7 +500,10 @@ CopyResult fulfill(HANDLE file, const Request& request) {
if (traced.fetch_add(1) >= 20000) return result;
const DWORD out = request.compression == compression_zlib ? request.output_size : request.size;
uint64_t head[2] = {0, 0};
if (SUCCEEDED(result.hr) && request.destination && out >= 16) std::memcpy(head, request.destination, 16);
if (SUCCEEDED(result.hr) && request.destination && out >= 16) {
RemapGuard remap_guard;
std::memcpy(head, request.destination, 16);
}
char detail[220];
std::snprintf(detail, sizeof(detail), "dst=%p..%p out=%lu src=%lu offset=0x%llx compression=%u hr=0x%08lx head=%016llx %016llx",
request.destination, static_cast<const uint8_t*>(request.destination) + out, out, request.size,
@@ -483,7 +525,7 @@ CopyResult fulfill_request(HANDLE file, const Request& request) {
}
if (!request.size) return {};
if (!request.resource) {
return {read_bytes(file, request.file_offset, request.destination, request.source, request.size), false};
return {read_bytes(file, request.file_offset, request.destination, request.source, request.size, true), false};
}
const D3D12_RESOURCE_DESC desc = request.resource->GetDesc();
@@ -511,6 +553,37 @@ CopyResult fulfill_request(HANDLE file, const Request& request) {
// before Submit: a full queue stalls the enqueuer until Submit is called on
// another thread and the drain frees a slot. The public DirectStorage queues use
// both; the BetterXen synthetic queues use neither.
// Xbox physical-page destinations (DSTORAGE_REQUEST.DestinationPageArray, authorized GDK header):
// 64 KB page numbers from XMemAllocatePhysicalPages. The request writes through a span of its own:
// xmem.dll's XMemMapPhysicalPages with a NULL address (a BetterXen extension, see
// shims/xmem/physical_pages.cpp) maps the pages contiguously, and the same call with a NULL page
// array unmaps the span. The pages are sections, so the title's own views see the bytes.
using MapPhysicalPagesFn = PVOID(WINAPI*)(PVOID, ULONG_PTR, PULONG_PTR);
MapPhysicalPagesFn map_physical_pages() {
static const MapPhysicalPagesFn fn = [] {
HMODULE xmem = GetModuleHandleW(L"xmem.dll");
if (!xmem) xmem = LoadLibraryW(L"xmem.dll");
return xmem ? reinterpret_cast<MapPhysicalPagesFn>(
reinterpret_cast<void*>(GetProcAddress(xmem, "XMemMapPhysicalPages")))
: nullptr;
}();
return fn;
}
void unmap_page_span(Request& request) {
if (!request.page_span) return;
const MapPhysicalPagesFn map = map_physical_pages();
if (!map || !map(request.page_span, request.page_span_count, nullptr)) {
char detail[96];
std::snprintf(detail, sizeof(detail), "unmapping %llu destination pages failed error=%lu",
static_cast<unsigned long long>(request.page_span_count), GetLastError());
bx_log_emit(BX_LOG_WARN, "xcrdapi", "dstorage_page_destination", detail);
}
request.page_span = nullptr;
request.page_span_count = 0;
}
class WorkQueue final : public Object<Queue, queue_iid> {
public:
WorkQueue(Entry* entries, UINT capacity, bool blocking = false, UINT auto_submit = 0)
@@ -729,6 +802,7 @@ private:
case Kind::request: {
const CopyResult outcome = fulfill(entry.handle, entry.request);
result = outcome.hr;
unmap_page_span(entry.request);
if (entry.handle) CloseHandle(entry.handle);
// keep_destination holds the AddRef taken at enqueue. Releasing
// it while the staged copy is still on the GPU frees the dest.
@@ -1362,8 +1436,10 @@ static_assert(offsetof(XboxQueueDesc, flags) == 0x18, "flags offset");
struct XboxRequest {
UINT64 options; // +0x00: bit 22 (0x400000) = memory source, bit 0 = compressed
void* destination; // +0x08
UINT64 destination_pad; // +0x10
void* destination; // +0x08: buffer, or the 64 KB page-number array (DestinationIsPhysicalPages)
UINT16 destination_page_offset; // +0x10: offset into the first page (DestinationIsPhysicalPages)
UINT16 reserved12;
UINT32 reserved14;
UINT32 destination_size; // +0x18
UINT32 reserved1c; // +0x1c
void* source_ptr; // +0x20: IXboxDStorageFile* (file) or const void* (memory)
@@ -1374,6 +1450,7 @@ struct XboxRequest {
static_assert(sizeof(XboxRequest) == 56, "XboxRequest must be 56 bytes");
static_assert(offsetof(XboxRequest, options) == 0x00, "options offset");
static_assert(offsetof(XboxRequest, destination) == 0x08, "destination offset");
static_assert(offsetof(XboxRequest, destination_page_offset) == 0x10, "destination_page_offset offset");
static_assert(offsetof(XboxRequest, destination_size) == 0x18, "destination_size offset");
static_assert(offsetof(XboxRequest, source_ptr) == 0x20, "source_ptr offset");
static_assert(offsetof(XboxRequest, file_offset) == 0x28, "file_offset offset");
@@ -1531,11 +1608,12 @@ public:
reject(E_NOTIMPL, Kind::request, "EnqueueRequest");
return;
}
if (request->options & (kXboxRequestDestinationPagesBit | kXboxRequestSourcePagesBit)) {
BX_VTABLE_STUB_LOG("IDStorageQueueX", 3u, "EnqueueRequest_physical_pages");
if (request->options & kXboxRequestSourcePagesBit) {
BX_VTABLE_STUB_LOG("IDStorageQueueX", 3u, "EnqueueRequest_physical_page_source");
reject(E_NOTIMPL, Kind::request, "EnqueueRequest");
return;
}
const bool to_pages = (request->options & kXboxRequestDestinationPagesBit) != 0;
const bool zlib = (request->options & kXboxRequestCompressedBit) != 0;
if (!request->destination || (zlib ? request->source_size >= request->destination_size
: request->source_size != request->destination_size)) {
@@ -1565,7 +1643,30 @@ public:
translated.file = file->inner();
translated.file_offset = request->file_offset;
}
accept(queue_->EnqueueRequest(&translated), Kind::request, "EnqueueRequest");
if (to_pages) {
// DestinationSize bytes from DestinationPageOffset in the first page, across as many
// 64 KB pages of the array as that covers.
constexpr UINT64 page = 64 * 1024;
const UINT64 end = static_cast<UINT64>(request->destination_page_offset) + request->destination_size;
const ULONG_PTR count = static_cast<ULONG_PTR>((end + page - 1) / page);
const MapPhysicalPagesFn map = map_physical_pages();
void* span = map ? map(nullptr, count, static_cast<PULONG_PTR>(request->destination)) : nullptr;
if (!span) {
const DWORD error = map ? GetLastError() : ERROR_PROC_NOT_FOUND;
char detail[128];
std::snprintf(detail, sizeof(detail), "mapping %llu destination pages failed error=%lu",
static_cast<unsigned long long>(count), error);
bx_log_emit(BX_LOG_WARN, "xcrdapi", "dstorage_page_destination", detail);
reject(HRESULT_FROM_WIN32(error), Kind::request, "EnqueueRequest");
return;
}
translated.destination = static_cast<BYTE*>(span) + request->destination_page_offset;
translated.page_span = span;
translated.page_span_count = count;
}
const HRESULT queued = queue_->EnqueueRequest(&translated);
if (FAILED(queued)) unmap_page_span(translated);
accept(queued, Kind::request, "EnqueueRequest");
}
void STDMETHODCALLTYPE EnqueueStatus(IXboxDStorageStatusArray* status_array, UINT32 index) override {
+2 -4
View File
@@ -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);
+57 -1
View File
@@ -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
+4
View File
@@ -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);
+22
View File
@@ -97,6 +97,17 @@ struct Lock {
~Lock() { ReleaseSRWLockExclusive(&memory_lock); }
};
// Replacing part of a mapped view can leave a temporary gap across that view
// while its remaining runs are restored. DirectStorage holds remap_lock shared
// while accessing title memory. Mapping and freeing take it exclusively during
// replacement. Acquire it before memory_lock to keep the lock order consistent.
SRWLOCK remap_lock = SRWLOCK_INIT;
struct RemapExclusive {
RemapExclusive() { AcquireSRWLockExclusive(&remap_lock); }
~RemapExclusive() { ReleaseSRWLockExclusive(&remap_lock); }
};
using ReservePlaceholder = PVOID (WINAPI*)(HANDLE, PVOID, SIZE_T, ULONG, ULONG,
MEM_EXTENDED_PARAMETER*, ULONG);
using ReplacePlaceholder = PVOID (WINAPI*)(HANDLE, HANDLE, PVOID, ULONG64, SIZE_T, ULONG,
@@ -690,6 +701,7 @@ extern "C" BOOL WINAPI XMemFreePhysicalPages(ULONG_PTR count, PULONG_PTR page_ar
return FALSE;
}
RemapExclusive remap;
Lock lock;
SIZE_T validated = 0;
for (; validated < count; ++validated) {
@@ -741,6 +753,7 @@ extern "C" PVOID WINAPI XMemMapPhysicalPages(PVOID address, ULONG_PTR count, PUL
return nullptr;
}
if (!have_placeholder_api()) return nullptr;
RemapExclusive remap;
Lock lock;
auto* base = static_cast<BYTE*>(address);
const auto begin = reinterpret_cast<uintptr_t>(address);
@@ -799,6 +812,7 @@ static BOOL scatter_impl(PVOID* addresses, ULONG_PTR count, PULONG_PTR page_arra
return FALSE;
}
if (!have_placeholder_api()) return FALSE;
RemapExclusive remap;
Lock lock;
for (ULONG_PTR i = 0; i < count; ++i) {
const auto slot = reinterpret_cast<uintptr_t>(addresses[i]);
@@ -838,6 +852,14 @@ static BOOL scatter_impl(PVOID* addresses, ULONG_PTR count, PULONG_PTR page_arra
return TRUE;
}
extern "C" void bx_xmem_remap_guard_enter(void) {
AcquireSRWLockShared(&remap_lock);
}
extern "C" void bx_xmem_remap_guard_leave(void) {
ReleaseSRWLockShared(&remap_lock);
}
extern "C" int bx_xmem_query_region(uint64_t va, bx_xmem_region_info_t* out_info) {
if (!out_info) return 0;
+89 -15
View File
@@ -85,6 +85,53 @@ void update_peak() {
peak_bytes = std::max(peak_bytes, heap_bytes + virtual_bytes + physical_bytes + external_bytes);
}
// The accounting as the internal ABI reports it. The caller holds usage_lock.
bx_xmem_stats_t stats_locked() {
return {title_limit(), heap_bytes + virtual_bytes + external_bytes, physical_bytes, peak_bytes};
}
// XMEM_WORKING_SET_STATISTICS as the authorized GDK header lays it out for x64: SIZE_T fields
// are 8 bytes and UINT32 fields 4, in declaration order with natural alignment.
struct WorkingSetStatistics {
uint64_t game_limit;
uint64_t game_used;
uint64_t tools_limit;
uint64_t tools_used;
uint32_t stack_used;
uint32_t game_allocated_physical_page_count;
uint64_t gpu_optimal_bandwidth_limit;
uint64_t gpu_optimal_bandwidth_used;
uint64_t tools_gpu_optimal_bandwidth_limit;
uint64_t tools_gpu_optimal_bandwidth_used;
uint32_t kernel_pool_used;
uint32_t kernel_pool_limit;
uint32_t direct_storage_used;
uint32_t frame_preserve_buffer_size;
uint64_t game_used_peak;
uint32_t gpu_page_table_size;
uint32_t cpu_page_table_size;
uint64_t reserved[2];
};
static_assert(offsetof(WorkingSetStatistics, stack_used) == 0x20);
static_assert(offsetof(WorkingSetStatistics, gpu_optimal_bandwidth_limit) == 0x28);
static_assert(offsetof(WorkingSetStatistics, kernel_pool_used) == 0x48);
static_assert(offsetof(WorkingSetStatistics, game_used_peak) == 0x58);
static_assert(offsetof(WorkingSetStatistics, reserved) == 0x68);
static_assert(sizeof(WorkingSetStatistics) == 0x78);
// XMEM_WORKING_SET_TITLE, _TOOLS, _STACK, _KERNEL_POOL and _CPU_PTE are 0x20000001, 0x20000002,
// 0x20000004, 0x20000008 and 0x20000010: a shared 0x20000000 bit and one bit per category.
constexpr DWORD working_set_marker = 0x20000000;
constexpr DWORD working_set_categories = 0x1F;
bool valid_working_set_flags(DWORD flags) {
return (flags & working_set_marker) && (flags & working_set_categories)
&& !(flags & ~(working_set_marker | working_set_categories));
}
// Physical pages are always 64 KiB (physical_pages.cpp).
constexpr uint64_t physical_page_bytes = 64 * 1024;
uintptr_t region_end(const MEMORY_BASIC_INFORMATION& region) {
return reinterpret_cast<uintptr_t>(region.BaseAddress) + region.RegionSize;
}
@@ -365,19 +412,47 @@ BOOL WINAPI XMemTransferMemory(PVOID dst, LPCVOID src, SIZE_T bytes, uint64_t /*
return TRUE;
}
BOOL WINAPI XMemGetWorkingSetStatistics(PVOID out_stats, SIZE_T stats_size) {
if (!out_stats || stats_size < sizeof(bx_xmem_stats_t)) {
/*
* XMemGetWorkingSetStatistics(WorkingSetFlags, Statistics), as the authorized GDK header declares
* it. The whole structure is written, whichever categories the flags select, from xmem's own
* accounting:
* - GameLimit: the title memory cap.
* - GameUsed: everything the cap counts (XMem heap, virtual commits, physical pages and
* external charges); GameUsedPeak is its highest value so far.
* - GameAllocatedPhysicalPageCount: the 64 KiB physical pages allocated.
* - Tools fields: 0, since tools memory is unavailable (XMemIsToolsMemAvailable).
* - Every other field: 0. The host has no console kernel pool, GPU or CPU page tables,
* frame-preserve buffer or separate GPU-optimal memory, and xmem does not count thread
* stacks or DirectStorage buffers.
* A NULL Statistics, or flags outside the five XMEM_WORKING_SET_* values, is refused.
*/
BOOL WINAPI XMemGetWorkingSetStatistics(DWORD flags, PVOID statistics) {
if (!statistics || !valid_working_set_flags(flags)) {
char detail[96];
std::snprintf(detail, sizeof(detail), "refused flags=0x%lx statistics=%p",
static_cast<unsigned long>(flags), statistics);
bx_log_emit(BX_LOG_WARN, "xmem", "working_set_statistics", detail);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
std::lock_guard guard(usage_lock);
if (!refresh_virtual_commits()) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
bx_xmem_stats_t stats;
{
std::lock_guard guard(usage_lock);
if (!refresh_virtual_commits()) {
bx_log_emit(BX_LOG_ERROR, "xmem", "working_set_statistics",
"refresh_virtual_commits failed; statistics not reported");
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
stats = stats_locked();
}
const bx_xmem_stats_t stats{title_limit(), heap_bytes + virtual_bytes + external_bytes, physical_bytes, peak_bytes};
std::memset(out_stats, 0, stats_size);
std::memcpy(out_stats, &stats, sizeof(stats));
WorkingSetStatistics out{};
out.game_limit = stats.title_limit_bytes;
out.game_used = stats.committed_virtual_bytes + stats.allocated_physical_bytes;
out.game_used_peak = stats.peak_committed_bytes;
out.game_allocated_physical_page_count = static_cast<uint32_t>(std::min<uint64_t>(
stats.allocated_physical_bytes / physical_page_bytes, std::numeric_limits<uint32_t>::max()));
std::memcpy(statistics, &out, sizeof(out));
return TRUE;
}
@@ -387,12 +462,11 @@ BOOL WINAPI XMemIsToolsMemAvailable(void) {
void bx_xmem_get_internal_stats(bx_xmem_stats_t* out_stats) {
if (!out_stats) return;
if (!XMemGetWorkingSetStatistics(out_stats, sizeof(*out_stats))) {
// The internal ABI has no error return. Preserve the most recent
// accounting snapshot if refreshing it runs out of bookkeeping memory.
std::lock_guard guard(usage_lock);
*out_stats = {title_limit(), heap_bytes + virtual_bytes + external_bytes, physical_bytes, peak_bytes};
}
std::lock_guard guard(usage_lock);
// The internal ABI has no error return. If refreshing runs out of bookkeeping memory, the
// tracked commits are left as they were and the most recent snapshot is reported.
(void)refresh_virtual_commits();
*out_stats = stats_locked();
}
int bx_xmem_try_charge_external(uint64_t bytes) {
@@ -0,0 +1,3 @@
add_executable(test_d3d12_committed_resource_x main.cpp)
target_compile_definitions(test_d3d12_committed_resource_x PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
target_link_libraries(test_d3d12_committed_resource_x PRIVATE d3d12_xs xmem kernel32 uuid)
@@ -0,0 +1,143 @@
/*
* CreateCommittedResourceX (Xbox device table slot 76): CreateCommittedResource with a
* D3D12XBOX_RESOURCE_DESC, which is the PC D3D12_RESOURCE_DESC followed by DccOptions, a struct of
* two 32-bit enums, CompressionLevel and ColorTransform (authorized GDK header). The resource must be created with the PC part of the description,
* whatever DccOptions says, and its memory requested through XMemAlloc like any committed
* resource (AllocatorId D3D 128, ObjectType Resource 4), so a title hooking XMemAlloc sees it.
*/
#include <windows.h>
#include <d3d12.h>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(PVOID adapter, const void* params, REFIID riid,
void** ppv);
extern "C" __declspec(dllimport) PVOID WINAPI XMemAllocDefault(SIZE_T, ULONGLONG);
extern "C" __declspec(dllimport) VOID WINAPI XMemFreeDefault(PVOID, ULONGLONG);
namespace {
// D3D12XBOX_RESOURCE_DESC, written out from the GDK header's field list.
struct DccOptions {
UINT32 CompressionLevel; // D3D12XBOX_DCC_COMPRESSION_LEVEL: 64B 0, 128B 1, 256B 2, DEFAULT 3
UINT32 ColorTransform; // D3D12XBOX_DCC_COLOR_TRANSFORM: 0..3
};
struct XboxResourceDesc {
D3D12_RESOURCE_DESC pc;
DccOptions Dcc;
};
static_assert(offsetof(XboxResourceDesc, Dcc) == 56, "DccOptions follows the 56-byte PC description");
static_assert(sizeof(XboxResourceDesc) == 64, "DccOptions is two 32-bit enums");
constexpr ULONGLONG kD3DResource = (128ull << 16) | 4;
int g_d3d_requests = 0;
PVOID WINAPI alloc_hook(SIZE_T size, ULONGLONG attributes) {
if ((attributes & ((0xFFull << 16) | 0x1F)) == kD3DResource) ++g_d3d_requests;
return XMemAllocDefault(size, attributes);
}
VOID WINAPI free_hook(PVOID address, ULONGLONG attributes) { XMemFreeDefault(address, attributes); }
constexpr int kRelease = 2, kResGetDesc = 10, kDevCreateCommittedResourceX = 76;
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 GetDescFn = void(STDMETHODCALLTYPE*)(void*, D3D12_RESOURCE_DESC*);
using CreateCommittedXFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_HEAP_PROPERTIES*, D3D12_HEAP_FLAGS,
const XboxResourceDesc*, D3D12_RESOURCE_STATES,
const D3D12_CLEAR_VALUE*, REFIID, void**);
int g_failed = 0;
#define CHECK(cond, ...) \
do { \
if (!(cond)) { \
++g_failed; \
std::fprintf(stderr, "FAIL: test_d3d12_committed_resource_x:%d: ", __LINE__); \
std::fprintf(stderr, __VA_ARGS__); \
std::fprintf(stderr, "\n"); \
} \
} while (0)
void create_and_check(void* dev, const XboxResourceDesc& x, const char* what) {
D3D12_HEAP_PROPERTIES heap{};
heap.Type = D3D12_HEAP_TYPE_DEFAULT;
const int before = g_d3d_requests;
void* resource = nullptr;
const HRESULT hr = slot<CreateCommittedXFn>(dev, kDevCreateCommittedResourceX)(
dev, &heap, D3D12_HEAP_FLAG_NONE, &x, D3D12_RESOURCE_STATE_COMMON, nullptr, __uuidof(ID3D12Resource), &resource);
CHECK(hr == S_OK && resource, "%s: hr=0x%08lx", what, static_cast<unsigned long>(hr));
if (!resource) return;
D3D12_RESOURCE_DESC got{};
slot<GetDescFn>(resource, kResGetDesc)(resource, &got);
CHECK(got.Dimension == x.pc.Dimension && got.Width == x.pc.Width && got.Height == x.pc.Height &&
got.MipLevels == x.pc.MipLevels && got.Format == x.pc.Format,
"%s: created with dim=%d %llux%u mips=%u format=%d", what, static_cast<int>(got.Dimension),
static_cast<unsigned long long>(got.Width), got.Height, got.MipLevels, static_cast<int>(got.Format));
CHECK(g_d3d_requests == before + 1, "%s: %d XMemAlloc requests for its memory", what, g_d3d_requests - before);
std::printf("%s: hr=0x%08lx %llux%u format=%d, XMemAlloc requests=%d\n", what, static_cast<unsigned long>(hr),
static_cast<unsigned long long>(got.Width), got.Height, static_cast<int>(got.Format),
g_d3d_requests - before);
slot<ReleaseFn>(resource, kRelease)(resource);
}
} // namespace
struct AllocationHooks {
PVOID(WINAPI* alloc)(SIZE_T, ULONGLONG);
VOID(WINAPI* free)(PVOID, ULONGLONG);
};
extern "C" __declspec(dllexport) AllocationHooks __XMemAllocationHooks__ = {alloc_hook, free_hook};
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_committed_resource_x: host lacks the Xbox-layout device interface\n");
return 77;
}
if (FAILED(hr) || !dev) {
std::fprintf(stderr, "FAIL: device creation hr=0x%08lx\n", static_cast<unsigned long>(hr));
return 1;
}
XboxResourceDesc target{};
target.pc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
target.pc.Width = 1920;
target.pc.Height = 1080;
target.pc.DepthOrArraySize = 1;
target.pc.MipLevels = 1;
target.pc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
target.pc.SampleDesc.Count = 1;
target.pc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
target.Dcc = {2, 3}; // 256B with a correlated colour transform: the host has no compression
create_and_check(dev, target, "render target with DccOptions");
XboxResourceDesc buffer{};
buffer.pc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
buffer.pc.Width = 256 * 1024;
buffer.pc.Height = 1;
buffer.pc.DepthOrArraySize = 1;
buffer.pc.MipLevels = 1;
buffer.pc.SampleDesc.Count = 1;
buffer.pc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
create_and_check(dev, buffer, "buffer");
void* none = reinterpret_cast<void*>(1);
D3D12_HEAP_PROPERTIES heap{};
heap.Type = D3D12_HEAP_TYPE_DEFAULT;
hr = slot<CreateCommittedXFn>(dev, kDevCreateCommittedResourceX)(dev, &heap, D3D12_HEAP_FLAG_NONE, nullptr,
D3D12_RESOURCE_STATE_COMMON, nullptr,
__uuidof(ID3D12Resource), &none);
CHECK(hr == E_INVALIDARG, "null description: hr=0x%08lx", static_cast<unsigned long>(hr));
slot<ReleaseFn>(dev, kRelease)(dev);
if (g_failed) return 1;
std::puts("PASS: test_d3d12_committed_resource_x");
return 0;
}
@@ -0,0 +1,3 @@
add_executable(test_d3d12_committed_tile_size main.cpp)
target_compile_definitions(test_d3d12_committed_tile_size PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
target_link_libraries(test_d3d12_committed_tile_size PRIVATE d3d12_xs xmem kernel32 uuid)
@@ -0,0 +1,128 @@
/*
* The XMemAlloc request a committed render-target or unordered-access texture makes. On the
* console the D3D12 runtime asks XMemAlloc (AllocatorId D3D 128, ObjectType Resource 4) for the
* resource's memory, and a title hooking XMemAlloc can size its pool for those requests and check
* what is left. A 2D render-target or UAV texture with one mip and one sample is laid out in 64 KB
* tiles (64KB_R_X): 128x128 elements at 4 bytes, 128x64 at 8, per slice. The expected sizes below
* are the tile part of the sizes the authorized GDK XG library reports for these descriptions,
* written out here; XG's render-target compression metadata after the tiles is not modelled.
*/
#include <windows.h>
#include <d3d12.h>
#include <cstdint>
#include <cstdio>
#include <cstring>
extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(PVOID adapter, const void* params, REFIID riid,
void** ppv);
extern "C" __declspec(dllimport) PVOID WINAPI XMemAllocDefault(SIZE_T, ULONGLONG);
extern "C" __declspec(dllimport) VOID WINAPI XMemFreeDefault(PVOID, ULONGLONG);
namespace {
constexpr ULONGLONG kD3DResource = (128ull << 16) | 4; // AllocatorId bits 16-23, ObjectType bits 0-4
SIZE_T g_last_request = 0;
PVOID WINAPI alloc_hook(SIZE_T size, ULONGLONG attributes) {
if ((attributes & ((0xFFull << 16) | 0x1F)) == kD3DResource) g_last_request = size;
return XMemAllocDefault(size, attributes);
}
VOID WINAPI free_hook(PVOID address, ULONGLONG attributes) { XMemFreeDefault(address, attributes); }
constexpr int kRelease = 2, kDevGetResourceAllocationInfo = 25, kDevCreateCommittedResource = 27;
int g_failed = 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 CreateCommittedFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_HEAP_PROPERTIES*, D3D12_HEAP_FLAGS,
const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_STATES,
const D3D12_CLEAR_VALUE*, REFIID, void**);
D3D12_RESOURCE_DESC texture(UINT64 w, UINT h, UINT16 slices, DXGI_FORMAT format, D3D12_RESOURCE_FLAGS flags) {
D3D12_RESOURCE_DESC d{};
d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
d.Width = w;
d.Height = h;
d.DepthOrArraySize = slices;
d.MipLevels = 1;
d.Format = format;
d.SampleDesc.Count = 1;
d.Flags = flags;
return d;
}
// Creates the resource and returns the size of the XMemAlloc request it made (0 on failure).
SIZE_T request_for(void* dev, const D3D12_RESOURCE_DESC& desc) {
D3D12_HEAP_PROPERTIES heap{};
heap.Type = D3D12_HEAP_TYPE_DEFAULT;
g_last_request = 0;
void* resource = nullptr;
const HRESULT hr = slot<CreateCommittedFn>(dev, kDevCreateCommittedResource)(
dev, &heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, __uuidof(ID3D12Resource), &resource);
if (FAILED(hr) || !resource) return 0;
slot<ReleaseFn>(resource, kRelease)(resource);
return g_last_request;
}
void expect(const char* what, SIZE_T got, SIZE_T want) {
std::printf("%-44s request=0x%llx expected=0x%llx\n", what, static_cast<unsigned long long>(got),
static_cast<unsigned long long>(want));
if (got != want) {
std::fprintf(stderr, "FAIL: test_d3d12_committed_tile_size: %s\n", what);
++g_failed;
}
}
} // namespace
struct AllocationHooks {
PVOID(WINAPI* alloc)(SIZE_T, ULONGLONG);
VOID(WINAPI* free)(PVOID, ULONGLONG);
};
extern "C" __declspec(dllexport) AllocationHooks __XMemAllocationHooks__ = {alloc_hook, free_hook};
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_committed_tile_size: host lacks the Xbox-layout device interface\n");
return 77;
}
if (FAILED(hr) || !dev) {
std::fprintf(stderr, "FAIL: device creation hr=0x%08lx\n", static_cast<unsigned long>(hr));
return 1;
}
constexpr auto RT = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
constexpr auto UAV = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
constexpr SIZE_T k64K = 64 * 1024;
expect("1920x1080 RGBA8 RT+UAV: 15x9 tiles",
request_for(dev, texture(1920, 1080, 1, DXGI_FORMAT_R8G8B8A8_UNORM, RT | UAV)), 135 * k64K);
expect("3840x2160 RGBA8 RT: 30x17 tiles",
request_for(dev, texture(3840, 2160, 1, DXGI_FORMAT_R8G8B8A8_UNORM, RT)), 510 * k64K);
expect("1920x1080 RGBA16F UAV: 15x17 tiles",
request_for(dev, texture(1920, 1080, 1, DXGI_FORMAT_R16G16B16A16_FLOAT, UAV)), 255 * k64K);
expect("1920x1080 RGBA8 RT+UAV x4 slices",
request_for(dev, texture(1920, 1080, 4, DXGI_FORMAT_R8G8B8A8_UNORM, RT | UAV)), 4 * 135 * k64K);
expect("64x64 RGBA8 RT: one tile",
request_for(dev, texture(64, 64, 1, DXGI_FORMAT_R8G8B8A8_UNORM, RT)), k64K);
// Outside that scope (no render-target or UAV flag) the request stays the host's size.
const D3D12_RESOURCE_DESC sampled = texture(1920, 1080, 1, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE);
const D3D12_RESOURCE_ALLOCATION_INFO host =
slot<AllocationInfoFn>(dev, kDevGetResourceAllocationInfo)(dev, 0, 1, &sampled);
expect("1920x1080 RGBA8 sampled only: host size", request_for(dev, sampled), static_cast<SIZE_T>(host.SizeInBytes));
slot<ReleaseFn>(dev, kRelease)(dev);
if (g_failed) return 1;
std::puts("PASS: test_d3d12_committed_tile_size");
return 0;
}
@@ -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;
}
+6 -10
View File
@@ -31,16 +31,12 @@ __declspec(dllimport) VOID WINAPI XMemFree(PVOID address, uint64_t attributes);
__declspec(dllimport) BOOL WINAPI XMemAllocatePhysicalPages(uint64_t flags, PULONG_PTR count, PULONG_PTR pages);
__declspec(dllimport) BOOL WINAPI XMemFreePhysicalPages(ULONG_PTR count, PULONG_PTR pages);
__declspec(dllimport) PVOID WINAPI XMemMapPhysicalPages(PVOID base, ULONG_PTR count, PULONG_PTR pages);
__declspec(dllimport) BOOL WINAPI XMemGetWorkingSetStatistics(PVOID out_stats, SIZE_T stats_size);
__declspec(dllimport) BOOL WINAPI XMemGetWorkingSetStatistics(DWORD flags, PVOID statistics);
}
struct bx_xmem_stats_t {
uint64_t title_limit_bytes;
uint64_t committed_virtual_bytes;
uint64_t allocated_physical_bytes;
uint64_t peak_committed_bytes;
};
static_assert(sizeof(bx_xmem_stats_t) == 32, "xmem stats struct is 32 bytes");
/* XMEM_WORKING_SET_TITLE; XMEM_WORKING_SET_STATISTICS is 120 bytes on x64 (authorized GDK header). */
constexpr DWORD kXMemWorkingSetTitle = 0x20000001;
constexpr size_t kXMemWorkingSetStatisticsSize = 120;
/* D3D12XboxCreateDevice requires a D3D12XBOX_CREATE_DEVICE_PARAMETERS block (80 bytes on Xbox
Series); a zeroed one asks for defaults. Only its Version field is read by the shim. */
@@ -515,8 +511,8 @@ void check_graphics_xmem_pairing(ID3D12Device* device, uint64_t cap) {
return;
}
bx_xmem_stats_t stats{};
check(XMemGetWorkingSetStatistics(&stats, sizeof(stats)) != 0, "pairing: xmem stats readable");
alignas(8) unsigned char stats[kXMemWorkingSetStatisticsSize]{};
check(XMemGetWorkingSetStatistics(kXMemWorkingSetTitle, stats) != 0, "pairing: xmem stats readable");
/* 300 MiB heap + 300 MiB xmem = 600 MiB > 512 MiB cap. */
void* too_much = XMemAlloc(300ull << 20, 0);
@@ -0,0 +1,3 @@
add_executable(test_d3d12_rect_list main.cpp)
target_compile_definitions(test_d3d12_rect_list PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
target_link_libraries(test_d3d12_rect_list PRIVATE d3d12_xs kernel32 uuid)
@@ -0,0 +1,437 @@
/*
* Conformance test: console rectangle lists.
*
* Contract (Xbox Series GDK d3d12_xs.h): D3D_PRIMITIVE_TOPOLOGY_RECTLIST = 17 is an Xbox
* extension that takes three vertices per rectangle, and a pipeline that draws it has topology
* type D3D12XBOX_PRIMITIVE_TOPOLOGY_TYPE_RECT = 19. The fourth corner is v0 + v2 - v1, and
* attributes are extended the same way (the convention of rectangle lists since Direct3D 9 on
* Xbox; recorded here as the contract the shim implements).
*
* PC Direct3D 12 has neither value. The test renders into a 128x128 target through an
* Xbox-layout device and reads the pixels back:
* - top-left quadrant: one rectangle with three differently coloured vertices. Every pixel must
* be covered (a single triangle covers half), and the corner that has no vertex of its own
* must show v0 + v2 - v1;
* - bottom-left quadrant: two rectangles in one draw that starts at a non-zero first vertex;
* - top-right quadrant: an ordinary triangle list afterwards, which must still work;
* - bottom-right quadrant: nothing drawn, including by an indexed rectangle-list draw, which
* is not emulated and must be logged as unimplemented.
*
* Slots (Xbox-layout tables, ADR 0009): 2 Release; device 9 CreateCommandAllocator,
* 10 CreateGraphicsPipelineState, 14 CreateDescriptorHeap, 16 CreateRootSignature,
* 20 CreateRenderTargetView, 27 CreateCommittedResource, 36 CreateFence, 48 CreateCommandQueueX,
* 73 CreateCommandListX; resource 8 Map, 11 GetGPUVirtualAddress; descriptor heap 9
* GetCPUDescriptorHandleForHeapStart; command list 9 Close, 12 DrawInstanced,
* 13 DrawIndexedInstanced, 16 CopyTextureRegion, 20 IASetPrimitiveTopology, 21 RSSetViewports,
* 22 RSSetScissorRects, 25 SetPipelineState, 26 ResourceBarrier, 34 SetGraphicsRootSignature,
* 48 IASetVertexBuffers, 50 OMSetRenderTargets, 52 ClearRenderTargetView; queue 10
* ExecuteCommandLists, 16 Signal; fence 9 SetEventOnCompletion.
*/
#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, kDevCreateGraphicsPipelineState = 10, kDevCreateDescriptorHeap = 14;
constexpr int kDevCreateRootSignature = 16, kDevCreateRenderTargetView = 20, kDevCreateCommittedResource = 27;
constexpr int kDevCreateFence = 36, kDevCreateCommandQueueX = 48, kDevCreateCommandListX = 73;
constexpr int kResMap = 8, kResGetGpuVirtualAddress = 11, kHeapGetCpuStart = 9;
constexpr int kListClose = 9, kListDrawInstanced = 12, kListDrawIndexedInstanced = 13, kListCopyTextureRegion = 16;
constexpr int kListIASetPrimitiveTopology = 20, kListRSSetViewports = 21, kListRSSetScissorRects = 22;
constexpr int kListSetPipelineState = 25, kListResourceBarrier = 26, kListSetGraphicsRootSignature = 34;
constexpr int kListIASetVertexBuffers = 48, kListOMSetRenderTargets = 50, kListClearRenderTargetView = 52;
constexpr int kQueueExecuteCommandLists = 10, kQueueSignal = 16, kFenceSetEventOnCompletion = 9;
constexpr auto kRectList = static_cast<D3D12_PRIMITIVE_TOPOLOGY>(17); // D3D_PRIMITIVE_TOPOLOGY_RECTLIST
constexpr auto kTopologyTypeRect = static_cast<D3D12_PRIMITIVE_TOPOLOGY_TYPE>(19); // D3D12XBOX_PRIMITIVE_TOPOLOGY_TYPE_RECT
constexpr UINT kSize = 128;
int g_checks = 0;
int g_failed = 0;
#define CHECK(cond, ...) \
do { \
++g_checks; \
if (!(cond)) { \
++g_failed; \
std::fprintf(stderr, "FAIL: test_d3d12_rect_list:%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 CreateFenceFn = HRESULT(STDMETHODCALLTYPE*)(void*, UINT64, D3D12_FENCE_FLAGS, REFIID, void**);
using CreateHeapFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_DESCRIPTOR_HEAP_DESC*, REFIID, void**);
using HeapStartFn = D3D12_CPU_DESCRIPTOR_HANDLE(STDMETHODCALLTYPE*)(void*);
using CreateRootFn = HRESULT(STDMETHODCALLTYPE*)(void*, UINT, const void*, SIZE_T, REFIID, void**);
using CreateRtvFn = void(STDMETHODCALLTYPE*)(void*, void*, const D3D12_RENDER_TARGET_VIEW_DESC*, D3D12_CPU_DESCRIPTOR_HANDLE);
using CreatePsoFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_GRAPHICS_PIPELINE_STATE_DESC*, REFIID, void**);
using MapFn = HRESULT(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_RANGE*, void**);
using GetGpuVaFn = D3D12_GPU_VIRTUAL_ADDRESS(STDMETHODCALLTYPE*)(void*);
using CloseFn = HRESULT(STDMETHODCALLTYPE*)(void*);
using DrawFn = void(STDMETHODCALLTYPE*)(void*, UINT, UINT, UINT, UINT);
using DrawIndexedFn = void(STDMETHODCALLTYPE*)(void*, UINT, UINT, UINT, INT, UINT);
using CopyTextureFn = void(STDMETHODCALLTYPE*)(void*, const D3D12_TEXTURE_COPY_LOCATION*, UINT, UINT, UINT,
const D3D12_TEXTURE_COPY_LOCATION*, const D3D12_BOX*);
using TopologyFn = void(STDMETHODCALLTYPE*)(void*, D3D12_PRIMITIVE_TOPOLOGY);
using ViewportsFn = void(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_VIEWPORT*);
using ScissorsFn = void(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_RECT*);
using SetObjectFn = void(STDMETHODCALLTYPE*)(void*, void*);
using BarrierFn = UINT(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_RESOURCE_BARRIER*);
using SetVbFn = void(STDMETHODCALLTYPE*)(void*, UINT, UINT, const D3D12_VERTEX_BUFFER_VIEW*);
using SetTargetsFn = void(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_CPU_DESCRIPTOR_HANDLE*, BOOL,
const D3D12_CPU_DESCRIPTOR_HANDLE*);
using ClearFn = void(STDMETHODCALLTYPE*)(void*, D3D12_CPU_DESCRIPTOR_HANDLE, const FLOAT*, UINT, const D3D12_RECT*);
using ExecuteFn = void(STDMETHODCALLTYPE*)(void*, UINT, void* const*);
using QueueSignalFn = HRESULT(STDMETHODCALLTYPE*)(void*, void*, UINT64);
using FenceEventFn = HRESULT(STDMETHODCALLTYPE*)(void*, UINT64, HANDLE);
using D3DCompileFn = HRESULT(WINAPI*)(LPCVOID, SIZE_T, LPCSTR, const void*, void*, LPCSTR, LPCSTR, UINT, UINT, ID3DBlob**,
ID3DBlob**);
using SerializeRootFn = HRESULT(WINAPI*)(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC*, ID3DBlob**, ID3DBlob**);
const char kShader[] =
"struct V { float4 pos : SV_Position; float4 col : COLOR; };\n"
"V vs(float2 p : POSITION, float4 c : COLOR) { V o; o.pos = float4(p, 0.0f, 1.0f); o.col = c; return o; }\n"
"float4 ps(V i) : SV_Target0 { return i.col; }\n";
ID3DBlob* compile(const char* entry, const char* target) {
HMODULE compiler = LoadLibraryA("d3dcompiler_47.dll");
auto fn = compiler ? reinterpret_cast<D3DCompileFn>(reinterpret_cast<void*>(GetProcAddress(compiler, "D3DCompile"))) : nullptr;
if (!fn) return nullptr;
ID3DBlob* code = nullptr;
ID3DBlob* errors = nullptr;
const HRESULT hr = fn(kShader, sizeof(kShader) - 1, "rect_list", nullptr, nullptr, entry, target, 0, 0, &code, &errors);
if (FAILED(hr) && errors) std::fprintf(stderr, "D3DCompile(%s): %s\n", entry, static_cast<const char*>(errors->GetBufferPointer()));
if (errors) errors->Release();
return SUCCEEDED(hr) ? code : nullptr;
}
struct Vertex {
float x, y;
float r, g, b, a;
};
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;
}
struct Pixel {
int r, g, b;
};
const uint8_t* g_pixels = nullptr;
constexpr UINT kRowPitch = kSize * 4; // 512: a multiple of the 256-byte texture data pitch alignment
Pixel at(UINT x, UINT y) {
const uint8_t* p = g_pixels + static_cast<size_t>(y) * kRowPitch + static_cast<size_t>(x) * 4;
return {p[0], p[1], p[2]};
}
bool is_clear(Pixel p) { return p.r < 40 && p.g > 215 && p.b < 40; } // the clear colour is green
/* Pixels of the half-open quadrant [x0, x0+64) x [y0, y0+64) that still show the clear colour. */
unsigned clear_pixels(UINT x0, UINT y0) {
unsigned n = 0;
for (UINT y = y0; y < y0 + kSize / 2; ++y) {
for (UINT x = x0; x < x0 + kSize / 2; ++x) n += is_clear(at(x, y)) ? 1 : 0;
}
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_rect_list: 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;
HMODULE d3d12 = LoadLibraryA("d3d12.dll");
auto serialize = d3d12 ? reinterpret_cast<SerializeRootFn>(
reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12SerializeVersionedRootSignature")))
: nullptr;
ID3DBlob* vs = compile("vs", "vs_5_0");
ID3DBlob* ps = compile("ps", "ps_5_0");
if (!serialize || !vs || !ps) {
std::printf("SKIP: test_d3d12_rect_list: no shader compiler or root-signature serializer in this bottle\n");
return 77;
}
// Queue, allocator, list, fence.
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;
void* fence = nullptr;
slot<CreateQueueXFn>(dev, kDevCreateCommandQueueX)(dev, &qdesc, __uuidof(ID3D12CommandQueue), &queue);
slot<CreateAllocatorFn>(dev, kDevCreateCommandAllocator)(dev, D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof(ID3D12CommandAllocator),
&allocator);
slot<CreateListXFn>(dev, kDevCreateCommandListX)(dev, &ldesc, allocator, nullptr, __uuidof(ID3D12GraphicsCommandList), &list);
slot<CreateFenceFn>(dev, kDevCreateFence)(dev, 0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &fence);
// Root signature (input assembler only) and the pipeline, created with the console's
// rectangle topology type.
D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{};
root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
root_desc.Desc_1_0.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
ID3DBlob* root_blob = nullptr;
hr = serialize(&root_desc, &root_blob, nullptr);
void* root = nullptr;
if (SUCCEEDED(hr) && root_blob) {
hr = slot<CreateRootFn>(dev, kDevCreateRootSignature)(dev, 0, root_blob->GetBufferPointer(), root_blob->GetBufferSize(),
__uuidof(ID3D12RootSignature), &root);
}
CHECK(hr == S_OK && root, "CreateRootSignature hr=0x%08lx", static_cast<unsigned long>(hr));
const D3D12_INPUT_ELEMENT_DESC elements[] = {
{"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 8, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
};
auto pipeline_desc = [&](D3D12_PRIMITIVE_TOPOLOGY_TYPE type) {
D3D12_GRAPHICS_PIPELINE_STATE_DESC d{};
d.pRootSignature = static_cast<ID3D12RootSignature*>(root);
d.VS = {vs->GetBufferPointer(), vs->GetBufferSize()};
d.PS = {ps->GetBufferPointer(), ps->GetBufferSize()};
d.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
d.SampleMask = UINT_MAX;
d.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
d.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
d.RasterizerState.DepthClipEnable = TRUE;
d.InputLayout = {elements, 2};
d.PrimitiveTopologyType = type;
d.NumRenderTargets = 1;
d.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
d.SampleDesc.Count = 1;
return d;
};
void* rect_pipeline = nullptr;
void* triangle_pipeline = nullptr;
D3D12_GRAPHICS_PIPELINE_STATE_DESC pd = pipeline_desc(kTopologyTypeRect);
hr = slot<CreatePsoFn>(dev, kDevCreateGraphicsPipelineState)(dev, &pd, __uuidof(ID3D12PipelineState), &rect_pipeline);
CHECK(hr == S_OK && rect_pipeline, "CreateGraphicsPipelineState(topology type RECT) hr=0x%08lx", static_cast<unsigned long>(hr));
pd = pipeline_desc(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
hr = slot<CreatePsoFn>(dev, kDevCreateGraphicsPipelineState)(dev, &pd, __uuidof(ID3D12PipelineState), &triangle_pipeline);
CHECK(hr == S_OK && triangle_pipeline, "CreateGraphicsPipelineState(TRIANGLE) hr=0x%08lx", static_cast<unsigned long>(hr));
// Render target, its view, the readback buffer and the vertex buffer.
D3D12_HEAP_PROPERTIES default_heap{}, upload_heap{}, readback_heap{};
default_heap.Type = D3D12_HEAP_TYPE_DEFAULT;
upload_heap.Type = D3D12_HEAP_TYPE_UPLOAD;
readback_heap.Type = D3D12_HEAP_TYPE_READBACK;
D3D12_RESOURCE_DESC target_desc{};
target_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
target_desc.Width = kSize;
target_desc.Height = kSize;
target_desc.DepthOrArraySize = 1;
target_desc.MipLevels = 1;
target_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
target_desc.SampleDesc.Count = 1;
target_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
D3D12_RESOURCE_DESC buffer_desc{};
buffer_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
buffer_desc.Height = 1;
buffer_desc.DepthOrArraySize = 1;
buffer_desc.MipLevels = 1;
buffer_desc.SampleDesc.Count = 1;
buffer_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
void* target = nullptr;
void* readback = nullptr;
void* vertices = nullptr;
auto committed = slot<CreateCommittedFn>(dev, kDevCreateCommittedResource);
hr = committed(dev, &default_heap, D3D12_HEAP_FLAG_NONE, &target_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, nullptr,
__uuidof(ID3D12Resource), &target);
CHECK(hr == S_OK && target, "render target hr=0x%08lx", static_cast<unsigned long>(hr));
buffer_desc.Width = static_cast<UINT64>(kRowPitch) * kSize;
hr = committed(dev, &readback_heap, D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
__uuidof(ID3D12Resource), &readback);
CHECK(hr == S_OK && readback, "readback buffer hr=0x%08lx", static_cast<unsigned long>(hr));
buffer_desc.Width = 64 * 1024;
hr = committed(dev, &upload_heap, D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
__uuidof(ID3D12Resource), &vertices);
CHECK(hr == S_OK && vertices, "vertex buffer hr=0x%08lx", static_cast<unsigned long>(hr));
D3D12_DESCRIPTOR_HEAP_DESC heap_desc{};
heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
heap_desc.NumDescriptors = 1;
void* rtv_heap = nullptr;
hr = slot<CreateHeapFn>(dev, kDevCreateDescriptorHeap)(dev, &heap_desc, __uuidof(ID3D12DescriptorHeap), &rtv_heap);
CHECK(hr == S_OK && rtv_heap, "RTV heap hr=0x%08lx", static_cast<unsigned long>(hr));
if (!queue || !allocator || !list || !fence || !root || !rect_pipeline || !triangle_pipeline || !target || !readback ||
!vertices || !rtv_heap) {
std::fprintf(stderr, "FAIL: test_d3d12_rect_list: setup\n");
return 1;
}
const D3D12_CPU_DESCRIPTOR_HANDLE rtv = slot<HeapStartFn>(rtv_heap, kHeapGetCpuStart)(rtv_heap);
slot<CreateRtvFn>(dev, kDevCreateRenderTargetView)(dev, target, nullptr, rtv);
const float R[4] = {1, 0, 0, 1}, K[4] = {0, 0, 0, 1}, B[4] = {0, 0, 1, 1}, W[4] = {1, 1, 1, 1}, Y[4] = {1, 1, 0, 1};
auto v = [](float x, float y, const float* c) { return Vertex{x, y, c[0], c[1], c[2], c[3]}; };
const Vertex data[] = {
// 0..2: one rectangle over the top-left quadrant; the corner (0, 1) has no vertex.
v(-1, 1, R), v(-1, 0, K), v(0, 0, B),
// 3..8: two rectangles that together cover the bottom-left quadrant.
v(-1, 0, W), v(-1, -1, W), v(-0.5f, -1, W),
v(-0.5f, 0, W), v(-0.5f, -1, W), v(0, -1, W),
// 9..11: a triangle inside the top-right quadrant, drawn as a triangle list.
v(0.1f, 0.9f, Y), v(0.9f, 0.9f, Y), v(0.1f, 0.1f, Y),
};
void* mapped = nullptr;
hr = slot<MapFn>(vertices, kResMap)(vertices, 0, nullptr, &mapped);
CHECK(hr == S_OK && mapped, "vertex buffer Map hr=0x%08lx", static_cast<unsigned long>(hr));
if (!mapped) return 1;
std::memcpy(mapped, data, sizeof(data));
const D3D12_VERTEX_BUFFER_VIEW vbv{slot<GetGpuVaFn>(vertices, kResGetGpuVirtualAddress)(vertices), sizeof(data), sizeof(Vertex)};
const std::string before = read_log();
const size_t stubs_before = count_of(before, "DrawIndexedInstanced(rectangle list)");
// Record.
const D3D12_VIEWPORT viewport{0, 0, static_cast<float>(kSize), static_cast<float>(kSize), 0, 1};
const D3D12_RECT scissor{0, 0, static_cast<LONG>(kSize), static_cast<LONG>(kSize)};
const FLOAT green[4] = {0, 1, 0, 1};
slot<SetObjectFn>(list, kListSetGraphicsRootSignature)(list, root);
slot<SetTargetsFn>(list, kListOMSetRenderTargets)(list, 1, &rtv, FALSE, nullptr);
slot<ViewportsFn>(list, kListRSSetViewports)(list, 1, &viewport);
slot<ScissorsFn>(list, kListRSSetScissorRects)(list, 1, &scissor);
slot<ClearFn>(list, kListClearRenderTargetView)(list, rtv, green, 0, nullptr);
slot<SetVbFn>(list, kListIASetVertexBuffers)(list, 0, 1, &vbv);
slot<SetObjectFn>(list, kListSetPipelineState)(list, rect_pipeline);
slot<TopologyFn>(list, kListIASetPrimitiveTopology)(list, kRectList);
slot<DrawFn>(list, kListDrawInstanced)(list, 3, 1, 0, 0); // one rectangle
slot<DrawFn>(list, kListDrawInstanced)(list, 6, 1, 3, 0); // two rectangles from vertex 3
slot<DrawIndexedFn>(list, kListDrawIndexedInstanced)(list, 3, 1, 0, 0, 0); // not emulated: logged, draws nothing
slot<SetObjectFn>(list, kListSetPipelineState)(list, triangle_pipeline);
slot<TopologyFn>(list, kListIASetPrimitiveTopology)(list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
slot<DrawFn>(list, kListDrawInstanced)(list, 3, 1, 9, 0); // an ordinary triangle afterwards
D3D12_RESOURCE_BARRIER to_copy{};
to_copy.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
to_copy.Transition.pResource = static_cast<ID3D12Resource*>(target);
to_copy.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
to_copy.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
to_copy.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
slot<BarrierFn>(list, kListResourceBarrier)(list, 1, &to_copy);
D3D12_TEXTURE_COPY_LOCATION dst{};
dst.pResource = static_cast<ID3D12Resource*>(readback);
dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
dst.PlacedFootprint.Footprint = {DXGI_FORMAT_R8G8B8A8_UNORM, kSize, kSize, 1, kRowPitch};
D3D12_TEXTURE_COPY_LOCATION src{};
src.pResource = static_cast<ID3D12Resource*>(target);
src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
slot<CopyTextureFn>(list, kListCopyTextureRegion)(list, &dst, 0, 0, 0, &src, nullptr);
CHECK(slot<CloseFn>(list, kListClose)(list) == S_OK, "list Close");
void* lists[] = {list};
slot<ExecuteFn>(queue, kQueueExecuteCommandLists)(queue, 1, lists);
CHECK(slot<QueueSignalFn>(queue, kQueueSignal)(queue, fence, 1) == S_OK, "queue Signal");
HANDLE done = CreateEventW(nullptr, FALSE, FALSE, nullptr);
CHECK(slot<FenceEventFn>(fence, kFenceSetEventOnCompletion)(fence, 1, done) == S_OK, "fence event");
CHECK(WaitForSingleObject(done, 10000) == WAIT_OBJECT_0, "GPU work completes");
CloseHandle(done);
void* result = nullptr;
hr = slot<MapFn>(readback, kResMap)(readback, 0, nullptr, &result);
CHECK(hr == S_OK && result, "readback Map hr=0x%08lx", static_cast<unsigned long>(hr));
if (!result) return 1;
g_pixels = static_cast<const uint8_t*>(result);
// Control: the clear reached the target and the untouched quadrant kept it.
const unsigned half = kSize / 2, quadrant = half * half;
CHECK(clear_pixels(half, half) == quadrant, "bottom-right quadrant: %u of %u pixels show the clear colour", clear_pixels(half, half),
quadrant);
// Top-left: the whole rectangle is covered, and the fourth corner is v0 + v2 - v1.
CHECK(clear_pixels(0, 0) == 0, "top-left rectangle: %u pixel(s) are not covered (a single triangle leaves about %u)",
clear_pixels(0, 0), quadrant / 2);
Pixel p = at(2, 2);
CHECK(p.r > 200 && p.g < 40 && p.b < 40, "corner v0 is red: (%d, %d, %d)", p.r, p.g, p.b);
p = at(2, half - 3);
CHECK(p.r < 40 && p.g < 40 && p.b < 40, "corner v1 is black: (%d, %d, %d)", p.r, p.g, p.b);
p = at(half - 3, half - 3);
CHECK(p.r < 40 && p.g < 40 && p.b > 200, "corner v2 is blue: (%d, %d, %d)", p.r, p.g, p.b);
p = at(half - 3, 2);
CHECK(p.r > 200 && p.g < 40 && p.b > 200, "the fourth corner is v0 + v2 - v1 = magenta: (%d, %d, %d)", p.r, p.g, p.b);
// Bottom-left: two rectangles from a non-zero first vertex cover the quadrant in white.
CHECK(clear_pixels(0, half) == 0, "bottom-left (two rectangles in one draw): %u pixel(s) are not covered", clear_pixels(0, half));
p = at(half - 3, half + 3);
CHECK(p.r > 215 && p.g > 215 && p.b > 215, "second rectangle's fourth corner is white: (%d, %d, %d)", p.r, p.g, p.b);
// Top-right: the triangle list afterwards draws a triangle, and only a triangle.
p = at(half + 13, 13); // near (0.2, 0.8): inside
CHECK(p.r > 215 && p.g > 215 && p.b < 40, "the triangle drawn afterwards is yellow inside: (%d, %d, %d)", p.r, p.g, p.b);
p = at(kSize - 8, half - 8); // near (0.88, 0.12): outside the triangle
CHECK(is_clear(p), "the triangle list is not turned into a rectangle: (%d, %d, %d)", p.r, p.g, p.b);
const std::string after = read_log();
if (!after.empty()) {
CHECK(count_of(after, "DrawIndexedInstanced(rectangle list)") - stubs_before == 1,
"the indexed rectangle-list draw is logged as unimplemented once (logged %zu time(s))",
count_of(after, "DrawIndexedInstanced(rectangle list)") - stubs_before);
} else {
std::printf("note: no BX_LOG_FILE; the log check did not run\n");
}
for (void* object : {rtv_heap, vertices, readback, target, triangle_pipeline, rect_pipeline, root, fence, list, allocator, queue,
dev}) {
slot<ReleaseFn>(object, kRelease)(object);
}
std::printf("%s: test_d3d12_rect_list (%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_title_memory_geometry main.cpp)
target_compile_definitions(test_d3d12_title_memory_geometry PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
target_link_libraries(test_d3d12_title_memory_geometry PRIVATE d3d12_xs kernel32 uuid)
@@ -0,0 +1,447 @@
/*
* Conformance test: index and vertex data bound from plain title memory are drawn.
*
* Contract: on the console a GPU virtual address is the title's own address and the GPU reads
* the memory when the commands execute. A title binds index and vertex data it keeps in plain
* memory, with no Direct3D resource created for it, and may write that data after it has
* recorded the draw (observed in a project-authorized target build: its UI layer draws from a
* 1.1 MiB vertex ring and a 384 KiB index ring bound this way).
*
* The test renders into a 128x128 target through an Xbox-layout device and reads the pixels back:
* - first submission: an indexed triangle whose vertices and indices live in VirtualAlloc
* memory and are written only AFTER the draw was recorded, before the list is submitted;
* - second submission (a second list): the same bindings after the vertex data changed, so
* the copy must be made at every submission, not once when the buffer was created;
* - a view that starts inside the first range and a non-indexed draw from it.
* Without the fix the bindings are left empty (or, before that, crashed the host) and nothing
* is drawn.
*
* Slots (Xbox-layout tables, ADR 0009): as in test_d3d12_rect_list, plus command list 47
* IASetIndexBuffer.
*/
#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, kDevCreateGraphicsPipelineState = 10, kDevCreateDescriptorHeap = 14;
constexpr int kDevCreateRootSignature = 16, kDevCreateRenderTargetView = 20, kDevCreateCommittedResource = 27;
constexpr int kDevCreateFence = 36, kDevCreateCommandQueueX = 48, kDevCreateCommandListX = 73;
constexpr int kResMap = 8, kResGetGpuVirtualAddress = 11, kHeapGetCpuStart = 9;
constexpr int kListClose = 9, kListDrawInstanced = 12, kListDrawIndexedInstanced = 13, kListCopyTextureRegion = 16;
constexpr int kListIASetPrimitiveTopology = 20, kListRSSetViewports = 21, kListRSSetScissorRects = 22;
constexpr int kListSetPipelineState = 25, kListResourceBarrier = 26, kListSetGraphicsRootSignature = 34;
constexpr int kListIASetIndexBuffer = 47, kListIASetVertexBuffers = 48, kListOMSetRenderTargets = 50;
constexpr int kListClearRenderTargetView = 52;
constexpr int kQueueExecuteCommandLists = 10, kQueueSignal = 16, kFenceSetEventOnCompletion = 9;
constexpr UINT kSize = 128;
int g_checks = 0;
int g_failed = 0;
#define CHECK(cond, ...) \
do { \
++g_checks; \
if (!(cond)) { \
++g_failed; \
std::fprintf(stderr, "FAIL: test_d3d12_title_memory_geometry:%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 CreateFenceFn = HRESULT(STDMETHODCALLTYPE*)(void*, UINT64, D3D12_FENCE_FLAGS, REFIID, void**);
using CreateHeapFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_DESCRIPTOR_HEAP_DESC*, REFIID, void**);
using HeapStartFn = D3D12_CPU_DESCRIPTOR_HANDLE(STDMETHODCALLTYPE*)(void*);
using CreateRootFn = HRESULT(STDMETHODCALLTYPE*)(void*, UINT, const void*, SIZE_T, REFIID, void**);
using CreateRtvFn = void(STDMETHODCALLTYPE*)(void*, void*, const D3D12_RENDER_TARGET_VIEW_DESC*, D3D12_CPU_DESCRIPTOR_HANDLE);
using CreatePsoFn = HRESULT(STDMETHODCALLTYPE*)(void*, const D3D12_GRAPHICS_PIPELINE_STATE_DESC*, REFIID, void**);
using MapFn = HRESULT(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_RANGE*, void**);
using GetGpuVaFn = D3D12_GPU_VIRTUAL_ADDRESS(STDMETHODCALLTYPE*)(void*);
using CloseFn = HRESULT(STDMETHODCALLTYPE*)(void*);
using DrawFn = void(STDMETHODCALLTYPE*)(void*, UINT, UINT, UINT, UINT);
using DrawIndexedFn = void(STDMETHODCALLTYPE*)(void*, UINT, UINT, UINT, INT, UINT);
using CopyTextureFn = void(STDMETHODCALLTYPE*)(void*, const D3D12_TEXTURE_COPY_LOCATION*, UINT, UINT, UINT,
const D3D12_TEXTURE_COPY_LOCATION*, const D3D12_BOX*);
using TopologyFn = void(STDMETHODCALLTYPE*)(void*, D3D12_PRIMITIVE_TOPOLOGY);
using ViewportsFn = void(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_VIEWPORT*);
using ScissorsFn = void(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_RECT*);
using SetObjectFn = void(STDMETHODCALLTYPE*)(void*, void*);
using BarrierFn = UINT(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_RESOURCE_BARRIER*);
using SetVbFn = void(STDMETHODCALLTYPE*)(void*, UINT, UINT, const D3D12_VERTEX_BUFFER_VIEW*);
using SetIbFn = void(STDMETHODCALLTYPE*)(void*, const D3D12_INDEX_BUFFER_VIEW*);
using SetTargetsFn = void(STDMETHODCALLTYPE*)(void*, UINT, const D3D12_CPU_DESCRIPTOR_HANDLE*, BOOL,
const D3D12_CPU_DESCRIPTOR_HANDLE*);
using ClearFn = void(STDMETHODCALLTYPE*)(void*, D3D12_CPU_DESCRIPTOR_HANDLE, const FLOAT*, UINT, const D3D12_RECT*);
using ExecuteFn = void(STDMETHODCALLTYPE*)(void*, UINT, void* const*);
using QueueSignalFn = HRESULT(STDMETHODCALLTYPE*)(void*, void*, UINT64);
using FenceEventFn = HRESULT(STDMETHODCALLTYPE*)(void*, UINT64, HANDLE);
using D3DCompileFn = HRESULT(WINAPI*)(LPCVOID, SIZE_T, LPCSTR, const void*, void*, LPCSTR, LPCSTR, UINT, UINT, ID3DBlob**,
ID3DBlob**);
using SerializeRootFn = HRESULT(WINAPI*)(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC*, ID3DBlob**, ID3DBlob**);
const char kShader[] =
"struct V { float4 pos : SV_Position; float4 col : COLOR; };\n"
"V vs(float2 p : POSITION, float4 c : COLOR) { V o; o.pos = float4(p, 0.0f, 1.0f); o.col = c; return o; }\n"
"float4 ps(V i) : SV_Target0 { return i.col; }\n";
ID3DBlob* compile(const char* entry, const char* target) {
HMODULE compiler = LoadLibraryA("d3dcompiler_47.dll");
auto fn = compiler ? reinterpret_cast<D3DCompileFn>(reinterpret_cast<void*>(GetProcAddress(compiler, "D3DCompile"))) : nullptr;
if (!fn) return nullptr;
ID3DBlob* code = nullptr;
ID3DBlob* errors = nullptr;
const HRESULT hr = fn(kShader, sizeof(kShader) - 1, "title_memory_geometry", nullptr, nullptr, entry, target, 0, 0, &code, &errors);
if (FAILED(hr) && errors) std::fprintf(stderr, "D3DCompile(%s): %s\n", entry, static_cast<const char*>(errors->GetBufferPointer()));
if (errors) errors->Release();
return SUCCEEDED(hr) ? code : nullptr;
}
struct Vertex {
float x, y;
float r, g, b, a;
};
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;
}
struct Pixel {
int r, g, b;
};
const uint8_t* g_pixels = nullptr;
constexpr UINT kRowPitch = kSize * 4; // 512: a multiple of the 256-byte texture data pitch alignment
Pixel at(UINT x, UINT y) {
const uint8_t* p = g_pixels + static_cast<size_t>(y) * kRowPitch + static_cast<size_t>(x) * 4;
return {p[0], p[1], p[2]};
}
bool is_clear(Pixel p) { return p.r < 40 && p.g > 215 && p.b < 40; } // the clear colour is green
/* Pixels of the half-open quadrant [x0, x0+64) x [y0, y0+64) that still show the clear colour. */
unsigned clear_pixels(UINT x0, UINT y0) {
unsigned n = 0;
for (UINT y = y0; y < y0 + kSize / 2; ++y) {
for (UINT x = x0; x < x0 + kSize / 2; ++x) n += is_clear(at(x, y)) ? 1 : 0;
}
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_title_memory_geometry: 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;
HMODULE d3d12 = LoadLibraryA("d3d12.dll");
auto serialize = d3d12 ? reinterpret_cast<SerializeRootFn>(
reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12SerializeVersionedRootSignature")))
: nullptr;
ID3DBlob* vs = compile("vs", "vs_5_0");
ID3DBlob* ps = compile("ps", "ps_5_0");
if (!serialize || !vs || !ps) {
std::printf("SKIP: test_d3d12_title_memory_geometry: no shader compiler or root-signature serializer in this bottle\n");
return 77;
}
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* allocators[2] = {};
void* lists[2] = {};
void* fence = nullptr;
slot<CreateQueueXFn>(dev, kDevCreateCommandQueueX)(dev, &qdesc, __uuidof(ID3D12CommandQueue), &queue);
for (int i = 0; i < 2; ++i) {
slot<CreateAllocatorFn>(dev, kDevCreateCommandAllocator)(dev, D3D12_COMMAND_LIST_TYPE_DIRECT,
__uuidof(ID3D12CommandAllocator), &allocators[i]);
slot<CreateListXFn>(dev, kDevCreateCommandListX)(dev, &ldesc, allocators[i], nullptr, __uuidof(ID3D12GraphicsCommandList),
&lists[i]);
}
slot<CreateFenceFn>(dev, kDevCreateFence)(dev, 0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &fence);
D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{};
root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
root_desc.Desc_1_0.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
ID3DBlob* root_blob = nullptr;
hr = serialize(&root_desc, &root_blob, nullptr);
void* root = nullptr;
if (SUCCEEDED(hr) && root_blob) {
hr = slot<CreateRootFn>(dev, kDevCreateRootSignature)(dev, 0, root_blob->GetBufferPointer(), root_blob->GetBufferSize(),
__uuidof(ID3D12RootSignature), &root);
}
CHECK(hr == S_OK && root, "CreateRootSignature hr=0x%08lx", static_cast<unsigned long>(hr));
const D3D12_INPUT_ELEMENT_DESC elements[] = {
{"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 8, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
};
D3D12_GRAPHICS_PIPELINE_STATE_DESC pd{};
pd.pRootSignature = static_cast<ID3D12RootSignature*>(root);
pd.VS = {vs->GetBufferPointer(), vs->GetBufferSize()};
pd.PS = {ps->GetBufferPointer(), ps->GetBufferSize()};
pd.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
pd.SampleMask = UINT_MAX;
pd.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
pd.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
pd.RasterizerState.DepthClipEnable = TRUE;
pd.InputLayout = {elements, 2};
pd.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
pd.NumRenderTargets = 1;
pd.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
pd.SampleDesc.Count = 1;
void* pipeline = nullptr;
hr = slot<CreatePsoFn>(dev, kDevCreateGraphicsPipelineState)(dev, &pd, __uuidof(ID3D12PipelineState), &pipeline);
CHECK(hr == S_OK && pipeline, "CreateGraphicsPipelineState hr=0x%08lx", static_cast<unsigned long>(hr));
D3D12_HEAP_PROPERTIES default_heap{}, readback_heap{};
default_heap.Type = D3D12_HEAP_TYPE_DEFAULT;
readback_heap.Type = D3D12_HEAP_TYPE_READBACK;
D3D12_RESOURCE_DESC target_desc{};
target_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
target_desc.Width = kSize;
target_desc.Height = kSize;
target_desc.DepthOrArraySize = 1;
target_desc.MipLevels = 1;
target_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
target_desc.SampleDesc.Count = 1;
target_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
D3D12_RESOURCE_DESC buffer_desc{};
buffer_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
buffer_desc.Width = static_cast<UINT64>(kRowPitch) * kSize;
buffer_desc.Height = 1;
buffer_desc.DepthOrArraySize = 1;
buffer_desc.MipLevels = 1;
buffer_desc.SampleDesc.Count = 1;
buffer_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
void* target = nullptr;
void* readbacks[2] = {};
auto committed = slot<CreateCommittedFn>(dev, kDevCreateCommittedResource);
hr = committed(dev, &default_heap, D3D12_HEAP_FLAG_NONE, &target_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, nullptr,
__uuidof(ID3D12Resource), &target);
CHECK(hr == S_OK && target, "render target hr=0x%08lx", static_cast<unsigned long>(hr));
for (int i = 0; i < 2; ++i) {
hr = committed(dev, &readback_heap, D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
__uuidof(ID3D12Resource), &readbacks[i]);
CHECK(hr == S_OK && readbacks[i], "readback buffer %d hr=0x%08lx", i, static_cast<unsigned long>(hr));
}
D3D12_DESCRIPTOR_HEAP_DESC heap_desc{};
heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
heap_desc.NumDescriptors = 1;
void* rtv_heap = nullptr;
hr = slot<CreateHeapFn>(dev, kDevCreateDescriptorHeap)(dev, &heap_desc, __uuidof(ID3D12DescriptorHeap), &rtv_heap);
CHECK(hr == S_OK && rtv_heap, "RTV heap hr=0x%08lx", static_cast<unsigned long>(hr));
// Plain title memory for the geometry: no Direct3D resource is ever created for it.
constexpr size_t kVertexBytes = 64 * 1024, kIndexBytes = 4096;
auto* vertex_memory = static_cast<Vertex*>(VirtualAlloc(nullptr, kVertexBytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
auto* index_memory = static_cast<uint16_t*>(VirtualAlloc(nullptr, kIndexBytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
if (!queue || !allocators[0] || !allocators[1] || !lists[0] || !lists[1] || !fence || !root || !pipeline || !target ||
!readbacks[0] || !readbacks[1] || !rtv_heap || !vertex_memory || !index_memory) {
std::fprintf(stderr, "FAIL: test_d3d12_title_memory_geometry: setup\n");
return 1;
}
const D3D12_CPU_DESCRIPTOR_HANDLE rtv = slot<HeapStartFn>(rtv_heap, kHeapGetCpuStart)(rtv_heap);
slot<CreateRtvFn>(dev, kDevCreateRenderTargetView)(dev, target, nullptr, rtv);
const std::string before = read_log();
const size_t stubs_before = count_of(before, "title memory without a host buffer");
const auto vertex_va = reinterpret_cast<D3D12_GPU_VIRTUAL_ADDRESS>(vertex_memory);
const auto index_va = reinterpret_cast<D3D12_GPU_VIRTUAL_ADDRESS>(index_memory);
const D3D12_VERTEX_BUFFER_VIEW whole{vertex_va, static_cast<UINT>(kVertexBytes), sizeof(Vertex)};
// A second view that starts 8 vertices into the same memory, as a ring allocator hands out.
const D3D12_VERTEX_BUFFER_VIEW tail{vertex_va + 8 * sizeof(Vertex), static_cast<UINT>(kVertexBytes - 8 * sizeof(Vertex)),
sizeof(Vertex)};
const D3D12_INDEX_BUFFER_VIEW ibv{index_va, static_cast<UINT>(kIndexBytes), DXGI_FORMAT_R16_UINT};
const D3D12_VIEWPORT viewport{0, 0, static_cast<float>(kSize), static_cast<float>(kSize), 0, 1};
const D3D12_RECT scissor{0, 0, static_cast<LONG>(kSize), static_cast<LONG>(kSize)};
const FLOAT green[4] = {0, 1, 0, 1};
auto record = [&](void* list, void* readback, D3D12_RESOURCE_STATES target_state) {
if (target_state != D3D12_RESOURCE_STATE_RENDER_TARGET) {
D3D12_RESOURCE_BARRIER back{};
back.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
back.Transition.pResource = static_cast<ID3D12Resource*>(target);
back.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
back.Transition.StateBefore = target_state;
back.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
slot<BarrierFn>(list, kListResourceBarrier)(list, 1, &back);
}
slot<SetObjectFn>(list, kListSetGraphicsRootSignature)(list, root);
slot<SetObjectFn>(list, kListSetPipelineState)(list, pipeline);
slot<SetTargetsFn>(list, kListOMSetRenderTargets)(list, 1, &rtv, FALSE, nullptr);
slot<ViewportsFn>(list, kListRSSetViewports)(list, 1, &viewport);
slot<ScissorsFn>(list, kListRSSetScissorRects)(list, 1, &scissor);
slot<ClearFn>(list, kListClearRenderTargetView)(list, rtv, green, 0, nullptr);
slot<TopologyFn>(list, kListIASetPrimitiveTopology)(list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
// Indexed: indices 0..2 select vertices 2, 0, 1 of the whole view (the left triangle).
slot<SetVbFn>(list, kListIASetVertexBuffers)(list, 0, 1, &whole);
slot<SetIbFn>(list, kListIASetIndexBuffer)(list, &ibv);
slot<DrawIndexedFn>(list, kListDrawIndexedInstanced)(list, 3, 1, 0, 0, 0);
// Non-indexed from the view that starts inside the same memory (the right triangle).
slot<SetVbFn>(list, kListIASetVertexBuffers)(list, 0, 1, &tail);
slot<DrawFn>(list, kListDrawInstanced)(list, 3, 1, 0, 0);
D3D12_RESOURCE_BARRIER to_copy{};
to_copy.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
to_copy.Transition.pResource = static_cast<ID3D12Resource*>(target);
to_copy.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
to_copy.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
to_copy.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
slot<BarrierFn>(list, kListResourceBarrier)(list, 1, &to_copy);
D3D12_TEXTURE_COPY_LOCATION dst{};
dst.pResource = static_cast<ID3D12Resource*>(readback);
dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
dst.PlacedFootprint.Footprint = {DXGI_FORMAT_R8G8B8A8_UNORM, kSize, kSize, 1, kRowPitch};
D3D12_TEXTURE_COPY_LOCATION src{};
src.pResource = static_cast<ID3D12Resource*>(target);
src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
slot<CopyTextureFn>(list, kListCopyTextureRegion)(list, &dst, 0, 0, 0, &src, nullptr);
CHECK(slot<CloseFn>(list, kListClose)(list) == S_OK, "list Close");
};
UINT64 fence_value = 0;
auto submit = [&](void* list) {
void* one[] = {list};
slot<ExecuteFn>(queue, kQueueExecuteCommandLists)(queue, 1, one);
++fence_value;
CHECK(slot<QueueSignalFn>(queue, kQueueSignal)(queue, fence, fence_value) == S_OK, "queue Signal");
HANDLE done = CreateEventW(nullptr, FALSE, FALSE, nullptr);
CHECK(slot<FenceEventFn>(fence, kFenceSetEventOnCompletion)(fence, fence_value, done) == S_OK, "fence event");
CHECK(WaitForSingleObject(done, 10000) == WAIT_OBJECT_0, "GPU work completes");
CloseHandle(done);
};
auto map = [&](void* readback) -> const uint8_t* {
void* result = nullptr;
const HRESULT map_hr = slot<MapFn>(readback, kResMap)(readback, 0, nullptr, &result);
CHECK(map_hr == S_OK && result, "readback Map hr=0x%08lx", static_cast<unsigned long>(map_hr));
return static_cast<const uint8_t*>(result);
};
const float R[4] = {1, 0, 0, 1}, B[4] = {0, 0, 1, 1}, W[4] = {1, 1, 1, 1}, Y[4] = {1, 1, 0, 1};
auto v = [](float x, float y, const float* c) { return Vertex{x, y, c[0], c[1], c[2], c[3]}; };
// --- First submission: the data is written after the draws were recorded. ---------------
std::memset(vertex_memory, 0, kVertexBytes);
std::memset(index_memory, 0, kIndexBytes);
record(lists[0], readbacks[0], D3D12_RESOURCE_STATE_RENDER_TARGET);
// Left half: a red triangle over the top-left quadrant's lower-left half.
vertex_memory[0] = v(-1, 1, R);
vertex_memory[1] = v(-1, 0, R);
vertex_memory[2] = v(0, 0, R);
index_memory[0] = 2;
index_memory[1] = 0;
index_memory[2] = 1;
// Right half, through the tail view (its vertex 0 is vertex 8 of the memory): blue.
vertex_memory[8] = v(0, 1, B);
vertex_memory[9] = v(1, 1, B);
vertex_memory[10] = v(1, 0, B);
submit(lists[0]);
g_pixels = map(readbacks[0]);
if (!g_pixels) return 1;
const unsigned half = kSize / 2;
CHECK(clear_pixels(0, half) == half * half && clear_pixels(half, half) == half * half,
"control: the bottom half keeps the clear colour (%u and %u of %u)", clear_pixels(0, half), clear_pixels(half, half),
half * half);
Pixel p = at(8, half - 16); // near (-0.875, 0.25): inside the left triangle
CHECK(p.r > 215 && p.g < 40 && p.b < 40,
"indexed draw from plain title memory, written after recording, is red inside its triangle: (%d, %d, %d)", p.r, p.g, p.b);
p = at(half - 8, 8); // near (-0.125, 0.875): outside the left triangle
CHECK(is_clear(p), "and leaves the rest of its quadrant alone: (%d, %d, %d)", p.r, p.g, p.b);
p = at(kSize - 16, 8); // near (0.75, 0.875): inside the right triangle
CHECK(p.r < 40 && p.g < 40 && p.b > 215,
"non-indexed draw through a view that starts inside the same memory is blue: (%d, %d, %d)", p.r, p.g, p.b);
// --- Second submission: the same bindings after the data changed. -----------------------
vertex_memory[0] = v(-1, 1, W);
vertex_memory[1] = v(0, 1, W);
vertex_memory[2] = v(0, 0, W); // now the upper-right half of the top-left quadrant, white
vertex_memory[8] = v(0, 0, Y);
vertex_memory[9] = v(1, 0, Y);
vertex_memory[10] = v(0, 1, Y); // now the lower-left half of the top-right quadrant, yellow
record(lists[1], readbacks[1], D3D12_RESOURCE_STATE_COPY_SOURCE);
submit(lists[1]);
g_pixels = map(readbacks[1]);
if (!g_pixels) return 1;
p = at(half - 8, 8);
CHECK(p.r > 215 && p.g > 215 && p.b > 215, "second submission draws the changed vertices (white): (%d, %d, %d)", p.r, p.g, p.b);
p = at(8, half - 16);
CHECK(is_clear(p), "and no longer the first triangle: (%d, %d, %d)", p.r, p.g, p.b);
p = at(half + 8, half - 8); // near (0.125, 0.125): inside the new right triangle
CHECK(p.r > 215 && p.g > 215 && p.b < 40, "changed tail-view vertices are drawn (yellow): (%d, %d, %d)", p.r, p.g, p.b);
const std::string after = read_log();
if (!after.empty()) {
CHECK(count_of(after, "title memory without a host buffer") == stubs_before,
"no binding is logged as unimplemented (%zu new)", count_of(after, "title memory without a host buffer") - stubs_before);
CHECK(count_of(after, "host buffer for bound title memory") > count_of(before, "host buffer for bound title memory"),
"the host buffers made for bound title memory are logged");
} else {
std::printf("note: no BX_LOG_FILE; the log checks did not run\n");
}
VirtualFree(vertex_memory, 0, MEM_RELEASE);
VirtualFree(index_memory, 0, MEM_RELEASE);
for (void* object : {rtv_heap, readbacks[1], readbacks[0], target, pipeline, root, fence, lists[1], lists[0], allocators[1],
allocators[0], queue, dev}) {
slot<ReleaseFn>(object, kRelease)(object);
}
std::printf("%s: test_d3d12_title_memory_geometry (%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,229 @@
/*
* Conformance test: index and vertex bindings at a title address this layer cannot give a host
* buffer 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. BetterXen gives such memory a host buffer when it is bound (drawing from it is covered by
* test_d3d12_title_memory_geometry). When it cannot, because the address is not readable memory,
* the address must still not be passed through: it is not a host address, and D3DMetal
* dereferences the buffer it fails to find (a null read inside IASetIndexBuffer). The binding is
* then left empty (Direct3D 12 defines a null binding) and the call is logged as unimplemented.
*
* Checked here, recording into an Xbox-layout command list:
* - bindings inside a buffer BetterXen created, and in plain committed title memory: accepted,
* not logged;
* - bindings in reserved but uncommitted address space: left empty, each logged exactly once;
* - null bindings: unchanged, not logged;
* - the list still closes.
* Before either fix the failure mode was the null read.
*
* 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)");
// Address space that is reserved but not committed: there is nothing to copy from.
auto* unreadable = static_cast<unsigned char*>(VirtualAlloc(nullptr, 64 * 1024, MEM_RESERVE, PAGE_NOACCESS));
CHECK(unreadable != nullptr, "VirtualAlloc(64 KiB, reserve only)");
if (!queue || !allocator || !list || !backed || !plain || !unreadable) {
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);
const auto unreadable_va = reinterpret_cast<D3D12_GPU_VIRTUAL_ADDRESS>(unreadable);
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 committed title memory: given a host buffer, not logged.
const D3D12_INDEX_BUFFER_VIEW plain_index{plain_va, 4096, DXGI_FORMAT_R16_UINT};
slot<SetIndexFn>(list, kListIASetIndexBuffer)(list, &plain_index);
const D3D12_VERTEX_BUFFER_VIEW plain_vertex{plain_va + 4096, 4096, 16};
slot<SetVertexFn>(list, kListIASetVertexBuffers)(list, 0, 1, &plain_vertex);
CHECK(true, "bindings in plain title memory returned");
{
const std::string now = read_log();
if (!now.empty()) {
CHECK(count_of(now, kIndexStub) == index_before && count_of(now, kVertexStub) == vertex_before,
"bindings in plain title memory are not logged as unimplemented");
}
}
// 3. Bindings in address space with no memory behind it: the process must survive them.
const D3D12_INDEX_BUFFER_VIEW unreadable_index{unreadable_va, 4096, DXGI_FORMAT_R16_UINT};
slot<SetIndexFn>(list, kListIASetIndexBuffer)(list, &unreadable_index);
CHECK(true, "IASetIndexBuffer at an unreadable title address returned");
// Two vertex streams: the first backed, the second not. Only the second is emptied.
const D3D12_VERTEX_BUFFER_VIEW streams[2] = {backed_vertex, {unreadable_va + 4096, 4096, 16}};
slot<SetVertexFn>(list, kListIASetVertexBuffers)(list, 0, 2, streams);
CHECK(true, "IASetVertexBuffers with one stream at an unreadable address returned");
// 4. 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 unreadable 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 unreadable 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(unreadable, 0, MEM_RELEASE);
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;
}
@@ -0,0 +1,7 @@
# #671: D3DMetal capability checks for translated console shaders (SM 6.6 heap indexing,
# 64-lane wave emulation, amplification and mesh shaders). Loads the host d3d12.dll at run time;
# links no BetterXen shim. Shader headers are generated by shaders/compile.sh (DXC v1.9.2609)
# and committed.
add_executable(test_d3dmetal_translator_caps main.cpp)
target_include_directories(test_d3dmetal_translator_caps PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test_d3dmetal_translator_caps PRIVATE kernel32)
@@ -0,0 +1,763 @@
/*
* #671: what D3DMetal does with the features translated console shaders need. Each check
* ends in one result line, "RESULT: <check> runs-correctly | workaround | blocked", with the
* observations it rests on:
*
* 1. heap_index SM 6.6 dynamic resources: a UAV, a raw SRV, a typed SRV, a texture and a
* sampler all fetched from the descriptor heaps by index. runs-correctly when
* every value matches.
* 2. wave64 A 64-lane console wave on host hardware: the host's wave width, then two
* routes over a 64-thread group, through groupshared memory and through the
* host's own wave operations merged across waves (ballot, prefix sum, read
* lane, active sum). workaround when a route gives the 64-lane answers; the
* [WaveSize(64)] attribute itself is measured by test_d3dmetal_gpu_limits.
* 3. atomic64 Measured by test_d3dmetal_gpu_limits (typed 64-bit atomics, lock emulation);
* not repeated here.
* 4. mesh Amplification -> mesh -> pixel into a 4x4 target: the reported mesh shader
* tier, pipeline creation, and every pixel's value.
*
* Talks to the host d3d12.dll directly (no BetterXen shim in the path), so under
* CrossOver/Wine with D3DMetal it measures D3DMetal. Expected values are computed here on
* the CPU from the public HLSL/D3D12 semantics, never by the GPU.
*
* A check whose result is not runs-correctly is an observation, not a failure: the test exits
* 0 when every result was reached, 1 when setup failed or the GPU hung, 77 without SM 6.6.
*/
#ifndef WIDL_EXPLICIT_AGGREGATE_RETURNS
#define WIDL_EXPLICIT_AGGREGATE_RETURNS /* call struct-returning COM methods with the real x64 ABI */
#endif
#include <windows.h>
#include <d3d12.h>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <vector>
#include "shaders/heap_index.h"
#include "shaders/mesh_as.h"
#include "shaders/mesh_ms.h"
#include "shaders/mesh_ps.h"
#include "shaders/wave64_emulation.h"
namespace {
constexpr uint32_t kSentinel = 0xA5A5A5A5u;
constexpr DWORD kGpuTimeoutMs = 10000;
int g_required = 0;
int g_failures = 0;
__attribute__((format(gnu_printf, 2, 3)))
bool require(bool ok, const char* fmt, ...) {
g_required++;
if (!ok) {
g_failures++;
char msg[320];
va_list ap;
va_start(ap, fmt);
std::vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
std::fprintf(stderr, "FAIL: %s\n", msg);
std::fflush(stderr);
}
return ok;
}
__attribute__((format(gnu_printf, 1, 2)))
void observed(const char* fmt, ...) {
char msg[320];
va_list ap;
va_start(ap, fmt);
std::vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
std::printf("OBSERVED: %s\n", msg);
std::fflush(stdout);
}
unsigned long ul(HRESULT hr) { return static_cast<unsigned long>(hr); }
template <typename T>
void release(T*& p) {
if (p) {
p->Release();
p = nullptr;
}
}
/* ---- D3D12 plumbing ---- */
using PFN_CreateDevice = HRESULT(WINAPI*)(IUnknown*, D3D_FEATURE_LEVEL, REFIID, void**);
using PFN_Serialize = HRESULT(WINAPI*)(const D3D12_ROOT_SIGNATURE_DESC*, D3D_ROOT_SIGNATURE_VERSION, ID3DBlob**,
ID3DBlob**);
struct Gpu {
ID3D12Device* dev = nullptr;
ID3D12CommandQueue* queue = nullptr;
ID3D12CommandAllocator* alloc = nullptr;
ID3D12GraphicsCommandList* list = nullptr;
ID3D12Fence* fence = nullptr;
UINT64 fence_value = 0;
HANDLE event = nullptr;
PFN_Serialize serialize = nullptr;
bool lost = false; /* a submission timed out or the device was removed */
};
/* Close, submit, wait (bounded) and reopen the list. False on timeout or device removal. */
bool submit(Gpu& g, const char* what) {
if (g.lost) return false;
HRESULT hr = g.list->Close();
if (FAILED(hr)) {
observed("%s command list Close failed hr=0x%08lx", what, ul(hr));
return false;
}
ID3D12CommandList* lists[] = {g.list};
g.queue->ExecuteCommandLists(1, lists);
hr = g.queue->Signal(g.fence, ++g.fence_value);
if (FAILED(hr)) {
observed("%s queue Signal failed hr=0x%08lx", what, ul(hr));
g.lost = true;
return false;
}
if (g.fence->GetCompletedValue() < g.fence_value) {
hr = g.fence->SetEventOnCompletion(g.fence_value, g.event);
if (FAILED(hr) || WaitForSingleObject(g.event, kGpuTimeoutMs) != WAIT_OBJECT_0) {
observed("%s GPU work did not finish within %lu ms (queue considered hung; later checks skipped)", what,
static_cast<unsigned long>(kGpuTimeoutMs));
g.lost = true;
return false;
}
}
if (g.fence->GetCompletedValue() == UINT64_MAX) {
observed("%s device removed, reason hr=0x%08lx", what, ul(g.dev->GetDeviceRemovedReason()));
g.lost = true;
return false;
}
hr = g.alloc->Reset();
if (SUCCEEDED(hr)) hr = g.list->Reset(g.alloc, nullptr);
if (FAILED(hr)) {
observed("%s allocator or command list Reset failed hr=0x%08lx", what, ul(hr));
g.lost = true;
return false;
}
return true;
}
/* Discards whatever is recorded in the open list without executing it (used when a
* check fails partway through recording), so the next check starts from an empty list. */
void abandon(Gpu& g) {
if (g.lost) return;
g.list->Close();
if (FAILED(g.alloc->Reset()) || FAILED(g.list->Reset(g.alloc, nullptr))) g.lost = true;
}
/* Releases a resource the GPU may have used. After a hung or removed queue the GPU may
* still reference it, so it is deliberately leaked instead. */
template <typename T>
void drop(const Gpu& g, T*& p) {
if (g.lost) {
p = nullptr;
return;
}
release(p);
}
ID3D12Resource* make_buffer(Gpu& g, D3D12_HEAP_TYPE heap, UINT64 size, D3D12_RESOURCE_STATES state,
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE) {
D3D12_HEAP_PROPERTIES hp = {};
hp.Type = heap;
D3D12_RESOURCE_DESC rd = {};
rd.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
rd.Width = size;
rd.Height = 1;
rd.DepthOrArraySize = 1;
rd.MipLevels = 1;
rd.SampleDesc.Count = 1;
rd.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
rd.Flags = flags;
ID3D12Resource* r = nullptr;
HRESULT hr = g.dev->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &rd, state, nullptr,
__uuidof(ID3D12Resource), reinterpret_cast<void**>(&r));
return SUCCEEDED(hr) ? r : nullptr;
}
ID3D12Resource* make_texture(Gpu& g, UINT width, UINT height, DXGI_FORMAT format) {
D3D12_HEAP_PROPERTIES hp = {};
hp.Type = D3D12_HEAP_TYPE_DEFAULT;
D3D12_RESOURCE_DESC rd = {};
rd.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
rd.Width = width;
rd.Height = height;
rd.DepthOrArraySize = 1;
rd.MipLevels = 1;
rd.Format = format;
rd.SampleDesc.Count = 1;
rd.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
ID3D12Resource* r = nullptr;
HRESULT hr = g.dev->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &rd, D3D12_RESOURCE_STATE_COPY_DEST,
nullptr, __uuidof(ID3D12Resource), reinterpret_cast<void**>(&r));
return SUCCEEDED(hr) ? r : nullptr;
}
void transition(Gpu& g, ID3D12Resource* r, D3D12_RESOURCE_STATES before, D3D12_RESOURCE_STATES after) {
D3D12_RESOURCE_BARRIER b = {};
b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
b.Transition.pResource = r;
b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
b.Transition.StateBefore = before;
b.Transition.StateAfter = after;
g.list->ResourceBarrier(1, &b);
}
bool map_write(ID3D12Resource* r, const void* src, size_t n) {
void* p = nullptr;
if (FAILED(r->Map(0, nullptr, &p)) || !p) return false;
std::memcpy(p, src, n);
r->Unmap(0, nullptr);
return true;
}
bool map_read(ID3D12Resource* r, void* dst, size_t n) {
void* p = nullptr;
D3D12_RANGE range = {0, n};
if (FAILED(r->Map(0, &range, &p)) || !p) return false;
std::memcpy(dst, p, n);
D3D12_RANGE none = {0, 0};
r->Unmap(0, &none);
return true;
}
/* Root signature from parameters; logs and returns null on failure. */
ID3D12RootSignature* make_root(Gpu& g, const char* what, const D3D12_ROOT_PARAMETER* params, UINT count) {
D3D12_ROOT_SIGNATURE_DESC desc = {};
desc.NumParameters = count;
desc.pParameters = params;
ID3DBlob* blob = nullptr;
ID3DBlob* err = nullptr;
HRESULT hr = g.serialize(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, &err);
release(err);
if (FAILED(hr)) {
observed("%s root signature serialization failed hr=0x%08lx", what, ul(hr));
return nullptr;
}
ID3D12RootSignature* rs = nullptr;
hr = g.dev->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), __uuidof(ID3D12RootSignature),
reinterpret_cast<void**>(&rs));
release(blob);
if (FAILED(hr)) {
observed("%s CreateRootSignature failed hr=0x%08lx", what, ul(hr));
return nullptr;
}
return rs;
}
ID3D12PipelineState* make_pipeline(Gpu& g, ID3D12RootSignature* rs, const unsigned char* code, size_t size,
HRESULT* out_hr) {
D3D12_COMPUTE_PIPELINE_STATE_DESC pd = {};
pd.pRootSignature = rs;
pd.CS.pShaderBytecode = code;
pd.CS.BytecodeLength = size;
ID3D12PipelineState* pso = nullptr;
*out_hr = g.dev->CreateComputePipelineState(&pd, __uuidof(ID3D12PipelineState), reinterpret_cast<void**>(&pso));
return SUCCEEDED(*out_hr) ? pso : nullptr;
}
D3D12_ROOT_PARAMETER root_uav(UINT reg) {
D3D12_ROOT_PARAMETER p = {};
p.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
p.Descriptor.ShaderRegister = reg;
p.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
return p;
}
/* ---- buffer kernels: run one dispatch over a root-UAV buffer, return its words ---- */
bool run_buffer_kernel(Gpu& g, const char* what, ID3D12PipelineState* pso, ID3D12RootSignature* rs,
const std::vector<uint32_t>& init, UINT groups, std::vector<uint32_t>& out) {
const UINT64 bytes = init.size() * sizeof(uint32_t);
ID3D12Resource* up = make_buffer(g, D3D12_HEAP_TYPE_UPLOAD, bytes, D3D12_RESOURCE_STATE_GENERIC_READ);
ID3D12Resource* buf = make_buffer(g, D3D12_HEAP_TYPE_DEFAULT, bytes, D3D12_RESOURCE_STATE_COMMON,
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
ID3D12Resource* rb = make_buffer(g, D3D12_HEAP_TYPE_READBACK, bytes, D3D12_RESOURCE_STATE_COPY_DEST);
bool ok = up && buf && rb && map_write(up, init.data(), bytes);
if (ok) {
g.list->CopyBufferRegion(buf, 0, up, 0, bytes);
transition(g, buf, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
g.list->SetComputeRootSignature(rs);
g.list->SetPipelineState(pso);
g.list->SetComputeRootUnorderedAccessView(0, buf->GetGPUVirtualAddress());
g.list->Dispatch(groups, 1, 1);
transition(g, buf, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
g.list->CopyBufferRegion(rb, 0, buf, 0, bytes);
ok = submit(g, what);
out.assign(init.size(), 0);
ok = ok && map_read(rb, out.data(), bytes);
} else {
observed("%s buffer creation or upload failed", what);
}
drop(g, up);
drop(g, buf);
drop(g, rb);
return ok;
}
struct TexCopy {
D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {};
UINT64 total = 0;
};
TexCopy footprint(Gpu& g, ID3D12Resource* tex) {
TexCopy t;
D3D12_RESOURCE_DESC rd;
tex->GetDesc(&rd);
UINT rows = 0;
UINT64 row_bytes = 0;
g.dev->GetCopyableFootprints(&rd, 0, 1, 0, &t.fp, &rows, &row_bytes, &t.total);
return t;
}
void copy_to_texture(Gpu& g, ID3D12Resource* tex, ID3D12Resource* up, const TexCopy& t) {
D3D12_TEXTURE_COPY_LOCATION dst = {};
dst.pResource = tex;
dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
D3D12_TEXTURE_COPY_LOCATION src = {};
src.pResource = up;
src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
src.PlacedFootprint = t.fp;
g.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
}
void result(const char* check, const char* outcome, const char* why) {
std::printf("RESULT: %s %s (%s)\n", check, outcome, why);
}
ID3D12RootSignature* make_root_flags(Gpu& g, const char* what, const D3D12_ROOT_PARAMETER* params, UINT count,
D3D12_ROOT_SIGNATURE_FLAGS flags) {
D3D12_ROOT_SIGNATURE_DESC desc = {};
desc.NumParameters = count;
desc.pParameters = params;
desc.Flags = flags;
ID3DBlob* blob = nullptr;
ID3DBlob* err = nullptr;
HRESULT hr = g.serialize(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, &err);
if (FAILED(hr)) {
observed("%s root signature serialization failed hr=0x%08lx %s", what, ul(hr),
err ? static_cast<const char*>(err->GetBufferPointer()) : "");
release(err);
return nullptr;
}
release(err);
ID3D12RootSignature* rs = nullptr;
hr = g.dev->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), __uuidof(ID3D12RootSignature),
reinterpret_cast<void**>(&rs));
release(blob);
if (FAILED(hr)) observed("%s CreateRootSignature failed hr=0x%08lx", what, ul(hr));
return SUCCEEDED(hr) ? rs : nullptr;
}
/* ---- 1. heap_index ---- */
void check_heap_index(Gpu& g) {
D3D12_FEATURE_DATA_D3D12_OPTIONS o = {};
if (SUCCEEDED(g.dev->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &o, sizeof(o)))) {
observed("heap_index.resource_binding_tier %d", static_cast<int>(o.ResourceBindingTier));
}
D3D12_ROOT_PARAMETER constants = {};
constants.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
constants.Constants.ShaderRegister = 0;
constants.Constants.Num32BitValues = 4;
constants.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
const auto flags = static_cast<D3D12_ROOT_SIGNATURE_FLAGS>(0x400 | 0x800); /* CBV_SRV_UAV_ and SAMPLER_HEAP_DIRECTLY_INDEXED */
ID3D12RootSignature* rs = make_root_flags(g, "heap_index", &constants, 1, flags);
if (!rs) {
result("heap_index", "blocked", "root signature with directly indexed heaps refused");
return;
}
HRESULT hr = S_OK;
ID3D12PipelineState* pso = make_pipeline(g, rs, g_heap_index_cs, sizeof(g_heap_index_cs), &hr);
if (!pso) {
observed("heap_index CreateComputePipelineState hr=0x%08lx", ul(hr));
result("heap_index", "blocked", "pipeline refused");
release(rs);
return;
}
constexpr UINT kN = 64;
std::vector<uint32_t> raw(kN), typed(kN);
for (UINT i = 0; i < kN; ++i) {
raw[i] = i * 5u + 1u;
typed[i] = 1000u + i;
}
const float texels[4] = {1.0f, 2.5f, 3.0f, 4.0f}; /* 2x2, row-major; texel (1,0) is 2.5 */
const UINT64 out_bytes = (kN + 1) * 4;
ID3D12Resource* raw_up = make_buffer(g, D3D12_HEAP_TYPE_UPLOAD, kN * 4, D3D12_RESOURCE_STATE_GENERIC_READ);
ID3D12Resource* typed_up = make_buffer(g, D3D12_HEAP_TYPE_UPLOAD, kN * 4, D3D12_RESOURCE_STATE_GENERIC_READ);
ID3D12Resource* outb = make_buffer(g, D3D12_HEAP_TYPE_DEFAULT, out_bytes, D3D12_RESOURCE_STATE_COMMON,
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
ID3D12Resource* rb = make_buffer(g, D3D12_HEAP_TYPE_READBACK, out_bytes, D3D12_RESOURCE_STATE_COPY_DEST);
ID3D12Resource* tex = make_texture(g, 2, 2, DXGI_FORMAT_R32_FLOAT);
TexCopy tc;
ID3D12Resource* tex_up = nullptr;
if (tex) {
tc = footprint(g, tex);
tex_up = make_buffer(g, D3D12_HEAP_TYPE_UPLOAD, tc.total, D3D12_RESOURCE_STATE_GENERIC_READ);
}
bool ok = raw_up && typed_up && outb && rb && tex && tex_up && map_write(raw_up, raw.data(), kN * 4) &&
map_write(typed_up, typed.data(), kN * 4);
if (ok) {
std::vector<uint8_t> staging(tc.total, 0);
for (UINT y = 0; y < 2; ++y) std::memcpy(&staging[tc.fp.Offset + y * tc.fp.Footprint.RowPitch], &texels[y * 2], 8);
ok = map_write(tex_up, staging.data(), staging.size());
}
ID3D12DescriptorHeap* heap = nullptr;
ID3D12DescriptorHeap* samplers = nullptr;
if (ok) {
D3D12_DESCRIPTOR_HEAP_DESC hd = {};
hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
hd.NumDescriptors = 4;
hd.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
D3D12_DESCRIPTOR_HEAP_DESC sd = hd;
sd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
sd.NumDescriptors = 1;
ok = SUCCEEDED(g.dev->CreateDescriptorHeap(&hd, __uuidof(ID3D12DescriptorHeap), reinterpret_cast<void**>(&heap))) &&
SUCCEEDED(g.dev->CreateDescriptorHeap(&sd, __uuidof(ID3D12DescriptorHeap), reinterpret_cast<void**>(&samplers)));
}
if (ok) {
D3D12_CPU_DESCRIPTOR_HANDLE h;
heap->GetCPUDescriptorHandleForHeapStart(&h);
const UINT inc = g.dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
D3D12_UNORDERED_ACCESS_VIEW_DESC ud = {};
ud.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
ud.Buffer.NumElements = kN + 1;
ud.Buffer.StructureByteStride = 4;
g.dev->CreateUnorderedAccessView(outb, nullptr, &ud, h);
D3D12_SHADER_RESOURCE_VIEW_DESC rd = {};
rd.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
rd.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
rd.Format = DXGI_FORMAT_R32_TYPELESS;
rd.Buffer.NumElements = kN;
rd.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
h.ptr += inc;
g.dev->CreateShaderResourceView(raw_up, &rd, h);
D3D12_SHADER_RESOURCE_VIEW_DESC td = rd;
td.Format = DXGI_FORMAT_R32_UINT;
td.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
h.ptr += inc;
g.dev->CreateShaderResourceView(typed_up, &td, h);
D3D12_SHADER_RESOURCE_VIEW_DESC xd = {};
xd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
xd.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
xd.Format = DXGI_FORMAT_R32_FLOAT;
xd.Texture2D.MipLevels = 1;
h.ptr += inc;
g.dev->CreateShaderResourceView(tex, &xd, h);
D3D12_SAMPLER_DESC smp = {};
smp.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
smp.AddressU = smp.AddressV = smp.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
smp.MaxLOD = 1000.0f;
D3D12_CPU_DESCRIPTOR_HANDLE sh;
samplers->GetCPUDescriptorHandleForHeapStart(&sh);
g.dev->CreateSampler(&smp, sh);
copy_to_texture(g, tex, tex_up, tc);
transition(g, tex, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
transition(g, outb, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
ID3D12DescriptorHeap* heaps[] = {heap, samplers};
g.list->SetDescriptorHeaps(2, heaps);
g.list->SetComputeRootSignature(rs);
g.list->SetPipelineState(pso);
const UINT indices[4] = {0, 1, 2, 3};
g.list->SetComputeRoot32BitConstants(0, 4, indices, 0);
g.list->Dispatch(1, 1, 1);
transition(g, outb, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
g.list->CopyBufferRegion(rb, 0, outb, 0, out_bytes);
ok = submit(g, "heap_index");
} else {
observed("heap_index setup failed");
abandon(g);
}
std::vector<uint32_t> out(kN + 1, kSentinel);
if (ok) ok = map_read(rb, out.data(), out_bytes);
if (!ok) {
require(false, "heap_index: setup and GPU work must complete");
} else {
UINT wrong = 0;
for (UINT i = 0; i < kN; ++i) wrong += out[i] != raw[i] * 3u + typed[i];
float sampled = 0;
std::memcpy(&sampled, &out[kN], 4);
observed("heap_index buffers: %u of %u words wrong; first word 0x%08x (expected 0x%08x)", wrong, kN, out[0],
raw[0] * 3u + typed[0]);
observed("heap_index sampler+texture: got %g (expected 2.5)", static_cast<double>(sampled));
const bool all = wrong == 0 && sampled == 2.5f;
result("heap_index", all ? "runs-correctly" : "blocked",
all ? "UAV, raw and typed SRVs, texture and sampler all fetched by heap index"
: "values from heap-indexed descriptors are wrong");
}
drop(g, raw_up);
drop(g, typed_up);
drop(g, outb);
drop(g, rb);
drop(g, tex);
drop(g, tex_up);
drop(g, heap);
drop(g, samplers);
release(pso);
release(rs);
}
/* ---- 2. wave64 ---- */
uint32_t value_of(uint32_t lane) { return (lane * 7u + 3u) & 31u; }
bool pred_of(uint32_t lane) { return ((lane * 13u + 5u) % 3u) == 0u; }
void check_wave64(Gpu& g) {
D3D12_FEATURE_DATA_D3D12_OPTIONS1 o1 = {};
if (SUCCEEDED(g.dev->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &o1, sizeof(o1)))) {
observed("wave64.reported WaveOps=%d WaveLaneCountMin=%u WaveLaneCountMax=%u", o1.WaveOps ? 1 : 0,
o1.WaveLaneCountMin, o1.WaveLaneCountMax);
}
D3D12_ROOT_PARAMETER params[] = {root_uav(0)};
ID3D12RootSignature* rs = make_root(g, "wave64", params, 1);
if (!require(rs != nullptr, "wave64 root signature")) return;
HRESULT hr = S_OK;
ID3D12PipelineState* pso = make_pipeline(g, rs, g_wave64_emulation_cs, sizeof(g_wave64_emulation_cs), &hr);
if (!pso) {
observed("wave64 CreateComputePipelineState hr=0x%08lx", ul(hr));
result("wave64", "blocked", "emulation kernel refused");
release(rs);
return;
}
std::vector<uint32_t> out;
const bool ran = run_buffer_kernel(g, "wave64", pso, rs, std::vector<uint32_t>(64 * 8, kSentinel), 1, out);
release(pso);
release(rs);
if (!require(ran, "wave64: dispatch must complete")) return;
/* CPU reference for a 64-lane wave. */
uint32_t lo = 0, hi = 0, total = 0;
for (uint32_t i = 0; i < 64; ++i) {
if (pred_of(i)) (i < 32 ? lo : hi) |= 1u << (i & 31u);
total += value_of(i);
}
UINT shared_wrong = 0, native_wrong = 0;
uint32_t prefix = 0;
for (uint32_t lane = 0; lane < 64; ++lane) {
const uint32_t* o = &out[lane * 8];
shared_wrong += o[0] != lo || o[1] != hi || o[2] != prefix || o[3] != value_of(37) || o[4] != total;
native_wrong += o[5] != lo || o[6] != hi || o[7] != prefix;
prefix += value_of(lane);
}
observed("wave64 shared route: %u of 64 lanes wrong", shared_wrong);
observed("wave64 native route: %u of 64 lanes wrong (ballot 0x%08x%08x, expected 0x%08x%08x)", native_wrong, out[6],
out[5], hi, lo);
if (shared_wrong == 0 && native_wrong == 0) {
result("wave64", "workaround", "64-lane ballot, prefix sum, read lane and sum correct through groupshared memory and through merged host waves");
} else if (shared_wrong == 0) {
result("wave64", "workaround", "groupshared route correct; merged host waves wrong");
} else {
result("wave64", "blocked", "no route gave the 64-lane answers");
}
}
/* ---- 4. mesh ---- */
struct alignas(void*) StreamRootSig { D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE; ID3D12RootSignature* rs; };
struct alignas(void*) StreamShader { D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; D3D12_SHADER_BYTECODE code; };
struct alignas(void*) StreamRtFormats { D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS; D3D12_RT_FORMAT_ARRAY formats; };
struct alignas(void*) StreamRasterizer { D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER; D3D12_RASTERIZER_DESC desc; };
struct MeshStream {
StreamRootSig rs;
StreamShader as{D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS, {}};
StreamShader ms{D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS, {}};
StreamShader ps{D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, {}};
StreamRtFormats rt;
StreamRasterizer raster;
};
void check_mesh(Gpu& g) {
D3D12_FEATURE_DATA_D3D12_OPTIONS7 o7 = {};
const HRESULT qhr = g.dev->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &o7, sizeof(o7));
observed("mesh.reported query hr=0x%08lx MeshShaderTier=%d", ul(qhr), SUCCEEDED(qhr) ? static_cast<int>(o7.MeshShaderTier) : -1);
ID3D12Device2* dev2 = nullptr;
ID3D12GraphicsCommandList6* list6 = nullptr;
g.dev->QueryInterface(__uuidof(ID3D12Device2), reinterpret_cast<void**>(&dev2));
g.list->QueryInterface(__uuidof(ID3D12GraphicsCommandList6), reinterpret_cast<void**>(&list6));
observed("mesh.interfaces ID3D12Device2=%d ID3D12GraphicsCommandList6=%d", dev2 ? 1 : 0, list6 ? 1 : 0);
ID3D12RootSignature* rs = make_root(g, "mesh", nullptr, 0);
ID3D12PipelineState* pso = nullptr;
HRESULT hr = E_NOINTERFACE;
if (dev2 && rs) {
MeshStream s;
s.rs.rs = rs;
s.as.code = {g_mesh_as, sizeof(g_mesh_as)};
s.ms.code = {g_mesh_ms, sizeof(g_mesh_ms)};
s.ps.code = {g_mesh_ps, sizeof(g_mesh_ps)};
s.rt.formats.NumRenderTargets = 1;
s.rt.formats.RTFormats[0] = DXGI_FORMAT_R32_UINT;
s.raster.desc.FillMode = D3D12_FILL_MODE_SOLID;
s.raster.desc.CullMode = D3D12_CULL_MODE_NONE;
s.raster.desc.DepthClipEnable = TRUE;
D3D12_PIPELINE_STATE_STREAM_DESC sd = {sizeof(s), &s};
hr = dev2->CreatePipelineState(&sd, __uuidof(ID3D12PipelineState), reinterpret_cast<void**>(&pso));
}
observed("mesh.pipeline CreatePipelineState hr=0x%08lx", ul(hr));
if (!pso || !list6) {
result("mesh", "blocked",
SUCCEEDED(qhr) && o7.MeshShaderTier == D3D12_MESH_SHADER_TIER_NOT_SUPPORTED
? "mesh shader tier not supported and the amplification+mesh pipeline is refused"
: "the amplification+mesh pipeline is refused");
release(pso);
release(rs);
release(list6);
release(dev2);
return;
}
/* 4x4 R32_UINT target; group 0 covers the lower-left half, group 1 the upper-right. */
D3D12_HEAP_PROPERTIES hp = {};
hp.Type = D3D12_HEAP_TYPE_DEFAULT;
D3D12_RESOURCE_DESC rd = {};
rd.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
rd.Width = 4;
rd.Height = 4;
rd.DepthOrArraySize = 1;
rd.MipLevels = 1;
rd.Format = DXGI_FORMAT_R32_UINT;
rd.SampleDesc.Count = 1;
rd.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
D3D12_CLEAR_VALUE cv = {};
cv.Format = DXGI_FORMAT_R32_UINT;
ID3D12Resource* target = nullptr;
g.dev->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &rd, D3D12_RESOURCE_STATE_RENDER_TARGET, &cv,
__uuidof(ID3D12Resource), reinterpret_cast<void**>(&target));
ID3D12DescriptorHeap* rtv = nullptr;
D3D12_DESCRIPTOR_HEAP_DESC hd = {};
hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
hd.NumDescriptors = 1;
g.dev->CreateDescriptorHeap(&hd, __uuidof(ID3D12DescriptorHeap), reinterpret_cast<void**>(&rtv));
TexCopy tc;
ID3D12Resource* rb = nullptr;
if (target) {
tc = footprint(g, target);
rb = make_buffer(g, D3D12_HEAP_TYPE_READBACK, tc.total, D3D12_RESOURCE_STATE_COPY_DEST);
}
bool ok = target && rtv && rb;
if (ok) {
D3D12_CPU_DESCRIPTOR_HANDLE h;
rtv->GetCPUDescriptorHandleForHeapStart(&h);
g.dev->CreateRenderTargetView(target, nullptr, h);
const float clear[4] = {0, 0, 0, 0};
g.list->ClearRenderTargetView(h, clear, 0, nullptr);
g.list->OMSetRenderTargets(1, &h, FALSE, nullptr);
D3D12_VIEWPORT vp = {0, 0, 4, 4, 0, 1};
D3D12_RECT sc = {0, 0, 4, 4};
g.list->RSSetViewports(1, &vp);
g.list->RSSetScissorRects(1, &sc);
g.list->SetGraphicsRootSignature(rs);
g.list->SetPipelineState(pso);
list6->DispatchMesh(1, 1, 1);
transition(g, target, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
D3D12_TEXTURE_COPY_LOCATION dst = {};
dst.pResource = rb;
dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
dst.PlacedFootprint = tc.fp;
D3D12_TEXTURE_COPY_LOCATION src = {};
src.pResource = target;
src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
g.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
ok = submit(g, "mesh");
} else {
observed("mesh render target setup failed");
abandon(g);
}
std::vector<uint8_t> data(tc.total, 0);
if (ok) ok = map_read(rb, data.data(), data.size());
if (!ok) {
require(false, "mesh: setup and GPU work must complete");
} else {
/* Pixel centre (x+0.5, y+0.5) in a 4x4 viewport; NDC y points up, so row y has
* ndc_y = 1 - (y+0.5)/2. Group 0's triangle is x_ndc + y_ndc < 0 (payload 0x40),
* group 1's is x_ndc + y_ndc > 0 (0x41); no pixel centre lies on the diagonal. */
UINT wrong = 0, blank = 0;
for (UINT y = 0; y < 4; ++y) {
for (UINT x = 0; x < 4; ++x) {
uint32_t v = 0;
std::memcpy(&v, &data[tc.fp.Offset + y * tc.fp.Footprint.RowPitch + x * 4], 4);
const double nx = (x + 0.5) / 2.0 - 1.0, ny = 1.0 - (y + 0.5) / 2.0;
const uint32_t want = nx + ny < 0 ? 0x40u : 0x41u;
blank += v == 0;
wrong += v != want;
}
}
observed("mesh pixels: %u of 16 wrong, %u left at the clear value", wrong, blank);
result("mesh", wrong == 0 ? "runs-correctly" : "blocked",
wrong == 0 ? "amplification payload and two mesh groups drawn as expected"
: "the amplification+mesh pipeline did not draw the expected pixels");
}
drop(g, target);
drop(g, rb);
drop(g, rtv);
release(pso);
release(rs);
release(list6);
release(dev2);
}
} // namespace
int main() {
std::setvbuf(stdout, nullptr, _IONBF, 0);
HMODULE d3d12 = LoadLibraryA("d3d12.dll");
auto create = d3d12 ? reinterpret_cast<PFN_CreateDevice>(reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12CreateDevice"))) : nullptr;
Gpu g;
g.serialize = d3d12 ? reinterpret_cast<PFN_Serialize>(
reinterpret_cast<void*>(GetProcAddress(d3d12, "D3D12SerializeRootSignature"))) : nullptr;
if (!create || !g.serialize) {
std::printf("SKIP: d3d12.dll or its exports are unavailable\n");
return 77;
}
HRESULT hr = create(nullptr, D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), reinterpret_cast<void**>(&g.dev));
if (FAILED(hr) || !g.dev) {
std::printf("SKIP: D3D12CreateDevice failed hr=0x%08lx\n", ul(hr));
return 77;
}
D3D12_FEATURE_DATA_SHADER_MODEL sm = {D3D_SHADER_MODEL_6_6};
if (FAILED(g.dev->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &sm, sizeof(sm))) ||
sm.HighestShaderModel < D3D_SHADER_MODEL_6_6) {
std::printf("SKIP: shader model 6.6 is not available\n");
release(g.dev);
return 77;
}
observed("device.shader_model 0x%x", static_cast<unsigned>(sm.HighestShaderModel));
D3D12_COMMAND_QUEUE_DESC qd = {};
qd.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
bool setup = SUCCEEDED(g.dev->CreateCommandQueue(&qd, __uuidof(ID3D12CommandQueue),
reinterpret_cast<void**>(&g.queue))) &&
SUCCEEDED(g.dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
__uuidof(ID3D12CommandAllocator),
reinterpret_cast<void**>(&g.alloc))) &&
SUCCEEDED(g.dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g.alloc, nullptr,
__uuidof(ID3D12GraphicsCommandList),
reinterpret_cast<void**>(&g.list))) &&
SUCCEEDED(g.dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence),
reinterpret_cast<void**>(&g.fence)));
g.event = CreateEventA(nullptr, FALSE, FALSE, nullptr);
if (!require(setup && g.event, "queue, allocator, command list and fence creation")) return 1;
check_heap_index(g);
check_wave64(g);
std::printf("RESULT: atomic64 see-test_d3dmetal_gpu_limits (typed 64-bit atomics and their lock emulation are measured there)\n");
check_mesh(g);
if (g.lost) require(false, "GPU work must finish and the device must stay alive");
std::printf("SUMMARY: %d required checks, %d failed\n", g_required, g_failures);
if (g.lost) return 1;
release(g.fence);
release(g.list);
release(g.alloc);
release(g.queue);
release(g.dev);
if (g.event) CloseHandle(g.event);
return g_failures == 0 ? 0 : 1;
}
@@ -0,0 +1,27 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Regenerates the committed *.h shader headers for test_d3dmetal_translator_caps (#671).
# Needs Microsoft's official DXC release v1.9.2609 (dxc_2026_09_29.zip, SHA-256
# ad31b1fc8443175d204f77a611fdb3ef2ec42759bdc2f1167368de24a4a7e7f1); it has no
# macOS build, so bin/x64/dxc.exe runs under a Wine/CrossOver loader.
#
# WINE=/path/to/wine DXC=/path/to/dxc/bin/x64/dxc.exe ./compile.sh
set -eu
: "${WINE:?set WINE to a Wine or CrossOver wine loader}"
: "${DXC:?set DXC to dxc.exe from the DXC v1.9.2609 release}"
cd "$(dirname "$0")"
dxc() { "$WINE" "$DXC" -nologo "$@"; }
dxc -T cs_6_6 -E main -Vn g_heap_index_cs -Fh heap_index.h heap_index.hlsl
dxc -T cs_6_6 -E main -Vn g_wave64_emulation_cs -Fh wave64_emulation.h wave64_emulation.hlsl
dxc -T as_6_6 -E as_main -Vn g_mesh_as -Fh mesh_as.h mesh.hlsl
dxc -T ms_6_6 -E ms_main -Vn g_mesh_ms -Fh mesh_ms.h mesh.hlsl
dxc -T ps_6_6 -E ps_main -Vn g_mesh_ps -Fh mesh_ps.h mesh.hlsl
for pair in heap_index:heap_index wave64_emulation:wave64_emulation mesh_as:mesh mesh_ms:mesh mesh_ps:mesh; do
h=${pair%%:*} src=${pair#*:}
{
printf '// SPDX-License-Identifier: GPL-3.0-or-later\n//\n'
printf '// GENERATED by DXC 1.9.2609 from %s.hlsl by compile.sh; do not edit.\n\n' "$src"
tr -d '\r' < "$h.h"
} > "$h.h.tmp" && mv "$h.h.tmp" "$h.h"
done
@@ -0,0 +1,517 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
// GENERATED by DXC 1.9.2609 from heap_index.hlsl by compile.sh; do not edit.
#if 0
;
; Note: shader requires additional functionality:
; Resource descriptor heap indexing
; Sampler descriptor heap indexing
;
;
; Input signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; no parameters
;
; Output signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; no parameters
; shader hash: b57f79fc70744ea5c2a5f08c555fc7c6
;
; Pipeline Runtime Information:
;
;PSVRuntimeInfo:
; Compute Shader
; NumThreads=(64,1,1)
; MinimumExpectedWaveLaneCount: 0
; MaximumExpectedWaveLaneCount: 4294967295
; UsesViewID: false
; SigInputElements: 0
; SigOutputElements: 0
; SigPatchConstOrPrimElements: 0
; SigInputVectors: 0
; SigOutputVectors[0]: 0
; SigOutputVectors[1]: 0
; SigOutputVectors[2]: 0
; SigOutputVectors[3]: 0
; EntryFunctionName: main
;
;
; Buffer Definitions:
;
; cbuffer idx
; {
;
; struct idx
; {
;
; struct struct.Indices
; {
;
; uint out_uav; ; Offset: 0
; uint raw_srv; ; Offset: 4
; uint typed_srv; ; Offset: 8
; uint tex_srv; ; Offset: 12
;
; } idx; ; Offset: 0
;
;
; } idx; ; Offset: 0 Size: 16
;
; }
;
;
; Resource Bindings:
;
; Name Type Format Dim ID HLSL Bind Count
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
; idx cbuffer NA NA CB0 cb0 1
;
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
target triple = "dxil-ms-dx"
%dx.types.Handle = type { i8* }
%dx.types.ResBind = type { i32, i32, i32, i8 }
%dx.types.ResourceProperties = type { i32, i32 }
%dx.types.CBufRet.i32 = type { i32, i32, i32, i32 }
%dx.types.ResRet.i32 = type { i32, i32, i32, i32, i32 }
%dx.types.ResRet.f32 = type { float, float, float, float, i32 }
%idx = type { %struct.Indices }
%struct.Indices = type { i32, i32, i32, i32 }
define void @main() {
%1 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 0, i8 2 }, i32 0, i1 false) ; CreateHandleFromBinding(bind,index,nonUniformIndex)
%2 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 13, i32 16 }) ; AnnotateHandle(res,props) resource: CBuffer
%3 = call i32 @dx.op.threadId.i32(i32 93, i32 0) ; ThreadId(component)
%4 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %2, i32 0) ; CBufferLoadLegacy(handle,regIndex)
%5 = extractvalue %dx.types.CBufRet.i32 %4, 0
%6 = call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 %5, i1 false, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
%7 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %6, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
%8 = extractvalue %dx.types.CBufRet.i32 %4, 1
%9 = call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 %8, i1 false, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
%10 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %9, %dx.types.ResourceProperties { i32 11, i32 0 }) ; AnnotateHandle(res,props) resource: ByteAddressBuffer
%11 = extractvalue %dx.types.CBufRet.i32 %4, 2
%12 = call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 %11, i1 false, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
%13 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %12, %dx.types.ResourceProperties { i32 10, i32 261 }) ; AnnotateHandle(res,props) resource: TypedBuffer<U32>
%14 = shl i32 %3, 2
%15 = call %dx.types.ResRet.i32 @dx.op.rawBufferLoad.i32(i32 139, %dx.types.Handle %10, i32 %14, i32 undef, i8 1, i32 4) ; RawBufferLoad(srv,index,elementOffset,mask,alignment)
%16 = extractvalue %dx.types.ResRet.i32 %15, 0
%17 = mul i32 %16, 3
%18 = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %13, i32 %3, i32 undef) ; BufferLoad(srv,index,wot)
%19 = extractvalue %dx.types.ResRet.i32 %18, 0
%20 = add i32 %17, %19
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %7, i32 %3, i32 0, i32 %20, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
%21 = icmp eq i32 %3, 0
br i1 %21, label %22, label %32
; <label>:22 ; preds = %0
%23 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %2, i32 0) ; CBufferLoadLegacy(handle,regIndex)
%24 = extractvalue %dx.types.CBufRet.i32 %23, 3
%25 = call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 %24, i1 false, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
%26 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %25, %dx.types.ResourceProperties { i32 2, i32 265 }) ; AnnotateHandle(res,props) resource: Texture2D<F32>
%27 = call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 true, i1 false) ; CreateHandleFromHeap(index,samplerHeap,nonUniformIndex)
%28 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %27, %dx.types.ResourceProperties { i32 14, i32 0 }) ; AnnotateHandle(res,props) resource: SamplerState
%29 = call %dx.types.ResRet.f32 @dx.op.sampleLevel.f32(i32 62, %dx.types.Handle %26, %dx.types.Handle %28, float 7.500000e-01, float 2.500000e-01, float undef, float undef, i32 0, i32 0, i32 undef, float 0.000000e+00) ; SampleLevel(srv,sampler,coord0,coord1,coord2,coord3,offset0,offset1,offset2,LOD)
%30 = extractvalue %dx.types.ResRet.f32 %29, 0
%31 = bitcast float %30 to i32
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %7, i32 64, i32 0, i32 %31, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
br label %32
; <label>:32 ; preds = %22, %0
ret void
}
; Function Attrs: nounwind readnone
declare i32 @dx.op.threadId.i32(i32, i32) #0
; Function Attrs: nounwind readnone
declare %dx.types.Handle @dx.op.createHandleFromHeap(i32, i32, i1, i1) #0
; Function Attrs: nounwind readonly
declare %dx.types.ResRet.i32 @dx.op.rawBufferLoad.i32(i32, %dx.types.Handle, i32, i32, i8, i32) #1
; Function Attrs: nounwind
declare void @dx.op.rawBufferStore.i32(i32, %dx.types.Handle, i32, i32, i32, i32, i32, i32, i8, i32) #2
; Function Attrs: nounwind readonly
declare %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32, %dx.types.Handle, i32, i32) #1
; Function Attrs: nounwind readonly
declare %dx.types.ResRet.f32 @dx.op.sampleLevel.f32(i32, %dx.types.Handle, %dx.types.Handle, float, float, float, float, i32, i32, i32, float) #1
; Function Attrs: nounwind readonly
declare %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32, %dx.types.Handle, i32) #1
; Function Attrs: nounwind readnone
declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #0
; Function Attrs: nounwind readnone
declare %dx.types.Handle @dx.op.createHandleFromBinding(i32, %dx.types.ResBind, i32, i1) #0
attributes #0 = { nounwind readnone }
attributes #1 = { nounwind readonly }
attributes #2 = { nounwind }
!llvm.ident = !{!0}
!dx.version = !{!1}
!dx.valver = !{!2}
!dx.shaderModel = !{!3}
!dx.resources = !{!4}
!dx.entryPoints = !{!7}
!0 = !{!"dxcoob 1.9.2609.5 (01b62ad47)"}
!1 = !{i32 1, i32 6}
!2 = !{i32 1, i32 9}
!3 = !{!"cs", i32 6, i32 6}
!4 = !{null, null, !5, null}
!5 = !{!6}
!6 = !{i32 0, %idx* undef, !"", i32 0, i32 0, i32 1, i32 16, null}
!7 = !{void ()* @main, !"main", null, !4, !8}
!8 = !{i32 0, i64 3221225472, i32 4, !9}
!9 = !{i32 64, i32 1, i32 1}
#endif
const unsigned char g_heap_index_cs[] = {
0x44, 0x58, 0x42, 0x43, 0x6a, 0x10, 0xf2, 0x40, 0x08, 0xc9, 0x05, 0xa5,
0xec, 0x67, 0xcc, 0x3b, 0xf4, 0x14, 0x30, 0xfb, 0x01, 0x00, 0x00, 0x00,
0xc4, 0x0f, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0xdc, 0x00, 0x00, 0x00, 0xe4, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
0x53, 0x46, 0x49, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x00, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4f, 0x53, 0x47, 0x31,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x50, 0x53, 0x56, 0x30, 0x68, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x41, 0x54, 0x00, 0x07, 0x00, 0x00,
0x66, 0x00, 0x05, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4c,
0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xe8, 0x06, 0x00, 0x00,
0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0xb7, 0x01, 0x00, 0x00,
0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
0x80, 0x18, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xc4, 0x10, 0x32, 0x14,
0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x62, 0x88, 0x48, 0x90, 0x14, 0x20,
0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42, 0xe4, 0x48, 0x0e, 0x90,
0x11, 0x23, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c, 0xe1, 0x83, 0xe5, 0x8a,
0x04, 0x31, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x1b, 0x8c, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0x40, 0x02, 0xa8, 0x0d,
0x86, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x03, 0x20, 0x01, 0xd5, 0x06, 0x62,
0xf8, 0xff, 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x49, 0x18, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42, 0x20, 0x4c, 0x08, 0x06,
0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00,
0x32, 0x22, 0x88, 0x09, 0x20, 0x64, 0x85, 0x04, 0x13, 0x23, 0xa4, 0x84,
0x04, 0x13, 0x23, 0xe3, 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8c, 0x8c,
0x0b, 0x84, 0xc4, 0x4c, 0x10, 0x94, 0xc1, 0x08, 0x40, 0x09, 0x00, 0x0a,
0xe6, 0x08, 0xc0, 0xa0, 0x0c, 0xc3, 0x30, 0x10, 0x31, 0x47, 0x80, 0x90,
0x71, 0xcf, 0x70, 0xf9, 0x13, 0xf6, 0x10, 0x92, 0x1f, 0x02, 0xcd, 0xb0,
0x10, 0x28, 0x38, 0xe6, 0x08, 0x82, 0x52, 0x20, 0xc3, 0x90, 0x24, 0xa4,
0xdc, 0x34, 0x5c, 0xfe, 0x84, 0x3d, 0x84, 0xe4, 0xaf, 0x84, 0xb4, 0x12,
0x93, 0x8f, 0xdc, 0x36, 0x2a, 0x86, 0x61, 0x18, 0x86, 0x72, 0x30, 0x03,
0x32, 0x0c, 0xc6, 0x40, 0x4d, 0x59, 0x80, 0x01, 0x19, 0x86, 0x61, 0x18,
0x06, 0x63, 0xa0, 0xa7, 0x14, 0xcc, 0x80, 0x0c, 0x03, 0x45, 0x33, 0x00,
0x37, 0x0d, 0x97, 0x3f, 0x61, 0x0f, 0x21, 0xf9, 0x2b, 0x21, 0xad, 0xc4,
0xe4, 0x17, 0xb7, 0x8d, 0x8a, 0x69, 0x9a, 0xa6, 0xa1, 0x30, 0xd4, 0x80,
0x20, 0xd3, 0x34, 0x4d, 0xc3, 0x30, 0x4c, 0x54, 0x1d, 0x35, 0x5c, 0xfe,
0x84, 0x3d, 0x84, 0xe4, 0x73, 0x1b, 0x55, 0xac, 0xc4, 0xe4, 0x23, 0xb7,
0x8d, 0x88, 0x61, 0x18, 0x86, 0x42, 0x5c, 0x03, 0x32, 0x10, 0x76, 0xdb,
0x70, 0xf9, 0x13, 0xf6, 0x10, 0x92, 0xbf, 0x12, 0x92, 0x43, 0x45, 0x02,
0x91, 0x46, 0xce, 0x43, 0x44, 0x13, 0x42, 0x48, 0x48, 0x18, 0x86, 0x42,
0x20, 0x03, 0xa2, 0xd1, 0x76, 0xd0, 0x70, 0xf9, 0x13, 0xf6, 0x10, 0x92,
0xbf, 0x12, 0xd2, 0x86, 0x34, 0x03, 0x22, 0x86, 0x61, 0x30, 0x4a, 0x81,
0x0c, 0xdd, 0x90, 0x90, 0x37, 0x10, 0x70, 0x8e, 0x34, 0x45, 0x94, 0x30,
0xf9, 0x62, 0x33, 0x20, 0x02, 0x21, 0x21, 0x62, 0x18, 0x86, 0xe1, 0x06,
0x64, 0xb8, 0x50, 0x10, 0x92, 0x38, 0x47, 0x00, 0x0a, 0x00, 0x00, 0x00,
0x13, 0x14, 0x72, 0xc0, 0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79,
0x68, 0x03, 0x72, 0xc0, 0x87, 0x0d, 0xaf, 0x50, 0x0e, 0x6d, 0xd0, 0x0e,
0x7a, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07,
0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0, 0x07, 0x73, 0x20, 0x07,
0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e,
0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe9, 0x30, 0x07,
0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x76, 0x40, 0x07,
0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x10, 0x07, 0x76, 0xa0, 0x07,
0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07,
0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07,
0x72, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x43, 0x9e, 0x00, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x3c, 0x04, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x79, 0x14, 0x20,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xf2, 0x34,
0x40, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xe4,
0x79, 0x80, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0xc8, 0x13, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x90, 0xa7, 0x02, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x21, 0x0f, 0x06, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x43, 0x9e, 0x0d, 0x08, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x86, 0x3c, 0x1e, 0x10, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x81, 0x00, 0x0e, 0x00, 0x00, 0x00,
0x32, 0x1e, 0x98, 0x14, 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47,
0xc6, 0x04, 0x43, 0x1a, 0x4a, 0xa0, 0x18, 0x46, 0x00, 0x0a, 0xa4, 0x0c,
0xca, 0xa1, 0x14, 0x0a, 0xa1, 0x20, 0x0a, 0xa3, 0x00, 0x03, 0xca, 0xa8,
0x08, 0x88, 0x2c, 0x40, 0x40, 0x40, 0x40, 0x0c, 0x12, 0x67, 0x00, 0x68,
0x9c, 0x01, 0xa0, 0x70, 0x06, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x75, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4,
0x8e, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45,
0xc6, 0x06, 0x26, 0xc7, 0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46,
0x26, 0x8c, 0x8c, 0xe6, 0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x06, 0x65,
0x82, 0x30, 0x2c, 0x1b, 0x84, 0x81, 0x98, 0x20, 0x0c, 0xcc, 0x06, 0xc1,
0x30, 0x28, 0x8c, 0xcd, 0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x8c, 0x41,
0xc6, 0x21, 0x8d, 0x0c, 0x6f, 0x82, 0x30, 0x34, 0x1b, 0x10, 0x43, 0x59,
0x0c, 0x63, 0x60, 0x80, 0x0d, 0x41, 0xb3, 0x81, 0x00, 0x00, 0x07, 0x98,
0x20, 0x84, 0x81, 0xc6, 0xe3, 0xad, 0x8e, 0xee, 0xab, 0x2e, 0xcc, 0x6e,
0x82, 0x30, 0x38, 0x13, 0x84, 0xe1, 0x99, 0x20, 0x0c, 0xd0, 0x06, 0x83,
0x88, 0x24, 0x63, 0xa2, 0x78, 0xc8, 0x85, 0xdd, 0x7d, 0xcd, 0xc9, 0xd9,
0x4d, 0x10, 0x86, 0x68, 0x83, 0x41, 0x58, 0xd2, 0x35, 0x51, 0x4c, 0xe8,
0xf2, 0xe0, 0xca, 0xc8, 0xbe, 0xe6, 0xe4, 0xec, 0x26, 0x08, 0x83, 0xb4,
0xc1, 0x20, 0x32, 0x49, 0x9b, 0x28, 0x1e, 0x74, 0x65, 0x78, 0x5f, 0x73,
0x72, 0x76, 0x13, 0x84, 0x61, 0xda, 0x60, 0x10, 0x9c, 0xd4, 0x4d, 0xd4,
0x86, 0x82, 0xa9, 0xb0, 0xcd, 0x9b, 0x20, 0x88, 0x01, 0xb6, 0x81, 0x20,
0x16, 0xc9, 0xd8, 0x20, 0x30, 0x61, 0xb0, 0xa1, 0x30, 0xa0, 0x0f, 0x0c,
0xc4, 0x60, 0x82, 0x20, 0x00, 0x1b, 0x80, 0x0d, 0x83, 0x51, 0x06, 0x65,
0xb0, 0x21, 0x30, 0x83, 0x0d, 0xc3, 0x40, 0x06, 0x67, 0x40, 0xa2, 0x2d,
0x2c, 0xcd, 0x6d, 0x82, 0x40, 0x06, 0xd7, 0x04, 0x61, 0xa0, 0x36, 0x0c,
0x6b, 0x30, 0x0c, 0x1b, 0x08, 0x43, 0x0d, 0x2e, 0x36, 0xd8, 0x50, 0x90,
0x41, 0x1a, 0x00, 0x4f, 0x1b, 0x10, 0x11, 0x93, 0x0b, 0x73, 0x1b, 0x43,
0x2b, 0x9b, 0x63, 0x91, 0xe6, 0x36, 0x47, 0x37, 0x37, 0x41, 0x18, 0x2a,
0x12, 0x69, 0x6e, 0x74, 0x73, 0x44, 0xe8, 0xca, 0xf0, 0xbe, 0xd8, 0xde,
0xc2, 0xc8, 0x26, 0x08, 0x83, 0x45, 0x84, 0xae, 0x0c, 0xef, 0xcb, 0xed,
0x4d, 0xae, 0x8d, 0x09, 0x5d, 0x19, 0xde, 0xd7, 0x1c, 0xdd, 0x9b, 0x5c,
0x19, 0x8b, 0xba, 0x34, 0x37, 0xba, 0xb9, 0x0d, 0xce, 0x1b, 0x0c, 0x70,
0x10, 0x07, 0x72, 0x20, 0xcd, 0x01, 0x1d, 0xd4, 0xc1, 0x60, 0x07, 0x74,
0x70, 0x07, 0x43, 0x15, 0x36, 0x36, 0xbb, 0x36, 0x97, 0x34, 0xb2, 0x32,
0x37, 0xba, 0x29, 0x41, 0x50, 0x85, 0x0c, 0xcf, 0xc5, 0xae, 0x4c, 0x6e,
0x2e, 0xed, 0xcd, 0x6d, 0x4a, 0x40, 0x34, 0x21, 0xc3, 0x73, 0xb1, 0x0b,
0x63, 0xb3, 0x2b, 0x93, 0x9b, 0x12, 0x18, 0x75, 0xc8, 0xf0, 0x5c, 0xe6,
0xd0, 0xc2, 0xc8, 0xca, 0xe4, 0x9a, 0xde, 0xc8, 0xca, 0xd8, 0xa6, 0x04,
0x48, 0x19, 0x32, 0x3c, 0x17, 0xb9, 0xb2, 0xb9, 0xb7, 0x3a, 0xb9, 0xb1,
0xb2, 0xb9, 0x29, 0x81, 0x53, 0x89, 0x0c, 0xcf, 0x85, 0x2e, 0x0f, 0xae,
0x2c, 0xc8, 0xcd, 0xed, 0x8d, 0x2e, 0x8c, 0x2e, 0xed, 0xcd, 0x6d, 0x6e,
0x8a, 0x20, 0x06, 0x67, 0x50, 0x87, 0x0c, 0xcf, 0xa5, 0xcc, 0x8d, 0x4e,
0x2e, 0x0f, 0xea, 0x2d, 0xcd, 0x8d, 0x6e, 0x6e, 0x4a, 0xd0, 0x06, 0x5d,
0xc8, 0xf0, 0x5c, 0xc6, 0xde, 0xea, 0xdc, 0xe8, 0xca, 0xe4, 0xe6, 0xa6,
0x04, 0x77, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00,
0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88,
0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73,
0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e,
0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30,
0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8,
0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b,
0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76,
0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e,
0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e,
0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61,
0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4,
0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76,
0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37,
0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76,
0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71,
0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e,
0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1,
0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61,
0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90,
0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8,
0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc,
0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc4,
0x21, 0x07, 0x7c, 0x70, 0x03, 0x7a, 0x28, 0x87, 0x76, 0x80, 0x87, 0x19,
0xd1, 0x43, 0x0e, 0xf8, 0xe0, 0x06, 0xe4, 0x20, 0x0e, 0xe7, 0xe0, 0x06,
0xf6, 0x10, 0x0e, 0xf2, 0xc0, 0x0e, 0xe1, 0x90, 0x0f, 0xef, 0x50, 0x0f,
0xf4, 0x30, 0x83, 0x81, 0xc8, 0x01, 0x1f, 0xdc, 0x40, 0x1c, 0xe4, 0xa1,
0x1c, 0xc2, 0x61, 0x1d, 0xdc, 0x40, 0x1c, 0xe4, 0x01, 0x00, 0x00, 0x00,
0x71, 0x20, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x86, 0x40, 0x0d, 0x97,
0xef, 0x3c, 0x3e, 0xd0, 0x34, 0xce, 0x04, 0x4c, 0x44, 0x08, 0x34, 0xc3,
0x42, 0x58, 0x01, 0x35, 0x5c, 0xbe, 0xf3, 0xf8, 0x01, 0x55, 0x14, 0x44,
0x54, 0x3a, 0xc0, 0xe0, 0x23, 0xb7, 0x6d, 0x07, 0xdb, 0x70, 0xf9, 0xce,
0xe3, 0x0b, 0x01, 0x55, 0x14, 0x44, 0x54, 0x3a, 0xc0, 0x50, 0x12, 0x06,
0x20, 0x60, 0x3e, 0x72, 0xdb, 0x96, 0xd0, 0x0d, 0x97, 0xef, 0x3c, 0xbe,
0x10, 0x11, 0xc0, 0x44, 0x84, 0x40, 0x33, 0x2c, 0xc4, 0x17, 0x39, 0xcc,
0x86, 0x34, 0x03, 0xd2, 0x18, 0x26, 0xa0, 0x0d, 0x97, 0xef, 0x3c, 0xbe,
0x10, 0x11, 0xc0, 0x44, 0x84, 0x40, 0x33, 0x2c, 0xc4, 0x17, 0x39, 0x4c,
0x48, 0x00, 0x8f, 0x0d, 0x5c, 0xc3, 0xe5, 0x3b, 0x8f, 0x1f, 0x01, 0xd6,
0x46, 0x15, 0x05, 0x11, 0x95, 0x0e, 0x30, 0xf8, 0xc8, 0x6d, 0x1b, 0x01,
0x36, 0x5c, 0xbe, 0xf3, 0xf8, 0x11, 0x60, 0x6d, 0x54, 0x51, 0x10, 0x11,
0x3b, 0x39, 0x11, 0xe1, 0x23, 0xb7, 0x6d, 0x06, 0xd5, 0x70, 0xf9, 0xce,
0xe3, 0x4b, 0x00, 0xf3, 0x2c, 0x44, 0x49, 0x54, 0xc4, 0xe2, 0x17, 0xb7,
0x6d, 0x01, 0xd2, 0x70, 0xf9, 0xce, 0xe3, 0x4f, 0x47, 0x44, 0x00, 0x83,
0x38, 0xf8, 0xc8, 0x6d, 0x1b, 0x00, 0xc1, 0x00, 0x48, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x41, 0x53, 0x48, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xb5, 0x7f, 0x79, 0xfc, 0x70, 0x74, 0x4e, 0xa5,
0xc2, 0xa5, 0xf0, 0x8c, 0x55, 0x5f, 0xc7, 0xc6, 0x44, 0x58, 0x49, 0x4c,
0xbc, 0x07, 0x00, 0x00, 0x66, 0x00, 0x05, 0x00, 0xef, 0x01, 0x00, 0x00,
0x44, 0x58, 0x49, 0x4c, 0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0xa4, 0x07, 0x00, 0x00, 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00,
0xe6, 0x01, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00,
0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49,
0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19,
0x1e, 0x04, 0x8b, 0x62, 0x80, 0x18, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42,
0xc4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x62, 0x88,
0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42,
0xe4, 0x48, 0x0e, 0x90, 0x11, 0x23, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c,
0xe1, 0x83, 0xe5, 0x8a, 0x04, 0x31, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x1b, 0x8c, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07,
0x40, 0x02, 0xa8, 0x0d, 0x86, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x03, 0x20,
0x01, 0xd5, 0x06, 0x62, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x01, 0x90, 0x00,
0x49, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42,
0x20, 0x4c, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00,
0x42, 0x00, 0x00, 0x00, 0x32, 0x22, 0x88, 0x09, 0x20, 0x64, 0x85, 0x04,
0x13, 0x23, 0xa4, 0x84, 0x04, 0x13, 0x23, 0xe3, 0x84, 0xa1, 0x90, 0x14,
0x12, 0x4c, 0x8c, 0x8c, 0x0b, 0x84, 0xc4, 0x4c, 0x10, 0x98, 0xc1, 0x08,
0x40, 0x09, 0x00, 0x0a, 0xe6, 0x08, 0xc0, 0xa0, 0x0c, 0xc3, 0x30, 0x10,
0x31, 0x47, 0x80, 0x90, 0x71, 0xcf, 0x70, 0xf9, 0x13, 0xf6, 0x10, 0x92,
0x1f, 0x02, 0xcd, 0xb0, 0x10, 0x28, 0x38, 0xe6, 0x08, 0x82, 0x52, 0x20,
0xc3, 0x90, 0x24, 0xa4, 0xdc, 0x34, 0x5c, 0xfe, 0x84, 0x3d, 0x84, 0xe4,
0xaf, 0x84, 0xb4, 0x12, 0x93, 0x8f, 0xdc, 0x36, 0x2a, 0x86, 0x61, 0x18,
0x86, 0x72, 0x30, 0x03, 0x32, 0x0c, 0xc6, 0x40, 0x4d, 0x59, 0x80, 0x01,
0x19, 0x86, 0x61, 0x18, 0x06, 0x63, 0xa0, 0xa7, 0x14, 0xcc, 0x80, 0x0c,
0x03, 0x45, 0x33, 0x00, 0x37, 0x0d, 0x97, 0x3f, 0x61, 0x0f, 0x21, 0xf9,
0x2b, 0x21, 0xad, 0xc4, 0xe4, 0x17, 0xb7, 0x8d, 0x8a, 0x69, 0x9a, 0xa6,
0xa1, 0x30, 0xd4, 0x80, 0x20, 0xd3, 0x34, 0x4d, 0xc3, 0x30, 0x4c, 0x54,
0x1d, 0x35, 0x5c, 0xfe, 0x84, 0x3d, 0x84, 0xe4, 0x73, 0x1b, 0x55, 0xac,
0xc4, 0xe4, 0x23, 0xb7, 0x8d, 0x88, 0x61, 0x18, 0x86, 0x42, 0x5c, 0x03,
0x32, 0x10, 0x76, 0xdb, 0x70, 0xf9, 0x13, 0xf6, 0x10, 0x92, 0xbf, 0x12,
0x92, 0x43, 0x45, 0x02, 0x91, 0x46, 0xce, 0x43, 0x44, 0x13, 0x42, 0x48,
0x48, 0x18, 0x86, 0x42, 0x20, 0x03, 0xa2, 0xd1, 0x76, 0xd0, 0x70, 0xf9,
0x13, 0xf6, 0x10, 0x92, 0xbf, 0x12, 0xd2, 0x86, 0x34, 0x03, 0x22, 0x86,
0x61, 0x30, 0x4a, 0x81, 0x0c, 0xdd, 0x90, 0x90, 0x37, 0x10, 0x70, 0x8e,
0x34, 0x45, 0x94, 0x30, 0xf9, 0x62, 0x33, 0x20, 0x02, 0x21, 0x21, 0x62,
0x18, 0x86, 0xe1, 0x06, 0x64, 0xb8, 0x50, 0x10, 0x92, 0x38, 0x47, 0x00,
0x0a, 0x53, 0x00, 0x00, 0x13, 0x14, 0x72, 0xc0, 0x87, 0x74, 0x60, 0x87,
0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xc0, 0x87, 0x0d, 0xaf, 0x50,
0x0e, 0x6d, 0xd0, 0x0e, 0x7a, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x30,
0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0,
0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x73, 0x20,
0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90,
0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x10,
0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
0x07, 0x76, 0x40, 0x07, 0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x43, 0x9e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86,
0x3c, 0x04, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x79, 0x14, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0xf2, 0x34, 0x40, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0xe4, 0x79, 0x80, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x60, 0xc8, 0x13, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x90, 0xa7, 0x02, 0x02, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21, 0x0f, 0x06, 0x04, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x9e, 0x0d, 0x08, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x3c, 0x1e, 0x10,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x81, 0x00,
0x0a, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x14, 0x19, 0x11, 0x4c, 0x90,
0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x1a, 0x4a, 0xa0, 0x18, 0x4a,
0x62, 0x04, 0xa0, 0x40, 0x0a, 0xa1, 0x00, 0x03, 0x88, 0x2c, 0x40, 0x40,
0x40, 0x40, 0x0c, 0x1a, 0x67, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x37, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4,
0x8e, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45,
0xc6, 0x06, 0x26, 0xc7, 0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46,
0x26, 0x8c, 0x8c, 0xe6, 0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x06, 0x65,
0x82, 0x30, 0x2c, 0x1b, 0x84, 0x81, 0x98, 0x20, 0x0c, 0xcc, 0x06, 0x61,
0x30, 0x28, 0x8c, 0xcd, 0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x0c, 0xcd,
0x04, 0x61, 0x0c, 0x24, 0x02, 0x13, 0x84, 0xc1, 0xd9, 0x80, 0x28, 0x0b,
0xa3, 0x28, 0x43, 0x03, 0x6c, 0x08, 0x9c, 0x0d, 0x04, 0x00, 0x3c, 0xc0,
0x04, 0x41, 0x00, 0x48, 0xb4, 0x85, 0xa5, 0xb9, 0x4d, 0x10, 0xc8, 0x20,
0x9a, 0x20, 0x0c, 0xcf, 0x04, 0x61, 0x80, 0x36, 0x0c, 0xd5, 0x30, 0x6c,
0x20, 0x94, 0x89, 0xb2, 0x36, 0x14, 0x91, 0x04, 0x40, 0x57, 0x15, 0x36,
0x36, 0xbb, 0x36, 0x97, 0x34, 0xb2, 0x32, 0x37, 0xba, 0x29, 0x41, 0x50,
0x85, 0x0c, 0xcf, 0xc5, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x6d, 0x4a,
0x40, 0x34, 0x21, 0xc3, 0x73, 0xb1, 0x0b, 0x63, 0xb3, 0x2b, 0x93, 0x9b,
0x12, 0x18, 0x75, 0xc8, 0xf0, 0x5c, 0xe6, 0xd0, 0xc2, 0xc8, 0xca, 0xe4,
0x9a, 0xde, 0xc8, 0xca, 0xd8, 0xa6, 0x04, 0x48, 0x19, 0x32, 0x3c, 0x17,
0xb9, 0xb2, 0xb9, 0xb7, 0x3a, 0xb9, 0xb1, 0xb2, 0xb9, 0x29, 0xc1, 0x53,
0x87, 0x0c, 0xcf, 0xa5, 0xcc, 0x8d, 0x4e, 0x2e, 0x0f, 0xea, 0x2d, 0xcd,
0x8d, 0x6e, 0x6e, 0x4a, 0x70, 0x01, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x51, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
0xb0, 0xc3, 0x0c, 0xc4, 0x21, 0x07, 0x7c, 0x70, 0x03, 0x7a, 0x28, 0x87,
0x76, 0x80, 0x87, 0x19, 0xd1, 0x43, 0x0e, 0xf8, 0xe0, 0x06, 0xe4, 0x20,
0x0e, 0xe7, 0xe0, 0x06, 0xf6, 0x10, 0x0e, 0xf2, 0xc0, 0x0e, 0xe1, 0x90,
0x0f, 0xef, 0x50, 0x0f, 0xf4, 0x30, 0x83, 0x81, 0xc8, 0x01, 0x1f, 0xdc,
0x40, 0x1c, 0xe4, 0xa1, 0x1c, 0xc2, 0x61, 0x1d, 0xdc, 0x40, 0x1c, 0xe4,
0x01, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00,
0x86, 0x40, 0x0d, 0x97, 0xef, 0x3c, 0x3e, 0xd0, 0x34, 0xce, 0x04, 0x4c,
0x44, 0x08, 0x34, 0xc3, 0x42, 0x58, 0x01, 0x35, 0x5c, 0xbe, 0xf3, 0xf8,
0x01, 0x55, 0x14, 0x44, 0x54, 0x3a, 0xc0, 0xe0, 0x23, 0xb7, 0x6d, 0x07,
0xdb, 0x70, 0xf9, 0xce, 0xe3, 0x0b, 0x01, 0x55, 0x14, 0x44, 0x54, 0x3a,
0xc0, 0x50, 0x12, 0x06, 0x20, 0x60, 0x3e, 0x72, 0xdb, 0x96, 0xd0, 0x0d,
0x97, 0xef, 0x3c, 0xbe, 0x10, 0x11, 0xc0, 0x44, 0x84, 0x40, 0x33, 0x2c,
0xc4, 0x17, 0x39, 0xcc, 0x86, 0x34, 0x03, 0xd2, 0x18, 0x26, 0xa0, 0x0d,
0x97, 0xef, 0x3c, 0xbe, 0x10, 0x11, 0xc0, 0x44, 0x84, 0x40, 0x33, 0x2c,
0xc4, 0x17, 0x39, 0x4c, 0x48, 0x00, 0x8f, 0x0d, 0x5c, 0xc3, 0xe5, 0x3b,
0x8f, 0x1f, 0x01, 0xd6, 0x46, 0x15, 0x05, 0x11, 0x95, 0x0e, 0x30, 0xf8,
0xc8, 0x6d, 0x1b, 0x01, 0x36, 0x5c, 0xbe, 0xf3, 0xf8, 0x11, 0x60, 0x6d,
0x54, 0x51, 0x10, 0x11, 0x3b, 0x39, 0x11, 0xe1, 0x23, 0xb7, 0x6d, 0x06,
0xd5, 0x70, 0xf9, 0xce, 0xe3, 0x4b, 0x00, 0xf3, 0x2c, 0x44, 0x49, 0x54,
0xc4, 0xe2, 0x17, 0xb7, 0x6d, 0x01, 0xd2, 0x70, 0xf9, 0xce, 0xe3, 0x4f,
0x47, 0x44, 0x00, 0x83, 0x38, 0xf8, 0xc8, 0x6d, 0x1b, 0x00, 0xc1, 0x00,
0x48, 0x03, 0x00, 0x00, 0x61, 0x20, 0x00, 0x00, 0x6f, 0x00, 0x00, 0x00,
0x13, 0x04, 0x43, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00,
0x34, 0xcc, 0x00, 0x14, 0xec, 0x40, 0xd1, 0x0e, 0x94, 0x5d, 0x11, 0x14,
0xa6, 0x40, 0xc9, 0x0e, 0x94, 0x46, 0xe9, 0x06, 0x14, 0x26, 0x50, 0x59,
0x14, 0x45, 0x29, 0x12, 0x94, 0xa5, 0x40, 0x19, 0x14, 0x62, 0x40, 0x49,
0x12, 0x14, 0x47, 0xf1, 0x91, 0x51, 0x02, 0x45, 0x40, 0xc9, 0x08, 0x40,
0x0d, 0xd0, 0x34, 0x03, 0x30, 0x46, 0x00, 0x82, 0x20, 0x48, 0x7f, 0x63,
0x04, 0x20, 0x08, 0x82, 0xe8, 0x37, 0x02, 0x40, 0xda, 0x1c, 0x82, 0xe6,
0xcc, 0x21, 0x70, 0xcf, 0x1c, 0x42, 0xd7, 0xcc, 0x21, 0x78, 0xdf, 0x1c,
0xc2, 0x35, 0x06, 0x73, 0x08, 0x64, 0xd0, 0x50, 0x37, 0x07, 0xd1, 0x34,
0xcd, 0x19, 0x00, 0x00, 0x23, 0x06, 0x08, 0x00, 0x82, 0x60, 0xe0, 0xb1,
0x01, 0x17, 0xa0, 0x41, 0x33, 0x62, 0x70, 0x00, 0x20, 0x08, 0x06, 0x9b,
0x1b, 0x88, 0x41, 0x80, 0x8c, 0x18, 0x18, 0x00, 0x08, 0x82, 0x01, 0x61,
0x07, 0x9c, 0x1a, 0x8c, 0x18, 0x1c, 0x00, 0x08, 0x82, 0x01, 0x16, 0x07,
0x62, 0x20, 0xac, 0xc1, 0x68, 0x42, 0x00, 0x8c, 0x18, 0x20, 0x00, 0x08,
0x82, 0x81, 0x82, 0x07, 0x65, 0x10, 0x48, 0xd2, 0x88, 0xc1, 0x01, 0x80,
0x20, 0x18, 0x6c, 0x73, 0x70, 0x06, 0x01, 0x33, 0x9a, 0x40, 0x04, 0x23,
0x06, 0x08, 0x00, 0x82, 0x60, 0xa0, 0xec, 0x01, 0x1a, 0x04, 0x55, 0x35,
0x62, 0x70, 0x00, 0x20, 0x08, 0x06, 0x9b, 0x1d, 0xa8, 0x41, 0xe0, 0x8c,
0x26, 0x1c, 0xc2, 0x88, 0x01, 0x02, 0x80, 0x20, 0x18, 0x28, 0x7e, 0xb0,
0x06, 0x01, 0x86, 0x8d, 0x18, 0x1c, 0x00, 0x08, 0x82, 0xc1, 0x96, 0x07,
0x6d, 0x10, 0x40, 0xb5, 0xac, 0xc1, 0x8d, 0x18, 0x28, 0x00, 0x08, 0x82,
0x41, 0x03, 0x0a, 0x63, 0x50, 0x04, 0x70, 0xd0, 0xd1, 0xc1, 0x68, 0x42,
0x00, 0x54, 0x40, 0x06, 0x32, 0x62, 0x80, 0x00, 0x20, 0x08, 0x06, 0x51,
0x28, 0x90, 0x41, 0xf1, 0xcc, 0xc1, 0x68, 0x42, 0x00, 0xd4, 0x10, 0xc0,
0x88, 0x81, 0x03, 0x80, 0x20, 0x18, 0x3c, 0xa5, 0x10, 0x07, 0x8e, 0xc4,
0x07, 0x81, 0x1d, 0xd8, 0x81, 0x1d, 0x8c, 0x81, 0x1e, 0x0c, 0x37, 0x48,
0x7c, 0x00, 0x06, 0xb3, 0x0c, 0x81, 0x10, 0x8c, 0x18, 0x1c, 0x00, 0x08,
0x82, 0x01, 0x36, 0x0a, 0x74, 0x40, 0xf5, 0xc1, 0x68, 0x42, 0x30, 0x8c,
0x18, 0x20, 0x00, 0x08, 0x82, 0x81, 0xa2, 0x0a, 0x77, 0x10, 0x90, 0x01,
0x19, 0x8c, 0x18, 0x1c, 0x00, 0x08, 0x82, 0xc1, 0x56, 0x0a, 0x79, 0x10,
0x6c, 0x23, 0x06, 0x08, 0x00, 0x82, 0x60, 0xa0, 0xb0, 0x42, 0x1e, 0x84,
0x42, 0x19, 0x98, 0xc1, 0x88, 0xc1, 0x01, 0x80, 0x20, 0x18, 0x6c, 0xa7,
0xb0, 0x07, 0x01, 0x37, 0x62, 0xf0, 0x00, 0x20, 0x08, 0x06, 0x95, 0x2a,
0xac, 0xc1, 0x10, 0x94, 0x01, 0x19, 0x98, 0x81, 0x19, 0x8c, 0xc2, 0x28,
0xf4, 0xc1, 0x18, 0x8c, 0x26, 0x04, 0xc0, 0x05, 0xc3, 0x8e, 0x18, 0x38,
0x00, 0x08, 0x82, 0xc1, 0xf3, 0x0a, 0x7b, 0x80, 0x8d, 0x82, 0x29, 0x04,
0xa0, 0x00, 0x0a, 0xa0, 0xd0, 0x06, 0xa4, 0x30, 0x4b, 0x20, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00
};
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// #671 check 1: SM 6.6 dynamic resources. Every resource and the sampler come from the
// descriptor heaps by index (ResourceDescriptorHeap / SamplerDescriptorHeap), the binding
// model a translator of console code that reads descriptors from memory relies on.
struct Indices { uint out_uav; uint raw_srv; uint typed_srv; uint tex_srv; };
ConstantBuffer<Indices> idx : register(b0);
[numthreads(64, 1, 1)]
void main(uint3 id : SV_DispatchThreadID)
{
RWStructuredBuffer<uint> outb = ResourceDescriptorHeap[idx.out_uav];
ByteAddressBuffer raw = ResourceDescriptorHeap[idx.raw_srv];
Buffer<uint> typed = ResourceDescriptorHeap[idx.typed_srv];
outb[id.x] = raw.Load(4 * id.x) * 3u + typed[id.x];
if (id.x == 0) {
Texture2D<float> tex = ResourceDescriptorHeap[idx.tex_srv];
SamplerState point_clamp = SamplerDescriptorHeap[0];
// Texel (1,0) of a 2x2 texture, sampled at its centre with point filtering.
outb[64] = asuint(tex.SampleLevel(point_clamp, float2(0.75, 0.25), 0));
}
}
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// #671 check 4: amplification -> mesh -> pixel. The amplification shader launches two mesh
// groups and passes a colour in its payload; each mesh group emits one triangle covering half
// of a 4x4 render target. The pixel shader writes the payload colour plus the group index.
struct Payload { uint colour; };
groupshared Payload g_payload;
[numthreads(1, 1, 1)]
void as_main()
{
g_payload.colour = 0x40u;
DispatchMesh(2, 1, 1, g_payload);
}
struct VOut { float4 pos : SV_Position; nointerpolation uint colour : COLOR0; };
[outputtopology("triangle")]
[numthreads(3, 1, 1)]
void ms_main(uint gtid : SV_GroupThreadID, uint gid : SV_GroupID, in payload Payload pl,
out vertices VOut verts[3], out indices uint3 tris[1])
{
SetMeshOutputCounts(3, 1);
// Group 0: the lower-left half of the viewport (x + y < 0 in NDC), group 1 the upper-right
// half (x + y > 0). They meet on the diagonal, which no pixel centre of a 4x4 target lies on.
const float2 a = gid == 0 ? float2(-1, -1) : float2(1, 1);
const float2 c0 = gid == 0 ? float2(-1, 1) : float2(1, -1);
const float2 c1 = gid == 0 ? float2(1, -1) : float2(-1, 1);
const float2 pos = gtid == 0 ? a : (gtid == 1 ? c0 : c1);
verts[gtid].pos = float4(pos, 0, 1);
verts[gtid].colour = pl.colour + gid;
if (gtid == 0) tris[0] = uint3(0, 1, 2);
}
uint ps_main(VOut v) : SV_Target { return v.colour; }
@@ -0,0 +1,296 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
// GENERATED by DXC 1.9.2609 from mesh.hlsl by compile.sh; do not edit.
#if 0
;
; Input signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; no parameters
;
; Output signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; no parameters
; shader hash: 09a9460a69151441aae685ce3642c255
;
; Pipeline Runtime Information:
;
;PSVRuntimeInfo:
; Amplification Shader
; NumThreads=(1,1,1)
; MinimumExpectedWaveLaneCount: 0
; MaximumExpectedWaveLaneCount: 4294967295
; UsesViewID: false
; SigInputElements: 0
; SigOutputElements: 0
; SigPatchConstOrPrimElements: 0
; SigInputVectors: 0
; SigOutputVectors[0]: 0
; SigOutputVectors[1]: 0
; SigOutputVectors[2]: 0
; SigOutputVectors[3]: 0
; EntryFunctionName: as_main
;
;
; Buffer Definitions:
;
;
; Resource Bindings:
;
; Name Type Format Dim ID HLSL Bind Count
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
;
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
target triple = "dxil-ms-dx"
%struct.Payload = type { i32 }
@"\01?g_payload@@3UPayload@@A" = external addrspace(3) global %struct.Payload, align 4
define void @as_main() {
store i32 64, i32 addrspace(3)* getelementptr inbounds (%struct.Payload, %struct.Payload addrspace(3)* @"\01?g_payload@@3UPayload@@A", i32 0, i32 0), align 4, !tbaa !8
call void @dx.op.dispatchMesh.struct.Payload(i32 173, i32 2, i32 1, i32 1, %struct.Payload addrspace(3)* nonnull @"\01?g_payload@@3UPayload@@A") ; DispatchMesh(threadGroupCountX,threadGroupCountY,threadGroupCountZ,payload)
ret void
}
; Function Attrs: nounwind
declare void @dx.op.dispatchMesh.struct.Payload(i32, i32, i32, i32, %struct.Payload addrspace(3)*) #0
attributes #0 = { nounwind }
!llvm.ident = !{!0}
!dx.version = !{!1}
!dx.valver = !{!2}
!dx.shaderModel = !{!3}
!dx.entryPoints = !{!4}
!0 = !{!"dxcoob 1.9.2609.5 (01b62ad47)"}
!1 = !{i32 1, i32 6}
!2 = !{i32 1, i32 9}
!3 = !{!"as", i32 6, i32 6}
!4 = !{void ()* @as_main, !"as_main", null, null, !5}
!5 = !{i32 10, !6}
!6 = !{!7, i32 4}
!7 = !{i32 1, i32 1, i32 1}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
#endif
const unsigned char g_mesh_as[] = {
0x44, 0x58, 0x42, 0x43, 0x63, 0x72, 0x0e, 0xf7, 0x08, 0x85, 0x0d, 0x0f,
0x8f, 0xbd, 0x8f, 0xc5, 0x53, 0xce, 0x45, 0xbd, 0x01, 0x00, 0x00, 0x00,
0xc8, 0x09, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0xc4, 0x00, 0x00, 0x00, 0x20, 0x05, 0x00, 0x00, 0x3c, 0x05, 0x00, 0x00,
0x53, 0x46, 0x49, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4f, 0x53, 0x47, 0x31,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x50, 0x53, 0x56, 0x30, 0x50, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x00, 0x61, 0x73, 0x5f, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x41, 0x54, 0x54, 0x04, 0x00, 0x00,
0x66, 0x00, 0x0e, 0x00, 0x15, 0x01, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4c,
0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x3c, 0x04, 0x00, 0x00,
0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0x0c, 0x01, 0x00, 0x00,
0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
0x80, 0x10, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0x84, 0x10, 0x32, 0x14,
0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x42, 0x88, 0x48, 0x90, 0x14, 0x20,
0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42, 0xe4, 0x48, 0x0e, 0x90,
0x11, 0x22, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c, 0xe1, 0x83, 0xe5, 0x8a,
0x04, 0x21, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x1b, 0x88, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0x40, 0x02, 0x00, 0x00,
0x49, 0x18, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x13, 0x82, 0x00, 0x00,
0x89, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x32, 0x22, 0x08, 0x09,
0x20, 0x64, 0x85, 0x04, 0x13, 0x22, 0xa4, 0x84, 0x04, 0x13, 0x22, 0xe3,
0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x88, 0x8c, 0x0b, 0x84, 0x84, 0x4c,
0x10, 0x24, 0x73, 0x04, 0x60, 0x70, 0x8e, 0x34, 0x45, 0x94, 0x30, 0xf9,
0x29, 0x80, 0x2d, 0x0e, 0x30, 0xa0, 0x00, 0x06, 0x11, 0x82, 0x61, 0x04,
0xa0, 0x04, 0x43, 0x54, 0x8c, 0x01, 0x00, 0x10, 0xb2, 0x81, 0x00, 0x00,
0x13, 0x14, 0x72, 0xc0, 0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79,
0x68, 0x03, 0x72, 0xc0, 0x87, 0x0d, 0xaf, 0x50, 0x0e, 0x6d, 0xd0, 0x0e,
0x7a, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07,
0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0, 0x07, 0x73, 0x20, 0x07,
0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e,
0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe9, 0x30, 0x07,
0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x76, 0x40, 0x07,
0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x10, 0x07, 0x76, 0xa0, 0x07,
0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07,
0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07,
0x72, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x3a, 0x0f, 0x24, 0x90, 0x21, 0x23,
0x45, 0x44, 0x00, 0x76, 0x00, 0xf0, 0x90, 0x87, 0x00, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21, 0x8f, 0x01, 0x04, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x20, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x10, 0x19, 0x11, 0x4c, 0x90,
0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x82, 0x12, 0x28, 0x86, 0x11,
0x80, 0x42, 0x28, 0x83, 0x72, 0x28, 0x85, 0xa2, 0xa0, 0x98, 0x01, 0x00,
0x79, 0x18, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x90,
0x46, 0x02, 0x13, 0xc4, 0x8e, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x0c, 0x24,
0xc6, 0x25, 0xc7, 0x45, 0xc6, 0x06, 0x26, 0xc7, 0xa5, 0x06, 0x04, 0x05,
0x26, 0x46, 0xcc, 0x46, 0x26, 0x8c, 0x8c, 0xe6, 0x26, 0x65, 0x43, 0x10,
0x4c, 0x10, 0x80, 0x61, 0x82, 0x00, 0x10, 0x1b, 0x84, 0x81, 0x98, 0x20,
0x00, 0xc5, 0x06, 0xc1, 0x30, 0x28, 0x84, 0xcd, 0x6d, 0x18, 0x10, 0x82,
0x98, 0x20, 0x04, 0xcb, 0x04, 0x01, 0x30, 0x68, 0x8c, 0xbd, 0xb1, 0xbd,
0xd5, 0xc9, 0x4d, 0x10, 0x80, 0x63, 0x82, 0x00, 0x20, 0x13, 0x04, 0x20,
0xd9, 0x60, 0x10, 0x4c, 0x63, 0x38, 0xcf, 0x06, 0x61, 0x81, 0x36, 0x0c,
0x86, 0x12, 0x4d, 0x10, 0x8a, 0x60, 0x03, 0xb0, 0x61, 0x18, 0x28, 0x6a,
0x43, 0x50, 0x6d, 0x18, 0x86, 0xc9, 0xe2, 0x11, 0x36, 0xf7, 0xd5, 0x16,
0x96, 0xe6, 0x36, 0x41, 0x00, 0x94, 0x0d, 0xc3, 0x30, 0x0c, 0x1b, 0x04,
0x6d, 0xd9, 0x20, 0x64, 0xdb, 0x86, 0x62, 0xc2, 0x00, 0x80, 0x63, 0x91,
0xe6, 0x36, 0x47, 0x37, 0xb7, 0x41, 0xf0, 0x9a, 0x2a, 0x6c, 0x6c, 0x76,
0x6d, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x53, 0x82, 0xa0, 0x0a, 0x19,
0x9e, 0x8b, 0x5d, 0x99, 0xdc, 0x5c, 0xda, 0x9b, 0xdb, 0x94, 0x80, 0x68,
0x42, 0x86, 0xe7, 0x62, 0x17, 0xc6, 0x66, 0x57, 0x26, 0x37, 0x25, 0x30,
0xea, 0x90, 0xe1, 0xb9, 0xcc, 0xa1, 0x85, 0x91, 0x95, 0xc9, 0x35, 0xbd,
0x91, 0x95, 0xb1, 0x4d, 0x09, 0x90, 0x4a, 0x64, 0x78, 0x2e, 0x74, 0x79,
0x70, 0x65, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x73, 0x53, 0x84, 0xc8, 0xaa, 0x43, 0x86, 0xe7, 0x52, 0xe6, 0x46, 0x27,
0x97, 0x07, 0xf5, 0x96, 0xe6, 0x46, 0x37, 0x37, 0x25, 0xe0, 0xba, 0x90,
0xe1, 0xb9, 0x8c, 0xbd, 0xd5, 0xb9, 0xd1, 0x95, 0xc9, 0xcd, 0x4d, 0x09,
0x3c, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00,
0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88,
0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73,
0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e,
0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30,
0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8,
0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b,
0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76,
0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e,
0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e,
0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61,
0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4,
0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76,
0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37,
0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76,
0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71,
0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e,
0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1,
0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61,
0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90,
0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8,
0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc,
0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x8c, 0xc8,
0x21, 0x07, 0x7c, 0x70, 0x03, 0x72, 0x10, 0x87, 0x73, 0x70, 0x03, 0x7b,
0x08, 0x07, 0x79, 0x60, 0x87, 0x70, 0xc8, 0x87, 0x77, 0xa8, 0x07, 0x7a,
0x98, 0x81, 0x3c, 0xe4, 0x80, 0x0f, 0x6e, 0x40, 0x0f, 0xe5, 0xd0, 0x0e,
0xf0, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
0x05, 0x90, 0x05, 0x7e, 0xe7, 0x2f, 0x3c, 0x9c, 0x67, 0xbf, 0xc3, 0x64,
0x20, 0x70, 0x56, 0x85, 0x86, 0xf3, 0xec, 0x77, 0x98, 0x0c, 0x04, 0x06,
0x2d, 0xe0, 0x00, 0xa4, 0x9f, 0x01, 0x90, 0xc6, 0x04, 0xc2, 0x60, 0xb8,
0x7c, 0xe7, 0xf1, 0x07, 0x44, 0x7a, 0x80, 0x49, 0x38, 0x4c, 0x42, 0x3a,
0x7c, 0x69, 0x8a, 0x28, 0x61, 0xf2, 0x53, 0x00, 0x5b, 0x1c, 0x60, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x41, 0x53, 0x48, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x09, 0xa9, 0x46, 0x0a, 0x69, 0x15, 0x14, 0x41,
0xaa, 0xe6, 0x85, 0xce, 0x36, 0x42, 0xc2, 0x55, 0x44, 0x58, 0x49, 0x4c,
0x84, 0x04, 0x00, 0x00, 0x66, 0x00, 0x0e, 0x00, 0x21, 0x01, 0x00, 0x00,
0x44, 0x58, 0x49, 0x4c, 0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x6c, 0x04, 0x00, 0x00, 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00,
0x18, 0x01, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00,
0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49,
0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19,
0x1e, 0x04, 0x8b, 0x62, 0x80, 0x10, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42,
0x84, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x42, 0x88,
0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42,
0xe4, 0x48, 0x0e, 0x90, 0x11, 0x22, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c,
0xe1, 0x83, 0xe5, 0x8a, 0x04, 0x21, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x1b, 0x88, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07,
0x40, 0xda, 0x40, 0x08, 0x05, 0x70, 0x06, 0x00, 0x49, 0x18, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42, 0x20, 0x00, 0x00, 0x00,
0x89, 0x20, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x32, 0x22, 0x08, 0x09,
0x20, 0x64, 0x85, 0x04, 0x13, 0x22, 0xa4, 0x84, 0x04, 0x13, 0x22, 0xe3,
0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x88, 0x8c, 0x0b, 0x84, 0x84, 0x4c,
0x10, 0x2c, 0x73, 0x04, 0x60, 0x70, 0x8e, 0x34, 0x45, 0x94, 0x30, 0xf9,
0x29, 0x80, 0x2d, 0x0e, 0x30, 0xa0, 0x00, 0x06, 0x11, 0x82, 0x61, 0x04,
0xa0, 0x04, 0x43, 0x54, 0x8c, 0x01, 0x00, 0x10, 0xb2, 0x81, 0x80, 0x41,
0x04, 0x60, 0x98, 0x23, 0x00, 0x05, 0x00, 0x00, 0x13, 0x14, 0x72, 0xc0,
0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xc0,
0x87, 0x0d, 0xaf, 0x50, 0x0e, 0x6d, 0xd0, 0x0e, 0x7a, 0x50, 0x0e, 0x6d,
0x00, 0x0f, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
0x90, 0x0e, 0x71, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x78,
0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a,
0x30, 0x07, 0x72, 0xd0, 0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73,
0x20, 0x07, 0x6d, 0x90, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74,
0xd0, 0x06, 0xe6, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6,
0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0xe0, 0x0e, 0x78,
0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x76,
0x40, 0x07, 0x3a, 0x0f, 0x24, 0x90, 0x21, 0x23, 0x45, 0x44, 0x00, 0x76,
0x00, 0xf0, 0x90, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x21, 0x8f, 0x01, 0x04, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x59, 0x20, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x32, 0x1e, 0x98, 0x10, 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47,
0xc6, 0x04, 0x43, 0x82, 0x12, 0x28, 0x86, 0x92, 0x28, 0x8a, 0x42, 0x20,
0x1d, 0x01, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00,
0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4, 0x8e, 0x0c, 0x6f, 0xec,
0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45, 0xc6, 0x06, 0x26, 0xc7,
0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46, 0x26, 0x8c, 0x8c, 0xe6,
0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x80, 0x61, 0x82, 0x00, 0x10, 0x1b,
0x84, 0x81, 0x98, 0x20, 0x00, 0xc5, 0x06, 0x61, 0x30, 0x28, 0x84, 0xcd,
0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x14, 0x01, 0x8f, 0xb0, 0xb9, 0xaf,
0xb6, 0xb0, 0x34, 0xb7, 0x09, 0x02, 0x60, 0x6c, 0x18, 0x86, 0x61, 0x98,
0x20, 0x00, 0xc7, 0x06, 0xa1, 0x71, 0x36, 0x08, 0xcc, 0xb3, 0xa1, 0x50,
0x16, 0x00, 0x80, 0x38, 0xa4, 0xb9, 0xd1, 0xf1, 0x79, 0x6b, 0x73, 0x4b,
0x83, 0x7b, 0xa3, 0x2b, 0x73, 0xa3, 0x03, 0x19, 0x43, 0x0b, 0x93, 0x63,
0x34, 0x95, 0xd6, 0x06, 0xc7, 0x56, 0x06, 0x32, 0xf4, 0x32, 0xb4, 0xb2,
0x02, 0x42, 0x25, 0x14, 0x14, 0xb4, 0x21, 0xa0, 0x26, 0x08, 0x0a, 0xb2,
0x61, 0x98, 0x2a, 0x6b, 0xc3, 0x20, 0x5d, 0xd6, 0x86, 0x01, 0xc3, 0xac,
0x2a, 0x6c, 0x6c, 0x76, 0x6d, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x53,
0x82, 0xa0, 0x0a, 0x19, 0x9e, 0x8b, 0x5d, 0x99, 0xdc, 0x5c, 0xda, 0x9b,
0xdb, 0x94, 0x80, 0x68, 0x42, 0x86, 0xe7, 0x62, 0x17, 0xc6, 0x66, 0x57,
0x26, 0x37, 0x25, 0x30, 0xea, 0x90, 0xe1, 0xb9, 0xcc, 0xa1, 0x85, 0x91,
0x95, 0xc9, 0x35, 0xbd, 0x91, 0x95, 0xb1, 0x4d, 0x09, 0x90, 0x3a, 0x64,
0x78, 0x2e, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74,
0x73, 0x53, 0x02, 0x08, 0x79, 0x18, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00,
0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88,
0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73,
0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e,
0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30,
0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8,
0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b,
0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76,
0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e,
0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e,
0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61,
0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4,
0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76,
0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37,
0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76,
0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71,
0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e,
0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1,
0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61,
0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90,
0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8,
0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc,
0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x8c, 0xc8,
0x21, 0x07, 0x7c, 0x70, 0x03, 0x72, 0x10, 0x87, 0x73, 0x70, 0x03, 0x7b,
0x08, 0x07, 0x79, 0x60, 0x87, 0x70, 0xc8, 0x87, 0x77, 0xa8, 0x07, 0x7a,
0x98, 0x81, 0x3c, 0xe4, 0x80, 0x0f, 0x6e, 0x40, 0x0f, 0xe5, 0xd0, 0x0e,
0xf0, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
0x05, 0x90, 0x05, 0x7e, 0xe7, 0x2f, 0x3c, 0x9c, 0x67, 0xbf, 0xc3, 0x64,
0x20, 0x70, 0x56, 0x85, 0x86, 0xf3, 0xec, 0x77, 0x98, 0x0c, 0x04, 0x06,
0x2d, 0xe0, 0x00, 0xa4, 0x9f, 0x01, 0x90, 0xc6, 0x04, 0xc2, 0x60, 0xb8,
0x7c, 0xe7, 0xf1, 0x07, 0x44, 0x7a, 0x80, 0x49, 0x38, 0x4c, 0x42, 0x3a,
0x7c, 0x69, 0x8a, 0x28, 0x61, 0xf2, 0x53, 0x00, 0x5b, 0x1c, 0x60, 0x00,
0x61, 0x20, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x13, 0x04, 0x41, 0x2c,
0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x23, 0x00, 0x05,
0x18, 0x50, 0xda, 0x02, 0x45, 0x40, 0x39, 0xd4, 0x11, 0x08, 0x00, 0x90,
0x00, 0x09, 0x00, 0x00, 0xc3, 0x06, 0x44, 0x40, 0x0c, 0xc0, 0x88, 0x41,
0x22, 0x80, 0x20, 0x18, 0x18, 0xcc, 0x20, 0x2c, 0x8b, 0x83, 0x01, 0x31,
0x02, 0x00, 0x00, 0x00, 0x5b, 0x06, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
@@ -0,0 +1,462 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
// GENERATED by DXC 1.9.2609 from mesh.hlsl by compile.sh; do not edit.
#if 0
;
; Input signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; no parameters
;
; Output signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; SV_Position 0 xyzw 0 POS float xyzw
; COLOR 0 x 1 NONE uint x
;
; shader hash: 2510c16d61408eae7d2e2f4b80d23e9e
;
; Pipeline Runtime Information:
;
;PSVRuntimeInfo:
; Mesh Shader
; MeshOutputTopology=triangle
; NumThreads=(3,1,1)
; MinimumExpectedWaveLaneCount: 0
; MaximumExpectedWaveLaneCount: 4294967295
; UsesViewID: false
; SigInputElements: 0
; SigOutputElements: 2
; SigPatchConstOrPrimElements: 0
; SigInputVectors: 0
; SigOutputVectors[0]: 2
; SigOutputVectors[1]: 0
; SigOutputVectors[2]: 0
; SigOutputVectors[3]: 0
; EntryFunctionName: ms_main
;
;
; Vertex Output signature:
;
; Name Index InterpMode DynIdx
; -------------------- ----- ---------------------- ------
; SV_Position 0 noperspective
; COLOR 0 nointerpolation
;
; Buffer Definitions:
;
;
; Resource Bindings:
;
; Name Type Format Dim ID HLSL Bind Count
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
;
;
; ViewId state:
;
; Number of inputs: 0, outputs: 5, primitive outputs: 0
; Outputs dependent on ViewId: { }
; Primitive Outputs dependent on ViewId: { }
; Inputs contributing to computation of Outputs:
; Inputs contributing to computation of Primitive Outputs:
;
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
target triple = "dxil-ms-dx"
%struct.Payload = type { i32 }
define void @ms_main() {
%1 = call i32 @dx.op.groupId.i32(i32 94, i32 0) ; GroupId(component)
%2 = call i32 @dx.op.threadIdInGroup.i32(i32 95, i32 0) ; ThreadIdInGroup(component)
%3 = call %struct.Payload* @dx.op.getMeshPayload.struct.Payload(i32 170) ; GetMeshPayload()
call void @dx.op.setMeshOutputCounts(i32 168, i32 3, i32 1) ; SetMeshOutputCounts(numVertices,numPrimitives)
%4 = icmp eq i32 %1, 0
%5 = select i1 %4, float -1.000000e+00, float 1.000000e+00
%6 = select i1 %4, float 1.000000e+00, float -1.000000e+00
%7 = icmp eq i32 %2, 0
%8 = icmp eq i32 %2, 1
%9 = select i1 %8, float %6, float %5
%10 = icmp ult i32 %2, 2
%11 = select i1 %10, float %5, float %6
%12 = select i1 %7, float %5, float %9
call void @dx.op.storeVertexOutput.f32(i32 171, i32 0, i32 0, i8 0, float %11, i32 %2) ; StoreVertexOutput(outputSigId,rowIndex,colIndex,value,vertexIndex)
call void @dx.op.storeVertexOutput.f32(i32 171, i32 0, i32 0, i8 1, float %12, i32 %2) ; StoreVertexOutput(outputSigId,rowIndex,colIndex,value,vertexIndex)
call void @dx.op.storeVertexOutput.f32(i32 171, i32 0, i32 0, i8 2, float 0.000000e+00, i32 %2) ; StoreVertexOutput(outputSigId,rowIndex,colIndex,value,vertexIndex)
call void @dx.op.storeVertexOutput.f32(i32 171, i32 0, i32 0, i8 3, float 1.000000e+00, i32 %2) ; StoreVertexOutput(outputSigId,rowIndex,colIndex,value,vertexIndex)
%13 = getelementptr inbounds %struct.Payload, %struct.Payload* %3, i32 0, i32 0
%14 = load i32, i32* %13, align 4, !tbaa !16
%15 = add i32 %14, %1
call void @dx.op.storeVertexOutput.i32(i32 171, i32 1, i32 0, i8 0, i32 %15, i32 %2) ; StoreVertexOutput(outputSigId,rowIndex,colIndex,value,vertexIndex)
br i1 %7, label %16, label %17
; <label>:16 ; preds = %0
call void @dx.op.emitIndices(i32 169, i32 0, i32 0, i32 1, i32 2) ; EmitIndices(PrimitiveIndex,VertexIndex0,VertexIndex1,VertexIndex2)
br label %17
; <label>:17 ; preds = %16, %0
ret void
}
; Function Attrs: nounwind
declare void @dx.op.emitIndices(i32, i32, i32, i32, i32) #0
; Function Attrs: nounwind readonly
declare %struct.Payload* @dx.op.getMeshPayload.struct.Payload(i32) #1
; Function Attrs: nounwind readnone
declare i32 @dx.op.threadIdInGroup.i32(i32, i32) #2
; Function Attrs: nounwind readnone
declare i32 @dx.op.groupId.i32(i32, i32) #2
; Function Attrs: nounwind
declare void @dx.op.storeVertexOutput.f32(i32, i32, i32, i8, float, i32) #0
; Function Attrs: nounwind
declare void @dx.op.storeVertexOutput.i32(i32, i32, i32, i8, i32, i32) #0
; Function Attrs: nounwind
declare void @dx.op.setMeshOutputCounts(i32, i32, i32) #0
attributes #0 = { nounwind }
attributes #1 = { nounwind readonly }
attributes #2 = { nounwind readnone }
!llvm.ident = !{!0}
!dx.version = !{!1}
!dx.valver = !{!2}
!dx.shaderModel = !{!3}
!dx.viewIdState = !{!4}
!dx.entryPoints = !{!5}
!0 = !{!"dxcoob 1.9.2609.5 (01b62ad47)"}
!1 = !{i32 1, i32 6}
!2 = !{i32 1, i32 9}
!3 = !{!"ms", i32 6, i32 6}
!4 = !{[3 x i32] [i32 0, i32 5, i32 0]}
!5 = !{void ()* @ms_main, !"ms_main", !6, null, !13}
!6 = !{null, !7, null}
!7 = !{!8, !11}
!8 = !{i32 0, !"SV_Position", i8 9, i8 3, !9, i8 4, i32 1, i8 4, i32 0, i8 0, !10}
!9 = !{i32 0}
!10 = !{i32 3, i32 15}
!11 = !{i32 1, !"COLOR", i8 5, i8 0, !9, i8 1, i32 1, i8 1, i32 1, i8 0, !12}
!12 = !{i32 3, i32 1}
!13 = !{i32 9, !14}
!14 = !{!15, i32 3, i32 1, i32 2, i32 4}
!15 = !{i32 3, i32 1, i32 1}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !18, i64 0}
!18 = !{!"omnipotent char", !19, i64 0}
!19 = !{!"Simple C/C++ TBAA"}
#endif
const unsigned char g_mesh_ms[] = {
0x44, 0x58, 0x42, 0x43, 0x60, 0x8d, 0xb9, 0x34, 0x73, 0x63, 0x46, 0x44,
0xa5, 0xe6, 0xaf, 0x5e, 0x2b, 0xc0, 0xfd, 0xb4, 0x01, 0x00, 0x00, 0x00,
0x34, 0x0e, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x44, 0x01, 0x00, 0x00, 0x48, 0x07, 0x00, 0x00, 0x64, 0x07, 0x00, 0x00,
0x53, 0x46, 0x49, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4f, 0x53, 0x47, 0x31,
0x5c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74,
0x69, 0x6f, 0x6e, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x00, 0x00,
0x50, 0x53, 0x56, 0x30, 0x7c, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x0d, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x6d, 0x73, 0x5f, 0x6d, 0x61,
0x69, 0x6e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x44, 0x03, 0x03, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x41, 0x00, 0x01, 0x01, 0x00, 0x00,
0x53, 0x54, 0x41, 0x54, 0xfc, 0x05, 0x00, 0x00, 0x66, 0x00, 0x0d, 0x00,
0x7f, 0x01, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4c, 0x06, 0x01, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0xe4, 0x05, 0x00, 0x00, 0x42, 0x43, 0xc0, 0xde,
0x21, 0x0c, 0x00, 0x00, 0x76, 0x01, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00,
0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91,
0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c,
0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02,
0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4b,
0x0a, 0x32, 0x52, 0x88, 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xa5,
0x00, 0x19, 0x32, 0x42, 0xe4, 0x48, 0x0e, 0x90, 0x91, 0x22, 0xc4, 0x50,
0x41, 0x51, 0x81, 0x8c, 0xe1, 0x83, 0xe5, 0x8a, 0x04, 0x29, 0x46, 0x06,
0x51, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1b, 0x88, 0xe0, 0xff,
0xff, 0xff, 0xff, 0x07, 0x40, 0xda, 0x60, 0x08, 0xff, 0xff, 0xff, 0xff,
0x3f, 0x00, 0x12, 0x50, 0x6d, 0x30, 0x86, 0xff, 0xff, 0xff, 0xff, 0x1f,
0x00, 0x09, 0xa0, 0x00, 0x49, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x13, 0x82, 0x60, 0x42, 0x20, 0x4c, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00,
0x89, 0x20, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
0x10, 0x58, 0x23, 0x00, 0x25, 0x00, 0x14, 0xe6, 0x08, 0xc0, 0xa0, 0x18,
0x60, 0x8c, 0x31, 0x06, 0x91, 0x73, 0xa4, 0x29, 0xa2, 0x84, 0xc9, 0x4f,
0x01, 0x6c, 0x71, 0x80, 0x01, 0x05, 0x83, 0x4c, 0x11, 0xce, 0x20, 0x54,
0x86, 0x31, 0x06, 0xa9, 0x39, 0x02, 0x64, 0x06, 0xa0, 0x1c, 0x60, 0x8c,
0xc1, 0xda, 0x20, 0x57, 0x0e, 0x30, 0xc6, 0x60, 0x63, 0x10, 0x2c, 0x04,
0x18, 0x63, 0x90, 0x1c, 0x08, 0xc8, 0x81, 0x01, 0x13, 0x14, 0x72, 0xc0,
0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xc0,
0x87, 0x0d, 0xaf, 0x50, 0x0e, 0x6d, 0xd0, 0x0e, 0x7a, 0x50, 0x0e, 0x6d,
0x00, 0x0f, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
0x90, 0x0e, 0x71, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x78,
0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a,
0x30, 0x07, 0x72, 0xd0, 0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73,
0x20, 0x07, 0x6d, 0x90, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74,
0xd0, 0x06, 0xe6, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6,
0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0xe0, 0x0e, 0x78,
0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x76,
0x40, 0x07, 0x43, 0x9e, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x86, 0x3c, 0x04, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0c, 0x79, 0x10, 0x20, 0x00, 0x04, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xf2, 0x28, 0x40, 0x00, 0x0c, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xe4, 0x51, 0x80, 0x00, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xc8, 0xe3, 0x00, 0x01,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x90, 0x07, 0x02,
0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21, 0x8f,
0x04, 0x04, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59,
0x20, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x14,
0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x1a,
0x25, 0x50, 0x0c, 0x23, 0x00, 0x85, 0x50, 0x06, 0xe5, 0x50, 0x0a, 0xe5,
0x51, 0x12, 0x45, 0x50, 0x32, 0xc4, 0x4a, 0xa0, 0x24, 0xca, 0xa0, 0x10,
0x46, 0x00, 0x4a, 0x81, 0xcc, 0x0c, 0x00, 0xd5, 0xb1, 0x06, 0xa0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00,
0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4, 0x8e, 0x0c, 0x6f, 0xec,
0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45, 0xc6, 0x06, 0x26, 0xc7,
0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46, 0x26, 0x8c, 0x8c, 0xe6,
0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x06, 0x64, 0x82, 0x30, 0x24, 0x1b,
0x84, 0x81, 0x98, 0x20, 0x0c, 0xca, 0x06, 0xc1, 0x30, 0x28, 0xb4, 0xcd,
0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x18, 0xd9, 0x04, 0x61, 0x58, 0x68,
0x8c, 0xbd, 0xb1, 0xbd, 0xd5, 0xc9, 0x4d, 0x10, 0x06, 0x66, 0x82, 0x30,
0x34, 0x13, 0x84, 0xc1, 0xd9, 0x60, 0x10, 0x4c, 0x63, 0x38, 0xcf, 0x06,
0x61, 0x81, 0x36, 0x0c, 0x86, 0x12, 0x4d, 0x10, 0x04, 0x60, 0x03, 0xb0,
0x61, 0x30, 0x28, 0x6a, 0x43, 0x50, 0x6d, 0x18, 0x86, 0xc9, 0x9a, 0x20,
0x54, 0xda, 0x86, 0x00, 0xe3, 0xd1, 0x36, 0xf7, 0xd5, 0x16, 0x96, 0xe6,
0xc6, 0x65, 0xca, 0xea, 0x0b, 0xea, 0x6d, 0x2e, 0x8d, 0x2e, 0xed, 0xcd,
0x6d, 0x82, 0xc0, 0x50, 0x13, 0x04, 0xa6, 0xda, 0x10, 0x18, 0x13, 0x04,
0xc6, 0x9a, 0x20, 0x30, 0xd7, 0x04, 0x61, 0x78, 0x36, 0x08, 0x4d, 0x18,
0x6c, 0x58, 0x8c, 0x8d, 0xeb, 0xbc, 0x6f, 0xf8, 0x0c, 0x30, 0x10, 0x03,
0x16, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x13, 0x04, 0x06, 0x9b, 0x20, 0x30,
0xd3, 0x06, 0xa1, 0x19, 0x36, 0x2c, 0x03, 0x19, 0x94, 0x01, 0x18, 0x78,
0x66, 0x30, 0x98, 0xc1, 0x00, 0x06, 0x67, 0xb0, 0x41, 0x18, 0x03, 0x34,
0xd8, 0x30, 0x00, 0x69, 0x00, 0x4c, 0x10, 0x06, 0x68, 0xc3, 0xd0, 0x0c,
0xc3, 0x04, 0x61, 0x88, 0x36, 0x14, 0x6c, 0xd0, 0x0c, 0x6d, 0xb0, 0x6c,
0x10, 0xd6, 0xc0, 0x0d, 0x36, 0x14, 0x93, 0xa6, 0x06, 0xc0, 0x1b, 0x10,
0x11, 0x93, 0x0b, 0x73, 0x1b, 0x43, 0x2b, 0x9b, 0x63, 0x91, 0xe6, 0x36,
0x47, 0x37, 0x37, 0x41, 0x18, 0x24, 0x12, 0x69, 0x6e, 0x74, 0x73, 0x34,
0xe6, 0xd2, 0xce, 0xbe, 0xe6, 0xe8, 0x36, 0x20, 0x71, 0x30, 0xc8, 0xc1,
0x1c, 0xd0, 0xc1, 0x53, 0x07, 0x4f, 0x15, 0x36, 0x36, 0xbb, 0x36, 0x97,
0x34, 0xb2, 0x32, 0x37, 0xba, 0x29, 0x41, 0x50, 0x85, 0x0c, 0xcf, 0xc5,
0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x6d, 0x4a, 0x40, 0x34, 0x21, 0xc3,
0x73, 0xb1, 0x0b, 0x63, 0xb3, 0x2b, 0x93, 0x9b, 0x12, 0x18, 0x75, 0xc8,
0xf0, 0x5c, 0xe6, 0xd0, 0xc2, 0xc8, 0xca, 0xe4, 0x9a, 0xde, 0xc8, 0xca,
0xd8, 0xa6, 0x04, 0x48, 0x25, 0x32, 0x3c, 0x17, 0xba, 0x3c, 0xb8, 0xb2,
0x20, 0x37, 0xb7, 0x37, 0xba, 0x30, 0xba, 0xb4, 0x37, 0xb7, 0xb9, 0x29,
0x42, 0x64, 0xd5, 0x21, 0xc3, 0x73, 0xb1, 0x4b, 0x2b, 0xbb, 0x4b, 0x22,
0x9b, 0xa2, 0x0b, 0xa3, 0x2b, 0x9b, 0x12, 0x60, 0x75, 0xc8, 0xf0, 0x5c,
0xca, 0xdc, 0xe8, 0xe4, 0xf2, 0xa0, 0xde, 0xd2, 0xdc, 0xe8, 0xe6, 0xa6,
0x04, 0x6f, 0xd0, 0x85, 0x0c, 0xcf, 0x65, 0xec, 0xad, 0xce, 0x8d, 0xae,
0x4c, 0x6e, 0x6e, 0x4a, 0x50, 0x07, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x51, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
0xb0, 0xc3, 0x0c, 0xc4, 0x21, 0x07, 0x7c, 0x70, 0x03, 0x7a, 0x28, 0x87,
0x76, 0x80, 0x87, 0x19, 0xd1, 0x43, 0x0e, 0xf8, 0xe0, 0x06, 0xe4, 0x20,
0x0e, 0xe7, 0xe0, 0x06, 0xf6, 0x10, 0x0e, 0xf2, 0xc0, 0x0e, 0xe1, 0x90,
0x0f, 0xef, 0x50, 0x0f, 0xf4, 0x30, 0x83, 0x81, 0xc8, 0x01, 0x1f, 0xdc,
0x40, 0x1c, 0xe4, 0xa1, 0x1c, 0xc2, 0x61, 0x1d, 0xdc, 0x40, 0x1c, 0xe4,
0x01, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
0x16, 0x10, 0x0d, 0x97, 0xef, 0x3c, 0x3e, 0xc1, 0x20, 0x93, 0xd8, 0x0c,
0x88, 0x40, 0x48, 0x26, 0x30, 0x06, 0xc3, 0xe5, 0x3b, 0x8f, 0x6f, 0x10,
0x93, 0x49, 0x48, 0x47, 0x0a, 0x60, 0x8b, 0x03, 0x0c, 0xbe, 0x34, 0x45,
0x94, 0x30, 0xf9, 0x29, 0x80, 0x2d, 0x0e, 0x30, 0x18, 0x41, 0x34, 0x5c,
0xbe, 0xf3, 0xf8, 0x46, 0xe4, 0x50, 0x8f, 0x38, 0xf8, 0xc8, 0x6d, 0xdb,
0x41, 0x36, 0x5c, 0xbe, 0xf3, 0xf8, 0x12, 0x31, 0x99, 0x84, 0x74, 0xa0,
0xd4, 0xf4, 0x50, 0x13, 0xe7, 0x50, 0xcd, 0x24, 0x59, 0xc1, 0x36, 0x5c,
0xbe, 0xf3, 0xf8, 0xd2, 0xe4, 0x44, 0xc4, 0x4b, 0x44, 0x13, 0x71, 0xa1,
0xd4, 0xf4, 0x50, 0x93, 0x5f, 0xdc, 0xb6, 0x19, 0x6c, 0xc3, 0xe5, 0x3b,
0x8f, 0x2f, 0x4d, 0x4e, 0x44, 0xbc, 0x44, 0x34, 0x11, 0x17, 0x4a, 0x4d,
0x0f, 0x35, 0xf9, 0xc8, 0x6d, 0xdb, 0x40, 0x36, 0x5c, 0xbe, 0xf3, 0xf8,
0xd3, 0x11, 0x11, 0xc0, 0x20, 0x0e, 0x62, 0x03, 0x46, 0x0e, 0xf5, 0xf8,
0xc8, 0x6d, 0x1b, 0xc0, 0xc1, 0x48, 0x3f, 0x03, 0x20, 0x0d, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x41, 0x53, 0x48, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x25, 0x10, 0xc1, 0x6d, 0x61, 0x40, 0x8e, 0xae,
0x7d, 0x2e, 0x2f, 0x4b, 0x80, 0xd2, 0x3e, 0x9e, 0x44, 0x58, 0x49, 0x4c,
0xc8, 0x06, 0x00, 0x00, 0x66, 0x00, 0x0d, 0x00, 0xb2, 0x01, 0x00, 0x00,
0x44, 0x58, 0x49, 0x4c, 0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0xb0, 0x06, 0x00, 0x00, 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00,
0xa9, 0x01, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00,
0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49,
0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19,
0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42,
0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x52, 0x88,
0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42,
0xe4, 0x48, 0x0e, 0x90, 0x91, 0x22, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c,
0xe1, 0x83, 0xe5, 0x8a, 0x04, 0x29, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x1b, 0x88, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07,
0x40, 0xda, 0x60, 0x08, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x12, 0x50,
0x6d, 0x30, 0x86, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x09, 0xa0, 0x00,
0x49, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42,
0x20, 0x4c, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00,
0x1b, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x64, 0x85, 0x04,
0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3, 0x84, 0xa1, 0x90, 0x14,
0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c, 0x10, 0x68, 0x23, 0x00,
0x25, 0x00, 0x14, 0xe6, 0x08, 0xc0, 0xa0, 0x18, 0x60, 0x8c, 0x31, 0x06,
0x91, 0x73, 0xa4, 0x29, 0xa2, 0x84, 0xc9, 0x4f, 0x01, 0x6c, 0x71, 0x80,
0x01, 0x05, 0x83, 0x4c, 0x11, 0xce, 0x20, 0x54, 0x86, 0x31, 0x06, 0xa9,
0x39, 0x02, 0x64, 0x06, 0xa0, 0x1c, 0x60, 0x8c, 0xc1, 0xda, 0x20, 0x57,
0x0e, 0x30, 0xc6, 0x60, 0x63, 0x10, 0x2c, 0x04, 0x18, 0x63, 0x90, 0x1c,
0x08, 0xc8, 0x81, 0x31, 0x47, 0x10, 0xd0, 0x98, 0x23, 0x00, 0x85, 0x29,
0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x72, 0xc0, 0x87, 0x74, 0x60, 0x87,
0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xc0, 0x87, 0x0d, 0xaf, 0x50,
0x0e, 0x6d, 0xd0, 0x0e, 0x7a, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x30,
0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0,
0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x73, 0x20,
0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90,
0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x10,
0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
0x07, 0x76, 0x40, 0x07, 0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x43, 0x9e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86,
0x3c, 0x04, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x79, 0x10, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0xf2, 0x28, 0x40, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0xe4, 0x51, 0x80, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x60, 0xc8, 0xe3, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x90, 0x07, 0x02, 0x02, 0x20, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21, 0x8f, 0x04, 0x04, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x20, 0x00, 0x00, 0x00,
0x0d, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x14, 0x19, 0x11, 0x4c, 0x90,
0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x1a, 0x25, 0x50, 0x0c, 0x25,
0x31, 0x02, 0x50, 0x06, 0xe5, 0x51, 0x04, 0x85, 0x40, 0xac, 0x24, 0xca,
0xa0, 0x10, 0x46, 0x00, 0x4a, 0xa1, 0x04, 0x08, 0x8f, 0x00, 0x50, 0x1d,
0x6b, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x59, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4,
0x8e, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45,
0xc6, 0x06, 0x26, 0xc7, 0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46,
0x26, 0x8c, 0x8c, 0xe6, 0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x06, 0x64,
0x82, 0x30, 0x24, 0x1b, 0x84, 0x81, 0x98, 0x20, 0x0c, 0xca, 0x06, 0x61,
0x30, 0x28, 0xb4, 0xcd, 0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x54, 0xd7,
0x86, 0x40, 0x99, 0x20, 0x08, 0x00, 0x8f, 0xb6, 0xb9, 0xaf, 0xb6, 0xb0,
0x34, 0xb7, 0x09, 0xc2, 0xb0, 0x70, 0x99, 0xb2, 0xfa, 0x82, 0x7a, 0x9b,
0x4b, 0xa3, 0x4b, 0x7b, 0x73, 0x9b, 0x20, 0x30, 0xd0, 0x04, 0x81, 0x89,
0x36, 0x04, 0xce, 0x04, 0x81, 0x91, 0x26, 0x08, 0xcc, 0x34, 0x41, 0x18,
0x98, 0x09, 0xc2, 0xd0, 0x6c, 0x10, 0x2a, 0x6b, 0xc3, 0xe2, 0x3c, 0x50,
0x24, 0x4d, 0xc3, 0xe4, 0x50, 0x17, 0x8b, 0xa1, 0x27, 0xa6, 0x27, 0xa9,
0x09, 0x02, 0x43, 0x4d, 0x10, 0x98, 0x6a, 0x83, 0x50, 0x0d, 0x1b, 0x96,
0x21, 0xd3, 0x28, 0x69, 0x1b, 0xb6, 0x81, 0xe2, 0x36, 0x08, 0x58, 0xb7,
0x61, 0x00, 0x3c, 0x60, 0xc3, 0x50, 0x0d, 0xc3, 0x04, 0x61, 0x70, 0x26,
0x08, 0xc3, 0xb3, 0xa1, 0x00, 0x83, 0x6a, 0x08, 0x03, 0x31, 0xd8, 0x20,
0x18, 0x63, 0xb0, 0xa1, 0x60, 0x9a, 0x0f, 0x20, 0x03, 0x0e, 0x69, 0x6e,
0x74, 0x7c, 0xde, 0xda, 0xdc, 0xd2, 0xe0, 0xde, 0xe8, 0xca, 0xdc, 0xe8,
0x40, 0xc6, 0xd0, 0xc2, 0xe4, 0x18, 0x4d, 0xa5, 0xb5, 0xc1, 0xb1, 0x95,
0x81, 0x0c, 0xbd, 0x0c, 0xad, 0xac, 0x80, 0x50, 0x09, 0x05, 0x05, 0x6d,
0x08, 0xd0, 0x60, 0x82, 0x80, 0x59, 0x1b, 0x86, 0x33, 0x48, 0x03, 0x35,
0xd8, 0x30, 0x98, 0xc1, 0x1a, 0xa8, 0xc1, 0x86, 0x81, 0x0d, 0xd8, 0x40,
0x0d, 0xaa, 0xb0, 0xb1, 0xd9, 0xb5, 0xb9, 0xa4, 0x91, 0x95, 0xb9, 0xd1,
0x4d, 0x09, 0x82, 0x2a, 0x64, 0x78, 0x2e, 0x76, 0x65, 0x72, 0x73, 0x69,
0x6f, 0x6e, 0x53, 0x02, 0xa2, 0x09, 0x19, 0x9e, 0x8b, 0x5d, 0x18, 0x9b,
0x5d, 0x99, 0xdc, 0x94, 0xc0, 0xa8, 0x43, 0x86, 0xe7, 0x32, 0x87, 0x16,
0x46, 0x56, 0x26, 0xd7, 0xf4, 0x46, 0x56, 0xc6, 0x36, 0x25, 0x40, 0xea,
0x90, 0xe1, 0xb9, 0xd8, 0xa5, 0x95, 0xdd, 0x25, 0x91, 0x4d, 0xd1, 0x85,
0xd1, 0x95, 0x4d, 0x09, 0x94, 0x3a, 0x64, 0x78, 0x2e, 0x65, 0x6e, 0x74,
0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x53, 0x02, 0x32, 0x00,
0x79, 0x18, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c,
0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3,
0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6,
0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e,
0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43,
0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03,
0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48,
0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20,
0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e,
0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d,
0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89,
0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83,
0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68,
0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90,
0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78,
0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98,
0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5,
0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c,
0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c,
0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43,
0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43,
0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82,
0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc4, 0x21, 0x07, 0x7c, 0x70,
0x03, 0x7a, 0x28, 0x87, 0x76, 0x80, 0x87, 0x19, 0xd1, 0x43, 0x0e, 0xf8,
0xe0, 0x06, 0xe4, 0x20, 0x0e, 0xe7, 0xe0, 0x06, 0xf6, 0x10, 0x0e, 0xf2,
0xc0, 0x0e, 0xe1, 0x90, 0x0f, 0xef, 0x50, 0x0f, 0xf4, 0x30, 0x83, 0x81,
0xc8, 0x01, 0x1f, 0xdc, 0x40, 0x1c, 0xe4, 0xa1, 0x1c, 0xc2, 0x61, 0x1d,
0xdc, 0x40, 0x1c, 0xe4, 0x01, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00,
0x27, 0x00, 0x00, 0x00, 0x16, 0x10, 0x0d, 0x97, 0xef, 0x3c, 0x3e, 0xc1,
0x20, 0x93, 0xd8, 0x0c, 0x88, 0x40, 0x48, 0x26, 0x30, 0x06, 0xc3, 0xe5,
0x3b, 0x8f, 0x6f, 0x10, 0x93, 0x49, 0x48, 0x47, 0x0a, 0x60, 0x8b, 0x03,
0x0c, 0xbe, 0x34, 0x45, 0x94, 0x30, 0xf9, 0x29, 0x80, 0x2d, 0x0e, 0x30,
0x18, 0x41, 0x34, 0x5c, 0xbe, 0xf3, 0xf8, 0x46, 0xe4, 0x50, 0x8f, 0x38,
0xf8, 0xc8, 0x6d, 0xdb, 0x41, 0x36, 0x5c, 0xbe, 0xf3, 0xf8, 0x12, 0x31,
0x99, 0x84, 0x74, 0xa0, 0xd4, 0xf4, 0x50, 0x13, 0xe7, 0x50, 0xcd, 0x24,
0x59, 0xc1, 0x36, 0x5c, 0xbe, 0xf3, 0xf8, 0xd2, 0xe4, 0x44, 0xc4, 0x4b,
0x44, 0x13, 0x71, 0xa1, 0xd4, 0xf4, 0x50, 0x93, 0x5f, 0xdc, 0xb6, 0x19,
0x6c, 0xc3, 0xe5, 0x3b, 0x8f, 0x2f, 0x4d, 0x4e, 0x44, 0xbc, 0x44, 0x34,
0x11, 0x17, 0x4a, 0x4d, 0x0f, 0x35, 0xf9, 0xc8, 0x6d, 0xdb, 0x40, 0x36,
0x5c, 0xbe, 0xf3, 0xf8, 0xd3, 0x11, 0x11, 0xc0, 0x20, 0x0e, 0x62, 0x03,
0x46, 0x0e, 0xf5, 0xf8, 0xc8, 0x6d, 0x1b, 0xc0, 0xc1, 0x48, 0x3f, 0x03,
0x20, 0x0d, 0x00, 0x00, 0x61, 0x20, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00,
0x13, 0x04, 0x43, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
0x34, 0xca, 0x5a, 0xa0, 0x78, 0x03, 0xca, 0x37, 0xa0, 0xa8, 0x05, 0x0a,
0x5a, 0xa0, 0xa4, 0x05, 0x88, 0x15, 0x01, 0xb5, 0x31, 0x02, 0x10, 0x04,
0x41, 0xfc, 0x1b, 0x23, 0x00, 0x41, 0x10, 0xc4, 0x7f, 0x61, 0x04, 0x00,
0x00, 0x00, 0x00, 0x00, 0x23, 0x06, 0x06, 0x00, 0x82, 0x60, 0xa0, 0x78,
0xc9, 0x35, 0x62, 0x60, 0x00, 0x20, 0x08, 0x06, 0x0a, 0x18, 0x24, 0xd8,
0x88, 0x41, 0x01, 0x80, 0x20, 0x18, 0x20, 0x62, 0x90, 0x8c, 0x18, 0x1c,
0x00, 0x08, 0x82, 0x81, 0xe4, 0x25, 0x59, 0x37, 0xdc, 0x30, 0x68, 0x60,
0x30, 0xdd, 0x60, 0x1c, 0xc1, 0x74, 0x03, 0x72, 0x08, 0xc3, 0x0d, 0x45,
0x07, 0x06, 0xc3, 0x0d, 0x46, 0x18, 0x80, 0xc1, 0x74, 0xc3, 0x40, 0x04,
0xc3, 0x0d, 0x48, 0x47, 0x06, 0xd3, 0x0d, 0x46, 0x11, 0x4c, 0x37, 0x1c,
0x43, 0x31, 0x62, 0xa0, 0x00, 0x20, 0x08, 0x06, 0x4e, 0x1a, 0x58, 0x63,
0x30, 0x06, 0x9b, 0xb0, 0x8c, 0x18, 0x28, 0x00, 0x08, 0x82, 0x81, 0x93,
0x06, 0xd6, 0x18, 0x8c, 0x41, 0x16, 0x2c, 0x23, 0x06, 0x0a, 0x00, 0x82,
0x60, 0xe0, 0xa4, 0x81, 0x35, 0x06, 0x63, 0x00, 0x35, 0xcb, 0x88, 0x81,
0x02, 0x80, 0x20, 0x18, 0x38, 0x69, 0x60, 0x8d, 0xc1, 0x18, 0x74, 0xcf,
0xb2, 0xcd, 0xa0, 0x8c, 0xc1, 0x18, 0x50, 0x30, 0x46, 0x05, 0x0e, 0x8c,
0x18, 0x28, 0x00, 0x08, 0x82, 0x01, 0xb4, 0x06, 0x59, 0x1a, 0x98, 0x81,
0x17, 0x38, 0xb3, 0x0c, 0x81, 0x90, 0x8c, 0x18, 0x24, 0x00, 0x08, 0x82,
0x01, 0x01, 0x07, 0x94, 0x19, 0x98, 0x41, 0x1a, 0x8c, 0xc1, 0x2c, 0x81,
0x80, 0x01, 0x31, 0x00, 0x02, 0x00, 0x00, 0x00, 0x5b, 0x06, 0x29, 0x60,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
@@ -0,0 +1,354 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
// GENERATED by DXC 1.9.2609 from mesh.hlsl by compile.sh; do not edit.
#if 0
;
; Input signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; SV_Position 0 xyzw 0 POS float
; COLOR 0 x 1 NONE uint x
;
;
; Output signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; SV_Target 0 x 0 TARGET uint x
;
; shader hash: 160420bd0099533dc20c0e6886f7806a
;
; Pipeline Runtime Information:
;
;PSVRuntimeInfo:
; Pixel Shader
; DepthOutput=0
; SampleFrequency=0
; MinimumExpectedWaveLaneCount: 0
; MaximumExpectedWaveLaneCount: 4294967295
; UsesViewID: false
; SigInputElements: 2
; SigOutputElements: 1
; SigPatchConstOrPrimElements: 0
; SigInputVectors: 2
; SigOutputVectors[0]: 1
; SigOutputVectors[1]: 0
; SigOutputVectors[2]: 0
; SigOutputVectors[3]: 0
; EntryFunctionName: ps_main
;
;
; Input signature:
;
; Name Index InterpMode DynIdx
; -------------------- ----- ---------------------- ------
; SV_Position 0 noperspective
; COLOR 0 nointerpolation
;
; Output signature:
;
; Name Index InterpMode DynIdx
; -------------------- ----- ---------------------- ------
; SV_Target 0
;
; Buffer Definitions:
;
;
; Resource Bindings:
;
; Name Type Format Dim ID HLSL Bind Count
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
;
;
; ViewId state:
;
; Number of inputs: 5, outputs: 1
; Outputs dependent on ViewId: { }
; Inputs contributing to computation of Outputs:
; output 0 depends on inputs: { 4 }
;
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
target triple = "dxil-ms-dx"
define void @ps_main() {
%1 = call i32 @dx.op.loadInput.i32(i32 4, i32 1, i32 0, i8 0, i32 undef) ; LoadInput(inputSigId,rowIndex,colIndex,gsVertexAxis)
call void @dx.op.storeOutput.i32(i32 5, i32 0, i32 0, i8 0, i32 %1) ; StoreOutput(outputSigId,rowIndex,colIndex,value)
ret void
}
; Function Attrs: nounwind readnone
declare i32 @dx.op.loadInput.i32(i32, i32, i32, i8, i32) #0
; Function Attrs: nounwind
declare void @dx.op.storeOutput.i32(i32, i32, i32, i8, i32) #1
attributes #0 = { nounwind readnone }
attributes #1 = { nounwind }
!llvm.ident = !{!0}
!dx.version = !{!1}
!dx.valver = !{!2}
!dx.shaderModel = !{!3}
!dx.viewIdState = !{!4}
!dx.entryPoints = !{!5}
!0 = !{!"dxcoob 1.9.2609.5 (01b62ad47)"}
!1 = !{i32 1, i32 6}
!2 = !{i32 1, i32 9}
!3 = !{!"ps", i32 6, i32 6}
!4 = !{[7 x i32] [i32 5, i32 1, i32 0, i32 0, i32 0, i32 0, i32 1]}
!5 = !{void ()* @ps_main, !"ps_main", !6, null, null}
!6 = !{!7, !12, null}
!7 = !{!8, !10}
!8 = !{i32 0, !"SV_Position", i8 9, i8 3, !9, i8 4, i32 1, i8 4, i32 0, i8 0, null}
!9 = !{i32 0}
!10 = !{i32 1, !"COLOR", i8 5, i8 0, !9, i8 1, i32 1, i8 1, i32 1, i8 0, !11}
!11 = !{i32 3, i32 1}
!12 = !{!13}
!13 = !{i32 0, !"SV_Target", i8 5, i8 16, !9, i8 0, i32 1, i8 1, i32 0, i8 0, !11}
#endif
const unsigned char g_mesh_ps[] = {
0x44, 0x58, 0x42, 0x43, 0x5c, 0x1f, 0x97, 0x75, 0x4e, 0x5a, 0xc6, 0x68,
0x71, 0x4f, 0xbc, 0x67, 0xfe, 0xcd, 0xdd, 0xf4, 0x01, 0x00, 0x00, 0x00,
0x34, 0x0b, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0xec, 0x00, 0x00, 0x00,
0xa0, 0x01, 0x00, 0x00, 0x64, 0x06, 0x00, 0x00, 0x80, 0x06, 0x00, 0x00,
0x53, 0x46, 0x49, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x31, 0x5c, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x53, 0x56, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00,
0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x00, 0x00, 0x4f, 0x53, 0x47, 0x31,
0x34, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54,
0x61, 0x72, 0x67, 0x65, 0x74, 0x00, 0x00, 0x00, 0x50, 0x53, 0x56, 0x30,
0xac, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x43, 0x4f, 0x4c,
0x4f, 0x52, 0x00, 0x70, 0x73, 0x5f, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x44, 0x03,
0x03, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x41, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x10, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x41, 0x54,
0xbc, 0x04, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x2f, 0x01, 0x00, 0x00,
0x44, 0x58, 0x49, 0x4c, 0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0xa4, 0x04, 0x00, 0x00, 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00,
0x26, 0x01, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00,
0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49,
0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19,
0x1e, 0x04, 0x8b, 0x62, 0x80, 0x10, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42,
0x84, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x42, 0x88,
0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42,
0xe4, 0x48, 0x0e, 0x90, 0x11, 0x22, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c,
0xe1, 0x83, 0xe5, 0x8a, 0x04, 0x21, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x1b, 0x8c, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07,
0x40, 0x02, 0xa8, 0x0d, 0x84, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x03, 0x20,
0x01, 0x00, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x13, 0x82, 0x60, 0x42, 0x20, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00,
0x0f, 0x00, 0x00, 0x00, 0x32, 0x22, 0x08, 0x09, 0x20, 0x64, 0x85, 0x04,
0x13, 0x22, 0xa4, 0x84, 0x04, 0x13, 0x22, 0xe3, 0x84, 0xa1, 0x90, 0x14,
0x12, 0x4c, 0x88, 0x8c, 0x0b, 0x84, 0x84, 0x4c, 0x10, 0x2c, 0x23, 0x00,
0x25, 0x00, 0x8a, 0x39, 0x02, 0x30, 0x98, 0x23, 0x40, 0x8a, 0x31, 0x33,
0x43, 0x43, 0x55, 0x0c, 0x98, 0x19, 0x1a, 0xba, 0x81, 0x80, 0x3c, 0x18,
0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x72, 0xc0, 0x87, 0x74, 0x60, 0x87,
0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xc0, 0x87, 0x0d, 0xaf, 0x50,
0x0e, 0x6d, 0xd0, 0x0e, 0x7a, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x30,
0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0,
0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x73, 0x20,
0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90,
0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x10,
0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
0x07, 0x76, 0x40, 0x07, 0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x43, 0x9e,
0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86,
0x3c, 0x05, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x79, 0x0e, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc8, 0x02, 0x01, 0x0b, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x10,
0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x9a,
0x12, 0x28, 0x86, 0x11, 0x80, 0x32, 0x20, 0x2a, 0x89, 0x32, 0x28, 0x84,
0x11, 0x80, 0x52, 0x28, 0x81, 0x02, 0x21, 0x1d, 0xeb, 0x28, 0x02, 0x00,
0x00, 0x80, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00,
0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4, 0x8e, 0x0c, 0x6f, 0xec,
0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45, 0xc6, 0x06, 0x26, 0xc7,
0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46, 0x26, 0x8c, 0x8c, 0xe6,
0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x86, 0x61, 0x82, 0x30, 0x10, 0x1b,
0x84, 0x81, 0x98, 0x20, 0x0c, 0xc5, 0x06, 0xc1, 0x30, 0x28, 0xc0, 0xcd,
0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x08, 0xc0, 0x06, 0x60, 0xc3, 0x60,
0x2c, 0xcb, 0x86, 0x80, 0xd9, 0x30, 0x0c, 0x4a, 0x33, 0x41, 0x50, 0x9c,
0x0d, 0xc1, 0xc3, 0x03, 0x6e, 0xee, 0xab, 0x2d, 0x2c, 0xcd, 0x8d, 0xcb,
0x94, 0xd5, 0x17, 0xd4, 0xdb, 0x5c, 0x1a, 0x5d, 0xda, 0x9b, 0xdb, 0x04,
0x81, 0x38, 0x26, 0x08, 0x04, 0xb2, 0x21, 0x30, 0x26, 0x08, 0x44, 0x32,
0x41, 0x20, 0x94, 0x0d, 0x8b, 0x21, 0x4d, 0x54, 0x65, 0x0d, 0x96, 0x71,
0x01, 0x2c, 0x86, 0x9e, 0x98, 0x9e, 0xa4, 0x26, 0x08, 0xc4, 0x32, 0x41,
0x20, 0x98, 0x09, 0xc2, 0x60, 0x6c, 0x10, 0xb8, 0x61, 0xc3, 0x32, 0x64,
0xda, 0x55, 0x6d, 0xc3, 0x36, 0x5c, 0xdd, 0x06, 0x01, 0xf3, 0x98, 0x4c,
0x59, 0x7d, 0x51, 0x85, 0xc9, 0x9d, 0x95, 0xd1, 0x4d, 0x10, 0x88, 0x66,
0xc3, 0x62, 0x80, 0x81, 0x16, 0x06, 0xd5, 0x35, 0x6c, 0xc6, 0xd5, 0x6d,
0x08, 0xc4, 0x60, 0xc3, 0xf0, 0x8d, 0x01, 0xb0, 0xa1, 0x50, 0x22, 0x32,
0x00, 0x00, 0x16, 0x69, 0x6e, 0x73, 0x74, 0x73, 0x34, 0xe6, 0xd2, 0xce,
0xbe, 0xd8, 0xc8, 0x68, 0xcc, 0xa5, 0x9d, 0x7d, 0xcd, 0xd1, 0x6d, 0x30,
0xcc, 0x80, 0x3b, 0x83, 0x01, 0x0d, 0x86, 0x2a, 0x6c, 0x6c, 0x76, 0x6d,
0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x53, 0x82, 0xa0, 0x0a, 0x19, 0x9e,
0x8b, 0x5d, 0x99, 0xdc, 0x5c, 0xda, 0x9b, 0xdb, 0x94, 0x80, 0x68, 0x42,
0x86, 0xe7, 0x62, 0x17, 0xc6, 0x66, 0x57, 0x26, 0x37, 0x25, 0x30, 0xea,
0x90, 0xe1, 0xb9, 0xcc, 0xa1, 0x85, 0x91, 0x95, 0xc9, 0x35, 0xbd, 0x91,
0x95, 0xb1, 0x4d, 0x09, 0x90, 0x4a, 0x64, 0x78, 0x2e, 0x74, 0x79, 0x70,
0x65, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73,
0x53, 0x82, 0xa6, 0x0e, 0x19, 0x9e, 0x8b, 0x5d, 0x5a, 0xd9, 0x5d, 0x12,
0xd9, 0x14, 0x5d, 0x18, 0x5d, 0xd9, 0x94, 0xe0, 0xa9, 0x43, 0x86, 0xe7,
0x52, 0xe6, 0x46, 0x27, 0x97, 0x07, 0xf5, 0x96, 0xe6, 0x46, 0x37, 0x37,
0x25, 0x20, 0x83, 0x2e, 0x64, 0x78, 0x2e, 0x63, 0x6f, 0x75, 0x6e, 0x74,
0x65, 0x72, 0x73, 0x53, 0x02, 0x34, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
0xb0, 0xc3, 0x0c, 0xc4, 0x21, 0x07, 0x7c, 0x70, 0x03, 0x7a, 0x28, 0x87,
0x76, 0x80, 0x87, 0x19, 0xd1, 0x43, 0x0e, 0xf8, 0xe0, 0x06, 0xe4, 0x20,
0x0e, 0xe7, 0xe0, 0x06, 0xf6, 0x10, 0x0e, 0xf2, 0xc0, 0x0e, 0xe1, 0x90,
0x0f, 0xef, 0x50, 0x0f, 0xf4, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00,
0x0b, 0x00, 0x00, 0x00, 0x16, 0x30, 0x0d, 0x97, 0xef, 0x3c, 0xfe, 0xe2,
0x00, 0x83, 0xd8, 0x3c, 0xd4, 0xe4, 0x23, 0xb7, 0x6d, 0x02, 0xd5, 0x70,
0xf9, 0xce, 0xe3, 0x4b, 0x93, 0x13, 0x11, 0x28, 0x35, 0x3d, 0xd4, 0xe4,
0x23, 0xb7, 0x6d, 0x00, 0xc7, 0x23, 0xfd, 0x0c, 0x80, 0x34, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x41, 0x53, 0x48, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x16, 0x04, 0x20, 0xbd, 0x00, 0x99, 0x53, 0x3d,
0xc2, 0x0c, 0x0e, 0x68, 0x86, 0xf7, 0x80, 0x6a, 0x44, 0x58, 0x49, 0x4c,
0xac, 0x04, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x2b, 0x01, 0x00, 0x00,
0x44, 0x58, 0x49, 0x4c, 0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x94, 0x04, 0x00, 0x00, 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00,
0x22, 0x01, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00,
0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49,
0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19,
0x1e, 0x04, 0x8b, 0x62, 0x80, 0x10, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42,
0x84, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x42, 0x88,
0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42,
0xe4, 0x48, 0x0e, 0x90, 0x11, 0x22, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c,
0xe1, 0x83, 0xe5, 0x8a, 0x04, 0x21, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x1b, 0x8c, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07,
0x40, 0x02, 0xa8, 0x0d, 0x84, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x03, 0x20,
0x01, 0x00, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x13, 0x82, 0x60, 0x42, 0x20, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00,
0x0f, 0x00, 0x00, 0x00, 0x32, 0x22, 0x08, 0x09, 0x20, 0x64, 0x85, 0x04,
0x13, 0x22, 0xa4, 0x84, 0x04, 0x13, 0x22, 0xe3, 0x84, 0xa1, 0x90, 0x14,
0x12, 0x4c, 0x88, 0x8c, 0x0b, 0x84, 0x84, 0x4c, 0x10, 0x2c, 0x23, 0x00,
0x25, 0x00, 0x8a, 0x39, 0x02, 0x30, 0x98, 0x23, 0x40, 0x8a, 0x31, 0x33,
0x43, 0x43, 0x55, 0x0c, 0x98, 0x19, 0x1a, 0xba, 0x81, 0x80, 0x3c, 0x18,
0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x72, 0xc0, 0x87, 0x74, 0x60, 0x87,
0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xc0, 0x87, 0x0d, 0xaf, 0x50,
0x0e, 0x6d, 0xd0, 0x0e, 0x7a, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x30,
0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0,
0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x73, 0x20,
0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90,
0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x10,
0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
0x07, 0x76, 0x40, 0x07, 0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x43, 0x9e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86,
0x3c, 0x05, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x79, 0x0e, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc8, 0x02, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x14,
0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x9a,
0x12, 0x28, 0x86, 0x92, 0x18, 0x01, 0x28, 0x03, 0xa2, 0x92, 0x28, 0x83,
0x42, 0x18, 0x01, 0x28, 0x85, 0x12, 0x28, 0x10, 0xd2, 0xb1, 0x8e, 0x22,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x49, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4,
0x8e, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45,
0xc6, 0x06, 0x26, 0xc7, 0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46,
0x26, 0x8c, 0x8c, 0xe6, 0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x86, 0x61,
0x82, 0x30, 0x10, 0x1b, 0x84, 0x81, 0x98, 0x20, 0x0c, 0xc5, 0x06, 0x61,
0x30, 0x28, 0xc0, 0xcd, 0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x28, 0xcf,
0x86, 0x40, 0x99, 0x20, 0x08, 0x00, 0x0f, 0xb8, 0xb9, 0xaf, 0xb6, 0xb0,
0x34, 0xb7, 0x09, 0xc2, 0x60, 0x70, 0x99, 0xb2, 0xfa, 0x82, 0x7a, 0x9b,
0x4b, 0xa3, 0x4b, 0x7b, 0x73, 0x9b, 0x20, 0x10, 0xc8, 0x04, 0x81, 0x48,
0x36, 0x04, 0xce, 0x04, 0x81, 0x50, 0x26, 0x08, 0xc4, 0xb2, 0x61, 0x71,
0x1e, 0x28, 0x92, 0xa6, 0x61, 0x72, 0x28, 0x80, 0xc5, 0xd0, 0x13, 0xd3,
0x93, 0xd4, 0x04, 0x81, 0x60, 0x26, 0x08, 0x44, 0x33, 0x41, 0x18, 0x8e,
0x0d, 0x42, 0x36, 0x6c, 0x58, 0x06, 0xeb, 0xa2, 0x24, 0x6c, 0xc0, 0x06,
0x4a, 0xdb, 0x20, 0x54, 0x1b, 0x93, 0x29, 0xab, 0x2f, 0xaa, 0x30, 0xb9,
0xb3, 0x32, 0xba, 0x09, 0x02, 0xe1, 0x6c, 0x58, 0x9c, 0xee, 0xf2, 0x24,
0x6a, 0xc0, 0x1c, 0x4a, 0xdb, 0x10, 0x7c, 0x1b, 0x06, 0x0e, 0x0c, 0x80,
0x0d, 0x05, 0xd3, 0x84, 0x01, 0x00, 0x54, 0x61, 0x63, 0xb3, 0x6b, 0x73,
0x49, 0x23, 0x2b, 0x73, 0xa3, 0x9b, 0x12, 0x04, 0x55, 0xc8, 0xf0, 0x5c,
0xec, 0xca, 0xe4, 0xe6, 0xd2, 0xde, 0xdc, 0xa6, 0x04, 0x44, 0x13, 0x32,
0x3c, 0x17, 0xbb, 0x30, 0x36, 0xbb, 0x32, 0xb9, 0x29, 0x81, 0x51, 0x87,
0x0c, 0xcf, 0x65, 0x0e, 0x2d, 0x8c, 0xac, 0x4c, 0xae, 0xe9, 0x8d, 0xac,
0x8c, 0x6d, 0x4a, 0x80, 0xd4, 0x21, 0xc3, 0x73, 0xb1, 0x4b, 0x2b, 0xbb,
0x4b, 0x22, 0x9b, 0xa2, 0x0b, 0xa3, 0x2b, 0x9b, 0x12, 0x28, 0x75, 0xc8,
0xf0, 0x5c, 0xca, 0xdc, 0xe8, 0xe4, 0xf2, 0xa0, 0xde, 0xd2, 0xdc, 0xe8,
0xe6, 0xa6, 0x04, 0x61, 0x00, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
0xb0, 0xc3, 0x0c, 0xc4, 0x21, 0x07, 0x7c, 0x70, 0x03, 0x7a, 0x28, 0x87,
0x76, 0x80, 0x87, 0x19, 0xd1, 0x43, 0x0e, 0xf8, 0xe0, 0x06, 0xe4, 0x20,
0x0e, 0xe7, 0xe0, 0x06, 0xf6, 0x10, 0x0e, 0xf2, 0xc0, 0x0e, 0xe1, 0x90,
0x0f, 0xef, 0x50, 0x0f, 0xf4, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00,
0x0b, 0x00, 0x00, 0x00, 0x16, 0x30, 0x0d, 0x97, 0xef, 0x3c, 0xfe, 0xe2,
0x00, 0x83, 0xd8, 0x3c, 0xd4, 0xe4, 0x23, 0xb7, 0x6d, 0x02, 0xd5, 0x70,
0xf9, 0xce, 0xe3, 0x4b, 0x93, 0x13, 0x11, 0x28, 0x35, 0x3d, 0xd4, 0xe4,
0x23, 0xb7, 0x6d, 0x00, 0xc7, 0x23, 0xfd, 0x0c, 0x80, 0x34, 0x00, 0x00,
0x61, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x13, 0x04, 0x41, 0x2c,
0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x34, 0x85, 0x30, 0x03,
0x50, 0x0a, 0x00, 0x00, 0x23, 0x06, 0x09, 0x00, 0x82, 0x60, 0x50, 0x48,
0x03, 0xd4, 0x20, 0xc2, 0x88, 0x41, 0x02, 0x80, 0x20, 0x18, 0x1c, 0x92,
0xe0, 0x38, 0x49, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
@@ -0,0 +1,690 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
// GENERATED by DXC 1.9.2609 from wave64_emulation.hlsl by compile.sh; do not edit.
#if 0
;
; Note: shader requires additional functionality:
; Wave level operations
;
;
; Input signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; no parameters
;
; Output signature:
;
; Name Index Mask Register SysValue Format Used
; -------------------- ----- ------ -------- -------- ------- ------
; no parameters
; shader hash: 3b5d2d89787d3b545fe7ad6022db2e55
;
; Pipeline Runtime Information:
;
;PSVRuntimeInfo:
; Compute Shader
; NumThreads=(64,1,1)
; MinimumExpectedWaveLaneCount: 0
; MaximumExpectedWaveLaneCount: 4294967295
; UsesViewID: false
; SigInputElements: 0
; SigOutputElements: 0
; SigPatchConstOrPrimElements: 0
; SigInputVectors: 0
; SigOutputVectors[0]: 0
; SigOutputVectors[1]: 0
; SigOutputVectors[2]: 0
; SigOutputVectors[3]: 0
; EntryFunctionName: main
;
;
; Buffer Definitions:
;
; Resource bind info for Out
; {
;
; uint $Element; ; Offset: 0 Size: 4
;
; }
;
;
; Resource Bindings:
;
; Name Type Format Dim ID HLSL Bind Count
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
; Out UAV struct r/w U0 u0 1
;
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
target triple = "dxil-ms-dx"
%dx.types.Handle = type { i8* }
%dx.types.ResBind = type { i32, i32, i32, i8 }
%dx.types.ResourceProperties = type { i32, i32 }
%dx.types.fouri32 = type { i32, i32, i32, i32 }
%"class.RWStructuredBuffer<unsigned int>" = type { i32 }
@"\01?g_pred@@3PAIA" = external addrspace(3) global [64 x i32], align 4
@"\01?g_val@@3PAIA" = external addrspace(3) global [64 x i32], align 4
@"\01?g_wave_ballot@@3PAIA" = external addrspace(3) global [64 x i32], align 4
@"\01?g_wave_sum@@3PAIA" = external addrspace(3) global [64 x i32], align 4
define void @main() {
%1 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 0, i8 1 }, i32 0, i1 false) ; CreateHandleFromBinding(bind,index,nonUniformIndex)
%2 = call i32 @dx.op.flattenedThreadIdInGroup.i32(i32 96) ; FlattenedThreadIdInGroup()
%3 = mul i32 %2, 7
%4 = add i32 %3, 3
%5 = and i32 %4, 31
%6 = mul i32 %2, 13
%7 = add i32 %6, 5
%8 = urem i32 %7, 3
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
%11 = getelementptr [64 x i32], [64 x i32] addrspace(3)* @"\01?g_pred@@3PAIA", i32 0, i32 %2
store i32 %10, i32 addrspace(3)* %11, align 4, !tbaa !11
%12 = getelementptr [64 x i32], [64 x i32] addrspace(3)* @"\01?g_val@@3PAIA", i32 0, i32 %2
store i32 %5, i32 addrspace(3)* %12, align 4, !tbaa !11
call void @dx.op.barrier(i32 80, i32 9) ; Barrier(barrierMode)
br label %33
; <label>:13 ; preds = %60
%14 = shl i32 %2, 3
%15 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %15, i32 %14, i32 0, i32 %52, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
%16 = or i32 %14, 1
%17 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %17, i32 %16, i32 0, i32 %51, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
%18 = or i32 %14, 2
%19 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %19, i32 %18, i32 0, i32 %62, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
%20 = load i32, i32 addrspace(3)* getelementptr inbounds ([64 x i32], [64 x i32] addrspace(3)* @"\01?g_val@@3PAIA", i32 0, i32 37), align 4, !tbaa !11
%21 = or i32 %14, 3
%22 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %22, i32 %21, i32 0, i32 %20, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
%23 = or i32 %14, 4
%24 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %24, i32 %23, i32 0, i32 %63, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
%25 = call i32 @dx.op.waveGetLaneCount(i32 112) ; WaveGetLaneCount()
%26 = udiv i32 %2, %25
%27 = call %dx.types.fouri32 @dx.op.waveActiveBallot(i32 116, i1 %9) ; WaveActiveBallot(cond)
%28 = extractvalue %dx.types.fouri32 %27, 0
%29 = extractvalue %dx.types.fouri32 %27, 1
%30 = call i32 @dx.op.wavePrefixOp.i32(i32 121, i32 %5, i8 0, i8 1) ; WavePrefixOp(value,op,sop)
%31 = call i32 @dx.op.waveActiveOp.i32(i32 119, i32 %5, i8 0, i8 1) ; WaveActiveOp(value,op,sop)
%32 = call i1 @dx.op.waveIsFirstLane(i32 110) ; WaveIsFirstLane()
br i1 %32, label %66, label %69
; <label>:33 ; preds = %60, %0
%34 = phi i32 [ 0, %0 ], [ %63, %60 ]
%35 = phi i32 [ 0, %0 ], [ %62, %60 ]
%36 = phi i32 [ 0, %0 ], [ %51, %60 ]
%37 = phi i32 [ 0, %0 ], [ %52, %60 ]
%38 = phi i32 [ 0, %0 ], [ %64, %60 ]
%39 = getelementptr [64 x i32], [64 x i32] addrspace(3)* @"\01?g_pred@@3PAIA", i32 0, i32 %38
%40 = load i32, i32 addrspace(3)* %39, align 4, !tbaa !11
%41 = icmp eq i32 %40, 0
br i1 %41, label %50, label %42
; <label>:42 ; preds = %33
%43 = icmp ult i32 %38, 32
%44 = and i32 %38, 31
%45 = shl i32 1, %44
br i1 %43, label %46, label %48
; <label>:46 ; preds = %42
%47 = or i32 %45, %37
br label %50
; <label>:48 ; preds = %42
%49 = or i32 %45, %36
br label %50
; <label>:50 ; preds = %48, %46, %33
%51 = phi i32 [ %36, %46 ], [ %49, %48 ], [ %36, %33 ]
%52 = phi i32 [ %47, %46 ], [ %37, %48 ], [ %37, %33 ]
%53 = icmp ult i32 %38, %2
%54 = getelementptr [64 x i32], [64 x i32] addrspace(3)* @"\01?g_val@@3PAIA", i32 0, i32 %38
br i1 %53, label %57, label %55
; <label>:55 ; preds = %50
%56 = load i32, i32 addrspace(3)* %54, align 4, !tbaa !11
br label %60
; <label>:57 ; preds = %50
%58 = load i32, i32 addrspace(3)* %54, align 4, !tbaa !11
%59 = add i32 %58, %35
br label %60
; <label>:60 ; preds = %57, %55
%61 = phi i32 [ %58, %57 ], [ %56, %55 ]
%62 = phi i32 [ %59, %57 ], [ %35, %55 ]
%63 = add i32 %61, %34
%64 = add nuw nsw i32 %38, 1
%65 = icmp eq i32 %64, 64
br i1 %65, label %13, label %33
; <label>:66 ; preds = %13
%67 = getelementptr [64 x i32], [64 x i32] addrspace(3)* @"\01?g_wave_ballot@@3PAIA", i32 0, i32 %26
store i32 %28, i32 addrspace(3)* %67, align 4, !tbaa !11
%68 = getelementptr [64 x i32], [64 x i32] addrspace(3)* @"\01?g_wave_sum@@3PAIA", i32 0, i32 %26
store i32 %31, i32 addrspace(3)* %68, align 4, !tbaa !11
br label %69
; <label>:69 ; preds = %66, %13
call void @dx.op.barrier(i32 80, i32 9) ; Barrier(barrierMode)
%70 = icmp eq i32 %26, 0
br i1 %70, label %73, label %71
; <label>:71 ; preds = %69
br label %76
; <label>:72 ; preds = %76
br label %73
; <label>:73 ; preds = %72, %69
%74 = phi i32 [ 0, %69 ], [ %81, %72 ]
%75 = icmp eq i32 %25, 32
br i1 %75, label %84, label %87
; <label>:76 ; preds = %76, %71
%77 = phi i32 [ %81, %76 ], [ 0, %71 ]
%78 = phi i32 [ %82, %76 ], [ 0, %71 ]
%79 = getelementptr [64 x i32], [64 x i32] addrspace(3)* @"\01?g_wave_sum@@3PAIA", i32 0, i32 %78
%80 = load i32, i32 addrspace(3)* %79, align 4, !tbaa !11
%81 = add i32 %80, %77
%82 = add nuw i32 %78, 1
%83 = icmp ult i32 %82, %26
br i1 %83, label %76, label %72
; <label>:84 ; preds = %73
%85 = load i32, i32 addrspace(3)* getelementptr inbounds ([64 x i32], [64 x i32] addrspace(3)* @"\01?g_wave_ballot@@3PAIA", i32 0, i32 0), align 4, !tbaa !11
%86 = load i32, i32 addrspace(3)* getelementptr inbounds ([64 x i32], [64 x i32] addrspace(3)* @"\01?g_wave_ballot@@3PAIA", i32 0, i32 1), align 4, !tbaa !11
br label %91
; <label>:87 ; preds = %73
%88 = icmp eq i32 %25, 64
%89 = select i1 %88, i32 %28, i32 0
%90 = select i1 %88, i32 %29, i32 0
br label %91
; <label>:91 ; preds = %87, %84
%92 = phi i32 [ %85, %84 ], [ %89, %87 ]
%93 = phi i32 [ %86, %84 ], [ %90, %87 ]
%94 = or i32 %14, 5
%95 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %95, i32 %94, i32 0, i32 %92, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
%96 = or i32 %14, 6
%97 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %97, i32 %96, i32 0, i32 %93, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
%98 = add i32 %74, %30
%99 = or i32 %14, 7
%100 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4108, i32 4 }) ; AnnotateHandle(res,props) resource: RWStructuredBuffer<stride=4>
call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %100, i32 %99, i32 0, i32 %98, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
ret void
}
; Function Attrs: nounwind readnone
declare i32 @dx.op.flattenedThreadIdInGroup.i32(i32) #0
; Function Attrs: noduplicate nounwind
declare void @dx.op.barrier(i32, i32) #1
; Function Attrs: nounwind
declare void @dx.op.rawBufferStore.i32(i32, %dx.types.Handle, i32, i32, i32, i32, i32, i32, i8, i32) #2
; Function Attrs: nounwind readnone
declare i32 @dx.op.waveGetLaneCount(i32) #0
; Function Attrs: nounwind
declare %dx.types.fouri32 @dx.op.waveActiveBallot(i32, i1) #2
; Function Attrs: nounwind
declare i32 @dx.op.waveActiveOp.i32(i32, i32, i8, i8) #2
; Function Attrs: nounwind
declare i32 @dx.op.wavePrefixOp.i32(i32, i32, i8, i8) #2
; Function Attrs: nounwind
declare i1 @dx.op.waveIsFirstLane(i32) #2
; Function Attrs: nounwind readnone
declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #0
; Function Attrs: nounwind readnone
declare %dx.types.Handle @dx.op.createHandleFromBinding(i32, %dx.types.ResBind, i32, i1) #0
attributes #0 = { nounwind readnone }
attributes #1 = { noduplicate nounwind }
attributes #2 = { nounwind }
!llvm.ident = !{!0}
!dx.version = !{!1}
!dx.valver = !{!2}
!dx.shaderModel = !{!3}
!dx.resources = !{!4}
!dx.entryPoints = !{!8}
!0 = !{!"dxcoob 1.9.2609.5 (01b62ad47)"}
!1 = !{i32 1, i32 6}
!2 = !{i32 1, i32 9}
!3 = !{!"cs", i32 6, i32 6}
!4 = !{null, !5, null, null}
!5 = !{!6}
!6 = !{i32 0, %"class.RWStructuredBuffer<unsigned int>"* undef, !"", i32 0, i32 0, i32 1, i32 12, i1 false, i1 false, i1 false, !7}
!7 = !{i32 1, i32 4}
!8 = !{void ()* @main, !"main", null, !4, !9}
!9 = !{i32 0, i64 524304, i32 4, !10}
!10 = !{i32 64, i32 1, i32 1}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C/C++ TBAA"}
#endif
const unsigned char g_wave64_emulation_cs[] = {
0x44, 0x58, 0x42, 0x43, 0x9b, 0xbd, 0xc8, 0xad, 0x5a, 0x85, 0x09, 0xde,
0x94, 0xc7, 0x79, 0x0b, 0x29, 0x89, 0xdb, 0xc6, 0x01, 0x00, 0x00, 0x00,
0xe0, 0x12, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0xdc, 0x00, 0x00, 0x00, 0x4c, 0x08, 0x00, 0x00, 0x68, 0x08, 0x00, 0x00,
0x53, 0x46, 0x49, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4f, 0x53, 0x47, 0x31,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x50, 0x53, 0x56, 0x30, 0x68, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x41, 0x54, 0x68, 0x07, 0x00, 0x00,
0x66, 0x00, 0x05, 0x00, 0xda, 0x01, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4c,
0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x50, 0x07, 0x00, 0x00,
0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0xd1, 0x01, 0x00, 0x00,
0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
0x80, 0x18, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xc4, 0x10, 0x32, 0x14,
0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x62, 0x88, 0x48, 0x90, 0x14, 0x20,
0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42, 0xe4, 0x48, 0x0e, 0x90,
0x11, 0x23, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c, 0xe1, 0x83, 0xe5, 0x8a,
0x04, 0x31, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x1b, 0x8c, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0x40, 0x02, 0xa8, 0x0d,
0x86, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0x00, 0xd2, 0x06, 0x62,
0xf8, 0xff, 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x49, 0x18, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42, 0x20, 0x4c, 0x08, 0x06,
0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00,
0x32, 0x22, 0x88, 0x09, 0x20, 0x64, 0x85, 0x04, 0x13, 0x23, 0xa4, 0x84,
0x04, 0x13, 0x23, 0xe3, 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8c, 0x8c,
0x0b, 0x84, 0xc4, 0x4c, 0x10, 0x84, 0xc1, 0x1c, 0x01, 0x18, 0x24, 0x10,
0x30, 0x88, 0x10, 0x0c, 0x23, 0x00, 0x25, 0x18, 0x88, 0x28, 0x02, 0x00,
0x90, 0x51, 0x86, 0x01, 0x00, 0x08, 0x99, 0x23, 0x40, 0x48, 0xb9, 0x67,
0xb8, 0xfc, 0x09, 0x7b, 0x08, 0xc9, 0x0f, 0x81, 0x66, 0x58, 0x08, 0x14,
0x2c, 0x65, 0x19, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14, 0x80, 0x9a,
0x83, 0x86, 0xcb, 0x9f, 0xb0, 0x87, 0x90, 0xfc, 0xc2, 0xa1, 0x22, 0xe4,
0xb6, 0x11, 0x01, 0x00, 0x00, 0x30, 0x47, 0x10, 0x94, 0xe1, 0x01, 0x20,
0x8a, 0x4a, 0x01, 0x00, 0x80, 0xa2, 0xd0, 0x54, 0x04, 0x08, 0xa0, 0xea,
0xb6, 0xe1, 0xf2, 0x27, 0xec, 0x21, 0x24, 0x7f, 0x25, 0x24, 0x87, 0x8a,
0x04, 0x22, 0x8d, 0x9c, 0x87, 0x88, 0x26, 0x84, 0x90, 0x90, 0x00, 0x00,
0x85, 0x60, 0x00, 0xe6, 0x22, 0xec, 0xa0, 0xe1, 0xf2, 0x27, 0xec, 0x21,
0x24, 0x7f, 0x25, 0xa4, 0x0d, 0x69, 0x06, 0x44, 0x00, 0x00, 0xa0, 0x94,
0x82, 0x01, 0x34, 0x00, 0xa2, 0x6d, 0x20, 0x60, 0x26, 0x33, 0x18, 0x07,
0x76, 0x08, 0x87, 0x79, 0x98, 0x07, 0x37, 0x90, 0x85, 0x5b, 0x98, 0x05,
0x7a, 0x90, 0x87, 0x7a, 0x18, 0x07, 0x7a, 0xa8, 0x07, 0x79, 0x28, 0x07,
0x72, 0x10, 0x85, 0x7a, 0x30, 0x07, 0x73, 0x28, 0x07, 0x79, 0xe0, 0x83,
0x7a, 0x70, 0x87, 0x79, 0x48, 0x87, 0x73, 0x70, 0x87, 0x72, 0x20, 0x07,
0x30, 0x48, 0x07, 0x77, 0xa0, 0x07, 0x3f, 0x40, 0x01, 0x40, 0xde, 0x1c,
0x01, 0x28, 0x00, 0x00, 0x13, 0x14, 0x72, 0xc0, 0x87, 0x74, 0x60, 0x87,
0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xc0, 0x87, 0x0d, 0xaf, 0x50,
0x0e, 0x6d, 0xd0, 0x0e, 0x7a, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x30,
0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0,
0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x73, 0x20,
0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90,
0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x10,
0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
0x07, 0x76, 0x40, 0x07, 0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60,
0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x3a, 0x0f,
0x24, 0x90, 0x21, 0x23, 0x45, 0x44, 0x00, 0x76, 0x00, 0x30, 0x3b, 0x00,
0x98, 0x1d, 0x00, 0xcc, 0x0e, 0x00, 0x1e, 0xf2, 0x10, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xe4, 0x31, 0x80, 0x00,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xc8, 0x83, 0x00,
0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x90, 0xa7,
0x01, 0x02, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21,
0x8f, 0x01, 0x04, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x43, 0x9e, 0x08, 0x08, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x86, 0x3c, 0x13, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x79, 0x26, 0x20, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0xf2, 0x54, 0x40, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x30, 0xe4, 0xc1, 0x80, 0x00, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xc8, 0xb3, 0x01, 0x01, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x16, 0x08, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x18, 0x19, 0x11, 0x4c, 0x90,
0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x02, 0x4a, 0xa0, 0x18, 0x46,
0x00, 0x0a, 0xa3, 0x10, 0xca, 0xa0, 0x1c, 0x4a, 0x61, 0x06, 0xa0, 0x00,
0x03, 0x0a, 0x10, 0xa2, 0x2c, 0x8a, 0xa0, 0x20, 0xca, 0x3c, 0xa0, 0x4c,
0x0a, 0x84, 0xa0, 0x11, 0x00, 0x02, 0x0b, 0x14, 0x10, 0x88, 0xbe, 0x19,
0x00, 0xf2, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x73, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4,
0x8e, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45,
0xc6, 0x06, 0x26, 0xc7, 0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46,
0x26, 0x8c, 0x8c, 0xe6, 0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x80, 0x67,
0x82, 0x00, 0x40, 0x1b, 0x84, 0x81, 0x98, 0x20, 0x00, 0xd1, 0x06, 0xc1,
0x30, 0x28, 0x8c, 0xcd, 0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x7c, 0x62,
0xc0, 0xe1, 0xa9, 0x8e, 0x6e, 0x82, 0x00, 0x48, 0x13, 0x04, 0x08, 0x0c,
0x26, 0x08, 0xc0, 0xb4, 0x41, 0x18, 0x9c, 0x0d, 0x8b, 0xa1, 0x2c, 0x86,
0x31, 0x30, 0x4d, 0xd3, 0x3c, 0x1b, 0x02, 0x68, 0x03, 0x01, 0x44, 0x00,
0x30, 0x41, 0xf0, 0xc6, 0x80, 0x01, 0xda, 0x04, 0x01, 0xa0, 0x26, 0x08,
0x40, 0x35, 0x41, 0x00, 0xac, 0x0d, 0x06, 0x41, 0x55, 0x86, 0x75, 0x4d,
0x10, 0x80, 0x6b, 0x83, 0x60, 0x64, 0x1b, 0x02, 0x6d, 0x83, 0x60, 0x6c,
0x1b, 0x06, 0x07, 0xe3, 0x36, 0x0c, 0xc6, 0xd4, 0x4d, 0x10, 0x0a, 0x62,
0x03, 0xb0, 0x61, 0x30, 0xc0, 0x00, 0x0c, 0x36, 0x04, 0x61, 0xb0, 0x61,
0x18, 0x3e, 0x31, 0x20, 0xd1, 0x16, 0x96, 0xe6, 0x36, 0x41, 0x00, 0x83,
0x30, 0x98, 0x20, 0x00, 0xd8, 0x86, 0xc1, 0x0c, 0x86, 0x61, 0x03, 0x61,
0x94, 0x81, 0x73, 0x06, 0x1b, 0x8a, 0x8f, 0x0c, 0x00, 0x09, 0x0d, 0x08,
0x85, 0xc9, 0xc9, 0x85, 0xe5, 0x7d, 0xd1, 0x9d, 0xcd, 0xb5, 0x7d, 0x89,
0xe5, 0xd1, 0x95, 0xcd, 0x4d, 0x10, 0x80, 0x8c, 0x4f, 0x98, 0x9c, 0x5c,
0x58, 0xde, 0x17, 0xdd, 0xd9, 0x5c, 0xdb, 0x17, 0x1b, 0xd9, 0x1c, 0xdd,
0x04, 0x01, 0xd0, 0x78, 0x88, 0x85, 0xc9, 0xc9, 0xa5, 0x95, 0xc9, 0x4d,
0x10, 0x80, 0x8d, 0x88, 0x98, 0x5c, 0x98, 0xdb, 0x18, 0x5a, 0xd9, 0xdc,
0x04, 0x01, 0xe0, 0x58, 0xa4, 0xb9, 0xcd, 0xd1, 0xcd, 0x4d, 0x10, 0x80,
0x8e, 0x44, 0x9a, 0x1b, 0xdd, 0xdc, 0x04, 0x01, 0xf0, 0x98, 0xd0, 0x95,
0xe1, 0x7d, 0xcd, 0xd1, 0xbd, 0xc9, 0x95, 0xb1, 0xa8, 0x4b, 0x73, 0xa3,
0x9b, 0x9b, 0x20, 0x00, 0xdf, 0x06, 0x48, 0x0d, 0xd6, 0x80, 0x0d, 0xda,
0xc0, 0x0d, 0xde, 0x00, 0x0e, 0xe2, 0x40, 0x0e, 0xe6, 0x80, 0x0e, 0xea,
0xc0, 0x0e, 0xe2, 0xe0, 0x0e, 0xf0, 0xa0, 0x0a, 0x1b, 0x9b, 0x5d, 0x9b,
0x4b, 0x1a, 0x59, 0x99, 0x1b, 0xdd, 0x94, 0x20, 0xa8, 0x42, 0x86, 0xe7,
0x62, 0x57, 0x26, 0x37, 0x97, 0xf6, 0xe6, 0x36, 0x25, 0x20, 0x9a, 0x90,
0xe1, 0xb9, 0xd8, 0x85, 0xb1, 0xd9, 0x95, 0xc9, 0x4d, 0x09, 0x8c, 0x3a,
0x64, 0x78, 0x2e, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x64,
0x65, 0x6c, 0x53, 0x02, 0xa4, 0x0c, 0x19, 0x9e, 0x8b, 0x5c, 0xd9, 0xdc,
0x5b, 0x9d, 0xdc, 0x58, 0xd9, 0xdc, 0x94, 0x20, 0xaa, 0x44, 0x86, 0xe7,
0x42, 0x97, 0x07, 0x57, 0x16, 0xe4, 0xe6, 0xf6, 0x46, 0x17, 0x46, 0x97,
0xf6, 0xe6, 0x36, 0x37, 0x45, 0xe8, 0xc4, 0xa0, 0x0e, 0x19, 0x9e, 0x4b,
0x99, 0x1b, 0x9d, 0x5c, 0x1e, 0xd4, 0x5b, 0x9a, 0x1b, 0xdd, 0xdc, 0x94,
0x00, 0x0d, 0xba, 0x90, 0xe1, 0xb9, 0x8c, 0xbd, 0xd5, 0xb9, 0xd1, 0x95,
0xc9, 0xcd, 0x4d, 0x09, 0xf0, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x51, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
0xb0, 0xc3, 0x0c, 0xc4, 0x21, 0x07, 0x7c, 0x70, 0x03, 0x7a, 0x28, 0x87,
0x76, 0x80, 0x87, 0x19, 0xd1, 0x43, 0x0e, 0xf8, 0xe0, 0x06, 0xe4, 0x20,
0x0e, 0xe7, 0xe0, 0x06, 0xf6, 0x10, 0x0e, 0xf2, 0xc0, 0x0e, 0xe1, 0x90,
0x0f, 0xef, 0x50, 0x0f, 0xf4, 0x30, 0x83, 0x81, 0xc8, 0x01, 0x1f, 0xdc,
0x40, 0x1c, 0xe4, 0xa1, 0x1c, 0xc2, 0x61, 0x1d, 0xdc, 0x40, 0x1c, 0xe4,
0x01, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00,
0x05, 0xf0, 0x04, 0x7e, 0xe7, 0x2f, 0x5c, 0x5e, 0x26, 0x03, 0x81, 0x33,
0x68, 0x30, 0x19, 0xac, 0x00, 0x27, 0xf0, 0x3b, 0x7f, 0xed, 0x61, 0x36,
0x10, 0x38, 0x83, 0x06, 0x93, 0xc1, 0x12, 0xb0, 0x02, 0xbf, 0xf3, 0xf7,
0x1e, 0xb6, 0x97, 0xbf, 0xe2, 0x30, 0x9b, 0xfd, 0xa6, 0x03, 0x81, 0x33,
0x68, 0x30, 0x19, 0xac, 0x81, 0x29, 0xf0, 0x3b, 0x7f, 0xef, 0x61, 0x7b,
0xf9, 0x3b, 0xaf, 0xb7, 0x81, 0xc0, 0x19, 0x34, 0x98, 0x0c, 0x5a, 0x03,
0x35, 0x5c, 0xbe, 0xf3, 0xf8, 0x40, 0xd3, 0x38, 0x13, 0x30, 0x11, 0x21,
0xd0, 0x0c, 0x0b, 0x61, 0x06, 0xcd, 0x70, 0xf9, 0xce, 0xe3, 0x07, 0x40,
0x14, 0x21, 0x44, 0x64, 0x0e, 0xdd, 0x70, 0xf9, 0xce, 0xe3, 0x0b, 0x11,
0x01, 0x4c, 0x44, 0x08, 0x34, 0xc3, 0x42, 0x7c, 0x91, 0xc3, 0x6c, 0x48,
0x33, 0x20, 0x8d, 0x61, 0x05, 0x62, 0x30, 0x5c, 0xbe, 0xf3, 0xf8, 0xc5,
0x02, 0x4c, 0x13, 0xd1, 0x10, 0x43, 0x7b, 0x44, 0x04, 0x30, 0x88, 0x83,
0xd8, 0x80, 0x91, 0x43, 0x3d, 0x3e, 0x72, 0xdb, 0x76, 0x80, 0x0d, 0x97,
0xef, 0x3c, 0x7e, 0x04, 0x58, 0x1b, 0x55, 0x14, 0x44, 0xc4, 0x4e, 0x4e,
0x44, 0xf8, 0xc8, 0x6d, 0x5b, 0x82, 0x35, 0x5c, 0xbe, 0xf3, 0xf8, 0x16,
0x50, 0x11, 0x9a, 0x30, 0x21, 0x15, 0xb1, 0x01, 0xcb, 0xe2, 0x4c, 0xa6,
0x60, 0x0d, 0x97, 0xef, 0x3c, 0xbe, 0x05, 0x54, 0x84, 0x26, 0x4c, 0x48,
0x45, 0xa0, 0x8f, 0x8f, 0xdc, 0xb6, 0x21, 0x58, 0xc3, 0xe5, 0x3b, 0x8f,
0x6f, 0x01, 0x15, 0x01, 0x12, 0x53, 0x09, 0x34, 0x04, 0xe7, 0x50, 0xcd,
0x64, 0x0c, 0xd5, 0x70, 0xf9, 0xce, 0xe3, 0x5b, 0x40, 0x45, 0x88, 0xd2,
0x87, 0x44, 0xd2, 0x54, 0x02, 0x0d, 0x61, 0x0b, 0xd6, 0x70, 0xf9, 0xce,
0xe3, 0x5b, 0x40, 0x45, 0xa4, 0x11, 0x51, 0x20, 0x17, 0xfa, 0xf8, 0xc8,
0x6d, 0x1b, 0x01, 0xc1, 0x00, 0x48, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x48, 0x41, 0x53, 0x48, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3b, 0x5d, 0x2d, 0x89, 0x78, 0x7d, 0x3b, 0x54, 0x5f, 0xe7, 0xad, 0x60,
0x22, 0xdb, 0x2e, 0x55, 0x44, 0x58, 0x49, 0x4c, 0x70, 0x0a, 0x00, 0x00,
0x66, 0x00, 0x05, 0x00, 0x9c, 0x02, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4c,
0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x58, 0x0a, 0x00, 0x00,
0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0x93, 0x02, 0x00, 0x00,
0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
0x80, 0x18, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xc4, 0x10, 0x32, 0x14,
0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x62, 0x88, 0x48, 0x90, 0x14, 0x20,
0x43, 0x46, 0x88, 0xa5, 0x00, 0x19, 0x32, 0x42, 0xe4, 0x48, 0x0e, 0x90,
0x11, 0x23, 0xc4, 0x50, 0x41, 0x51, 0x81, 0x8c, 0xe1, 0x83, 0xe5, 0x8a,
0x04, 0x31, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x1b, 0x8c, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0x40, 0x02, 0xa8, 0x0d,
0x86, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0x00, 0xd2, 0x06, 0x62,
0xf8, 0xff, 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x49, 0x18, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42, 0x20, 0x4c, 0x08, 0x06,
0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
0x32, 0x22, 0x88, 0x09, 0x20, 0x64, 0x85, 0x04, 0x13, 0x23, 0xa4, 0x84,
0x04, 0x13, 0x23, 0xe3, 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8c, 0x8c,
0x0b, 0x84, 0xc4, 0x4c, 0x10, 0x8c, 0xc1, 0x1c, 0x01, 0x18, 0x24, 0x10,
0x30, 0x88, 0x10, 0x0c, 0x23, 0x00, 0x25, 0x18, 0x88, 0x28, 0x02, 0x00,
0x90, 0x51, 0x86, 0x01, 0x00, 0x08, 0x99, 0x23, 0x40, 0x48, 0xb9, 0x67,
0xb8, 0xfc, 0x09, 0x7b, 0x08, 0xc9, 0x0f, 0x81, 0x66, 0x58, 0x08, 0x14,
0x2c, 0x65, 0x19, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14, 0x80, 0x9a,
0x83, 0x86, 0xcb, 0x9f, 0xb0, 0x87, 0x90, 0xfc, 0xc2, 0xa1, 0x22, 0xe4,
0xb6, 0x11, 0x01, 0x00, 0x00, 0x30, 0x47, 0x10, 0x94, 0xe1, 0x01, 0x20,
0x8a, 0x4a, 0x01, 0x00, 0x80, 0xa2, 0xd0, 0x54, 0x04, 0x08, 0xa0, 0xea,
0xb6, 0xe1, 0xf2, 0x27, 0xec, 0x21, 0x24, 0x7f, 0x25, 0x24, 0x87, 0x8a,
0x04, 0x22, 0x8d, 0x9c, 0x87, 0x88, 0x26, 0x84, 0x90, 0x90, 0x00, 0x00,
0x85, 0x60, 0x00, 0xe6, 0x22, 0xec, 0xa0, 0xe1, 0xf2, 0x27, 0xec, 0x21,
0x24, 0x7f, 0x25, 0xa4, 0x0d, 0x69, 0x06, 0x44, 0x00, 0x00, 0xa0, 0x94,
0x82, 0x01, 0x34, 0x00, 0xa2, 0x6d, 0x20, 0x60, 0x26, 0x33, 0x18, 0x07,
0x76, 0x08, 0x87, 0x79, 0x98, 0x07, 0x37, 0x90, 0x85, 0x5b, 0x98, 0x05,
0x7a, 0x90, 0x87, 0x7a, 0x18, 0x07, 0x7a, 0xa8, 0x07, 0x79, 0x28, 0x07,
0x72, 0x10, 0x85, 0x7a, 0x30, 0x07, 0x73, 0x28, 0x07, 0x79, 0xe0, 0x83,
0x7a, 0x70, 0x87, 0x79, 0x48, 0x87, 0x73, 0x70, 0x87, 0x72, 0x20, 0x07,
0x30, 0x48, 0x07, 0x77, 0xa0, 0x07, 0x3f, 0x40, 0x01, 0x40, 0xde, 0x1c,
0x01, 0x28, 0x0c, 0x22, 0x00, 0xc3, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
0x13, 0x14, 0x72, 0xc0, 0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79,
0x68, 0x03, 0x72, 0xc0, 0x87, 0x0d, 0xaf, 0x50, 0x0e, 0x6d, 0xd0, 0x0e,
0x7a, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07,
0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0, 0x07, 0x73, 0x20, 0x07,
0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e,
0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe9, 0x30, 0x07,
0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x76, 0x40, 0x07,
0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x10, 0x07, 0x76, 0xa0, 0x07,
0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07,
0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07,
0x72, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x3a, 0x0f, 0x24, 0x90, 0x21, 0x23,
0x45, 0x44, 0x00, 0x76, 0x00, 0x30, 0x3b, 0x00, 0x98, 0x1d, 0x00, 0xcc,
0x0e, 0x00, 0x1e, 0xf2, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x30, 0xe4, 0x31, 0x80, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0xc8, 0x83, 0x00, 0x01, 0x20, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x90, 0xa7, 0x01, 0x02, 0x60, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21, 0x8f, 0x01, 0x04, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x9e, 0x08, 0x08,
0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x3c, 0x13,
0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x79,
0x26, 0x20, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0xf2, 0x54, 0x40, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x30, 0xe4, 0xc1, 0x80, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0xc8, 0xb3, 0x01, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x16, 0x08, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00,
0x32, 0x1e, 0x98, 0x14, 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47,
0xc6, 0x04, 0x43, 0x02, 0x4a, 0xa0, 0x18, 0x4a, 0x62, 0x04, 0xa0, 0x30,
0x0a, 0xa1, 0x00, 0x03, 0x08, 0x1a, 0x01, 0x20, 0x70, 0x04, 0xa0, 0x40,
0x01, 0x81, 0xe8, 0x9b, 0x01, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x90, 0x46, 0x02, 0x13, 0xc4,
0x8e, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x0c, 0x24, 0xc6, 0x25, 0xc7, 0x45,
0xc6, 0x06, 0x26, 0xc7, 0xa5, 0x06, 0x04, 0x05, 0x26, 0x46, 0xcc, 0x46,
0x26, 0x8c, 0x8c, 0xe6, 0x26, 0x65, 0x43, 0x10, 0x4c, 0x10, 0x80, 0x67,
0x82, 0x00, 0x40, 0x1b, 0x84, 0x81, 0x98, 0x20, 0x00, 0xd1, 0x06, 0x61,
0x30, 0x28, 0x8c, 0xcd, 0x6d, 0x18, 0x10, 0x82, 0x98, 0x20, 0x00, 0xd2,
0x04, 0xe1, 0xcb, 0x08, 0x4c, 0x10, 0x80, 0x69, 0x82, 0x00, 0x59, 0x13,
0x04, 0x80, 0xda, 0x20, 0x0c, 0xcf, 0x86, 0x45, 0x59, 0x18, 0x45, 0x19,
0x1a, 0xc7, 0x71, 0xa0, 0x0d, 0x41, 0xb4, 0x81, 0x00, 0x24, 0x00, 0x98,
0x20, 0x14, 0x04, 0x89, 0xb6, 0xb0, 0x34, 0xb7, 0x09, 0x02, 0x18, 0x60,
0x13, 0x04, 0xa0, 0xda, 0x30, 0x5c, 0xc3, 0xb0, 0x81, 0x50, 0xac, 0x07,
0xdb, 0x50, 0x50, 0x15, 0x30, 0x65, 0x1c, 0xd2, 0xdc, 0xe8, 0xf8, 0xbc,
0xb5, 0xb9, 0xa5, 0xc1, 0xbd, 0xd1, 0x95, 0xb9, 0xd1, 0x81, 0x8c, 0xa1,
0x85, 0xc9, 0x31, 0x9a, 0x4a, 0x6b, 0x83, 0x63, 0x2b, 0x03, 0x19, 0x7a,
0x19, 0x5a, 0x59, 0x01, 0xa1, 0x12, 0x0a, 0x0a, 0xda, 0x10, 0x74, 0x13,
0x04, 0x30, 0xb8, 0x36, 0x0c, 0x9c, 0xf7, 0x6d, 0x18, 0x36, 0x30, 0xf8,
0x36, 0x0c, 0x61, 0x10, 0x06, 0x5f, 0x15, 0x36, 0x36, 0xbb, 0x36, 0x97,
0x34, 0xb2, 0x32, 0x37, 0xba, 0x29, 0x41, 0x50, 0x85, 0x0c, 0xcf, 0xc5,
0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x6d, 0x4a, 0x40, 0x34, 0x21, 0xc3,
0x73, 0xb1, 0x0b, 0x63, 0xb3, 0x2b, 0x93, 0x9b, 0x12, 0x18, 0x75, 0xc8,
0xf0, 0x5c, 0xe6, 0xd0, 0xc2, 0xc8, 0xca, 0xe4, 0x9a, 0xde, 0xc8, 0xca,
0xd8, 0xa6, 0x04, 0x48, 0x19, 0x32, 0x3c, 0x17, 0xb9, 0xb2, 0xb9, 0xb7,
0x3a, 0xb9, 0xb1, 0xb2, 0xb9, 0x29, 0x81, 0x54, 0x87, 0x0c, 0xcf, 0xa5,
0xcc, 0x8d, 0x4e, 0x2e, 0x0f, 0xea, 0x2d, 0xcd, 0x8d, 0x6e, 0x6e, 0x4a,
0x90, 0x01, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00,
0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88,
0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73,
0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e,
0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30,
0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8,
0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b,
0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76,
0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e,
0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e,
0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61,
0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4,
0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76,
0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37,
0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76,
0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71,
0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e,
0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1,
0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61,
0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90,
0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8,
0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc,
0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc4,
0x21, 0x07, 0x7c, 0x70, 0x03, 0x7a, 0x28, 0x87, 0x76, 0x80, 0x87, 0x19,
0xd1, 0x43, 0x0e, 0xf8, 0xe0, 0x06, 0xe4, 0x20, 0x0e, 0xe7, 0xe0, 0x06,
0xf6, 0x10, 0x0e, 0xf2, 0xc0, 0x0e, 0xe1, 0x90, 0x0f, 0xef, 0x50, 0x0f,
0xf4, 0x30, 0x83, 0x81, 0xc8, 0x01, 0x1f, 0xdc, 0x40, 0x1c, 0xe4, 0xa1,
0x1c, 0xc2, 0x61, 0x1d, 0xdc, 0x40, 0x1c, 0xe4, 0x01, 0x00, 0x00, 0x00,
0x71, 0x20, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x05, 0xf0, 0x04, 0x7e,
0xe7, 0x2f, 0x5c, 0x5e, 0x26, 0x03, 0x81, 0x33, 0x68, 0x30, 0x19, 0xac,
0x00, 0x27, 0xf0, 0x3b, 0x7f, 0xed, 0x61, 0x36, 0x10, 0x38, 0x83, 0x06,
0x93, 0xc1, 0x12, 0xb0, 0x02, 0xbf, 0xf3, 0xf7, 0x1e, 0xb6, 0x97, 0xbf,
0xe2, 0x30, 0x9b, 0xfd, 0xa6, 0x03, 0x81, 0x33, 0x68, 0x30, 0x19, 0xac,
0x81, 0x29, 0xf0, 0x3b, 0x7f, 0xef, 0x61, 0x7b, 0xf9, 0x3b, 0xaf, 0xb7,
0x81, 0xc0, 0x19, 0x34, 0x98, 0x0c, 0x5a, 0x03, 0x35, 0x5c, 0xbe, 0xf3,
0xf8, 0x40, 0xd3, 0x38, 0x13, 0x30, 0x11, 0x21, 0xd0, 0x0c, 0x0b, 0x61,
0x06, 0xcd, 0x70, 0xf9, 0xce, 0xe3, 0x07, 0x40, 0x14, 0x21, 0x44, 0x64,
0x0e, 0xdd, 0x70, 0xf9, 0xce, 0xe3, 0x0b, 0x11, 0x01, 0x4c, 0x44, 0x08,
0x34, 0xc3, 0x42, 0x7c, 0x91, 0xc3, 0x6c, 0x48, 0x33, 0x20, 0x8d, 0x61,
0x05, 0x62, 0x30, 0x5c, 0xbe, 0xf3, 0xf8, 0xc5, 0x02, 0x4c, 0x13, 0xd1,
0x10, 0x43, 0x7b, 0x44, 0x04, 0x30, 0x88, 0x83, 0xd8, 0x80, 0x91, 0x43,
0x3d, 0x3e, 0x72, 0xdb, 0x76, 0x80, 0x0d, 0x97, 0xef, 0x3c, 0x7e, 0x04,
0x58, 0x1b, 0x55, 0x14, 0x44, 0xc4, 0x4e, 0x4e, 0x44, 0xf8, 0xc8, 0x6d,
0x5b, 0x82, 0x35, 0x5c, 0xbe, 0xf3, 0xf8, 0x16, 0x50, 0x11, 0x9a, 0x30,
0x21, 0x15, 0xb1, 0x01, 0xcb, 0xe2, 0x4c, 0xa6, 0x60, 0x0d, 0x97, 0xef,
0x3c, 0xbe, 0x05, 0x54, 0x84, 0x26, 0x4c, 0x48, 0x45, 0xa0, 0x8f, 0x8f,
0xdc, 0xb6, 0x21, 0x58, 0xc3, 0xe5, 0x3b, 0x8f, 0x6f, 0x01, 0x15, 0x01,
0x12, 0x53, 0x09, 0x34, 0x04, 0xe7, 0x50, 0xcd, 0x64, 0x0c, 0xd5, 0x70,
0xf9, 0xce, 0xe3, 0x5b, 0x40, 0x45, 0x88, 0xd2, 0x87, 0x44, 0xd2, 0x54,
0x02, 0x0d, 0x61, 0x0b, 0xd6, 0x70, 0xf9, 0xce, 0xe3, 0x5b, 0x40, 0x45,
0xa4, 0x11, 0x51, 0x20, 0x17, 0xfa, 0xf8, 0xc8, 0x6d, 0x1b, 0x01, 0xc1,
0x00, 0x48, 0x03, 0x00, 0x61, 0x20, 0x00, 0x00, 0xee, 0x00, 0x00, 0x00,
0x13, 0x04, 0x53, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00,
0x04, 0xcc, 0x00, 0x14, 0xec, 0x40, 0x61, 0x0a, 0x94, 0x41, 0x39, 0x94,
0x4f, 0x29, 0x14, 0x68, 0x40, 0x01, 0x95, 0xec, 0x40, 0x01, 0x07, 0x94,
0x46, 0x61, 0x02, 0x15, 0x41, 0x29, 0x15, 0x78, 0x40, 0xa1, 0x07, 0x94,
0x7c, 0x40, 0xb9, 0x07, 0x14, 0x77, 0x00, 0x29, 0x25, 0x30, 0x02, 0x40,
0xd7, 0x1c, 0x82, 0x19, 0x50, 0xa4, 0xcd, 0x41, 0x48, 0x92, 0xe4, 0x06,
0x14, 0x0e, 0x75, 0x04, 0x42, 0x00, 0x48, 0x00, 0x1a, 0x0c, 0x75, 0x04,
0x82, 0x00, 0x48, 0x80, 0x34, 0xd4, 0x11, 0x08, 0x02, 0x20, 0x01, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x23, 0x06, 0x08, 0x00, 0x82, 0x60, 0xb0, 0x9d,
0x81, 0x44, 0x8c, 0xc1, 0x37, 0x62, 0x50, 0x00, 0x20, 0x08, 0x06, 0x46,
0x1c, 0x48, 0x15, 0x64, 0x52, 0xc1, 0x06, 0x15, 0x68, 0x5a, 0x44, 0x25,
0x15, 0x6c, 0x50, 0xc1, 0x57, 0xc3, 0x0d, 0xc1, 0x1a, 0x80, 0xc1, 0x05,
0x40, 0xac, 0x60, 0xf8, 0x83, 0x36, 0x48, 0x86, 0x0d, 0x88, 0x40, 0x18,
0x80, 0x15, 0x0c, 0x7f, 0xe0, 0x06, 0xca, 0xb0, 0x01, 0x11, 0x20, 0x03,
0x30, 0x62, 0x60, 0x00, 0x20, 0x08, 0x06, 0xc8, 0x1e, 0x80, 0x01, 0x1c,
0xcc, 0x12, 0x08, 0xb5, 0x90, 0xc1, 0x8d, 0x18, 0x1c, 0x00, 0x08, 0x82,
0x01, 0x56, 0x07, 0x67, 0xd0, 0x48, 0x23, 0x06, 0x0e, 0x00, 0x82, 0x60,
0xd0, 0xf0, 0xc1, 0x19, 0x04, 0x42, 0x1c, 0x84, 0xff, 0xff, 0xff, 0xff,
0x90, 0x06, 0x69, 0x90, 0x06, 0xd5, 0x1b, 0x94, 0x40, 0x07, 0x3b, 0x62,
0x70, 0x00, 0x20, 0x08, 0x06, 0xd8, 0x1d, 0xa4, 0xc1, 0x43, 0x8d, 0x18,
0x38, 0x00, 0x08, 0x82, 0x41, 0xe3, 0x07, 0x69, 0x10, 0x08, 0x73, 0x40,
0xfe, 0xff, 0xff, 0xff, 0xc3, 0x1a, 0xac, 0xc1, 0x1a, 0x5c, 0x71, 0x50,
0x84, 0xb7, 0x23, 0x06, 0x07, 0x00, 0x82, 0x60, 0x80, 0xe5, 0xc1, 0x1a,
0x44, 0xd6, 0x88, 0x81, 0x03, 0x80, 0x20, 0x18, 0x34, 0xa0, 0xb0, 0x06,
0x81, 0x50, 0x07, 0xbe, 0xff, 0xff, 0xff, 0x3f, 0xb4, 0x41, 0x1b, 0xb4,
0x41, 0x36, 0x07, 0x54, 0x01, 0xa3, 0x8e, 0x35, 0xd8, 0x11, 0x83, 0x03,
0x00, 0x41, 0x30, 0xc0, 0xf8, 0xc0, 0x0d, 0xa8, 0x6c, 0xc4, 0xc0, 0x01,
0x40, 0x10, 0x0c, 0x9a, 0x51, 0x70, 0x83, 0x40, 0xc0, 0x83, 0x01, 0x0e,
0xe0, 0x00, 0x0e, 0x38, 0x3b, 0xa8, 0xc4, 0x0e, 0x76, 0xc4, 0xe0, 0x00,
0x40, 0x10, 0x0c, 0x30, 0x3f, 0x80, 0x03, 0x6b, 0x1b, 0x31, 0x70, 0x00,
0x10, 0x04, 0x83, 0xa6, 0x14, 0xe0, 0x20, 0x10, 0xf4, 0x40, 0xfc, 0xff,
0xff, 0xff, 0x07, 0x39, 0x90, 0x03, 0x39, 0xf0, 0xf0, 0x60, 0xc4, 0xa0,
0x00, 0x40, 0x10, 0x0c, 0x0c, 0x52, 0x18, 0x83, 0xba, 0x82, 0x19, 0x31,
0x30, 0x00, 0x10, 0x04, 0x83, 0xa8, 0x14, 0xc8, 0x20, 0x1a, 0x4d, 0x08,
0x80, 0xd1, 0x04, 0x21, 0x18, 0x31, 0x40, 0x00, 0x10, 0x04, 0x83, 0xc9,
0x14, 0xcc, 0x00, 0x13, 0x83, 0x31, 0x18, 0x31, 0x40, 0x00, 0x10, 0x04,
0x83, 0x09, 0x15, 0xcc, 0x20, 0x1b, 0x03, 0x32, 0x18, 0x31, 0x28, 0x00,
0x10, 0x04, 0x83, 0xea, 0x14, 0xcc, 0x60, 0x96, 0x41, 0x59, 0x82, 0x81,
0x0a, 0x80, 0x24, 0x80, 0x36, 0x48, 0x06, 0x2a, 0x00, 0x93, 0x00, 0xd2,
0x20, 0x19, 0xa8, 0x00, 0x50, 0x02, 0xb8, 0x92, 0x81, 0x0a, 0x40, 0x25,
0x80, 0x2b, 0x19, 0xa8, 0x00, 0x58, 0x02, 0x38, 0x83, 0x64, 0x05, 0x43,
0x2e, 0x9c, 0x42, 0x40, 0x01, 0x30, 0x86, 0x1b, 0x82, 0x54, 0x00, 0x83,
0x59, 0x06, 0x63, 0x08, 0x86, 0x1b, 0x08, 0x3d, 0x20, 0x83, 0x2a, 0xfc,
0x40, 0xeb, 0x15, 0x82, 0x9b, 0x65, 0x20, 0x8a, 0xa1, 0x02, 0x64, 0x67,
0x09, 0x8c, 0x12, 0x94, 0x9d, 0x25, 0x30, 0x06, 0x3a, 0x00, 0x8b, 0x10,
0x0a, 0x4b, 0x18, 0xe8, 0x00, 0x0c, 0xc2, 0x2a, 0x2c, 0x61, 0xb8, 0x61,
0x69, 0x03, 0x32, 0x58, 0xc1, 0x30, 0x0e, 0xb2, 0xc0, 0xcc, 0x32, 0x20,
0x87, 0x40, 0x01, 0x30, 0x66, 0x09, 0x12, 0x12, 0x80, 0x51, 0x81, 0x04,
0xb3, 0x04, 0xc9, 0x40, 0x05, 0x40, 0x20, 0xc6, 0x31, 0x50, 0x01, 0x10,
0x08, 0x1a, 0x1c, 0x25, 0x58, 0x60, 0x13, 0x2f, 0xc0, 0x60, 0xb8, 0x21,
0xb8, 0x05, 0x30, 0x98, 0x65, 0x08, 0x84, 0x60, 0x05, 0xc3, 0x3a, 0xec,
0x02, 0x18, 0x0c, 0x1b, 0x10, 0xc1, 0x37, 0x00, 0x2b, 0x18, 0xd6, 0x81,
0x17, 0xc2, 0x60, 0xd8, 0x80, 0x08, 0xba, 0x01, 0x98, 0x25, 0x58, 0x46,
0x0c, 0x0c, 0x00, 0x04, 0xc1, 0x00, 0x49, 0x07, 0x57, 0xf0, 0x85, 0xe1,
0x06, 0x31, 0xe8, 0x05, 0x30, 0x98, 0x65, 0x70, 0x98, 0x60, 0x96, 0xe0,
0x99, 0x25, 0x70, 0x06, 0x2a, 0x00, 0xbe, 0x58, 0x9a, 0x66, 0xb8, 0xa1,
0x0c, 0x5e, 0x01, 0x0c, 0x66, 0x19, 0xa0, 0x28, 0x18, 0xa8, 0x00, 0x92,
0x07, 0x34, 0x98, 0x81, 0x0a, 0x20, 0x79, 0x44, 0x83, 0x59, 0xc1, 0x10,
0x0f, 0xe2, 0x10, 0x50, 0x00, 0x8c, 0x0a, 0x08, 0x30, 0x02, 0x1d, 0x20,
0x30, 0xdc, 0x10, 0xac, 0x01, 0x19, 0xcc, 0x32, 0x3c, 0x4d, 0x40, 0xa6,
0x00, 0x0c, 0x32, 0x05, 0x60, 0xcc, 0x12, 0x48, 0xc3, 0x0d, 0x6f, 0x60,
0x0e, 0x60, 0x30, 0xdd, 0xd0, 0x06, 0xea, 0x10, 0x4c, 0x37, 0xb4, 0xc1,
0x3a, 0x08, 0xb3, 0x04, 0xd2, 0x40, 0x05, 0xa0, 0x40, 0x44, 0x34, 0x50,
0x01, 0x28, 0x10, 0x11, 0xd5, 0x1f, 0x80, 0xc3, 0x8e, 0x18, 0x1c, 0x00,
0x08, 0x82, 0x01, 0x46, 0x0f, 0xe6, 0xc0, 0x0a, 0xb1, 0x30, 0x62, 0xe0,
0x00, 0x20, 0x08, 0x06, 0xcd, 0x3e, 0x98, 0x43, 0x20, 0xc0, 0x03, 0x81,
0x0e, 0xe8, 0x80, 0x0e, 0xb4, 0xe0, 0x0e, 0x15, 0x0a, 0xf2, 0xb0, 0x23,
0x06, 0x07, 0x00, 0x82, 0x60, 0x80, 0xd9, 0x03, 0x3a, 0xb8, 0xc2, 0x2c,
0x8c, 0x18, 0x38, 0x00, 0x08, 0x82, 0x41, 0xd3, 0x0f, 0xe8, 0x10, 0x08,
0xf2, 0x50, 0xa8, 0x83, 0x3a, 0xa8, 0x83, 0x2d, 0xc0, 0x43, 0x51, 0x73,
0x00, 0x45, 0x0a, 0xe7, 0xb0, 0x23, 0x06, 0x07, 0x00, 0x82, 0x60, 0x80,
0xe5, 0xc3, 0x3a, 0xc4, 0x82, 0x2d, 0x8c, 0x18, 0x38, 0x00, 0x08, 0x82,
0x41, 0x03, 0x12, 0xeb, 0x10, 0x08, 0xf5, 0x30, 0xb4, 0x43, 0x3b, 0xb4,
0x43, 0x2e, 0xcc, 0x03, 0x06, 0xc4, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
0x5b, 0x86, 0x25, 0x08, 0x83, 0x2d, 0x43, 0x13, 0x84, 0xc1, 0x96, 0x21,
0x0b, 0xc2, 0x60, 0xcb, 0xf0, 0x06, 0x41, 0x18, 0x6c, 0x19, 0xfe, 0x20,
0x08, 0x83, 0x2d, 0x43, 0x28, 0x04, 0x61, 0xb0, 0x65, 0x58, 0x85, 0x20,
0x0c, 0xb6, 0x0c, 0xad, 0x10, 0x84, 0xc1, 0x96, 0x41, 0x17, 0x82, 0x30,
0xd8, 0x32, 0xfc, 0x42, 0x10, 0x06, 0x5b, 0x06, 0x70, 0x08, 0xc2, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// #671 check 2: 64-lane wave behaviour on hardware that runs narrower waves. A 64-thread group
// stands for one console wave of 64 lanes; lane = SV_GroupIndex. Two routes a translator can
// take are computed side by side:
// shared - every 64-lane operation through groupshared memory and group barriers;
// native - the host's own wave operations per hardware wave, merged across waves.
// Out[lane*8 + k] for k: 0 ballot lo, 1 ballot hi, 2 exclusive prefix sum, 3 read lane 37,
// 4 active sum (shared route); 5 ballot lo, 6 ballot hi, 7 exclusive prefix sum (native).
RWStructuredBuffer<uint> Out : register(u0);
groupshared uint g_pred[64];
groupshared uint g_val[64];
groupshared uint g_wave_ballot[64]; // one 32-bit ballot word per hardware wave (up to 64 waves)
groupshared uint g_wave_sum[64];
uint value_of(uint lane) { return (lane * 7u + 3u) & 31u; }
bool pred_of(uint lane) { return ((lane * 13u + 5u) % 3u) == 0u; }
[numthreads(64, 1, 1)]
void main(uint lane : SV_GroupIndex)
{
const uint v = value_of(lane);
const bool p = pred_of(lane);
// shared route
g_pred[lane] = p ? 1u : 0u;
g_val[lane] = v;
GroupMemoryBarrierWithGroupSync();
uint lo = 0, hi = 0, prefix = 0, total = 0;
for (uint i = 0; i < 64; ++i) {
if (g_pred[i]) { if (i < 32) lo |= 1u << i; else hi |= 1u << (i - 32); }
if (i < lane) prefix += g_val[i];
total += g_val[i];
}
Out[lane * 8 + 0] = lo;
Out[lane * 8 + 1] = hi;
Out[lane * 8 + 2] = prefix;
Out[lane * 8 + 3] = g_val[37];
Out[lane * 8 + 4] = total;
// native route: host wave ops within each hardware wave, then merged through groupshared.
const uint width = WaveGetLaneCount();
const uint wave = lane / width;
const uint4 b = WaveActiveBallot(p);
const uint wave_prefix = WavePrefixSum(v);
const uint wave_sum = WaveActiveSum(v);
if (WaveIsFirstLane()) {
g_wave_ballot[wave] = b.x; // a 32-lane wave fills one word; wider waves are reported
g_wave_sum[wave] = wave_sum;
}
GroupMemoryBarrierWithGroupSync();
uint before = 0;
for (uint w = 0; w < wave; ++w) before += g_wave_sum[w];
uint nlo = 0, nhi = 0;
if (width == 32) { nlo = g_wave_ballot[0]; nhi = g_wave_ballot[1]; }
else if (width == 64) { nlo = b.x; nhi = b.y; }
Out[lane * 8 + 5] = nlo;
Out[lane * 8 + 6] = nhi;
Out[lane * 8 + 7] = before + wave_prefix;
}
@@ -0,0 +1,2 @@
add_executable(test_gameinput_keyboard main.cpp)
target_link_libraries(test_gameinput_keyboard PRIVATE kernel32 user32 uuid)
@@ -0,0 +1,185 @@
#include <windows.h>
#include <unknwn.h>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
namespace {
constexpr uint32_t gamepad_kind = 0x00040000;
constexpr uint32_t keyboard_kind = 0x10;
constexpr uint32_t connected = 1;
constexpr uint32_t input_enabled = 2;
constexpr GUID device_iid = {0x31dd86fb, 0x4c1b, 0x408a, {0x86, 0x8f, 0x43, 0x9b, 0x3c, 0xd4, 0x71, 0x25}};
constexpr GUID reading_iid = {0x2156947a, 0xe1fa, 0x4de0, {0xa3, 0x0b, 0xd8, 0x12, 0x93, 0x1d, 0xbd, 0x8d}};
struct State {
uint32_t buttons;
float lt, rt, lx, ly, rx, ry;
};
static_assert(sizeof(State) == 28);
template <typename Fn>
Fn slot(IUnknown* object, unsigned index) {
return reinterpret_cast<Fn>((*reinterpret_cast<void***>(object))[index]);
}
using Create = HRESULT (WINAPI*)(void**);
using Current = HRESULT (WINAPI*)(IUnknown*, uint32_t, IUnknown*, IUnknown**);
using DeviceCallback = void (WINAPI*)(uint64_t, void*, IUnknown*, uint64_t, uint32_t, uint32_t);
using Register = HRESULT (WINAPI*)(IUnknown*, IUnknown*, uint32_t, uint32_t, uint32_t, void*, DeviceCallback, uint64_t*);
using Unregister = bool (WINAPI*)(IUnknown*, uint64_t, uint64_t);
using StateFn = bool (WINAPI*)(IUnknown*, State*);
using Sequence = uint64_t (WINAPI*)(IUnknown*, uint32_t);
struct Notification {
unsigned count = 0;
uint64_t token = 0;
uint64_t timestamp = 0;
uint32_t current = 0;
uint32_t previous = 0;
IUnknown* device = nullptr;
};
void WINAPI note_device(uint64_t token, void* context, IUnknown* device, uint64_t timestamp,
uint32_t current, uint32_t previous) {
auto& result = *static_cast<Notification*>(context);
result = {result.count + 1, token, timestamp, current, previous, device};
}
void pump_messages() {
MSG message;
while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessageW(&message);
}
}
bool focus_window(HWND window) {
SetForegroundWindow(window);
for (unsigned i = 0; i < 40; ++i) {
pump_messages();
if (GetForegroundWindow() == window) return true;
Sleep(10);
}
return false;
}
template <size_t N>
bool keys(const std::array<WORD, N>& bindings, bool down) {
std::array<INPUT, N> events{};
for (size_t i = 0; i < N; ++i) {
events[i].type = INPUT_KEYBOARD;
events[i].ki.wVk = bindings[i];
events[i].ki.dwFlags = down ? 0 : KEYEVENTF_KEYUP;
}
const bool ok = SendInput(static_cast<UINT>(N), events.data(), sizeof(INPUT)) == N;
for (unsigned i = 0; i < 4; ++i) {
pump_messages();
Sleep(10);
}
return ok;
}
uint32_t read_u32(const unsigned char* bytes, size_t offset) {
uint32_t value;
std::memcpy(&value, bytes + offset, sizeof(value));
return value;
}
#define REQUIRE(expr) do { if (!(expr)) { \
std::fprintf(stderr, "FAIL: GameInput keyboard line %d: %s\n", __LINE__, #expr); return 1; \
} } while (false)
} // namespace
int main() {
HMODULE module = LoadLibraryW(L"GameInput.dll");
REQUIRE(module);
const auto create = reinterpret_cast<Create>(reinterpret_cast<void*>(GetProcAddress(module, MAKEINTRESOURCEA(1))));
REQUIRE(create);
IUnknown* game_input = nullptr;
REQUIRE(create(reinterpret_cast<void**>(&game_input)) == S_OK && game_input);
const auto current = slot<Current>(game_input, 4);
const auto register_device = slot<Register>(game_input, 9);
const auto unregister = slot<Unregister>(game_input, 13);
Notification pad{};
uint64_t token = 0;
REQUIRE(register_device(game_input, nullptr, gamepad_kind, connected, 2, &pad, note_device, &token) == S_OK);
REQUIRE(pad.count == 1 && pad.token == token && pad.device && pad.timestamp);
REQUIRE(pad.current == (connected | input_enabled) && pad.previous == 0);
REQUIRE(unregister(game_input, token, 10000));
Notification filtered{};
REQUIRE(register_device(game_input, nullptr, keyboard_kind, connected, 2, &filtered, note_device, &token) == S_OK);
REQUIRE(filtered.count == 0 && unregister(game_input, token, 10000));
REQUIRE(register_device(game_input, pad.device, gamepad_kind, connected, 0, &filtered, note_device, &token) == S_OK);
REQUIRE(filtered.count == 0 && unregister(game_input, token, 10000));
void* interface_pointer = nullptr;
REQUIRE(pad.device->QueryInterface(device_iid, &interface_pointer) == S_OK && interface_pointer == pad.device);
static_cast<IUnknown*>(interface_pointer)->Release();
using Info = const unsigned char* (WINAPI*)(IUnknown*);
const auto info = slot<Info>(pad.device, 3)(pad.device);
REQUIRE(info && read_u32(info, 0) == 320 && read_u32(info, 104) == gamepad_kind);
using Find = HRESULT (WINAPI*)(IUnknown*, const void*, IUnknown**);
IUnknown* found = nullptr;
REQUIRE(slot<Find>(game_input, 16)(game_input, info + 32, &found) == S_OK && found == pad.device);
found->Release();
IUnknown* resting = nullptr;
REQUIRE(current(game_input, gamepad_kind, pad.device, &resting) == S_OK && resting);
REQUIRE(resting->QueryInterface(reading_iid, &interface_pointer) == S_OK && interface_pointer == resting);
static_cast<IUnknown*>(interface_pointer)->Release();
const auto state = slot<StateFn>(resting, 22);
const auto sequence = slot<Sequence>(resting, 4);
using GetDevice = void (WINAPI*)(IUnknown*, IUnknown**);
slot<GetDevice>(resting, 6)(resting, &found);
REQUIRE(found == pad.device);
found->Release();
State neutral{};
REQUIRE(state(resting, &neutral) && neutral.buttons == 0 && neutral.lx == 0 && neutral.rt == 0);
REQUIRE(sequence(resting, gamepad_kind) != 0 && sequence(resting, keyboard_kind) == 0);
IUnknown* invalid = resting;
REQUIRE(current(game_input, gamepad_kind, game_input, &invalid) == static_cast<HRESULT>(0x838a0002u) && !invalid);
HWND window = CreateWindowExW(0, L"STATIC", L"BetterXen keyboard conformance",
WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
300, 150, nullptr, nullptr, GetModuleHandleW(nullptr), nullptr);
REQUIRE(window && focus_window(window));
const std::array<WORD, 7> bindings{VK_RETURN, VK_LEFT, 'W', 'D', 'J', 'C', 'Q'};
const bool keydown = keys(bindings, true);
IUnknown* active = nullptr;
const HRESULT active_result = current(game_input, gamepad_kind, pad.device, &active);
ShowWindow(window, SW_HIDE);
pump_messages();
IUnknown* unfocused = nullptr;
const HRESULT unfocused_result = current(game_input, gamepad_kind, pad.device, &unfocused);
const bool keyup = keys(bindings, false);
DestroyWindow(window);
REQUIRE(keydown && keyup && active_result == S_OK && active);
REQUIRE(unfocused_result == S_OK && unfocused);
State pressed{};
REQUIRE(state(active, &pressed));
REQUIRE(pressed.buttons == (0x4 | 0x100 | 0x400));
REQUIRE(pressed.lt == 0 && pressed.rt == 1);
REQUIRE(std::fabs(pressed.lx - 0.70710678f) < 0.001f && std::fabs(pressed.ly - 0.70710678f) < 0.001f);
REQUIRE(pressed.rx == -1 && pressed.ry == 0);
REQUIRE(state(resting, &neutral) && neutral.buttons == 0);
REQUIRE(state(unfocused, &neutral) && neutral.buttons == 0 && neutral.rt == 0 && neutral.lx == 0);
REQUIRE(sequence(active, gamepad_kind) > sequence(resting, gamepad_kind));
REQUIRE(sequence(unfocused, gamepad_kind) > sequence(active, gamepad_kind));
unfocused->Release();
active->Release();
resting->Release();
game_input->Release();
FreeLibrary(module);
std::puts("PASS: GameInput v0 keyboard gamepad enumeration, state, and foreground handling");
return 0;
}
@@ -0,0 +1,3 @@
add_executable(test_veh_clwb_loop main.cpp)
target_include_directories(test_veh_clwb_loop PRIVATE "${BX_ABI_INCLUDE_DIR}")
target_link_libraries(test_veh_clwb_loop PRIVATE bx_runtime_veh kernel32)
@@ -0,0 +1,151 @@
// Synthetic Windows x64 fixture for CLWB range loops under the Rosetta exception path.
//
// CLWB (Intel SDM vol. 2A; 66 0F AE /6 with a memory operand) writes back the cache line that
// contains its operand. It changes no register, no flag and no memory content. Rosetta 2 does not
// run it, so bx_runtime_veh.dll skips it from the illegal-instruction exception. A title flushes
// an address range with a loop of the form
//
// clwb [reg] ; add reg, 0x40 ; cmp reg, <reg64> ; jbe|jb <the clwb>
//
// which would raise one exception per 64 bytes. The handler completes such a loop in the first
// exception by advancing the pointer register to the last value the loop would have used.
//
// This fixture runs its own machine-code loops (bytes written here, no title code) and checks:
// * the pointer register's final value against the loop's definition (the value native
// execution leaves, computed here from the start, the limit and the branch condition);
// * the number of illegal-instruction exceptions, counted by a handler of its own that runs
// before BetterXen's: one per loop that matches the form, one per iteration otherwise;
// * that memory is unchanged.
// On a host that runs CLWB natively no exception is raised and the fixture skips (exit 77).
#include <windows.h>
#include <cstdint>
#include <cstdio>
#include <cstring>
extern "C" uint64_t bx_veh_get_clwb_trap_count(void); // imports bx_runtime_veh.dll, which installs the handler
namespace {
unsigned failures = 0;
unsigned checks = 0;
void expect(bool passed, const char* name) {
++checks;
if (passed) {
std::printf("ok: %s\n", name);
} else {
std::fprintf(stderr, "FAIL: %s\n", name);
++failures;
}
}
volatile LONG g_illegal = 0;
// Registered first: sees every illegal instruction before BetterXen's handler emulates it.
LONG CALLBACK count_first(PEXCEPTION_POINTERS ep) {
if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) InterlockedIncrement(&g_illegal);
return EXCEPTION_CONTINUE_SEARCH;
}
using Loop = uint64_t (*)(uint8_t* start, uint8_t* limit); // rcx = start, rdx = limit; returns the final pointer
// mov rax, rdx ; L: clwb [rcx] ; add rcx, 0x40 ; cmp rcx, rax ; jbe L ; mov rax, rcx ; ret
const uint8_t kJbeRcx[] = {0x48, 0x89, 0xD0, 0x66, 0x0F, 0xAE, 0x31, 0x48, 0x83, 0xC1, 0x40,
0x48, 0x39, 0xC1, 0x76, 0xF3, 0x48, 0x89, 0xC8, 0xC3};
// mov r9, rcx ; mov rax, rdx ; L: clwb [r9] ; add r9, 0x40 ; cmp r9, rax ; jbe L ; mov rax, r9 ; ret
const uint8_t kJbeR9[] = {0x49, 0x89, 0xC9, 0x48, 0x89, 0xD0, 0x66, 0x41, 0x0F, 0xAE, 0x31, 0x49, 0x83,
0xC1, 0x40, 0x49, 0x39, 0xC1, 0x76, 0xF2, 0x4C, 0x89, 0xC8, 0xC3};
// mov r10, rdx ; L: clwb [rcx] ; add rcx, 0x40 ; cmp rcx, r10 ; jb L ; mov rax, rcx ; ret
const uint8_t kJbRcxR10[] = {0x49, 0x89, 0xD2, 0x66, 0x0F, 0xAE, 0x31, 0x48, 0x83, 0xC1, 0x40,
0x4C, 0x39, 0xD1, 0x72, 0xF3, 0x48, 0x89, 0xC8, 0xC3};
// The jbe loop with a NOP before the add, which is not the recognised form:
// mov rax, rdx ; L: clwb [rcx] ; nop ; add rcx, 0x40 ; cmp rcx, rax ; jbe L ; mov rax, rcx ; ret
const uint8_t kOther[] = {0x48, 0x89, 0xD0, 0x66, 0x0F, 0xAE, 0x31, 0x90, 0x48, 0x83, 0xC1,
0x40, 0x48, 0x39, 0xC1, 0x76, 0xF2, 0x48, 0x89, 0xC8, 0xC3};
Loop make(const uint8_t* code, size_t size) {
void* page = VirtualAlloc(nullptr, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (!page) return nullptr;
std::memcpy(page, code, size);
FlushInstructionCache(GetCurrentProcess(), page, size);
return reinterpret_cast<Loop>(page);
}
// The pointer value native execution leaves: the body runs once, then again while the advanced
// pointer is <= limit (jbe) or < limit (jb).
uint64_t native_final(uint64_t start, uint64_t limit, bool inclusive) {
uint64_t p = start;
do {
p += 64;
} while (inclusive ? p <= limit : p < limit);
return p;
}
uint64_t iterations(uint64_t start, uint64_t limit, bool inclusive) { return (native_final(start, limit, inclusive) - start) / 64; }
struct Case {
const char* name;
Loop loop;
bool inclusive;
size_t start_offset;
size_t limit_offset;
LONG want_exceptions; // 0 = one per iteration
};
} // namespace
int main() {
(void)bx_veh_get_clwb_trap_count();
void* first = AddVectoredExceptionHandler(1, count_first);
const Loop jbe_rcx = make(kJbeRcx, sizeof(kJbeRcx));
const Loop jbe_r9 = make(kJbeR9, sizeof(kJbeR9));
const Loop jb_rcx_r10 = make(kJbRcxR10, sizeof(kJbRcxR10));
const Loop other = make(kOther, sizeof(kOther));
constexpr size_t kBytes = 1 << 20;
auto* buffer = static_cast<uint8_t*>(VirtualAlloc(nullptr, kBytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
if (!first || !jbe_rcx || !jbe_r9 || !jb_rcx_r10 || !other || !buffer) {
std::fprintf(stderr, "FAIL: setup\n");
return 1;
}
for (size_t i = 0; i < kBytes; ++i) buffer[i] = static_cast<uint8_t>(i * 131 + 7);
// One iteration first: on a host that runs CLWB natively there is nothing to test.
InterlockedExchange(&g_illegal, 0);
(void)jbe_rcx(buffer, buffer);
if (g_illegal == 0) {
std::printf("SKIP: test_veh_clwb_loop: CLWB raised no exception on this host (it runs natively)\n");
return 77;
}
const Case cases[] = {
{"jbe, pointer rcx, 1000 lines", jbe_rcx, true, 0, 1000 * 64, 1},
{"jbe, pointer r9 (REX.B), 1000 lines", jbe_r9, true, 0, 1000 * 64, 1},
{"jb, limit r10 (REX.R), 1000 lines", jb_rcx_r10, false, 0, 1000 * 64, 1},
{"jbe, a 6 MiB-style range: unaligned start, limit inside a line", jbe_rcx, true, 40, 12345 * 64 + 17, 1},
{"jb, limit exactly one line past the start", jb_rcx_r10, false, 0, 64, 1},
{"jbe, limit below the start (the body runs once)", jbe_rcx, true, 4096, 64, 1},
{"other loop form: one exception per iteration", other, true, 0, 8 * 64, 0},
};
for (const Case& c : cases) {
const uint64_t start = reinterpret_cast<uint64_t>(buffer) + c.start_offset;
const uint64_t limit = reinterpret_cast<uint64_t>(buffer) + c.limit_offset;
InterlockedExchange(&g_illegal, 0);
const uint64_t got = c.loop(reinterpret_cast<uint8_t*>(start), reinterpret_cast<uint8_t*>(limit));
const uint64_t want = native_final(start, limit, c.inclusive);
const LONG want_exceptions = c.want_exceptions ? c.want_exceptions : static_cast<LONG>(iterations(start, limit, c.inclusive));
char name[200];
std::snprintf(name, sizeof(name), "%s: final pointer = native value (start+%llu, got start+%llu)", c.name,
static_cast<unsigned long long>(want - start), static_cast<unsigned long long>(got - start));
expect(got == want, name);
std::snprintf(name, sizeof(name), "%s: %ld exception(s) (got %ld)", c.name, want_exceptions, g_illegal);
expect(g_illegal == want_exceptions, name);
}
bool unchanged = true;
for (size_t i = 0; i < kBytes && unchanged; ++i) unchanged = buffer[i] == static_cast<uint8_t>(i * 131 + 7);
expect(unchanged, "memory is unchanged by every loop");
RemoveVectoredExceptionHandler(first);
std::printf("%s: test_veh_clwb_loop (%u of %u checks passed)\n", failures ? "FAIL" : "PASS", checks - failures, checks);
return failures ? 1 : 0;
}
@@ -0,0 +1,6 @@
# Synthetic conformance test: Xbox DirectStorage requests whose destination is an array of
# xmem.dll physical pages (DestinationIsPhysicalPages).
add_executable(test_xcrdapi_page_destination main.cpp)
target_compile_definitions(test_xcrdapi_page_destination PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
target_include_directories(test_xcrdapi_page_destination PRIVATE "${BX_ABI_INCLUDE_DIR}" "${BX_ROOT_DIR}/shims/xcrdapi/dstorage")
target_link_libraries(test_xcrdapi_page_destination PRIVATE xcrdapi xmem bx_runtime_veh kernel32)
@@ -0,0 +1,410 @@
/*
* Synthetic conformance test: Xbox DirectStorage requests whose destination is an array of
* physical pages (DSTORAGE_REQUEST_OPTIONS.DestinationIsPhysicalPages).
*
* Contract, from the authorized GDK header and documentation of DSTORAGE_REQUEST:
* - DestinationIsPhysicalPages is bit 21 of the options (after ZlibDecompress:1, BcpackMode:4,
* SwizzleMode:16); SourceType is bit 22 and SourceIsPhysicalPages bit 23.
* - With it, the destination union holds DestinationPageArray (an array of 64 KB page numbers
* from XMemAllocatePhysicalPages) at +0x08 and DestinationPageOffset (UINT16, the offset into
* the first page where the destination starts) at +0x10.
* - DestinationSize bytes are written from that offset, page after page in array order.
* The 56-byte request layout is the one test_xcrdapi_xbox already uses.
*
* The expected bytes are built here from a formula; the zlib stream was produced from the same
* formula by CPython's zlib module (level 9), not by the code under test.
*/
#include <windows.h>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include "dstorage.h"
extern "C" {
__declspec(dllimport) HRESULT WINAPI DStorageGetFactory(REFIID riid, void** ppv);
PVOID WINAPI XMemVirtualAlloc(PVOID, SIZE_T, DWORD, uint64_t, DWORD);
BOOL WINAPI XMemAllocatePhysicalPages(uint64_t, PULONG_PTR, PULONG_PTR);
BOOL WINAPI XMemFreePhysicalPages(ULONG_PTR, PULONG_PTR);
PVOID WINAPI XMemMapPhysicalPages(PVOID, ULONG_PTR, PULONG_PTR);
}
struct XboxQueueDesc {
UINT64 source_type;
UINT16 capacity;
INT8 priority;
UINT8 reserved_pad[5];
PCSTR name;
UINT64 flags;
};
struct XboxRequest {
UINT64 options;
void* destination; // DestinationPageArray when bit 21 is set
UINT16 destination_page_offset; // DestinationPageOffset
UINT16 reserved12;
UINT32 reserved14;
UINT32 destination_size;
UINT32 reserved1c;
void* source_ptr;
UINT64 file_offset;
UINT32 source_size;
UINT32 reserved34;
};
static_assert(sizeof(XboxRequest) == 56, "DSTORAGE_REQUEST is 56 bytes");
static_assert(offsetof(XboxRequest, destination_page_offset) == 0x10, "DestinationPageOffset at +0x10");
static_assert(offsetof(XboxRequest, destination_size) == 0x18, "DestinationSize at +0x18");
struct IXboxDStorageFile : IUnknown {
virtual void STDMETHODCALLTYPE Close() = 0;
virtual HRESULT STDMETHODCALLTYPE GetFileInformation(BY_HANDLE_FILE_INFORMATION* info) = 0;
};
struct IXboxDStorageStatusArray : IUnknown {
virtual bool STDMETHODCALLTYPE IsComplete(UINT32 index) = 0;
virtual HRESULT STDMETHODCALLTYPE GetHResult(UINT32 index) = 0;
};
struct IXboxDStorageQueue : IUnknown {
virtual void STDMETHODCALLTYPE EnqueueRequest(const XboxRequest* request) = 0;
virtual void STDMETHODCALLTYPE EnqueueStatus(IXboxDStorageStatusArray* status_array, UINT32 index) = 0;
virtual void STDMETHODCALLTYPE EnqueueSignal(void* fence, UINT64 value) = 0;
virtual void STDMETHODCALLTYPE Submit() = 0;
virtual void STDMETHODCALLTYPE CancelRequestsWithTag(UINT64 mask, UINT64 value) = 0;
virtual void STDMETHODCALLTYPE Close() = 0;
};
struct IXboxDStorageFactory : IUnknown {
virtual HRESULT STDMETHODCALLTYPE CreateQueue(const void* desc, REFIID riid, void** ppv) = 0;
virtual HRESULT STDMETHODCALLTYPE OpenFile(const WCHAR* path, REFIID riid, void** ppv) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateStatusArray(UINT32 capacity, PCSTR name, REFIID riid, void** ppv) = 0;
virtual void STDMETHODCALLTYPE SetDebugFlags(UINT32 flags) = 0;
virtual HRESULT STDMETHODCALLTYPE StubSlot7() = 0;
virtual HRESULT STDMETHODCALLTYPE SetStagingBufferSize(UINT32 size) = 0;
virtual HRESULT STDMETHODCALLTYPE StubSlot9() = 0;
virtual HRESULT STDMETHODCALLTYPE CreateQueueX(const XboxQueueDesc* desc, REFIID riid, void** ppv) = 0;
};
namespace {
constexpr IID kXboxFactoryIid{0x62959d11, 0xd45f, 0x4884, {0xa0, 0xa3, 0xf7, 0x86, 0x2e, 0xa2, 0x43, 0xae}};
constexpr IID kXboxFileIid{0x43704f9f, 0x27c6, 0x4a9f, {0x88, 0x15, 0xd1, 0x65, 0x27, 0x89, 0x4d, 0xf4}};
constexpr IID kXboxStatusArrayIid{0xcd66d752, 0x2786, 0x44f7, {0x90, 0x70, 0xe2, 0xa6, 0xfd, 0xad, 0x3f, 0x1b}};
constexpr IID kXboxQueueIid{0x3c02cb0c, 0xc050, 0x4195, {0x99, 0xa1, 0xa1, 0xce, 0x94, 0xba, 0x33, 0xc5}};
// DSTORAGE_REQUEST_OPTIONS bits (authorized GDK header).
constexpr UINT64 kZlibDecompress = 1ull << 0;
constexpr UINT64 kDestinationIsPhysicalPages = 1ull << 21;
constexpr UINT64 kSourceTypeMemory = 1ull << 22;
constexpr UINT64 kSourceIsPhysicalPages = 1ull << 23;
// xmem constants (authorized GDK documentation, as in test_xmem_physical).
constexpr SIZE_T kPage = 64 * 1024;
constexpr DWORD kMem64KPages = 0x20400000;
constexpr uint64_t kXMemCpu = 0x1;
constexpr uint64_t kXMemMappable = 0x20;
constexpr BYTE kFill = 0xCC;
int g_failed = 0;
int g_checks = 0;
void check(bool cond, const char* fmt, ...) {
++g_checks;
if (cond) return;
++g_failed;
va_list args;
va_start(args, fmt);
std::fprintf(stderr, "FAIL: ");
std::vfprintf(stderr, fmt, args);
std::fprintf(stderr, "\n");
va_end(args);
}
bool wait_complete(IXboxDStorageStatusArray* status, UINT32 index) {
for (int i = 0; i < 500; ++i) {
if (status->IsComplete(index)) return true;
Sleep(10);
}
return false;
}
/* "pg %04d;" for i % 251, i = 0..16999 (136000 bytes), zlib level 9 (CPython). */
constexpr size_t kPlainSize = 136000;
const uint8_t kZlibStream[] = {
0x78, 0xda, 0xed, 0xd5, 0xbb, 0x0d, 0x05, 0x86, 0x0d, 0x04, 0xc1, 0x56, 0x5c, 0x82, 0x8e, 0xef,
0x0f, 0x17, 0xe4, 0x54, 0xfd, 0x47, 0x16, 0xac, 0x75, 0x09, 0xca, 0x86, 0x09, 0xb3, 0xcb, 0x16,
0xf3, 0xe7, 0x7f, 0xfe, 0xf5, 0xc7, 0x5f, 0xf7, 0xef, 0x3f, 0xff, 0xf7, 0xd7, 0xbf, 0xfe, 0xa3,
0xff, 0xec, 0xbf, 0xfa, 0xef, 0xfe, 0xa7, 0xff, 0xed, 0xff, 0xfe, 0xfe, 0x6b, 0x6f, 0xed, 0xad,
0xbd, 0xb5, 0xb7, 0xf6, 0xd6, 0xde, 0xda, 0x5b, 0x7b, 0x6b, 0x6f, 0xed, 0x5d, 0x7b, 0xd7, 0xde,
0xb5, 0x77, 0xed, 0x5d, 0x7b, 0xd7, 0xde, 0xb5, 0x77, 0xed, 0x5d, 0x7b, 0xd7, 0xde, 0xa3, 0xbd,
0x47, 0x7b, 0x8f, 0xf6, 0x1e, 0xed, 0x3d, 0xda, 0x7b, 0xb4, 0xf7, 0x68, 0xef, 0xd1, 0xde, 0xa3,
0xbd, 0x47, 0x7b, 0xcf, 0xf6, 0x9e, 0xed, 0x3d, 0xdb, 0x7b, 0xb6, 0xf7, 0x6c, 0xef, 0xd9, 0xde,
0xb3, 0xbd, 0x67, 0x7b, 0xcf, 0xf6, 0x9e, 0xed, 0xbd, 0xda, 0x7b, 0xb5, 0xf7, 0x6a, 0xef, 0xd5,
0xde, 0xab, 0xbd, 0x57, 0x7b, 0xaf, 0xf6, 0x5e, 0xed, 0xbd, 0xda, 0x7b, 0xb5, 0xf7, 0x6e, 0xef,
0xdd, 0xde, 0xbb, 0xbd, 0x77, 0x7b, 0xef, 0xf6, 0xde, 0xed, 0xbd, 0xdb, 0x7b, 0xb7, 0xf7, 0x6e,
0xef, 0xdd, 0xde, 0xa7, 0xbd, 0x4f, 0x7b, 0x9f, 0xf6, 0x3e, 0xed, 0x7d, 0xda, 0xfb, 0xb4, 0xf7,
0x69, 0xef, 0xd3, 0xde, 0xa7, 0xbd, 0x4f, 0x7b, 0xdf, 0xf6, 0xbe, 0xed, 0x7d, 0xdb, 0xfb, 0xb6,
0xf7, 0x6d, 0xef, 0xdb, 0xde, 0xb7, 0xbd, 0x6f, 0x7b, 0xdf, 0xf6, 0xbe, 0xed, 0xfd, 0xda, 0xfb,
0xb5, 0xf7, 0x6b, 0xef, 0xd7, 0xde, 0xaf, 0xbd, 0x5f, 0x7b, 0xbf, 0xf6, 0x7e, 0xed, 0xfd, 0xda,
0xfb, 0xfd, 0xbd, 0xb7, 0xfa, 0x58, 0x7d, 0xac, 0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea,
0x63, 0xf5, 0xb1, 0xfa, 0x58, 0x7d, 0xac, 0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63,
0xf5, 0xb1, 0xfa, 0x58, 0x7d, 0xac, 0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5,
0xb1, 0xfa, 0x58, 0x7d, 0xac, 0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1,
0xfa, 0x58, 0x7d, 0xac, 0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1, 0xfa,
0x58, 0x7d, 0xac, 0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1, 0xfa, 0x58,
0x7d, 0xac, 0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1, 0xfa, 0x58, 0x7d,
0xac, 0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1, 0xfa, 0x58, 0x7d, 0xac,
0x3e, 0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1, 0xfa, 0x58, 0x7d, 0xac, 0x3e,
0x56, 0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1, 0xfa, 0x58, 0x7d, 0xac, 0x3e, 0x56,
0x1f, 0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1, 0xfa, 0x58, 0x7d, 0xac, 0x3e, 0x56, 0x1f,
0xab, 0x8f, 0xd5, 0xc7, 0xea, 0x63, 0xf5, 0xb1, 0xfa, 0x58, 0x7d, 0xac, 0x3e, 0x56, 0x1f, 0x57,
0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57,
0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57,
0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57,
0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57,
0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57,
0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57, 0x1f, 0x57,
0x1f, 0x57, 0x1f, 0xf7, 0x7f, 0x3f, 0xb8, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a,
0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae,
0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7,
0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75,
0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c,
0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce,
0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb,
0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9,
0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d,
0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7,
0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73,
0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a,
0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae,
0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7,
0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75,
0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c,
0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce,
0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb,
0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9,
0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d,
0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7,
0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73,
0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a,
0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae,
0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7,
0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75,
0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c,
0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce,
0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb,
0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9,
0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d,
0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7,
0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73,
0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a,
0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae,
0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7,
0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75,
0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c,
0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce,
0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb,
0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9,
0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d,
0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7,
0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73,
0x9d, 0xeb, 0x5c, 0xe7, 0x3a, 0xd7, 0xb9, 0xce, 0x75, 0xae, 0x73, 0x9d, 0xeb, 0x5c, 0xe7, 0xfa,
0x3f, 0xe2, 0xfa, 0x7f, 0x01, 0xc6, 0xe2, 0x9e, 0xc4,
};
char g_plain[kPlainSize + 1];
void build_plain() {
for (int i = 0, at = 0; i < 17000; ++i) {
at += std::snprintf(g_plain + at, sizeof(g_plain) - at, "pg %04d;", i % 251);
}
}
// The title's view: its four pages mapped in allocation order at `view`.
BYTE* g_view = nullptr;
ULONG_PTR g_pages[4] = {};
BYTE* page_in_view(ULONG_PTR number) {
for (int i = 0; i < 4; ++i) {
if (g_pages[i] == number) return g_view + i * kPage;
}
return nullptr;
}
void fill_view() { std::memset(g_view, kFill, 4 * kPage); }
// Checks that `size` bytes of `expected` were written from `offset` through `array` (in array
// order), and that every other byte of the four pages kept the fill.
void check_written(const char* what, const ULONG_PTR* array, size_t count, size_t offset, const void* expected,
size_t size) {
static BYTE want[4 * kPage];
std::memset(want, kFill, sizeof(want));
const auto* src = static_cast<const BYTE*>(expected);
for (size_t j = 0; j < size; ++j) {
const size_t at = offset + j;
const size_t k = at / kPage;
if (k >= count) break;
BYTE* page = page_in_view(array[k]);
want[(page - g_view) + at % kPage] = src[j];
}
size_t first_bad = SIZE_MAX;
for (size_t i = 0; i < sizeof(want) && first_bad == SIZE_MAX; ++i) {
if (g_view[i] != want[i]) first_bad = i;
}
check(first_bad == SIZE_MAX, "%s: page bytes differ first at page %zu offset 0x%zx (got 0x%02x, want 0x%02x)",
what, first_bad / kPage, first_bad % kPage, first_bad == SIZE_MAX ? 0 : g_view[first_bad],
first_bad == SIZE_MAX ? 0 : want[first_bad]);
}
} // namespace
int main() {
build_plain();
ULONG_PTR count = 4;
check(XMemAllocatePhysicalPages(0, &count, g_pages) && count == 4, "XMemAllocatePhysicalPages(4) must succeed");
g_view = static_cast<BYTE*>(
XMemVirtualAlloc(nullptr, 4 * kPage, MEM_RESERVE | kMem64KPages, kXMemMappable | kXMemCpu, PAGE_READWRITE));
check(g_view && XMemMapPhysicalPages(g_view, 4, g_pages) == g_view, "the title view of the pages must map");
if (g_failed) return 1;
IXboxDStorageFactory* factory = nullptr;
HRESULT hr = DStorageGetFactory(kXboxFactoryIid, reinterpret_cast<void**>(&factory));
check(hr == S_OK && factory, "DStorageGetFactory(Xbox) must succeed (hr=0x%08lx)", static_cast<unsigned long>(hr));
IXboxDStorageStatusArray* status = nullptr;
hr = factory ? factory->CreateStatusArray(4, "pages", kXboxStatusArrayIid, reinterpret_cast<void**>(&status)) : E_FAIL;
check(hr == S_OK && status, "CreateStatusArray must succeed (hr=0x%08lx)", static_cast<unsigned long>(hr));
if (g_failed) return 1;
/* 1. File source, zlib, into three pages given out of order, starting 0x9000 into the first:
* 136000 bytes from 0x9000 end in the third page. */
WCHAR temp_dir[MAX_PATH] = {};
WCHAR zlib_file[MAX_PATH] = {};
check(GetTempPathW(MAX_PATH, temp_dir) > 0 && GetTempFileNameW(temp_dir, L"bxp", 0, zlib_file) != 0,
"a temporary file name must be available");
HANDLE raw = CreateFileW(zlib_file, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (raw != INVALID_HANDLE_VALUE) {
BYTE prefix[100];
std::memset(prefix, 0x5A, sizeof(prefix));
DWORD written = 0;
check(WriteFile(raw, prefix, sizeof(prefix), &written, nullptr) &&
WriteFile(raw, kZlibStream, sizeof(kZlibStream), &written, nullptr) && written == sizeof(kZlibStream),
"the zlib payload must be written");
CloseHandle(raw);
}
IXboxDStorageFile* file = nullptr;
hr = factory->OpenFile(zlib_file, kXboxFileIid, reinterpret_cast<void**>(&file));
check(hr == S_OK && file, "OpenFile must succeed (hr=0x%08lx)", static_cast<unsigned long>(hr));
XboxQueueDesc file_desc{};
file_desc.capacity = 16;
file_desc.name = "page_file_queue";
IXboxDStorageQueue* file_q = nullptr;
hr = factory->CreateQueueX(&file_desc, kXboxQueueIid, reinterpret_cast<void**>(&file_q));
check(hr == S_OK && file_q, "CreateQueueX(file) must succeed (hr=0x%08lx)", static_cast<unsigned long>(hr));
if (file && file_q) {
ULONG_PTR array[] = {g_pages[2], g_pages[0], g_pages[1]};
fill_view();
XboxRequest r{};
r.options = kZlibDecompress | kDestinationIsPhysicalPages;
r.destination = array;
r.destination_page_offset = 0x9000;
r.destination_size = kPlainSize;
r.source_ptr = file;
r.file_offset = 100;
r.source_size = sizeof(kZlibStream);
file_q->EnqueueRequest(&r);
file_q->EnqueueStatus(status, 0);
file_q->Submit();
check(wait_complete(status, 0) && status->GetHResult(0) == S_OK,
"zlib file request into physical pages must succeed (hr=0x%08lx)",
static_cast<unsigned long>(status->GetHResult(0)));
check_written("zlib file request", array, 3, 0x9000, g_plain, kPlainSize);
/* 2. A page number that was never allocated fails the request and writes nothing. */
ULONG_PTR bad[] = {g_pages[3], g_pages[0] + g_pages[1] + g_pages[2] + g_pages[3] + 16 * 1024};
fill_view();
XboxRequest b = r;
b.destination = bad;
b.destination_page_offset = 0;
b.destination_size = static_cast<UINT32>(kPage + 16);
b.source_size = sizeof(kZlibStream);
file_q->EnqueueRequest(&b);
file_q->EnqueueStatus(status, 1);
file_q->Submit();
check(wait_complete(status, 1) && FAILED(status->GetHResult(1)),
"a request naming an unallocated page must fail (hr=0x%08lx)",
static_cast<unsigned long>(status->GetHResult(1)));
check_written("unallocated page", bad, 0, 0, g_plain, 0);
file_q->Close();
}
/* 3. Memory source, uncompressed, 64 bytes across a page boundary (0xFFE0 in the first page). */
XboxQueueDesc mem_desc{};
mem_desc.source_type = 1;
mem_desc.capacity = 16;
mem_desc.name = "page_memory_queue";
IXboxDStorageQueue* mem_q = nullptr;
hr = factory->CreateQueueX(&mem_desc, kXboxQueueIid, reinterpret_cast<void**>(&mem_q));
check(hr == S_OK && mem_q, "CreateQueueX(memory) must succeed (hr=0x%08lx)", static_cast<unsigned long>(hr));
if (mem_q) {
BYTE source[64];
for (int i = 0; i < 64; ++i) source[i] = static_cast<BYTE>(0x80 + i);
ULONG_PTR array[] = {g_pages[3], g_pages[1]};
fill_view();
XboxRequest m{};
m.options = kSourceTypeMemory | kDestinationIsPhysicalPages;
m.destination = array;
m.destination_page_offset = 0xFFE0;
m.destination_size = sizeof(source);
m.source_ptr = source;
m.source_size = sizeof(source);
mem_q->EnqueueRequest(&m);
mem_q->EnqueueStatus(status, 2);
mem_q->Submit();
check(wait_complete(status, 2) && status->GetHResult(2) == S_OK,
"memory request into physical pages must succeed (hr=0x%08lx)",
static_cast<unsigned long>(status->GetHResult(2)));
check_written("memory request", array, 2, 0xFFE0, source, sizeof(source));
/* 4. A physical-page source is not implemented: refused with E_NOTIMPL, nothing written. */
fill_view();
XboxRequest s = m;
s.options = kSourceTypeMemory | kSourceIsPhysicalPages;
s.destination = source;
s.destination_page_offset = 0;
s.source_ptr = array;
mem_q->EnqueueRequest(&s);
mem_q->EnqueueStatus(status, 3);
mem_q->Submit();
check(wait_complete(status, 3) && status->GetHResult(3) == E_NOTIMPL,
"a physical-page source must be refused with E_NOTIMPL (hr=0x%08lx)",
static_cast<unsigned long>(status->GetHResult(3)));
check_written("physical-page source", array, 0, 0, source, 0);
mem_q->Close();
mem_q->Release();
}
if (file_q) file_q->Release();
if (file) {
file->Close();
file->Release();
}
DeleteFileW(zlib_file);
status->Release();
factory->Release();
/* The request's own mapping is gone: the pages can be unmapped and freed. */
check(XMemMapPhysicalPages(g_view, 4, nullptr) == g_view, "the title view must unmap");
check(XMemFreePhysicalPages(4, g_pages), "the pages must be freed");
if (g_failed) {
std::fprintf(stderr, "test_xcrdapi_page_destination: %d of %d checks failed\n", g_failed, g_checks);
return 1;
}
std::printf("test_xcrdapi_page_destination: PASS (%d checks)\n", g_checks);
return 0;
}
@@ -0,0 +1,5 @@
add_executable(test_xcrdapi_remap_guard main.cpp)
target_compile_definitions(test_xcrdapi_remap_guard PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
target_include_directories(test_xcrdapi_remap_guard PRIVATE "${BX_ABI_INCLUDE_DIR}"
"${BX_ROOT_DIR}/shims/xcrdapi" "${BX_ROOT_DIR}/shims/xcrdapi/dstorage")
target_link_libraries(test_xcrdapi_remap_guard PRIVATE xcrdapi xmem kernel32 uuid)
@@ -0,0 +1,243 @@
/*
* XCRDAPI.dll stores into a title's memory on worker threads while the title remaps neighbouring
* pages of the same XMemMapPhysicalPages window (handoff #668: an access violation in
* XCRDAPI.dll, writing to memory that is not mapped). Windows and Wine cannot replace a mapped
* view in one step, so XCRDAPI.dll brackets its stores with xmem.dll's remap guard
* (bx_xmem_remap_guard_enter / _leave) and the remapping calls wait for it. Memory requests that
* span the window are queued while the window is remapped over and over; without the guard a
* store lands in a gap and the process dies in an access violation. Three request shapes, each
* for about 2 s:
* 1. memory to memory into the window (public DirectStorage interface): stores;
* 2. a zlib stream inflated into the window for about 4 s (BetterXen's request interface):
* stores and back-reference loads by the inflater;
* 3. memory to memory out of the window into private memory: loads, which fault in the gap
* like stores.
* The zlib stream is built here by hand (RFC 1950/1951, fixed Huffman codes), so the expected
* output does not come from the code under test.
*/
#include <windows.h>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <vector>
#include "dstorage_mingw.h"
#include "synthetic_storage.h"
extern "C" {
PVOID WINAPI XMemVirtualAlloc(PVOID, SIZE_T, DWORD, uint64_t, DWORD);
BOOL WINAPI XMemAllocatePhysicalPages(uint64_t, PULONG_PTR, PULONG_PTR);
PVOID WINAPI XMemMapPhysicalPages(PVOID, ULONG_PTR, PULONG_PTR);
}
namespace {
constexpr SIZE_T kPage = 64 * 1024;
constexpr UINT32 kSlots = 4; // one request spans four 64 KB slots
constexpr UINT32 kRequestBytes = kSlots * kPage;
constexpr DWORD kMem64KPages = 0x20400000;
constexpr uint64_t kXMemCpu = 0x1;
constexpr uint64_t kXMemMappable = 0x20;
#define CHECK(condition) \
do { \
if (!(condition)) { \
std::fprintf(stderr, "xcrdapi remap guard:%d: %s (Win32 error %lu)\n", __LINE__, \
#condition, static_cast<unsigned long>(GetLastError())); \
return 1; \
} \
} while (false)
template <class Interface>
struct Com {
Interface* value = nullptr;
~Com() {
if (value) value->Release();
}
Interface* operator->() const { return value; }
void** out() { return reinterpret_cast<void**>(&value); }
};
// RFC 1950 stream for `count` copies of `byte`: one fixed-Huffman deflate block (RFC 1951
// 3.2.6) holding the byte as a literal, then copies of distance 1 (length 258, and one shorter
// copy for the rest), then end of block; adler-32 at the end.
class BitWriter {
public:
std::vector<unsigned char> bytes;
void bits(uint32_t value, int n) { // LSB first, as deflate packs header and extra bits
for (int i = 0; i < n; ++i) put((value >> i) & 1u);
}
void code(uint32_t value, int n) { // Huffman codes are packed most significant bit first
for (int i = n - 1; i >= 0; --i) put((value >> i) & 1u);
}
private:
void put(uint32_t bit) {
if (used_ == 0) bytes.push_back(0);
bytes.back() |= static_cast<unsigned char>(bit << used_);
used_ = (used_ + 1) & 7;
}
int used_ = 0;
};
std::vector<unsigned char> zlib_repeat(unsigned char byte, uint32_t count) {
BitWriter w;
w.bits(1, 1); // BFINAL
w.bits(1, 2); // BTYPE = 01, fixed Huffman codes
w.code(0x30u + byte, 8); // literals 0-143: 8-bit codes 00110000 + value
uint32_t left = count - 1;
while (left) {
if (left >= 258) {
w.code(0xC0u + (285 - 280), 8); // length 258: symbol 285, codes 280-287 are 11000000 + n
left -= 258;
} else {
// Lengths 3..257 below 258 use symbols 257-284 with extra bits; this stream only needs
// what is left after 258-byte copies, which the test keeps at 15 (symbol 267: lengths
// 15-16, 1 extra bit).
if (left != 15) return {};
w.code(267 - 256, 7); // symbols 256-279: 7-bit codes 0000000 + (n - 256)
w.bits(0, 1); // extra bit: 15 = base 15 + 0
left = 0;
}
w.code(0, 5); // distance code 0 = distance 1, 5-bit fixed code, no extra bits
}
w.code(0, 7); // end of block: symbol 256
std::vector<unsigned char> out = {0x78, 0x01};
out.insert(out.end(), w.bytes.begin(), w.bytes.end());
uint32_t a = 1, b = 0;
for (uint32_t i = 0; i < count; ++i) {
a = (a + byte) % 65521;
b = (b + a) % 65521;
}
const uint32_t adler = (b << 16) | a;
for (int shift = 24; shift >= 0; shift -= 8) out.push_back(static_cast<unsigned char>(adler >> shift));
return out;
}
} // namespace
int main() {
// Eight pages: four in the window under test, four to swap in and out of it.
ULONG_PTR count = 8;
ULONG_PTR pages[8]{};
CHECK(XMemAllocatePhysicalPages(0, &count, pages) && count == 8);
auto* base = static_cast<BYTE*>(XMemVirtualAlloc(nullptr, kSlots * kPage, MEM_RESERVE | kMem64KPages,
kXMemMappable | kXMemCpu, PAGE_READWRITE));
CHECK(base);
CHECK(XMemMapPhysicalPages(base, kSlots, pages) == base);
Com<IDStorageFactory> factory;
CHECK(DStorageGetFactory(__uuidof(IDStorageFactory), factory.out()) == S_OK && factory.value);
DSTORAGE_QUEUE_DESC desc{};
desc.SourceType = DSTORAGE_REQUEST_SOURCE_MEMORY;
desc.Capacity = DSTORAGE_MIN_QUEUE_CAPACITY;
desc.Priority = DSTORAGE_PRIORITY_NORMAL;
Com<IDStorageQueue1> queue;
CHECK(factory->CreateQueue(&desc, __uuidof(IDStorageQueue1), queue.out()) == S_OK);
HANDLE done = CreateEventW(nullptr, FALSE, FALSE, nullptr);
CHECK(done);
std::vector<unsigned char> source(kRequestBytes, 0xA5);
DSTORAGE_REQUEST request{};
request.Options.SourceType = DSTORAGE_REQUEST_SOURCE_MEMORY;
request.Options.DestinationType = DSTORAGE_REQUEST_DESTINATION_MEMORY;
request.Source.Memory.Source = source.data();
request.Source.Memory.Size = kRequestBytes;
request.Destination.Memory.Buffer = base;
request.Destination.Memory.Size = kRequestBytes;
// Slots 1 and 2 of the window are remapped between two page pairs; slots 0 and 3 keep theirs.
ULONG_PTR swap_a[2] = {pages[1], pages[2]};
ULONG_PTR swap_b[2] = {pages[5], pages[6]};
const DWORD start = GetTickCount();
int batches = 0;
int remaps = 0;
while (GetTickCount() - start < 3000) {
for (int i = 0; i < 4; ++i) queue->EnqueueRequest(&request);
queue->EnqueueSetEvent(done);
queue->Submit();
// Remap under the requests while they run: the title does this between requests.
for (int i = 0; i < 4; ++i) {
CHECK(XMemMapPhysicalPages(base + kPage, 2, (remaps & 1) ? swap_b : swap_a) == base + kPage);
++remaps;
}
CHECK(WaitForSingleObject(done, 10000) == WAIT_OBJECT_0);
++batches;
}
CHECK(WaitForSingleObject(queue->GetErrorEvent(), 0) == WAIT_TIMEOUT);
std::printf("stores: batches=%d remaps=%d\n", batches, remaps);
CHECK(batches > 10 && remaps > 40);
// 2. zlib streams inflated into the window, through BetterXen's request interface.
using namespace bx::storage;
Com<Factory> synthetic;
CHECK(DStorageGetFactory(factory_iid, synthetic.out()) == S_OK && synthetic.value);
Com<Queue> zqueue;
CHECK(synthetic->CreateQueue(64, queue_iid, zqueue.out()) == S_OK && zqueue.value);
const std::vector<unsigned char> zstream = zlib_repeat(0x5A, kRequestBytes); // 1 + 1016 * 258 + 15 bytes
CHECK(!zstream.empty() && zstream.size() < kRequestBytes);
Request zrequest{nullptr, 0, zstream.data(), base, static_cast<DWORD>(zstream.size()), compression_zlib};
zrequest.output_size = kRequestBytes;
// Control: the stream inflates correctly with nothing remapped.
zqueue->EnqueueRequest(&zrequest);
zqueue->EnqueueSetEvent(done);
zqueue->Submit();
CHECK(WaitForSingleObject(done, 10000) == WAIT_OBJECT_0);
ErrorRecord zcontrol{};
zqueue->RetrieveErrorRecord(&zcontrol);
std::printf("zlib control: failures=%llu hr=0x%08lx first=%02x last=%02x\n",
static_cast<unsigned long long>(zcontrol.failure_count), static_cast<unsigned long>(zcontrol.first_error),
base[0], base[kRequestBytes - 1]);
CHECK(zcontrol.failure_count == 0 && base[0] == 0x5A && base[kPage + 7] == 0x5A && base[kRequestBytes - 1] == 0x5A);
int zbatches = 0;
const DWORD zstart = GetTickCount();
while (GetTickCount() - zstart < 4000) {
for (int i = 0; i < 4; ++i) zqueue->EnqueueRequest(&zrequest);
zqueue->EnqueueSetEvent(done);
zqueue->Submit();
for (int i = 0; i < 8; ++i) {
CHECK(XMemMapPhysicalPages(base + kPage, 2, (remaps & 1) ? swap_b : swap_a) == base + kPage);
++remaps;
}
CHECK(WaitForSingleObject(done, 10000) == WAIT_OBJECT_0);
++zbatches;
}
ErrorRecord zerr{};
zqueue->RetrieveErrorRecord(&zerr);
std::printf("zlib under remap: batches=%d failures=%llu\n", zbatches, static_cast<unsigned long long>(zerr.failure_count));
if (zerr.failure_count) std::printf("zlib first error hr=0x%08lx count=%llu\n", static_cast<unsigned long>(zerr.first_error), static_cast<unsigned long long>(zerr.failure_count));
CHECK(zerr.failure_count == 0);
CHECK(base[0] == 0x5A && base[kRequestBytes - 1] == 0x5A); // slots 0 and 3 keep their pages
CHECK(zbatches > 10);
// 3. The window as the source: loads from title memory into private memory.
std::vector<unsigned char> sink(kRequestBytes, 0);
DSTORAGE_REQUEST load{};
load.Options.SourceType = DSTORAGE_REQUEST_SOURCE_MEMORY;
load.Options.DestinationType = DSTORAGE_REQUEST_DESTINATION_MEMORY;
load.Source.Memory.Source = base;
load.Source.Memory.Size = kRequestBytes;
load.Destination.Memory.Buffer = sink.data();
load.Destination.Memory.Size = kRequestBytes;
int lbatches = 0;
const DWORD lstart = GetTickCount();
while (GetTickCount() - lstart < 2000) {
for (int i = 0; i < 4; ++i) queue->EnqueueRequest(&load);
queue->EnqueueSetEvent(done);
queue->Submit();
for (int i = 0; i < 4; ++i) {
CHECK(XMemMapPhysicalPages(base + kPage, 2, (remaps & 1) ? swap_b : swap_a) == base + kPage);
++remaps;
}
CHECK(WaitForSingleObject(done, 10000) == WAIT_OBJECT_0);
++lbatches;
}
CHECK(WaitForSingleObject(queue->GetErrorEvent(), 0) == WAIT_TIMEOUT);
CHECK(sink[0] == 0x5A); // slot 0 still holds the inflated bytes
std::printf("loads: batches=%d remaps=%d\n", lbatches, remaps);
CHECK(lbatches > 10);
CloseHandle(done);
std::puts("test_xcrdapi_remap_guard: passed");
return 0;
}
@@ -3,3 +3,16 @@ add_executable(test_xcrdapi_xbox main.cpp)
target_compile_definitions(test_xcrdapi_xbox PRIVATE WIDL_EXPLICIT_AGGREGATE_RETURNS)
target_include_directories(test_xcrdapi_xbox PRIVATE "${BX_ABI_INCLUDE_DIR}" "${BX_ROOT_DIR}/shims/xcrdapi/dstorage")
target_link_libraries(test_xcrdapi_xbox PRIVATE xcrdapi bx_runtime_veh kernel32)
# Load this observer explicitly from a test-only directory. Keep the fixture
# DLL and its import library away from the real shim's build artifacts.
add_library(test_xcrdapi_guard_observer SHARED guard_observer.cpp)
set(guard_fixture_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xcrdapi_guard_fixture")
set_target_properties(test_xcrdapi_guard_observer PROPERTIES
PREFIX ""
OUTPUT_NAME xmem
RUNTIME_OUTPUT_DIRECTORY "${guard_fixture_dir}"
ARCHIVE_OUTPUT_DIRECTORY "${guard_fixture_dir}"
LIBRARY_OUTPUT_DIRECTORY "${guard_fixture_dir}")
target_link_libraries(test_xcrdapi_guard_observer PRIVATE kernel32)
add_dependencies(test_xcrdapi_xbox test_xcrdapi_guard_observer)
@@ -0,0 +1,22 @@
// Test-only XMem provider. Records guard calls on stable buffers without remapping memory.
#include <windows.h>
#include <cstdint>
namespace {
volatile LONG enters = 0;
volatile LONG leaves = 0;
}
extern "C" __declspec(dllexport) void bx_xmem_remap_guard_enter() {
InterlockedIncrement(&enters);
}
extern "C" __declspec(dllexport) void bx_xmem_remap_guard_leave() {
InterlockedIncrement(&leaves);
}
extern "C" __declspec(dllexport) uint64_t bx_test_guard_counts() {
const auto enter_count = static_cast<uint32_t>(InterlockedCompareExchange(&enters, 0, 0));
const auto leave_count = static_cast<uint32_t>(InterlockedCompareExchange(&leaves, 0, 0));
return (static_cast<uint64_t>(enter_count) << 32) | leave_count;
}
@@ -100,6 +100,40 @@ bool wait_complete(IXboxDStorageStatusArray* status, UINT32 index) {
return false;
}
using GuardCounts = uint64_t (*)();
struct GuardObserver {
HMODULE module = nullptr;
GuardCounts counts = nullptr;
bool load() {
wchar_t executable[MAX_PATH]{};
const DWORD length = GetModuleFileNameW(nullptr, executable, MAX_PATH);
if (!length || length >= MAX_PATH || GetModuleHandleW(L"xmem.dll")) return false;
const std::wstring path(executable, length);
const size_t separator = path.find_last_of(L"\\/");
if (separator == std::wstring::npos) return false;
const std::wstring library = path.substr(0, separator + 1) + L"xcrdapi_guard_fixture\\xmem.dll";
module = LoadLibraryExW(library.c_str(), nullptr,
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
if (!module) return false;
counts = reinterpret_cast<GuardCounts>(reinterpret_cast<void*>(GetProcAddress(module, "bx_test_guard_counts")));
return counts != nullptr;
}
~GuardObserver() {
if (module) FreeLibrary(module);
}
void expect(uint64_t before, uint32_t expected, const char* operation) const {
const uint64_t after = counts();
const auto entered = static_cast<uint32_t>((after >> 32) - (before >> 32));
const auto left = static_cast<uint32_t>(after) - static_cast<uint32_t>(before);
check(entered == expected && left == expected, "%s guard count: enter=%u leave=%u expected=%u",
operation, entered, left, expected);
}
};
/* Reads only what this run appended: bx-cli run appends to a supplied BX_LOG_FILE,
* so records from an earlier run must not satisfy these checks. */
long g_log_start = 0;
@@ -162,6 +196,12 @@ int main() {
}
g_log_start = log_size(log_path);
GuardObserver guard;
if (!guard.load() || !SetEnvironmentVariableW(L"BX_DSTORAGE_TRACE", L"1")) {
std::fprintf(stderr, "FAIL: unable to initialize the DirectStorage guard observer\n");
return 1;
}
IXboxDStorageFactory* factory = nullptr;
HRESULT hr = DStorageGetFactory(kXboxFactoryIid, reinterpret_cast<void**>(&factory));
check(hr == S_OK && factory != nullptr, "DStorageGetFactory(Xbox) must succeed (hr=0x%08lx)",
@@ -247,6 +287,7 @@ int main() {
req.source_ptr = file;
req.file_offset = 64;
req.source_size = sizeof(dest);
const uint64_t file_read_guards = guard.counts();
file_q->EnqueueRequest(&req);
file_q->EnqueueStatus(status, 0);
file_q->Submit();
@@ -254,6 +295,7 @@ int main() {
check(status->GetHResult(0) == S_OK, "file read status must be S_OK (hr=0x%08lx)",
static_cast<unsigned long>(status->GetHResult(0)));
check(std::memcmp(dest, payload + 64, sizeof(dest)) == 0, "file read bytes must match payload[64..192]");
guard.expect(file_read_guards, 2, "file read and destination trace");
/* DSTORAGE_REQUEST_OPTIONS.BcpackMode (bits 1-4) has no decoder: E_NOTIMPL and a stub log. */
XboxRequest bcpack_req = req;
@@ -308,6 +350,7 @@ int main() {
fz.source_ptr = zfile;
fz.file_offset = 100;
fz.source_size = sizeof(kZlibStream);
const uint64_t file_inflate_guards = guard.counts();
file_q->EnqueueRequest(&fz);
file_q->EnqueueStatus(status, 1);
file_q->Submit();
@@ -315,6 +358,7 @@ int main() {
"file-source zlib request must succeed (hr=0x%08lx)", static_cast<unsigned long>(status->GetHResult(1)));
check(std::memcmp(file_inflated, expected_text, kZlibPlainSize) == 0,
"file-source zlib request must inflate to the expected text");
guard.expect(file_inflate_guards, 2, "file-source inflate and destination trace");
zfile->Close();
zfile->Release();
}
@@ -372,12 +416,14 @@ int main() {
zreq.destination_size = kZlibPlainSize;
zreq.source_ptr = const_cast<uint8_t*>(kZlibStream);
zreq.source_size = sizeof(kZlibStream);
const uint64_t mem_inflate_guards = guard.counts();
mem_q->EnqueueRequest(&zreq);
mem_q->EnqueueStatus(status, 1);
mem_q->Submit();
check(wait_complete(status, 1) && status->GetHResult(1) == S_OK, "zlib request must succeed (hr=0x%08lx)",
static_cast<unsigned long>(status->GetHResult(1)));
check(std::memcmp(inflated, expected, kZlibPlainSize) == 0, "zlib request must inflate to the expected text");
guard.expect(mem_inflate_guards, 3, "compressed memory read, inflate, and destination trace");
/* DSTORAGE_QUEUE_OPTIONS.AutoSubmitDisabled (flags bit 0, authorized GDK documentation):
* enqueued work waits for Submit. Without it the queue submits by itself once half full
@@ -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);
+19 -8
View File
@@ -15,12 +15,14 @@ VOID WINAPI XMemFreeDefault(PVOID, uint64_t);
PVOID WINAPI XMemVirtualAlloc(PVOID, SIZE_T, DWORD, uint64_t, DWORD);
SIZE_T WINAPI XMemVirtualQuery(LPCVOID, PMEMORY_BASIC_INFORMATION, SIZE_T);
BOOL WINAPI XMemTransferMemory(PVOID, LPCVOID, SIZE_T, uint64_t);
BOOL WINAPI XMemGetWorkingSetStatistics(PVOID, SIZE_T);
BOOL WINAPI XMemGetWorkingSetStatistics(DWORD, PVOID);
BOOL WINAPI XMemIsToolsMemAvailable();
}
/* XMEM_CPU from the authorized GDK documentation of XMemVirtualAlloc. */
constexpr uint64_t kXMemCpu = 0x1;
/* XMEM_WORKING_SET_TITLE from the authorized GDK header (test_xmem_working_set covers the rest). */
constexpr DWORD kXMemWorkingSetTitle = 0x20000001;
#define CHECK(condition) \
do { \
@@ -38,7 +40,8 @@ int main() {
const auto* config = bx_get_runtime_config();
bx_xmem_stats_t stats{};
CHECK(config && XMemGetWorkingSetStatistics(&stats, sizeof(stats)));
CHECK(config);
bx_xmem_get_internal_stats(&stats);
char profile[16]{};
GetEnvironmentVariableA("BX_PROFILE", profile, sizeof(profile));
const uint64_t expected_limit = std::strcmp(profile, "anaconda") == 0
@@ -48,14 +51,22 @@ int main() {
CHECK(stats.title_limit_bytes == config->title_memory_limit_bytes);
CHECK(stats.committed_virtual_bytes == 0 && stats.allocated_physical_bytes == 0);
CHECK(!XMemIsToolsMemAvailable());
CHECK(!XMemGetWorkingSetStatistics(&stats, sizeof(stats) - 1));
SetLastError(0);
CHECK(!XMemGetWorkingSetStatistics(kXMemWorkingSetTitle, nullptr));
CHECK(GetLastError() == ERROR_INVALID_PARAMETER);
unsigned char large_stats[sizeof(bx_xmem_stats_t) + 16];
std::memset(large_stats, 0xCC, sizeof(large_stats));
CHECK(XMemGetWorkingSetStatistics(large_stats, sizeof(large_stats)));
for (size_t i = sizeof(bx_xmem_stats_t); i < sizeof(large_stats); ++i) {
CHECK(large_stats[i] == 0);
// XMEM_WORKING_SET_STATISTICS is 120 bytes on x64; GameLimit is its first SIZE_T and GameUsed
// its second. Nothing past the structure is written.
alignas(8) unsigned char working_set[120 + 16];
std::memset(working_set, 0xCC, sizeof(working_set));
CHECK(XMemGetWorkingSetStatistics(kXMemWorkingSetTitle, working_set));
uint64_t game_limit = 0;
uint64_t game_used = 0;
std::memcpy(&game_limit, working_set, sizeof(game_limit));
std::memcpy(&game_used, working_set + 8, sizeof(game_used));
CHECK(game_limit == stats.title_limit_bytes && game_used == 0);
for (size_t i = 120; i < sizeof(working_set); ++i) {
CHECK(working_set[i] == 0xCC);
}
auto* ordinary = XMemAlloc(73, 0);
@@ -5,14 +5,36 @@
#include <cstdint>
#include <cstdio>
#include <cstring>
#include "bx_xmem_internal.h"
extern "C" {
PVOID WINAPI XMemVirtualAlloc(PVOID, SIZE_T, DWORD, uint64_t, DWORD);
BOOL WINAPI XMemGetWorkingSetStatistics(PVOID, SIZE_T);
BOOL WINAPI XMemGetWorkingSetStatistics(DWORD, PVOID);
}
namespace {
// XMEM_WORKING_SET_TITLE, and the title fields of the 120-byte XMEM_WORKING_SET_STATISTICS on
// x64 (authorized GDK header): GameLimit, GameUsed and GameUsedPeak are SIZE_Ts at these offsets.
constexpr DWORD kXMemWorkingSetTitle = 0x20000001;
struct TitleUsage {
uint64_t limit;
uint64_t used;
uint64_t peak;
};
bool title_usage(TitleUsage& usage) {
alignas(8) unsigned char statistics[120]{};
if (!XMemGetWorkingSetStatistics(kXMemWorkingSetTitle, statistics)) return false;
std::memcpy(&usage.limit, statistics + 0x00, sizeof(usage.limit));
std::memcpy(&usage.used, statistics + 0x08, sizeof(usage.used));
std::memcpy(&usage.peak, statistics + 0x58, sizeof(usage.peak));
return true;
}
} // namespace
#define CHECK(condition) \
do { \
if (!(condition)) { \
@@ -28,24 +50,24 @@ int main() {
GetSystemInfo(&sys);
const SIZE_T page = sys.dwPageSize;
bx_xmem_stats_t stats{};
CHECK(XMemGetWorkingSetStatistics(&stats, sizeof(stats)));
const uint64_t used = stats.committed_virtual_bytes + stats.allocated_physical_bytes;
CHECK(used < stats.title_limit_bytes);
TitleUsage stats{};
CHECK(title_usage(stats));
const uint64_t used = stats.used;
CHECK(used < stats.limit);
// Only bookkeeping is charged; nothing of this size is allocated on the host.
const uint64_t headroom = stats.title_limit_bytes - used;
const uint64_t headroom = stats.limit - used;
// Graphics-first order: an external charge fills the cap...
CHECK(bx_xmem_try_charge_external(headroom) == 1);
CHECK(bx_xmem_try_charge_external(1) == 0);
// ...is visible in the reported usage, and peak never exceeds it...
CHECK(XMemGetWorkingSetStatistics(&stats, sizeof(stats)));
CHECK(stats.committed_virtual_bytes + stats.allocated_physical_bytes == stats.title_limit_bytes);
CHECK(stats.peak_committed_bytes <= stats.title_limit_bytes);
CHECK(title_usage(stats));
CHECK(stats.used == stats.limit);
CHECK(stats.peak <= stats.limit);
bx_xmem_stats_t internal{};
bx_xmem_get_internal_stats(&internal);
CHECK(internal.committed_virtual_bytes == stats.committed_virtual_bytes);
CHECK(internal.committed_virtual_bytes + internal.allocated_physical_bytes == stats.used);
// ...and a later XMem commit is refused against the same cap.
SetLastError(0);
@@ -55,13 +77,13 @@ int main() {
// An over-release is refused and leaves the outstanding charge in place.
bx_xmem_release_charge_external(headroom + 1);
CHECK(bx_xmem_try_charge_external(1) == 0);
CHECK(XMemGetWorkingSetStatistics(&stats, sizeof(stats)));
CHECK(stats.committed_virtual_bytes + stats.allocated_physical_bytes == stats.title_limit_bytes);
CHECK(title_usage(stats));
CHECK(stats.used == stats.limit);
// Releasing the real charge admits the same XMem commit again.
bx_xmem_release_charge_external(headroom);
CHECK(XMemGetWorkingSetStatistics(&stats, sizeof(stats)));
CHECK(stats.committed_virtual_bytes + stats.allocated_physical_bytes == used);
CHECK(title_usage(stats));
CHECK(stats.used == used);
void* block = XMemVirtualAlloc(nullptr, page, MEM_COMMIT | MEM_RESERVE, 0x1 /* XMEM_CPU */, PAGE_READWRITE);
CHECK(block != nullptr);
CHECK(VirtualFree(block, 0, MEM_RELEASE));
+19 -7
View File
@@ -8,8 +8,10 @@
*/
#include <windows.h>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include "bx_xmem_internal.h"
@@ -21,7 +23,7 @@ BOOL WINAPI XMemAllocatePhysicalPages(uint64_t, PULONG_PTR, PULONG_PTR);
BOOL WINAPI XMemFreePhysicalPages(ULONG_PTR, PULONG_PTR);
PVOID WINAPI XMemMapPhysicalPages(PVOID, ULONG_PTR, PULONG_PTR);
BOOL WINAPI XMemMapPhysicalPagesScatter(PVOID*, ULONG_PTR, PULONG_PTR);
BOOL WINAPI XMemGetWorkingSetStatistics(PVOID, SIZE_T);
BOOL WINAPI XMemGetWorkingSetStatistics(DWORD, PVOID);
}
namespace {
@@ -37,6 +39,11 @@ constexpr uint64_t kXMemGraphics32BitAddress = 0x7;
constexpr DWORD kMemReservePlaceholder = 0x40000;
constexpr DWORD kMemReplacePlaceholder = 0x4000;
constexpr DWORD kPageGraphicsReadWrite = 0x2000;
// XMEM_WORKING_SET_TITLE; in the 120-byte XMEM_WORKING_SET_STATISTICS (x64),
// GameAllocatedPhysicalPageCount is the UINT32 at byte 0x24.
constexpr DWORD kXMemWorkingSetTitle = 0x20000001;
constexpr size_t kWorkingSetSize = 120;
constexpr size_t kGameAllocatedPhysicalPageCount = 0x24;
#define CHECK(condition) \
do { \
@@ -54,7 +61,7 @@ DWORD state_of(const void* address) {
bool check_physical_pages() {
bx_xmem_stats_t stats{};
CHECK(XMemGetWorkingSetStatistics(&stats, sizeof(stats)));
bx_xmem_get_internal_stats(&stats);
CHECK(stats.allocated_physical_bytes == 0);
// Flags outside 2 MB clusters and the bandwidth values are refused before anything changes.
@@ -76,9 +83,11 @@ bool check_physical_pages() {
CHECK((pages[0] >> 4) != (pages[1] >> 4) && (pages[1] >> 4) != (pages[2] >> 4) && (pages[2] >> 4) != (pages[3] >> 4));
bx_xmem_get_internal_stats(&stats);
CHECK(stats.allocated_physical_bytes == 4 * kPage);
bx_xmem_stats_t ws_stats{};
CHECK(XMemGetWorkingSetStatistics(&ws_stats, sizeof(ws_stats)));
CHECK(ws_stats.allocated_physical_bytes == 4 * kPage);
alignas(8) unsigned char working_set[kWorkingSetSize]{};
CHECK(XMemGetWorkingSetStatistics(kXMemWorkingSetTitle, working_set));
uint32_t working_set_pages = 0;
std::memcpy(&working_set_pages, working_set + kGameAllocatedPhysicalPageCount, sizeof(working_set_pages));
CHECK(working_set_pages == 4);
ULONG_PTR cap_pages = static_cast<ULONG_PTR>(stats.title_limit_bytes / kPage);
CHECK(!XMemAllocatePhysicalPages(0, &cap_pages, pages));
@@ -101,8 +110,11 @@ bool check_physical_pages() {
ULONG_PTR reversed[] = {pages[3], pages[2], pages[1], pages[0]};
CHECK(XMemMapPhysicalPages(base + 4 * kPage, 4, reversed) == base + 4 * kPage);
CHECK(base[4 * kPage + 9] == 0x43 && base[7 * kPage + 9] == 0x40);
base[5 * kPage + 1] = 0x7e;
CHECK(base[2 * kPage + 1] == 0x7e);
// Slots 2 and 5 now alias one physical page, which the compiler cannot know: write and read
// through volatile, or the read may be scheduled before the write.
volatile BYTE* const view = base;
view[5 * kPage + 1] = 0x7e;
CHECK(view[2 * kPage + 1] == 0x7e);
bx_xmem_region_info_t info{};
CHECK(bx_xmem_query_region(reinterpret_cast<uintptr_t>(base + 4 * kPage + 3), &info));
@@ -0,0 +1,3 @@
add_executable(test_xmem_remap_guard main.cpp)
target_include_directories(test_xmem_remap_guard PRIVATE "${BX_ABI_INCLUDE_DIR}")
target_link_libraries(test_xmem_remap_guard PRIVATE xmem kernel32)
@@ -0,0 +1,169 @@
/*
* The remap guard (bx_xmem_remap_guard_enter / _leave): Windows and Wine cannot replace a mapped
* view in one step, so remapping a range leaves its pages unmapped for a moment and a store from
* another thread into that window faults. A writer that brackets its stores with the guard must
* never see that gap, and XMemMapPhysicalPages, XMemMapPhysicalPagesScatter and
* XMemFreePhysicalPages must wait for it. Observed on the target build (handoff #668): worker
* threads of XCRDAPI.dll storing into a window the title was remapping.
*/
#include <windows.h>
#include <cstdint>
#include <cstdio>
#include "bx_xmem_internal.h"
extern "C" {
PVOID WINAPI XMemVirtualAlloc(PVOID, SIZE_T, DWORD, uint64_t, DWORD);
BOOL WINAPI XMemAllocatePhysicalPages(uint64_t, PULONG_PTR, PULONG_PTR);
BOOL WINAPI XMemFreePhysicalPages(ULONG_PTR, PULONG_PTR);
PVOID WINAPI XMemMapPhysicalPages(PVOID, ULONG_PTR, PULONG_PTR);
BOOL WINAPI XMemMapPhysicalPagesScatter(PVOID*, ULONG_PTR, PULONG_PTR);
}
namespace {
constexpr SIZE_T kPage = 64 * 1024;
constexpr DWORD kMem64KPages = 0x20400000;
constexpr uint64_t kXMemCpu = 0x1;
constexpr uint64_t kXMemMappable = 0x20;
#define CHECK(condition) \
do { \
if (!(condition)) { \
std::fprintf(stderr, "xmem remap guard:%d: %s (Win32 error %lu)\n", __LINE__, \
#condition, static_cast<unsigned long>(GetLastError())); \
return false; \
} \
} while (false)
struct Holder {
HANDLE entered;
HANDLE release;
};
DWORD WINAPI hold_guard(void* arg) {
auto* holder = static_cast<Holder*>(arg);
bx_xmem_remap_guard_enter();
SetEvent(holder->entered);
WaitForSingleObject(holder->release, 10000);
bx_xmem_remap_guard_leave();
return 0;
}
enum class Call { map, scatter, free_pages };
struct Remap {
Call call;
BYTE* base;
ULONG_PTR* pages;
bool ok;
};
DWORD WINAPI do_remap(void* arg) {
auto* remap = static_cast<Remap*>(arg);
switch (remap->call) {
case Call::map:
remap->ok = XMemMapPhysicalPages(remap->base, 2, remap->pages) == remap->base;
break;
case Call::scatter: {
PVOID slots[2] = {remap->base, remap->base + kPage};
remap->ok = XMemMapPhysicalPagesScatter(slots, 2, remap->pages) != FALSE;
break;
}
case Call::free_pages:
remap->ok = XMemFreePhysicalPages(2, remap->pages) != FALSE;
break;
}
return 0;
}
// While one thread holds the guard, the call must not finish; once released, it must.
bool blocks_until_released(Call call, BYTE* base, ULONG_PTR* pages) {
Holder holder{CreateEventW(nullptr, TRUE, FALSE, nullptr), CreateEventW(nullptr, TRUE, FALSE, nullptr)};
CHECK(holder.entered && holder.release);
HANDLE guard_thread = CreateThread(nullptr, 0, hold_guard, &holder, 0, nullptr);
CHECK(guard_thread);
CHECK(WaitForSingleObject(holder.entered, 5000) == WAIT_OBJECT_0);
Remap remap{call, base, pages, false};
HANDLE remap_thread = CreateThread(nullptr, 0, do_remap, &remap, 0, nullptr);
CHECK(remap_thread);
CHECK(WaitForSingleObject(remap_thread, 300) == WAIT_TIMEOUT); // waits for the open guard
SetEvent(holder.release);
CHECK(WaitForSingleObject(remap_thread, 5000) == WAIT_OBJECT_0); // and goes on once it is gone
CHECK(remap.ok);
WaitForSingleObject(guard_thread, 5000);
CloseHandle(remap_thread);
CloseHandle(guard_thread);
CloseHandle(holder.entered);
CloseHandle(holder.release);
return true;
}
struct Writer {
BYTE* stable; // a slot that keeps its page
BYTE* neighbour; // a slot that is remapped all the time
volatile LONG stop;
volatile LONG stores;
};
DWORD WINAPI write_under_guard(void* arg) {
auto* writer = static_cast<Writer*>(arg);
while (!writer->stop) {
bx_xmem_remap_guard_enter();
for (int i = 0; i < 64; ++i) {
writer->stable[i * 8] = static_cast<BYTE>(i);
writer->neighbour[i * 8] = static_cast<BYTE>(i);
}
bx_xmem_remap_guard_leave();
InterlockedIncrement(&writer->stores);
}
return 0;
}
bool check_remap_guard() {
ULONG_PTR count = 8;
ULONG_PTR pages[8]{};
CHECK(XMemAllocatePhysicalPages(0, &count, pages) && count == 8);
auto* base = static_cast<BYTE*>(XMemVirtualAlloc(nullptr, 8 * kPage, MEM_RESERVE | kMem64KPages,
kXMemMappable | kXMemCpu, PAGE_READWRITE));
CHECK(base);
CHECK(XMemMapPhysicalPages(base, 4, pages) == base);
// 1. Each call that unmaps or maps views waits for an open guard.
ULONG_PTR other[2] = {pages[5], pages[6]};
CHECK(blocks_until_released(Call::map, base + 2 * kPage, other));
CHECK(blocks_until_released(Call::scatter, base + 2 * kPage, pages + 2));
CHECK(blocks_until_released(Call::free_pages, base, pages + 6));
// 2. A writer that brackets its stores never faults while its neighbours are remapped as
// often (without the guard the process dies in an access violation).
CHECK(XMemMapPhysicalPages(base, 4, pages) == base);
Writer writer{base, base + kPage, 0, 0};
HANDLE thread = CreateThread(nullptr, 0, write_under_guard, &writer, 0, nullptr);
CHECK(thread);
ULONG_PTR a[2] = {pages[1], pages[2]};
ULONG_PTR b[2] = {pages[2], pages[1]};
const DWORD start = GetTickCount();
int remaps = 0;
while (GetTickCount() - start < 1500) {
CHECK(XMemMapPhysicalPages(base + kPage, 2, (remaps & 1) ? b : a) == base + kPage);
++remaps;
Sleep(1); // a title remaps between requests; SRW locks are not fair to a loop with no gap
}
InterlockedExchange(&writer.stop, 1);
CHECK(WaitForSingleObject(thread, 5000) == WAIT_OBJECT_0);
CloseHandle(thread);
std::printf("remaps=%d guarded writer batches=%ld\n", remaps, static_cast<long>(writer.stores));
CHECK(remaps > 10 && writer.stores > 10);
return true;
}
} // namespace
int main() {
if (!check_remap_guard()) return 1;
std::puts("test_xmem_remap_guard: passed");
}
@@ -0,0 +1,3 @@
add_executable(test_xmem_working_set main.cpp)
target_include_directories(test_xmem_working_set PRIVATE "${BX_ABI_INCLUDE_DIR}")
target_link_libraries(test_xmem_working_set PRIVATE xmem bx_runtime_veh kernel32)
@@ -0,0 +1,243 @@
/*
* XMemGetWorkingSetStatistics(WorkingSetFlags, Statistics), as the authorized GDK header declares
* it: a DWORD of XMEM_WORKING_SET_* flags, then a pointer to the statistics structure.
*
* The flag values and the structure layout below are written out from that header for x64
* (SIZE_T is 8 bytes, UINT32 is 4, fields in declaration order with natural alignment), not taken
* from xmem.dll. Fields are read at these literal byte offsets, so a shim that lays the structure
* out differently, or writes past it, fails here.
*
* What xmem.dll reports (BetterXen's inference, recorded in shims/xmem/xmem.cpp):
* - GameLimit is the title memory cap, GameUsed everything the cap counts (XMem heap, virtual
* commits, physical pages, external charges), GameUsedPeak the highest GameUsed, and
* GameAllocatedPhysicalPageCount the 64 KiB physical pages allocated;
* - tools memory is unavailable (XMemIsToolsMemAvailable is FALSE), so the tools fields are 0;
* - the counters the host does not track (stack, GPU-optimal bandwidth, kernel pool,
* DirectStorage, frame-preserve buffer, page tables) and the reserved words are 0;
* - every field is written whichever flags are passed, and flags outside the five
* XMEM_WORKING_SET_* values are refused.
*/
#include <windows.h>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include "bx_log.h"
#include "bx_xmem_internal.h"
extern "C" {
BOOL WINAPI XMemGetWorkingSetStatistics(DWORD, PVOID);
BOOL WINAPI XMemIsToolsMemAvailable();
PVOID WINAPI XMemAllocDefault(SIZE_T, uint64_t);
VOID WINAPI XMemFreeDefault(PVOID, uint64_t);
PVOID WINAPI XMemVirtualAlloc(PVOID, SIZE_T, DWORD, uint64_t, DWORD);
BOOL WINAPI XMemAllocatePhysicalPages(uint64_t, PULONG_PTR, PULONG_PTR);
BOOL WINAPI XMemFreePhysicalPages(ULONG_PTR, PULONG_PTR);
}
namespace {
// XMEM_WORKING_SET_* flags.
constexpr DWORD kTitle = 0x20000001;
constexpr DWORD kTools = 0x20000002;
constexpr DWORD kStack = 0x20000004;
constexpr DWORD kKernelPool = 0x20000008;
constexpr DWORD kCpuPte = 0x20000010;
constexpr DWORD kAll = kTitle | kTools | kStack | kKernelPool | kCpuPte;
// XMEM_WORKING_SET_STATISTICS byte offsets on x64.
constexpr size_t kGameLimit = 0x00; // SIZE_T
constexpr size_t kGameUsed = 0x08; // SIZE_T
constexpr size_t kToolsLimit = 0x10; // SIZE_T
constexpr size_t kToolsUsed = 0x18; // SIZE_T
constexpr size_t kStackUsed = 0x20; // UINT32
constexpr size_t kGameAllocatedPhysicalPageCount = 0x24; // UINT32
constexpr size_t kGpuOptimalBandwidthLimit = 0x28; // SIZE_T
constexpr size_t kGpuOptimalBandwidthUsed = 0x30; // SIZE_T
constexpr size_t kToolsGpuOptimalBandwidthLimit = 0x38; // SIZE_T
constexpr size_t kToolsGpuOptimalBandwidthUsed = 0x40; // SIZE_T
constexpr size_t kKernelPoolUsed = 0x48; // UINT32
constexpr size_t kKernelPoolLimit = 0x4C; // UINT32
constexpr size_t kDirectStorageUsed = 0x50; // UINT32
constexpr size_t kFramePreserveBufferSize = 0x54; // UINT32
constexpr size_t kGameUsedPeak = 0x58; // SIZE_T
constexpr size_t kGpuPageTableSize = 0x60; // UINT32
constexpr size_t kCpuPageTableSize = 0x64; // UINT32
constexpr size_t kReserved0 = 0x68; // SIZE_T reserved1[0]
constexpr size_t kReserved1 = 0x70; // SIZE_T reserved1[1]
constexpr size_t kStatisticsSize = 0x78;
// XMEM_CPU (XMemVirtualAlloc) and the physical page size, from the same documentation.
constexpr uint64_t kXMemCpu = 0x1;
constexpr uint64_t kPhysicalPage = 64 * 1024;
constexpr unsigned char kFill = 0xCC;
constexpr size_t kGuard = 32;
// The structure sits between two guard bands; the shim may write only the structure.
struct Probe {
alignas(16) unsigned char bytes[kGuard + kStatisticsSize + kGuard];
void fill() { std::memset(bytes, kFill, sizeof(bytes)); }
void* statistics() { return bytes + kGuard; }
uint64_t u64(size_t offset) const {
uint64_t value;
std::memcpy(&value, bytes + kGuard + offset, sizeof(value));
return value;
}
uint32_t u32(size_t offset) const {
uint32_t value;
std::memcpy(&value, bytes + kGuard + offset, sizeof(value));
return value;
}
bool guards_intact() const {
for (size_t i = 0; i < kGuard; ++i) {
if (bytes[i] != kFill || bytes[kGuard + kStatisticsSize + i] != kFill) return false;
}
return true;
}
bool untouched() const {
for (unsigned char byte : bytes) {
if (byte != kFill) return false;
}
return true;
}
// Fields xmem.dll does not account for are written as zero, whatever the flags.
bool untracked_fields_zero() const {
return u64(kToolsLimit) == 0 && u64(kToolsUsed) == 0 && u32(kStackUsed) == 0
&& u64(kGpuOptimalBandwidthLimit) == 0 && u64(kGpuOptimalBandwidthUsed) == 0
&& u64(kToolsGpuOptimalBandwidthLimit) == 0 && u64(kToolsGpuOptimalBandwidthUsed) == 0
&& u32(kKernelPoolUsed) == 0 && u32(kKernelPoolLimit) == 0 && u32(kDirectStorageUsed) == 0
&& u32(kFramePreserveBufferSize) == 0 && u32(kGpuPageTableSize) == 0
&& u32(kCpuPageTableSize) == 0 && u64(kReserved0) == 0 && u64(kReserved1) == 0;
}
};
// A shim that reads the flags as an address writes through them. Report that as a failure
// instead of an unexplained crash; the handler acts only while the export is running.
volatile LONG g_in_call = 0;
LONG CALLBACK fault_in_call(EXCEPTION_POINTERS* info) {
if (g_in_call && info->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
std::fprintf(stderr, "FAIL: test_xmem_working_set: access violation inside "
"XMemGetWorkingSetStatistics (write=%llu address=0x%llx)\n",
static_cast<unsigned long long>(info->ExceptionRecord->ExceptionInformation[0]),
static_cast<unsigned long long>(info->ExceptionRecord->ExceptionInformation[1]));
std::fflush(stderr);
ExitProcess(1);
}
return EXCEPTION_CONTINUE_SEARCH;
}
BOOL get_statistics(DWORD flags, void* statistics) {
InterlockedExchange(&g_in_call, 1);
const BOOL ok = XMemGetWorkingSetStatistics(flags, statistics);
InterlockedExchange(&g_in_call, 0);
return ok;
}
} // namespace
#define CHECK(condition) \
do { \
if (!(condition)) { \
std::fprintf(stderr, "xmem working set:%d: %s (Win32 error %lu)\n", \
__LINE__, #condition, static_cast<unsigned long>(GetLastError())); \
return 1; \
} \
} while (false)
int main() {
CHECK(AddVectoredExceptionHandler(1, fault_in_call) != nullptr);
SYSTEM_INFO sys{};
GetSystemInfo(&sys);
const SIZE_T page = sys.dwPageSize;
const auto* config = bx_get_runtime_config();
CHECK(config && config->title_memory_limit_bytes != 0);
const uint64_t limit = config->title_memory_limit_bytes;
Probe probe{};
// The shape a tools-memory path uses: tools and kernel pool, no title bit.
probe.fill();
SetLastError(0);
CHECK(get_statistics(kTools | kKernelPool, probe.statistics()));
CHECK(probe.guards_intact());
CHECK(probe.untracked_fields_zero());
CHECK(!XMemIsToolsMemAvailable());
CHECK(probe.u64(kGameLimit) == limit);
// Title usage at start.
probe.fill();
CHECK(get_statistics(kTitle, probe.statistics()));
CHECK(probe.guards_intact());
CHECK(probe.untracked_fields_zero());
CHECK(probe.u64(kGameLimit) == limit);
const uint64_t used0 = probe.u64(kGameUsed);
const uint32_t pages0 = probe.u32(kGameAllocatedPhysicalPageCount);
const uint64_t peak0 = probe.u64(kGameUsedPeak);
CHECK(used0 < limit && peak0 >= used0);
CHECK(uint64_t{pages0} * kPhysicalPage <= used0);
// Every kind of charge counts in GameUsed: XMem heap, a virtual commit, two physical
// pages and an external charge made on behalf of another DLL.
void* heap = XMemAllocDefault(4096, 0);
CHECK(heap != nullptr);
void* block = XMemVirtualAlloc(nullptr, 3 * page, MEM_COMMIT | MEM_RESERVE, kXMemCpu, PAGE_READWRITE);
CHECK(block != nullptr);
ULONG_PTR count = 2;
ULONG_PTR physical[2]{};
CHECK(XMemAllocatePhysicalPages(0, &count, physical) && count == 2);
constexpr uint64_t external = 1 << 20;
CHECK(bx_xmem_try_charge_external(external) == 1);
const uint64_t expected_used = used0 + 4096 + 3 * page + 2 * kPhysicalPage + external;
probe.fill();
CHECK(get_statistics(kTitle, probe.statistics()));
CHECK(probe.guards_intact());
CHECK(probe.untracked_fields_zero());
CHECK(probe.u64(kGameLimit) == limit);
CHECK(probe.u64(kGameUsed) == expected_used);
CHECK(probe.u32(kGameAllocatedPhysicalPageCount) == pages0 + 2);
const uint64_t peak1 = probe.u64(kGameUsedPeak);
CHECK(peak1 >= expected_used && peak1 >= peak0);
// XMEM_WORKING_SET_ALL reports the same title figures.
probe.fill();
CHECK(get_statistics(kAll, probe.statistics()));
CHECK(probe.guards_intact());
CHECK(probe.untracked_fields_zero());
CHECK(probe.u64(kGameUsed) == expected_used);
CHECK(probe.u32(kGameAllocatedPhysicalPageCount) == pages0 + 2);
// Releasing everything returns GameUsed to where it started; the peak stays.
bx_xmem_release_charge_external(external);
CHECK(XMemFreePhysicalPages(2, physical));
CHECK(VirtualFree(block, 0, MEM_RELEASE));
XMemFreeDefault(heap, 0);
probe.fill();
CHECK(get_statistics(kTitle, probe.statistics()));
CHECK(probe.guards_intact());
CHECK(probe.u64(kGameUsed) == used0);
CHECK(probe.u32(kGameAllocatedPhysicalPageCount) == pages0);
CHECK(probe.u64(kGameUsedPeak) == peak1);
// A NULL structure, or flags outside the five XMEM_WORKING_SET_* values, is refused and
// nothing is written.
SetLastError(0);
CHECK(!get_statistics(kTitle, nullptr));
CHECK(GetLastError() == ERROR_INVALID_PARAMETER);
const DWORD bad_flags[] = {0, 0x1, 0x20000000, 0x20000020, kTitle | 0x100};
for (DWORD flags : bad_flags) {
probe.fill();
SetLastError(0);
CHECK(!get_statistics(flags, probe.statistics()));
CHECK(GetLastError() == ERROR_INVALID_PARAMETER);
CHECK(probe.untouched());
}
std::printf("PASS: test_xmem_working_set\n");
return 0;
}