diff --git a/core/gen/video_driver.cpp b/core/gen/video_driver.cpp index 1a60c5dc..1ec67519 100644 --- a/core/gen/video_driver.cpp +++ b/core/gen/video_driver.cpp @@ -640,9 +640,19 @@ int VideoDriver::shape_job(Job& j, const VideoRequest& r, int32_t chunks, int32_ "this server cannot run"); j.dec_rows = nd; if (d.ref_rows && !j.ref_tab.empty()) { - if (r.upscale > 1.0) - return no("reference conditioning does not yet combine with latent upscale; ask for " - "the size you want without latent_upscale"); + /* References combine with latent upscale: their rows carry the references' OWN grids and + * never depend on the target canvas, so the draft and full phases condition identically -- + * only the pack's video target segment changes size, laid out twice below. Endpoint + * keyframes do not survive two canvases: a pin is the keyframe latent sitting AT the output + * frame's row on the target grid itself, and a draft grid plus a full grid leaves it with + * no single frame to pin -- every repair would alter the run towards the pinned frame. + * A keyframe request never carries references, so a table with any key word is refused by + * name, pointing at the reference route for those who want the upscale anyway. */ + if (r.upscale > 1.0 && j.ref_tab[1] > 0) + return no("a keyframe pins an exact output frame on the exact target grid, and latent " + "upscale denoises a smaller draft grid first -- the pin would sit between " + "two grids and the video could drift off your frame; run the keyframe " + "request without latent_upscale, or send the frame as a reference image"); if (!pack_) return no("the generator says it conditions on references but exports no " "rad_arch_video_pack"); @@ -701,6 +711,56 @@ int VideoDriver::shape_job(Job& j, const VideoRequest& r, int32_t chunks, int32_ j.lat_v = pr - j.seg[(size_t)(nseg - 2)]; j.lat_a = decl_.audio_channels * (int64_t)j.geom.n_audio; j.ref_wide = true; + /* An upscale's draft steps run at the small grid: pack the SAME references again over it. + * The reference and audio segments are grid-independent, so their rows and boundaries are + * identical; the video target shrinks and every boundary at or after it shifts with it. + * The modulation groups count the same (a cell is fixed by segment kind, not size), so + * the `max_ref_segs` check above covers both phases. The small grid's own legality was + * already refused below at the upscale's validation if the factor cannot leave a smaller + * size; an over-tall pack here is refused the same way the full one is. */ + if (r.upscale > 1.0) { + int32_t sw = 0, sh = 0; + video_small_size(d, r.width, r.height, r.upscale, &sw, &sh); + const VideoShape ss = video_shape(d, sw, sh, chunks); + RadVideoGeom gs = j.geom; + gs.lat_h = ss.lat_h; + gs.lat_w = ss.lat_w; + const int64_t ps = pack_(&gs, j.ref_tab.data(), nullptr, 0, nullptr, 0); + if (ps <= 0) + return no("the model refused the reference conditioning layout at the draft " + "size " + std::to_string(sw) + "x" + std::to_string(sh)); + if (ps > max_tok_) + return no("a conditioned draft step is " + std::to_string(ps) + " rows and a pass " + "carries " + std::to_string(max_tok_) + "; ask for a shorter or smaller " + "video, or fewer references"); + std::vector segs((size_t)kSegCap, 0); + j.pos_small.assign((size_t)(3 * ps), 0.0f); + if (pack_(&gs, j.ref_tab.data(), segs.data(), kSegCap, j.pos_small.data(), 3 * ps) != ps) + return no("the model could not lay the reference conditioning out at the draft size"); + int nseg_s = -1; + for (int k = 0; k < kSegCap; ++k) + if (segs[(size_t)k] == (int32_t)ps) { nseg_s = k + 1; break; } + if (nseg_s < 1) + return no("the draft-size reference conditioning layout has no closing segment " + "boundary"); + j.seg_s.assign(segs.begin(), segs.begin() + nseg_s); + j.nseg_s = nseg_s; + if (mod_segs_) { + j.mod_seg_s.assign((size_t)kSegCap, 0); + const int n = (int)mod_segs_(&gs, j.ref_tab.data(), j.mod_seg_s.data(), kSegCap); + if (n < 1 || n > kSegCap) + return no("the model could not merge the draft-size reference conditioning " + "into its modulation groups"); + j.mod_seg_s.resize((size_t)n); + j.nmod_s = n; + } else { + j.nmod_s = nseg_s; /* nothing merges: the groups are the fine segments */ + j.mod_seg_s = j.seg_s; + } + j.step_rows_s = ps; + j.lat_v_s = ps - j.seg_s[(size_t)(nseg_s - 2)]; + j.ref_wide_small = true; + } } else { j.rows = j.geom.n_text + s.audio_rows + s.video_rows; if (j.rows > max_tok_) @@ -765,14 +825,19 @@ int VideoDriver::shape_job(Job& j, const VideoRequest& r, int32_t chunks, int32_ j.geom_small.lat_h = ss.lat_h; j.geom_small.lat_w = ss.lat_w; j.rows_small = j.geom.n_text + ss.audio_rows + ss.video_rows; - const int64_t ns = positions_(RAD_VPOS_STEP, &j.geom_small, nullptr, 0); - if (ns != j.rows_small) - return no("the model lays the small size " + std::to_string(sw) + "x" + - std::to_string(sh) + " out in " + std::to_string(ns) + " step rows, which " - "this server cannot run"); - j.pos_small.assign((size_t)(3 * ns), 0.0f); - if (positions_(RAD_VPOS_STEP, &j.geom_small, j.pos_small.data(), ns) != ns) - return no("the model could not lay the small size out"); + /* A reference-conditioned job already laid the draft steps out -- twice -- at the pack + * above (seg_s/mod_seg_s/step_rows_s, positions in pos_small); the plain small layout + * below is only what a step WITHOUT references stages. */ + if (!j.ref_wide) { + const int64_t ns = positions_(RAD_VPOS_STEP, &j.geom_small, nullptr, 0); + if (ns != j.rows_small) + return no("the model lays the small size " + std::to_string(sw) + "x" + + std::to_string(sh) + " out in " + std::to_string(ns) + " step rows, which " + "this server cannot run"); + j.pos_small.assign((size_t)(3 * ns), 0.0f); + if (positions_(RAD_VPOS_STEP, &j.geom_small, j.pos_small.data(), ns) != ns) + return no("the model could not lay the small size out"); + } j.split = evals - refine; j.factor = (float)(((double)r.width / sw + (double)r.height / sh) / 2.0); r.ticket->small_width = sw; @@ -1041,12 +1106,16 @@ void VideoDriver::stage_geom(const Job& j, const RadVideoGeom& g0, int64_t rows, g[RAD_VGEOM_FIRST_CU + 2] = ppf * g0.lat_frames; reg_[R_GEOM].used = RAD_VGEOM_N * 4; const bool wide = j.ref_wide && ref_step; + /* On a widened step, which phase's pack is staged: the draft phase (an upscale that has not + * run yet) laid the references over the small grid; every later wide step uses the full one. */ + const bool wsmall = wide && small_now(j); const int64_t audio_rows = (decl_.audio_streams > 0 ? decl_.audio_streams : decl_.audio_channels) * (int64_t)g0.n_audio; /* With references riding, the sampler owns only the target video rows -- not the reference * rows the pack placed ahead of them -- so the target count is the pack's, not the plain * rows-minus-text-minus-audio. The audio target is the whole soundtrack either way. */ - const int64_t video_rows = wide ? j.lat_v : rows - g0.n_text - audio_rows; + const int64_t video_rows = + wide ? (wsmall ? j.lat_v_s : j.lat_v) : rows - g0.n_text - audio_rows; *hptr(R_LANE) = j.lane; *hptr(R_FIRST) = j.step == 0; int32_t* seg = hptr(R_SEG); @@ -1054,9 +1123,12 @@ void VideoDriver::stage_geom(const Job& j, const RadVideoGeom& g0, int64_t rows, /* The pack laid the reference rows out ahead of the target streams, video grid last. Stage * its boundaries verbatim: the VSA derives its segment count from the operand length, so * every reference becomes a dense prefix sink with no kernel change. Only the step pass - * stages this table; the decode, encode and upscale passes stage the plain layout below. */ - std::memcpy(seg, j.seg.data(), j.seg.size() * sizeof(int32_t)); - reg_[R_SEG].used = (int64_t)j.seg.size() * 4; + * stages this table; the decode, encode and upscale passes stage the plain layout below. + * An upscaling job switches tables at the upscale: the draft phase's steps read the + * small-grid pack, the refine steps the full-grid one. */ + const std::vector& tab = wsmall ? j.seg_s : j.seg; + std::memcpy(seg, tab.data(), tab.size() * sizeof(int32_t)); + reg_[R_SEG].used = (int64_t)tab.size() * 4; } else { /* The pack lays the segments out (rad_arch_video_segs, or the reference-aware * rad_arch_video_pack once refs ride); for a plain request its table is the one computed @@ -1087,9 +1159,10 @@ void VideoDriver::stage_geom(const Job& j, const RadVideoGeom& g0, int64_t rows, * is the fine table verbatim -- nothing merges there, so the norm reads the same bytes as the * attention and the generated output is exactly what it was before this operand split. */ int32_t* mod = hptr(R_MOD); - if (wide && j.nmod > 0) { - std::memcpy(mod, j.mod_seg.data(), j.mod_seg.size() * sizeof(int32_t)); - reg_[R_MOD].used = (int64_t)j.mod_seg.size() * 4; + if (wide && (wsmall ? j.nmod_s : j.nmod) > 0) { + const std::vector& tab = wsmall ? j.mod_seg_s : j.mod_seg; + std::memcpy(mod, tab.data(), tab.size() * sizeof(int32_t)); + reg_[R_MOD].used = (int64_t)tab.size() * 4; } else { std::memcpy(mod, seg, reg_[R_SEG].used); reg_[R_MOD].used = reg_[R_SEG].used; @@ -1413,7 +1486,11 @@ const RadBatch* VideoDriver::build_step(Job& j, int step) { for (int g = 0; g < R_N; ++g) reg_[g].used = 0; const bool small = small_now(j); const RadVideoGeom& g = small ? j.geom_small : j.geom; - const int64_t rows = small ? j.rows_small : j.step_rows; /* widened by references when they ride */ + /* Each phase runs at ITS pack when references ride: the draft at the small-grid pack, the + * refine at the full one; plain requests at the plain rows. `pos_small` is the pack's + * positions on a reference-conditioned job and the plain layout's otherwise -- either way + * it is the draft phase's. */ + const int64_t rows = small ? (j.ref_wide_small ? j.step_rows_s : j.rows_small) : j.step_rows; const std::vector& pos = small ? j.pos_small : j.pos; stage_sched(j, j.step, small && j.step == j.split - 1); std::memcpy(hptr(R_ROPE), pos.data(), pos.size() * 4); @@ -1424,9 +1501,9 @@ const RadBatch* VideoDriver::build_step(Job& j, int step) { cu[0] = 0; cu[1] = (int32_t)rows; reg_[R_CU].used = 2 * 4; - /* A reference-conditioned step stages the pack's reference-aware segment table; the plain and - * small (pre-upscale) steps stage the plain four-boundary table. ref_wide never coincides with - * small -- submit refuses upscale together with references. */ + /* A reference-conditioned step stages the pack's reference-aware segment table -- the draft + * phase's own small-grid one while the draft runs, the full grid's after the upscale; plain + * steps stage the plain four-boundary table. */ stage_geom(j, g, rows, 0, j.ref_wide); if (upload() < 0) return nullptr; base_batches(j, g, rows, step); diff --git a/core/gen/video_driver.h b/core/gen/video_driver.h index c4db677c..91ad913e 100644 --- a/core/gen/video_driver.h +++ b/core/gen/video_driver.h @@ -108,6 +108,18 @@ private: std::vector mod_seg; int32_t nmod = 0; int64_t lat_v = 0, lat_a = 0; + /* A step that is BOTH reference-conditioned and in an upscale's small (draft) phase needs + * the pack laid out AGAIN at the small grid: the video target shrinks, so every boundary + * after it shifts. These mirror the fields above for that one phase -- `seg_s`/`mod_seg_s` + * its boundary tables, `nseg_s`/`nmod_s` their counts, `step_rows_s` its row total, and + * `lat_v_s` the small video target's rows (the audio target is the grid-independent + * soundtrack, so it needs no small twin). `pos_small` carries the pack's positions here, + * where on the plain path it carries the plain layout's. `ref_wide_small` is false for + * every plain job and for every wide step of a job that does not upscale. */ + bool ref_wide_small = false; + int32_t nseg_s = 0, nmod_s = 0; + std::vector seg_s, mod_seg_s; + int64_t step_rows_s = 0, lat_v_s = 0; /* The denoising step's row count: the widened total once references ride, otherwise equal * to `rows`. Only build_step uses it -- the encode, decode, audio and upscale passes keep * staging against the plain `rows` (their segment table and target counts are their own, diff --git a/docs/GUIDE.md b/docs/GUIDE.md index f6454e64..b5573569 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -2998,7 +2998,11 @@ upscaler, re-noised, and the last **`upscale_refine_steps`** run at the full siz and 12 of the base model's 49 by default). The steps at the small size cost a fraction of a full-size step's, so most of the time goes to the refinement. The video object of an upscaled video carries `latent_upscale`, the `upscale_refine_steps` it ran and `upscale_from`, the small -size. +size. REF2VA takes it too — a reference row carries the *reference's own* latent grid, so the +draft and the refine stage condition identically and the pack is simply laid out again at the +draft size. The keyframe tasks refuse it (`i2va`/`l2va`/`fl2va`): a pin sits AT the output frame's +own row on the exact target grid, and a smaller draft canvas leaves the pin between two grids — +run those without `latent_upscale`, or send the frame as a reference image. ```sh curl -s http://localhost:8000/v1/videos -H 'Content-Type: application/json' -d '{ diff --git a/docs/NOTE-REF2VA.md b/docs/NOTE-REF2VA.md index 08dcba59..404383c8 100644 --- a/docs/NOTE-REF2VA.md +++ b/docs/NOTE-REF2VA.md @@ -334,10 +334,18 @@ as point 6 / point 4. Nothing here claims to match ComfyUI's timings. budget (point 2) and the interleaving mod-group ceiling (point 1) remain the true binding limits at high resolution, and now bind for real, since videos reopen the video-conditioned cell. -5. **References and latent upscaling are mutually exclusive.** Combining the widened reference - layout with the small-size-then-upscale denoise is not unified; a request asking for both is - refused at submit (*"reference conditioning does not yet combine with latent upscale"*). Ask for - the target size directly. +5. **References combine with latent upscaling; keyframes do not.** The pack is laid out **twice** + for an upscaled reference job — once over the draft geometry and once over the full one — because + the video target segment changes size between the stages and every boundary at or after it moves + with it (the reference and audio segments are grid-independent, so their rows are identical in + both). The driver stages the draft phase's table while `small_now` holds and the full one after + the upscale pass; the plugin needs no change — it re-derives the pack from the staged + `RadVideoGenBatch::geom`, which already switches per phase. Endpoint keyframes stay refused with + `latent_upscale` *on semantics*: a pin is the keyframe latent at the output frame's own row on + the exact target grid, two canvases leave it with no single row to sit on, and every repair + (re-encode per stage, pin one stage only) alters the trajectory toward the pinned endpoint with + no reference workflow to verify against. The refusal names the knob and points at the reference + route. 6. **Numeric parity with the reference denoiser for the *conditioned* step is not yet published.** A per-tensor / perceptual match to ComfyUI's outputs for the wide step remains an open parity task diff --git a/integrations/comfyui/ComfyUI-Radiance-MiniMax/README.md b/integrations/comfyui/ComfyUI-Radiance-MiniMax/README.md index ee31f577..32a37b24 100644 --- a/integrations/comfyui/ComfyUI-Radiance-MiniMax/README.md +++ b/integrations/comfyui/ComfyUI-Radiance-MiniMax/README.md @@ -94,9 +94,12 @@ path on the **server's** filesystem (loopback-only unless `--api-key` is set). the latent-upscaler weights (the DaSiWa companion folder; `minimax-h3-dasiwa-*.rad` has them — the server log names the upscaler at boot) diffuses the early steps at size/2 (or /4), enlarges the clean latent, then refines at full - size in the last steps. **`t2va` only** — the server refuses latent upscale - combined with references *or keyframes* — and the output still stays within - the canvas, so it buys speed and detail, not 1080p. + size in the last steps. Works with **`t2va` and `ref2va`** — reference rows + carry their own grids, so they condition the draft and the refine stage + identically — and is **refused with `i2va`/`l2va`/`fl2va` keyframes**: a pin + sits AT the exact output frame on the exact target grid, and a draft canvas + leaves it nowhere to sit (send the frame as a reference image instead). The + output still stays within the canvas, so it buys speed and detail, not 1080p. ### Media sockets — purely wire-driven, task-sensitive diff --git a/integrations/comfyui/ComfyUI-Radiance-MiniMax/radiance_node.py b/integrations/comfyui/ComfyUI-Radiance-MiniMax/radiance_node.py index c80f9637..e0fa2aef 100644 --- a/integrations/comfyui/ComfyUI-Radiance-MiniMax/radiance_node.py +++ b/integrations/comfyui/ComfyUI-Radiance-MiniMax/radiance_node.py @@ -130,9 +130,12 @@ digits but past 2^53 the engine rounds the seed and past bigger values are clamped here rather than silently changing the run. latent_upscale (advanced): the container's built-in latent -upscaler -- early steps at size/2, refine at full size. t2va -ONLY (the server refuses it with refs or keyframes); the -output still stays within the canvas, so it buys speed and +upscaler -- early steps at size/2, refine at full size. +Works with t2va and ref2va (references carry their own +grids); REFUSED with i2va/l2va/fl2va keyframes -- a pin +sits at the exact output frame on the exact target grid +and a draft canvas leaves it nowhere to sit. The output +still stays within the canvas, so it buys speed and detail, not 1080p. off by default. server_url: http://:8133. LAN needs the server on --host 0.0.0.0; NO auth -- trusted LAN only. @@ -414,9 +417,11 @@ class RadianceMiniMax(io.ComfyNode): "- **latent_upscale** — advanced, **off** by default: a container converted with " "the latent-upscaler weights (DaSiWa's companion — the server log names it at " "boot) runs the early steps at size/2 or /4, enlarges the clean latent, and " - "refines at full size in the last steps. **t2va only** — the server refuses it " - "combined with references or keyframes — and the output stays within the canvas, " - "so it buys speed/detail, not 1080p.\n" + "refines at full size in the last steps. Works with **t2va and ref2va** — " + "references carry their own grids, so they condition both stages identically — " + "and is **refused with i2va/l2va/fl2va keyframes**: a pin sits AT the exact " + "output frame on the exact target grid, and a draft canvas leaves it nowhere to " + "sit. The output stays within the canvas, so it buys speed/detail, not 1080p.\n" "- **server_url / model** — which box (`http://:8133`; LAN needs the " "server on `--host 0.0.0.0`, no auth — trusted LAN only) and which served " "model id (`GET /v1/models`).\n\n" @@ -521,8 +526,9 @@ class RadianceMiniMax(io.ComfyNode): "the container's built-in latent upscaler (the DaSiWa companion weights, " "baked into the .rad at convert time -- the server log names it at boot): " "the early steps run at size/2 (or /4), the clean latent is enlarged, " - "re-noised, and the last steps refine at the FULL size. t2va only -- the " - "server refuses it with references or keyframes. The OUTPUT stays within " + "re-noised, and the last steps refine at the FULL size. Works with t2va and " + "ref2va (references carry their own grids); refused with i2va/l2va/fl2va " + "keyframes (a pin needs the exact target grid). The OUTPUT stays within " "the canvas (the refine steps run full size): this buys speed and detail, " "not 1080p -- sizes stay multiples of 32 and under 1344x768 either way"), *images, *videos, *vauds, *adus, @@ -640,13 +646,16 @@ class RadianceMiniMax(io.ComfyNode): "shift": str(shift), "audio_shift": str(audio_shift), } if str(latent_upscale) not in ("off", "", "1"): - # the driver refuses upscale together with ANY packed conditioning -- references - # AND endpoint keyframes ride the same table (video_driver.cpp, "does not yet - # combine") -- so say it here instead of eating a round trip - if task != "t2va": - raise ValueError(f"latent_upscale {latent_upscale} with task {task}: the server " - "refuses latent upscale combined with references or keyframes " - "(text-to-video only for now)") + # the draft/refine split re-lays the reference pack per stage -- refs carry their own + # grids, so ref2va rides an upscale fine. A KEYFRAME pin sits AT the output frame's row + # on the exact target grid, and two canvases leave it nowhere to sit -- the driver + # refuses those by name (video_driver.cpp), so say it here instead of eating a round trip + if task in ("i2va", "l2va", "fl2va"): + raise ValueError(f"latent_upscale {latent_upscale} with task {task}: a keyframe " + "pins an exact output frame on the exact target grid, and latent " + "upscale drafts at a smaller grid first -- run the keyframe " + "request without latent_upscale, or send the frame as a " + "reference image (ref2va supports the upscale)") data["latent_upscale"] = str(latent_upscale) # The two dropdown slots become the server's adapter list IN ORDER; # 'none' is off and either slot may stand alone. A slot holding diff --git a/tests/video_gen_test.cpp b/tests/video_gen_test.cpp index 492d088a..04bcf341 100644 --- a/tests/video_gen_test.cpp +++ b/tests/video_gen_test.cpp @@ -1467,6 +1467,127 @@ TEST(a_keyframe_completion_needs_no_vision_tower) { CHECK_OK(f.drv.submit(std::move(r), &why)); /* the pin-only path admits without a tower */ } +/* References ride an upscale: their rows carry the references' OWN grids, so the conditioning + * survives the two canvases -- but the pack must be laid out PER PHASE, because the video target + * shrinks in the draft and every boundary at or after it moves with it. The draft steps therefore + * run on the small-grid pack (reference block identical, video target the small one, positions the + * pack's own), the upscale pass and every non-step pass keep their ref-less layout, and the refine + * step returns to the full-grid pack. */ +TEST(references_reride_the_draft_phase_of_an_upscaled_request) { + VideoFixture f; + f.build(); + f.prog.video_gen.upscale_max = 4.0; + f.prog.video_gen.upscale_refine = 1; + with_tower(f, 16); + RadVideoGenDecl& d = f.prog.video_gen; + d.encodes = 1; + d.enc_ratio = 16; + d.max_enc_frames = 1; + d.max_enc_side = 16; + d.ref_rows = 1; + CHECK_OK(f.start_with_pack_encode(fake_pack_ref, fake_encode_geom)); + std::string why; + auto r = f.req(1, 4); + r->tokens = { 1, 700, 701, 2, 3 }; /* 5 text tokens */ + r->width = 64; + r->height = 64; + r->upscale = 2.0; + gen::VideoRefMedia m = ref_part(gen::VideoRefMedia::IMAGE, "ref_image_1", 1); + m.enc_frames = 1; + m.enc_h = 16; + m.enc_w = 16; + m.enc_pixels.assign(16 * 16 * 3, 1.0f); + r->refs.push_back(m); + r->media = picture_media(6, 1); + CHECK_OK(f.drv.submit(std::move(r), &why)); + + /* Draft: 5 text + 4 reference + 60 audio + 2 small-video = 71 rows, boundaries + * [0|5|9|69|71]. Refine: the video target grows to 8 -- 77 rows, [0|5|9|73|77]. */ + const int64_t n_text = 5, rper = 4, audio = 60, v_small = 2, v_full = 8; + const int64_t draft_rows = n_text + rper + audio + v_small; + const int64_t full_rows = n_text + rper + audio + v_full; + + std::string kinds; + int steps_seen = 0, enc_seen = 0; + bool saw_upscale = false; + for (int i = 0; i < 20; ++i) { + const RadBatch* b = f.drv.next(i); + if (!b) break; + const RadVideoGenBatch* V = b->vgen_b; + REQUIRE(V != nullptr); + if (b->gen == RAD_GEN_PASS_VENCODE) { ++enc_seen; kinds += "E"; } + else kinds += kind_of(b->gen); + if (b->gen == RAD_GEN_PASS_VSTEP) { + const bool small = steps_seen < 2; + const int64_t rows = small ? draft_rows : full_rows, v = small ? v_small : v_full; + CHECK(V->ref_tab != nullptr); + CHECK_EQ(b->n_tok, rows); /* the phase's own pack width */ + CHECK_EQ(V->geom.lat_h, small ? 2 : 4); /* the draft grid, then the full one */ + CHECK_EQ(V->geom_d[RAD_VGEOM_LAT_H], small ? 2 : 4); + CHECK_EQ(V->seg_cu[0], 0); + CHECK_EQ(V->seg_cu[1], (int32_t)n_text); /* the reference block is grid-independent */ + CHECK_EQ(V->seg_cu[2], (int32_t)(n_text + rper)); + CHECK_EQ(V->seg_cu[3], (int32_t)(n_text + rper + audio)); + CHECK_EQ(V->seg_cu[4], (int32_t)rows); /* every boundary from the video on shifts */ + CHECK_EQ(V->mod_cu[4], V->seg_cu[4]); /* no mod_segs export: groups == segments */ + CHECK_EQ(V->lat_cu[1], (int32_t)v); /* the sampler owns the phase's target */ + CHECK_EQ(V->lat_cu[3], (int32_t)audio); + /* The positions are the PHASE's pack's: channel c's row i is 1000c + i, so its last + * written word is 2000 + rows - 1 -- beyond the plain draft layout's 3*rows_small. */ + CHECK_EQ(V->pos[rows - 1], (float)(rows - 1)); + CHECK_EQ(V->pos[3 * rows - 1], (float)(2000 + rows - 1)); + ++steps_seen; + } else if (b->gen == RAD_GEN_PASS_VUPSCALE) { + saw_upscale = true; + CHECK_EQ(V->geom.lat_h, 4); + CHECK_EQ(V->geom_from.lat_h, 2); + CHECK_EQ(V->upscale[0], 2.0f); + CHECK_EQ(V->seg_cu[3], (int32_t)(n_text + audio + v_full)); /* the ref-less layout */ + } else if (b->gen == RAD_GEN_PASS_VCOND) { + CHECK_EQ(V->seg_cu[3], (int32_t)(n_text + audio + v_small)); /* ref-less, draft size */ + } + f.answer(10 * i); + CHECK_OK(f.drv.done()); + } + CHECK_EQ(steps_seen, 3); + CHECK(saw_upscale); + CHECK_EQ(enc_seen, 1); + CHECK_EQ(kinds, std::string("ECSSUSAD")); +} + +/* Keyframes and latent upscale stay refused -- on semantics, not plumbing. A pin is the keyframe's + * latent AT the output frame's own row on the exact target grid; a draft grid and a full grid in one + * job leave it with no single row to sit on, and every repair would move the video away from the + * frame the caller asked for. The refusal names the knob and points at the reference route. */ +TEST(keyframes_and_latent_upscale_are_refused_by_name) { + VideoFixture f; + f.build(); + f.prog.video_gen.upscale_max = 4.0; + f.prog.video_gen.upscale_refine = 1; + RadVideoGenDecl& d = f.prog.video_gen; + d.encodes = 1; + d.enc_ratio = 16; + d.max_enc_frames = 1; + d.max_enc_side = 16; + d.ref_rows = 1; + CHECK_OK(f.start_with_pack_encode(fake_pack_ref, fake_encode_geom)); + std::string why; + auto r = f.req(1, 4); + r->tokens = { 1, 2, 3 }; + r->width = 64; + r->height = 64; + r->upscale = 2.0; + gen::VideoRefMedia first = ref_part(gen::VideoRefMedia::FIRST_FRAME, "first_frame", 1); + first.enc_frames = 1; + first.enc_h = 16; + first.enc_w = 16; + first.enc_pixels.assign(16 * 16 * 3, 1.0f); + r->refs.push_back(first); + CHECK_EQ(f.drv.submit(std::move(r), &why), (int)RAD_E_INVAL); + CHECK(has(why, "keyframe")); + CHECK(has(why, "latent_upscale")); +} + /* What the container cannot consume is refused at submit, naming the part or the budget it breaks — * never silently dropped into a weaker video. A reference video, soundtrack or audio needs the VAE * encoders; on a container converted without them (encodes 0) they are refused by name here, and on