Skip to content

Commit

Permalink
Use differential information to generate pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjian85 committed Nov 12, 2023
1 parent a77820c commit 0a47078
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 99 deletions.
93 changes: 55 additions & 38 deletions src/main/scala/graphics/DiffInfo.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import chisel3._

object DiffInfo {
def build(p0: (Int, Int), p1: (Int, Int), p2: (Int, Int)) = {
val diffInfo = Wire(new DiffInfo)

val dx0 = p1._1 - p0._1
val dx1 = p2._1 - p1._1
val dx2 = p0._1 - p2._1
diffInfo.dx0 := dx0.S
diffInfo.dx1 := dx1.S
diffInfo.dx2 := dx2.S

val dy0 = p0._2 - p1._2
val dy1 = p1._2 - p2._2
val dy2 = p2._2 - p0._2
diffInfo.dy0 := dy0.S
diffInfo.dy1 := dy1.S
diffInfo.dy2 := dy2.S

diffInfo.dj0 := (-dy0).S // The negate operator of SInt is broken, WTF???
diffInfo.dj1 := (-dy1).S
diffInfo.dj2 := (-dy2).S

diffInfo.di0 := (-dx0 + dy0 * (Tile.size - 1)).S
diffInfo.di1 := (-dx1 + dy1 * (Tile.size - 1)).S
diffInfo.di2 := (-dx2 + dy2 * (Tile.size - 1)).S

diffInfo.dc0 := ((-dy0 + dx0) * Tile.size).S
diffInfo.dc1 := ((-dy1 + dx1) * Tile.size).S
diffInfo.dc2 := ((-dy2 + dx2) * Tile.size).S

diffInfo.dr0 := (dy0 * (Tile.nrCols - 1) * Tile.size).S
diffInfo.dr1 := (dy1 * (Tile.nrCols - 1) * Tile.size).S
diffInfo.dr2 := (dy2 * (Tile.nrCols - 1) * Tile.size).S

val e0 = dx0 * p0._2 + dy0 * p0._1
val e1 = dx1 * p1._2 + dy1 * p1._1
Expand Down Expand Up @@ -99,15 +108,23 @@ class DiffInfo extends Bundle {
val e1 = SInt(32.W)
val e2 = SInt(32.W)

val dx0 = SInt(32.W)
val dx1 = SInt(32.W)
val dx2 = SInt(32.W)
val dj0 = SInt()
val dj1 = SInt()
val dj2 = SInt()

val di0 = SInt()
val di1 = SInt()
val di2 = SInt()

val dc0 = SInt()
val dc1 = SInt()
val dc2 = SInt()

val dy0 = SInt(32.W)
val dy1 = SInt(32.W)
val dy2 = SInt(32.W)
val dr0 = SInt()
val dr1 = SInt()
val dr2 = SInt()

val a = SInt(32.W)
val a = SInt()

val r = SInt(32.W)
val g = SInt(32.W)
Expand All @@ -117,35 +134,35 @@ class DiffInfo extends Bundle {
val eg = SInt(32.W)
val eb = SInt(32.W)

val dquorj = SInt(32.W)
val dquogj = SInt(32.W)
val dquobj = SInt(32.W)
val dquorj = SInt()
val dquogj = SInt()
val dquobj = SInt()

val dremrj = SInt(32.W)
val dremgj = SInt(32.W)
val drembj = SInt(32.W)
val dremrj = SInt()
val dremgj = SInt()
val drembj = SInt()

val dquori = SInt(32.W)
val dquogi = SInt(32.W)
val dquobi = SInt(32.W)
val dquori = SInt()
val dquogi = SInt()
val dquobi = SInt()

val dremri = SInt(32.W)
val dremgi = SInt(32.W)
val drembi = SInt(32.W)
val dremri = SInt()
val dremgi = SInt()
val drembi = SInt()

val dquorc = SInt(32.W)
val dquogc = SInt(32.W)
val dquobc = SInt(32.W)
val dquorc = SInt()
val dquogc = SInt()
val dquobc = SInt()

val dremrc = SInt(32.W)
val dremgc = SInt(32.W)
val drembc = SInt(32.W)
val dremrc = SInt()
val dremgc = SInt()
val drembc = SInt()

val dquorr = SInt(32.W)
val dquogr = SInt(32.W)
val dquobr = SInt(32.W)
val dquorr = SInt()
val dquogr = SInt()
val dquobr = SInt()

val dremrr = SInt(32.W)
val dremgr = SInt(32.W)
val drembr = SInt(32.W)
val dremrr = SInt()
val dremgr = SInt()
val drembr = SInt()
}
73 changes: 12 additions & 61 deletions src/main/scala/graphics/Graphics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ class Graphics extends Module {
val e0 = RegInit(diffInfos(0).e0)
val e1 = RegInit(diffInfos(0).e1)
val e2 = RegInit(diffInfos(0).e2)
val ie0 = RegInit(diffInfos(0).e0)
val ie1 = RegInit(diffInfos(0).e1)
val ie2 = RegInit(diffInfos(0).e2)
val ce0 = RegInit(diffInfos(0).e0)
val ce1 = RegInit(diffInfos(0).e1)
val ce2 = RegInit(diffInfos(0).e2)
val re0 = RegInit(diffInfos(0).e0)
val re1 = RegInit(diffInfos(0).e1)
val re2 = RegInit(diffInfos(0).e2)

val r = RegInit(diffInfos(0).r)
val g = RegInit(diffInfos(0).g)
Expand All @@ -85,15 +76,6 @@ class Graphics extends Module {
e0 := diffInfos(angle).e0
e1 := diffInfos(angle).e1
e2 := diffInfos(angle).e2
ie0 := diffInfos(angle).e0
ie1 := diffInfos(angle).e1
ie2 := diffInfos(angle).e2
ce0 := diffInfos(angle).e0
ce1 := diffInfos(angle).e1
ce2 := diffInfos(angle).e2
re0 := diffInfos(angle).e0
re1 := diffInfos(angle).e1
re2 := diffInfos(angle).e2

r := diffInfos(angle).r
g := diffInfos(angle).g
Expand All @@ -112,20 +94,9 @@ class Graphics extends Module {
when (valid && tileWriter.io.inReq.ready) {
valid := false.B

val ne0 = ce0 - diffInfo.dy0 * Tile.size.S
e0 := ne0
ie0 := ne0
ce0 := ne0

val ne1 = ce1 - diffInfo.dy1 * Tile.size.S
e1 := ne1
ie1 := ne1
ce1 := ne1

val ne2 = ce2 - diffInfo.dy2 * Tile.size.S
e2 := ne2
ie2 := ne2
ce2 := ne2
e0 := e0 + diffInfo.dc0
e1 := e1 + diffInfo.dc1
e2 := e2 + diffInfo.dc2

val (rquo, rrem) = incrDiv(diffInfo.dquorc, diffInfo.dremrc, diffInfo.a, r, er)
r := rquo
Expand All @@ -142,23 +113,9 @@ class Graphics extends Module {
col := col + 1.U

when (col === (Tile.nrCols - 1).U) {
val ne0 = re0 - diffInfo.dx0 * Tile.size.S
e0 := ne0
ie0 := ne0
ce0 := ne0
re0 := ne0

val ne1 = re1 - diffInfo.dx1 * Tile.size.S
e1 := ne1
ie1 := ne1
ce1 := ne1
re1 := ne1

val ne2 = re2 - diffInfo.dx2 * Tile.size.S
e2 := ne2
ie2 := ne2
ce2 := ne2
re2 := ne2
e0 := e0 + diffInfo.dr0
e1 := e1 + diffInfo.dr1
e2 := e2 + diffInfo.dr2

val (rquo, rrem) = incrDiv(diffInfo.dquorr, diffInfo.dremrr, diffInfo.a, r, er)
r := rquo
Expand Down Expand Up @@ -187,9 +144,9 @@ class Graphics extends Module {

j := j + 1.U

e0 := e0 - diffInfo.dy0
e1 := e1 - diffInfo.dy1
e2 := e2 - diffInfo.dy2
e0 := e0 + diffInfo.dj0
e1 := e1 + diffInfo.dj1
e2 := e2 + diffInfo.dj2

val (rquo, rrem) = incrDiv(diffInfo.dquorj, diffInfo.dremrj, diffInfo.a, r, er)
r := rquo
Expand All @@ -207,15 +164,9 @@ class Graphics extends Module {
j := 0.U
i := i + 1.U

val ne0 = ie0 - diffInfo.dx0
e0 := ne0
ie0 := ne0
val ne1 = ie1 - diffInfo.dx1
e1 := ne1
ie1 := ne1
val ne2 = ie2 - diffInfo.dx2
e2 := ne2
ie2 := ne2
e0 := e0 + diffInfo.di0
e1 := e1 + diffInfo.di1
e2 := e2 + diffInfo.di2

val (rquo, rrem) = incrDiv(diffInfo.dquori, diffInfo.dremri, diffInfo.a, r, er)
r := rquo
Expand Down

0 comments on commit 0a47078

Please sign in to comment.