mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 01:49:59 -04:00
Check three of this pass's decisions without a device: the automatic texture detail, the device made with DLSS Frame Generation on, and the mesh fallback's depth hold.
Each decision moves into a header the runtime and a test both read, as vk_mesh_path.h does: vk_tex_detail.h (tex_detail_auto), vk_dlssg_device.h (dlssg_card_skipped, dlssg_device_create) and mesh_fb_hold.h (the hold's table). The runtime's behaviour is the same as before the move. tests/tex_detail_check has the budgets from players' logs of 0.10.1 (a handheld's integrated GPU at 10,361 MiB now gets reduced, a 12 GiB card at 11,313 MiB full). tests/dlssg_device_check plays the laptop of the report with stand-ins for the interposer and the loader: the chosen Intel card is skipped, the NVIDIA card is made through the interposer, a card of another vendor is made by the loader without the interposer being asked, and a refusal falls through to the loader. tests/mesh_fb_hold_check holds a list for two presents after its colour draw was skipped, through a wait of 600 frames, and no longer once it is drawn or gone. Built against the rule 0.10.1 had, the first two and mesh_path_check fail (6, 13 and 3 checks). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
31
runtime/mesh_fb_hold.h
Normal file
31
runtime/mesh_fb_hold.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// The mesh fallback's depth hold (vk_exec_draw.c "a list's depth-only draw is held"): which lists' colour draws were
|
||||
// skipped lately. Header only, so that tests/mesh_fb_hold_check.c checks the table without a device.
|
||||
//
|
||||
// A list is its indirect record's address in the game's memory (below 2^39). One word per slot: the address above
|
||||
// MFB_HOLD_BITS bits of the present count. The colour draw stamps its list with the present it was skipped in and
|
||||
// clears the stamp when it is drawn; the list is held while the stamp is at most MFB_HOLD_PRESENTS presents old.
|
||||
// Read and written by the replay's threads without a lock: a lost update costs a list one frame of the hold, and two
|
||||
// lists in one slot (MFB_HOLD_SLOTS of them, by a hash of the address) hold only the one stamped last.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#define MFB_HOLD_SLOTS 1024
|
||||
#define MFB_HOLD_PRESENTS 2
|
||||
#define MFB_HOLD_BITS 24
|
||||
#define MFB_HOLD_MASK ((1ull << MFB_HOLD_BITS) - 1)
|
||||
|
||||
static inline uint32_t mfb_hold_index(uint64_t list) { return (uint32_t)((list >> 2) * 0x9e3779b1u) >> 22; }
|
||||
|
||||
// The list's colour draw was skipped for its modules or pipeline (waits 1) at this present, or was drawn (0).
|
||||
static inline void mfb_hold_mark(volatile uint64_t *tab, uint64_t list, int waits, uint64_t present) {
|
||||
volatile uint64_t *slot = &tab[mfb_hold_index(list)];
|
||||
if (waits) __atomic_store_n(slot, list << MFB_HOLD_BITS | (present & MFB_HOLD_MASK), __ATOMIC_RELAXED);
|
||||
else if (__atomic_load_n(slot, __ATOMIC_RELAXED) >> MFB_HOLD_BITS == list) __atomic_store_n(slot, 0, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
// Whether the list's depth-only draw is held at this present.
|
||||
static inline int mfb_hold_test(const volatile uint64_t *tab, uint64_t list, uint64_t present) {
|
||||
uint64_t w = __atomic_load_n(&tab[mfb_hold_index(list)], __ATOMIC_RELAXED);
|
||||
if (!w || w >> MFB_HOLD_BITS != list) return 0;
|
||||
return ((present - w) & MFB_HOLD_MASK) <= MFB_HOLD_PRESENTS;
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "vk_gpa.h"
|
||||
#include "vk_fg.h"
|
||||
#include "vk_dlssg.h"
|
||||
#include "vk_dlssg_device.h"
|
||||
#include "vk_lowlat.h"
|
||||
#include "vk_mesh_path.h"
|
||||
|
||||
@@ -272,7 +273,7 @@ retry:
|
||||
// (vk_dlssg_create_device), and the settings ask for what only an NVIDIA card runs. Not usable, so the best
|
||||
// usable one is taken below, as for a card that is gone; where no NVIDIA card is usable either, the pass
|
||||
// without a choice takes what there is and the device is made without frame generation.
|
||||
if ((want >= 0 || (name && *name)) && vk_dlssg_interposed() && p.vendorID != 0x10de) {
|
||||
if (dlssg_card_skipped(vk_dlssg_interposed(), want >= 0 || (name && *name), p.vendorID)) {
|
||||
rt_log("vk: gpu %u skipped: DLSS Frame Generation is on (framegen = dlss), which only an NVIDIA card runs", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "vk.h"
|
||||
#include "vk_dlaa.h"
|
||||
#include "vk_dlssg.h"
|
||||
#include "vk_dlssg_device.h"
|
||||
#include "dlssg/nx2_sl.h"
|
||||
#include "ui/menu.h"
|
||||
|
||||
@@ -213,20 +214,31 @@ static void give_up(const char *why) {
|
||||
// set to DLSS and the Graphics card setting on the Intel one, that ended every start with "no usable Vulkan device"
|
||||
// (exit code 70) until nx2navi.ini was edited by hand: four reports on 0.10.1. A device of another vendor is now made
|
||||
// by the loader, without frame generation, and so is one the interposer refuses for any other reason.
|
||||
// The order of the attempts is vk_dlssg_device.h's dlssg_device_create (tests/dlssg_device_check.c).
|
||||
typedef struct { PFN_vkCreateDevice f; VkPhysicalDevice pd; const VkDeviceCreateInfo *ci; VkDevice *out; } DevCreate;
|
||||
static int create_interposed(void *u) {
|
||||
const DevCreate *d = u;
|
||||
return (int)d->f(d->pd, d->ci, NULL, d->out);
|
||||
}
|
||||
static int create_loader(void *u) {
|
||||
const DevCreate *d = u;
|
||||
return (int)vkCreateDevice(d->pd, d->ci, NULL, d->out);
|
||||
}
|
||||
|
||||
VkResult vk_dlssg_create_device(VkInstance inst, VkPhysicalDevice pd, const VkDeviceCreateInfo *ci, VkDevice *out) {
|
||||
if (S.loaded > 0) {
|
||||
VkPhysicalDeviceProperties p;
|
||||
vkGetPhysicalDeviceProperties(pd, &p);
|
||||
if (p.vendorID != 0x10de) give_up("the graphics card in use is not an NVIDIA card (the Graphics card setting, gpu_index)");
|
||||
VkPhysicalDeviceProperties p;
|
||||
vkGetPhysicalDeviceProperties(pd, &p);
|
||||
DevCreate d = {S.loaded > 0 ? (PFN_vkCreateDevice)S.gipa()(inst, "vkCreateDevice") : NULL, pd, ci, out};
|
||||
int how, refused;
|
||||
VkResult r = (VkResult)dlssg_device_create(d.f != NULL, p.vendorID, create_interposed, create_loader, &d, &how, &refused);
|
||||
if (how == DLSSG_DEV_NOT_NVIDIA) {
|
||||
give_up("the graphics card in use is not an NVIDIA card (the Graphics card setting, gpu_index)");
|
||||
} else if (how == DLSSG_DEV_REFUSED) {
|
||||
char why[96];
|
||||
snprintf(why, sizeof why, "Streamline could not make the device (%d)", refused);
|
||||
give_up(why);
|
||||
}
|
||||
PFN_vkCreateDevice f = S.loaded > 0 ? (PFN_vkCreateDevice)S.gipa()(inst, "vkCreateDevice") : NULL;
|
||||
if (!f) return vkCreateDevice(pd, ci, NULL, out);
|
||||
VkResult r = f(pd, ci, NULL, out);
|
||||
if (r == VK_SUCCESS) return r;
|
||||
char why[96];
|
||||
snprintf(why, sizeof why, "Streamline could not make the device (%d)", (int)r);
|
||||
give_up(why);
|
||||
return vkCreateDevice(pd, ci, NULL, out);
|
||||
return r;
|
||||
}
|
||||
|
||||
void vk_dlssg_device_ready(VkPhysicalDevice physical, VkDevice dev) {
|
||||
|
||||
39
runtime/vk_dlssg_device.h
Normal file
39
runtime/vk_dlssg_device.h
Normal file
@@ -0,0 +1,39 @@
|
||||
// DLSS Frame Generation and the card the device is made on (vk_device.c pick_device, vk_dlssg.c
|
||||
// vk_dlssg_create_device). Header only, so that tests/dlssg_device_check.c checks both decisions without a device.
|
||||
//
|
||||
// With frame generation on, the instance and the device are made through Streamline's interposer, whose vkCreateDevice
|
||||
// asks the card for NVIDIA's extensions (VK_NV_low_latency2 among them) and fails without them
|
||||
// (VK_ERROR_EXTENSION_NOT_PRESENT, -7). On a laptop with an NVIDIA card and Intel graphics, framegen = dlss and
|
||||
// gpu_index on the Intel one, that was the only attempt, and every start ended with "no usable Vulkan device" (exit
|
||||
// code 70) until nx2navi.ini was edited by hand.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#define DLSSG_VENDOR_NVIDIA 0x10deu
|
||||
|
||||
// pick_device: a card the player chose (gpu_index, gpu_name) counts as not usable while the interposer is in use and
|
||||
// the card is of another vendor, so the best usable card is taken instead, as for a chosen card that is gone. Without
|
||||
// a choice nothing is skipped: the pass takes what there is, and dlssg_device_create makes the device.
|
||||
static inline int dlssg_card_skipped(int interposed, int chosen, uint32_t vendor) {
|
||||
return interposed && chosen && vendor != DLSSG_VENDOR_NVIDIA;
|
||||
}
|
||||
|
||||
// A creation attempt: 0 (VK_SUCCESS) or the VkResult it failed with.
|
||||
typedef int (*DlssgCreate)(void *user);
|
||||
|
||||
// How the device was made, or tried: by the loader with the interposer not in use; through the interposer; by the
|
||||
// loader because the card is not an NVIDIA one (the interposer is not asked); by the loader after the interposer
|
||||
// refused (*refused holds its result). In the last two frame generation is off for the run.
|
||||
enum { DLSSG_DEV_LOADER, DLSSG_DEV_INTERPOSER, DLSSG_DEV_NOT_NVIDIA, DLSSG_DEV_REFUSED };
|
||||
|
||||
// Returns the result of the attempt that counts: the interposer's when it made the device, else the loader's.
|
||||
static inline int dlssg_device_create(int interposed, uint32_t vendor, DlssgCreate via_interposer, DlssgCreate via_loader,
|
||||
void *user, int *how, int *refused) {
|
||||
*refused = 0;
|
||||
if (!interposed) return *how = DLSSG_DEV_LOADER, via_loader(user);
|
||||
if (vendor != DLSSG_VENDOR_NVIDIA) return *how = DLSSG_DEV_NOT_NVIDIA, via_loader(user);
|
||||
int r = via_interposer(user);
|
||||
if (!r) return *how = DLSSG_DEV_INTERPOSER, 0;
|
||||
*refused = r;
|
||||
return *how = DLSSG_DEV_REFUSED, via_loader(user);
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "vk_exec.h"
|
||||
#include "vk_gpa.h"
|
||||
#include "mesh_fb.h"
|
||||
#include "mesh_fb_hold.h"
|
||||
#include "vk_mesh_fb.h"
|
||||
#include "vk_scratch_lru.h"
|
||||
#include "vk_index_rewrite.h"
|
||||
@@ -4482,10 +4483,8 @@ static const VkPipeInfo *PD_info; // the pipeline of the last draw prepare_dra
|
||||
// skipped in and clears the stamp when it is drawn; the depth-only draw, which comes first in the frame, is held when
|
||||
// the stamp is at most MFB_HOLD_PRESENTS presents old, so a list whose colour draw no longer comes is held no longer
|
||||
// than that. A draw whose stages write memory is never held (mfb_draw): the writes are wanted whatever is drawn.
|
||||
// One word per slot (the address above 24 bits of the present count), read and written by the replay's threads without
|
||||
// a lock: a lost update costs a list one frame of the hold. NX2NAVI_MESH_FALLBACK_HOLD=0 turns it off.
|
||||
#define MFB_HOLD_SLOTS 1024
|
||||
#define MFB_HOLD_PRESENTS 2
|
||||
// The table is mesh_fb_hold.h's (tests/mesh_fb_hold_check.c), read and written by the replay's threads without a lock:
|
||||
// a lost update costs a list one frame of the hold. NX2NAVI_MESH_FALLBACK_HOLD=0 turns it off.
|
||||
static volatile uint64_t mfb_hold[MFB_HOLD_SLOTS];
|
||||
static volatile uint64_t mfb_held_draws;
|
||||
|
||||
@@ -4495,23 +4494,13 @@ static int mfb_hold_on(void) {
|
||||
return on;
|
||||
}
|
||||
|
||||
static volatile uint64_t *mfb_hold_slot(uint64_t list) {
|
||||
return &mfb_hold[(uint32_t)((list >> 2) * 0x9e3779b1u) >> 22];
|
||||
}
|
||||
|
||||
// The list's colour draw was skipped for its modules or pipeline (waits 1), or was drawn (0).
|
||||
static void mfb_hold_set(uint64_t list, int waits) {
|
||||
volatile uint64_t *slot = mfb_hold_slot(list);
|
||||
if (waits)
|
||||
__atomic_store_n(slot, list << 24 | (__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED) & 0xffffff),
|
||||
__ATOMIC_RELAXED);
|
||||
else if (__atomic_load_n(slot, __ATOMIC_RELAXED) >> 24 == list) __atomic_store_n(slot, 0, __ATOMIC_RELAXED);
|
||||
mfb_hold_mark(mfb_hold, list, waits, __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED));
|
||||
}
|
||||
|
||||
static int mfb_held(uint64_t list) {
|
||||
uint64_t w = __atomic_load_n(mfb_hold_slot(list), __ATOMIC_RELAXED);
|
||||
if (!w || w >> 24 != list) return 0;
|
||||
return ((__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED) - w) & 0xffffff) <= MFB_HOLD_PRESENTS;
|
||||
return mfb_hold_test(mfb_hold, list, __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED));
|
||||
}
|
||||
|
||||
// A held depth-only draw is left out, counted as a draw whose own pipeline is building: the frame lacks it for the
|
||||
|
||||
20
runtime/vk_tex_detail.h
Normal file
20
runtime/vk_tex_detail.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// The level texture_detail = auto picks (vk_texture.c "texture detail", vk_texture_detail_auto). Header only, so that
|
||||
// tests/tex_detail_check.c checks the choice without a device.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
// Full from DETAIL_FULL_MB of device-local budget on, low under DETAIL_LOW_MB, reduced between; under DETAIL_RGBA8_MB
|
||||
// one step lower where the ASTC textures stay uncompressed. vk_texture.c says where each number comes from.
|
||||
#define DETAIL_FULL_MB 10240
|
||||
#define DETAIL_LOW_MB 6144
|
||||
#define DETAIL_RGBA8_MB 20480
|
||||
|
||||
// mb: the device-local budget in MiB, 0 when the device reports none. shared: the video memory is the system's own
|
||||
// (an integrated GPU), whose budget is a share of the PC's memory: never full. rgba8: the ASTC textures stay RGBA8
|
||||
// here (astc = cpu, a card without the decoder, astc_bc = 0). Returns 0 full, 1 reduced, 2 low.
|
||||
static inline int tex_detail_auto(int64_t mb, int shared, int rgba8) {
|
||||
int most = !mb || mb >= DETAIL_FULL_MB ? 0 : mb >= DETAIL_LOW_MB ? 1 : 2;
|
||||
if (mb && !most && shared) most = 1;
|
||||
if (mb && mb < DETAIL_RGBA8_MB && most < 2 && rgba8) most++;
|
||||
return most;
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "vk_dlaa.h"
|
||||
#include "vk_exec.h"
|
||||
#include "vk_tex_compact.h"
|
||||
#include "vk_tex_detail.h"
|
||||
#include "vk_tex_release.h"
|
||||
#include "prof.h"
|
||||
#include "platform/platform.h"
|
||||
@@ -1118,15 +1119,13 @@ static int astc_opaque(const tex_t *t, uint64_t addr, const TexVkFormat *f) {
|
||||
// An integrated GPU's budget is a share of the system's memory, not memory of its own: one reported 10,361 MiB on a
|
||||
// handheld with 16 GiB of memory in all, auto chose full, and the game ended when a save was loaded until its player
|
||||
// set reduced. auto never chooses full there.
|
||||
// The choice itself is vk_tex_detail.h's tex_detail_auto, with the three budgets (tests/tex_detail_check.c).
|
||||
#define DETAIL_MIN 256
|
||||
#define DETAIL_LOW_MIN 1024
|
||||
#define DETAIL_FULL_MB 10240
|
||||
#define DETAIL_LOW_MB 6144
|
||||
// The levels above assume the ASTC textures end as BC3 (or stay ASTC), a byte a texel. Where they stay RGBA8 (astc =
|
||||
// cpu, a card without the decoder, astc_bc = 0) they take four times that, which is what one level left out gives
|
||||
// back: under this budget auto then goes one step lower. A card with 8 GiB that decoded on the CPU held two texture
|
||||
// arrays of 852 MiB each, was 560 MiB over its budget and lost its device.
|
||||
#define DETAIL_RGBA8_MB 20480
|
||||
#define EXACT_MAX 65536
|
||||
static nvn_hmap exact = {.klen = sizeof(TexKey)}; // keys made whole whatever the setting; value 1
|
||||
static uint64_t n_exact; // textures made whole again so far
|
||||
@@ -1150,10 +1149,7 @@ int vk_texture_detail_auto(void) {
|
||||
mb = vk_mem_vram(&used, &budget, &exact_budget) ? (int64_t)(budget >> 20) : 0;
|
||||
__atomic_store_n(&detail_budget_mb, mb, __ATOMIC_RELAXED);
|
||||
}
|
||||
int most = !mb || mb >= DETAIL_FULL_MB ? 0 : mb >= DETAIL_LOW_MB ? 1 : 2;
|
||||
if (mb && !most && detail_shared()) most = 1;
|
||||
if (mb && mb < DETAIL_RGBA8_MB && most < 2 && vk_astc_mode() != VK_ASTC_NATIVE && !vk_astc_bc()) most++;
|
||||
return most;
|
||||
return tex_detail_auto(mb, detail_shared(), vk_astc_mode() != VK_ASTC_NATIVE && !vk_astc_bc());
|
||||
}
|
||||
|
||||
static const char *const detail_names[3] = {"full", "reduced", "low"};
|
||||
|
||||
Reference in New Issue
Block a user