mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 20:10:44 +00:00
Merge pull request #265 from Swastickc/task/263-native-app-gate2
app: show the trusted fixture's guest-driven Metal frame (Gate 2, #263)
This commit is contained in:
8 files changed
+341
-7
No files matched your search
@@ -11,6 +11,8 @@ remains unsupported.
|
||||
|
||||
### Added
|
||||
|
||||
- Showed the first guest-driven frame in the native app (Gate 2, #263). The C interface gains `xenora_session_run_trusted_fixture`, which runs only the embedded trusted PE fixture: its x86-64 code is translated and executed, its `xenora.dll!fixture_draw` call compiles the x9 RDNA2 shader fixtures to MSL and renders on the native Metal device, and the 4×3 RGBA8 read-back is returned only if the guest halts with the CLI runner's expected results and every pixel equals the pixel shader's export, (1, 0, 0, 1) as opaque red. Xenora.app's "Run trusted fixture" button shows that frame, and `--smoke-frame` prints it. A `gpu-tests` test, run by `scripts/test-gpu.sh`, executes the fixture three times through the interface with Metal validation enabled. The frame is a read-back image, not drawable presentation, and no caller-supplied executable can run. Verified on one Apple Silicon Mac; the window was checked by screenshot.
|
||||
- Added a minimal native macOS application shell and its Rust interface (Gate 1 of the native application work). `crates/ffi` builds a static library with a versioned C interface (`crates/ffi/include/xenora.h`, version 1): opaque, generation-checked 64-bit session handles (never pointers), at most 64 live sessions, stable status codes, and panics caught at the boundary. Version 1 can only create and destroy sessions and parse the bundled trusted PE fixture; it executes no guest code. `app/` is a SwiftUI app built with Swift Package Manager that shows the interface version and the fixture's section count and entry point. `scripts/build-app.sh` builds an ad-hoc-signed, arm64-only `build/Xenora.app` with no entitlements and runs its `--smoke` check. Six Rust tests cover invalid, stale and double-destroyed handles, version mismatch, null outputs, 4,000 concurrent create and destroy cycles, and header/constant agreement. The CLI and headless workflows are unchanged. Verified locally on one Apple Silicon Mac (macOS 27.2.1, Swift 6.4, Rust 1.100.0); not yet run in CI.
|
||||
- Added the gfx1030 SOPC compares `s_cmp_{eq,lg,gt,ge,lt,le}_{i32,u32}` through the semantic registry, which replaces the hand-written `s_cmp_eq_u32` path. Each sets only SCC to whether the relation holds with SSRC0 on the left (AMD guide section 12.4); the registry gained a `compare` operation with a declared `relation` and a `sopc_scalar` operand rule. `Instruction::ScalarCompareEqU32` is now `Instruction::ScalarCompare { op: ScalarCompareOp, .. }`; `s_cmp_eq_u32` behaves as before. The reference and independent semantic-review interpreters, written separately from the guide, evaluate all twelve, checked against 7,824 guide-derived cases on both CPU interpreters and on native Metal with validation; 348 rejected programs are refused by both interpreters and by the compiler. A new LLVM-assembled fixture covers all twelve. Two literal selectors stay rejected. Part of #215, stage D.
|
||||
- Added eight gfx1030 SOP2 forms through the semantic registry alone: `s_andn2_b32`, `s_orn2_b32`, `s_nand_b32`, `s_nor_b32`, `s_xnor_b32`, `s_lshl_b32`, `s_lshr_b32` and `s_ashr_i32`, each with SCC = result != 0. Each is one registry entry with no per-form Rust; the registry gained these primitives and a declared shift-count width (`shift_count_bits = 5`, so shifts use S1[4:0] as in the AMD guide, section 12.1), which the generator applies as a mask and checks against the XML's unsigned count operand. The reference interpreter and the independent semantic-review interpreter, written separately from the guide, now evaluate the same eight forms and are checked against 6,896 guide-derived cases; a new LLVM-assembled fixture (`fixtures/rdna2/scalar-logic.s`) runs on CPU and native Metal with validation. A NULL destination (s125) stays rejected. Part of #215, stage C.
|
||||
- Added an independent operand-domain verification harness for the 9 supported SOP2 scalar ALU forms and 12 VOPC integer compares (`tests/validation/tests/operand_domains.rs`, part of #215 stage E): 4,788 generated cases (boundary values, 64-bit carry and borrow chains, aliased registers, every integer inline constant, literals, s105 and v255, partial and zero EXEC, VCCZ) and 498 rejections (missing literal words, and encodings outside Xenora's supported subset) run on `xenora_ref` and, as an ignored test picked up by `scripts/test-gpu.sh`, on native Metal. Expected values come from the public AMD RDNA 2 guide's pseudocode, written out in the test without Xenora code; this is agreement with a spec-derived reference, not with Xbox hardware. Local verification only: 32 deliberate code breaks were each caught; the guide leaves the width of `S1 + SCC` in `s_subb_u32` open, and those 8 cases are kept in their own family.
|
||||
|
||||
Generated
+2
@@ -184,6 +184,8 @@ name = "xenora-ffi"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"xenora-loader",
|
||||
"xenora-metal",
|
||||
"xenora-shader",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// Gate 1 shell: proves the app links the Rust runtime through the versioned C
|
||||
// interface. It inspects the bundled trusted fixture and executes no guest code.
|
||||
// Native shell over the versioned C interface. "Run trusted fixture" executes the
|
||||
// bundled trusted PE fixture (x86-64 translated to ARM64; its draw request is rendered
|
||||
// by native Metal) and shows the verified read-back frame. No other executable can run.
|
||||
|
||||
import CXenora
|
||||
import Foundation
|
||||
@@ -30,29 +31,112 @@ struct RuntimeProbe {
|
||||
}
|
||||
}
|
||||
|
||||
/// The frame produced by one run of the trusted fixture.
|
||||
struct GuestFrame {
|
||||
let status: Int32
|
||||
let width: Int
|
||||
let height: Int
|
||||
let rgba: [UInt8]
|
||||
|
||||
static func run() -> GuestFrame {
|
||||
var session: xenora_session = 0
|
||||
var status = xenora_session_create(XENORA_ABI_VERSION, &session)
|
||||
guard status == XENORA_OK else { return GuestFrame(status: status, width: 0, height: 0, rgba: []) }
|
||||
defer { _ = xenora_session_destroy(session) }
|
||||
var rgba = [UInt8](repeating: 0, count: Int(XENORA_FIXTURE_FRAME_WIDTH * XENORA_FIXTURE_FRAME_HEIGHT * 4))
|
||||
var width: UInt32 = 0
|
||||
var height: UInt32 = 0
|
||||
status = rgba.withUnsafeMutableBufferPointer { buffer in
|
||||
xenora_session_run_trusted_fixture(session, buffer.baseAddress, UInt64(buffer.count), &width, &height)
|
||||
}
|
||||
return GuestFrame(status: status, width: Int(width), height: Int(height), rgba: status == XENORA_OK ? rgba : [])
|
||||
}
|
||||
|
||||
var image: CGImage? {
|
||||
guard status == XENORA_OK, let provider = CGDataProvider(data: Data(rgba) as CFData) else { return nil }
|
||||
return CGImage(
|
||||
width: width, height: height, bitsPerComponent: 8, bitsPerPixel: 32, bytesPerRow: width * 4,
|
||||
space: CGColorSpaceCreateDeviceRGB(),
|
||||
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue),
|
||||
provider: provider, decode: nil, shouldInterpolate: false, intent: .defaultIntent)
|
||||
}
|
||||
|
||||
var summary: String {
|
||||
let first = rgba.prefix(4).map(String.init).joined(separator: ",")
|
||||
return "status=\(status) frame=\(width)x\(height) first_pixel=\(first)"
|
||||
}
|
||||
}
|
||||
|
||||
/// Owns the latest fixture run. A class with @Published avoids SwiftUI macros,
|
||||
/// which the command-line toolchain does not ship.
|
||||
@MainActor
|
||||
final class FrameModel: ObservableObject {
|
||||
@Published var frame: GuestFrame?
|
||||
@Published var running = false
|
||||
|
||||
func run() {
|
||||
running = true
|
||||
Task {
|
||||
// The fixture blocks while it executes and renders, so keep it off the main thread.
|
||||
frame = await Task.detached { GuestFrame.run() }.value
|
||||
running = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView: View {
|
||||
let probe = RuntimeProbe.run()
|
||||
@ObservedObject var model: FrameModel
|
||||
private var frame: GuestFrame? { model.frame }
|
||||
private var running: Bool { model.running }
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("Guest display") {
|
||||
if let image = frame?.image {
|
||||
Image(decorative: image, scale: 1)
|
||||
.resizable()
|
||||
.interpolation(.none)
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(maxWidth: .infinity, minHeight: 120, maxHeight: 240)
|
||||
.accessibilityLabel("Guest frame, \(frame!.width) by \(frame!.height) pixels")
|
||||
Text("Guest code ran, its draw was rendered by native Metal, and all \(frame!.width * frame!.height) pixels matched the fixture shader's output.")
|
||||
.font(.callout)
|
||||
.foregroundStyle(.secondary)
|
||||
} else if let frame {
|
||||
Text("Run failed (status \(frame.status)). No frame is shown.")
|
||||
.foregroundStyle(.red)
|
||||
}
|
||||
Button(running ? "Running…" : "Run trusted fixture") { model.run() }
|
||||
.disabled(running || !probe.connected)
|
||||
}
|
||||
LabeledContent("Runtime", value: probe.connected ? "Connected" : "Unavailable (status \(probe.status))")
|
||||
LabeledContent("Interface version", value: "\(probe.abiVersion)")
|
||||
LabeledContent("Trusted fixture sections", value: "\(probe.sections)")
|
||||
LabeledContent("Trusted fixture entry RVA", value: String(format: "0x%X", probe.entryRVA))
|
||||
Text("Guest execution and live display are not available in this build.")
|
||||
Text("Only the bundled trusted fixture can run. Live presentation, persistent sessions and input are not available yet.")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.frame(minWidth: 420, minHeight: 240)
|
||||
.frame(minWidth: 460, minHeight: 420)
|
||||
}
|
||||
}
|
||||
|
||||
struct XenoraApp: App {
|
||||
let model = FrameModel()
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup("Xenora") { ContentView() }
|
||||
WindowGroup("Xenora") { ContentView(model: model) }
|
||||
}
|
||||
}
|
||||
|
||||
// `--smoke-frame` runs the trusted fixture on the Metal device and exits; it needs a GPU.
|
||||
if CommandLine.arguments.contains("--smoke-frame") {
|
||||
let frame = GuestFrame.run()
|
||||
print(frame.summary)
|
||||
exit(frame.status == XENORA_OK ? 0 : 1)
|
||||
}
|
||||
|
||||
// `--smoke` prints the probe and exits without opening a window, for scripts and CI.
|
||||
if CommandLine.arguments.contains("--smoke") {
|
||||
let probe = RuntimeProbe.run()
|
||||
|
||||
@@ -12,5 +12,11 @@ crate-type = ["staticlib", "rlib"]
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[features]
|
||||
# Runs the tests that need a native Metal device (scripts/test-gpu.sh).
|
||||
gpu-tests = []
|
||||
|
||||
[dependencies]
|
||||
xenora-loader = { path = "../loader" }
|
||||
xenora-metal = { path = "../metal" }
|
||||
xenora-shader = { path = "../shader" }
|
||||
@@ -25,8 +25,14 @@ enum {
|
||||
XENORA_INTERNAL_ERROR = 4,
|
||||
XENORA_PE_ERROR = 5,
|
||||
XENORA_LIMIT_EXCEEDED = 6,
|
||||
XENORA_BUFFER_TOO_SMALL = 7,
|
||||
XENORA_EXECUTION_FAILED = 8,
|
||||
};
|
||||
|
||||
/* Size of the frame drawn by the trusted fixture: RGBA8, rows top to bottom. */
|
||||
#define XENORA_FIXTURE_FRAME_WIDTH 4u
|
||||
#define XENORA_FIXTURE_FRAME_HEIGHT 3u
|
||||
|
||||
typedef uint64_t xenora_session;
|
||||
|
||||
/* The interface version this library implements. */
|
||||
@@ -44,4 +50,19 @@ xenora_status xenora_session_inspect_trusted_fixture(
|
||||
uint32_t *out_section_count,
|
||||
uint32_t *out_entry_rva);
|
||||
|
||||
/*
|
||||
* Run the bundled trusted PE fixture: its x86-64 code is translated and executed,
|
||||
* and its single draw request is rendered on the native Metal device. On XENORA_OK,
|
||||
* `out_rgba` holds width * height * 4 bytes of the read-back frame, which has been
|
||||
* checked against the fixture shader's known output. `capacity` is the size of
|
||||
* `out_rgba` in bytes. Blocks the calling thread; call it off the main thread.
|
||||
* Only the embedded fixture can run; no caller-supplied executable is accepted.
|
||||
*/
|
||||
xenora_status xenora_session_run_trusted_fixture(
|
||||
xenora_session session,
|
||||
uint8_t *out_rgba,
|
||||
uint64_t capacity,
|
||||
uint32_t *out_width,
|
||||
uint32_t *out_height);
|
||||
|
||||
#endif
|
||||
+176
-2
@@ -7,8 +7,11 @@
|
||||
//! Every exported function catches panics and reports them as `XENORA_INTERNAL_ERROR`.
|
||||
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
use std::sync::Mutex;
|
||||
use xenora_loader::ParsedPe;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use xenora_loader::startup::{StartupLayout, run_synthetic_startup};
|
||||
use xenora_loader::{ExitReason, ImportRegistry, ParsedPe, Register};
|
||||
use xenora_metal::NativeCompute;
|
||||
use xenora_shader::{Architecture, PIXEL_ENTRY_POINT, VERTEX_ENTRY_POINT, compile_graphics};
|
||||
|
||||
pub const XENORA_ABI_VERSION: u32 = 1;
|
||||
|
||||
@@ -19,6 +22,12 @@ pub const XENORA_VERSION_MISMATCH: i32 = 3;
|
||||
pub const XENORA_INTERNAL_ERROR: i32 = 4;
|
||||
pub const XENORA_PE_ERROR: i32 = 5;
|
||||
pub const XENORA_LIMIT_EXCEEDED: i32 = 6;
|
||||
pub const XENORA_BUFFER_TOO_SMALL: i32 = 7;
|
||||
pub const XENORA_EXECUTION_FAILED: i32 = 8;
|
||||
|
||||
pub const XENORA_FIXTURE_FRAME_WIDTH: u32 = 4;
|
||||
pub const XENORA_FIXTURE_FRAME_HEIGHT: u32 = 3;
|
||||
const FRAME_BYTES: usize = (XENORA_FIXTURE_FRAME_WIDTH * XENORA_FIXTURE_FRAME_HEIGHT * 4) as usize;
|
||||
|
||||
/// Upper bound on simultaneously live sessions.
|
||||
const MAX_SESSIONS: usize = 64;
|
||||
@@ -129,6 +138,134 @@ pub unsafe extern "C" fn xenora_session_inspect_trusted_fixture(
|
||||
})
|
||||
}
|
||||
|
||||
// The trusted fixture's contract, as checked by the CLI runner (crates/cli/src/runner.rs).
|
||||
// ponytail: duplicated from the runner so the CLI stays untouched; extract a shared
|
||||
// fixture-run function into a library when a third caller appears.
|
||||
const IMAGE_BASE: u64 = 0x1_5000_0000;
|
||||
const TICKET_ADDRESS: u64 = IMAGE_BASE + 0x3000;
|
||||
const TICKET: u64 = 17;
|
||||
const DRAW_RESULT: u64 = 0x42;
|
||||
const ENTRY_STEPS: usize = 100;
|
||||
/// `x9-constant-ps.s` exports (1.0, 0, 0, 1.0) to mrt0; in an RGBA8 target that is opaque red.
|
||||
const EXPECTED_PIXEL: [u8; 4] = [255, 0, 0, 255];
|
||||
|
||||
fn draw() -> Result<Vec<u8>, String> {
|
||||
let shader = compile_graphics(
|
||||
Architecture::Gfx1030,
|
||||
include_bytes!("../../../fixtures/rdna2/x9-constant-vs.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/x9-constant-ps.bin"),
|
||||
)
|
||||
.map_err(|e| format!("shader translation: {e}"))?;
|
||||
let gpu = NativeCompute::new().map_err(|e| format!("Metal device: {e}"))?;
|
||||
let pixels = gpu
|
||||
.render_rgba8(
|
||||
&shader.msl,
|
||||
[VERTEX_ENTRY_POINT, PIXEL_ENTRY_POINT],
|
||||
&[
|
||||
[-1.0, -1.0, 0.5, 1.0],
|
||||
[3.0, -1.0, 0.5, 1.0],
|
||||
[-1.0, 3.0, 0.5, 1.0],
|
||||
],
|
||||
&[[0.0; 4]; 3],
|
||||
[
|
||||
XENORA_FIXTURE_FRAME_WIDTH as usize,
|
||||
XENORA_FIXTURE_FRAME_HEIGHT as usize,
|
||||
],
|
||||
[19, 43, 93, 251],
|
||||
)
|
||||
.map_err(|e| format!("Metal render: {e}"))?;
|
||||
if pixels != EXPECTED_PIXEL.repeat(FRAME_BYTES / 4) {
|
||||
return Err("read-back frame differs from the fixture shader's output".into());
|
||||
}
|
||||
Ok(pixels)
|
||||
}
|
||||
|
||||
/// Run the embedded fixture and return its verified frame.
|
||||
fn run_fixture() -> Result<Vec<u8>, String> {
|
||||
let frame = Arc::new(Mutex::new(None));
|
||||
let draw_frame = Arc::clone(&frame);
|
||||
let mut imports = ImportRegistry::new();
|
||||
imports.register("xenora.dll", "fixture_draw", move |args, _, memory| {
|
||||
let fault = ExitReason::IllegalInstruction(0xff);
|
||||
let ticket = args.get(0, memory).map_err(ExitReason::MemoryFault)?;
|
||||
let mut slot = draw_frame.lock().map_err(|_| fault)?;
|
||||
if slot.is_some()
|
||||
|| ticket != TICKET_ADDRESS
|
||||
|| memory.read_u64(ticket).map_err(ExitReason::MemoryFault)? != TICKET
|
||||
{
|
||||
return Err(fault);
|
||||
}
|
||||
let result = draw();
|
||||
let ok = result.is_ok();
|
||||
*slot = Some(result);
|
||||
if ok { Ok(DRAW_RESULT) } else { Err(fault) }
|
||||
});
|
||||
let startup = run_synthetic_startup(
|
||||
FIXTURE,
|
||||
StartupLayout {
|
||||
image_base: IMAGE_BASE,
|
||||
stack_top: 0x2_0001_0000,
|
||||
tls_base: 0x3_0000_0000,
|
||||
},
|
||||
imports,
|
||||
ENTRY_STEPS,
|
||||
)
|
||||
.map_err(|e| format!("startup: {e}"))?;
|
||||
let drawn = frame.lock().map_err(|_| "frame lock poisoned")?.take();
|
||||
if let Some(Err(e)) = drawn {
|
||||
return Err(e);
|
||||
}
|
||||
let execution = &startup.execution;
|
||||
if execution.exit_reason != ExitReason::Halt
|
||||
|| startup.relocations.applied_dir64 != 4
|
||||
|| startup.bound_imports != 1
|
||||
|| startup.tls_callbacks != 1
|
||||
|| execution.final_state.get(Register::Rax) != DRAW_RESULT
|
||||
{
|
||||
return Err(format!(
|
||||
"unexpected guest result: {:?}",
|
||||
execution.exit_reason
|
||||
));
|
||||
}
|
||||
drawn.ok_or_else(|| String::from("guest halted without a draw"))?
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// `out_rgba` must be null or valid for `capacity` byte writes; each `u32` output
|
||||
/// must be null or valid for one aligned write.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn xenora_session_run_trusted_fixture(
|
||||
session: u64,
|
||||
out_rgba: *mut u8,
|
||||
capacity: u64,
|
||||
out_width: *mut u32,
|
||||
out_height: *mut u32,
|
||||
) -> i32 {
|
||||
guarded(|| {
|
||||
if out_rgba.is_null() || out_width.is_null() || out_height.is_null() {
|
||||
return XENORA_INVALID_ARGUMENT;
|
||||
}
|
||||
match SESSIONS.lock() {
|
||||
Ok(slots) if is_live(&slots, session) => {}
|
||||
Ok(_) => return XENORA_INVALID_HANDLE,
|
||||
Err(_) => return XENORA_INTERNAL_ERROR,
|
||||
}
|
||||
if capacity < FRAME_BYTES as u64 {
|
||||
return XENORA_BUFFER_TOO_SMALL;
|
||||
}
|
||||
let Ok(pixels) = run_fixture() else {
|
||||
return XENORA_EXECUTION_FAILED;
|
||||
};
|
||||
// SAFETY: non-null and at least FRAME_BYTES long, both checked above.
|
||||
unsafe {
|
||||
std::ptr::copy_nonoverlapping(pixels.as_ptr(), out_rgba, FRAME_BYTES);
|
||||
out_width.write(XENORA_FIXTURE_FRAME_WIDTH);
|
||||
out_height.write(XENORA_FIXTURE_FRAME_HEIGHT);
|
||||
}
|
||||
XENORA_OK
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -172,9 +309,17 @@ mod tests {
|
||||
("XENORA_INTERNAL_ERROR", XENORA_INTERNAL_ERROR),
|
||||
("XENORA_PE_ERROR", XENORA_PE_ERROR),
|
||||
("XENORA_LIMIT_EXCEEDED", XENORA_LIMIT_EXCEEDED),
|
||||
("XENORA_BUFFER_TOO_SMALL", XENORA_BUFFER_TOO_SMALL),
|
||||
("XENORA_EXECUTION_FAILED", XENORA_EXECUTION_FAILED),
|
||||
] {
|
||||
assert!(header.contains(&format!("{name} = {value},")), "{name}");
|
||||
}
|
||||
assert!(header.contains(&format!(
|
||||
"XENORA_FIXTURE_FRAME_WIDTH {XENORA_FIXTURE_FRAME_WIDTH}u"
|
||||
)));
|
||||
assert!(header.contains(&format!(
|
||||
"XENORA_FIXTURE_FRAME_HEIGHT {XENORA_FIXTURE_FRAME_HEIGHT}u"
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -261,4 +406,33 @@ mod tests {
|
||||
fn panics_do_not_cross_the_boundary() {
|
||||
assert_eq!(guarded(|| panic!("injected")), XENORA_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fixture_run_rejects_bad_arguments_before_executing() {
|
||||
let _serial = serial();
|
||||
let handle = create();
|
||||
let (mut buf, mut w, mut h) = ([0u8; 48], 0u32, 0u32);
|
||||
let run = |session, buf: *mut u8, cap, w: *mut u32, h: *mut u32| unsafe {
|
||||
xenora_session_run_trusted_fixture(session, buf, cap, w, h)
|
||||
};
|
||||
assert_eq!(
|
||||
run(handle, buf.as_mut_ptr(), 47, &mut w, &mut h),
|
||||
XENORA_BUFFER_TOO_SMALL
|
||||
);
|
||||
assert_eq!(
|
||||
run(handle, null_mut(), 48, &mut w, &mut h),
|
||||
XENORA_INVALID_ARGUMENT
|
||||
);
|
||||
assert_eq!(
|
||||
run(handle, buf.as_mut_ptr(), 48, null_mut(), &mut h),
|
||||
XENORA_INVALID_ARGUMENT
|
||||
);
|
||||
xenora_session_destroy(handle);
|
||||
assert_eq!(
|
||||
run(handle, buf.as_mut_ptr(), 48, &mut w, &mut h),
|
||||
XENORA_INVALID_HANDLE
|
||||
);
|
||||
assert_eq!((w, h), (0, 0), "outputs untouched on failure");
|
||||
assert!(buf.iter().all(|&b| b == 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! Runs the trusted fixture through the C interface on a native Metal device.
|
||||
//! Needs `--features gpu-tests` (scripts/test-gpu.sh).
|
||||
#![cfg(feature = "gpu-tests")]
|
||||
|
||||
use xenora_ffi::*;
|
||||
|
||||
/// fixtures/rdna2/x9-constant-ps.s: `v_mov_b32 v8, 1.0; v_mov_b32 v9, 0;
|
||||
/// exp mrt0, v8, v9, v9, v8` writes (1, 0, 0, 1); as RGBA8 unorm that is (255, 0, 0, 255).
|
||||
const SHADER_OUTPUT: [u8; 4] = [255, 0, 0, 255];
|
||||
|
||||
#[test]
|
||||
fn guest_fixture_frame_reaches_the_caller_through_metal() {
|
||||
for run in 0..3 {
|
||||
let mut session = 0;
|
||||
assert_eq!(
|
||||
unsafe { xenora_session_create(XENORA_ABI_VERSION, &mut session) },
|
||||
XENORA_OK
|
||||
);
|
||||
let (mut rgba, mut width, mut height) = ([0u8; 64], 0u32, 0u32);
|
||||
let status = unsafe {
|
||||
xenora_session_run_trusted_fixture(
|
||||
session,
|
||||
rgba.as_mut_ptr(),
|
||||
64,
|
||||
&mut width,
|
||||
&mut height,
|
||||
)
|
||||
};
|
||||
assert_eq!(status, XENORA_OK, "run {run}");
|
||||
assert_eq!((width, height), (4, 3));
|
||||
assert_eq!(&rgba[..48], SHADER_OUTPUT.repeat(12).as_slice());
|
||||
assert!(
|
||||
rgba[48..].iter().all(|&b| b == 0),
|
||||
"no write past the frame"
|
||||
);
|
||||
assert_eq!(xenora_session_destroy(session), XENORA_OK);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,11 @@ cargo test --locked -p xenora-loader --features gpu-tests --test graphics_d3d12
|
||||
timeout 30s cargo test --locked -p xenora-loader --features gpu-tests --test graphics_d3d12 -- \
|
||||
--nocapture --test-threads=1
|
||||
|
||||
# The native app interface runs the trusted fixture's guest draw on Metal.
|
||||
cargo test --locked -p xenora-ffi --features gpu-tests --test native_frame --no-run
|
||||
timeout 30s cargo test --locked -p xenora-ffi --features gpu-tests --test native_frame -- \
|
||||
--nocapture --test-threads=1
|
||||
|
||||
# Native Metal known answers of the independent semantic review, including SOP2 scalar ALU
|
||||
# and VOPC compares.
|
||||
cargo test --locked -p xenora-semantic-review --no-run
|
||||
|
||||
Reference in new issue
Block a user