Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ if(EXISTS "${INTAKE_PYTHON}")
"${CMAKE_CURRENT_BINARY_DIR}/triangle_ps_flip.h")
target_include_directories(cpu_shim_draw PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_compile_features(cpu_shim_draw PRIVATE cxx_std_17)
target_link_libraries(cpu_shim_draw PRIVATE dxgi d3d12)
target_link_libraries(cpu_shim_draw PRIVATE dxgi d3d12 d3d12_xs_shim)
add_executable(cpu_shim_startup tests/cpu/shim_startup.asm tests/cpu/exe_startup.asm)
set_target_properties(cpu_shim_startup PROPERTIES LINKER_LANGUAGE CXX)
target_link_options(cpu_shim_startup PRIVATE /ENTRY:native_startup /SUBSYSTEM:CONSOLE /NODEFAULTLIB /INCREMENTAL:NO)
Expand Down
8 changes: 8 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -3831,3 +3831,11 @@ GPU fence, and verifies exit code 42. The stale binding changes only the
second color frame and is checked against its own reference.

Run `ctest --preset release --no-tests=error -R '^cpu_shim_shadow_(warp|hardware)$' -V`.

The EXE shadow path selects an adapter in the host and calls the
`d3d12_xs.dll!D3D12XboxCreateDevice` shim to create the actual device at feature
level 12.0. The fixture uses a null parameter block and the desktop
`ID3D12Device` interface. A non-null Xbox parameter block or unsupported
interface is rejected. The negative case supplies an unsupported IID after
adapter selection. It checks the cleared device output, release of the adapter
and factory references, zero frame bytes and exit code 20 on all three runners.
12 changes: 12 additions & 0 deletions src/d3d12_xs_shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ extern "C" HRESULT WINAPI d3d12_xs_CreateRootSignatureDeserializer(
return D3D12CreateRootSignatureDeserializer(
src_data, src_data_size_in_bytes, deserializer_interface, deserializer);
}

extern "C" HRESULT WINAPI d3d12_xs_XboxCreateDevice(
IUnknown* adapter, const void* parameters, REFIID iid, void** device)
{
if (!device) return E_POINTER;
*device = nullptr;
// This entry supports an explicit desktop consumer of the returned interface.
// The Xbox parameter block and the Xbox device vtable require their own implementation.
if (parameters) return E_INVALIDARG;
if (iid != __uuidof(ID3D12Device)) return E_NOINTERFACE;
return D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_12_0, iid, device);
}
1 change: 1 addition & 0 deletions src/d3d12_xs_shim.def
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ LIBRARY d3d12_xs
EXPORTS
D3D12SerializeVersionedRootSignature=d3d12_xs_SerializeVersionedRootSignature
D3D12CreateRootSignatureDeserializer=d3d12_xs_CreateRootSignatureDeserializer
D3D12XboxCreateDevice=d3d12_xs_XboxCreateDevice
24 changes: 20 additions & 4 deletions tests/cpu/shim_chain_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <string>
#include <vector>

extern "C" HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**);

namespace {
using Microsoft::WRL::ComPtr;

Expand Down Expand Up @@ -65,7 +67,7 @@ std::vector<char> read_input(const char* name)
// WARP by default. "hardware" takes the first physical D3D12 adapter in high-performance
// order or, with XBOX2WINDOWS_ADAPTER, the first whose description contains that value.
// No physical adapter is a capability skip (77); a filter that matches none is an error.
ComPtr<ID3D12Device> create_device()
ComPtr<ID3D12Device> create_device(bool xbox_shim = false, bool reject = false)
{
ComPtr<IDXGIFactory6> factory;
require(CreateDXGIFactory2(0, IID_PPV_ARGS(&factory)), "CreateDXGIFactory2");
Expand Down Expand Up @@ -106,7 +108,21 @@ ComPtr<ID3D12Device> create_device()
require(E_INVALIDARG, "Select draw adapter");
}
ComPtr<ID3D12Device> device;
require(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)), "D3D12CreateDevice");
if (!xbox_shim) {
require(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)), "D3D12CreateDevice");
return device;
}
if (reject) {
void* rejected = adapter.Get();
const auto hr = D3D12XboxCreateDevice(adapter.Get(), nullptr, __uuidof(IDXGIFactory6), &rejected);
if (hr != E_NOINTERFACE || rejected || !adapter || !factory)
fail("Unexpected rejected shim device or missing adapter ownership");
adapter.Reset();
factory.Reset();
std::fputs("Xbox device rejected: no device, released adapter and factory\n", stderr);
throw Failure{};
}
require(D3D12XboxCreateDevice(adapter.Get(), nullptr, IID_PPV_ARGS(&device)), "D3D12XboxCreateDevice");
return device;
}

Expand Down Expand Up @@ -380,13 +396,13 @@ bool shim_chain_gpu(unsigned mode, std::vector<unsigned char>& published, unsign
}
}

