chore(scene3d): remove [s3d] debug output

Drop the serial tracing from startup, the render thread and the
pre-render loop.
This commit is contained in:
TermiNexus committed 2026-10-27 17:52:32 +08:00
1 parent 28d1a23677
commit 976b8307f9
1 file changed
+1 -50
+1 -50
View File
@@ -1,10 +1,8 @@
import vpsdk.window as window
import vpsdk.process as process
import vpsdk.vpui as vpui
import vpsdk.devfs as devfs
import string
from stdint import *
import viperlib
import gfx
define SCENE_W = 640
@@ -27,37 +25,17 @@ _render_done: int = 0
# (x 变大后相邻采样点的相位差被量化 ⇒ 曲线塌成一条平线、热力图颜色失去层次)。
define TIME_WRAP = float(12.566370614359172)
def _dbg(msg: const str):
# 【诊断·临时】与 explorer 同路径的串口输出。app 在建窗失败时会**静默退出**
# (Tk.mainloop 的循环条件是 win_id 有效,win_id=-1 时一次都不循环),所以必须分步打点。
devfs.serial_puts(msg)
def _render_thread(arg: rawptr):
global _time_val, _render_done
root: vpui.Tk* = _root_ptr
canvas: vpui.FBCanvas* = _canvas_ptr
s3d: gfx.Scene3D* = _s3d_ptr
# 【诊断·临时】线程是否真的起来了、参数是否有效
_rb: [160]char
viperlib.snprintf(&_rb, 160, "[s3d] rt enter root=0x%lx s3d=0x%lx active=%d\n",
uint64(root), uint64(s3d), root.winfo_exists())
_dbg(&_rb)
_rn: int = 0
while root.winfo_exists():
s3d.Render(_time_val)
_time_val += float(0.02)
if _time_val >= TIME_WRAP: _time_val = _time_val - TIME_WRAP
root.update()
# 【诊断·临时】每 60 轮打一次:证明渲染循环在跑,并采样画布像素(Clear 色 = 0x0F0F19)
_rn += 1
if (_rn % 60) == 0:
_pb: [176]char
viperlib.snprintf(&_pb, 176, "[s3d] rt n=%d t100=%d fb0=0x%x axis=0x%x\n",
_rn, int(_time_val * float(100.0)),
_fb_mem[0], _fb_mem[(SCENE_H - 150) * SCENE_W + (SCENE_W / 2)])
_dbg(&_pb)
process.yield_cpu()
_dbg("[s3d] rt exit loop\n")
_render_done = 1
# 窗口已被 explorer 回收:显式 THREAD_EXIT,绝不 return —— 用户线程的 return 会落到
# 出口跳板(旧调用号 34,而 THREAD_EXIT=60)⇒ Ring3 `jmp $` 空转、全机不再调度。
@@ -65,16 +43,13 @@ def _render_thread(arg: rawptr):
@__attribute__(section(".text.startup"), aligned(16))
export def _start() -> int:
_dbg("[s3d] start\n")
root: vpui.Tk = vpui.Tk()
_dbg("[s3d] tk ok\n")
root.title("3D Scene")
root.set_style(window.STYLE_WIN11)
root.bg_color = uint32(0x0F0F19)
master: vpui.Tk* = &root
canvas: vpui.FBCanvas = vpui.FBCanvas(master, SCENE_W, SCENE_H)
_dbg("[s3d] canvas ok\n")
root.pack(0, vpui.PACK_TOP, vpui.FILL_BOTH, 1, 0, 0)
zbuf: float* = &_zbuf_mem
@@ -85,13 +60,8 @@ export def _start() -> int:
canvas.set_fb(fb, SCENE_W, SCENE_H)
s3d: gfx.Scene3D = gfx.Scene3D(fb, zbuf, SCENE_W, SCENE_H)
_dbg("[s3d] scene ok\n")
root.geometry(100, 30, SCENE_W, SCENE_H + 32)
_wbuf: [128]char
viperlib.snprintf(&_wbuf, 128, "[s3d] geometry win_id=%d buf=0x%lx\n",
root.win_id, uint64(root.buf))
_dbg(&_wbuf)
global _root_ptr, _canvas_ptr, _s3d_ptr, _render_tid
@@ -99,35 +69,16 @@ export def _start() -> int:
_canvas_ptr = &canvas
_s3d_ptr = &s3d
# 【诊断·临时】主线程先直推 3 帧:把"管道"和"线程调度"对半切开。
# 能看见这几帧 ⇒ 渲染→FBCanvas→合成 全通,问题只在 thread_create / 调度;
# 仍然全空 ⇒ 管道里有断点,与线程无关。
# 主线程先直推 3 帧,再启动渲染线程。
global _time_val
_dbg("[s3d] pre-render 3 frames (main thread)\n")
for _pi in range(3):
s3d.Render(_time_val)
_time_val += float(0.02)
root.update()
# 非清屏像素计数:>0 说明确实画出了东西;axis 取 Render 里那条**必画**的横轴
# (DrawLine2D(50, rh-150, rw-50, rh-150),y=210,颜色 0x505050)。
_pre_nz: int = 0
_pre_i: int = 0
while _pre_i < SCENE_W * SCENE_H:
if _fb_mem[_pre_i] != uint32(0x0F0F19): _pre_nz += 1
_pre_i += 1
_pbb: [192]char
viperlib.snprintf(&_pbb, 192, "[s3d] pre %d fb0=0x%x axis=0x%x cube=0x%x nz=%d tri=%d/%d\n",
_pi, _fb_mem[0],
_fb_mem[(SCENE_H - 150) * SCENE_W + (SCENE_W / 2)],
_fb_mem[134 * SCENE_W + 254], _pre_nz,
gfx.DbgTriHits(), gfx.DbgTriCalls())
_dbg(&_pbb)
_render_tid = process.thread_create(_render_thread, None)
_dbg("[s3d] render thread created\n")
root.mainloop()
_dbg("[s3d] mainloop returned\n")
# 窗口已关闭:先等渲染线程退出,才允许回收主线程用户栈(root/canvas/s3d 都在其上)。
# 渲染线程每轮都会 yield 且只差一次循环判定,正常情况下几百次切换内即退出;