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
7 changes: 5 additions & 2 deletions apps/desktop/e2e/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@ test('the graphics card and drawing without it are chosen in the settings and ap
const hint = dialog.getByTestId('settings-graphics-restart');
await expect(dialog.getByTestId('setting-gpuPreference-restart')).toBeVisible();
await expect(hint).toHaveCount(0);
await dialog.getByTestId('settings-gpu-preference').getByText('Fast').click();
const gpu = dialog.getByTestId('settings-gpu-preference');
await gpu.getByRole('button').click();
await page.getByRole('option', { name: 'Fast' }).click();
await expect(hint).toBeVisible();
// Back to what PartBuddy started with: nothing waits for a restart.
await dialog.getByTestId('settings-gpu-preference').getByText('Automatic').click();
await gpu.getByRole('button').click();
await page.getByRole('option', { name: 'Automatic' }).click();
await expect(hint).toHaveCount(0);
await dialog.getByTestId('settings-software-rendering').click();
await expect(hint).toBeVisible();
Expand Down
34 changes: 32 additions & 2 deletions apps/desktop/src/main/gpuPreference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import type { GpuPreference } from '../shared/contract';
* adapter for WebGL on Windows, so this is the way that holds (issue #484).
*/
const KEY = 'HKCU\\Software\\Microsoft\\DirectX\\UserGpuPreferences';
/** What Windows writes as the preference when one particular card is chosen. */
const SPECIFIC = 1073741824;
/** Microsoft's Basic Render Driver: drawing on the processor, which "Draw without the graphics card" covers. */
const MICROSOFT = 0x1414;

/** The `reg.exe` arguments that set or (automatic) remove the preference for `program`. */
export function windowsGpuArgs(program: string, preference: GpuPreference): string[] {
if (preference === 'auto') return ['delete', KEY, '/v', program, '/f'];
return ['add', KEY, '/v', program, '/t', 'REG_SZ', '/d', `GpuPreference=${preference === 'high' ? 2 : 1};`, '/f'];
const value =
preference === 'high' ? 'GpuPreference=2;' : preference === 'low' ? 'GpuPreference=1;' : `SpecificAdapter=${preference};GpuPreference=${SPECIFIC};`;
return ['add', KEY, '/v', program, '/t', 'REG_SZ', '/d', value, '/f'];
}

/** Sets Windows' preference for `program`; a removal of an entry that is not there counts as done. */
Expand All @@ -26,7 +32,31 @@ export function applyWindowsGpuPreference(program: string, preference: GpuPrefer
});
}

/** Chromium's switch on macOS, read at the start. */
/** Chromium's switch on macOS, read at the start; a particular card is Windows only. */
export function macGpuSwitch(preference: GpuPreference): string | null {
return preference === 'high' ? 'force_high_performance_gpu' : preference === 'low' ? 'force_low_power_gpu' : null;
}

/** A graphics card as Electron's `getGPUInfo('complete')` lists it in `gpuDevice`. */
export interface GpuDevice {
vendorId?: number;
deviceId?: number;
subSysId?: number;
deviceString?: string;
}

const hex = (value: number, digits: number) => (value >>> 0).toString(16).toUpperCase().padStart(digits, '0');