bool shim_shadow_gpu(bool stale, std::vector<unsigned char>& output)
bool shim_shadow_gpu(bool stale, bool reject, std::vector<unsigned char>& output)
{
try {
const auto* path = std::getenv("X2W_SHIM_CHAIN_DIR");
if (!path || !*path) return false;
const auto directory = std::filesystem::path(path);
auto device = create_device();
auto device = create_device(true, reject);
if (!check_mesh_shadow_draw(device.Get(), (directory / "mesh.dxil").string().c_str(),
(directory / "receiver.dxil").string().c_str(),
(directory / "caster.dxil").string().c_str(),
Expand Down
7 changes: 4 additions & 3 deletions tests/cpu/shim_draw_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
bool shim_draw_gpu(unsigned mode, std::vector<unsigned char>& rgba);
bool shim_chain_gpu(unsigned mode, std::vector<unsigned char>& published, unsigned& mismatches);

bool shim_shadow_gpu(bool stale, std::vector<unsigned char>& output);
bool shim_shadow_gpu(bool stale, bool reject, std::vector<unsigned char>& output);

namespace {
constexpr unsigned side = 64;
Expand Down Expand Up @@ -54,6 +54,7 @@ extern "C" __declspec(dllexport) DWORD draw_request()
if (!std::strcmp(mode, "fail-second")) return 8;
if (!std::strcmp(mode, "shadow")) return 14;
if (!std::strcmp(mode, "shadow-stale")) return 15;
if (!std::strcmp(mode, "shadow-reject")) return 16;
if (!std::strcmp(mode, "texture")) return 10;
if (!std::strcmp(mode, "texture-stale")) return 12;
}
Expand All @@ -69,9 +70,9 @@ extern "C" __declspec(dllexport) DWORD draw_frame(DWORD mode)
if (!publish(published.data(), static_cast<DWORD>(published.size()))) ExitProcess(23);
return count;
}
if (mode == 14 || mode == 15) {
if (mode >= 14 && mode <= 16) {
std::vector<unsigned char> output;
if (!shim_shadow_gpu(mode == 15, output)) return 0xFFFFFFFF;
if (!shim_shadow_gpu(mode == 15, mode == 16, output)) return 0xFFFFFFFF;
if (!publish(output.data(), static_cast<DWORD>(output.size()))) ExitProcess(23);
return 0;
}
Expand Down
14 changes: 10 additions & 4 deletions tests/cpu/shim_shadow_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,25 @@ def run(directory, dxc, mapper, exe, lifted, companion, io, xmem, d3d12):
mapped = [sys.executable, "-B", Path(__file__).with_name("shim_startup_check.py"), "--map",
mapper, exe, companion, io, xmem, d3d12, ""]
markers = sorted(f"bound {dll}!{symbol}" for dll, symbols in SHIM_IMPORTS.items() for symbol in symbols)
for case, expected in (("shadow", current), ("shadow-stale", stale)):
for case, expected in (("shadow", current), ("shadow-stale", stale), ("shadow-reject", b"")):
env = dict(os.environ, X2W_SHIM_DRAW_CASE=case, X2W_SHIM_COMPUTE_CASE="", X2W_SHIM_CHAIN_DIR=str(directory))
for runner, command in (("native", [exe]), ("pe_map", mapped), ("AOT", [lifted])):
child = subprocess.run(command, env=env, capture_output=True, timeout=120)
lines = child.stderr.decode(errors="replace").splitlines()
if child.returncode == 77 and case == "shadow" and runner == "native":
print("skip:", child.stdout.decode(errors="replace"), lines)
return 77
check(f"{case} {runner} diagnostics", sorted(lines),
sorted([*markers, "mapped host returned"]) if runner == "pe_map" else [])
check(f"{case} {runner} exit", child.returncode, 42)
diagnostics = [*markers, "mapped host returned"] if runner == "pe_map" else []
if case == "shadow-reject":
diagnostics.append("Xbox device rejected: no device, released adapter and factory")
check(f"{case} {runner} diagnostics", sorted(lines), sorted(diagnostics))
check(f"{case} {runner} exit", child.returncode, 20 if case == "shadow-reject" else 42)
check(f"{case} {runner} startup", child.stdout[:len(EXPECTED.output)], EXPECTED.output)
payload = child.stdout[len(EXPECTED.output):]
if case == "shadow-reject":
check(f"{case} {runner} publishes no frame data", payload, b"")
print(f"{case} {runner}: adapter and factory released, no frame payload, exit=20")
continue
check(f"{case} {runner} frame payload length", len(payload), len(expected) + 1)
check(f"{case} {runner} tracked surface releases", payload[-1], 4)
check(f"{case} {runner} readback mismatch count", shadow.differences(payload[:-1], expected), 0)
Expand Down
Loading