diff --git a/programs/roulette.lua b/programs/roulette.lua index 6984edd..6c1447a 100644 --- a/programs/roulette.lua +++ b/programs/roulette.lua @@ -43,16 +43,30 @@ local function findGPU() end local function makeGpuBackend(gpu) + -- refreshSize() is async: it schedules the monitor-wall scan on the + -- server thread and returns immediately. Poll until blocksX or + -- blocksY grows, or we time out (2 s). gpu.refreshSize() - -- Try a high per-block resolution; older/cheaper GPU tiers may cap - -- this so fall back if it errors. + local pw, ph, bx, by, sb + local deadline = os.clock() + 2 + repeat + sleep(0.1) + pw, ph, bx, by, sb = gpu.getSize() + until ((bx or 0) > 1 or (by or 0) > 1) or os.clock() >= deadline + + -- If still 1x1 try once more after a longer wait, then proceed anyway. + if (bx or 0) <= 1 and (by or 0) <= 1 then + sleep(0.5) + pw, ph, bx, by, sb = gpu.getSize() + end + + -- Try a high per-block resolution; fall back if GPU tier caps it. local trySizes = { 64, 32, 16, 8 } for _, s in ipairs(trySizes) do if pcall(gpu.setSize, s) then break end end - - -- getSize() returns: pixelW, pixelH, blocksX, blocksY, sizePerBlock - local pw, ph, bx, by, sb = gpu.getSize() + -- Re-read size after setSize (pixel dimensions change). + pw, ph, bx, by, sb = gpu.getSize() print(("[roulette] GPU pixel size: %sx%s blocks: %sx%s per-block: %s") :format(tostring(pw), tostring(ph), tostring(bx), tostring(by), tostring(sb)))