Parallel: send only the atlas rows changed since an Actor's copy (instead of the whole texture per update)
Build & Release / build (push) Canceled after 0s

This commit is contained in:
4DBug committed 2026-10-17 09:12:34 -05:00
1 parent cd826cf3ca
commit 4c9bac2117
6 files changed
+83 -11

No files matched your search

+26 -3
View File
@@ -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
+9 -1
View File
@@ -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
+6 -1
View File
@@ -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()
+1 -1
View File
@@ -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"]]
[[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"]]
+35 -4
View File
@@ -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
+6 -1
View File
@@ -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()