ws-video-vp8: small copies / fills through readu32 / writeu32 (buffer.copy of 4-16 bytes costs ~45 ns in Luau)
This commit is contained in:
1 parent
087e1c861e
commit
828389b643
2 files changed
+66
-26
No files matched your search
@@ -21,6 +21,7 @@ local Predict = require("@formats/codecs/Vp8/Predict")
|
||||
|
||||
local band, bor, rshift, lshift = bit32.band, bit32.bor, bit32.rshift, bit32.lshift
|
||||
local readu8, writeu8, readi16, writei16 = buffer.readu8, buffer.writeu8, buffer.readi16, buffer.writei16
|
||||
local readu32, writeu32 = buffer.readu32, buffer.writeu32
|
||||
local bfill, bcopy, bcreate = buffer.fill, buffer.copy, buffer.create
|
||||
local abs = math.abs
|
||||
|
||||
@@ -520,7 +521,10 @@ end
|
||||
-- prediction: modes 0 DC, 1 TM, 2 VE, 3 HE; 4 DC no top, 5 DC no left, 6 DC no top-left (16x16 and chroma)
|
||||
local function fill(b: buffer, dst: number, size: number, v: number)
|
||||
for j = 0, size - 1 do
|
||||
bfill(b, dst + j * BPS, v, size)
|
||||
local o = dst + j * BPS
|
||||
for i = o, o + size - 4, 4 do
|
||||
writeu32(b, i, v * 0x01010101)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -547,11 +551,18 @@ local function predictBlock(b: buffer, dst: number, size: number, mode: number)
|
||||
trueMotion(b, dst, size)
|
||||
elseif mode == 2 then
|
||||
for j = 0, size - 1 do
|
||||
bcopy(b, dst + j * BPS, b, dst - BPS, size)
|
||||
local o = dst + j * BPS
|
||||
for i = 0, size - 4, 4 do
|
||||
writeu32(b, o + i, readu32(b, dst - BPS + i))
|
||||
end
|
||||
end
|
||||
elseif mode == 3 then
|
||||
for j = 0, size - 1 do
|
||||
bfill(b, dst + j * BPS, readu8(b, dst + j * BPS - 1), size)
|
||||
local o = dst + j * BPS
|
||||
local v = readu8(b, o - 1) * 0x01010101
|
||||
for i = o, o + size - 4, 4 do
|
||||
writeu32(b, i, v)
|
||||
end
|
||||
end
|
||||
elseif mode == 4 then -- no top: left samples
|
||||
local dc = size // 2
|
||||
@@ -600,10 +611,10 @@ local function predict4(b: buffer, dst: number, mode: number)
|
||||
elseif mode == 3 then
|
||||
local A, B, C, D = readu8(b, dst - 1 - BPS), readu8(b, dst - 1), readu8(b, dst - 1 + BPS), readu8(b, dst - 1 + 2 * BPS)
|
||||
local E = readu8(b, dst - 1 + 3 * BPS)
|
||||
bfill(b, dst, avg3(A, B, C), 4)
|
||||
bfill(b, dst + BPS, avg3(B, C, D), 4)
|
||||
bfill(b, dst + 2 * BPS, avg3(C, D, E), 4)
|
||||
bfill(b, dst + 3 * BPS, avg3(D, E, E), 4)
|
||||
writeu32(b, dst, avg3(A, B, C) * 0x01010101)
|
||||
writeu32(b, dst + BPS, avg3(B, C, D) * 0x01010101)
|
||||
writeu32(b, dst + 2 * BPS, avg3(C, D, E) * 0x01010101)
|
||||
writeu32(b, dst + 3 * BPS, avg3(D, E, E) * 0x01010101)
|
||||
else
|
||||
local I, J, K, L = readu8(b, dst - 1), readu8(b, dst - 1 + BPS), readu8(b, dst - 1 + 2 * BPS), readu8(b, dst - 1 + 3 * BPS)
|
||||
local t = dst - BPS
|
||||
@@ -1773,17 +1784,24 @@ function Decode.decodeFrame(st: State, buf: buffer, off: number, len: number, ma
|
||||
if rf == 0 and mbx > 0 then
|
||||
-- the left context of an intra macroblock: the previous macroblock's last columns
|
||||
for j = -1, 15 do
|
||||
bcopy(yuv, Y_OFF + j * BPS - 4, yuv, Y_OFF + j * BPS + 12, 4)
|
||||
writeu32(yuv, Y_OFF + j * BPS - 4, readu32(yuv, Y_OFF + j * BPS + 12))
|
||||
end
|
||||
for j = -1, 7 do
|
||||
bcopy(yuv, U_OFF + j * BPS - 4, yuv, U_OFF + j * BPS + 4, 4)
|
||||
bcopy(yuv, V_OFF + j * BPS - 4, yuv, V_OFF + j * BPS + 4, 4)
|
||||
writeu32(yuv, U_OFF + j * BPS - 4, readu32(yuv, U_OFF + j * BPS + 4))
|
||||
writeu32(yuv, V_OFF + j * BPS - 4, readu32(yuv, V_OFF + j * BPS + 4))
|
||||
end
|
||||
end
|
||||
if mby > 0 then
|
||||
bcopy(yuv, Y_OFF - BPS, topY, mbx * 16, 16)
|
||||
bcopy(yuv, U_OFF - BPS, topU, mbx * 8, 8)
|
||||
bcopy(yuv, V_OFF - BPS, topV, mbx * 8, 8)
|
||||
local t = mbx * 16
|
||||
writeu32(yuv, Y_OFF - BPS, readu32(topY, t))
|
||||
writeu32(yuv, Y_OFF - BPS + 4, readu32(topY, t + 4))
|
||||
writeu32(yuv, Y_OFF - BPS + 8, readu32(topY, t + 8))
|
||||
writeu32(yuv, Y_OFF - BPS + 12, readu32(topY, t + 12))
|
||||
t = mbx * 8
|
||||
writeu32(yuv, U_OFF - BPS, readu32(topU, t))
|
||||
writeu32(yuv, U_OFF - BPS + 4, readu32(topU, t + 4))
|
||||
writeu32(yuv, V_OFF - BPS, readu32(topV, t))
|
||||
writeu32(yuv, V_OFF - BPS + 4, readu32(topV, t + 4))
|
||||
end
|
||||
if rf > 0 then
|
||||
-- the prediction (Predict.row): luma rows 0..15, then the chroma rows (U and V side by side)
|
||||
@@ -1801,14 +1819,15 @@ function Decode.decodeFrame(st: State, buf: buffer, off: number, len: number, ma
|
||||
local tr = Y_OFF - BPS + 16
|
||||
if mby > 0 then
|
||||
if mbx >= mbw - 1 then
|
||||
bfill(yuv, tr, readu8(topY, mbx * 16 + 15), 4)
|
||||
writeu32(yuv, tr, readu8(topY, mbx * 16 + 15) * 0x01010101)
|
||||
else
|
||||
bcopy(yuv, tr, topY, mbx * 16 + 16, 4)
|
||||
writeu32(yuv, tr, readu32(topY, mbx * 16 + 16))
|
||||
end
|
||||
end
|
||||
bcopy(yuv, tr + 4 * BPS, yuv, tr, 4)
|
||||
bcopy(yuv, tr + 8 * BPS, yuv, tr, 4)
|
||||
bcopy(yuv, tr + 12 * BPS, yuv, tr, 4)
|
||||
local trv = readu32(yuv, tr)
|
||||
writeu32(yuv, tr + 4 * BPS, trv)
|
||||
writeu32(yuv, tr + 8 * BPS, trv)
|
||||
writeu32(yuv, tr + 12 * BPS, trv)
|
||||
for n = 0, 15 do
|
||||
local dst = Y_OFF + (n % 4) * 4 + (n // 4) * 4 * BPS
|
||||
predict4(yuv, dst, mbModes[mbx * 16 + n + 1])
|
||||
@@ -1831,18 +1850,34 @@ function Decode.decodeFrame(st: State, buf: buffer, off: number, len: number, ma
|
||||
doUVTransform(buv, coeffs, co + 16 * 32, yuv, U_OFF)
|
||||
doUVTransform(rshift(buv, 8), coeffs, co + 20 * 32, yuv, V_OFF)
|
||||
if mby < mbh - 1 then
|
||||
bcopy(topY, mbx * 16, yuv, Y_OFF + 15 * BPS, 16)
|
||||
bcopy(topU, mbx * 8, yuv, U_OFF + 7 * BPS, 8)
|
||||
bcopy(topV, mbx * 8, yuv, V_OFF + 7 * BPS, 8)
|
||||
local t = mbx * 16
|
||||
local r = Y_OFF + 15 * BPS
|
||||
writeu32(topY, t, readu32(yuv, r))
|
||||
writeu32(topY, t + 4, readu32(yuv, r + 4))
|
||||
writeu32(topY, t + 8, readu32(yuv, r + 8))
|
||||
writeu32(topY, t + 12, readu32(yuv, r + 12))
|
||||
t = mbx * 8
|
||||
r = U_OFF + 7 * BPS
|
||||
writeu32(topU, t, readu32(yuv, r))
|
||||
writeu32(topU, t + 4, readu32(yuv, r + 4))
|
||||
writeu32(topV, t, readu32(yuv, r + 16))
|
||||
writeu32(topV, t + 4, readu32(yuv, r + 20))
|
||||
end
|
||||
local yo = yb + mby * 16 * ys + mbx * 16
|
||||
for j = 0, 15 do
|
||||
bcopy(Y, yo + j * ys, yuv, Y_OFF + j * BPS, 16)
|
||||
local d, r = yo + j * ys, Y_OFF + j * BPS
|
||||
writeu32(Y, d, readu32(yuv, r))
|
||||
writeu32(Y, d + 4, readu32(yuv, r + 4))
|
||||
writeu32(Y, d + 8, readu32(yuv, r + 8))
|
||||
writeu32(Y, d + 12, readu32(yuv, r + 12))
|
||||
end
|
||||
local uo = uvb + mby * 8 * uvs + mbx * 8
|
||||
for j = 0, 7 do
|
||||
bcopy(U, uo + j * uvs, yuv, U_OFF + j * BPS, 8)
|
||||
bcopy(V, uo + j * uvs, yuv, V_OFF + j * BPS, 8)
|
||||
local d, r = uo + j * uvs, U_OFF + j * BPS
|
||||
writeu32(U, d, readu32(yuv, r))
|
||||
writeu32(U, d + 4, readu32(yuv, r + 4))
|
||||
writeu32(V, d, readu32(yuv, r + 16))
|
||||
writeu32(V, d + 4, readu32(yuv, r + 20))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
local Tables = require("@formats/codecs/Vp8/Tables")
|
||||
|
||||
local readu8, writeu8, bcopy, bcreate, bfill = buffer.readu8, buffer.writeu8, buffer.copy, buffer.create, buffer.fill
|
||||
local readu32, writeu32 = buffer.readu32, buffer.writeu32
|
||||
local rshift, band = bit32.rshift, bit32.band
|
||||
local SIX, BIL = Tables.SIXTAP, Tables.BILINEAR
|
||||
|
||||
@@ -115,8 +116,12 @@ local function block(src: buffer, stride: number, base: number, wmax: number, hm
|
||||
end
|
||||
if fx == 0 then
|
||||
if fy == 0 then
|
||||
for r = 0, h - 1 do
|
||||
bcopy(dst, d + r * BPS, sb, so + r * ss, w)
|
||||
for _ = 1, h do
|
||||
for i = 0, w - 4, 4 do
|
||||
writeu32(dst, d + i, readu32(sb, so + i))
|
||||
end
|
||||
so += ss
|
||||
d += BPS
|
||||
end
|
||||
elseif bil then
|
||||
bilV(sb, so, ss, dst, d, BPS, w, h, fy)
|
||||
|
||||
Reference in new issue
Block a user