Sample a flat texture that a shader reads as a 3D one through a one-slice 3D copy instead of a stand-in.

Maxwell samples a texture by its own descriptor, so a 2D texture under a 3D sample gives its texel at (u, v). Vulkan
has no 3D view of a 2D image, and get_view found no view for such a binding: the draw sampled a stand-in. Such a
texture (plain colour, one sample, up to 1024 x 1024 texels) now gets a 3D image of one slice with all of its levels,
made in the upload batch and copied again when the texture was uploaded or drawn into since, or another layer is
asked for (vk_texture.c vk_texture_flat3d_locked). NX2NAVI_TEX_FLAT3D=0 gives the stand-in as before.

Seen in Kakariko: two of the game's 4 x 4 RGBA8 textures are sampled as 3D textures, and each got its copy; the runs
through eight reloads at 60 and 144 fps ended without errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 03:26:09 -05:00
parent 7dcfb72b70
commit bd32077e54
4 changed files with 95 additions and 2 deletions

View File

@@ -754,7 +754,13 @@ static VkImageView get_view(VkExec *ex, const VkTexImage *img, const view_t *v,
switch (vt) {
case VK_IMAGE_VIEW_TYPE_1D:
case VK_IMAGE_VIEW_TYPE_1D_ARRAY: ok = img->type == VK_IMAGE_TYPE_1D; break;
case VK_IMAGE_VIEW_TYPE_3D: ok = img->type == VK_IMAGE_TYPE_3D; break;
case VK_IMAGE_VIEW_TYPE_3D:
ok = img->type == VK_IMAGE_TYPE_3D;
if (!ok && !storage && !ms && img->type == VK_IMAGE_TYPE_2D) { // a flat texture under a 3D sample: its 3D copy
const VkTexImage *f = vk_texture_flat3d_locked(img, hv && v->set_layers ? v->min_layer : 0);
if (f) img = f, ok = 1;
}
break;
case VK_IMAGE_VIEW_TYPE_CUBE:
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
ok = img->type == VK_IMAGE_TYPE_2D && (img->view_type == VK_IMAGE_VIEW_TYPE_CUBE || img->view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY);