diff --git a/runtime/cfg.c b/runtime/cfg.c index 4483845f..3dde3222 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -42,8 +42,8 @@ static const char *const known[] = { "COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT", "DESC_TEMPLATE", "DEVICE_PROFILE", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "LOG_CS_BINDS", "LOG_TEX_FLAGS", "LOG_MESH", "MESH", "POOL", "NATIVE_TENSOR", "LOG_RCOND", "LOG_RT_SIZES", "DUMP_WHITE", "DUMP_AFTER", "DUMP_MOVIE", "SUBMIT_FINISH", "ACQUIRE_WAIT", "CS_FALLBACK", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", - "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FREEZE_IDLE", "FREE_CORES", - "FULLSCREEN", "FXAA", "GAME_ASPECT", "GAME_RES", "GPA", "GPA_EMPTY", "GPA_TWIN", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE", + "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOLIAGE_SHADOW_CULL", "FOLIAGE_SHADOW_VRS", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FREEZE_IDLE", "FREE_CORES", + "FULLSCREEN", "FXAA", "GAME_ASPECT", "GAME_RES", "GPA", "GPA_EMPTY", "GPA_TWIN", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_PASSES", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE", "HDR_PEAK_NITS", "HDR_UI_NITS", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD", "LIB_PREBUILD_BIG", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MENU_LANG", "MENU_SOUND_VOLUME", "MENU_TEST", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_HOST", "MOVIE_PACE", @@ -58,7 +58,7 @@ static const char *const known[] = { "SHADER_MEMO", "SHADOW_COMPARE", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", "SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "SPV_OVERRIDE", "STICK_DEADZONE", "STICK_SENS", "SWKBD_ANSWER", - "SWKBD_TEST", "TAA", "TEST_PAD", "TEST_PAD_AT", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TEX_RELEASED_MB", "TEX_COMMIT_FREE_MB", "TIMER_1MS", "TRACE", "TXD_TRANSPOSE", "UBO_SNAPSHOT", "UPSCALER", "VK_DYN_A2C", "VK_DYN_VERTEX", "VK_NOOPT", "VK_NO_FLOAT64", + "SET_AT", "SWKBD_TEST", "TAA", "TEST_PAD", "TEST_PAD_AT", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TEX_RELEASED_MB", "TEX_COMMIT_FREE_MB", "TIMER_1MS", "TRACE", "TXD_TRANSPOSE", "UBO_SNAPSHOT", "UPSCALER", "VK_DYN_A2C", "VK_DYN_VERTEX", "VK_NOOPT", "VK_NO_FLOAT64", "VK_PRESENT", "VK_RECORDER", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION", "VOLUME", "VRAM_HEADROOM", "VS_OUTS", "WALK_KEY", "WALK_SCALE", "WB_EXACT", "WB_FENCE_LIMIT", "WB_MERGE", "WINDOW_SIZE", "XLATE", "XLATE_ID", "XLATE_KEEP", "XLATE_PROCS", "ZSTD_CHECK", "ZSTD_NATIVE", @@ -118,9 +118,9 @@ static const CfgMeta metas[] = { {"PERF_OVERLAY", "off", "off|fps|full", LIVE}, {"OUTPUT_RES", "1920x1080", NULL, RESTART}, {"RENDER_SCALE", "game", "game|50|67|75|100|125|150|200", RESTART}, {"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE}, - {"DLAA", "0", "0|1", RESTART}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE}, - {"DLSS_PRESET", "default", "default|k|j", LIVE}, {"TAA", "dlss", "dlss|fsr3", RESTART}, // vk_dlaa.c fsr3 - {"FRAMEGEN", "off", "off|fsr3|dlss", RESTART}, // vk_fg.cpp, vk_dlssg.c + {"DLAA", "0", "0|1", LIVE}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE}, + {"DLSS_PRESET", "default", "default|k|j", LIVE}, {"TAA", "dlss", "dlss|fsr3", LIVE}, // vk_dlaa.c fsr3 + {"FRAMEGEN", "off", "off|fsr3|dlss", LIVE}, // vk_fg.cpp, vk_dlssg.c {"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"FXAA", "1", "0|1", LIVE}, {"GAME_ASPECT", "16:9", "16:9|window|21:9|32:9", RESTART}, // widescreen.c {"GAME_RES", "1440", "1080|1440|1800|2160|2880|window", RESTART}, // widescreen.c: the picture's height @@ -145,7 +145,7 @@ static const CfgMeta metas[] = { {"MODS_REBUILD", "auto", "auto|off", RESTART}, {"HIGHFPS_FIX", "1", "0|1", RESTART}, {"LANG", "", "ja|en-US|fr|de|it|es|zh-CN|ko|nl|pt|ru|zh-TW|en-GB|fr-CA|es-419|zh-Hans|zh-Hant|pt-BR|pl", RESTART}, - {"OPERATION_MODE", "docked", "docked|handheld", RESTART}, + {"OPERATION_MODE", "docked", "docked|handheld", LIVE}, {"ASSUME_FOCUS", "1", "0|1", LIVE}, // read on every focus change (ov_system.c) // Sound, Controls, Menu {"VOLUME", "100", "0..100", LIVE}, {"MENU_SOUND_VOLUME", "80", "0..100", LIVE}, {"AUDIO_CHANNELS", "stereo", "auto|stereo|5.1", RESTART}, diff --git a/runtime/frame_rate.c b/runtime/frame_rate.c index 462573aa..647d4fde 100644 --- a/runtime/frame_rate.c +++ b/runtime/frame_rate.c @@ -203,11 +203,12 @@ static int movie_cap_hz(void) { // frames, so the two never stack. NX2NAVI_RTSS=0 and frame generation (RTSS would count the generated frames) keep it out. uint64_t frame_step_cap_ns(void) { frame_limit_live(); - static int rtss = -1; - if (rtss < 0) { + static int rtss_allowed = -1; + if (rtss_allowed < 0) { const char *e = cfg_get("NX2NAVI_RTSS"); - rtss = !(e && !strcmp(e, "0")) && !vk_fg_wanted(); + rtss_allowed = !(e && !strcmp(e, "0")); } + int rtss = rtss_allowed && !vk_fg_wanted(); int movie_hz = movie_cap_hz(); static int movie_was, movie_logs; if (!!movie_hz != movie_was) { diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index e77a8797..759503c4 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -21,6 +21,7 @@ #include "gfx.h" #include "gfx_wsys.h" #include "nvn_api.h" +#include "ov.h" #include "platform/platform.h" #include "ui/menu.h" #include "vk.h" @@ -244,6 +245,8 @@ static void window_settings_live(void) { snprintf(present, sizeof present, "%s", e); if (started) plat_xchg32(&g_dirty, 1); } + if (started && vk_fg_wanted() != vk_fg_active()) plat_xchg32(&g_dirty, 1); // frame generation switched: its own swapchain + ov_operation_mode_live(); if (started) gfx_window_apply_settings(); started = 1; } @@ -357,6 +360,12 @@ static int create_swapchain(void) { // Frame generation (vk_fg.cpp): AMD's swapchain in this one's place. Its swapchain is replaced only after the old // one is gone; a first creation that fails leaves the plain swapchain below. VkResult r = VK_ERROR_FEATURE_NOT_PRESENT; + if (!vk_fg_wanted() && vk_fg_active()) { // switched off in the menu: AMD's swapchain and contexts go, the plain one follows + if (old) vk_fg_destroy_swapchain(old); + vk_fg_release(); + ci.oldSwapchain = VK_NULL_HANDLE; + old = g_sc = VK_NULL_HANDLE; + } if (vk_fg_wanted()) { if (old && vk_fg_active()) vk_fg_destroy_swapchain(old); else if (old) vkDestroySwapchainKHR(c->device, old, NULL); diff --git a/runtime/ipc.c b/runtime/ipc.c index 1ecad549..ba6dd934 100644 --- a/runtime/ipc.c +++ b/runtime/ipc.c @@ -11,6 +11,7 @@ #include "audren.h" #include "host.h" #include "ipc.h" +#include "ov.h" #include "nfp.h" #include "platform/platform.h" @@ -117,14 +118,14 @@ static void applet_stub_handler(IpcSession *s, const IpcRequest *rq, IpcResponse rs->result = AM_R_NO_MESSAGES; return; } - if (common && rq->cmd == 5) { // GetOperationMode: docked (matches the oe override) - uint8_t mode = 1; + if (common && rq->cmd == 5) { // GetOperationMode (matches the oe override) + uint8_t mode = !ov_handheld(); IPC_OUT(rs, mode); rs->result = 0; return; } - if (common && rq->cmd == 6) { // GetPerformanceMode: boost (docked) - uint32_t mode = 1; + if (common && rq->cmd == 6) { // GetPerformanceMode: boost when docked + uint32_t mode = !ov_handheld(); IPC_OUT(rs, mode); rs->result = 0; return; diff --git a/runtime/ov.h b/runtime/ov.h index f189a529..ca89ef88 100644 --- a/runtime/ov.h +++ b/runtime/ov.h @@ -8,6 +8,7 @@ #include "gfx.h" // ---- ov_system.c +void ov_operation_mode_live(void); // a changed NX2NAVI_OPERATION_MODE goes to the game int ov_handheld(void); // NX2NAVI_OPERATION_MODE=handheld (default docked); fatal on another value const char *ov_language(void); // the game's language, a Switch language code ("en-US", "zh-Hans", ...) const char *ov_shared_font_dir(char *buf, size_t n); // NX2NAVI_SHARED_FONTS, else /../../firmware/shared-fonts diff --git a/runtime/ov_system.c b/runtime/ov_system.c index 31608994..e22af8f7 100644 --- a/runtime/ov_system.c +++ b/runtime/ov_system.c @@ -37,20 +37,25 @@ static void need(int ok, const char *what) { static const char *caller(Cpu *c, char *buf, int n) { return ldr_describe(c->x[30] - 4, buf, n); } // ==== nn::oe (services.c) -// NX2NAVI_OPERATION_MODE, read once: 1 handheld (OperationMode 0, PerformanceMode Normal 0), 0 docked (1, Boost 1). +// NX2NAVI_OPERATION_MODE: 1 handheld (OperationMode 0, PerformanceMode Normal 0), 0 docked (1, Boost 1). It follows the +// setting; the game is told of a change as the console tells it (ov_operation_mode_live). int ov_handheld(void) { - static volatile int32_t v = -1; - int32_t h = v; - if (h < 0) { - const char *e = cfg_value("NX2NAVI_OPERATION_MODE"); - if (!strcmp(e, "docked")) h = 0; - else if (!strcmp(e, "handheld")) h = 1; - else rt_fatal("NX2NAVI_OPERATION_MODE must be docked or handheld, not '%s'", e); - if (plat_cas32(&v, h, -1) == -1) - rt_log("oe: operation mode reported to the game: %s", h ? "handheld (performance normal)" - : "docked (performance boost)"); + const char *e = cfg_value("NX2NAVI_OPERATION_MODE"); + if (!strcmp(e, "docked")) return 0; + if (!strcmp(e, "handheld")) return 1; + rt_fatal("NX2NAVI_OPERATION_MODE must be docked or handheld, not '%s'", e); +} + +// After a settings change (gfx_present.c window_settings_live): a new mode reaches the game through the applet messages +// OperationModeChanged and PerformanceModeChanged, which make it read the mode again. +void ov_operation_mode_live(void) { + static int was = -1; + int h = ov_handheld(); + if (h != was) { + rt_log("oe: operation mode reported to the game: %s", h ? "handheld (performance normal)" : "docked (performance boost)"); + if (was >= 0) oe_push_message(0x1e), oe_push_message(0x1f); + was = h; } - return (int)h; } // The Switch language for a BCP 47 tag; en-US for a language the game does not ship. diff --git a/runtime/prof_win.c b/runtime/prof_win.c index c7dc93d6..cb160358 100644 --- a/runtime/prof_win.c +++ b/runtime/prof_win.c @@ -396,7 +396,7 @@ void prof_sampler_frame(uint64_t frame, uint64_t now, uint64_t d) { // the end of a NX2NAVI_PROFILE_FRAMES window writes the profile then: a test run ended by a timeout never reaches // the exit handlers (prof_write) if (frame_hi && frame > frame_hi && !written) prof_sampler_write(); - if (slow_ns && d >= slow_ns && !dump_hi) { + if (slow_ns && d >= slow_ns && !dump_hi && frame >= frame_lo && (!frame_hi || frame <= frame_hi)) { dump_lo = (LONG64)(now - d - 20000000ull); dump_frame = (LONG64)frame; InterlockedExchange64(&dump_hi, (LONG64)now); diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index ba93f702..d035cfe8 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -739,16 +739,6 @@ static void row_fps_limit() { opt_choice_list("NX2NAVI_FPS_LIMIT", UI_MENU_FPS_LIMIT, vals, names, n, UI_MENU_FPS_LIMIT_DESC, cur, note); } -// The menu's name of a NX2NAVI_VK_PRESENT mode (gfx_window_present_mode); NULL for another. -static const char *present_name(const char *mode) { - static const struct { const char *mode; UiTextId name; } names[] = { - {"mailbox", UI_MENU_PRESENT_MAILBOX}, {"fifo", UI_MENU_PRESENT_VSYNC}, {"immediate", UI_MENU_PRESENT_IMMEDIATE}, - }; - for (const auto &n : names) - if (!strcmp(n.mode, mode)) return menu_text(n.name); - return nullptr; -} - // "in use: ..." under the VSync row when the swapchain does other than the row says: VSync when it is off and the driver // cannot present without waiting, Immediate when it is on and the driver has neither mailbox nor relaxed FIFO // (gfx_present.c pick_present_mode), so the game tears; NULL otherwise, and before the first swapchain. @@ -780,6 +770,23 @@ static bool dlss_offered(void) { // for the mode (vk_dlaa.c evaluate, dlss_preset at its default). The list: bilinear, FSR 1, the DLSS modes where DLSS // runs (dlss_offered), the FSR 3.1 modes; a DLSS mode still set where DLSS does not run stays listed last until another // choice replaces it, so the row shows what is set. +// The Upscaling row's name of what is set now, for the performance overlay. +static void upscaling_name(char *out, size_t size) { + static const char *const modes[] = {"dlaa", "quality", "balanced", "performance", "ultra_performance"}; + static const UiTextId dlss[] = {UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA}; + static const UiTextId fsr3[] = {UI_MENU_FSR3_NATIVE, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA}; + if (!cfg_bool("NX2NAVI_DLAA")) { + if (strcmp(cfg_value("NX2NAVI_UPSCALER"), "fsr")) snprintf(out, size, "%s", menu_text(UI_MENU_UPSCALER_BILINEAR)); + else snprintf(out, size, menu_text(UI_MENU_OV_FMT_FSR), cfg_int("NX2NAVI_SHARPNESS")); + return; + } + int mode = 0; + for (int i = 0; i < 5; i++) + if (!strcmp(cfg_value("NX2NAVI_DLSS"), modes[i])) mode = i; + if (!strcmp(cfg_value("NX2NAVI_TAA"), "fsr3")) snprintf(out, size, "AMD FSR 3.1 %s", menu_text(fsr3[mode])); + else snprintf(out, size, mode ? "DLSS %s" : "NVIDIA %s", menu_text(dlss[mode])); +} + static void row_upscaling(void) { static const char *const modes[] = {"dlaa", "quality", "balanced", "performance", "ultra_performance"}; static const UiTextId mode_names[] = {UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED, @@ -824,7 +831,7 @@ static void row_upscaling(void) { bool temporal = now.kind >= DLSS; int nv = opt_choice_index("NX2NAVI_UPSCALER", UI_MENU_UPSCALING, names, n, cur, 1, dlss ? UI_MENU_UPSCALING_DESC : UI_MENU_UPSCALING_DESC_FSR, - temporal ? menu_text(dlss ? UI_MENU_UPSCALING_DLSS_NOTE : UI_MENU_UPSCALING_FSR_NOTE) : nullptr); + temporal && dlss ? menu_text(UI_MENU_UPSCALING_DLSS_NOTE) : nullptr); if (nv < 0 || nv >= n) return; const Entry e = list[nv]; opt_apply("NX2NAVI_UPSCALER", e.kind == FSR1 ? "fsr" : "bilinear"); @@ -858,7 +865,7 @@ static void row_hdr(void) { // game's own tonemap in place (vk_hdr.c aces_extend), so NX2NAVI_HDR_HUE changes nothing in this game } -// Frame generation (vk_fg.cpp), after a restart; it needs a temporal upscaler's motion vectors +// Frame generation (vk_fg.cpp, at once; NVIDIA's after a restart); it needs a temporal upscaler's motion vectors static void row_framegen(void) { // the generated frames are made from DLSS's or FSR 3.1's motion vectors: without one of them it would do nothing const bool dlss = dlss_offered(); @@ -1316,9 +1323,8 @@ static void perf_tick(uint64_t now, const MenuTarget *t) { g_perf_last_ns = now; } -// The picture lines: the window, the game image the present shows and the 3D scene it holds (resolution.c), how the -// present scales the image to the window (gfx_present.c, the last present), the frame limit and the presentation mode -// in use; formatted into the panel's picture lines. +// The picture lines: the window, the game image the present shows and the 3D scene it holds (resolution.c), then the +// settings as the menu's rows name them, so the overlay and the menu agree. static void perf_picture(const MenuTarget *t, PerfPanel *p) { unsigned out[2], scene[2]; res_sizes(out, scene); @@ -1326,24 +1332,24 @@ static void perf_picture(const MenuTarget *t, PerfPanel *p) { snprintf(v[0], sizeof v[0], menu_text(UI_MENU_OV_FMT_SIZE), t->width, t->height); snprintf(v[1], sizeof v[1], menu_text(UI_MENU_OV_FMT_SIZE), (unsigned)t->image_w, (unsigned)t->image_h); snprintf(v[2], sizeof v[2], menu_text(UI_MENU_OV_FMT_SCENE), scene[0], scene[1], scene[0] * 100.0 / out[0]); - int sharp = cfg_int("NX2NAVI_SHARPNESS"); - sharp = sharp < 0 ? 0 : sharp > 100 ? 100 : sharp; - if (t->scaler == 2) { - snprintf(v[3], sizeof v[3], menu_text(UI_MENU_OV_FMT_FSR), sharp); - } else if (t->scaler == 3) { // shrunk by the blit, then RCAS (vk_fsr.c shrink_sharpen) - snprintf(v[3], sizeof v[3], menu_text(UI_MENU_OV_FMT_SHRINK), sharp); - } else { - // FSR with sharpness 0 and an image larger than the window: the plain shrink blit (vk_fsr_record) - int down = t->scaler == 1 && !strcmp(cfg_value("NX2NAVI_UPSCALER"), "fsr") && - (t->image_w > (int)t->width || t->image_h > (int)t->height); - snprintf(v[3], sizeof v[3], "%s", - menu_text(down ? UI_MENU_OV_SCALE_DOWN : t->scaler ? UI_MENU_OV_SCALE_BILINEAR : UI_MENU_OV_SCALE_NONE)); - } + upscaling_name(v[3], sizeof v[3]); double hz = frame_step_limit_hz(); snprintf(v[4], sizeof v[4], "%s", menu_text(UI_MENU_OV_NONE)); if (hz > 0) snprintf(v[4], sizeof v[4], menu_text(UI_MENU_OV_FPS), hz); - const char *pm = present_name(gfx_window_present_mode()); - snprintf(v[5], sizeof v[5], "%s", pm ? pm : menu_text(UI_MENU_OV_NONE)); + snprintf(v[5], sizeof v[5], "%s", menu_text(strcmp(cfg_value("NX2NAVI_VK_PRESENT"), "immediate") ? UI_MENU_ON : UI_MENU_OFF)); + v[6][0] = v[7][0] = 0; + if (wide_available()) { + const char *a = cfg_value("NX2NAVI_GAME_ASPECT"); + snprintf(v[6], sizeof v[6], "%s", menu_text(!strcmp(a, "window") ? UI_MENU_GAME_ASPECT_WINDOW : !strcmp(a, "21:9") ? UI_MENU_GAME_ASPECT_21_9 + : !strcmp(a, "32:9") ? UI_MENU_GAME_ASPECT_32_9 : UI_MENU_GAME_ASPECT_16_9)); + const char *r = cfg_value("NX2NAVI_GAME_RES"); + if (!strcmp(r, "window")) snprintf(v[7], sizeof v[7], "%s", menu_text(UI_MENU_GAME_RES_NATIVE)); + else snprintf(v[7], sizeof v[7], "%sp", r); + } + const char *hdr = cfg_value("NX2NAVI_HDR"); + snprintf(v[8], sizeof v[8], "%s", menu_text(!strcmp(hdr, "native") ? UI_MENU_HDR_NATIVE : cfg_bool("NX2NAVI_HDR") ? UI_MENU_HDR_ENHANCED : UI_MENU_FRAMEGEN_OFF)); + const char *fg = cfg_value("NX2NAVI_FRAMEGEN"); + snprintf(v[9], sizeof v[9], "%s", !strcmp(fg, "fsr3") ? "AMD FSR 3.1" : !strcmp(fg, "dlss") ? "NVIDIA DLSS" : menu_text(UI_MENU_FRAMEGEN_OFF)); // The 3D scene's size is known only where resolution.c sets it (the builds with its patch sets); Ocarina sizes its // own scene dynamically and res_sizes would report a fixed 1600x900, so the line is left out p->scene_known = res_adjustable() != 0; diff --git a/runtime/ui/perf_panel.cpp b/runtime/ui/perf_panel.cpp index d07a0ee2..6997742c 100644 --- a/runtime/ui/perf_panel.cpp +++ b/runtime/ui/perf_panel.cpp @@ -163,15 +163,15 @@ void waits(const PerfStats &s) { } void picture(const PerfPanel *p) { - static const UiTextId labels[6] = {UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE, - UI_MENU_OV_SCALING, UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT}; + static const UiTextId labels[10] = {UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE, UI_MENU_UPSCALING, UI_MENU_OV_LIMIT, + UI_MENU_PRESENT_VSYNC, UI_MENU_GAME_ASPECT, UI_MENU_GAME_RES, UI_MENU_HDR, UI_MENU_FRAMEGEN}; if (!ImGui::BeginTable("##perfp", 2, ImGuiTableFlags_SizingFixedFit)) return; float vw = 0; for (const auto &v : p->picture) vw = fmaxf(vw, ImGui::CalcTextSize(v).x); ImGui::TableSetupColumn("##p0", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("##p1", ImGuiTableColumnFlags_WidthFixed, vw); - for (int i = 0; i < 6; i++) { - if (i == 2 && !p->scene_known) continue; + for (int i = 0; i < 10; i++) { + if ((i == 2 && !p->scene_known) || !p->picture[i][0]) continue; label(labels[i]); ImGui::TableNextColumn(); right(p->picture[i], false); diff --git a/runtime/ui/perf_panel.h b/runtime/ui/perf_panel.h index 74a5520a..a3142a3f 100644 --- a/runtime/ui/perf_panel.h +++ b/runtime/ui/perf_panel.h @@ -10,7 +10,9 @@ extern "C" { typedef struct { PerfStats s; // perfmon_snapshot const char *version; // "NX2navi , game " - char picture[6][64]; // window, game image, scene, scaling, frame limit, presentation (formatted) + // window, game image, scene, then the settings as the menu names them: upscaling, frame limit, VSync, widescreen, + // resolution, HDR, frame generation. An empty string leaves its line out. + char picture[10][64]; bool scene_known; // the scene line is shown (resolution.c sets the scene's size) float fg_fps; // frames the display gets with frame generation, 0 without it bool under_menu; // the menu is open: the panel goes under its window diff --git a/runtime/ui_text.c b/runtime/ui_text.c index dfe72319..e4690fe4 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -480,9 +480,8 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_BOOT_STARTING] = "Starting", [UI_BOOT_SHADERS] = "Shaders: %lld of %lld", [UI_BOOT_PIPELINES] = "Pipelines: %lld of %lld", [UI_MENU_UPSCALING] = "Upscaling", [UI_MENU_UPSCALING_DESC] = "How the picture is smoothed and scaled to your window.", - [UI_MENU_UPSCALING_DLSS_NOTE] = "DLSS or FSR 3.1 on or off: after restart", + [UI_MENU_UPSCALING_DLSS_NOTE] = "DLSS on or off: after restart", [UI_MENU_UPSCALING_DESC_FSR] = "How the picture is smoothed and scaled to your window.", - [UI_MENU_UPSCALING_FSR_NOTE] = "FSR 3.1 on or off: after restart", [UI_MENU_FRAMEGEN] = "Frame generation", [UI_MENU_FRAMEGEN_DESC] = "Adds generated frames for smoother motion. Needs DLSS or FSR 3.1.", [UI_MENU_FRAMEGEN_OFF] = "Off", @@ -491,7 +490,7 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_FRAMEGEN_NOTE] = "after restart; needs DLSS or FSR 3.1", [UI_MENU_FRAMEGEN_NEEDS] = "choose a DLSS or FSR 3.1 mode under Upscaling first", [UI_MENU_FRAMEGEN_NEEDS_FSR] = "choose an FSR 3.1 mode under Upscaling first", - [UI_MENU_FRAMEGEN_NOTE_FSR] = "after restart; needs FSR 3.1", + [UI_MENU_FRAMEGEN_NOTE_FSR] = "needs FSR 3.1", [UI_MENU_FRAMEGEN_DESC_FSR] = "Adds generated frames for smoother motion. Needs FSR 3.1.", [UI_MENU_GAME_RES] = "Resolution", [UI_MENU_GAME_RES_DESC] = "Height of the game's picture. Higher is sharper but costs more GPU power.", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 03048bcf..e3276e3f 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -246,7 +246,7 @@ typedef enum { UI_MENU_FRAMEGEN_OFF, UI_MENU_FRAMEGEN_NOTE, UI_MENU_FRAMEGEN_NEEDS, UI_MENU_HDR_NOTE, UI_MENU_HDR_ENHANCED, UI_MENU_HDR_NATIVE, UI_MENU_GAME_RES, UI_MENU_GAME_RES_DESC, UI_MENU_GAME_RES_NATIVE, // the same rows' texts on a GPU DLSS does not run on (not NVIDIA): the menu leaves DLSS out there - UI_MENU_UPSCALING_DESC_FSR, UI_MENU_UPSCALING_FSR_NOTE, UI_MENU_FRAMEGEN_DESC_FSR, UI_MENU_FRAMEGEN_NOTE_FSR, + UI_MENU_UPSCALING_DESC_FSR, UI_MENU_FRAMEGEN_DESC_FSR, UI_MENU_FRAMEGEN_NOTE_FSR, UI_MENU_FRAMEGEN_NEEDS_FSR, UI_TEXT_COUNT } UiTextId; diff --git a/runtime/vk.h b/runtime/vk.h index 4453bb84..1ca4f7ac 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -37,7 +37,7 @@ typedef struct VkCtx { has_astc_ldr, // textureCompressionASTC_LDR (enabled when reported) has_calibrated, // VK_KHR/EXT_calibrated_timestamps (GPU idle split in the perf line) has_hdr_metadata, // VK_EXT_hdr_metadata (vk_hdr.c vk_hdr_metadata) - has_mesh_shader; // VK_EXT_mesh_shader with taskShader and meshShader (NVN2 task/mesh stages) + has_mesh_shader, has_mesh_queries, has_vrs; // VK_EXT_mesh_shader with taskShader and meshShader (NVN2 task/mesh stages) // Feedback loops (maxwell.md 1.9, vk_exec_draw.c feedback_prepare): a draw samples a target of its open pass that // an earlier draw of the pass wrote. NX2NAVI_FEEDBACK=0: VK_FEEDBACK_OFF (sampled in GENERAL without a barrier, the // old behaviour); VK_FEEDBACK_LAYOUT with VK_EXT_attachment_feedback_loop_layout and dynamicRenderingLocalRead @@ -110,7 +110,10 @@ typedef struct { uint64_t fence; // the submission: the timeline value it signals VkFormat color[8], depth; // attachment formats (VK_FORMAT_UNDEFINED: none) const GfxShader *first[2], *last[2];// vertex and fragment shader of the first and last draw; a dispatch: first[0] + uint32_t gp; // NX2NAVI_GPU_PASSES: the timestamp pair of this mark plus one; 0 none + uint32_t layer; // NX2NAVI_GPU_PASSES: the first layer of the depth target (a shadow cascade) } VkPassMark; +void vk_gpu_passes_frame(uint64_t frame); // vk_crumbs.c, each present: NX2NAVI_GPU_PASSES, GPU time per pass and dispatch // Pass marks wanted and possible (NX2NAVI_PASS_CRUMBS and the extensions): set by vk_crumbs_init. extern int vk_pass_marks_on; // vk_device.c create_device, before vkCreateDevice: 1 when NX2NAVI_PASS_CRUMBS asks for NVIDIA checkpoints. diff --git a/runtime/vk_backend.c b/runtime/vk_backend.c index a9a86908..a7aa7161 100644 --- a/runtime/vk_backend.c +++ b/runtime/vk_backend.c @@ -107,6 +107,7 @@ static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uin vk_mvsurvey_frame(); vk_mvprev_frame(); vk_mem_census(frame); + vk_gpu_passes_frame(frame); if (vk_dump_armed) vk_dump_present(frame); __atomic_store_n(&gfx_counters.validation_errors, (uint64_t)vk_validation_errors_total(), __ATOMIC_RELAXED); const VkTexImage *img = vk_texture_get(t); diff --git a/runtime/vk_crumbs.c b/runtime/vk_crumbs.c index 1450e6ae..dee08752 100644 --- a/runtime/vk_crumbs.c +++ b/runtime/vk_crumbs.c @@ -10,6 +10,7 @@ // per pass and dispatch, numbers in a ring of 4096, text only at the device loss. #include #include +#include #include #include "cfg.h" @@ -121,6 +122,212 @@ void vk_pass_mark_cmd(VkCommandBuffer cb, uint32_t id, int end) { if (set_checkpoint) set_checkpoint(cb, (const void *)(uintptr_t)((uint64_t)id << 1 | (end != 0))); } +// ---- NX2NAVI_GPU_PASSES=1 (diagnosis, needs the pass marks): every GP_PERIOD presents the render passes and dispatches +// of GP_FRAMES frames get GPU timestamps around them. Some presents later the results are summed by what the pass is +// (targets, shaders) and the most expensive are logged in ms per frame. The timestamps run on the replay's command +// buffers, through the recorder like the marks. +#define GP_SLOTS 16384 +#define GP_PERIOD 240 +#define GP_FRAMES 4 +#define GP_LATER 30 // presents after the capture before the results are read: the GPU is done with them by then +#define GP_TOP 30 +typedef struct { uint8_t kind, used; uint32_t w, h, d, draws, layer; int c0; uint64_t vs, fs; } GpLabel; +static GpLabel gp_labels[GP_SLOTS]; +static VkQueryPool gp_pool, gp_prims; // gp_prims: mesh primitives generated per pass (with meshShaderQueries) +static VkQueryPool gp_stats; // fragment shader invocations per pass +static int gp_state, gp_phase, gp_capture; // state 0 not set up, 1 on, -1 off; phase 0 idle, 1 capturing, 2 waiting +static uint32_t gp_n; +static uint64_t gp_start; + +static unsigned long long shader_id(const GfxShader *s); +uint32_t vk_exec_mesh_counts(const uint32_t **out); // vk_exec_draw.c + +// The hash NX2NAVI_SKIP_SHADERS takes and the frame dump prints: FNV-1a over the shader's SPIR-V. +static uint64_t gp_shader_hash(const GfxShader *s) { + static struct { const GfxShader *s; uint64_t h; } memo[1024]; + if (!s) return 0; + uint32_t i = (uint32_t)(((uintptr_t)s * 0x9E3779B97F4A7C15ull) >> 54); + if (memo[i].s == s) return memo[i].h; + uint64_t words = 0, h = 0xcbf29ce484222325ull; + const uint8_t *b = (const uint8_t *)gfx_shader_spirv(s, &words); + for (uint64_t k = 0; b && k < words * 4; k++) h = (h ^ b[k]) * 0x100000001b3ull; + memo[i].s = s, memo[i].h = h; + return h; +} + +static int kind_is_pass(const VkPassMark *m) { return m->kind == VK_MARK_PASS; } + +int vk_gpu_passes_capturing(void) { return gp_capture; } + +static void gp_begin(VkCommandBuffer cb, VkPassMark *m) { + m->gp = 0; + if (!gp_capture || gp_n >= GP_SLOTS) return; + gp_labels[gp_n].used = 0; + vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, gp_pool, gp_n * 2); + if (gp_prims && kind_is_pass(m)) vkCmdBeginQuery(cb, gp_prims, gp_n, 0); + if (gp_stats && kind_is_pass(m)) vkCmdBeginQuery(cb, gp_stats, gp_n, 0); + m->gp = ++gp_n; +} + +static void gp_end(VkCommandBuffer cb, const VkPassMark *m) { + if (!m->gp) return; + uint32_t i = m->gp - 1; + if (gp_prims && kind_is_pass(m)) vkCmdEndQuery(cb, gp_prims, i); + if (gp_stats && kind_is_pass(m)) vkCmdEndQuery(cb, gp_stats, i); + vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, gp_pool, i * 2 + 1); + GpLabel *l = &gp_labels[i]; + l->kind = m->kind, l->w = m->w, l->h = m->h, l->d = m->d, l->draws = m->draws == UINT32_MAX ? 0 : m->draws; + l->layer = m->layer; + l->c0 = m->kind == VK_MARK_PASS && m->ncolor ? (int)m->color[0] : 0; + l->vs = gp_shader_hash(m->first[0]), l->fs = m->kind == VK_MARK_PASS ? gp_shader_hash(m->first[1]) : 0; + l->used = 1; +} + +typedef struct { GpLabel l; double ms; uint32_t n; uint64_t draws, prims, frags; } GpSum; + +static int gp_sum_cmp(const void *a, const void *b) { + double x = ((const GpSum *)a)->ms, y = ((const GpSum *)b)->ms; + return x < y ? 1 : x > y ? -1 : 0; +} + +static void gp_report(uint64_t frame) { + enum { MAX_SUMS = 2048 }; + static GpSum sums[MAX_SUMS]; + VkCtx *c = vk_ctx(); + int n = 0; + uint32_t read = 0, unread = 0; + double tick_ms = c->props.limits.timestampPeriod / 1e6, total = 0; + for (uint32_t i = 0; i < gp_n; i++) { + const GpLabel *l = &gp_labels[i]; + uint64_t q[4] = {0}; + if (!l->used || vkGetQueryPoolResults(c->device, gp_pool, i * 2, 2, sizeof q, q, 2 * sizeof q[0], + VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) != VK_SUCCESS || + !q[1] || !q[3]) { + unread++; + continue; + } + read++; + double ms = (double)(q[2] - q[0]) * tick_ms; + total += ms; + // a pass of many draws and its neighbours differ in the draw count: the sum is by targets and shaders alone + int s = 0; + while (s < n && !(sums[s].l.kind == l->kind && sums[s].l.w == l->w && sums[s].l.h == l->h && sums[s].l.c0 == l->c0 && sums[s].l.layer == l->layer && + sums[s].l.vs == l->vs && sums[s].l.fs == l->fs)) + s++; + if (s == n) { + if (n == MAX_SUMS) continue; + sums[n++] = (GpSum){*l, 0, 0, 0, 0, 0}; + } + uint64_t pr[2] = {0}; + if (gp_prims && l->kind == VK_MARK_PASS && + vkGetQueryPoolResults(c->device, gp_prims, i, 1, sizeof pr, pr, sizeof pr, + VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) == VK_SUCCESS && pr[1]) + sums[s].prims += pr[0]; + uint64_t fr[2] = {0}; + if (gp_stats && l->kind == VK_MARK_PASS && + vkGetQueryPoolResults(c->device, gp_stats, i, 1, sizeof fr, fr, sizeof fr, + VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) == VK_SUCCESS && fr[1]) + sums[s].frags += fr[0]; + sums[s].ms += ms, sums[s].n++, sums[s].draws += l->draws; + } + qsort(sums, (size_t)n, sizeof sums[0], gp_sum_cmp); + rt_log("gpu passes: frame %llu: %.2f ms per frame in %u passes and dispatches over %d frames (%u not read, %d kinds)", + (unsigned long long)frame, total / GP_FRAMES, read, GP_FRAMES, unread, n); + { // the mesh workgroup counts of the indirect mesh draws (vk_exec_draw.c mesh_ring_entry) + const uint32_t *mc; + uint32_t mn = vk_exec_mesh_counts(&mc); + uint64_t sum = 0; + uint32_t top = 0; + char list[200]; + int o = 0; + for (uint32_t i = 0; i < mn; i++) { + sum += mc[i]; + if (mc[i] > top) top = mc[i]; + if (i < 18 && o < 180) o += snprintf(list + o, sizeof list - (size_t)o, " %u", mc[i]); + } + list[o] = 0; + rt_log("gpu passes: indirect mesh draws: %.1f per frame, %.0f workgroups per frame, largest %u; first:%s", (double)mn / GP_FRAMES, + (double)sum / GP_FRAMES, top, list); + } + for (int s = 0; s < n && s < GP_TOP; s++) { + const GpSum *e = &sums[s]; + if (e->l.kind == VK_MARK_DISPATCH) + rt_log("gpu passes: %7.3f ms x%-5.1f dispatch %ux%ux%u cs %016llx", e->ms / GP_FRAMES, (double)e->n / GP_FRAMES, + e->l.w, e->l.h, e->l.d, (unsigned long long)e->l.vs); + else + rt_log("gpu passes: %7.3f ms x%-5.1f pass %ux%u layer %u fmt %d, %.1f draws, %.2fM fragments, %.2fM mesh prims, vs %016llx fs %016llx", e->ms / GP_FRAMES, + (double)e->n / GP_FRAMES, e->l.w, e->l.h, e->l.layer, e->l.c0, (double)e->draws / GP_FRAMES, e->frags / 1e6 / GP_FRAMES, e->prims / 1e6 / GP_FRAMES, + (unsigned long long)e->l.vs, (unsigned long long)e->l.fs); + } +} + +// NX2NAVI_SET_AT=:=[;...]: settings changed by a test run while the game plays, as the menu would. +static void set_at_frame(uint64_t frame) { + static char buf[512]; + static const char *next; + static int state; + if (!state) { + const char *e = cfg_get("NX2NAVI_SET_AT"); + state = e && *e ? 1 : -1; + if (state > 0) snprintf(buf, sizeof buf, "%s", e), next = buf; + } + while (state > 0 && next && *next && strtoull(next, NULL, 10) <= frame) { + char item[128], *eq; + const char *colon = strchr(next, ':'), *end = strchr(next, ';'); + if (!colon) { state = -1; return; } + snprintf(item, sizeof item, "%.*s", end ? (int)(end - colon - 1) : (int)strlen(colon + 1), colon + 1); + if ((eq = strchr(item, '='))) { + *eq = 0; + rt_log("set-at: frame %llu: %s = %s", (unsigned long long)frame, item, eq + 1); + cfg_set(item, eq + 1); + } + next = end ? end + 1 : NULL; + } +} + +void vk_gpu_passes_frame(uint64_t frame) { + set_at_frame(frame); + if (gp_state < 0) return; + VkCtx *c = vk_ctx(); + if (!gp_state) { + gp_state = -1; + const char *e = cfg_get("NX2NAVI_GPU_PASSES"); + if (!e || !*e || !strcmp(e, "0") || !c) return; + VkQueryPoolCreateInfo qi = {.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, .queryType = VK_QUERY_TYPE_TIMESTAMP, + .queryCount = GP_SLOTS * 2}; + if (!vk_pass_marks_on || vkCreateQueryPool(c->device, &qi, NULL, &gp_pool) != VK_SUCCESS) { + rt_log("gpu passes: not available (needs the pass marks and a timestamp pool)"); + return; + } + if (c->has_mesh_queries) { + VkQueryPoolCreateInfo pi = {.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, + .queryType = VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT, .queryCount = GP_SLOTS}; + if (vkCreateQueryPool(c->device, &pi, NULL, &gp_prims) != VK_SUCCESS) gp_prims = VK_NULL_HANDLE; + } + { + VkQueryPoolCreateInfo si = {.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, .queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS, + .queryCount = GP_SLOTS, + .pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT}; + if (vkCreateQueryPool(c->device, &si, NULL, &gp_stats) != VK_SUCCESS) gp_stats = VK_NULL_HANDLE; + } + gp_state = 1; + rt_log("gpu passes: timing %d frames every %d presents (NX2NAVI_GPU_PASSES)", GP_FRAMES, GP_PERIOD); + } + if (gp_phase == 0) { + if (frame % GP_PERIOD) return; + vkResetQueryPool(c->device, gp_pool, 0, GP_SLOTS * 2); + if (gp_prims) vkResetQueryPool(c->device, gp_prims, 0, GP_SLOTS); + if (gp_stats) vkResetQueryPool(c->device, gp_stats, 0, GP_SLOTS); + gp_n = 0, gp_start = frame, gp_capture = 1, gp_phase = 1; + } else if (gp_phase == 1) { + if (frame < gp_start + GP_FRAMES) return; + gp_capture = 0, gp_phase = 2; + } else if (frame >= gp_start + GP_FRAMES + GP_LATER) { + gp_report(frame); + gp_phase = 0; + } +} + VkPassMark *vk_pass_mark_begin(VkCommandBuffer cb, int kind, uint64_t fence) { if (!vk_pass_marks_on || !cb) return NULL; uint32_t id = ++seq; @@ -128,11 +335,14 @@ VkPassMark *vk_pass_mark_begin(VkCommandBuffer cb, int kind, uint64_t fence) { VkPassMark *m = &ring[id & (VK_PASS_MARKS - 1)]; m->id = id, m->kind = (uint8_t)kind, m->fence = fence, m->draws = UINT32_MAX; rec_pass_mark(cb, id, 0); + gp_begin(cb, m); return m; } void vk_pass_mark_end(VkCommandBuffer cb, const VkPassMark *m) { - if (m && cb) rec_pass_mark(cb, m->id, 1); + if (!m || !cb) return; + gp_end(cb, m); + rec_pass_mark(cb, m->id, 1); } int vk_pass_marks_read(uint32_t *started, uint32_t *finished) { diff --git a/runtime/vk_device.c b/runtime/vk_device.c index 83bed0dd..fdaf30bf 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -233,6 +233,7 @@ typedef struct { VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT fbl; VkPhysicalDeviceDynamicRenderingLocalReadFeaturesKHR lr; VkPhysicalDeviceMeshShaderFeaturesEXT mesh; + VkPhysicalDeviceFragmentShadingRateFeaturesKHR vrs; } FeatureChain; static int create_device(void) { @@ -269,6 +270,8 @@ static int create_device(void) { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT); // NVN2 task and mesh programs (gameplay geometry) draw through VK_EXT_mesh_shader (vk_exec_draw.c op_draw_mesh) OPTIONAL_EXT(has_mesh_shader, VK_EXT_MESH_SHADER_EXTENSION_NAME, mesh, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT); + // The foliage's far shadow cascades shade one fragment per 2x2 pixels (vk_exec_draw.c mesh_shading_rate) + OPTIONAL_EXT(has_vrs, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME, vrs, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR); // Feedback loops (vk.h VkCtx.feedback): the layout, and barriers inside dynamic rendering int has_fbl = 0, has_lr = 0; if (has_ext(ep, ne, VK_EXT_ATTACHMENT_FEEDBACK_LOOP_LAYOUT_EXTENSION_NAME) && @@ -281,8 +284,9 @@ static int create_device(void) { } vk_dlaa_device_exts(ep, ne, ext, &n_ext, 40); // NGX's; the eight slots after it stay for the eight below // FSR 3.1 (vk_ffx.cpp): its Vulkan back end looks vkGetBufferMemoryRequirements2KHR up by that name, which resolves - // only with the extension enabled (the core function has no suffix); without it the back end called address 0 - if ((vk_dlaa_fsr3() || vk_fg_wanted() || vk_dlssg_wanted()) && has_ext(ep, ne, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME)) + // only with the extension enabled (the core function has no suffix); without it the back end called address 0. + // Always asked for: FSR 3.1 can be switched on in the menu during a run + if (has_ext(ep, ne, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME)) ext[n_ext++] = VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME; // DLSS Frame Generation (vk_dlssg.c): Streamline's plugins look functions of extensions core in Vulkan 1.3 up by // their suffixed names too, which resolve only with the extension itself enabled @@ -347,10 +351,17 @@ static int create_device(void) { else if (!h->textureCompressionBC) miss = "textureCompressionBC"; if (miss) { rt_log("vk: required feature missing on %s: %s", g_vk.props.deviceName, miss); free(c); return 0; } if (!c->fault.deviceFault) g_vk.has_device_fault = 0; + if (g_vk.has_vrs) { // the rate is set per draw; no rate attachment and no per-primitive rates + c->vrs.attachmentFragmentShadingRate = c->vrs.primitiveFragmentShadingRate = VK_FALSE; + if (!c->vrs.pipelineFragmentShadingRate) g_vk.has_vrs = 0; + rt_log("vk: fragment shading rate: %s", g_vk.has_vrs ? "per draw" : "not supported"); + } if (g_vk.has_mesh_shader) { // these two need features that are not enabled (multiview, primitive fragment shading rate) c->mesh.multiviewMeshShader = c->mesh.primitiveFragmentShadingRateMeshShader = VK_FALSE; - c->mesh.meshShaderQueries = VK_FALSE; + const char *gp = cfg_get("NX2NAVI_GPU_PASSES"); + g_vk.has_mesh_queries = c->mesh.meshShaderQueries && gp && *gp && strcmp(gp, "0"); // vk_crumbs.c, diagnosis + c->mesh.meshShaderQueries = g_vk.has_mesh_queries ? VK_TRUE : VK_FALSE; if (!c->mesh.meshShader || !c->mesh.taskShader) g_vk.has_mesh_shader = 0; rt_log("vk: mesh shaders: %s", g_vk.has_mesh_shader ? "VK_EXT_mesh_shader" : "not supported (task/mesh draws are skipped)"); } // vkGetDeviceFaultInfoEXT needs the feature, not just the extension diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index fb03013d..7f3028df 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -71,6 +71,7 @@ static struct { PFN_Evaluate evaluate; PFN_Release release; int tried, loaded, available; + int ngx_up; // vk_dlaa_init brought NGX up: DLSS serves this run int wanted; // -1 not read yet } N = {.wanted = -1}; @@ -104,23 +105,19 @@ static int p_getp(const NgxParam *p, const char *n, void **v) { return NGX_OK((( #define DLSS_MODEL "libnvidia-ngx-dlss.so." #endif -// NGX is brought up only when dlaa is on at start: its device extensions can only be asked for at device creation, and -// loading the driver's NGX core on every NVIDIA machine would cost start time and change the device with DLAA off. So -// dlaa applies after a restart; switched off, nothing else of DLAA runs. +// NGX is brought up only when DLSS is wanted at start: its device extensions can only be asked for at device creation, +// and loading the driver's NGX core on every NVIDIA machine would cost start time and change the device with DLAA off. +// So DLSS applies after a restart. FSR 3.1 (amd_fidelityfx_vk.dll, vk_ffx.cpp) asks nothing of the device: NX2NAVI_TAA +// and dlaa follow the setting at once when NGX is not up, and vk_dlaa_frame loads the library the first time it is used. int vk_dlaa_wanted(void) { - static int wanted = -1; - if (wanted < 0) wanted = cfg_bool("NX2NAVI_DLAA"); - return wanted; + static int at_start = -1; + if (at_start < 0) at_start = cfg_bool("NX2NAVI_DLAA"); + return at_start || (!N.ngx_up && cfg_bool("NX2NAVI_DLAA") && !strcmp(cfg_value("NX2NAVI_TAA"), "fsr3")); } -// The temporal upscaler behind dlaa (NX2NAVI_TAA, read once: like dlaa it applies after a restart): NVIDIA DLSS through -// NGX, or AMD FSR 3.1 through amd_fidelityfx_vk.dll (vk_ffx.cpp), which takes the same inputs and needs no device -// extensions. The DLSS mode setting (NX2NAVI_DLSS) is the render scale for both. -static int fsr3(void) { - static int on = -1; - if (on < 0) on = !strcmp(cfg_value("NX2NAVI_TAA"), "fsr3"); - return on; -} +// The temporal upscaler behind dlaa: NVIDIA DLSS through NGX, once NGX is up, or else AMD FSR 3.1, which takes the same +// inputs. The DLSS mode setting (NX2NAVI_DLSS) is the render scale for both. +static int fsr3(void) { return !N.ngx_up && !strcmp(cfg_value("NX2NAVI_TAA"), "fsr3"); } int vk_dlaa_fsr3(void) { return vk_dlaa_wanted() && fsr3(); } static int core_load(void) { @@ -275,6 +272,7 @@ void vk_dlaa_init(void) { p_geti(caps, "SuperSampling.NeedsUpdatedDriver", &driver); } N.available = avail != 0; + N.ngx_up = 1; rt_log("dlaa: NGX up; DLSS %s%s", avail ? "available" : "NOT available (is " DLSS_MODEL " next to the executable?)", driver ? "; the driver needs an update" : ""); } @@ -1481,6 +1479,7 @@ void vk_dlaa_frame(void) { vk_dlaa_swap_img = NULL, vk_dlaa_swap_view = VK_NULL_HANDLE; dlss_mode(); preset_check(); + if (!N.ngx_up) N.available = fsr3() && cfg_bool("NX2NAVI_DLAA") && vk_ffx_load(); // FSR 3.1 follows the setting int on = N.available && cfg_bool("NX2NAVI_DLAA"); if (on != D.on) { rt_log("dlaa: %s", on ? "on" : "off"); diff --git a/runtime/vk_dump.c b/runtime/vk_dump.c index eca36c81..0a7dab75 100644 --- a/runtime/vk_dump.c +++ b/runtime/vk_dump.c @@ -749,6 +749,9 @@ void vk_dump_draw(VkExec *ex, const VkPipeState *s, VkPipeline p, const VkPipeIn sp(&b, " blend: enabled targets %#x; target 0 rgb %u*src %u*dst eq %u, alpha %u*src %u*dst eq %u; channel mask %#x\n", (unsigned)s->color.blend_en, (unsigned)bl->src_rgb, (unsigned)bl->dst_rgb, (unsigned)bl->eq_rgb, (unsigned)bl->src_a, (unsigned)bl->dst_a, (unsigned)bl->eq_a, (unsigned)s->chmask.mask); + sp(&b, " depth: test %u write %u func %u; alpha func %u; cull %u; a2c %u; samples %u; mesh task %d\n", (unsigned)s->ds.dt, + (unsigned)s->ds.dw, (unsigned)s->ds.df, (unsigned)s->color.alpha_func, (unsigned)s->poly.cull, (unsigned)s->ms.a2c, + (unsigned)s->samples, s->ts != NULL); describe_bindings(&b, ex, info); ents[nents++] = (Ent){p, th, 1, b.s}; out: diff --git a/runtime/vk_exec.c b/runtime/vk_exec.c index b95b3b80..115270fa 100644 --- a/runtime/vk_exec.c +++ b/runtime/vk_exec.c @@ -635,6 +635,7 @@ void vk_exec_pass_begin(VkExec *ex) { if (m) { m->step = ex->mark_passes++; m->w = ex->pass_w, m->h = ex->pass_h, m->d = ex->pass_layers; + m->layer = ex->depth.image ? ex->depth.base_layer : 0; m->ncolor = (uint8_t)(ex->pass_ncolor < 8 ? ex->pass_ncolor : 8); for (int i = 0; i < m->ncolor; i++) m->color[i] = ex->pass_color[i]; m->depth = ex->pass_depth ? ex->pass_depth : ex->pass_stencil; diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index a4b91111..a94490ca 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -2776,6 +2776,22 @@ static void bind_vertex_buffers(VkExec *ex) { B.vb_valid = 1; } +// NX2NAVI_FOLIAGE_SHADOW_CULL=[f] (0 to 3, default 1; 3 turns it off): the foliage's mesh draws into the sun's shadow cascades +// from this layer on drop one side of their cards ("f": the front faces, else the back faces). The game draws them +// double-sided, and stacks of alpha-tested cards seen from the sun reached about 1,000 million fragments in one draw of +// the 2.5 million texel far cascade, where half the cards still cover the same texels. Cull mode is dynamic state, so +// this needs no other pipeline. +static void foliage_shadow_cull(const VkExec *ex, VkPipeState *s) { + static int from = -1, face; + if (from < 0) { + const char *e = cfg_get("NX2NAVI_FOLIAGE_SHADOW_CULL"); + from = e && *e ? atoi(e) : 1; + face = e && strchr(e, 'f') ? NVN_FACE_FRONT : NVN_FACE_BACK; + } + if (!ex->color[0].image && ex->depth.image && (int)ex->depth.base_layer >= from && s->poly.cull == NVN_FACE_NONE) + s->poly.cull = (unsigned)face; +} + // NX2NAVI_PIPE_SKIP: which draws are skipped, rather than waited for, while their shaders or pipeline build. // strict (0): only draws whose pass targets were all rendered in the previous presented frame; a pass with a target // that was not counts as one-shot and waits. @@ -2953,6 +2969,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int uint32_t fbl = feedback_prepare(ex, fs); VkPipeState s = ex->pipe; s.vs = vs, s.fs = fs, s.ts = ts; + if (mesh) foliage_shadow_cull(ex, &s); s.feedback = (uint8_t)((fbl & 0xff ? 1 : 0) | (fbl & 0x100 ? 2 : 0)); s.prim = (uint8_t)prim; s.depth_minus_w = (uint8_t)(nvn_depth_minus_w() != 0); @@ -3033,7 +3050,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int if (fbl & ex->fb_dirty) feedback_barrier(ex); feedback_written(ex, &s, fbl); if (!mesh) bind_vertex_buffers(ex); - if (vk_dump_armed && !mesh) vk_dump_draw(ex, &s, p, info); + if (vk_dump_armed) vk_dump_draw(ex, &s, p, info); if (vk_hdr_track) vk_hdr_draw(ex, info); vk_exec_oq_draw(ex); DRS.issued[mesh]++; @@ -3813,6 +3830,25 @@ static PFN_vkCmdDrawMeshTasksEXT draw_mesh_fn(void) { return fn; } +// NX2NAVI_FOLIAGE_SHADOW_VRS (0 to 3, default 2): the foliage's mesh draws in the shadow cascades from this one on shade one +// fragment per 2x2 pixels; 3 turns it off. A leaf's alpha test then runs a quarter as often, and the far cascade's texels +// are metres across the forest floor, where the coarser cut-out does not show. A mesh pipeline has the rate as dynamic +// state, so every mesh draw sets it. +static void mesh_shading_rate(VkExec *ex) { + static PFN_vkCmdSetFragmentShadingRateKHR fn; + static int looked, from; + if (!looked) { + looked = 1; + const char *e = cfg_get("NX2NAVI_FOLIAGE_SHADOW_VRS"); + from = e && *e ? atoi(e) : 2; + if (vk_ctx()->has_vrs) + fn = (PFN_vkCmdSetFragmentShadingRateKHR)vkGetDeviceProcAddr(vk_ctx()->device, "vkCmdSetFragmentShadingRateKHR"); + } + if (!fn) return; + rec_shading_rate(fn, ex->cb, !ex->color[0].image && ex->depth.image && (int)ex->depth.base_layer >= from ? 2 : 1); + ex->recorded++; +} + static void op_draw_mesh(VkExec *ex, const p_draw_mesh *d) { PFN_vkCmdDrawMeshTasksEXT fn = draw_mesh_fn(); if (!fn) return warn_once(W_MESH, "mesh draws need VK_EXT_mesh_shader: skipped"); @@ -3828,6 +3864,7 @@ static void op_draw_mesh(VkExec *ex, const p_draw_mesh *d) { n_logged++; rt_log("vk: mesh draw: %u workgroups, program %llu", d->count, (unsigned long long)ex->prog->serial); } + mesh_shading_rate(ex); rec_draw_mesh(fn, ex->cb, d->count, 1, 1); ex->recorded++; } @@ -3841,6 +3878,35 @@ enum { MESH_RING = 4096 }; static VkBuffer mesh_ring; static uint32_t mesh_ring_next; +// NX2NAVI_GPU_PASSES: the workgroup counts of the indirect mesh draws of the timed frames, copied to host memory. +int vk_gpu_passes_capturing(void); +enum { MESH_COUNTS = 4096 }; +static VkBuffer mesh_count_buf; +static uint32_t *mesh_count_map, mesh_count_n, mesh_count_was; +uint32_t vk_exec_mesh_counts(const uint32_t **out) { + *out = mesh_count_map; + return mesh_count_map ? mesh_count_n : 0; +} +static void mesh_count_note(VkExec *ex, const VkMemSpan *src) { + uint32_t cap = (uint32_t)vk_gpu_passes_capturing(); + if (!cap) { mesh_count_was = 0; return; } + if (!mesh_count_was) mesh_count_was = 1, mesh_count_n = 0; + if (!mesh_count_buf) { + VkBufferCreateInfo bi = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = 4ull * MESH_COUNTS, + .usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT}; + VmaAllocationCreateInfo ai = {.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST, + .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT}; + VmaAllocationInfo info; + VmaAllocation a; + if (vmaCreateBuffer(vk_ctx()->vma, &bi, &ai, &mesh_count_buf, &a, &info) != VK_SUCCESS) return; + mesh_count_map = info.pMappedData; + } + if (mesh_count_n >= MESH_COUNTS) return; + VkBufferCopy cp = {src->offset, 4ull * mesh_count_n++, 4}; + vkCmdCopyBuffer(ex->cb, src->buffer, mesh_count_buf, 1, &cp); + ex->recorded++; +} + static int mesh_ring_entry(VkExec *ex, const VkMemSpan *src, VkDeviceSize *at) { if (!mesh_ring) { VkBufferCreateInfo bi = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = 12ull * MESH_RING, @@ -3857,6 +3923,7 @@ static int mesh_ring_entry(VkExec *ex, const VkMemSpan *src, VkDeviceSize *at) { vkCmdFillBuffer(ex->cb, mesh_ring, *at + 4, 8, 1); VkBufferCopy cp = {src->offset, *at, 4}; vkCmdCopyBuffer(ex->cb, src->buffer, mesh_ring, 1, &cp); + mesh_count_note(ex, src); VkMemoryBarrier2 mb = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER_2, .srcStageMask = VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, .srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT, .dstStageMask = VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT, @@ -3897,6 +3964,7 @@ static void op_draw_mesh_ind(VkExec *ex, const p_draw_mesh_ind *d) { rt_log("vk: indirect mesh draw: arguments at %#llx, program %llu", (unsigned long long)d->ind, (unsigned long long)ex->prog->serial); } + mesh_shading_rate(ex); rec_draw_mesh_ind(fn, ex->cb, mesh_ring, at, 1, 12); ex->recorded++; vk_mem_count(ip.cls, VK_MUSE_IND, 4); diff --git a/runtime/vk_fg.cpp b/runtime/vk_fg.cpp index f9fd71ca..2915147a 100644 --- a/runtime/vk_fg.cpp +++ b/runtime/vk_fg.cpp @@ -33,7 +33,6 @@ extern "C" { namespace { struct { - int wanted = -1; VkQueue present = VK_NULL_HANDLE, acquire = VK_NULL_HANDLE; ffxContext sc = nullptr; // the swapchain context ffxContext fg = nullptr; // the frame generation context @@ -78,18 +77,14 @@ void fail(const char *what, unsigned r) { } // namespace +// Follows the setting: gfx_present.c's window_settings_live remakes the swapchain when this stops matching vk_fg_active. +// It needs DLSS's or FSR 3.1's motion vectors, so it also needs one of them on. extern "C" int vk_fg_wanted(void) { - if (F.wanted < 0) { - F.wanted = !strcmp(cfg_value("NX2NAVI_FRAMEGEN"), "fsr3"); - if (F.wanted && !vk_dlaa_wanted()) { - rt_log("fg: frame generation needs DLSS or FSR 3.1 upscaling (any mode): off"); - F.wanted = 0; - } - } - return F.wanted; + return !strcmp(cfg_value("NX2NAVI_FRAMEGEN"), "fsr3") && cfg_bool("NX2NAVI_DLAA") && vk_dlaa_wanted(); } -extern "C" uint32_t vk_fg_queue_count(void) { return vk_fg_wanted() ? 3 : 1; } +// Always the three queues: the setting can be switched on during a run, and idle queues cost nothing. +extern "C" uint32_t vk_fg_queue_count(void) { return 3; } extern "C" void vk_fg_queues(VkQueue present, VkQueue acquire) { F.present = present, F.acquire = acquire; } @@ -268,4 +263,5 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, extern "C" void vk_fg_release(void) { if (F.fg) vk_ffx_destroy(&F.fg), F.fg = nullptr; if (F.sc) vk_ffx_destroy(&F.sc), F.sc = nullptr; + __atomic_store_n(&F.on, 0, __ATOMIC_RELAXED); } diff --git a/runtime/vk_fg.h b/runtime/vk_fg.h index 01b39b94..23db7e93 100644 --- a/runtime/vk_fg.h +++ b/runtime/vk_fg.h @@ -3,8 +3,8 @@ #include #include -int vk_fg_wanted(void); // NX2NAVI_FRAMEGEN = fsr3 with DLSS or FSR 3.1 upscaling on (read once) -uint32_t vk_fg_queue_count(void); // graphics-family queues the device creates: 3 with frame generation, else 1 +int vk_fg_wanted(void); // NX2NAVI_FRAMEGEN = fsr3 with DLSS or FSR 3.1 upscaling on (live) +uint32_t vk_fg_queue_count(void); // graphics-family queues the device creates void vk_fg_queues(VkQueue present, VkQueue acquire); // vk_device.c, after the device exists int vk_fg_active(void); // the frame generation swapchain exists int vk_fg_generating(void); // ... and the last frame had generation on (not paused for the menu) diff --git a/runtime/vk_pipeline.c b/runtime/vk_pipeline.c index 919f5c2a..4bdf3662 100644 --- a/runtime/vk_pipeline.c +++ b/runtime/vk_pipeline.c @@ -1568,13 +1568,14 @@ static VkPipeline create_graphics(const VkPipeState *s, const GKey *k, const Lay .attachmentCount = k->n_color, .pAttachments = cba}; VkPipelineDynamicStateCreateInfo dy = {.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, .dynamicStateCount = P.n_dyn, .pDynamicStates = P.dyn}; - VkDynamicState mdyn[sizeof P.dyn / sizeof P.dyn[0]]; + VkDynamicState mdyn[sizeof P.dyn / sizeof P.dyn[0] + 1]; if (mesh) { // a mesh pipeline must not list vertex input, topology or primitive restart as dynamic uint32_t n = 0; for (uint32_t i = 0; i < P.n_dyn; i++) if (P.dyn[i] != VK_DYNAMIC_STATE_VERTEX_INPUT_EXT && P.dyn[i] != VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE && P.dyn[i] != VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY && P.dyn[i] != VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE) mdyn[n++] = P.dyn[i]; + if (vk_ctx()->has_vrs) mdyn[n++] = VK_DYNAMIC_STATE_FRAGMENT_SHADING_RATE_KHR; // vk_exec_draw.c mesh_shading_rate dy.dynamicStateCount = n, dy.pDynamicStates = mdyn; } VkPipelineRenderingCreateInfo ri = {.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO, .colorAttachmentCount = k->n_color, diff --git a/runtime/vk_rec.c b/runtime/vk_rec.c index 446764de..b0d892b4 100644 --- a/runtime/vk_rec.c +++ b/runtime/vk_rec.c @@ -42,7 +42,7 @@ enum { R_SetRasterizerDiscardEnable, R_SetScissorWithCount, R_SetStencilCompareMask, R_SetStencilOp, R_SetStencilReference, R_SetStencilTestEnable, R_SetStencilWriteMask, R_SetViewportWithCount, R_WriteTimestamp, R_WriteTimestamp2, R_PushTpl, R_Push, R_VertexInput, R_Bool, R_PolygonMode, R_BlendEnable, R_BlendEquation, R_WriteMask, R_EndCb, - R_PassMark, R_DrawMesh, R_DrawMeshInd, + R_PassMark, R_DrawMesh, R_DrawMeshInd, R_ShadingRate, }; static uint64_t now_ns(void) { return plat_now_ns(); } @@ -632,6 +632,19 @@ void rec_draw_mesh_ind(PFN_vkCmdDrawMeshTasksIndirectEXT fn, VkCommandBuffer cb, pub(); } +typedef struct { PFN_vkCmdSetFragmentShadingRateKHR fn; uint32_t size; } A_ShadingRate; +static void shading_rate_call(PFN_vkCmdSetFragmentShadingRateKHR fn, VkCommandBuffer cb, uint32_t size) { + VkExtent2D e = {size, size}; + VkFragmentShadingRateCombinerOpKHR ops[2] = {VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR, VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR}; + fn(cb, &e, ops); +} +void rec_shading_rate(PFN_vkCmdSetFragmentShadingRateKHR fn, VkCommandBuffer cb, uint32_t size) { + if (!OWNED(cb)) { shading_rate_call(fn, cb, size); return; } + A_ShadingRate *a = put(R_ShadingRate, sizeof *a); + *a = (A_ShadingRate){fn, size}; + pub(); +} + typedef struct { uint32_t id; int end; } A_PassMark; void rec_pass_mark(VkCommandBuffer cb, uint32_t id, int end) { if (!OWNED(cb)) { vk_pass_mark_cmd(cb, id, end); return; } @@ -731,6 +744,7 @@ static void exec_packet(uint32_t op, void *p) { case R_PassMark: { A_PassMark *a = p; vk_pass_mark_cmd(cb, a->id, a->end); break; } case R_DrawMesh: { A_DrawMesh *a = p; a->fn(cb, a->x, a->y, a->z); break; } case R_DrawMeshInd: { A_DrawMeshInd *a = p; a->fn(cb, a->b, a->o, a->n, a->stride); break; } + case R_ShadingRate: { A_ShadingRate *a = p; shading_rate_call(a->fn, cb, a->size); break; } case R_EndCb: { A_EndCb *a = p; if (a->kind) vk_crumb(cb, a->kind, a->n); diff --git a/runtime/vk_rec.h b/runtime/vk_rec.h index ec73909b..62c5be1a 100644 --- a/runtime/vk_rec.h +++ b/runtime/vk_rec.h @@ -44,6 +44,7 @@ void rec_blend_equation(PFN_vkCmdSetColorBlendEquationEXT fn, VkCommandBuffer cb void rec_write_mask(PFN_vkCmdSetColorWriteMaskEXT fn, VkCommandBuffer cb, uint32_t first, uint32_t n, const VkColorComponentFlags *v); void rec_draw_mesh(PFN_vkCmdDrawMeshTasksEXT fn, VkCommandBuffer cb, uint32_t x, uint32_t y, uint32_t z); +void rec_shading_rate(PFN_vkCmdSetFragmentShadingRateKHR fn, VkCommandBuffer cb, uint32_t size); // size x size pixels per fragment void rec_draw_mesh_ind(PFN_vkCmdDrawMeshTasksIndirectEXT fn, VkCommandBuffer cb, VkBuffer b, VkDeviceSize o, uint32_t n, uint32_t stride); // A pass mark (vk_crumbs.c vk_pass_mark_cmd: a buffer marker and a checkpoint), in order with the commands around it. diff --git a/tools/menu_preview.cpp b/tools/menu_preview.cpp index c417f251..1acbab78 100644 --- a/tools/menu_preview.cpp +++ b/tools/menu_preview.cpp @@ -257,9 +257,13 @@ static void scene_overlay(float w, float h, float scale) { p.version = "NX2navi 0.5.0, game 1.1.1"; snprintf(p.picture[0], 64, "1920x1080"); snprintf(p.picture[1], 64, "2560x1440"); - snprintf(p.picture[3], 64, "bilinear"); + snprintf(p.picture[3], 64, "AMD FSR 3.1 Performance"); snprintf(p.picture[4], 64, "60 FPS"); - snprintf(p.picture[5], 64, "VSync"); + snprintf(p.picture[5], 64, "%s", menu_text(UI_MENU_ON)); + snprintf(p.picture[6], 64, "21:9"); + snprintf(p.picture[7], 64, "1440p"); + snprintf(p.picture[8], 64, "%s", menu_text(UI_MENU_HDR_ENHANCED)); + snprintf(p.picture[9], 64, "%s", menu_text(UI_MENU_FRAMEGEN_OFF)); p.scene_known = false, p.fg_fps = 60, p.under_menu = false; perf_panel_draw(&p, w, scale); }