@@ -5,19 +5,22 @@ import chisel3._
5
5
import chisel3 .util ._
6
6
7
7
object Tile {
8
- val width = 32
8
+ val size = 16
9
9
10
- val nrRows = (Fb .width + width - 1 ) / width * width
11
- val nrCols = (Fb .height + width - 1 ) / width * width
10
+ val nrCols = (Fb .width + size - 1 ) / size
11
+ val nrRows = (Fb .height + size - 1 ) / size
12
+
13
+ val width = nrCols * size
14
+ val height = nrRows * size
15
+
16
+ def apply () = new Tile
12
17
}
13
18
14
19
class Tile extends Bundle {
15
- val elem = Vec (Tile .width , Vec (Tile .width , FbRGB ()))
20
+ val elem = Vec (Tile .size , Vec (Tile .size , FbRGB ()))
16
21
17
- def apply (i : Int , j : Int ) = elem(i)(j)
18
- def apply (i : Int , j : UInt ) = elem(i)(j)
19
- def apply (i : UInt , j : Int ) = elem(i)(j)
20
- def apply (i : UInt , j : UInt ) = elem(i)(j)
22
+ def apply (idx : Int ) = elem(idx)
23
+ def apply (idx : UInt ) = elem(idx)
21
24
}
22
25
23
26
class TileBuffer extends Module {
@@ -26,5 +29,55 @@ class TileBuffer extends Module {
26
29
val outReq = Irrevocable (new FbWrReq )
27
30
})
28
31
32
+ val buf = SyncReadMem (2 * Tile .nrCols, Tile ())
33
+ val fron = RegInit (0 .U (log2Up(buf.length).W ))
34
+ val rear = RegInit (0 .U (log2Up(buf.length).W ))
35
+ val size = RegInit (0 .U (unsignedBitLength(buf.length).W ))
36
+
37
+ val nextRear = Mux (rear =/= (buf.length - 1 ).U , rear + 1 .U , 0 .U )
38
+ val full = nextRear === fron
39
+ io.inReq.ready := ! full
40
+ when (! full && io.inReq.valid) {
41
+ buf.write(rear, io.inReq.bits)
42
+ rear := nextRear
43
+ size := size + 1 .U
44
+ }
29
45
46
+ val col = RegInit (0 .U (log2Up(Tile .nrCols).W ))
47
+ val row = RegInit (0 .U (log2Up(Tile .size).W ))
48
+ val idx = RegInit (0 .U (log2Up(Tile .size / Fb .nrBanks).W ))
49
+ val nextFron = WireDefault (fron)
50
+ val nextCol = WireDefault (col)
51
+ val nextRow = WireDefault (row)
52
+ val nextIdx = WireDefault (idx)
53
+ val writing = size >= Tile .nrCols.U
54
+ io.outReq.valid := writing
55
+ val pix = Wire (Vec (Fb .nrBanks, FbRGB ()))
56
+ for (i <- 0 until Fb .nrBanks) {
57
+ pix(i) := buf.read(nextFron + nextCol)(nextRow)(nextIdx << log2Up(Fb .nrBanks) | i.U )
58
+ }
59
+ io.outReq.bits.pix := pix
60
+ when (writing && io.outReq.ready) {
61
+ nextIdx := idx + 1 .U
62
+ idx := nextIdx
63
+ when (idx === (Tile .size / Fb .nrBanks - 1 ).U ) {
64
+ nextIdx := 0 .U
65
+ nextCol := col + 1 .U
66
+ col := nextCol
67
+ when (col === (Tile .nrCols - 1 ).U ) {
68
+ nextCol := 0 .U
69
+ nextRow := row + 1 .U
70
+ row := nextRow
71
+ when (row === (Tile .size - 1 ).U ) {
72
+ row := 0 .U
73
+ nextFron := fron + Tile .nrCols.U
74
+ fron := nextFron
75
+ when (fron === (buf.length - Tile .nrCols).U ) {
76
+ nextFron := 0 .U
77
+ }
78
+ size := size - Tile .nrCols.U
79
+ }
80
+ }
81
+ }
82
+ }
30
83
}
0 commit comments