0.4.0
Build & Release / build (push) Canceled after 0s

This commit is contained in:
4DBug committed 2026-10-16 22:53:18 -05:00
1 parent 1a83724317
commit 386b0c475e
46 files changed
+7897 -4414

No files matched your search

+108
View File
@@ -0,0 +1,108 @@
-- Demo Assets Browser (10000 items) scrolled continuously for ~1000 frames in raster mode: live tiles and
-- EditableImage bytes must stay bounded by what is visible and flat (no growth trend between the 1st and 2nd half).
-- Then (no input) the screen composited from those tiles (many recycled from the free list) must equal the one after
-- rebuilding every tile from scratch: a recycled EditableImage never shows stale pixels.
-- run: python3 tools/test/run.py --main tools/test/scripts/t_assets_scroll.luau --frames 1010 --quiet --roblox
local G = require(game:GetService("ReplicatedStorage"):WaitForChild("ImGui"))
local ImGui, ImVec2 = G.ImGui, G.ImVec2
local Impl = G.ImGui_ImplRoblox
ImGui.CreateContext()
Impl.Init()
Impl.SetRenderRate(0)
local io = ImGui.GetIO()
local N = 1000
local frame, open = 0, true
local peak = { { 0, 0, 0 }, { 0, 0, 0 } } -- per half: tiles, EI count, EI bytes
local scroll_min, scroll_max = math.huge, 0
local W, H = 1280, 760 -- (composite: copied from t_composite.luau)
local function composite(gui)
local screen = buffer.create(W * H * 3)
local function walk(inst, ox, oy, kx0, ky0, kx1, ky1)
local kids = inst:GetChildren()
table.sort(kids, function(a, b) return (a.ZIndex or 1) < (b.ZIndex or 1) end) -- table.sort isn't stable, but siblings with equal ZIndex never overlap here
for _, c in ipairs(kids) do
if c.Visible ~= false then
local x, y = ox + (c.Position and c.Position.X or 0), oy + (c.Position and c.Position.Y or 0)
local cx0, cy0, cx1, cy1 = kx0, ky0, kx1, ky1
if c.ClipsDescendants then
cx0, cy0 = math.max(cx0, x), math.max(cy0, y)
cx1, cy1 = math.min(cx1, x + c.Size.X), math.min(cy1, y + c.Size.Y)
end
if c.ClassName == "ImageLabel" then
local img = c.ImageContent.Object
local px, sz = img.Pixels, img.Size.X
for ty = 0, sz - 1 do
local sy = y + ty
if sy >= ky0 and sy < ky1 then
for tx = 0, sz - 1 do
local sx = x + tx
if sx >= kx0 and sx < kx1 then
local o = (ty * sz + tx) * 4
local a = buffer.readu8(px, o + 3)
if a > 0 then
local d = (sy * W + sx) * 3
local fa = a / 255
for ch = 0, 2 do
local v = buffer.readu8(px, o + ch) * fa + buffer.readu8(screen, d + ch) * (1 - fa)
buffer.writeu8(screen, d + ch, math.floor(v + 0.5))
end
end
end
end
end
end
end
walk(c, x, y, cx0, cy0, cx1, cy1)
end
end
end
walk(gui, 0, 0, 0, 0, W, H)
return screen
end
local before
game:GetService("RunService").Stepped:Connect(function()
frame += 1
if frame > N + 10 then return end
Impl.NewFrame()
io.DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(20, 20), G.ImGuiCond.Always)
open = G.ShowExampleAppAssetsBrowser(open)
local w = ImGui.FindWindowByName("Example: Assets Browser")
if w and frame > 2 and frame <= N then
io:AddMousePosEvent(w.Pos.x + w.Size.x / 2, w.Pos.y + w.Size.y / 2)
io:AddMouseWheelEvent(0, (frame % 400 < 250) and -2 or 3) -- down, then back up: continuous, both directions
end
ImGui.Render()
Impl.RenderDrawData(ImGui.GetDrawData())
local s
if Impl.GetStats then s = Impl.GetStats() else -- (older backends, for before/after numbers: 1 EditableImage per tile)
local n = 0
for _, d in ipairs(game:GetService("Players").LocalPlayer.PlayerGui:GetDescendants()) do if d.ClassName == "ImageLabel" and d.Name:sub(1, 4) == "Tile" then n += 1 end end
s = { Tiles = n, EditableImages = n, EditableImageBytes = n * 65536, EditableImageCap = math.huge }
end
assert(s.EditableImageBytes <= s.EditableImageCap)
for _, c in ipairs(w and w.DC.ChildWindows.Data or {}) do scroll_min = math.min(scroll_min, c.Scroll.y); scroll_max = math.max(scroll_max, c.Scroll.y) end
if frame > 50 then
local p = peak[frame <= 525 and 1 or 2]
p[1], p[2], p[3] = math.max(p[1], s.Tiles), math.max(p[2], s.EditableImages), math.max(p[3], s.EditableImageBytes)
end
if frame == N then
print(("ASSETS scrolled %d..%d px; peak tiles %d / %d, EditableImages %d / %d, EI bytes %d / %d (1st / 2nd half); now %d tiles"):format(
scroll_min, scroll_max, peak[1][1], peak[2][1], peak[1][2], peak[2][2], peak[1][3], peak[2][3], s.Tiles))
assert(scroll_max - scroll_min > 5000, "assets browser did not scroll")
-- the whole demo-sized screen is ~ 10 x 6 tiles per layer; content + chrome + spares + free list stay well below 150
assert(peak[1][1] <= 150 and peak[2][1] <= 150, "tile count not bounded by what is visible")
assert(peak[2][2] <= peak[1][2] + 4 and peak[2][3] <= peak[1][3] + 4 * 128 * 128 * 4, "EditableImage use grows over time")
end
if frame == N + 8 then
before = buffer.tostring(composite(game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ImGui")))
Impl.SetRenderScale(2); Impl.SetRenderScale(1) -- (drops every tile: the next frame redraws all of them)
elseif frame == N + 9 then
local after = buffer.tostring(composite(game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ImGui")))
assert(#before:gsub("%z", "") > 10000, "nothing composited")
assert(before == after, "recycled tiles show different pixels than freshly drawn ones")
print("ASSETS OK")
end
end)
+171
View File
@@ -0,0 +1,171 @@
-- Parallel raster executor (ImGui_ImplRoblox.EnableParallel) vs the inline backend, pixel for pixel. Two contexts draw the same
-- benchmark scenarios every frame: A inline (Config.Inline), B through the executor in Sync mode (the mock has no Actors: the "workers"
-- run inline, same code). Frames cycle through: dispatch window open (batches pending until Finish, like
-- PreSimulation -> PostSimulation), open with SyncDrop (half the worker results lost -> Finish falls back), and closed
-- (late RenderDrawData: rasterized + uploaded at once). The composites of A and B must match at every checkpoint.
-- Prints the executor's main-thread pack cost per frame next to A's inline raster + upload cost.
-- run: python3 tools/test/run.py --main tools/test/scripts/t_parallel.luau --frames 900 --quiet --roblox
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImGui, ImVec2 = G.ImGui, G.ImVec2
local Impl = G.ImGui_ImplRoblox
local W, H = 1280, 760
local N = ARG_N or 120 -- frames per scenario
local function composite(gui)
local screen = buffer.create(W * H * 3)
local function walk(inst, ox, oy, kx0, ky0, kx1, ky1)
local kids = inst:GetChildren()
table.sort(kids, function(a, b) return (a.ZIndex or 1) < (b.ZIndex or 1) end)
for _, c in ipairs(kids) do
if c.Visible ~= false then
local x, y = ox + (c.Position and c.Position.X or 0), oy + (c.Position and c.Position.Y or 0)
local cx0, cy0, cx1, cy1 = kx0, ky0, kx1, ky1
if c.ClipsDescendants then
cx0, cy0 = math.max(cx0, x), math.max(cy0, y)
cx1, cy1 = math.min(cx1, x + c.Size.X), math.min(cy1, y + c.Size.Y)
end
if c.ClassName == "ImageLabel" then
local px, sz = c.ImageContent.Object.Pixels, c.ImageContent.Object.Size.X
for ty = math.max(0, cy0 - y), math.min(sz, cy1 - y) - 1 do
local sy = y + ty
for tx = math.max(0, cx0 - x), math.min(sz, cx1 - x) - 1 do
local o = (ty * sz + tx) * 4
local a = buffer.readu8(px, o + 3)
if a > 0 then
local d = (sy * W + x + tx) * 3
local fa = a / 255
for ch = 0, 2 do
buffer.writeu8(screen, d + ch, math.floor(buffer.readu8(px, o + ch) * fa + buffer.readu8(screen, d + ch) * (1 - fa) + 0.5))
end
end
end
end
end
walk(c, x, y, cx0, cy0, cx1, cy1)
end
end
end
walk(gui, 0, 0, 0, 0, W, H)
local h = 0
for i = 0, W * H * 3 - 4, 4 do h = (h * 31 + buffer.readu32(screen, i)) % 2147483647 end
return h
end
local plot = table.create(120, 0)
local SCEN = {
{ "resize", function(f)
local s = 520 + ((f % 80) < 40 and (f % 40) * 7 or (40 - f % 40) * 7)
ImGui.ShowDemoWindow()
ImGui.SetWindowPos("Dear ImGui Demo", ImVec2(30, 20)); ImGui.SetWindowSize("Dear ImGui Demo", ImVec2(s, s * 0.8 + 60))
end },
{ "assets", function(f)
ImGui.SetNextWindowPos(ImVec2(20, 20), G.ImGuiCond.Always)
G.ShowExampleAppAssetsBrowser(true)
local w = ImGui.FindWindowByName("Example: Assets Browser")
if w and f > 2 then for _, c in ipairs(w.DC.ChildWindows.Data) do ImGui.SetScrollY(c, (f * 40) % 6000) end end
end },
{ "list", function(f)
ImGui.SetNextWindowPos(ImVec2(40, 30), G.ImGuiCond.Always); ImGui.SetNextWindowSize(ImVec2(560, 680), G.ImGuiCond.Always)
ImGui.Begin("Long list")
ImGui.SetScrollY(13 * (f <= 60 and f or 120 - f))
local clipper = G.ImGuiListClipper()
clipper:Begin(10000)
while clipper:Step() do
for i = clipper.DisplayStart, clipper.DisplayEnd - 1 do ImGui.Text("%05d: The quick brown fox jumps over the lazy dog", i) end
end
ImGui.End()
end },
{ "plots", function(f)
for i = 1, 120 do plot[i] = math.sin((i + f) * 0.15) + 0.3 * math.sin((i * 3 + f) * 0.4) end
ImGui.SetNextWindowPos(ImVec2(40, 30), G.ImGuiCond.Always); ImGui.SetNextWindowSize(ImVec2(620, 520), G.ImGuiCond.Always)
ImGui.Begin("Plots")
ImGui.PlotLines("Lines", plot, nil, 120, 0, nil, -1.5, 1.5, ImVec2(0, 160))
ImGui.PlotHistogram("Histogram", plot, nil, 120, 0, nil, -1.5, 1.5, ImVec2(0, 160))
ImGui.Text("frame %d", f)
ImGui.End()
end },
}
local ctx, gui = {}, {}
for i = 1, 2 do
ctx[i] = ImGui.CreateContext()
ImGui.SetCurrentContext(ctx[i])
local parent = Instance.new("Folder")
Impl.Init(parent)
Impl.SetRenderRate(0)
Impl.SetStageTiming(true)
gui[i] = parent:FindFirstChild("ImGui")
end
Impl.EnableParallel({ Sync = true, Actors = 4 })
local C = Impl.GetParallelConfig()
local si, f, checks, bad = 1, 0, 0, 0
local pack, inline, flushes = {}, {}, { open = 0, drop = 0, closed = 0 }
local S = Impl.GetParallelStats()
local s0 = table.clone(S)
local kb = { 0, 0 } -- KB allocated in RenderDrawData (+ Finish for the executor context), per context
local function k_add(i, k0) local d = collectgarbage("count") - k0; if f > 5 and d > 0 then kb[i] += d end end
game:GetService("RunService").Stepped:Connect(function()
local sc = SCEN[si]
if not sc then return end
f += 1
local mode = f % 3 -- 0 closed, 1 open, 2 open + SyncDrop
C.SyncDrop = mode == 2
if mode ~= 0 then Impl.BeginParallelFrame() end
flushes[mode == 0 and "closed" or mode == 1 and "open" or "drop"] += 1
for i = 1, 2 do
ImGui.SetCurrentContext(ctx[i])
C.Inline = i == 1
Impl.NewFrame()
local io = ImGui.GetIO()
io.DeltaTime = 1 / 60
io:AddMousePosEvent(1270, 750)
ImGui.NewFrame()
sc[2](f)
ImGui.Render()
local fake = os.clock
os.clock = os.realclock -- (mock: os.clock is frozen; real time for the stage / pack timers)
local p0, k0 = S.Pack, collectgarbage("count")
Impl.RenderDrawData(ImGui.GetDrawData())
k_add(i, k0)
os.clock = fake
if f > 5 then
if i == 1 then local st = Impl.GetStats().Frame; table.insert(inline, (st.Raster + st.Upload) * 1000)
else table.insert(pack, (S.Pack - p0) * 1000) end
end
end
local k0 = collectgarbage("count")
Impl.FinishParallel()
k_add(2, k0)
if f % 10 == 0 or f == N then
checks += 1
local a, b = composite(gui[1]), composite(gui[2])
if a ~= b then bad += 1; print("MISMATCH", sc[1], f, a, b) end
end
if f == N then
local function stats(t)
local s, m = 0, 0
for _, v in t do s += v; m = math.max(m, v) end
return s / math.max(#t, 1), m
end
local pm, px = stats(pack)
local im, ix = stats(inline)
print(string.format("PACK %-7s mean %.3f max %.3f ms/frame | inline raster+upload mean %.3f max %.3f ms/frame | tiles %.1f rects %.1f send %d KB/frame, tex resends %d (%d KB)",
sc[1], pm, px, im, ix, (S.Tiles - s0.Tiles) / N, (S.Rects - s0.Rects) / N, (S.SendBytes - s0.SendBytes) / 1024 / N, S.TexSends - s0.TexSends, (S.TexBytes - s0.TexBytes) / 1024))
print(string.format("ALLOC %-7s KB/frame inline %.1f executor %.1f (Sync: includes the inline worker raster)", sc[1], kb[1] / (N - 5), kb[2] / (N - 5)))
kb = { 0, 0 }
s0 = table.clone(S)
pack, inline = {}, {}
for i = 1, 2 do ImGui.SetCurrentContext(ctx[i]); Impl.SetRenderScale(2); Impl.SetRenderScale(1) end
si += 1; f = 0
Impl.EnableParallel({ Actors = si }) -- runtime re-Enable with a different actor count (pixels must still match)
assert(C.Sync and Impl.GetParallelConfig() == C, "re-Enable kept Sync")
if not SCEN[si] then
print(string.format("STATS parallel flushes %d serial %d tiles %d fallbacks %d | frames open %d drop %d closed %d",
S.ParallelFlushes, S.SerialFlushes, S.Tiles, S.Fallbacks, flushes.open, flushes.drop, flushes.closed))
assert(S.ParallelFlushes > 0 and S.SerialFlushes > 0 and S.Fallbacks > 0, "a path was not exercised")
if bad == 0 then print("PARALLEL OK " .. checks .. " checkpoints") else print("PARALLEL FAIL " .. bad .. "/" .. checks) end
end
end
end)
+32
View File
@@ -0,0 +1,32 @@
-- Two contexts sharing one font atlas (one backend module): new glyphs baked while B is current used to hit
-- UpdateTexture's assert (per-context texture tables). Textures are now module-wide.
-- run: python3 tools/test/run.py --main tools/test/scripts/t_pool_ctx.luau --frames 60 --quiet --roblox
local G = require(game:GetService("ReplicatedStorage"):WaitForChild("ImGui"))
local ImGui, ImVec2 = G.ImGui, G.ImVec2
local Impl = G.ImGui_ImplRoblox
local a = ImGui.CreateContext(); ImGui.SetCurrentContext(a); Impl.Init(); Impl.SetRenderRate(0)
local b = ImGui.CreateContext(ImGui.GetIO().Fonts); ImGui.SetCurrentContext(b); Impl.Init(); Impl.SetRenderRate(0)
local function frame(ctx, body)
ImGui.SetCurrentContext(ctx)
Impl.NewFrame(); ImGui.GetIO().DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always); ImGui.SetNextWindowSize(ImVec2(900, 700), G.ImGuiCond.Always)
ImGui.Begin("W"); body(); ImGui.End()
ImGui.Render(); Impl.RenderDrawData(ImGui.GetDrawData())
end
local n = 0
game:GetService("RunService").Stepped:Connect(function()
n += 1
if n > 60 then return end
frame(a, function() ImGui.Text("context A"); if n == 20 then ImGui.PushFont(nil, 33); ImGui.Text("Glyphs baked under A"); ImGui.PopFont() end end)
frame(b, function()
if n == 5 then ImGui.PushFont(nil, 41); ImGui.Text("Big glyphs baked under B"); ImGui.PopFont() end
ImGui.Text("context B")
end)
if n == 60 then
assert(Impl.GetStats().Tiles > 0)
print("POOLCTX OK")
end
end)
+49
View File
@@ -0,0 +1,49 @@
-- Scrolling a long child window must not leak tiles: scrolled-away tiles are freed (recycled), so the live tile count
-- stays bounded by what is on screen. Then with a tiny EditableImage cap (SetEditableImageCap): tiles that don't fit
-- are skipped (GetTile -> nil, no assert) and the budget is never exceeded.
-- run: python3 tools/test/run.py --main tools/test/scripts/t_tile_bound.luau --frames 200 --quiet --roblox
local G = require(game:GetService("ReplicatedStorage"):WaitForChild("ImGui"))
local ImGui, ImVec2 = G.ImGui, G.ImVec2
local Impl = G.ImGui_ImplRoblox
ImGui.CreateContext()
Impl.Init()
Impl.SetRenderRate(0)
local io = ImGui.GetIO()
local P = 100 -- frames per phase
local frame, peak = 0, 0
local TILE_BYTES = 128 * 128 * 4
game:GetService("RunService").Stepped:Connect(function()
frame += 1
if frame > 2 * P then return end
local t = (frame - 1) % P + 1
if frame == P + 1 then Impl.SetEditableImageCap(10 * TILE_BYTES); Impl.SetRenderScale(2) end -- (rebuild: shown tiles are never evicted)
Impl.NewFrame()
io.DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(20, 20), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(400, 400), G.ImGuiCond.Always)
ImGui.Begin("Scroll")
ImGui.BeginChild("long", ImVec2(0, 0), G.ImGuiChildFlags.Borders)
for i = 1, 3000 do ImGui.Text("row %d some text to fill the tile width ........", i) end
ImGui.SetScrollY(t * 300) -- ~30k px per phase: hundreds of distinct tiles if never freed
ImGui.EndChild()
ImGui.End()
ImGui.Render()
Impl.RenderDrawData(ImGui.GetDrawData())
local s = Impl.GetStats()
if frame <= P or t > 1 then assert(s.EditableImageBytes <= s.EditableImageCap, "over the EditableImage budget") end -- (the free list drains on the next create)
assert(s.EditableImages >= s.Tiles)
if frame <= P and t > 20 then peak = math.max(peak, s.Tiles) end
if frame == P then
print(("raster: peak tiles %d, now %d tiles, %d EditableImages, %d Instances"):format(peak, s.Tiles, s.EditableImages, s.Instances))
-- a 400x400 window covers ~4x4 tiles per layer (+1 row/col when unaligned) + a few spares
assert(peak <= 60, "tile count not bounded by what is on screen")
end
if frame == 2 * P then
print(("capped: %d tiles, %d EditableImages, %d / %d bytes"):format(s.Tiles, s.EditableImages, s.EditableImageBytes, s.EditableImageCap))
assert(s.EditableImages <= 10)
Impl.SetEditableImageCap(nil)
print("TILEBOUND OK")
end
end)