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:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-10-26 16:25:56 +03:00
1 parent 05f3643dc0
commit 6029719713
5 files changed
+53 -6

No files matched your search

+3
View File
@@ -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
+8 -1
View File
@@ -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
View File
@@ -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);