feat(boot): xtask boot build makes one image with amdgpu beside NVK outside a release, and AMD's stack draws on RADV wherever the image's Mesa build holds it, where --amdgpu and --radv chose among three images

This commit is contained in:
Tyler Smith committed 2026-11-18 12:22:08 -05:00
1 parent 96ecd080ac
commit c5dcdc28ff
9 files changed
+75 -73

No files matched your search

+3 -4
View File
@@ -33,11 +33,10 @@ diagnostics = ["stela-drivers/irq-diagnostics"]
native-profile = ["stela-soc/native-profile", "stela-engine/native-profile"]
# NVK, NIR and NAK in the image, from `cargo xtask gpu nvk`.
nvk = ["dep:stela-mesa", "stela-drivers/metal-linked"]
# amdgpu in the image's Linux environment, for the AMD GPUs its table holds.
# amdgpu in the image's Linux environment, for the AMD GPUs its table holds,
# with their firmware in the bundle; its GPUs draw on RADV where the image's
# Mesa build holds it. `cargo xtask boot build` turns it on outside a release.
amdgpu = ["stela-drivers/amdgpu-port", "stela-loader/amdgpu-port"]
# amdgpu with RADV, NIR and ACO among the Mesa drivers `cargo xtask gpu nvk`
# builds, which back the Metal device on the GPU amdgpu binds.
radv = ["nvk", "amdgpu", "stela-drivers/radv"]
# Test builds only: holds the Metal device to `STELA_VRAM_CAP_MIB` MiB of
# device memory, which `cargo xtask boot` selects when the variable is set.
vram-cap = ["stela-drivers/vram-cap"]
+6 -6
View File
@@ -30,12 +30,12 @@ const ETIME: i64 = -62;
/// An ioctl argument's first bytes as the caller passed them: the kernel
/// writes its answer over the same structure. Only amdgpu's are decoded.
#[cfg_attr(not(feature = "radv"), allow(dead_code))]
#[cfg_attr(not(feature = "amdgpu"), allow(dead_code))]
pub(super) struct Input {
bytes: [u8; KEPT],
}
#[cfg_attr(not(feature = "radv"), allow(dead_code))]
#[cfg_attr(not(feature = "amdgpu"), allow(dead_code))]
impl Input {
fn u32(&self, at: usize) -> u32 {
u32::from_le_bytes(self.bytes[at..at + 4].try_into().expect("four bytes"))
@@ -191,7 +191,7 @@ fn name(number: u32) -> Option<&'static str> {
})
}
#[cfg(feature = "radv")]
#[cfg(feature = "amdgpu")]
fn driver(command: u32) -> Option<&'static str> {
Some(match command {
0x00 => "AMDGPU_GEM_CREATE",
@@ -214,14 +214,14 @@ fn driver(command: u32) -> Option<&'static str> {
})
}
#[cfg(not(feature = "radv"))]
#[cfg(not(feature = "amdgpu"))]
fn driver(_: u32) -> Option<&'static str> {
None
}
/// What the call asked for, for the driver commands whose refusal a Vulkan
/// driver reports as out of memory, written after a space each.
#[cfg(feature = "radv")]
#[cfg(feature = "amdgpu")]
fn describe(number: u32, input: &Input, out: &mut alloc::string::String) {
use core::fmt::Write;
let Some(command) = number.checked_sub(COMMAND_BASE) else {
@@ -284,5 +284,5 @@ fn describe(number: u32, input: &Input, out: &mut alloc::string::String) {
};
}
#[cfg(not(feature = "radv"))]
#[cfg(not(feature = "amdgpu"))]
fn describe(_: u32, _: &Input, _: &mut alloc::string::String) {}
-3
View File
@@ -36,9 +36,6 @@ metal = ["dep:stela-contracts"]
metal-vulkan = ["metal", "dep:ash"]
# The image links the Metal compiler's C (`crates/stela-mesa`).
metal-linked = ["metal-vulkan"]
# AMD's stack draws on RADV, which the image must link (`stela_vulkan_amd`);
# without it amdgpu shows frames another GPU drew.
radv = ["amdgpu-port", "metal-linked"]
# Test builds only: holds the Metal device to `STELA_VRAM_CAP_MIB` MiB of
# device memory when the build sets it, so a GPU with much memory takes the
# paths of one with little.
+15 -8
View File
@@ -142,9 +142,11 @@ pub static NVIDIA: GpuStack = GpuStack {
vulkan: Some(crate::metal::nvidia::DRIVER),
};
/// amdgpu with its display core, and RADV's admission. RADV is its Vulkan
/// driver in an image built with `radv` ([`AMD_VULKAN`]); in any other its
/// GPU shows the frames another GPU draws, on the displays wired to it.
/// amdgpu with its display core, RADV's admission and RADV, with ACO, as
/// its Vulkan driver when the image holds it ([`AMD_VULKAN`]). Whether its
/// GPU serves the Metal device is [`metal_devices`]' choice; otherwise, or
/// in an image built without RADV's tools, it shows the frames another GPU
/// draws on the displays wired to it.
#[cfg(feature = "amdgpu-port")]
pub static AMD: GpuStack = GpuStack {
vendor: Vendor::Amd,
@@ -178,15 +180,20 @@ pub static AMD: GpuStack = GpuStack {
vulkan: AMD_VULKAN,
};
/// RADV, in an image built with `radv`, whose build links it.
#[cfg(all(feature = "amdgpu-port", feature = "radv", not(test), stela_vulkan_amd))]
const AMD_VULKAN: Option<crate::metal::native::Driver> = Some(crate::metal::amd::DRIVER);
/// No Vulkan driver: an image built without `radv`.
/// RADV, in an image whose Mesa build holds it.
#[cfg(all(
feature = "amdgpu-port",
feature = "metal-linked",
not(test),
not(all(feature = "radv", stela_vulkan_amd))
stela_vulkan_amd
))]
const AMD_VULKAN: Option<crate::metal::native::Driver> = Some(crate::metal::amd::DRIVER);
/// No Vulkan driver: an image built where RADV's tools were missing.
#[cfg(all(
feature = "amdgpu-port",
feature = "metal-linked",
not(test),
not(stela_vulkan_amd)
))]
const AMD_VULKAN: Option<crate::metal::native::Driver> = None;
-1
View File
@@ -24,7 +24,6 @@ xe-port = ["stela-driver-gpu/xe-port"]
metal = ["stela-driver-gpu/metal"]
metal-vulkan = ["stela-driver-gpu/metal-vulkan"]
metal-linked = ["stela-driver-gpu/metal-linked"]
radv = ["amdgpu-port", "metal-linked", "stela-driver-gpu/radv"]
# Test builds only: the Metal device's memory cap.
vram-cap = ["stela-driver-gpu/vram-cap"]
+21 -37
View File
@@ -115,22 +115,15 @@ enum Scenario {
#[derive(Subcommand)]
pub enum Command {
/// Build `stela.efi` with its NVK GPU stack and guest components.
/// Build `stela.efi` with its GPU stacks and guest components: NVK
/// over nouveau, and, outside a release, amdgpu, whose GPUs draw on
/// RADV where the image's Mesa build holds it ([`linked_features`]).
Build {
#[arg(long)]
release: bool,
/// Include authored hardware fixtures in the mount.
#[arg(long)]
diagnostics: bool,
/// Carry amdgpu beside nouveau and the image's Mesa drivers, for a
/// Radeon RX 9070 (Navi 48) or RX 6800-6950 XT (Navi 21): amdgpu
/// binds it in the Linux environment.
#[arg(long, conflicts_with = "radv")]
amdgpu: bool,
/// Carry amdgpu and require RADV among the image's Mesa drivers:
/// amdgpu binds the GPU and RADV backs the Metal device over it.
#[arg(long)]
radv: bool,
},
/// Boot `stela.efi` with an ARM image in x86 QEMU.
Run(Box<Run>),
@@ -507,20 +500,13 @@ pub fn run(command: Command) -> Result<ExitCode> {
Command::Build {
release,
diagnostics,
amdgpu,
radv,
} => {
crate::gpu::fetch::fetch(false)?;
crate::gpu::build_nvk(crate::gpu::default_jobs())?;
let gpu = if radv {
crate::gpu::require_vulkan_driver("amd")?;
Gpu::Radv
} else if amdgpu {
Gpu::Amdgpu
} else {
Gpu::Nvk
};
println!("{}", build_for_boot(release, diagnostics, gpu)?.display());
println!(
"{}",
build_for_boot(release, diagnostics, Gpu::Linked)?.display()
);
Ok(ExitCode::SUCCESS)
}
Command::Run(arguments) => launch(*arguments),
@@ -529,7 +515,7 @@ pub fn run(command: Command) -> Result<ExitCode> {
pub fn build(release: bool) -> Result<PathBuf> {
crate::gpu::build_nvk(crate::gpu::default_jobs())?;
build_with_diagnostics(release, false, Gpu::Nvk)
build_with_diagnostics(release, false, Gpu::Linked)
}
/// The GPU drivers a `stela.efi` carries beyond its Linux environment.
@@ -537,13 +523,17 @@ pub fn build(release: bool) -> Result<PathBuf> {
enum Gpu {
/// None: nouveau binds nothing without NVK.
None,
/// NVK, NIR and NAK over nouveau, from `cargo xtask gpu nvk`.
Nvk,
/// amdgpu beside NVK: the GPU claims run in an image with the Mesa
/// drivers.
Amdgpu,
/// amdgpu with RADV, ACO and NIR among the image's Mesa drivers.
Radv,
/// The image's Mesa drivers and kernel drivers ([`linked_features`]).
Linked,
}
/// stela-boot's features for an image with its Mesa drivers: NVK over
/// nouveau, and, outside a release, amdgpu. Which GPUs draw is then the
/// image's own detection: AMD's stack gives RADV where `gpu nvk` built it
/// (`stela_vulkan_amd`), and otherwise its GPUs show frames another GPU
/// draws. A release leaves the AMD port and its firmware out.
pub(crate) fn linked_features(release: bool) -> &'static str {
if release { "nvk" } else { "nvk,amdgpu" }
}
fn build_for_boot(release: bool, diagnostics: bool, gpu: Gpu) -> Result<PathBuf> {
@@ -600,14 +590,8 @@ fn build_with_diagnostics(release: bool, diagnostics: bool, gpu: Gpu) -> Result<
}
match gpu {
Gpu::None => {}
Gpu::Nvk => {
command.args(["--features", "nvk"]);
}
Gpu::Amdgpu => {
command.args(["--features", "nvk,amdgpu"]);
}
Gpu::Radv => {
command.args(["--features", "radv"]);
Gpu::Linked => {
command.args(["--features", linked_features(crate::tools::release_build())]);
}
}
// A test build that holds the Metal device to that much device memory.
+18
View File
@@ -549,3 +549,21 @@ fn the_host_vfct_goes_to_the_run_only_when_it_holds_a_lent_gpus_video_bios() {
"file=/run/a,,b/VFCT"
);
}
#[test]
fn a_release_image_leaves_the_amd_port_out() {
// A development image holds amdgpu beside NVK; a release holds NVK
// alone, and stela-boot has no other GPU feature to choose.
assert_eq!(linked_features(false), "nvk,amdgpu");
assert_eq!(linked_features(true), "nvk");
let manifest = include_str!("../../../crates/stela-boot/Cargo.toml");
for feature in linked_features(false).split(',') {
assert!(
manifest
.lines()
.any(|line| line.starts_with(&format!("{feature} = "))),
"{feature}"
);
}
assert!(!manifest.lines().any(|line| line.starts_with("radv = ")));
}
+12 -1
View File
@@ -98,6 +98,12 @@ pub fn run(fix: bool, low_memory: bool) -> Result<()> {
"--features",
"metal-linked,nouveau-port",
]),
uefi([
"-p",
"stela-driver-gpu",
"--features",
"metal-linked,nouveau-port,amdgpu-port",
]),
];
let mut nvk_clippy = uefi([BOOT[0], BOOT[1], "--features", "nvk"]);
// Mesa's unchanged path crates declare their upstream naming lint
@@ -105,13 +111,18 @@ pub fn run(fix: bool, low_memory: bool) -> Result<()> {
// Stela's driver owners are checked separately above.
nvk_clippy.env("RUSTFLAGS", BOOT_RUSTFLAGS);
boot_lane.push(nvk_clippy);
// A development image's drivers, with the AMD port a release leaves out
// (`boot::linked_features`).
let mut ports_clippy = uefi([BOOT[0], BOOT[1], "--features", "nvk,amdgpu"]);
ports_clippy.env("RUSTFLAGS", BOOT_RUSTFLAGS);
boot_lane.push(ports_clippy);
let mut linked = command([
"build",
"--locked",
"--manifest-path",
BOOT_MANIFEST,
"--features",
"nvk",
crate::boot::linked_features(crate::tools::release_build()),
"--target",
BOOT_TARGET,
"--target-dir",
-13
View File
@@ -203,16 +203,3 @@ pub fn build_nvk(jobs: u16) -> Result<()> {
nvk::build(jobs)?;
crate::guest::run()
}
/// Fails unless the last `gpu nvk` linked the Vulkan driver `name` (Meson's
/// name for it), which needs the build host's tools (`clc.rs`).
pub fn require_vulkan_driver(name: &str) -> Result<()> {
let list = support::build_directory("nvk").join(nvk::LINKED);
let linked = std::fs::read_to_string(&list).unwrap_or_default();
anyhow::ensure!(
linked.lines().any(|linked| linked == name),
"Vulkan driver {name} is not built: `cargo xtask gpu nvk` says why ({})",
list.display()
);
Ok(())
}