diff --git a/runtime/vk.h b/runtime/vk.h index 0b105c78..53f06c17 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -679,8 +679,9 @@ void vk_pipeline_answers(const VkPipeState *s, GfxShaderAnswers *vs, GfxShaderAn int vk_pipeline_tex_type(int nvn_target); // NVN_TEXTURE_TARGET_* -> GFX_TEX_* (GfxShaderAnswers.tex_type) uint32_t vk_pipeline_target_wmask(const VkPipeState *s, int i); // colour write mask of target i the pipeline uses // The sign of the depth bias a volume mask draw gets (vk_pipeline.c, see there), -1 toward smaller depth, 1 toward -// larger, 0 for any other draw. vk_pipeline_set_dynamic enables the bias for it; vk_exec_draw.c record_fixed sets the -// values, VOLUME_BIAS_UNITS and VOLUME_BIAS_SLOPE times the sign. +// larger, 0 for any other draw. vk_pipeline_set_dynamic enables the bias for it; vk_exec_draw.c prepare_draw decides it +// where the draw's state changes and record_fixed sets the values, VOLUME_BIAS_UNITS and VOLUME_BIAS_SLOPE times the +// sign. int vk_pipeline_volume_bias(const VkPipeState *s); #define VOLUME_BIAS_UNITS 16.0f #define VOLUME_BIAS_SLOPE 1.0f diff --git a/runtime/vk_exec.h b/runtime/vk_exec.h index 9e475ccb..a08b6124 100644 --- a/runtime/vk_exec.h +++ b/runtime/vk_exec.h @@ -119,7 +119,7 @@ typedef struct VkExec { uint32_t st_vmask[2], st_wmask[2], st_ref[2]; // OP_STENCIL per face (0 front, 1 back): compare mask, write mask, ref float point_size; // OP_BIND_STATE kind 6: NVN point size for the support buffer; 0 = never set = 1 p_poly_offset poly_offset; // OP_POLY_OFFSET: depth bias factor, units, clamp - int8_t volume_bias; // the sign of the volume bias recorded in place of poly_offset (record_fixed) + int8_t volume_bias; // the sign of the volume bias recorded in place of poly_offset: set by prepare_draw, used by record_fixed p_prim_restart prim_restart; // OP_PRIM_RESTART: applied to indexed strip and fan draws (op_draw_idx) float blend_color[4]; // OP_BLEND_COLOR int64_t copy_stride; // OP_COPY_STRIDE: row stride of buffer <-> texture copies (vk_exec_xfer.c) diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index 95c74f32..1a217027 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -2784,11 +2784,11 @@ static VkViewport draw_viewport(VkExec *ex) { return v; } -// s: the draw's state. A volume mask draw records its own depth bias (vk_pipeline_volume_bias) in place of the game's. -static void record_fixed(VkExec *ex, const VkPipeState *s) { +// A volume mask draw records its own depth bias in place of the game's: ex->volume_bias, which prepare_draw sets from +// vk_pipeline_volume_bias where the draw's dynamic state changes. +static void record_fixed(VkExec *ex) { VkCommandBuffer cb = ex->cb; - int vb = vk_pipeline_volume_bias(s); - if (vb != ex->volume_bias) ex->dirty |= VK_EXEC_DIRTY_DEPTH_BIAS, ex->volume_bias = (int8_t)vb; + int vb = ex->volume_bias; if (ex->dirty & VK_EXEC_DIRTY_VIEWPORT) { VkViewport v = draw_viewport(ex); vkCmdSetViewportWithCount(cb, 1, &v); @@ -3425,6 +3425,10 @@ static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) { __atomic_fetch_add(&DD.calls, 1, __ATOMIC_RELAXED), __atomic_fetch_add(&DD.cmds, cmds, __ATOMIC_RELAXED); if (!cmds) __atomic_fetch_add(&DD.empty, 1, __ATOMIC_RELAXED); ex->recorded += cmds != 0; + // The volume bias follows the state alone, so it is decided here, once per state change, and a draw with the + // state recorded last keeps it. A new command buffer or a pipeline bind clears st_valid and comes here. + int vb = vk_pipeline_volume_bias(sp); + if (vb != ex->volume_bias) ex->dirty |= VK_EXEC_DIRTY_DEPTH_BIAS, ex->volume_bias = (int8_t)vb; MX_CPY(&D->B.st, sp, sizeof *sp), D->B.st_valid = 1; if (ex->mark && ex->fr.draws == ex->mark_draws0) ex->mark->first[0] = vs, ex->mark->first[1] = fs; } @@ -3435,7 +3439,7 @@ static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) { vk_mvsurvey_draw(ex); vk_mvprev_draw(ex); if (mo) plat_mutex_unlock(&mo_lock); - record_fixed(ex, sp); + record_fixed(ex); repeat_stats(ex, info); if (bim) bi_gt(ex, bgt), bi_gb(ex, bgb); if (bim == 2) bi_census(ex, info, sp, bgt, bgb, bsg, sm_hit); // on counts nothing: it is what gets timed diff --git a/runtime/vk_pipeline.c b/runtime/vk_pipeline.c index ea1f420a..b144140c 100644 --- a/runtime/vk_pipeline.c +++ b/runtime/vk_pipeline.c @@ -3278,7 +3278,11 @@ uint32_t vk_pipeline_set_dynamic(VkCommandBuffer cb, const VkPipeState *s) { // moves the rebuilt depth but not the volume. Such a draw, when the game sets no polygon offset for it, gets a depth // bias toward the viewer of VOLUME_BIAS_UNITS plus VOLUME_BIAS_SLOPE times its depth slope (one pixel of it), so a // surface the face lies on counts as inside, as the test's equal case means; a surface farther from the face than a -// pixel of its slope is decided as before. TOTK_VOLUME_MASK_BIAS=0 (test) leaves such draws as the game sets them. +// pixel of its slope is decided as before. Only tests whose equal case passes (LEQUAL, GEQUAL) get the bias, toward +// passing. The same pass also draws state-alike draws with GREATER, whose equal case fails: the volume's back faces +// into the same channel and, in towns and in rain, another shader's front faces into the red channel. Biasing those +// toward passing would turn the game's tie the other way, so they are left as the game sets them. +// TOTK_VOLUME_MASK_BIAS=0 (test) leaves every such draw as the game sets it. int vk_pipeline_volume_bias(const VkPipeState *s) { static int knob = -1; if (knob < 0) knob = rt_knob("VOLUME_MASK_BIAS", "1"); @@ -3290,8 +3294,7 @@ int vk_pipeline_volume_bias(const VkPipeState *s) { if (!d->dt || d->dw || (pl->offset_en >> mode & 1) || !(s->color.blend_en & 1) || b->eq_rgb != NVN_BLEND_EQUATION_REVERSE_SUB || b->src_rgb != NVN_BLEND_FUNC_ONE || b->dst_rgb != NVN_BLEND_FUNC_ONE) return 0; - if (d->df == NVN_DEPTH_FUNC_LESS || d->df == NVN_DEPTH_FUNC_LEQUAL) return -1; - return d->df == NVN_DEPTH_FUNC_GREATER || d->df == NVN_DEPTH_FUNC_GEQUAL; + return d->df == NVN_DEPTH_FUNC_LEQUAL ? -1 : d->df == NVN_DEPTH_FUNC_GEQUAL; } // The values vk_pipeline_set_dynamic records for a state, as the commands take them.