75 lines
2.5 KiB
Go
75 lines
2.5 KiB
Go
package generator
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestWGPUMoveSquare(t *testing.T) {
|
|
const width, height = 1920, 1080
|
|
g, err := NewWGPUGenerator(width, height, filepath.Join("..", "..", "kernels", "v210_bars_move.wgsl"))
|
|
if err != nil {
|
|
t.Fatalf("init: %v", err)
|
|
}
|
|
defer g.Close()
|
|
|
|
buf := make([]byte, width*height*8/3)
|
|
sample := func(x, y int) (yc, cb, cr uint32) {
|
|
p := y*width + x
|
|
off := (p / 6) * 16
|
|
w0 := binary.LittleEndian.Uint32(buf[off:])
|
|
w1 := binary.LittleEndian.Uint32(buf[off+4:])
|
|
w2 := binary.LittleEndian.Uint32(buf[off+8:])
|
|
w3 := binary.LittleEndian.Uint32(buf[off+12:])
|
|
switch p % 6 {
|
|
case 0:
|
|
return (w0 >> 10) & 0x3FF, w0 & 0x3FF, (w0 >> 20) & 0x3FF
|
|
case 1:
|
|
return w1 & 0x3FF, w0 & 0x3FF, (w0 >> 20) & 0x3FF
|
|
case 2:
|
|
return (w1 >> 20) & 0x3FF, (w1 >> 10) & 0x3FF, w2 & 0x3FF
|
|
case 3:
|
|
return (w2 >> 10) & 0x3FF, (w1 >> 10) & 0x3FF, w2 & 0x3FF
|
|
case 4:
|
|
return w3 & 0x3FF, (w2 >> 20) & 0x3FF, (w3 >> 10) & 0x3FF
|
|
default:
|
|
return (w3 >> 20) & 0x3FF, (w2 >> 20) & 0x3FF, (w3 >> 10) & 0x3FF
|
|
}
|
|
}
|
|
|
|
// square center x=960 sits on the green bar (534/253/207):
|
|
// inverted -> Y=1004-534=470, Cb=1024-253=771, Cr=1024-207=817
|
|
const invY, invCb, invCr = 470, 771, 817
|
|
const greenY = 534 // bar 3 covers x in [823,1098)
|
|
|
|
// tick 0: offset = 0, square centered at (960,540), half = 75
|
|
if err := g.GenerateFrame(buf, 0); err != nil {
|
|
t.Fatalf("tick 0: %v", err)
|
|
}
|
|
if y, cb, cr := sample(960, 540); y != invY || cb != invCb || cr != invCr {
|
|
t.Fatalf("tick 0 center: got %d/%d/%d, want inverted green 470/771/817", y, cb, cr)
|
|
}
|
|
if y, _, _ := sample(860, 540); y != greenY {
|
|
t.Fatalf("tick 0 left of square: Y=%d, want green %d", y, greenY)
|
|
}
|
|
|
|
// amplitude = centerX - half = 885: tick 79 (sin~1) puts the square at
|
|
// the far right, x in [1770,1920), over the blue bar (111/848/481):
|
|
// inverted -> Y=1004-111=893, Cb=1024-848=176, Cr=1024-481=543
|
|
const invBlueY, invBlueCb, invBlueCr = 893, 176, 543
|
|
if err := g.GenerateFrame(buf, 79); err != nil {
|
|
t.Fatalf("tick 79: %v", err)
|
|
}
|
|
if y, cb, cr := sample(1840, 540); y != invBlueY || cb != invBlueCb || cr != invBlueCr {
|
|
t.Fatalf("tick 79 shifted center: got %d/%d/%d, want inverted blue 893/176/543", y, cb, cr)
|
|
}
|
|
if y, _, _ := sample(960, 540); y != greenY {
|
|
t.Fatalf("tick 79 old center: Y=%d, want green %d (square moved away)", y, greenY)
|
|
}
|
|
// bars untouched far from the square
|
|
if y, _, _ := sample(100, 100); y != 721 {
|
|
t.Fatalf("tick 79 bars: Y=%d, want white 721", y)
|
|
}
|
|
}
|