[jak 2] add lightning renderer (#2203)

Implements the jak 2 lightning renderer as an alternate path through
Generic2. Also set up some generic stuff in the goal code.

There is a problem with the texture pool, which doesn't support the case
where two textures have the same tbp, but different cluts. So lightning
is often the wrong color (usually red).
This commit is contained in:
water111
2023-02-09 19:11:13 -05:00
committed by GitHub
parent 722ffa3f19
commit e26efcc4f3
27 changed files with 706 additions and 123 deletions
+56 -8
View File
@@ -372,20 +372,68 @@
)
(cond
((zero? a1-1)
(set! (-> v1-3 base-strgif qword vector4w y) #x303e4000)
(set! (-> v1-3 base-strgif qword vector4w x) #x303ec000)
(set! (-> v1-3 base-strgif str-prim)
(new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :fge #x1 :abe #x1)
:nreg #x3
)
)
(set! (-> v1-3 base-strgif fan-prim)
(new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :iip #x1 :tme #x1 :fge #x1 :abe #x1)
:nreg #x3
)
)
)
((= a1-1 1)
(set! (-> v1-3 base-strgif qword vector4w y) #x303d4000)
(set! (-> v1-3 base-strgif qword vector4w x) #x303d4000)
(set! (-> v1-3 base-strgif str-prim)
(new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type line-strip) :iip #x1 :tme #x1 :fge #x1 :abe #x1)
:nreg #x3
)
)
(set! (-> v1-3 base-strgif fan-prim)
(new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type line-strip) :iip #x1 :tme #x1 :fge #x1 :abe #x1)
:nreg #x3
)
)
)
((= a1-1 2)
(set! (-> v1-3 base-strgif qword vector4w y) #x30364000)
(set! (-> v1-3 base-strgif qword vector4w x) #x3036c000)
(set! (-> v1-3 base-strgif str-prim)
(new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :fge #x1 :abe #x1)
:nreg #x3
)
)
(set! (-> v1-3 base-strgif fan-prim)
(new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :iip #x1 :fge #x1 :abe #x1)
:nreg #x3
)
)
)
((= a1-1 3)
(set! (-> v1-3 base-strgif qword vector4w y) #x30354000)
(set! (-> v1-3 base-strgif qword vector4w x) #x3036c000)
(set! (-> v1-3 base-strgif str-prim)
(new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type line-strip) :iip #x1 :fge #x1 :abe #x1)
:nreg #x3
)
)
(set! (-> v1-3 base-strgif fan-prim)
(new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :iip #x1 :fge #x1 :abe #x1)
:nreg #x3
)
)
)
)
)
+8 -8
View File
@@ -392,12 +392,12 @@
;; definition of type generic-gif-tag
(deftype generic-gif-tag (structure)
((data uint32 4 :offset-assert 0)
(qword qword :inline :offset 0)
(fan-prim uint32 :offset 0)
(str-prim uint32 :offset 4)
(regs uint32 :offset 8)
(num-strips uint32 :offset 12)
((data uint32 4 :offset-assert 0)
(qword qword :inline :offset 0)
(fan-prim gif-tag-prim :offset 0)
(str-prim gif-tag-prim :offset 4)
(regs gif-tag-regs-32 :offset 8)
(num-strips uint32 :offset 12)
)
:method-count-assert 9
:size-assert #x10
@@ -411,8 +411,8 @@
(goto cfg-4)
)
(format #t "[~8x] ~A~%" obj 'generic-gif-tag)
(format #t "~1Tdata[4] @ #x~X~%" (-> obj data))
(format #t "~1Tqword: #<qword @ #x~X>~%" (-> obj data))
(format #t "~1Tdata[4] @ #x~X~%" (&-> obj fan-prim))
(format #t "~1Tqword: #<qword @ #x~X>~%" (&-> obj fan-prim))
(format #t "~1Tfan-prim: ~D~%" (-> obj fan-prim))
(format #t "~1Tstr-prim: ~D~%" (-> obj str-prim))
(format #t "~1Tregs: ~D~%" (-> obj regs))
+9 -2
View File
@@ -740,7 +740,12 @@ bits 5 and 6 (0x20 and 0x40) should be zero"
;; definition of type gif-tag-prim
(deftype gif-tag-prim (uint32)
()
((id uint16 :offset 0 :size 14)
(pre uint8 :offset 14 :size 1)
(prim gs-prim :offset 15 :size 11)
(flg gif-flag :offset 26 :size 2)
(nreg uint8 :offset 28 :size 4)
)
:method-count-assert 9
:size-assert #x4
:flag-assert #x900000004
@@ -748,7 +753,9 @@ bits 5 and 6 (0x20 and 0x40) should be zero"
;; definition of type gif-tag-count
(deftype gif-tag-count (uint32)
()
((nloop uint16 :offset 0 :size 15)
(eop uint8 :offset 15 :size 1)
)
:method-count-assert 9
:size-assert #x4
:flag-assert #x900000004
+15 -4
View File
@@ -13,7 +13,19 @@
;; definition for symbol *lightning-gcf*, type gcf-control
(define *lightning-gcf*
(new 'static 'gcf-control
:giftag (new 'static 'generic-gif-tag :data (new 'static 'array uint32 4 #x302ec000 #x302e4000 #x412 #x0))
:giftag (new 'static 'generic-gif-tag
:fan-prim (new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :iip #x1 :tme #x1 :abe #x1)
:nreg #x3
)
:str-prim (new 'static 'gif-tag-prim
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :abe #x1)
:nreg #x3
)
:regs (new 'static 'gif-tag-regs-32 :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyzf2))
)
:adnops (new 'static 'inline-array gs-adcmd 2
(new 'static 'gs-adcmd :word (new 'static 'array uint32 4 #x0 #x0 #x7f #x0))
(new 'static 'gs-adcmd :word (new 'static 'array uint32 4 #x0 #x0 #x7f #x0))
@@ -728,7 +740,7 @@
(set! (-> v1-86 trans quad) a3-32)
)
(quad-copy! (the-as pointer (-> sv-176 giftag)) (the-as pointer (-> s1-0 giftag)) 3)
(set! (-> sv-176 giftag qword vector4w w) 1)
(set! (-> sv-176 giftag num-strips) (the-as uint 1))
(set! (-> sv-176 num-dps) (the-as uint (* sv-144 2)))
(set! (-> sv-176 kick-offset) (the-as uint 0))
(adgif-shader<-texture-simple! (the-as adgif-shader (-> sv-176 shader)) sv-32)
@@ -848,8 +860,7 @@
;; definition for function lightning-draw-all
;; WARN: Return type mismatch int vs none.
;; WARN: Failed store: (s.w! (+ v1-31 8) 0) at op 89
;; WARN: Failed store: (s.w! (+ v1-31 12) 0) at op 90
;; ERROR: Failed store: (s.w! (+ v1-31 8) 0) at op 89
(defun lightning-draw-all ()
(when (and *lightning* (not (-> *blit-displays-work* menu-mode)))
(when (logtest? (-> *display* vu1-enable-user) (vu1-renderer-mask generic))
+26 -33
View File
@@ -427,10 +427,9 @@
;; definition for function draw-prototype-inline-array-shrub
;; INFO: Used lq/sq
;; ERROR: Function may read a register that is not set: a2
;; ERROR: Failed load: (set! a2-26 (l.d (+ a0-26 96))) at op 223
(defun draw-prototype-inline-array-shrub ((proto-array-len int) (proto-array (inline-array prototype-bucket-shrub)))
(local-vars
(dma-ptr object)
(sv-16 drawable)
(sv-32 uint)
(sv-48 int)
@@ -456,22 +455,18 @@
)
(&+! (-> a0-6 base) 16)
)
(set! dma-ptr
(when (nonzero? (-> v1-0 count 2))
(let ((a2-7 (-> a0-6 base)))
(set! (-> (the-as (pointer uint128) a2-7)) (-> *instance-shrub-work* count-tmpl (-> v1-0 mod-count 2) quad))
(set! (-> (the-as (pointer uint64) a2-7))
(logior (logand (-> (the-as (pointer uint64) a2-7)) (the-as uint #x80000000ffffffff))
(shr (shl (-> v1-0 next 2) 33) 1)
)
)
(set! (-> v1-0 next 2) (the-as uint a2-7))
(when (nonzero? (-> v1-0 count 2))
(let ((a2-7 (-> a0-6 base)))
(set! (-> (the-as (pointer uint128) a2-7)) (-> *instance-shrub-work* count-tmpl (-> v1-0 mod-count 2) quad))
(set! (-> (the-as (pointer uint64) a2-7))
(logior (logand (-> (the-as (pointer uint64) a2-7)) (the-as uint #x80000000ffffffff))
(shr (shl (-> v1-0 next 2) 33) 1)
)
)
(set! dma-ptr (&+ (-> a0-6 base) 16))
(set! (-> a0-6 base) (the-as pointer dma-ptr))
dma-ptr
)
)
(set! (-> v1-0 next 2) (the-as uint a2-7))
)
(&+! (-> a0-6 base) 16)
)
(&+! v1-0 112)
)
)
@@ -481,7 +476,7 @@
(let* ((s2-0 (-> *display* frames (-> *display* on-screen) global-buf))
(s3-0 (-> s2-0 base))
)
(generic-init-buf s2-0 #x1000130 (the-as gs-zbuf dma-ptr))
(generic-init-buf s2-0 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24)))
(generic-add-shrub-constants s2-0 #x5026b 60 61)
(let ((a0-14
(the-as
@@ -493,11 +488,11 @@
(a1-7 (the-as object (+ (-> *instance-shrub-work* near-last) 176)))
)
(set! (-> a0-14 init-tmpl dma addr) (-> *instance-shrub-work* near-next))
(let ((a2-13 (-> a0-14 init-tmpl quad))
(let ((a2-14 (-> a0-14 init-tmpl quad))
(a3-18 (-> a0-14 init-data 0 quad))
(a0-15 (-> a0-14 init-data 1 quad))
)
(set! (-> (the-as vector4w-3 v1-23) vector 0 quad) a2-13)
(set! (-> (the-as vector4w-3 v1-23) vector 0 quad) a2-14)
(set! (-> (the-as vector4w-3 v1-23) vector 1 quad) a3-18)
(set! (-> (the-as vector4w-3 v1-23) vector 2 quad) a0-15)
)
@@ -517,7 +512,6 @@
(a0-18 (-> *display* frames (-> *display* on-screen) bucket-group))
(v1-32 *draw-index*)
)
(set! dma-ptr s3-0)
(t9-2
a0-18
(cond
@@ -540,7 +534,7 @@
(bucket-id shrub-n-l5-shrub)
)
)
(the-as pointer dma-ptr)
s3-0
(the-as (pointer dma-tag) a3-19)
)
)
@@ -551,10 +545,9 @@
(set! (-> v1-33 length) (max 28 (-> v1-33 length)))
(set! (-> v1-33 data 27 name) "shrubbery")
(+! (-> v1-33 data 27 count) 1)
(let ((a1-19 (-> v1-33 data 27 used)))
(set! dma-ptr (&- (-> *display* frames (-> *display* on-screen) global-buf base) (the-as uint s4-0)))
(set! (-> v1-33 data 27 used) (+ a1-19 (the-as int dma-ptr)))
)
(+! (-> v1-33 data 27 used)
(&- (-> *display* frames (-> *display* on-screen) global-buf base) (the-as uint s4-0))
)
(set! (-> v1-33 data 27 total) (-> v1-33 data 27 used))
)
)
@@ -565,7 +558,7 @@
(let* ((s2-1 (-> *display* frames (-> *display* on-screen) global-buf))
(s3-1 (-> s2-1 base))
)
(generic-init-buf s2-1 #x1000130 (the-as gs-zbuf dma-ptr))
(generic-init-buf s2-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24)))
(generic-add-shrub-constants s2-1 #x51001 124 125)
(let ((a0-26
(+ (+ (-> *instance-shrub-work* current-shrub-near-trans-packet) 5152) (the-as uint *instance-shrub-work*))
@@ -573,18 +566,18 @@
(v1-50 (-> s2-1 base))
(a1-26 (+ (-> *instance-shrub-work* near-trans-last) 176))
)
(let ((a2-25 (logior (logand (l.d (+ a0-26 96)) (the-as uint #x80000000ffffffff))
(let ((a2-28 (logior (logand (l.d (+ a0-26 96)) (the-as uint #x80000000ffffffff))
(shr (shl (-> *instance-shrub-work* near-trans-next) 33) 1)
)
)
)
(s.d! (+ a0-26 96) a2-25)
(s.d! (+ a0-26 96) a2-28)
)
(let ((a2-26 (l.q (+ a0-26 96)))
(let ((a2-29 (l.q (+ a0-26 96)))
(a3-27 (l.q (+ a0-26 112)))
(a0-27 (l.q (+ a0-26 128)))
)
(set! (-> (the-as (pointer uint128) v1-50)) a2-26)
(set! (-> (the-as (pointer uint128) v1-50)) a2-29)
(s.q! (+ v1-50 16) a3-27)
(s.q! (+ v1-50 32) a0-27)
)
@@ -874,7 +867,7 @@
(when (logtest? (vu1-renderer-mask billboard) (-> *display* vu1-enable-user))
(let* ((s4-4 (-> *display* frames (-> *display* on-screen) global-buf base))
(v1-168 (-> *display* frames (-> *display* on-screen) global-buf))
(a2-67 (-> v1-168 base))
(a2-70 (-> v1-168 base))
)
(let* ((a0-68 v1-168)
(a1-84 (-> a0-68 base))
@@ -973,7 +966,7 @@
(bucket-id billboard-l5-shrub)
)
)
a2-67
a2-70
(the-as (pointer dma-tag) a3-54)
)
)