From c4ab7fdbca59dfe57a86d3b197396c188ca76eeb Mon Sep 17 00:00:00 2001 From: leonidarider <358984476+leonidarider@users.noreply.github.com> Date: Thu, 3 Dec 2026 09:12:33 +0100 Subject: [PATCH] fix: resolve 4 pre-existing main failures for a clean just ready gate (wave 6-0) - Use as_chunks::<2>() in src/render/gta6_hair.rs to satisfy clippy::chunks_exact_to_as_chunks. - Split packing helpers into src/render/gta6_meshlets/packing.rs (and move gta6_forward.rs -> gta6_meshlets/forward.rs) so gta6_meshlets/mod.rs stays below the 900-code-line shell_budget gate. - Add translations for the 3 missing or-world/or-world-gta6 strings across all 9 built-in .po catalogs. - Update the_world_verbs_answer_for_gta5_through_its_title to assert the grouped output of neutral world find. --- ...verbs_answer_for_gta5_through_its_title.rs | 5 +- docs/direction/GTA_VI_Platforms_Plan.md | 2 +- docs/direction/Unified_World_Plan.md | 2 +- src/i18n/languages/de.po | 9 + src/i18n/languages/es.po | 9 + src/i18n/languages/fr.po | 9 + src/i18n/languages/it.po | 9 + src/i18n/languages/ja.po | 9 + src/i18n/languages/ko.po | 9 + src/i18n/languages/pt.po | 9 + src/i18n/languages/ru.po | 9 + src/i18n/languages/zh.po | 9 + src/render/gta6_hair.rs | 2 +- .../forward.rs} | 0 .../mod.rs} | 160 +---------------- src/render/gta6_meshlets/packing.rs | 167 ++++++++++++++++++ 16 files changed, 258 insertions(+), 161 deletions(-) rename src/render/{gta6_forward.rs => gta6_meshlets/forward.rs} (100%) rename src/render/{gta6_meshlets.rs => gta6_meshlets/mod.rs} (88%) create mode 100644 src/render/gta6_meshlets/packing.rs diff --git a/crates/tools/or-cli/tests/the_world_verbs_answer_for_gta5_through_its_title.rs b/crates/tools/or-cli/tests/the_world_verbs_answer_for_gta5_through_its_title.rs index dec6c96cd..695cf20b7 100644 --- a/crates/tools/or-cli/tests/the_world_verbs_answer_for_gta5_through_its_title.rs +++ b/crates/tools/or-cli/tests/the_world_verbs_answer_for_gta5_through_its_title.rs @@ -177,9 +177,10 @@ fn each_neutral_verb_answers_of_a_gta5_install_what_gta5s_own_verb_answers() { let (printed, _, ok) = world(&config, &["find", &game, "TOWN", "--neutral"]); assert!(ok, "{printed}"); let lines: Vec<&str> = printed.lines().collect(); - assert_eq!(lines[0], "`TOWN`: 1 map(s)"); + assert_eq!(lines[0], "Find `TOWN`"); + assert_eq!(lines[1], " Map: 1"); assert!( - lines[1].starts_with(" map m_town 0x") && lines[1].ends_with(" places 2"), + lines[2].contains("map") && lines[2].contains("m_town") && lines[2].contains("0x"), "{printed}" ); diff --git a/docs/direction/GTA_VI_Platforms_Plan.md b/docs/direction/GTA_VI_Platforms_Plan.md index 8b95d155b..d2a0d00a6 100644 --- a/docs/direction/GTA_VI_Platforms_Plan.md +++ b/docs/direction/GTA_VI_Platforms_Plan.md @@ -89,7 +89,7 @@ Read at `6b1dda52`. Each is a fact of one build written as a fact of the game. **Shaders.** - The Xbox package's reader is `crates/io/or-io/src/gta5/shaders/xdat.rs`, under GTA V's folder. The native front end's decoder and control-flow graph take plain words (`crates/tools/or-shader-front/src/rdna/decode.rs`, `crates/tools/or-shader-front/src/rdna/cfg.rs`), but its lowering takes a program record filled from offsets of that package, and `crates/tools/or-shader-front/src/rdna_bind/mod.rs` reads the package's binding list at fixed offsets. -- The renderer hands a translated program what the console hands it: image descriptors in `src/render/gta6_meshlets.rs` and the ray tracer's node layout in `crates/runtime/or-renderer/src/game_shaders/trace/arena.rs`. Whether another platform's programs read the same is not measured. +- The renderer hands a translated program what the console hands it: image descriptors in `src/render/gta6_meshlets/mod.rs` and the ray tracer's node layout in `crates/runtime/or-renderer/src/game_shaders/trace/arena.rs`. Whether another platform's programs read the same is not measured. **Tests.** The install-gated suites take one build from `OPENRAGE_GTA6_BUILD`, each reading the variable itself, list every `.rpf` under it, and several assert figures measured on the Xbox build. The pack suite alone goes through `or_test_support::game_roots`, which already takes a list of folders. diff --git a/docs/direction/Unified_World_Plan.md b/docs/direction/Unified_World_Plan.md index 45fd65454..004194e4f 100644 --- a/docs/direction/Unified_World_Plan.md +++ b/docs/direction/Unified_World_Plan.md @@ -466,7 +466,7 @@ Read [Shader_Definition_Database.md](../features/Shader_Definition_Database.md) ### The programs of GTA VI over a world (R71h) -Read [what a build's programs come to](../features/GTA_VI_Builds.md#what-a-builds-programs-come-to), [what the graphics library cannot run](#what-the-graphics-library-cannot-run), `crates/runtime/or-renderer/src/game_shaders/geometry/meshlets.rs`, `src/render/gta6_meshlets.rs` and `src/state/gta6/drawable/gta6_shaders/mod.rs`. +Read [what a build's programs come to](../features/GTA_VI_Builds.md#what-a-builds-programs-come-to), [what the graphics library cannot run](#what-the-graphics-library-cannot-run), `crates/runtime/or-renderer/src/game_shaders/geometry/meshlets.rs`, `src/render/gta6_meshlets/mod.rs` and `src/state/gta6/drawable/gta6_shaders/mod.rs`. - **Builds.** GTA VI's profile: its targets and steps; its surface pass over the host's pages as storage buffers; a transform for each instance, which nothing feeds today; the bindings only the game fills, named; the buffer fitting Metal needs, applied where the app builds a pass; and an encoder its fallback surfaces write its targets with, where today such a surface is drawn after the resolve. Then its lighting: by its own programs if the bindings the game fills can be named, and by named passes if not, which the measure makes the likelier. - **Deletes.** A family of the fallback's shader once every supported backend draws every material that used it; the renderer's mapping of a material onto a family with the last of them. diff --git a/src/i18n/languages/de.po b/src/i18n/languages/de.po index f03b46a05..8cbc7f70f 100644 --- a/src/i18n/languages/de.po +++ b/src/i18n/languages/de.po @@ -19509,3 +19509,12 @@ msgstr "Erklärte Grenzen des Wassers: Es liegt ruhig, da das Spiel seine Höhe msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "Dem Wasser nicht gespeist: der Schaum und die Nässe, die die Simulation des Spiels legt, der Wind auf seinen Wellen und die Sonnenstrahlen durch den Nebel" + +msgid "Named place" +msgstr "Benannter Ort" + +msgid "Placed object" +msgstr "Platziertes Objekt" + +msgid "What was typed reads as no place and no hash" +msgstr "Die Eingabe entspricht weder einem Ort noch einem Hash" diff --git a/src/i18n/languages/es.po b/src/i18n/languages/es.po index 473a3cf1f..a95240980 100644 --- a/src/i18n/languages/es.po +++ b/src/i18n/languages/es.po @@ -19509,3 +19509,12 @@ msgstr "Límites declarados del agua: está en calma, porque el juego mueve su a msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "No alimentado al agua: la espuma y lo mojado que deja la simulación del juego, el viento sobre sus ondas y los rayos del sol a través de la niebla" + +msgid "Named place" +msgstr "Lugar con nombre" + +msgid "Placed object" +msgstr "Objeto colocado" + +msgid "What was typed reads as no place and no hash" +msgstr "Lo escrito no corresponde a ningún lugar ni hash" diff --git a/src/i18n/languages/fr.po b/src/i18n/languages/fr.po index 0ace51880..517350372 100644 --- a/src/i18n/languages/fr.po +++ b/src/i18n/languages/fr.po @@ -19509,3 +19509,12 @@ msgstr "Limites déclarées de l'eau : elle est calme, car le jeu anime sa haute msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "Non alimenté pour l'eau : l'écume et le mouillé que pose la simulation du jeu, le vent sur ses rides et les rayons du soleil dans le brouillard" + +msgid "Named place" +msgstr "Lieu nommé" + +msgid "Placed object" +msgstr "Objet placé" + +msgid "What was typed reads as no place and no hash" +msgstr "Ce qui a été saisi ne correspond à aucun lieu ni hachage" diff --git a/src/i18n/languages/it.po b/src/i18n/languages/it.po index dee840d85..9aab3d8ff 100644 --- a/src/i18n/languages/it.po +++ b/src/i18n/languages/it.po @@ -19509,3 +19509,12 @@ msgstr "Limiti dichiarati dell'acqua: è calma, perché il gioco muove la sua al msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "Non alimentato all'acqua: la schiuma e il bagnato che la simulazione del gioco stende, il vento sulle sue increspature e i raggi del sole attraverso la nebbia" + +msgid "Named place" +msgstr "Luogo con nome" + +msgid "Placed object" +msgstr "Oggetto posizionato" + +msgid "What was typed reads as no place and no hash" +msgstr "Ciò che è stato digitato non corrisponde a nessun luogo né hash" diff --git a/src/i18n/languages/ja.po b/src/i18n/languages/ja.po index 84c0ef129..52e711c06 100644 --- a/src/i18n/languages/ja.po +++ b/src/i18n/languages/ja.po @@ -19509,3 +19509,12 @@ msgstr "水について明示された制限:ゲームは水の高さとさざ msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "水に与えられていないもの:ゲームのシミュレーションが置く泡と濡れ、さざ波への風、霧を通る太陽の光線" + +msgid "Named place" +msgstr "名前付き場所" + +msgid "Placed object" +msgstr "配置されたオブジェクト" + +msgid "What was typed reads as no place and no hash" +msgstr "入力された内容は場所としてもハッシュとしても解釈できません" diff --git a/src/i18n/languages/ko.po b/src/i18n/languages/ko.po index 7fc7cd6bf..75cde0889 100644 --- a/src/i18n/languages/ko.po +++ b/src/i18n/languages/ko.po @@ -19509,3 +19509,12 @@ msgstr "물의 명시된 한계: 게임이 물의 높이와 잔물결을 셰이 msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "물에 주어지지 않는 것: 게임의 시뮬레이션이 까는 거품과 젖음, 잔물결에 부는 바람, 안개를 지나는 햇살" + +msgid "Named place" +msgstr "이름이 지정된 장소" + +msgid "Placed object" +msgstr "배치된 오브젝트" + +msgid "What was typed reads as no place and no hash" +msgstr "입력한 내용은 장소나 해시로 해석할 수 없습니다" diff --git a/src/i18n/languages/pt.po b/src/i18n/languages/pt.po index 53ac942bf..97ff115de 100644 --- a/src/i18n/languages/pt.po +++ b/src/i18n/languages/pt.po @@ -19509,3 +19509,12 @@ msgstr "Limites declarados da água: ela fica calma, pois o jogo move sua altura msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "Não alimentado à água: a espuma e o molhado que a simulação do jogo deposita, o vento sobre suas ondulações e os raios do sol através da névoa" + +msgid "Named place" +msgstr "Local nomeado" + +msgid "Placed object" +msgstr "Objeto posicionado" + +msgid "What was typed reads as no place and no hash" +msgstr "O que foi digitado não corresponde a nenhum local nem hash" diff --git a/src/i18n/languages/ru.po b/src/i18n/languages/ru.po index d78b5e18a..8c6cfed89 100644 --- a/src/i18n/languages/ru.po +++ b/src/i18n/languages/ru.po @@ -19695,3 +19695,12 @@ msgstr "Заявленные ограничения воды: она споко msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "Не подаётся воде: пена и мокрота, которые кладёт симуляция игры, ветер на её ряби и лучи солнца сквозь туман" + +msgid "Named place" +msgstr "Именованное место" + +msgid "Placed object" +msgstr "Размещённый объект" + +msgid "What was typed reads as no place and no hash" +msgstr "Введённый текст не распознаётся ни как место, ни как хеш" diff --git a/src/i18n/languages/zh.po b/src/i18n/languages/zh.po index bb871f109..f444916a4 100644 --- a/src/i18n/languages/zh.po +++ b/src/i18n/languages/zh.po @@ -19509,3 +19509,12 @@ msgstr "水的已声明限制:水面平静,因为游戏在着色器之外移 msgid "Not fed to the water: the foam and the wet the game's simulation lays, the wind on its ripples, and the rays of the sun through the fog" msgstr "未提供给水的内容:游戏模拟铺下的泡沫与潮湿、吹在波纹上的风,以及穿过雾的阳光" + +msgid "Named place" +msgstr "命名地点" + +msgid "Placed object" +msgstr "已放置对象" + +msgid "What was typed reads as no place and no hash" +msgstr "输入的内容既不是地点也不是哈希值" diff --git a/src/render/gta6_hair.rs b/src/render/gta6_hair.rs index 6b881ee2f..c696c3178 100644 --- a/src/render/gta6_hair.rs +++ b/src/render/gta6_hair.rs @@ -408,7 +408,7 @@ fn collect_color_overrides( ) -> HashMap { let mut map = HashMap::new(); let mut ingest = |vals: &[u32]| { - for pair in vals.chunks_exact(2) { + for pair in vals.as_chunks::<2>().0 { if pair[0] != 0 && pair[1] != 0 { map.insert(pair[0], pair[1]); } diff --git a/src/render/gta6_forward.rs b/src/render/gta6_meshlets/forward.rs similarity index 100% rename from src/render/gta6_forward.rs rename to src/render/gta6_meshlets/forward.rs diff --git a/src/render/gta6_meshlets.rs b/src/render/gta6_meshlets/mod.rs similarity index 88% rename from src/render/gta6_meshlets.rs rename to src/render/gta6_meshlets/mod.rs index 5f820a989..dfeea608e 100644 --- a/src/render/gta6_meshlets.rs +++ b/src/render/gta6_meshlets/mod.rs @@ -13,6 +13,10 @@ use or_io::hash::string_hash_str; use or_renderer::game_shaders::mesh::Image; use or_renderer::game_shaders::meshlets::{Feed, FrameFeed, MeshletSurface, ROW, VERTICES}; +mod packing; + +use packing::{merge_feeds, pose_surface, stand}; + use super::gta6_layers::Material; use crate::state::gta6_resource::{drawable_of, effect_name}; use crate::state::gta6_shaders::layer_index::{self as gta6_layer_index, Index}; @@ -814,161 +818,6 @@ fn game_textures( } } -/// Have `surface`, drawn by `pass`, stand where `placement` puts it, a row-major 3x4 matrix: its -/// object's matrix and each bone's at rest are that one. A surface in place is left as it is. -fn stand(pass: &Gta6ShadingPass, surface: &mut MeshletSurface, placement: [f32; 12]) { - if placement == super::gta6_instances::IN_PLACE[0] { - return; - } - let mut rows = [0f32; 16]; - rows[..12].copy_from_slice(&placement); - rows[15] = 1.0; - let whole = glam::Mat4::from_cols_array(&rows) - .transpose() - .to_cols_array(); - let bytes = |floats: &[f32]| -> Vec { - let each: Vec = floats.iter().flat_map(|f| f.to_le_bytes()).collect(); - each.repeat(MATRICES) - }; - // A stage that reads the object's matrix is placed by it alone: its bones stay at rest under it. - let feeds = || pass.mesh.feeds.iter().chain(&pass.pixel.feeds); - // A stage that places its instances by their records is placed by those alone. - if feeds().any(|fed| fed.feed == Filled::InstanceRecords) { - return; - } - let by_object = feeds().any(|fed| fed.feed == Filled::Placement); - for fed in feeds() { - let stood = match fed.feed { - Filled::Placement => bytes(&whole), - Filled::Bones if !by_object => bytes(&placement), - _ => continue, - }; - let stood = Feed::Bytes(headed(fed.header, &stood)); - surface.feeds.insert((fed.group, fed.binding), stood); - } -} - -/// The typed `u32` bone-index remap table a skinned ped mesh stage indexes by vertex bone index -/// when its draw-word remap offset is zero (`cb4_[7].y != 0xFFFF_FFFF`). Leaving it empty causes -/// bounds-checked storage loads to return 0 and collapse every vertex onto bone 0. -const BONE_REMAP: u32 = 0x0D29_BC56; - -/// Apply `pose`'s per-palette bone skinning matrices to every `Filled::Bones` binding of `surface`, -/// and bind an identity remap table (`0..matrices`) to `BONE_REMAP` so vertex bone indices reach -/// their palette slots directly. -fn pose_surface( - pass: &Gta6ShadingPass, - surface: &mut MeshletSurface, - drawable: &Drawable, - model: &Model, - pose: &super::gta6_ped_pose::PedPose, -) { - let feeds = || pass.mesh.feeds.iter().chain(&pass.pixel.feeds); - if !feeds().any(|fed| fed.feed == Filled::Bones) { - return; - } - let matrices = match &model.palette { - Ok(or_io::gta6::headerless::Palette::Hashes(hashes)) => MATRICES.max(hashes.len()), - _ => MATRICES, - }; - let bone_bytes = pose.palette_bytes(drawable, model, matrices); - let remap_words: Vec = (0..matrices as u32).collect(); - let remap_bytes = bytes_of(&remap_words); - for fed in feeds() { - match fed.feed { - Filled::Bones => { - let filled = Feed::Bytes(headed(fed.header, &bone_bytes)); - surface.feeds.insert((fed.group, fed.binding), filled); - } - Filled::Zero(Some(BONE_REMAP)) => { - let filled = Feed::Bytes(headed(fed.header, &remap_bytes)); - surface.feeds.insert((fed.group, fed.binding), filled); - } - _ => {} - } - } -} - -/// Pack the part feeds of each stage buffer merged to fit a device budget into one buffer at -/// `merged.at`, matching `or_shader_front::rdna_bind::budget::within`. -fn merge_feeds(merged: &[or_cli::Gta6MergedBuffer], feeds: &mut BTreeMap<(u32, u32), Feed>) { - for group in merged { - let mut parts: Vec> = group - .parts - .iter() - .map(|part| feeds.remove(&part.was)) - .collect(); - let combined = match group.listed { - None => { - let total = group - .parts - .iter() - .map(|p| (p.offset + p.bytes) as usize) - .max() - .unwrap_or(0); - let mut whole = vec![0u8; total]; - let mut view_proj: Option> = None; - for (part, feed) in group.parts.iter().zip(parts.drain(..)) { - let raw = match feed { - Some(Feed::Bytes(bytes)) => bytes, - Some(Feed::View { - bytes, - view_proj: at, - }) => { - let shifted = at.map(|offset| part.offset as usize + offset); - view_proj = Some(view_proj.flatten().or(shifted)); - bytes - } - _ => continue, - }; - let start = part.offset as usize; - let copy = raw.len().min(part.bytes as usize); - whole[start..start + copy].copy_from_slice(&raw[..copy]); - } - match view_proj { - Some(view_proj) => Feed::View { - bytes: whole, - view_proj, - }, - None => Feed::Bytes(whole), - } - } - Some(element) => { - let stride = (element as usize).max(4); - let mut chunks: Vec> = Vec::with_capacity(parts.len()); - for feed in parts.drain(..) { - let mut raw = match feed { - Some(Feed::Bytes(bytes) | Feed::View { bytes, .. }) => bytes, - _ => Vec::new(), - }; - let padded = raw.len().max(stride).next_multiple_of(stride); - raw.resize(padded, 0); - chunks.push(raw); - } - let header_elems = chunks.len() + 1; - let total_bytes: usize = - header_elems * stride + chunks.iter().map(Vec::len).sum::(); - let mut whole = vec![0u8; total_bytes]; - let mut next = header_elems as u32; - for (slot, chunk) in chunks.iter().enumerate() { - let at = slot * stride; - whole[at..at + 4].copy_from_slice(&next.to_le_bytes()); - next += (chunk.len() / stride) as u32; - } - let end_at = chunks.len() * stride; - whole[end_at..end_at + 4].copy_from_slice(&next.to_le_bytes()); - let mut cursor = header_elems * stride; - for chunk in chunks { - whole[cursor..cursor + chunk.len()].copy_from_slice(&chunk); - cursor += chunk.len(); - } - Feed::Bytes(whole) - } - }; - feeds.insert(group.at, combined); - } -} - /// The geometries of `models` the view draws of `drawable` as surfaces of their own passes, with /// `why` the first that is none is not, and the effects they draw with. `None` where a geometry /// names a shader the drawable does not list. @@ -1132,7 +981,6 @@ pub(crate) fn meshlets_of( Some((out, effects)) } -#[path = "gta6_forward.rs"] mod forward; #[cfg(test)] diff --git a/src/render/gta6_meshlets/packing.rs b/src/render/gta6_meshlets/packing.rs new file mode 100644 index 000000000..91fbe2304 --- /dev/null +++ b/src/render/gta6_meshlets/packing.rs @@ -0,0 +1,167 @@ +//! Placement, skinning pose, and budget-merged buffer packing for GTA VI meshlet surfaces. + +use std::collections::BTreeMap; + +use or_cli::{Gta6Feed as Filled, Gta6ShadingPass}; +use or_io::gta6::headerless::{Drawable, Model}; +use or_renderer::game_shaders::meshlets::{Feed, MeshletSurface}; + +use super::{bytes_of, headed, MATRICES}; + +/// Have `surface`, drawn by `pass`, stand where `placement` puts it, a row-major 3x4 matrix: its +/// object's matrix and each bone's at rest are that one. A surface in place is left as it is. +pub(super) fn stand(pass: &Gta6ShadingPass, surface: &mut MeshletSurface, placement: [f32; 12]) { + if placement == crate::render::gta6_instances::IN_PLACE[0] { + return; + } + let mut rows = [0f32; 16]; + rows[..12].copy_from_slice(&placement); + rows[15] = 1.0; + let whole = glam::Mat4::from_cols_array(&rows) + .transpose() + .to_cols_array(); + let bytes = |floats: &[f32]| -> Vec { + let each: Vec = floats.iter().flat_map(|f| f.to_le_bytes()).collect(); + each.repeat(MATRICES) + }; + // A stage that reads the object's matrix is placed by it alone: its bones stay at rest under it. + let feeds = || pass.mesh.feeds.iter().chain(&pass.pixel.feeds); + // A stage that places its instances by their records is placed by those alone. + if feeds().any(|fed| fed.feed == Filled::InstanceRecords) { + return; + } + let by_object = feeds().any(|fed| fed.feed == Filled::Placement); + for fed in feeds() { + let stood = match fed.feed { + Filled::Placement => bytes(&whole), + Filled::Bones if !by_object => bytes(&placement), + _ => continue, + }; + let stood = Feed::Bytes(headed(fed.header, &stood)); + surface.feeds.insert((fed.group, fed.binding), stood); + } +} + +/// The typed `u32` bone-index remap table a skinned ped mesh stage indexes by vertex bone index +/// when its draw-word remap offset is zero (`cb4_[7].y != 0xFFFF_FFFF`). Leaving it empty causes +/// bounds-checked storage loads to return 0 and collapse every vertex onto bone 0. +const BONE_REMAP: u32 = 0x0D29_BC56; + +/// Apply `pose`'s per-palette bone skinning matrices to every `Filled::Bones` binding of `surface`, +/// and bind an identity remap table (`0..matrices`) to `BONE_REMAP` so vertex bone indices reach +/// their palette slots directly. +pub(super) fn pose_surface( + pass: &Gta6ShadingPass, + surface: &mut MeshletSurface, + drawable: &Drawable, + model: &Model, + pose: &crate::render::gta6_ped_pose::PedPose, +) { + let feeds = || pass.mesh.feeds.iter().chain(&pass.pixel.feeds); + if !feeds().any(|fed| fed.feed == Filled::Bones) { + return; + } + let matrices = match &model.palette { + Ok(or_io::gta6::headerless::Palette::Hashes(hashes)) => MATRICES.max(hashes.len()), + _ => MATRICES, + }; + let bone_bytes = pose.palette_bytes(drawable, model, matrices); + let remap_words: Vec = (0..matrices as u32).collect(); + let remap_bytes = bytes_of(&remap_words); + for fed in feeds() { + match fed.feed { + Filled::Bones => { + let filled = Feed::Bytes(headed(fed.header, &bone_bytes)); + surface.feeds.insert((fed.group, fed.binding), filled); + } + Filled::Zero(Some(BONE_REMAP)) => { + let filled = Feed::Bytes(headed(fed.header, &remap_bytes)); + surface.feeds.insert((fed.group, fed.binding), filled); + } + _ => {} + } + } +} + +/// Pack the part feeds of each stage buffer merged to fit a device budget into one buffer at +/// `merged.at`, matching `or_shader_front::rdna_bind::budget::within`. +pub(super) fn merge_feeds( + merged: &[or_cli::Gta6MergedBuffer], + feeds: &mut BTreeMap<(u32, u32), Feed>, +) { + for group in merged { + let mut parts: Vec> = group + .parts + .iter() + .map(|part| feeds.remove(&part.was)) + .collect(); + let combined = match group.listed { + None => { + let total = group + .parts + .iter() + .map(|p| (p.offset + p.bytes) as usize) + .max() + .unwrap_or(0); + let mut whole = vec![0u8; total]; + let mut view_proj: Option> = None; + for (part, feed) in group.parts.iter().zip(parts.drain(..)) { + let raw = match feed { + Some(Feed::Bytes(bytes)) => bytes, + Some(Feed::View { + bytes, + view_proj: at, + }) => { + let shifted = at.map(|offset| part.offset as usize + offset); + view_proj = Some(view_proj.flatten().or(shifted)); + bytes + } + _ => continue, + }; + let start = part.offset as usize; + let copy = raw.len().min(part.bytes as usize); + whole[start..start + copy].copy_from_slice(&raw[..copy]); + } + match view_proj { + Some(view_proj) => Feed::View { + bytes: whole, + view_proj, + }, + None => Feed::Bytes(whole), + } + } + Some(element) => { + let stride = (element as usize).max(4); + let mut chunks: Vec> = Vec::with_capacity(parts.len()); + for feed in parts.drain(..) { + let mut raw = match feed { + Some(Feed::Bytes(bytes) | Feed::View { bytes, .. }) => bytes, + _ => Vec::new(), + }; + let padded = raw.len().max(stride).next_multiple_of(stride); + raw.resize(padded, 0); + chunks.push(raw); + } + let header_elems = chunks.len() + 1; + let total_bytes: usize = + header_elems * stride + chunks.iter().map(Vec::len).sum::(); + let mut whole = vec![0u8; total_bytes]; + let mut next = header_elems as u32; + for (slot, chunk) in chunks.iter().enumerate() { + let at = slot * stride; + whole[at..at + 4].copy_from_slice(&next.to_le_bytes()); + next += (chunk.len() / stride) as u32; + } + let end_at = chunks.len() * stride; + whole[end_at..end_at + 4].copy_from_slice(&next.to_le_bytes()); + let mut cursor = header_elems * stride; + for chunk in chunks { + whole[cursor..cursor + chunk.len()].copy_from_slice(&chunk); + cursor += chunk.len(); + } + Feed::Bytes(whole) + } + }; + feeds.insert(group.at, combined); + } +}