gpu,gpu/internal: support variable strides in ReadPixels

It saves a roundtrip to scratch memory when the CPU fallback renderer
downloads rendered materials.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-08-26 19:18:29 +02:00
parent 06ffa42d16
commit 7f6e376424
6 changed files with 25 additions and 23 deletions
+1 -11
View File
@@ -95,7 +95,6 @@ type compute struct {
frag struct {
buf driver.Buffer
}
scratch []byte
}
timers struct {
profile string
@@ -1006,20 +1005,11 @@ func (g *compute) renderMaterials() error {
copyFBO := atlas.fbo
data := atlas.cpuImage.Data()
for _, r := range m.regions {
dims := r.Size()
if n := dims.X * dims.Y * 4; n > len(m.scratch) {
m.scratch = make([]byte, n)
}
copyFBO.ReadPixels(r, m.scratch)
stride := atlas.size.X * 4
col := r.Min.X * 4
row := stride * r.Min.Y
off := col + row
w := dims.X * 4
for y := 0; y < dims.Y; y++ {
copy(data[off:off+w], m.scratch[y*dims.X*4:])
off += stride
}
copyFBO.ReadPixels(r, data[off:], stride)
}
}
return nil