diff --git a/nx2navi.ini.example b/nx2navi.ini.example index e107edb2..0ef76279 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -1143,8 +1143,11 @@ # mesh_ahead = 1 # Graphics cards without mesh shaders (GTX 10 series, RX 500 and 5000 series, many integrated ones): the game's mesh # draws, most of the world, are computed in compute passes and drawn as ordinary triangles. auto (default) does that -# only on such a card; 1 does it on every card (for testing: it is slower than mesh shaders); 0 never, and such a -# card then draws no world. +# on such a card, and on the RX 6000 series with AMD's Windows driver, where the game drawn with mesh shaders lost the +# graphics card in play ("driver timeout", the game ends with code 72); there it costs some frame rate, and a place's +# ground, rocks and plants show a moment late the first time they are drawn in a run. 1 does it on every card (for +# testing: it is slower than mesh shaders); 0 never: an RX 6000 card then draws with mesh shaders as version 0.10.1 +# did, and a card without them draws no world. # mesh_fallback = auto # Video memory in MB for what those compute passes hand to the draws. A draw that needs more loses the geometry that # does not fit, and the log says so. diff --git a/runtime/cfg.c b/runtime/cfg.c index e655d99d..f0ff25b4 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -323,7 +323,8 @@ static const CfgMeta metas[] = { {"DRAW_WRITERS_WAIT", "1", "0|1", RESTART}, // vk_exec_draw.c writers_wait_on {"PREPARE_PIPELINES", "all", "0|mesh|all", RESTART}, // vk_pipeline.c seed_pipelines // vk_device.c: task and mesh programs through compute passes (vk_exec_draw.c "mesh fallback"); auto: on a device - // without mesh shaders. The megabytes are the buffers the passes write (vk_mesh_fb.c). + // without mesh shaders and on AMD's Windows driver for RDNA 1 and 2 (vk_mesh_path.h). The megabytes are the + // buffers the passes write (vk_mesh_fb.c). {"MESH_FALLBACK", "auto", "auto|0|1", RESTART}, {"MESH_FALLBACK_MB", "128", "16..4096", RESTART}, {"MESH_FALLBACK_WORKERS", "auto", "auto|1|2|3|4", RESTART}, // vk_exec_draw.c mfb_worker_count {"PIPE_AHEAD", "1", "0|1", RESTART}, // vk_exec.c vk_exec_ahead, vk_pipeline.c vk_pipeline_hint diff --git a/runtime/vk.h b/runtime/vk.h index b1786491..ea37f7ad 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -73,7 +73,7 @@ typedef struct VkCtx { lists_low_latency, // the driver lists one of the two, left out: the run started with the mode off has_mesh_queries; // meshShaderQueries, kept while NX2NAVI_GPU_PASSES or NX2NAVI_DUMP is set int mesh_fallback; // task and mesh programs run as compute passes and are drawn from buffers - // (mesh_fallback: auto without has_mesh_shader; vk_exec_draw.c "mesh fallback") + // (mesh_fallback: auto as vk_mesh_path.h decides; vk_exec_draw.c "mesh fallback") // 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 diff --git a/runtime/vk_device.c b/runtime/vk_device.c index dde3f939..24741a53 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -19,6 +19,7 @@ #include "vk_fg.h" #include "vk_dlssg.h" #include "vk_lowlat.h" +#include "vk_mesh_path.h" // The loader's vkGetDeviceProcAddr until Streamline is on the device (see vk.h). PFN_vkGetDeviceProcAddr vk_dpa = vkGetDeviceProcAddr; @@ -606,19 +607,23 @@ static int create_device(void) { 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" : "the extension is there, its task or mesh feature is not"); } // vkGetDeviceFaultInfoEXT needs the feature, not just the extension - { // mesh_fallback: auto (on a device without mesh shaders), 1 (on every device, for testing) or 0 - // without mesh shaders the mesh emulation (NX2NAVI_MESH_EMULATION, on unless 0) draws them; mesh_emulation = 0 - // leaves them to this fallback - const char *mf = cfg_value("NX2NAVI_MESH_FALLBACK"), *me = cfg_value("NX2NAVI_MESH_EMULATION"); - int emu = !g_vk.has_mesh_shader && strcmp(me, "0"); - g_vk.mesh_fallback = !emu && (!strcmp(mf, "1") || (strcmp(mf, "0") && !g_vk.has_mesh_shader)); - g_mesh_path = emu ? "emulated (mesh_emulation)" : g_vk.mesh_fallback ? "through the mesh fallback (compute passes)" - : g_vk.has_mesh_shader ? "native (VK_EXT_mesh_shader)" : "skipped (no mesh shaders, mesh_fallback = 0)"; - if (emu) rt_log("vk: mesh shaders: emulated with compute (mesh_emulation = 1); mesh_fallback is not used"); - else if (g_vk.mesh_fallback) + { // mesh_fallback: auto, 1 (on every device) or 0 (vk_mesh_path.h says when auto takes it, and why on AMD's driver + // for RDNA 1 and 2). Without mesh shaders the mesh emulation (mesh_emulation = 1) draws them instead. + // has_mesh_shader keeps saying what the hardware has: the recorder thread (vk_rec.c) and the low-end card + // test (vk_low_end_card) go by it, not by how mesh programs are drawn. + const char *mf = cfg_value("NX2NAVI_MESH_FALLBACK"), *me = cfg_value("NX2NAVI_MESH_EMULATION"), *why = ""; + int path = mesh_path_decide(g_vk.has_mesh_shader, vk_caps.amd_sc, mf, me, &why); + g_vk.mesh_fallback = path == MESH_PATH_FALLBACK; + g_mesh_path = path == MESH_PATH_EMULATION ? "emulated (mesh_emulation)" + : path == MESH_PATH_FALLBACK ? (g_vk.has_mesh_shader ? "through the mesh fallback on a device with mesh " + "shaders (compute passes)" + : "through the mesh fallback (compute passes)") + : path == MESH_PATH_NATIVE ? "native (VK_EXT_mesh_shader)" : "skipped (no mesh shaders, mesh_fallback = 0)"; + if (path == MESH_PATH_EMULATION) rt_log("vk: mesh shaders: emulated with compute (mesh_emulation = 1); mesh_fallback is not used"); + else if (path == MESH_PATH_FALLBACK) rt_log("vk: mesh fallback: task and mesh programs run as compute passes and are drawn from their buffers (%s)", - g_vk.has_mesh_shader ? "mesh_fallback = 1" : "this device has no mesh shaders"); - else if (!g_vk.has_mesh_shader) + why); + else if (path == MESH_PATH_NONE) rt_log("vk: mesh shaders: not supported and mesh_fallback = 0 (task/mesh draws are skipped)"); } if (g_vk.has_maximal_reconvergence && !c->mrc.shaderMaximalReconvergence) g_vk.has_maximal_reconvergence = 0; diff --git a/runtime/vk_exec.c b/runtime/vk_exec.c index 97fc7d06..99445f60 100644 --- a/runtime/vk_exec.c +++ b/runtime/vk_exec.c @@ -1165,7 +1165,8 @@ static uint64_t n_parts, n_subs, n_idle_parts, n_pass_splits, n_cuts; // tests there; in area loads and some places a tail hands the CPU results and goes as before. The pictures matched // those without it standing, along the route and through warps to five areas. Not measured with the lazy write-back // (NVIDIA's and Intel's default), where a tail's uniform updates are noted as writes and no tail goes early. -// Not with shadow storage, emulated mesh shaders, a frame dump or a pass capture, nor inside a chunk or a continuation. +// Not with shadow storage, emulated mesh shaders, the mesh fallback (vk_mesh_path.h: never measured with the early +// tail), a frame dump or a pass capture, nor inside a chunk or a continuation. static struct { int on; // the submission's tail is being recorded int live0; // vk_mem_live_swap's note from before it @@ -2639,7 +2640,9 @@ static void rec_claim(void) { void vk_exec_tail_begin(VkExec *ex) { if (!tail_enabled() || TL.on || ex != x_cur || rw_chunk || evo_in) return; if (Q.drained != Q.out) group_drain(ex, PW_OP); // the cut needs every piece of the part - if (!vk_sync_wb_split() || !vk_mesh_shader_native() || vk_dump_armed || vk_gpu_passes_capturing()) return; + if (!vk_sync_wb_split() || !vk_mesh_shader_native() || vk_ctx()->mesh_fallback || vk_dump_armed || + vk_gpu_passes_capturing()) + return; if (!vk_sync_tail_ok()) return; if (ex->in_pass) vk_exec_pass_end(ex); vk_exec_barrier(ex); // the command buffer so far ends behind a full barrier, every image back in GENERAL diff --git a/runtime/vk_mesh_path.h b/runtime/vk_mesh_path.h new file mode 100644 index 00000000..c64d5401 --- /dev/null +++ b/runtime/vk_mesh_path.h @@ -0,0 +1,48 @@ +// How the game's task and mesh programs are drawn (vk_device.c create_device). Header only, so that +// tests/mesh_path_check.c checks the decision without a device. +// +// native VK_EXT_mesh_shader pipelines +// fallback the mesh fallback: the programs run as compute passes and an ordinary draw reads what they wrote +// (vk_exec_draw.c "mesh fallback", vk_mesh_fb.c) +// emulation the mesh emulation (mesh_emulation = 1 on a device without mesh shaders, vk_exec_draw.c) +// none a device without mesh shaders with both off: mesh draws are skipped +// +// mesh_fallback = auto (the default) takes the fallback on a device without mesh shaders, and on AMD's Windows driver +// for RDNA 1 and 2 (vk_caps.amd_sc), which has them on RDNA 2. That driver lost the device ("No fault detected", a +// timeout) minutes into play on RX 6600 to RX 6950 XT cards in every version from 0.6.0 to 0.9.2 (0.10.x built its mesh +// pipelines without the driver's optimiser, NX2NAVI_VK_NOOPT, which no reporter has confirmed), with the pipeline +// library, the replay workers, the asynchronous replay, the lazy write-back and the low-end GPU mode each on and off. +// Where the pass marks named the pass the GPU was in, it was one that starts with a native mesh draw. The same driver +// on RDNA 1 has no mesh shaders and draws through this fallback, and AMD's driver for RDNA 3 and 4 (LLPC) draws them +// natively; neither has such a report. That the native mesh path is the cause is not shown: the fallback is what the +// marks leave to try, at the cost of a compute pass and a pass break per mesh draw, and of mesh programs that are +// left out of the picture until their compute passes are built, at their first sight in a run. mesh_fallback = 0 +// draws them natively again; 1 takes the fallback on every device. +#pragma once +#include + +enum { MESH_PATH_NATIVE, MESH_PATH_FALLBACK, MESH_PATH_EMULATION, MESH_PATH_NONE }; + +// has_mesh: the device has VK_EXT_mesh_shader with task and mesh shaders; amd_sc: AMD's Windows driver for RDNA 1 and +// 2; fallback: the mesh_fallback setting ("auto", "0", "1"; anything else reads as auto); emulation: mesh_emulation +// ("0" off). *why: the reason, for the boot line. +static inline int mesh_path_decide(int has_mesh, int amd_sc, const char *fallback, const char *emulation, + const char **why) { + const char *w; + int path; + if (!has_mesh && strcmp(emulation, "0")) + path = MESH_PATH_EMULATION, w = "mesh_emulation = 1 on a device without mesh shaders"; + else if (!strcmp(fallback, "1")) + path = MESH_PATH_FALLBACK, w = "mesh_fallback = 1"; + else if (!strcmp(fallback, "0")) + path = has_mesh ? MESH_PATH_NATIVE : MESH_PATH_NONE, w = "mesh_fallback = 0"; + else if (!has_mesh) + path = MESH_PATH_FALLBACK, w = "this device has no mesh shaders"; + else if (amd_sc) + path = MESH_PATH_FALLBACK, w = "the default on AMD's driver for RDNA 1 and 2, where native mesh pipelines lost " + "the device in play; mesh_fallback = 0 draws them natively"; + else + path = MESH_PATH_NATIVE, w = "VK_EXT_mesh_shader"; + if (why) *why = w; + return path; +} diff --git a/runtime/vk_pipeline.c b/runtime/vk_pipeline.c index 93d8d69a..dfd8c86a 100644 --- a/runtime/vk_pipeline.c +++ b/runtime/vk_pipeline.c @@ -1038,7 +1038,7 @@ static VkPipelineCreateFlags noopt_flag_for(int mesh); static void mesh_lib_init(const VkCtx *c) { const char *why = !c->has_mesh_shader ? "this GPU has no mesh shaders" - : c->mesh_fallback ? "mesh draws go through the mesh fallback (mesh_fallback = 1)" + : c->mesh_fallback ? "mesh draws go through the mesh fallback (vk_device.c, mesh_fallback)" : !vk_caps.gpl ? "the graphics pipeline library is off" : !cfg_bool("NX2NAVI_GPL_MESH") ? "NX2NAVI_GPL_MESH=0" : noopt_flag_for(1) != noopt_flag_for(0) ? "they alone are built without the driver's optimiser " @@ -3379,11 +3379,14 @@ static int is_src1(unsigned f) { return f >= NVN_BLEND_FUNC_SRC1_COLOR && f <= N // ("No fault detected", a timeout) minutes into play on RX 6600 to RX 6950 XT cards in every version from 0.6.0 to // 0.9.2, with the pipeline library on or off and the lazy write-back on or off. Where the reports' pass marks name a // pass the GPU was in, twelve logs of five reporters, it is a pass whose first draw is a mesh pipeline (mesh shader -// ba4302f1 with fragment shader f64a96dd in nine, the one-draw pass of 1bbdb17e with 6cc3a476 in three); the five -// logs of 0.9.1 and 0.9.2 stop between the compute dispatch before such a pass and the pass. No reporter ran with -// the optimiser off, so that it is the cause is not shown: it is the one suspect the marks leave, it costs shader -// speed in those pipelines and not the picture, and NX2NAVI_VK_NOOPT=0 gives the optimised ones back. The flag is -// part of what the driver's cache keys a pipeline by, so those pipelines are built once more after the change. +// ba4302f1 with fragment shader f64a96dd in nine, the one-draw pass of 1bbdb17e with 6cc3a476 in three). The logs of +// 0.9.1 and 0.9.2 end with the game's dispatch of cs d7566eb1 finished and nothing after it marked: the group of draws +// that followed was recorded by the replay workers, whose passes have no marks, so which draw of it hung is not known. +// No reporter ran with the optimiser off, so that it is the cause is not shown: it costs shader speed in those +// pipelines and not the picture, and NX2NAVI_VK_NOOPT=0 gives the optimised ones back. The flag is part of what the +// driver's cache keys a pipeline by, so those pipelines are built once more after the change. +// Since then that driver draws mesh programs through the mesh fallback by default (vk_mesh_path.h), and no mesh +// pipeline is built there: this applies with mesh_fallback = 0 alone, as the 0.10.x way to compare against. static VkPipelineCreateFlags noopt_flag_for(int mesh) { static int on = -1; if (on < 0) { @@ -6031,8 +6034,9 @@ static void prewarm_run(void) { // (NX2NAVI_MESH_EMULATION) it is a vertex pipeline and its compute stages (pipe_miss: layout_get_emu), built // here like the others: left to the first draw, each took 113-830 ms on an RX 580 and the draws waiting for it // were skipped (22 of the 48 pipelines missed entering Kokiri Forest, 0.9.1), frames held back or shown without - // them. - if (is_mesh(&s) && !vk_ctx()->has_mesh_shader && !mesh_emu_on()) { + // them. With the mesh fallback on a device that has mesh shaders (vk_mesh_path.h: AMD's driver for RDNA 1 and + // 2) none is built either: no mesh draw uses one, and that driver is not to compile them. + if (is_mesh(&s) && (vk_ctx()->mesh_fallback || (!vk_ctx()->has_mesh_shader && !mesh_emu_on()))) { dropped++; continue; } @@ -8338,7 +8342,7 @@ static int seed_pipelines(const char *dir) { other++; continue; } - if (is_mesh(&s) && !vk_ctx()->has_mesh_shader) { // this GPU draws no mesh pipeline + if (is_mesh(&s) && (!vk_ctx()->has_mesh_shader || vk_ctx()->mesh_fallback)) { // no mesh draw uses one no_mesh++; continue; } @@ -8840,7 +8844,7 @@ static int save_with(uint32_t wait_ms, int exiting) { (unsigned long long)P.g.ready_fresh); // The mesh pipelines by themselves: with stage libraries the first two numbers follow each other and the // times are a link's; without (the start's line says why) none is linked and the time is a whole build's. - if (vk_ctx()->has_mesh_shader) + if (vk_ctx()->has_mesh_shader && !vk_ctx()->mesh_fallback) rt_log("vk_pipeline: gpl: mesh pipelines (%s): %llu fast links (avg %.2f ms, max %.2f ms); the %llu a draw " "missed were usable after avg %.1f ms, longest %.0f ms, %llu of them through a fast link (the others " "after their whole build); their libraries made in this run: %llu of task and mesh stages (avg %.1f " diff --git a/tests/mesh_path_check.c b/tests/mesh_path_check.c new file mode 100644 index 00000000..6bc38a97 --- /dev/null +++ b/tests/mesh_path_check.c @@ -0,0 +1,50 @@ +// runtime/vk_mesh_path.h: how the game's task and mesh programs are drawn (vk_device.c create_device): natively, through +// the mesh fallback, the mesh emulation or not at all, for each device kind and setting. Built and run by +// tests/mesh_path_check.py; prints each failed check and exits 1 on any. +#include +#include + +#include "vk_mesh_path.h" + +static int fails; +#define CHECK(c, ...) do { if (!(c)) { fails++; printf("FAIL line %d: ", __LINE__); printf(__VA_ARGS__); printf("\n"); } } while (0) + +static const char *const names[] = {"native", "fallback", "emulation", "none"}; + +static void expect(int has_mesh, int amd_sc, const char *mf, const char *me, int want, const char *what) { + const char *why = NULL; + int got = mesh_path_decide(has_mesh, amd_sc, mf, me, &why); + CHECK(got == want, "%s (mesh shaders %d, AMD RDNA 1/2 driver %d, mesh_fallback %s, mesh_emulation %s): %s, not %s", + what, has_mesh, amd_sc, mf, me, names[got], names[want]); + CHECK(why && *why, "%s: no reason for the boot line", what); +} + +int main(void) { + // ---- the default (auto, emulation off) by device + expect(1, 0, "auto", "0", MESH_PATH_NATIVE, "NVIDIA, Intel, Mesa or AMD's RDNA 3/4 driver with mesh shaders"); + expect(1, 1, "auto", "0", MESH_PATH_FALLBACK, "an RX 6000 card on AMD's RDNA 1/2 driver"); + expect(0, 1, "auto", "0", MESH_PATH_FALLBACK, "an RX 5000 card on AMD's RDNA 1/2 driver (no mesh shaders)"); + expect(0, 0, "auto", "0", MESH_PATH_FALLBACK, "a GTX 10 card (no mesh shaders)"); + // ---- mesh_fallback = 0 gives an RX 6000 card native mesh pipelines back, as 0.10.1 drew them + expect(1, 1, "0", "0", MESH_PATH_NATIVE, "an RX 6000 card with mesh_fallback = 0"); + expect(1, 0, "0", "0", MESH_PATH_NATIVE, "a card with mesh shaders and mesh_fallback = 0"); + expect(0, 0, "0", "0", MESH_PATH_NONE, "a card without mesh shaders and mesh_fallback = 0"); + // ---- mesh_fallback = 1 on every device + expect(1, 0, "1", "0", MESH_PATH_FALLBACK, "an NVIDIA card with mesh_fallback = 1"); + expect(1, 1, "1", "0", MESH_PATH_FALLBACK, "an RX 6000 card with mesh_fallback = 1"); + // ---- the mesh emulation acts only without mesh shaders, and then before the fallback + expect(0, 0, "auto", "1", MESH_PATH_EMULATION, "no mesh shaders, mesh_emulation = 1"); + expect(0, 1, "1", "1", MESH_PATH_EMULATION, "no mesh shaders, both set"); + expect(1, 1, "auto", "1", MESH_PATH_FALLBACK, "an RX 6000 card with mesh_emulation = 1 (low_end_gpu)"); + expect(1, 0, "auto", "1", MESH_PATH_NATIVE, "a card with mesh shaders and mesh_emulation = 1"); + // ---- a value the settings table does not list reads as auto + expect(1, 1, "", "0", MESH_PATH_FALLBACK, "an RX 6000 card with an empty mesh_fallback"); + expect(1, 0, "yes", "0", MESH_PATH_NATIVE, "a card with mesh shaders and mesh_fallback = yes"); + // ---- the reason names the driver default, and how to turn it off + const char *why = NULL; + mesh_path_decide(1, 1, "auto", "0", &why); + CHECK(why && strstr(why, "mesh_fallback = 0"), "the RX 6000 default's reason does not say how to turn it off: %s", why ? why : "(none)"); + + printf("mesh_path_check: %s\n", fails ? "FAILED" : "passed"); + return fails ? 1 : 0; +} diff --git a/tests/mesh_path_check.py b/tests/mesh_path_check.py new file mode 100644 index 00000000..fe411db4 --- /dev/null +++ b/tests/mesh_path_check.py @@ -0,0 +1,41 @@ +"""Build and run tests/mesh_path_check.c: runtime/vk_mesh_path.h, how the game's task and mesh programs are drawn +(vk_device.c create_device): natively, through the mesh fallback, the mesh emulation or not at all, for each device kind +and setting. + +No GPU, no game files, any Python. + +Usage: mesh_path_check.py +""" +import os +import shutil +import subprocess +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +MSYS_BIN = Path(r'C:\msys64\ucrt64\bin') + + +def compiler(): + """$CC, else MSYS2 UCRT64's clang, else clang on PATH (as tests/diff/common.py picks it, without its Unicorn).""" + if os.environ.get('CC'): + return os.environ['CC'] + if os.name == 'nt' and (MSYS_BIN / 'clang.exe').exists(): + return str(MSYS_BIN / 'clang.exe') + return shutil.which('clang') or 'clang' + + +def main(): + work = ROOT / 'build' / 'test' / 'mesh_path' + work.mkdir(parents=True, exist_ok=True) + exe = work / ('mesh_path_check.exe' if os.name == 'nt' else 'mesh_path_check') + env = dict(os.environ) + if os.name == 'nt' and MSYS_BIN.exists(): + env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '') + subprocess.check_call([compiler(), '-std=gnu11', '-O1', '-Wall', '-Werror', '-I', str(ROOT / 'runtime'), + str(ROOT / 'tests' / 'mesh_path_check.c'), '-o', str(exe)], env=env) + return subprocess.run([str(exe)], env=env).returncode + + +if __name__ == '__main__': + sys.exit(main())