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
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ add_custom_command(OUTPUT "${pixel_vs}" COMMAND "${DXC_EXECUTABLE}" -T vs_6_0 -E
-Fh "${pixel_vs}" -Vn pixel_aot_vs "${CMAKE_CURRENT_SOURCE_DIR}/tests/pixel_aot_vs.hlsl"
DEPENDS tests/pixel_aot_vs.hlsl VERBATIM)
target_sources(offscreen_check PRIVATE tests/pixel_aot_render.cpp tests/pixel_compare_render.cpp "${pixel_vs}")
target_sources(offscreen_check PRIVATE tests/mesh_entry_draw.cpp tests/mesh_shadow_draw.cpp)
target_sources(offscreen_check PRIVATE tests/desktop_gpu.cpp tests/mesh_entry_draw.cpp tests/mesh_shadow_draw.cpp)
target_sources(offscreen_check PRIVATE tests/binding_mips.cpp tests/ffx_recurrent_views.cpp)
target_sources(offscreen_check PRIVATE tests/ffx_rcas_views.cpp)
foreach(storage IN ITEMS Native Packed)
Expand Down Expand Up @@ -2217,7 +2217,7 @@ if(EXISTS "${INTAKE_PYTHON}")
target_compile_features(cpu_shim_compute PRIVATE cxx_std_17)
target_link_libraries(cpu_shim_compute PRIVATE xmem_shim dxgi d3d12)
add_library(cpu_shim_draw SHARED tests/cpu/shim_draw_provider.cpp tests/cpu/shim_draw_gpu.cpp
tests/cpu/shim_chain_gpu.cpp)
tests/cpu/shim_chain_gpu.cpp tests/desktop_gpu.cpp tests/mesh_shadow_draw.cpp)
set(shim_draw_color_header "${CMAKE_CURRENT_BINARY_DIR}/shim_draw_color.h")
add_custom_command(OUTPUT "${shim_draw_color_header}"
COMMAND "${DXC_EXECUTABLE}" -T ps_6_0 -E main -Fh "${shim_draw_color_header}" -Vn shim_draw_color
Expand Down Expand Up @@ -2304,6 +2304,13 @@ if(EXISTS "${INTAKE_PYTHON}")
"$<TARGET_FILE:d3d12_xs_shim>" "$<TARGET_FILE:cpu_shim_draw>")
set_tests_properties(cpu_shim_chain_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_SHIM_DRAW_ADAPTER=${adapter};X2W_SHIM_COMPUTE_CASE=")
add_test(NAME cpu_shim_shadow_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/cpu/shim_shadow_check.py" "${DXC_EXECUTABLE}"
"$<TARGET_FILE:pe_map>" "$<TARGET_FILE:cpu_shim_startup>" "$<TARGET_FILE:cpu_shim_startup_lifted>"
"$<TARGET_FILE:cpu_shim_startup_guest>" "$<TARGET_FILE:cpu_exe_io>" "$<TARGET_FILE:xmem_shim>"
"$<TARGET_FILE:d3d12_xs_shim>" "$<TARGET_FILE:cpu_shim_draw>")
set_tests_properties(cpu_shim_shadow_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_SHIM_DRAW_ADAPTER=${adapter};X2W_SHIM_COMPUTE_CASE=")
endforeach()

add_test(NAME cpu_native_exe_chain COMMAND "${INTAKE_PYTHON}" -B
Expand Down
13 changes: 13 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -3793,3 +3793,16 @@ ctest --preset dev --no-tests=error -R '^pixel_aot_vop3_ternary_int_(warp|hardwa
Python-only controls check explicit reference words and translator acceptance.
Those controls do not establish GPU execution; the command above must pass on
the named backend before recording readback evidence.

### Two shadow frames from the EXE entry

The native, mapped and AOT runners use the existing translated shadow scene. The
second frame shifts the caster four pixels while retaining the device, pipeline
states, descriptor heap, camera depth and color target. Two light depth maps
remain live so the second camera pass can deliberately select the first one.
The fixture compares all 4,096 color pixels and 4,096 light-depth texels of each
frame against the CPU reference, checks four owned surface releases after the
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`.
43 changes: 0 additions & 43 deletions tests/compute_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ constexpr UINT sentinel = 0xc5c5c5c5u;
constexpr std::array<UINT, 16> constants{count, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 23, 29};
}

ComPtr<ID3D12Resource> make_buffer(ID3D12Device* device, UINT64 length, D3D12_HEAP_TYPE heap,
D3D12_RESOURCE_STATES state, D3D12_RESOURCE_FLAGS flags)
{
D3D12_RESOURCE_DESC desc{};
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
desc.Width = length;
desc.Height = desc.DepthOrArraySize = desc.MipLevels = desc.SampleDesc.Count = 1;
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
desc.Flags = flags;
return resource(device, desc, heap, state);
}

static UINT input_word(UINT i) { return 0x8b02a7f1u + i * 0x413b1u; }

static void fill_upload(ID3D12Resource* upload)
Expand All @@ -54,15 +42,6 @@ static void fill_upload(ID3D12Resource* upload)
upload->Unmap(0, nullptr);
}

void transition(ID3D12GraphicsCommandList* list, ID3D12Resource* buffer,
D3D12_RESOURCE_STATES before, D3D12_RESOURCE_STATES after)
{
D3D12_RESOURCE_BARRIER barrier{};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Transition = {buffer, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, before, after};
list->ResourceBarrier(1, &barrier);
}

static ComPtr<ID3D12DescriptorHeap> bind_tables(ID3D12Device* device, ID3D12GraphicsCommandList* list,
ID3D12Resource* input, ID3D12Resource* output)
{
Expand Down Expand Up @@ -248,25 +227,3 @@ void check_bvh_root_roundtrip(ID3D12Device* device)
run_compute(device, false, shader, {roundtrip->GetBufferPointer(), roundtrip->GetBufferSize()});
std::puts("normalized_signature=matched_control root_creation=passed pipeline_creation=passed dispatch=passed");
}

ComputeCommands::ComputeCommands(ID3D12Device* device, ID3D12PipelineState* pipeline, D3D12_COMMAND_LIST_TYPE type)
{
D3D12_COMMAND_QUEUE_DESC desc{};
desc.Type = type;
check(device->CreateCommandQueue(&desc, IID_PPV_ARGS(&queue)), "Create compute queue");
check(device->CreateCommandAllocator(desc.Type, IID_PPV_ARGS(&allocator)), "Create compute allocator");
check(device->CreateCommandList(0, desc.Type, allocator.Get(), pipeline, IID_PPV_ARGS(&list)),
"Create compute command list");
}

void ComputeCommands::submit_and_wait(ID3D12Device* device)
{
check(list->Close(), "Close compute command list");
ComPtr<ID3D12Fence> fence;
check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)), "Create compute fence");
ID3D12CommandList* submitted[]{list.Get()};
queue->ExecuteCommandLists(1, submitted);
check(queue->Signal(fence.Get(), 1), "Signal compute fence");
check(fence->SetEventOnCompletion(1, nullptr), "Wait for compute");
check(device->GetDeviceRemovedReason(), "Compute completion");
}
33 changes: 24 additions & 9 deletions tests/cpu/shim_chain_gpu.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "../desktop_gpu.h"
#include <cstdlib>
#include <filesystem>
// Run the translated compute -> mesh -> pixel chain for one EXE-requested frame.
//
// This repeats the sequence of `offscreen_check --compute-mesh-texture`
Expand Down Expand Up @@ -131,15 +134,6 @@ ComPtr<ID3D12Resource> buffer(ID3D12Device* device, UINT64 bytes, D3D12_HEAP_TYP
return committed(device, desc, heap, state);
}

void transition(ID3D12GraphicsCommandList* list, ID3D12Resource* resource,
D3D12_RESOURCE_STATES before, D3D12_RESOURCE_STATES after)
{
D3D12_RESOURCE_BARRIER barrier{};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Transition = {resource, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, before, after};
list->ResourceBarrier(1, &barrier);
}

template<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Kind, typename T>
struct alignas(void*) Field {
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE kind = Kind;
Expand Down Expand Up @@ -385,3 +379,24 @@ bool shim_chain_gpu(unsigned mode, std::vector<unsigned char>& published, unsign
return false;
}
}

bool shim_shadow_gpu(bool stale, 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();
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(),
(directory / "frames.case").string().c_str(), stale, &output))
ExitProcess(77);
return true;
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return false;
} catch (const Failure&) {
return false;
}
}
10 changes: 10 additions & 0 deletions tests/cpu/shim_draw_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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);

namespace {
constexpr unsigned side = 64;

Expand Down Expand Up @@ -50,6 +52,8 @@ extern "C" __declspec(dllexport) DWORD draw_request()
if (!std::strcmp(mode, "two")) return 6;
if (!std::strcmp(mode, "stale")) return 7;
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, "texture")) return 10;
if (!std::strcmp(mode, "texture-stale")) return 12;
}
Expand All @@ -65,6 +69,12 @@ 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) {
std::vector<unsigned char> output;
if (!shim_shadow_gpu(mode == 15, output)) return 0xFFFFFFFF;
if (!publish(output.data(), static_cast<DWORD>(output.size()))) ExitProcess(23);
return 0;
}
if (mode < 1 || mode > 13) ExitProcess(22);
if (mode >= 6) std::fprintf(stderr, "draw_frame mode=%lu\n", static_cast<unsigned long>(mode));
std::vector<unsigned char> rgba;
Expand Down
72 changes: 72 additions & 0 deletions tests/cpu/shim_shadow_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Compare two submitted shadow frames from one native, mapped and translated EXE."""
import os
from pathlib import Path
import struct
import subprocess
import sys
from tempfile import TemporaryDirectory

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import mesh_shadow_check as shadow
from shim_startup_check import EXPECTED, SHIM_IMPORTS, check


def build(directory, dxc):
shadow.compile_stage(dxc, directory, "mesh",
shadow.lower(shadow.enumerate_pcs(shadow.mesh_program()), shadow.WORDS, (3, 1), shadow.HEADER),
"ms_6_5", ["-DTRACE_EXPORTS"])
shadow.compile_stage(dxc, directory, "caster", shadow.translate_caster(shadow.caster_program()))
words = shadow.sampler_words("LESS", "point")
shadow.compile_stage(dxc, directory, "receiver", shadow.translate_receiver(shadow.receiver_program(words), words))
moved = tuple((x + 4, y) for x, y in shadow.CASTER)
lights = [shadow.light_casters(shadow.LIGHT_SHEAR, True, corners) for corners in (shadow.CASTER, moved)]
maps = [shadow.shadow_map(casters) for casters in lights]
draws = [shadow.draw_inputs([(*point, depth) for point in triangle])
for casters in lights for triangle, depth in casters]
draws += shadow.camera_draws() + shadow.camera_draws(moved)
state = shadow.comparison_sampler_state(words)
header = struct.pack("<8I", shadow.SIDE, len(lights[0]), len(lights[1]),
state["d3d12_filter"], state["d3d12_comparison_func"], 0, 0, 0)
(directory / "frames.case").write_bytes(header + b"".join(data for data, _ in draws)
+ b"".join(trace for _, trace in draws))
first = shadow.scene_image(maps[0])[0]
second = shadow.scene_image(maps[1], corners=moved)[0]
stale = shadow.scene_image(maps[0], corners=moved)[0]
depths = b"".join(struct.pack("<f", float(value)) for frame in maps for value in frame)
mismatch = shadow.differences(second, stale)
if not mismatch or maps[0] == maps[1]:
raise AssertionError("moving the caster must change depth and reveal the stale binding")
return first + second + depths, first + stale + depths, mismatch


def run(directory, dxc, mapper, exe, lifted, companion, io, xmem, d3d12):
current, stale, mismatch = build(directory, dxc)
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)):
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)
check(f"{case} {runner} startup", child.stdout[:len(EXPECTED.output)], EXPECTED.output)
payload = child.stdout[len(EXPECTED.output):]
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)
check(f"{case} {runner} differences from fresh depth binding",
shadow.differences(payload[:-1], current), mismatch if case == "shadow-stale" else 0)
print(f"{case} {runner}: two color/depth frames match; releases=4 exit=42")
print(f"stale map: {mismatch} second-frame color pixels differ; light depth still matches")
return 0


if __name__ == "__main__":
with TemporaryDirectory() as folder:
sys.exit(run(Path(folder), *map(Path, sys.argv[1:-1])))
3 changes: 3 additions & 0 deletions tests/cpu/shim_startup.asm
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ draw_phase:
call qword ptr [__imp_draw_request]
test eax, eax
jz success
cmp eax, 14
jae draw_single
cmp eax, 10
jae draw_texture
cmp eax, 6
jae draw_two
draw_single:
mov ecx, eax
call qword ptr [__imp_draw_frame]
test eax, eax
Expand Down
82 changes: 82 additions & 0 deletions tests/desktop_gpu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "desktop_gpu.h"
#include <cstdio>

using Microsoft::WRL::ComPtr;

#if defined(OFFSCREEN_AGILITY_620)
extern "C" const UINT D3D12SDKVersion;
#endif

void check(HRESULT hr, const char* stage)
{
if (FAILED(hr)) {
std::fprintf(stderr, "%s failed (HRESULT 0x%08lx)\n", stage, static_cast<unsigned long>(hr));
throw std::runtime_error(stage);
}
}

HRESULT check_feature(ID3D12Device* device, D3D12_FEATURE feature, void* data, UINT size)
{
#if defined(OFFSCREEN_AGILITY_620) && defined(__ID3D12Device16_INTERFACE_DEFINED__)
ComPtr<ID3D12Device16> versioned;
if (SUCCEEDED(device->QueryInterface(IID_PPV_ARGS(&versioned))))
return versioned->CheckFeatureSupport1(feature, data, size, D3D12SDKVersion);
#endif
return device->CheckFeatureSupport(feature, data, size);
}

ComPtr<ID3D12Resource> resource(ID3D12Device* device, const D3D12_RESOURCE_DESC& desc,
D3D12_HEAP_TYPE heap, D3D12_RESOURCE_STATES state,
const D3D12_CLEAR_VALUE* clear)
{
D3D12_HEAP_PROPERTIES props{};
props.Type = heap;
props.CreationNodeMask = props.VisibleNodeMask = 1;
ComPtr<ID3D12Resource> result;
check(device->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, state, clear,
IID_PPV_ARGS(&result)), "Create resource");
return result;
}

ComPtr<ID3D12Resource> make_buffer(ID3D12Device* device, UINT64 length, D3D12_HEAP_TYPE heap,
D3D12_RESOURCE_STATES state, D3D12_RESOURCE_FLAGS flags)
{
D3D12_RESOURCE_DESC desc{};
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
desc.Width = length;
desc.Height = desc.DepthOrArraySize = desc.MipLevels = desc.SampleDesc.Count = 1;
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
desc.Flags = flags;
return resource(device, desc, heap, state);
}

void transition(ID3D12GraphicsCommandList* list, ID3D12Resource* buffer,
D3D12_RESOURCE_STATES before, D3D12_RESOURCE_STATES after)
{
D3D12_RESOURCE_BARRIER barrier{};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Transition = {buffer, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, before, after};
list->ResourceBarrier(1, &barrier);
}

ComputeCommands::ComputeCommands(ID3D12Device* device, ID3D12PipelineState* pipeline, D3D12_COMMAND_LIST_TYPE type)
{
D3D12_COMMAND_QUEUE_DESC desc{};
desc.Type = type;
check(device->CreateCommandQueue(&desc, IID_PPV_ARGS(&queue)), "Create compute queue");
check(device->CreateCommandAllocator(desc.Type, IID_PPV_ARGS(&allocator)), "Create compute allocator");
check(device->CreateCommandList(0, desc.Type, allocator.Get(), pipeline, IID_PPV_ARGS(&list)),
"Create compute command list");
}

void ComputeCommands::submit_and_wait(ID3D12Device* device)
{
check(list->Close(), "Close compute command list");
ComPtr<ID3D12Fence> fence;
check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)), "Create compute fence");
ID3D12CommandList* submitted[]{list.Get()};
queue->ExecuteCommandLists(1, submitted);
check(queue->Signal(fence.Get(), 1), "Signal compute fence");
check(fence->SetEventOnCompletion(1, nullptr), "Wait for compute");
check(device->GetDeviceRemovedReason(), "Compute completion");
}
3 changes: 2 additions & 1 deletion tests/desktop_gpu.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <d3d12.h>
#include <stdexcept>
#include <vector>
#include <wrl/client.h>

void check(HRESULT hr, const char* stage);
Expand Down Expand Up @@ -48,7 +49,7 @@ void check_compute_to_pixel(ID3D12Device* device, const char* compute, const cha
void check_pixel_quad_lod(ID3D12Device* device, const char* shader);
void check_pixel_compare(ID3D12Device* device, const char* shader, const char* reference);
bool check_mesh_shadow_draw(ID3D12Device*, const char* mesh, const char* receiver, const char* caster,
const char* fixture, bool stale);
const char* fixture, bool stale, std::vector<unsigned char>* frames = nullptr);
void check_bc7_pixel(ID3D12Device* device, const char* shader, const char* input,
const char* capture, const char* mip1 = nullptr);
void check_bc7_tail(ID3D12Device* device, const char* shader, const char* firstMip, int count, char** paths);
Expand Down
Loading
Loading