Skip to content

Commit d7fabfa

Browse files
committed
fix(windows): probe MeshLLM catalog VRAM with DXGI
Signed-off-by: stevepresley <[email protected]>
1 parent 3aaea80 commit d7fabfa

8 files changed

Lines changed: 145 additions & 133 deletions

File tree

‎.github/workflows/windows-canary.yml‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ jobs:
124124
~/.cargo/git
125125
target
126126
desktop/src-tauri/target
127-
!desktop/src-tauri/target/**/release/bundle
127+
!desktop/src-tauri/target/**/release/bundle/**
128128
key: ${{ steps.rust_cache_key.outputs.key }}
129129

130+
- name: Remove restored bundle outputs
131+
shell: bash
132+
run: rm -rf desktop/src-tauri/target/**/release/bundle
133+
130134
- name: Generate non-updating bundle config
131135
shell: bash
132136
run: |
@@ -157,15 +161,18 @@ jobs:
157161
- name: Locate NSIS installer
158162
id: artifact
159163
shell: bash
164+
env:
165+
VERSION: ${{ steps.version.outputs.version }}
160166
run: |
161167
set -euo pipefail
162168
BUNDLE_DIR="desktop/src-tauri/target/${TARGET}/release/bundle"
163-
EXE=$(find "$BUNDLE_DIR/nsis" -name '*.exe' -type f | head -1)
164-
if [[ -z "$EXE" ]]; then
165-
echo "::error::No NSIS installer found in $BUNDLE_DIR/nsis"
169+
mapfile -t EXES < <(find "$BUNDLE_DIR/nsis" -name "*${VERSION}*.exe" -type f | sort)
170+
if [[ ${#EXES[@]} -ne 1 ]]; then
171+
echo "::error::Expected exactly one NSIS installer for version $VERSION in $BUNDLE_DIR/nsis; found ${#EXES[@]}"
172+
find "$BUNDLE_DIR/nsis" -name '*.exe' -type f -print || true
166173
exit 1
167174
fi
168-
echo "exe=$EXE" >> "$GITHUB_OUTPUT"
175+
echo "exe=${EXES[0]}" >> "$GITHUB_OUTPUT"
169176
170177
- name: Upload Windows canary installer
171178
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
@@ -191,7 +198,7 @@ jobs:
191198
~/.cargo/git
192199
target
193200
desktop/src-tauri/target
194-
!desktop/src-tauri/target/**/release/bundle
201+
!desktop/src-tauri/target/**/release/bundle/**
195202
key: ${{ steps.rust_cache_key.outputs.key }}
196203

197204
- name: Save pnpm store cache

‎desktop/src-tauri/Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎desktop/src-tauri/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ user-idle = { version = "0.6", default-features = false }
6363
plist = "1"
6464

6565
[target.'cfg(windows)'.dependencies]
66+
windows = { version = "0.62", features = ["Win32_Graphics_Dxgi"] }
6667
windows-sys = { version = "0.61", features = ["Win32_Security", "Win32_Storage_FileSystem", "Win32_System_JobObjects", "Win32_System_LibraryLoader", "Win32_System_Registry", "Win32_System_Threading", "Win32_Foundation"] }
6768
keyring = { version = "3.6.3", default-features = false, features = ["windows-native", "vendored"], optional = true }
6869
user-idle = { version = "0.6", default-features = false }

‎desktop/src-tauri/src/commands/mesh_llm.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ fn prepare_windows_mesh_runtime_dependencies(app: &AppHandle) {
269269
for name in WINDOWS_MESH_RUNTIME_DEP_DLLS {
270270
let src = dependency_dir.join(name);
271271
let dst = lib_dir.join(name);
272+
// Runtime archives are authoritative for DLLs they ship;
273+
// Buzz's bundle only fills gaps (for example CUDA
274+
// archives that lack MinGW support DLLs). Do not
275+
// replace archive-provided DLLs with runner-local
276+
// MinGW copies, whose version depends on whether the
277+
// bundler bootstrapped via MSYS2 or Chocolatey.
272278
if dst.is_file() {
273279
append_mesh_debug_log(
274280
app,

‎desktop/src-tauri/src/mesh_llm/catalog.rs‎

Lines changed: 109 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ pub enum ModelFit {
6060
Tight,
6161
Tradeoff,
6262
TooLarge,
63+
Unknown,
6364
}
6465

6566
fn fit_code(model_gb: f64, vram_gb: f64) -> ModelFit {
66-
if model_gb <= vram_gb * 0.6 {
67+
if vram_gb <= 0.0 {
68+
ModelFit::Unknown
69+
} else if model_gb <= vram_gb * 0.6 {
6770
ModelFit::Comfortable
6871
} else if model_gb <= vram_gb * 0.9 {
6972
ModelFit::Tight
@@ -80,6 +83,7 @@ fn fit_rank(fit: ModelFit) -> u8 {
8083
ModelFit::Tight => 1,
8184
ModelFit::Tradeoff => 2,
8285
ModelFit::TooLarge => 3,
86+
ModelFit::Unknown => 4,
8387
}
8488
}
8589

@@ -148,129 +152,67 @@ fn catalog_hardware() -> CatalogHardware {
148152
// GPU VRAM. That is useful for runtime placement, but misleading in the
149153
// picker: a 16 GB card with 32 GB system RAM reads as ~32 GB and receives
150154
// too-large recommendations. For the catalog, report and rank against
151-
// dedicated GPU memory only. These probes also hide child console windows,
152-
// avoiding the visible PowerShell/nvidia-smi flashes from the upstream
153-
// survey when Settings → Compute opens.
154-
if let Some((names, vram_bytes)) = windows_nvidia_smi_gpus() {
155-
return CatalogHardware {
156-
gpu_name: summarize_gpu_names(&names),
157-
vram_bytes,
158-
};
159-
}
160-
let gpus = windows_video_controllers();
161-
let names: Vec<String> = gpus.iter().map(|(name, _)| name.clone()).collect();
162-
let vram_bytes = gpus.iter().map(|(_, bytes)| *bytes).sum();
163-
CatalogHardware {
164-
gpu_name: summarize_gpu_names(&names),
165-
vram_bytes,
166-
}
167-
}
168-
169-
#[cfg(target_os = "windows")]
170-
fn windows_command_output(program: &str, args: &[&str]) -> Option<String> {
171-
use std::os::windows::process::CommandExt;
172-
173-
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
174-
let output = std::process::Command::new(program)
175-
.args(args)
176-
.creation_flags(CREATE_NO_WINDOW)
177-
.output()
178-
.ok()?;
179-
if !output.status.success() {
180-
return None;
181-
}
182-
String::from_utf8(output.stdout).ok()
183-
}
184-
185-
#[cfg(target_os = "windows")]
186-
fn windows_nvidia_smi_gpus() -> Option<(Vec<String>, u64)> {
187-
let output = windows_command_output(
188-
"nvidia-smi",
189-
&[
190-
"--query-gpu=name,memory.total",
191-
"--format=csv,noheader,nounits",
192-
],
193-
)?;
194-
parse_nvidia_smi_catalog_output(&output)
155+
// dedicated GPU memory only.
156+
select_catalog_adapter(&dxgi_adapters())
157+
.map(|adapter| CatalogHardware {
158+
gpu_name: Some(adapter.name.clone()),
159+
vram_bytes: adapter.dedicated_vram_bytes,
160+
})
161+
.unwrap_or(CatalogHardware {
162+
gpu_name: None,
163+
vram_bytes: 0,
164+
})
195165
}
196166

197167
#[cfg(target_os = "windows")]
198-
fn parse_nvidia_smi_catalog_output(output: &str) -> Option<(Vec<String>, u64)> {
199-
let mut names = Vec::new();
200-
let mut total = 0_u64;
201-
for line in output
202-
.lines()
203-
.map(str::trim)
204-
.filter(|line| !line.is_empty())
205-
{
206-
let Some((name, mib)) = line.rsplit_once(',') else {
207-
continue;
208-
};
209-
let Ok(mib) = mib.trim().parse::<u64>() else {
210-
continue;
211-
};
212-
if mib == 0 {
213-
continue;
214-
}
215-
names.push(name.trim().to_string());
216-
total = total.saturating_add(mib.saturating_mul(1024 * 1024));
217-
}
218-
(!names.is_empty() && total > 0).then_some((names, total))
168+
#[derive(Debug, Clone, PartialEq, Eq)]
169+
struct DxgiAdapterInfo {
170+
name: String,
171+
dedicated_vram_bytes: u64,
172+
software: bool,
219173
}
220174

221175
#[cfg(target_os = "windows")]
222-
#[derive(serde::Deserialize)]
223-
#[serde(rename_all = "PascalCase")]
224-
struct WindowsVideoController {
225-
name: Option<String>,
226-
#[serde(rename = "AdapterRAM")]
227-
adapter_ram: Option<serde_json::Value>,
176+
fn select_catalog_adapter(adapters: &[DxgiAdapterInfo]) -> Option<&DxgiAdapterInfo> {
177+
adapters
178+
.iter()
179+
.filter(|adapter| !adapter.software && adapter.dedicated_vram_bytes > 0)
180+
// Rank against a single adapter's memory. Summing multiple GPUs would
181+
// recommend models that fit in no one adapter unless the runtime can
182+
// explicitly shard layers across devices.
183+
.max_by_key(|adapter| adapter.dedicated_vram_bytes)
228184
}
229185

230186
#[cfg(target_os = "windows")]
231-
fn windows_video_controllers() -> Vec<(String, u64)> {
232-
let Some(output) = windows_command_output(
233-
"powershell",
234-
&[
235-
"-NoProfile",
236-
"-Command",
237-
"Get-CimInstance Win32_VideoController | Select-Object Name,AdapterRAM | ConvertTo-Json -Compress",
238-
],
239-
) else {
240-
return Vec::new();
187+
fn dxgi_adapters() -> Vec<DxgiAdapterInfo> {
188+
use windows::Win32::Graphics::Dxgi::{
189+
CreateDXGIFactory1, IDXGIFactory1, DXGI_ADAPTER_FLAG_SOFTWARE,
241190
};
242-
parse_windows_video_controller_catalog_json(&output)
243-
}
244-
245-
#[cfg(target_os = "windows")]
246-
fn parse_windows_video_controller_catalog_json(output: &str) -> Vec<(String, u64)> {
247-
fn ram(value: &serde_json::Value) -> Option<u64> {
248-
value
249-
.as_u64()
250-
.or_else(|| value.as_str().and_then(|s| s.trim().parse().ok()))
251-
}
252191

253-
let parse_one = |controller: WindowsVideoController| {
254-
let name = controller.name?.trim().to_string();
255-
let bytes = ram(&controller.adapter_ram?)?;
256-
(bytes > 0 && !name.is_empty()).then_some((name, bytes))
192+
let Ok(factory) = (unsafe { CreateDXGIFactory1::<IDXGIFactory1>() }) else {
193+
return Vec::new();
257194
};
258195

259-
if let Ok(controller) = serde_json::from_str::<WindowsVideoController>(output) {
260-
return parse_one(controller).into_iter().collect();
196+
let mut adapters = Vec::new();
197+
let mut index = 0;
198+
while let Ok(adapter) = unsafe { factory.EnumAdapters1(index) } {
199+
index += 1;
200+
let Ok(desc) = (unsafe { adapter.GetDesc1() }) else {
201+
continue;
202+
};
203+
adapters.push(DxgiAdapterInfo {
204+
name: utf16_description(&desc.Description),
205+
dedicated_vram_bytes: desc.DedicatedVideoMemory as u64,
206+
software: (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32) != 0,
207+
});
261208
}
262-
serde_json::from_str::<Vec<WindowsVideoController>>(output)
263-
.map(|controllers| controllers.into_iter().filter_map(parse_one).collect())
264-
.unwrap_or_default()
209+
adapters
265210
}
266211

267212
#[cfg(target_os = "windows")]
268-
fn summarize_gpu_names(names: &[String]) -> Option<String> {
269-
match names {
270-
[] => None,
271-
[one] => Some(one.clone()),
272-
_ => Some(format!("{} GPUs", names.len())),
273-
}
213+
fn utf16_description(value: &[u16]) -> String {
214+
let len = value.iter().position(|ch| *ch == 0).unwrap_or(value.len());
215+
String::from_utf16_lossy(&value[..len]).trim().to_string()
274216
}
275217

276218
fn installed_names() -> Vec<(String, String)> {
@@ -337,7 +279,8 @@ fn build_catalog(
337279
});
338280
}
339281

340-
let recommended = Some(buzz_recommended_model(rated_capacity_gb(vram_bytes)).to_string());
282+
let recommended =
283+
(vram_bytes > 0).then(|| buzz_recommended_model(rated_capacity_gb(vram_bytes)).to_string());
341284
for entry in &mut entries {
342285
entry.recommended = recommended.as_deref() == Some(entry.name.as_str());
343286
// Both curated tiers are always offered: the recommended one for this
@@ -356,7 +299,11 @@ fn build_catalog(
356299

357300
MeshModelCatalog {
358301
gpu_name,
359-
vram_display: format_rated_capacity(vram_bytes),
302+
vram_display: if vram_bytes > 0 {
303+
format_rated_capacity(vram_bytes)
304+
} else {
305+
"Unknown".to_string()
306+
},
360307
vram_gb,
361308
recommended,
362309
entries,
@@ -386,6 +333,7 @@ mod tests {
386333
assert_eq!(fit_code(10.0, 12.0), ModelFit::Tight);
387334
assert_eq!(fit_code(10.0, 10.0), ModelFit::Tradeoff);
388335
assert_eq!(fit_code(10.0, 8.0), ModelFit::TooLarge);
336+
assert_eq!(fit_code(10.0, 0.0), ModelFit::Unknown);
389337
}
390338

391339
#[test]
@@ -434,27 +382,62 @@ mod tests {
434382

435383
#[cfg(target_os = "windows")]
436384
#[test]
437-
fn windows_catalog_uses_dedicated_gpu_vram_not_system_offload() {
438-
let (names, bytes) = parse_nvidia_smi_catalog_output("NVIDIA GeForce RTX 5060 Ti, 16376\n")
439-
.expect("nvidia-smi row parses");
440-
assert_eq!(names, vec!["NVIDIA GeForce RTX 5060 Ti"]);
441-
assert_eq!(bytes, 16_376 * 1024 * 1024);
442-
assert_eq!(format_rated_capacity(bytes), "16 GB");
385+
fn windows_catalog_uses_max_dedicated_adapter_vram() {
386+
let adapters = vec![
387+
DxgiAdapterInfo {
388+
name: "AMD Radeon RX 7600 XT".to_string(),
389+
dedicated_vram_bytes: 16 * 1024 * 1024 * 1024,
390+
software: false,
391+
},
392+
DxgiAdapterInfo {
393+
name: "NVIDIA GeForce RTX 4060".to_string(),
394+
dedicated_vram_bytes: 8 * 1024 * 1024 * 1024,
395+
software: false,
396+
},
397+
];
398+
let selected = select_catalog_adapter(&adapters).expect("adapter selected");
399+
assert_eq!(selected.name, "AMD Radeon RX 7600 XT");
400+
// The catalog ranks what fits on one adapter, not pooled multi-GPU VRAM.
401+
assert_eq!(selected.dedicated_vram_bytes, 16 * 1024 * 1024 * 1024);
402+
assert_eq!(
403+
format_rated_capacity(selected.dedicated_vram_bytes),
404+
"16 GB"
405+
);
406+
}
407+
408+
#[test]
409+
fn unknown_vram_does_not_mark_entries_too_large() {
410+
let catalog = build_catalog(None, 0, 0.0, &[]);
411+
assert_eq!(catalog.vram_display, "Unknown");
412+
assert!(catalog.recommended.is_none());
413+
assert!(catalog
414+
.entries
415+
.iter()
416+
.all(|entry| entry.fit == ModelFit::Unknown));
443417
}
444418

445419
#[cfg(target_os = "windows")]
446420
#[test]
447-
fn windows_catalog_parses_cim_video_controller_json() {
448-
let controllers = parse_windows_video_controller_catalog_json(
449-
r#"[{"Name":"GPU A","AdapterRAM":8589934592},{"Name":"GPU B","AdapterRAM":"4294967296"}]"#,
450-
);
451-
assert_eq!(
452-
controllers,
453-
vec![
454-
("GPU A".to_string(), 8_589_934_592),
455-
("GPU B".to_string(), 4_294_967_296)
456-
]
457-
);
421+
fn windows_catalog_ignores_software_and_zero_vram_adapters() {
422+
let adapters = vec![
423+
DxgiAdapterInfo {
424+
name: "Microsoft Basic Render Driver".to_string(),
425+
dedicated_vram_bytes: 32 * 1024 * 1024 * 1024,
426+
software: true,
427+
},
428+
DxgiAdapterInfo {
429+
name: "DisplayLink".to_string(),
430+
dedicated_vram_bytes: 0,
431+
software: false,
432+
},
433+
DxgiAdapterInfo {
434+
name: "AMD Radeon RX 7600 XT".to_string(),
435+
dedicated_vram_bytes: 16 * 1024 * 1024 * 1024,
436+
software: false,
437+
},
438+
];
439+
let selected = select_catalog_adapter(&adapters).expect("hardware adapter selected");
440+
assert_eq!(selected.name, "AMD Radeon RX 7600 XT");
458441
}
459442

460443
#[test]

‎desktop/src/features/mesh-compute/catalogDefault.test.mjs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ test("defaultShareModelFromCatalog never picks too large entries", () => {
4949
);
5050
});
5151

52+
test("defaultShareModelFromCatalog can pick unknown-fit entries", () => {
53+
assert.equal(
54+
defaultShareModelFromCatalog([entry("unknown", { fit: "unknown" })]),
55+
"unknown",
56+
);
57+
});
58+
5259
test("defaultShareModelFromCatalog returns null when nothing is usable", () => {
5360
assert.equal(
5461
defaultShareModelFromCatalog([entry("too-large", { fit: "too_large" })]),

0 commit comments

Comments
 (0)