mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-20 04:35:57 +00:00
Read depth textures sampled without a compare as one texel, and round the reference of D16 array shadow compares to 16 bits, as MacNativeGames 6283599 does: the game binds linear samplers to depth it reads as data, and the Switch compares D16 against a reference at the texture's precision
The point form of a sampler slot is built once (vk_sampler_point_by_id_locked). Translator patch 0009 rounds the 2DArrayShadow reference in Ryujinx's SPIR-V backend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
05f3643dc0
commit
6029719713
5 files changed
+53
-6
No files matched your search
@@ -258,6 +258,9 @@ void vk_texture_lock(void);
|
||||
void vk_texture_unlock(void);
|
||||
const VkTexImage *vk_texture_by_id_locked(int id, view_t *view, int *has_view);
|
||||
VkSampler vk_sampler_by_id_locked(int id);
|
||||
// The slot's sampler with nearest filtering and no anisotropy: a depth texture read without a compare lands on one texel
|
||||
// on the Switch although the game binds a linear sampler (MacNativeGames 6283599). VK_NULL_HANDLE for an empty slot.
|
||||
VkSampler vk_sampler_point_by_id_locked(int id);
|
||||
uint32_t vk_texture_slots_gen(void);
|
||||
uint32_t vk_sampler_gen(void); // changes whenever a sampler slot is registered
|
||||
void vk_texture_gpu_written(const tex_t *t); // rendered or copied into by the GPU: no re-upload from storage
|
||||
|
||||
@@ -978,7 +978,14 @@ static void tex_info(VkExec *ex, const GfxShaderRes *r, uint64_t h, int storage,
|
||||
if (img) view = get_view(ex, img, &v, hv, r->type, storage);
|
||||
if (img && storage) vk_texture_storage_bound_locked(img);
|
||||
if (img && !storage && ex->nfbl && in_fbl(ex, img->image)) layout = VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT;
|
||||
if (!storage && !separate) samp = vk_sampler_by_id_locked((int)(h >> 20 & 0xfff));
|
||||
if (!storage && !separate) {
|
||||
// A depth texture sampled without a compare reads one texel on the Switch, whatever the sampler's filter:
|
||||
// blending neighbouring depths puts reconstructed positions in mid-air at object edges (shadow masks).
|
||||
int sid = (int)(h >> 20 & 0xfff);
|
||||
int point = img && (img->aspect & VK_IMAGE_ASPECT_DEPTH_BIT) && !(r->type & 0x400) &&
|
||||
vk_exec_view_aspect(img, &v, hv) != VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
samp = point ? vk_sampler_point_by_id_locked(sid) : vk_sampler_by_id_locked(sid);
|
||||
}
|
||||
}
|
||||
if (!view) {
|
||||
int di = dummy_index(res_view_type(r->type), ms);
|
||||
|
||||
+18
-2
@@ -70,7 +70,8 @@ typedef struct {
|
||||
view_t v;
|
||||
tex_t t;
|
||||
} TexSlot;
|
||||
typedef struct { samp_par p; VkSampler s; uint8_t used; } SampSlot; // s: vk_sampler_for(&p) once looked up
|
||||
typedef struct { samp_par p; VkSampler s, sp; uint8_t used; } SampSlot; // s: vk_sampler_for(&p) once looked up; sp:
|
||||
// its point-sampled form (vk_sampler_point_by_id_locked)
|
||||
|
||||
static CRITICAL_SECTION tex_lock;
|
||||
static INIT_ONCE tex_once = INIT_ONCE_STATIC_INIT;
|
||||
@@ -1462,7 +1463,7 @@ void vk_sampler_register(int id, const samp_par *s) {
|
||||
sslots = p, nsslots = n;
|
||||
}
|
||||
sslots[id].p = *s;
|
||||
sslots[id].s = VK_NULL_HANDLE;
|
||||
sslots[id].s = sslots[id].sp = VK_NULL_HANDLE;
|
||||
sslots[id].used = 1;
|
||||
samp_gen++;
|
||||
unlock();
|
||||
@@ -1503,6 +1504,21 @@ VkSampler vk_sampler_by_id_locked(int id) {
|
||||
return v;
|
||||
}
|
||||
|
||||
VkSampler vk_sampler_point_by_id_locked(int id) {
|
||||
VkCtx *c = vk_ctx();
|
||||
if (!c || id < 0 || id >= nsslots || !sslots[id].used) return VK_NULL_HANDLE;
|
||||
SampSlot *s = &sslots[id];
|
||||
if (!s->sp) {
|
||||
samp_par k = s->p;
|
||||
k.magf = NVN_MAG_FILTER_NEAREST;
|
||||
k.minf = k.minf == NVN_MIN_FILTER_LINEAR ? NVN_MIN_FILTER_NEAREST :
|
||||
k.minf > NVN_MIN_FILTER_LINEAR ? NVN_MIN_FILTER_NEAREST_MIPMAP_NEAREST : k.minf;
|
||||
k.aniso = 1;
|
||||
s->sp = sampler_for(c, &k);
|
||||
}
|
||||
return s->sp;
|
||||
}
|
||||
|
||||
VkSampler vk_sampler_by_id(int id) {
|
||||
lock();
|
||||
VkSampler v = vk_sampler_by_id_locked(id);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Build the shader translator: build/xlate/totk_xlate.exe (Ryujinx 1.3.2 + patches, NativeAOT, SPIR-V for Vulkan).
|
||||
|
||||
Copies tools/vendor/ryujinx to build/xlate/ryujinx, applies tools/xlate/patches/*.patch there (tools/vendor stays
|
||||
byte-identical; 0001-0004 are MNG's, 0005 and 0006 are ours), then runs `dotnet publish`. Needs the .NET 10 SDK, the MSVC build
|
||||
byte-identical; 0001-0004 are MNG's, 0005-0009 are ours), then runs `dotnet publish`. Needs the .NET 10 SDK, the MSVC build
|
||||
tools and vswhere.exe (docs/toolchain-windows.md). Run with .venv.
|
||||
|
||||
Next to the exe it writes totk_xlate.id: the translator identity, a sha256 over everything the build reads (this script,
|
||||
@@ -96,8 +96,8 @@ def prepare_sources() -> Path:
|
||||
for junk in list(src.glob("src/*/obj")) + list(src.glob("src/*/bin")):
|
||||
shutil.rmtree(junk)
|
||||
patches = sorted((XLATE / "patches").glob("*.patch"))
|
||||
if len(patches) != 8:
|
||||
sys.exit(f"expected 8 patches, found {len(patches)}")
|
||||
if len(patches) != 9:
|
||||
sys.exit(f"expected 9 patches, found {len(patches)}")
|
||||
for patch in patches:
|
||||
# git apply works outside a repository when given a directory; --check first so a failure names the patch.
|
||||
for extra in (["--check"], []):
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
|
||||
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
|
||||
@@ -1283,6 +1283,18 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
||||
if (isShadow)
|
||||
{
|
||||
dRef = Src(AggregateType.FP32);
|
||||
+
|
||||
+ // TOTK: the shadow cascades are D16 array textures. Maxwell rounds the compare reference to the texture's
|
||||
+ // 16-bit precision before the compare; Vulkan drivers may compare the full float (AMD does), so a lit
|
||||
+ // surface fails its own compare by a fraction of a step and the whole face reads as shadowed. Array
|
||||
+ // compares only: in TotK those are the D16 cascades (MacNativeGames 6283599 rounds the same ones).
|
||||
+ if (isArray)
|
||||
+ {
|
||||
+ SpvInstruction d16Fp32 = context.TypeFP32();
|
||||
+ SpvInstruction d16Clamped = context.GlslFClamp(d16Fp32, dRef, context.Constant(d16Fp32, 0f), context.Constant(d16Fp32, 1f));
|
||||
+ SpvInstruction d16Scaled = context.FAdd(d16Fp32, context.FMul(d16Fp32, d16Clamped, context.Constant(d16Fp32, 65535f)), context.Constant(d16Fp32, 0.5f));
|
||||
+ dRef = context.FMul(d16Fp32, context.GlslFloor(d16Fp32, d16Scaled), context.Constant(d16Fp32, 1f / 65535f));
|
||||
+ }
|
||||
}
|
||||
|
||||
SpvInstruction[] derivatives = null;
|
||||
Reference in new issue
Block a user