From 4c9bac21173c530ff118e2f08bdfa5a8321e1c85 Mon Sep 17 00:00:00 2001 From: 4DBug <4DBug@github.com> Date: Sat, 17 Oct 2026 09:12:34 -0500 Subject: [PATCH] Parallel: send only the atlas rows changed since an Actor's copy (instead of the whole texture per update) --- backends/roblox/parallel.lua | 29 +++++++++++++++++++++++--- backends/roblox/textures.lua | 10 ++++++++- backends/roblox/worker.luau | 7 ++++++- build/ImGui.linemap.json | 2 +- build/ImGui.luau | 39 +++++++++++++++++++++++++++++++---- build/ImGuiWorker.client.luau | 7 ++++++- 6 files changed, 83 insertions(+), 11 deletions(-) diff --git a/backends/roblox/parallel.lua b/backends/roblox/parallel.lua index e28a349..a8b7e05 100644 --- a/backends/roblox/parallel.lua +++ b/backends/roblox/parallel.lua @@ -272,14 +272,37 @@ function M.Flush() local tex, s = NO_TEX, sent[a] for rec, id in used[a] do local v = rec.V or 0 - if s[rec] ~= v then + local had = s[rec] + if had ~= v then if tex == NO_TEX then tex = {} end s[rec] = v - tex[#tex + 1] = { id, rec.Buffer, rec.Width, rec.Height } + -- the Actor has version `had`: send only the rows changed since then when the log covers them + local y0, y1, log = math.huge, -1, rec.Log + if had and log then + for k = had + 1, v do + local e = log[k] + if not e then y0 = nil; break end + if e[2] > e[1] then + if e[1] < y0 then y0 = e[1] end + if e[2] > y1 then y1 = e[2] end + end + end + else + y0 = nil + end + if y0 == nil then + tex[#tex + 1] = { id, rec.Buffer, rec.Width, rec.Height } + Stats.TexBytes += buffer.len(rec.Buffer) + elseif y1 > y0 then + local row = rec.Width * 4 + local patch = buffer.create((y1 - y0) * row) + copy(patch, 0, rec.Buffer, y0 * row, (y1 - y0) * row) + tex[#tex + 1] = { id, false, rec.Width, rec.Height, y0 * row, patch } + Stats.TexBytes += buffer.len(patch) + end Stats.TexSends += 1 - Stats.TexBytes += buffer.len(rec.Buffer) end end Stats.SendBytes += Pn[a] + tl diff --git a/backends/roblox/textures.lua b/backends/roblox/textures.lua index 8a5019b..e29a01e 100644 --- a/backends/roblox/textures.lua +++ b/backends/roblox/textures.lua @@ -81,10 +81,18 @@ function M.UpdateTexture(tex) CreateTextureRecord(tex) return end + local y0, y1 = math.huge, -1 for _, r in tex.Updates:iter() do CopyTexturePixels(tex, t.Buffer, r.x, r.y, r.w, r.h) + if r.y < y0 then y0 = r.y end + if r.y + r.h > y1 then y1 = r.y + r.h end end - t.V = (t.V or 0) + 1 -- parallel workers hold copies, resent when this changes + -- parallel workers hold copies, patched when this changes: Log[V] = changed rows (only the last 16 kept) + local v = (t.V or 0) + 1 + t.V = v + t.Log = t.Log or {} + t.Log[v] = y1 > y0 and { y0, y1 } or { 0, 0 } + t.Log[v - 16] = nil tex:SetStatus(ImTextureStatus.OK) elseif tex.Status == ImTextureStatus.WantDestroy then if tex.BackendUserData then diff --git a/backends/roblox/worker.luau b/backends/roblox/worker.luau index cf4c992..2d0fae5 100644 --- a/backends/roblox/worker.luau +++ b/backends/roblox/worker.luau @@ -10,7 +10,12 @@ local Textures = {} Actor:BindToMessageParallel("job", function(Id, Prims, Tiles, TexUpdates, TileLength) for _, Texture in TexUpdates do - Textures[Texture[1]] = { Buffer = Texture[2], Width = Texture[3], Height = Texture[4] } + if Texture[2] then + Textures[Texture[1]] = { Buffer = Texture[2], Width = Texture[3], Height = Texture[4] } + else -- rows changed since the copy this Actor has + local T = Textures[Texture[1]] + buffer.copy(T.Buffer, Texture[5], Texture[6]) + end end local Results = Raster.RasterJobs(Prims, Tiles, TileLength, Textures) task.synchronize() diff --git a/build/ImGui.linemap.json b/build/ImGui.linemap.json index 094e759..acb16a4 100644 --- a/build/ImGui.linemap.json +++ b/build/ImGui.linemap.json @@ -1 +1 @@ -[[46, "imgui.lua"], [22664, "imgui_demo.lua"], [34521, "imgui_draw.lua"], [42861, "imgui_h.lua"], [45864, "roblox/raster.lua"], [46340, "roblox/textures.lua"], [46511, "roblox/layers.lua"], [46848, "roblox/overlays.lua"], [46929, "roblox/render.lua"], [47774, "roblox/parallel.lua"], [48173, "imgui_impl_roblox.lua"], [48674, "imgui_impl_roblox_fonts.lua"], [55077, "imgui_internal.lua"], [59045, "imgui_tables.lua"], [64137, "imgui_widgets.lua"], [76378, "imstb_rectpack.lua"], [77055, "imstb_textedit.lua"], [78597, "imstb_truetype.lua"], [81538, "imstd_minstdio.lua"]] \ No newline at end of file +[[46, "imgui.lua"], [22664, "imgui_demo.lua"], [34521, "imgui_draw.lua"], [42861, "imgui_h.lua"], [45864, "roblox/raster.lua"], [46340, "roblox/textures.lua"], [46519, "roblox/layers.lua"], [46856, "roblox/overlays.lua"], [46937, "roblox/render.lua"], [47782, "roblox/parallel.lua"], [48204, "imgui_impl_roblox.lua"], [48705, "imgui_impl_roblox_fonts.lua"], [55108, "imgui_internal.lua"], [59076, "imgui_tables.lua"], [64168, "imgui_widgets.lua"], [76409, "imstb_rectpack.lua"], [77086, "imstb_textedit.lua"], [78628, "imstb_truetype.lua"], [81569, "imstd_minstdio.lua"]] \ No newline at end of file diff --git a/build/ImGui.luau b/build/ImGui.luau index d1c7ead..aead896 100644 --- a/build/ImGui.luau +++ b/build/ImGui.luau @@ -46420,10 +46420,18 @@ function M.UpdateTexture(tex) CreateTextureRecord(tex) return end + local y0, y1 = math.huge, -1 for _, r in tex.Updates:iter() do CopyTexturePixels(tex, t.Buffer, r.x, r.y, r.w, r.h) + if r.y < y0 then y0 = r.y end + if r.y + r.h > y1 then y1 = r.y + r.h end end - t.V = (t.V or 0) + 1 -- parallel workers hold copies, resent when this changes + -- parallel workers hold copies, patched when this changes: Log[V] = changed rows (only the last 16 kept) + local v = (t.V or 0) + 1 + t.V = v + t.Log = t.Log or {} + t.Log[v] = y1 > y0 and { y0, y1 } or { 0, 0 } + t.Log[v - 16] = nil tex:SetStatus(0 --[[ImTextureStatus.OK]]) elseif tex.Status == 4 --[[ImTextureStatus.WantDestroy]] then if tex.BackendUserData then @@ -48045,14 +48053,37 @@ function M.Flush() local tex, s = NO_TEX, sent[a] for rec, id in used[a] do local v = rec.V or 0 - if s[rec] ~= v then + local had = s[rec] + if had ~= v then if tex == NO_TEX then tex = {} end s[rec] = v - tex[#tex + 1] = { id, rec.Buffer, rec.Width, rec.Height } + -- the Actor has version `had`: send only the rows changed since then when the log covers them + local y0, y1, log = math.huge, -1, rec.Log + if had and log then + for k = had + 1, v do + local e = log[k] + if not e then y0 = nil; break end + if e[2] > e[1] then + if e[1] < y0 then y0 = e[1] end + if e[2] > y1 then y1 = e[2] end + end + end + else + y0 = nil + end + if y0 == nil then + tex[#tex + 1] = { id, rec.Buffer, rec.Width, rec.Height } + Stats.TexBytes += buffer.len(rec.Buffer) + elseif y1 > y0 then + local row = rec.Width * 4 + local patch = buffer.create((y1 - y0) * row) + copy(patch, 0, rec.Buffer, y0 * row, (y1 - y0) * row) + tex[#tex + 1] = { id, false, rec.Width, rec.Height, y0 * row, patch } + Stats.TexBytes += buffer.len(patch) + end Stats.TexSends += 1 - Stats.TexBytes += buffer.len(rec.Buffer) end end Stats.SendBytes += Pn[a] + tl diff --git a/build/ImGuiWorker.client.luau b/build/ImGuiWorker.client.luau index 57415e6..d401316 100644 --- a/build/ImGuiWorker.client.luau +++ b/build/ImGuiWorker.client.luau @@ -487,7 +487,12 @@ local Textures = {} Actor:BindToMessageParallel("job", function(Id, Prims, Tiles, TexUpdates, TileLength) for _, Texture in TexUpdates do - Textures[Texture[1]] = { Buffer = Texture[2], Width = Texture[3], Height = Texture[4] } + if Texture[2] then + Textures[Texture[1]] = { Buffer = Texture[2], Width = Texture[3], Height = Texture[4] } + else -- rows changed since the copy this Actor has + local T = Textures[Texture[1]] + buffer.copy(T.Buffer, Texture[5], Texture[6]) + end end local Results = Raster.RasterJobs(Prims, Tiles, TileLength, Textures) task.synchronize()