diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index aa354f8e21..9594559724 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -252365,6 +252365,7 @@ "qsv", "vaapi", "nvenc", + "videotoolbox", "none" ], "type": "string" diff --git a/docs/admin-api.md b/docs/admin-api.md index 48e49641c8..6618d0b285 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -382,8 +382,8 @@ configuration, last health result, and last stored hardware inventory. See `hw_accel_override` and `hw_device_override` override the cluster-wide `playback.hw_accel` and `playback.hw_device` settings for one node. `hw_accel_override` takes the same values as the cluster setting — `auto`, -`qsv`, `vaapi`, `nvenc`, `none`. Absent means inherit; there is no separate -"inherit" value to set. +`qsv`, `vaapi`, `nvenc`, `videotoolbox`, `none`. Absent means inherit; there +is no separate "inherit" value to set. They exist for a heterogeneous deployment: one CPU-only node in a QSV cluster sets `none` for itself instead of forcing every node onto the lowest common @@ -839,11 +839,11 @@ indistinguishable from omission. `200 OK` with the updated node, `404 Not Found` for an unknown id, `422 validation_failed` when `hw_accel_override` is not one of `auto`, `qsv`, -`vaapi`, `nvenc`, `none` (matched case-insensitively and stored lowercase, as -`playback.hw_accel` is). The node pools are reloaded afterwards, so remote -dispatch honors a new override immediately; the target node itself picks it up -on its next config reload — see "Acceleration overrides" above for what waits -for a restart. +`vaapi`, `nvenc`, `videotoolbox`, `none` (matched case-insensitively and +stored lowercase, as `playback.hw_accel` is). The node pools are reloaded +afterwards, so remote dispatch honors a new override immediately; the target +node itself picks it up on its next config reload — see "Acceleration +overrides" above for what waits for a restart. `download_artifact_dir_override` (an absolute path; `null` or empty restores the inherited directory) and `download_artifact_max_bytes_override` (bytes, `0` for no @@ -1000,7 +1000,7 @@ Top-level (and each node's own report): | Field | Type | Meaning | |---|---|---| -| `resolved` | string | The backend that would actually be used: `nvenc`, `qsv`, `vaapi`, or `none`. An explicitly configured backend wins even when its probe failed — read `detected_backends` for why. | +| `resolved` | string | The backend that would actually be used: `nvenc`, `qsv`, `vaapi`, `videotoolbox`, or `none`. An explicitly configured backend wins even when its probe failed — read `detected_backends` for why. | | `render_devices` | string[] | Every accessible `/dev/dri/renderD*` path. | | `render_device_details` | object[] | One entry per device (see below). | | `intel_detected` | bool | An Intel GPU is present in the inventory. | @@ -1025,7 +1025,7 @@ Top-level (and each node's own report): | Field | Type | Meaning | |---|---|---| -| `backend` | string | `nvenc`, `qsv`, or `vaapi`. | +| `backend` | string | `nvenc`, `qsv`, `vaapi`, or `videotoolbox`. | | `verified` | bool | At least one candidate device passed a real single-frame encode, not just an FFmpeg build-flag listing. | | `devices` | string[] | Every candidate considered for this backend. | | `device` | string | The candidate whose probe passed. Empty for NVENC, which addresses its GPU through CUDA rather than a render node. | diff --git a/internal/nodecontrol/protocol.go b/internal/nodecontrol/protocol.go index 327f7603dc..0193dee4e5 100644 --- a/internal/nodecontrol/protocol.go +++ b/internal/nodecontrol/protocol.go @@ -173,7 +173,7 @@ type Registration struct { Group *string `json:"group,omitempty"` MaxJobs *int `json:"max_jobs,omitempty"` SourceAccess *string `json:"source_access,omitempty" enum:"local,core"` - HWAccelOverride *string `json:"hw_accel_override,omitempty" enum:"auto,qsv,vaapi,nvenc,none"` + HWAccelOverride *string `json:"hw_accel_override,omitempty" enum:"auto,qsv,vaapi,nvenc,videotoolbox,none"` HWDeviceOverride *string `json:"hw_device_override,omitempty"` DownloadArtifactDirOverride *string `json:"download_artifact_dir_override,omitempty"` DownloadArtifactMaxBytesOverride *int64 `json:"download_artifact_max_bytes_override,omitempty"` diff --git a/internal/nodedeclare/nodedeclare_test.go b/internal/nodedeclare/nodedeclare_test.go index 1c91ecf136..6c2badefce 100644 --- a/internal/nodedeclare/nodedeclare_test.go +++ b/internal/nodedeclare/nodedeclare_test.go @@ -20,7 +20,7 @@ func TestFromEnv(t *testing.T) { }) t.Run("values follow the update body", func(t *testing.T) { in, err := FromEnv(nodepool.NodeTypeTranscode, env(map[string]string{ - "SILO_NODE_MAX_TRANSCODES": "0", "SILO_NODE_HW_ACCEL": "QSV", "SILO_NODE_SOURCE_ACCESS": "core", + "SILO_NODE_MAX_TRANSCODES": "0", "SILO_NODE_HW_ACCEL": "VideoToolbox", "SILO_NODE_SOURCE_ACCESS": "core", "SILO_NODE_URL": "http://gpu1:8082", "SILO_NODE_DOWNLOAD_ARTIFACT_MAX_BYTES": "0", // A proxy variable means nothing to a transcode node. "SILO_NODE_MAX_STREAMS": "5", @@ -32,7 +32,7 @@ func TestFromEnv(t *testing.T) { if got := in.SetFields(); !slices.Equal(got, want) { t.Fatalf("declared %v, want %v", got, want) } - if *in.MaxJobs != 0 || *in.HWAccelOverride != "qsv" || *in.DownloadArtifactMaxBytesOverride != 0 { + if *in.MaxJobs != 0 || *in.HWAccelOverride != "videotoolbox" || *in.DownloadArtifactMaxBytesOverride != 0 { t.Fatalf("max_jobs %d, hw_accel %q, max_bytes %d", *in.MaxJobs, *in.HWAccelOverride, *in.DownloadArtifactMaxBytesOverride) } }) diff --git a/internal/nodepool/declaration_db_test.go b/internal/nodepool/declaration_db_test.go index b47a608e73..f1170ac673 100644 --- a/internal/nodepool/declaration_db_test.go +++ b/internal/nodepool/declaration_db_test.go @@ -25,7 +25,7 @@ func TestNodeDeclarationsLockFieldsDB(t *testing.T) { return revision, generation } - group, jobs, accel := "rack-a", 0, "vaapi" + group, jobs, accel := "rack-a", 0, "videotoolbox" declared, _, err := store.Declare(ctx, node.ID, UpdateNodeInput{Group: &group, MaxJobs: &jobs, HWAccelOverride: &accel}) if err != nil { t.Fatal(err) @@ -38,7 +38,7 @@ func TestNodeDeclarationsLockFieldsDB(t *testing.T) { // Restating a declared value, in the spelling a full-form save sends, // goes through; changing one is refused and changes nothing. restated, zero := "rack-a", 0 - if _, _, err := store.Update(ctx, node.ID, UpdateNodeInput{Group: &restated, MaxJobs: &zero}, accept); err != nil { + if _, _, err := store.Update(ctx, node.ID, UpdateNodeInput{Group: &restated, MaxJobs: &zero, HWAccelOverride: &accel}, accept); err != nil { t.Fatalf("restating declared values: %v", err) } other, name := "rack-b", "renamed" diff --git a/internal/nodepool/repository.go b/internal/nodepool/repository.go index 7022e98c46..da93cb27a1 100644 --- a/internal/nodepool/repository.go +++ b/internal/nodepool/repository.go @@ -448,17 +448,18 @@ func (i UpdateNodeInput) ValidateFor(node *Node) error { // internal/config/admin_settings.go and the CHECK constraint on // stream_nodes.hw_accel_override: a per-node override may only name a backend // the cluster-wide setting could also name. -var hwAccelOverrideValues = []string{hwAccelAuto, hwAccelQSV, hwAccelVAAPI, hwAccelNVENC, hwAccelNone} +var hwAccelOverrideValues = []string{hwAccelAuto, hwAccelQSV, hwAccelVAAPI, hwAccelNVENC, hwAccelVideoToolbox, hwAccelNone} const ( // hwAccelAuto asks the node to resolve its own backend against live // hardware at session start; dispatch passes it through untouched for // exactly that reason. - hwAccelAuto = "auto" - hwAccelQSV = "qsv" - hwAccelVAAPI = "vaapi" - hwAccelNVENC = "nvenc" - hwAccelNone = "none" + hwAccelAuto = "auto" + hwAccelQSV = "qsv" + hwAccelVAAPI = "vaapi" + hwAccelNVENC = "nvenc" + hwAccelVideoToolbox = "videotoolbox" + hwAccelNone = "none" ) // sameURL is true when an update leaves the row addressing the same worker. diff --git a/migrations/sql/20261121042328_allow_videotoolbox_node_override.sql b/migrations/sql/20261121042328_allow_videotoolbox_node_override.sql new file mode 100644 index 0000000000..791e673e78 --- /dev/null +++ b/migrations/sql/20261121042328_allow_videotoolbox_node_override.sql @@ -0,0 +1,22 @@ +-- +goose Up +-- A node can be pinned to VideoToolbox, as the cluster-wide playback.hw_accel +-- already can: hw_accel_override takes the same values as that setting. +ALTER TABLE public.stream_nodes DROP CONSTRAINT stream_nodes_hw_accel_override_check; +ALTER TABLE public.stream_nodes + ADD CONSTRAINT stream_nodes_hw_accel_override_check + CHECK (hw_accel_override IN ('auto', 'qsv', 'vaapi', 'nvenc', 'videotoolbox', 'none')); + +-- +goose Down +-- A node pinned to VideoToolbox goes back to inheriting the cluster setting, +-- and a field its environment declared is no longer locked to that value. +-- The table lock the ALTERs need comes first: taken after the UPDATE, it could +-- deadlock with a node's health write waiting on a row the UPDATE changed. +LOCK TABLE public.stream_nodes IN ACCESS EXCLUSIVE MODE; +UPDATE public.stream_nodes +SET hw_accel_override = NULL, + env_managed = array_remove(env_managed, 'hw_accel_override') +WHERE hw_accel_override = 'videotoolbox'; +ALTER TABLE public.stream_nodes DROP CONSTRAINT stream_nodes_hw_accel_override_check; +ALTER TABLE public.stream_nodes + ADD CONSTRAINT stream_nodes_hw_accel_override_check + CHECK (hw_accel_override IN ('auto', 'qsv', 'vaapi', 'nvenc', 'none')); diff --git a/web/src/pages/AdminNodes.tsx b/web/src/pages/AdminNodes.tsx index 2001a1c20e..e04c5e7f59 100644 --- a/web/src/pages/AdminNodes.tsx +++ b/web/src/pages/AdminNodes.tsx @@ -97,6 +97,7 @@ import { nodeUsesCUDADevices, parseHWDeviceOverride, restoreEnvManagedFields, + nodeUsesVideoToolbox, } from "./adminNodesPresentation"; import { NodeRoutingSettings } from "@/pages/admin-settings/NodeRoutingSettings"; @@ -1055,6 +1056,9 @@ function NodeForm({ const { data: serverSettings } = useAdminServerSettings(); const clusterHWAccel = serverSettings?.["playback.hw_accel"]; const usesCUDADevices = nodeUsesCUDADevices(node, hwAccelOverride, clusterHWAccel); + // VideoToolbox takes no device, so its control is hidden. The value stays in + // state and is saved as it was: hiding it clears nothing. + const showDeviceOverride = !nodeUsesVideoToolbox(node, hwAccelOverride, clusterHWAccel); // A device override written for one syntax means nothing in the other: a // render path is not a CUDA identity and neither is settable as the other, so // moving the selection between them drops the stored value rather than @@ -1319,61 +1323,63 @@ function NodeForm({ {lockedNote("hw_accel_override")} -
- - {hasDeviceInventory ? ( - - setHwDeviceOverride(toggleHWDevice(hwDeviceOverride, path, devicePaths)) - } - onInherit={() => setHwDeviceOverride("")} - disabled={isLocked("hw_device_override")} - /> - ) : ( - <> - + + {hasDeviceInventory ? ( + + setHwDeviceOverride(toggleHWDevice(hwDeviceOverride, path, devicePaths)) + } + onInherit={() => setHwDeviceOverride("")} disabled={isLocked("hw_device_override")} - onChange={(e) => setHwDeviceOverride(e.target.value)} - placeholder={t("web.admin.nodes.form.gpuDevicesPlaceholder")} /> - {/* - Each branch is a whole sentence rather than a shared tail: an - NVENC node reaches the free-text field *with* a reported - inventory (its render devices are real, they are just not what - NVENC addresses), so "no inventory yet" is only true of the - other branch — and splitting one sentence across the - conditional also lets JSX drop the space before "empty". - - Neither branch says what leaving this empty resolves to. Empty - inherits the cluster-wide playback.hw_device verbatim, and this - form does not know that value — naming a default here would be - a guess, and on the NVENC branch a dangerous one, since an - inherited /dev/dri path reaches NVENC as a CUDA identity. - */} -

- {usesCUDADevices - ? t("web.admin.nodes.form.cudaDeviceHelp", { - index: "0", - uuid: "GPU-a1b2c3d4", - path: "/dev/dri", - mono, - }) - : t("web.admin.nodes.form.renderDeviceHelp", { - example: "/dev/dri/renderD128,/dev/dri/renderD129", - mono, - })} -

- - )} - {lockedNote("hw_device_override")} -
+ ) : ( + <> + setHwDeviceOverride(e.target.value)} + placeholder={t("web.admin.nodes.form.gpuDevicesPlaceholder")} + /> + {/* + Each branch is a whole sentence rather than a shared tail: an + NVENC node reaches the free-text field *with* a reported + inventory (its render devices are real, they are just not what + NVENC addresses), so "no inventory yet" is only true of the + other branch — and splitting one sentence across the + conditional also lets JSX drop the space before "empty". + + Neither branch says what leaving this empty resolves to. Empty + inherits the cluster-wide playback.hw_device verbatim, and this + form does not know that value — naming a default here would be + a guess, and on the NVENC branch a dangerous one, since an + inherited /dev/dri path reaches NVENC as a CUDA identity. + */} +

+ {usesCUDADevices + ? t("web.admin.nodes.form.cudaDeviceHelp", { + index: "0", + uuid: "GPU-a1b2c3d4", + path: "/dev/dri", + mono, + }) + : t("web.admin.nodes.form.renderDeviceHelp", { + example: "/dev/dri/renderD128,/dev/dri/renderD129", + mono, + })} +

+ + )} + {lockedNote("hw_device_override")} + + )} )} diff --git a/web/src/pages/adminNodesPresentation.test.ts b/web/src/pages/adminNodesPresentation.test.ts index abbd4f43a6..075636a6c9 100644 --- a/web/src/pages/adminNodesPresentation.test.ts +++ b/web/src/pages/adminNodesPresentation.test.ts @@ -20,6 +20,7 @@ import { nodeHasHWDeviceInventory, hwDeviceSyntaxChanges, nodeUsesCUDADevices, + nodeUsesVideoToolbox, restoreEnvManagedFields, } from "./adminNodesPresentation"; @@ -520,6 +521,16 @@ describe("buildNodeHWDeviceRows", () => { }); }); +describe("nodeUsesVideoToolbox", () => { + it("follows a Mac node's own resolution and an explicit pin", () => { + const mac = makeNode({ capabilities: { resolved: "videotoolbox" } }); + expect(nodeUsesVideoToolbox(mac, HW_ACCEL_INHERIT, "auto")).toBe(true); + expect(nodeUsesVideoToolbox(mac, "auto", "qsv")).toBe(true); + expect(nodeUsesVideoToolbox(makeNode({}), "videotoolbox")).toBe(true); + expect(nodeUsesVideoToolbox(mac, HW_ACCEL_INHERIT, "qsv")).toBe(false); + }); +}); + describe("nodeUsesCUDADevices", () => { it("follows what the node resolves to when the cluster names no backend", () => { const node = makeNode({ capabilities: { resolved: "nvenc" } }); diff --git a/web/src/pages/adminNodesPresentation.ts b/web/src/pages/adminNodesPresentation.ts index 36a7ab0339..a6ca34a4af 100644 --- a/web/src/pages/adminNodesPresentation.ts +++ b/web/src/pages/adminNodesPresentation.ts @@ -675,6 +675,7 @@ export const HW_ACCEL_INHERIT = "inherit"; const QSV_LABEL = "Intel Quick Sync (QSV)"; const VAAPI_LABEL = "VA-API"; const NVENC_LABEL = "NVIDIA NVENC"; +const VIDEOTOOLBOX_LABEL = "VideoToolbox"; /** * The acceleration choices a node may be pinned to, inherit first. The backend @@ -689,6 +690,7 @@ export function hwAccelOverrideOptions(): { value: string; label: string }[] { { value: "qsv", label: QSV_LABEL }, { value: "vaapi", label: VAAPI_LABEL }, { value: "nvenc", label: NVENC_LABEL }, + { value: "videotoolbox", label: VIDEOTOOLBOX_LABEL }, { value: "none", label: t("web.admin.nodes.hwAccel.software") }, ]; } @@ -723,20 +725,44 @@ export function nodeUsesCUDADevices( override: string | null | undefined, clusterHWAccel?: string | null, ): boolean { + return nodeBackend(node, override, clusterHWAccel) === "nvenc"; +} + +/** + * The backend this node will run under the editor's selection: an explicit + * backend, the cluster's backend while inheriting one, and otherwise what the + * node resolves to itself (an explicit `auto`, or inheriting an `auto` + * cluster). See nodeUsesCUDADevices for why inheritance follows the cluster. + */ +function nodeBackend( + node: StreamNode | null | undefined, + override: string | null | undefined, + clusterHWAccel?: string | null, +): string { const selected = override?.trim().toLowerCase() ?? ""; - if (selected === "nvenc") { - return true; - } if (selected !== "" && selected !== HW_ACCEL_INHERIT && selected !== "auto") { - return false; + return selected; } if (selected === "" || selected === HW_ACCEL_INHERIT) { const cluster = clusterHWAccel?.trim().toLowerCase() ?? ""; if (cluster !== "" && cluster !== "auto") { - return cluster === "nvenc"; + return cluster; } } - return node?.capabilities?.resolved?.trim().toLowerCase() === "nvenc"; + return node?.capabilities?.resolved?.trim().toLowerCase() ?? ""; +} + +/** + * Whether this node will run VideoToolbox, which takes no device: its FFmpeg + * arguments name none, so the device control has nothing to set. A Mac node on + * the cluster default or Auto resolves VideoToolbox itself. + */ +export function nodeUsesVideoToolbox( + node: StreamNode | null | undefined, + override: string | null | undefined, + clusterHWAccel?: string | null, +): boolean { + return nodeBackend(node, override, clusterHWAccel) === "videotoolbox"; } /**