Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adapt legacy renderer to current NVN host interface
  • Loading branch information
seedds authored and widmonstertony committed Oct 28, 2026
commit 98fce597753072b70f29f969d84c5ec57620b836
4 changes: 4 additions & 0 deletions dm/gfx/nvn/nvn_mtl.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ int mtl_link_wait_ticks(int ticks, uint64_t timeout_ns) {
void mtl_hybrid_stats(uint64_t *draws, uint64_t *made, uint64_t *none) { *draws = *made = *none = 0; }
void mtl_pso_line(char *out, size_t size) { if (size) snprintf(out, size, "legacy renderer (Metal 4 pipeline archive unavailable)"); }
void mtl_ab_gpu(uint64_t frame, double gpu_ms, double frame_ms) { (void)frame; (void)gpu_ms; (void)frame_ms; }
int mtl_link_tick(uint64_t n, double *target, double *lead_ms, int *ticks, double *gap_ms) {
(void)n; (void)target; (void)lead_ms; (void)ticks; (void)gap_ms;
return 0; // The legacy display-link path does not retain per-present tick diagnostics.
}
#else

// Metal execution layer of the NVN null device, see nvn_mtl.h.
Expand Down
4 changes: 3 additions & 1 deletion dm/gfx/nvn/nvn_mtl_legacy.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3841,6 +3841,8 @@ static int g_tpool_n; static uint64_t g_stat_tex_oob;
// convention itself (text rendered into textures for the title and the menus came out upside down, and a MIRROR_Y copy of the frame)
static _Atomic int g_origin_ll;
void mtl_set_origin_lower_left(int on) { if (atomic_exchange(&g_origin_ll, on) != on) MLOG("窗口原点:%s", on ? "左下(GL,视口倒向、绕向反、出图翻转)" : "左上"); }
static int g_queue_origin_ll; // SET_WINDOW_ORIGIN's raster flip is queue state, independent of later device-origin changes.
void mtl_set_queue_origin_lower_left(int on) { g_queue_origin_ll = on != 0; }
void mtl_set_tex_pool_n(int n) { g_tpool_n = n; }
static id<MTLTexture> tex_by_id(int tid) { // Caller holds g_rmu
if (g_tpool_n && tid >= g_tpool_n) { if (!g_stat_tex_oob++) MLOG("池外贴图号 %d(池容量 %d)按空槽处理:读出 0", tid, g_tpool_n); return nil; }
Expand Down Expand Up @@ -7781,7 +7783,7 @@ frz_plain:;
static int diag_no_cull = -1;
if (diag_no_cull < 0) { const char *e = getenv("DM_NVN_CULL_NONE"); diag_no_cull = e && !strcmp(e, "1"); if (diag_no_cull) MLOG("DM_NVN_CULL_NONE=1: disable triangle culling"); }
enc_r_cull(en, diag_no_cull ? MTLCullModeNone : S.poly.cull == NVN_FACE_FRONT ? MTLCullModeFront : S.poly.cull == NVN_FACE_BACK ? MTLCullModeBack : MTLCullModeNone);
enc_r_winding(en, (S.poly.front == NVN_FRONT_FACE_CCW) != atomic_load_explicit(&g_origin_ll, memory_order_relaxed) ? MTLWindingCounterClockwise : MTLWindingClockwise); // the y flip of lower-left mode reverses the winding
enc_r_winding(en, (S.poly.front == NVN_FRONT_FACE_CCW) != g_queue_origin_ll ? MTLWindingCounterClockwise : MTLWindingClockwise); // NVN's raster flip is captured when the queue is initialized, rather than when the device origin changes.
enc_r_fill(en, S.poly.mode == NVN_POLYGON_MODE_LINE ? MTLTriangleFillModeLines : MTLTriangleFillModeFill);
if (S.poly.offset_en & 4) enc_r_depth_bias(en, S.po.units, S.po.factor, S.po.clamp); else enc_r_depth_bias(en, 0, 0, 0);
enc_r_depth_clip(en, !S.depth_clamp); // NVN depth clamp enabled means Metal depth clipping is disabled.
Expand Down