mirror of
https://github.com/open-goal/jak-project
synced 2026-08-08 18:44:15 -04:00
150 lines
5.1 KiB
Common Lisp
150 lines
5.1 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
(bundles "ENGINE.CGO" "GAME.CGO")
|
|
(require "kernel/gcommon.gc")
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
(deftype tr-stat (structure)
|
|
((groups uint16)
|
|
(fragments uint16)
|
|
(tris uint32)
|
|
(dverts uint32)
|
|
(instances uint16)
|
|
(pad uint16)))
|
|
|
|
(deftype merc-global-stats (structure)
|
|
((merc tr-stat :inline)
|
|
(mercneric tr-stat :inline)))
|
|
|
|
(defenum perf-counter-pair
|
|
:type uint32
|
|
:bitfield #f
|
|
(cycles-instructions 0)
|
|
(icache-dcache 1))
|
|
|
|
;; One renderer bucket is sampled at a time. select chooses either cycles/instructions or
|
|
;; instruction-cache/data-cache events, ctrl is the corresponding EE Perf register value, and
|
|
;; accum0/accum1 collect the raw counter pair until the end-of-frame code assigns the named totals.
|
|
;; The explicit wait totals account for stalls that the event counters do not describe directly.
|
|
(deftype perf-stat (structure)
|
|
((frame-number uint32)
|
|
(count uint32)
|
|
(cycles uint32)
|
|
(instructions uint32)
|
|
(icache uint32)
|
|
(dcache uint32)
|
|
(select perf-counter-pair)
|
|
(ctrl uint32)
|
|
(accum0 uint32)
|
|
(accum1 uint32)
|
|
(to-vu0-waits uint32)
|
|
(to-spr-waits uint32)
|
|
(from-spr-waits uint32))
|
|
:pack-me
|
|
(:methods
|
|
(perf-stat-method-9 (_type_) none)
|
|
(print-to-stream (_type_ string basic) none)
|
|
(reset! (_type_) none)
|
|
(read! (_type_) none)
|
|
(update-wait-stats (_type_ uint uint uint) none)))
|
|
|
|
(deftype perf-stat-array (inline-array-class)
|
|
((data perf-stat :inline :dynamic)))
|
|
|
|
;; perf-stat is exactly 52 bytes; inline arrays use that as their dynamic element stride.
|
|
(set! (-> perf-stat-array heap-base) (the-as uint 52))
|
|
|
|
(#unless PC_PORT
|
|
(defmethod reset! ((this perf-stat))
|
|
"Begin one performance-counter sample. The EE clears and enables both counters selected by
|
|
ctrl; the PC port records the current CPU clock because it exposes only elapsed cycles."
|
|
(declare (asm-func none))
|
|
(rlet ((this-reg :reg a0)
|
|
(control :reg v1)
|
|
(sample-count :reg a1)
|
|
(result :reg v0))
|
|
(l.wu control this-reg 28)
|
|
(l.wu sample-count this-reg 4)
|
|
(add.i sample-count sample-count 1)
|
|
(s.w sample-count this-reg 4)
|
|
(b.z control counters-disabled :delay (nop!))
|
|
;; Stop both counters before clearing them. The two sync pairs keep the COP0 control write
|
|
;; and the performance-counter writes from crossing before sampling is enabled again.
|
|
(m Perf r0)
|
|
(sync.l)
|
|
(sync.p)
|
|
(mtpc pcr0 r0)
|
|
(mtpc pcr1 r0)
|
|
(sync.l)
|
|
(sync.p)
|
|
(m Perf control)
|
|
(sync.l)
|
|
(sync.p)
|
|
(label counters-disabled)
|
|
(m result r0)
|
|
(jr ra :delay (add sp sp r0)))))
|
|
|
|
(#when PC_PORT
|
|
(define *pc-perf-stat-counter* (the-as uint 0))
|
|
(defmethod reset! ((this perf-stat))
|
|
"Begin one performance-counter sample. The EE clears and enables both counters selected by
|
|
ctrl; the PC port records the current CPU clock because it exposes only elapsed cycles."
|
|
(+! (-> this count) 1)
|
|
(when (nonzero? (-> this ctrl))
|
|
(set! *pc-perf-stat-counter* (get-cpu-clock)))
|
|
0
|
|
(none)))
|
|
|
|
(#unless PC_PORT
|
|
(defmethod read! ((this perf-stat))
|
|
"Stop the active performance-counter sample and add its two counter values to accum0 and
|
|
accum1. The PC port adds elapsed CPU-clock ticks to accum0 and leaves accum1 at zero."
|
|
(declare (asm-func none))
|
|
(rlet ((this-reg :reg a0)
|
|
(counter :reg v1)
|
|
(accumulator :reg a1)
|
|
(result :reg v0))
|
|
(l.wu counter this-reg 28)
|
|
(b.z counter counters-disabled :delay (nop!))
|
|
;; Freeze both counters before reading them, then accumulate the two selected events.
|
|
(m Perf r0)
|
|
(sync.l)
|
|
(sync.p)
|
|
(mfpc counter pcr0)
|
|
(l.wu accumulator this-reg 32)
|
|
(add counter accumulator counter)
|
|
(s.w counter this-reg 32)
|
|
(mfpc counter pcr1)
|
|
(l.wu accumulator this-reg 36)
|
|
(add counter accumulator counter)
|
|
(s.w counter this-reg 36)
|
|
(label counters-disabled)
|
|
(m result r0)
|
|
(jr ra :delay (add sp sp r0)))))
|
|
|
|
(#when PC_PORT
|
|
(defmethod read! ((this perf-stat))
|
|
"Stop the active performance-counter sample and add its two counter values to accum0 and
|
|
accum1. The PC port adds elapsed CPU-clock ticks to accum0 and leaves accum1 at zero."
|
|
(when (nonzero? (-> this ctrl))
|
|
(+! (-> this accum0) (- (get-cpu-clock) *pc-perf-stat-counter*))
|
|
(set! (-> this accum1) 0))
|
|
0
|
|
(none)))
|
|
|
|
(defmethod update-wait-stats ((this perf-stat) (vu0-waits uint) (to-scratchpad-waits uint) (from-scratchpad-waits uint))
|
|
"Add the waits spent transferring data to VU0, to scratchpad, and from scratchpad while this
|
|
performance bucket is enabled."
|
|
(when (nonzero? (-> this ctrl))
|
|
(+! (-> this to-vu0-waits) vu0-waits)
|
|
(+! (-> this to-spr-waits) to-scratchpad-waits)
|
|
(+! (-> this from-spr-waits) from-scratchpad-waits))
|
|
0
|
|
(none))
|
|
|
|
(when (not *debug-segment*)
|
|
(set! (-> perf-stat method-table 11) nothing)
|
|
(set! (-> perf-stat method-table 12) nothing)
|
|
(set! (-> perf-stat method-table 13) nothing))
|