mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 04:15:57 +00:00
Size a pass without attachments by the far corner of viewport 0, else of the scissor, and reopen it when a draw needs more area, as MacNativeGames 62da927 does; an offset viewport no longer falls outside the scissor
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f25c818f7b
commit
7ceda9475b
3 files changed
+31
-3
No files matched your search
+23
-3
@@ -12,6 +12,7 @@
|
||||
// full barrier before each pass), the scissor clip and attachment clears follow LAS Recomp
|
||||
// runtime/nvn/vulkan/exec.c:855-1149, 3553-3778 (https://github.com/peiikai/LASRecomp @
|
||||
// da35b83a9611d046a9a681aae668d7085954d37f, MIT, Copyright (c) 2026 Peiikai).
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -204,6 +205,21 @@ static void resolve_target(const tex_t *t, const view_t *v, int has_v, int depth
|
||||
if (!o->aspect) o->image = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
/* The size of a pass without attachments: the far corner of viewport 0, else of the scissor, 1..16384 (MacNativeGames
|
||||
62da927, nxnative 7ed061f). TotK draws a fragment shader that only writes a storage buffer into a 1x1 viewport; a
|
||||
pass sized by the viewport's width alone puts an offset viewport outside the scissor, and the cave rock loses its
|
||||
ambient light. */
|
||||
void vk_exec_noatt_dims(const VkExec *ex, uint32_t *w, uint32_t *h) {
|
||||
double x1 = 0, y1 = 0;
|
||||
if (ex->has_vp) {
|
||||
x1 = ceil(fmax(ex->vp[0][0], ex->vp[0][0] + ex->vp[0][2]));
|
||||
y1 = ceil(fmax(ex->vp[0][1], ex->vp[0][1] + ex->vp[0][3]));
|
||||
}
|
||||
if ((x1 < 1 || y1 < 1) && ex->has_scissor) x1 = (double)ex->scissor.x + ex->scissor.w, y1 = (double)ex->scissor.y + ex->scissor.h;
|
||||
*w = x1 < 1 ? 1 : x1 > 16384 ? 16384 : (uint32_t)x1;
|
||||
*h = y1 < 1 ? 1 : y1 > 16384 ? 16384 : (uint32_t)y1;
|
||||
}
|
||||
|
||||
// Resolves ex->rt to this command buffer's images and derives the pass parameters and the pipeline's target formats.
|
||||
static void resolve_rt(VkExec *ex) {
|
||||
if (ex->rt_resolved) return;
|
||||
@@ -233,10 +249,14 @@ static void resolve_rt(VkExec *ex) {
|
||||
if (d->layers < layers) layers = d->layers;
|
||||
if (!samples) samples = d->samples;
|
||||
}
|
||||
if (w == UINT32_MAX) { // no attachment: the area of viewport 0
|
||||
w = ex->has_vp && ex->vp[0][2] >= 1 ? (uint32_t)ex->vp[0][2] : 16;
|
||||
h = ex->has_vp && ex->vp[0][3] >= 1 ? (uint32_t)ex->vp[0][3] : 16;
|
||||
ex->pass_noatt = w == UINT32_MAX;
|
||||
if (ex->pass_noatt) {
|
||||
vk_exec_noatt_dims(ex, &w, &h);
|
||||
layers = 1;
|
||||
static int logged;
|
||||
if (logged < 8 && ex->has_vp && (ex->vp[0][0] != 0 || ex->vp[0][1] != 0 || ex->vp[0][2] != w || ex->vp[0][3] != h))
|
||||
logged++, rt_log("vk_exec: pass without attachments %ux%u for viewport %g,%g %gx%g", w, h, ex->vp[0][0],
|
||||
ex->vp[0][1], ex->vp[0][2], ex->vp[0][3]);
|
||||
}
|
||||
ex->pass_w = w, ex->pass_h = h, ex->pass_layers = layers;
|
||||
ex->pass_ncolor = (uint32_t)n;
|
||||
|
||||
@@ -51,6 +51,7 @@ typedef struct VkExec {
|
||||
int rt_resolved; // color[] and depth hold this command buffer's images for rt
|
||||
VkExecTarget color[8], depth; // resolved targets
|
||||
uint32_t pass_w, pass_h, pass_layers; // render area and layer count of the open (or next) pass
|
||||
int pass_noatt; // the pass has no attachment: its size follows the draws (vk_exec_noatt_dims)
|
||||
VkFormat pass_color[8], pass_depth, pass_stencil; // attachment formats of the pass (VkPipelineRenderingCreateInfo);
|
||||
// VK_FORMAT_UNDEFINED: none
|
||||
uint32_t pass_ncolor, pass_samples; // colorAttachmentCount and rasterization samples of the pass
|
||||
@@ -123,6 +124,7 @@ void vk_exec_draw_new_cb(void);
|
||||
VkBuffer vk_exec_inline_buffer(VkDeviceSize size);
|
||||
// Scissor 0 clipped to the render area of the open pass; extent 0: nothing to draw.
|
||||
VkRect2D vk_exec_scissor(const VkExec *ex);
|
||||
void vk_exec_noatt_dims(const VkExec *ex, uint32_t *w, uint32_t *h); // pass size when no attachment is set
|
||||
// 1: every target of the current pass (any 1: at least one) was rendered in the previous presented frame (per-frame
|
||||
// targets); 0 otherwise, or when the pass has none.
|
||||
int vk_exec_targets_recent(VkExec *ex, int any);
|
||||
|
||||
@@ -1508,6 +1508,12 @@ static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) {
|
||||
if (ex->render_disabled) return 0;
|
||||
cb_res(ex);
|
||||
dummies_init();
|
||||
if (ex->pass_noatt) { // no attachment: the pass covers this draw's viewport or scissor, reopened when it needs more
|
||||
uint32_t w, h;
|
||||
vk_exec_noatt_dims(ex, &w, &h);
|
||||
if (ex->in_pass && (w > ex->pass_w || h > ex->pass_h)) vk_exec_pass_end(ex);
|
||||
if (!ex->in_pass) ex->rt_resolved = 0;
|
||||
}
|
||||
if (!ex->in_pass) ex->dirty |= VK_EXEC_DIRTY_VIEWPORT | VK_EXEC_DIRTY_SCISSOR;
|
||||
vk_exec_pass_begin(ex);
|
||||
VkRect2D sc = vk_exec_scissor(ex);
|
||||
|
||||
Reference in new issue
Block a user