/**
* The cards to choose from, by the id Windows writes for them. Chromium lists a card once per role, so
* the same id comes up more than once; two identical cards share it too, and Windows cannot tell them apart.
*/
export function gpuAdapters(devices: readonly GpuDevice[]): { id: string; name: string }[] {
const cards = new Map<string, string>();
for (const { vendorId = 0, deviceId = 0, subSysId = 0, deviceString } of devices) {
if (!vendorId || vendorId === MICROSOFT) continue;
const id = `${hex(vendorId, 4)}&${hex(deviceId, 4)}&${hex(subSysId, 8)}`;
if (!cards.has(id)) cards.set(id, deviceString?.trim() || id);
}
return [...cards].map(([id, name]) => ({ id, name }));
}
16 changes: 14 additions & 2 deletions apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GeneralSettings } from './generalSettings';
import { SettingsStore } from './settingsStore';
import { RESET_KEYS } from '../shared/settings';
import { Updates } from './updates';
import { applyWindowsGpuPreference, macGpuSwitch } from './gpuPreference';
import { applyWindowsGpuPreference, gpuAdapters, macGpuSwitch, type GpuDevice } from './gpuPreference';
import { Assistant } from './agents/assistant';
import { commonSignatures, withSignatures } from './agents/signatures';
import { SolidCraftTools } from './agents/solidcraftTools';
Expand Down Expand Up @@ -561,14 +561,26 @@ if (!app.requestSingleInstanceLock()) {
});
if (updates.enabled && settingsStore.get('checkUpdates')) setTimeout(() => void updates.check(), 10_000);
// Interface size, start behaviour and update check (2026-11-07): the size applies at once, the rest at the next start.
const appSettings = () => ({
// The cards to choose one by one; only Windows takes a particular card.
const gpuCards =
process.platform === 'win32'
? app
.getGPUInfo('complete')
.then((info) => gpuAdapters((info as { gpuDevice?: GpuDevice[] }).gpuDevice ?? []))
.catch((error: unknown) => {
log(`warning: the graphics cards could not be listed (${String(error)})`);
return [];
})
: Promise.resolve([]);
const appSettings = async () => ({
zoom: settingsStore.get('zoom'),
startPage: settingsStore.get('startPage'),
checkUpdates: settingsStore.get('checkUpdates'),
viewportStats: settingsStore.get('viewportStats'),
viewportQuality: settingsStore.get('viewportQuality'),
gpuPreference: settingsStore.get('gpuPreference'),
softwareRendering: settingsStore.get('softwareRendering'),
gpuAdapters: await gpuCards,
graphicsRestart: settingsStore.get('gpuPreference') !== startGraphics.gpu || settingsStore.get('softwareRendering') !== startGraphics.software,
});
const applyZoom = () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/renderer/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@
},
"gpuPreference": {
"title": "Grafikkarte",
"hint": "Auf einem Rechner mit zwei Grafikkarten: Schnell wünscht die eigene Grafikkarte, Sparsam die im Prozessor, die Akku spart. Unter Windows stellt PartBuddy das in den Grafikeinstellungen von Windows für sich ein; Automatisch überlässt die Wahl wieder Windows. „Grafikkarte“ unten zeigt, welche zeichnet.",
"hint": "Auf einem Rechner mit zwei Grafikkarten: Schnell wünscht die eigene Grafikkarte, Sparsam die im Prozessor, die Akku spart. Unter Windows stellt PartBuddy das in den Grafikeinstellungen von Windows für sich ein; Automatisch überlässt die Wahl wieder Windows. Unter Windows lässt sich auch genau eine Karte aus der Liste wählen; zwei baugleiche Karten unterscheidet Windows nicht. „Grafikkarte“ unten zeigt, welche zeichnet.",
"auto": "Automatisch",
"high": "Schnell",
"low": "Sparsam"
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/renderer/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@
},
"gpuPreference": {
"title": "Graphics card",
"hint": "On a computer with two graphics cards: Fast asks for the dedicated card, Frugal for the integrated one, which saves battery. On Windows PartBuddy sets this in Windows' graphics settings for itself; Automatic leaves the choice to Windows again. “Graphics card” below shows which one draws.",
"hint": "On a computer with two graphics cards: Fast asks for the dedicated card, Frugal for the integrated one, which saves battery. On Windows PartBuddy sets this in Windows' graphics settings for itself; Automatic leaves the choice to Windows again. On Windows one particular card can be chosen from the list as well; Windows cannot tell two identical cards apart. “Graphics card” below shows which one draws.",
"auto": "Automatic",
"high": "Fast",
"low": "Frugal"
Expand Down
12 changes: 8 additions & 4 deletions apps/desktop/src/renderer/src/shell/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { PrintProfilesEditor } from '../print/PrintProfilesEditor';
import { platform } from '../platform';
import { useStudio, type SettingsSection } from '../state/store';
import { Button, iconButtonClass, linkClass } from '../ui/Button';
import { SwitchMark, segmentClass, segmentGroupClass } from '../ui/Choice';
import { SelectField, SwitchMark, segmentClass, segmentGroupClass } from '../ui/Choice';
import { DialogClose, dialogTitleClass, modalClass, overlayClass } from '../ui/Dialog';
import { inputClass } from '../ui/Field';
import { tabClass, tabListClass } from '../ui/Navigation';
Expand Down Expand Up @@ -418,13 +418,17 @@ function GeneralSection() {
/>
</Setting>
<Setting id="gpuPreference">
<Segmented
id="gpuPreference"
<SelectField
aria-label={t('settings.gpuPreference.title')}
value={app.gpuPreference}
options={(['auto', 'high', 'low'] as const).map((id) => ({ id, label: t(`settings.gpuPreference.${id}`) }))}
items={[
...(['auto', 'high', 'low'] as const).map((id) => ({ id, label: t(`settings.gpuPreference.${id}`) })),
...app.gpuAdapters.map(({ id, name }) => ({ id, label: name })),
]}
onChange={(next) => {
void platform().settings.setApp({ key: 'gpuPreference', value: next }).then(setApp);
}}
className="w-64"
testId="settings-gpu-preference"
/>
</Setting>
Expand Down
11 changes: 9 additions & 2 deletions apps/desktop/src/shared/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,13 @@ export const startPageSchema = z.enum(['home', 'last']);
/** How the 3D view trades picture for speed (issue #484); balanced is how it drew before. */
export const viewportQualitySchema = z.enum(['performance', 'balanced', 'quality']);
export type ViewportQuality = z.infer<typeof viewportQualitySchema>;
/** Which graphics card PartBuddy asks for (issue #484): Windows' or Chromium's choice, the fast one or the frugal one. */
export const gpuPreferenceSchema = z.enum(['auto', 'high', 'low']);
/** One graphics card as Windows' graphics settings name it: vendor, device and subsystem in hex. */
export const gpuAdapterIdSchema = z.string().regex(/^[0-9A-F]{4}&[0-9A-F]{4}&[0-9A-F]{8}$/);
/**
* Which graphics card PartBuddy asks for (issue #484): Windows' or Chromium's choice, the fast one, the
* frugal one, or one particular card (Windows only).
*/
export const gpuPreferenceSchema = z.union([z.enum(['auto', 'high', 'low']), gpuAdapterIdSchema]);
export type GpuPreference = z.infer<typeof gpuPreferenceSchema>;
/** The app-wide settings without a channel of their own, read and changed together. */
export const appSettingsSchema = z
Expand All @@ -388,6 +393,8 @@ export const appSettingsSchema = z
viewportQuality: viewportQualitySchema,
gpuPreference: gpuPreferenceSchema,
softwareRendering: z.boolean(),
/** The graphics cards of this computer to choose one by one (Windows, empty elsewhere). */
gpuAdapters: z.array(z.object({ id: gpuAdapterIdSchema, name: z.string() }).strict()),
/** The graphics settings differ from those PartBuddy started with: they apply after a restart. */
graphicsRestart: z.boolean(),
})
Expand Down
17 changes: 16 additions & 1 deletion apps/desktop/test/gpuPreference.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { macGpuSwitch, windowsGpuArgs } from '../src/main/gpuPreference';
import { gpuAdapters, macGpuSwitch, windowsGpuArgs } from '../src/main/gpuPreference';

const program = 'C:\\Program Files\\PartBuddy\\PartBuddy.exe';
const key = 'HKCU\\Software\\Microsoft\\DirectX\\UserGpuPreferences';
Expand All @@ -11,6 +11,21 @@ describe('graphics preference', () => {
expect(windowsGpuArgs(program, 'low')).toEqual(['add', key, '/v', program, '/t', 'REG_SZ', '/d', 'GpuPreference=1;', '/f']);
});

it('names one particular card the way Windows does', () => {
expect(windowsGpuArgs(program, '8086&A780&7D991462')).toEqual(['add', key, '/v', program, '/t', 'REG_SZ', '/d', 'SpecificAdapter=8086&A780&7D991462;GpuPreference=1073741824;', '/f']);
expect(macGpuSwitch('8086&A780&7D991462')).toBeNull();
});

it('lists each card once, without the processor driver', () => {
// As Electron 45 reported them on the server (2026-11-16): the active card again in its role, and Microsoft's driver.
const quadro = { vendorId: 4318, deviceId: 7857, subSysId: 312479784, deviceString: 'NVIDIA Quadro RTX 4000' };
const devices = [quadro, { vendorId: 32902, deviceId: 42880, subSysId: 2107184226, deviceString: 'Intel(R) UHD Graphics 770' }, quadro, { vendorId: 5140, deviceId: 140, subSysId: 0, deviceString: 'Microsoft Basic Render Driver' }];
expect(gpuAdapters(devices)).toEqual([
{ id: '10DE&1EB1&12A01028', name: 'NVIDIA Quadro RTX 4000' },
{ id: '8086&A780&7D991462', name: 'Intel(R) UHD Graphics 770' },
]);
});

it('leaves the choice to Windows again by removing it', () => {
expect(windowsGpuArgs(program, 'auto')).toEqual(['delete', key, '/v', program, '/f']);
});
Expand Down
2 changes: 1 addition & 1 deletion docs/feature-catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Work runs in three phases, one pull request per step, in this order.
| F13 Refined designs by default (done) | Decided 2026-11-07: the assistant designs nice, well-made parts without being asked. The rules go with the print profile note (`printNote`) in four groups: rounded and chamfered edges (outer radius 1/2/3 mm by part size, 45° chamfers on the bed, inner corners under load rounded), print-in-place joints first (gap one nozzle, at least 0.3 mm; another joint only with a reason), details (even walls, chamfered hole entries and lead-ins, sunk screw heads, soft transitions, text size) and sizes snapped to the printer (walls to whole lines of nozzle × 1.125, floors, lids, steps and chamfer heights to whole layers). Always on: sizes the user names are built exactly, with one sentence and a better value when they print poorly; fits by purpose with the material clearance scaled to the nozzle; printing before looks; one line per step naming what was added. Snapped parameters carry `[auto 3×line]` in their comment; a printer or nozzle change fits only those again, as user steps; a size the user sets in the table loses the mark; parameters of earlier projects have none and stay as they are. Off per group in Settings › Assistant, or for one project in the chat (`partbuddy_design_rules`, kept in the design's print file); the project goes before the setting. |
| F14 Material catalog and tolerance assistant (done) | Decided 2026-11-08, after R2 had removed measuring after printing (#77): measured are only the design values of a material profile, which the assistant needs while designing and no slicer knows; flow, temperature, shrinkage factor and calibration stay with the slicer. "Add material" in Settings › Printer and material copies one of 17 material types (#184) with starting values from design guides and data sheets, each with its source and a note where a value is derived. "Measure tolerances …" there: SolidCraft builds three test pieces for the nozzle and layer of the printer in use (`solidcraft-cli run`): a fit comb with a 6 mm pin and 13 holes from −0.1 to 0.5 mm clearance per side, drilled wider by the material's hole allowance so a step read is the room after printing (`combHole`, BC-16), a hole plate of 3, 5, 8 and 10 mm and an overhang staircase from 20° to 70°, every step engraved; together about 38 minutes and 13 g of PLA (Bambu Studio, X1C, 0.20 mm). Saved as 3MF or opened in a slicer SolidCraft found, with a picture SolidCraft renders and a short print guide. The user enters per fit the smallest step that clamps, pushes, slides or turns, the measured holes and the steepest clean overhang; `applyReadings` takes the steps, less half of what the comb was drilled wider than the plate measures now, marks them read off this comb (`fitsAfterPrint`; fits read off the older comb are said in the editor and the answers), averages nominal minus measured on 0.05 mm and keeps every value in the profile's limits, a preview shows before and after, Apply writes into the settings draft and Save keeps it. |
| F15 Dimension field round (done) | Decided 2026-11-08: the dimension field of the selection dock ([ADR 0017](adr/0017-dimension-field.md)) grows where the assistant was still needed. ↑ and ↓ step the value by 1 mm, Shift by 10, Alt by 0.1, in the dock and in the dimension labels on the part. Two parallel flat faces of one body show their distance (wall, offset, step) and change it like an edge, found by the same trying in SolidCraft (`model.faces`: point and normal). When several parameters move the selection, the dock lists them with a preview of the picked one instead of asking the assistant. A drag arrow at the dimension (end of the edge, side of the cylinder, second face) sets the value by pulling it, in whole mm or tenths with Alt, and applies it when let go once SolidCraft has tried it; the arrow is a Tabler icon turned to the dimension on screen. |
| F16 3D view and graphics (done) | Issue #484 (decided with the product owner on 2026-11-16). The view draws only while something changes or moves (`frameloop="demand"`), so an idle view costs no GPU. Settings › General › 3D view: the display quality (Performance: base resolution without smoothed edges and shadow; Balanced, the default; Quality: full resolution while turning and a finer shadow); the graphics card (Automatic, Fast, Frugal; on Windows the installed app writes Windows' own per-program preference, since Chromium cannot pick the adapter for WebGL there, on macOS a Chromium switch) and drawing without graphics card (hardware acceleration off), both after a restart; what draws (backend, graphics card, hardware or software); a switch for frames per second, frame time, draw calls and triangles over the view. Not done: a custom profile, picking one adapter by name, vendor-specific paths. WebGPU was measured and not taken: three's WebGPURenderer drew the same scene slower than WebGL on both cards of the test machine ([probe](../tools/webgpu-probe/README.md)). |
| F16 3D view and graphics (done) | Issue #484 (decided with the product owner on 2026-11-16). The view draws only while something changes or moves (`frameloop="demand"`), so an idle view costs no GPU. Settings › General › 3D view: the display quality (Performance: base resolution without smoothed edges and shadow; Balanced, the default; Quality: full resolution while turning and a finer shadow); the graphics card (Automatic, Fast, Frugal, or on Windows one card of the computer by name, written as Windows' `SpecificAdapter`; two identical cards share one id; on Windows the installed app writes Windows' own per-program preference, since Chromium cannot pick the adapter for WebGL there, on macOS a Chromium switch) and drawing without graphics card (hardware acceleration off), both after a restart; what draws (backend, graphics card, hardware or software); a switch for frames per second, frame time, draw calls and triangles over the view. Not done: a custom profile, picking one adapter on macOS, vendor-specific paths. WebGPU was measured and not taken: three's WebGPURenderer drew the same scene slower than WebGL on both cards of the test machine ([probe](../tools/webgpu-probe/README.md)). |

### Phase 3: motion (release 0.3.0)

Expand Down