mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 06:59:57 -04:00
Create FSR 3.1's pipelines through the pipeline caches kept across runs, so a context is not compiled again at every start the driver's own cache does not serve.
The library creates its pipelines itself and names no pipeline cache. It is now handed pipeline creates of the runtime's in the place of the device's two, and a create without a cache is asked of the pipeline cache first and compiled into the play cache otherwise. ffx_pipe_cache = 0 turns it off. --probe-ffx-cache makes one upscaling context without a window or the game and says where its pipelines came from, and tests/ffx_cache_check.py runs it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -46,7 +46,7 @@ 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_CAM_KEEP", "DLSS_IDLE_FREE", "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", "DUMP_RAW", "DUMP_SHADERS", "DUMP_FILE", "DS3", "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", "CRASH_FILTER_GUARD", "CS_FALLBACK", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
|
||||
"FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLIGHT_EVERY", "FLUSH_SPAN", "FLUSH_UPLOAD", "FOG_CULL", "FOLIAGE_SHADOW_CULL", "FOLIAGE_SHADOW_VRS", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FG_MULT", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FRAMEGEN_MULTIPLIER", "FREEZE_IDLE", "FREE_CORES",
|
||||
"FFX_PIPE_CACHE", "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLIGHT_EVERY", "FLUSH_SPAN", "FLUSH_UPLOAD", "FOG_CULL", "FOLIAGE_SHADOW_CULL", "FOLIAGE_SHADOW_VRS", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FG_MULT", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FRAMEGEN_MULTIPLIER", "FREEZE_IDLE", "FREE_CORES",
|
||||
"FULLSCREEN", "FXAA", "GAME_ASPECT", "GAME_RES", "GPA", "GPA_EMPTY", "GPA_TWIN", "GPA_TWIN_MAX_KB", "GPL", "GPL_DRAW_BUILD", "GPL_FEEDBACK", "PIPE_AHEAD", "PIPE_FAST_WORKERS", "PIPE_FRAME_WAIT_MS", "PIPE_LINK_DRAW_MS", "PIPE_SKIP_STEADY", "PROG_LEAD", "GPU", "GPU_INDEX", "GPU_PASSES", "GPU_NAME", "HDR", "HDR_BLOWOUT", "HDR_CONTRAST",
|
||||
"HDR_EXPOSURE", "HDR_FLARE", "HDR_GAMMA", "HDR_GAME_NITS", "HDR_GRADE", "HDR_HIGHLIGHT_SAT", "HDR_HIGHLIGHTS", "HDR_HUE",
|
||||
"HDR_HUE_CLIP", "HDR_LIVE", "HEAP_LAZY", "HDR_MATCH_SLOPE", "HDR_MIDGRAY",
|
||||
@@ -136,7 +136,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"COMPUTE_KEEP", "performance"},
|
||||
{"PREWARM_XLATE", "performance"}, {"GPL", "performance"}, {"ASTC", "performance"}, {"MEMORY", "performance"},
|
||||
{"TEX_ALIAS", "performance"}, {"DEPTH_INIT_INLINE", "performance"}, {"DEPTH_ALIAS_LOG", "diagnostics"}, {"TEX_DISUSE", "performance"}, {"TEX_DISUSE_EVICT", "performance"}, {"TEX_GEN_UNDO", "performance"}, {"TEX_REUSE", "performance"}, {"TEX_VRAM_PRESSURE", "performance"}, {"TEX_PROC_COMMIT_MB", "performance"}, {"ASTC_BC", "performance"}, {"LOD_GUARD", "performance"}, {"FIX_C0", "performance"}, {"FIX_ZERO", "performance"},
|
||||
{"BIND_SKIP", "performance"}, {"SHADER_CACHE_FLUSH", "performance"}, {"SHADER_CARRY", "performance"}, {"PIPELINE_CACHE_PLAY", "performance"}, {"PIPELINE_CACHE_PLAY_MB", "performance"}, {"SHADER_MEMO", "performance"}, {"PIPE_MEMO", "performance"}, {"TEX_MEMO", "performance"}, {"DESC_TEMPLATE", "performance"},
|
||||
{"BIND_SKIP", "performance"}, {"SHADER_CACHE_FLUSH", "performance"}, {"SHADER_CARRY", "performance"}, {"PIPELINE_CACHE_PLAY", "performance"}, {"PIPELINE_CACHE_PLAY_MB", "performance"}, {"FFX_PIPE_CACHE", "performance"}, {"SHADER_MEMO", "performance"}, {"PIPE_MEMO", "performance"}, {"TEX_MEMO", "performance"}, {"DESC_TEMPLATE", "performance"},
|
||||
{"PUSH_SKIP", "performance"}, {"SPLIT_DRAWS", "performance"}, {"SPLIT_IDLE", "performance"}, {"SPLIT_IN_PASS", "performance"}, {"SPLIT_US", "performance"}, {"VK_VALIDATION", "performance"},
|
||||
{"VK_DYN_VERTEX", "performance"}, {"VK_DYN_A2C", "performance"}, {"VK_SUBGROUP_PIN", "performance"}, {"VK_RECONVERGE", "performance"},
|
||||
{"VK_NAN_PRESERVE", "performance"}, {"VK_NAN_BITS", "performance"},
|
||||
@@ -281,6 +281,7 @@ static const CfgMeta metas[] = {
|
||||
{"PIPE_PREBUILD", "1", "0|1", RESTART}, {"PREWARM_XLATE", "", "1..64", RESTART}, {"GPL", "", "0|1", RESTART}, // vk_caps.c vk_caps_gpl: by the driver, off with AMD's for RDNA 2 and older
|
||||
{"LIB_PREBUILD_BIG_BG", "1", "0|1", RESTART}, {"PIPE_FEEDBACK", "1", "0|1|2", RESTART},
|
||||
{"PIPELINE_CACHE_MAX_MB", "512", "0..65536", RESTART},
|
||||
{"FFX_PIPE_CACHE", "1", "0|1", RESTART}, // vk_ffx.cpp vk_ffx_proc_addr: FSR 3.1's pipelines through the pipeline caches
|
||||
{"PIPELINE_CACHE_PLAY", "1", "0|1", RESTART}, {"PIPELINE_CACHE_PLAY_MB", "64", "1..65536", RESTART}, // vk_pipeline.c "the play cache": what a run compiles goes into a file of its own
|
||||
{"PIPE_BINARIES", "0", "0|1", RESTART}, {"ONESHOT_WAIT_MS", "30000", "0..60000", RESTART}, {"ONESHOT_BUDGET", "1", "0|1", RESTART}, {"PIPE_BINARIES_MAX_MB", "1024", "0..65536", RESTART}, {"BIG_BUILD_FREE_MB", "8192", "0..262144", RESTART},
|
||||
{"BIG_BUILD_MAX_MB", "4096", "0..262144", RESTART},
|
||||
|
||||
@@ -444,6 +444,7 @@ int vk_pipeline_warm_shaders(void); // vk_pipeline.c: --w
|
||||
int vk_pipeline_prepare_pipelines(void); // vk_pipeline.c: --prepare-pipelines (the shared pipeline list)
|
||||
int vk_pipeline_probe_prewarm(void); // vk_pipeline.c: --probe-prewarm
|
||||
int vk_pipeline_probe_buildgate(void); // vk_pipeline.c: --probe-buildgate
|
||||
int vk_ffx_probe_cache(void); // vk_ffx.cpp: --probe-ffx-cache
|
||||
// vk_device.c: the drivers' own shader caches beside the exe (MESA_SHADER_CACHE_DIR, on NVIDIA's Linux driver
|
||||
// __GL_SHADER_DISK_CACHE_PATH and _SIZE) in the environment, once; before any thread can load a Vulkan driver
|
||||
void vk_driver_cache_env(void);
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
// --probe-nvn, --probe-nvn-tex, --probe-window, --probe-shader, --probe-vkmem, --probe-vkexec graphics probes
|
||||
// --probe-prewarm the boot's pipeline stages from the caches next to the executable, the memory each leaves and
|
||||
// what a compute pipeline's first dispatch costs; skips without recorded shaders, runs no game
|
||||
// --probe-ffx-cache one FSR 3.1 upscaling context and where its pipelines came from (the pipeline caches kept
|
||||
// across runs); skips without amd_fidelityfx_vk.dll, runs no game
|
||||
// --probe-astc the compute ASTC decoder against astc_decode_ldr; needs no game files
|
||||
// --probe-zstd host zstd streams (ov_zstd.c) on frames made here; needs no game files
|
||||
// --probe-input gamepad polls on a virtual gamepad, also while SDL's update takes long; needs no game files
|
||||
@@ -534,7 +536,7 @@ static int usage(const char *argv0) {
|
||||
"--probe-cfg | --probe-dpi | --probe-mods | --probe-kernel | --probe-ipc | --probe-services | --probe-fs | --probe-gfx-abi | "
|
||||
"--probe-nvn | --probe-nvn-tex | --probe-window | --probe-shader | --probe-vkmem | "
|
||||
"--probe-vkexec | --probe-astc | --probe-zstd | --probe-input | --probe-movie | --probe-crash-call | --probe-crash-null | --probe-discord | --probe-coop | "
|
||||
"--prepare-shaders | --warm-shaders | --prepare-pipelines | --probe-prewarm | --probe-buildgate | --probe-memneed | --probe-devlost | --boot |--seconds S [--shot PNG]]\n", argv0);
|
||||
"--prepare-shaders | --warm-shaders | --prepare-pipelines | --probe-prewarm | --probe-buildgate | --probe-ffx-cache | --probe-memneed | --probe-devlost | --boot |--seconds S [--shot PNG]]\n", argv0);
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -696,6 +698,7 @@ int main(int argc, char **argv) {
|
||||
if (!strcmp(mode, "--prepare-pipelines")) return vk_pipeline_prepare_pipelines();
|
||||
if (!strcmp(mode, "--probe-prewarm")) return vk_pipeline_probe_prewarm();
|
||||
if (!strcmp(mode, "--probe-buildgate")) return vk_pipeline_probe_buildgate();
|
||||
if (!strcmp(mode, "--probe-ffx-cache")) return vk_ffx_probe_cache();
|
||||
if (!strcmp(mode, "--probe-memneed")) { mem_start_note(1); return 0; }
|
||||
if (!strcmp(mode, "--boot")) { mem_start_note(0); cfg.boot = 1; rt_boot(); return 0; }
|
||||
return usage(argv[0]);
|
||||
|
||||
@@ -874,5 +874,13 @@ void vk_pipeline_autosave(void); // vk_pipeline_save at most every 20
|
||||
void vk_pipeline_shutdown(void); // waits for background builds, saves, destroys pipelines, layouts and the
|
||||
// cache; before vk_shutdown
|
||||
int vk_pipeline_selftest(void); // one graphics and one compute pipeline from census shaders; 0 on success
|
||||
// Pipelines a library creates on our device without a pipeline cache of its own (FSR 3.1, vk_ffx.cpp), through the
|
||||
// pipeline caches kept across runs; as vkCreateComputePipelines (compute 1) or vkCreateGraphicsPipelines with no cache.
|
||||
VkResult vk_pipeline_create_foreign(VkDevice dev, int compute, uint32_t n, const void *infos,
|
||||
const VkAllocationCallbacks *alloc, VkPipeline *out);
|
||||
// How many it made so far: from_cache came without a compile and compiled went into the play cache (both only with a
|
||||
// play cache, which is what can tell them apart); uncached were created with no cache of ours.
|
||||
typedef struct { uint64_t made, from_cache, compiled, uncached; } VkForeignPipes;
|
||||
void vk_pipeline_foreign_counts(VkForeignPipes *o);
|
||||
|
||||
#include "vk_rec.h" // last: its macros route the vkCmd* calls of every file that includes vk.h
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@@ -61,6 +62,54 @@ void message(uint32_t type, const wchar_t *msg) {
|
||||
if (told++ < 40) rt_log("ffx: %s %s", type == FFX_API_MESSAGE_TYPE_ERROR ? "error:" : "warning:", s);
|
||||
}
|
||||
|
||||
// The library's pipeline creates (vk_ffx_proc_addr). It passes no pipeline cache, so one that names none goes through
|
||||
// the runtime's (vk_pipeline.c vk_pipeline_create_foreign); one that names a cache is the library's own business.
|
||||
VKAPI_ATTR VkResult VKAPI_CALL compute_pipelines(VkDevice dev, VkPipelineCache cache, uint32_t n,
|
||||
const VkComputePipelineCreateInfo *ci, const VkAllocationCallbacks *a,
|
||||
VkPipeline *out) {
|
||||
if (cache) return vkCreateComputePipelines(dev, cache, n, ci, a, out);
|
||||
return vk_pipeline_create_foreign(dev, 1, n, ci, a, out);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL graphics_pipelines(VkDevice dev, VkPipelineCache cache, uint32_t n,
|
||||
const VkGraphicsPipelineCreateInfo *ci, const VkAllocationCallbacks *a,
|
||||
VkPipeline *out) {
|
||||
if (cache) return vkCreateGraphicsPipelines(dev, cache, n, ci, a, out);
|
||||
return vk_pipeline_create_foreign(dev, 0, n, ci, a, out);
|
||||
}
|
||||
|
||||
int pipe_cache_on(void) { // NX2NAVI_FFX_PIPE_CACHE, read once
|
||||
static std::atomic<int> on{-1};
|
||||
int v = on.load(std::memory_order_relaxed);
|
||||
if (v < 0) on.store(v = cfg_bool("NX2NAVI_FFX_PIPE_CACHE"), std::memory_order_relaxed);
|
||||
return v;
|
||||
}
|
||||
|
||||
// ffxCreateContext with what it made in pipelines: the library compiles every pass of a context inside this call, on
|
||||
// the thread that asked, so the line says what a context cost and where its pipelines came from.
|
||||
ffxReturnCode_t create_counted(ffxContext *ctx, ffxCreateContextDescHeader *desc) {
|
||||
VkForeignPipes p0, p1;
|
||||
vk_pipeline_foreign_counts(&p0);
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
ffxReturnCode_t r = A.create(ctx, desc, nullptr);
|
||||
double ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count();
|
||||
vk_pipeline_foreign_counts(&p1);
|
||||
unsigned long long made = p1.made - p0.made, hit = p1.from_cache - p0.from_cache, comp = p1.compiled - p0.compiled,
|
||||
none = p1.uncached - p0.uncached;
|
||||
if (r != FFX_API_RETURN_OK) return r;
|
||||
if (!pipe_cache_on())
|
||||
rt_log("ffx: context created in %.0f ms; its pipelines are made without the runtime's pipeline caches "
|
||||
"(NX2NAVI_FFX_PIPE_CACHE=0)", ms);
|
||||
else if (!made)
|
||||
rt_log("ffx: context created in %.0f ms; it made no pipeline through the runtime's creates", ms);
|
||||
else
|
||||
rt_log("ffx: context created in %.0f ms; its %llu pipelines: %llu from the pipeline caches without a compile, "
|
||||
"%llu compiled and kept in the play cache for the next start, %llu through the one pipeline cache (what "
|
||||
"it held is not told apart), %llu with no pipeline cache (none is up yet, or pipeline binaries are on)",
|
||||
ms, made, hit, comp, made - hit - comp - none, none);
|
||||
return r;
|
||||
}
|
||||
|
||||
// One upscaling context per render and output size: each render scale the menu sets brings its own, and so do the
|
||||
// game's second scenes. When all are taken, the least recently used one is destroyed for the new size once the GPU is
|
||||
// idle, as vk_dlaa.c free_size does for DLSS. Without that, a seventh size found no context, and vk_dlaa.c turned
|
||||
@@ -119,7 +168,7 @@ Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
be.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK;
|
||||
be.vkDevice = c->device;
|
||||
be.vkPhysicalDevice = c->phys;
|
||||
be.vkDeviceProcAddr = vkGetDeviceProcAddr;
|
||||
be.vkDeviceProcAddr = vk_ffx_proc_addr;
|
||||
ffxCreateContextDescUpscale d = {};
|
||||
d.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE;
|
||||
d.header.pNext = &be.header;
|
||||
@@ -127,7 +176,7 @@ Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
d.maxRenderSize = {w, h};
|
||||
d.maxUpscaleSize = {ow, oh};
|
||||
d.fpMessage = message;
|
||||
ffxReturnCode_t r = A.create(&slot->ctx, &d.header, nullptr);
|
||||
ffxReturnCode_t r = create_counted(&slot->ctx, &d.header);
|
||||
if (r != FFX_API_RETURN_OK) {
|
||||
rt_log("ffx: FSR 3.1 context creation at %ux%u -> %ux%u failed (%u)", w, h, ow, oh, (unsigned)r);
|
||||
slot->ctx = nullptr;
|
||||
@@ -229,7 +278,55 @@ extern "C" int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const
|
||||
}
|
||||
|
||||
extern "C" ffxReturnCode_t vk_ffx_create(ffxContext *ctx, ffxCreateContextDescHeader *desc) {
|
||||
return vk_ffx_load() ? A.create(ctx, desc, nullptr) : FFX_API_RETURN_ERROR;
|
||||
return vk_ffx_load() ? create_counted(ctx, desc) : FFX_API_RETURN_ERROR;
|
||||
}
|
||||
|
||||
// What the library is handed as ffxCreateBackendVKDesc.vkDeviceProcAddr: the device's functions, with the two
|
||||
// pipeline creates replaced by ours (compute_pipelines, graphics_pipelines) unless NX2NAVI_FFX_PIPE_CACHE is 0.
|
||||
extern "C" VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_ffx_proc_addr(VkDevice dev, const char *name) {
|
||||
if (name && pipe_cache_on()) {
|
||||
if (!strcmp(name, "vkCreateComputePipelines")) return (PFN_vkVoidFunction)compute_pipelines;
|
||||
if (!strcmp(name, "vkCreateGraphicsPipelines")) return (PFN_vkVoidFunction)graphics_pipelines;
|
||||
}
|
||||
return vkGetDeviceProcAddr(dev, name);
|
||||
}
|
||||
|
||||
// --probe-ffx-cache (host.h): one FSR 3.1 upscaling context on the device, without a window or the game, and where
|
||||
// its pipelines came from. The pipeline caches are those beside the executable, or NX2NAVI_PIPELINE_CACHE's, and are
|
||||
// saved as after a run, so a second run of the probe shows what the first one's files give
|
||||
// (tests/ffx_cache_check.py runs it twice on a folder of its own). Fails when the context is not created, or when
|
||||
// the library made no pipeline through the runtime's creates although they are on.
|
||||
extern "C" int vk_ffx_probe_cache(void) {
|
||||
if (!vk_init()) {
|
||||
printf("probe-ffx-cache: SKIP (no Vulkan device)\n");
|
||||
return 0;
|
||||
}
|
||||
if (!vk_ffx_load()) {
|
||||
printf("probe-ffx-cache: SKIP (no amd_fidelityfx_vk.dll beside the executable, or a build without FSR 3.1)\n");
|
||||
return 0;
|
||||
}
|
||||
vk_pipeline_push_fn(); // the first vk_pipeline_* call reads the pipeline caches
|
||||
VkForeignPipes p0, p1;
|
||||
vk_pipeline_foreign_counts(&p0);
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
Up *u = context_for(1280, 720, 2560, 1440);
|
||||
double ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count();
|
||||
vk_pipeline_foreign_counts(&p1);
|
||||
unsigned long long made = p1.made - p0.made, hit = p1.from_cache - p0.from_cache, comp = p1.compiled - p0.compiled,
|
||||
none = p1.uncached - p0.uncached;
|
||||
int on = pipe_cache_on(), fails = 0;
|
||||
printf("probe-ffx-cache: context %s in %.0f ms; pipelines made through the runtime's creates: %llu (from the "
|
||||
"pipeline caches %llu, compiled into the play cache %llu, through the one cache %llu, with no cache %llu); "
|
||||
"NX2NAVI_FFX_PIPE_CACHE %d\n", u ? "created" : "not created", ms, made, hit, comp, made - hit - comp - none,
|
||||
none, on);
|
||||
if (!u) fails++, printf("probe-ffx-cache: FAIL: no context\n");
|
||||
if (u && on && !made) fails++, printf("probe-ffx-cache: FAIL: the library created its pipelines past the runtime\n");
|
||||
if (u && !on && made) fails++, printf("probe-ffx-cache: FAIL: pipelines came through the runtime with the setting 0\n");
|
||||
vk_queue_lock(), vkDeviceWaitIdle(vk_ctx()->device), vk_queue_unlock();
|
||||
vk_ffx_release();
|
||||
vk_pipeline_save();
|
||||
printf("probe-ffx-cache: %s\n", fails ? "FAILED" : "passed");
|
||||
return fails ? 1 : 0;
|
||||
}
|
||||
extern "C" ffxReturnCode_t vk_ffx_destroy(ffxContext *ctx) { return A.ok ? A.destroy(ctx, nullptr) : FFX_API_RETURN_ERROR; }
|
||||
extern "C" ffxReturnCode_t vk_ffx_configure(ffxContext *ctx, const ffxConfigureDescHeader *desc) {
|
||||
|
||||
@@ -22,6 +22,9 @@ int vk_ffx_framegen_available(void);
|
||||
int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv,
|
||||
const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y);
|
||||
void vk_ffx_release(void); // before the device goes away
|
||||
// The device's functions as the library is given them (ffxCreateBackendVKDesc.vkDeviceProcAddr): its pipeline creates
|
||||
// go through the runtime's pipeline caches (vk_pipeline.c vk_pipeline_create_foreign; NX2NAVI_FFX_PIPE_CACHE=0: not).
|
||||
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_ffx_proc_addr(VkDevice dev, const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
// The API's calls themselves, for vk_fg.cpp (0 = FFX_API_RETURN_OK): the library loaded first (vk_ffx_load).
|
||||
|
||||
@@ -200,7 +200,7 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt,
|
||||
be.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK;
|
||||
be.vkDevice = c->device;
|
||||
be.vkPhysicalDevice = c->phys;
|
||||
be.vkDeviceProcAddr = vkGetDeviceProcAddr;
|
||||
be.vkDeviceProcAddr = vk_ffx_proc_addr;
|
||||
// the HUD-less picture has the swapchain's format (gfx_present.c hudless_record)
|
||||
ffxCreateContextDescFrameGenerationHudless hl = {};
|
||||
hl.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION_HUDLESS;
|
||||
|
||||
@@ -593,6 +593,82 @@ static VkResult pipe_create_in(int kind, void *ci, VkPipeline *pipe, VkPipelineC
|
||||
return r;
|
||||
}
|
||||
|
||||
// ---- pipelines of a library that draws on our device (FSR 3.1: vk_ffx.cpp vk_ffx_proc_addr)
|
||||
// Such a library creates its pipelines itself and passes no pipeline cache, so nothing of ours kept them: every
|
||||
// context it made (one per render and output size, and one for frame generation) compiled its passes again unless the
|
||||
// driver's own disk cache still had them, which a renamed or updated exe on NVIDIA and a driver without a disk cache
|
||||
// do not. vk_ffx.cpp hands the library these creates in the place of vkCreateComputePipelines and
|
||||
// vkCreateGraphicsPipelines; a create that names no cache goes through ours as pipe_create_in does: asked of P.cache
|
||||
// first without compiling, and compiled into the play cache when neither it nor the driver has the pipeline, so the
|
||||
// file a run writes (pipeline-cache-play.bin, or pipeline-cache.bin without a play cache) holds it for the next start.
|
||||
// Before the first pipeline of ours (P.ready 0) and with pipeline binaries on there is no cache to give: the create
|
||||
// goes to the driver as the library asked. infos: n VkComputePipelineCreateInfo (compute 1) or
|
||||
// VkGraphicsPipelineCreateInfo. Any thread.
|
||||
static struct { volatile uint64_t made, from_cache, compiled, uncached; } FP;
|
||||
|
||||
void vk_pipeline_foreign_counts(VkForeignPipes *o) {
|
||||
o->made = __atomic_load_n(&FP.made, __ATOMIC_RELAXED), o->from_cache = __atomic_load_n(&FP.from_cache, __ATOMIC_RELAXED);
|
||||
o->compiled = __atomic_load_n(&FP.compiled, __ATOMIC_RELAXED), o->uncached = __atomic_load_n(&FP.uncached, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
static VkResult foreign_one(VkDevice dev, int compute, VkPipelineCache cache, uint32_t n, const void *ci,
|
||||
const VkAllocationCallbacks *alloc, VkPipeline *out) {
|
||||
return compute ? vkCreateComputePipelines(dev, cache, n, ci, alloc, out)
|
||||
: vkCreateGraphicsPipelines(dev, cache, n, ci, alloc, out);
|
||||
}
|
||||
|
||||
VkResult vk_pipeline_create_foreign(VkDevice dev, int compute, uint32_t n, const void *infos,
|
||||
const VkAllocationCallbacks *alloc, VkPipeline *out) {
|
||||
VkPipelineCache cache = __atomic_load_n(&P.ready, __ATOMIC_ACQUIRE) && dev == P.device ? P.cache : VK_NULL_HANDLE;
|
||||
if (!cache) {
|
||||
VkResult r = foreign_one(dev, compute, VK_NULL_HANDLE, n, infos, alloc, out);
|
||||
if (r == VK_SUCCESS) __atomic_fetch_add(&FP.made, n, __ATOMIC_RELAXED), __atomic_fetch_add(&FP.uncached, n, __ATOMIC_RELAXED);
|
||||
return r;
|
||||
}
|
||||
VkResult r = VK_SUCCESS;
|
||||
plat_mutex_lock_shared(&cache_rw);
|
||||
if (!P.play) { // one cache: whether it held them is not known here; its save looks at the data's size
|
||||
r = foreign_one(dev, compute, cache, n, infos, alloc, out);
|
||||
if (r == VK_SUCCESS) __atomic_fetch_add(&FP.made, n, __ATOMIC_RELAXED), __atomic_fetch_add(&cache_merges, n, __ATOMIC_RELAXED);
|
||||
}
|
||||
for (uint32_t i = 0; P.play && i < n; i++) {
|
||||
// a copy of the create info: the flags are ours to change, the library's struct is not
|
||||
VkComputePipelineCreateInfo cc;
|
||||
VkGraphicsPipelineCreateInfo gc;
|
||||
void *ci;
|
||||
if (compute) cc = ((const VkComputePipelineCreateInfo *)infos)[i], ci = &cc;
|
||||
else gc = ((const VkGraphicsPipelineCreateInfo *)infos)[i], ci = &gc;
|
||||
PipeCiHead *hd = ci;
|
||||
// Flags given in a VkPipelineCreateFlags2CreateInfo replace the struct's own, so the question "without
|
||||
// compiling" cannot be put through hd->flags: such a create goes to the play cache at once.
|
||||
int flags2 = 0;
|
||||
for (const VkBaseInStructure *b = hd->pNext; b && !flags2; b = b->pNext)
|
||||
flags2 = b->sType == VK_STRUCTURE_TYPE_PIPELINE_CREATE_FLAGS_2_CREATE_INFO_KHR;
|
||||
VkPipelineCreateFlags flags = hd->flags;
|
||||
VkResult ri = VK_PIPELINE_COMPILE_REQUIRED;
|
||||
out[i] = VK_NULL_HANDLE;
|
||||
if (!flags2) {
|
||||
hd->flags = flags | VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT;
|
||||
ri = foreign_one(dev, compute, cache, 1, ci, alloc, &out[i]);
|
||||
hd->flags = flags;
|
||||
if (ri == VK_SUCCESS) __atomic_fetch_add(&FP.from_cache, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
if (ri == VK_PIPELINE_COMPILE_REQUIRED) {
|
||||
ri = foreign_one(dev, compute, P.play, 1, ci, alloc, &out[i]);
|
||||
if (ri == VK_SUCCESS) {
|
||||
__atomic_fetch_add(&FP.compiled, 1, __ATOMIC_RELAXED);
|
||||
__atomic_fetch_add(&P.play_made, 1, __ATOMIC_RELAXED);
|
||||
__atomic_fetch_add(&cache_merges, 1, __ATOMIC_RELAXED); // autosave_once: the play file is due
|
||||
}
|
||||
}
|
||||
if (ri == VK_SUCCESS) __atomic_fetch_add(&FP.made, 1, __ATOMIC_RELAXED);
|
||||
else if (r == VK_SUCCESS) r = ri; // the first that failed, as a create of several reports one result
|
||||
if (ri != VK_SUCCESS) out[i] = VK_NULL_HANDLE;
|
||||
}
|
||||
plat_mutex_unlock_shared(&cache_rw);
|
||||
return r;
|
||||
}
|
||||
|
||||
static VkResult pipe_create(int kind, void *ci, VkPipeline *pipe) {
|
||||
PipeCiHead *hd = ci;
|
||||
VkResult r;
|
||||
|
||||
Reference in New Issue
Block a user